Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 54 additions & 25 deletions stdlib/public/core/SIMDVector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -467,17 +467,15 @@ extension SIMD where Scalar: Comparable {
return lhs .> Self(repeating: rhs)
}

/* Temporarily removed pending plan for Swift.min / Swift.max
@_alwaysEmitIntoClient
public mutating func clamp(lowerBound: Self, upperBound: Self) {
self = self.clamped(lowerBound: lowerBound, upperBound: upperBound)
}

@_alwaysEmitIntoClient
public func clamped(lowerBound: Self, upperBound: Self) -> Self {
return Swift.min(upperBound, Swift.max(lowerBound, self))
return pointwiseMin(upperBound, pointwiseMax(lowerBound, self))
}
*/
}

extension SIMD where Scalar: FixedWidthInteger {
Expand Down Expand Up @@ -550,6 +548,42 @@ extension SIMD where Scalar: FloatingPoint {
public static var one: Self {
return Self(repeating: 1)
}

/// The lanewise minimum of two vectors.
///
/// Each element of the result is the minimum of the corresponding elements
/// of the inputs.
@_alwaysEmitIntoClient
public static func min(_ a: Self, _ b: Self) -> Self {
var result = Self()
for i in result.indices {
result[i] = Scalar.minimum(a[i], b[i])
}
return result
}

/// The lanewise maximum of two vectors.
///
/// Each element of the result is the minimum of the corresponding elements
/// of the inputs.
@_alwaysEmitIntoClient
public static func max(_ a: Self, _ b: Self) -> Self {
var result = Self()
for i in result.indices {
result[i] = Scalar.maximum(a[i], b[i])
}
return result
}

@_alwaysEmitIntoClient
public mutating func clamp(lowerBound: Self, upperBound: Self) {
self = self.clamped(lowerBound: lowerBound, upperBound: upperBound)
}

@_alwaysEmitIntoClient
public func clamped(lowerBound: Self, upperBound: Self) -> Self {
return pointwiseMin(upperBound, pointwiseMax(lowerBound, self))
}
}

extension SIMD
Expand Down Expand Up @@ -1343,34 +1377,30 @@ public func all<Storage>(_ mask: SIMDMask<Storage>) -> Bool {
return mask._storage.max() < 0
}

/*
Temporarily removed while we investigate compile-time regressions caused by
introducing these global functions.

/// The lanewise minimum of two vectors.
///
/// Each element of the result is the minimum of the corresponding elements
/// of the inputs.
@_alwaysEmitIntoClient
public func min<V>(_ lhs: V, _ rhs: V) -> V
where V: SIMD, V.Scalar: Comparable {
var result = V()
public func pointwiseMin<T>(_ a: T, _ b: T) -> T
where T: SIMD, T.Scalar: Comparable {
var result = T()
for i in result.indices {
result[i] = min(lhs[i], rhs[i])
result[i] = min(a[i], b[i])
}
return result
}

/// The lanewise maximum of two vectors.
///
/// Each element of the result is the maximum of the corresponding elements
/// Each element of the result is the minimum of the corresponding elements
/// of the inputs.
@_alwaysEmitIntoClient
public func max<V>(_ lhs: V, _ rhs: V) -> V
where V: SIMD, V.Scalar: Comparable {
var result = V()
public func pointwiseMax<T>(_ a: T, _ b: T) -> T
where T: SIMD, T.Scalar: Comparable {
var result = T()
for i in result.indices {
result[i] = max(lhs[i], rhs[i])
result[i] = max(a[i], b[i])
}
return result
}
Expand All @@ -1381,11 +1411,11 @@ where V: SIMD, V.Scalar: Comparable {
/// Each element of the result is the minimum of the corresponding elements
/// of the inputs.
@_alwaysEmitIntoClient
public func min<V>(_ lhs: V, _ rhs: V) -> V
where V: SIMD, V.Scalar: FloatingPoint {
var result = V()
public func pointwiseMin<T>(_ a: T, _ b: T) -> T
where T: SIMD, T.Scalar: FloatingPoint {
var result = T()
for i in result.indices {
result[i] = V.Scalar.minimum(lhs[i], rhs[i])
result[i] = T.Scalar.minimum(a[i], b[i])
}
return result
}
Expand All @@ -1395,12 +1425,11 @@ where V: SIMD, V.Scalar: FloatingPoint {
/// Each element of the result is the maximum of the corresponding elements
/// of the inputs.
@_alwaysEmitIntoClient
public func max<V>(_ lhs: V, _ rhs: V) -> V
where V: SIMD, V.Scalar: FloatingPoint {
var result = V()
public func pointwiseMax<T>(_ a: T, _ b: T) -> T
where T: SIMD, T.Scalar: FloatingPoint {
var result = T()
for i in result.indices {
result[i] = V.Scalar.maximum(lhs[i], rhs[i])
result[i] = T.Scalar.maximum(a[i], b[i])
}
return result
}
*/