File tree 2 files changed +11
-5
lines changed
2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -411,11 +411,7 @@ const REBPOOLSPEC Mem_Pool_Spec[MAX_POOLS] =
411
411
#endif
412
412
} else {
413
413
if (powerof2 ) {
414
- // !!! WHO added this and why??? Just use a left shift and mask!
415
- REBCNT len = 2048 ;
416
- while (len < length )
417
- len *=2 ;
418
- length = len ;
414
+ U32_ROUND_UP_POWER_OF_2 (length );
419
415
} else
420
416
length = ALIGN (length , 2048 );
421
417
#ifdef DEBUGGING
Original file line number Diff line number Diff line change @@ -306,6 +306,16 @@ typedef void(*CFUNC)(void *);
306
306
307
307
#define ROUND_TO_INT (d ) (REBINT)(floor((d) + 0.5 ))
308
308
309
+ // https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
310
+ // Note: 32bit, v must be > 0
311
+ #define U32_ROUND_UP_POWER_OF_2 (v ) \
312
+ v--; \
313
+ v |= v >> 1 ; \
314
+ v |= v >> 2 ; \
315
+ v |= v >> 4 ; \
316
+ v |= v >> 8 ; \
317
+ v |= v >> 16 ; \
318
+ v++; \
309
319
310
320
/* **********************************************************************
311
321
**
You can’t perform that action at this time.
0 commit comments