Skip to content

Commit cd74516

Browse files
committed
Don't count nop instructions after functions
Looks like disassemblers will fill this in and/or LLVM inserts them for alignment, not useful to us in calculations.
1 parent b3281ce commit cd74516

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

stdsimd-test/src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,15 @@ pub fn assert(fnptr: usize, fnname: &str, expected: &str) {
278278
assert_eq!(functions.len(), 1);
279279
let function = &functions[0];
280280

281+
let mut instrs = &function.instrs[..];
282+
while instrs.last().map(|s| s.parts == ["nop"]).unwrap_or(false) {
283+
instrs = &instrs[..instrs.len() - 1];
284+
}
285+
281286
// Look for `expected` as the first part of any instruction in this
282287
// function, returning if we do indeed find it.
283288
let mut found = false;
284-
for instr in &function.instrs {
289+
for instr in instrs {
285290
// Gets the first instruction, e.g. tzcntl in tzcntl %rax,%rax
286291
if let Some(part) = instr.parts.get(0) {
287292
// Truncates the instruction with the length of the expected
@@ -298,7 +303,7 @@ pub fn assert(fnptr: usize, fnname: &str, expected: &str) {
298303
// calling one intrinsic from another should not generate `call`
299304
// instructions.
300305
let mut inlining_failed = false;
301-
for (i, instr) in function.instrs.iter().enumerate() {
306+
for (i, instr) in instrs.iter().enumerate() {
302307
let part = match instr.parts.get(0) {
303308
Some(part) => part,
304309
None => continue,
@@ -342,7 +347,7 @@ pub fn assert(fnptr: usize, fnname: &str, expected: &str) {
342347
_ => 20,
343348
};
344349
let probably_only_one_instruction =
345-
function.instrs.len() < instruction_limit;
350+
instrs.len() < instruction_limit;
346351

347352
if found && probably_only_one_instruction && !inlining_failed {
348353
return;
@@ -354,7 +359,7 @@ pub fn assert(fnptr: usize, fnname: &str, expected: &str) {
354359
"disassembly for {}: ",
355360
sym.as_ref().expect("symbol not found")
356361
);
357-
for (i, instr) in function.instrs.iter().enumerate() {
362+
for (i, instr) in instrs.iter().enumerate() {
358363
print!("\t{:2}: ", i);
359364
for part in &instr.parts {
360365
print!("{} ", part);
@@ -371,7 +376,7 @@ pub fn assert(fnptr: usize, fnname: &str, expected: &str) {
371376
panic!(
372377
"instruction found, but the disassembly contains too many \
373378
instructions: #instructions = {} >= {} (limit)",
374-
function.instrs.len(),
379+
instrs.len(),
375380
instruction_limit
376381
);
377382
} else if inlining_failed {

0 commit comments

Comments
 (0)