On Wed, Apr 9, 2008 at 5:49 PM, Martin Rubey <martin.rubey@...> wrote:
> I believe I just realised that
> (* x y)
> is *exactly* as fast in sbcl as
> (* (the integer x) (the integer y))
> i.e., there is no point at all declaring integers, except of course, if for
> some reason sbcl can prove that x and y are in fact fixnums.
> Is that correct?
> I guess the same actually holds for
> (+ (the integer x) 1)
> doesn't it? (or is there a faster way to increment a bignum by one?)
> In case the answers to the above are "yes", is that a principal impossibility,
> or just because noone implemented something better (in sbcl)?
Sorry for the late answer, but...
Yes and no. If there isn't sufficient information to do something
better, calls to arithmentic functions tend to end up as calls to
their generic versions.
However, if you know that your values are possibly bignums, but still
at most word-sized, you can use modular arithmetic.
(defun foo (x y)
(declare (type (unsigned-byte 32) x y))
(ldb (byte 32 0) (+ x y)))