@@ -1489,14 +1489,25 @@ ${assignmentOperatorComment(x.operator, False)}
1489
1489
/// - Complexity: O(1).
1490
1490
static prefix func ~ ( _ x: Self ) -> Self
1491
1491
1492
- % for x in binaryBitwise + maskingShifts :
1492
+ % for x in binaryBitwise:
1493
1493
${ operatorComment ( x. operator, False) }
1494
1494
static func ${ x. operator} ( _ lhs: Self, _ rhs: Self) - > Self
1495
1495
1496
1496
${ assignmentOperatorComment ( x. operator, False) }
1497
1497
static func ${ x. operator} = ( _ lhs: inout Self, _ rhs: Self)
1498
1498
% end
1499
1499
1500
+ % for x in maskingShifts:
1501
+ ${ operatorComment ( x. nonMaskingOperator, False) }
1502
+ static func ${ x. nonMaskingOperator} < RHS: BinaryInteger> (
1503
+ _ lhs: Self, _ rhs: RHS
1504
+ ) - > Self
1505
+
1506
+ ${ assignmentOperatorComment ( x. nonMaskingOperator, False) }
1507
+ static func ${ x. nonMaskingOperator} = < RHS: BinaryInteger> (
1508
+ _ lhs: inout Self, _ rhs: RHS)
1509
+ % end
1510
+
1500
1511
/// Returns the quotient and remainder of this value divided by the given
1501
1512
/// value.
1502
1513
///
@@ -1549,8 +1560,9 @@ extension BinaryInteger {
1549
1560
return ( self / rhs, self % rhs)
1550
1561
}
1551
1562
1552
- % for x in binaryBitwise + maskingShifts :
1563
+ % for x in binaryBitwise:
1553
1564
1565
+ // Homogeneous
1554
1566
${ operatorComment ( x. operator, False) }
1555
1567
@_transparent
1556
1568
public static func ${ x. operator} ( lhs: Self, rhs: Self) - > Self {
@@ -1561,24 +1573,18 @@ ${operatorComment(x.operator, False)}
1561
1573
1562
1574
% end
1563
1575
1564
- % for x in maskingShifts:
1565
-
1566
- ${ operatorComment ( x. operator, False) }
1567
- public static func ${ x. operator} <
1568
- Other : BinaryInteger
1569
- > ( lhs: Self, rhs: Other) - > Self {
1570
- return lhs ${ x. operator} Self( extendingOrTruncating: rhs)
1571
- }
1572
-
1573
- ${ assignmentOperatorComment ( x. operator, False) }
1574
- @_transparent
1575
- public static func ${ x. operator} = <
1576
- Other : BinaryInteger
1577
- > ( lhs: inout Self, rhs: Other) {
1578
- lhs = lhs ${ x. operator} rhs
1576
+ % for x in maskingShifts:
1577
+ // Heterogeneous non-masking shift in terms of shift-assignment
1578
+ ${ operatorComment ( x. nonMaskingOperator, False) }
1579
+ public static func ${ x. nonMaskingOperator} < RHS: BinaryInteger> (
1580
+ _ lhs: Self, _ rhs: RHS
1581
+ ) - > Self {
1582
+ var r = lhs
1583
+ r ${ x. nonMaskingOperator} = rhs
1584
+ return r
1579
1585
}
1586
+ % end
1580
1587
1581
- % end
1582
1588
}
1583
1589
1584
1590
// Strideable conformance
@@ -1835,50 +1841,6 @@ extension BinaryInteger {
1835
1841
}
1836
1842
}
1837
1843
1838
- //===----------------------------------------------------------------------===//
1839
- //===--- BinaryInteger smart shifts ---------------------------------------===//
1840
- //===----------------------------------------------------------------------===//
1841
- // FIXME(integers): uncomment once <rdar://problem/29643515> gets fixed
1842
- #if false
1843
- extension BinaryInteger {
1844
- % for x in maskingShifts:
1845
- @_transparent
1846
- public static func ${ x. nonMaskingOperator} <
1847
- Other : BinaryInteger
1848
- > ( lhs: Self, rhs: Other) - > Self {
1849
- var lhs = lhs
1850
- lhs ${ x. nonMaskingOperator} = rhs
1851
- return lhs
1852
- }
1853
-
1854
- // It is hard to imagine overshift to the left in an arbitrarily sized
1855
- // integer, but shifting too far to the right and negative shift cases are
1856
- // supported.
1857
- % reversedOperator = x. operator. translate ( maketrans ( '<> ', '> < ') )
1858
- % isRightShift = '> ' in x. operator
1859
- @_transparent
1860
- public static func ${ x. nonMaskingOperator} = <
1861
- Other : BinaryInteger
1862
- > ( lhs: inout Self, rhs: Other) {
1863
- if rhs < ( 0 as Other ) {
1864
- lhs ${ reversedOperator} = ( 0 - rhs)
1865
- return
1866
- }
1867
- % if isRightShift:
1868
- let overshift = Self . isSigned
1869
- ? ( lhs < ( 0 as Self ) ? ~ ( 0 as Self ) : 0 )
1870
- : 0
1871
- if rhs >= lhs. bitWidth {
1872
- lhs = overshift
1873
- return
1874
- }
1875
- % end
1876
- lhs ${ x. operator} = Self ( extendingOrTruncating: rhs)
1877
- }
1878
- % end
1879
- }
1880
- #endif
1881
-
1882
1844
//===----------------------------------------------------------------------===//
1883
1845
//===--- FixedWidthInteger ------------------------------------------------===//
1884
1846
//===----------------------------------------------------------------------===//
@@ -2105,6 +2067,15 @@ ${overflowOperationComment(x.operator)}
2105
2067
2106
2068
/// A representation of this integer with the byte order swapped.
2107
2069
var byteSwapped : Self { get }
2070
+
2071
+ % for x in maskingShifts:
2072
+ ${ operatorComment ( x. operator, False) }
2073
+ static func ${ x. operator} ( _ lhs: Self, _ rhs: Self) - > Self
2074
+
2075
+ ${ assignmentOperatorComment ( x. operator, False) }
2076
+ static func ${ x. operator} = ( _ lhs: inout Self, _ rhs: Self)
2077
+ % end
2078
+
2108
2079
}
2109
2080
2110
2081
extension FixedWidthInteger {
@@ -2162,6 +2133,37 @@ extension FixedWidthInteger {
2162
2133
return byteSwapped
2163
2134
#endif
2164
2135
}
2136
+
2137
+ % for x in maskingShifts:
2138
+
2139
+ // Homogeneous masking shift
2140
+ ${ operatorComment( x. operator, False) }
2141
+ @_transparent
2142
+ public static func ${ x. operator} ( lhs: Self, rhs: Self) - > Self {
2143
+ var lhs = lhs
2144
+ lhs ${ x. operator} = rhs
2145
+ return lhs
2146
+ }
2147
+
2148
+
2149
+ // Heterogeneous masking shift
2150
+ ${ operatorComment ( x. operator, False) }
2151
+ public static func ${ x. operator} <
2152
+ Other : BinaryInteger
2153
+ > ( lhs: Self, rhs: Other) - > Self {
2154
+ return lhs ${ x. operator} Self( extendingOrTruncating: rhs)
2155
+ }
2156
+
2157
+ // Heterogeneous masking shift assignment
2158
+ ${ assignmentOperatorComment ( x. operator, False) }
2159
+ @_transparent
2160
+ public static func ${ x. operator} = <
2161
+ Other : BinaryInteger
2162
+ > ( lhs: inout Self, rhs: Other) {
2163
+ lhs = lhs ${ x. operator} rhs
2164
+ }
2165
+
2166
+ % end
2165
2167
}
2166
2168
2167
2169
//===----------------------------------------------------------------------===//
@@ -2190,20 +2192,6 @@ ${operatorComment(x.nonMaskingOperator, True)}
2190
2192
return lhs
2191
2193
}
2192
2194
2193
- // FIXME(integers): uncommenting this overload results in a compiler not being
2194
- // able to typecheck expression like `(int64 >> 8) & 0xFF`.
2195
- #if false
2196
- @_transparent
2197
- public static func ${ x. nonMaskingOperator} ( _ lhs: Self, _ rhs: Int) - > Self {
2198
- return ${ x. helper} ( lhs, rhs)
2199
- }
2200
-
2201
- @_transparent
2202
- public static func ${ x. nonMaskingOperator} = ( _ lhs: inout Self, _ rhs: Int) {
2203
- lhs = ${ x. helper} ( lhs, rhs)
2204
- }
2205
- #endif
2206
-
2207
2195
@_transparent
2208
2196
public static func ${ x. nonMaskingOperator} = <
2209
2197
Other : BinaryInteger
0 commit comments