[m-rev.] for review: unchecked_logical_right_shift
Simon Taylor
staylr at gmail.com
Fri Dec 29 16:04:20 AEDT 2006
Estimated hours taken: 2
Branches: main
compiler/builtin_ops.m:
compiler/bytecode.m:
compiler/c_util.m:
compiler/const_prop.m:
compiler/llds.m:
compiler/llds_out.m:
compiler/gcc.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_c.m:
compiler/java_util.m:
Add a new builtin: unchecked_logical_right_shift.
This needs to be bootstrapped before the declaration is added
to library/int.m.
XXX This doesn't work with `--target asm' because mlds_to_gcc.m
currently has no way to cast to MR_Unsigned. As far as I can
tell `--target asm' is not tested anywhere.
Is it supported any more?
Index: compiler/builtin_ops.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/builtin_ops.m,v
retrieving revision 1.27
diff -u -u -r1.27 builtin_ops.m
--- compiler/builtin_ops.m 27 Sep 2006 06:16:47 -0000 1.27
+++ compiler/builtin_ops.m 26 Dec 2006 02:08:03 -0000
@@ -48,6 +48,7 @@
% XXX `mod' should be renamed `rem'
; unchecked_left_shift
; unchecked_right_shift
+ ; unchecked_logical_right_shift
; bitwise_and
; bitwise_or
; bitwise_xor
@@ -222,6 +223,8 @@
assign(Z, binary(unchecked_left_shift, leaf(X), leaf(Y)))).
builtin_translation("int", "unchecked_right_shift", 0, [X, Y, Z],
assign(Z, binary(unchecked_right_shift, leaf(X), leaf(Y)))).
+builtin_translation("int", "unchecked_logical_right_shift", 0, [X, Y, Z],
+ assign(Z, binary(unchecked_logical_right_shift, leaf(X), leaf(Y)))).
builtin_translation("int", "/\\", 0, [X, Y, Z],
assign(Z, binary(bitwise_and, leaf(X), leaf(Y)))).
builtin_translation("int", "\\/", 0, [X, Y, Z],
Index: compiler/bytecode.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/bytecode.m,v
retrieving revision 1.71
diff -u -u -r1.71 bytecode.m
--- compiler/bytecode.m 2 Oct 2006 05:21:08 -0000 1.71
+++ compiler/bytecode.m 26 Dec 2006 02:08:03 -0000
@@ -1026,36 +1026,37 @@
binop_code(int_mod, 4).
binop_code(unchecked_left_shift, 5).
binop_code(unchecked_right_shift, 6).
-binop_code(bitwise_and, 7).
-binop_code(bitwise_or, 8).
-binop_code(bitwise_xor, 9).
-binop_code(logical_and, 10).
-binop_code(logical_or, 11).
-binop_code(eq, 12).
-binop_code(ne, 13).
-binop_code(array_index(_Type), 14).
-binop_code(str_eq, 15).
-binop_code(str_ne, 16).
-binop_code(str_lt, 17).
-binop_code(str_gt, 18).
-binop_code(str_le, 19).
-binop_code(str_ge, 20).
-binop_code(int_lt, 21).
-binop_code(int_gt, 22).
-binop_code(int_le, 23).
-binop_code(int_ge, 24).
-binop_code(float_plus, 25).
-binop_code(float_minus, 26).
-binop_code(float_times, 27).
-binop_code(float_divide, 28).
-binop_code(float_eq, 29).
-binop_code(float_ne, 30).
-binop_code(float_lt, 31).
-binop_code(float_gt, 32).
-binop_code(float_le, 33).
-binop_code(float_ge, 34).
-binop_code(body, 35).
-binop_code(unsigned_le, 36).
+binop_code(unchecked_logical_right_shift, 7).
+binop_code(bitwise_and, 8).
+binop_code(bitwise_or, 9).
+binop_code(bitwise_xor, 10).
+binop_code(logical_and, 11).
+binop_code(logical_or, 12).
+binop_code(eq, 13).
+binop_code(ne, 14).
+binop_code(array_index(_Type), 15).
+binop_code(str_eq, 16).
+binop_code(str_ne, 17).
+binop_code(str_lt, 18).
+binop_code(str_gt, 19).
+binop_code(str_le, 20).
+binop_code(str_ge, 21).
+binop_code(int_lt, 22).
+binop_code(int_gt, 23).
+binop_code(int_le, 24).
+binop_code(int_ge, 25).
+binop_code(float_plus, 26).
+binop_code(float_minus, 27).
+binop_code(float_times, 28).
+binop_code(float_divide, 29).
+binop_code(float_eq, 30).
+binop_code(float_ne, 31).
+binop_code(float_lt, 32).
+binop_code(float_gt, 33).
+binop_code(float_le, 34).
+binop_code(float_ge, 35).
+binop_code(body, 36).
+binop_code(unsigned_le, 37).
:- pred binop_debug(binary_op::in, string::out) is det.
@@ -1066,6 +1067,7 @@
binop_debug(int_mod, "mod").
binop_debug(unchecked_left_shift, "<<").
binop_debug(unchecked_right_shift, ">>").
+binop_debug(unchecked_logical_right_shift, "U>>").
binop_debug(bitwise_and, "&").
binop_debug(bitwise_or, "|").
binop_debug(bitwise_xor, "^").
Index: compiler/c_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/c_util.m,v
retrieving revision 1.34
diff -u -u -r1.34 c_util.m
--- compiler/c_util.m 27 Sep 2006 06:16:48 -0000 1.34
+++ compiler/c_util.m 26 Dec 2006 02:08:03 -0000
@@ -121,6 +121,11 @@
%
:- pred unsigned_compare_op(binary_op::in, string::out) is semidet.
+ % The operator returned will be an infix operator. The left argument
+ % should be cast to MR_Unsigned, and the result will be an integer.
+ %
+:- pred logical_shift_op(binary_op::in, string::out) is semidet.
+
% The operator returned will be either a prefix operator or a macro
% or function name. The operand needs to be placed in parentheses
% after the operator name.
@@ -392,6 +397,8 @@
unsigned_compare_op(unsigned_le, "<=").
+logical_shift_op(unchecked_logical_right_shift, ">>").
+
float_op(float_plus, "+").
float_op(float_minus, "-").
float_op(float_times, "*").
Index: compiler/const_prop.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/const_prop.m,v
retrieving revision 1.43
diff -u -u -r1.43 const_prop.m
--- compiler/const_prop.m 19 Dec 2006 07:00:54 -0000 1.43
+++ compiler/const_prop.m 26 Dec 2006 02:08:03 -0000
@@ -301,6 +301,14 @@
Y ^ arg_inst = bound(_YUniq, [bound_functor(int_const(YVal), [])]),
ZVal = unchecked_right_shift(XVal, YVal).
+/*
+evaluate_det_call("int", "unchecked_logical_right_shift",
+ 0, _, [X, Y, Z], Z, int_const(ZVal)) :-
+ X ^ arg_inst = bound(_XUniq, [bound_functor(int_const(XVal), [])]),
+ Y ^ arg_inst = bound(_YUniq, [bound_functor(int_const(YVal), [])]),
+ ZVal = unchecked_logical_right_shift(XVal, YVal).
+*/
+
evaluate_det_call("int", ">>", 0, _, [X, Y, Z], Z, int_const(ZVal)) :-
X ^ arg_inst = bound(_XUniq, [bound_functor(int_const(XVal), [])]),
Y ^ arg_inst = bound(_YUniq, [bound_functor(int_const(YVal), [])]),
Index: compiler/gcc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/gcc.m,v
retrieving revision 1.34
diff -u -u -r1.34 gcc.m
--- compiler/gcc.m 31 Jul 2006 08:31:38 -0000 1.34
+++ compiler/gcc.m 26 Dec 2006 02:08:03 -0000
@@ -385,7 +385,7 @@
:- func bit_not_expr = gcc__op. % ~ (bitwise complement)
:- func lshift_expr = gcc__op. % << (left shift)
-:- func rshift_expr = gcc__op. % >> (left shift)
+:- func rshift_expr = gcc__op. % >> (right shift)
:- func array_ref = gcc__op. % [] (array indexing)
% first operand is the array,
Index: compiler/java_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/java_util.m,v
retrieving revision 1.20
diff -u -u -r1.20 java_util.m
--- compiler/java_util.m 1 Dec 2006 15:04:02 -0000 1.20
+++ compiler/java_util.m 26 Dec 2006 02:08:03 -0000
@@ -106,6 +106,7 @@
java_binary_infix_op(int_mod, "%").
java_binary_infix_op(unchecked_left_shift, "<<").
java_binary_infix_op(unchecked_right_shift, ">>").
+java_binary_infix_op(unchecked_logical_right_shift, ">>>").
java_binary_infix_op(bitwise_and, "&").
java_binary_infix_op(bitwise_or, "|").
java_binary_infix_op(bitwise_xor, "^").
Index: compiler/llds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds.m,v
retrieving revision 1.342
diff -u -u -r1.342 llds.m
--- compiler/llds.m 1 Nov 2006 02:31:07 -0000 1.342
+++ compiler/llds.m 26 Dec 2006 02:08:03 -0000
@@ -1242,6 +1242,7 @@
binop_return_type(int_mod, integer).
binop_return_type(unchecked_left_shift, integer).
binop_return_type(unchecked_right_shift, integer).
+binop_return_type(unchecked_logical_right_shift, integer).
binop_return_type(bitwise_and, integer).
binop_return_type(bitwise_or, integer).
binop_return_type(bitwise_xor, integer).
Index: compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.301
diff -u -u -r1.301 llds_out.m
--- compiler/llds_out.m 27 Dec 2006 04:16:27 -0000 1.301
+++ compiler/llds_out.m 28 Dec 2006 04:27:50 -0000
@@ -4809,6 +4809,16 @@
output_rval_as_type(Y, unsigned, !IO),
io.write_string(")", !IO)
;
+ c_util.logical_shift_op(Op, OpStr)
+ ->
+ io.write_string("(", !IO),
+ output_rval_as_type(X, unsigned, !IO),
+ io.write_string(" ", !IO),
+ io.write_string(OpStr, !IO),
+ io.write_string(" ", !IO),
+ output_rval(Y, !IO),
+ io.write_string(")", !IO)
+ ;
io.write_string("(", !IO),
output_rval_as_type(X, integer, !IO),
io.write_string(" ", !IO),
Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.207
diff -u -u -r1.207 mlds_to_c.m
--- compiler/mlds_to_c.m 23 Dec 2006 12:49:24 -0000 1.207
+++ compiler/mlds_to_c.m 26 Dec 2006 02:08:03 -0000
@@ -3682,6 +3682,16 @@
mlds_output_bracketed_rval(Y, !IO),
io.write_string(")", !IO)
;
+ c_util.logical_shift_op(Op, OpStr)
+ ->
+ io.write_string("( (MR_Unsigned) ", !IO),
+ mlds_output_bracketed_rval(X, !IO),
+ io.write_string(" ", !IO),
+ io.write_string(OpStr, !IO),
+ io.write_string(" ", !IO),
+ mlds_output_bracketed_rval(Y, !IO),
+ io.write_string(")", !IO)
+ ;
% XXX Broken for C == minint, (since `NewC is 0 - C' overflows)
% Op = (+),
% Y = const(int_const(C)),
Index: compiler/mlds_to_gcc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.126
diff -u -u -r1.126 mlds_to_gcc.m
--- compiler/mlds_to_gcc.m 23 Dec 2006 12:49:24 -0000 1.126
+++ compiler/mlds_to_gcc.m 26 Dec 2006 02:08:03 -0000
@@ -3554,6 +3558,9 @@
build_type(MLDS_Type, DefnInfo ^ global_info,
GCC_ResultType)
;
+ % XXX Need to cast left operand of
+ % unchecked_logical_right_shift to
+ % unsigned int.
{ convert_binary_op(BinaryOp, GCC_BinaryOp,
GCC_ResultType) }
),
@@ -3587,6 +3594,8 @@
convert_binary_op(int_mod, gcc__trunc_mod_expr, 'MR_Integer').
convert_binary_op(unchecked_left_shift, gcc__lshift_expr, 'MR_Integer').
convert_binary_op(unchecked_right_shift,gcc__rshift_expr, 'MR_Integer').
+ % Cast left operand to MR_Unsigned.
+convert_binary_op(unchecked_logical_right_shift,gcc__rshift_expr, 'MR_Integer').
convert_binary_op(bitwise_and, gcc__bit_and_expr, 'MR_Integer').
convert_binary_op(bitwise_or, gcc__bit_ior_expr, 'MR_Integer').
convert_binary_op(bitwise_xor, gcc__bit_xor_expr, 'MR_Integer').
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.175
diff -u -u -r1.175 mlds_to_il.m
--- compiler/mlds_to_il.m 23 Dec 2006 12:49:24 -0000 1.175
+++ compiler/mlds_to_il.m 26 Dec 2006 02:08:03 -0000
@@ -2669,6 +2669,9 @@
binaryop_to_il(unchecked_right_shift, instr_node(I), !Info) :-
I = shr(signed).
+binaryop_to_il(unchecked_logical_right_shift, instr_node(I), !Info) :-
+ I = shr(unsigned).
+
binaryop_to_il(bitwise_and, instr_node(I), !Info) :-
I = bitwise_and.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list