mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This reapplies commit r22864 - it is not changing the public api as we initially thought. sqrt() was never available without importing Darwin. This change only changes where sqrt() gets "forwarded" to. Before 'sqrt' called the builtin '_sqrt' defined in BuiltinMath now it just calls the math library's 'sqrt' function. I also added a stdlib test. rdar://18371371 Swift SVN r22870
75 lines
2.1 KiB
Swift
75 lines
2.1 KiB
Swift
//===--- BuiltinMath.swift.gyb --------------------------------*- swift -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
%{
|
|
|
|
# Don't need 64-bit (Double/CDouble) overlays. The ordinary C imports work fine.
|
|
# FIXME: need 80-bit (Float80/long double) versions when long double is imported
|
|
overlayFloatBits = [32] # 80
|
|
allFloatBits = [32, 64] # 80
|
|
|
|
def floatName(bits):
|
|
if bits == 32:
|
|
return 'Float'
|
|
if bits == 64:
|
|
return 'Double'
|
|
if bits == 80:
|
|
return 'Float80'
|
|
|
|
def cFloatName(bits):
|
|
if bits == 32:
|
|
return 'CFloat'
|
|
if bits == 64:
|
|
return 'CDouble'
|
|
if bits == 80:
|
|
return 'CLongDouble'
|
|
|
|
def cFuncSuffix(bits):
|
|
if bits == 32:
|
|
return 'f'
|
|
if bits == 64:
|
|
return ''
|
|
if bits == 80:
|
|
return 'l'
|
|
|
|
# Each of the following lists is ordered to match math.h
|
|
|
|
# These functions have a corresponding LLVM intrinsic
|
|
# Note, keep this up to date with Darwin/tgmath.swift.gyb
|
|
UnaryIntrinsicFunctions = ['cos', 'sin',
|
|
'exp', 'exp2',
|
|
'log', 'log10', 'log2',
|
|
'fabs',
|
|
'ceil', 'floor', 'nearbyint', 'rint', 'round', 'trunc',
|
|
]
|
|
|
|
def TypedUnaryIntrinsicFunctions():
|
|
for ufunc in UnaryIntrinsicFunctions:
|
|
for bits in allFloatBits:
|
|
yield floatName(bits), cFloatName(bits), bits, ufunc
|
|
|
|
}%
|
|
|
|
// Unary intrinsic functions
|
|
// Note these have a corresponding LLVM intrinsic
|
|
% for T, CT, bits, ufunc in TypedUnaryIntrinsicFunctions():
|
|
@transparent
|
|
public func _${ufunc}(x: ${T}) -> ${T} {
|
|
return ${T}(_bits: Builtin.int_${ufunc}_FPIEEE${bits}(x.value))
|
|
}
|
|
|
|
% end
|
|
|
|
// ${'Local Variables'}:
|
|
// eval: (read-only-mode 1)
|
|
// End:
|