Skip to content

Commit 147b847

Browse files
adlichRoberto Santos
andauthored
[perf] "Force" inline in inverseNtt hot path (#291)
`@inline(__always)` helps optimized code-gen in the hot branch as observed in profiler and benchmarks -> ~50% wall time or 2x speed up for `InverseNtt UInt32 metrics`. Co-authored-by: Roberto Santos <ra_santos@apple.com>
1 parent 55c558f commit 147b847

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Sources/HomomorphicEncryption/PolyRq/PolyRq+Ntt.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024-2025 Apple Inc. and the Swift Homomorphic Encryption project authors
1+
// Copyright 2024-2026 Apple Inc. and the Swift Homomorphic Encryption project authors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -405,7 +405,8 @@ extension _NttContext {
405405
let kTimesModulus = modulus &<< lazyReductionCounter
406406

407407
if m == 1 {
408-
// Final stage, folding in multiplication by n^{-1} and modular reduction
408+
// swiftlint:disable:next local_doc_comment
409+
/// Final stage, folding in multiplication by n^{-1} and modular reduction
409410
func applyOp(_ op: (_ x: inout T, _ y: inout T) -> Void) {
410411
for xIdx in 0..<nDiv2 {
411412
let yIdx = xIdx &+ nDiv2
@@ -451,6 +452,7 @@ extension _NttContext {
451452
applyOp { _, _ in }
452453
}
453454
} else {
455+
@inline(__always)
454456
func applyOp(_ op: (_ x: inout T, _ y: inout T) -> Void) {
455457
for i in 0..<m {
456458
let inverseRootOfUnity = inverseRootOfUnityPowers[rootIdx &+ i]

0 commit comments

Comments
 (0)