-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Machine code verification | ||
|
||
This crates verifies the machine code generated for some of the portable packed | ||
vector APIs by disassembling the API at run-time and comparing the machine code | ||
generated against the desired one for a particular target and target features. | ||
|
||
This is done by using the | ||
[`stdsimd-test`](https://github.com/rust-lang-nursery/stdsimd/tree/master/crates/stdsimd-test) | ||
crate, which exposes the `assert_instr` procedural macro. It is used like this: | ||
|
||
```rust | ||
// The verification functions must be #[inline]: | ||
#[inline] | ||
// Enable the target features required for the desired code generation | ||
// on the different targets: | ||
#[cfg_attr( | ||
any(target_arch = "x86", target_arch = "x86_64"), | ||
target_feature(enable = "avx512f,avx512vl") | ||
)] | ||
// Check that the disassembly contains a particular instruction: | ||
#[cfg_attr( | ||
any(target_arch = "x86", target_arch = "x86_64"), | ||
assert_instr(vpro) | ||
)] | ||
unsafe fn rotate_right_variable(x: u64x8, v: u64x8) -> u64x8 { | ||
x.rotate_right(v) | ||
} | ||
``` | ||
|
||
The `assert_instr` procedural macro creates a test that contains a | ||
`#[inline(never)]` function that calls the API. It then gets a function pointer | ||
to this function, and calls `stdsimd_test::assert` with it, the function name, | ||
and the expected assembly instruction. `stdsimd_test` uses `objdump` or similar | ||
to disassemble itself, it then looks for the function address and name in the | ||
disassembly, and verifies that the machine code for the function contains the | ||
instruction. |