Fix isZeroMask in SignedSecretWord

This commit is contained in:
Mamy Ratsimbazafy 2023-01-29 01:05:54 +01:00
parent 915f89fdd6
commit a385acf2b8
No known key found for this signature in database
GPG Key ID: 6227262F49BE273A
3 changed files with 59 additions and 57 deletions

View File

@ -626,7 +626,7 @@ func legendreImpl[N, E](
accL = (accL + accL.isOdd()) and SignedSecretWord(3) accL = (accL + accL.isOdd()) and SignedSecretWord(3)
accL = SignedSecretWord(1)-accL accL = SignedSecretWord(1)-accL
accL.csetZero(f.isZeroMask()) accL.csetZero(not f.isZeroMask())
return SecretWord(accL) return SecretWord(accL)
func legendre*(a, M: Limbs, bits: static int): SecretWord = func legendre*(a, M: Limbs, bits: static int): SecretWord =

View File

@ -280,9 +280,10 @@ func isOdd*(a: SignedSecretWord): SignedSecretWord {.inline.} =
a and SignedSecretWord(1) a and SignedSecretWord(1)
func isZeroMask*(a: SignedSecretWord): SignedSecretWord {.inline.} = func isZeroMask*(a: SignedSecretWord): SignedSecretWord {.inline.} =
## Produce the -1 mask if a is negative ## Produce the -1 mask if a is 0
## and 0 otherwise ## and 0 otherwise
not SignedSecretWord(a.SecretWord().isZero()) # In x86 assembly, we can use "neg" + "sbb"
-SignedSecretWord(a.SecretWord().isZero())
func isNegMask*(a: SignedSecretWord): SignedSecretWord {.inline.} = func isNegMask*(a: SignedSecretWord): SignedSecretWord {.inline.} =
## Produce the -1 mask if a is negative ## Produce the -1 mask if a is negative

View File

@ -215,6 +215,7 @@ template isNonZero*[T: Ct](x: T): CTBool[T] =
isMsbSet(x_NZ or -x_NZ) isMsbSet(x_NZ or -x_NZ)
template isZero*[T: Ct](x: T): CTBool[T] = template isZero*[T: Ct](x: T): CTBool[T] =
# In x86 assembly, we can use "neg" + "adc"
not isNonZero(x) not isNonZero(x)
# ############################################################ # ############################################################