Change the result type for the bit-counting instructions from a fixed i8 to the iB type variable which is the type of the input. This matches the convention in WebAssembly, and at least Intel's instructions will set a full register's worth of count result, even if it is always < 64. Duplicate the Intel 'ur' encoding recipe into 'umr' and 'urm' variants corresponding to the RM and MR encoding variants. The difference is which register is encoded as 'reg' and which is 'r/m' in the ModR/M byte. A 'mov' register copy uses the MR variant, a unary popcnt uses the RM variant.
238 lines
9.6 KiB
Plaintext
238 lines
9.6 KiB
Plaintext
; binary emission of 32-bit code.
|
|
test binemit
|
|
isa intel
|
|
|
|
; The binary encodings can be verified with the command:
|
|
;
|
|
; sed -ne 's/^ *; asm: *//p' filetests/isa/intel/binary32.cton | llvm-mc -show-encoding -triple=i386
|
|
;
|
|
|
|
function %I32() {
|
|
fn0 = function %foo()
|
|
sig0 = signature()
|
|
|
|
ebb0:
|
|
; asm: movl $1, %ecx
|
|
[-,%rcx] v1 = iconst.i32 1 ; bin: b9 00000001
|
|
; asm: movl $2, %esi
|
|
[-,%rsi] v2 = iconst.i32 2 ; bin: be 00000002
|
|
|
|
; Integer Register-Register Operations.
|
|
|
|
; asm: addl %esi, %ecx
|
|
[-,%rcx] v10 = iadd v1, v2 ; bin: 01 f1
|
|
; asm: addl %ecx, %esi
|
|
[-,%rsi] v11 = iadd v2, v1 ; bin: 01 ce
|
|
; asm: subl %esi, %ecx
|
|
[-,%rcx] v12 = isub v1, v2 ; bin: 29 f1
|
|
; asm: subl %ecx, %esi
|
|
[-,%rsi] v13 = isub v2, v1 ; bin: 29 ce
|
|
|
|
; asm: andl %esi, %ecx
|
|
[-,%rcx] v14 = band v1, v2 ; bin: 21 f1
|
|
; asm: andl %ecx, %esi
|
|
[-,%rsi] v15 = band v2, v1 ; bin: 21 ce
|
|
; asm: orl %esi, %ecx
|
|
[-,%rcx] v16 = bor v1, v2 ; bin: 09 f1
|
|
; asm: orl %ecx, %esi
|
|
[-,%rsi] v17 = bor v2, v1 ; bin: 09 ce
|
|
; asm: xorl %esi, %ecx
|
|
[-,%rcx] v18 = bxor v1, v2 ; bin: 31 f1
|
|
; asm: xorl %ecx, %esi
|
|
[-,%rsi] v19 = bxor v2, v1 ; bin: 31 ce
|
|
|
|
; Dynamic shifts take the shift amount in %rcx.
|
|
|
|
; asm: shll %cl, %esi
|
|
[-,%rsi] v20 = ishl v2, v1 ; bin: d3 e6
|
|
; asm: shll %cl, %ecx
|
|
[-,%rcx] v21 = ishl v1, v1 ; bin: d3 e1
|
|
; asm: shrl %cl, %esi
|
|
[-,%rsi] v22 = ushr v2, v1 ; bin: d3 ee
|
|
; asm: shrl %cl, %ecx
|
|
[-,%rcx] v23 = ushr v1, v1 ; bin: d3 e9
|
|
; asm: sarl %cl, %esi
|
|
[-,%rsi] v24 = sshr v2, v1 ; bin: d3 fe
|
|
; asm: sarl %cl, %ecx
|
|
[-,%rcx] v25 = sshr v1, v1 ; bin: d3 f9
|
|
; asm: roll %cl, %esi
|
|
[-,%rsi] v26 = rotl v2, v1 ; bin: d3 c6
|
|
; asm: roll %cl, %ecx
|
|
[-,%rcx] v27 = rotl v1, v1 ; bin: d3 c1
|
|
; asm: rorl %cl, %esi
|
|
[-,%rsi] v28 = rotr v2, v1 ; bin: d3 ce
|
|
; asm: rorl %cl, %ecx
|
|
[-,%rcx] v29 = rotr v1, v1 ; bin: d3 c9
|
|
|
|
; Integer Register - Immediate 8-bit operations.
|
|
; The 8-bit immediate is sign-extended.
|
|
|
|
; asm: addl $-128, %ecx
|
|
[-,%rcx] v30 = iadd_imm v1, -128 ; bin: 83 c1 80
|
|
; asm: addl $10, %esi
|
|
[-,%rsi] v31 = iadd_imm v2, 10 ; bin: 83 c6 0a
|
|
|
|
; asm: andl $-128, %ecx
|
|
[-,%rcx] v32 = band_imm v1, -128 ; bin: 83 e1 80
|
|
; asm: andl $10, %esi
|
|
[-,%rsi] v33 = band_imm v2, 10 ; bin: 83 e6 0a
|
|
; asm: orl $-128, %ecx
|
|
[-,%rcx] v34 = bor_imm v1, -128 ; bin: 83 c9 80
|
|
; asm: orl $10, %esi
|
|
[-,%rsi] v35 = bor_imm v2, 10 ; bin: 83 ce 0a
|
|
; asm: xorl $-128, %ecx
|
|
[-,%rcx] v36 = bxor_imm v1, -128 ; bin: 83 f1 80
|
|
; asm: xorl $10, %esi
|
|
[-,%rsi] v37 = bxor_imm v2, 10 ; bin: 83 f6 0a
|
|
|
|
; Integer Register - Immediate 32-bit operations.
|
|
|
|
; asm: addl $-128000, %ecx
|
|
[-,%rcx] v40 = iadd_imm v1, -128000 ; bin: 81 c1 fffe0c00
|
|
; asm: addl $1000000, %esi
|
|
[-,%rsi] v41 = iadd_imm v2, 1000000 ; bin: 81 c6 000f4240
|
|
|
|
; asm: andl $-128000, %ecx
|
|
[-,%rcx] v42 = band_imm v1, -128000 ; bin: 81 e1 fffe0c00
|
|
; asm: andl $1000000, %esi
|
|
[-,%rsi] v43 = band_imm v2, 1000000 ; bin: 81 e6 000f4240
|
|
; asm: orl $-128000, %ecx
|
|
[-,%rcx] v44 = bor_imm v1, -128000 ; bin: 81 c9 fffe0c00
|
|
; asm: orl $1000000, %esi
|
|
[-,%rsi] v45 = bor_imm v2, 1000000 ; bin: 81 ce 000f4240
|
|
; asm: xorl $-128000, %ecx
|
|
[-,%rcx] v46 = bxor_imm v1, -128000 ; bin: 81 f1 fffe0c00
|
|
; asm: xorl $1000000, %esi
|
|
[-,%rsi] v47 = bxor_imm v2, 1000000 ; bin: 81 f6 000f4240
|
|
|
|
; Register copies.
|
|
|
|
; asm: movl %esi, %ecx
|
|
[-,%rcx] v80 = copy v2 ; bin: 89 f1
|
|
; asm: movl %ecx, %esi
|
|
[-,%rsi] v81 = copy v1 ; bin: 89 ce
|
|
|
|
; Load/Store instructions.
|
|
|
|
; Register indirect addressing with no displacement.
|
|
|
|
; asm: movl %ecx, (%esi)
|
|
store v1, v2 ; bin: 89 0e
|
|
; asm: movl %esi, (%ecx)
|
|
store v2, v1 ; bin: 89 31
|
|
; asm: movw %cx, (%esi)
|
|
istore16 v1, v2 ; bin: 66 89 0e
|
|
; asm: movw %si, (%ecx)
|
|
istore16 v2, v1 ; bin: 66 89 31
|
|
; asm: movb %cl, (%esi)
|
|
istore8 v1, v2 ; bin: 88 0e
|
|
; Can't store %sil in 32-bit mode (needs REX prefix).
|
|
|
|
; asm: movl (%ecx), %edi
|
|
[-,%rdi] v100 = load.i32 v1 ; bin: 8b 39
|
|
; asm: movl (%esi), %edx
|
|
[-,%rdx] v101 = load.i32 v2 ; bin: 8b 16
|
|
; asm: movzwl (%ecx), %edi
|
|
[-,%rdi] v102 = uload16.i32 v1 ; bin: 0f b7 39
|
|
; asm: movzwl (%esi), %edx
|
|
[-,%rdx] v103 = uload16.i32 v2 ; bin: 0f b7 16
|
|
; asm: movswl (%ecx), %edi
|
|
[-,%rdi] v104 = sload16.i32 v1 ; bin: 0f bf 39
|
|
; asm: movswl (%esi), %edx
|
|
[-,%rdx] v105 = sload16.i32 v2 ; bin: 0f bf 16
|
|
; asm: movzbl (%ecx), %edi
|
|
[-,%rdi] v106 = uload8.i32 v1 ; bin: 0f b6 39
|
|
; asm: movzbl (%esi), %edx
|
|
[-,%rdx] v107 = uload8.i32 v2 ; bin: 0f b6 16
|
|
; asm: movsbl (%ecx), %edi
|
|
[-,%rdi] v108 = sload8.i32 v1 ; bin: 0f be 39
|
|
; asm: movsbl (%esi), %edx
|
|
[-,%rdx] v109 = sload8.i32 v2 ; bin: 0f be 16
|
|
|
|
; Register-indirect with 8-bit signed displacement.
|
|
|
|
; asm: movl %ecx, 100(%esi)
|
|
store v1, v2+100 ; bin: 89 4e 64
|
|
; asm: movl %esi, -100(%ecx)
|
|
store v2, v1-100 ; bin: 89 71 9c
|
|
; asm: movw %cx, 100(%esi)
|
|
istore16 v1, v2+100 ; bin: 66 89 4e 64
|
|
; asm: movw %si, -100(%ecx)
|
|
istore16 v2, v1-100 ; bin: 66 89 71 9c
|
|
; asm: movb %cl, 100(%esi)
|
|
istore8 v1, v2+100 ; bin: 88 4e 64
|
|
|
|
; asm: movl 50(%ecx), %edi
|
|
[-,%rdi] v110 = load.i32 v1+50 ; bin: 8b 79 32
|
|
; asm: movl -50(%esi), %edx
|
|
[-,%rdx] v111 = load.i32 v2-50 ; bin: 8b 56 ce
|
|
; asm: movzwl 50(%ecx), %edi
|
|
[-,%rdi] v112 = uload16.i32 v1+50 ; bin: 0f b7 79 32
|
|
; asm: movzwl -50(%esi), %edx
|
|
[-,%rdx] v113 = uload16.i32 v2-50 ; bin: 0f b7 56 ce
|
|
; asm: movswl 50(%ecx), %edi
|
|
[-,%rdi] v114 = sload16.i32 v1+50 ; bin: 0f bf 79 32
|
|
; asm: movswl -50(%esi), %edx
|
|
[-,%rdx] v115 = sload16.i32 v2-50 ; bin: 0f bf 56 ce
|
|
; asm: movzbl 50(%ecx), %edi
|
|
[-,%rdi] v116 = uload8.i32 v1+50 ; bin: 0f b6 79 32
|
|
; asm: movzbl -50(%esi), %edx
|
|
[-,%rdx] v117 = uload8.i32 v2-50 ; bin: 0f b6 56 ce
|
|
; asm: movsbl 50(%ecx), %edi
|
|
[-,%rdi] v118 = sload8.i32 v1+50 ; bin: 0f be 79 32
|
|
; asm: movsbl -50(%esi), %edx
|
|
[-,%rdx] v119 = sload8.i32 v2-50 ; bin: 0f be 56 ce
|
|
|
|
; Register-indirect with 32-bit signed displacement.
|
|
|
|
; asm: movl %ecx, 10000(%esi)
|
|
store v1, v2+10000 ; bin: 89 8e 00002710
|
|
; asm: movl %esi, -10000(%ecx)
|
|
store v2, v1-10000 ; bin: 89 b1 ffffd8f0
|
|
; asm: movw %cx, 10000(%esi)
|
|
istore16 v1, v2+10000 ; bin: 66 89 8e 00002710
|
|
; asm: movw %si, -10000(%ecx)
|
|
istore16 v2, v1-10000 ; bin: 66 89 b1 ffffd8f0
|
|
; asm: movb %cl, 10000(%esi)
|
|
istore8 v1, v2+10000 ; bin: 88 8e 00002710
|
|
|
|
; asm: movl 50000(%ecx), %edi
|
|
[-,%rdi] v120 = load.i32 v1+50000 ; bin: 8b b9 0000c350
|
|
; asm: movl -50000(%esi), %edx
|
|
[-,%rdx] v121 = load.i32 v2-50000 ; bin: 8b 96 ffff3cb0
|
|
; asm: movzwl 50000(%ecx), %edi
|
|
[-,%rdi] v122 = uload16.i32 v1+50000 ; bin: 0f b7 b9 0000c350
|
|
; asm: movzwl -50000(%esi), %edx
|
|
[-,%rdx] v123 = uload16.i32 v2-50000 ; bin: 0f b7 96 ffff3cb0
|
|
; asm: movswl 50000(%ecx), %edi
|
|
[-,%rdi] v124 = sload16.i32 v1+50000 ; bin: 0f bf b9 0000c350
|
|
; asm: movswl -50000(%esi), %edx
|
|
[-,%rdx] v125 = sload16.i32 v2-50000 ; bin: 0f bf 96 ffff3cb0
|
|
; asm: movzbl 50000(%ecx), %edi
|
|
[-,%rdi] v126 = uload8.i32 v1+50000 ; bin: 0f b6 b9 0000c350
|
|
; asm: movzbl -50000(%esi), %edx
|
|
[-,%rdx] v127 = uload8.i32 v2-50000 ; bin: 0f b6 96 ffff3cb0
|
|
; asm: movsbl 50000(%ecx), %edi
|
|
[-,%rdi] v128 = sload8.i32 v1+50000 ; bin: 0f be b9 0000c350
|
|
; asm: movsbl -50000(%esi), %edx
|
|
[-,%rdx] v129 = sload8.i32 v2-50000 ; bin: 0f be 96 ffff3cb0
|
|
|
|
; Bit-counting instructions.
|
|
|
|
; asm: popcntl %esi, %ecx
|
|
[-,%rcx] v200 = popcnt v2 ; bin: f3 0f b8 ce
|
|
; asm: popcntl %ecx, %esi
|
|
[-,%rsi] v201 = popcnt v1 ; bin: f3 0f b8 f1
|
|
|
|
; asm: call foo
|
|
call fn0() ; bin: e8 PCRel4(fn0) 00000000
|
|
|
|
; asm: call *%ecx
|
|
call_indirect sig0, v1() ; bin: ff d1
|
|
; asm: call *%esi
|
|
call_indirect sig0, v2() ; bin: ff d6
|
|
|
|
; asm: ret
|
|
return ; bin: c3
|
|
}
|