|
| 1 | +%# -*- mode: swift -*- |
| 2 | + |
| 3 | +%# Ignore the following admonition; it applies to the resulting .swift file only |
| 4 | +//// Automatically Generated From tgmath.swift.gyb. Do Not Edit Directly |
| 5 | +//===----------------------------------------------------------------------===// |
| 6 | +// |
| 7 | +// This source file is part of the Swift.org open source project |
| 8 | +// |
| 9 | +// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors |
| 10 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 11 | +// |
| 12 | +// See http://swift.org/LICENSE.txt for license information |
| 13 | +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 14 | +// |
| 15 | +//===----------------------------------------------------------------------===// |
| 16 | + |
| 17 | +%{ |
| 18 | + |
| 19 | +# Don't need 64-bit (Double/CDouble) overlays. The ordinary C imports work fine. |
| 20 | +# FIXME: need 80-bit (Float80/long double) versions when long double is imported |
| 21 | +overlayFloatBits = [32] # 80 |
| 22 | +allFloatBits = [32, 64] # 80 |
| 23 | + |
| 24 | +def floatName(bits): |
| 25 | + if bits == 32: |
| 26 | + return 'Float' |
| 27 | + if bits == 64: |
| 28 | + return 'Double' |
| 29 | + if bits == 80: |
| 30 | + return 'Float80' |
| 31 | + |
| 32 | +def cFloatName(bits): |
| 33 | + if bits == 32: |
| 34 | + return 'CFloat' |
| 35 | + if bits == 64: |
| 36 | + return 'CDouble' |
| 37 | + if bits == 80: |
| 38 | + return 'CLongDouble' |
| 39 | + |
| 40 | +def cFuncSuffix(bits): |
| 41 | + if bits == 32: |
| 42 | + return 'f' |
| 43 | + if bits == 64: |
| 44 | + return '' |
| 45 | + if bits == 80: |
| 46 | + return 'l' |
| 47 | + |
| 48 | +# Each of the following lists is ordered to match tgmath.h. |
| 49 | + |
| 50 | +UnaryFunctions = ['acos', 'asin', 'atan', 'acosh', 'asinh', 'atanh', |
| 51 | + 'cos', 'sin', 'tan', 'cosh', 'sinh', 'tanh', |
| 52 | + 'exp', 'log', 'sqrt', 'fabs', 'cbrt', 'ceil', |
| 53 | + 'erf', 'erfc', 'exp2', 'expm1', 'floor', 'lgamma', |
| 54 | + 'log10', 'log1p', 'log2', 'logb', |
| 55 | + 'nearbyint', 'rint', 'round', 'tgamma', 'trunc'] |
| 56 | + |
| 57 | +BinaryFunctions = ['pow', 'atan2', 'copysign', 'fdim', 'fmax', 'fmin', |
| 58 | +# FIXME: rdar://17275152 call to fmodf causes deserialization crash |
| 59 | +# 'fmod', |
| 60 | + 'hypot', 'nextafter', 'remainder'] |
| 61 | + |
| 62 | +OtherFunctions = ['fma', 'frexp', 'ilogb', 'ldexp', 'remquo', 'scalbn'] |
| 63 | + |
| 64 | +UnhandledFunctions = ['llrint', 'llround', 'lrint', 'lround', 'nexttoward', |
| 65 | + 'scalbln', 'carg', 'cimag', 'conj', 'cproj', 'creal'] |
| 66 | + |
| 67 | +def AllFloatTypes(): |
| 68 | + for bits in allFloatBits: |
| 69 | + yield floatName(bits), cFloatName(bits), cFuncSuffix(bits) |
| 70 | + |
| 71 | +def OverlayFloatTypes(): |
| 72 | + for bits in overlayFloatBits: |
| 73 | + yield floatName(bits), cFloatName(bits), cFuncSuffix(bits) |
| 74 | + |
| 75 | +def TypedUnaryFunctions(): |
| 76 | + for ufunc in UnaryFunctions: |
| 77 | + for bits in overlayFloatBits: |
| 78 | + yield floatName(bits), cFloatName(bits), cFuncSuffix(bits), ufunc |
| 79 | + |
| 80 | +def TypedBinaryFunctions(): |
| 81 | + for bfunc in BinaryFunctions: |
| 82 | + for bits in overlayFloatBits: |
| 83 | + yield floatName(bits), cFloatName(bits), cFuncSuffix(bits), bfunc |
| 84 | + |
| 85 | +}% |
| 86 | + |
| 87 | +% for T, CT, f, ufunc in TypedUnaryFunctions(): |
| 88 | +@transparent |
| 89 | +func ${ufunc}(x: ${T}) -> ${T} { |
| 90 | + return ${T}(${ufunc}${f}(${CT}(x))) |
| 91 | +} |
| 92 | + |
| 93 | +% end |
| 94 | + |
| 95 | +% for T, CT, f, bfunc in TypedBinaryFunctions(): |
| 96 | +@transparent |
| 97 | +func ${bfunc}(lhs: ${T}, rhs: ${T}) -> ${T} { |
| 98 | + return ${T}(${bfunc}${f}(${CT}(lhs), ${CT}(rhs))) |
| 99 | +} |
| 100 | + |
| 101 | +%end |
| 102 | + |
| 103 | +% for T, CT, f in OverlayFloatTypes(): |
| 104 | +@transparent |
| 105 | +func fma(x: ${T}, y: ${T}, z: ${T}) -> ${T} { |
| 106 | + return ${T}(fma${f}(${CT}(x), ${CT}(y), ${CT}(z))) |
| 107 | +} |
| 108 | + |
| 109 | +% end |
| 110 | + |
| 111 | +% # This is AllFloatTypes not OverlayFloatTypes because of the tuple return. |
| 112 | +% for T, CT, f in AllFloatTypes(): |
| 113 | +@transparent |
| 114 | +func frexp(value: ${T}) -> (${T}, Int) { |
| 115 | + var exp = CInt(0) |
| 116 | + let frac = frexp${f}(${CT}(value), &exp) |
| 117 | + return (${T}(frac), Int(exp)) |
| 118 | +} |
| 119 | + |
| 120 | +% end |
| 121 | + |
| 122 | +% # This would be AllFloatTypes not OverlayFloatTypes because of the Int return. |
| 123 | +% # ... except we need an asmname to avoid an overload ambiguity. |
| 124 | +% for T, CT, f in OverlayFloatTypes(): |
| 125 | +@transparent |
| 126 | +func ilogb(x: ${T}) -> Int { |
| 127 | + return Int(ilogb${f}(${CT}(x))) |
| 128 | +} |
| 129 | + |
| 130 | +@asmname("ilogb") |
| 131 | +func _swift_Darwin_ilogb(value: CDouble) -> CInt |
| 132 | +@transparent |
| 133 | +func ilogb(x: Double) -> Int { |
| 134 | + return Int(_swift_Darwin_ilogb(CDouble(x))) |
| 135 | +} |
| 136 | + |
| 137 | +% end |
| 138 | + |
| 139 | +% # This is AllFloatTypes not OverlayFloatTypes because of the Int parameter. |
| 140 | +% for T, CT, f in AllFloatTypes(): |
| 141 | +@transparent |
| 142 | +func ldexp(x: ${T}, n: Int) -> ${T} { |
| 143 | + return ${T}(ldexp${f}(${CT}(x), CInt(n))) |
| 144 | +} |
| 145 | + |
| 146 | +% end |
| 147 | + |
| 148 | +% # This is AllFloatTypes not OverlayFloatTypes because of the tuple return. |
| 149 | +% for T, CT, f in AllFloatTypes(): |
| 150 | +@transparent |
| 151 | +func remquo(x: ${T}, y: ${T}) -> (${T}, Int) { |
| 152 | + var quo = CInt(0) |
| 153 | + let rem = remquo${f}(${CT}(x), ${CT}(y), &quo) |
| 154 | + return (${T}(rem), Int(quo)) |
| 155 | +} |
| 156 | + |
| 157 | +% end |
| 158 | + |
| 159 | +% # This is AllFloatTypes not OverlayFloatTypes because of the Int parameter. |
| 160 | +% for T, CT, f in AllFloatTypes(): |
| 161 | +@transparent |
| 162 | +func scalbn(x: ${T}, n: Int) -> ${T} { |
| 163 | + return ${T}(scalbn${f}(${CT}(x), CInt(n))) |
| 164 | +} |
| 165 | + |
| 166 | +% end |
0 commit comments