Skip to content

Commit

Permalink
ADX implies BMI2
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Feb 9, 2021
1 parent a910a3e commit 992e51f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion constantine/arithmetic/limbs_extmul.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func prod*[rLen, aLen, bLen: static int](r: var Limbs[rLen], a: Limbs[aLen], b:
## `r` must not alias ``a`` or ``b``

when UseASM_X86_64 and aLen <= 6:
if ({.noSideEffect.}: hasBmi2()) and ({.noSideEffect.}: hasAdx()):
# ADX implies BMI2
if ({.noSideEffect.}: hasAdx()):
mul_asm_adx_bmi2(r, a, b)
else:
mul_asm(r, a, b)
Expand Down
6 changes: 4 additions & 2 deletions constantine/arithmetic/limbs_montgomery.nim
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ func montyMul*(
# - keep it generic and optimize code size
when spareBits >= 1:
when UseASM_X86_64 and a.len in {2 .. 6}: # TODO: handle spilling
if ({.noSideEffect.}: hasBmi2()) and ({.noSideEffect.}: hasAdx()):
# ADX implies BMI2
if ({.noSideEffect.}: hasAdx()):
montMul_CIOS_nocarry_asm_adx_bmi2(r, a, b, M, m0ninv)
else:
montMul_CIOS_nocarry_asm(r, a, b, M, m0ninv)
Expand Down Expand Up @@ -466,7 +467,8 @@ func montyRedc2x*[N: static int](
m0ninv: BaseType, spareBits: static int) {.inline.} =
## Montgomery reduce a double-precision bigint modulo M
when UseASM_X86_64 and r.len <= 6:
if ({.noSideEffect.}: hasBmi2()) and ({.noSideEffect.}: hasAdx()):
# ADX implies BMI2
if ({.noSideEffect.}: hasAdx()):
montRed_asm_adx_bmi2(r, a, M, m0ninv, spareBits)
else:
montRed_asm(r, a, M, m0ninv, spareBits)
Expand Down

0 comments on commit 992e51f

Please sign in to comment.