Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions cranelift/codegen/src/machinst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,44 @@ impl<T: CompilePhase> CompiledCodeBase<T> {

writeln!(buf)?;
}

// `disasm_all` stops at the first instruction it cannot decode and
// reports success rather than an error, so without this the rest of
// the block would silently vanish from the listing. That matters
// most for `precise-output` filetests, whose expectations would
// then assert nothing at all about those bytes. Print them as
// `.byte` directives instead, the same form capstone itself
// produces for undecodable s390x instructions.
let decoded: usize = insns.iter().map(|i| i.bytes().len()).sum();
for (chunk_idx, chunk) in buffer[decoded..].chunks(8).enumerate() {
let addr = start as u64 + decoded as u64 + (chunk_idx * 8) as u64;
let chunk_end = addr + chunk.len() as u64;
let contains = |off| addr <= off && off < chunk_end;

write!(buf, " .byte ")?;
for (i, byte) in chunk.iter().enumerate() {
if i > 0 {
write!(buf, ", ")?;
}
write!(buf, "{byte:#04x}")?;
}

for reloc in relocs.iter().filter(|reloc| contains(reloc.offset as u64)) {
write!(
buf,
" ; reloc_external {} {} {}",
reloc.kind,
reloc.target.display(params),
reloc.addend,
)?;
}

if let Some(trap) = traps.iter().find(|trap| contains(trap.offset as u64)) {
write!(buf, " ; trap: {}", trap.code)?;
}

writeln!(buf)?;
}
}

return Ok(buf);
Expand Down
4 changes: 4 additions & 0 deletions cranelift/filetests/filetests/isa/x64/branches.clif
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,9 @@ block5(v5: i32):
; movslq (%rcx, %r10, 4), %rax
; addq %rax, %rcx
; jmpq *%rcx
; .byte 0x2f, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00
; .byte 0x24, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00
; .byte 0x3a, 0x00, 0x00, 0x00
; block2: ; offset 0x38
; jmp 0x48
; block3: ; offset 0x3d
Expand Down Expand Up @@ -1089,6 +1092,7 @@ block1(v5: i32):
; addb %al, (%rax)
; subb $0, %al
; addb %al, (%rax)
; .byte 0x2f, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00
; block2: ; offset 0x4d
; movq %r11, %rax
; jmp 0x68
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
test compile precise-output
set unwind_info=false
target x86_64 has_avx has_avx_vnni

;; The bundled capstone build cannot decode AVX-VNNI, and capstone stops at the
;; first instruction it does not recognize rather than reporting an error. The
;; remaining bytes are therefore printed as `.byte` directives so that they stay
;; visible here instead of silently disappearing from this expectation. Note
;; that x86 instruction length cannot be determined without decoding, so there
;; is no way to resynchronize: everything after `vpdpbusd`, including the
;; epilogue, is covered by the byte dump.

function %vpdpbusd_i8x16(i8x16, i8x16, i32x4) -> i32x4 {
block0(v0: i8x16, v1: i8x16, v2: i32x4):
v3 = swiden_low v0
v4 = uwiden_low v1
v5 = imul v3, v4
v6 = swiden_high v0
v7 = uwiden_high v1
v8 = imul v6, v7
v9 = swiden_low v5
v10 = swiden_high v5
v11 = iadd_pairwise v9, v10
v12 = swiden_low v8
v13 = swiden_high v8
v14 = iadd_pairwise v12, v13
v15 = iadd_pairwise v11, v14
v16 = iadd v15, v2
return v16
}

; VCode:
; pushq %rbp
; movq %rsp, %rbp
; block0:
; movdqa %xmm0, %xmm5
; movdqa %xmm2, %xmm0
; vpdpbusd %xmm5, %xmm1, %xmm0
; movq %rbp, %rsp
; popq %rbp
; retq
;
; Disassembled:
; block0: ; offset 0x0
; pushq %rbp
; movq %rsp, %rbp
; block1: ; offset 0x4
; movdqa %xmm0, %xmm5
; movdqa %xmm2, %xmm0
; .byte 0xc4, 0xe2, 0x71, 0x50, 0xc5, 0x48, 0x89, 0xec
; .byte 0x5d, 0xc3

1 change: 1 addition & 0 deletions cranelift/filetests/filetests/isa/x64/f128const.clif
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ block0():
; addb %al, (%rax)
; addb %al, (%rax)
; addb %bh, %bh
; .byte 0x3f

8 changes: 8 additions & 0 deletions cranelift/filetests/filetests/isa/x64/fcvt-avx.clif
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ block0(v0: i64x2):
; addb %al, (%rax)
; addb %al, (%rax)
; addb %al, (%rax)
; .byte 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
; .byte 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
; .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x43
; .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x43
; .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x45
; .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x45
; .byte 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x45
; .byte 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x45

function %i64x2_to_f64x2(i64x2) -> f64x2 {
block0(v0: i64x2):
Expand Down
9 changes: 9 additions & 0 deletions cranelift/filetests/filetests/isa/x64/fcvt.clif
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ block0(v0: i32x4):
; addb %al, (%rax)
; addb %al, (%rax)
; addb %dh, (%rax)
; .byte 0x43

function %f12(i32x4) -> f32x4 {
block0(v0: i32x4):
Expand Down Expand Up @@ -1195,6 +1196,14 @@ block0(v0: i64x2):
; addb %al, (%rax)
; addb %al, (%rax)
; addb %al, (%rax)
; .byte 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
; .byte 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
; .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x43
; .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x43
; .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x45
; .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x45
; .byte 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x45
; .byte 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x45

function %i64x2_to_f64x2(i64x2) -> f64x2 {
block0(v0: i64x2):
Expand Down
2 changes: 2 additions & 0 deletions cranelift/filetests/filetests/isa/x64/float-avx.clif
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,8 @@ block0(v0: f64x2):
; addb %al, (%rax)
; addb %al, (%rax)
; sarb $0xff, %bh
; .byte 0xff, 0xdf, 0x41, 0x00, 0x00, 0xc0, 0xff, 0xff
; .byte 0xff, 0xdf, 0x41

function %load_and_store_f32(i64, i64) {
block0(v0: i64, v1: i64):
Expand Down
1 change: 1 addition & 0 deletions cranelift/filetests/filetests/isa/x64/i128.clif
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,7 @@ block0(v0: i128, v1: i128):
; addb %ah, (%rax, %rax)
; addb %al, (%rax)
; addb %al, (%rax)
; .byte 0x00

function %uadd_overflow_as_i128(i64, i64) -> i64, i64 {
block0(v0: i64, v1: i64):
Expand Down
1 change: 1 addition & 0 deletions cranelift/filetests/filetests/isa/x64/immediates.clif
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ block0(v0: i64, v1: i64):
; fstp %st(5)
; outb %al, %dx
; outb %al, %dx
; .byte 0xff, 0xff

1 change: 1 addition & 0 deletions cranelift/filetests/filetests/isa/x64/mul.clif
Original file line number Diff line number Diff line change
Expand Up @@ -698,4 +698,5 @@ block0:
; andb (%rdx), %ah
; andb (%rax), %al
; addb %al, (%rax)
; .byte 0x00

2 changes: 2 additions & 0 deletions cranelift/filetests/filetests/isa/x64/narrowing.clif
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ block0(v0: f64x2):
; addb %al, (%rax)
; addb %al, (%rax)
; addb %al, %al
; .byte 0xff, 0xff, 0xff, 0xdf, 0x41, 0x00, 0x00, 0xc0
; .byte 0xff, 0xff, 0xff, 0xdf, 0x41

function %f4(i16x8, i16x8) -> i8x16 {
block0(v0: i16x8, v1: i16x8):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ block0(v0: f32, v1: f32):
; addb %al, (%rax)
; addb %al, (%rax)
; addb %al, (%rax)
; .byte 0x00

2 changes: 2 additions & 0 deletions cranelift/filetests/filetests/isa/x64/shuffle-avx512.clif
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ block0(v0: i8x16, v1: i8x16):
; addb %al, (%rax)
; addb %al, (%rax)
; addb %al, (%rax)
; .byte 0x11

function %f3(i8x16, i8x16) -> i8x16 {
block0(v0: i8x16, v1: i8x16):
Expand Down Expand Up @@ -75,4 +76,5 @@ block0(v0: i8x16, v1: i8x16):
; addb %bl, (%rdi)
; sbbb (%rsi, %rax), %al
; orb $0xb, %al
; .byte 0x17, 0x0d, 0x18, 0x04, 0x02, 0x0f, 0x11, 0x05

41 changes: 41 additions & 0 deletions cranelift/filetests/filetests/isa/x64/simd-arith-avx.clif
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ block0(v0: i16x8, v1: i16x8):
; addb %al, (%rax)
; addb %al, -0x7fff8000(%rax)
; addb %al, -0x7fff8000(%rax)
; .byte 0x00, 0x80, 0x00, 0x80

function %i64x2_extmul_high_i32x4_s(i32x4, i32x4) -> i64x2 {
block0(v0: i32x4, v1: i32x4):
Expand Down Expand Up @@ -703,6 +704,7 @@ block0(v0: i32x4):
; addb %al, (%r8)
; addb %al, (%rax)
; addb %al, (%rax)
; .byte 0x30, 0x43

function %f32x4_add(f32x4, f32x4) -> f32x4 {
block0(v0: f32x4, v1: f32x4):
Expand Down Expand Up @@ -1298,6 +1300,7 @@ block0(v0: i16x8):
; addb %al, (%rcx)
; addb %al, (%rcx)
; addb %al, (%rcx)
; .byte 0x00

function %i8x16_splat(i8) -> i8x16 {
block0(v0: i8):
Expand Down Expand Up @@ -1370,6 +1373,10 @@ block0(v0: f64x2):
; addb %al, (%rax)
; addb %al, (%rax)
; loopne 0x33
; .byte 0xff, 0xff, 0xef, 0x41, 0x00, 0x00, 0xe0, 0xff
; .byte 0xff, 0xff, 0xef, 0x41, 0x00, 0x00, 0x00, 0x00
; .byte 0x00, 0x00, 0x30, 0x43, 0x00, 0x00, 0x00, 0x00
; .byte 0x00, 0x00, 0x30, 0x43

function %i8x16_shl(i8x16, i32) -> i8x16 {
block0(v0: i8x16, v1: i32):
Expand Down Expand Up @@ -1410,6 +1417,22 @@ block0(v0: i8x16, v1: i32):
; addb %al, (%rax)
; addb %al, (%rax)
; addb %al, (%rax)
; .byte 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
; .byte 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
; .byte 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe
; .byte 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe
; .byte 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc
; .byte 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc
; .byte 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8
; .byte 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8
; .byte 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0
; .byte 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0
; .byte 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0
; .byte 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0
; .byte 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0
; .byte 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0
; .byte 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80
; .byte 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80

function %i8x16_shl_imm(i8x16) -> i8x16 {
block0(v0: i8x16):
Expand Down Expand Up @@ -1443,6 +1466,8 @@ block0(v0: i8x16):
; addb %al, (%rax)
; addb %al, (%rax)
; addb %al, (%rax)
; .byte 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe
; .byte 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe

function %i16x8_shl(i16x8, i32) -> i16x8 {
block0(v0: i16x8, v1: i32):
Expand Down Expand Up @@ -1648,6 +1673,22 @@ block0(v0: i8x16, v1: i32):
; addb %al, (%rax)
; addb %al, (%rax)
; addb %al, (%rax)
; .byte 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
; .byte 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
; .byte 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
; .byte 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
; .byte 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f
; .byte 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f
; .byte 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f
; .byte 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f
; .byte 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f
; .byte 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f
; .byte 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07
; .byte 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07
; .byte 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03
; .byte 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03
; .byte 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
; .byte 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01

function %i8x16_ushr_imm(i8x16) -> i8x16 {
block0(v0: i8x16):
Expand Down
2 changes: 2 additions & 0 deletions cranelift/filetests/filetests/isa/x64/simd-bitselect.clif
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ block0(v0: i16x8, v1: i16x8):
; addb %al, (%rax)
; incl (%rax)
; addb %al, (%rax)
; .byte 0xff, 0xff, 0xff, 0x00, 0xff, 0xff

function %bad_const_mask(i8x16, i8x16) -> i8x16 {
block0(v0: i8x16, v1: i8x16):
Expand Down Expand Up @@ -250,4 +251,5 @@ block0(v0: i8x16, v1: i8x16):
; addb %bh, %bh
; addb %al, (%rax)
; addb %al, (%rax)
; .byte 0xff

27 changes: 27 additions & 0 deletions cranelift/filetests/filetests/isa/x64/simd-bitwise-compile.clif
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,24 @@ block0(v0: i32):
; addb %al, (%rcx)
; addb (%rbx), %al
; addb $5, %al
; .byte 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d
; .byte 0x0e, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
; .byte 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
; .byte 0xff, 0xff, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe
; .byte 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe
; .byte 0xfe, 0xfe, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc
; .byte 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc
; .byte 0xfc, 0xfc, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8
; .byte 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8
; .byte 0xf8, 0xf8, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0
; .byte 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0
; .byte 0xf0, 0xf0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0
; .byte 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0
; .byte 0xe0, 0xe0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0
; .byte 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0
; .byte 0xc0, 0xc0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80
; .byte 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80
; .byte 0x80, 0x80

function %ishl_i8x16_imm(i8x16) -> i8x16 {
block0(v0: i8x16):
Expand Down Expand Up @@ -395,6 +413,8 @@ block0(v0: i8x16):
; addb %al, (%rax)
; addb %al, (%rax)
; addb %al, (%rax)
; .byte 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0
; .byte 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0

function %ishl_i16x8_imm(i16x8) -> i16x8 {
block0(v0: i16x8):
Expand Down Expand Up @@ -508,6 +528,10 @@ block0:
; addb %al, (%rcx)
; addb (%rbx), %al
; addb $5, %al
; .byte 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d
; .byte 0x0e, 0x0f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
; .byte 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
; .byte 0x7f, 0x7f

function %ushr_i16x8_imm(i16x8) -> i16x8 {
block0(v0: i16x8):
Expand Down Expand Up @@ -639,6 +663,8 @@ block0(v0: i32):
; addb %al, (%rcx)
; addb (%rbx), %al
; addb $5, %al
; .byte 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d
; .byte 0x0e, 0x0f

function %sshr_i8x16_imm(i8x16, i32) -> i8x16 {
block0(v0: i8x16, v1: i32):
Expand Down Expand Up @@ -926,4 +952,5 @@ block0(v0: i64x2, v1: i32):
; addb %al, (%rax)
; addb %al, (%rax)
; addb %al, (%rax)
; .byte 0x00, 0x80

Loading
Loading