|
| 1 | +//===--- BuiltinMath.swift --------------------------------*- swift -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +// Each of the following functions is ordered to match math.h |
| 14 | + |
| 15 | +// These functions have a corresponding LLVM intrinsic. |
| 16 | +// Note, keep this up to date with Darwin/tgmath.swift.gyb |
| 17 | + |
| 18 | +// Order of intrinsics: cos, sin, exp, exp2, log, log10, log2, nearbyint, rint |
| 19 | + |
| 20 | +// Float Intrinsics (32 bits) |
| 21 | + |
| 22 | +@_transparent |
| 23 | +public func _cos(_ x: Float) -> Float { |
| 24 | + return Float(Builtin.int_cos_FPIEEE32(x._value)) |
| 25 | +} |
| 26 | + |
| 27 | +@_transparent |
| 28 | +public func _sin(_ x: Float) -> Float { |
| 29 | + return Float(Builtin.int_sin_FPIEEE32(x._value)) |
| 30 | +} |
| 31 | + |
| 32 | +@_transparent |
| 33 | +public func _exp(_ x: Float) -> Float { |
| 34 | + return Float(Builtin.int_exp_FPIEEE32(x._value)) |
| 35 | +} |
| 36 | + |
| 37 | +@_transparent |
| 38 | +public func _exp2(_ x: Float) -> Float { |
| 39 | + return Float(Builtin.int_exp2_FPIEEE32(x._value)) |
| 40 | +} |
| 41 | + |
| 42 | +@_transparent |
| 43 | +public func _log(_ x: Float) -> Float { |
| 44 | + return Float(Builtin.int_log_FPIEEE32(x._value)) |
| 45 | +} |
| 46 | + |
| 47 | +@_transparent |
| 48 | +public func _log10(_ x: Float) -> Float { |
| 49 | + return Float(Builtin.int_log10_FPIEEE32(x._value)) |
| 50 | +} |
| 51 | + |
| 52 | +@_transparent |
| 53 | +public func _log2(_ x: Float) -> Float { |
| 54 | + return Float(Builtin.int_log2_FPIEEE32(x._value)) |
| 55 | +} |
| 56 | + |
| 57 | +@_transparent |
| 58 | +public func _nearbyint(_ x: Float) -> Float { |
| 59 | + return Float(Builtin.int_nearbyint_FPIEEE32(x._value)) |
| 60 | +} |
| 61 | + |
| 62 | +@_transparent |
| 63 | +public func _rint(_ x: Float) -> Float { |
| 64 | + return Float(Builtin.int_rint_FPIEEE32(x._value)) |
| 65 | +} |
| 66 | + |
| 67 | +// Double Intrinsics (64 bits) |
| 68 | + |
| 69 | +@_transparent |
| 70 | +public func _cos(_ x: Double) -> Double { |
| 71 | + return Double(Builtin.int_cos_FPIEEE64(x._value)) |
| 72 | +} |
| 73 | + |
| 74 | +@_transparent |
| 75 | +public func _sin(_ x: Double) -> Double { |
| 76 | + return Double(Builtin.int_sin_FPIEEE64(x._value)) |
| 77 | +} |
| 78 | + |
| 79 | +@_transparent |
| 80 | +public func _exp(_ x: Double) -> Double { |
| 81 | + return Double(Builtin.int_exp_FPIEEE64(x._value)) |
| 82 | +} |
| 83 | + |
| 84 | +@_transparent |
| 85 | +public func _exp2(_ x: Double) -> Double { |
| 86 | + return Double(Builtin.int_exp2_FPIEEE64(x._value)) |
| 87 | +} |
| 88 | + |
| 89 | +@_transparent |
| 90 | +public func _log(_ x: Double) -> Double { |
| 91 | + return Double(Builtin.int_log_FPIEEE64(x._value)) |
| 92 | +} |
| 93 | + |
| 94 | +@_transparent |
| 95 | +public func _log10(_ x: Double) -> Double { |
| 96 | + return Double(Builtin.int_log10_FPIEEE64(x._value)) |
| 97 | +} |
| 98 | + |
| 99 | +@_transparent |
| 100 | +public func _log2(_ x: Double) -> Double { |
| 101 | + return Double(Builtin.int_log2_FPIEEE64(x._value)) |
| 102 | +} |
| 103 | + |
| 104 | +@_transparent |
| 105 | +public func _nearbyint(_ x: Double) -> Double { |
| 106 | + return Double(Builtin.int_nearbyint_FPIEEE64(x._value)) |
| 107 | +} |
| 108 | + |
| 109 | +@_transparent |
| 110 | +public func _rint(_ x: Double) -> Double { |
| 111 | + return Double(Builtin.int_rint_FPIEEE64(x._value)) |
| 112 | +} |
| 113 | + |
| 114 | +// Float80 Intrinsics (80 bits) |
| 115 | + |
| 116 | +#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64)) |
| 117 | +@_transparent |
| 118 | +public func _cos(_ x: Float80) -> Float80 { |
| 119 | + return Float80(Builtin.int_cos_FPIEEE80(x._value)) |
| 120 | +} |
| 121 | + |
| 122 | +@_transparent |
| 123 | +public func _sin(_ x: Float80) -> Float80 { |
| 124 | + return Float80(Builtin.int_sin_FPIEEE80(x._value)) |
| 125 | +} |
| 126 | + |
| 127 | +@_transparent |
| 128 | +public func _exp(_ x: Float80) -> Float80 { |
| 129 | + return Float80(Builtin.int_exp_FPIEEE80(x._value)) |
| 130 | +} |
| 131 | + |
| 132 | +@_transparent |
| 133 | +public func _exp2(_ x: Float80) -> Float80 { |
| 134 | + return Float80(Builtin.int_exp2_FPIEEE80(x._value)) |
| 135 | +} |
| 136 | + |
| 137 | +@_transparent |
| 138 | +public func _log(_ x: Float80) -> Float80 { |
| 139 | + return Float80(Builtin.int_log_FPIEEE80(x._value)) |
| 140 | +} |
| 141 | + |
| 142 | +@_transparent |
| 143 | +public func _log10(_ x: Float80) -> Float80 { |
| 144 | + return Float80(Builtin.int_log10_FPIEEE80(x._value)) |
| 145 | +} |
| 146 | + |
| 147 | +@_transparent |
| 148 | +public func _log2(_ x: Float80) -> Float80 { |
| 149 | + return Float80(Builtin.int_log2_FPIEEE80(x._value)) |
| 150 | +} |
| 151 | + |
| 152 | +@_transparent |
| 153 | +public func _nearbyint(_ x: Float80) -> Float80 { |
| 154 | + return Float80(Builtin.int_nearbyint_FPIEEE80(x._value)) |
| 155 | +} |
| 156 | + |
| 157 | +@_transparent |
| 158 | +public func _rint(_ x: Float80) -> Float80 { |
| 159 | + return Float80(Builtin.int_rint_FPIEEE80(x._value)) |
| 160 | +} |
| 161 | +#endif |
0 commit comments