Skip to content

Commit 1c85999

Browse files
authored
Faster inverse NTT (#294)
1 parent 9e05e11 commit 1c85999

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

Sources/HomomorphicEncryption/PolyRq/PolyRq+Ntt.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 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.
@@ -76,7 +76,7 @@ extension ScalarType {
7676
return nil
7777
}
7878

79-
/// Generates the smallest primitive `degree`'th primitive root for integers mod this value, `p`.
79+
/// Generates the smallest primitive degree'th primitive root for integers mod this value, p.
8080
///
8181
/// This value, `p`, must be prime.
8282
/// - Parameter degree: Must be a power of two that divides `p - 1`.
@@ -104,11 +104,11 @@ extension ScalarType {
104104
}
105105

106106
@usableFromInline
107-
struct NttContext<T: ScalarType>: Sendable {
107+
struct NttContext<T: ScalarType> {
108108
@usableFromInline let rootOfUnityPowers: MultiplyConstantArrayModulus<T>
109109
@usableFromInline let inverseRootOfUnityPowers: MultiplyConstantArrayModulus<T>
110110
@usableFromInline let inverseDegree: MultiplyConstantModulus<T> // degree^{-1} mod modulus
111-
// (degree)^{-1} * w^{-N} mod modulus for `w` a root of unity mod modulus
111+
/// (degree)^{-1} * w^{-N} mod modulus for `w` a root of unity mod modulus.
112112
@usableFromInline let inverseDegreeRootOfUnity: MultiplyConstantModulus<T>
113113

114114
@inlinable
@@ -408,7 +408,8 @@ extension PolyRq where F == Eval {
408408
let kTimesModulus = modulus &<< lazyReductionCounter
409409

410410
if m == 1 {
411-
// Final stage, folding in multiplication by n^{-1} and modular reduction
411+
// swiftlint:disable:next local_doc_comment
412+
/// Final stage, folding in multiplication by n^{-1} and modular reduction
412413
func applyOp(_ op: (_ x: inout T, _ y: inout T) -> Void) {
413414
for xIdx in 0..<nDiv2 {
414415
let yIdx = xIdx &+ nDiv2
@@ -454,6 +455,7 @@ extension PolyRq where F == Eval {
454455
applyOp { _, _ in }
455456
}
456457
} else {
458+
@inline(__always)
457459
func applyOp(_ op: (_ x: inout T, _ y: inout T) -> Void) {
458460
for i in 0..<m {
459461
let inverseRootOfUnity = inverseRootOfUnityPowers[rootIdx &+ i]

0 commit comments

Comments
 (0)