asm/asm.c
void *asmalloc(usize n) {
    usize align = region && (((uptr) region->current) % 16 != 0) ?
        (16 - (((uptr) region->current) % 16)) :
        0;

    if (region == NULL || region->current + align + n >= region->end) {
        usize size = MAX(REGION_MIN_SIZE, 1 << (64 - __builtin_clz(n - 1)));
        void *allocated = malloc(size);
        assert(allocated);

       *((struct Region *) allocated) = (struct Region) {
            .current = allocated + sizeof(struct Region),
            .end = allocated + size,
            .next = region
        };

       region = allocated;
       align = 0;
       asmdbg(
            NULL, NULL,
            "Allocated new region of size 0x%08x at %p\n",
            size, region
        );
    }

    region->current += align;

    void *result = region->current;
    region->current += n;
    return result;
}
// allocates a buffer of at least n bytes which is cleaned up at exit time
allocates a buffer of at least n bytes which is cleaned up at exit time
allocates a buffer of at least n bytes which is cleaned up at exit time
void *asmalloc(usize n) {
    usize align = region && (((uptr) region->current) % 16 != 0) ?
        (16 - (((uptr) region->current) % 16)) :
        0;
    if (region == NULL || region->current + align + n >= region->end) {
        usize size = MAX(REGION_MIN_SIZE, 1 << (64 - __builtin_clz(n - 1)));
        void *allocated = malloc(size);
        assert(allocated);
       *((struct Region *) allocated) = (struct Region) {
            .current = allocated + sizeof(struct Region),
            .end = allocated + size,
            .next = region
        };
       region = allocated;
       align = 0;
       asmdbg(
            NULL, NULL,
            "Allocated new region of size 0x%08x at %p\n",
            size, region
        );
    }
    region->current += align;
    void *result = region->current;
    region->current += n;
    return result;
}
void * asmalloc ( usize n ) { usize align = region && ( ( ( uptr ) region -> current ) % 16 != 0 ) ? ( 16 - ( ( ( uptr ) region -> current ) % 16 ) ) : 0 ; if ( region == NULL || region -> current + align + n >= region -> end ) { usize size = MAX ( REGION_MIN_SIZE , 1 << ( 64 - __builtin_clz ( n - 1 ) ) ) ; void * allocated = malloc ( size ) ; assert ( allocated ) ; * ( ( struct Region * ) allocated ) = ( struct Region ) { . current = allocated + sizeof ( struct Region ) , . end = allocated + size , . next = region } ; region = allocated ; align = 0 ; asmdbg ( NULL , NULL , " \n " , size , region ) ; } region -> current += align ; void * result = region -> current ; region -> current += n ; return result ; }
allocates a buffer of at least n bytes which is cleaned up at exit time
allocates a buffer of at least n bytes which is cleaned up at exit time