]> git.codecow.com Git - nano25519.git/commitdiff
Cut module size by 10% by letting compiler decide which hot paths to inline.
authorChris Duncan <chris@zoso.dev>
Fri, 2 Oct 2026 08:16:07 +0000 (01:16 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 2 Oct 2026 08:16:07 +0000 (01:16 -0700)
src/assembly/ed25519/fe.ts
src/assembly/ed25519/ge.ts
src/assembly/ed25519/p.ts
src/assembly/ed25519/utils.ts

index a1f30ee041af9dea97ffa99d89972107e15541d0..adbd8028d90beb0d0f4622c7f2f81863860a49de 100644 (file)
@@ -37,8 +37,6 @@ export function fe (): FieldElement {
  *
  * @param h FieldElement destination
  */
-//@ts-expect-error
-@inline
 export function fe_0 (h: FieldElement): void {
        memory.fill(changetype<usize>(h), 0, 48)
 }
@@ -48,8 +46,6 @@ export function fe_0 (h: FieldElement): void {
  *
  * @param h FieldElement destination
  */
-//@ts-expect-error
-@inline
 export function fe_1 (h: FieldElement): void {
        fe_0(h)
        h[0] = 1
@@ -62,8 +58,6 @@ export function fe_1 (h: FieldElement): void {
  * @param f FieldElement summand source
  * @param g FieldElement summand source
  */
-//@ts-expect-error
-@inline
 export function fe_add (h: FieldElement, f: FieldElement, g: FieldElement): void {
        const h_ptr = changetype<usize>(h)
        const f_ptr = changetype<usize>(f)
@@ -80,8 +74,6 @@ export function fe_add (h: FieldElement, f: FieldElement, g: FieldElement): void
  * @param {FieldElement} g source
  * @param {u64} b Copy `g` into `f` if 1, copy `f` into `f` if 0
  */
-//@ts-expect-error
-@inline
 export function fe_cmov (f: FieldElement, g: FieldElement, b: u64): void {
        const f_ptr = changetype<usize>(f)
        const g_ptr = changetype<usize>(g)
@@ -97,8 +89,6 @@ export function fe_cmov (f: FieldElement, g: FieldElement, b: u64): void {
  * @param {FieldElement} h destination
  * @param {FieldElement} f source
  */
-//@ts-expect-error
-@inline
 export function fe_copy (h: FieldElement, f: FieldElement): void {
        memory.copy(changetype<usize>(h), changetype<usize>(f), 40)
 }
@@ -109,8 +99,6 @@ export function fe_copy (h: FieldElement, f: FieldElement): void {
  * @param h FieldElement sum destination
  * @param f FieldElement summand source
  */
-//@ts-expect-error
-@inline
 export function fe_dbl (h: FieldElement, f: FieldElement): void {
        const h_ptr = changetype<usize>(h)
        const f_ptr = changetype<usize>(f)
@@ -252,8 +240,6 @@ const fe_isnegative_t = fe()
  * Preconditions:
  * |f| bounded by 1.1x2²⁶,1.1x2²⁵,1.1x2²⁶,1.1x2²⁵,etc.
  */
-//@ts-expect-error
-@inline
 export function fe_isnegative (f: FieldElement): u8 {
        const t = fe_isnegative_t
        fe_reduce(t, f)
@@ -268,8 +254,6 @@ const fe_iszero_s = new StaticArray<u8>(32)
  * Preconditions:
  * |f| bounded by 1.1x2²⁶,1.1x2²⁵,1.1x2²⁶,1.1x2²⁵,etc.
  */
-//@ts-expect-error
-@inline
 export function fe_iszero (f: FieldElement): u8 {
        const s = fe_iszero_s
        fe_tobytes(s, f)
@@ -512,8 +496,6 @@ export function fe_mul (h: FieldElement, f: FieldElement, g: FieldElement): void
  * @param {FieldElement} h result destination
  * @param {FieldElement} f operand source
  */
-//@ts-expect-error
-@inline
 export function fe_neg (h: FieldElement, f: FieldElement): void {
        const h_ptr = changetype<usize>(h)
        const f_ptr = changetype<usize>(f)
@@ -1074,8 +1056,6 @@ export function fe_sq2 (h: FieldElement, f: FieldElement): void {
  * @param f FieldElement minuend source
  * @param g FieldElement subtrahend source
  */
-//@ts-expect-error
-@inline
 export function fe_sub (h: FieldElement, f: FieldElement, g: FieldElement): void {
        const f_ptr = changetype<usize>(f)
        const g_ptr = changetype<usize>(g)
index 820586e229ba2af9a454a606b6018ddc878da8f1..93acadbd2a758fc477667c5fc8cd36c3c072137e 100644 (file)
@@ -36,8 +36,6 @@ const ed25519_d: FieldElement = StaticArray.fromArray<i32>([
        -10913610, 13857413, -15372611, 6949391, 114729, -8787816, -6275908, -3247719, -18696448, -12055116, 0, 0
 ])
 
-//@ts-expect-error
-@inline
 function ge_cmov8_base (t: ge_precomp, bp: usize, b: i8): void {
        const isbneg: i8 = (b >> 7) & 1 /* 0: positive; 1: negative */
        const babs: i8 = b - (((-isbneg) & b) * (i8(1) << 1))
index 6be80190737c60210dec1991ab65bed8d2f629f3..726306afddd0e0c7e8d33ad5d67b6b97195dcf0a 100644 (file)
@@ -43,16 +43,12 @@ export class ge_precomp {
        xy2d: FieldElement = fe()
 }
 
-//@ts-expect-error
-@inline
 export function ge_p2_0 (h: ge_p2): void {
        fe_0(h.X)
        fe_1(h.Y)
        fe_1(h.Z)
 }
 
-//@ts-expect-error
-@inline
 export function ge_p1p1_0 (h: ge_p1p1): void {
        fe_0(h.X)
        fe_1(h.Y)
@@ -60,8 +56,6 @@ export function ge_p1p1_0 (h: ge_p1p1): void {
        fe_0(h.T)
 }
 
-//@ts-expect-error
-@inline
 export function ge_p3_0 (h: ge_p3): void {
        fe_0(h.X)
        fe_1(h.Y)
@@ -69,8 +63,6 @@ export function ge_p3_0 (h: ge_p3): void {
        fe_0(h.T)
 }
 
-//@ts-expect-error
-@inline
 export function ge_precomp_0 (h: ge_precomp): void {
        fe_1(h.yplusx)
        fe_1(h.yminusx)
@@ -80,8 +72,6 @@ export function ge_precomp_0 (h: ge_precomp): void {
 /**
  * r = p
  */
-//@ts-expect-error
-@inline
 export function ge_p2_to_p3 (r: ge_p3, p: ge_p2): void {
        fe_copy(r.X, p.X)
        fe_copy(r.Y, p.Y)
@@ -92,16 +82,12 @@ export function ge_p2_to_p3 (r: ge_p3, p: ge_p2): void {
 /**
  * r = p
  */
-//@ts-expect-error
-@inline
 export function ge_p1p1_to_p2 (r: ge_p2, p: ge_p1p1): void {
        fe_mul(r.X, p.X, p.T)
        fe_mul(r.Y, p.Y, p.Z)
        fe_mul(r.Z, p.Z, p.T)
 }
 
-//@ts-expect-error
-@inline
 export function ge_p1p1_to_p3 (r: ge_p3, p: ge_p1p1): void {
        fe_mul(r.X, p.X, p.T)
        fe_mul(r.Y, p.Y, p.Z)
@@ -112,8 +98,6 @@ export function ge_p1p1_to_p3 (r: ge_p3, p: ge_p1p1): void {
 /**
  * r = p
  */
-//@ts-expect-error
-@inline
 export function ge_p3_to_cached (r: ge_cached, p: ge_p3): void {
        fe_add(r.YplusX, p.Y, p.X)
        fe_sub(r.YminusX, p.Y, p.X)
@@ -139,8 +123,6 @@ const ge_p2_dbl_t: FieldElement = fe()
 /**
  * r = 2 * p
  */
-//@ts-expect-error
-@inline
 export function ge_p2_dbl (r: ge_p1p1, p: ge_p2): void {
        const t = ge_p2_dbl_t
        fe_sq(r.X, p.X)
@@ -196,8 +178,6 @@ export function ge_add_cached (r: ge_p1p1, p: ge_p3, q: ge_cached): void {
  * `p.Z` is doubled and stored to itself because its value is not referenced
  * again before being reassigned at all three call sites of this function.
  */
-//@ts-expect-error
-@inline
 export function ge_add_precomp (r: ge_p1p1, p: ge_p3, q: ge_precomp): void {
        fe_add(r.X, p.Y, p.X)
        fe_sub(r.Y, p.Y, p.X)
@@ -214,8 +194,6 @@ export function ge_add_precomp (r: ge_p1p1, p: ge_p3, q: ge_precomp): void {
 const ge_sub_p3_q_cached = new ge_cached()
 const ge_sub_p3_p1p1 = new ge_p1p1()
 /* r = p-q */
-//@ts-expect-error
-@inline
 export function ge_sub_p3 (r: ge_p3, p: ge_p3, q: ge_p3): void {
        const q_cached = ge_sub_p3_q_cached
        const p1p1 = ge_sub_p3_p1p1
index ab2d8742e7521005f929f70c2f61af890f93afb5..4a5c4a82efd0f939fa5683a41ce6d523350e962f 100644 (file)
@@ -8,8 +8,6 @@
  * performance.
  * @param k 32-byte scalar
  */
-//@ts-expect-error
-@inline
 export function clamp (k: StaticArray<u8>): void {
        k[0] &= 248
        k[31] &= 127
@@ -23,8 +21,6 @@ export function clamp (k: StaticArray<u8>): void {
  * @param {i32} n
  * @returns 1 if `n` bytes are equal, else 0
  */
-//@ts-expect-error
-@inline
 export function equalbytes (f: StaticArray<u8>, g: StaticArray<u8>, n: i32): u8 {
        let b: i32 = 0
        for (let i = 0; i < n; i++) {
@@ -34,8 +30,6 @@ export function equalbytes (f: StaticArray<u8>, g: StaticArray<u8>, n: i32): u8
        return u8(((b - 1) >> 8) & 1)
 }
 
-//@ts-expect-error
-@inline
 export function load_3 (input: StaticArray<u8>, i: u8): u64 {
        let result: u64 = u64(input[i])
        result |= u64(input[i + 1]) << 8
@@ -43,16 +37,12 @@ export function load_3 (input: StaticArray<u8>, i: u8): u64 {
        return result
 }
 
-//@ts-expect-error
-@inline
 export function load_4 (input: StaticArray<u8>, i: u8): u64 {
        let result: u64 = load_3(input, i)
        result |= u64(input[i + 3]) << 24
        return result
 }
 
-//@ts-expect-error
-@inline
 export function sodium_is_zero (n: StaticArray<u8>, nlen: i32): u8 {
        let d: i32 = 0
        for (let i: i32 = 0; i < nlen; i++) {