* Function names should start with % * Create FunctionName from string * Implement displaying of FunctionName as %nnnn with fallback to #xxxx * Run rustfmt and fix FunctionName::with_string in parser * Implement FunctionName::new as a generic function * Binary function names should start with # * Implement NameRepr for function name * Fix examples in docs to reflect that function names start with % * Rebase and fix filecheck tests
202 lines
8.3 KiB
Plaintext
202 lines
8.3 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() {
|
|
ebb0:
|
|
[-,%rcx] v1 = iconst.i32 1
|
|
[-,%rsi] v2 = iconst.i32 2
|
|
|
|
; 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
|
|
|
|
; 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
|
|
|
|
; 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
|
|
|
|
return
|
|
}
|