Skip to content

Commit 52fb0e4

Browse files
committed
[assert-instr] compare only the instruction prefix
When comparing the assembly instructions against the expected instruction, depending on the platform, we might end up with `tzcntl != tzcnt`. This commit truncates the instructions to the length of the expected instruction, such that `tzcntl => tzcnt` and the comparison succeeds.
1 parent 799b92c commit 52fb0e4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

assert-instr/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,14 @@ pub fn assert(fnptr: usize, expected: &str) {
242242
// Look for `expected` as the first part of any instruction in this
243243
// function, returning if we do indeed find it.
244244
for instr in function.instrs.iter() {
245+
// Gets the first instruction, e.g. tzcntl in tzcntl %rax,%rax
245246
if let Some(part) = instr.parts.get(0) {
246-
if part == expected {
247-
return
247+
// Truncates the instruction with the length of the expected
248+
// instruction: tzcntl => tzcnt and compares that.
249+
if let Some(part) = part.get(0..expected.len()) {
250+
if part == expected {
251+
return
252+
}
248253
}
249254
}
250255
}

0 commit comments

Comments
 (0)