diff --git a/std/assembly/internal/array.ts b/std/assembly/internal/array.ts index 71232887..388341af 100644 --- a/std/assembly/internal/array.ts +++ b/std/assembly/internal/array.ts @@ -36,14 +36,14 @@ export function weakHeapSort(arr: Array, comparator: (a: T, b: T) => i32): const typeShift = alignof(); const intShift = alignof(); - var blen = (len + 7) >> 3; + var blen = (len + 31) >> 5; var bitset = allocate_memory(blen << intShift); set_memory(bitset, 0, blen << intShift); for (i = len - 1; i > 0; i--) { j = i; - while ((j & 1) == ((load(bitset + ((j >> 4) << intShift)) >> ((j >> 1) & 7)) & 1)) { + while ((j & 1) == ((load(bitset + ((j >> 6) << intShift)) >> ((j >> 1) & 31)) & 1)) { j >>= 1; } @@ -54,8 +54,8 @@ export function weakHeapSort(arr: Array, comparator: (a: T, b: T) => i32): if (comparator(a, b) < 0) { store( - bitset + ((i >> 3) << intShift), - load(bitset + ((i >> 3) << intShift)) ^ (1 << (i & 7)) + bitset + ((i >> 5) << intShift), + load(bitset + ((i >> 5) << intShift)) ^ (1 << (i & 31)) ); store(arr.__memory + (i << typeShift), a); // arr[i] = a; store(arr.__memory + (p << typeShift), b); // arr[p] = b; @@ -73,7 +73,7 @@ export function weakHeapSort(arr: Array, comparator: (a: T, b: T) => i32): store(arr.__memory + (i << typeShift), a); let x = 1; - while ((y = (x << 1) + ((load(bitset + ((x >> 3) << intShift)) >> (x & 7)) & 1)) < i) { + while ((y = (x << 1) + ((load(bitset + ((x >> 5) << intShift)) >> (x & 31)) & 1)) < i) { x = y; } @@ -83,8 +83,8 @@ export function weakHeapSort(arr: Array, comparator: (a: T, b: T) => i32): if (comparator(a, b) < 0) { store( - bitset + ((x >> 3) << intShift), - load(bitset + ((x >> 3) << intShift)) ^ (1 << (x & 7)) + bitset + ((x >> 5) << intShift), + load(bitset + ((x >> 5) << intShift)) ^ (1 << (x & 31)) ); store(arr.__memory + (x << typeShift), a); // arr[x] = a; diff --git a/tests/compiler/std/array.optimized.wat b/tests/compiler/std/array.optimized.wat index 7f8e40bf..f9010722 100644 --- a/tests/compiler/std/array.optimized.wat +++ b/tests/compiler/std/array.optimized.wat @@ -4030,9 +4030,9 @@ (get_local $0) ) ) - (i32.const 7) + (i32.const 31) ) - (i32.const 3) + (i32.const 5) ) ) (i32.const 2) @@ -4076,7 +4076,7 @@ (i32.shl (i32.shr_s (get_local $2) - (i32.const 4) + (i32.const 6) ) (i32.const 2) ) @@ -4087,7 +4087,7 @@ (get_local $2) (i32.const 1) ) - (i32.const 7) + (i32.const 31) ) ) (i32.const 1) @@ -4156,7 +4156,7 @@ (i32.shl (i32.shr_s (get_local $3) - (i32.const 3) + (i32.const 5) ) (i32.const 2) ) @@ -4168,7 +4168,7 @@ (i32.shl (i32.shr_s (get_local $3) - (i32.const 3) + (i32.const 5) ) (i32.const 2) ) @@ -4178,7 +4178,7 @@ (i32.const 1) (i32.and (get_local $3) - (i32.const 7) + (i32.const 31) ) ) ) @@ -4287,7 +4287,7 @@ (i32.shl (i32.shr_s (get_local $2) - (i32.const 3) + (i32.const 5) ) (i32.const 2) ) @@ -4295,7 +4295,7 @@ ) (i32.and (get_local $2) - (i32.const 7) + (i32.const 31) ) ) (i32.const 1) @@ -4360,7 +4360,7 @@ (i32.shl (i32.shr_s (get_local $2) - (i32.const 3) + (i32.const 5) ) (i32.const 2) ) @@ -4372,7 +4372,7 @@ (i32.shl (i32.shr_s (get_local $2) - (i32.const 3) + (i32.const 5) ) (i32.const 2) ) @@ -4382,7 +4382,7 @@ (i32.const 1) (i32.and (get_local $2) - (i32.const 7) + (i32.const 31) ) ) ) diff --git a/tests/compiler/std/array.untouched.wat b/tests/compiler/std/array.untouched.wat index 12d22bac..efe7cc39 100644 --- a/tests/compiler/std/array.untouched.wat +++ b/tests/compiler/std/array.untouched.wat @@ -4635,9 +4635,9 @@ (i32.shr_s (i32.add (get_local $2) - (i32.const 7) + (i32.const 31) ) - (i32.const 3) + (i32.const 5) ) ) (set_local $10 @@ -4690,7 +4690,7 @@ (i32.shl (i32.shr_s (get_local $4) - (i32.const 4) + (i32.const 6) ) (i32.const 2) ) @@ -4701,7 +4701,7 @@ (get_local $4) (i32.const 1) ) - (i32.const 7) + (i32.const 31) ) ) (i32.const 1) @@ -4774,7 +4774,7 @@ (i32.shl (i32.shr_s (get_local $3) - (i32.const 3) + (i32.const 5) ) (i32.const 2) ) @@ -4786,7 +4786,7 @@ (i32.shl (i32.shr_s (get_local $3) - (i32.const 3) + (i32.const 5) ) (i32.const 2) ) @@ -4796,7 +4796,7 @@ (i32.const 1) (i32.and (get_local $3) - (i32.const 7) + (i32.const 31) ) ) ) @@ -4910,7 +4910,7 @@ (i32.shl (i32.shr_s (get_local $11) - (i32.const 3) + (i32.const 5) ) (i32.const 2) ) @@ -4918,7 +4918,7 @@ ) (i32.and (get_local $11) - (i32.const 7) + (i32.const 31) ) ) (i32.const 1) @@ -4988,7 +4988,7 @@ (i32.shl (i32.shr_s (get_local $11) - (i32.const 3) + (i32.const 5) ) (i32.const 2) ) @@ -5000,7 +5000,7 @@ (i32.shl (i32.shr_s (get_local $11) - (i32.const 3) + (i32.const 5) ) (i32.const 2) ) @@ -5010,7 +5010,7 @@ (i32.const 1) (i32.and (get_local $11) - (i32.const 7) + (i32.const 31) ) ) )