property list hack, profiling, compiler optimization, looking at code
Subject: property list hack, profiling, compiler optimization, looking at code
From: Stavros Macrakis
Date: Sat, 11 Aug 2012 19:02:18 -0400
PS I just noticed that fixnump is a function defined in clmacs -- it really
should be an inline function, along with several others in that file....
Or just use (typep x 'fixnum) below.
On Sat, Aug 11, 2012 at 5:38 PM, Stavros Macrakis <macrakis at alum.mit.edu>wrote:
> On Sat, Aug 11, 2012 at 2:11 PM, Richard Fateman <
> fateman at eecs.berkeley.edu> wrote:
>>
>> An additional observation regarding speed and zerop1, which is defined
>> this way:
>>
>> (defun zerop1 (x)
>> (or (and (integerp x) (= 0 x))
>> (and (floatp x) (= 0.0 x))
>> (and ($bfloatp x) (= 0 (second x)))))
>>
>
> This is a strange definition, as for a non-zero integer, it still checks
> floatp and $bfloatp. More straightforward would be:
>
> (defun zerop1 (x)
> (declare (inline $bfloatp)) ; worthwhile for such a common function
> (requires declaim/inline etc. @ $bfloatp)
> (cond ((fixnump x) (= 0 x)) ; a bignum can't be 0
> ((floatp x) (= 0.0 x))
> (($bfloatp x) (= 0 (second x)))
> (t nil)))
>
> Of course, the straightforward definition isn't necessarily the fastest,
> and may depend on the particular compiler and processor.
>
> Though I find micro-optimizing like this peculiarly entertaining, I'm
> pretty sure this will make no noticeable difference to the user experience,
> certainly less difference than improving functionality in any one of a
> number of ways.
>
> -s
>
>