[m-dev.] diff: fix int_rem_bits_per_int

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Feb 12 17:14:13 AEDT 2001


Estimated hours taken: 0.5

library/bitmap.m:
library/int.m:
	Move the definition of int_rem_bits_per_int from bitmap.m to
	int.m.  Also change the way it is defined to
	(a) match the definition of int__quot_bits_per_int and
	(b) to avoid assuming that bits_per_int is a power of 2.

----------

I examined the generated C and assembler code on x86 (at -O2, using
both hlc.gc and asm_fast.gc) and it is a little better after this change.

----------

Workspace: /home/venus/fjh/ws-venus2/mercury
Index: library/bitmap.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/bitmap.m,v
retrieving revision 1.2
diff -u -d -r1.2 bitmap.m
--- library/bitmap.m	2001/02/08 17:24:37	1.2
+++ library/bitmap.m	2001/02/12 06:05:30
@@ -381,7 +381,7 @@
     % than rem.  Do modern back-ends do the decent thing here if
     % int__bits_per_int is the expected power of two?
     %
-bitmask(I) = 1 `unchecked_left_shift` int_rem_bits_per_int(I).
+bitmask(I) = 1 `unchecked_left_shift` int__rem_bits_per_int(I).
 
 % ---------------------------------------------------------------------------- %
 
@@ -396,19 +396,6 @@
 bitsmask(I) = BitsMask :-
     BitMask  = bitmask(I),
     BitsMask = BitMask \/ (BitMask - 1).
-
-% ---------------------------------------------------------------------------- %
-
-    % XXX To go in int.m
-    %
-    % int_rem_bits_per_int(I) = I `rem` int__bits_per_int.
-    %
-    % XXX This assumes that int__bits_per_int is a power of two.
-    %
-:- func int_rem_bits_per_int(int) = int.
-
-int_rem_bits_per_int(I) =
-    I /\ (int__bits_per_int - 1).
 
 % ---------------------------------------------------------------------------- %
 % ---------------------------------------------------------------------------- %
Index: library/int.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/int.m,v
retrieving revision 1.73
diff -u -d -r1.73 int.m
--- library/int.m	2001/02/05 15:37:09	1.73
+++ library/int.m	2001/02/12 05:55:16
@@ -243,6 +243,13 @@
 	% int__times_bits_per_int(X) = X * bits_per_int.		
 :- func int__times_bits_per_int(int) = int.
 
+	% Used by bitmap.m.  Like the ones above, the purpose of
+	% defining this in C is to make it clearer to gcc that
+	% this can be optimized.
+
+	% int__rem_bits_per_int(X) = X `rem` bits_per_int.		
+:- func int__rem_bits_per_int(int) = int.
+
 %-----------------------------------------------------------------------------%
 
 %
@@ -535,7 +542,12 @@
 	Result = Int * ML_BITS_PER_INT;
 ").
 
+:- pragma foreign_code("C", int__rem_bits_per_int(Int::in) = (Rem::out),
+		[will_not_call_mercury, thread_safe], "
+	Rem = Int % ML_BITS_PER_INT;
+").
 
+
 :- pragma foreign_code("MC++", int__max_int(Max::out),
 		[will_not_call_mercury, thread_safe], "
 	Max = System::Int32::MaxValue;
@@ -559,6 +571,11 @@
 :- pragma foreign_code("MC++", int__times_bits_per_int(Int::in) = (Result::out),
 		[will_not_call_mercury, thread_safe], "
 	Result = Int * ML_BITS_PER_INT;
+").
+
+:- pragma foreign_code("MC++", int__rem_bits_per_int(Int::in) = (Rem::out),
+		[will_not_call_mercury, thread_safe], "
+	Rem = Int % ML_BITS_PER_INT;
 ").
 
 

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list