[m-rev.] for review: change the semantics of the int shift operations
Julien Fischer
jfischer at opturion.com
Tue Aug 29 00:43:00 AEST 2017
For review by anyone.
------------------------
Change the semantics of the int shift operations.
Change int.(<<) and int.(>>) to throw an exception if their second operand is
not in [0, bits_per_int). This brings them into line with the other integer
types.
As a transitional measure, add new functions that provide the old semantics.
library/int.m:
As above.
NEWS:
Announce the above change.
Include the fixed size integer types in the list of reserved type names.
tests/hard_coded/shift_test.m:
Call the legacy versions of the int shift operations.
tests/hard_coded/bitwise_int.{m,exp}:
A new test of bitwise operations for the int type.
(XXX I will add a 32-bit expected output separately.)
tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
Include the new test case.
Do not warn about the use of the obsolete legacy shift operations.
Julien.
diff --git a/NEWS b/NEWS
index 8ed1768ec..43c00d7cf 100644
--- a/NEWS
+++ b/NEWS
@@ -44,7 +44,9 @@ Changes that may break compatibility:
type names are:
int
+ int{8,16,32}
uint
+ uint{8,16,32}
float
character
string
@@ -105,6 +107,12 @@ Changes that may break compatibility:
the term or lexer modules may use the `old_term_parser' library in the
extras instead.
+* We have changed the semantics of int.(<<) and int.(>>) so that they throw
+ an exception if their second operand is not in [0, bits_per_int). For now,
+ the old behaviour of these operations is provided by the functions
+ int.legacy_left_shift/2 and int.legacy_right_shift/2. These functions
+ will be deleted in a future release.
+
Changes to the Mercury language:
* We have added a new primitive type, uint, which is an unsigned integer type
diff --git a/library/int.m b/library/int.m
index 72441dc51..19927599e 100644
--- a/library/int.m
+++ b/library/int.m
@@ -178,11 +178,20 @@
% Left shift.
% X << Y returns X "left shifted" by Y bits.
- % To be precise, if Y is negative, the result is
- % X div (2^(-Y)), otherwise the result is X * (2^Y).
+ % The bit positions vacated by the shift are filled by zeros.
+ % Throws an exception if Y is not in [0, bits_per_int).
%
:- func (int::in) << (int::in) = (int::uo) is det.
+ % legacy_left_shift(X, Y) returns X "left shifted" by Y bits.
+ % To be precise, if Y is negative, the result is X div (2^(-Y)), otherwise
+ % the result is X * (2^Y).
+ %
+ % NOTE: this function is deprecated and may be removed in a future release.
+ %
+:- pragma obsolete(legacy_left_shift/2).
+:- func legacy_left_shift(int::in, int::in) = (int::uo) is det.
+
% unchecked_left_shift(X, Y) is the same as X << Y
% except that the behaviour is undefined if Y is negative,
% or greater than or equal to the result of `bits_per_int/1'.
@@ -191,12 +200,19 @@
:- func unchecked_left_shift(int::in, int::in) = (int::uo) is det.
% Right shift.
- % X >> Y returns X "arithmetic right shifted" by Y bits.
- % To be precise, if Y is negative, the result is
- % X * (2^(-Y)), otherwise the result is X div (2^Y).
+ % X >> Y returns X "right shifted" by Y bits.
+ % The bit positions vacated by the shift are filled by the sign bit.
+ % Throws an exception if Y is not in [0, bits_per_int).
%
:- func (int::in) >> (int::in) = (int::uo) is det.
+ % legacy_right_shift(X, Y) returns X "arithmetic right shifted" by Y bits.
+ % To be precise, if Y is negative, the result is X * (2^(-Y)), otherwise
+ % the result is X div (2^Y).
+ %
+:- pragma obsolete(legacy_right_shift/2).
+:- func legacy_right_shift(int::in, int::in) = (int::uo) is det.
+
% unchecked_right_shift(X, Y) is the same as X >> Y
% except that the behaviour is undefined if Y is negative,
% or greater than or equal to the result of `bits_per_int/1'.
@@ -698,6 +714,14 @@ log2_loop(CurX, CurLogXSoFar, CeilLogX) :-
%---------------------------------------------------------------------------%
X << Y = Z :-
+ ( if Y `unsigned_lt` bits_per_int then
+ Z = unchecked_left_shift(X, Y)
+ else
+ Msg = "int.(<<): second operand is out of range",
+ throw(math.domain_error(Msg))
+ ).
+
+legacy_left_shift(X, Y) = Z :-
bits_per_int(IntBits),
( if Y >= 0 then
( if Y >= IntBits then
@@ -714,6 +738,14 @@ X << Y = Z :-
).
X >> Y = Z :-
+ ( if Y `unsigned_lt` bits_per_int then
+ Z = unchecked_right_shift(X, Y)
+ else
+ Msg = "int.(<<): second operand is out of range",
+ throw(math.domain_error(Msg))
+ ).
+
+legacy_right_shift(X, Y) = Z :-
% Note: this assumes two's complement arithmetic.
% tests/hard_coded/shift_test.m will fail if this is not the case.
bits_per_int(IntBits),
@@ -731,6 +763,36 @@ X >> Y = Z :-
)
).
+% We define unsigned less than as a foreign_proc here in order to avoid this
+% module having to import uint.
+% XXX we should probably provide unsigned_lt as a builtin for ints.
+%
+:- pred unsigned_lt(int::in, int::in) is semidet.
+:- pragma foreign_proc("C",
+ unsigned_lt(A::in, B::in),
+ [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail],
+"
+ SUCCESS_INDICATOR = (MR_Unsigned)A < (MR_Unsigned)B;
+").
+
+:- pragma foreign_proc("C#",
+ unsigned_lt(A::in, B::in),
+ [will_not_call_mercury, promise_pure, thread_safe],
+"
+ SUCCESS_INDICATOR = (uint)A < (uint)B;
+").
+
+:- pragma foreign_proc("Java",
+ unsigned_lt(A::in, B::in),
+ [will_not_call_mercury, promise_pure, thread_safe],
+"
+ SUCCESS_INDICATOR = (A & 0xffffffffL) < (B & 0xffffffffL);
+").
+
+:- pragma no_determinism_warning(unsigned_lt/2).
+unsigned_lt(_, _) :-
+ sorry($module, "int.unsigned_lt/2 NYI for Erlang").
+
%---------------------------------------------------------------------------%
% is/2 is replaced with `=' in the parser, but the following is useful
diff --git a/tests/hard_coded/Mercury.options b/tests/hard_coded/Mercury.options
index df6dbe552..bb093d950 100644
--- a/tests/hard_coded/Mercury.options
+++ b/tests/hard_coded/Mercury.options
@@ -67,6 +67,7 @@ MCFLAGS-pack_args_reuse = --structure-reuse
MCFLAGS-reuse_double = --ctgc
MCFLAGS-reuse_ho = --ctgc --no-optimise-higher-order
MCFLAGS-sharing_comb = --ctgc --structure-sharing-widening 2
+MCFLAGS-shift_test = --no-warn-obsolete
MCFLAGS-simplify_multi_arm_switch = -O3
MCFLAGS-spawn_native = --no-ansi-c
MCFLAGS-string_substring = --no-warn-obsolete
diff --git a/tests/hard_coded/Mmakefile b/tests/hard_coded/Mmakefile
index 700c6c543..4524cc959 100644
--- a/tests/hard_coded/Mmakefile
+++ b/tests/hard_coded/Mmakefile
@@ -626,6 +626,7 @@ ifeq "$(findstring profdeep,$(GRADE))" ""
arith_uint8 \
bitmap_empty \
bitmap_test \
+ bitwise_int \
bitwise_int16 \
bitwise_int32 \
bitwise_int8 \
diff --git a/tests/hard_coded/bitwise_int.exp b/tests/hard_coded/bitwise_int.exp
index e69de29bb..cb90f68be 100644
--- a/tests/hard_coded/bitwise_int.exp
+++ b/tests/hard_coded/bitwise_int.exp
@@ -0,0 +1,1337 @@
+*** Test unary operation '\' ***
+
+\ 1000000000000000000000000000000000000000000000000000000000000000 =
+ 0111111111111111111111111111111111111111111111111111111111111111
+
+\ 0000000000000000000000000000000000000000000000000000000000000000 =
+ 1111111111111111111111111111111111111111111111111111111111111111
+
+\ 0000000000000000000000000000000000000000000000000000000000000001 =
+ 1111111111111111111111111111111111111111111111111111111111111110
+
+\ 0000000000000000000000000000000000000000000000000000000000000010 =
+ 1111111111111111111111111111111111111111111111111111111111111101
+
+\ 0000000000000000000000000000000000000000000000000000000000001000 =
+ 1111111111111111111111111111111111111111111111111111111111110111
+
+\ 0000000000000000000000000000000000000000000000000000000000001010 =
+ 1111111111111111111111111111111111111111111111111111111111110101
+
+\ 0000000000000000000000000000000000000000000000000000000000010000 =
+ 1111111111111111111111111111111111111111111111111111111111101111
+
+\ 0111111111111111111111111111111111111111111111111111111111111111 =
+ 1000000000000000000000000000000000000000000000000000000000000000
+
+
+*** Test binary operation '/\' ***
+
+1000000000000000000000000000000000000000000000000000000000000000 /\
+1000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 /\
+0000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 /\
+0000000000000000000000000000000000000000000000000000000000000001 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 /\
+0000000000000000000000000000000000000000000000000000000000000010 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 /\
+0000000000000000000000000000000000000000000000000000000000001000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 /\
+0000000000000000000000000000000000000000000000000000000000001010 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 /\
+0000000000000000000000000000000000000000000000000000000000010000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 /\
+0111111111111111111111111111111111111111111111111111111111111111 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000000 /\
+1000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000000 /\
+0000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000000 /\
+0000000000000000000000000000000000000000000000000000000000000001 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000000 /\
+0000000000000000000000000000000000000000000000000000000000000010 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000000 /\
+0000000000000000000000000000000000000000000000000000000000001000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000000 /\
+0000000000000000000000000000000000000000000000000000000000001010 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000000 /\
+0000000000000000000000000000000000000000000000000000000000010000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000000 /\
+0111111111111111111111111111111111111111111111111111111111111111 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000001 /\
+1000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000001 /\
+0000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000001 /\
+0000000000000000000000000000000000000000000000000000000000000001 =
+0000000000000000000000000000000000000000000000000000000000000001
+
+0000000000000000000000000000000000000000000000000000000000000001 /\
+0000000000000000000000000000000000000000000000000000000000000010 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000001 /\
+0000000000000000000000000000000000000000000000000000000000001000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000001 /\
+0000000000000000000000000000000000000000000000000000000000001010 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000001 /\
+0000000000000000000000000000000000000000000000000000000000010000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000001 /\
+0111111111111111111111111111111111111111111111111111111111111111 =
+0000000000000000000000000000000000000000000000000000000000000001
+
+0000000000000000000000000000000000000000000000000000000000000010 /\
+1000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000010 /\
+0000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000010 /\
+0000000000000000000000000000000000000000000000000000000000000001 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000010 /\
+0000000000000000000000000000000000000000000000000000000000000010 =
+0000000000000000000000000000000000000000000000000000000000000010
+
+0000000000000000000000000000000000000000000000000000000000000010 /\
+0000000000000000000000000000000000000000000000000000000000001000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000010 /\
+0000000000000000000000000000000000000000000000000000000000001010 =
+0000000000000000000000000000000000000000000000000000000000000010
+
+0000000000000000000000000000000000000000000000000000000000000010 /\
+0000000000000000000000000000000000000000000000000000000000010000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000010 /\
+0111111111111111111111111111111111111111111111111111111111111111 =
+0000000000000000000000000000000000000000000000000000000000000010
+
+0000000000000000000000000000000000000000000000000000000000001000 /\
+1000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000001000 /\
+0000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000001000 /\
+0000000000000000000000000000000000000000000000000000000000000001 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000001000 /\
+0000000000000000000000000000000000000000000000000000000000000010 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000001000 /\
+0000000000000000000000000000000000000000000000000000000000001000 =
+0000000000000000000000000000000000000000000000000000000000001000
+
+0000000000000000000000000000000000000000000000000000000000001000 /\
+0000000000000000000000000000000000000000000000000000000000001010 =
+0000000000000000000000000000000000000000000000000000000000001000
+
+0000000000000000000000000000000000000000000000000000000000001000 /\
+0000000000000000000000000000000000000000000000000000000000010000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000001000 /\
+0111111111111111111111111111111111111111111111111111111111111111 =
+0000000000000000000000000000000000000000000000000000000000001000
+
+0000000000000000000000000000000000000000000000000000000000001010 /\
+1000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000001010 /\
+0000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000001010 /\
+0000000000000000000000000000000000000000000000000000000000000001 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000001010 /\
+0000000000000000000000000000000000000000000000000000000000000010 =
+0000000000000000000000000000000000000000000000000000000000000010
+
+0000000000000000000000000000000000000000000000000000000000001010 /\
+0000000000000000000000000000000000000000000000000000000000001000 =
+0000000000000000000000000000000000000000000000000000000000001000
+
+0000000000000000000000000000000000000000000000000000000000001010 /\
+0000000000000000000000000000000000000000000000000000000000001010 =
+0000000000000000000000000000000000000000000000000000000000001010
+
+0000000000000000000000000000000000000000000000000000000000001010 /\
+0000000000000000000000000000000000000000000000000000000000010000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000001010 /\
+0111111111111111111111111111111111111111111111111111111111111111 =
+0000000000000000000000000000000000000000000000000000000000001010
+
+0000000000000000000000000000000000000000000000000000000000010000 /\
+1000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000010000 /\
+0000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000010000 /\
+0000000000000000000000000000000000000000000000000000000000000001 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000010000 /\
+0000000000000000000000000000000000000000000000000000000000000010 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000010000 /\
+0000000000000000000000000000000000000000000000000000000000001000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000010000 /\
+0000000000000000000000000000000000000000000000000000000000001010 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000010000 /\
+0000000000000000000000000000000000000000000000000000000000010000 =
+0000000000000000000000000000000000000000000000000000000000010000
+
+0000000000000000000000000000000000000000000000000000000000010000 /\
+0111111111111111111111111111111111111111111111111111111111111111 =
+0000000000000000000000000000000000000000000000000000000000010000
+
+0111111111111111111111111111111111111111111111111111111111111111 /\
+1000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0111111111111111111111111111111111111111111111111111111111111111 /\
+0000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0111111111111111111111111111111111111111111111111111111111111111 /\
+0000000000000000000000000000000000000000000000000000000000000001 =
+0000000000000000000000000000000000000000000000000000000000000001
+
+0111111111111111111111111111111111111111111111111111111111111111 /\
+0000000000000000000000000000000000000000000000000000000000000010 =
+0000000000000000000000000000000000000000000000000000000000000010
+
+0111111111111111111111111111111111111111111111111111111111111111 /\
+0000000000000000000000000000000000000000000000000000000000001000 =
+0000000000000000000000000000000000000000000000000000000000001000
+
+0111111111111111111111111111111111111111111111111111111111111111 /\
+0000000000000000000000000000000000000000000000000000000000001010 =
+0000000000000000000000000000000000000000000000000000000000001010
+
+0111111111111111111111111111111111111111111111111111111111111111 /\
+0000000000000000000000000000000000000000000000000000000000010000 =
+0000000000000000000000000000000000000000000000000000000000010000
+
+0111111111111111111111111111111111111111111111111111111111111111 /\
+0111111111111111111111111111111111111111111111111111111111111111 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+
+*** Test binary operation '\/' ***
+
+1000000000000000000000000000000000000000000000000000000000000000 \/
+1000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 \/
+0000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 \/
+0000000000000000000000000000000000000000000000000000000000000001 =
+1000000000000000000000000000000000000000000000000000000000000001
+
+1000000000000000000000000000000000000000000000000000000000000000 \/
+0000000000000000000000000000000000000000000000000000000000000010 =
+1000000000000000000000000000000000000000000000000000000000000010
+
+1000000000000000000000000000000000000000000000000000000000000000 \/
+0000000000000000000000000000000000000000000000000000000000001000 =
+1000000000000000000000000000000000000000000000000000000000001000
+
+1000000000000000000000000000000000000000000000000000000000000000 \/
+0000000000000000000000000000000000000000000000000000000000001010 =
+1000000000000000000000000000000000000000000000000000000000001010
+
+1000000000000000000000000000000000000000000000000000000000000000 \/
+0000000000000000000000000000000000000000000000000000000000010000 =
+1000000000000000000000000000000000000000000000000000000000010000
+
+1000000000000000000000000000000000000000000000000000000000000000 \/
+0111111111111111111111111111111111111111111111111111111111111111 =
+1111111111111111111111111111111111111111111111111111111111111111
+
+0000000000000000000000000000000000000000000000000000000000000000 \/
+1000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000000 \/
+0000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0000000000000000000000000000000000000000000000000000000000000000 \/
+0000000000000000000000000000000000000000000000000000000000000001 =
+0000000000000000000000000000000000000000000000000000000000000001
+
+0000000000000000000000000000000000000000000000000000000000000000 \/
+0000000000000000000000000000000000000000000000000000000000000010 =
+0000000000000000000000000000000000000000000000000000000000000010
+
+0000000000000000000000000000000000000000000000000000000000000000 \/
+0000000000000000000000000000000000000000000000000000000000001000 =
+0000000000000000000000000000000000000000000000000000000000001000
+
+0000000000000000000000000000000000000000000000000000000000000000 \/
+0000000000000000000000000000000000000000000000000000000000001010 =
+0000000000000000000000000000000000000000000000000000000000001010
+
+0000000000000000000000000000000000000000000000000000000000000000 \/
+0000000000000000000000000000000000000000000000000000000000010000 =
+0000000000000000000000000000000000000000000000000000000000010000
+
+0000000000000000000000000000000000000000000000000000000000000000 \/
+0111111111111111111111111111111111111111111111111111111111111111 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0000000000000000000000000000000000000000000000000000000000000001 \/
+1000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000000001
+
+0000000000000000000000000000000000000000000000000000000000000001 \/
+0000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000001
+
+0000000000000000000000000000000000000000000000000000000000000001 \/
+0000000000000000000000000000000000000000000000000000000000000001 =
+0000000000000000000000000000000000000000000000000000000000000001
+
+0000000000000000000000000000000000000000000000000000000000000001 \/
+0000000000000000000000000000000000000000000000000000000000000010 =
+0000000000000000000000000000000000000000000000000000000000000011
+
+0000000000000000000000000000000000000000000000000000000000000001 \/
+0000000000000000000000000000000000000000000000000000000000001000 =
+0000000000000000000000000000000000000000000000000000000000001001
+
+0000000000000000000000000000000000000000000000000000000000000001 \/
+0000000000000000000000000000000000000000000000000000000000001010 =
+0000000000000000000000000000000000000000000000000000000000001011
+
+0000000000000000000000000000000000000000000000000000000000000001 \/
+0000000000000000000000000000000000000000000000000000000000010000 =
+0000000000000000000000000000000000000000000000000000000000010001
+
+0000000000000000000000000000000000000000000000000000000000000001 \/
+0111111111111111111111111111111111111111111111111111111111111111 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0000000000000000000000000000000000000000000000000000000000000010 \/
+1000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000000010
+
+0000000000000000000000000000000000000000000000000000000000000010 \/
+0000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000010
+
+0000000000000000000000000000000000000000000000000000000000000010 \/
+0000000000000000000000000000000000000000000000000000000000000001 =
+0000000000000000000000000000000000000000000000000000000000000011
+
+0000000000000000000000000000000000000000000000000000000000000010 \/
+0000000000000000000000000000000000000000000000000000000000000010 =
+0000000000000000000000000000000000000000000000000000000000000010
+
+0000000000000000000000000000000000000000000000000000000000000010 \/
+0000000000000000000000000000000000000000000000000000000000001000 =
+0000000000000000000000000000000000000000000000000000000000001010
+
+0000000000000000000000000000000000000000000000000000000000000010 \/
+0000000000000000000000000000000000000000000000000000000000001010 =
+0000000000000000000000000000000000000000000000000000000000001010
+
+0000000000000000000000000000000000000000000000000000000000000010 \/
+0000000000000000000000000000000000000000000000000000000000010000 =
+0000000000000000000000000000000000000000000000000000000000010010
+
+0000000000000000000000000000000000000000000000000000000000000010 \/
+0111111111111111111111111111111111111111111111111111111111111111 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0000000000000000000000000000000000000000000000000000000000001000 \/
+1000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000001000
+
+0000000000000000000000000000000000000000000000000000000000001000 \/
+0000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000001000
+
+0000000000000000000000000000000000000000000000000000000000001000 \/
+0000000000000000000000000000000000000000000000000000000000000001 =
+0000000000000000000000000000000000000000000000000000000000001001
+
+0000000000000000000000000000000000000000000000000000000000001000 \/
+0000000000000000000000000000000000000000000000000000000000000010 =
+0000000000000000000000000000000000000000000000000000000000001010
+
+0000000000000000000000000000000000000000000000000000000000001000 \/
+0000000000000000000000000000000000000000000000000000000000001000 =
+0000000000000000000000000000000000000000000000000000000000001000
+
+0000000000000000000000000000000000000000000000000000000000001000 \/
+0000000000000000000000000000000000000000000000000000000000001010 =
+0000000000000000000000000000000000000000000000000000000000001010
+
+0000000000000000000000000000000000000000000000000000000000001000 \/
+0000000000000000000000000000000000000000000000000000000000010000 =
+0000000000000000000000000000000000000000000000000000000000011000
+
+0000000000000000000000000000000000000000000000000000000000001000 \/
+0111111111111111111111111111111111111111111111111111111111111111 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0000000000000000000000000000000000000000000000000000000000001010 \/
+1000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000001010
+
+0000000000000000000000000000000000000000000000000000000000001010 \/
+0000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000001010
+
+0000000000000000000000000000000000000000000000000000000000001010 \/
+0000000000000000000000000000000000000000000000000000000000000001 =
+0000000000000000000000000000000000000000000000000000000000001011
+
+0000000000000000000000000000000000000000000000000000000000001010 \/
+0000000000000000000000000000000000000000000000000000000000000010 =
+0000000000000000000000000000000000000000000000000000000000001010
+
+0000000000000000000000000000000000000000000000000000000000001010 \/
+0000000000000000000000000000000000000000000000000000000000001000 =
+0000000000000000000000000000000000000000000000000000000000001010
+
+0000000000000000000000000000000000000000000000000000000000001010 \/
+0000000000000000000000000000000000000000000000000000000000001010 =
+0000000000000000000000000000000000000000000000000000000000001010
+
+0000000000000000000000000000000000000000000000000000000000001010 \/
+0000000000000000000000000000000000000000000000000000000000010000 =
+0000000000000000000000000000000000000000000000000000000000011010
+
+0000000000000000000000000000000000000000000000000000000000001010 \/
+0111111111111111111111111111111111111111111111111111111111111111 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0000000000000000000000000000000000000000000000000000000000010000 \/
+1000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000010000
+
+0000000000000000000000000000000000000000000000000000000000010000 \/
+0000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000010000
+
+0000000000000000000000000000000000000000000000000000000000010000 \/
+0000000000000000000000000000000000000000000000000000000000000001 =
+0000000000000000000000000000000000000000000000000000000000010001
+
+0000000000000000000000000000000000000000000000000000000000010000 \/
+0000000000000000000000000000000000000000000000000000000000000010 =
+0000000000000000000000000000000000000000000000000000000000010010
+
+0000000000000000000000000000000000000000000000000000000000010000 \/
+0000000000000000000000000000000000000000000000000000000000001000 =
+0000000000000000000000000000000000000000000000000000000000011000
+
+0000000000000000000000000000000000000000000000000000000000010000 \/
+0000000000000000000000000000000000000000000000000000000000001010 =
+0000000000000000000000000000000000000000000000000000000000011010
+
+0000000000000000000000000000000000000000000000000000000000010000 \/
+0000000000000000000000000000000000000000000000000000000000010000 =
+0000000000000000000000000000000000000000000000000000000000010000
+
+0000000000000000000000000000000000000000000000000000000000010000 \/
+0111111111111111111111111111111111111111111111111111111111111111 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 \/
+1000000000000000000000000000000000000000000000000000000000000000 =
+1111111111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 \/
+0000000000000000000000000000000000000000000000000000000000000000 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 \/
+0000000000000000000000000000000000000000000000000000000000000001 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 \/
+0000000000000000000000000000000000000000000000000000000000000010 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 \/
+0000000000000000000000000000000000000000000000000000000000001000 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 \/
+0000000000000000000000000000000000000000000000000000000000001010 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 \/
+0000000000000000000000000000000000000000000000000000000000010000 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 \/
+0111111111111111111111111111111111111111111111111111111111111111 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+
+*** Test binary operation 'xor' ***
+
+1000000000000000000000000000000000000000000000000000000000000000 xor
+1000000000000000000000000000000000000000000000000000000000000000 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 xor
+0000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 xor
+0000000000000000000000000000000000000000000000000000000000000001 =
+1000000000000000000000000000000000000000000000000000000000000001
+
+1000000000000000000000000000000000000000000000000000000000000000 xor
+0000000000000000000000000000000000000000000000000000000000000010 =
+1000000000000000000000000000000000000000000000000000000000000010
+
+1000000000000000000000000000000000000000000000000000000000000000 xor
+0000000000000000000000000000000000000000000000000000000000001000 =
+1000000000000000000000000000000000000000000000000000000000001000
+
+1000000000000000000000000000000000000000000000000000000000000000 xor
+0000000000000000000000000000000000000000000000000000000000001010 =
+1000000000000000000000000000000000000000000000000000000000001010
+
+1000000000000000000000000000000000000000000000000000000000000000 xor
+0000000000000000000000000000000000000000000000000000000000010000 =
+1000000000000000000000000000000000000000000000000000000000010000
+
+1000000000000000000000000000000000000000000000000000000000000000 xor
+0111111111111111111111111111111111111111111111111111111111111111 =
+1111111111111111111111111111111111111111111111111111111111111111
+
+0000000000000000000000000000000000000000000000000000000000000000 xor
+1000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000000000
+
+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
+0111111111111111111111111111111111111111111111111111111111111111 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0000000000000000000000000000000000000000000000000000000000000001 xor
+1000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000000001
+
+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
+0111111111111111111111111111111111111111111111111111111111111111 =
+0111111111111111111111111111111111111111111111111111111111111110
+
+0000000000000000000000000000000000000000000000000000000000000010 xor
+1000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000000010
+
+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
+0111111111111111111111111111111111111111111111111111111111111111 =
+0111111111111111111111111111111111111111111111111111111111111101
+
+0000000000000000000000000000000000000000000000000000000000001000 xor
+1000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000001000
+
+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
+0111111111111111111111111111111111111111111111111111111111111111 =
+0111111111111111111111111111111111111111111111111111111111110111
+
+0000000000000000000000000000000000000000000000000000000000001010 xor
+1000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000001010
+
+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
+0111111111111111111111111111111111111111111111111111111111111111 =
+0111111111111111111111111111111111111111111111111111111111110101
+
+0000000000000000000000000000000000000000000000000000000000010000 xor
+1000000000000000000000000000000000000000000000000000000000000000 =
+1000000000000000000000000000000000000000000000000000000000010000
+
+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
+0111111111111111111111111111111111111111111111111111111111111111 =
+0111111111111111111111111111111111111111111111111111111111101111
+
+0111111111111111111111111111111111111111111111111111111111111111 xor
+1000000000000000000000000000000000000000000000000000000000000000 =
+1111111111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 xor
+0000000000000000000000000000000000000000000000000000000000000000 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 xor
+0000000000000000000000000000000000000000000000000000000000000001 =
+0111111111111111111111111111111111111111111111111111111111111110
+
+0111111111111111111111111111111111111111111111111111111111111111 xor
+0000000000000000000000000000000000000000000000000000000000000010 =
+0111111111111111111111111111111111111111111111111111111111111101
+
+0111111111111111111111111111111111111111111111111111111111111111 xor
+0000000000000000000000000000000000000000000000000000000000001000 =
+0111111111111111111111111111111111111111111111111111111111110111
+
+0111111111111111111111111111111111111111111111111111111111111111 xor
+0000000000000000000000000000000000000000000000000000000000001010 =
+0111111111111111111111111111111111111111111111111111111111110101
+
+0111111111111111111111111111111111111111111111111111111111111111 xor
+0000000000000000000000000000000000000000000000000000000000010000 =
+0111111111111111111111111111111111111111111111111111111111101111
+
+0111111111111111111111111111111111111111111111111111111111111111 xor
+0111111111111111111111111111111111111111111111111111111111111111 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+
+*** Test binary operation '>>' ***
+
+1000000000000000000000000000000000000000000000000000000000000000 >> -1 =
+<<exception>>
+
+1000000000000000000000000000000000000000000000000000000000000000 >> 0 =
+1000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 >> 1 =
+1100000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 >> 2 =
+1110000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 >> 3 =
+1111000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 >> 4 =
+1111100000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 >> 8 =
+1111111110000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 >> 16 =
+1111111111111111100000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 >> 24 =
+1111111111111111111111111000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 >> 63 =
+1111111111111111111111111111111111111111111111111111111111111111
+
+1000000000000000000000000000000000000000000000000000000000000000 >> 64 =
+<<exception>>
+
+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>>
+
+0111111111111111111111111111111111111111111111111111111111111111 >> -1 =
+<<exception>>
+
+0111111111111111111111111111111111111111111111111111111111111111 >> 0 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 >> 1 =
+0011111111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 >> 2 =
+0001111111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 >> 3 =
+0000111111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 >> 4 =
+0000011111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 >> 8 =
+0000000001111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 >> 16 =
+0000000000000000011111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 >> 24 =
+0000000000000000000000000111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 >> 63 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+0111111111111111111111111111111111111111111111111111111111111111 >> 64 =
+<<exception>>
+
+
+*** Test binary operation '<<' ***
+
+1000000000000000000000000000000000000000000000000000000000000000 << -1 =
+<<exception>>
+
+1000000000000000000000000000000000000000000000000000000000000000 << 0 =
+1000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 << 1 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 << 2 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 << 3 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 << 4 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 << 8 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 << 16 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 << 24 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 << 63 =
+0000000000000000000000000000000000000000000000000000000000000000
+
+1000000000000000000000000000000000000000000000000000000000000000 << 64 =
+<<exception>>
+
+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>>
+
+0111111111111111111111111111111111111111111111111111111111111111 << -1 =
+<<exception>>
+
+0111111111111111111111111111111111111111111111111111111111111111 << 0 =
+0111111111111111111111111111111111111111111111111111111111111111
+
+0111111111111111111111111111111111111111111111111111111111111111 << 1 =
+1111111111111111111111111111111111111111111111111111111111111110
+
+0111111111111111111111111111111111111111111111111111111111111111 << 2 =
+1111111111111111111111111111111111111111111111111111111111111100
+
+0111111111111111111111111111111111111111111111111111111111111111 << 3 =
+1111111111111111111111111111111111111111111111111111111111111000
+
+0111111111111111111111111111111111111111111111111111111111111111 << 4 =
+1111111111111111111111111111111111111111111111111111111111110000
+
+0111111111111111111111111111111111111111111111111111111111111111 << 8 =
+1111111111111111111111111111111111111111111111111111111100000000
+
+0111111111111111111111111111111111111111111111111111111111111111 << 16 =
+1111111111111111111111111111111111111111111111110000000000000000
+
+0111111111111111111111111111111111111111111111111111111111111111 << 24 =
+1111111111111111111111111111111111111111000000000000000000000000
+
+0111111111111111111111111111111111111111111111111111111111111111 << 63 =
+1000000000000000000000000000000000000000000000000000000000000000
+
+0111111111111111111111111111111111111111111111111111111111111111 << 64 =
+<<exception>>
+
diff --git a/tests/hard_coded/bitwise_int.m b/tests/hard_coded/bitwise_int.m
index e69de29bb..660289d52 100644
--- a/tests/hard_coded/bitwise_int.m
+++ b/tests/hard_coded/bitwise_int.m
@@ -0,0 +1,208 @@
+%---------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%---------------------------------------------------------------------------%
+
+% Test bitwise operations for signed integers.
+
+:- module bitwise_int.
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is cc_multi.
+
+%---------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module int.
+
+:- import_module exception.
+:- import_module list.
+:- import_module require.
+:- import_module string.
+
+:- pragma foreign_import_module("C", int). % For ML_BITS_PER_INT.
+
+%---------------------------------------------------------------------------%
+
+main(!IO) :-
+ run_unop_test(int.(\), "\\", !IO),
+ io.nl(!IO),
+ run_binop_test(int.(/\), "/\\", !IO),
+ io.nl(!IO),
+ run_binop_test(int.(\/), "\\/", !IO),
+ io.nl(!IO),
+ run_binop_test(int_xor_proxy, "xor", !IO),
+ io.nl(!IO),
+ run_shift_test(int.(>>), ">>", !IO),
+ io.nl(!IO),
+ run_shift_test(int.(<<), "<<", !IO).
+
+:- func int_xor_proxy(int, int) = int.
+
+int_xor_proxy(A, B) = int.xor(A, B).
+
+%---------------------------------------------------------------------------%
+
+:- pred run_unop_test((func(int) = int)::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(int) = int)::in, string::in,
+ int::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 =\n %s\n",
+ [s(Desc), s(to_binary_string_lz(A)), s(ResultStr)], !IO),
+ io.nl(!IO).
+
+%---------------------------------------------------------------------------%
+
+:- pred run_binop_test((func(int, int) = int)::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(int, int) = int)::in, string::in,
+ list(int)::in, int::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(int, int) = int)::in, string::in,
+ int::in, int::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\n%s =\n%s\n",
+ [s(to_binary_string_lz(A)), s(Desc),
+ s(to_binary_string_lz(B)), s(ResultStr)], !IO),
+ io.nl(!IO).
+
+%---------------------------------------------------------------------------%
+
+:- pred run_shift_test((func(int, int) = int)::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(int, int) = int)::in, string::in,
+ list(int)::in, int::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(int, int) = int)::in, string::in,
+ int::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 =\n%s\n",
+ [s(to_binary_string_lz(A)), s(Desc), i(B), s(ResultStr)], !IO),
+ io.nl(!IO).
+
+%---------------------------------------------------------------------------%
+
+:- func numbers = list(int).
+
+numbers = [
+ min_int,
+ 0,
+ 1,
+ 2,
+ 8,
+ 10,
+ 16,
+ max_int
+].
+
+:- func shift_amounts = list(int).
+
+shift_amounts = [
+ -1,
+ 0,
+ 1,
+ 2,
+ 3,
+ 4,
+ 8,
+ 16,
+ 24,
+ bits_per_int - 1,
+ bits_per_int
+].
+
+%---------------------------------------------------------------------------%
+
+:- func to_binary_string_lz(int::in) = (string::uo) is det.
+
+:- pragma foreign_proc("C",
+ to_binary_string_lz(I::in) = (S::uo),
+ [will_not_call_mercury, promise_pure, thread_safe, will_not_modify_trail],
+"
+ int i = ML_BITS_PER_INT;
+
+ MR_Unsigned U = (MR_Unsigned) I;
+ MR_allocate_aligned_string_msg(S, ML_BITS_PER_INT, MR_ALLOC_ID);
+ S[ML_BITS_PER_INT] = '\\0';
+ while (i >= 0) {
+ i--;
+ S[i] = (U & 1) ? '1' : '0';
+ U = U >> 1;
+ }
+").
+
+:- pragma foreign_proc("C#",
+ to_binary_string_lz(I::in) = (S::uo),
+ [will_not_call_mercury, promise_pure, thread_safe],
+"
+ S = System.Convert.ToString((uint)I, 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 bitwise_int.
+%---------------------------------------------------------------------------%
diff --git a/tests/hard_coded/shift_test.m b/tests/hard_coded/shift_test.m
index 18306190d..dd2cbaaef 100644
--- a/tests/hard_coded/shift_test.m
+++ b/tests/hard_coded/shift_test.m
@@ -17,29 +17,29 @@
:- import_module string.
main -->
- shift_test((<<), "<<", 64, 0, 64),
- shift_test((<<), "<<", 64, 2, 256),
- shift_test((<<), "<<", -64, 2, -256),
- shift_test((<<), "<<", 64, -2, 16),
- shift_test((<<), "<<", -64, -2, -16),
- shift_test((<<), "<<", 64, -256, 0),
- shift_test((<<), "<<", -64, -256, -1),
- shift_test((<<), "<<", 25, 3, 200),
- shift_test((<<), "<<", -25, 3, -200),
- shift_test((<<), "<<", 25, -3, 3),
- shift_test((<<), "<<", -25, -3, -4),
+ shift_test(legacy_left_shift, "<<", 64, 0, 64),
+ shift_test(legacy_left_shift, "<<", 64, 2, 256),
+ shift_test(legacy_left_shift, "<<", -64, 2, -256),
+ shift_test(legacy_left_shift, "<<", 64, -2, 16),
+ shift_test(legacy_left_shift, "<<", -64, -2, -16),
+ shift_test(legacy_left_shift, "<<", 64, -256, 0),
+ shift_test(legacy_left_shift, "<<", -64, -256, -1),
+ shift_test(legacy_left_shift, "<<", 25, 3, 200),
+ shift_test(legacy_left_shift, "<<", -25, 3, -200),
+ shift_test(legacy_left_shift, "<<", 25, -3, 3),
+ shift_test(legacy_left_shift, "<<", -25, -3, -4),
- shift_test((>>), ">>", 64, 0, 64),
- shift_test((>>), ">>", 64, 2, 16),
- shift_test((>>), ">>", -64, 2, -16),
- shift_test((>>), ">>", 64, -2, 256),
- shift_test((>>), ">>", -64, -2, -256),
- shift_test((>>), ">>", 64, 256, 0),
- shift_test((>>), ">>", -64, 256, -1),
- shift_test((>>), ">>", 25, 3, 3),
- shift_test((>>), ">>", -25, 3, -4),
- shift_test((>>), ">>", 25, -3, 200),
- shift_test((>>), ">>", -25, -3, -200),
+ shift_test(legacy_right_shift, ">>", 64, 0, 64),
+ shift_test(legacy_right_shift, ">>", 64, 2, 16),
+ shift_test(legacy_right_shift, ">>", -64, 2, -16),
+ shift_test(legacy_right_shift, ">>", 64, -2, 256),
+ shift_test(legacy_right_shift, ">>", -64, -2, -256),
+ shift_test(legacy_right_shift, ">>", 64, 256, 0),
+ shift_test(legacy_right_shift, ">>", -64, 256, -1),
+ shift_test(legacy_right_shift, ">>", 25, 3, 3),
+ shift_test(legacy_right_shift, ">>", -25, 3, -4),
+ shift_test(legacy_right_shift, ">>", 25, -3, 200),
+ shift_test(legacy_right_shift, ">>", -25, -3, -200),
shift_test(unchecked_left_shift, "unchecked_left_shift",
64, 2, 256),
@@ -48,10 +48,10 @@ main -->
io__write_string("The following cases test undefined behaviour\n"),
io__write_string("(they cause overflow):\n"),
- shift_test((<<), "<<", 64, 256, 0),
- shift_test((<<), "<<", -64, 256, 0),
- shift_test((>>), ">>", 64, -256, 0),
- shift_test((>>), ">>", -64, -256, 0).
+ shift_test(legacy_left_shift, "<<", 64, 256, 0),
+ shift_test(legacy_left_shift, "<<", -64, 256, 0),
+ shift_test(legacy_right_shift, ">>", 64, -256, 0),
+ shift_test(legacy_right_shift, ">>", -64, -256, 0).
:- pred shift_test((func(int, int) = int)::(func(in, in) = out is det),
string::in, int::in, int::in, int::in,
More information about the reviews
mailing list