4 #define LEAFSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_LEAF))
5 #define BRANCHSIZ (sizeof(RAA)-sizeof(RAA_UNION)+sizeof(RAA_BRANCH))
7 #define LAYERSHIFT(r) ( (r)->layers==0 ? RAA_BLKSHIFT : RAA_LAYERSHIFT )
9 static struct RAA
*real_raa_init(int layers
)
15 r
= nasm_zalloc(LEAFSIZ
);
18 r
= nasm_malloc(BRANCHSIZ
);
20 for (i
= 0; i
< RAA_LAYERSIZE
; i
++)
21 r
->u
.b
.data
[i
] = NULL
;
23 (RAA_BLKSHIFT
- RAA_LAYERSHIFT
) + layers
* RAA_LAYERSHIFT
;
28 struct RAA
*raa_init(void)
30 return real_raa_init(0);
33 void raa_free(struct RAA
*r
)
37 for (p
= r
->u
.b
.data
; p
- r
->u
.b
.data
< RAA_LAYERSIZE
; p
++)
44 int64_t raa_read(struct RAA
*r
, int32_t posn
)
46 if ((uint32_t) posn
>= (UINT32_C(1) << (r
->shift
+ LAYERSHIFT(r
))))
47 return 0; /* Return 0 for undefined entries */
48 while (r
->layers
> 0) {
49 int32_t l
= posn
>> r
->shift
;
50 posn
&= (UINT32_C(1) << r
->shift
) - 1;
53 return 0; /* Return 0 for undefined entries */
55 return r
->u
.l
.data
[posn
];
58 struct RAA
*raa_write(struct RAA
*r
, int32_t posn
, int64_t value
)
63 nasm_malloc_error(ERR_PANIC
, "negative position in raa_write");
65 while ((UINT32_C(1) << (r
->shift
+ LAYERSHIFT(r
))) <= (uint32_t) posn
) {
72 s
= nasm_malloc(BRANCHSIZ
);
73 for (i
= 0; i
< RAA_LAYERSIZE
; i
++)
74 s
->u
.b
.data
[i
] = NULL
;
75 s
->layers
= r
->layers
+ 1;
76 s
->shift
= LAYERSHIFT(r
) + r
->shift
;
83 while (r
->layers
> 0) {
85 int32_t l
= posn
>> r
->shift
;
86 posn
&= (UINT32_C(1) << r
->shift
) - 1;
89 *s
= real_raa_init(r
->layers
- 1);
93 r
->u
.l
.data
[posn
] = value
;