Skip to content

Commit

Permalink
bit faster
Browse files Browse the repository at this point in the history
  • Loading branch information
nindanaoto committed Jun 30, 2024
1 parent 309cd11 commit 2fa21d9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
22 changes: 11 additions & 11 deletions include/mulfft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,20 @@ template <uint32_t N>
inline void FMAInFD(std::array<double, N> &res, const std::array<double, N> &a,
const std::array<double, N> &b)
{
// for (int i = 0; i < N / 2; i++) {
// res[i] = std::fma(a[i], b[i], res[i]);
// res[i + N / 2] = std::fma(a[i + N / 2], b[i], res[i + N / 2]);
// }
// for (int i = 0; i < N / 2; i++) {
// res[i + N / 2] = std::fma(a[i], b[i + N / 2], res[i + N / 2]);
// res[i] -= a[i + N / 2] * b[i + N / 2];
// }
for (int i = 0; i < N / 2; i++) {
res[i] = std::fma(a[i + N / 2], b[i + N / 2], -res[i]);
res[i] = std::fma(a[i], b[i], -res[i]);
res[i + N / 2] = std::fma(a[i], b[i + N / 2], res[i + N / 2]);
res[i] = std::fma(a[i], b[i], res[i]);
res[i + N / 2] = std::fma(a[i + N / 2], b[i], res[i + N / 2]);
}
for (int i = 0; i < N / 2; i++) {
res[i + N / 2] = std::fma(a[i], b[i + N / 2], res[i + N / 2]);
res[i] -= a[i + N / 2] * b[i + N / 2];
}
// for (int i = 0; i < N / 2; i++) {
// res[i] = std::fma(a[i + N / 2], b[i + N / 2], -res[i]);
// res[i] = std::fma(a[i], b[i], -res[i]);
// res[i + N / 2] = std::fma(a[i], b[i + N / 2], res[i + N / 2]);
// res[i + N / 2] = std::fma(a[i + N / 2], b[i], res[i + N / 2]);
// }
}

template <class P>
Expand Down
4 changes: 2 additions & 2 deletions include/params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ using BootstrappingKey =
std::array<BootstrappingKeyElement<P>, P::domainP::k * P::domainP::n>;
template <class P>
using BootstrappingKeyFFT =
std::array<BootstrappingKeyElementFFT<P>,
alignas(16) std::array<BootstrappingKeyElementFFT<P>,
P::domainP::k * P::domainP::n / P::Addends>;
template <class P>
using BootstrappingKeyNTT =
Expand All @@ -143,7 +143,7 @@ using BootstrappingKeyRAINTT =
std::array<TRGSWRAINTT<typename P::targetP>, P::domainP::k * P::domainP::n>;

template <class P>
using KeySwitchingKey = std::array<
using KeySwitchingKey = alignas(16) std::array<
std::array<std::array<TLWE<typename P::targetP>, (1 << P::basebit) - 1>,
P::t>,
P::domainP::k * P::domainP::n>;
Expand Down
13 changes: 11 additions & 2 deletions test/gatebootstrapping.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifdef USE_PERF
#include <gperftools/profiler.h>
#endif

#include <cassert>
#include <chrono>
#include <iostream>
Expand All @@ -6,7 +10,7 @@

int main()
{
constexpr uint32_t num_test = 10;
constexpr uint32_t num_test = 1000;
std::random_device seed_gen;
std::default_random_engine engine(seed_gen());
std::uniform_int_distribution<uint32_t> binary(0, 1);
Expand All @@ -28,11 +32,16 @@ int main()

std::chrono::system_clock::time_point start, end;
start = std::chrono::system_clock::now();

#ifdef USE_PERF
ProfilerStart("gb.prof");
#endif
for (int test = 0; test < num_test; test++) {
TFHEpp::GateBootstrapping<iksP, bkP, bkP::targetP::μ>(bootedtlwe[test],
tlwe[test], ek);
}
#ifdef USE_PERF
ProfilerStop();
#endif

end = std::chrono::system_clock::now();
double elapsed =
Expand Down

0 comments on commit 2fa21d9

Please sign in to comment.