Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

riscv64: Add support for bitcast.i128 with a i128 argument #8851

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cranelift/codegen/src/isa/riscv64/lower.isle
Original file line number Diff line number Diff line change
Expand Up @@ -2465,20 +2465,25 @@

;; These rules should probably be handled in `gen_bitcast`, but it's convenient to have that return
;; a single register, instead of a `ValueRegs`
(rule 2 (lower (has_type $I128 (bitcast _ v @ (value_type (ty_vec_fits_in_register _)))))
(rule 3 (lower (has_type $I128 (bitcast _ v @ (value_type (ty_vec_fits_in_register _)))))
(value_regs
(gen_extractlane $I64X2 v 0)
(gen_extractlane $I64X2 v 1)))

;; Move the high half into a vector register, and then use vslide1up to move it up and
;; insert the lower half in one instruction.
(rule 1 (lower (has_type (ty_vec_fits_in_register _) (bitcast _ v @ (value_type $I128))))
(rule 2 (lower (has_type (ty_vec_fits_in_register _) (bitcast _ v @ (value_type $I128))))
(let ((lo XReg (value_regs_get v 0))
(hi XReg (value_regs_get v 1))
(vstate VState (vstate_from_type $I64X2))
(vec VReg (rv_vmv_sx hi vstate)))
(rv_vslide1up_vx vec vec lo (unmasked) vstate)))

;; `gen_bitcast` below only works with single register values, so handle I128
;; specially here.
(rule 1 (lower (has_type $I128 (bitcast _ v @ (value_type $I128))))
v)

(rule 0 (lower (has_type out_ty (bitcast _ v @ (value_type in_ty))))
(gen_bitcast v in_ty out_ty))

Expand Down
15 changes: 15 additions & 0 deletions cranelift/filetests/filetests/runtests/i128-bitcast.clif
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
test interpret
test run
set enable_llvm_abi_extensions=true
target aarch64
target x86_64
target s390x
target riscv64
target riscv64 has_c has_zcb

function %bitcast_i128_i128(i128) -> i128 {
block0(v0: i128):
v1 = bitcast.i128 v0
return v1
}
; run: %bitcast_i128_i128(0) == 0
Loading