Skip to content

Commit

Permalink
pulley: Support smaller int-to-float conversions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed Jan 14, 2025
1 parent 2103f02 commit d5b4c07
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
24 changes: 12 additions & 12 deletions cranelift/codegen/src/isa/pulley_shared/lower.isle
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down
4 changes: 4 additions & 0 deletions cranelift/filetests/filetests/runtests/issue5952.clif
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d5b4c07

Please sign in to comment.