Browse Source
* x64: Add some more tests for `ctz`/`clz` * x64: Improve lowerings for i8/i16/i128 `ctz` and `clz` intructionspull/8677/head
Afonso Bordado
6 months ago
committed by
GitHub
9 changed files with 599 additions and 26 deletions
@ -0,0 +1,198 @@ |
|||
test compile precise-output |
|||
set enable_llvm_abi_extensions=true |
|||
target x86_64 |
|||
|
|||
|
|||
function %clz(i128) -> i128 { |
|||
block0(v0: i128): |
|||
v1 = clz v0 |
|||
return v1 |
|||
} |
|||
|
|||
; VCode: |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block0: |
|||
; movq %rdi, %r8 |
|||
; movabsq $-1, %rcx |
|||
; bsrq %rsi, %r9 |
|||
; cmovzq %rcx, %r9, %r9 |
|||
; movl $63, %edi |
|||
; subq %rdi, %r9, %rdi |
|||
; movabsq $-1, %rdx |
|||
; bsrq %r8, %r10 |
|||
; cmovzq %rdx, %r10, %r10 |
|||
; movl $63, %eax |
|||
; subq %rax, %r10, %rax |
|||
; addq %rax, $64, %rax |
|||
; cmpq $64, %rdi |
|||
; cmovnzq %rdi, %rax, %rax |
|||
; xorq %rdx, %rdx, %rdx |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; ret |
|||
; |
|||
; Disassembled: |
|||
; block0: ; offset 0x0 |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block1: ; offset 0x4 |
|||
; movq %rdi, %r8 |
|||
; movq $18446744073709551615, %rcx |
|||
; bsrq %rsi, %r9 |
|||
; cmoveq %rcx, %r9 |
|||
; movl $0x3f, %edi |
|||
; subq %r9, %rdi |
|||
; movq $18446744073709551615, %rdx |
|||
; bsrq %r8, %r10 |
|||
; cmoveq %rdx, %r10 |
|||
; movl $0x3f, %eax |
|||
; subq %r10, %rax |
|||
; addq $0x40, %rax |
|||
; cmpq $0x40, %rdi |
|||
; cmovneq %rdi, %rax |
|||
; xorq %rdx, %rdx |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; retq |
|||
|
|||
function %clz(i64) -> i64 { |
|||
block0(v0: i64): |
|||
v1 = clz v0 |
|||
return v1 |
|||
} |
|||
|
|||
; VCode: |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block0: |
|||
; movabsq $-1, %rax |
|||
; bsrq %rdi, %r8 |
|||
; cmovzq %rax, %r8, %r8 |
|||
; movl $63, %eax |
|||
; subq %rax, %r8, %rax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; ret |
|||
; |
|||
; Disassembled: |
|||
; block0: ; offset 0x0 |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block1: ; offset 0x4 |
|||
; movq $18446744073709551615, %rax |
|||
; bsrq %rdi, %r8 |
|||
; cmoveq %rax, %r8 |
|||
; movl $0x3f, %eax |
|||
; subq %r8, %rax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; retq |
|||
|
|||
function %clz(i32) -> i32 { |
|||
block0(v0: i32): |
|||
v1 = clz v0 |
|||
return v1 |
|||
} |
|||
|
|||
; VCode: |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block0: |
|||
; movabsq $-1, %rax |
|||
; bsrl %edi, %r8d |
|||
; cmovzl %eax, %r8d, %r8d |
|||
; movl $31, %eax |
|||
; subl %eax, %r8d, %eax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; ret |
|||
; |
|||
; Disassembled: |
|||
; block0: ; offset 0x0 |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block1: ; offset 0x4 |
|||
; movq $18446744073709551615, %rax |
|||
; bsrl %edi, %r8d |
|||
; cmovel %eax, %r8d |
|||
; movl $0x1f, %eax |
|||
; subl %r8d, %eax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; retq |
|||
|
|||
function %clz(i16) -> i16 { |
|||
block0(v0: i16): |
|||
v1 = clz v0 |
|||
return v1 |
|||
} |
|||
|
|||
; VCode: |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block0: |
|||
; movzwq %di, %rax |
|||
; movabsq $-1, %rdx |
|||
; bsrq %rax, %r10 |
|||
; cmovzq %rdx, %r10, %r10 |
|||
; movl $63, %eax |
|||
; subq %rax, %r10, %rax |
|||
; subq %rax, $48, %rax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; ret |
|||
; |
|||
; Disassembled: |
|||
; block0: ; offset 0x0 |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block1: ; offset 0x4 |
|||
; movzwq %di, %rax |
|||
; movq $18446744073709551615, %rdx |
|||
; bsrq %rax, %r10 |
|||
; cmoveq %rdx, %r10 |
|||
; movl $0x3f, %eax |
|||
; subq %r10, %rax |
|||
; subq $0x30, %rax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; retq |
|||
|
|||
function %clz(i8) -> i8 { |
|||
block0(v0: i8): |
|||
v1 = clz v0 |
|||
return v1 |
|||
} |
|||
|
|||
; VCode: |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block0: |
|||
; movzbq %dil, %rax |
|||
; movabsq $-1, %rdx |
|||
; bsrq %rax, %r10 |
|||
; cmovzq %rdx, %r10, %r10 |
|||
; movl $63, %eax |
|||
; subq %rax, %r10, %rax |
|||
; subq %rax, $56, %rax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; ret |
|||
; |
|||
; Disassembled: |
|||
; block0: ; offset 0x0 |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block1: ; offset 0x4 |
|||
; movzbq %dil, %rax |
|||
; movq $18446744073709551615, %rdx |
|||
; bsrq %rax, %r10 |
|||
; cmoveq %rdx, %r10 |
|||
; movl $0x3f, %eax |
|||
; subq %r10, %rax |
|||
; subq $0x38, %rax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; retq |
|||
|
@ -0,0 +1,172 @@ |
|||
test compile precise-output |
|||
set enable_llvm_abi_extensions=true |
|||
target x86_64 |
|||
|
|||
|
|||
function %ctz(i128) -> i128 { |
|||
block0(v0: i128): |
|||
v1 = ctz v0 |
|||
return v1 |
|||
} |
|||
|
|||
; VCode: |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block0: |
|||
; movl $64, %ecx |
|||
; bsfq %rdi, %rax |
|||
; cmovzq %rcx, %rax, %rax |
|||
; movl $64, %edi |
|||
; bsfq %rsi, %rdx |
|||
; cmovzq %rdi, %rdx, %rdx |
|||
; addq %rdx, $64, %rdx |
|||
; cmpq $64, %rax |
|||
; cmovzq %rdx, %rax, %rax |
|||
; xorq %rdx, %rdx, %rdx |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; ret |
|||
; |
|||
; Disassembled: |
|||
; block0: ; offset 0x0 |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block1: ; offset 0x4 |
|||
; movl $0x40, %ecx |
|||
; bsfq %rdi, %rax |
|||
; cmoveq %rcx, %rax |
|||
; movl $0x40, %edi |
|||
; bsfq %rsi, %rdx |
|||
; cmoveq %rdi, %rdx |
|||
; addq $0x40, %rdx |
|||
; cmpq $0x40, %rax |
|||
; cmoveq %rdx, %rax |
|||
; xorq %rdx, %rdx |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; retq |
|||
|
|||
function %ctz(i64) -> i64 { |
|||
block0(v0: i64): |
|||
v1 = ctz v0 |
|||
return v1 |
|||
} |
|||
|
|||
; VCode: |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block0: |
|||
; movl $64, %ecx |
|||
; bsfq %rdi, %rax |
|||
; cmovzq %rcx, %rax, %rax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; ret |
|||
; |
|||
; Disassembled: |
|||
; block0: ; offset 0x0 |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block1: ; offset 0x4 |
|||
; movl $0x40, %ecx |
|||
; bsfq %rdi, %rax |
|||
; cmoveq %rcx, %rax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; retq |
|||
|
|||
function %ctz(i32) -> i32 { |
|||
block0(v0: i32): |
|||
v1 = ctz v0 |
|||
return v1 |
|||
} |
|||
|
|||
; VCode: |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block0: |
|||
; movl $32, %ecx |
|||
; bsfl %edi, %eax |
|||
; cmovzl %ecx, %eax, %eax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; ret |
|||
; |
|||
; Disassembled: |
|||
; block0: ; offset 0x0 |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block1: ; offset 0x4 |
|||
; movl $0x20, %ecx |
|||
; bsfl %edi, %eax |
|||
; cmovel %ecx, %eax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; retq |
|||
|
|||
function %ctz(i16) -> i16 { |
|||
block0(v0: i16): |
|||
v1 = ctz v0 |
|||
return v1 |
|||
} |
|||
|
|||
; VCode: |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block0: |
|||
; movzwl %di, %ecx |
|||
; orl %ecx, $65536, %ecx |
|||
; movl $16, %r9d |
|||
; bsfl %ecx, %eax |
|||
; cmovzl %r9d, %eax, %eax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; ret |
|||
; |
|||
; Disassembled: |
|||
; block0: ; offset 0x0 |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block1: ; offset 0x4 |
|||
; movzwl %di, %ecx |
|||
; orl $0x10000, %ecx |
|||
; movl $0x10, %r9d |
|||
; bsfl %ecx, %eax |
|||
; cmovel %r9d, %eax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; retq |
|||
|
|||
function %ctz(i8) -> i8 { |
|||
block0(v0: i8): |
|||
v1 = ctz v0 |
|||
return v1 |
|||
} |
|||
|
|||
; VCode: |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block0: |
|||
; movzbl %dil, %ecx |
|||
; orl %ecx, $256, %ecx |
|||
; movl $8, %r9d |
|||
; bsfl %ecx, %eax |
|||
; cmovzl %r9d, %eax, %eax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; ret |
|||
; |
|||
; Disassembled: |
|||
; block0: ; offset 0x0 |
|||
; pushq %rbp |
|||
; movq %rsp, %rbp |
|||
; block1: ; offset 0x4 |
|||
; movzbl %dil, %ecx |
|||
; orl $0x100, %ecx |
|||
; movl $8, %r9d |
|||
; bsfl %ecx, %eax |
|||
; cmovel %r9d, %eax |
|||
; movq %rbp, %rsp |
|||
; popq %rbp |
|||
; retq |
|||
|
Loading…
Reference in new issue