Skip to content

Commit baf6ae8

Browse files
committed
Adopt core-approved naming of min/max.
1 parent 7334319 commit baf6ae8

File tree

1 file changed

+59
-28
lines changed

1 file changed

+59
-28
lines changed

stdlib/public/core/SIMDVector.swift

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -345,32 +345,6 @@ extension SIMD where Scalar: Comparable {
345345
public func max() -> Scalar {
346346
return indices.reduce(into: self[0]) { $0 = Swift.max($0, self[$1]) }
347347
}
348-
349-
/// The lanewise minimum of two vectors.
350-
///
351-
/// Each element of the result is the minimum of the corresponding elements
352-
/// of the inputs.
353-
@_alwaysEmitIntoClient
354-
public static func min(_ a: Self, _ b: Self) -> Self {
355-
var result = Self()
356-
for i in result.indices {
357-
result[i] = Swift.min(a[i], b[i])
358-
}
359-
return result
360-
}
361-
362-
/// The lanewise maximum of two vectors.
363-
///
364-
/// Each element of the result is the minimum of the corresponding elements
365-
/// of the inputs.
366-
@_alwaysEmitIntoClient
367-
public static func max(_ a: Self, _ b: Self) -> Self {
368-
var result = Self()
369-
for i in result.indices {
370-
result[i] = Swift.max(a[i], b[i])
371-
}
372-
return result
373-
}
374348
}
375349

376350
// These operations should never need @_semantics; they should be trivial
@@ -500,7 +474,7 @@ extension SIMD where Scalar: Comparable {
500474

501475
@_alwaysEmitIntoClient
502476
public func clamped(lowerBound: Self, upperBound: Self) -> Self {
503-
return Self.min(upperBound, Self.max(lowerBound, self))
477+
return pointwiseMin(upperBound, pointwiseMax(lowerBound, self))
504478
}
505479
}
506480

@@ -608,7 +582,7 @@ extension SIMD where Scalar: FloatingPoint {
608582

609583
@_alwaysEmitIntoClient
610584
public func clamped(lowerBound: Self, upperBound: Self) -> Self {
611-
return Self.min(upperBound, Self.max(lowerBound, self))
585+
return pointwiseMin(upperBound, pointwiseMax(lowerBound, self))
612586
}
613587
}
614588

@@ -1402,3 +1376,60 @@ public func any<Storage>(_ mask: SIMDMask<Storage>) -> Bool {
14021376
public func all<Storage>(_ mask: SIMDMask<Storage>) -> Bool {
14031377
return mask._storage.max() < 0
14041378
}
1379+
1380+
/// The lanewise minimum of two vectors.
1381+
///
1382+
/// Each element of the result is the minimum of the corresponding elements
1383+
/// of the inputs.
1384+
@_alwaysEmitIntoClient
1385+
public func pointwiseMin<T>(_ a: T, _ b: T) -> T
1386+
where T: SIMD, T.Scalar: Comparable {
1387+
var result = T()
1388+
for i in result.indices {
1389+
result[i] = min(a[i], b[i])
1390+
}
1391+
return result
1392+
}
1393+
1394+
/// The lanewise maximum of two vectors.
1395+
///
1396+
/// Each element of the result is the minimum of the corresponding elements
1397+
/// of the inputs.
1398+
@_alwaysEmitIntoClient
1399+
public func pointwiseMax<T>(_ a: T, _ b: T) -> T
1400+
where T: SIMD, T.Scalar: Comparable {
1401+
var result = T()
1402+
for i in result.indices {
1403+
result[i] = max(a[i], b[i])
1404+
}
1405+
return result
1406+
}
1407+
1408+
1409+
/// The lanewise minimum of two vectors.
1410+
///
1411+
/// Each element of the result is the minimum of the corresponding elements
1412+
/// of the inputs.
1413+
@_alwaysEmitIntoClient
1414+
public func pointwiseMin<T>(_ a: T, _ b: T) -> T
1415+
where T: SIMD, T.Scalar: FloatingPoint {
1416+
var result = T()
1417+
for i in result.indices {
1418+
result[i] = T.Scalar.minimum(a[i], b[i])
1419+
}
1420+
return result
1421+
}
1422+
1423+
/// The lanewise maximum of two vectors.
1424+
///
1425+
/// Each element of the result is the minimum of the corresponding elements
1426+
/// of the inputs.
1427+
@_alwaysEmitIntoClient
1428+
public func pointwiseMax<T>(_ a: T, _ b: T) -> T
1429+
where T: SIMD, T.Scalar: FloatingPoint {
1430+
var result = T()
1431+
for i in result.indices {
1432+
result[i] = T.Scalar.maximum(a[i], b[i])
1433+
}
1434+
return result
1435+
}

0 commit comments

Comments
 (0)