## Re: [Sbcl-help] lisp optimization

 Re: [Sbcl-help] lisp optimization From: Nikodemus Siivola - 2008-08-04 12:34:51 ```On Wed, Apr 9, 2008 at 5:49 PM, 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. See: http://www.sbcl.org/manual/Modular-arithmetic.html#Modular-arithmetic Example: (defun foo (x y) (declare (type (unsigned-byte 32) x y)) (ldb (byte 32 0) (+ x y))) Cheers, -- Nikodemus ```

 [Sbcl-help] lisp optimization From: Martin Rubey - 2008-04-09 14:50:18 ```Dear all, 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)? Martin ```
 Re: [Sbcl-help] lisp optimization From: Nikodemus Siivola - 2008-08-04 12:34:51 ```On Wed, Apr 9, 2008 at 5:49 PM, 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. See: http://www.sbcl.org/manual/Modular-arithmetic.html#Modular-arithmetic Example: (defun foo (x y) (declare (type (unsigned-byte 32) x y)) (ldb (byte 32 0) (+ x y))) Cheers, -- Nikodemus ```