forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
aarch64: Add support for the
extr
instruction
This is pattern-matched from `bor` patterns of a specific shape. I found this when doing some benchmarking of Wasmtime on aarch64 and I saw LLVM generating this pattern but Wasmtime didn't. I didn't perform any benchmarking between wasmtime/native though, so I'm just relying on this reducing the number of instructions to probably be a wee bit faster.
- Loading branch information
1 parent
305c3f9
commit 9f4a9e1
Showing
7 changed files
with
326 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
test compile precise-output | ||
target aarch64 | ||
|
||
function %a64_extr_i32_12(i32, i32) -> i32 { | ||
block0(v0: i32, v1: i32): | ||
v2 = ushr_imm v0, 12 | ||
v3 = ishl_imm v1, 20 | ||
v4 = bor v2, v3 | ||
return v4 | ||
} | ||
|
||
; VCode: | ||
; block0: | ||
; ror w0, w1, w0, LSL 12 | ||
; ret | ||
; | ||
; Disassembled: | ||
; block0: ; offset 0x0 | ||
; extr w0, w1, w0, #0xc | ||
; ret | ||
|
||
function %a64_extr_i32_12_swap(i32, i32) -> i32 { | ||
block0(v0: i32, v1: i32): | ||
v2 = ishl_imm v0, 20 | ||
v3 = ushr_imm v1, 12 | ||
v4 = bor v2, v3 | ||
return v4 | ||
} | ||
|
||
; VCode: | ||
; block0: | ||
; ror w0, w0, w1, LSL 12 | ||
; ret | ||
; | ||
; Disassembled: | ||
; block0: ; offset 0x0 | ||
; extr w0, w0, w1, #0xc | ||
; ret | ||
|
||
function %a64_extr_i32_28(i32, i32) -> i32 { | ||
block0(v0: i32, v1: i32): | ||
v2 = ushr_imm v0, 4 | ||
v3 = ishl_imm v1, 28 | ||
v4 = bor v2, v3 | ||
return v4 | ||
} | ||
|
||
; VCode: | ||
; block0: | ||
; ror w0, w1, w0, LSL 4 | ||
; ret | ||
; | ||
; Disassembled: | ||
; block0: ; offset 0x0 | ||
; extr w0, w1, w0, #4 | ||
; ret | ||
|
||
function %a64_extr_i32_28_swap(i32, i32) -> i32 { | ||
block0(v0: i32, v1: i32): | ||
v2 = ishl_imm v0, 4 | ||
v3 = ushr_imm v1, 28 | ||
v4 = bor v2, v3 | ||
return v4 | ||
} | ||
|
||
; VCode: | ||
; block0: | ||
; ror w0, w0, w1, LSL 28 | ||
; ret | ||
; | ||
; Disassembled: | ||
; block0: ; offset 0x0 | ||
; extr w0, w0, w1, #0x1c | ||
; ret | ||
|
||
function %a64_extr_i64_12(i64, i64) -> i64 { | ||
block0(v0: i64, v1: i64): | ||
v2 = ushr_imm v0, 12 | ||
v3 = ishl_imm v1, 52 | ||
v4 = bor v2, v3 | ||
return v4 | ||
} | ||
|
||
; VCode: | ||
; block0: | ||
; ror x0, x1, x0, LSR 12 | ||
; ret | ||
; | ||
; Disassembled: | ||
; block0: ; offset 0x0 | ||
; extr x0, x1, x0, #0xc | ||
; ret | ||
|
||
function %a64_extr_i64_12_swap(i64, i64) -> i64 { | ||
block0(v0: i64, v1: i64): | ||
v2 = ishl_imm v0, 52 | ||
v3 = ushr_imm v1, 12 | ||
v4 = bor v2, v3 | ||
return v4 | ||
} | ||
|
||
; VCode: | ||
; block0: | ||
; ror x0, x0, x1, LSR 12 | ||
; ret | ||
; | ||
; Disassembled: | ||
; block0: ; offset 0x0 | ||
; extr x0, x0, x1, #0xc | ||
; ret | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
;;! target = "aarch64" | ||
;;! test = "compile" | ||
|
||
(module | ||
(func $i32_21 (param i32 i32) (result i32) | ||
local.get 0 | ||
i32.const 11 | ||
i32.shl | ||
local.get 1 | ||
i32.const 21 | ||
i32.shr_u | ||
i32.or) | ||
(func $i32_21_swapped (param i32 i32) (result i32) | ||
local.get 1 | ||
i32.const 21 | ||
i32.shr_u | ||
local.get 0 | ||
i32.const 11 | ||
i32.shl | ||
i32.or) | ||
(func $i32_11 (param i32 i32) (result i32) | ||
local.get 0 | ||
i32.const 21 | ||
i32.shl | ||
local.get 1 | ||
i32.const 11 | ||
i32.shr_u | ||
i32.or) | ||
|
||
(func $i64_21 (param i64 i64) (result i64) | ||
local.get 0 | ||
i64.const 43 | ||
i64.shl | ||
local.get 1 | ||
i64.const 21 | ||
i64.shr_u | ||
i64.or) | ||
(func $i64_21_swapped (param i64 i64) (result i64) | ||
local.get 1 | ||
i64.const 21 | ||
i64.shr_u | ||
local.get 0 | ||
i64.const 43 | ||
i64.shl | ||
i64.or) | ||
(func $i64_11 (param i64 i64) (result i64) | ||
local.get 0 | ||
i64.const 53 | ||
i64.shl | ||
local.get 1 | ||
i64.const 11 | ||
i64.shr_u | ||
i64.or) | ||
) | ||
|
||
;; wasm[0]::function[0]::i32_21: | ||
;; stp x29, x30, [sp, #-0x10]! | ||
;; mov x29, sp | ||
;; extr w2, w5, w4, #0x15 | ||
;; ldp x29, x30, [sp], #0x10 | ||
;; ret | ||
;; | ||
;; wasm[0]::function[1]::i32_21_swapped: | ||
;; stp x29, x30, [sp, #-0x10]! | ||
;; mov x29, sp | ||
;; extr w2, w5, w4, #0x15 | ||
;; ldp x29, x30, [sp], #0x10 | ||
;; ret | ||
;; | ||
;; wasm[0]::function[2]::i32_11: | ||
;; stp x29, x30, [sp, #-0x10]! | ||
;; mov x29, sp | ||
;; extr w2, w5, w4, #0xb | ||
;; ldp x29, x30, [sp], #0x10 | ||
;; ret | ||
;; | ||
;; wasm[0]::function[3]::i64_21: | ||
;; stp x29, x30, [sp, #-0x10]! | ||
;; mov x29, sp | ||
;; extr x2, x5, x4, #0x15 | ||
;; ldp x29, x30, [sp], #0x10 | ||
;; ret | ||
;; | ||
;; wasm[0]::function[4]::i64_21_swapped: | ||
;; stp x29, x30, [sp, #-0x10]! | ||
;; mov x29, sp | ||
;; extr x2, x5, x4, #0x15 | ||
;; ldp x29, x30, [sp], #0x10 | ||
;; ret | ||
;; | ||
;; wasm[0]::function[5]::i64_11: | ||
;; stp x29, x30, [sp, #-0x10]! | ||
;; mov x29, sp | ||
;; extr x2, x5, x4, #0xb | ||
;; ldp x29, x30, [sp], #0x10 | ||
;; ret |