-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmarks for floating point math
This adds comparisons among the compiler-builtins function, system functions if available, and optionally handwritten assembly. These also serve as some additional testing since we check our functions against assembly operations.
- Loading branch information
Showing
12 changed files
with
1,266 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,59 @@ | ||
#![feature(f128)] | ||
|
||
use compiler_builtins::float::add; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use testcrate::float_bench; | ||
|
||
float_bench! { | ||
name: add_f32, | ||
sig: (a: f32, b: f32) -> f32, | ||
crate_fn: add::__addsf3, | ||
sys_fn: __addsf3, | ||
sys_available: all(), | ||
asm: [ | ||
#[cfg(target_arch = "x86_64")] | ||
asm!( | ||
"addss xmm0, xmm1", | ||
"ret", | ||
); | ||
|
||
#[cfg(target_arch = "aarch64")] | ||
asm!( | ||
"fadd s0, s0, s1", | ||
"ret", | ||
); | ||
], | ||
} | ||
|
||
float_bench! { | ||
name: add_f64, | ||
sig: (a: f64, b: f64) -> f64, | ||
crate_fn: add::__adddf3, | ||
sys_fn: __adddf3, | ||
sys_available: all(), | ||
asm: [ | ||
#[cfg(target_arch = "x86_64")] | ||
asm!( | ||
"addsd xmm0, xmm1", | ||
"ret", | ||
); | ||
|
||
#[cfg(target_arch = "aarch64")] | ||
asm!( | ||
"fadd d0, d0, d1", | ||
"ret", | ||
); | ||
], | ||
} | ||
|
||
float_bench! { | ||
name: add_f128, | ||
sig: (a: f128, b: f128) -> f128, | ||
crate_fn: add::__addtf3, | ||
sys_fn: __addtf3, | ||
sys_available: not(feature = "no-sys-f128"), | ||
asm: [] | ||
} | ||
|
||
criterion_group!(float_add, add_f32, add_f64, add_f128); | ||
criterion_main!(float_add); |
This file contains 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,131 @@ | ||
#![feature(f128)] | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use testcrate::float_bench; | ||
|
||
use compiler_builtins::float::cmp; | ||
|
||
float_bench! { | ||
name: cmp_f32_gt, | ||
sig: (a: f32, b: f32) -> i32, | ||
crate_fn: cmp::__gtsf2, | ||
sys_fn: __gtsf2, | ||
sys_available: all(), | ||
asm: [ | ||
#[cfg(target_arch = "x86_64")] | ||
asm!( | ||
"xor eax, eax", | ||
"ucomiss xmm0, xmm1", | ||
"seta al", | ||
"ret", | ||
); | ||
|
||
#[cfg(target_arch = "aarch64")] | ||
asm!( | ||
"fcmp s0, s1", | ||
"cset w0, gt", | ||
"ret", | ||
); | ||
], | ||
} | ||
|
||
float_bench! { | ||
name: cmp_f32_unord, | ||
sig: (a: f32, b: f32) -> i32, | ||
crate_fn: cmp::__unordsf2, | ||
sys_fn: __unordsf2, | ||
sys_available: all(), | ||
asm: [ | ||
#[cfg(target_arch = "x86_64")] | ||
asm!( | ||
"cmpneqss xmm0, xmm1", | ||
"movd eax, xmm0", | ||
"and eax, 1", | ||
"ret", | ||
); | ||
|
||
#[cfg(target_arch = "aarch64")] | ||
asm!( | ||
"fcmp s0, s1", | ||
"cset w0, eq", | ||
"ret", | ||
); | ||
], | ||
} | ||
|
||
float_bench! { | ||
name: cmp_f64_gt, | ||
sig: (a: f64, b: f64) -> i32, | ||
crate_fn: cmp::__gtdf2, | ||
sys_fn: __gtdf2, | ||
sys_available: all(), | ||
asm: [ | ||
#[cfg(target_arch = "x86_64")] | ||
asm!( | ||
"xor eax, eax", | ||
"ucomisd xmm0, xmm1", | ||
"seta al", | ||
"ret", | ||
); | ||
|
||
#[cfg(target_arch = "aarch64")] | ||
asm!( | ||
"fcmp d0, d1", | ||
"cset w0, gt", | ||
"ret", | ||
); | ||
], | ||
} | ||
|
||
float_bench! { | ||
name: cmp_f64_unord, | ||
sig: (a: f64, b: f64) -> i32, | ||
crate_fn: cmp::__unorddf2, | ||
sys_fn: __unorddf2, | ||
sys_available: all(), | ||
asm: [ | ||
#[cfg(target_arch = "x86_64")] | ||
asm!( | ||
"cmpeqsd xmm0, xmm1", | ||
"movq rax, xmm0", | ||
"and eax, 1", | ||
"ret", | ||
); | ||
|
||
#[cfg(target_arch = "aarch64")] | ||
asm!( | ||
"fcmp d0, d1", | ||
"cset w0, eq", | ||
"ret", | ||
); | ||
], | ||
} | ||
|
||
float_bench! { | ||
name: cmp_f128_gt, | ||
sig: (a: f128, b: f128) -> i32, | ||
crate_fn: cmp::__gttf2, | ||
sys_fn: __gttf2, | ||
sys_available: not(feature = "no-sys-f128"), | ||
asm: [] | ||
} | ||
|
||
float_bench! { | ||
name: cmp_f128_unord, | ||
sig: (a: f128, b: f128) -> i32, | ||
crate_fn: cmp::__unordtf2, | ||
sys_fn: __unordtf2, | ||
sys_available: not(feature = "no-sys-f128"), | ||
asm: [] | ||
} | ||
|
||
criterion_group!( | ||
float_cmp, | ||
cmp_f32_gt, | ||
cmp_f32_unord, | ||
cmp_f64_gt, | ||
cmp_f64_unord, | ||
cmp_f128_gt, | ||
cmp_f128_unord | ||
); | ||
criterion_main!(float_cmp); |
Oops, something went wrong.