Browse Source

cranelift: Add support for `bswap.i128` (#5186)

* fuzzgen: Request only one variable for bswap

This was included by accident. Bswap only has one input, instead of two.

* cranelift: Add `bswap.i128` support

Adds support only for x86, AArch64, S390X.

RISCV does not yet have bswap.
pull/5191/head
Afonso Bordado 2 years ago
committed by GitHub
parent
commit
2c69b94744
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      cranelift/codegen/src/isa/aarch64/lower.isle
  2. 11
      cranelift/codegen/src/isa/s390x/lower.isle
  3. 5
      cranelift/codegen/src/isa/x64/lower.isle
  4. 6
      cranelift/filetests/filetests/runtests/i128-bswap.clif
  5. 10
      cranelift/fuzzgen/src/function_generator.rs

5
cranelift/codegen/src/isa/aarch64/lower.isle

@ -1528,6 +1528,11 @@
(rule (lower (has_type $I64 (bswap x))) (rule (lower (has_type $I64 (bswap x)))
(a64_rev64 $I64 x)) (a64_rev64 $I64 x))
(rule (lower (has_type $I128 (bswap x)))
(value_regs
(a64_rev64 $I64 (value_regs_get x 1))
(a64_rev64 $I64 (value_regs_get x 0))))
;;;; Rules for `bmask` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Rules for `bmask` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Bmask tests the value against zero, and uses `csetm` to assert the result. ;; Bmask tests the value against zero, and uses `csetm` to assert the result.

11
cranelift/codegen/src/isa/s390x/lower.isle

@ -1190,15 +1190,8 @@
;;;; Rules for `bswap` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Rules for `bswap` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(rule (lower (has_type $I16 (bswap x))) (rule (lower (has_type ty (bswap x)))
(lshr_imm $I32 (bswap_reg $I32 x) 16)) (bitrev_bytes ty x))
(rule (lower (has_type $I32 (bswap x)))
(bswap_reg $I32 x))
(rule (lower (has_type $I64 (bswap x)))
(bswap_reg $I64 x))
;;;; Rules for `clz` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Rules for `clz` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

5
cranelift/codegen/src/isa/x64/lower.isle

@ -2060,6 +2060,11 @@
(rule (lower (has_type $I64 (bswap src))) (rule (lower (has_type $I64 (bswap src)))
(x64_bswap $I64 src)) (x64_bswap $I64 src))
(rule (lower (has_type $I128 (bswap src)))
(value_regs
(x64_bswap $I64 (value_regs_get_gpr src 1))
(x64_bswap $I64 (value_regs_get_gpr src 0))))
;; Rules for `is_null` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Rules for `is_null` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Null references are represented by the constant value `0`. ;; Null references are represented by the constant value `0`.

6
cranelift/filetests/filetests/runtests/i128-bswap.clif

@ -1,4 +1,9 @@
test interpret test interpret
test run
set enable_llvm_abi_extensions
target x86_64
target aarch64
target s390x
function %bswap_i128(i128) -> i128 { function %bswap_i128(i128) -> i128 {
block0(v0: i128): block0(v0: i128):
@ -9,4 +14,3 @@ block0(v0: i128):
; run: %bswap_i128(1) == 0x01000000_00000000_00000000_00000000 ; run: %bswap_i128(1) == 0x01000000_00000000_00000000_00000000
; run: %bswap_i128(0x12345678_9ABCDEF0_CAFEF00D_F00DCAFE) == 0xFECA0DF0_0DF0FECA_F0DEBC9A_78563412 ; run: %bswap_i128(0x12345678_9ABCDEF0_CAFEF00D_F00DCAFE) == 0xFECA0DF0_0DF0FECA_F0DEBC9A_78563412
; run: %bswap_i128(-2) == 0xFEFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF ; run: %bswap_i128(-2) == 0xFEFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF

10
cranelift/fuzzgen/src/function_generator.rs

@ -672,12 +672,10 @@ const OPCODE_SIGNATURES: &'static [(
(Opcode::Bmask, &[I64], &[I128], insert_opcode), (Opcode::Bmask, &[I64], &[I128], insert_opcode),
(Opcode::Bmask, &[I128], &[I128], insert_opcode), (Opcode::Bmask, &[I128], &[I128], insert_opcode),
// Bswap // Bswap
(Opcode::Bswap, &[I16, I16], &[I16], insert_opcode), (Opcode::Bswap, &[I16], &[I16], insert_opcode),
(Opcode::Bswap, &[I32, I32], &[I32], insert_opcode), (Opcode::Bswap, &[I32], &[I32], insert_opcode),
(Opcode::Bswap, &[I64, I64], &[I64], insert_opcode), (Opcode::Bswap, &[I64], &[I64], insert_opcode),
// I128 version not yet implemented. (Opcode::Bswap, &[I128], &[I128], insert_opcode),
#[cfg(not(any(target_arch = "x86_64", target_arch = "aarch64")))]
(Opcode::Bswap, &[I128, I128], &[I128], insert_opcode),
// Fadd // Fadd
(Opcode::Fadd, &[F32, F32], &[F32], insert_opcode), (Opcode::Fadd, &[F32, F32], &[F32], insert_opcode),
(Opcode::Fadd, &[F64, F64], &[F64], insert_opcode), (Opcode::Fadd, &[F64, F64], &[F64], insert_opcode),

Loading…
Cancel
Save