@@ -454,13 +454,7 @@ extension DoubleWidth : FixedWidthInteger {
454
454
lhs = 0
455
455
return
456
456
}
457
-
458
- // Shift is exactly the bit width of `Base`.
459
- if rhs. _storage. low == Base . bitWidth {
460
- lhs = DoubleWidth ( ( High ( truncatingIfNeeded: lhs. _storage. low) , 0 ) )
461
- return
462
- }
463
-
457
+
464
458
lhs &<<= rhs
465
459
}
466
460
@@ -478,48 +472,48 @@ extension DoubleWidth : FixedWidthInteger {
478
472
lhs = lhs < ( 0 as DoubleWidth ) ? ~ 0 : 0
479
473
return
480
474
}
481
-
482
- // Shift is exactly the bit width of `Base`.
483
- if rhs. _storage. low == Base . bitWidth {
484
- lhs = DoubleWidth ( (
485
- lhs < ( 0 as DoubleWidth ) ? ~ 0 : 0 ,
486
- Low ( truncatingIfNeeded: lhs. _storage. high) ) )
487
- return
488
- }
489
475
490
476
lhs &>>= rhs
491
477
}
492
478
493
479
@_inlineable // FIXME(sil-serialize-all)
494
480
public static func &<<= ( lhs: inout DoubleWidth , rhs: DoubleWidth ) {
495
- // We need to use smart shifts since rhs can be greater than Base.bitWidth.
496
481
let rhs = rhs & DoubleWidth ( DoubleWidth . bitWidth &- 1 )
497
482
498
- // If Base.bitWidth >= 4, then rhs == High(rhs ._storage.low).
499
- lhs. _storage. high << = High ( rhs . _storage . low )
500
-
501
- let lowInHigh = Base . bitWidth > rhs. _storage. low
502
- ? lhs. _storage. low >> ( Low ( Base . bitWidth ) &- rhs . _storage . low )
503
- : lhs . _storage . low << ( rhs . _storage . low &- Low ( Base . bitWidth ) )
504
- lhs . _storage . high |= High ( truncatingIfNeeded : lowInHigh )
483
+ guard rhs. _storage. low < Base . bitWidth else {
484
+ lhs. _storage. high = High (
485
+ truncatingIfNeeded : lhs . _storage . low &<<
486
+ ( rhs. _storage. low &- Low ( Base . bitWidth ) ) )
487
+ lhs. _storage. low = 0
488
+ return
489
+ }
505
490
506
- lhs. _storage. low <<= rhs. _storage. low
491
+ guard rhs. _storage. low != ( 0 as Low ) else { return }
492
+ lhs. _storage. high &<<= High ( rhs. _storage. low)
493
+ lhs. _storage. high |= High (
494
+ truncatingIfNeeded: lhs. _storage. low &>>
495
+ ( Low ( Base . bitWidth) &- rhs. _storage. low) )
496
+ lhs. _storage. low &<<= rhs. _storage. low
507
497
}
508
498
509
499
@_inlineable // FIXME(sil-serialize-all)
510
500
public static func &>>= ( lhs: inout DoubleWidth , rhs: DoubleWidth ) {
511
- // We need to use smart shifts since rhs can be greater than Base.bitWidth.
512
501
let rhs = rhs & DoubleWidth ( DoubleWidth . bitWidth &- 1 )
513
502
514
- lhs . _storage. low >>= rhs . _storage . low
515
-
516
- // If Base.bitWidth >= 4, then rhs == High(rhs ._storage.low).
517
- let highInLow = Base . bitWidth > rhs. _storage. low
518
- ? lhs. _storage. high << ( High ( Base . bitWidth ) &- High ( rhs . _storage . low ) )
519
- : lhs . _storage . high >> ( High ( rhs . _storage . low ) &- High ( Base . bitWidth ) )
520
- lhs . _storage . low |= Low ( truncatingIfNeeded : highInLow )
503
+ guard rhs . _storage. low < Base . bitWidth else {
504
+ lhs . _storage . low = Low (
505
+ truncatingIfNeeded : lhs . _storage. high &>>
506
+ High ( rhs. _storage. low &- Low ( Base . bitWidth ) ) )
507
+ lhs . _storage . high = lhs. _storage. high < ( 0 as High ) ? ~ 0 : 0
508
+ return
509
+ }
521
510
522
- lhs. _storage. high >>= High ( rhs. _storage. low)
511
+ guard rhs. _storage. low != ( 0 as Low ) else { return }
512
+ lhs. _storage. low &>>= rhs. _storage. low
513
+ lhs. _storage. low |= Low (
514
+ truncatingIfNeeded: lhs. _storage. high &<<
515
+ High ( Low ( Base . bitWidth) &- rhs. _storage. low) )
516
+ lhs. _storage. high &>>= High ( rhs. _storage. low)
523
517
}
524
518
525
519
% {
0 commit comments