Skip to content

Commit 0c49b11

Browse files
committed
Removed "if" to make code branchless
1 parent 388ed61 commit 0c49b11

File tree

1 file changed

+2
-2
lines changed
  • src/commonMain/kotlin/asia/hombre/kyber/internal

1 file changed

+2
-2
lines changed

src/commonMain/kotlin/asia/hombre/kyber/internal/KyberMath.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ internal class KyberMath {
375375
fun moduloOf(value: Number, modulo: Number): Short {
376376
val shortedValue = value.toInt()
377377
val shortedModulo = modulo.toShort()
378-
return if(shortedValue < 0) (shortedModulo - (abs(shortedValue) % shortedModulo)).toShort()
379-
else (shortedValue % shortedModulo).toShort()
378+
val isNegative = shortedValue < 0
379+
return (((shortedModulo - (abs(shortedValue) % shortedModulo)) * isNegative.int) + ((shortedValue % shortedModulo) * (!isNegative).int)).toShort()
380380
}
381381

382382
@JvmSynthetic

0 commit comments

Comments
 (0)