Skip to content

Commit

Permalink
feat(crandall reduction): prevent asm for mul on 32-bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Jul 27, 2024
1 parent 15788c8 commit 49f0646
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func mulCranPartialReduce_asm*[N: static int](
r: var Limbs[N],
a, b: Limbs[N],
m: static int, c: static SecretWord) =
static: doAssert UseASM_X86_64, "x86-32 does not have enough registers for multiplication"
var r2 {.noInit.}: Limbs[2*N]
r2.mul_asm(a, b)
r.reduceCrandallPartial_asm(r2, m, c)
Expand All @@ -243,6 +244,7 @@ func squareCranPartialReduce_asm*[N: static int](
r: var Limbs[N],
a: Limbs[N],
m: static int, c: static SecretWord) =
static: doAssert UseASM_X86_64, "x86-32 does not have enough registers for squaring"
var r2 {.noInit.}: Limbs[2*N]
r2.square_asm(a)
r.reduceCrandallPartial_asm(r2, m, c)
Expand Down
8 changes: 4 additions & 4 deletions constantine/math/arithmetic/limbs_crandall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func mulCranPartialReduce[N: static int](
r: var Limbs[N],
a, b: Limbs[N],
m: static int, c: static SecretWord) {.inline.} =
when UseASM_X86_32 and a.len in {3..6}:
when UseASM_X86_64 and a.len in {3..6}:
# ADX implies BMI2
if ({.noSideEffect.}: hasAdx()):
r.mulCranPartialReduce_asm_adx(a, b, m, c)
Expand All @@ -206,7 +206,7 @@ func mulCran*[N: static int](
lazyReduce: static bool = false) {.inline.} =
when lazyReduce:
r.mulCranPartialReduce(a, b, m, c)
elif UseASM_X86_32 and a.len in {3..6}:
elif UseASM_X86_64 and a.len in {3..6}:
# ADX implies BMI2
if ({.noSideEffect.}: hasAdx()):
r.mulCran_asm_adx(a, b, p, m, c)
Expand All @@ -222,7 +222,7 @@ func squareCranPartialReduce[N: static int](
r: var Limbs[N],
a: Limbs[N],
m: static int, c: static SecretWord) {.inline.} =
when UseASM_X86_32 and a.len in {3..6}:
when UseASM_X86_64 and a.len in {3..6}:
# ADX implies BMI2
if ({.noSideEffect.}: hasAdx()):
r.squareCranPartialReduce_asm_adx(a, m, c)
Expand All @@ -241,7 +241,7 @@ func squareCran*[N: static int](
lazyReduce: static bool = false) {.inline.} =
when lazyReduce:
r.squareCranPartialReduce(a, m, c)
elif UseASM_X86_32 and a.len in {3..6}:
elif UseASM_X86_64 and a.len in {3..6}:
# ADX implies BMI2
if ({.noSideEffect.}: hasAdx()):
r.squareCran_asm_adx(a, p, m, c)
Expand Down

0 comments on commit 49f0646

Please sign in to comment.