mirror of
https://github.com/apple/swift-numerics
synced 2026-11-22 04:30:45 +00:00
Use BuiltinRelaxedFP ops instead of C shims when they're available.
There used to not be any way to attach reassociate or contract flags to fadd/fmul from Swift, which meant that we had to use inline C shims to accomplish this. But I added some Builtins to Swift, so now we don't need C to do this any longer.
This commit is contained in:
4 files changed
+35
-2
No files matched your search
@@ -222,11 +222,19 @@ extension Double: Real {
|
||||
|
||||
@_transparent
|
||||
public static func _relaxedAdd(_ a: Double, _ b: Double) -> Double {
|
||||
#if hasFeature(BuiltinRelaxedFP) // Swift 6.5 and later
|
||||
Double(Builtin.fadd_relaxed_FPIEEE64(a._value, b._value))
|
||||
#else
|
||||
_numerics_relaxed_add(a, b)
|
||||
#endif
|
||||
}
|
||||
|
||||
@_transparent
|
||||
public static func _relaxedMul(_ a: Double, _ b: Double) -> Double {
|
||||
#if hasFeature(BuiltinRelaxedFP) // Swift 6.5 and later
|
||||
Double(Builtin.fmul_relaxed_FPIEEE64(a._value, b._value))
|
||||
#else
|
||||
_numerics_relaxed_mul(a, b)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -195,11 +195,19 @@ extension Float: Real {
|
||||
|
||||
@_transparent
|
||||
public static func _relaxedAdd(_ a: Float, _ b: Float) -> Float {
|
||||
#if hasFeature(BuiltinRelaxedFP) // Swift 6.5 and later
|
||||
Float(Builtin.fadd_relaxed_FPIEEE32(a._value, b._value))
|
||||
#else
|
||||
_numerics_relaxed_addf(a, b)
|
||||
#endif
|
||||
}
|
||||
|
||||
@_transparent
|
||||
public static func _relaxedMul(_ a: Float, _ b: Float) -> Float {
|
||||
#if hasFeature(BuiltinRelaxedFP) // Swift 6.5 and later
|
||||
Float(Builtin.fmul_relaxed_FPIEEE32(a._value, b._value))
|
||||
#else
|
||||
_numerics_relaxed_mulf(a, b)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -173,18 +173,27 @@ extension Float16: Real {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !arch(wasm32)
|
||||
#if !arch(wasm32) || hasFeature(BuiltinRelaxedFP)
|
||||
// WASM doesn't have _Float16 on the C side, so we can't define the C hooks
|
||||
// that these use. TODO: implement these as Swift builtins instead.
|
||||
// that these use. However, if we have BuiltinRelaxedFP we can use builtins
|
||||
// to do this directly without needing the C hooks.
|
||||
|
||||
@_transparent
|
||||
public static func _relaxedAdd(_ a: Float16, _ b: Float16) -> Float16 {
|
||||
#if hasFeature(BuiltinRelaxedFP) // Swift 6.5 and later
|
||||
Float16(Builtin.fadd_relaxed_FPIEEE16(a._value, b._value))
|
||||
#else
|
||||
_numerics_relaxed_addf16(a, b)
|
||||
#endif
|
||||
}
|
||||
|
||||
@_transparent
|
||||
public static func _relaxedMul(_ a: Float16, _ b: Float16) -> Float16 {
|
||||
#if hasFeature(BuiltinRelaxedFP) // Swift 6.5 and later
|
||||
Float16(Builtin.fmul_relaxed_FPIEEE16(a._value, b._value))
|
||||
#else
|
||||
_numerics_relaxed_mulf16(a, b)
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -168,12 +168,20 @@ extension Float80: Real {
|
||||
|
||||
@_transparent
|
||||
public static func _relaxedAdd(_ a: Float80, _ b: Float80) -> Float80 {
|
||||
#if hasFeature(BuiltinRelaxedFP) // Swift 6.5 and later
|
||||
Float80(Builtin.fadd_relaxed_FPIEEE80(a._value, b._value))
|
||||
#else
|
||||
_numerics_relaxed_addl(a, b)
|
||||
#endif
|
||||
}
|
||||
|
||||
@_transparent
|
||||
public static func _relaxedMul(_ a: Float80, _ b: Float80) -> Float80 {
|
||||
#if hasFeature(BuiltinRelaxedFP) // Swift 6.5 and later
|
||||
Float80(Builtin.fmul_relaxed_FPIEEE80(a._value, b._value))
|
||||
#else
|
||||
_numerics_relaxed_mull(a, b)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user