* @param g FieldElement multiplicand source
*/
export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void {
- // mask to select (v1, v0, v1, v0)
- const m: v128 = i32x4(-1, 0, -1, 0)
-
- const f0: v128 = v128.load_splat<i32>(changetype<usize>(f), 0 << 2)
- let f1: v128 = v128.load_splat<i32>(changetype<usize>(f), 1 << 2)
- const f2: v128 = v128.load_splat<i32>(changetype<usize>(f), 2 << 2)
- let f3: v128 = v128.load_splat<i32>(changetype<usize>(f), 3 << 2)
- const f4: v128 = v128.load_splat<i32>(changetype<usize>(f), 4 << 2)
- let f5: v128 = v128.load_splat<i32>(changetype<usize>(f), 5 << 2)
- const f6: v128 = v128.load_splat<i32>(changetype<usize>(f), 6 << 2)
- let f7: v128 = v128.load_splat<i32>(changetype<usize>(f), 7 << 2)
- const f8: v128 = v128.load_splat<i32>(changetype<usize>(f), 8 << 2)
- let f9: v128 = v128.load_splat<i32>(changetype<usize>(f), 9 << 2)
+ 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 f0123_2: v128 = v128.add<i32>(f0123, f0123)
+ const f4567_2: v128 = v128.add<i32>(f4567, f4567)
+ const f89xx_2: v128 = v128.add<i32>(f89xx, f89xx)
+
+ const f0: v128 = v128.shuffle<i32>(f0123, f0123, 0, 0, 0, 0)
+ const f1: v128 = v128.shuffle<i32>(f0123_2, f0123, 1, 5, 1, 5)
+ const f2: v128 = v128.shuffle<i32>(f0123, f0123, 2, 2, 2, 2)
+ const f3: v128 = v128.shuffle<i32>(f0123_2, f0123, 3, 7, 3, 7)
+ const f4: v128 = v128.shuffle<i32>(f4567, f4567, 0, 0, 0, 0)
+ const f5: v128 = v128.shuffle<i32>(f4567_2, f4567, 1, 5, 1, 5)
+ const f6: v128 = v128.shuffle<i32>(f4567, f4567, 2, 2, 2, 2)
+ const f7: v128 = v128.shuffle<i32>(f4567_2, f4567, 3, 7, 3, 7)
+ const f8: v128 = v128.shuffle<i32>(f89xx, f89xx, 0, 0, 0, 0)
+ const f9: v128 = v128.shuffle<i32>(f89xx_2, f89xx, 1, 5, 1, 5)
const g0123: v128 = v128.load(changetype<usize>(g), 0 << 4)
const g4567: v128 = v128.load(changetype<usize>(g), 1 << 4)
const g78xx: v128 = v128.shuffle<i32>(g4567, g89xx, 3, 4, 6, 7)
// factor of 19 for wrap from h9 to h0
- const g0123_19: v128 = v128.add<i32>(g0123, v128.add<i32>(v128.shl<i32>(g0123, 1), v128.shl<i32>(g0123, 4)))
- const g4567_19: v128 = v128.add<i32>(g4567, v128.add<i32>(v128.shl<i32>(g4567, 1), v128.shl<i32>(g4567, 4)))
- const g89xx_19: v128 = v128.add<i32>(g89xx, v128.add<i32>(v128.shl<i32>(g89xx, 1), v128.shl<i32>(g89xx, 4)))
+ const g0123_19: v128 = v128.add<i32>(g0123, v128.add<i32>(v128.add<i32>(g0123, g0123), v128.shl<i32>(g0123, 4)))
+ const g4567_19: v128 = v128.add<i32>(g4567, v128.add<i32>(v128.add<i32>(g4567, g4567), v128.shl<i32>(g4567, 4)))
+ const g89xx_19: v128 = v128.add<i32>(g89xx, v128.add<i32>(v128.add<i32>(g89xx, g89xx), v128.shl<i32>(g89xx, 4)))
- const g9012_19: v128 = v128.bitselect(v128.add<i32>(g9012, v128.add<i32>(v128.shl<i32>(g9012, 1), v128.shl<i32>(g9012, 4))), g9012, i32x4(-1, 0, -1, -1))
- const g3456_19: v128 = v128.add<i32>(g3456, v128.add<i32>(v128.shl<i32>(g3456, 1), v128.shl<i32>(g3456, 4)))
- const g78xx_19: v128 = v128.add<i32>(g78xx, v128.add<i32>(v128.shl<i32>(g78xx, 1), v128.shl<i32>(g78xx, 4)))
+ const g9012_19: v128 = v128.bitselect(v128.add<i32>(g9012, v128.add<i32>(v128.add<i32>(g9012, g9012), v128.shl<i32>(g9012, 4))), g9012, i32x4(-1, 0, -1, -1))
+ const g3456_19: v128 = v128.add<i32>(g3456, v128.add<i32>(v128.add<i32>(g3456, g3456), v128.shl<i32>(g3456, 4)))
+ const g78xx_19: v128 = v128.add<i32>(g78xx, v128.add<i32>(v128.add<i32>(g78xx, g78xx), v128.shl<i32>(g78xx, 4)))
// f[0]
let h01: v128 = i64x2.extmul_low_i32x4_s(f0, g0123)
let h89: v128 = i64x2.extmul_low_i32x4_s(f0, g89xx)
// f[1]
- f1 = v128.add<i32>(f1, v128.and(f1, m))
-
let t0: v128 = i64x2.extmul_low_i32x4_s(f1, g9012_19)
let t1: v128 = i64x2.extmul_high_i32x4_s(f1, g9012)
let t2: v128 = i64x2.extmul_low_i32x4_s(f1, g3456)
h01 = i64x2.add(h01, t4)
// f[3]
- f3 = v128.add<i32>(f3, v128.and(f3, m))
-
t0 = i64x2.extmul_low_i32x4_s(f3, g9012_19)
t1 = i64x2.extmul_high_i32x4_s(f3, g9012)
t2 = i64x2.extmul_low_i32x4_s(f3, g3456)
h23 = i64x2.add(h23, t4)
// f[5]
- f5 = v128.add<i32>(f5, v128.and(f5, m))
-
t0 = i64x2.extmul_low_i32x4_s(f5, g9012_19)
t1 = i64x2.extmul_high_i32x4_s(f5, g9012)
t2 = i64x2.extmul_low_i32x4_s(f5, g3456)
h45 = i64x2.add(h45, t4)
// f[7]
- f7 = v128.add<i32>(f7, v128.and(f7, m))
-
t0 = i64x2.extmul_low_i32x4_s(f7, g9012_19)
t1 = i64x2.extmul_high_i32x4_s(f7, g9012)
t2 = i64x2.extmul_low_i32x4_s(f7, g3456_19)
h67 = i64x2.add(h67, t4)
// f[9]
- f9 = v128.add<i32>(f9, v128.and(f9, m))
-
t0 = i64x2.extmul_low_i32x4_s(f9, g9012_19)
t1 = i64x2.extmul_high_i32x4_s(f9, g9012_19)
t2 = i64x2.extmul_low_i32x4_s(f9, g3456_19)