Skip to content

Commit fc73624

Browse files
jswrennjoshlf
andauthored
[codegen] Test and document codegen under different layouts (#3085)
* [codegen] Test and document codegen under different layouts This improves the robustness of our suite to different code paths, and illustrates in our documentation the relationship between type complexity and codegen complexity. gherrit-pr-id: G39e297d5b891f5115ef9607b090c5fbe95427d68 * [ci] Change zizmor persona from 'pedantic' to 'regular' * [ci] Temporarily disable `zizmor` job --------- Co-authored-by: Joshua Liebow-Feeser <joshlf@users.noreply.github.com>
1 parent 098b966 commit fc73624

File tree

143 files changed

+3198
-413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+3198
-413
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,8 @@ jobs:
988988
zizmor:
989989
runs-on: ubuntu-latest
990990
name: zizmor
991+
# FIXME(#3093): Re-enable
992+
if: ${{ false }}
991993
steps:
992994
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
993995
with:
@@ -1001,7 +1003,7 @@ jobs:
10011003
# (without manually configuring a ruleset) is to fail the job, which
10021004
# the action only does if advanced-security is false.
10031005
advanced-security: false
1004-
persona: pedantic
1006+
persona: regular
10051007

10061008
# Used to signal to branch protections that all other jobs have succeeded.
10071009
all-jobs-succeed:

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[package]
1616
edition = "2021"
1717
name = "zerocopy"
18-
version = "0.8.41-alpha"
18+
version = "0.8.41"
1919
authors = [
2020
"Joshua Liebow-Feeser <joshlf@google.com>",
2121
"Jack Wrenn <jswrenn@amazon.com>",
@@ -112,13 +112,13 @@ __internal_use_only_features_that_work_on_stable = [
112112
]
113113

114114
[dependencies]
115-
zerocopy-derive = { version = "=0.8.41-alpha", path = "zerocopy-derive", optional = true }
115+
zerocopy-derive = { version = "=0.8.41", path = "zerocopy-derive", optional = true }
116116

117117
# The "associated proc macro pattern" ensures that the versions of zerocopy and
118118
# zerocopy-derive remain equal, even if the 'derive' feature isn't used.
119119
# See: https://github.com/matklad/macro-dep-test
120120
[target.'cfg(any())'.dependencies]
121-
zerocopy-derive = { version = "=0.8.41-alpha", path = "zerocopy-derive" }
121+
zerocopy-derive = { version = "=0.8.41", path = "zerocopy-derive" }
122122

123123
[dev-dependencies]
124124
# FIXME(#381) Remove this dependency once we have our own layout gadgets.
@@ -129,4 +129,4 @@ rustversion = "1.0"
129129
static_assertions = "1.1"
130130
testutil = { path = "testutil" }
131131
# In tests, unlike in production, zerocopy-derive is not optional
132-
zerocopy-derive = { version = "=0.8.41-alpha", path = "zerocopy-derive" }
132+
zerocopy-derive = { version = "=0.8.41", path = "zerocopy-derive" }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use zerocopy_derive::*;
2+
3+
// The only valid value of this type are the bytes `0xC0C0`.
4+
#[derive(TryFromBytes, KnownLayout, Immutable)]
5+
#[repr(u16)]
6+
pub enum C0C0 {
7+
_XC0C0 = 0xC0C0,
8+
}
9+
10+
#[derive(FromBytes, KnownLayout, Immutable)]
11+
#[repr(C, align(2))]
12+
pub struct Packet<Magic> {
13+
magic_number: Magic,
14+
mug_size: u8,
15+
temperature: u8,
16+
marshmallows: [u8; 2],
17+
}
18+
19+
/// A packet begining with the magic number `0xC0C0`.
20+
pub type CocoPacket = Packet<C0C0>;
21+
22+
/// A packet beginning with any two initialized bytes.
23+
pub type LocoPacket = Packet<[u8; 2]>;

benches/read_from_bytes.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#[path = "formats/coco_static_size.rs"]
2+
mod format;
3+
4+
#[unsafe(no_mangle)]
5+
fn bench_read_from_bytes_static_size(source: &[u8]) -> Option<format::LocoPacket> {
6+
zerocopy::FromBytes::read_from_bytes(source).ok()
7+
}

benches/read_from_bytes.x86-64

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
bench_read_from_bytes_static_size:
2+
mov rcx, rsi
3+
cmp rsi, 6
4+
jne .LBB5_2
5+
mov eax, dword ptr [rdi]
6+
movzx ecx, word ptr [rdi + 4]
7+
shl rcx, 32
8+
or rcx, rax
9+
.LBB5_2:
10+
shl rcx, 16
11+
inc rcx
12+
xor eax, eax
13+
cmp rsi, 6
14+
cmove rax, rcx
15+
ret

benches/read_from_bytes.x86-64.mca

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Iterations: 100
2+
Instructions: 1300
3+
Total Cycles: 377
4+
Total uOps: 1400
5+
6+
Dispatch Width: 4
7+
uOps Per Cycle: 3.71
8+
IPC: 3.45
9+
Block RThroughput: 3.5
10+
11+
12+
Instruction Info:
13+
[1]: #uOps
14+
[2]: Latency
15+
[3]: RThroughput
16+
[4]: MayLoad
17+
[5]: MayStore
18+
[6]: HasSideEffects (U)
19+
20+
[1] [2] [3] [4] [5] [6] Instructions:
21+
1 1 0.33 mov rcx, rsi
22+
1 1 0.33 cmp rsi, 6
23+
1 1 1.00 jne .LBB5_2
24+
1 5 0.50 * mov eax, dword ptr [rdi]
25+
1 5 0.50 * movzx ecx, word ptr [rdi + 4]
26+
1 1 0.50 shl rcx, 32
27+
1 1 0.33 or rcx, rax
28+
1 1 0.50 shl rcx, 16
29+
1 1 0.33 inc rcx
30+
1 0 0.25 xor eax, eax
31+
1 1 0.33 cmp rsi, 6
32+
2 2 0.67 cmove rax, rcx
33+
1 1 1.00 U ret
34+
35+
36+
Resources:
37+
[0] - SBDivider
38+
[1] - SBFPDivider
39+
[2] - SBPort0
40+
[3] - SBPort1
41+
[4] - SBPort4
42+
[5] - SBPort5
43+
[6.0] - SBPort23
44+
[6.1] - SBPort23
45+
46+
47+
Resource pressure per iteration:
48+
[0] [1] [2] [3] [4] [5] [6.0] [6.1]
49+
- - 3.66 3.67 - 3.67 1.00 1.00
50+
51+
Resource pressure by instruction:
52+
[0] [1] [2] [3] [4] [5] [6.0] [6.1] Instructions:
53+
- - 0.63 0.36 - 0.01 - - mov rcx, rsi
54+
- - 0.05 0.05 - 0.90 - - cmp rsi, 6
55+
- - - - - 1.00 - - jne .LBB5_2
56+
- - - - - - - 1.00 mov eax, dword ptr [rdi]
57+
- - - - - - 1.00 - movzx ecx, word ptr [rdi + 4]
58+
- - 0.97 - - 0.03 - - shl rcx, 32
59+
- - 0.02 0.35 - 0.63 - - or rcx, rax
60+
- - 0.98 - - 0.02 - - shl rcx, 16
61+
- - - 0.98 - 0.02 - - inc rcx
62+
- - - - - - - - xor eax, eax
63+
- - 0.03 0.93 - 0.04 - - cmp rsi, 6
64+
- - 0.98 1.00 - 0.02 - - cmove rax, rcx
65+
- - - - - 1.00 - - ret

benches/read_from_prefix.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#[path = "formats/coco_static_size.rs"]
2+
mod format;
3+
4+
#[unsafe(no_mangle)]
5+
fn bench_read_from_prefix_static_size(source: &[u8]) -> Option<format::LocoPacket> {
6+
match zerocopy::FromBytes::read_from_prefix(source) {
7+
Ok((packet, _rest)) => Some(packet),
8+
_ => None,
9+
}
10+
}

0 commit comments

Comments
 (0)