]> git.codecow.com Git - nano25519.git/commitdiff
Set pointers where they are reused to guarantee to the compiler that they won't change.
authorChris Duncan <chris@codecow.com>
Wed, 28 Oct 2026 19:53:23 +0000 (12:53 -0700)
committerChris Duncan <chris@codecow.com>
Wed, 28 Oct 2026 19:53:23 +0000 (12:53 -0700)
src/assembly/ed25519/fe.ts

index 74a7c9d50e325fdc64ec9d9170b511624cc47df6..3f1c178b9c5ad9c084f2410ee365ac9a5672effd 100644 (file)
@@ -39,7 +39,10 @@ export function fe (): FieldElement {
  * @param h FieldElement destination
  */
 export function fe_0 (h: FieldElement): void {
-       memory.fill(changetype<usize>(h), 0, 48)
+       const h_ptr: usize = changetype<usize>(h)
+       v128.store(h_ptr, i64x2.splat(0), 0 << 4)
+       v128.store(h_ptr, i64x2.splat(0), 1 << 4)
+       v128.store(h_ptr, i64x2.splat(0), 2 << 4)
 }
 
 /**
@@ -60,17 +63,20 @@ export function fe_1 (h: FieldElement): void {
  * @param g FieldElement summand source
  */
 export function fe_add (h: FieldElement, f: FieldElement, g: FieldElement): void {
-       const f0 = v128.load(changetype<usize>(f), 0 << 4)
-       const f1 = v128.load(changetype<usize>(f), 1 << 4)
-       const f2 = v128.load64_zero(changetype<usize>(f), 2 << 4)
+       const f_ptr: usize = changetype<usize>(f)
+       const f0 = v128.load(f_ptr, 0 << 4)
+       const f1 = v128.load(f_ptr, 1 << 4)
+       const f2 = v128.load64_zero(f_ptr, 2 << 4)
 
-       const g0 = v128.load(changetype<usize>(g), 0 << 4)
-       const g1 = v128.load(changetype<usize>(g), 1 << 4)
-       const g2 = v128.load64_zero(changetype<usize>(g), 2 << 4)
+       const g_ptr: usize = changetype<usize>(g)
+       const g0 = v128.load(g_ptr, 0 << 4)
+       const g1 = v128.load(g_ptr, 1 << 4)
+       const g2 = v128.load64_zero(g_ptr, 2 << 4)
 
-       v128.store(changetype<usize>(h), v128.add<i32>(f0, g0), 0 << 4)
-       v128.store(changetype<usize>(h), v128.add<i32>(f1, g1), 1 << 4)
-       v128.store_lane<i64>(changetype<usize>(h), v128.add<i32>(f2, g2), 0, 2 << 4)
+       const h_ptr: usize = changetype<usize>(h)
+       v128.store(h_ptr, v128.add<i32>(f0, g0), 0 << 4)
+       v128.store(h_ptr, v128.add<i32>(f1, g1), 1 << 4)
+       v128.store_lane<i64>(h_ptr, v128.add<i32>(f2, g2), 0, 2 << 4)
 }
 
 /**
@@ -84,20 +90,25 @@ export function fe_add (h: FieldElement, f: FieldElement, g: FieldElement): void
  * @param {FieldElement} g difference destination, summand source, and subtrahend source
  */
 export function fe_addsub (a: FieldElement, b: FieldElement, f: FieldElement, g: FieldElement): void {
-       const f0 = v128.load(changetype<usize>(f), 0 << 4)
-       const f1 = v128.load(changetype<usize>(f), 1 << 4)
-       const f2 = v128.load64_zero(changetype<usize>(f), 2 << 4)
-
-       const g0 = v128.load(changetype<usize>(g), 0 << 4)
-       const g1 = v128.load(changetype<usize>(g), 1 << 4)
-       const g2 = v128.load64_zero(changetype<usize>(g), 2 << 4)
-
-       v128.store(changetype<usize>(a), v128.add<i32>(f0, g0), 0 << 4)
-       v128.store(changetype<usize>(a), v128.add<i32>(f1, g1), 1 << 4)
-       v128.store_lane<i64>(changetype<usize>(a), v128.add<i32>(f2, g2), 0, 2 << 4)
-       v128.store(changetype<usize>(b), v128.sub<i32>(f0, g0), 0 << 4)
-       v128.store(changetype<usize>(b), v128.sub<i32>(f1, g1), 1 << 4)
-       v128.store_lane<i64>(changetype<usize>(b), v128.sub<i32>(f2, g2), 0, 2 << 4)
+       const f_ptr: usize = changetype<usize>(f)
+       const f0 = v128.load(f_ptr, 0 << 4)
+       const f1 = v128.load(f_ptr, 1 << 4)
+       const f2 = v128.load64_zero(f_ptr, 2 << 4)
+
+       const g_ptr: usize = changetype<usize>(g)
+       const g0 = v128.load(g_ptr, 0 << 4)
+       const g1 = v128.load(g_ptr, 1 << 4)
+       const g2 = v128.load64_zero(g_ptr, 2 << 4)
+
+       const a_ptr: usize = changetype<usize>(a)
+       v128.store(a_ptr, v128.add<i32>(f0, g0), 0 << 4)
+       v128.store(a_ptr, v128.add<i32>(f1, g1), 1 << 4)
+       v128.store_lane<i64>(a_ptr, v128.add<i32>(f2, g2), 0, 2 << 4)
+
+       const b_ptr: usize = changetype<usize>(b)
+       v128.store(b_ptr, v128.sub<i32>(f0, g0), 0 << 4)
+       v128.store(b_ptr, v128.sub<i32>(f1, g1), 1 << 4)
+       v128.store_lane<i64>(b_ptr, v128.sub<i32>(f2, g2), 0, 2 << 4)
 }
 
 /**
@@ -109,12 +120,24 @@ export function fe_addsub (a: FieldElement, b: FieldElement, f: FieldElement, g:
  */
 export function fe_cmov (f: FieldElement, g: FieldElement, b: u64): void {
        const c = v128.splat<u64>(0 - b)
-       const f0 = v128.load(changetype<usize>(f), 0 << 4), f1 = v128.load(changetype<usize>(f), 1 << 4), f2 = v128.load64_zero(changetype<usize>(f), 2 << 4)
-       const g0 = v128.load(changetype<usize>(g), 0 << 4), g1 = v128.load(changetype<usize>(g), 1 << 4), g2 = v128.load64_zero(changetype<usize>(g), 2 << 4)
-       const h0 = v128.bitselect(g0, f0, c), h1 = v128.bitselect(g1, f1, c), h2 = v128.bitselect(g2, f2, c)
-       v128.store(changetype<usize>(f), h0, 0 << 4)
-       v128.store(changetype<usize>(f), h1, 1 << 4)
-       v128.store_lane<u64>(changetype<usize>(f), h2, 0, 2 << 4)
+
+       const f_ptr: usize = changetype<usize>(f)
+       const f0 = v128.load(f_ptr, 0 << 4)
+       const f1 = v128.load(f_ptr, 1 << 4)
+       const f2 = v128.load64_zero(f_ptr, 2 << 4)
+
+       const g_ptr: usize = changetype<usize>(g)
+       const g0 = v128.load(g_ptr, 0 << 4)
+       const g1 = v128.load(g_ptr, 1 << 4)
+       const g2 = v128.load64_zero(g_ptr, 2 << 4)
+
+       const h0 = v128.bitselect(g0, f0, c)
+       const h1 = v128.bitselect(g1, f1, c)
+       const h2 = v128.bitselect(g2, f2, c)
+
+       v128.store(f_ptr, h0, 0 << 4)
+       v128.store(f_ptr, h1, 1 << 4)
+       v128.store_lane<u64>(f_ptr, h2, 0, 2 << 4)
 }
 
 /**
@@ -124,7 +147,11 @@ export function fe_cmov (f: FieldElement, g: FieldElement, b: u64): void {
  * @param {FieldElement} f source
  */
 export function fe_copy (h: FieldElement, f: FieldElement): void {
-       memory.copy(changetype<usize>(h), changetype<usize>(f), 40)
+       const f_ptr: usize = changetype<usize>(f)
+       const h_ptr: usize = changetype<usize>(h)
+       v128.store(h_ptr, v128.load(f_ptr, 0 << 4), 0 << 4)
+       v128.store(h_ptr, v128.load(f_ptr, 1 << 4), 1 << 4)
+       v128.store_lane<i64>(h_ptr, v128.load64_zero(f_ptr, 2 << 4), 0, 2 << 4)
 }
 
 /**
@@ -134,11 +161,19 @@ export function fe_copy (h: FieldElement, f: FieldElement): void {
  * @param f FieldElement summand source
  */
 export function fe_dbl (h: FieldElement, f: FieldElement): void {
-       const f0 = v128.load(changetype<usize>(f), 0 << 4), f1 = v128.load(changetype<usize>(f), 1 << 4), f2 = v128.load64_zero(changetype<usize>(f), 2 << 4)
-       const h0 = v128.add<i32>(f0, f0), h1 = v128.add<i32>(f1, f1), h2 = v128.add<i32>(f2, f2)
-       v128.store(changetype<usize>(h), h0, 0 << 4)
-       v128.store(changetype<usize>(h), h1, 1 << 4)
-       v128.store_lane<i64>(changetype<usize>(h), h2, 0, 2 << 4)
+       const f_ptr: usize = changetype<usize>(f)
+       const f0 = v128.load(f_ptr, 0 << 4)
+       const f1 = v128.load(f_ptr, 1 << 4)
+       const f2 = v128.load64_zero(f_ptr, 2 << 4)
+
+       const h0 = v128.add<i32>(f0, f0)
+       const h1 = v128.add<i32>(f1, f1)
+       const h2 = v128.add<i32>(f2, f2)
+
+       const h_ptr: usize = changetype<usize>(h)
+       v128.store(h_ptr, h0, 0 << 4)
+       v128.store(h_ptr, h1, 1 << 4)
+       v128.store_lane<i64>(h_ptr, h2, 0, 2 << 4)
 }
 
 /**
@@ -225,16 +260,17 @@ export function fe_frombytes (h: FieldElement, s: StaticArray<u8>): void {
        h8 -= c & m26
        h9 += carry8
 
-       store<i32>(changetype<usize>(h), h0, 0 << 2)
-       store<i32>(changetype<usize>(h), h1, 1 << 2)
-       store<i32>(changetype<usize>(h), h2, 2 << 2)
-       store<i32>(changetype<usize>(h), h3, 3 << 2)
-       store<i32>(changetype<usize>(h), h4, 4 << 2)
-       store<i32>(changetype<usize>(h), h5, 5 << 2)
-       store<i32>(changetype<usize>(h), h6, 6 << 2)
-       store<i32>(changetype<usize>(h), h7, 7 << 2)
-       store<i32>(changetype<usize>(h), h8, 8 << 2)
-       store<i32>(changetype<usize>(h), h9, 9 << 2)
+       const h_ptr: usize = changetype<usize>(h)
+       store<i32>(h_ptr, h0, 0 << 2)
+       store<i32>(h_ptr, h1, 1 << 2)
+       store<i32>(h_ptr, h2, 2 << 2)
+       store<i32>(h_ptr, h3, 3 << 2)
+       store<i32>(h_ptr, h4, 4 << 2)
+       store<i32>(h_ptr, h5, 5 << 2)
+       store<i32>(h_ptr, h6, 6 << 2)
+       store<i32>(h_ptr, h7, 7 << 2)
+       store<i32>(h_ptr, h8, 8 << 2)
+       store<i32>(h_ptr, h9, 9 << 2)
 }
 
 /**
@@ -308,8 +344,9 @@ export function fe_isnegative (f: FieldElement, t: FieldElement): u8 {
  */
 export function fe_iszero (f: FieldElement, t_fe: FieldElement, t_u8x32: StaticArray<u8>): u8 {
        fe_tobytes(t_u8x32, f, t_fe)
-       const t0 = v128.load(changetype<usize>(t_u8x32), 0 << 4)
-       const t1 = v128.load(changetype<usize>(t_u8x32), 1 << 4)
+       const t_ptr: usize = changetype<usize>(t_u8x32)
+       const t0 = v128.load(t_ptr, 0 << 4)
+       const t1 = v128.load(t_ptr, 1 << 4)
        const d = v128.or(t0, t1)
        return u8(v128.any_true(d)) ^ 1
 }
@@ -323,9 +360,10 @@ export function fe_iszero (f: FieldElement, t_fe: FieldElement, t_u8x32: StaticA
  */
 export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void {
        // Load all 10 limbs of `f`
-       const f0123: v128 = v128.load(changetype<usize>(f), 0 << 4)
-       const f4567: v128 = v128.load(changetype<usize>(f), 1 << 4)
-       const f89xx: v128 = v128.load64_zero(changetype<usize>(f), 2 << 4)
+       const f_ptr: usize = changetype<usize>(f)
+       const f0123: v128 = v128.load(f_ptr, 0 << 4)
+       const f4567: v128 = v128.load(f_ptr, 1 << 4)
+       const f89xx: v128 = v128.load64_zero(f_ptr, 2 << 4)
 
        // Splat even limbs
        const f0: v128 = v128.shuffle<i32>(f0123, f0123, 0, 0, 0, 0)
@@ -354,9 +392,10 @@ export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void
        const f9: v128 = v128.shuffle<i32>(f9_2, f9_1, 0, 5, 0, 5)
 
        // Load all 10 limbs of `g`
-       const g0123: v128 = v128.load(changetype<usize>(g), 0 << 4)
-       const g4567: v128 = v128.load(changetype<usize>(g), 1 << 4)
-       const g89xx: v128 = v128.load64_zero(changetype<usize>(g), 2 << 4)
+       const g_ptr: usize = changetype<usize>(g)
+       const g0123: v128 = v128.load(g_ptr, 0 << 4)
+       const g4567: v128 = v128.load(g_ptr, 1 << 4)
+       const g89xx: v128 = v128.load64_zero(g_ptr, 2 << 4)
 
        // Shift limbs to align with even-odd `f` limbs
        const g9012: v128 = v128.shuffle<i32>(g89xx, g0123, 1, 4, 5, 6)
@@ -588,16 +627,17 @@ export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void
        h1 += carry0
 
        // assign results to output
-       store<i32>(changetype<usize>(h), h0, 0)
-       store<i32>(changetype<usize>(h), h1, 4)
-       store<i32>(changetype<usize>(h), h2, 8)
-       store<i32>(changetype<usize>(h), h3, 12)
-       store<i32>(changetype<usize>(h), h4, 16)
-       store<i32>(changetype<usize>(h), h5, 20)
-       store<i32>(changetype<usize>(h), h6, 24)
-       store<i32>(changetype<usize>(h), h7, 28)
-       store<i32>(changetype<usize>(h), h8, 32)
-       store<i32>(changetype<usize>(h), h9, 36)
+       const h_ptr: usize = changetype<usize>(h)
+       store<i32>(h_ptr, h0, 0)
+       store<i32>(h_ptr, h1, 4)
+       store<i32>(h_ptr, h2, 8)
+       store<i32>(h_ptr, h3, 12)
+       store<i32>(h_ptr, h4, 16)
+       store<i32>(h_ptr, h5, 20)
+       store<i32>(h_ptr, h6, 24)
+       store<i32>(h_ptr, h7, 28)
+       store<i32>(h_ptr, h8, 32)
+       store<i32>(h_ptr, h9, 36)
 }
 
 /**
@@ -613,13 +653,15 @@ export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void
  */
 export function fe_mul_dual (h_a: FieldElement, f_a: FieldElement, g_a: FieldElement, h_b: FieldElement, f_b: FieldElement, g_b: FieldElement): void {
        // Load all 10 limbs of each `f`
-       const f_a_0123: v128 = v128.load(changetype<usize>(f_a), 0 << 4)
-       const f_a_4567: v128 = v128.load(changetype<usize>(f_a), 1 << 4)
-       const f_a_89xx: v128 = v128.load64_zero(changetype<usize>(f_a), 2 << 4)
+       const f_a_ptr: usize = changetype<usize>(f_a)
+       const f_a_0123: v128 = v128.load(f_a_ptr, 0 << 4)
+       const f_a_4567: v128 = v128.load(f_a_ptr, 1 << 4)
+       const f_a_89xx: v128 = v128.load64_zero(f_a_ptr, 2 << 4)
 
-       const f_b_0123: v128 = v128.load(changetype<usize>(f_b), 0 << 4)
-       const f_b_4567: v128 = v128.load(changetype<usize>(f_b), 1 << 4)
-       const f_b_89xx: v128 = v128.load64_zero(changetype<usize>(f_b), 2 << 4)
+       const f_b_ptr: usize = changetype<usize>(f_b)
+       const f_b_0123: v128 = v128.load(f_b_ptr, 0 << 4)
+       const f_b_4567: v128 = v128.load(f_b_ptr, 1 << 4)
+       const f_b_89xx: v128 = v128.load64_zero(f_b_ptr, 2 << 4)
 
        // Blend each `f` index in alternating lanes
        const f01: v128 = v128.shuffle<i32>(f_a_0123, f_b_0123, 0, 4, 1, 5)
@@ -655,13 +697,15 @@ export function fe_mul_dual (h_a: FieldElement, f_a: FieldElement, g_a: FieldEle
        const f9: v128 = v128.shuffle<i32>(f9_1, f9_2, 0, 1, 4, 5)
 
        // Load all 10 limbs of each `g`
-       const g_a_0123: v128 = v128.load(changetype<usize>(g_a), 0 << 4)
-       const g_a_4567: v128 = v128.load(changetype<usize>(g_a), 1 << 4)
-       const g_a_89xx: v128 = v128.load64_zero(changetype<usize>(g_a), 2 << 4)
+       const g_a_ptr: usize = changetype<usize>(g_a)
+       const g_a_0123: v128 = v128.load(g_a_ptr, 0 << 4)
+       const g_a_4567: v128 = v128.load(g_a_ptr, 1 << 4)
+       const g_a_89xx: v128 = v128.load64_zero(g_a_ptr, 2 << 4)
 
-       const g_b_0123: v128 = v128.load(changetype<usize>(g_b), 0 << 4)
-       const g_b_4567: v128 = v128.load(changetype<usize>(g_b), 1 << 4)
-       const g_b_89xx: v128 = v128.load64_zero(changetype<usize>(g_b), 2 << 4)
+       const g_b_ptr: usize = changetype<usize>(g_b)
+       const g_b_0123: v128 = v128.load(g_b_ptr, 0 << 4)
+       const g_b_4567: v128 = v128.load(g_b_ptr, 1 << 4)
+       const g_b_89xx: v128 = v128.load64_zero(g_b_ptr, 2 << 4)
 
        // Blend each `g` index in alternating lanes
        const g01: v128 = v128.shuffle<i32>(g_a_0123, g_b_0123, 0, 4, 1, 5)
@@ -875,13 +919,15 @@ export function fe_mul_dual (h_a: FieldElement, f_a: FieldElement, g_a: FieldEle
        const h89: v128 = v128.shuffle<i32>(h8, h9, 0, 2, 4, 6) // h8a, h8b, h9a, h9b
 
        // assign results to parallel outputs
-       v128.store(changetype<usize>(h_a), v128.shuffle<i32>(h01, h23, 0, 2, 4, 6), 0 << 4)
-       v128.store(changetype<usize>(h_a), v128.shuffle<i32>(h45, h67, 0, 2, 4, 6), 1 << 4)
-       v128.store_lane<i64>(changetype<usize>(h_a), v128.shuffle<i32>(h89, h89, 0, 2, 4, 6), 0, 2 << 4)
-
-       v128.store(changetype<usize>(h_b), v128.shuffle<i32>(h01, h23, 1, 3, 5, 7), 0 << 4)
-       v128.store(changetype<usize>(h_b), v128.shuffle<i32>(h45, h67, 1, 3, 5, 7), 1 << 4)
-       v128.store_lane<i64>(changetype<usize>(h_b), v128.shuffle<i32>(h89, h89, 1, 3, 5, 7), 0, 2 << 4)
+       const h_a_ptr: usize = changetype<usize>(h_a)
+       v128.store(h_a_ptr, v128.shuffle<i32>(h01, h23, 0, 2, 4, 6), 0 << 4)
+       v128.store(h_a_ptr, v128.shuffle<i32>(h45, h67, 0, 2, 4, 6), 1 << 4)
+       v128.store_lane<i64>(h_a_ptr, v128.shuffle<i32>(h89, h89, 0, 2, 4, 6), 0, 2 << 4)
+
+       const h_b_ptr: usize = changetype<usize>(h_b)
+       v128.store(h_b_ptr, v128.shuffle<i32>(h01, h23, 1, 3, 5, 7), 0 << 4)
+       v128.store(h_b_ptr, v128.shuffle<i32>(h45, h67, 1, 3, 5, 7), 1 << 4)
+       v128.store_lane<i64>(h_b_ptr, v128.shuffle<i32>(h89, h89, 1, 3, 5, 7), 0, 2 << 4)
 }
 
 /**
@@ -897,13 +943,15 @@ export function fe_mul_dual (h_a: FieldElement, f_a: FieldElement, g_a: FieldEle
  */
 export function fe_mul2_dual (h_a: FieldElement, f_a: FieldElement, g_a: FieldElement, h_b: FieldElement, f_b: FieldElement, g_b: FieldElement): void {
        // Load all 10 limbs of each `f`
-       const f_a_0123: v128 = v128.load(changetype<usize>(f_a), 0 << 4)
-       const f_a_4567: v128 = v128.load(changetype<usize>(f_a), 1 << 4)
-       const f_a_89xx: v128 = v128.load64_zero(changetype<usize>(f_a), 2 << 4)
+       const f_a_ptr: usize = changetype<usize>(f_a)
+       const f_a_0123: v128 = v128.load(f_a_ptr, 0 << 4)
+       const f_a_4567: v128 = v128.load(f_a_ptr, 1 << 4)
+       const f_a_89xx: v128 = v128.load64_zero(f_a_ptr, 2 << 4)
 
-       const f_b_0123: v128 = v128.load(changetype<usize>(f_b), 0 << 4)
-       const f_b_4567: v128 = v128.load(changetype<usize>(f_b), 1 << 4)
-       const f_b_89xx: v128 = v128.load64_zero(changetype<usize>(f_b), 2 << 4)
+       const f_b_ptr: usize = changetype<usize>(f_b)
+       const f_b_0123: v128 = v128.load(f_b_ptr, 0 << 4)
+       const f_b_4567: v128 = v128.load(f_b_ptr, 1 << 4)
+       const f_b_89xx: v128 = v128.load64_zero(f_b_ptr, 2 << 4)
 
        // Blend each `f` index in alternating lanes
        const f01: v128 = v128.shuffle<i32>(f_a_0123, f_b_0123, 0, 4, 1, 5)
@@ -939,13 +987,15 @@ export function fe_mul2_dual (h_a: FieldElement, f_a: FieldElement, g_a: FieldEl
        const f9: v128 = v128.shuffle<i32>(f9_1, f9_2, 0, 1, 4, 5)
 
        // Load all 10 limbs of each `g`
-       const g_a_0123: v128 = v128.load(changetype<usize>(g_a), 0 << 4)
-       const g_a_4567: v128 = v128.load(changetype<usize>(g_a), 1 << 4)
-       const g_a_89xx: v128 = v128.load64_zero(changetype<usize>(g_a), 2 << 4)
+       const g_a_ptr: usize = changetype<usize>(g_a)
+       const g_a_0123: v128 = v128.load(g_a_ptr, 0 << 4)
+       const g_a_4567: v128 = v128.load(g_a_ptr, 1 << 4)
+       const g_a_89xx: v128 = v128.load64_zero(g_a_ptr, 2 << 4)
 
-       const g_b_0123: v128 = v128.load(changetype<usize>(g_b), 0 << 4)
-       const g_b_4567: v128 = v128.load(changetype<usize>(g_b), 1 << 4)
-       const g_b_89xx: v128 = v128.load64_zero(changetype<usize>(g_b), 2 << 4)
+       const g_b_ptr: usize = changetype<usize>(g_b)
+       const g_b_0123: v128 = v128.load(g_b_ptr, 0 << 4)
+       const g_b_4567: v128 = v128.load(g_b_ptr, 1 << 4)
+       const g_b_89xx: v128 = v128.load64_zero(g_b_ptr, 2 << 4)
 
        // Blend each `g` index in alternating lanes
        const g01: v128 = v128.shuffle<i32>(g_a_0123, g_b_0123, 0, 4, 1, 5)
@@ -1172,13 +1222,15 @@ export function fe_mul2_dual (h_a: FieldElement, f_a: FieldElement, g_a: FieldEl
        const h89: v128 = v128.shuffle<i32>(h8, h9, 0, 2, 4, 6) // h8a, h8b, h9a, h9b
 
        // assign results to parallel outputs
-       v128.store(changetype<usize>(h_a), v128.shuffle<i32>(h01, h23, 0, 2, 4, 6), 0 << 4)
-       v128.store(changetype<usize>(h_a), v128.shuffle<i32>(h45, h67, 0, 2, 4, 6), 1 << 4)
-       v128.store_lane<i64>(changetype<usize>(h_a), v128.shuffle<i32>(h89, h89, 0, 2, 4, 6), 0, 2 << 4)
-
-       v128.store(changetype<usize>(h_b), v128.shuffle<i32>(h01, h23, 1, 3, 5, 7), 0 << 4)
-       v128.store(changetype<usize>(h_b), v128.shuffle<i32>(h45, h67, 1, 3, 5, 7), 1 << 4)
-       v128.store_lane<i64>(changetype<usize>(h_b), v128.shuffle<i32>(h89, h89, 1, 3, 5, 7), 0, 2 << 4)
+       const h_a_ptr: usize = changetype<usize>(h_a)
+       v128.store(h_a_ptr, v128.shuffle<i32>(h01, h23, 0, 2, 4, 6), 0 << 4)
+       v128.store(h_a_ptr, v128.shuffle<i32>(h45, h67, 0, 2, 4, 6), 1 << 4)
+       v128.store_lane<i64>(h_a_ptr, v128.shuffle<i32>(h89, h89, 0, 2, 4, 6), 0, 2 << 4)
+
+       const h_b_ptr: usize = changetype<usize>(h_b)
+       v128.store(h_b_ptr, v128.shuffle<i32>(h01, h23, 1, 3, 5, 7), 0 << 4)
+       v128.store(h_b_ptr, v128.shuffle<i32>(h45, h67, 1, 3, 5, 7), 1 << 4)
+       v128.store_lane<i64>(h_b_ptr, v128.shuffle<i32>(h89, h89, 1, 3, 5, 7), 0, 2 << 4)
 }
 
 /**
@@ -1188,13 +1240,15 @@ export function fe_mul2_dual (h_a: FieldElement, f_a: FieldElement, g_a: FieldEl
  * @param {FieldElement} f operand source
  */
 export function fe_neg (h: FieldElement, f: FieldElement): void {
-       const f0 = v128.load(changetype<usize>(f), 0 << 4)
-       const f1 = v128.load(changetype<usize>(f), 1 << 4)
-       const f2 = v128.load64_zero(changetype<usize>(f), 2 << 4)
+       const f_ptr: usize = changetype<usize>(f)
+       const f0 = v128.load(f_ptr, 0 << 4)
+       const f1 = v128.load(f_ptr, 1 << 4)
+       const f2 = v128.load64_zero(f_ptr, 2 << 4)
 
-       v128.store(changetype<usize>(h), v128.neg<i32>(f0), 0 << 4)
-       v128.store(changetype<usize>(h), v128.neg<i32>(f1), 1 << 4)
-       v128.store_lane<i64>(changetype<usize>(h), v128.neg<i32>(f2), 0, 2 << 4)
+       const h_ptr: usize = changetype<usize>(h)
+       v128.store(h_ptr, v128.neg<i32>(f0), 0 << 4)
+       v128.store(h_ptr, v128.neg<i32>(f1), 1 << 4)
+       v128.store_lane<i64>(h_ptr, v128.neg<i32>(f2), 0, 2 << 4)
 }
 
 /**
@@ -1376,16 +1430,17 @@ export function fe_reduce (h: FieldElement, f: FieldElement): void {
  * @param f FieldElement base source
  */
 export function fe_sq (h: FieldElement, f: FieldElement): void {
-       const f0: i64 = i64(load<i32>(changetype<usize>(f), 0 << 2))
-       const f1: i64 = i64(load<i32>(changetype<usize>(f), 1 << 2))
-       const f2: i64 = i64(load<i32>(changetype<usize>(f), 2 << 2))
-       const f3: i64 = i64(load<i32>(changetype<usize>(f), 3 << 2))
-       const f4: i64 = i64(load<i32>(changetype<usize>(f), 4 << 2))
-       const f5: i64 = i64(load<i32>(changetype<usize>(f), 5 << 2))
-       const f6: i64 = i64(load<i32>(changetype<usize>(f), 6 << 2))
-       const f7: i64 = i64(load<i32>(changetype<usize>(f), 7 << 2))
-       const f8: i64 = i64(load<i32>(changetype<usize>(f), 8 << 2))
-       const f9: i64 = i64(load<i32>(changetype<usize>(f), 9 << 2))
+       const f_ptr: usize = changetype<usize>(f)
+       const f0: i64 = i64(load<i32>(f_ptr, 0 << 2))
+       const f1: i64 = i64(load<i32>(f_ptr, 1 << 2))
+       const f2: i64 = i64(load<i32>(f_ptr, 2 << 2))
+       const f3: i64 = i64(load<i32>(f_ptr, 3 << 2))
+       const f4: i64 = i64(load<i32>(f_ptr, 4 << 2))
+       const f5: i64 = i64(load<i32>(f_ptr, 5 << 2))
+       const f6: i64 = i64(load<i32>(f_ptr, 6 << 2))
+       const f7: i64 = i64(load<i32>(f_ptr, 7 << 2))
+       const f8: i64 = i64(load<i32>(f_ptr, 8 << 2))
+       const f9: i64 = i64(load<i32>(f_ptr, 9 << 2))
 
        const f0_2: i64 = f0 + f0
        const f1_2: i64 = f1 + f1
@@ -1546,16 +1601,17 @@ export function fe_sq (h: FieldElement, f: FieldElement): void {
        h0 -= c & m26
        h1 += carry0
 
-       store<i32>(changetype<usize>(h), h0, 0)
-       store<i32>(changetype<usize>(h), h1, 4)
-       store<i32>(changetype<usize>(h), h2, 8)
-       store<i32>(changetype<usize>(h), h3, 12)
-       store<i32>(changetype<usize>(h), h4, 16)
-       store<i32>(changetype<usize>(h), h5, 20)
-       store<i32>(changetype<usize>(h), h6, 24)
-       store<i32>(changetype<usize>(h), h7, 28)
-       store<i32>(changetype<usize>(h), h8, 32)
-       store<i32>(changetype<usize>(h), h9, 36)
+       const h_ptr: usize = changetype<usize>(h)
+       store<i32>(h_ptr, h0, 0)
+       store<i32>(h_ptr, h1, 4)
+       store<i32>(h_ptr, h2, 8)
+       store<i32>(h_ptr, h3, 12)
+       store<i32>(h_ptr, h4, 16)
+       store<i32>(h_ptr, h5, 20)
+       store<i32>(h_ptr, h6, 24)
+       store<i32>(h_ptr, h7, 28)
+       store<i32>(h_ptr, h8, 32)
+       store<i32>(h_ptr, h9, 36)
 }
 
 /**
@@ -1592,13 +1648,15 @@ export function fe_sq (h: FieldElement, f: FieldElement): void {
  */
 export function fe_sq_dual (h_a: FieldElement, f_a: FieldElement, h_b: FieldElement, f_b: FieldElement): void {
        // Load all 10 limbs of each `f`
-       const f_a_0123: v128 = v128.load(changetype<usize>(f_a), 0 << 4)
-       const f_a_4567: v128 = v128.load(changetype<usize>(f_a), 1 << 4)
-       const f_a_89xx: v128 = v128.load64_zero(changetype<usize>(f_a), 2 << 4)
+       const f_a_ptr: usize = changetype<usize>(f_a)
+       const f_a_0123: v128 = v128.load(f_a_ptr, 0 << 4)
+       const f_a_4567: v128 = v128.load(f_a_ptr, 1 << 4)
+       const f_a_89xx: v128 = v128.load64_zero(f_a_ptr, 2 << 4)
 
-       const f_b_0123: v128 = v128.load(changetype<usize>(f_b), 0 << 4)
-       const f_b_4567: v128 = v128.load(changetype<usize>(f_b), 1 << 4)
-       const f_b_89xx: v128 = v128.load64_zero(changetype<usize>(f_b), 2 << 4)
+       const f_b_ptr: usize = changetype<usize>(f_b)
+       const f_b_0123: v128 = v128.load(f_b_ptr, 0 << 4)
+       const f_b_4567: v128 = v128.load(f_b_ptr, 1 << 4)
+       const f_b_89xx: v128 = v128.load64_zero(f_b_ptr, 2 << 4)
 
        // Blend each `f` index in alternating lanes
        const f01: v128 = v128.shuffle<i32>(f_a_0123, f_b_0123, 0, 4, 1, 5)
@@ -1783,13 +1841,15 @@ export function fe_sq_dual (h_a: FieldElement, f_a: FieldElement, h_b: FieldElem
        const h89: v128 = v128.shuffle<i32>(h8, h9, 0, 2, 4, 6) // h8a, h8b, h9a, h9b
 
        // assign results to parallel outputs
-       v128.store(changetype<usize>(h_a), v128.shuffle<i32>(h01, h23, 0, 2, 4, 6), 0 << 4)
-       v128.store(changetype<usize>(h_a), v128.shuffle<i32>(h45, h67, 0, 2, 4, 6), 1 << 4)
-       v128.store_lane<i64>(changetype<usize>(h_a), v128.shuffle<i32>(h89, h89, 0, 2, 4, 6), 0, 2 << 4)
-
-       v128.store(changetype<usize>(h_b), v128.shuffle<i32>(h01, h23, 1, 3, 5, 7), 0 << 4)
-       v128.store(changetype<usize>(h_b), v128.shuffle<i32>(h45, h67, 1, 3, 5, 7), 1 << 4)
-       v128.store_lane<i64>(changetype<usize>(h_b), v128.shuffle<i32>(h89, h89, 1, 3, 5, 7), 0, 2 << 4)
+       const h_a_ptr: usize = changetype<usize>(h_a)
+       v128.store(h_a_ptr, v128.shuffle<i32>(h01, h23, 0, 2, 4, 6), 0 << 4)
+       v128.store(h_a_ptr, v128.shuffle<i32>(h45, h67, 0, 2, 4, 6), 1 << 4)
+       v128.store_lane<i64>(h_a_ptr, v128.shuffle<i32>(h89, h89, 0, 2, 4, 6), 0, 2 << 4)
+
+       const h_b_ptr: usize = changetype<usize>(h_b)
+       v128.store(h_b_ptr, v128.shuffle<i32>(h01, h23, 1, 3, 5, 7), 0 << 4)
+       v128.store(h_b_ptr, v128.shuffle<i32>(h45, h67, 1, 3, 5, 7), 1 << 4)
+       v128.store_lane<i64>(h_b_ptr, v128.shuffle<i32>(h89, h89, 1, 3, 5, 7), 0, 2 << 4)
 }
 
 /**
@@ -1813,13 +1873,15 @@ export function fe_sq_dual (h_a: FieldElement, f_a: FieldElement, h_b: FieldElem
  */
 export function fe_sq2_dual (h_a: FieldElement, f_a: FieldElement, h_b: FieldElement, f_b: FieldElement): void {
        // Load all 10 limbs of each `f`
-       const f_a_0123: v128 = v128.load(changetype<usize>(f_a), 0 << 4)
-       const f_a_4567: v128 = v128.load(changetype<usize>(f_a), 1 << 4)
-       const f_a_89xx: v128 = v128.load64_zero(changetype<usize>(f_a), 2 << 4)
+       const f_a_ptr: usize = changetype<usize>(f_a)
+       const f_a_0123: v128 = v128.load(f_a_ptr, 0 << 4)
+       const f_a_4567: v128 = v128.load(f_a_ptr, 1 << 4)
+       const f_a_89xx: v128 = v128.load64_zero(f_a_ptr, 2 << 4)
 
-       const f_b_0123: v128 = v128.load(changetype<usize>(f_b), 0 << 4)
-       const f_b_4567: v128 = v128.load(changetype<usize>(f_b), 1 << 4)
-       const f_b_89xx: v128 = v128.load64_zero(changetype<usize>(f_b), 2 << 4)
+       const f_b_ptr: usize = changetype<usize>(f_b)
+       const f_b_0123: v128 = v128.load(f_b_ptr, 0 << 4)
+       const f_b_4567: v128 = v128.load(f_b_ptr, 1 << 4)
+       const f_b_89xx: v128 = v128.load64_zero(f_b_ptr, 2 << 4)
 
        // Blend each `f` index in alternating lanes
        const f01: v128 = v128.shuffle<i32>(f_a_0123, f_b_0123, 0, 4, 1, 5)
@@ -2017,13 +2079,15 @@ export function fe_sq2_dual (h_a: FieldElement, f_a: FieldElement, h_b: FieldEle
        const h89: v128 = v128.shuffle<i32>(h8, h9, 0, 2, 4, 6) // h8a, h8b, h9a, h9b
 
        // assign results to parallel outputs
-       v128.store(changetype<usize>(h_a), v128.shuffle<i32>(h01, h23, 0, 2, 4, 6), 0 << 4)
-       v128.store(changetype<usize>(h_a), v128.shuffle<i32>(h45, h67, 0, 2, 4, 6), 1 << 4)
-       v128.store_lane<i64>(changetype<usize>(h_a), v128.shuffle<i32>(h89, h89, 0, 2, 4, 6), 0, 2 << 4)
-
-       v128.store(changetype<usize>(h_b), v128.shuffle<i32>(h01, h23, 1, 3, 5, 7), 0 << 4)
-       v128.store(changetype<usize>(h_b), v128.shuffle<i32>(h45, h67, 1, 3, 5, 7), 1 << 4)
-       v128.store_lane<i64>(changetype<usize>(h_b), v128.shuffle<i32>(h89, h89, 1, 3, 5, 7), 0, 2 << 4)
+       const h_a_ptr: usize = changetype<usize>(h_a)
+       v128.store(h_a_ptr, v128.shuffle<i32>(h01, h23, 0, 2, 4, 6), 0 << 4)
+       v128.store(h_a_ptr, v128.shuffle<i32>(h45, h67, 0, 2, 4, 6), 1 << 4)
+       v128.store_lane<i64>(h_a_ptr, v128.shuffle<i32>(h89, h89, 0, 2, 4, 6), 0, 2 << 4)
+
+       const h_b_ptr: usize = changetype<usize>(h_b)
+       v128.store(h_b_ptr, v128.shuffle<i32>(h01, h23, 1, 3, 5, 7), 0 << 4)
+       v128.store(h_b_ptr, v128.shuffle<i32>(h45, h67, 1, 3, 5, 7), 1 << 4)
+       v128.store_lane<i64>(h_b_ptr, v128.shuffle<i32>(h89, h89, 1, 3, 5, 7), 0, 2 << 4)
 }
 
 /**
@@ -2034,17 +2098,20 @@ export function fe_sq2_dual (h_a: FieldElement, f_a: FieldElement, h_b: FieldEle
  * @param g FieldElement subtrahend source
  */
 export function fe_sub (h: FieldElement, f: FieldElement, g: FieldElement): void {
-       const f0 = v128.load(changetype<usize>(f), 0 << 4)
-       const f1 = v128.load(changetype<usize>(f), 1 << 4)
-       const f2 = v128.load64_zero(changetype<usize>(f), 2 << 4)
+       const f_ptr: usize = changetype<usize>(f)
+       const f0 = v128.load(f_ptr, 0 << 4)
+       const f1 = v128.load(f_ptr, 1 << 4)
+       const f2 = v128.load64_zero(f_ptr, 2 << 4)
 
-       const g0 = v128.load(changetype<usize>(g), 0 << 4)
-       const g1 = v128.load(changetype<usize>(g), 1 << 4)
-       const g2 = v128.load64_zero(changetype<usize>(g), 2 << 4)
+       const g_ptr: usize = changetype<usize>(g)
+       const g0 = v128.load(g_ptr, 0 << 4)
+       const g1 = v128.load(g_ptr, 1 << 4)
+       const g2 = v128.load64_zero(g_ptr, 2 << 4)
 
-       v128.store(changetype<usize>(h), v128.sub<i32>(f0, g0), 0 << 4)
-       v128.store(changetype<usize>(h), v128.sub<i32>(f1, g1), 1 << 4)
-       v128.store_lane<i64>(changetype<usize>(h), v128.sub<i32>(f2, g2), 0, 2 << 4)
+       const h_ptr: usize = changetype<usize>(h)
+       v128.store(h_ptr, v128.sub<i32>(f0, g0), 0 << 4)
+       v128.store(h_ptr, v128.sub<i32>(f1, g1), 1 << 4)
+       v128.store_lane<i64>(h_ptr, v128.sub<i32>(f2, g2), 0, 2 << 4)
 }
 
 /**
@@ -2056,47 +2123,50 @@ export function fe_sub (h: FieldElement, f: FieldElement, g: FieldElement): void
  */
 export function fe_tobytes (s: StaticArray<u8>, h: FieldElement, t_fe: FieldElement): void {
        fe_reduce(t_fe, h)
-       const t0 = load<i32>(changetype<usize>(t_fe), 0 << 2)
-       const t1 = load<i32>(changetype<usize>(t_fe), 1 << 2)
-       const t2 = load<i32>(changetype<usize>(t_fe), 2 << 2)
-       const t3 = load<i32>(changetype<usize>(t_fe), 3 << 2)
-       const t4 = load<i32>(changetype<usize>(t_fe), 4 << 2)
-       const t5 = load<i32>(changetype<usize>(t_fe), 5 << 2)
-       const t6 = load<i32>(changetype<usize>(t_fe), 6 << 2)
-       const t7 = load<i32>(changetype<usize>(t_fe), 7 << 2)
-       const t8 = load<i32>(changetype<usize>(t_fe), 8 << 2)
-       const t9 = load<i32>(changetype<usize>(t_fe), 9 << 2)
-
-       store<u8>(changetype<usize>(s), t0 >> 0, 0)
-       store<u8>(changetype<usize>(s), t0 >> 8, 1)
-       store<u8>(changetype<usize>(s), t0 >> 16, 2)
-       store<u8>(changetype<usize>(s), (t0 >> 24) | (t1 << 2), 3)
-       store<u8>(changetype<usize>(s), t1 >> 6, 4)
-       store<u8>(changetype<usize>(s), t1 >> 14, 5)
-       store<u8>(changetype<usize>(s), (t1 >> 22) | (t2 << 3), 6)
-       store<u8>(changetype<usize>(s), t2 >> 5, 7)
-       store<u8>(changetype<usize>(s), t2 >> 13, 8)
-       store<u8>(changetype<usize>(s), (t2 >> 21) | (t3 << 5), 9)
-       store<u8>(changetype<usize>(s), t3 >> 3, 10)
-       store<u8>(changetype<usize>(s), t3 >> 11, 11)
-       store<u8>(changetype<usize>(s), (t3 >> 19) | (t4 << 6), 12)
-       store<u8>(changetype<usize>(s), t4 >> 2, 13)
-       store<u8>(changetype<usize>(s), t4 >> 10, 14)
-       store<u8>(changetype<usize>(s), t4 >> 18, 15)
-       store<u8>(changetype<usize>(s), t5 >> 0, 16)
-       store<u8>(changetype<usize>(s), t5 >> 8, 17)
-       store<u8>(changetype<usize>(s), t5 >> 16, 18)
-       store<u8>(changetype<usize>(s), (t5 >> 24) | (t6 << 1), 19)
-       store<u8>(changetype<usize>(s), t6 >> 7, 20)
-       store<u8>(changetype<usize>(s), t6 >> 15, 21)
-       store<u8>(changetype<usize>(s), (t6 >> 23) | (t7 << 3), 22)
-       store<u8>(changetype<usize>(s), t7 >> 5, 23)
-       store<u8>(changetype<usize>(s), t7 >> 13, 24)
-       store<u8>(changetype<usize>(s), (t7 >> 21) | (t8 << 4), 25)
-       store<u8>(changetype<usize>(s), t8 >> 4, 26)
-       store<u8>(changetype<usize>(s), t8 >> 12, 27)
-       store<u8>(changetype<usize>(s), (t8 >> 20) | (t9 << 6), 28)
-       store<u8>(changetype<usize>(s), t9 >> 2, 29)
-       store<u8>(changetype<usize>(s), t9 >> 10, 30)
-       store<u8>(changetype<usize>(s), t9 >> 18, 31)
+
+       const t_ptr: usize = changetype<usize>(t_fe)
+       const t0 = load<i32>(t_ptr, 0 << 2)
+       const t1 = load<i32>(t_ptr, 1 << 2)
+       const t2 = load<i32>(t_ptr, 2 << 2)
+       const t3 = load<i32>(t_ptr, 3 << 2)
+       const t4 = load<i32>(t_ptr, 4 << 2)
+       const t5 = load<i32>(t_ptr, 5 << 2)
+       const t6 = load<i32>(t_ptr, 6 << 2)
+       const t7 = load<i32>(t_ptr, 7 << 2)
+       const t8 = load<i32>(t_ptr, 8 << 2)
+       const t9 = load<i32>(t_ptr, 9 << 2)
+
+       const s_ptr: usize = changetype<usize>(s)
+       store<u8>(s_ptr, t0 >> 0, 0)
+       store<u8>(s_ptr, t0 >> 8, 1)
+       store<u8>(s_ptr, t0 >> 16, 2)
+       store<u8>(s_ptr, (t0 >> 24) | (t1 << 2), 3)
+       store<u8>(s_ptr, t1 >> 6, 4)
+       store<u8>(s_ptr, t1 >> 14, 5)
+       store<u8>(s_ptr, (t1 >> 22) | (t2 << 3), 6)
+       store<u8>(s_ptr, t2 >> 5, 7)
+       store<u8>(s_ptr, t2 >> 13, 8)
+       store<u8>(s_ptr, (t2 >> 21) | (t3 << 5), 9)
+       store<u8>(s_ptr, t3 >> 3, 10)
+       store<u8>(s_ptr, t3 >> 11, 11)
+       store<u8>(s_ptr, (t3 >> 19) | (t4 << 6), 12)
+       store<u8>(s_ptr, t4 >> 2, 13)
+       store<u8>(s_ptr, t4 >> 10, 14)
+       store<u8>(s_ptr, t4 >> 18, 15)
+       store<u8>(s_ptr, t5 >> 0, 16)
+       store<u8>(s_ptr, t5 >> 8, 17)
+       store<u8>(s_ptr, t5 >> 16, 18)
+       store<u8>(s_ptr, (t5 >> 24) | (t6 << 1), 19)
+       store<u8>(s_ptr, t6 >> 7, 20)
+       store<u8>(s_ptr, t6 >> 15, 21)
+       store<u8>(s_ptr, (t6 >> 23) | (t7 << 3), 22)
+       store<u8>(s_ptr, t7 >> 5, 23)
+       store<u8>(s_ptr, t7 >> 13, 24)
+       store<u8>(s_ptr, (t7 >> 21) | (t8 << 4), 25)
+       store<u8>(s_ptr, t8 >> 4, 26)
+       store<u8>(s_ptr, t8 >> 12, 27)
+       store<u8>(s_ptr, (t8 >> 20) | (t9 << 6), 28)
+       store<u8>(s_ptr, t9 >> 2, 29)
+       store<u8>(s_ptr, t9 >> 10, 30)
+       store<u8>(s_ptr, t9 >> 18, 31)
 }