]> git.codecow.com Git - nano25519.git/commitdiff
Add paired lane swap.
authorChris Duncan <chris@codecow.com>
Fri, 23 Oct 2026 19:36:43 +0000 (12:36 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 23 Oct 2026 19:36:43 +0000 (12:36 -0700)
src/assembly/ed25519/fep.ts

index 02dc1f155c74061d0eaa04ad1675a86cdc7624d6..eaa23b2dae89c53cadc768e9589bb32a7a20363a 100644 (file)
@@ -38,7 +38,27 @@ export function fep_pack (f: FieldElementPair, f_a: FieldElement, f_b: FieldElem
        }
 }
 
-export function fep_unpack (f_a: FieldElementPair, f_b: FieldElement, f: FieldElementPair): void {
+export function fep_swap (h: FieldElementPair, f: FieldElementPair): void {
+       const f0 = v128.load(changetype<usize>(f), 0 << 4)
+       const f1 = v128.load(changetype<usize>(f), 1 << 4)
+       const f2 = v128.load(changetype<usize>(f), 2 << 4)
+       const f3 = v128.load(changetype<usize>(f), 3 << 4)
+       const f4 = v128.load(changetype<usize>(f), 4 << 4)
+
+       const h0 = v128.shuffle<i32>(f0, f0, 1, 0, 3, 2)
+       const h1 = v128.shuffle<i32>(f1, f1, 1, 0, 3, 2)
+       const h2 = v128.shuffle<i32>(f2, f2, 1, 0, 3, 2)
+       const h3 = v128.shuffle<i32>(f3, f3, 1, 0, 3, 2)
+       const h4 = v128.shuffle<i32>(f4, f4, 1, 0, 3, 2)
+
+       v128.store(changetype<usize>(h), h0, 0 << 4)
+       v128.store(changetype<usize>(h), h1, 1 << 4)
+       v128.store(changetype<usize>(h), h2, 2 << 4)
+       v128.store(changetype<usize>(h), h3, 3 << 4)
+       v128.store(changetype<usize>(h), h4, 4 << 4)
+}
+
+export function fep_unpack (f_a: FieldElement, f_b: FieldElement, f: FieldElementPair): void {
        for (let i = 0, j = 0; i < 10; i++, j += 2) {
                f_a[i] = f[j]
                f_b[i] = f[j + 1]