Use intrinsics for abs and copysign when available
Currently our implementations for `abs` and `copysign` are defined on the trait, and these are then called from `generic`. It would be better to call core's `.abs()` / `.copysign(y)`, but we can't do this in the generic because calling the standalone function could become recursive (`fabsf` becomes `intrinsics::fabsf32`, that may lower to a call to `fabsf`). Change this so the traits uses the call to `core` if available, falling back to a call to the standalone generic function. In practice the recursion isn't likely to be a problem since LLVM probably always lowers `abs`/`copysign` to assembly, but this pattern should be more correct for functions that we will add in the future (e.g. `fma`). This should eventually be followed by a change to call the trait methods rather than `fabs`/`copysign` directly.
This commit is contained in:
committed by
Trevor Gross
parent
a277ec6954
commit
14e6d05dfb
@@ -70,6 +70,14 @@ impl Float for f8 {
|
||||
Self(a)
|
||||
}
|
||||
|
||||
fn abs(self) -> Self {
|
||||
libm::generic::fabs(self)
|
||||
}
|
||||
|
||||
fn copysign(self, other: Self) -> Self {
|
||||
libm::generic::copysign(self, other)
|
||||
}
|
||||
|
||||
fn normalize(_significand: Self::Int) -> (i32, Self::Int) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user