> Firstly it pays off well to inline the common case (to use the Lisp
> parlance - FIXNUMs, immediate tagged integers).  You are typically
> going to have to pay for tag-testing before the operation and overflow
> checking afterwards, but some architectures allow you do these quite
> cheaply [Sparc's tagged-add instruction, for instance]  If you only
> call out-of-line for actual BIGNUMs, then you save a lot of
> (micro-)context switching.

I agree this looks like a favourable tradeoff (optimising the common
case against the small overhead of tagging), we just haven't got
around to doing it because of the high effort-to-benefit ratio - most
people worried about performance use Ints anyway.

> The tag tests for binary operations are
> usually combined into one by ORing the tags together, and you avoid
> tag-correction in the common cases of addition and subtraction by
> assigning a zero tag to FIXnums - multiply and divide need only a
> single shift to correct.

Sure, except that we'd probably keep the tags in the info table for
the constructor, out of the way of the value itself.  The tag-test is
the same either way (one memory load + AND), and you don't have to
worry about arithmetic on tagged values.

However, real tagged Ints would have a use - currently you can't pass
unboxed values to polymorphic functions in GHC, since the garbage
collector would have no way of knowing whether a value on the stack is
a pointer or not.  Similarly for placing unboxed values in polymorphic
constructor fields, like lists.  However, if the value was tagged we
could do this - you could then have efficient strict Ints (albeit
31-bit Ints), chars, and small strict Integers.

Cheers,
        Simon

-- 
Simon Marlow                                             [EMAIL PROTECTED]
University of Glasgow                       http://www.dcs.gla.ac.uk/~simonm/
finger for PGP public key

Reply via email to