]> git.codecow.com Git - nano25519.git/commitdiff
Eliminate a few extra ops.
authorChris Duncan <chris@codecow.com>
Wed, 21 Oct 2026 14:07:59 +0000 (07:07 -0700)
committerChris Duncan <chris@codecow.com>
Wed, 21 Oct 2026 14:07:59 +0000 (07:07 -0700)
src/assembly/ed25519/fe.ts

index d26bb606198535ce96644a788eb857195d78caa7..143123f23f744d1a00b0f5593063766fe075d544 100644 (file)
@@ -1205,16 +1205,12 @@ export function fe_sq_dual (h_a: FieldElement, f_a: FieldElement, h_b: FieldElem
        const f8_2: v128 = v128.shuffle<i32>(f89_2, f89_2, 0, 1, 0, 1)
        const f9_2: v128 = v128.shuffle<i32>(f89_2, f89_2, 2, 3, 6, 7)
 
-       // factor of 19 for wrap from h9 to h0
-       const f5_19: v128 = v128.add<i32>(f5, v128.add<i32>(f5_2, v128.shl<i32>(f5_2, 3)))
+       // factor of 19 for wrap from h9 to h0 with odds doubled
+       const f5_38: v128 = v128.add<i32>(f5_2, v128.add<i32>(v128.add<i32>(f5_2, f5_2), v128.shl<i32>(f5_2, 4)))
        const f6_19: v128 = v128.add<i32>(f6, v128.add<i32>(f6_2, v128.shl<i32>(f6_2, 3)))
-       const f7_19: v128 = v128.add<i32>(f7, v128.add<i32>(f7_2, v128.shl<i32>(f7_2, 3)))
+       const f7_38: v128 = v128.add<i32>(f7_2, v128.add<i32>(v128.add<i32>(f7_2, f7_2), v128.shl<i32>(f7_2, 4)))
        const f8_19: v128 = v128.add<i32>(f8, v128.add<i32>(f8_2, v128.shl<i32>(f8_2, 3)))
-       const f9_19: v128 = v128.add<i32>(f9, v128.add<i32>(f9_2, v128.shl<i32>(f9_2, 3)))
-
-       // doubled odd-on-odd factor of 19
-       const f7_38: v128 = v128.add<i32>(f7_19, f7_19)
-       const f9_38: v128 = v128.add<i32>(f9_19, f9_19)
+       const f9_38: v128 = v128.add<i32>(f9_2, v128.add<i32>(v128.add<i32>(f9_2, f9_2), v128.shl<i32>(f9_2, 4)))
 
        // f[0]
        let h0: v128 = v128.extmul_low<i32>(f0, f0)
@@ -1247,7 +1243,7 @@ export function fe_sq_dual (h_a: FieldElement, f_a: FieldElement, h_b: FieldElem
        h8 = v128.add<i64>(h8, v128.extmul_low<i32>(f2_2, f6))
        h9 = v128.add<i64>(h9, v128.extmul_low<i32>(f2_2, f7))
        h0 = v128.add<i64>(h0, v128.extmul_low<i32>(f2_2, f8_19))
-       h1 = v128.add<i64>(h1, v128.extmul_low<i32>(f2_2, f9_19))
+       h1 = v128.add<i64>(h1, v128.extmul_low<i32>(f2, f9_38))
 
        // f[3]
        h6 = v128.add<i64>(h6, v128.extmul_low<i32>(f3_2, f3))
@@ -1262,12 +1258,12 @@ export function fe_sq_dual (h_a: FieldElement, f_a: FieldElement, h_b: FieldElem
        h8 = v128.add<i64>(h8, v128.extmul_low<i32>(f4, f4))
        h9 = v128.add<i64>(h9, v128.extmul_low<i32>(f4_2, f5))
        h0 = v128.add<i64>(h0, v128.extmul_low<i32>(f4_2, f6_19))
-       h1 = v128.add<i64>(h1, v128.extmul_low<i32>(f4_2, f7_19))
+       h1 = v128.add<i64>(h1, v128.extmul_low<i32>(f4, f7_38))
        h2 = v128.add<i64>(h2, v128.extmul_low<i32>(f4_2, f8_19))
-       h3 = v128.add<i64>(h3, v128.extmul_low<i32>(f4_2, f9_19))
+       h3 = v128.add<i64>(h3, v128.extmul_low<i32>(f4, f9_38))
 
        // f[5]
-       h0 = v128.add<i64>(h0, v128.extmul_low<i32>(f5_2, f5_19))
+       h0 = v128.add<i64>(h0, v128.extmul_low<i32>(f5, f5_38))
        h1 = v128.add<i64>(h1, v128.extmul_low<i32>(f5_2, f6_19))
        h2 = v128.add<i64>(h2, v128.extmul_low<i32>(f5_2, f7_38))
        h3 = v128.add<i64>(h3, v128.extmul_low<i32>(f5_2, f8_19))
@@ -1275,21 +1271,21 @@ export function fe_sq_dual (h_a: FieldElement, f_a: FieldElement, h_b: FieldElem
 
        // f[6]
        h2 = v128.add<i64>(h2, v128.extmul_low<i32>(f6, f6_19))
-       h3 = v128.add<i64>(h3, v128.extmul_low<i32>(f6_2, f7_19))
+       h3 = v128.add<i64>(h3, v128.extmul_low<i32>(f6, f7_38))
        h4 = v128.add<i64>(h4, v128.extmul_low<i32>(f6_2, f8_19))
-       h5 = v128.add<i64>(h5, v128.extmul_low<i32>(f6_2, f9_19))
+       h5 = v128.add<i64>(h5, v128.extmul_low<i32>(f6, f9_38))
 
        // f[7]
-       h4 = v128.add<i64>(h4, v128.extmul_low<i32>(f7_2, f7_19))
+       h4 = v128.add<i64>(h4, v128.extmul_low<i32>(f7, f7_38))
        h5 = v128.add<i64>(h5, v128.extmul_low<i32>(f7_2, f8_19))
        h6 = v128.add<i64>(h6, v128.extmul_low<i32>(f7_2, f9_38))
 
        // f[8]
        h6 = v128.add<i64>(h6, v128.extmul_low<i32>(f8, f8_19))
-       h7 = v128.add<i64>(h7, v128.extmul_low<i32>(f8_2, f9_19))
+       h7 = v128.add<i64>(h7, v128.extmul_low<i32>(f8, f9_38))
 
        // f[9]
-       h8 = v128.add<i64>(h8, v128.extmul_low<i32>(f9_2, f9_19))
+       h8 = v128.add<i64>(h8, v128.extmul_low<i32>(f9, f9_38))
 
        // reduce scalars with carry
        let carry0: v128