Skip to content

General optimize#13

Merged
juny2400 merged 3 commits into
mainfrom
general-optimize
Jun 24, 2026
Merged

General optimize#13
juny2400 merged 3 commits into
mainfrom
general-optimize

Conversation

@juny2400

@juny2400 juny2400 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor
  1. Performance Optimizations
  • Compile-time-prime Barrett kernels (ModArith.hpp, PresetTraits.hpp): For compile-time presets (P != PRESET_EMPTY, u64), each polyunit's prime / Barrett ratio / shift is folded into immediates instead of reloaded from runtime members. Yields ~1.25–1.3x on the Barrett multiply path. Dispatch via mulPolyP / mulPolyConstP safely falls back to the runtime path when no prime matches.
  • Rewritten poly add/sub/mul loops (ModArith.cpp): Dropped collapse(2) in favor of raw-pointer affine loops with the prime hoisted for better vectorization. Unified the lazy-reduction variant via a LazyConstSub template parameter.
  • Precomputed CRT constants in Decryptor (Decryptor.hpp/.cpp): The two-prime CRT Bezout coefficients (modular inverses) are computed once in the constructor, removing ~60 modular multiplications per inverse from the decrypt hot path.
  • MSVC hardware intrinsics (Basic.hpp): u128 multiply/divide now use _umul128/_udiv128 at runtime while staying constexpr-compatible via __builtin_is_constant_evaluated().
  • Reused encode scratch buffers in Encryptor: avoids per-encrypt reallocation.
  1. Seed-Only Ciphertext Feature
  • Added CipherSeedMode (NONE / UNIFORM / PUBLICKEY) — stores only the RNG seed instead of the full a part of a ciphertext, reducing serialized size.
  • New EncryptOptions: SeedOnlyA, ASeed (fixed a seed), and ErrorSeed (deterministic noise, for testing).
  • EncryptorT::completeCiphertext() (two overloads: key-free UNIFORM / encryption-key PUBLICKEY) and the expandUniformAxInplace() helper regenerate the a part on demand.
  • New CiphertextT API: hasSeed / getSeed / setSeed / flushSeed / seedMode / flushAx / isAxFlushed.
  1. Serialization (DebFBType.fbs)
  • Added seed and seed_mode fields to the FlatBuffers s
  • Narrowed field widths for size: preset/encoding/type → uint8, ntt_info → int8, and renamed Sk.seeds → seed.
  1. Build / Docs / Examples
  • New CMake options: DEB_SERIALIZE_API, DEB_SUPPORT_U64/U32, DEB_MEMORY_ALIGN_SIZE, DEB_EXT_LIB_FOR_SECURE_ZERO.
  • Added DEB_ARCH=x86-64-v3 to the benchmark preset andbench_ct_vs_rt.cpp, CT vs RT path comparison) with nogoogle/benchmark dependency.
  • New example SeedOnlyCiphertext.cpp, new tests (EnDec, and README updates.

⚠️ Security note: Reusing the same ErrorSeed across — intended for testing/reproducibility only.

@juny2400 juny2400 requested a review from a team June 23, 2026 08:31
@leejonghyeong

Copy link
Copy Markdown
Contributor

doxygen docs seems different (from git diff private/main -- CMakeLists.txt)

     doxygen_add_docs(
       deb_doc
       ${CMAKE_CURRENT_SOURCE_DIR}/include/deb/CKKSTypes.hpp
-      ${CMAKE_CURRENT_SOURCE_DIR}/include/deb/utils/Constant.hpp
+      ${CMAKE_CURRENT_SOURCE_DIR}/include/deb/Constant.hpp
+      ${CMAKE_CURRENT_SOURCE_DIR}/include/deb/Context.hpp

@juny2400 juny2400 merged commit 862b4fe into main Jun 24, 2026
4 checks passed
@juny2400 juny2400 deleted the general-optimize branch June 24, 2026 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants