Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Integer arithmetic: mod
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Gerard Malecki <johnm@a...>
Subject: Re: [Caml-list] Integer arithmetic: mod
Does anyone know if the hardware implementation of integer division
and/or remainder is faster because the returned value from remainder
is sometimes negative?  Maybe its slower but everyone does it the same
way for backwards compatibility?

One reason for the hardware remainder to be positive is that it allows
for easier compiler optimizations.  If the remainder is always
positive then the following transformations are always available:

	 M /   (2**N) == M asr  N
	 M mod (2**N) == M land (2**N-1)

I guess it doesn't much matter as this optimization is normally
applied to array indices which usually are non-negative anyway.

PS - i'm not sure if this trick also works with 1s complement
     representation but when was the last time anyone built one of
     those machines?
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr