File tree 4 files changed +18
-6
lines changed
testsuite/tests/lib-smallint
4 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,8 @@ let shift_left x y = of_int (Int.shift_left (to_int x) y)
68
68
69
69
let shift_right x y = of_int (Int. shift_right (to_int x) y)
70
70
71
- let shift_right_logical x y = of_int (Int. shift_right_logical (to_int x) y)
71
+ let shift_right_logical x y =
72
+ of_int (Int. shift_right_logical (to_int x land mask) y)
72
73
73
74
let equal x y = Int. equal (to_int x) (to_int y)
74
75
Original file line number Diff line number Diff line change @@ -68,7 +68,8 @@ let shift_left x y = of_int (Int.shift_left (to_int x) y)
68
68
69
69
let shift_right x y = of_int (Int. shift_right (to_int x) y)
70
70
71
- let shift_right_logical x y = of_int (Int. shift_right_logical (to_int x) y)
71
+ let shift_right_logical x y =
72
+ of_int (Int. shift_right_logical (to_int x land mask) y)
72
73
73
74
let equal x y = Int. equal (to_int x) (to_int y)
74
75
Original file line number Diff line number Diff line change @@ -82,6 +82,11 @@ let test_logical1 = test_conv1 ~equal:equal_logical
82
82
83
83
let test_logical2 = test_conv2 ~equal: equal_logical
84
84
85
+ let reference_shift_right_logical x i =
86
+ (* we need to ensure that we shift in zero bytes, which is incompatible with
87
+ sign-extension *)
88
+ Int. shift_right_logical (if i > 0 then x land mask else x) i
89
+
85
90
let () =
86
91
test_round_trip () ;
87
92
assert (to_int Int16. zero == Int. zero);
@@ -104,8 +109,8 @@ let () =
104
109
test_logical1 (apply_shift Int16. shift_right) (apply_shift Int. shift_right);
105
110
test_conv1
106
111
(apply_shift Int16. shift_right_logical)
107
- (apply_shift Int. shift_right_logical )
108
- ~equal: ( if shift = 0 then equal_logical else equal_arith) ;
112
+ (apply_shift reference_shift_right_logical )
113
+ ~equal: equal_logical;
109
114
test_conv1
110
115
(apply_shift Int16. shift_left)
111
116
(apply_shift Int. shift_left)
Original file line number Diff line number Diff line change @@ -82,6 +82,11 @@ let test_logical1 = test_conv1 ~equal:equal_logical
82
82
83
83
let test_logical2 = test_conv2 ~equal: equal_logical
84
84
85
+ let reference_shift_right_logical x i =
86
+ (* we need to ensure that we shift in zero bytes, which is incompatible with
87
+ sign-extension *)
88
+ Int. shift_right_logical (if i > 0 then x land mask else x) i
89
+
85
90
let () =
86
91
test_round_trip () ;
87
92
assert (to_int Int8. zero == Int. zero);
@@ -104,8 +109,8 @@ let () =
104
109
test_logical1 (apply_shift Int8. shift_right) (apply_shift Int. shift_right);
105
110
test_conv1
106
111
(apply_shift Int8. shift_right_logical)
107
- (apply_shift Int. shift_right_logical )
108
- ~equal: ( if shift = 0 then equal_logical else equal_arith) ;
112
+ (apply_shift reference_shift_right_logical )
113
+ ~equal: equal_logical;
109
114
test_conv1
110
115
(apply_shift Int8. shift_left)
111
116
(apply_shift Int. shift_left)
You can’t perform that action at this time.
0 commit comments