Skip to content
Merged
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
9 changes: 9 additions & 0 deletions benches/as_bytes_dynamic_size.rs
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()
}
5 changes: 5 additions & 0 deletions benches/as_bytes_dynamic_size.x86-64
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
47 changes: 47 additions & 0 deletions benches/as_bytes_dynamic_size.x86-64.mca
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
9 changes: 9 additions & 0 deletions benches/as_bytes_static_size.rs
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()
}
4 changes: 4 additions & 0 deletions benches/as_bytes_static_size.x86-64
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
45 changes: 45 additions & 0 deletions benches/as_bytes_static_size.x86-64.mca
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
28 changes: 16 additions & 12 deletions benches/formats/coco_dynamic_size.rs
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]);
28 changes: 16 additions & 12 deletions benches/formats/coco_static_size.rs
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]);
9 changes: 9 additions & 0 deletions benches/write_to_dynamic_size.rs
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()
}
21 changes: 21 additions & 0 deletions benches/write_to_dynamic_size.x86-64
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
77 changes: 77 additions & 0 deletions benches/write_to_dynamic_size.x86-64.mca
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
12 changes: 12 additions & 0 deletions benches/write_to_prefix_dynamic_size.rs
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()
}
21 changes: 21 additions & 0 deletions benches/write_to_prefix_dynamic_size.x86-64
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
Loading
Loading