Skip to content

Commit 7bfd3a7

Browse files
committed
Support f*_fast
1 parent 9cb2a63 commit 7bfd3a7

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/builder.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,24 +971,44 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
971971

972972
fn fadd_fast(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
973973
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
974+
if let Some(value) =
975+
self.f16_arithmetic_binary_op(lhs, rhs, |this, lhs, rhs| this.assign_to_var(lhs + rhs))
976+
{
977+
return value;
978+
}
974979
let result = set_rvalue_location(self, lhs + rhs);
975980
self.assign_to_var(result)
976981
}
977982

978983
fn fsub_fast(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
979984
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
985+
if let Some(value) =
986+
self.f16_arithmetic_binary_op(lhs, rhs, |this, lhs, rhs| this.assign_to_var(lhs - rhs))
987+
{
988+
return value;
989+
}
980990
let result = set_rvalue_location(self, lhs - rhs);
981991
self.assign_to_var(result)
982992
}
983993

984994
fn fmul_fast(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
985995
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
996+
if let Some(value) =
997+
self.f16_arithmetic_binary_op(lhs, rhs, |this, lhs, rhs| this.assign_to_var(lhs * rhs))
998+
{
999+
return value;
1000+
}
9861001
let result = set_rvalue_location(self, lhs * rhs);
9871002
self.assign_to_var(result)
9881003
}
9891004

9901005
fn fdiv_fast(&mut self, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> RValue<'gcc> {
9911006
// NOTE: it seems like we cannot enable fast-mode for a single operation in GCC.
1007+
if let Some(value) =
1008+
self.f16_arithmetic_binary_op(lhs, rhs, |this, lhs, rhs| this.assign_to_var(lhs / rhs))
1009+
{
1010+
return value;
1011+
}
9921012
let result = set_rvalue_location(self, lhs / rhs);
9931013
self.assign_to_var(result)
9941014
}

tests/run/f16.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use std::cmp::Ordering;
1010
use std::hint::black_box;
11-
use std::intrinsics::{fmaf16, powif16};
11+
use std::intrinsics::{fadd_fast, fdiv_fast, fmaf16, fmul_fast, fsub_fast, powif16};
1212

1313
unsafe extern "C" {
1414
#[link_name = "llvm.fma.f16"]
@@ -45,6 +45,10 @@ fn main() {
4545
assert_f16_bits(two * three, 0x4600);
4646
assert_f16_bits(two / one, 0x4000);
4747
assert_f16_bits(-three, 0xc200);
48+
assert_f16_bits(unsafe { fadd_fast(one, two) }, 0x4200);
49+
assert_f16_bits(unsafe { fsub_fast(two, one) }, 0x3c00);
50+
assert_f16_bits(unsafe { fmul_fast(two, three) }, 0x4600);
51+
assert_f16_bits(unsafe { fdiv_fast(three, two) }, 0x3e00);
4852
assert_f16_bits(fmaf16(one, two, -three), 0xbc00);
4953
assert_f16_bits(unsafe { llvm_fma_f16(one, two, -three) }, 0xbc00);
5054
assert_f16_bits(powif16(two, 3), 0x4800);

0 commit comments

Comments
 (0)