Skip to content

Commit

Permalink
Removed "if" to make code branchless
Browse files Browse the repository at this point in the history
  • Loading branch information
ronhombre committed Jan 17, 2024
1 parent 388ed61 commit 0c49b11
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/commonMain/kotlin/asia/hombre/kyber/internal/KyberMath.kt
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ internal class KyberMath {
fun moduloOf(value: Number, modulo: Number): Short {
val shortedValue = value.toInt()
val shortedModulo = modulo.toShort()
return if(shortedValue < 0) (shortedModulo - (abs(shortedValue) % shortedModulo)).toShort()
else (shortedValue % shortedModulo).toShort()
val isNegative = shortedValue < 0
return (((shortedModulo - (abs(shortedValue) % shortedModulo)) * isNegative.int) + ((shortedValue % shortedModulo) * (!isNegative).int)).toShort()
}

@JvmSynthetic
Expand Down

0 comments on commit 0c49b11

Please sign in to comment.