From d5b4c077633ec8407ab9d425409ee7ae0757ca8d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 14 Jan 2025 13:38:42 -0800 Subject: [PATCH] pulley: Support smaller int-to-float conversions This adds support for converting 8/16-bit integers to floats to Pulley. This is not directly accessible from wasm instructions but is possible through various optimizations to create. A new `*.clif` runtest was added exercising many combinations of scalars-to-scalars for int-to-floats of varying widths. --- .../codegen/src/isa/pulley_shared/lower.isle | 24 +++++++++---------- .../filetests/runtests/issue5952.clif | 4 ++++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/cranelift/codegen/src/isa/pulley_shared/lower.isle b/cranelift/codegen/src/isa/pulley_shared/lower.isle index 7c477f5cc967..5bb2e9170b78 100644 --- a/cranelift/codegen/src/isa/pulley_shared/lower.isle +++ b/cranelift/codegen/src/isa/pulley_shared/lower.isle @@ -1258,28 +1258,28 @@ ;;;; Rules for `fcvt_from_{u,s}int` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(rule (lower (has_type $F32 (fcvt_from_uint val @ (value_type $I32)))) - (pulley_f32_from_x32_u val)) +(rule 0 (lower (has_type $F32 (fcvt_from_uint val @ (value_type (fits_in_32 _))))) + (pulley_f32_from_x32_u (zext32 val))) -(rule (lower (has_type $F32 (fcvt_from_uint val @ (value_type $I64)))) +(rule 1 (lower (has_type $F32 (fcvt_from_uint val @ (value_type $I64)))) (pulley_f32_from_x64_u val)) -(rule (lower (has_type $F64 (fcvt_from_uint val @ (value_type $I32)))) - (pulley_f64_from_x32_u val)) +(rule 0 (lower (has_type $F64 (fcvt_from_uint val @ (value_type (fits_in_32 _))))) + (pulley_f64_from_x32_u (zext32 val))) -(rule (lower (has_type $F64 (fcvt_from_uint val @ (value_type $I64)))) +(rule 1 (lower (has_type $F64 (fcvt_from_uint val @ (value_type $I64)))) (pulley_f64_from_x64_u val)) -(rule (lower (has_type $F32 (fcvt_from_sint val @ (value_type $I32)))) - (pulley_f32_from_x32_s val)) +(rule 0 (lower (has_type $F32 (fcvt_from_sint val @ (value_type (fits_in_32 _))))) + (pulley_f32_from_x32_s (sext32 val))) -(rule (lower (has_type $F32 (fcvt_from_sint val @ (value_type $I64)))) +(rule 1 (lower (has_type $F32 (fcvt_from_sint val @ (value_type $I64)))) (pulley_f32_from_x64_s val)) -(rule (lower (has_type $F64 (fcvt_from_sint val @ (value_type $I32)))) - (pulley_f64_from_x32_s val)) +(rule 0 (lower (has_type $F64 (fcvt_from_sint val @ (value_type (fits_in_32 _))))) + (pulley_f64_from_x32_s (sext32 val))) -(rule (lower (has_type $F64 (fcvt_from_sint val @ (value_type $I64)))) +(rule 1 (lower (has_type $F64 (fcvt_from_sint val @ (value_type $I64)))) (pulley_f64_from_x64_s val)) (rule (lower (has_type $F32X4 (fcvt_from_sint val @ (value_type $I32X4)))) diff --git a/cranelift/filetests/filetests/runtests/issue5952.clif b/cranelift/filetests/filetests/runtests/issue5952.clif index 7e29ba668fa3..1a5ae8c382a0 100644 --- a/cranelift/filetests/filetests/runtests/issue5952.clif +++ b/cranelift/filetests/filetests/runtests/issue5952.clif @@ -5,6 +5,10 @@ target x86_64 target s390x target riscv64 target riscv64 has_c has_zcb +target pulley32 +target pulley32be +target pulley64 +target pulley64be function %a(i16 uext) -> f32 { block0(v0: i16):