-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(integer): improve shift/rotate by encrypted amount #1647
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tmontaigu
commented
Oct 8, 2024
tmontaigu
commented
Oct 8, 2024
tmontaigu
commented
Oct 8, 2024
tmontaigu
force-pushed
the
tm/faster-shift
branch
from
October 9, 2024 13:17
8b7bb5e
to
2d17588
Compare
nsarlin-zama
reviewed
Oct 9, 2024
tmontaigu
force-pushed
the
tm/faster-shift
branch
from
October 9, 2024 15:34
2d17588
to
cac859c
Compare
nsarlin-zama
reviewed
Oct 9, 2024
tmontaigu
force-pushed
the
tm/faster-shift
branch
2 times, most recently
from
October 10, 2024 08:50
f273633
to
1bcfce3
Compare
nsarlin-zama
approved these changes
Oct 10, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good for me !
This commit does a few things: * Changes the BitExtractor to use many_lut to reduce number of PBS done * Add blocks rotation/shift operation * Implement a new algorithm for bit shift/rotation by encrypted amounts * Add support bit shift/rotation for 1_1 parameters (as result of adding block shift/rotation) The gist of the new bit shift/rotation is to use the same idea as the scalar version where we first shift blocks between adjacent blocks, then use a rotation of blocks. Doing this requires to do a division and modulo operation: ```rust let (shift_within_blocks, block_rotations) = (amount / bits_per_block, amount % bits_per_block) ``` When `amount` is clear this operation is simple, when `amount` is encrypted then is harder (`bits_per_block` is always clear). However, when bits_per_block is a power of 2 (e.g 1, 2, 4) `/` and `%` can be made by shifting and bit-masking, which are simple operations. This means the new algorithm is only compatible with 1_1, 2_2, 4_4 but not 3_3. The new algorithm improves the latency as well as the throughput as it requires less PBS in total
tmontaigu
force-pushed
the
tm/faster-shift
branch
from
October 11, 2024 11:18
1bcfce3
to
db85d98
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit does a few things:
The gist of the new bit shift/rotation is to use the same idea as the scalar version where we first shift blocks between adjacent blocks, then use a rotation of blocks.
Doing this requires to do a division and modulo operation:
When
amount
is clear this operation is simple, whenamount
is encrypted then is harder (bits_per_block
is always clear). However, when bits_per_block is a power of 2 (e.g 1, 2, 4)/
and%
can be made by shifting and bit-masking, which are simple operations.This means the new algorithm is only compatible with 1_1, 2_2, 4_4 but not 3_3.
The new algorithm improves the latency as well as the throughput as it requires less PBS in total
closes: please link all relevant issues
PR content/description
Check-list: