Skip to content

Commit 633d5bc

Browse files
authored
Enable x86_64 and i686 ELF triples for embedded Swift (swiftlang#70642)
This is just as useful for x86 bare metal as the already enabled `arm*-none-none-eabi` triples.
1 parent 204b20c commit 633d5bc

15 files changed

+34
-24
lines changed

stdlib/private/StdlibUnittest/OpaqueIdentityFunctions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public func getFloat32(_ x: Float32) -> Float32 { return _opaqueIdentity(x) }
7777
@inline(never)
7878
public func getFloat64(_ x: Float64) -> Float64 { return _opaqueIdentity(x) }
7979

80-
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
80+
#if !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS)))) && (arch(i386) || arch(x86_64))
8181
@inline(never)
8282
public func getFloat80(_ x: Float80) -> Float80 { return _opaqueIdentity(x) }
8383
#endif

stdlib/public/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB)
190190
"riscv64 riscv64-none-none-eabi riscv64-none-none-eabi"
191191
)
192192
endif()
193+
if("X86" IN_LIST LLVM_TARGETS_TO_BUILD)
194+
list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES
195+
"i686 i686-unknown-none-elf i686-unknown-none-elf"
196+
"x86_64 x86_64-unknown-none-elf x86_64-unknown-none-elf"
197+
)
198+
endif()
193199

194200
if("WebAssembly" IN_LIST LLVM_TARGETS_TO_BUILD)
195201
list(APPEND EMBEDDED_STDLIB_TARGET_TRIPLES

stdlib/public/Differentiation/FloatingPointDifferentiation.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def Availability(bits):
2626
}%
2727

2828
% if bits == 80:
29-
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
29+
#if !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS)))) && (arch(i386) || arch(x86_64))
3030
% end
3131
% if bits == 16:
3232
#if !os(macOS) && !(os(iOS) && targetEnvironment(macCatalyst))
@@ -62,7 +62,7 @@ extension ${Self} {
6262
}%
6363

6464
% if other_bits == 80:
65-
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
65+
#if !(os(Windows) || os(Android) || $Embedded) && (arch(i386) || arch(x86_64))
6666
% end
6767
% if other_bits == 16:
6868
#if !os(macOS) && !(os(iOS) && targetEnvironment(macCatalyst))

stdlib/public/Differentiation/TgmathDerivatives.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func _${derivative_kind}Trunc${generic_signature} (
143143
% linear_map_kind = 'differential' if derivative_kind == 'jvp' else 'pullback'
144144
% for T in ['Float', 'Double', 'Float80']:
145145
% if T == 'Float80':
146-
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
146+
#if !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS)))) && (arch(i386) || arch(x86_64))
147147
% end
148148
@inlinable
149149
@derivative(of: exp)
@@ -284,7 +284,7 @@ func _${derivative_kind}Erfc(_ x: ${T}) -> (value: ${T}, ${linear_map_kind}: (${
284284
// Binary functions
285285
%for T in ['Float', 'Double', 'Float80']:
286286
% if T == 'Float80':
287-
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
287+
#if !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS)))) && (arch(i386) || arch(x86_64))
288288
% end
289289
@inlinable
290290
@derivative(of: pow)

stdlib/public/Platform/tgmath.swift.gyb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def TypedBinaryFunctions():
222222
// Note these do not have a corresponding LLVM intrinsic
223223
% for T, CT, f, ufunc in TypedUnaryFunctions():
224224
% if T == 'Float80':
225-
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android))
225+
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS))))
226226
% end
227227
@_transparent
228228
public func ${ufunc}(_ x: ${T}) -> ${T} {
@@ -239,7 +239,7 @@ public func ${ufunc}(_ x: ${T}) -> ${T} {
239239
// Note these have a corresponding LLVM intrinsic
240240
% for T, ufunc in TypedUnaryIntrinsicFunctions():
241241
% if T == 'Float80':
242-
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android))
242+
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS))))
243243
% end
244244
@_transparent
245245
public func ${ufunc}(_ x: ${T}) -> ${T} {
@@ -258,7 +258,7 @@ public func ${ufunc}(_ x: ${T}) -> ${T} {
258258
% for ufunc in UnaryIntrinsicFunctions:
259259
% for T, CT, f in OverlayFloatTypes():
260260
% if T == 'Float80':
261-
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android))
261+
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS))))
262262
% end
263263
@_transparent
264264
public func ${ufunc}(_ x: ${T}) -> ${T} {
@@ -275,7 +275,7 @@ public func ${ufunc}(_ x: ${T}) -> ${T} {
275275

276276
% for T, CT, f, bfunc in TypedBinaryFunctions():
277277
% if T == 'Float80':
278-
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android))
278+
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS))))
279279
% end
280280
@_transparent
281281
public func ${bfunc}(_ lhs: ${T}, _ rhs: ${T}) -> ${T} {
@@ -290,7 +290,7 @@ public func ${bfunc}(_ lhs: ${T}, _ rhs: ${T}) -> ${T} {
290290
% # This is AllFloatTypes not OverlayFloatTypes because of the tuple return.
291291
% for T, CT, f in AllFloatTypes():
292292
% if T == 'Float80':
293-
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || os(OpenBSD))
293+
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || os(OpenBSD) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS))))
294294
% else:
295295
// lgamma not available on Windows, apparently?
296296
#if !os(Windows)
@@ -308,7 +308,7 @@ public func lgamma(_ x: ${T}) -> (${T}, Int) {
308308
% # This is AllFloatTypes not OverlayFloatTypes because of the tuple return.
309309
% for T, CT, f in AllFloatTypes():
310310
% if T == 'Float80':
311-
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android))
311+
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS))))
312312
% end
313313
@_transparent
314314
public func remquo(_ x: ${T}, _ y: ${T}) -> (${T}, Int) {
@@ -324,7 +324,7 @@ public func remquo(_ x: ${T}, _ y: ${T}) -> (${T}, Int) {
324324

325325
% for T, CT, f in OverlayFloatTypes():
326326
% if T == 'Float80':
327-
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android))
327+
#if (arch(i386) || arch(x86_64)) && !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS))))
328328
% end
329329
@available(swift, deprecated: 4.2/*, obsoleted: 5.1*/, message:
330330
"use ${T}(nan: ${T}.RawSignificand).")

stdlib/public/core/BuiltinMath.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public func _rint(_ x: Double) -> Double {
113113

114114
// Float80 Intrinsics (80 bits)
115115

116-
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
116+
#if !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS)))) && (arch(i386) || arch(x86_64))
117117
@_transparent
118118
public func _cos(_ x: Float80) -> Float80 {
119119
return Float80(Builtin.int_cos_FPIEEE80(x._value))

stdlib/public/core/CTypes.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ public typealias CLongDouble = Float80
109109
#else
110110
#error("CLongDouble needs to be defined for this FreeBSD architecture")
111111
#endif
112+
#elseif $Embedded
113+
#if arch(x86_64) || arch(i386)
114+
public typealias CLongDouble = Double
115+
#endif
112116
#else
113117
// TODO: define CLongDouble for other OSes
114118
#endif

stdlib/public/core/FloatingPoint.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ public protocol BinaryFloatingPoint: FloatingPoint, ExpressibleByFloatLiteral {
15161516
/// - Parameter value: A floating-point value to be converted.
15171517
init(_ value: Double)
15181518

1519-
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
1519+
#if !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS)))) && (arch(i386) || arch(x86_64))
15201520
/// Creates a new instance from the given value, rounded to the closest
15211521
/// possible representation.
15221522
///
@@ -1927,7 +1927,7 @@ extension BinaryFloatingPoint {
19271927
significandBitPattern:
19281928
UInt64(truncatingIfNeeded: value.significandBitPattern))
19291929
self = Self(value_)
1930-
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
1930+
#if !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS)))) && (arch(i386) || arch(x86_64))
19311931
case (15, 63):
19321932
let value_ = value as? Float80 ?? Float80(
19331933
sign: value.sign,

stdlib/public/core/FloatingPointParsing.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ internal func _isspace_clocale(_ u: UTF16.CodeUnit) -> Bool {
4141
% Self = floatName(bits)
4242

4343
% if bits == 80:
44-
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
44+
#if !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS)))) && (arch(i386) || arch(x86_64))
4545
% elif bits == 16:
4646
#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))
4747
% end

stdlib/public/core/FloatingPointTypes.swift.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ else:
6666
}%
6767

6868
% if bits == 80:
69-
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
69+
#if !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS)))) && (arch(i386) || arch(x86_64))
7070
% elif bits == 16:
7171
#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))
7272
% end
@@ -922,7 +922,7 @@ extension ${Self}: _ExpressibleByBuiltinIntegerLiteral, ExpressibleByIntegerLite
922922
}
923923

924924
% if bits != 80:
925-
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
925+
#if !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS)))) && (arch(i386) || arch(x86_64))
926926
% end
927927

928928
% builtinFloatLiteralBits = 80
@@ -1129,7 +1129,7 @@ extension ${Self} {
11291129
% That = src_type.stdlib_name
11301130

11311131
% if srcBits == 80:
1132-
#if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
1132+
#if !(os(Windows) || os(Android) || ($Embedded && !os(Linux) && !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS)))) && (arch(i386) || arch(x86_64))
11331133
% elif srcBits == 16:
11341134
#if !((os(macOS) || targetEnvironment(macCatalyst)) && arch(x86_64))
11351135
% end

0 commit comments

Comments
 (0)