caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Andreas Rossberg <rossberg@ps.uni-sb.de>
Cc: Florian Weimer <fw@deneb.enyo.de>,
	Yaron Minsky <yminsky@cs.cornell.edu>,
	Oliver Bandel <oliver@first.in-berlin.de>,
	caml-list@inria.fr
Subject: Re: [Caml-list] int_of_string bug
Date: Fri, 30 Mar 2007 19:20:46 +1000	[thread overview]
Message-ID: <1175246446.22118.35.camel@rosella.wigram> (raw)
In-Reply-To: <460CD180.6080404@ps.uni-sb.de>

On Fri, 2007-03-30 at 10:59 +0200, Andreas Rossberg wrote:
> skaller wrote:
> >>
> >>> That's a problem too, but there is at least a defensible reason for
> >>> that, which is that it is expensive to get integer overflow to throw
> >>> an exception.
> >> i386 and amd64 have hardware support for that, so it's not very
> >> expensive.  There are pretty short RISC sequences for the checks, too.
> >>
> >> MLton uses the i386 hardware support, and I think you can disable the
> >> checks, so measuring the overhead shouldn't be too hard.
> > 
> > But there is a difference you may have missed: Ocaml integers
> > are 31 or 63 bits, not 32 or 64 bits. 
> 
> But it uses the most significant 31/63 bits for ints, so that becomes a 
> non-issue. ;-)

For addition maybe, certainly not for multiplication: one of the
operands has to be shifted right 1 place.

But it depends on the code generator internal details. You could
always shift BOTH operands, do the register calculation, then
shift back .. in which case you'd lose overflow detection.
The problem is you cannot use the carry bit after the shift back
because the bit will definitely be set if the result is negative.

>From what I've seen Ocaml actually uses tricks which also might
defeat detection, for example I've seen some use of LEA
(load effective address) with the scale by 2 option to 
load and shift one bit in a single instruction.

Processors are quirky about flag bits .. some set sign bit
on loading and others don't, etc, so it could be quite messy.
This is why C doesn't specify what happens on overflow:
it would compromise performance on some processors.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


  reply	other threads:[~2007-03-30  9:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-29 16:27 Yaron Minsky
2007-03-29 21:29 ` [Caml-list] " Oliver Bandel
2007-03-30  0:26   ` Yaron Minsky
2007-03-30  7:30     ` Florian Weimer
2007-03-30  8:44       ` skaller
2007-03-30  8:59         ` Andreas Rossberg
2007-03-30  9:20           ` skaller [this message]
2007-03-30  1:21 ` Brian Hurt
2007-03-30  1:26   ` Yaron Minsky
2007-03-30  4:23     ` skaller
2007-03-30  5:59       ` Erik de Castro Lopo
2007-03-30  6:22         ` skaller
2007-03-30 13:38         ` Markus Mottl
2007-04-03 17:51           ` Toby Kelsey
2007-04-03 22:37             ` ls-ocaml-developer-2006

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1175246446.22118.35.camel@rosella.wigram \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@inria.fr \
    --cc=fw@deneb.enyo.de \
    --cc=oliver@first.in-berlin.de \
    --cc=rossberg@ps.uni-sb.de \
    --cc=yminsky@cs.cornell.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).