Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: optimize div to right shift (NOT!)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jonathan Kimmitt <jonathan@k...>
Subject: Re: optimize div to right shift (NOT!)

> A C compiler would optimize this to a right shift. Changing that to 'Int64.shift_right n 1' speeds
> up the code.

Sorry to be a pedant, but this is not correct. The optimisation is only possible when the arguments
are unsigned integers which I don't think is specifiable when working in OCAML

# Int64.shift_right (-2L) 1;;
- : int64 = -1L (So far, so good)
# Int64.div (-1L) 2L;;
- : int64 = 0L (Good)
# Int64.shift_right (-1L) 1;;
- : int64 = -1L (Duh)