-
Notifications
You must be signed in to change notification settings - Fork 44
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
When doing module and division, first cast to unsigned 32 bit then promote to 64 bit #731
Conversation
…omote to 64 bit Signed-off-by: Alan Jowett <[email protected]>
WalkthroughThe pull request introduces modifications to the Changes
Assessment against linked issues
Possibly related PRs
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 5
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (3)
- src/crab/split_dbm.cpp (1 hunks)
- src/test/test_yaml.cpp (1 hunks)
- test-data/muldiv.yaml (1 hunks)
🧰 Additional context used
🔇 Additional comments (4)
test-data/muldiv.yaml (2)
4-16
: LGTM: 32-bit division test case is correct and comprehensive.This test case effectively verifies the behavior of 32-bit unsigned division with a negative divisor. The expected result (1) matches the actual result of the operation, demonstrating correct handling of unsigned division in 32-bit context.
19-30
: LGTM: 32-bit modulo test case is accurate and well-defined.This test case successfully validates the behavior of 32-bit unsigned modulo operation with a negative divisor. The expected result (97779712) aligns with the actual outcome of the operation, demonstrating proper handling of unsigned modulo in 32-bit context.
src/test/test_yaml.cpp (1)
35-35
: LGTM! New test case added correctly.The addition of
YAML_CASE("test-data/muldiv.yaml")
is consistent with the existing structure and follows the correct pattern. This new test case aligns with the PR objectives, focusing on unsigned division and modulo operations.Let's verify the existence of the new test file:
src/crab/split_dbm.cpp (1)
1011-1022
: Request Verification of Immediate Value Casting RulesTo ensure compliance with the BPF ISA specification, please verify whether the immediate value for 64-bit unsigned division and modulo operations should be treated as a signed 32-bit integer (
int32_t
) or an unsigned 32-bit integer (uint32_t
). The current implementation casts toint32_t
whenfinite_width
is 64, which may not align with the specification if the immediate should be unsigned.Run the following script to check for any inconsistencies in the immediate value casting within the codebase:
Also applies to: 1024-1034
Signed-off-by: Alan Jowett <[email protected]>
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (1)
- src/crab/split_dbm.cpp (2 hunks)
🧰 Additional context used
📓 Learnings (2)
📓 Common learnings
Learnt from: Alan-Jowett PR: vbpf/ebpf-verifier#731 File: src/crab/split_dbm.cpp:1024-1034 Timestamp: 2024-10-15T16:40:13.215Z Learning: In the BPF ISA specification, for 64-bit unsigned modulo operations, the immediate value is treated as a 32-bit signed integer, so casting to `int32_t` is correct.
Learnt from: Alan-Jowett PR: vbpf/ebpf-verifier#731 File: src/crab/split_dbm.cpp:1011-1022 Timestamp: 2024-10-15T16:41:02.868Z Learning: In the BPF ISA specification, for 64-bit unsigned division operations, the immediate value is sign-extended from 32 bits to 64 bits and then interpreted as a 64-bit unsigned value, so casting to `int32_t` is correct.
src/crab/split_dbm.cpp (2)
Learnt from: Alan-Jowett PR: vbpf/ebpf-verifier#731 File: src/crab/split_dbm.cpp:1024-1034 Timestamp: 2024-10-15T16:40:13.215Z Learning: In the BPF ISA specification, for 64-bit unsigned modulo operations, the immediate value is treated as a 32-bit signed integer, so casting to `int32_t` is correct.
Learnt from: Alan-Jowett PR: vbpf/ebpf-verifier#731 File: src/crab/split_dbm.cpp:1011-1022 Timestamp: 2024-10-15T16:41:02.868Z Learning: In the BPF ISA specification, for 64-bit unsigned division operations, the immediate value is sign-extended from 32 bits to 64 bits and then interpreted as a 64-bit unsigned value, so casting to `int32_t` is correct.
🔇 Additional comments (3)
src/crab/split_dbm.cpp (3)
1001-1012
: Correct handling of immediate values for unsigned division and moduloThe function
read_imm_for_udiv_or_umod
correctly implements the casting of immediate values for unsigned division and modulo operations according to the BPF ISA specification. By casting touint32_t
for 32-bit width and toint32_t
for 64-bit width, it ensures that immediate values are interpreted correctly, including proper sign extension for 64-bit operations.
1014-1025
: Correct handling of immediate values for signed division and moduloThe function
read_imm_for_sdiv_or_smod
appropriately handles immediate values for signed division and modulo operations in line with the BPF ISA specification. Casting toint32_t
for 32-bit width and toint64_t
for 64-bit width ensures that immediate values are correctly sign-extended and interpreted as signed integers of the appropriate width.
1036-1039
: Appropriate use of helper functions in arithmetic operationsIn the
apply
method, the updated cases forSDIV
,UDIV
,SREM
, andUREM
correctly utilize the helper functionsread_imm_for_sdiv_or_smod
andread_imm_for_udiv_or_umod
to handle immediate values appropriately, ensuring compliance with the BPF ISA specification.
Signed-off-by: Elazar Gershuni <[email protected]>
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
📒 Files selected for processing (1)
- src/crab/split_dbm.cpp (11 hunks)
🧰 Additional context used
📓 Learnings (1)
src/crab/split_dbm.cpp (1)
Learnt from: Alan-Jowett PR: vbpf/ebpf-verifier#731 File: src/crab/split_dbm.cpp:1005-1012 Timestamp: 2024-10-15T18:33:28.643Z Learning: In `src/crab/split_dbm.cpp`, the functions `read_imm_for_udiv_or_umod` and `read_imm_for_sdiv_or_smod` are intentionally kept separate to clarify the differences between unsigned and signed division and modulo operations.
🔇 Additional comments (4)
src/crab/split_dbm.cpp (4)
1006-1012
:read_imm_for_udiv_or_umod
andread_imm_for_sdiv_or_smod
correctly handle immediate values per BPF ISA specificationThe implementation of
read_imm_for_udiv_or_umod
andread_imm_for_sdiv_or_smod
accurately reflects the BPF ISA specification for handling immediate values in unsigned and signed division and modulo operations. Keeping these functions separate enhances code clarity by explicitly distinguishing between the different treatments of immediate values based on operation type and bit width.Also applies to: 1014-1024
1034-1036
: Ensure correct construction oflinear_expression_t
for multiplicationIn the
MUL
case of theapply
method, the line:assign(x, linear_expression_t(k, y));It's important to verify that
linear_expression_t
is correctly constructed to represent the expressiony * k
. Ensure that the constructorlinear_expression_t(k, y)
properly initializes the linear expression for multiplication, as this may not be immediately clear and could lead to incorrect behavior ifk
andy
are misinterpreted.
983-984
: Consistent handling of finite widths in arithmetic operationsThe methods
apply
for both variable and immediate operations acceptfinite_width
as a parameter. Ensure that thefinite_width
is consistently used within these methods when calling functions likeget_interval
,SDiv
,UDiv
, etc., to correctly handle operations according to the specified bit widths and to prevent unintended behavior due to width mismatches.Also applies to: 1026-1027
15-15
: 🛠️ Refactor suggestionConsider passing
variable_t
and fundamental types by const referenceSeveral functions are updated to pass
variable_t
and fundamental types likeint
by value with aconst
qualifier. For non-trivial types likevariable_t
, passing byconst
reference (i.e.,const variable_t&
) can avoid unnecessary copying and improve performance. For fundamental types likeint
, passing by value is acceptable and efficient, and theconst
qualifier can be omitted as it doesn't affect the function signature.Also applies to: 743-743, 926-926, 950-950, 983-984, 1026-1027, 1223-1223, 1233-1233, 1309-1309, 1336-1336
⛔ Skipped due to learnings
Learnt from: elazarg PR: vbpf/ebpf-verifier#689 File: src/crab/split_dbm.cpp:910-910 Timestamp: 2024-09-26T00:57:58.072Z Learning: Avoid suggesting changes that are unrelated to the current PR.
Resolves: #730
This pull request includes changes to handle different bit-widths for unsigned division and modulo operations in the
SplitDBM
class, and adds new test cases to verify these changes.Enhancements to arithmetic operations:
src/crab/split_dbm.cpp
: Modified the handling ofUDIV
andUREM
operations to correctly cast the immediate value based on the bit-width (32-bit or 64-bit) as specified in the BPF ISA specification.Addition of new test cases:
src/test/test_yaml.cpp
: Added a new YAML test case filemuldiv.yaml
to the test suite.test-data/muldiv.yaml
: Created a new test file with cases for 32-bit and 64-bit unsigned division and modulo operations to ensure correct behavior with negative divisors.Summary by CodeRabbit
New Features
Bug Fixes
Documentation