Skip to content

Implement fmin_pseudo and fmax_pseudo for scalars #3115

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

Merged
merged 4 commits into from
Aug 30, 2021
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
4 changes: 4 additions & 0 deletions cranelift/codegen/src/isa/x64/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4413,6 +4413,10 @@ fn lower_insn_to_regs<C: LowerCtx<I = Inst>>(
let ty = ty.unwrap();
ctx.emit(Inst::gen_move(dst, rhs, ty));
let sse_opcode = match (ty, op) {
(types::F32, Opcode::FminPseudo) => SseOpcode::Minss,
(types::F32, Opcode::FmaxPseudo) => SseOpcode::Maxss,
(types::F64, Opcode::FminPseudo) => SseOpcode::Minsd,
(types::F64, Opcode::FmaxPseudo) => SseOpcode::Maxsd,
(types::F32X4, Opcode::FminPseudo) => SseOpcode::Minps,
(types::F32X4, Opcode::FmaxPseudo) => SseOpcode::Maxps,
(types::F64X2, Opcode::FminPseudo) => SseOpcode::Minpd,
Expand Down
Binary file removed cranelift/codegen/src/preopt.serialized
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
test run
; target s390x TODO: Not yet implemented on s390x
set enable_simd
target aarch64
target x86_64 machinst skylake

function %fmin_pseudo_f32x4(f32x4, f32x4) -> f32x4 {
block0(v0:f32x4, v1:f32x4):
v2 = fmin_pseudo v0, v1
return v2
}
; run: %fmin_pseudo_f32x4([0x1.0 NaN 0x0.1 -0x0.0], [0x2.0 0x2.0 NaN 0x0.0]) == [0x1.0 NaN 0x0.1 -0x0.0]

function %fmax_pseudo_f32x4(f32x4, f32x4) -> f32x4 {
block0(v0:f32x4, v1:f32x4):
v2 = fmax_pseudo v0, v1
return v2
}
; run: %fmax_pseudo_f32x4([0x1.0 NaN 0x0.1 -0x0.0], [0x2.0 0x2.0 NaN 0x0.0]) == [0x2.0 NaN 0x0.1 -0x0.0]

function %fmin_pseudo_f64x2(f64x2, f64x2) -> f64x2 {
block0(v0:f64x2, v1:f64x2):
v2 = fmin_pseudo v0, v1
return v2
}
; run: %fmin_pseudo_f64x2([0x1.0 NaN], [0x2.0 0x2.0]) == [0x1.0 NaN]
; run: %fmin_pseudo_f64x2([0x0.1 -0x0.0], [NaN 0x0.0]) == [0x0.1 -0x0.0]

function %fmax_pseudo_f64x2(f64x2, f64x2) -> f64x2 {
block0(v0:f64x2, v1:f64x2):
v2 = fmax_pseudo v0, v1
return v2
}
; run: %fmax_pseudo_f64x2([0x1.0 NaN], [0x2.0 0x2.0]) == [0x2.0 NaN]
; run: %fmax_pseudo_f64x2([0x0.1 -0x0.0], [NaN 0x0.0]) == [0x0.1 -0x0.0]

50 changes: 50 additions & 0 deletions cranelift/filetests/filetests/runtests/fmin-max-pseudo.clif
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
test run
; target s390x TODO: Not yet implemented on s390x
; target aarch64 TODO: Not yet implemented on aarch64
set enable_simd
target x86_64 machinst skylake

function %fmin_pseudo_f32(f32, f32) -> f32 {
block0(v0:f32, v1:f32):
v2 = fmin_pseudo v0, v1
return v2
}
; run: %fmin_pseudo_f32(0x1.0, 0x2.0) == 0x1.0
; run: %fmin_pseudo_f32(NaN, 0x2.0) == NaN
; run: %fmin_pseudo_f32(0x0.1, NaN) == 0x0.1
; run: %fmin_pseudo_f32(0x0.0, -0x0.0) == 0x0.0
; run: %fmin_pseudo_f32(-0x0.0, 0x0.0) == -0x0.0

function %fmax_pseudo_f32(f32, f32) -> f32 {
block0(v0:f32, v1:f32):
v2 = fmax_pseudo v0, v1
return v2
}
; run: %fmax_pseudo_f32(0x1.0, 0x2.0) == 0x2.0
; run: %fmax_pseudo_f32(NaN, 0x2.0) == NaN
; run: %fmax_pseudo_f32(0x0.1, NaN) == 0x0.1
; run: %fmax_pseudo_f32(0x0.0, 0x0.0) == 0x0.0
; run: %fmax_pseudo_f32(-0x0.0, 0x0.0) == -0x0.0

function %fmin_pseudo_f64(f64, f64) -> f64 {
block0(v0:f64, v1:f64):
v2 = fmin_pseudo v0, v1
return v2
}
; run: %fmin_pseudo_f64(0x1.0, 0x2.0) == 0x1.0
; run: %fmin_pseudo_f64(NaN, 0x2.0) == NaN
; run: %fmin_pseudo_f64(0x0.1, NaN) == 0x0.1
; run: %fmin_pseudo_f64(0x0.0, -0x0.0) == 0x0.0
; run: %fmin_pseudo_f64(-0x0.0, 0x0.0) == -0x0.0

function %fmax_pseudo_f64(f64, f64) -> f64 {
block0(v0:f64, v1:f64):
v2 = fmax_pseudo v0, v1
return v2
}
; run: %fmax_pseudo_f64(0x1.0, 0x2.0) == 0x2.0
; run: %fmax_pseudo_f64(NaN, 0x2.0) == NaN
; run: %fmax_pseudo_f64(0x0.1, NaN) == 0x0.1
; run: %fmax_pseudo_f64(0x0.0, 0x0.0) == 0x0.0
; run: %fmax_pseudo_f64(-0x0.0, 0x0.0) == -0x0.0