[m-rev.] for review: add left and right shifts for uints

Julien Fischer jfischer at opturion.com
Thu May 4 13:34:01 AEST 2017


For review by anyone.

This adds left and right shifts for uints.  As proposed on the mailing list
these operations throw an exception if the second operand is not in the
range [0, bits_per_uint).  (I assume everyone is alright with this
behaviour since nobody objected when Zoltan suggested it.)  I will make
a corresponding change to the int module separately.

--------------------------------------

Implement checked shifts for uints.

library/uint.m:
      Add checked left and right shift operations on uints.

tests/hard_coded/Mmakefile:
tests/hard_coded/uint_bitwise.m:
      Test bitwise operators on uints.

tests/hard_coded/uint_bitwise.exp:
      Expected output for 64-bit machines.

tests/hard_coded/uint_bitwise.exp2:
      Expected output for 32-bit machines (as well as the
      C# and Java grades).

Julien.

diff --git a/library/uint.m b/library/uint.m
index 89ae643f6..f757cd78e 100644
--- a/library/uint.m
+++ b/library/uint.m
@@ -81,8 +81,30 @@

  :- func unchecked_rem(uint::in, uint::in) = (uint::uo) is det.

+    % Left shift.
+    % X << Y returns X "left shifted" by Y bits.
+    % The bit positions vacated by the shift are filled by zeros.
+    % Throws an exception if Y is not in [0, bits_per_uint).
+    %
+:- func (uint::in) << (int::in) = (uint::uo) is det.
+
+    % unchecked_lift_shift(X, Y) is the same as X << Y except that the
+    % behaviour is undefined if Y is not in [0, bits_per_uint).
+    % It will typically be be implemented more efficiently than X << Y.
+    %
  :- func unchecked_left_shift(uint::in, int::in) = (uint::uo) is det.

+    % Right shift.
+    % X >> Y returns X "right shifted" by Y bits.
+    % The bit positions vacated by the shift are filled by zeros.
+    % Throws an exception if Y is not in [0, bits_per_uint).
+    %
+:- func (uint::in) >> (int::in) = (uint::uo) is det.
+
+    % unchecked_right_shift(X, Y) is the same as X >> Y except that the
+    % behaviour is undefined if Y is not in [0, bits_per_uint).
+    % It will typically be implemented more efficiently than X >> Y.
+    %
  :- func unchecked_right_shift(uint::in, int::in) = (uint::uo) is det.

      % even(X) is equivalent to (X mod 2 = 0).
@@ -126,6 +148,8 @@

  :- implementation.

+:- import_module exception.
+:- import_module math.
  :- import_module require.
  :- import_module string.

@@ -220,6 +244,24 @@ cast_to_int(_) = _ :-

  %---------------------------------------------------------------------------%

+X << Y = Result :-
+    ( if cast_from_int(Y) < cast_from_int(bits_per_uint) then
+        Result = unchecked_left_shift(X, Y)
+    else
+        Msg = "uint.(<<): second operand is out of range",
+        throw(math.domain_error(Msg))
+    ).
+
+X >> Y = Result :-
+    ( if cast_from_int(Y) < cast_from_int(bits_per_uint) then
+        Result = unchecked_right_shift(X, Y)
+    else
+        Msg = "uint.(>>): second operand is out of range",
+        throw(math.domain_error(Msg))
+    ).
+
+%---------------------------------------------------------------------------%
+
  max(X, Y) =
      ( if X > Y then X else Y ).

diff --git a/tests/hard_coded/Mmakefile b/tests/hard_coded/Mmakefile
index e611975b9..5643d7cde 100644
--- a/tests/hard_coded/Mmakefile
+++ b/tests/hard_coded/Mmakefile
@@ -637,6 +637,7 @@ ifeq "$(findstring profdeep,$(GRADE))" ""
  		try_syntax_6 \
  		try_syntax_7 \
  		uint_arith \
+		uint_bitwise \
  		user_defined_equality \
  		version_array_test \
  		version_hash_table_delete \
diff --git a/tests/hard_coded/uint_bitwise.exp b/tests/hard_coded/uint_bitwise.exp
index e69de29bb..38e447d98 100644
--- a/tests/hard_coded/uint_bitwise.exp
+++ b/tests/hard_coded/uint_bitwise.exp
@@ -0,0 +1,325 @@
+*** Test unary operation '\' ***
+
+\ 0000000000000000000000000000000000000000000000000000000000000000 = 1111111111111111111111111111111111111111111111111111111111111111
+\ 0000000000000000000000000000000000000000000000000000000000000001 = 1111111111111111111111111111111111111111111111111111111111111110
+\ 0000000000000000000000000000000000000000000000000000000000000010 = 1111111111111111111111111111111111111111111111111111111111111101
+\ 0000000000000000000000000000000000000000000000000000000000001000 = 1111111111111111111111111111111111111111111111111111111111110111
+\ 0000000000000000000000000000000000000000000000000000000000001010 = 1111111111111111111111111111111111111111111111111111111111110101
+\ 0000000000000000000000000000000000000000000000000000000000010000 = 1111111111111111111111111111111111111111111111111111111111101111
+\ 1111111111111111111111111111111111111111111111111111111111111111 = 0000000000000000000000000000000000000000000000000000000000000000
+
+*** Test binary operation '/\' ***
+
+0000000000000000000000000000000000000000000000000000000000000000 /\ 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 /\ 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 /\ 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 /\ 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 /\ 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 /\ 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 /\ 1111111111111111111111111111111111111111111111111111111111111111 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 /\ 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 /\ 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000000001
+0000000000000000000000000000000000000000000000000000000000000001 /\ 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 /\ 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 /\ 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 /\ 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 /\ 1111111111111111111111111111111111111111111111111111111111111111 = 0000000000000000000000000000000000000000000000000000000000000001
+0000000000000000000000000000000000000000000000000000000000000010 /\ 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000010 /\ 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000010 /\ 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000000010 /\ 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000010 /\ 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000000010 /\ 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000010 /\ 1111111111111111111111111111111111111111111111111111111111111111 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000001000 /\ 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001000 /\ 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001000 /\ 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001000 /\ 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000001000 /\ 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000001000 /\ 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001000 /\ 1111111111111111111111111111111111111111111111111111111111111111 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000001010 /\ 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001010 /\ 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001010 /\ 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000001010 /\ 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000001010 /\ 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000001010 /\ 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001010 /\ 1111111111111111111111111111111111111111111111111111111111111111 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000010000 /\ 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000010000 /\ 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000010000 /\ 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000010000 /\ 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000010000 /\ 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000010000 /\ 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000010000
+0000000000000000000000000000000000000000000000000000000000010000 /\ 1111111111111111111111111111111111111111111111111111111111111111 = 0000000000000000000000000000000000000000000000000000000000010000
+1111111111111111111111111111111111111111111111111111111111111111 /\ 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000000000
+1111111111111111111111111111111111111111111111111111111111111111 /\ 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000000001
+1111111111111111111111111111111111111111111111111111111111111111 /\ 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000000010
+1111111111111111111111111111111111111111111111111111111111111111 /\ 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000001000
+1111111111111111111111111111111111111111111111111111111111111111 /\ 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000001010
+1111111111111111111111111111111111111111111111111111111111111111 /\ 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000010000
+1111111111111111111111111111111111111111111111111111111111111111 /\ 1111111111111111111111111111111111111111111111111111111111111111 = 1111111111111111111111111111111111111111111111111111111111111111
+
+*** Test binary operation '\/' ***
+
+0000000000000000000000000000000000000000000000000000000000000000 \/ 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 \/ 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000000001
+0000000000000000000000000000000000000000000000000000000000000000 \/ 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000000000 \/ 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000000000 \/ 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000000000 \/ 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000010000
+0000000000000000000000000000000000000000000000000000000000000000 \/ 1111111111111111111111111111111111111111111111111111111111111111 = 1111111111111111111111111111111111111111111111111111111111111111
+0000000000000000000000000000000000000000000000000000000000000001 \/ 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000000001
+0000000000000000000000000000000000000000000000000000000000000001 \/ 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000000001
+0000000000000000000000000000000000000000000000000000000000000001 \/ 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000000011
+0000000000000000000000000000000000000000000000000000000000000001 \/ 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000001001
+0000000000000000000000000000000000000000000000000000000000000001 \/ 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000001011
+0000000000000000000000000000000000000000000000000000000000000001 \/ 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000010001
+0000000000000000000000000000000000000000000000000000000000000001 \/ 1111111111111111111111111111111111111111111111111111111111111111 = 1111111111111111111111111111111111111111111111111111111111111111
+0000000000000000000000000000000000000000000000000000000000000010 \/ 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000000010 \/ 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000000011
+0000000000000000000000000000000000000000000000000000000000000010 \/ 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000000010 \/ 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000000010 \/ 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000000010 \/ 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000010010
+0000000000000000000000000000000000000000000000000000000000000010 \/ 1111111111111111111111111111111111111111111111111111111111111111 = 1111111111111111111111111111111111111111111111111111111111111111
+0000000000000000000000000000000000000000000000000000000000001000 \/ 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000001000 \/ 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000001001
+0000000000000000000000000000000000000000000000000000000000001000 \/ 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000001000 \/ 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000001000 \/ 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000001000 \/ 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000011000
+0000000000000000000000000000000000000000000000000000000000001000 \/ 1111111111111111111111111111111111111111111111111111111111111111 = 1111111111111111111111111111111111111111111111111111111111111111
+0000000000000000000000000000000000000000000000000000000000001010 \/ 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000001010 \/ 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000001011
+0000000000000000000000000000000000000000000000000000000000001010 \/ 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000001010 \/ 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000001010 \/ 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000001010 \/ 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000011010
+0000000000000000000000000000000000000000000000000000000000001010 \/ 1111111111111111111111111111111111111111111111111111111111111111 = 1111111111111111111111111111111111111111111111111111111111111111
+0000000000000000000000000000000000000000000000000000000000010000 \/ 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000010000
+0000000000000000000000000000000000000000000000000000000000010000 \/ 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000010001
+0000000000000000000000000000000000000000000000000000000000010000 \/ 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000010010
+0000000000000000000000000000000000000000000000000000000000010000 \/ 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000011000
+0000000000000000000000000000000000000000000000000000000000010000 \/ 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000011010
+0000000000000000000000000000000000000000000000000000000000010000 \/ 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000010000
+0000000000000000000000000000000000000000000000000000000000010000 \/ 1111111111111111111111111111111111111111111111111111111111111111 = 1111111111111111111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 \/ 0000000000000000000000000000000000000000000000000000000000000000 = 1111111111111111111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 \/ 0000000000000000000000000000000000000000000000000000000000000001 = 1111111111111111111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 \/ 0000000000000000000000000000000000000000000000000000000000000010 = 1111111111111111111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 \/ 0000000000000000000000000000000000000000000000000000000000001000 = 1111111111111111111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 \/ 0000000000000000000000000000000000000000000000000000000000001010 = 1111111111111111111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 \/ 0000000000000000000000000000000000000000000000000000000000010000 = 1111111111111111111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 \/ 1111111111111111111111111111111111111111111111111111111111111111 = 1111111111111111111111111111111111111111111111111111111111111111
+
+*** Test binary operation 'xor' ***
+
+0000000000000000000000000000000000000000000000000000000000000000 xor 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 xor 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000000001
+0000000000000000000000000000000000000000000000000000000000000000 xor 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000000000 xor 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000000000 xor 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000000000 xor 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000010000
+0000000000000000000000000000000000000000000000000000000000000000 xor 1111111111111111111111111111111111111111111111111111111111111111 = 1111111111111111111111111111111111111111111111111111111111111111
+0000000000000000000000000000000000000000000000000000000000000001 xor 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000000001
+0000000000000000000000000000000000000000000000000000000000000001 xor 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 xor 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000000011
+0000000000000000000000000000000000000000000000000000000000000001 xor 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000001001
+0000000000000000000000000000000000000000000000000000000000000001 xor 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000001011
+0000000000000000000000000000000000000000000000000000000000000001 xor 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000010001
+0000000000000000000000000000000000000000000000000000000000000001 xor 1111111111111111111111111111111111111111111111111111111111111111 = 1111111111111111111111111111111111111111111111111111111111111110
+0000000000000000000000000000000000000000000000000000000000000010 xor 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000000010 xor 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000000011
+0000000000000000000000000000000000000000000000000000000000000010 xor 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000010 xor 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000000010 xor 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000000010 xor 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000010010
+0000000000000000000000000000000000000000000000000000000000000010 xor 1111111111111111111111111111111111111111111111111111111111111111 = 1111111111111111111111111111111111111111111111111111111111111101
+0000000000000000000000000000000000000000000000000000000000001000 xor 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000001000 xor 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000001001
+0000000000000000000000000000000000000000000000000000000000001000 xor 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000001000 xor 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001000 xor 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000001000 xor 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000011000
+0000000000000000000000000000000000000000000000000000000000001000 xor 1111111111111111111111111111111111111111111111111111111111111111 = 1111111111111111111111111111111111111111111111111111111111110111
+0000000000000000000000000000000000000000000000000000000000001010 xor 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000001010 xor 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000001011
+0000000000000000000000000000000000000000000000000000000000001010 xor 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000001010 xor 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000001010 xor 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001010 xor 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000011010
+0000000000000000000000000000000000000000000000000000000000001010 xor 1111111111111111111111111111111111111111111111111111111111111111 = 1111111111111111111111111111111111111111111111111111111111110101
+0000000000000000000000000000000000000000000000000000000000010000 xor 0000000000000000000000000000000000000000000000000000000000000000 = 0000000000000000000000000000000000000000000000000000000000010000
+0000000000000000000000000000000000000000000000000000000000010000 xor 0000000000000000000000000000000000000000000000000000000000000001 = 0000000000000000000000000000000000000000000000000000000000010001
+0000000000000000000000000000000000000000000000000000000000010000 xor 0000000000000000000000000000000000000000000000000000000000000010 = 0000000000000000000000000000000000000000000000000000000000010010
+0000000000000000000000000000000000000000000000000000000000010000 xor 0000000000000000000000000000000000000000000000000000000000001000 = 0000000000000000000000000000000000000000000000000000000000011000
+0000000000000000000000000000000000000000000000000000000000010000 xor 0000000000000000000000000000000000000000000000000000000000001010 = 0000000000000000000000000000000000000000000000000000000000011010
+0000000000000000000000000000000000000000000000000000000000010000 xor 0000000000000000000000000000000000000000000000000000000000010000 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000010000 xor 1111111111111111111111111111111111111111111111111111111111111111 = 1111111111111111111111111111111111111111111111111111111111101111
+1111111111111111111111111111111111111111111111111111111111111111 xor 0000000000000000000000000000000000000000000000000000000000000000 = 1111111111111111111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 xor 0000000000000000000000000000000000000000000000000000000000000001 = 1111111111111111111111111111111111111111111111111111111111111110
+1111111111111111111111111111111111111111111111111111111111111111 xor 0000000000000000000000000000000000000000000000000000000000000010 = 1111111111111111111111111111111111111111111111111111111111111101
+1111111111111111111111111111111111111111111111111111111111111111 xor 0000000000000000000000000000000000000000000000000000000000001000 = 1111111111111111111111111111111111111111111111111111111111110111
+1111111111111111111111111111111111111111111111111111111111111111 xor 0000000000000000000000000000000000000000000000000000000000001010 = 1111111111111111111111111111111111111111111111111111111111110101
+1111111111111111111111111111111111111111111111111111111111111111 xor 0000000000000000000000000000000000000000000000000000000000010000 = 1111111111111111111111111111111111111111111111111111111111101111
+1111111111111111111111111111111111111111111111111111111111111111 xor 1111111111111111111111111111111111111111111111111111111111111111 = 0000000000000000000000000000000000000000000000000000000000000000
+
+*** Test binary operation '>>' ***
+
+0000000000000000000000000000000000000000000000000000000000000000 >> -1 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000000000 >> 0 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 >> 1 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 >> 2 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 >> 3 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 >> 4 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 >> 8 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 >> 16 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 >> 24 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 >> 63 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 >> 64 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000000001 >> -1 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000000001 >> 0 = 0000000000000000000000000000000000000000000000000000000000000001
+0000000000000000000000000000000000000000000000000000000000000001 >> 1 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 >> 2 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 >> 3 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 >> 4 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 >> 8 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 >> 16 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 >> 24 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 >> 63 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 >> 64 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000000010 >> -1 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000000010 >> 0 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000000010 >> 1 = 0000000000000000000000000000000000000000000000000000000000000001
+0000000000000000000000000000000000000000000000000000000000000010 >> 2 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000010 >> 3 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000010 >> 4 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000010 >> 8 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000010 >> 16 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000010 >> 24 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000010 >> 63 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000010 >> 64 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000001000 >> -1 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000001000 >> 0 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000001000 >> 1 = 0000000000000000000000000000000000000000000000000000000000000100
+0000000000000000000000000000000000000000000000000000000000001000 >> 2 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000001000 >> 3 = 0000000000000000000000000000000000000000000000000000000000000001
+0000000000000000000000000000000000000000000000000000000000001000 >> 4 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001000 >> 8 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001000 >> 16 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001000 >> 24 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001000 >> 63 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001000 >> 64 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000001010 >> -1 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000001010 >> 0 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000001010 >> 1 = 0000000000000000000000000000000000000000000000000000000000000101
+0000000000000000000000000000000000000000000000000000000000001010 >> 2 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000001010 >> 3 = 0000000000000000000000000000000000000000000000000000000000000001
+0000000000000000000000000000000000000000000000000000000000001010 >> 4 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001010 >> 8 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001010 >> 16 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001010 >> 24 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001010 >> 63 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001010 >> 64 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000010000 >> -1 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000010000 >> 0 = 0000000000000000000000000000000000000000000000000000000000010000
+0000000000000000000000000000000000000000000000000000000000010000 >> 1 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000010000 >> 2 = 0000000000000000000000000000000000000000000000000000000000000100
+0000000000000000000000000000000000000000000000000000000000010000 >> 3 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000010000 >> 4 = 0000000000000000000000000000000000000000000000000000000000000001
+0000000000000000000000000000000000000000000000000000000000010000 >> 8 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000010000 >> 16 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000010000 >> 24 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000010000 >> 63 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000010000 >> 64 = <<exception>>
+1111111111111111111111111111111111111111111111111111111111111111 >> -1 = <<exception>>
+1111111111111111111111111111111111111111111111111111111111111111 >> 0 = 1111111111111111111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 >> 1 = 0111111111111111111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 >> 2 = 0011111111111111111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 >> 3 = 0001111111111111111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 >> 4 = 0000111111111111111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 >> 8 = 0000000011111111111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 >> 16 = 0000000000000000111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 >> 24 = 0000000000000000000000001111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 >> 63 = 0000000000000000000000000000000000000000000000000000000000000001
+1111111111111111111111111111111111111111111111111111111111111111 >> 64 = <<exception>>
+
+*** Test binary operation '<<' ***
+
+0000000000000000000000000000000000000000000000000000000000000000 << -1 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000000000 << 0 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 << 1 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 << 2 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 << 3 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 << 4 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 << 8 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 << 16 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 << 24 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 << 63 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000000 << 64 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000000001 << -1 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000000001 << 0 = 0000000000000000000000000000000000000000000000000000000000000001
+0000000000000000000000000000000000000000000000000000000000000001 << 1 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000000001 << 2 = 0000000000000000000000000000000000000000000000000000000000000100
+0000000000000000000000000000000000000000000000000000000000000001 << 3 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000000001 << 4 = 0000000000000000000000000000000000000000000000000000000000010000
+0000000000000000000000000000000000000000000000000000000000000001 << 8 = 0000000000000000000000000000000000000000000000000000000100000000
+0000000000000000000000000000000000000000000000000000000000000001 << 16 = 0000000000000000000000000000000000000000000000010000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 << 24 = 0000000000000000000000000000000000000001000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 << 63 = 1000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000001 << 64 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000000010 << -1 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000000010 << 0 = 0000000000000000000000000000000000000000000000000000000000000010
+0000000000000000000000000000000000000000000000000000000000000010 << 1 = 0000000000000000000000000000000000000000000000000000000000000100
+0000000000000000000000000000000000000000000000000000000000000010 << 2 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000000010 << 3 = 0000000000000000000000000000000000000000000000000000000000010000
+0000000000000000000000000000000000000000000000000000000000000010 << 4 = 0000000000000000000000000000000000000000000000000000000000100000
+0000000000000000000000000000000000000000000000000000000000000010 << 8 = 0000000000000000000000000000000000000000000000000000001000000000
+0000000000000000000000000000000000000000000000000000000000000010 << 16 = 0000000000000000000000000000000000000000000000100000000000000000
+0000000000000000000000000000000000000000000000000000000000000010 << 24 = 0000000000000000000000000000000000000010000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000010 << 63 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000000010 << 64 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000001000 << -1 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000001000 << 0 = 0000000000000000000000000000000000000000000000000000000000001000
+0000000000000000000000000000000000000000000000000000000000001000 << 1 = 0000000000000000000000000000000000000000000000000000000000010000
+0000000000000000000000000000000000000000000000000000000000001000 << 2 = 0000000000000000000000000000000000000000000000000000000000100000
+0000000000000000000000000000000000000000000000000000000000001000 << 3 = 0000000000000000000000000000000000000000000000000000000001000000
+0000000000000000000000000000000000000000000000000000000000001000 << 4 = 0000000000000000000000000000000000000000000000000000000010000000
+0000000000000000000000000000000000000000000000000000000000001000 << 8 = 0000000000000000000000000000000000000000000000000000100000000000
+0000000000000000000000000000000000000000000000000000000000001000 << 16 = 0000000000000000000000000000000000000000000010000000000000000000
+0000000000000000000000000000000000000000000000000000000000001000 << 24 = 0000000000000000000000000000000000001000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001000 << 63 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001000 << 64 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000001010 << -1 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000001010 << 0 = 0000000000000000000000000000000000000000000000000000000000001010
+0000000000000000000000000000000000000000000000000000000000001010 << 1 = 0000000000000000000000000000000000000000000000000000000000010100
+0000000000000000000000000000000000000000000000000000000000001010 << 2 = 0000000000000000000000000000000000000000000000000000000000101000
+0000000000000000000000000000000000000000000000000000000000001010 << 3 = 0000000000000000000000000000000000000000000000000000000001010000
+0000000000000000000000000000000000000000000000000000000000001010 << 4 = 0000000000000000000000000000000000000000000000000000000010100000
+0000000000000000000000000000000000000000000000000000000000001010 << 8 = 0000000000000000000000000000000000000000000000000000101000000000
+0000000000000000000000000000000000000000000000000000000000001010 << 16 = 0000000000000000000000000000000000000000000010100000000000000000
+0000000000000000000000000000000000000000000000000000000000001010 << 24 = 0000000000000000000000000000000000001010000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001010 << 63 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000001010 << 64 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000010000 << -1 = <<exception>>
+0000000000000000000000000000000000000000000000000000000000010000 << 0 = 0000000000000000000000000000000000000000000000000000000000010000
+0000000000000000000000000000000000000000000000000000000000010000 << 1 = 0000000000000000000000000000000000000000000000000000000000100000
+0000000000000000000000000000000000000000000000000000000000010000 << 2 = 0000000000000000000000000000000000000000000000000000000001000000
+0000000000000000000000000000000000000000000000000000000000010000 << 3 = 0000000000000000000000000000000000000000000000000000000010000000
+0000000000000000000000000000000000000000000000000000000000010000 << 4 = 0000000000000000000000000000000000000000000000000000000100000000
+0000000000000000000000000000000000000000000000000000000000010000 << 8 = 0000000000000000000000000000000000000000000000000001000000000000
+0000000000000000000000000000000000000000000000000000000000010000 << 16 = 0000000000000000000000000000000000000000000100000000000000000000
+0000000000000000000000000000000000000000000000000000000000010000 << 24 = 0000000000000000000000000000000000010000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000010000 << 63 = 0000000000000000000000000000000000000000000000000000000000000000
+0000000000000000000000000000000000000000000000000000000000010000 << 64 = <<exception>>
+1111111111111111111111111111111111111111111111111111111111111111 << -1 = <<exception>>
+1111111111111111111111111111111111111111111111111111111111111111 << 0 = 1111111111111111111111111111111111111111111111111111111111111111
+1111111111111111111111111111111111111111111111111111111111111111 << 1 = 1111111111111111111111111111111111111111111111111111111111111110
+1111111111111111111111111111111111111111111111111111111111111111 << 2 = 1111111111111111111111111111111111111111111111111111111111111100
+1111111111111111111111111111111111111111111111111111111111111111 << 3 = 1111111111111111111111111111111111111111111111111111111111111000
+1111111111111111111111111111111111111111111111111111111111111111 << 4 = 1111111111111111111111111111111111111111111111111111111111110000
+1111111111111111111111111111111111111111111111111111111111111111 << 8 = 1111111111111111111111111111111111111111111111111111111100000000
+1111111111111111111111111111111111111111111111111111111111111111 << 16 = 1111111111111111111111111111111111111111111111110000000000000000
+1111111111111111111111111111111111111111111111111111111111111111 << 24 = 1111111111111111111111111111111111111111000000000000000000000000
+1111111111111111111111111111111111111111111111111111111111111111 << 63 = 1000000000000000000000000000000000000000000000000000000000000000
+1111111111111111111111111111111111111111111111111111111111111111 << 64 = <<exception>>
diff --git a/tests/hard_coded/uint_bitwise.exp2 b/tests/hard_coded/uint_bitwise.exp2
index e69de29bb..eda7822fd 100644
--- a/tests/hard_coded/uint_bitwise.exp2
+++ b/tests/hard_coded/uint_bitwise.exp2
@@ -0,0 +1,325 @@
+*** Test unary operation '\' ***
+
+\ 00000000000000000000000000000000 = 11111111111111111111111111111111
+\ 00000000000000000000000000000001 = 11111111111111111111111111111110
+\ 00000000000000000000000000000010 = 11111111111111111111111111111101
+\ 00000000000000000000000000001000 = 11111111111111111111111111110111
+\ 00000000000000000000000000001010 = 11111111111111111111111111110101
+\ 00000000000000000000000000010000 = 11111111111111111111111111101111
+\ 11111111111111111111111111111111 = 00000000000000000000000000000000
+
+*** Test binary operation '/\' ***
+
+00000000000000000000000000000000 /\ 00000000000000000000000000000000 = 00000000000000000000000000000000
+00000000000000000000000000000000 /\ 00000000000000000000000000000001 = 00000000000000000000000000000000
+00000000000000000000000000000000 /\ 00000000000000000000000000000010 = 00000000000000000000000000000000
+00000000000000000000000000000000 /\ 00000000000000000000000000001000 = 00000000000000000000000000000000
+00000000000000000000000000000000 /\ 00000000000000000000000000001010 = 00000000000000000000000000000000
+00000000000000000000000000000000 /\ 00000000000000000000000000010000 = 00000000000000000000000000000000
+00000000000000000000000000000000 /\ 11111111111111111111111111111111 = 00000000000000000000000000000000
+00000000000000000000000000000001 /\ 00000000000000000000000000000000 = 00000000000000000000000000000000
+00000000000000000000000000000001 /\ 00000000000000000000000000000001 = 00000000000000000000000000000001
+00000000000000000000000000000001 /\ 00000000000000000000000000000010 = 00000000000000000000000000000000
+00000000000000000000000000000001 /\ 00000000000000000000000000001000 = 00000000000000000000000000000000
+00000000000000000000000000000001 /\ 00000000000000000000000000001010 = 00000000000000000000000000000000
+00000000000000000000000000000001 /\ 00000000000000000000000000010000 = 00000000000000000000000000000000
+00000000000000000000000000000001 /\ 11111111111111111111111111111111 = 00000000000000000000000000000001
+00000000000000000000000000000010 /\ 00000000000000000000000000000000 = 00000000000000000000000000000000
+00000000000000000000000000000010 /\ 00000000000000000000000000000001 = 00000000000000000000000000000000
+00000000000000000000000000000010 /\ 00000000000000000000000000000010 = 00000000000000000000000000000010
+00000000000000000000000000000010 /\ 00000000000000000000000000001000 = 00000000000000000000000000000000
+00000000000000000000000000000010 /\ 00000000000000000000000000001010 = 00000000000000000000000000000010
+00000000000000000000000000000010 /\ 00000000000000000000000000010000 = 00000000000000000000000000000000
+00000000000000000000000000000010 /\ 11111111111111111111111111111111 = 00000000000000000000000000000010
+00000000000000000000000000001000 /\ 00000000000000000000000000000000 = 00000000000000000000000000000000
+00000000000000000000000000001000 /\ 00000000000000000000000000000001 = 00000000000000000000000000000000
+00000000000000000000000000001000 /\ 00000000000000000000000000000010 = 00000000000000000000000000000000
+00000000000000000000000000001000 /\ 00000000000000000000000000001000 = 00000000000000000000000000001000
+00000000000000000000000000001000 /\ 00000000000000000000000000001010 = 00000000000000000000000000001000
+00000000000000000000000000001000 /\ 00000000000000000000000000010000 = 00000000000000000000000000000000
+00000000000000000000000000001000 /\ 11111111111111111111111111111111 = 00000000000000000000000000001000
+00000000000000000000000000001010 /\ 00000000000000000000000000000000 = 00000000000000000000000000000000
+00000000000000000000000000001010 /\ 00000000000000000000000000000001 = 00000000000000000000000000000000
+00000000000000000000000000001010 /\ 00000000000000000000000000000010 = 00000000000000000000000000000010
+00000000000000000000000000001010 /\ 00000000000000000000000000001000 = 00000000000000000000000000001000
+00000000000000000000000000001010 /\ 00000000000000000000000000001010 = 00000000000000000000000000001010
+00000000000000000000000000001010 /\ 00000000000000000000000000010000 = 00000000000000000000000000000000
+00000000000000000000000000001010 /\ 11111111111111111111111111111111 = 00000000000000000000000000001010
+00000000000000000000000000010000 /\ 00000000000000000000000000000000 = 00000000000000000000000000000000
+00000000000000000000000000010000 /\ 00000000000000000000000000000001 = 00000000000000000000000000000000
+00000000000000000000000000010000 /\ 00000000000000000000000000000010 = 00000000000000000000000000000000
+00000000000000000000000000010000 /\ 00000000000000000000000000001000 = 00000000000000000000000000000000
+00000000000000000000000000010000 /\ 00000000000000000000000000001010 = 00000000000000000000000000000000
+00000000000000000000000000010000 /\ 00000000000000000000000000010000 = 00000000000000000000000000010000
+00000000000000000000000000010000 /\ 11111111111111111111111111111111 = 00000000000000000000000000010000
+11111111111111111111111111111111 /\ 00000000000000000000000000000000 = 00000000000000000000000000000000
+11111111111111111111111111111111 /\ 00000000000000000000000000000001 = 00000000000000000000000000000001
+11111111111111111111111111111111 /\ 00000000000000000000000000000010 = 00000000000000000000000000000010
+11111111111111111111111111111111 /\ 00000000000000000000000000001000 = 00000000000000000000000000001000
+11111111111111111111111111111111 /\ 00000000000000000000000000001010 = 00000000000000000000000000001010
+11111111111111111111111111111111 /\ 00000000000000000000000000010000 = 00000000000000000000000000010000
+11111111111111111111111111111111 /\ 11111111111111111111111111111111 = 11111111111111111111111111111111
+
+*** Test binary operation '\/' ***
+
+00000000000000000000000000000000 \/ 00000000000000000000000000000000 = 00000000000000000000000000000000
+00000000000000000000000000000000 \/ 00000000000000000000000000000001 = 00000000000000000000000000000001
+00000000000000000000000000000000 \/ 00000000000000000000000000000010 = 00000000000000000000000000000010
+00000000000000000000000000000000 \/ 00000000000000000000000000001000 = 00000000000000000000000000001000
+00000000000000000000000000000000 \/ 00000000000000000000000000001010 = 00000000000000000000000000001010
+00000000000000000000000000000000 \/ 00000000000000000000000000010000 = 00000000000000000000000000010000
+00000000000000000000000000000000 \/ 11111111111111111111111111111111 = 11111111111111111111111111111111
+00000000000000000000000000000001 \/ 00000000000000000000000000000000 = 00000000000000000000000000000001
+00000000000000000000000000000001 \/ 00000000000000000000000000000001 = 00000000000000000000000000000001
+00000000000000000000000000000001 \/ 00000000000000000000000000000010 = 00000000000000000000000000000011
+00000000000000000000000000000001 \/ 00000000000000000000000000001000 = 00000000000000000000000000001001
+00000000000000000000000000000001 \/ 00000000000000000000000000001010 = 00000000000000000000000000001011
+00000000000000000000000000000001 \/ 00000000000000000000000000010000 = 00000000000000000000000000010001
+00000000000000000000000000000001 \/ 11111111111111111111111111111111 = 11111111111111111111111111111111
+00000000000000000000000000000010 \/ 00000000000000000000000000000000 = 00000000000000000000000000000010
+00000000000000000000000000000010 \/ 00000000000000000000000000000001 = 00000000000000000000000000000011
+00000000000000000000000000000010 \/ 00000000000000000000000000000010 = 00000000000000000000000000000010
+00000000000000000000000000000010 \/ 00000000000000000000000000001000 = 00000000000000000000000000001010
+00000000000000000000000000000010 \/ 00000000000000000000000000001010 = 00000000000000000000000000001010
+00000000000000000000000000000010 \/ 00000000000000000000000000010000 = 00000000000000000000000000010010
+00000000000000000000000000000010 \/ 11111111111111111111111111111111 = 11111111111111111111111111111111
+00000000000000000000000000001000 \/ 00000000000000000000000000000000 = 00000000000000000000000000001000
+00000000000000000000000000001000 \/ 00000000000000000000000000000001 = 00000000000000000000000000001001
+00000000000000000000000000001000 \/ 00000000000000000000000000000010 = 00000000000000000000000000001010
+00000000000000000000000000001000 \/ 00000000000000000000000000001000 = 00000000000000000000000000001000
+00000000000000000000000000001000 \/ 00000000000000000000000000001010 = 00000000000000000000000000001010
+00000000000000000000000000001000 \/ 00000000000000000000000000010000 = 00000000000000000000000000011000
+00000000000000000000000000001000 \/ 11111111111111111111111111111111 = 11111111111111111111111111111111
+00000000000000000000000000001010 \/ 00000000000000000000000000000000 = 00000000000000000000000000001010
+00000000000000000000000000001010 \/ 00000000000000000000000000000001 = 00000000000000000000000000001011
+00000000000000000000000000001010 \/ 00000000000000000000000000000010 = 00000000000000000000000000001010
+00000000000000000000000000001010 \/ 00000000000000000000000000001000 = 00000000000000000000000000001010
+00000000000000000000000000001010 \/ 00000000000000000000000000001010 = 00000000000000000000000000001010
+00000000000000000000000000001010 \/ 00000000000000000000000000010000 = 00000000000000000000000000011010
+00000000000000000000000000001010 \/ 11111111111111111111111111111111 = 11111111111111111111111111111111
+00000000000000000000000000010000 \/ 00000000000000000000000000000000 = 00000000000000000000000000010000
+00000000000000000000000000010000 \/ 00000000000000000000000000000001 = 00000000000000000000000000010001
+00000000000000000000000000010000 \/ 00000000000000000000000000000010 = 00000000000000000000000000010010
+00000000000000000000000000010000 \/ 00000000000000000000000000001000 = 00000000000000000000000000011000
+00000000000000000000000000010000 \/ 00000000000000000000000000001010 = 00000000000000000000000000011010
+00000000000000000000000000010000 \/ 00000000000000000000000000010000 = 00000000000000000000000000010000
+00000000000000000000000000010000 \/ 11111111111111111111111111111111 = 11111111111111111111111111111111
+11111111111111111111111111111111 \/ 00000000000000000000000000000000 = 11111111111111111111111111111111
+11111111111111111111111111111111 \/ 00000000000000000000000000000001 = 11111111111111111111111111111111
+11111111111111111111111111111111 \/ 00000000000000000000000000000010 = 11111111111111111111111111111111
+11111111111111111111111111111111 \/ 00000000000000000000000000001000 = 11111111111111111111111111111111
+11111111111111111111111111111111 \/ 00000000000000000000000000001010 = 11111111111111111111111111111111
+11111111111111111111111111111111 \/ 00000000000000000000000000010000 = 11111111111111111111111111111111
+11111111111111111111111111111111 \/ 11111111111111111111111111111111 = 11111111111111111111111111111111
+
+*** Test binary operation 'xor' ***
+
+00000000000000000000000000000000 xor 00000000000000000000000000000000 = 00000000000000000000000000000000
+00000000000000000000000000000000 xor 00000000000000000000000000000001 = 00000000000000000000000000000001
+00000000000000000000000000000000 xor 00000000000000000000000000000010 = 00000000000000000000000000000010
+00000000000000000000000000000000 xor 00000000000000000000000000001000 = 00000000000000000000000000001000
+00000000000000000000000000000000 xor 00000000000000000000000000001010 = 00000000000000000000000000001010
+00000000000000000000000000000000 xor 00000000000000000000000000010000 = 00000000000000000000000000010000
+00000000000000000000000000000000 xor 11111111111111111111111111111111 = 11111111111111111111111111111111
+00000000000000000000000000000001 xor 00000000000000000000000000000000 = 00000000000000000000000000000001
+00000000000000000000000000000001 xor 00000000000000000000000000000001 = 00000000000000000000000000000000
+00000000000000000000000000000001 xor 00000000000000000000000000000010 = 00000000000000000000000000000011
+00000000000000000000000000000001 xor 00000000000000000000000000001000 = 00000000000000000000000000001001
+00000000000000000000000000000001 xor 00000000000000000000000000001010 = 00000000000000000000000000001011
+00000000000000000000000000000001 xor 00000000000000000000000000010000 = 00000000000000000000000000010001
+00000000000000000000000000000001 xor 11111111111111111111111111111111 = 11111111111111111111111111111110
+00000000000000000000000000000010 xor 00000000000000000000000000000000 = 00000000000000000000000000000010
+00000000000000000000000000000010 xor 00000000000000000000000000000001 = 00000000000000000000000000000011
+00000000000000000000000000000010 xor 00000000000000000000000000000010 = 00000000000000000000000000000000
+00000000000000000000000000000010 xor 00000000000000000000000000001000 = 00000000000000000000000000001010
+00000000000000000000000000000010 xor 00000000000000000000000000001010 = 00000000000000000000000000001000
+00000000000000000000000000000010 xor 00000000000000000000000000010000 = 00000000000000000000000000010010
+00000000000000000000000000000010 xor 11111111111111111111111111111111 = 11111111111111111111111111111101
+00000000000000000000000000001000 xor 00000000000000000000000000000000 = 00000000000000000000000000001000
+00000000000000000000000000001000 xor 00000000000000000000000000000001 = 00000000000000000000000000001001
+00000000000000000000000000001000 xor 00000000000000000000000000000010 = 00000000000000000000000000001010
+00000000000000000000000000001000 xor 00000000000000000000000000001000 = 00000000000000000000000000000000
+00000000000000000000000000001000 xor 00000000000000000000000000001010 = 00000000000000000000000000000010
+00000000000000000000000000001000 xor 00000000000000000000000000010000 = 00000000000000000000000000011000
+00000000000000000000000000001000 xor 11111111111111111111111111111111 = 11111111111111111111111111110111
+00000000000000000000000000001010 xor 00000000000000000000000000000000 = 00000000000000000000000000001010
+00000000000000000000000000001010 xor 00000000000000000000000000000001 = 00000000000000000000000000001011
+00000000000000000000000000001010 xor 00000000000000000000000000000010 = 00000000000000000000000000001000
+00000000000000000000000000001010 xor 00000000000000000000000000001000 = 00000000000000000000000000000010
+00000000000000000000000000001010 xor 00000000000000000000000000001010 = 00000000000000000000000000000000
+00000000000000000000000000001010 xor 00000000000000000000000000010000 = 00000000000000000000000000011010
+00000000000000000000000000001010 xor 11111111111111111111111111111111 = 11111111111111111111111111110101
+00000000000000000000000000010000 xor 00000000000000000000000000000000 = 00000000000000000000000000010000
+00000000000000000000000000010000 xor 00000000000000000000000000000001 = 00000000000000000000000000010001
+00000000000000000000000000010000 xor 00000000000000000000000000000010 = 00000000000000000000000000010010
+00000000000000000000000000010000 xor 00000000000000000000000000001000 = 00000000000000000000000000011000
+00000000000000000000000000010000 xor 00000000000000000000000000001010 = 00000000000000000000000000011010
+00000000000000000000000000010000 xor 00000000000000000000000000010000 = 00000000000000000000000000000000
+00000000000000000000000000010000 xor 11111111111111111111111111111111 = 11111111111111111111111111101111
+11111111111111111111111111111111 xor 00000000000000000000000000000000 = 11111111111111111111111111111111
+11111111111111111111111111111111 xor 00000000000000000000000000000001 = 11111111111111111111111111111110
+11111111111111111111111111111111 xor 00000000000000000000000000000010 = 11111111111111111111111111111101
+11111111111111111111111111111111 xor 00000000000000000000000000001000 = 11111111111111111111111111110111
+11111111111111111111111111111111 xor 00000000000000000000000000001010 = 11111111111111111111111111110101
+11111111111111111111111111111111 xor 00000000000000000000000000010000 = 11111111111111111111111111101111
+11111111111111111111111111111111 xor 11111111111111111111111111111111 = 00000000000000000000000000000000
+
+*** Test binary operation '>>' ***
+
+00000000000000000000000000000000 >> -1 = <<exception>>
+00000000000000000000000000000000 >> 0 = 00000000000000000000000000000000
+00000000000000000000000000000000 >> 1 = 00000000000000000000000000000000
+00000000000000000000000000000000 >> 2 = 00000000000000000000000000000000
+00000000000000000000000000000000 >> 3 = 00000000000000000000000000000000
+00000000000000000000000000000000 >> 4 = 00000000000000000000000000000000
+00000000000000000000000000000000 >> 8 = 00000000000000000000000000000000
+00000000000000000000000000000000 >> 16 = 00000000000000000000000000000000
+00000000000000000000000000000000 >> 24 = 00000000000000000000000000000000
+00000000000000000000000000000000 >> 31 = 00000000000000000000000000000000
+00000000000000000000000000000000 >> 32 = <<exception>>
+00000000000000000000000000000001 >> -1 = <<exception>>
+00000000000000000000000000000001 >> 0 = 00000000000000000000000000000001
+00000000000000000000000000000001 >> 1 = 00000000000000000000000000000000
+00000000000000000000000000000001 >> 2 = 00000000000000000000000000000000
+00000000000000000000000000000001 >> 3 = 00000000000000000000000000000000
+00000000000000000000000000000001 >> 4 = 00000000000000000000000000000000
+00000000000000000000000000000001 >> 8 = 00000000000000000000000000000000
+00000000000000000000000000000001 >> 16 = 00000000000000000000000000000000
+00000000000000000000000000000001 >> 24 = 00000000000000000000000000000000
+00000000000000000000000000000001 >> 31 = 00000000000000000000000000000000
+00000000000000000000000000000001 >> 32 = <<exception>>
+00000000000000000000000000000010 >> -1 = <<exception>>
+00000000000000000000000000000010 >> 0 = 00000000000000000000000000000010
+00000000000000000000000000000010 >> 1 = 00000000000000000000000000000001
+00000000000000000000000000000010 >> 2 = 00000000000000000000000000000000
+00000000000000000000000000000010 >> 3 = 00000000000000000000000000000000
+00000000000000000000000000000010 >> 4 = 00000000000000000000000000000000
+00000000000000000000000000000010 >> 8 = 00000000000000000000000000000000
+00000000000000000000000000000010 >> 16 = 00000000000000000000000000000000
+00000000000000000000000000000010 >> 24 = 00000000000000000000000000000000
+00000000000000000000000000000010 >> 31 = 00000000000000000000000000000000
+00000000000000000000000000000010 >> 32 = <<exception>>
+00000000000000000000000000001000 >> -1 = <<exception>>
+00000000000000000000000000001000 >> 0 = 00000000000000000000000000001000
+00000000000000000000000000001000 >> 1 = 00000000000000000000000000000100
+00000000000000000000000000001000 >> 2 = 00000000000000000000000000000010
+00000000000000000000000000001000 >> 3 = 00000000000000000000000000000001
+00000000000000000000000000001000 >> 4 = 00000000000000000000000000000000
+00000000000000000000000000001000 >> 8 = 00000000000000000000000000000000
+00000000000000000000000000001000 >> 16 = 00000000000000000000000000000000
+00000000000000000000000000001000 >> 24 = 00000000000000000000000000000000
+00000000000000000000000000001000 >> 31 = 00000000000000000000000000000000
+00000000000000000000000000001000 >> 32 = <<exception>>
+00000000000000000000000000001010 >> -1 = <<exception>>
+00000000000000000000000000001010 >> 0 = 00000000000000000000000000001010
+00000000000000000000000000001010 >> 1 = 00000000000000000000000000000101
+00000000000000000000000000001010 >> 2 = 00000000000000000000000000000010
+00000000000000000000000000001010 >> 3 = 00000000000000000000000000000001
+00000000000000000000000000001010 >> 4 = 00000000000000000000000000000000
+00000000000000000000000000001010 >> 8 = 00000000000000000000000000000000
+00000000000000000000000000001010 >> 16 = 00000000000000000000000000000000
+00000000000000000000000000001010 >> 24 = 00000000000000000000000000000000
+00000000000000000000000000001010 >> 31 = 00000000000000000000000000000000
+00000000000000000000000000001010 >> 32 = <<exception>>
+00000000000000000000000000010000 >> -1 = <<exception>>
+00000000000000000000000000010000 >> 0 = 00000000000000000000000000010000
+00000000000000000000000000010000 >> 1 = 00000000000000000000000000001000
+00000000000000000000000000010000 >> 2 = 00000000000000000000000000000100
+00000000000000000000000000010000 >> 3 = 00000000000000000000000000000010
+00000000000000000000000000010000 >> 4 = 00000000000000000000000000000001
+00000000000000000000000000010000 >> 8 = 00000000000000000000000000000000
+00000000000000000000000000010000 >> 16 = 00000000000000000000000000000000
+00000000000000000000000000010000 >> 24 = 00000000000000000000000000000000
+00000000000000000000000000010000 >> 31 = 00000000000000000000000000000000
+00000000000000000000000000010000 >> 32 = <<exception>>
+11111111111111111111111111111111 >> -1 = <<exception>>
+11111111111111111111111111111111 >> 0 = 11111111111111111111111111111111
+11111111111111111111111111111111 >> 1 = 01111111111111111111111111111111
+11111111111111111111111111111111 >> 2 = 00111111111111111111111111111111
+11111111111111111111111111111111 >> 3 = 00011111111111111111111111111111
+11111111111111111111111111111111 >> 4 = 00001111111111111111111111111111
+11111111111111111111111111111111 >> 8 = 00000000111111111111111111111111
+11111111111111111111111111111111 >> 16 = 00000000000000001111111111111111
+11111111111111111111111111111111 >> 24 = 00000000000000000000000011111111
+11111111111111111111111111111111 >> 31 = 00000000000000000000000000000001
+11111111111111111111111111111111 >> 32 = <<exception>>
+
+*** Test binary operation '<<' ***
+
+00000000000000000000000000000000 << -1 = <<exception>>
+00000000000000000000000000000000 << 0 = 00000000000000000000000000000000
+00000000000000000000000000000000 << 1 = 00000000000000000000000000000000
+00000000000000000000000000000000 << 2 = 00000000000000000000000000000000
+00000000000000000000000000000000 << 3 = 00000000000000000000000000000000
+00000000000000000000000000000000 << 4 = 00000000000000000000000000000000
+00000000000000000000000000000000 << 8 = 00000000000000000000000000000000
+00000000000000000000000000000000 << 16 = 00000000000000000000000000000000
+00000000000000000000000000000000 << 24 = 00000000000000000000000000000000
+00000000000000000000000000000000 << 31 = 00000000000000000000000000000000
+00000000000000000000000000000000 << 32 = <<exception>>
+00000000000000000000000000000001 << -1 = <<exception>>
+00000000000000000000000000000001 << 0 = 00000000000000000000000000000001
+00000000000000000000000000000001 << 1 = 00000000000000000000000000000010
+00000000000000000000000000000001 << 2 = 00000000000000000000000000000100
+00000000000000000000000000000001 << 3 = 00000000000000000000000000001000
+00000000000000000000000000000001 << 4 = 00000000000000000000000000010000
+00000000000000000000000000000001 << 8 = 00000000000000000000000100000000
+00000000000000000000000000000001 << 16 = 00000000000000010000000000000000
+00000000000000000000000000000001 << 24 = 00000001000000000000000000000000
+00000000000000000000000000000001 << 31 = 10000000000000000000000000000000
+00000000000000000000000000000001 << 32 = <<exception>>
+00000000000000000000000000000010 << -1 = <<exception>>
+00000000000000000000000000000010 << 0 = 00000000000000000000000000000010
+00000000000000000000000000000010 << 1 = 00000000000000000000000000000100
+00000000000000000000000000000010 << 2 = 00000000000000000000000000001000
+00000000000000000000000000000010 << 3 = 00000000000000000000000000010000
+00000000000000000000000000000010 << 4 = 00000000000000000000000000100000
+00000000000000000000000000000010 << 8 = 00000000000000000000001000000000
+00000000000000000000000000000010 << 16 = 00000000000000100000000000000000
+00000000000000000000000000000010 << 24 = 00000010000000000000000000000000
+00000000000000000000000000000010 << 31 = 00000000000000000000000000000000
+00000000000000000000000000000010 << 32 = <<exception>>
+00000000000000000000000000001000 << -1 = <<exception>>
+00000000000000000000000000001000 << 0 = 00000000000000000000000000001000
+00000000000000000000000000001000 << 1 = 00000000000000000000000000010000
+00000000000000000000000000001000 << 2 = 00000000000000000000000000100000
+00000000000000000000000000001000 << 3 = 00000000000000000000000001000000
+00000000000000000000000000001000 << 4 = 00000000000000000000000010000000
+00000000000000000000000000001000 << 8 = 00000000000000000000100000000000
+00000000000000000000000000001000 << 16 = 00000000000010000000000000000000
+00000000000000000000000000001000 << 24 = 00001000000000000000000000000000
+00000000000000000000000000001000 << 31 = 00000000000000000000000000000000
+00000000000000000000000000001000 << 32 = <<exception>>
+00000000000000000000000000001010 << -1 = <<exception>>
+00000000000000000000000000001010 << 0 = 00000000000000000000000000001010
+00000000000000000000000000001010 << 1 = 00000000000000000000000000010100
+00000000000000000000000000001010 << 2 = 00000000000000000000000000101000
+00000000000000000000000000001010 << 3 = 00000000000000000000000001010000
+00000000000000000000000000001010 << 4 = 00000000000000000000000010100000
+00000000000000000000000000001010 << 8 = 00000000000000000000101000000000
+00000000000000000000000000001010 << 16 = 00000000000010100000000000000000
+00000000000000000000000000001010 << 24 = 00001010000000000000000000000000
+00000000000000000000000000001010 << 31 = 00000000000000000000000000000000
+00000000000000000000000000001010 << 32 = <<exception>>
+00000000000000000000000000010000 << -1 = <<exception>>
+00000000000000000000000000010000 << 0 = 00000000000000000000000000010000
+00000000000000000000000000010000 << 1 = 00000000000000000000000000100000
+00000000000000000000000000010000 << 2 = 00000000000000000000000001000000
+00000000000000000000000000010000 << 3 = 00000000000000000000000010000000
+00000000000000000000000000010000 << 4 = 00000000000000000000000100000000
+00000000000000000000000000010000 << 8 = 00000000000000000001000000000000
+00000000000000000000000000010000 << 16 = 00000000000100000000000000000000
+00000000000000000000000000010000 << 24 = 00010000000000000000000000000000
+00000000000000000000000000010000 << 31 = 00000000000000000000000000000000
+00000000000000000000000000010000 << 32 = <<exception>>
+11111111111111111111111111111111 << -1 = <<exception>>
+11111111111111111111111111111111 << 0 = 11111111111111111111111111111111
+11111111111111111111111111111111 << 1 = 11111111111111111111111111111110
+11111111111111111111111111111111 << 2 = 11111111111111111111111111111100
+11111111111111111111111111111111 << 3 = 11111111111111111111111111111000
+11111111111111111111111111111111 << 4 = 11111111111111111111111111110000
+11111111111111111111111111111111 << 8 = 11111111111111111111111100000000
+11111111111111111111111111111111 << 16 = 11111111111111110000000000000000
+11111111111111111111111111111111 << 24 = 11111111000000000000000000000000
+11111111111111111111111111111111 << 31 = 10000000000000000000000000000000
+11111111111111111111111111111111 << 32 = <<exception>>
diff --git a/tests/hard_coded/uint_bitwise.m b/tests/hard_coded/uint_bitwise.m
index e69de29bb..c4c34a78b 100644
--- a/tests/hard_coded/uint_bitwise.m
+++ b/tests/hard_coded/uint_bitwise.m
@@ -0,0 +1,198 @@
+%---------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%---------------------------------------------------------------------------%
+
+% Test bitwise operations for unsigned integers.
+
+:- module uint_bitwise.
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is cc_multi.
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module int.
+:- import_module uint.
+
+:- import_module exception.
+:- import_module list.
+:- import_module require.
+:- import_module string.
+
+%---------------------------------------------------------------------------%
+
+main(!IO) :-
+    run_unop_test(uint.(\), "\\", !IO),
+    io.nl(!IO),
+    run_binop_test(uint.(/\), "/\\", !IO),
+    io.nl(!IO),
+    run_binop_test(uint.(\/), "\\/", !IO),
+    io.nl(!IO),
+    run_binop_test(uint.(xor), "xor", !IO),
+    io.nl(!IO),
+    run_shift_test(uint.(>>), ">>", !IO),
+    io.nl(!IO),
+    run_shift_test(uint.(<<), "<<", !IO).
+
+%---------------------------------------------------------------------------%
+
+:- pred run_unop_test((func(uint) = uint)::in, string::in,
+    io::di, io::uo) is cc_multi.
+
+run_unop_test(UnOpFunc, Desc, !IO) :-
+    io.format("*** Test unary operation '%s' ***\n\n", [s(Desc)], !IO),
+    As = numbers,
+    list.foldl(run_unop_test_2(UnOpFunc, Desc), As, !IO).
+
+:- pred run_unop_test_2((func(uint) = uint)::in, string::in,
+    uint::in, io::di, io::uo) is cc_multi.
+
+run_unop_test_2(UnOpFunc, Desc, A, !IO) :-
+    ( try []
+        Result0 = UnOpFunc(A)
+    then
+        ResultStr = to_binary_string_lz(Result0)
+    catch_any _ ->
+        ResultStr = "<<exception>>"
+    ),
+    io.format("%s %s = %s\n",
+        [s(Desc), s(to_binary_string_lz(A)), s(ResultStr)], !IO).
+
+%---------------------------------------------------------------------------%
+
+:- pred run_binop_test((func(uint, uint) = uint)::in, string::in,
+    io::di, io::uo) is cc_multi.
+
+run_binop_test(BinOpFunc, Desc, !IO) :-
+    io.format("*** Test binary operation '%s' ***\n\n", [s(Desc)], !IO),
+    As = numbers,
+    Bs = numbers,
+    list.foldl(run_binop_test_2(BinOpFunc, Desc, Bs), As, !IO).
+
+:- pred run_binop_test_2((func(uint, uint) = uint)::in, string::in,
+    list(uint)::in, uint::in, io::di, io::uo) is cc_multi.
+
+run_binop_test_2(BinOpFunc, Desc, Bs, A, !IO) :-
+    list.foldl(run_binop_test_3(BinOpFunc, Desc, A), Bs, !IO).
+
+:- pred run_binop_test_3((func(uint, uint) = uint)::in, string::in,
+    uint::in, uint::in, io::di, io::uo) is cc_multi.
+
+run_binop_test_3(BinOpFunc, Desc, A, B, !IO) :-
+    ( try []
+        Result0 = BinOpFunc(A, B)
+    then
+        ResultStr = to_binary_string_lz(Result0)
+    catch_any _ ->
+        ResultStr = "<<exception>>"
+    ),
+    io.format("%s %s %s = %s\n",
+        [s(to_binary_string_lz(A)), s(Desc),
+        s(to_binary_string_lz(B)), s(ResultStr)], !IO).
+
+%---------------------------------------------------------------------------%
+
+:- pred run_shift_test((func(uint, int) = uint)::in, string::in,
+    io::di, io::uo) is cc_multi.
+
+run_shift_test(ShiftOpFunc, Desc, !IO) :-
+    io.format("*** Test binary operation '%s' ***\n\n", [s(Desc)], !IO),
+    As = numbers,
+    Bs = shift_amounts,
+    list.foldl(run_shift_test_2(ShiftOpFunc, Desc, Bs), As, !IO).
+
+:- pred run_shift_test_2((func(uint, int) = uint)::in, string::in,
+    list(int)::in, uint::in, io::di, io::uo) is cc_multi.
+
+run_shift_test_2(ShiftOpFunc, Desc, Bs, A, !IO) :-
+    list.foldl(run_shift_test_3(ShiftOpFunc, Desc, A), Bs, !IO).
+
+:- pred run_shift_test_3((func(uint, int) = uint)::in, string::in,
+    uint::in, int::in, io::di, io::uo) is cc_multi.
+
+run_shift_test_3(ShiftOpFunc, Desc, A, B, !IO) :-
+    ( try []
+        Result0 = ShiftOpFunc(A, B)
+    then
+        ResultStr = to_binary_string_lz(Result0)
+    catch_any _ ->
+        ResultStr = "<<exception>>"
+    ),
+    io.format("%s %s %d = %s\n",
+        [s(to_binary_string_lz(A)), s(Desc), i(B), s(ResultStr)], !IO).
+
+%---------------------------------------------------------------------------%
+
+:- func numbers = list(uint).
+
+numbers = [
+    0u,
+    1u,
+    2u,
+    8u,
+    10u,
+    16u,
+    max_uint
+].
+
+:- func shift_amounts = list(int).
+
+shift_amounts = [
+    -1,
+    0,
+    1,
+    2,
+    3,
+    4,
+    8,
+    16,
+    24,
+    bits_per_uint - 1,
+    bits_per_uint
+].
+
+%---------------------------------------------------------------------------%
+
+:- func to_binary_string_lz(uint::in) = (string::uo) is det.
+
+:- pragma foreign_proc("C",
+    to_binary_string_lz(U::in) = (S::uo),
+    [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail],
+"
+    int i = ML_BITS_PER_UINT;
+
+    MR_allocate_aligned_string_msg(S, ML_BITS_PER_UINT, MR_ALLOC_ID);
+    S[ML_BITS_PER_UINT] = '\\0';
+    while (i >= 0) {
+        i--;
+        S[i] = (U & 1) ? '1' : '0';
+        U = U >> 1;
+    }
+").
+
+:- pragma foreign_proc("C#",
+    to_binary_string_lz(U::in) = (S::uo),
+    [will_not_call_mercury, promise_pure, thread_safe],
+"
+    S = System.Convert.ToString(U, 2).PadLeft(32, '0');
+").
+
+:- pragma foreign_proc("Java",
+    to_binary_string_lz(U::in) = (S::uo),
+    [will_not_call_mercury, promise_pure, thread_safe],
+"
+    S = java.lang.String.format(""%32s"",
+        java.lang.Integer.toBinaryString(U)).replace(' ', '0');
+").
+
+to_binary_string_lz(_) = _ :-
+    sorry($file, $pred, "to_binary_string_lz for Erlang backend").
+
+%---------------------------------------------------------------------------%
+:- end_module uint_bitwise.
+%---------------------------------------------------------------------------%


More information about the reviews mailing list