-
Notifications
You must be signed in to change notification settings - Fork 296
stdarch-test
: various cleanups
#1860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
0875002
5bf90b6
b56f7fe
4f5fc03
ca8a120
fb989f8
ded4a23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,12 @@ | |
#![deny(rust_2018_idioms)] | ||
#![allow(clippy::missing_docs_in_private_items, clippy::print_stdout)] | ||
|
||
#[macro_use] | ||
extern crate lazy_static; | ||
#[macro_use] | ||
extern crate cfg_if; | ||
|
||
pub use assert_instr_macro::*; | ||
pub use simd_test_macro::*; | ||
use std::{cmp, collections::HashSet, env, hash, hint::black_box, str}; | ||
use std::{cmp, collections::HashSet, env, hash, hint::black_box, str, sync::LazyLock}; | ||
|
||
cfg_if! { | ||
if #[cfg(target_arch = "wasm32")] { | ||
|
@@ -25,9 +23,7 @@ cfg_if! { | |
} | ||
} | ||
|
||
lazy_static! { | ||
static ref DISASSEMBLY: HashSet<Function> = disassemble_myself(); | ||
} | ||
static DISASSEMBLY: LazyLock<HashSet<Function>> = LazyLock::new(disassemble_myself); | ||
|
||
#[derive(Debug)] | ||
struct Function { | ||
|
@@ -65,11 +61,12 @@ pub fn assert(shim_addr: usize, fnname: &str, expected: &str) { | |
black_box(shim_addr); | ||
|
||
//eprintln!("shim name: {fnname}"); | ||
let function = &DISASSEMBLY | ||
.get(&Function::new(fnname)) | ||
.unwrap_or_else(|| panic!("function \"{fnname}\" not found in the disassembly")); | ||
let Some(function) = &DISASSEMBLY.get(&Function::new(fnname)) else { | ||
panic!("function `{fnname}` not found in the disassembly") | ||
}; | ||
//eprintln!(" function: {:?}", function); | ||
|
||
// Trim any filler instructions. | ||
let mut instrs = &function.instrs[..]; | ||
while instrs.last().is_some_and(|s| s == "nop" || s == "int3") { | ||
instrs = &instrs[..instrs.len() - 1]; | ||
|
@@ -84,12 +81,26 @@ pub fn assert(shim_addr: usize, fnname: &str, expected: &str) { | |
// 2. It is a mark, indicating that the instruction will be | ||
// compiled into other instructions - mainly because of llvm | ||
// optimization. | ||
let expected = if expected == "unknown" { | ||
"<unknown>" // Workaround for rust-lang/stdarch#1674, todo: remove when the issue is fixed | ||
} else { | ||
expected | ||
let expected = match expected { | ||
// `<unknown>` is what LLVM will generate for unknown instructions. We use this to fail | ||
// loudly when LLVM does start supporting these instructions. | ||
// | ||
// This was introduced in https://github.com/rust-lang/stdarch/pull/1674 to work around the | ||
// RISC-V P extension not yet being supported. | ||
"unknown" => "<unknown>", | ||
_ => expected, | ||
}; | ||
let found = expected == "nop" || instrs.iter().any(|s| s.starts_with(expected)); | ||
|
||
// Check whether the given instruction is part of the disassemblied body. | ||
let found = expected == "nop" | ||
|| instrs.iter().any(|instruction| { | ||
instruction.starts_with(expected) | ||
// Check that the next character is non-alphabetic. This prevents false negatives | ||
// when e.g. `fminnm` was used but `fmin` was expected. | ||
// | ||
// TODO: resolve the conflicts (x86_64 has a bunch, probably others) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you intending to have this merged as it is, or wait for x86 conflicts to be resolved first? I'm happy to merge either way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is good to go, we can work through the false positives over time (it's not the most fun task). |
||
// && !instruction[expected.len()..].starts_with(|c: char| c.is_ascii_alphabetic()) | ||
}); | ||
|
||
// Look for subroutine call instructions in the disassembly to detect whether | ||
// inlining failed: all intrinsics are `#[inline(always)]`, so calling one | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect digits (
is_ascii_digit
) to also be part of the instruction name.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is what I had earlier, but it gave lots of hits for
ld1
where the test just asserts onld
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any intrinsics that specifically match on "ld". All the load instrinsics explicitly specify the number since this is an important part of the instruction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm maybe it was a different instruction? In any case it gave a lot of false positives somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer if this included digits and had a way to explicitly opt-in to wildcard matching.