-
Notifications
You must be signed in to change notification settings - Fork 146
[codegen] Document and test IntoBytes
#3109
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| use zerocopy::*; | ||
|
|
||
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| fn bench_as_bytes_dynamic_size(source: &format::CocoPacket) -> &[u8] { | ||
| source.as_bytes() | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| bench_as_bytes_dynamic_size: | ||
| mov rax, rdi | ||
| lea rdx, [2*rsi + 5] | ||
| and rdx, -2 | ||
| ret |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| Iterations: 100 | ||
| Instructions: 400 | ||
| Total Cycles: 137 | ||
| Total uOps: 400 | ||
|
|
||
| Dispatch Width: 4 | ||
| uOps Per Cycle: 2.92 | ||
| IPC: 2.92 | ||
| Block RThroughput: 1.0 | ||
|
|
||
|
|
||
| Instruction Info: | ||
| [1]: #uOps | ||
| [2]: Latency | ||
| [3]: RThroughput | ||
| [4]: MayLoad | ||
| [5]: MayStore | ||
| [6]: HasSideEffects (U) | ||
|
|
||
| [1] [2] [3] [4] [5] [6] Instructions: | ||
| 1 1 0.33 mov rax, rdi | ||
| 1 1 0.50 lea rdx, [2*rsi + 5] | ||
| 1 1 0.33 and rdx, -2 | ||
| 1 1 1.00 U ret | ||
|
|
||
|
|
||
| Resources: | ||
| [0] - SBDivider | ||
| [1] - SBFPDivider | ||
| [2] - SBPort0 | ||
| [3] - SBPort1 | ||
| [4] - SBPort4 | ||
| [5] - SBPort5 | ||
| [6.0] - SBPort23 | ||
| [6.1] - SBPort23 | ||
|
|
||
|
|
||
| Resource pressure per iteration: | ||
| [0] [1] [2] [3] [4] [5] [6.0] [6.1] | ||
| - - 1.33 1.33 - 1.34 - - | ||
|
|
||
| Resource pressure by instruction: | ||
| [0] [1] [2] [3] [4] [5] [6.0] [6.1] Instructions: | ||
| - - - 0.66 - 0.34 - - mov rax, rdi | ||
| - - 0.33 0.67 - - - - lea rdx, [2*rsi + 5] | ||
| - - 1.00 - - - - - and rdx, -2 | ||
| - - - - - 1.00 - - ret |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| use zerocopy::*; | ||
|
|
||
| #[path = "formats/coco_static_size.rs"] | ||
| mod format; | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| fn bench_as_bytes_static_size(source: &format::CocoPacket) -> &[u8] { | ||
| source.as_bytes() | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| bench_as_bytes_static_size: | ||
| mov rax, rdi | ||
| mov edx, 6 | ||
| ret |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| Iterations: 100 | ||
| Instructions: 300 | ||
| Total Cycles: 104 | ||
| Total uOps: 300 | ||
|
|
||
| Dispatch Width: 4 | ||
| uOps Per Cycle: 2.88 | ||
| IPC: 2.88 | ||
| Block RThroughput: 1.0 | ||
|
|
||
|
|
||
| Instruction Info: | ||
| [1]: #uOps | ||
| [2]: Latency | ||
| [3]: RThroughput | ||
| [4]: MayLoad | ||
| [5]: MayStore | ||
| [6]: HasSideEffects (U) | ||
|
|
||
| [1] [2] [3] [4] [5] [6] Instructions: | ||
| 1 1 0.33 mov rax, rdi | ||
| 1 1 0.33 mov edx, 6 | ||
| 1 1 1.00 U ret | ||
|
|
||
|
|
||
| Resources: | ||
| [0] - SBDivider | ||
| [1] - SBFPDivider | ||
| [2] - SBPort0 | ||
| [3] - SBPort1 | ||
| [4] - SBPort4 | ||
| [5] - SBPort5 | ||
| [6.0] - SBPort23 | ||
| [6.1] - SBPort23 | ||
|
|
||
|
|
||
| Resource pressure per iteration: | ||
| [0] [1] [2] [3] [4] [5] [6.0] [6.1] | ||
| - - 0.99 1.00 - 1.01 - - | ||
|
|
||
| Resource pressure by instruction: | ||
| [0] [1] [2] [3] [4] [5] [6.0] [6.1] Instructions: | ||
| - - 0.99 - - 0.01 - - mov rax, rdi | ||
| - - - 1.00 - - - - mov edx, 6 | ||
| - - - - - 1.00 - - ret |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,27 @@ | ||
| use zerocopy_derive::*; | ||
|
|
||
| // The only valid value of this type are the bytes `0xC0C0`. | ||
| #[derive(TryFromBytes, KnownLayout, Immutable)] | ||
| #[derive(TryFromBytes, KnownLayout, Immutable, IntoBytes)] | ||
| #[repr(u16)] | ||
| pub enum C0C0 { | ||
| _XC0C0 = 0xC0C0, | ||
| } | ||
|
|
||
| #[derive(FromBytes, KnownLayout, Immutable)] | ||
| #[repr(C, align(2))] | ||
| pub struct Packet<Magic> { | ||
| magic_number: Magic, | ||
| mug_size: u8, | ||
| temperature: u8, | ||
| marshmallows: [[u8; 2]], | ||
| macro_rules! define_packet { | ||
| ($name: ident, $trait: ident, $leading_field: ty) => { | ||
| #[derive($trait, KnownLayout, Immutable, IntoBytes)] | ||
| #[repr(C, align(2))] | ||
| pub struct $name { | ||
| magic_number: $leading_field, | ||
| mug_size: u8, | ||
| temperature: u8, | ||
| marshmallows: [[u8; 2]], | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /// A packet begining with the magic number `0xC0C0`. | ||
| pub type CocoPacket = Packet<C0C0>; | ||
| /// Packet begins with bytes 0xC0C0. | ||
| define_packet!(CocoPacket, TryFromBytes, C0C0); | ||
|
|
||
| /// A packet beginning with any two initialized bytes. | ||
| pub type LocoPacket = Packet<[u8; 2]>; | ||
| /// Packet begins with any two bytes. | ||
| define_packet!(LocoPacket, FromBytes, [u8; 2]); | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,27 @@ | ||
| use zerocopy_derive::*; | ||
|
|
||
| // The only valid value of this type are the bytes `0xC0C0`. | ||
| #[derive(TryFromBytes, KnownLayout, Immutable)] | ||
| #[derive(TryFromBytes, KnownLayout, Immutable, IntoBytes)] | ||
| #[repr(u16)] | ||
| pub enum C0C0 { | ||
| _XC0C0 = 0xC0C0, | ||
| } | ||
|
|
||
| #[derive(FromBytes, KnownLayout, Immutable)] | ||
| #[repr(C, align(2))] | ||
| pub struct Packet<Magic> { | ||
| magic_number: Magic, | ||
| mug_size: u8, | ||
| temperature: u8, | ||
| marshmallows: [u8; 2], | ||
| macro_rules! define_packet { | ||
| ($name: ident, $trait: ident, $leading_field: ty) => { | ||
| #[derive($trait, KnownLayout, Immutable, IntoBytes)] | ||
| #[repr(C, align(2))] | ||
| pub struct $name { | ||
| magic_number: $leading_field, | ||
| mug_size: u8, | ||
| temperature: u8, | ||
| marshmallows: [u8; 2], | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /// A packet begining with the magic number `0xC0C0`. | ||
| pub type CocoPacket = Packet<C0C0>; | ||
| /// Packet begins with bytes 0xC0C0. | ||
| define_packet!(CocoPacket, TryFromBytes, C0C0); | ||
|
|
||
| /// A packet beginning with any two initialized bytes. | ||
| pub type LocoPacket = Packet<[u8; 2]>; | ||
| /// Packet begins with any two bytes. | ||
| define_packet!(LocoPacket, FromBytes, [u8; 2]); |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| use zerocopy::*; | ||
|
|
||
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| fn bench_write_to_dynamic_size(source: &format::CocoPacket, destination: &mut [u8]) -> Option<()> { | ||
| source.write_to(destination).ok() | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| bench_write_to_dynamic_size: | ||
| push r14 | ||
| push rbx | ||
| push rax | ||
| mov rbx, rcx | ||
| lea r14, [2*rsi + 5] | ||
| and r14, -2 | ||
| cmp rcx, r14 | ||
| jne .LBB5_2 | ||
| mov rax, rdi | ||
| mov rdi, rdx | ||
| mov rsi, rax | ||
| mov rdx, rbx | ||
| call qword ptr [rip + memcpy@GOTPCREL] | ||
| .LBB5_2: | ||
| cmp rbx, r14 | ||
| sete al | ||
| add rsp, 8 | ||
| pop rbx | ||
| pop r14 | ||
| ret |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| Iterations: 100 | ||
| Instructions: 1900 | ||
| Total Cycles: 2890 | ||
| Total uOps: 2500 | ||
|
|
||
| Dispatch Width: 4 | ||
| uOps Per Cycle: 0.87 | ||
| IPC: 0.66 | ||
| Block RThroughput: 6.3 | ||
|
|
||
|
|
||
| Instruction Info: | ||
| [1]: #uOps | ||
| [2]: Latency | ||
| [3]: RThroughput | ||
| [4]: MayLoad | ||
| [5]: MayStore | ||
| [6]: HasSideEffects (U) | ||
|
|
||
| [1] [2] [3] [4] [5] [6] Instructions: | ||
| 2 5 1.00 * push r14 | ||
| 2 5 1.00 * push rbx | ||
| 2 5 1.00 * push rax | ||
| 1 1 0.33 mov rbx, rcx | ||
| 1 1 0.50 lea r14, [2*rsi + 5] | ||
| 1 1 0.33 and r14, -2 | ||
| 1 1 0.33 cmp rcx, r14 | ||
| 1 1 1.00 jne .LBB5_2 | ||
| 1 1 0.33 mov rax, rdi | ||
| 1 1 0.33 mov rdi, rdx | ||
| 1 1 0.33 mov rsi, rax | ||
| 1 1 0.33 mov rdx, rbx | ||
| 4 7 1.00 * call qword ptr [rip + memcpy@GOTPCREL] | ||
| 1 1 0.33 cmp rbx, r14 | ||
| 1 1 0.50 sete al | ||
| 1 1 0.33 add rsp, 8 | ||
| 1 6 0.50 * pop rbx | ||
| 1 6 0.50 * pop r14 | ||
| 1 1 1.00 U ret | ||
|
|
||
|
|
||
| Resources: | ||
| [0] - SBDivider | ||
| [1] - SBFPDivider | ||
| [2] - SBPort0 | ||
| [3] - SBPort1 | ||
| [4] - SBPort4 | ||
| [5] - SBPort5 | ||
| [6.0] - SBPort23 | ||
| [6.1] - SBPort23 | ||
|
|
||
|
|
||
| Resource pressure per iteration: | ||
| [0] [1] [2] [3] [4] [5] [6.0] [6.1] | ||
| - - 4.66 4.64 4.00 4.70 4.00 3.00 | ||
|
|
||
| Resource pressure by instruction: | ||
| [0] [1] [2] [3] [4] [5] [6.0] [6.1] Instructions: | ||
| - - - - 1.00 - - 1.00 push r14 | ||
| - - - - 1.00 - 1.00 - push rbx | ||
| - - - - 1.00 - - 1.00 push rax | ||
| - - 0.02 0.97 - 0.01 - - mov rbx, rcx | ||
| - - 0.97 0.03 - - - - lea r14, [2*rsi + 5] | ||
| - - 0.63 0.35 - 0.02 - - and r14, -2 | ||
| - - 0.31 0.34 - 0.35 - - cmp rcx, r14 | ||
| - - - - - 1.00 - - jne .LBB5_2 | ||
| - - 0.33 0.33 - 0.34 - - mov rax, rdi | ||
| - - 0.36 0.31 - 0.33 - - mov rdi, rdx | ||
| - - 0.33 0.35 - 0.32 - - mov rsi, rax | ||
| - - 0.35 0.63 - 0.02 - - mov rdx, rbx | ||
| - - - - 1.00 1.00 2.00 - call qword ptr [rip + memcpy@GOTPCREL] | ||
| - - 0.65 0.35 - - - - cmp rbx, r14 | ||
| - - 0.69 - - 0.31 - - sete al | ||
| - - 0.02 0.98 - - - - add rsp, 8 | ||
| - - - - - - - 1.00 pop rbx | ||
| - - - - - - 1.00 - pop r14 | ||
| - - - - - 1.00 - - ret |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| use zerocopy::*; | ||
|
|
||
| #[path = "formats/coco_dynamic_size.rs"] | ||
| mod format; | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| fn bench_write_to_prefix_dynamic_size( | ||
| source: &format::CocoPacket, | ||
| destination: &mut [u8], | ||
| ) -> Option<()> { | ||
| source.write_to_prefix(destination).ok() | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| bench_write_to_prefix_dynamic_size: | ||
| push r14 | ||
| push rbx | ||
| push rax | ||
| mov rbx, rcx | ||
| lea r14, [2*rsi + 5] | ||
| and r14, -2 | ||
| cmp r14, rcx | ||
| ja .LBB5_2 | ||
| mov rax, rdi | ||
| mov rdi, rdx | ||
| mov rsi, rax | ||
| mov rdx, r14 | ||
| call qword ptr [rip + memcpy@GOTPCREL] | ||
| .LBB5_2: | ||
| cmp r14, rbx | ||
| setbe al | ||
| add rsp, 8 | ||
| pop rbx | ||
| pop r14 | ||
| ret |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.