Skip to content

Commit a3eea2e

Browse files
Pass integer parameter by value to function instead of by constant reference
1 parent 9f26e2d commit a3eea2e

File tree

12 files changed

+38
-38
lines changed

12 files changed

+38
-38
lines changed

benchmark/src/IntegerMath.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static void BM_BigInt_DividedByEq(benchmark::State& state) {
187187
}
188188

189189
template <typename I>
190-
static void exp_BigInt(const I& a, const uint32_t& b) {
190+
static void exp_BigInt(const I& a, uint32_t b) {
191191
__attribute__((unused)) I c1 = a.Exp(b);
192192
}
193193

@@ -199,7 +199,7 @@ static void BM_BigInt_Exp(benchmark::State& state) {
199199
}
200200

201201
template <typename I>
202-
static void expeq_BigInt(I a, const uint32_t& b) {
202+
static void expeq_BigInt(I a, uint32_t b) {
203203
a.ExpEq(b);
204204
}
205205

@@ -239,7 +239,7 @@ static void BM_BigInt_MultiplyAndRoundEq(benchmark::State& state) {
239239
}
240240

241241
template <typename I>
242-
static void lshift_BigInt(const I& a, const uint16_t& b) {
242+
static void lshift_BigInt(const I& a, uint16_t b) {
243243
__attribute__((unused)) I c1 = a.LShift(b);
244244
}
245245

@@ -251,7 +251,7 @@ static void BM_BigInt_LShift(benchmark::State& state) {
251251
}
252252

253253
template <typename I>
254-
static void lshifteq_BigInt(I a, const uint16_t& b) {
254+
static void lshifteq_BigInt(I a, uint16_t b) {
255255
a.LShiftEq(b);
256256
}
257257

@@ -263,7 +263,7 @@ static void BM_BigInt_LShiftEq(benchmark::State& state) {
263263
}
264264

265265
template <typename I>
266-
static void rshift_BigInt(const I& a, const uint16_t& b) {
266+
static void rshift_BigInt(const I& a, uint16_t b) {
267267
__attribute__((unused)) I c1 = a.RShift(b);
268268
}
269269

@@ -275,7 +275,7 @@ static void BM_BigInt_RShift(benchmark::State& state) {
275275
}
276276

277277
template <typename I>
278-
static void rshifteq_BigInt(I a, const uint16_t& b) {
278+
static void rshifteq_BigInt(I a, uint16_t b) {
279279
a.RShiftEq(b);
280280
}
281281

benchmark/src/ckks-functional-bootstrapping.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ struct fbt_config {
338338

339339
auto exact(x);
340340
std::transform(x.begin(), x.end(), exact.begin(),
341-
[&](const int64_t& elem) { return (elem >= t.PInput.ConvertToDouble() / 2.); });
341+
[&](int64_t elem) { return (elem >= t.PInput.ConvertToDouble() / 2.); });
342342

343343
std::vector<int64_t> coeffintMod;
344344
std::vector<std::complex<double>> coeffcompMod;

src/core/extras/math.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int main(int argc, char* argv[]) {
7171
do { \
7272
try { \
7373
TIC(t); \
74-
for (uint32_t j = 0; j < nloop; j++) { \
74+
for (uint32_t j = 0; j < nloop; j++) { \
7575
res = (fn); \
7676
} \
7777
time2 = TOC(t); \

src/core/extras/ntt1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int main(int argc, char* argv[]) {
6666
do { \
6767
try { \
6868
TIC(t); \
69-
for (uint32_t j = 0; j < nloop; j++) { \
69+
for (uint32_t j = 0; j < nloop; j++) { \
7070
res = (fn); \
7171
} \
7272
time2 = TOC(t); \

src/core/include/lattice/hal/dcrtpoly-interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ class DCRTPolyInterface : public ILElement<DerivedType, BigVecType> {
12991299
const std::vector<NativeInteger>& mtildeQHatInvModq, const std::vector<NativeInteger>& mtildeQHatInvModqPrecon,
13001300
const std::vector<std::vector<NativeInteger>>& QHatModbsk, const std::vector<uint64_t>& QHatModmtilde,
13011301
const std::vector<NativeInteger>& QModbsk, const std::vector<NativeInteger>& QModbskPrecon,
1302-
const uint64_t& negQInvModmtilde, const std::vector<NativeInteger>& mtildeInvModbsk,
1302+
uint64_t negQInvModmtilde, const std::vector<NativeInteger>& mtildeInvModbsk,
13031303
const std::vector<NativeInteger>& mtildeInvModbskPrecon) = 0;
13041304

13051305
/**

src/core/include/lattice/hal/default/dcrtpoly-impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ DCRTPolyImpl<VecType> DCRTPolyImpl<VecType>::ScaleAndRound(
15171517
OPENFHE_THROW("Use of ScaleAndRound with NATIVEINT == 32 may lead to overflow");
15181518

15191519
DCRTPolyImpl<VecType> ans(paramsOutput, m_format, true);
1520-
uint32_t ringDim = m_params->GetRingDimension();
1520+
uint32_t ringDim = m_params->GetRingDimension();
15211521
uint32_t sizeQP = m_vectors.size();
15221522
uint32_t sizeO = ans.m_vectors.size();
15231523
uint32_t sizeI = sizeQP - sizeO;
@@ -1697,7 +1697,7 @@ void DCRTPolyImpl<VecType>::FastBaseConvqToBskMontgomery(
16971697
const std::vector<NativeInteger>& mtildeQHatInvModq, const std::vector<NativeInteger>& mtildeQHatInvModqPrecon,
16981698
const std::vector<std::vector<NativeInteger>>& QHatModbsk, const std::vector<uint64_t>& QHatModmtilde,
16991699
const std::vector<NativeInteger>& QModbsk, const std::vector<NativeInteger>& QModbskPrecon,
1700-
const uint64_t& negQInvModmtilde, const std::vector<NativeInteger>& mtildeInvModbsk,
1700+
uint64_t negQInvModmtilde, const std::vector<NativeInteger>& mtildeInvModbsk,
17011701
const std::vector<NativeInteger>& mtildeInvModbskPrecon) {
17021702
constexpr uint64_t mtilde = (uint64_t)1 << 16;
17031703
constexpr uint64_t mtilde_half = mtilde >> 1;

src/core/include/lattice/hal/default/dcrtpoly.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class DCRTPolyImpl final : public DCRTPolyInterface<DCRTPolyImpl<VecType>, VecTy
307307
const std::vector<NativeInteger>& mtildeQHatInvModq, const std::vector<NativeInteger>& mtildeQHatInvModqPrecon,
308308
const std::vector<std::vector<NativeInteger>>& QHatModbsk, const std::vector<uint64_t>& QHatModmtilde,
309309
const std::vector<NativeInteger>& QModbsk, const std::vector<NativeInteger>& QModbskPrecon,
310-
const uint64_t& negQInvModmtilde, const std::vector<NativeInteger>& mtildeInvModbsk,
310+
uint64_t negQInvModmtilde, const std::vector<NativeInteger>& mtildeInvModbsk,
311311
const std::vector<NativeInteger>& mtildeInvModbskPrecon) override;
312312

313313
void FastRNSFloorq(const NativeInteger& t, const std::vector<NativeInteger>& moduliQ,

src/core/include/math/hal/bigintdyn/mubintvecdyn.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class mubintvec final : public lbcrypto::BigVectorInterface<mubintvec<ubint_el_t
9696
* @param modulus uint32_t associated with entries in the vector.
9797
*/
9898
// TODO: what practical purpose with uint32_t modulus??
99-
// explicit mubintvec(uint32_t length, const uint32_t& modulus) noexcept
99+
// explicit mubintvec(uint32_t length, uint32_t modulus) noexcept
100100
// : m_modulus(modulus), m_modulus_state(State::INITIALIZED), m_data(length) {}
101101

102102
/**
@@ -269,7 +269,7 @@ class mubintvec final : public lbcrypto::BigVectorInterface<mubintvec<ubint_el_t
269269
*
270270
* @param value is the value to set.
271271
*/
272-
// void SetModulus(const uint32_t& value) noexcept {
272+
// void SetModulus(uint32_t value) noexcept {
273273
// m_modulus = ubint_el_t(value);
274274
// m_modulus_state = State::INITIALIZED;
275275
// }

src/core/include/math/hal/bigintntl/mubintvecntl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class myVecP : public NTL::Vec<myT>,
195195
}
196196

197197
// sets modulus and the NTL init function uint64_t argument
198-
inline void SetModulus(const uint64_t& value) {
198+
inline void SetModulus(uint64_t value) {
199199
if (value == 0) {
200200
OPENFHE_THROW("SetModulus(uint64_t) cannot be zero");
201201
}

src/pke/examples/functional-bootstrapping-ckks.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,13 @@ void ArbitraryLUT(BigInteger QBFVInit, BigInteger PInput, BigInteger POutput, Bi
230230
std::cerr << "]" << std::endl;
231231

232232
auto exact(x);
233-
std::transform(x.begin(), x.end(), exact.begin(), [&](const int64_t& elem) {
233+
std::transform(x.begin(), x.end(), exact.begin(), [&](int64_t elem) {
234234
return (func(elem) > POutput.ConvertToDouble() / 2.) ? func(elem) - POutput.ConvertToInt() : func(elem);
235235
});
236236

237237
std::transform(exact.begin(), exact.end(), computed.begin(), exact.begin(), std::minus<int64_t>());
238238
std::transform(exact.begin(), exact.end(), exact.begin(),
239-
[&](const int64_t& elem) { return (std::abs(elem)) % (POutput.ConvertToInt()); });
239+
[&](int64_t elem) { return (std::abs(elem)) % (POutput.ConvertToInt()); });
240240
auto max_error_it = std::max_element(exact.begin(), exact.end());
241241
std::cerr << "Max absolute error obtained: " << *max_error_it << std::endl << std::endl;
242242
}
@@ -393,12 +393,12 @@ void MultiValueBootstrapping(BigInteger QBFVInit, BigInteger PInput, BigInteger
393393
Ciphertext<DCRTPoly> ctxtAfterFBT1, ctxtAfterFBT2;
394394

395395
auto exact(x);
396-
std::transform(x.begin(), x.end(), exact.begin(), [&](const int64_t& elem) {
396+
std::transform(x.begin(), x.end(), exact.begin(), [&](int64_t elem) {
397397
return (func1(elem) > POutput.ConvertToDouble() / 2.) ? func1(elem) - POutput.ConvertToInt() : func1(elem);
398398
});
399399

400400
auto exact2(x);
401-
std::transform(x.begin(), x.end(), exact2.begin(), [&](const int64_t& elem) {
401+
std::transform(x.begin(), x.end(), exact2.begin(), [&](int64_t elem) {
402402
return (func2(elem) > POutput.ConvertToDouble() / 2.) ? func2(elem) - POutput.ConvertToInt() : func2(elem);
403403
});
404404

@@ -459,7 +459,7 @@ void MultiValueBootstrapping(BigInteger QBFVInit, BigInteger PInput, BigInteger
459459

460460
std::transform(exact.begin(), exact.end(), computed.begin(), exact.begin(), std::minus<int64_t>());
461461
std::transform(exact.begin(), exact.end(), exact.begin(),
462-
[&](const int64_t& elem) { return (std::abs(elem)) % (POutput.ConvertToInt()); });
462+
[&](int64_t elem) { return (std::abs(elem)) % (POutput.ConvertToInt()); });
463463
auto max_error_it = std::max_element(exact.begin(), exact.end());
464464
std::cerr << "Max absolute error obtained in the first LUT: " << *max_error_it << std::endl << std::endl;
465465

@@ -473,7 +473,7 @@ void MultiValueBootstrapping(BigInteger QBFVInit, BigInteger PInput, BigInteger
473473

474474
std::transform(exact2.begin(), exact2.end(), computed.begin(), exact2.begin(), std::minus<int64_t>());
475475
std::transform(exact2.begin(), exact2.end(), exact2.begin(),
476-
[&](const int64_t& elem) { return (std::abs(elem)) % (POutput.ConvertToInt()); });
476+
[&](int64_t elem) { return (std::abs(elem)) % (POutput.ConvertToInt()); });
477477
max_error_it = std::max_element(exact2.begin(), exact2.end());
478478
std::cerr << "Max absolute error obtained in the second LUT: " << *max_error_it << std::endl << std::endl;
479479
}
@@ -514,7 +514,7 @@ void MultiPrecisionSign(BigInteger QBFVInit, BigInteger PInput, BigInteger PDigi
514514

515515
auto exact(x);
516516
std::transform(x.begin(), x.end(), exact.begin(),
517-
[&](const int64_t& elem) { return (elem >= PInput.ConvertToDouble() / 2.); });
517+
[&](int64_t elem) { return (elem >= PInput.ConvertToDouble() / 2.); });
518518

519519
/* 4. The case of Boolean LUTs using the first order Trigonometric Hermite Interpolation
520520
* supports an optimized implementation.
@@ -691,7 +691,7 @@ void MultiPrecisionSign(BigInteger QBFVInit, BigInteger PInput, BigInteger PDigi
691691

692692
std::transform(exact.begin(), exact.end(), computed.begin(), exact.begin(), std::minus<int64_t>());
693693
std::transform(exact.begin(), exact.end(), exact.begin(),
694-
[&](const int64_t& elem) { return (std::abs(elem)) % (pOrig.ConvertToInt()); });
694+
[&](int64_t elem) { return (std::abs(elem)) % (pOrig.ConvertToInt()); });
695695
auto max_error_it = std::max_element(exact.begin(), exact.end());
696696
std::cerr << "\nMax absolute error obtained: " << *max_error_it << std::endl << std::endl;
697697
}

0 commit comments

Comments
 (0)