Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,11 @@ jobs:
run: |
set -eo pipefail
sudo apt install -qq llvm
# The codegen tests evaluate assembly for multiple target architectures.
# These tests assume that `rustup` is installed on the host. We must
# explicitly add the targets before compilation, because `rustc` aborts
# when commanded to emit assembly for a target that has not been added.
rustup target add --toolchain $(./cargo.sh --version nightly) thumbv7m-none-eabi riscv32imc-unknown-none-elf
./cargo.sh +nightly install --quiet cargo-show-asm
RUSTFLAGS="$RUSTFLAGS -Awarnings" ./cargo.sh +nightly test \
--package zerocopy \
Expand Down
2 changes: 1 addition & 1 deletion benches/formats/coco_dynamic_padding.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use zerocopy_derive::*;
use zerocopy::*;

// The only valid value of this type are the bytes `0xC0C0`.
#[derive(TryFromBytes, KnownLayout, Immutable)]
Expand Down
2 changes: 1 addition & 1 deletion benches/formats/coco_dynamic_size.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use zerocopy_derive::*;
use zerocopy::*;

// The only valid value of this type are the bytes `0xC0C0`.
#[derive(TryFromBytes, KnownLayout, Immutable)]
Expand Down
2 changes: 1 addition & 1 deletion benches/formats/coco_static_size.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use zerocopy_derive::*;
use zerocopy::*;

// The only valid value of this type are the bytes `0xC0C0`.
#[derive(TryFromBytes, KnownLayout, Immutable)]
Expand Down
16 changes: 16 additions & 0 deletions benches/read_from_bytes.cortex-m3
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
bench_read_from_bytes_static_size:
push {r7, lr}
mov r7, sp
cmp r2, #6
bne .LBB0_2
ldrh r2, [r1]
ldr.w r1, [r1, #2]
strh r2, [r0, #2]
str r1, [r0, #4]
movs r1, #1
strh r1, [r0]
pop {r7, pc}
.LBB0_2:
movs r1, #0
strh r1, [r0]
pop {r7, pc}
26 changes: 26 additions & 0 deletions benches/read_from_bytes.generic-rv32
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
bench_read_from_bytes_static_size:
li a3, 6
bne a2, a3, .LBB0_2
lbu a6, 4(a1)
lbu a3, 5(a1)
lbu a4, 1(a1)
lbu a5, 0(a1)
lbu a2, 2(a1)
lbu a1, 3(a1)
slli a4, a4, 8
or a4, a4, a5
slli a6, a6, 16
slli a3, a3, 24
or a3, a3, a6
slli a1, a1, 8
or a1, a1, a2
srli a3, a3, 16
sh a4, 2(a0)
sh a1, 4(a0)
sh a3, 6(a0)
li a1, 1
sh a1, 0(a0)
ret
.LBB0_2:
sh zero, 0(a0)
ret
4 changes: 2 additions & 2 deletions benches/read_from_bytes.x86-64
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
bench_read_from_bytes_static_size:
mov rcx, rsi
cmp rsi, 6
jne .LBB5_2
jne .LBB0_2
Copy link
Collaborator

Choose a reason for hiding this comment

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

Separate from accepting this PR, it looks like we'll need to implement some form of label normalization.

Copy link
Member Author

Choose a reason for hiding this comment

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

IIUC this is just because we're changing how compilation works (compiling in a different context with different numbers of basic blocks), which is why this changed. It should still be stable.

mov eax, dword ptr [rdi]
movzx ecx, word ptr [rdi + 4]
shl rcx, 32
or rcx, rax
.LBB5_2:
.LBB0_2:
shl rcx, 16
inc rcx
xor eax, eax
Expand Down
4 changes: 2 additions & 2 deletions benches/read_from_bytes.x86-64.mca
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Instruction Info:
[1] [2] [3] [4] [5] [6] Instructions:
1 1 0.33 mov rcx, rsi
1 1 0.33 cmp rsi, 6
1 1 1.00 jne .LBB5_2
1 1 1.00 jne .LBB0_2
1 5 0.50 * mov eax, dword ptr [rdi]
1 5 0.50 * movzx ecx, word ptr [rdi + 4]
1 1 0.50 shl rcx, 32
Expand Down Expand Up @@ -52,7 +52,7 @@ Resource pressure by instruction:
[0] [1] [2] [3] [4] [5] [6.0] [6.1] Instructions:
- - 0.63 0.36 - 0.01 - - mov rcx, rsi
- - 0.05 0.05 - 0.90 - - cmp rsi, 6
- - - - - 1.00 - - jne .LBB5_2
- - - - - 1.00 - - jne .LBB0_2
- - - - - - - 1.00 mov eax, dword ptr [rdi]
- - - - - - 1.00 - movzx ecx, word ptr [rdi + 4]
- - 0.97 - - 0.03 - - shl rcx, 32
Expand Down
16 changes: 16 additions & 0 deletions benches/read_from_prefix.cortex-m3
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
bench_read_from_prefix_static_size:
push {r7, lr}
mov r7, sp
cmp r2, #6
bhs .LBB1_2
movs r1, #0
strh r1, [r0]
pop {r7, pc}
.LBB1_2:
ldr r2, [r1]
ldrh r1, [r1, #4]
str.w r2, [r0, #2]
strh r1, [r0, #6]
movs r1, #1
strh r1, [r0]
pop {r7, pc}
26 changes: 26 additions & 0 deletions benches/read_from_prefix.generic-rv32
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
bench_read_from_prefix_static_size:
li a3, 6
bgeu a2, a3, .LBB1_2
sh zero, 0(a0)
ret
.LBB1_2:
lbu a6, 4(a1)
lbu a3, 5(a1)
lbu a4, 0(a1)
lbu a5, 1(a1)
lbu a2, 2(a1)
lbu a1, 3(a1)
slli a3, a3, 8
or a3, a3, a6
slli a2, a2, 16
slli a1, a1, 24
or a1, a1, a2
slli a5, a5, 8
or a4, a4, a5
srli a1, a1, 16
sh a4, 2(a0)
sh a1, 4(a0)
sh a3, 6(a0)
li a1, 1
sh a1, 0(a0)
ret
4 changes: 2 additions & 2 deletions benches/read_from_prefix.x86-64
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
bench_read_from_prefix_static_size:
cmp rsi, 5
jbe .LBB5_2
jbe .LBB1_2
mov eax, dword ptr [rdi]
movzx edi, word ptr [rdi + 4]
shl rdi, 32
or rdi, rax
.LBB5_2:
.LBB1_2:
shl rdi, 16
inc rdi
xor eax, eax
Expand Down
4 changes: 2 additions & 2 deletions benches/read_from_prefix.x86-64.mca
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Instruction Info:

[1] [2] [3] [4] [5] [6] Instructions:
1 1 0.33 cmp rsi, 5
1 1 1.00 jbe .LBB5_2
1 1 1.00 jbe .LBB1_2
1 5 0.50 * mov eax, dword ptr [rdi]
1 5 0.50 * movzx edi, word ptr [rdi + 4]
1 1 0.50 shl rdi, 32
Expand Down Expand Up @@ -50,7 +50,7 @@ Resource pressure per iteration:
Resource pressure by instruction:
[0] [1] [2] [3] [4] [5] [6.0] [6.1] Instructions:
- - 0.05 0.94 - 0.01 - - cmp rsi, 5
- - - - - 1.00 - - jbe .LBB5_2
- - - - - 1.00 - - jbe .LBB1_2
- - - - - - - 1.00 mov eax, dword ptr [rdi]
- - - - - - 1.00 - movzx edi, word ptr [rdi + 4]
- - 0.71 - - 0.29 - - shl rdi, 32
Expand Down
17 changes: 17 additions & 0 deletions benches/read_from_suffix.cortex-m3
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
bench_read_from_suffix_static_size:
push {r7, lr}
mov r7, sp
cmp r2, #6
bhs .LBB2_2
movs r1, #0
strh r1, [r0]
pop {r7, pc}
.LBB2_2:
add r1, r2
ldr r2, [r1, #-6]
ldrh r1, [r1, #-2]
str.w r2, [r0, #2]
strh r1, [r0, #6]
movs r1, #1
strh r1, [r0]
pop {r7, pc}
27 changes: 27 additions & 0 deletions benches/read_from_suffix.generic-rv32
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
bench_read_from_suffix_static_size:
li a3, 6
bgeu a2, a3, .LBB2_2
sh zero, 0(a0)
ret
.LBB2_2:
add a1, a1, a2
lbu a6, -6(a1)
lbu a3, -5(a1)
lbu a4, -4(a1)
lbu a5, -3(a1)
lbu a2, -2(a1)
lbu a1, -1(a1)
slli a4, a4, 16
slli a5, a5, 24
or a4, a4, a5
slli a3, a3, 8
or a3, a3, a6
slli a1, a1, 8
or a1, a1, a2
srli a4, a4, 16
sh a3, 2(a0)
sh a4, 4(a0)
sh a1, 6(a0)
li a1, 1
sh a1, 0(a0)
ret
4 changes: 2 additions & 2 deletions benches/read_from_suffix.x86-64
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
bench_read_from_suffix_static_size:
mov rcx, rsi
cmp rsi, 6
jb .LBB5_2
jb .LBB2_2
mov eax, dword ptr [rdi + rsi - 6]
movzx ecx, word ptr [rdi + rsi - 2]
shl rcx, 32
or rcx, rax
.LBB5_2:
.LBB2_2:
shl rcx, 16
inc rcx
xor eax, eax
Expand Down
4 changes: 2 additions & 2 deletions benches/read_from_suffix.x86-64.mca
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Instruction Info:
[1] [2] [3] [4] [5] [6] Instructions:
1 1 0.33 mov rcx, rsi
1 1 0.33 cmp rsi, 6
1 1 1.00 jb .LBB5_2
1 1 1.00 jb .LBB2_2
1 5 0.50 * mov eax, dword ptr [rdi + rsi - 6]
1 5 0.50 * movzx ecx, word ptr [rdi + rsi - 2]
1 1 0.50 shl rcx, 32
Expand Down Expand Up @@ -52,7 +52,7 @@ Resource pressure by instruction:
[0] [1] [2] [3] [4] [5] [6.0] [6.1] Instructions:
- - 0.63 0.36 - 0.01 - - mov rcx, rsi
- - 0.05 0.05 - 0.90 - - cmp rsi, 6
- - - - - 1.00 - - jb .LBB5_2
- - - - - 1.00 - - jb .LBB2_2
- - - - - - - 1.00 mov eax, dword ptr [rdi + rsi - 6]
- - - - - - 1.00 - movzx ecx, word ptr [rdi + rsi - 2]
- - 0.97 - - 0.03 - - shl rcx, 32
Expand Down
26 changes: 26 additions & 0 deletions benches/ref_from_bytes_dynamic_padding.cortex-m3
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
bench_ref_from_bytes_dynamic_padding:
push {r7, lr}
mov r7, sp
lsls r2, r0, #30
bne .LBB3_3
movw r2, #65532
movt r2, #32767
ands r2, r1
cmp r2, #9
blo .LBB3_3
movw r3, #43691
subs r2, #9
movt r3, #43690
umull r2, r3, r2, r3
lsrs r2, r3, #1
add.w r3, r2, r2, lsl #1
orr r3, r3, #3
adds r3, #9
cmp r1, r3
beq .LBB3_4
.LBB3_3:
movs r0, #0
mov r2, r1
.LBB3_4:
mov r1, r2
pop {r7, pc}
24 changes: 24 additions & 0 deletions benches/ref_from_bytes_dynamic_padding.generic-rv32
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
bench_ref_from_bytes_dynamic_padding:
andi a2, a0, 3
bnez a2, .LBB3_3
lui a2, 524288
addi a2, a2, -4
and a2, a2, a1
li a3, 9
bltu a2, a3, .LBB3_3
addi a2, a2, -9
lui a3, 699051
addi a3, a3, -1365
mulhu a3, a2, a3
srli a2, a3, 1
andi a3, a3, -2
add a3, a3, a2
ori a3, a3, 3
addi a3, a3, 9
beq a1, a3, .LBB3_4
.LBB3_3:
li a0, 0
mv a2, a1
.LBB3_4:
mv a1, a2
ret
10 changes: 5 additions & 5 deletions benches/ref_from_bytes_dynamic_padding.x86-64
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
bench_ref_from_bytes_dynamic_padding:
test dil, 3
jne .LBB5_3
jne .LBB3_3
movabs rax, 9223372036854775804
and rax, rsi
cmp rax, 9
jb .LBB5_3
jb .LBB3_3
add rax, -9
movabs rcx, -6148914691236517205
mul rcx
Expand All @@ -13,10 +13,10 @@ bench_ref_from_bytes_dynamic_padding:
or rax, 3
add rax, 9
cmp rsi, rax
je .LBB5_4
.LBB5_3:
je .LBB3_4
.LBB3_3:
xor edi, edi
mov rdx, rsi
.LBB5_4:
.LBB3_4:
mov rax, rdi
ret
12 changes: 6 additions & 6 deletions benches/ref_from_bytes_dynamic_padding.x86-64.mca
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Instruction Info:

[1] [2] [3] [4] [5] [6] Instructions:
1 1 0.33 test dil, 3
1 1 1.00 jne .LBB5_3
1 1 1.00 jne .LBB3_3
1 1 0.33 movabs rax, 9223372036854775804
1 1 0.33 and rax, rsi
1 1 0.33 cmp rax, 9
1 1 1.00 jb .LBB5_3
1 1 1.00 jb .LBB3_3
1 1 0.33 add rax, -9
1 1 0.33 movabs rcx, -6148914691236517205
2 4 1.00 mul rcx
Expand All @@ -32,7 +32,7 @@ Instruction Info:
1 1 0.33 or rax, 3
1 1 0.33 add rax, 9
1 1 0.33 cmp rsi, rax
1 1 1.00 je .LBB5_4
1 1 1.00 je .LBB3_4
1 0 0.25 xor edi, edi
1 1 0.33 mov rdx, rsi
1 1 0.33 mov rax, rdi
Expand All @@ -57,11 +57,11 @@ Resource pressure per iteration:
Resource pressure by instruction:
[0] [1] [2] [3] [4] [5] [6.0] [6.1] Instructions:
- - 0.64 0.35 - 0.01 - - test dil, 3
- - - - - 1.00 - - jne .LBB5_3
- - - - - 1.00 - - jne .LBB3_3
- - 0.34 0.65 - 0.01 - - movabs rax, 9223372036854775804
- - 0.35 0.65 - - - - and rax, rsi
- - 0.33 0.34 - 0.33 - - cmp rax, 9
- - - - - 1.00 - - jb .LBB5_3
- - - - - 1.00 - - jb .LBB3_3
- - 0.35 - - 0.65 - - add rax, -9
- - 0.97 0.01 - 0.02 - - movabs rcx, -6148914691236517205
- - 1.00 1.00 - - - - mul rcx
Expand All @@ -70,7 +70,7 @@ Resource pressure by instruction:
- - 0.34 0.66 - - - - or rax, 3
- - 0.33 0.66 - 0.01 - - add rax, 9
- - 0.01 0.99 - - - - cmp rsi, rax
- - - - - 1.00 - - je .LBB5_4
- - - - - 1.00 - - je .LBB3_4
- - - - - - - - xor edi, edi
- - 0.32 0.01 - 0.67 - - mov rdx, rsi
- - 0.02 0.34 - 0.64 - - mov rax, rdi
Expand Down
Loading
Loading