Browse thread
Estimating the size of the ocaml community
-
Yaron Minsky
-
Christopher A. Watford
-
Frédéric_Gava
-
skaller
-
Erik de Castro Lopo
- Olivier_Pérès
-
Thomas Fischbacher
-
Frédéric_Gava
-
Thomas Fischbacher
- Paul Snively
- josh
- Richard Jones
-
Jon Harrop
-
Michael Walter
-
Jon Harrop
- Damien Doligez
- Thomas Fischbacher
- Michael Walter
-
Radu Grigore
- Gerd Stolpmann
- Jon
-
Jon Harrop
- Thomas Fischbacher
- Richard Jones
-
Michael Walter
- Ville-Pertti Keinonen
- Oliver Bandel
- Basile STARYNKEVITCH
-
Thomas Fischbacher
- ronniec95@l...
- skaller
- chris.danx
-
Frédéric_Gava
-
Erik de Castro Lopo
- sejourne_kevin
- Stefano Zacchiroli
-
skaller
-
Frédéric_Gava
- Kenneth Knowles
- Michael Jeffrey Tucker
- Richard Jones
- Nicolas Cannasse
- Evan Martin
- Eric Stokes
- chris.danx
- Sylvain LE GALL
- sejourne_kevin
- Sven Luther
- Johann Spies
-
Christopher A. Watford
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2005-02-12 (15:38) |
From: | Brian Hurt <bhurt@s...> |
Subject: | Re: [Caml-list] The boon of static type checking |
On Mon, 7 Feb 2005, Marcin 'Qrczak' Kowalczyk wrote: > Brian Hurt <bhurt@spnz.org> writes: > > > Hint: I've yet to meet a compiler that couldn't turn x/32 into > > x >> 5. > > Actually this is incorrect when x is a signed type (and might be > negative). I've just compiled the code: signed long foo(signed long x) { return x/32; } with gcc -O1 (gcc version 3.2.2, Redhat 9.0 default for the x86), and got the assembly language output: foo: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax testl %eax, %eax jns .L2 addl $31, %eax .L2: sarl $5, %eax leave ret Note the use of a sarl instruction, instead of a div instruction. By the same logic, compiling: let foo x = x / 32;; under Ocamlopt (3.08.1, x86 on Redhat) we get the function: camlEx2__foo_57: .L100: sarl $1, %eax testl %eax, %eax jge .L101 addl $31, %eax .L101: sarl $5, %eax lea 1(%eax, %eax), %eax ret While it's not technically a >> operator, a shift operator (as opposed to a divide) is being used. Brian