Skip to content
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

Fix - test_code_length_estimate() #4

Merged
merged 1 commit into from
Dec 19, 2024
Merged

Conversation

Lichtso
Copy link
Collaborator

@Lichtso Lichtso commented Dec 19, 2024

No description provided.

@Lichtso Lichtso requested a review from LucasSte December 19, 2024 13:05
@Lichtso Lichtso force-pushed the fix/test_code_length_estimate branch 2 times, most recently from 3cf48f4 to 7b01ed7 Compare December 19, 2024 17:07
for sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] {
println!("opcode;machine_code_length_per_instruction;assembly");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for debugging?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It enables one to run the test with --nocapture and get a CSV of the machine_code_length_per_instruction.

};
for pc in 0..INSTRUCTION_COUNT {
prog[pc * ebpf::INSN_SIZE] = opcode;
prog[pc * ebpf::INSN_SIZE + 1] = registers;
prog[pc * ebpf::INSN_SIZE + 2] = 0xFF;
prog[pc * ebpf::INSN_SIZE + 3] = 0xFF;
let offset = 7_u16.wrapping_sub(pc as u16);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this subtraction supposed to create randomness?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is for having relative jump offsets in conditional branches. This way some point forward and others backward. Otherwise they would be -1 and always point to themselves.

src/jit.rs Outdated
@@ -1900,12 +1912,19 @@ mod tests {
(machine_code_length_per_instruction + 0.5) as usize
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The floating point division and the 0.5 addition aren't necessary here.

@Lichtso Lichtso force-pushed the fix/test_code_length_estimate branch from 7b01ed7 to ae750f7 Compare December 19, 2024 17:28
@Lichtso Lichtso merged commit 995c78f into main Dec 19, 2024
11 checks passed
@Lichtso Lichtso deleted the fix/test_code_length_estimate branch December 19, 2024 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants