diff --git a/Makefile b/Makefile index 52cc5b7bfd..9a1b7c4cc9 100644 --- a/Makefile +++ b/Makefile @@ -350,6 +350,9 @@ clippy_integer: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ --features=integer,experimental \ -p $(TFHE_SPEC) -- --no-deps -D warnings + RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ + --features=integer,experimental,extended-types \ + -p $(TFHE_SPEC) -- --no-deps -D warnings .PHONY: clippy # Run clippy lints enabling the boolean, shortint, integer clippy: install_rs_check_toolchain @@ -388,10 +391,10 @@ clippy_c_api: install_rs_check_toolchain .PHONY: clippy_js_wasm_api # Run clippy lints enabling the boolean, shortint, integer and the js wasm API clippy_js_wasm_api: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ - --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,high-level-client-js-wasm-api,zk-pok \ + --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,high-level-client-js-wasm-api,zk-pok,extended-types \ -p $(TFHE_SPEC) -- --no-deps -D warnings RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy \ - --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,high-level-client-js-wasm-api \ + --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,high-level-client-js-wasm-api,extended-types \ -p $(TFHE_SPEC) -- --no-deps -D warnings .PHONY: clippy_tasks # Run clippy lints on helper tasks crate. @@ -407,10 +410,10 @@ clippy_trivium: install_rs_check_toolchain .PHONY: clippy_all_targets # Run clippy lints on all targets (benches, examples, etc.) clippy_all_targets: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \ - --features=boolean,shortint,integer,internal-keycache,zk-pok,strings \ + --features=boolean,shortint,integer,internal-keycache,zk-pok,strings,extended-types \ -p $(TFHE_SPEC) -- --no-deps -D warnings RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \ - --features=boolean,shortint,integer,internal-keycache,zk-pok,strings,experimental \ + --features=boolean,shortint,integer,internal-keycache,zk-pok,strings,extended-types,experimental \ -p $(TFHE_SPEC) -- --no-deps -D warnings .PHONY: clippy_tfhe_csprng # Run clippy lints on tfhe-csprng @@ -528,7 +531,7 @@ build_web_js_api: install_rs_build_toolchain install_wasm_pack cd tfhe && \ RUSTFLAGS="$(WASM_RUSTFLAGS)" rustup run "$(RS_BUILD_TOOLCHAIN)" \ wasm-pack build --release --target=web \ - -- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,zk-pok + -- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,zk-pok,extended-types .PHONY: build_web_js_api_parallel # Build the js API targeting the web browser with parallelism support build_web_js_api_parallel: install_rs_check_toolchain install_wasm_pack @@ -536,7 +539,7 @@ build_web_js_api_parallel: install_rs_check_toolchain install_wasm_pack rustup component add rust-src --toolchain $(RS_CHECK_TOOLCHAIN) && \ RUSTFLAGS="$(WASM_RUSTFLAGS) -C target-feature=+atomics,+bulk-memory" rustup run $(RS_CHECK_TOOLCHAIN) \ wasm-pack build --release --target=web \ - -- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,parallel-wasm-api,zk-pok \ + -- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,parallel-wasm-api,zk-pok,extended-types \ -Z build-std=panic_abort,std && \ find pkg/snippets -type f -iname workerHelpers.js -exec sed -i "s|const pkg = await import('..\/..\/..');|const pkg = await import('..\/..\/..\/tfhe.js');|" {} \; jq '.files += ["snippets"]' tfhe/pkg/package.json > tmp_pkg.json && mv -f tmp_pkg.json tfhe/pkg/package.json @@ -546,7 +549,7 @@ build_node_js_api: install_rs_build_toolchain install_wasm_pack cd tfhe && \ RUSTFLAGS="$(WASM_RUSTFLAGS)" rustup run "$(RS_BUILD_TOOLCHAIN)" \ wasm-pack build --release --target=nodejs \ - -- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,zk-pok + -- --features=boolean-client-js-wasm-api,shortint-client-js-wasm-api,integer-client-js-wasm-api,zk-pok,extended-types .PHONY: build_tfhe_csprng # Build tfhe_csprng build_tfhe_csprng: install_rs_build_toolchain diff --git a/tfhe/Cargo.toml b/tfhe/Cargo.toml index cf93316693..a3435b37be 100644 --- a/tfhe/Cargo.toml +++ b/tfhe/Cargo.toml @@ -92,6 +92,9 @@ internal-keycache = ["dep:fs2"] gpu = ["dep:tfhe-cuda-backend"] zk-pok = ["dep:tfhe-zk-pok"] +# Adds more FheUint/FheInt types to the HL +extended-types = [] + pbs-stats = [] noise-asserts = [] diff --git a/tfhe/build.rs b/tfhe/build.rs index ee078e5707..355bd20e78 100644 --- a/tfhe/build.rs +++ b/tfhe/build.rs @@ -59,6 +59,8 @@ fn gen_c_api() { "gpu", #[cfg(feature = "zk-pok")] "zk-pok", + #[cfg(feature = "extended-types")] + "extended-types", ]; let parse_expand_vec = if parse_expand_features_vec.is_empty() { diff --git a/tfhe/src/c_api/high_level_api/mod.rs b/tfhe/src/c_api/high_level_api/mod.rs index 840beb4423..e73140cd9a 100644 --- a/tfhe/src/c_api/high_level_api/mod.rs +++ b/tfhe/src/c_api/high_level_api/mod.rs @@ -61,6 +61,7 @@ pub enum FheTypes { Type_FheInt1024 = 32, Type_FheInt2048 = 33, + // Extended types Type_FheUint24 = 34, Type_FheUint40 = 35, Type_FheUint48 = 36, diff --git a/tfhe/src/high_level_api/compact_list.rs b/tfhe/src/high_level_api/compact_list.rs index 7dcffb2d18..3a71ec403a 100644 --- a/tfhe/src/high_level_api/compact_list.rs +++ b/tfhe/src/high_level_api/compact_list.rs @@ -634,6 +634,47 @@ mod tests { } } + #[cfg(feature = "extended-types")] + #[test] + fn test_compact_list_extended_types() { + let config = crate::ConfigBuilder::default().build(); + + let ck = crate::ClientKey::generate(config); + let sk = crate::ServerKey::new(&ck); + let pk = crate::CompactPublicKey::new(&ck); + + set_server_key(sk); + + let compact_list = CompactCiphertextList::builder(&pk) + .push_with_num_bits(-17i64, 40) + .unwrap() + .push_with_num_bits(3u8, 24) + .unwrap() + .build_packed(); + + let serialized = bincode::serialize(&compact_list).unwrap(); + let compact_list: CompactCiphertextList = bincode::deserialize(&serialized).unwrap(); + let expander = compact_list.expand().unwrap(); + + { + let a: crate::FheInt40 = expander.get(0).unwrap().unwrap(); + let b: crate::FheUint24 = expander.get(1).unwrap().unwrap(); + + let a: i64 = a.decrypt(&ck); + assert_eq!(a, -17); + let b: u8 = b.decrypt(&ck); + assert_eq!(b, 3); + } + + { + // Incorrect type + assert!(expander.get::(0).is_err()); + + // Correct type but wrong number of bits + assert!(expander.get::(0).is_err()); + } + } + #[test] fn test_compact_list_with_casting() { let config = crate::ConfigBuilder::with_custom_parameters( diff --git a/tfhe/src/high_level_api/integers/mod.rs b/tfhe/src/high_level_api/integers/mod.rs index 344c808563..7d8518ab72 100644 --- a/tfhe/src/high_level_api/integers/mod.rs +++ b/tfhe/src/high_level_api/integers/mod.rs @@ -1,21 +1,32 @@ expand_pub_use_fhe_type!( pub use unsigned{ FheUint2, FheUint4, FheUint6, FheUint8, FheUint10, FheUint12, FheUint14, FheUint16, - FheUint24, FheUint32, FheUint40, FheUint48, FheUint56, FheUint64, FheUint72, FheUint80, - FheUint88, FheUint96, FheUint104, FheUint112, FheUint120, FheUint128, FheUint136, - FheUint144, FheUint152, FheUint160, FheUint168, FheUint176, FheUint184, FheUint192, - FheUint200, FheUint208, FheUint216, FheUint224, FheUint232, FheUint240, FheUint248, - FheUint256, FheUint512, FheUint1024, FheUint2048, + FheUint32, FheUint64, FheUint128, FheUint160, FheUint256, FheUint512, FheUint1024, + FheUint2048, + }; +); +#[cfg(feature = "extended-types")] +expand_pub_use_fhe_type!( + pub use unsigned{ + FheUint24, FheUint40, FheUint48, FheUint56, FheUint72, FheUint80,FheUint88, FheUint96, + FheUint104, FheUint112, FheUint120, FheUint136, FheUint144, FheUint152, FheUint168, + FheUint176, FheUint184, FheUint192, FheUint200, FheUint208, FheUint216, FheUint224, + FheUint232, FheUint240, FheUint248, }; ); expand_pub_use_fhe_type!( pub use signed{ - FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt24, - FheInt32, FheInt40, FheInt48, FheInt56, FheInt64, FheInt72, FheInt80, FheInt88, FheInt96, - FheInt104, FheInt112, FheInt120, FheInt128, FheInt136, FheInt144, FheInt152, FheInt160, - FheInt168, FheInt176, FheInt184, FheInt192, FheInt200, FheInt208, FheInt216, FheInt224, - FheInt232, FheInt240, FheInt248, FheInt256, FheInt512, FheInt1024, FheInt2048, + FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt32, + FheInt64, FheInt128, FheInt160, FheInt256, FheInt512, FheInt1024, FheInt2048, + }; +); +#[cfg(feature = "extended-types")] +expand_pub_use_fhe_type!( + pub use signed{ + FheInt24, FheInt40, FheInt48, FheInt56, FheInt72, FheInt80, FheInt88, FheInt96, FheInt104, + FheInt112, FheInt120, FheInt136, FheInt144, FheInt152, FheInt168, FheInt176, FheInt184, + FheInt192, FheInt200, FheInt208, FheInt216, FheInt224, FheInt232, FheInt240, FheInt248, }; ); diff --git a/tfhe/src/high_level_api/integers/signed/mod.rs b/tfhe/src/high_level_api/integers/signed/mod.rs index 2bd83b926a..63df1db9f4 100644 --- a/tfhe/src/high_level_api/integers/signed/mod.rs +++ b/tfhe/src/high_level_api/integers/signed/mod.rs @@ -17,10 +17,15 @@ pub(in crate::high_level_api) use inner::{RadixCiphertext, RadixCiphertextVersio expand_pub_use_fhe_type!( pub use static_{ - FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt24, - FheInt32, FheInt40, FheInt48, FheInt56, FheInt64, FheInt72, FheInt80, FheInt88, FheInt96, - FheInt104, FheInt112, FheInt120, FheInt128, FheInt136, FheInt144, FheInt152, FheInt160, - FheInt168, FheInt176, FheInt184, FheInt192, FheInt200, FheInt208, FheInt216, FheInt224, - FheInt232, FheInt240, FheInt248, FheInt256, FheInt512, FheInt1024, FheInt2048 + FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt32, + FheInt64,FheInt128, FheInt160, FheInt256, FheInt512, FheInt1024, FheInt2048 + }; +); +#[cfg(feature = "extended-types")] +expand_pub_use_fhe_type!( + pub use static_{ + FheInt24, FheInt40, FheInt48, FheInt56, FheInt72, FheInt80, FheInt88, FheInt96, FheInt104, + FheInt112, FheInt120, FheInt136, FheInt144, FheInt152, FheInt168, FheInt176, FheInt184, + FheInt192, FheInt200, FheInt208, FheInt216, FheInt224, FheInt232, FheInt240, FheInt248 }; ); diff --git a/tfhe/src/high_level_api/integers/signed/scalar_ops.rs b/tfhe/src/high_level_api/integers/signed/scalar_ops.rs index f2735ad1cb..e0bbb71698 100644 --- a/tfhe/src/high_level_api/integers/signed/scalar_ops.rs +++ b/tfhe/src/high_level_api/integers/signed/scalar_ops.rs @@ -428,22 +428,13 @@ macro_rules! generic_integer_impl_scalar_div_rem { }; } +#[cfg(feature = "extended-types")] generic_integer_impl_scalar_div_rem!( fhe_and_scalar_type: - (super::FheInt2, i8), - (super::FheInt4, i8), - (super::FheInt6, i8), - (super::FheInt8, i8), - (super::FheInt10, i16), - (super::FheInt12, i16), - (super::FheInt14, i16), - (super::FheInt16, i16), (super::FheInt24, i32), - (super::FheInt32, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -451,8 +442,9 @@ generic_integer_impl_scalar_div_rem!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -464,6 +456,21 @@ generic_integer_impl_scalar_div_rem!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), +); +generic_integer_impl_scalar_div_rem!( + fhe_and_scalar_type: + (super::FheInt2, i8), + (super::FheInt4, i8), + (super::FheInt6, i8), + (super::FheInt8, i8), + (super::FheInt10, i16), + (super::FheInt12, i16), + (super::FheInt14, i16), + (super::FheInt16, i16), + (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), (super::FheInt256, I256), (super::FheInt512, I512), (super::FheInt1024, I1024), @@ -475,6 +482,7 @@ use crate::high_level_api::integers::unsigned::scalar_ops::{ generic_integer_impl_scalar_operation_assign, }; +#[cfg(feature = "extended-types")] generic_integer_impl_scalar_operation!( rust_trait: Add(add), implem: { @@ -499,20 +507,10 @@ generic_integer_impl_scalar_operation!( } }, fhe_and_scalar_type: - (super::FheInt2, i8), - (super::FheInt4, i8), - (super::FheInt6, i8), - (super::FheInt8, i8), - (super::FheInt10, i16), - (super::FheInt12, i16), - (super::FheInt14, i16), - (super::FheInt16, i16), (super::FheInt24, i32), - (super::FheInt32, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -520,8 +518,9 @@ generic_integer_impl_scalar_operation!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -533,26 +532,22 @@ generic_integer_impl_scalar_operation!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), ); generic_integer_impl_scalar_operation!( - rust_trait: Sub(sub), + rust_trait: Add(add), implem: { |lhs: &FheInt<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_sub_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_add_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_sub( + cuda_key.key.key.scalar_add( &*lhs.ciphertext.on_gpu(streams), rhs, streams ) }); @@ -570,52 +565,32 @@ generic_integer_impl_scalar_operation!( (super::FheInt12, i16), (super::FheInt14, i16), (super::FheInt16, i16), - (super::FheInt24, i32), (super::FheInt32, i32), - (super::FheInt40, i64), - (super::FheInt48, i64), - (super::FheInt56, i64), (super::FheInt64, i64), - (super::FheInt72, i128), - (super::FheInt80, i128), - (super::FheInt88, i128), - (super::FheInt96, i128), - (super::FheInt104, i128), - (super::FheInt112, i128), - (super::FheInt120, i128), (super::FheInt128, i128), (super::FheInt160, I256), - (super::FheInt168, I256), - (super::FheInt176, I256), - (super::FheInt184, I256), - (super::FheInt192, I256), - (super::FheInt200, I256), - (super::FheInt208, I256), - (super::FheInt216, I256), - (super::FheInt224, I256), - (super::FheInt232, I256), - (super::FheInt240, I256), - (super::FheInt248, I256), (super::FheInt256, I256), (super::FheInt512, I512), (super::FheInt1024, I1024), (super::FheInt2048, I2048), ); + +#[cfg(feature = "extended-types")] generic_integer_impl_scalar_operation!( - rust_trait: Mul(mul), + rust_trait: Sub(sub), implem: { |lhs: &FheInt<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_mul_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_sub_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_mul( + cuda_key.key.key.scalar_sub( &*lhs.ciphertext.on_gpu(streams), rhs, streams ) }); @@ -625,20 +600,10 @@ generic_integer_impl_scalar_operation!( } }, fhe_and_scalar_type: - (super::FheInt2, i8), - (super::FheInt4, i8), - (super::FheInt6, i8), - (super::FheInt8, i8), - (super::FheInt10, i16), - (super::FheInt12, i16), - (super::FheInt14, i16), - (super::FheInt16, i16), (super::FheInt24, i32), - (super::FheInt32, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -646,8 +611,9 @@ generic_integer_impl_scalar_operation!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -659,26 +625,22 @@ generic_integer_impl_scalar_operation!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), ); generic_integer_impl_scalar_operation!( - rust_trait: BitAnd(bitand), + rust_trait: Sub(sub), implem: { |lhs: &FheInt<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_bitand_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_sub_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_bitand( + cuda_key.key.key.scalar_sub( &*lhs.ciphertext.on_gpu(streams), rhs, streams ) }); @@ -696,12 +658,45 @@ generic_integer_impl_scalar_operation!( (super::FheInt12, i16), (super::FheInt14, i16), (super::FheInt16, i16), - (super::FheInt24, i32), (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: Mul(mul), + implem: { + |lhs: &FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_mul_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_mul( + &*lhs.ciphertext.on_gpu(streams), rhs, streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -709,8 +704,9 @@ generic_integer_impl_scalar_operation!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -722,26 +718,22 @@ generic_integer_impl_scalar_operation!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), ); generic_integer_impl_scalar_operation!( - rust_trait: BitOr(bitor), + rust_trait: Mul(mul), implem: { |lhs: &FheInt<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_bitor_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_mul_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_bitor( + cuda_key.key.key.scalar_mul( &*lhs.ciphertext.on_gpu(streams), rhs, streams ) }); @@ -759,12 +751,45 @@ generic_integer_impl_scalar_operation!( (super::FheInt12, i16), (super::FheInt14, i16), (super::FheInt16, i16), - (super::FheInt24, i32), (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: BitAnd(bitand), + implem: { + |lhs: &FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_bitand_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_bitand( + &*lhs.ciphertext.on_gpu(streams), rhs, streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -772,8 +797,9 @@ generic_integer_impl_scalar_operation!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -785,27 +811,22 @@ generic_integer_impl_scalar_operation!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), ); generic_integer_impl_scalar_operation!( - rust_trait: BitXor(bitxor), + rust_trait: BitAnd(bitand), implem: { |lhs: &FheInt<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_bitxor_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_bitand_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, - #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_bitxor( + cuda_key.key.key.scalar_bitand( &*lhs.ciphertext.on_gpu(streams), rhs, streams ) }); @@ -823,12 +844,45 @@ generic_integer_impl_scalar_operation!( (super::FheInt12, i16), (super::FheInt14, i16), (super::FheInt16, i16), - (super::FheInt24, i32), (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: BitOr(bitor), + implem: { + |lhs: &FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_bitor_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_bitor( + &*lhs.ciphertext.on_gpu(streams), rhs, streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -836,8 +890,9 @@ generic_integer_impl_scalar_operation!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -849,27 +904,23 @@ generic_integer_impl_scalar_operation!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), ); generic_integer_impl_scalar_operation!( - rust_trait: Shl(shl), + rust_trait: BitOr(bitor), implem: { |lhs: &FheInt<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_left_shift_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_bitor_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_left_shift( - &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams + cuda_key.key.key.scalar_bitor( + &*lhs.ciphertext.on_gpu(streams), rhs, streams ) }); RadixCiphertext::Cuda(inner_result) @@ -878,20 +929,148 @@ generic_integer_impl_scalar_operation!( } }, fhe_and_scalar_type: - (super::FheInt2, u8, u16, u32, u64, u128), - (super::FheInt4, u8, u16, u32, u64, u128), - (super::FheInt6, u8, u16, u32, u64, u128), - (super::FheInt8, u8, u16, u32, u64, u128), - (super::FheInt10, u8, u16, u32, u64, u128), - (super::FheInt12, u8, u16, u32, u64, u128), - (super::FheInt14, u8, u16, u32, u64, u128), - (super::FheInt16, u8, u16, u32, u64, u128), - (super::FheInt24, u8, u16, u32, u64, u128), - (super::FheInt32, u8, u16, u32, u64, u128), + (super::FheInt2, i8), + (super::FheInt4, i8), + (super::FheInt6, i8), + (super::FheInt8, i8), + (super::FheInt10, i16), + (super::FheInt12, i16), + (super::FheInt14, i16), + (super::FheInt16, i16), + (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: BitXor(bitxor), + implem: { + |lhs: &FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_bitxor_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_bitxor( + &*lhs.ciphertext.on_gpu(streams), rhs, streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), + (super::FheInt40, i64), + (super::FheInt48, i64), + (super::FheInt56, i64), + (super::FheInt72, i128), + (super::FheInt80, i128), + (super::FheInt88, i128), + (super::FheInt96, i128), + (super::FheInt104, i128), + (super::FheInt112, i128), + (super::FheInt120, i128), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), + (super::FheInt168, I256), + (super::FheInt176, I256), + (super::FheInt184, I256), + (super::FheInt192, I256), + (super::FheInt200, I256), + (super::FheInt208, I256), + (super::FheInt216, I256), + (super::FheInt224, I256), + (super::FheInt232, I256), + (super::FheInt240, I256), + (super::FheInt248, I256), +); +generic_integer_impl_scalar_operation!( + rust_trait: BitXor(bitxor), + implem: { + |lhs: &FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_bitxor_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_bitxor( + &*lhs.ciphertext.on_gpu(streams), rhs, streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt2, i8), + (super::FheInt4, i8), + (super::FheInt6, i8), + (super::FheInt8, i8), + (super::FheInt10, i16), + (super::FheInt12, i16), + (super::FheInt14, i16), + (super::FheInt16, i16), + (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: Shl(shl), + implem: { + |lhs: &FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_left_shift_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_left_shift( + &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, u8, u16, u32, u64, u128), (super::FheInt40, u8, u16, u32, u64, u128), (super::FheInt48, u8, u16, u32, u64, u128), (super::FheInt56, u8, u16, u32, u64, u128), - (super::FheInt64, u8, u16, u32, u64, u128), (super::FheInt72, u8, u16, u32, u64, u128), (super::FheInt80, u8, u16, u32, u64, u128), (super::FheInt88, u8, u16, u32, u64, u128), @@ -899,11 +1078,9 @@ generic_integer_impl_scalar_operation!( (super::FheInt104, u8, u16, u32, u64, u128), (super::FheInt112, u8, u16, u32, u64, u128), (super::FheInt120, u8, u16, u32, u64, u128), - (super::FheInt128, u8, u16, u32, u64, u128), (super::FheInt136, u8, u16, u32, u64, u128, U256), (super::FheInt144, u8, u16, u32, u64, u128, U256), (super::FheInt152, u8, u16, u32, u64, u128, U256), - (super::FheInt160, u8, u16, u32, u64, u128, U256), (super::FheInt168, u8, u16, u32, u64, u128, U256), (super::FheInt176, u8, u16, u32, u64, u128, U256), (super::FheInt184, u8, u16, u32, u64, u128, U256), @@ -915,26 +1092,22 @@ generic_integer_impl_scalar_operation!( (super::FheInt232, u8, u16, u32, u64, u128, U256), (super::FheInt240, u8, u16, u32, u64, u128, U256), (super::FheInt248, u8, u16, u32, u64, u128, U256), - (super::FheInt256, u8, u16, u32, u64, u128, U256), - (super::FheInt512, u8, u16, u32, u64, u128, U256, U512), - (super::FheInt1024, u8, u16, u32, u64, u128, U256, U512, U1024), - (super::FheInt2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); generic_integer_impl_scalar_operation!( - rust_trait: Shr(shr), + rust_trait: Shl(shl), implem: { |lhs: &FheInt<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_right_shift_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_left_shift_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_right_shift( + cuda_key.key.key.scalar_left_shift( &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams ) }); @@ -952,12 +1125,45 @@ generic_integer_impl_scalar_operation!( (super::FheInt12, u8, u16, u32, u64, u128), (super::FheInt14, u8, u16, u32, u64, u128), (super::FheInt16, u8, u16, u32, u64, u128), - (super::FheInt24, u8, u16, u32, u64, u128), (super::FheInt32, u8, u16, u32, u64, u128), + (super::FheInt64, u8, u16, u32, u64, u128), + (super::FheInt128, u8, u16, u32, u64, u128), + (super::FheInt160, u8, u16, u32, u64, u128, U256), + (super::FheInt256, u8, u16, u32, u64, u128, U256), + (super::FheInt512, u8, u16, u32, u64, u128, U256, U512), + (super::FheInt1024, u8, u16, u32, u64, u128, U256, U512, U1024), + (super::FheInt2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: Shr(shr), + implem: { + |lhs: &FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_right_shift_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_right_shift( + &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, u8, u16, u32, u64, u128), (super::FheInt40, u8, u16, u32, u64, u128), (super::FheInt48, u8, u16, u32, u64, u128), (super::FheInt56, u8, u16, u32, u64, u128), - (super::FheInt64, u8, u16, u32, u64, u128), (super::FheInt72, u8, u16, u32, u64, u128), (super::FheInt80, u8, u16, u32, u64, u128), (super::FheInt88, u8, u16, u32, u64, u128), @@ -965,11 +1171,9 @@ generic_integer_impl_scalar_operation!( (super::FheInt104, u8, u16, u32, u64, u128), (super::FheInt112, u8, u16, u32, u64, u128), (super::FheInt120, u8, u16, u32, u64, u128), - (super::FheInt128, u8, u16, u32, u64, u128), (super::FheInt136, u8, u16, u32, u64, u128, U256), (super::FheInt144, u8, u16, u32, u64, u128, U256), (super::FheInt152, u8, u16, u32, u64, u128, U256), - (super::FheInt160, u8, u16, u32, u64, u128, U256), (super::FheInt168, u8, u16, u32, u64, u128, U256), (super::FheInt176, u8, u16, u32, u64, u128, U256), (super::FheInt184, u8, u16, u32, u64, u128, U256), @@ -981,26 +1185,22 @@ generic_integer_impl_scalar_operation!( (super::FheInt232, u8, u16, u32, u64, u128, U256), (super::FheInt240, u8, u16, u32, u64, u128, U256), (super::FheInt248, u8, u16, u32, u64, u128, U256), - (super::FheInt256, u8, u16, u32, u64, u128, U256), - (super::FheInt512, u8, u16, u32, u64, u128, U256, U512), - (super::FheInt1024, u8, u16, u32, u64, u128, U256, U512, U1024), - (super::FheInt2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); generic_integer_impl_scalar_operation!( - rust_trait: RotateLeft(rotate_left), + rust_trait: Shr(shr), implem: { |lhs: &FheInt<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_rotate_left_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_right_shift_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_rotate_left( + cuda_key.key.key.scalar_right_shift( &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams ) }); @@ -1018,12 +1218,45 @@ generic_integer_impl_scalar_operation!( (super::FheInt12, u8, u16, u32, u64, u128), (super::FheInt14, u8, u16, u32, u64, u128), (super::FheInt16, u8, u16, u32, u64, u128), - (super::FheInt24, u8, u16, u32, u64, u128), (super::FheInt32, u8, u16, u32, u64, u128), + (super::FheInt64, u8, u16, u32, u64, u128), + (super::FheInt128, u8, u16, u32, u64, u128), + (super::FheInt160, u8, u16, u32, u64, u128, U256), + (super::FheInt256, u8, u16, u32, u64, u128, U256), + (super::FheInt512, u8, u16, u32, u64, u128, U256, U512), + (super::FheInt1024, u8, u16, u32, u64, u128, U256, U512, U1024), + (super::FheInt2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: RotateLeft(rotate_left), + implem: { + |lhs: &FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_rotate_left_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_rotate_left( + &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, u8, u16, u32, u64, u128), (super::FheInt40, u8, u16, u32, u64, u128), (super::FheInt48, u8, u16, u32, u64, u128), (super::FheInt56, u8, u16, u32, u64, u128), - (super::FheInt64, u8, u16, u32, u64, u128), (super::FheInt72, u8, u16, u32, u64, u128), (super::FheInt80, u8, u16, u32, u64, u128), (super::FheInt88, u8, u16, u32, u64, u128), @@ -1031,11 +1264,9 @@ generic_integer_impl_scalar_operation!( (super::FheInt104, u8, u16, u32, u64, u128), (super::FheInt112, u8, u16, u32, u64, u128), (super::FheInt120, u8, u16, u32, u64, u128), - (super::FheInt128, u8, u16, u32, u64, u128), (super::FheInt136, u8, u16, u32, u64, u128, U256), (super::FheInt144, u8, u16, u32, u64, u128, U256), (super::FheInt152, u8, u16, u32, u64, u128, U256), - (super::FheInt160, u8, u16, u32, u64, u128, U256), (super::FheInt168, u8, u16, u32, u64, u128, U256), (super::FheInt176, u8, u16, u32, u64, u128, U256), (super::FheInt184, u8, u16, u32, u64, u128, U256), @@ -1047,26 +1278,22 @@ generic_integer_impl_scalar_operation!( (super::FheInt232, u8, u16, u32, u64, u128, U256), (super::FheInt240, u8, u16, u32, u64, u128, U256), (super::FheInt248, u8, u16, u32, u64, u128, U256), - (super::FheInt256, u8, u16, u32, u64, u128, U256), - (super::FheInt512, u8, u16, u32, u64, u128, U256, U512), - (super::FheInt1024, u8, u16, u32, u64, u128, U256, U512, U1024), - (super::FheInt2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); generic_integer_impl_scalar_operation!( - rust_trait: RotateRight(rotate_right), + rust_trait: RotateLeft(rotate_left), implem: { |lhs: &FheInt<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_rotate_right_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_rotate_left_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_rotate_right( + cuda_key.key.key.scalar_rotate_left( &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams ) }); @@ -1084,12 +1311,45 @@ generic_integer_impl_scalar_operation!( (super::FheInt12, u8, u16, u32, u64, u128), (super::FheInt14, u8, u16, u32, u64, u128), (super::FheInt16, u8, u16, u32, u64, u128), - (super::FheInt24, u8, u16, u32, u64, u128), (super::FheInt32, u8, u16, u32, u64, u128), + (super::FheInt64, u8, u16, u32, u64, u128), + (super::FheInt128, u8, u16, u32, u64, u128), + (super::FheInt160, u8, u16, u32, u64, u128, U256), + (super::FheInt256, u8, u16, u32, u64, u128, U256), + (super::FheInt512, u8, u16, u32, u64, u128, U256, U512), + (super::FheInt1024, u8, u16, u32, u64, u128, U256, U512, U1024), + (super::FheInt2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: RotateRight(rotate_right), + implem: { + |lhs: &FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_rotate_right_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_rotate_right( + &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, u8, u16, u32, u64, u128), (super::FheInt40, u8, u16, u32, u64, u128), (super::FheInt48, u8, u16, u32, u64, u128), (super::FheInt56, u8, u16, u32, u64, u128), - (super::FheInt64, u8, u16, u32, u64, u128), (super::FheInt72, u8, u16, u32, u64, u128), (super::FheInt80, u8, u16, u32, u64, u128), (super::FheInt88, u8, u16, u32, u64, u128), @@ -1097,11 +1357,9 @@ generic_integer_impl_scalar_operation!( (super::FheInt104, u8, u16, u32, u64, u128), (super::FheInt112, u8, u16, u32, u64, u128), (super::FheInt120, u8, u16, u32, u64, u128), - (super::FheInt128, u8, u16, u32, u64, u128), (super::FheInt136, u8, u16, u32, u64, u128, U256), (super::FheInt144, u8, u16, u32, u64, u128, U256), (super::FheInt152, u8, u16, u32, u64, u128, U256), - (super::FheInt160, u8, u16, u32, u64, u128, U256), (super::FheInt168, u8, u16, u32, u64, u128, U256), (super::FheInt176, u8, u16, u32, u64, u128, U256), (super::FheInt184, u8, u16, u32, u64, u128, U256), @@ -1113,11 +1371,100 @@ generic_integer_impl_scalar_operation!( (super::FheInt232, u8, u16, u32, u64, u128, U256), (super::FheInt240, u8, u16, u32, u64, u128, U256), (super::FheInt248, u8, u16, u32, u64, u128, U256), +); +generic_integer_impl_scalar_operation!( + rust_trait: RotateRight(rotate_right), + implem: { + |lhs: &FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_rotate_right_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_rotate_right( + &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt2, u8, u16, u32, u64, u128), + (super::FheInt4, u8, u16, u32, u64, u128), + (super::FheInt6, u8, u16, u32, u64, u128), + (super::FheInt8, u8, u16, u32, u64, u128), + (super::FheInt10, u8, u16, u32, u64, u128), + (super::FheInt12, u8, u16, u32, u64, u128), + (super::FheInt14, u8, u16, u32, u64, u128), + (super::FheInt16, u8, u16, u32, u64, u128), + (super::FheInt32, u8, u16, u32, u64, u128), + (super::FheInt64, u8, u16, u32, u64, u128), + (super::FheInt128, u8, u16, u32, u64, u128), + (super::FheInt160, u8, u16, u32, u64, u128, U256), (super::FheInt256, u8, u16, u32, u64, u128, U256), (super::FheInt512, u8, u16, u32, u64, u128, U256, U512), (super::FheInt1024, u8, u16, u32, u64, u128, U256, U512, U1024), (super::FheInt2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: Div(div), + implem: { + |lhs: &FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .signed_scalar_div_parallelized(&lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.signed_scalar_div( + &lhs.ciphertext.on_gpu(streams), rhs, streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), + (super::FheInt40, i64), + (super::FheInt48, i64), + (super::FheInt56, i64), + (super::FheInt72, i128), + (super::FheInt80, i128), + (super::FheInt88, i128), + (super::FheInt96, i128), + (super::FheInt104, i128), + (super::FheInt112, i128), + (super::FheInt120, i128), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), + (super::FheInt168, I256), + (super::FheInt176, I256), + (super::FheInt184, I256), + (super::FheInt192, I256), + (super::FheInt200, I256), + (super::FheInt208, I256), + (super::FheInt216, I256), + (super::FheInt224, I256), + (super::FheInt232, I256), + (super::FheInt240, I256), + (super::FheInt248, I256), +); generic_integer_impl_scalar_operation!( rust_trait: Div(div), implem: { @@ -1150,12 +1497,45 @@ generic_integer_impl_scalar_operation!( (super::FheInt12, i16), (super::FheInt14, i16), (super::FheInt16, i16), - (super::FheInt24, i32), (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: Rem(rem), + implem: { + |lhs: &FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .signed_scalar_rem_parallelized(&lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.signed_scalar_rem( + &lhs.ciphertext.on_gpu(streams), rhs, streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -1163,8 +1543,9 @@ generic_integer_impl_scalar_operation!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -1176,10 +1557,6 @@ generic_integer_impl_scalar_operation!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), ); generic_integer_impl_scalar_operation!( rust_trait: Rem(rem), @@ -1213,12 +1590,31 @@ generic_integer_impl_scalar_operation!( (super::FheInt12, i16), (super::FheInt14, i16), (super::FheInt16, i16), - (super::FheInt24, i32), (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_left_operation!( + rust_trait: Add(add), + implem: { + |lhs, rhs: &FheInt<_>| { + // `+` is commutative + let result: FheInt<_> = rhs + lhs; + result.ciphertext + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -1226,8 +1622,9 @@ generic_integer_impl_scalar_operation!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -1239,12 +1636,7 @@ generic_integer_impl_scalar_operation!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), ); - generic_integer_impl_scalar_left_operation!( rust_trait: Add(add), implem: { @@ -1284,12 +1676,50 @@ generic_integer_impl_scalar_left_operation!( /// assert_eq!(result, 23i16 + 3i16); /// ``` i16), - (super::FheInt24, i32), (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_left_operation!( + rust_trait: Sub(sub), + implem: { + |lhs, rhs: &FheInt<_>| { + // `-` is not commutative, so we resort to converting to trivial + // which should give same perf + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let mut result = cpu_key + .pbs_key() + .create_trivial_radix(lhs, rhs.ciphertext.on_cpu().blocks().len()); + cpu_key + .pbs_key() + .sub_assign_parallelized(&mut result, &*rhs.ciphertext.on_cpu()); + RadixCiphertext::Cpu(result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(_cuda_key) => { + with_thread_local_cuda_streams(|_stream| { + panic!("Cuda devices do not support subtracting a chiphertext to a clear") +// let mut result = cuda_key.key.key.create_signed_trivial_radix(lhs, rhs.ciphertext.on_gpu(streams).ciphertext.info.blocks.len(), streams); +// cuda_key.key.key.sub_assign(&mut result, &rhs.ciphertext.on_gpu(streams), streams); +// RadixCiphertext::Cuda(result) + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -1297,8 +1727,9 @@ generic_integer_impl_scalar_left_operation!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -1310,11 +1741,6 @@ generic_integer_impl_scalar_left_operation!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), - ); generic_integer_impl_scalar_left_operation!( rust_trait: Sub(sub), @@ -1374,12 +1800,31 @@ generic_integer_impl_scalar_left_operation!( /// assert_eq!(result, 23i16 - 3i16); /// ``` i16), - (super::FheInt24, i32), (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_left_operation!( + rust_trait: Mul(mul), + implem: { + |lhs, rhs: &FheInt<_>| { + // `*` is commutative + let result: FheInt<_> = rhs * lhs; + result.ciphertext + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -1387,8 +1832,9 @@ generic_integer_impl_scalar_left_operation!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -1400,11 +1846,6 @@ generic_integer_impl_scalar_left_operation!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), - ); generic_integer_impl_scalar_left_operation!( rust_trait: Mul(mul), @@ -1445,12 +1886,31 @@ generic_integer_impl_scalar_left_operation!( /// assert_eq!(result, 23i16 * 3i16); /// ``` i16), - (super::FheInt24, i32), (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_left_operation!( + rust_trait: BitAnd(bitand), + implem: { + |lhs, rhs: &FheInt<_>| { + // `&` is commutative + let result: FheInt<_> = rhs & lhs; + result.ciphertext + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -1458,8 +1918,9 @@ generic_integer_impl_scalar_left_operation!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -1471,10 +1932,6 @@ generic_integer_impl_scalar_left_operation!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), ); generic_integer_impl_scalar_left_operation!( rust_trait: BitAnd(bitand), @@ -1513,12 +1970,31 @@ generic_integer_impl_scalar_left_operation!( /// assert_eq!(result, 23i16 & 3i16); /// ``` i16), - (super::FheInt24, i32), (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_left_operation!( + rust_trait: BitOr(bitor), + implem: { + |lhs, rhs: &FheInt<_>| { + // `|` is commutative + let result: FheInt<_> = rhs | lhs; + result.ciphertext + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -1526,8 +2002,9 @@ generic_integer_impl_scalar_left_operation!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -1539,11 +2016,6 @@ generic_integer_impl_scalar_left_operation!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), - ); generic_integer_impl_scalar_left_operation!( rust_trait: BitOr(bitor), @@ -1582,12 +2054,31 @@ generic_integer_impl_scalar_left_operation!( /// assert_eq!(result, 23i16 | 3i16); /// ``` i16), - (super::FheInt24, i32), (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_left_operation!( + rust_trait: BitXor(bitxor), + implem: { + |lhs, rhs: &FheInt<_>| { + // `^` is commutative + let result: FheInt<_> = rhs ^ lhs; + result.ciphertext + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -1595,8 +2086,9 @@ generic_integer_impl_scalar_left_operation!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -1608,11 +2100,6 @@ generic_integer_impl_scalar_left_operation!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), - ); generic_integer_impl_scalar_left_operation!( rust_trait: BitXor(bitxor), @@ -1624,39 +2111,69 @@ generic_integer_impl_scalar_left_operation!( } }, fhe_and_scalar_type: - (super::FheInt2, i8), - (super::FheInt4, i8), - (super::FheInt6, i8), - (super::FheInt8, i8), - (super::FheInt10, i16), - (super::FheInt12, i16), - (super::FheInt14, i16), - (super::FheInt16, - /// Performs a bitwise 'xor' between a clear and [super::FheInt16] - /// - /// # Example - /// - /// ```rust - /// use tfhe::prelude::*; - /// use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheInt16}; - /// - /// let (client_key, server_key) = generate_keys(ConfigBuilder::default()); - /// set_server_key(server_key); - /// - /// let a = 23i16; - /// let b = FheInt16::encrypt(3i16, &client_key); - /// - /// let result = a ^ &b; - /// let result: i16 = result.decrypt(&client_key); - /// assert_eq!(result, 23i16 ^ 3i16); - /// ``` - i16), + (super::FheInt2, i8), + (super::FheInt4, i8), + (super::FheInt6, i8), + (super::FheInt8, i8), + (super::FheInt10, i16), + (super::FheInt12, i16), + (super::FheInt14, i16), + (super::FheInt16, + /// Performs a bitwise 'xor' between a clear and [super::FheInt16] + /// + /// # Example + /// + /// ```rust + /// use tfhe::prelude::*; + /// use tfhe::{generate_keys, set_server_key, ConfigBuilder, FheInt16}; + /// + /// let (client_key, server_key) = generate_keys(ConfigBuilder::default()); + /// set_server_key(server_key); + /// + /// let a = 23i16; + /// let b = FheInt16::encrypt(3i16, &client_key); + /// + /// let result = a ^ &b; + /// let result: i16 = result.decrypt(&client_key); + /// assert_eq!(result, 23i16 ^ 3i16); + /// ``` + i16), + (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: AddAssign(add_assign), + implem: { + |lhs: &mut FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_add_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_add_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: (super::FheInt24, i32), - (super::FheInt32, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -1664,8 +2181,9 @@ generic_integer_impl_scalar_left_operation!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -1677,13 +2195,7 @@ generic_integer_impl_scalar_left_operation!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), - ); - generic_integer_impl_scalar_operation_assign!( rust_trait: AddAssign(add_assign), implem: { @@ -1735,12 +2247,42 @@ generic_integer_impl_scalar_operation_assign!( /// assert_eq!(result, 23i16 + 3i16); /// ``` i16), - (super::FheInt24, i32), (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: SubAssign(sub_assign), + implem: { + |lhs: &mut FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_sub_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_sub_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -1748,8 +2290,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -1761,11 +2304,6 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), - ); generic_integer_impl_scalar_operation_assign!( rust_trait: SubAssign(sub_assign), @@ -1796,12 +2334,42 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt12, i16), (super::FheInt14, i16), (super::FheInt16, i16), - (super::FheInt24, i32), (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: MulAssign(mul_assign), + implem: { + |lhs: &mut FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_mul_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_mul_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -1809,8 +2377,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -1822,10 +2391,6 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), ); generic_integer_impl_scalar_operation_assign!( rust_trait: MulAssign(mul_assign), @@ -1856,12 +2421,42 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt12, i16), (super::FheInt14, i16), (super::FheInt16, i16), - (super::FheInt24, i32), (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: BitAndAssign(bitand_assign), + implem: { + |lhs: &mut FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_bitand_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_bitand_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -1869,8 +2464,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -1882,10 +2478,6 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), ); generic_integer_impl_scalar_operation_assign!( rust_trait: BitAndAssign(bitand_assign), @@ -1916,12 +2508,42 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt12, i16), (super::FheInt14, i16), (super::FheInt16, i16), - (super::FheInt24, i32), (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: BitOrAssign(bitor_assign), + implem: { + |lhs: &mut FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_bitor_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_bitor_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -1929,8 +2551,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -1942,10 +2565,6 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), ); generic_integer_impl_scalar_operation_assign!( rust_trait: BitOrAssign(bitor_assign), @@ -1976,12 +2595,42 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt12, i16), (super::FheInt14, i16), (super::FheInt16, i16), - (super::FheInt24, i32), (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), + (super::FheInt256, I256), + (super::FheInt512, I512), + (super::FheInt1024, I1024), + (super::FheInt2048, I2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: BitXorAssign(bitxor_assign), + implem: { + |lhs: &mut FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_bitxor_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_bitxor_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -1989,8 +2638,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -2002,10 +2652,6 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), - (super::FheInt256, I256), - (super::FheInt512, I512), - (super::FheInt1024, I1024), - (super::FheInt2048, I2048), ); generic_integer_impl_scalar_operation_assign!( rust_trait: BitXorAssign(bitxor_assign), @@ -2036,37 +2682,17 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt12, i16), (super::FheInt14, i16), (super::FheInt16, i16), - (super::FheInt24, i32), (super::FheInt32, i32), - (super::FheInt40, i64), - (super::FheInt48, i64), - (super::FheInt56, i64), (super::FheInt64, i64), - (super::FheInt72, i128), - (super::FheInt80, i128), - (super::FheInt88, i128), - (super::FheInt96, i128), - (super::FheInt104, i128), - (super::FheInt112, i128), - (super::FheInt120, i128), (super::FheInt128, i128), (super::FheInt160, I256), - (super::FheInt168, I256), - (super::FheInt176, I256), - (super::FheInt184, I256), - (super::FheInt192, I256), - (super::FheInt200, I256), - (super::FheInt208, I256), - (super::FheInt216, I256), - (super::FheInt224, I256), - (super::FheInt232, I256), - (super::FheInt240, I256), - (super::FheInt248, I256), (super::FheInt256, I256), (super::FheInt512, I512), (super::FheInt1024, I1024), (super::FheInt2048, I2048), ); + +#[cfg(feature = "extended-types")] generic_integer_impl_scalar_operation_assign!( rust_trait: ShlAssign(shl_assign), implem: { @@ -2088,20 +2714,10 @@ generic_integer_impl_scalar_operation_assign!( } }, fhe_and_scalar_type: - (super::FheInt2, u8, u16, u32, u64, u128), - (super::FheInt4, u8, u16, u32, u64, u128), - (super::FheInt6, u8, u16, u32, u64, u128), - (super::FheInt8, u8, u16, u32, u64, u128), - (super::FheInt10, u8, u16, u32, u64, u128), - (super::FheInt12, u8, u16, u32, u64, u128), - (super::FheInt14, u8, u16, u32, u64, u128), - (super::FheInt16, u8, u16, u32, u64, u128), (super::FheInt24, u8, u16, u32, u64, u128), - (super::FheInt32, u8, u16, u32, u64, u128), (super::FheInt40, u8, u16, u32, u64, u128), (super::FheInt48, u8, u16, u32, u64, u128), (super::FheInt56, u8, u16, u32, u64, u128), - (super::FheInt64, u8, u16, u32, u64, u128), (super::FheInt72, u8, u16, u32, u64, u128), (super::FheInt80, u8, u16, u32, u64, u128), (super::FheInt88, u8, u16, u32, u64, u128), @@ -2109,11 +2725,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt104, u8, u16, u32, u64, u128), (super::FheInt112, u8, u16, u32, u64, u128), (super::FheInt120, u8, u16, u32, u64, u128), - (super::FheInt128, u8, u16, u32, u64, u128), (super::FheInt136, u8, u16, u32, u64, u128, U256), (super::FheInt144, u8, u16, u32, u64, u128, U256), (super::FheInt152, u8, u16, u32, u64, u128, U256), - (super::FheInt160, u8, u16, u32, u64, u128, U256), (super::FheInt168, u8, u16, u32, u64, u128, U256), (super::FheInt176, u8, u16, u32, u64, u128, U256), (super::FheInt184, u8, u16, u32, u64, u128, U256), @@ -2125,26 +2739,22 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt232, u8, u16, u32, u64, u128, U256), (super::FheInt240, u8, u16, u32, u64, u128, U256), (super::FheInt248, u8, u16, u32, u64, u128, U256), - (super::FheInt256, u8, u16, u32, u64, u128, U256), - (super::FheInt512, u8, u16, u32, u64, u128, U256, U512), - (super::FheInt1024, u8, u16, u32, u64, u128, U256, U512, U1024), - (super::FheInt2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); generic_integer_impl_scalar_operation_assign!( - rust_trait: ShrAssign(shr_assign), + rust_trait: ShlAssign(shl_assign), implem: { |lhs: &mut FheInt<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { cpu_key .pbs_key() - .scalar_right_shift_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + .scalar_left_shift_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { with_thread_local_cuda_streams(|streams| { cuda_key.key.key - .scalar_right_shift_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + .scalar_left_shift_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); }) } }) @@ -2159,12 +2769,42 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt12, u8, u16, u32, u64, u128), (super::FheInt14, u8, u16, u32, u64, u128), (super::FheInt16, u8, u16, u32, u64, u128), - (super::FheInt24, u8, u16, u32, u64, u128), (super::FheInt32, u8, u16, u32, u64, u128), + (super::FheInt64, u8, u16, u32, u64, u128), + (super::FheInt128, u8, u16, u32, u64, u128), + (super::FheInt160, u8, u16, u32, u64, u128, U256), + (super::FheInt256, u8, u16, u32, u64, u128, U256), + (super::FheInt512, u8, u16, u32, u64, u128, U256, U512), + (super::FheInt1024, u8, u16, u32, u64, u128, U256, U512, U1024), + (super::FheInt2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: ShrAssign(shr_assign), + implem: { + |lhs: &mut FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_right_shift_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_right_shift_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, u8, u16, u32, u64, u128), (super::FheInt40, u8, u16, u32, u64, u128), (super::FheInt48, u8, u16, u32, u64, u128), (super::FheInt56, u8, u16, u32, u64, u128), - (super::FheInt64, u8, u16, u32, u64, u128), (super::FheInt72, u8, u16, u32, u64, u128), (super::FheInt80, u8, u16, u32, u64, u128), (super::FheInt88, u8, u16, u32, u64, u128), @@ -2172,11 +2812,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt104, u8, u16, u32, u64, u128), (super::FheInt112, u8, u16, u32, u64, u128), (super::FheInt120, u8, u16, u32, u64, u128), - (super::FheInt128, u8, u16, u32, u64, u128), (super::FheInt136, u8, u16, u32, u64, u128, U256), (super::FheInt144, u8, u16, u32, u64, u128, U256), (super::FheInt152, u8, u16, u32, u64, u128, U256), - (super::FheInt160, u8, u16, u32, u64, u128, U256), (super::FheInt168, u8, u16, u32, u64, u128, U256), (super::FheInt176, u8, u16, u32, u64, u128, U256), (super::FheInt184, u8, u16, u32, u64, u128, U256), @@ -2188,26 +2826,22 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt232, u8, u16, u32, u64, u128, U256), (super::FheInt240, u8, u16, u32, u64, u128, U256), (super::FheInt248, u8, u16, u32, u64, u128, U256), - (super::FheInt256, u8, u16, u32, u64, u128, U256), - (super::FheInt512, u8, u16, u32, u64, u128, U256, U512), - (super::FheInt1024, u8, u16, u32, u64, u128, U256, U512, U1024), - (super::FheInt2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); generic_integer_impl_scalar_operation_assign!( - rust_trait: RotateLeftAssign(rotate_left_assign), + rust_trait: ShrAssign(shr_assign), implem: { |lhs: &mut FheInt<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { cpu_key .pbs_key() - .scalar_rotate_left_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + .scalar_right_shift_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { with_thread_local_cuda_streams(|streams| { cuda_key.key.key - .scalar_rotate_left_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + .scalar_right_shift_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); }) } }) @@ -2222,12 +2856,42 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt12, u8, u16, u32, u64, u128), (super::FheInt14, u8, u16, u32, u64, u128), (super::FheInt16, u8, u16, u32, u64, u128), - (super::FheInt24, u8, u16, u32, u64, u128), (super::FheInt32, u8, u16, u32, u64, u128), + (super::FheInt64, u8, u16, u32, u64, u128), + (super::FheInt128, u8, u16, u32, u64, u128), + (super::FheInt160, u8, u16, u32, u64, u128, U256), + (super::FheInt256, u8, u16, u32, u64, u128, U256), + (super::FheInt512, u8, u16, u32, u64, u128, U256, U512), + (super::FheInt1024, u8, u16, u32, u64, u128, U256, U512, U1024), + (super::FheInt2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: RotateLeftAssign(rotate_left_assign), + implem: { + |lhs: &mut FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_rotate_left_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_rotate_left_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, u8, u16, u32, u64, u128), (super::FheInt40, u8, u16, u32, u64, u128), (super::FheInt48, u8, u16, u32, u64, u128), (super::FheInt56, u8, u16, u32, u64, u128), - (super::FheInt64, u8, u16, u32, u64, u128), (super::FheInt72, u8, u16, u32, u64, u128), (super::FheInt80, u8, u16, u32, u64, u128), (super::FheInt88, u8, u16, u32, u64, u128), @@ -2235,11 +2899,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt104, u8, u16, u32, u64, u128), (super::FheInt112, u8, u16, u32, u64, u128), (super::FheInt120, u8, u16, u32, u64, u128), - (super::FheInt128, u8, u16, u32, u64, u128), (super::FheInt136, u8, u16, u32, u64, u128, U256), (super::FheInt144, u8, u16, u32, u64, u128, U256), (super::FheInt152, u8, u16, u32, u64, u128, U256), - (super::FheInt160, u8, u16, u32, u64, u128, U256), (super::FheInt168, u8, u16, u32, u64, u128, U256), (super::FheInt176, u8, u16, u32, u64, u128, U256), (super::FheInt184, u8, u16, u32, u64, u128, U256), @@ -2251,26 +2913,22 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt232, u8, u16, u32, u64, u128, U256), (super::FheInt240, u8, u16, u32, u64, u128, U256), (super::FheInt248, u8, u16, u32, u64, u128, U256), - (super::FheInt256, u8, u16, u32, u64, u128, U256), - (super::FheInt512, u8, u16, u32, u64, u128, U256, U512), - (super::FheInt1024, u8, u16, u32, u64, u128, U256, U512, U1024), - (super::FheInt2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); generic_integer_impl_scalar_operation_assign!( - rust_trait: RotateRightAssign(rotate_right_assign), + rust_trait: RotateLeftAssign(rotate_left_assign), implem: { |lhs: &mut FheInt<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { cpu_key .pbs_key() - .scalar_rotate_right_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + .scalar_rotate_left_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { with_thread_local_cuda_streams(|streams| { cuda_key.key.key - .scalar_rotate_right_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + .scalar_rotate_left_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); }) } }) @@ -2285,12 +2943,42 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt12, u8, u16, u32, u64, u128), (super::FheInt14, u8, u16, u32, u64, u128), (super::FheInt16, u8, u16, u32, u64, u128), - (super::FheInt24, u8, u16, u32, u64, u128), (super::FheInt32, u8, u16, u32, u64, u128), + (super::FheInt64, u8, u16, u32, u64, u128), + (super::FheInt128, u8, u16, u32, u64, u128), + (super::FheInt160, u8, u16, u32, u64, u128, U256), + (super::FheInt256, u8, u16, u32, u64, u128, U256), + (super::FheInt512, u8, u16, u32, u64, u128, U256, U512), + (super::FheInt1024, u8, u16, u32, u64, u128, U256, U512, U1024), + (super::FheInt2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: RotateRightAssign(rotate_right_assign), + implem: { + |lhs: &mut FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_rotate_right_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_rotate_right_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt24, u8, u16, u32, u64, u128), (super::FheInt40, u8, u16, u32, u64, u128), (super::FheInt48, u8, u16, u32, u64, u128), (super::FheInt56, u8, u16, u32, u64, u128), - (super::FheInt64, u8, u16, u32, u64, u128), (super::FheInt72, u8, u16, u32, u64, u128), (super::FheInt80, u8, u16, u32, u64, u128), (super::FheInt88, u8, u16, u32, u64, u128), @@ -2298,11 +2986,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt104, u8, u16, u32, u64, u128), (super::FheInt112, u8, u16, u32, u64, u128), (super::FheInt120, u8, u16, u32, u64, u128), - (super::FheInt128, u8, u16, u32, u64, u128), (super::FheInt136, u8, u16, u32, u64, u128, U256), (super::FheInt144, u8, u16, u32, u64, u128, U256), (super::FheInt152, u8, u16, u32, u64, u128, U256), - (super::FheInt160, u8, u16, u32, u64, u128, U256), (super::FheInt168, u8, u16, u32, u64, u128, U256), (super::FheInt176, u8, u16, u32, u64, u128, U256), (super::FheInt184, u8, u16, u32, u64, u128, U256), @@ -2314,11 +3000,47 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt232, u8, u16, u32, u64, u128, U256), (super::FheInt240, u8, u16, u32, u64, u128, U256), (super::FheInt248, u8, u16, u32, u64, u128, U256), +); +generic_integer_impl_scalar_operation_assign!( + rust_trait: RotateRightAssign(rotate_right_assign), + implem: { + |lhs: &mut FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_rotate_right_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_rotate_right_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt2, u8, u16, u32, u64, u128), + (super::FheInt4, u8, u16, u32, u64, u128), + (super::FheInt6, u8, u16, u32, u64, u128), + (super::FheInt8, u8, u16, u32, u64, u128), + (super::FheInt10, u8, u16, u32, u64, u128), + (super::FheInt12, u8, u16, u32, u64, u128), + (super::FheInt14, u8, u16, u32, u64, u128), + (super::FheInt16, u8, u16, u32, u64, u128), + (super::FheInt32, u8, u16, u32, u64, u128), + (super::FheInt64, u8, u16, u32, u64, u128), + (super::FheInt128, u8, u16, u32, u64, u128), + (super::FheInt160, u8, u16, u32, u64, u128, U256), (super::FheInt256, u8, u16, u32, u64, u128, U256), (super::FheInt512, u8, u16, u32, u64, u128, U256, U512), (super::FheInt1024, u8, u16, u32, u64, u128, U256, U512, U1024), (super::FheInt2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); + +#[cfg(feature = "extended-types")] generic_integer_impl_scalar_operation_assign!( rust_trait: DivAssign(div_assign), implem: { @@ -2337,13 +3059,10 @@ generic_integer_impl_scalar_operation_assign!( } }, fhe_and_scalar_type: - (super::FheInt16, i16), (super::FheInt24, i32), - (super::FheInt32, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -2351,8 +3070,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -2364,11 +3084,44 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), +); +generic_integer_impl_scalar_operation_assign!( + rust_trait: DivAssign(div_assign), + implem: { + |lhs: &mut FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .signed_scalar_div_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(_) => { + panic!("DivAssign '/=' with clear value is not yet supported by Cuda devices") + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt2, i8), + (super::FheInt4, i8), + (super::FheInt6, i8), + (super::FheInt8, i8), + (super::FheInt10, i16), + (super::FheInt12, i16), + (super::FheInt14, i16), + (super::FheInt16, i16), + (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), (super::FheInt256, I256), (super::FheInt512, I512), (super::FheInt1024, I1024), (super::FheInt2048, I2048), ); + +#[cfg(feature = "extended-types")] generic_integer_impl_scalar_operation_assign!( rust_trait: RemAssign(rem_assign), implem: { @@ -2387,13 +3140,10 @@ generic_integer_impl_scalar_operation_assign!( } }, fhe_and_scalar_type: - (super::FheInt16, i16), (super::FheInt24, i32), - (super::FheInt32, i32), (super::FheInt40, i64), (super::FheInt48, i64), (super::FheInt56, i64), - (super::FheInt64, i64), (super::FheInt72, i128), (super::FheInt80, i128), (super::FheInt88, i128), @@ -2401,8 +3151,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt104, i128), (super::FheInt112, i128), (super::FheInt120, i128), - (super::FheInt128, i128), - (super::FheInt160, I256), + (super::FheInt136, I256), + (super::FheInt144, I256), + (super::FheInt152, I256), (super::FheInt168, I256), (super::FheInt176, I256), (super::FheInt184, I256), @@ -2414,6 +3165,37 @@ generic_integer_impl_scalar_operation_assign!( (super::FheInt232, I256), (super::FheInt240, I256), (super::FheInt248, I256), +); +generic_integer_impl_scalar_operation_assign!( + rust_trait: RemAssign(rem_assign), + implem: { + |lhs: &mut FheInt<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .signed_scalar_rem_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(_) => { + panic!("RemAssign '%=' with clear value is not yet supported by Cuda devices") + } + }) + } + }, + fhe_and_scalar_type: + (super::FheInt2, i8), + (super::FheInt4, i8), + (super::FheInt6, i8), + (super::FheInt8, i8), + (super::FheInt10, i16), + (super::FheInt12, i16), + (super::FheInt14, i16), + (super::FheInt16, i16), + (super::FheInt32, i32), + (super::FheInt64, i64), + (super::FheInt128, i128), + (super::FheInt160, I256), (super::FheInt256, I256), (super::FheInt512, I512), (super::FheInt1024, I1024), diff --git a/tfhe/src/high_level_api/integers/signed/static_.rs b/tfhe/src/high_level_api/integers/signed/static_.rs index c65945b08c..4a1cba4ea7 100644 --- a/tfhe/src/high_level_api/integers/signed/static_.rs +++ b/tfhe/src/high_level_api/integers/signed/static_.rs @@ -97,198 +97,206 @@ static_int_type! { static_int_type! { Signed { - num_bits: 24, + num_bits: 32, } } static_int_type! { Signed { - num_bits: 32, + num_bits: 64, } } static_int_type! { Signed { - num_bits: 40, + num_bits: 128, } } static_int_type! { Signed { - num_bits: 48, + num_bits: 160, } } static_int_type! { Signed { - num_bits: 56, + num_bits: 256, } } static_int_type! { Signed { - num_bits: 64, + num_bits: 512, } } static_int_type! { Signed { - num_bits: 72, + num_bits: 1024, } } static_int_type! { Signed { - num_bits: 80, + num_bits: 2048, } } -static_int_type! { - Signed { - num_bits: 88, +#[cfg(feature = "extended-types")] +pub use extended::*; + +#[cfg(feature = "extended-types")] +mod extended { + use super::*; + + static_int_type! { + Signed { + num_bits: 24, + } } -} -static_int_type! { - Signed { - num_bits: 96, + static_int_type! { + Signed { + num_bits: 40, + } } -} -static_int_type! { - Signed { - num_bits: 104, + static_int_type! { + Signed { + num_bits: 48, + } } -} -static_int_type! { - Signed { - num_bits: 112, + static_int_type! { + Signed { + num_bits: 56, + } } -} -static_int_type! { - Signed { - num_bits: 120, + static_int_type! { + Signed { + num_bits: 72, + } } -} -static_int_type! { - Signed { - num_bits: 128, + static_int_type! { + Signed { + num_bits: 80, + } } -} -static_int_type! { - Signed { - num_bits: 136, + static_int_type! { + Signed { + num_bits: 88, + } } -} -static_int_type! { - Signed { - num_bits: 144, + static_int_type! { + Signed { + num_bits: 96, + } } -} -static_int_type! { - Signed { - num_bits: 152, + static_int_type! { + Signed { + num_bits: 104, + } } -} -static_int_type! { - Signed { - num_bits: 160, + static_int_type! { + Signed { + num_bits: 112, + } } -} -static_int_type! { - Signed { - num_bits: 168, + static_int_type! { + Signed { + num_bits: 120, + } } -} -static_int_type! { - Signed { - num_bits: 176, + static_int_type! { + Signed { + num_bits: 136, + } } -} -static_int_type! { - Signed { - num_bits: 184, + static_int_type! { + Signed { + num_bits: 144, + } } -} -static_int_type! { - Signed { - num_bits: 192, + static_int_type! { + Signed { + num_bits: 152, + } } -} -static_int_type! { - Signed { - num_bits: 200, + static_int_type! { + Signed { + num_bits: 168, + } } -} -static_int_type! { - Signed { - num_bits: 208, + static_int_type! { + Signed { + num_bits: 176, + } } -} -static_int_type! { - Signed { - num_bits: 216, + static_int_type! { + Signed { + num_bits: 184, + } } -} -static_int_type! { - Signed { - num_bits: 224, + static_int_type! { + Signed { + num_bits: 192, + } } -} -static_int_type! { - Signed { - num_bits: 232, + static_int_type! { + Signed { + num_bits: 200, + } } -} -static_int_type! { - Signed { - num_bits: 240, + static_int_type! { + Signed { + num_bits: 208, + } } -} -static_int_type! { - Signed { - num_bits: 248, + static_int_type! { + Signed { + num_bits: 216, + } } -} -static_int_type! { - Signed { - num_bits: 256, + static_int_type! { + Signed { + num_bits: 224, + } } -} -static_int_type! { - Signed { - num_bits: 512, + static_int_type! { + Signed { + num_bits: 232, + } } -} -static_int_type! { - Signed { - num_bits: 1024, + static_int_type! { + Signed { + num_bits: 240, + } } -} -static_int_type! { - Signed { - num_bits: 2048, + static_int_type! { + Signed { + num_bits: 248, + } } } diff --git a/tfhe/src/high_level_api/integers/unsigned/mod.rs b/tfhe/src/high_level_api/integers/unsigned/mod.rs index 2995dcaf1a..f82f946613 100644 --- a/tfhe/src/high_level_api/integers/unsigned/mod.rs +++ b/tfhe/src/high_level_api/integers/unsigned/mod.rs @@ -3,11 +3,17 @@ pub use base::{FheUint, FheUintId}; expand_pub_use_fhe_type!( pub use static_{ FheUint2, FheUint4, FheUint6, FheUint8, FheUint10, FheUint12, FheUint14, FheUint16, - FheUint24, FheUint32, FheUint40, FheUint48, FheUint56, FheUint64, FheUint72, FheUint80, - FheUint88, FheUint96, FheUint104, FheUint112, FheUint120, FheUint128, FheUint136, - FheUint144, FheUint152, FheUint160, FheUint168, FheUint176, FheUint184, FheUint192, - FheUint200, FheUint208, FheUint216, FheUint224, FheUint232, FheUint240, FheUint248, - FheUint256, FheUint512, FheUint1024, FheUint2048, + FheUint32, FheUint64, FheUint128, FheUint160, FheUint256, FheUint512, FheUint1024, + FheUint2048, + }; +); +#[cfg(feature = "extended-types")] +expand_pub_use_fhe_type!( + pub use static_{ + FheUint24, FheUint40, FheUint48, FheUint56, FheUint72, FheUint80, FheUint88, FheUint96, + FheUint104, FheUint112, FheUint120, FheUint136, FheUint144, FheUint152, FheUint168, + FheUint176, FheUint184, FheUint192, FheUint200, FheUint208, FheUint216, FheUint224, + FheUint232, FheUint240, FheUint248, }; ); diff --git a/tfhe/src/high_level_api/integers/unsigned/scalar_ops.rs b/tfhe/src/high_level_api/integers/unsigned/scalar_ops.rs index 6b0eda3bd4..8e82ece707 100644 --- a/tfhe/src/high_level_api/integers/unsigned/scalar_ops.rs +++ b/tfhe/src/high_level_api/integers/unsigned/scalar_ops.rs @@ -513,22 +513,14 @@ macro_rules! generic_integer_impl_scalar_div_rem { )* // Closing first repeating pattern }; } + +#[cfg(feature = "extended-types")] generic_integer_impl_scalar_div_rem!( fhe_and_scalar_type: - (super::FheUint2, u8), - (super::FheUint4, u8), - (super::FheUint6, u8), - (super::FheUint8, u8), - (super::FheUint10, u16), - (super::FheUint12, u16), - (super::FheUint14, u16), - (super::FheUint16, u16), (super::FheUint24, u32), - (super::FheUint32, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -536,8 +528,9 @@ generic_integer_impl_scalar_div_rem!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -549,6 +542,22 @@ generic_integer_impl_scalar_div_rem!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), +); + +generic_integer_impl_scalar_div_rem!( + fhe_and_scalar_type: + (super::FheUint2, u8), + (super::FheUint4, u8), + (super::FheUint6, u8), + (super::FheUint8, u8), + (super::FheUint10, u16), + (super::FheUint12, u16), + (super::FheUint14, u16), + (super::FheUint16, u16), + (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), (super::FheUint256, U256), (super::FheUint512, U512), (super::FheUint1024, U1024), @@ -598,6 +607,7 @@ macro_rules! generic_integer_impl_scalar_operation { pub(in crate::high_level_api::integers) use generic_integer_impl_scalar_operation; +#[cfg(feature = "extended-types")] generic_integer_impl_scalar_operation!( rust_trait: Add(add), implem: { @@ -622,20 +632,10 @@ generic_integer_impl_scalar_operation!( } }, fhe_and_scalar_type: - (super::FheUint2, u8), - (super::FheUint4, u8), - (super::FheUint6, u8), - (super::FheUint8, u8), - (super::FheUint10, u16), - (super::FheUint12, u16), - (super::FheUint14, u16), - (super::FheUint16, u16), (super::FheUint24, u32), - (super::FheUint32, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -643,8 +643,9 @@ generic_integer_impl_scalar_operation!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -656,26 +657,22 @@ generic_integer_impl_scalar_operation!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); generic_integer_impl_scalar_operation!( - rust_trait: Sub(sub), + rust_trait: Add(add), implem: { |lhs: &FheUint<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_sub_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_add_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_sub( + cuda_key.key.key.scalar_add( &*lhs.ciphertext.on_gpu(streams), rhs, streams ) }); @@ -693,12 +690,45 @@ generic_integer_impl_scalar_operation!( (super::FheUint12, u16), (super::FheUint14, u16), (super::FheUint16, u16), - (super::FheUint24, u32), (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: Sub(sub), + implem: { + |lhs: &FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_sub_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_sub( + &*lhs.ciphertext.on_gpu(streams), rhs, streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -706,8 +736,9 @@ generic_integer_impl_scalar_operation!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -719,27 +750,22 @@ generic_integer_impl_scalar_operation!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); - generic_integer_impl_scalar_operation!( - rust_trait: Mul(mul), + rust_trait: Sub(sub), implem: { |lhs: &FheUint<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_mul_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_sub_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_mul( + cuda_key.key.key.scalar_sub( &*lhs.ciphertext.on_gpu(streams), rhs, streams ) }); @@ -757,12 +783,45 @@ generic_integer_impl_scalar_operation!( (super::FheUint12, u16), (super::FheUint14, u16), (super::FheUint16, u16), - (super::FheUint24, u32), (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: Mul(mul), + implem: { + |lhs: &FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_mul_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_mul( + &*lhs.ciphertext.on_gpu(streams), rhs, streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -770,8 +829,9 @@ generic_integer_impl_scalar_operation!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -783,27 +843,22 @@ generic_integer_impl_scalar_operation!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); - generic_integer_impl_scalar_operation!( - rust_trait: BitAnd(bitand), + rust_trait: Mul(mul), implem: { |lhs: &FheUint<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_bitand_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_mul_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_bitand( + cuda_key.key.key.scalar_mul( &*lhs.ciphertext.on_gpu(streams), rhs, streams ) }); @@ -821,53 +876,32 @@ generic_integer_impl_scalar_operation!( (super::FheUint12, u16), (super::FheUint14, u16), (super::FheUint16, u16), - (super::FheUint24, u32), (super::FheUint32, u32), - (super::FheUint40, u64), - (super::FheUint48, u64), - (super::FheUint56, u64), (super::FheUint64, u64), - (super::FheUint72, u128), - (super::FheUint80, u128), - (super::FheUint88, u128), - (super::FheUint96, u128), - (super::FheUint104, u128), - (super::FheUint112, u128), - (super::FheUint120, u128), (super::FheUint128, u128), (super::FheUint160, U256), - (super::FheUint168, U256), - (super::FheUint176, U256), - (super::FheUint184, U256), - (super::FheUint192, U256), - (super::FheUint200, U256), - (super::FheUint208, U256), - (super::FheUint216, U256), - (super::FheUint224, U256), - (super::FheUint232, U256), - (super::FheUint240, U256), - (super::FheUint248, U256), (super::FheUint256, U256), (super::FheUint512, U512), (super::FheUint1024, U1024), (super::FheUint2048, U2048), ); +#[cfg(feature = "extended-types")] generic_integer_impl_scalar_operation!( - rust_trait: BitOr(bitor), + rust_trait: BitAnd(bitand), implem: { |lhs: &FheUint<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_bitor_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_bitand_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_bitor( + cuda_key.key.key.scalar_bitand( &*lhs.ciphertext.on_gpu(streams), rhs, streams ) }); @@ -877,20 +911,10 @@ generic_integer_impl_scalar_operation!( } }, fhe_and_scalar_type: - (super::FheUint2, u8), - (super::FheUint4, u8), - (super::FheUint6, u8), - (super::FheUint8, u8), - (super::FheUint10, u16), - (super::FheUint12, u16), - (super::FheUint14, u16), - (super::FheUint16, u16), (super::FheUint24, u32), - (super::FheUint32, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -898,8 +922,9 @@ generic_integer_impl_scalar_operation!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -911,28 +936,22 @@ generic_integer_impl_scalar_operation!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); - generic_integer_impl_scalar_operation!( - rust_trait: BitXor(bitxor), + rust_trait: BitAnd(bitand), implem: { |lhs: &FheUint<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_bitxor_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_bitand_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, - #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_bitxor( + cuda_key.key.key.scalar_bitand( &*lhs.ciphertext.on_gpu(streams), rhs, streams ) }); @@ -950,12 +969,45 @@ generic_integer_impl_scalar_operation!( (super::FheUint12, u16), (super::FheUint14, u16), (super::FheUint16, u16), - (super::FheUint24, u32), (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: BitOr(bitor), + implem: { + |lhs: &FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_bitor_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_bitor( + &*lhs.ciphertext.on_gpu(streams), rhs, streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -963,8 +1015,9 @@ generic_integer_impl_scalar_operation!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -976,28 +1029,161 @@ generic_integer_impl_scalar_operation!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); - generic_integer_impl_scalar_operation!( - rust_trait: Shl(shl), + rust_trait: BitOr(bitor), implem: { |lhs: &FheUint<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_left_shift_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_bitor_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_left_shift( - &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams + cuda_key.key.key.scalar_bitor( + &*lhs.ciphertext.on_gpu(streams), rhs, streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint2, u8), + (super::FheUint4, u8), + (super::FheUint6, u8), + (super::FheUint8, u8), + (super::FheUint10, u16), + (super::FheUint12, u16), + (super::FheUint14, u16), + (super::FheUint16, u16), + (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: BitXor(bitxor), + implem: { + |lhs: &FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_bitxor_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_bitxor( + &*lhs.ciphertext.on_gpu(streams), rhs, streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), + (super::FheUint40, u64), + (super::FheUint48, u64), + (super::FheUint56, u64), + (super::FheUint72, u128), + (super::FheUint80, u128), + (super::FheUint88, u128), + (super::FheUint96, u128), + (super::FheUint104, u128), + (super::FheUint112, u128), + (super::FheUint120, u128), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), + (super::FheUint168, U256), + (super::FheUint176, U256), + (super::FheUint184, U256), + (super::FheUint192, U256), + (super::FheUint200, U256), + (super::FheUint208, U256), + (super::FheUint216, U256), + (super::FheUint224, U256), + (super::FheUint232, U256), + (super::FheUint240, U256), + (super::FheUint248, U256), +); +generic_integer_impl_scalar_operation!( + rust_trait: BitXor(bitxor), + implem: { + |lhs: &FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_bitxor_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_bitxor( + &*lhs.ciphertext.on_gpu(streams), rhs, streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint2, u8), + (super::FheUint4, u8), + (super::FheUint6, u8), + (super::FheUint8, u8), + (super::FheUint10, u16), + (super::FheUint12, u16), + (super::FheUint14, u16), + (super::FheUint16, u16), + (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: Shl(shl), + implem: { + |lhs: &FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_left_shift_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_left_shift( + &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams ) }); RadixCiphertext::Cuda(inner_result) @@ -1006,20 +1192,10 @@ generic_integer_impl_scalar_operation!( } }, fhe_and_scalar_type: - (super::FheUint2, u8, u16, u32, u64, u128), - (super::FheUint4, u8, u16, u32, u64, u128), - (super::FheUint6, u8, u16, u32, u64, u128), - (super::FheUint8, u8, u16, u32, u64, u128), - (super::FheUint10, u8, u16, u32, u64, u128), - (super::FheUint12, u8, u16, u32, u64, u128), - (super::FheUint14, u8, u16, u32, u64, u128), - (super::FheUint16, u8, u16, u32, u64, u128), (super::FheUint24, u8, u16, u32, u64, u128), - (super::FheUint32, u8, u16, u32, u64, u128), (super::FheUint40, u8, u16, u32, u64, u128), (super::FheUint48, u8, u16, u32, u64, u128), (super::FheUint56, u8, u16, u32, u64, u128), - (super::FheUint64, u8, u16, u32, u64, u128), (super::FheUint72, u8, u16, u32, u64, u128), (super::FheUint80, u8, u16, u32, u64, u128), (super::FheUint88, u8, u16, u32, u64, u128), @@ -1027,11 +1203,9 @@ generic_integer_impl_scalar_operation!( (super::FheUint104, u8, u16, u32, u64, u128), (super::FheUint112, u8, u16, u32, u64, u128), (super::FheUint120, u8, u16, u32, u64, u128), - (super::FheUint128, u8, u16, u32, u64, u128), (super::FheUint136, u8, u16, u32, u64, u128, U256), (super::FheUint144, u8, u16, u32, u64, u128, U256), (super::FheUint152, u8, u16, u32, u64, u128, U256), - (super::FheUint160, u8, u16, u32, u64, u128, U256), (super::FheUint168, u8, u16, u32, u64, u128, U256), (super::FheUint176, u8, u16, u32, u64, u128, U256), (super::FheUint184, u8, u16, u32, u64, u128, U256), @@ -1043,26 +1217,22 @@ generic_integer_impl_scalar_operation!( (super::FheUint232, u8, u16, u32, u64, u128, U256), (super::FheUint240, u8, u16, u32, u64, u128, U256), (super::FheUint248, u8, u16, u32, u64, u128, U256), - (super::FheUint256, u8, u16, u32, u64, u128, U256), - (super::FheUint512, u8, u16, u32, u64, u128, U256, U512), - (super::FheUint1024, u8, u16, u32, u64, u128, U256, U512, U1024), - (super::FheUint2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); generic_integer_impl_scalar_operation!( - rust_trait: Shr(shr), + rust_trait: Shl(shl), implem: { |lhs: &FheUint<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_right_shift_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_left_shift_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_right_shift( + cuda_key.key.key.scalar_left_shift( &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams ) }); @@ -1080,12 +1250,45 @@ generic_integer_impl_scalar_operation!( (super::FheUint12, u8, u16, u32, u64, u128), (super::FheUint14, u8, u16, u32, u64, u128), (super::FheUint16, u8, u16, u32, u64, u128), - (super::FheUint24, u8, u16, u32, u64, u128), (super::FheUint32, u8, u16, u32, u64, u128), + (super::FheUint64, u8, u16, u32, u64, u128), + (super::FheUint128, u8, u16, u32, u64, u128), + (super::FheUint160, u8, u16, u32, u64, u128, U256), + (super::FheUint256, u8, u16, u32, u64, u128, U256), + (super::FheUint512, u8, u16, u32, u64, u128, U256, U512), + (super::FheUint1024, u8, u16, u32, u64, u128, U256, U512, U1024), + (super::FheUint2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: Shr(shr), + implem: { + |lhs: &FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_right_shift_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_right_shift( + &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u8, u16, u32, u64, u128), (super::FheUint40, u8, u16, u32, u64, u128), (super::FheUint48, u8, u16, u32, u64, u128), (super::FheUint56, u8, u16, u32, u64, u128), - (super::FheUint64, u8, u16, u32, u64, u128), (super::FheUint72, u8, u16, u32, u64, u128), (super::FheUint80, u8, u16, u32, u64, u128), (super::FheUint88, u8, u16, u32, u64, u128), @@ -1093,11 +1296,9 @@ generic_integer_impl_scalar_operation!( (super::FheUint104, u8, u16, u32, u64, u128), (super::FheUint112, u8, u16, u32, u64, u128), (super::FheUint120, u8, u16, u32, u64, u128), - (super::FheUint128, u8, u16, u32, u64, u128), (super::FheUint136, u8, u16, u32, u64, u128, U256), (super::FheUint144, u8, u16, u32, u64, u128, U256), (super::FheUint152, u8, u16, u32, u64, u128, U256), - (super::FheUint160, u8, u16, u32, u64, u128, U256), (super::FheUint168, u8, u16, u32, u64, u128, U256), (super::FheUint176, u8, u16, u32, u64, u128, U256), (super::FheUint184, u8, u16, u32, u64, u128, U256), @@ -1109,26 +1310,22 @@ generic_integer_impl_scalar_operation!( (super::FheUint232, u8, u16, u32, u64, u128, U256), (super::FheUint240, u8, u16, u32, u64, u128, U256), (super::FheUint248, u8, u16, u32, u64, u128, U256), - (super::FheUint256, u8, u16, u32, u64, u128, U256), - (super::FheUint512, u8, u16, u32, u64, u128, U256, U512), - (super::FheUint1024, u8, u16, u32, u64, u128, U256, U512, U1024), - (super::FheUint2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); generic_integer_impl_scalar_operation!( - rust_trait: RotateLeft(rotate_left), + rust_trait: Shr(shr), implem: { |lhs: &FheUint<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_rotate_left_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_right_shift_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_rotate_left( + cuda_key.key.key.scalar_right_shift( &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams ) }); @@ -1146,12 +1343,45 @@ generic_integer_impl_scalar_operation!( (super::FheUint12, u8, u16, u32, u64, u128), (super::FheUint14, u8, u16, u32, u64, u128), (super::FheUint16, u8, u16, u32, u64, u128), - (super::FheUint24, u8, u16, u32, u64, u128), (super::FheUint32, u8, u16, u32, u64, u128), + (super::FheUint64, u8, u16, u32, u64, u128), + (super::FheUint128, u8, u16, u32, u64, u128), + (super::FheUint160, u8, u16, u32, u64, u128, U256), + (super::FheUint256, u8, u16, u32, u64, u128, U256), + (super::FheUint512, u8, u16, u32, u64, u128, U256, U512), + (super::FheUint1024, u8, u16, u32, u64, u128, U256, U512, U1024), + (super::FheUint2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: RotateLeft(rotate_left), + implem: { + |lhs: &FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_rotate_left_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_rotate_left( + &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u8, u16, u32, u64, u128), (super::FheUint40, u8, u16, u32, u64, u128), (super::FheUint48, u8, u16, u32, u64, u128), (super::FheUint56, u8, u16, u32, u64, u128), - (super::FheUint64, u8, u16, u32, u64, u128), (super::FheUint72, u8, u16, u32, u64, u128), (super::FheUint80, u8, u16, u32, u64, u128), (super::FheUint88, u8, u16, u32, u64, u128), @@ -1159,11 +1389,9 @@ generic_integer_impl_scalar_operation!( (super::FheUint104, u8, u16, u32, u64, u128), (super::FheUint112, u8, u16, u32, u64, u128), (super::FheUint120, u8, u16, u32, u64, u128), - (super::FheUint128, u8, u16, u32, u64, u128), (super::FheUint136, u8, u16, u32, u64, u128, U256), (super::FheUint144, u8, u16, u32, u64, u128, U256), (super::FheUint152, u8, u16, u32, u64, u128, U256), - (super::FheUint160, u8, u16, u32, u64, u128, U256), (super::FheUint168, u8, u16, u32, u64, u128, U256), (super::FheUint176, u8, u16, u32, u64, u128, U256), (super::FheUint184, u8, u16, u32, u64, u128, U256), @@ -1175,26 +1403,22 @@ generic_integer_impl_scalar_operation!( (super::FheUint232, u8, u16, u32, u64, u128, U256), (super::FheUint240, u8, u16, u32, u64, u128, U256), (super::FheUint248, u8, u16, u32, u64, u128, U256), - (super::FheUint256, u8, u16, u32, u64, u128, U256), - (super::FheUint512, u8, u16, u32, u64, u128, U256, U512), - (super::FheUint1024, u8, u16, u32, u64, u128, U256, U512, U1024), - (super::FheUint2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); generic_integer_impl_scalar_operation!( - rust_trait: RotateRight(rotate_right), + rust_trait: RotateLeft(rotate_left), implem: { |lhs: &FheUint<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_rotate_right_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + .scalar_rotate_left_parallelized(&*lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_rotate_right( + cuda_key.key.key.scalar_rotate_left( &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams ) }); @@ -1212,12 +1436,45 @@ generic_integer_impl_scalar_operation!( (super::FheUint12, u8, u16, u32, u64, u128), (super::FheUint14, u8, u16, u32, u64, u128), (super::FheUint16, u8, u16, u32, u64, u128), - (super::FheUint24, u8, u16, u32, u64, u128), (super::FheUint32, u8, u16, u32, u64, u128), + (super::FheUint64, u8, u16, u32, u64, u128), + (super::FheUint128, u8, u16, u32, u64, u128), + (super::FheUint160, u8, u16, u32, u64, u128, U256), + (super::FheUint256, u8, u16, u32, u64, u128, U256), + (super::FheUint512, u8, u16, u32, u64, u128, U256, U512), + (super::FheUint1024, u8, u16, u32, u64, u128, U256, U512, U1024), + (super::FheUint2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: RotateRight(rotate_right), + implem: { + |lhs: &FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_rotate_right_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_rotate_right( + &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u8, u16, u32, u64, u128), (super::FheUint40, u8, u16, u32, u64, u128), (super::FheUint48, u8, u16, u32, u64, u128), (super::FheUint56, u8, u16, u32, u64, u128), - (super::FheUint64, u8, u16, u32, u64, u128), (super::FheUint72, u8, u16, u32, u64, u128), (super::FheUint80, u8, u16, u32, u64, u128), (super::FheUint88, u8, u16, u32, u64, u128), @@ -1225,11 +1482,9 @@ generic_integer_impl_scalar_operation!( (super::FheUint104, u8, u16, u32, u64, u128), (super::FheUint112, u8, u16, u32, u64, u128), (super::FheUint120, u8, u16, u32, u64, u128), - (super::FheUint128, u8, u16, u32, u64, u128), (super::FheUint136, u8, u16, u32, u64, u128, U256), (super::FheUint144, u8, u16, u32, u64, u128, U256), (super::FheUint152, u8, u16, u32, u64, u128, U256), - (super::FheUint160, u8, u16, u32, u64, u128, U256), (super::FheUint168, u8, u16, u32, u64, u128, U256), (super::FheUint176, u8, u16, u32, u64, u128, U256), (super::FheUint184, u8, u16, u32, u64, u128, U256), @@ -1241,11 +1496,50 @@ generic_integer_impl_scalar_operation!( (super::FheUint232, u8, u16, u32, u64, u128, U256), (super::FheUint240, u8, u16, u32, u64, u128, U256), (super::FheUint248, u8, u16, u32, u64, u128, U256), +); +generic_integer_impl_scalar_operation!( + rust_trait: RotateRight(rotate_right), + implem: { + |lhs: &FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_rotate_right_parallelized(&*lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_rotate_right( + &*lhs.ciphertext.on_gpu(streams), u64::cast_from(rhs), streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint2, u8, u16, u32, u64, u128), + (super::FheUint4, u8, u16, u32, u64, u128), + (super::FheUint6, u8, u16, u32, u64, u128), + (super::FheUint8, u8, u16, u32, u64, u128), + (super::FheUint10, u8, u16, u32, u64, u128), + (super::FheUint12, u8, u16, u32, u64, u128), + (super::FheUint14, u8, u16, u32, u64, u128), + (super::FheUint16, u8, u16, u32, u64, u128), + (super::FheUint32, u8, u16, u32, u64, u128), + (super::FheUint64, u8, u16, u32, u64, u128), + (super::FheUint128, u8, u16, u32, u64, u128), + (super::FheUint160, u8, u16, u32, u64, u128, U256), (super::FheUint256, u8, u16, u32, u64, u128, U256), (super::FheUint512, u8, u16, u32, u64, u128, U256, U512), (super::FheUint1024, u8, u16, u32, u64, u128, U256, U512, U1024), (super::FheUint2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); + +#[cfg(feature = "extended-types")] generic_integer_impl_scalar_operation!( rust_trait: Div(div), implem: { @@ -1270,20 +1564,10 @@ generic_integer_impl_scalar_operation!( } }, fhe_and_scalar_type: - (super::FheUint2, u8), - (super::FheUint4, u8), - (super::FheUint6, u8), - (super::FheUint8, u8), - (super::FheUint10, u16), - (super::FheUint12, u16), - (super::FheUint14, u16), - (super::FheUint16, u16), (super::FheUint24, u32), - (super::FheUint32, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -1291,8 +1575,9 @@ generic_integer_impl_scalar_operation!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -1304,27 +1589,22 @@ generic_integer_impl_scalar_operation!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); - generic_integer_impl_scalar_operation!( - rust_trait: Rem(rem), + rust_trait: Div(div), implem: { |lhs: &FheUint<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { let inner_result = cpu_key .pbs_key() - .scalar_rem_parallelized(&lhs.ciphertext.on_cpu(), rhs); + .scalar_div_parallelized(&lhs.ciphertext.on_cpu(), rhs); RadixCiphertext::Cpu(inner_result) }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(cuda_key) => { let inner_result = with_thread_local_cuda_streams(|streams| { - cuda_key.key.key.scalar_rem( + cuda_key.key.key.scalar_div( &lhs.ciphertext.on_gpu(streams), rhs, streams ) }); @@ -1342,12 +1622,45 @@ generic_integer_impl_scalar_operation!( (super::FheUint12, u16), (super::FheUint14, u16), (super::FheUint16, u16), - (super::FheUint24, u32), (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation!( + rust_trait: Rem(rem), + implem: { + |lhs: &FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_rem_parallelized(&lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_rem( + &lhs.ciphertext.on_gpu(streams), rhs, streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -1355,19 +1668,57 @@ generic_integer_impl_scalar_operation!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), + (super::FheUint168, U256), + (super::FheUint176, U256), + (super::FheUint184, U256), + (super::FheUint192, U256), + (super::FheUint200, U256), + (super::FheUint208, U256), + (super::FheUint216, U256), + (super::FheUint224, U256), + (super::FheUint232, U256), + (super::FheUint240, U256), + (super::FheUint248, U256), +); +generic_integer_impl_scalar_operation!( + rust_trait: Rem(rem), + implem: { + |lhs: &FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let inner_result = cpu_key + .pbs_key() + .scalar_rem_parallelized(&lhs.ciphertext.on_cpu(), rhs); + RadixCiphertext::Cpu(inner_result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + let inner_result = with_thread_local_cuda_streams(|streams| { + cuda_key.key.key.scalar_rem( + &lhs.ciphertext.on_gpu(streams), rhs, streams + ) + }); + RadixCiphertext::Cuda(inner_result) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint2, u8), + (super::FheUint4, u8), + (super::FheUint6, u8), + (super::FheUint8, u8), + (super::FheUint10, u16), + (super::FheUint12, u16), + (super::FheUint14, u16), + (super::FheUint16, u16), + (super::FheUint32, u32), + (super::FheUint64, u64), (super::FheUint128, u128), (super::FheUint160, U256), - (super::FheUint168, U256), - (super::FheUint176, U256), - (super::FheUint184, U256), - (super::FheUint192, U256), - (super::FheUint200, U256), - (super::FheUint208, U256), - (super::FheUint216, U256), - (super::FheUint224, U256), - (super::FheUint232, U256), - (super::FheUint240, U256), - (super::FheUint248, U256), (super::FheUint256, U256), (super::FheUint512, U512), (super::FheUint1024, U1024), @@ -1441,6 +1792,43 @@ macro_rules! generic_integer_impl_scalar_left_operation { pub(in crate::high_level_api::integers) use generic_integer_impl_scalar_left_operation; +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_left_operation!( + rust_trait: Add(add), + implem: { + |lhs, rhs: &FheUint<_>| { + // `+` is commutative + let result: FheUint<_> = rhs + lhs; + result.ciphertext + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), + (super::FheUint40, u64), + (super::FheUint48, u64), + (super::FheUint56, u64), + (super::FheUint72, u128), + (super::FheUint80, u128), + (super::FheUint88, u128), + (super::FheUint96, u128), + (super::FheUint104, u128), + (super::FheUint112, u128), + (super::FheUint120, u128), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), + (super::FheUint168, U256), + (super::FheUint176, U256), + (super::FheUint184, U256), + (super::FheUint192, U256), + (super::FheUint200, U256), + (super::FheUint208, U256), + (super::FheUint216, U256), + (super::FheUint224, U256), + (super::FheUint232, U256), + (super::FheUint240, U256), + (super::FheUint248, U256), +); generic_integer_impl_scalar_left_operation!( rust_trait: Add(add), implem: { @@ -1480,12 +1868,50 @@ generic_integer_impl_scalar_left_operation!( /// assert_eq!(result, 23u16 + 3u16); /// ``` u16), - (super::FheUint24, u32), (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_left_operation!( + rust_trait: Sub(sub), + implem: { + |lhs, rhs: &FheUint<_>| { + // `-` is not commutative, so we resort to converting to trivial + // which should give same perf + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + let mut result = cpu_key + .pbs_key() + .create_trivial_radix(lhs, rhs.ciphertext.on_cpu().blocks().len()); + cpu_key + .pbs_key() + .sub_assign_parallelized(&mut result, &*rhs.ciphertext.on_cpu()); + RadixCiphertext::Cpu(result) + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + let mut result: CudaUnsignedRadixCiphertext = cuda_key.key.key.create_trivial_radix( + lhs, rhs.ciphertext.on_gpu(streams).ciphertext.info.blocks.len(), streams); + cuda_key.key.key.sub_assign(&mut result, &rhs.ciphertext.on_gpu(streams), streams); + RadixCiphertext::Cuda(result) + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -1493,8 +1919,9 @@ generic_integer_impl_scalar_left_operation!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -1506,10 +1933,6 @@ generic_integer_impl_scalar_left_operation!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); generic_integer_impl_scalar_left_operation!( rust_trait: Sub(sub), @@ -1569,12 +1992,31 @@ generic_integer_impl_scalar_left_operation!( /// assert_eq!(result, 23u16 - 3u16); /// ``` u16), - (super::FheUint24, u32), (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_left_operation!( + rust_trait: Mul(mul), + implem: { + |lhs, rhs: &FheUint<_>| { + // `*` is commutative + let result: FheUint<_> = rhs * lhs; + result.ciphertext + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -1582,8 +2024,9 @@ generic_integer_impl_scalar_left_operation!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -1595,10 +2038,6 @@ generic_integer_impl_scalar_left_operation!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); generic_integer_impl_scalar_left_operation!( rust_trait: Mul(mul), @@ -1639,12 +2078,31 @@ generic_integer_impl_scalar_left_operation!( /// assert_eq!(result, 23u16 * 3u16); /// ``` u16), - (super::FheUint24, u32), (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_left_operation!( + rust_trait: BitAnd(bitand), + implem: { + |lhs, rhs: &FheUint<_>| { + // `&` is commutative + let result: FheUint<_> = rhs & lhs; + result.ciphertext + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -1652,8 +2110,9 @@ generic_integer_impl_scalar_left_operation!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -1665,10 +2124,6 @@ generic_integer_impl_scalar_left_operation!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); generic_integer_impl_scalar_left_operation!( rust_trait: BitAnd(bitand), @@ -1707,12 +2162,31 @@ generic_integer_impl_scalar_left_operation!( /// assert_eq!(result, 23u16 & 3u16); /// ``` u16), - (super::FheUint24, u32), (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_left_operation!( + rust_trait: BitOr(bitor), + implem: { + |lhs, rhs: &FheUint<_>| { + // `|` is commutative + let result: FheUint<_> = rhs | lhs; + result.ciphertext + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -1720,8 +2194,9 @@ generic_integer_impl_scalar_left_operation!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -1733,10 +2208,6 @@ generic_integer_impl_scalar_left_operation!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); generic_integer_impl_scalar_left_operation!( rust_trait: BitOr(bitor), @@ -1775,12 +2246,31 @@ generic_integer_impl_scalar_left_operation!( /// assert_eq!(result, 23u16 | 3u16); /// ``` u16), - (super::FheUint24, u32), (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_left_operation!( + rust_trait: BitXor(bitxor), + implem: { + |lhs, rhs: &FheUint<_>| { + // `^` is commutative + let result: FheUint<_> = rhs ^ lhs; + result.ciphertext + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -1788,8 +2278,9 @@ generic_integer_impl_scalar_left_operation!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -1801,10 +2292,6 @@ generic_integer_impl_scalar_left_operation!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); generic_integer_impl_scalar_left_operation!( rust_trait: BitXor(bitxor), @@ -1843,32 +2330,10 @@ generic_integer_impl_scalar_left_operation!( /// assert_eq!(result, 23u16 ^ 3u16); /// ``` u16), - (super::FheUint24, u32), (super::FheUint32, u32), - (super::FheUint40, u64), - (super::FheUint48, u64), - (super::FheUint56, u64), (super::FheUint64, u64), - (super::FheUint72, u128), - (super::FheUint80, u128), - (super::FheUint88, u128), - (super::FheUint96, u128), - (super::FheUint104, u128), - (super::FheUint112, u128), - (super::FheUint120, u128), (super::FheUint128, u128), (super::FheUint160, U256), - (super::FheUint168, U256), - (super::FheUint176, U256), - (super::FheUint184, U256), - (super::FheUint192, U256), - (super::FheUint200, U256), - (super::FheUint208, U256), - (super::FheUint216, U256), - (super::FheUint224, U256), - (super::FheUint232, U256), - (super::FheUint240, U256), - (super::FheUint248, U256), (super::FheUint256, U256), (super::FheUint512, U512), (super::FheUint1024, U1024), @@ -1905,6 +2370,54 @@ macro_rules! generic_integer_impl_scalar_operation_assign { pub(in crate::high_level_api::integers) use generic_integer_impl_scalar_operation_assign; +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: AddAssign(add_assign), + implem: { + |lhs: &mut FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_add_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_add_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), + (super::FheUint40, u64), + (super::FheUint48, u64), + (super::FheUint56, u64), + (super::FheUint72, u128), + (super::FheUint80, u128), + (super::FheUint88, u128), + (super::FheUint96, u128), + (super::FheUint104, u128), + (super::FheUint112, u128), + (super::FheUint120, u128), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), + (super::FheUint168, U256), + (super::FheUint176, U256), + (super::FheUint184, U256), + (super::FheUint192, U256), + (super::FheUint200, U256), + (super::FheUint208, U256), + (super::FheUint216, U256), + (super::FheUint224, U256), + (super::FheUint232, U256), + (super::FheUint240, U256), + (super::FheUint248, U256), +); generic_integer_impl_scalar_operation_assign!( rust_trait: AddAssign(add_assign), implem: { @@ -1956,12 +2469,42 @@ generic_integer_impl_scalar_operation_assign!( /// assert_eq!(result, 23u16 + 3u16); /// ``` u16), - (super::FheUint24, u32), (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: SubAssign(sub_assign), + implem: { + |lhs: &mut FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_sub_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_sub_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -1969,8 +2512,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -1982,10 +2526,6 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); generic_integer_impl_scalar_operation_assign!( rust_trait: SubAssign(sub_assign), @@ -2016,12 +2556,42 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint12, u16), (super::FheUint14, u16), (super::FheUint16, u16), - (super::FheUint24, u32), (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: MulAssign(mul_assign), + implem: { + |lhs: &mut FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_mul_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_mul_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -2029,8 +2599,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -2042,10 +2613,6 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); generic_integer_impl_scalar_operation_assign!( rust_trait: MulAssign(mul_assign), @@ -2076,12 +2643,42 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint12, u16), (super::FheUint14, u16), (super::FheUint16, u16), - (super::FheUint24, u32), (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: BitAndAssign(bitand_assign), + implem: { + |lhs: &mut FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_bitand_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_bitand_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -2089,8 +2686,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -2102,10 +2700,6 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); generic_integer_impl_scalar_operation_assign!( rust_trait: BitAndAssign(bitand_assign), @@ -2136,12 +2730,42 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint12, u16), (super::FheUint14, u16), (super::FheUint16, u16), - (super::FheUint24, u32), (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: BitOrAssign(bitor_assign), + implem: { + |lhs: &mut FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_bitor_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_bitor_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -2149,8 +2773,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -2162,10 +2787,6 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); generic_integer_impl_scalar_operation_assign!( rust_trait: BitOrAssign(bitor_assign), @@ -2196,12 +2817,42 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint12, u16), (super::FheUint14, u16), (super::FheUint16, u16), - (super::FheUint24, u32), (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: BitXorAssign(bitxor_assign), + implem: { + |lhs: &mut FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_bitxor_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_bitxor_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -2209,8 +2860,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -2222,10 +2874,6 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); generic_integer_impl_scalar_operation_assign!( rust_trait: BitXorAssign(bitxor_assign), @@ -2256,37 +2904,64 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint12, u16), (super::FheUint14, u16), (super::FheUint16, u16), - (super::FheUint24, u32), (super::FheUint32, u32), - (super::FheUint40, u64), - (super::FheUint48, u64), - (super::FheUint56, u64), (super::FheUint64, u64), - (super::FheUint72, u128), - (super::FheUint80, u128), - (super::FheUint88, u128), - (super::FheUint96, u128), - (super::FheUint104, u128), - (super::FheUint112, u128), - (super::FheUint120, u128), (super::FheUint128, u128), (super::FheUint160, U256), - (super::FheUint168, U256), - (super::FheUint176, U256), - (super::FheUint184, U256), - (super::FheUint192, U256), - (super::FheUint200, U256), - (super::FheUint208, U256), - (super::FheUint216, U256), - (super::FheUint224, U256), - (super::FheUint232, U256), - (super::FheUint240, U256), - (super::FheUint248, U256), (super::FheUint256, U256), (super::FheUint512, U512), (super::FheUint1024, U1024), (super::FheUint2048, U2048), ); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: ShlAssign(shl_assign), + implem: { + |lhs: &mut FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_left_shift_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_left_shift_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u8, u16, u32, u64, u128), + (super::FheUint40, u8, u16, u32, u64, u128), + (super::FheUint48, u8, u16, u32, u64, u128), + (super::FheUint56, u8, u16, u32, u64, u128), + (super::FheUint72, u8, u16, u32, u64, u128), + (super::FheUint80, u8, u16, u32, u64, u128), + (super::FheUint88, u8, u16, u32, u64, u128), + (super::FheUint96, u8, u16, u32, u64, u128), + (super::FheUint104, u8, u16, u32, u64, u128), + (super::FheUint112, u8, u16, u32, u64, u128), + (super::FheUint120, u8, u16, u32, u64, u128), + (super::FheUint136, u8, u16, u32, u64, u128, U256), + (super::FheUint144, u8, u16, u32, u64, u128, U256), + (super::FheUint152, u8, u16, u32, u64, u128, U256), + (super::FheUint168, u8, u16, u32, u64, u128, U256), + (super::FheUint176, u8, u16, u32, u64, u128, U256), + (super::FheUint184, u8, u16, u32, u64, u128, U256), + (super::FheUint192, u8, u16, u32, u64, u128, U256), + (super::FheUint200, u8, u16, u32, u64, u128, U256), + (super::FheUint208, u8, u16, u32, u64, u128, U256), + (super::FheUint216, u8, u16, u32, u64, u128, U256), + (super::FheUint224, u8, u16, u32, u64, u128, U256), + (super::FheUint232, u8, u16, u32, u64, u128, U256), + (super::FheUint240, u8, u16, u32, u64, u128, U256), + (super::FheUint248, u8, u16, u32, u64, u128, U256), +); generic_integer_impl_scalar_operation_assign!( rust_trait: ShlAssign(shl_assign), implem: { @@ -2316,12 +2991,42 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint12, u8, u16, u32, u64, u128), (super::FheUint14, u8, u16, u32, u64, u128), (super::FheUint16, u8, u16, u32, u64, u128), - (super::FheUint24, u8, u16, u32, u64, u128), (super::FheUint32, u8, u16, u32, u64, u128), + (super::FheUint64, u8, u16, u32, u64, u128), + (super::FheUint128, u8, u16, u32, u64, u128), + (super::FheUint160, u8, u16, u32, u64, u128, U256), + (super::FheUint256, u8, u16, u32, u64, u128, U256), + (super::FheUint512, u8, u16, u32, u64, u128, U256, U512), + (super::FheUint1024, u8, u16, u32, u64, u128, U256, U512, U1024), + (super::FheUint2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: ShrAssign(shr_assign), + implem: { + |lhs: &mut FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_right_shift_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_right_shift_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u8, u16, u32, u64, u128), (super::FheUint40, u8, u16, u32, u64, u128), (super::FheUint48, u8, u16, u32, u64, u128), (super::FheUint56, u8, u16, u32, u64, u128), - (super::FheUint64, u8, u16, u32, u64, u128), (super::FheUint72, u8, u16, u32, u64, u128), (super::FheUint80, u8, u16, u32, u64, u128), (super::FheUint88, u8, u16, u32, u64, u128), @@ -2329,11 +3034,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint104, u8, u16, u32, u64, u128), (super::FheUint112, u8, u16, u32, u64, u128), (super::FheUint120, u8, u16, u32, u64, u128), - (super::FheUint128, u8, u16, u32, u64, u128), (super::FheUint136, u8, u16, u32, u64, u128, U256), (super::FheUint144, u8, u16, u32, u64, u128, U256), (super::FheUint152, u8, u16, u32, u64, u128, U256), - (super::FheUint160, u8, u16, u32, u64, u128, U256), (super::FheUint168, u8, u16, u32, u64, u128, U256), (super::FheUint176, u8, u16, u32, u64, u128, U256), (super::FheUint184, u8, u16, u32, u64, u128, U256), @@ -2345,10 +3048,6 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint232, u8, u16, u32, u64, u128, U256), (super::FheUint240, u8, u16, u32, u64, u128, U256), (super::FheUint248, u8, u16, u32, u64, u128, U256), - (super::FheUint256, u8, u16, u32, u64, u128, U256), - (super::FheUint512, u8, u16, u32, u64, u128, U256, U512), - (super::FheUint1024, u8, u16, u32, u64, u128, U256, U512, U1024), - (super::FheUint2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); generic_integer_impl_scalar_operation_assign!( rust_trait: ShrAssign(shr_assign), @@ -2379,12 +3078,42 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint12, u8, u16, u32, u64, u128), (super::FheUint14, u8, u16, u32, u64, u128), (super::FheUint16, u8, u16, u32, u64, u128), - (super::FheUint24, u8, u16, u32, u64, u128), (super::FheUint32, u8, u16, u32, u64, u128), + (super::FheUint64, u8, u16, u32, u64, u128), + (super::FheUint128, u8, u16, u32, u64, u128), + (super::FheUint160, u8, u16, u32, u64, u128, U256), + (super::FheUint256, u8, u16, u32, u64, u128, U256), + (super::FheUint512, u8, u16, u32, u64, u128, U256, U512), + (super::FheUint1024, u8, u16, u32, u64, u128, U256, U512, U1024), + (super::FheUint2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: RotateLeftAssign(rotate_left_assign), + implem: { + |lhs: &mut FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_rotate_left_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_rotate_left_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u8, u16, u32, u64, u128), (super::FheUint40, u8, u16, u32, u64, u128), (super::FheUint48, u8, u16, u32, u64, u128), (super::FheUint56, u8, u16, u32, u64, u128), - (super::FheUint64, u8, u16, u32, u64, u128), (super::FheUint72, u8, u16, u32, u64, u128), (super::FheUint80, u8, u16, u32, u64, u128), (super::FheUint88, u8, u16, u32, u64, u128), @@ -2392,11 +3121,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint104, u8, u16, u32, u64, u128), (super::FheUint112, u8, u16, u32, u64, u128), (super::FheUint120, u8, u16, u32, u64, u128), - (super::FheUint128, u8, u16, u32, u64, u128), (super::FheUint136, u8, u16, u32, u64, u128, U256), (super::FheUint144, u8, u16, u32, u64, u128, U256), (super::FheUint152, u8, u16, u32, u64, u128, U256), - (super::FheUint160, u8, u16, u32, u64, u128, U256), (super::FheUint168, u8, u16, u32, u64, u128, U256), (super::FheUint176, u8, u16, u32, u64, u128, U256), (super::FheUint184, u8, u16, u32, u64, u128, U256), @@ -2408,10 +3135,6 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint232, u8, u16, u32, u64, u128, U256), (super::FheUint240, u8, u16, u32, u64, u128, U256), (super::FheUint248, u8, u16, u32, u64, u128, U256), - (super::FheUint256, u8, u16, u32, u64, u128, U256), - (super::FheUint512, u8, u16, u32, u64, u128, U256, U512), - (super::FheUint1024, u8, u16, u32, u64, u128, U256, U512, U1024), - (super::FheUint2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); generic_integer_impl_scalar_operation_assign!( rust_trait: RotateLeftAssign(rotate_left_assign), @@ -2442,12 +3165,42 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint12, u8, u16, u32, u64, u128), (super::FheUint14, u8, u16, u32, u64, u128), (super::FheUint16, u8, u16, u32, u64, u128), - (super::FheUint24, u8, u16, u32, u64, u128), (super::FheUint32, u8, u16, u32, u64, u128), + (super::FheUint64, u8, u16, u32, u64, u128), + (super::FheUint128, u8, u16, u32, u64, u128), + (super::FheUint160, u8, u16, u32, u64, u128, U256), + (super::FheUint256, u8, u16, u32, u64, u128, U256), + (super::FheUint512, u8, u16, u32, u64, u128, U256, U512), + (super::FheUint1024, u8, u16, u32, u64, u128, U256, U512, U1024), + (super::FheUint2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: RotateRightAssign(rotate_right_assign), + implem: { + |lhs: &mut FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_rotate_right_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(cuda_key) => { + with_thread_local_cuda_streams(|streams| { + cuda_key.key.key + .scalar_rotate_right_assign(lhs.ciphertext.as_gpu_mut(streams), rhs, streams); + }) + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u8, u16, u32, u64, u128), (super::FheUint40, u8, u16, u32, u64, u128), (super::FheUint48, u8, u16, u32, u64, u128), (super::FheUint56, u8, u16, u32, u64, u128), - (super::FheUint64, u8, u16, u32, u64, u128), (super::FheUint72, u8, u16, u32, u64, u128), (super::FheUint80, u8, u16, u32, u64, u128), (super::FheUint88, u8, u16, u32, u64, u128), @@ -2455,11 +3208,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint104, u8, u16, u32, u64, u128), (super::FheUint112, u8, u16, u32, u64, u128), (super::FheUint120, u8, u16, u32, u64, u128), - (super::FheUint128, u8, u16, u32, u64, u128), (super::FheUint136, u8, u16, u32, u64, u128, U256), (super::FheUint144, u8, u16, u32, u64, u128, U256), (super::FheUint152, u8, u16, u32, u64, u128, U256), - (super::FheUint160, u8, u16, u32, u64, u128, U256), (super::FheUint168, u8, u16, u32, u64, u128, U256), (super::FheUint176, u8, u16, u32, u64, u128, U256), (super::FheUint184, u8, u16, u32, u64, u128, U256), @@ -2471,10 +3222,6 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint232, u8, u16, u32, u64, u128, U256), (super::FheUint240, u8, u16, u32, u64, u128, U256), (super::FheUint248, u8, u16, u32, u64, u128, U256), - (super::FheUint256, u8, u16, u32, u64, u128, U256), - (super::FheUint512, u8, u16, u32, u64, u128, U256, U512), - (super::FheUint1024, u8, u16, u32, u64, u128, U256, U512, U1024), - (super::FheUint2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); generic_integer_impl_scalar_operation_assign!( rust_trait: RotateRightAssign(rotate_right_assign), @@ -2505,40 +3252,17 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint12, u8, u16, u32, u64, u128), (super::FheUint14, u8, u16, u32, u64, u128), (super::FheUint16, u8, u16, u32, u64, u128), - (super::FheUint24, u8, u16, u32, u64, u128), (super::FheUint32, u8, u16, u32, u64, u128), - (super::FheUint40, u8, u16, u32, u64, u128), - (super::FheUint48, u8, u16, u32, u64, u128), - (super::FheUint56, u8, u16, u32, u64, u128), (super::FheUint64, u8, u16, u32, u64, u128), - (super::FheUint72, u8, u16, u32, u64, u128), - (super::FheUint80, u8, u16, u32, u64, u128), - (super::FheUint88, u8, u16, u32, u64, u128), - (super::FheUint96, u8, u16, u32, u64, u128), - (super::FheUint104, u8, u16, u32, u64, u128), - (super::FheUint112, u8, u16, u32, u64, u128), - (super::FheUint120, u8, u16, u32, u64, u128), (super::FheUint128, u8, u16, u32, u64, u128), - (super::FheUint136, u8, u16, u32, u64, u128, U256), - (super::FheUint144, u8, u16, u32, u64, u128, U256), - (super::FheUint152, u8, u16, u32, u64, u128, U256), (super::FheUint160, u8, u16, u32, u64, u128, U256), - (super::FheUint168, u8, u16, u32, u64, u128, U256), - (super::FheUint176, u8, u16, u32, u64, u128, U256), - (super::FheUint184, u8, u16, u32, u64, u128, U256), - (super::FheUint192, u8, u16, u32, u64, u128, U256), - (super::FheUint200, u8, u16, u32, u64, u128, U256), - (super::FheUint208, u8, u16, u32, u64, u128, U256), - (super::FheUint216, u8, u16, u32, u64, u128, U256), - (super::FheUint224, u8, u16, u32, u64, u128, U256), - (super::FheUint232, u8, u16, u32, u64, u128, U256), - (super::FheUint240, u8, u16, u32, u64, u128, U256), - (super::FheUint248, u8, u16, u32, u64, u128, U256), (super::FheUint256, u8, u16, u32, u64, u128, U256), (super::FheUint512, u8, u16, u32, u64, u128, U256, U512), (super::FheUint1024, u8, u16, u32, u64, u128, U256, U512, U1024), (super::FheUint2048, u8, u16, u32, u64, u128, U256, U512, U1024, U2048), ); + +#[cfg(feature = "extended-types")] generic_integer_impl_scalar_operation_assign!( rust_trait: DivAssign(div_assign), implem: { @@ -2557,20 +3281,10 @@ generic_integer_impl_scalar_operation_assign!( } }, fhe_and_scalar_type: - (super::FheUint2, u8), - (super::FheUint4, u8), - (super::FheUint6, u8), - (super::FheUint8, u8), - (super::FheUint10, u16), - (super::FheUint12, u16), - (super::FheUint14, u16), - (super::FheUint16, u16), (super::FheUint24, u32), - (super::FheUint32, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -2578,8 +3292,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -2591,24 +3306,20 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), - (super::FheUint256, U256), - (super::FheUint512, U512), - (super::FheUint1024, U1024), - (super::FheUint2048, U2048), ); generic_integer_impl_scalar_operation_assign!( - rust_trait: RemAssign(rem_assign), + rust_trait: DivAssign(div_assign), implem: { |lhs: &mut FheUint<_>, rhs| { global_state::with_internal_keys(|key| match key { InternalServerKey::Cpu(cpu_key) => { cpu_key .pbs_key() - .scalar_rem_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + .scalar_div_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); }, #[cfg(feature = "gpu")] InternalServerKey::Cuda(_) => { - panic!("RemAssign '%=' with clear value is not yet supported by Cuda devices") + panic!("DivAssign '/=' with clear value is not yet supported by Cuda devices") } }) } @@ -2622,12 +3333,39 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint12, u16), (super::FheUint14, u16), (super::FheUint16, u16), - (super::FheUint24, u32), (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), + (super::FheUint256, U256), + (super::FheUint512, U512), + (super::FheUint1024, U1024), + (super::FheUint2048, U2048), +); + +#[cfg(feature = "extended-types")] +generic_integer_impl_scalar_operation_assign!( + rust_trait: RemAssign(rem_assign), + implem: { + |lhs: &mut FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_rem_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(_) => { + panic!("RemAssign '%=' with clear value is not yet supported by Cuda devices") + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint24, u32), (super::FheUint40, u64), (super::FheUint48, u64), (super::FheUint56, u64), - (super::FheUint64, u64), (super::FheUint72, u128), (super::FheUint80, u128), (super::FheUint88, u128), @@ -2635,8 +3373,9 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint104, u128), (super::FheUint112, u128), (super::FheUint120, u128), - (super::FheUint128, u128), - (super::FheUint160, U256), + (super::FheUint136, U256), + (super::FheUint144, U256), + (super::FheUint152, U256), (super::FheUint168, U256), (super::FheUint176, U256), (super::FheUint184, U256), @@ -2648,6 +3387,37 @@ generic_integer_impl_scalar_operation_assign!( (super::FheUint232, U256), (super::FheUint240, U256), (super::FheUint248, U256), +); +generic_integer_impl_scalar_operation_assign!( + rust_trait: RemAssign(rem_assign), + implem: { + |lhs: &mut FheUint<_>, rhs| { + global_state::with_internal_keys(|key| match key { + InternalServerKey::Cpu(cpu_key) => { + cpu_key + .pbs_key() + .scalar_rem_assign_parallelized(lhs.ciphertext.as_cpu_mut(), rhs); + }, + #[cfg(feature = "gpu")] + InternalServerKey::Cuda(_) => { + panic!("RemAssign '%=' with clear value is not yet supported by Cuda devices") + } + }) + } + }, + fhe_and_scalar_type: + (super::FheUint2, u8), + (super::FheUint4, u8), + (super::FheUint6, u8), + (super::FheUint8, u8), + (super::FheUint10, u16), + (super::FheUint12, u16), + (super::FheUint14, u16), + (super::FheUint16, u16), + (super::FheUint32, u32), + (super::FheUint64, u64), + (super::FheUint128, u128), + (super::FheUint160, U256), (super::FheUint256, U256), (super::FheUint512, U512), (super::FheUint1024, U1024), diff --git a/tfhe/src/high_level_api/integers/unsigned/static_.rs b/tfhe/src/high_level_api/integers/unsigned/static_.rs index 51e28eda97..899170f27a 100644 --- a/tfhe/src/high_level_api/integers/unsigned/static_.rs +++ b/tfhe/src/high_level_api/integers/unsigned/static_.rs @@ -98,198 +98,206 @@ static_int_type! { static_int_type! { Unsigned { - num_bits: 24, + num_bits: 32, } } static_int_type! { Unsigned { - num_bits: 32, + num_bits: 64, } } static_int_type! { Unsigned { - num_bits: 40, + num_bits: 128, } } static_int_type! { Unsigned { - num_bits: 48, + num_bits: 160, } } static_int_type! { Unsigned { - num_bits: 56, + num_bits: 256, } } static_int_type! { Unsigned { - num_bits: 64, + num_bits: 512, } } static_int_type! { Unsigned { - num_bits: 72, + num_bits: 1024, } } static_int_type! { Unsigned { - num_bits: 80, + num_bits: 2048, } } -static_int_type! { - Unsigned { - num_bits: 88, +#[cfg(feature = "extended-types")] +pub use extended::*; + +#[cfg(feature = "extended-types")] +mod extended { + use super::*; + + static_int_type! { + Unsigned { + num_bits: 24, + } } -} -static_int_type! { - Unsigned { - num_bits: 96, + static_int_type! { + Unsigned { + num_bits: 40, + } } -} -static_int_type! { - Unsigned { - num_bits: 104, + static_int_type! { + Unsigned { + num_bits: 48, + } } -} -static_int_type! { - Unsigned { - num_bits: 112, + static_int_type! { + Unsigned { + num_bits: 56, + } } -} -static_int_type! { - Unsigned { - num_bits: 120, + static_int_type! { + Unsigned { + num_bits: 72, + } } -} -static_int_type! { - Unsigned { - num_bits: 128, + static_int_type! { + Unsigned { + num_bits: 80, + } } -} -static_int_type! { - Unsigned { - num_bits: 136, + static_int_type! { + Unsigned { + num_bits: 88, + } } -} -static_int_type! { - Unsigned { - num_bits: 144, + static_int_type! { + Unsigned { + num_bits: 96, + } } -} -static_int_type! { - Unsigned { - num_bits: 152, + static_int_type! { + Unsigned { + num_bits: 104, + } } -} -static_int_type! { - Unsigned { - num_bits: 160, + static_int_type! { + Unsigned { + num_bits: 112, + } } -} -static_int_type! { - Unsigned { - num_bits: 168, + static_int_type! { + Unsigned { + num_bits: 120, + } } -} -static_int_type! { - Unsigned { - num_bits: 176, + static_int_type! { + Unsigned { + num_bits: 136, + } } -} -static_int_type! { - Unsigned { - num_bits: 184, + static_int_type! { + Unsigned { + num_bits: 144, + } } -} -static_int_type! { - Unsigned { - num_bits: 192, + static_int_type! { + Unsigned { + num_bits: 152, + } } -} -static_int_type! { - Unsigned { - num_bits: 200, + static_int_type! { + Unsigned { + num_bits: 168, + } } -} -static_int_type! { - Unsigned { - num_bits: 208, + static_int_type! { + Unsigned { + num_bits: 176, + } } -} -static_int_type! { - Unsigned { - num_bits: 216, + static_int_type! { + Unsigned { + num_bits: 184, + } } -} -static_int_type! { - Unsigned { - num_bits: 224, + static_int_type! { + Unsigned { + num_bits: 192, + } } -} -static_int_type! { - Unsigned { - num_bits: 232, + static_int_type! { + Unsigned { + num_bits: 200, + } } -} -static_int_type! { - Unsigned { - num_bits: 240, + static_int_type! { + Unsigned { + num_bits: 208, + } } -} -static_int_type! { - Unsigned { - num_bits: 248, + static_int_type! { + Unsigned { + num_bits: 216, + } } -} -static_int_type! { - Unsigned { - num_bits: 256, + static_int_type! { + Unsigned { + num_bits: 224, + } } -} -static_int_type! { - Unsigned { - num_bits: 512, + static_int_type! { + Unsigned { + num_bits: 232, + } } -} -static_int_type! { - Unsigned { - num_bits: 1024, + static_int_type! { + Unsigned { + num_bits: 240, + } } -} -static_int_type! { - Unsigned { - num_bits: 2048, + static_int_type! { + Unsigned { + num_bits: 248, + } } } diff --git a/tfhe/src/high_level_api/mod.rs b/tfhe/src/high_level_api/mod.rs index 3ecb764f87..70d232a111 100644 --- a/tfhe/src/high_level_api/mod.rs +++ b/tfhe/src/high_level_api/mod.rs @@ -65,20 +65,29 @@ pub use keys::{ mod tests; pub use crate::high_level_api::booleans::{CompressedFheBool, FheBool, FheBoolConformanceParams}; + +#[cfg(feature = "extended-types")] +expand_pub_use_fhe_type!( + pub use crate::high_level_api::integers{ + FheUint24, FheUint40, FheUint48, FheUint56, FheUint72, FheUint80,FheUint88, FheUint96, + FheUint104, FheUint112, FheUint120, FheUint136, FheUint144, FheUint152, FheUint168, + FheUint176, FheUint184, FheUint192, FheUint200, FheUint208, FheUint216, FheUint224, + FheUint232, FheUint240, FheUint248, + + FheInt24, FheInt40, FheInt48, FheInt56, FheInt72, FheInt80,FheInt88, FheInt96, FheInt104, + FheInt112, FheInt120, FheInt136, FheInt144, FheInt152, FheInt168, FheInt176, FheInt184, + FheInt192, FheInt200, FheInt208, FheInt216, FheInt224, FheInt232, FheInt240, FheInt248, + }; +); + expand_pub_use_fhe_type!( pub use crate::high_level_api::integers{ FheUint2, FheUint4, FheUint6, FheUint8, FheUint10, FheUint12, FheUint14, FheUint16, - FheUint24, FheUint32, FheUint40, FheUint48, FheUint56, FheUint64, FheUint72, FheUint80, - FheUint88, FheUint96, FheUint104, FheUint112, FheUint120, FheUint128, FheUint136, - FheUint144, FheUint152, FheUint160, FheUint168, FheUint176, FheUint184, FheUint192, - FheUint200, FheUint208, FheUint216, FheUint224, FheUint232, FheUint240, FheUint248, - FheUint256, FheUint512, FheUint1024, FheUint2048, - - FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt24, - FheInt32, FheInt40, FheInt48, FheInt56, FheInt64, FheInt72, FheInt80, FheInt88, FheInt96, - FheInt104, FheInt112, FheInt120, FheInt128, FheInt136, FheInt144, FheInt152, FheInt160, - FheInt168, FheInt176, FheInt184, FheInt192, FheInt200, FheInt208, FheInt216, FheInt224, - FheInt232, FheInt240, FheInt248, FheInt256, FheInt512, FheInt1024, FheInt2048 + FheUint32, FheUint64, FheUint128, FheUint160, FheUint256, FheUint512, FheUint1024, + FheUint2048, + + FheInt2, FheInt4, FheInt6, FheInt8, FheInt10, FheInt12, FheInt14, FheInt16, FheInt32, + FheInt64, FheInt128, FheInt160, FheInt256, FheInt512, FheInt1024, FheInt2048, }; ); pub use array::{ diff --git a/tfhe/src/js_on_wasm_api/js_high_level_api/integers.rs b/tfhe/src/js_on_wasm_api/js_high_level_api/integers.rs index 5563cf330c..c0b4dff877 100644 --- a/tfhe/src/js_on_wasm_api/js_high_level_api/integers.rs +++ b/tfhe/src/js_on_wasm_api/js_high_level_api/integers.rs @@ -322,6 +322,82 @@ macro_rules! create_wrapper_type_non_native_type ( } ); +create_wrapper_type_non_native_type!( + { + type_name: FheUint128, + compressed_type_name: CompressedFheUint128, + proven_type: ProvenFheUint128, + rust_type: u128, + }, + { + type_name: FheUint160, + compressed_type_name: CompressedFheUint160, + proven_type: ProvenFheUint160, + rust_type: U256, + }, + { + type_name: FheUint256, + compressed_type_name: CompressedFheUint256, + proven_type: ProvenFheUint256, + rust_type: U256, + }, + { + type_name: FheUint512, + compressed_type_name: CompressedFheUint512, + proven_type: ProvenFheUint512, + rust_type: U512, + }, + { + type_name: FheUint1024, + compressed_type_name: CompressedFheUint1024, + proven_type: ProvenFheUint1024, + rust_type: U1024, + }, + { + type_name: FheUint2048, + compressed_type_name: CompressedFheUint2048, + proven_type: ProvenFheUint2048, + rust_type: U2048, + }, + { + type_name: FheInt128, + compressed_type_name: CompressedFheInt128, + proven_type: ProvenFheInt128, + rust_type: i128, + }, + { + type_name: FheInt160, + compressed_type_name: CompressedFheInt160, + proven_type: ProvenFheInt160, + rust_type: I256, + }, + { + type_name: FheInt256, + compressed_type_name: CompressedFheInt256, + proven_type: ProvenFheInt256, + rust_type: I256, + }, + { + type_name: FheInt512, + compressed_type_name: CompressedFheInt512, + proven_type: ProvenFheInt512, + rust_type: I512, + }, + { + type_name: FheInt1024, + compressed_type_name: CompressedFheInt1024, + proven_type: ProvenFheInt1024, + rust_type: I1024, + }, + { + type_name: FheInt2048, + compressed_type_name: CompressedFheInt2048, + proven_type: ProvenFheInt2048, + rust_type: I2048, + }, +); + +#[cfg(feature = "extended-types")] create_wrapper_type_non_native_type!( { type_name: FheUint72, @@ -365,12 +441,6 @@ create_wrapper_type_non_native_type!( proven_type: ProvenFheUint120, rust_type: u128, }, - { - type_name: FheUint128, - compressed_type_name: CompressedFheUint128, - proven_type: ProvenFheUint128, - rust_type: u128, - }, { type_name: FheUint136, compressed_type_name: CompressedFheUint136, @@ -389,12 +459,6 @@ create_wrapper_type_non_native_type!( proven_type: ProvenFheUint152, rust_type: U256, }, - { - type_name: FheUint160, - compressed_type_name: CompressedFheUint160, - proven_type: ProvenFheUint160, - rust_type: U256, - }, { type_name: FheUint168, compressed_type_name: CompressedFheUint168, @@ -461,30 +525,6 @@ create_wrapper_type_non_native_type!( proven_type: ProvenFheUint248, rust_type: U256, }, - { - type_name: FheUint256, - compressed_type_name: CompressedFheUint256, - proven_type: ProvenFheUint256, - rust_type: U256, - }, - { - type_name: FheUint512, - compressed_type_name: CompressedFheUint512, - proven_type: ProvenFheUint512, - rust_type: U512, - }, - { - type_name: FheUint1024, - compressed_type_name: CompressedFheUint1024, - proven_type: ProvenFheUint1024, - rust_type: U1024, - }, - { - type_name: FheUint2048, - compressed_type_name: CompressedFheUint2048, - proven_type: ProvenFheUint2048, - rust_type: U2048, - }, // Signed { type_name: FheInt72, @@ -528,12 +568,6 @@ create_wrapper_type_non_native_type!( proven_type: ProvenFheInt120, rust_type: i128, }, - { - type_name: FheInt128, - compressed_type_name: CompressedFheInt128, - proven_type: ProvenFheInt128, - rust_type: i128, - }, { type_name: FheInt136, compressed_type_name: CompressedFheInt136, @@ -552,12 +586,6 @@ create_wrapper_type_non_native_type!( proven_type: ProvenFheInt152, rust_type: I256, }, - { - type_name: FheInt160, - compressed_type_name: CompressedFheInt160, - proven_type: ProvenFheInt160, - rust_type: I256, - }, { type_name: FheInt168, compressed_type_name: CompressedFheInt168, @@ -624,30 +652,6 @@ create_wrapper_type_non_native_type!( proven_type: ProvenFheInt248, rust_type: I256, }, - { - type_name: FheInt256, - compressed_type_name: CompressedFheInt256, - proven_type: ProvenFheInt256, - rust_type: I256, - }, - { - type_name: FheInt512, - compressed_type_name: CompressedFheInt512, - proven_type: ProvenFheInt512, - rust_type: I512, - }, - { - type_name: FheInt1024, - compressed_type_name: CompressedFheInt1024, - proven_type: ProvenFheInt1024, - rust_type: I1024, - }, - { - type_name: FheInt2048, - compressed_type_name: CompressedFheInt2048, - proven_type: ProvenFheInt2048, - rust_type: I2048, - }, ); // We use this macro to define wasm wrapper for @@ -832,6 +836,58 @@ macro_rules! create_wrapper_type_that_has_native_type ( } ); +#[cfg(feature = "extended-types")] +create_wrapper_type_that_has_native_type!( + { + type_name: FheUint24, + compressed_type_name: CompressedFheUint24, + proven_type: ProvenFheUint24, + native_type: u32, + }, + { + type_name: FheUint40, + compressed_type_name: CompressedFheUint40, + proven_type: ProvenFheUint40, + native_type: u64, + }, + { + type_name: FheUint48, + compressed_type_name: CompressedFheUint48, + proven_type: ProvenFheUint48, + native_type: u64, + }, + { + type_name: FheUint56, + compressed_type_name: CompressedFheUint56, + proven_type: ProvenFheUint56, + native_type: u64, + }, + { + type_name: FheInt24, + compressed_type_name: CompressedFheInt24, + proven_type: ProvenFheInt24, + native_type: i32, + }, + { + type_name: FheInt40, + compressed_type_name: CompressedFheInt40, + proven_type: ProvenFheInt40, + native_type: i64, + }, + { + type_name: FheInt48, + compressed_type_name: CompressedFheInt48, + proven_type: ProvenFheInt48, + native_type: i64, + }, + { + type_name: FheInt56, + compressed_type_name: CompressedFheInt56, + proven_type: ProvenFheInt56, + native_type: i64, + }, +); + create_wrapper_type_that_has_native_type!( { type_name: FheBool, @@ -887,43 +943,18 @@ create_wrapper_type_that_has_native_type!( proven_type: ProvenFheUint16, native_type: u16, }, - { - type_name: FheUint24, - compressed_type_name: CompressedFheUint24, - proven_type: ProvenFheUint24, - native_type: u32, - }, { type_name: FheUint32, compressed_type_name: CompressedFheUint32, proven_type: ProvenFheUint32, native_type: u32, }, - { - type_name: FheUint40, - compressed_type_name: CompressedFheUint40, - proven_type: ProvenFheUint40, - native_type: u64, - }, - { - type_name: FheUint48, - compressed_type_name: CompressedFheUint48, - proven_type: ProvenFheUint48, - native_type: u64, - }, - { - type_name: FheUint56, - compressed_type_name: CompressedFheUint56, - proven_type: ProvenFheUint56, - native_type: u64, - }, { type_name: FheUint64, compressed_type_name: CompressedFheUint64, proven_type: ProvenFheUint64, native_type: u64, }, - // Signed { type_name: FheInt2, compressed_type_name: CompressedFheInt2, @@ -972,36 +1003,12 @@ create_wrapper_type_that_has_native_type!( proven_type: ProvenFheInt16, native_type: i16, }, - { - type_name: FheInt24, - compressed_type_name: CompressedFheInt24, - proven_type: ProvenFheInt24, - native_type: i32, - }, { type_name: FheInt32, compressed_type_name: CompressedFheInt32, proven_type: ProvenFheInt32, native_type: i32, }, - { - type_name: FheInt40, - compressed_type_name: CompressedFheInt40, - proven_type: ProvenFheInt40, - native_type: i64, - }, - { - type_name: FheInt48, - compressed_type_name: CompressedFheInt48, - proven_type: ProvenFheInt48, - native_type: i64, - }, - { - type_name: FheInt56, - compressed_type_name: CompressedFheInt56, - proven_type: ProvenFheInt56, - native_type: i64, - }, { type_name: FheInt64, compressed_type_name: CompressedFheInt64, @@ -1243,6 +1250,14 @@ macro_rules! define_builder_push_method { }; } +#[cfg(feature = "extended-types")] +define_builder_push_method!(unsigned: { + 24 <= u32, + 40 <= u64, + 48 <= u64, + 56 <= u64, +}); + define_builder_push_method!(unsigned: { 2 <= u8, 4 <= u8, @@ -1252,14 +1267,18 @@ define_builder_push_method!(unsigned: { 12 <= u16, 14 <= u16, 16 <= u16, - 24 <= u32, 32 <= u32, - 40 <= u64, - 48 <= u64, - 56 <= u64, 64 <= u64, }); +#[cfg(feature = "extended-types")] +define_builder_push_method!(signed: { + 24 <= i32, + 40 <= i64, + 48 <= i64, + 56 <= i64, +}); + define_builder_push_method!(signed: { 2 <= i8, 4 <= i8, @@ -1269,14 +1288,70 @@ define_builder_push_method!(signed: { 12 <= i16, 14 <= i16, 16 <= i16, - 24 <= i32, 32 <= i32, - 40 <= i64, - 48 <= i64, - 56 <= i64, 64 <= i64, }); +#[wasm_bindgen] +impl CompactCiphertextListBuilder { + #[wasm_bindgen] + pub fn push_u128(&mut self, value: JsValue) -> Result<(), JsError> { + catch_panic_result(|| { + let value = u128::try_from(value).map_err(into_js_error)?; + self.0.push(value); + Ok(()) + }) + } + + #[wasm_bindgen] + pub fn push_i128(&mut self, value: JsValue) -> Result<(), JsError> { + catch_panic_result(|| { + let value = i128::try_from(value).map_err(into_js_error)?; + self.0.push(value); + Ok(()) + }) + } + + #[wasm_bindgen] + pub fn push_boolean(&mut self, value: bool) -> Result<(), JsError> { + catch_panic(|| { + self.0.push(value); + }) + } + + #[wasm_bindgen] + pub fn build(&self) -> Result { + catch_panic(|| { + let inner = self.0.build(); + CompactCiphertextList(inner) + }) + } + + #[wasm_bindgen] + pub fn build_packed(&self) -> Result { + catch_panic(|| { + let inner = self.0.build_packed(); + CompactCiphertextList(inner) + }) + } + + #[cfg(feature = "zk-pok")] + pub fn build_with_proof_packed( + &self, + crs: &CompactPkeCrs, + metadata: &[u8], + compute_load: ZkComputeLoad, + ) -> Result { + catch_panic_result(|| { + self.0 + .build_with_proof_packed(&crs.0, metadata, compute_load.into()) + .map_err(into_js_error) + .map(ProvenCompactCiphertextList) + }) + } +} + +#[cfg(feature = "extended-types")] #[wasm_bindgen] impl CompactCiphertextListBuilder { #[wasm_bindgen] @@ -1342,15 +1417,6 @@ impl CompactCiphertextListBuilder { }) } - #[wasm_bindgen] - pub fn push_u128(&mut self, value: JsValue) -> Result<(), JsError> { - catch_panic_result(|| { - let value = u128::try_from(value).map_err(into_js_error)?; - self.0.push(value); - Ok(()) - }) - } - #[wasm_bindgen] pub fn push_u136(&mut self, value: JsValue) -> Result<(), JsError> { catch_panic_result(|| { @@ -1585,15 +1651,6 @@ impl CompactCiphertextListBuilder { }) } - #[wasm_bindgen] - pub fn push_i128(&mut self, value: JsValue) -> Result<(), JsError> { - catch_panic_result(|| { - let value = i128::try_from(value).map_err(into_js_error)?; - self.0.push(value); - Ok(()) - }) - } - #[wasm_bindgen] pub fn push_i136(&mut self, value: JsValue) -> Result<(), JsError> { catch_panic_result(|| { @@ -1764,44 +1821,6 @@ impl CompactCiphertextListBuilder { Ok(()) }) } - - #[wasm_bindgen] - pub fn push_boolean(&mut self, value: bool) -> Result<(), JsError> { - catch_panic(|| { - self.0.push(value); - }) - } - - #[wasm_bindgen] - pub fn build(&self) -> Result { - catch_panic(|| { - let inner = self.0.build(); - CompactCiphertextList(inner) - }) - } - - #[wasm_bindgen] - pub fn build_packed(&self) -> Result { - catch_panic(|| { - let inner = self.0.build_packed(); - CompactCiphertextList(inner) - }) - } - - #[cfg(feature = "zk-pok")] - pub fn build_with_proof_packed( - &self, - crs: &CompactPkeCrs, - metadata: &[u8], - compute_load: ZkComputeLoad, - ) -> Result { - catch_panic_result(|| { - self.0 - .build_with_proof_packed(&crs.0, metadata, compute_load.into()) - .map_err(into_js_error) - .map(ProvenCompactCiphertextList) - }) - } } /// Helper macro to define get methods for the expander @@ -1860,15 +1879,25 @@ macro_rules! define_expander_get_method { } }; } + +#[cfg(feature = "extended-types")] +define_expander_get_method!( + unsigned: { 24, 40, 48, 56, 72, 80, 88, 96, 104, 112, 120, 136, 144, 152, 160, 168, 176, 184, + 192, 200, 208, 216, 224, 232, 240, 248, 256, 512, 1024, 2048 } +); + +define_expander_get_method!( + unsigned: { 2, 4, 6, 8, 10, 12, 14, 16, 32, 64, 128 } +); + +#[cfg(feature = "extended-types")] define_expander_get_method!( - unsigned: { 2, 4, 6, 8, 10, 12, 14, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, - 128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, 240, 248, 256, - 512, 1024, 2048 } + signed: { 24, 40, 48, 56, 72, 80, 88, 96, 104, 112, 120, 136, 144, 152, 160, 168, 176, 184, 192, + 200, 208, 216, 224, 232, 240, 248, 256, 512, 1024, 2048 } ); + define_expander_get_method!( - signed: { 2, 4, 6, 8, 10, 12, 14, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, - 128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, 240, 248, 256, - 512, 1024, 2048 } + signed: { 2, 4, 6, 8, 10, 12, 14, 16, 32, 64, 128 } ); #[wasm_bindgen]