@@ -602,7 +602,7 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
602
602
if (abs_shift_amt >= @typeInfo (C ).int .bits ) return @splat (0 );
603
603
break :blk @as (@Vector (len , Log2Int (C )), @splat (@as (Log2Int (C ), @intCast (abs_shift_amt ))));
604
604
} else {
605
- if (abs_shift_amt >= @typeInfo (T ).int .bits ) return 0 ;
605
+ if (T != comptime_int and abs_shift_amt >= @typeInfo (T ).int .bits ) return 0 ;
606
606
break :blk @as (Log2Int (T ), @intCast (abs_shift_amt ));
607
607
}
608
608
};
@@ -642,7 +642,7 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
642
642
if (abs_shift_amt >= @typeInfo (C ).int .bits ) return @splat (0 );
643
643
break :blk @as (@Vector (len , Log2Int (C )), @splat (@as (Log2Int (C ), @intCast (abs_shift_amt ))));
644
644
} else {
645
- if (abs_shift_amt >= @typeInfo (T ).int .bits ) return 0 ;
645
+ if (T != comptime_int and abs_shift_amt >= @typeInfo (T ).int .bits ) return if ( a < 0 ) -1 else 0 ;
646
646
break :blk @as (Log2Int (T ), @intCast (abs_shift_amt ));
647
647
}
648
648
};
@@ -658,6 +658,8 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
658
658
659
659
test shr {
660
660
try testing .expect (shr (u8 , 0b11111111 , @as (usize , 3 )) == 0b00011111 );
661
+ try testing .expect (shr (i8 , -1 , @as (usize , 3 )) == -1 );
662
+ try testing .expect (shr (i8 , -1 , @as (usize , 9 )) == -1 );
661
663
try testing .expect (shr (u8 , 0b11111111 , @as (usize , 8 )) == 0 );
662
664
try testing .expect (shr (u8 , 0b11111111 , @as (usize , 9 )) == 0 );
663
665
try testing .expect (shr (u8 , 0b11111111 , @as (isize , -2 )) == 0b11111100 );
0 commit comments