@@ -345,32 +345,6 @@ extension SIMD where Scalar: Comparable {
345
345
public func max( ) -> Scalar {
346
346
return indices. reduce ( into: self [ 0 ] ) { $0 = Swift . max ( $0, self [ $1] ) }
347
347
}
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
- }
374
348
}
375
349
376
350
// These operations should never need @_semantics; they should be trivial
@@ -500,7 +474,7 @@ extension SIMD where Scalar: Comparable {
500
474
501
475
@_alwaysEmitIntoClient
502
476
public func clamped( lowerBound: Self , upperBound: Self ) -> Self {
503
- return Self . min ( upperBound, Self . max ( lowerBound, self ) )
477
+ return pointwiseMin ( upperBound, pointwiseMax ( lowerBound, self ) )
504
478
}
505
479
}
506
480
@@ -608,7 +582,7 @@ extension SIMD where Scalar: FloatingPoint {
608
582
609
583
@_alwaysEmitIntoClient
610
584
public func clamped( lowerBound: Self , upperBound: Self ) -> Self {
611
- return Self . min ( upperBound, Self . max ( lowerBound, self ) )
585
+ return pointwiseMin ( upperBound, pointwiseMax ( lowerBound, self ) )
612
586
}
613
587
}
614
588
@@ -1402,3 +1376,60 @@ public func any<Storage>(_ mask: SIMDMask<Storage>) -> Bool {
1402
1376
public func all< Storage> ( _ mask: SIMDMask < Storage > ) -> Bool {
1403
1377
return mask. _storage. max ( ) < 0
1404
1378
}
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