From: ······@gmail.com
Subject: declare 64 bit integers?
Date: 
Message-ID: <1190866164.760010.18370@50g2000hsm.googlegroups.com>
I'm writing a chess program using rotate bitboards (64 bit integers)
(http://en.wikipedia.org/wiki/Bitboard) .  Anyways, I'm competing
against some people writing the program in Java and C++, and I want to
top them when I get mine all compiled.  So I know you can declare
fixnums (28-bit), but is there any way to declare 64-bit integers to
get compiled LISP running super fast?

-JW

From: Matthias Benkard
Subject: Re: declare 64 bit integers?
Date: 
Message-ID: <1190883470.023556.141970@50g2000hsm.googlegroups.com>
Hi,

> So I know you can declare
> fixnums (28-bit),

A FIXNUM is not necessarily 28 bits wide.  The size is implementation-
and platform-dependent (at least 16 bits, though).

> but is there any way to declare 64-bit integers ... ?

(declare (type (signed-byte 64) x))
(declare (type (unsigned-byte 64) y))

You can specify any integer length you want by using SIGNED-BYTE and
UNSIGNED-BYTE.  The implementation is not guaranteed to optimise just
any weird integer type you throw at it, though.  (You can't count on
optimisation of 64-bit integers, either.  The only thing you can do is
try it out.)

You may also want to look at the INTEGER type, which lets you express
ranges of integers in a more meaningful way:

(declare (type (integer -100 100) z))

~ Matthias
From: Pascal Costanza
Subject: Re: declare 64 bit integers?
Date: 
Message-ID: <5m19ruFaitpdU1@mid.individual.net>
Matthias Benkard wrote:
> Hi,
> 
>> So I know you can declare
>> fixnums (28-bit),
> 
> A FIXNUM is not necessarily 28 bits wide.  The size is implementation-
> and platform-dependent (at least 16 bits, though).
> 
>> but is there any way to declare 64-bit integers ... ?
> 
> (declare (type (signed-byte 64) x))
> (declare (type (unsigned-byte 64) y))
> 
> You can specify any integer length you want by using SIGNED-BYTE and
> UNSIGNED-BYTE.  The implementation is not guaranteed to optimise just
> any weird integer type you throw at it, though.  (You can't count on
> optimisation of 64-bit integers, either.  The only thing you can do is
> try it out.)

...or check the documentation.


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: bob_bane
Subject: Re: declare 64 bit integers?
Date: 
Message-ID: <1190908919.976251.165040@n39g2000hsh.googlegroups.com>
On Sep 27, 12:09 am, ······@gmail.com wrote:
> I'm writing a chess program using rotate bitboards (64 bit integers)

Given that this is Common Lisp, you should probably just work with
vectors of bits rather than integers.  Most implementations will do
logical operations on bit vectors really fast, especially if you use
the three-argument form:

(bit-and a1 a2 a1)

which shouldn't cons at all.
From: Alex Mizrahi
Subject: Re: declare 64 bit integers?
Date: 
Message-ID: <46fc07a4$0$90272$14726298@news.sunsite.dk>
(message (Hello ·······@gmail.com)
(you :wrote  :on '(Thu, 27 Sep 2007 04:09:24 -0000))
(

 j> I'm writing a chess program using rotate bitboards (64 bit integers)
 j> (http://en.wikipedia.org/wiki/Bitboard) .  Anyways, I'm competing
 j> against some people writing the program in Java and C++, and I want to
 j> top them when I get mine all compiled.  So I know you can declare
 j> fixnums (28-bit), but is there any way to declare 64-bit integers to
 j> get compiled LISP running super fast?

i'm afraid it won't run "super fast" (if you mean using directly machine 
registers/CPU instructions) on any available implementation.
you can pick one -- for example, SBCL -- and ask developers if it's possible 
to extend compiler to suport this stuff.

if you are not aiming for "absolutely fast" you can check bit vectors etc..

check what it does in disassembly, in any way..

)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"Hanging In The Balance Of Deceit And Blasphemy") 
From: David Lichteblau
Subject: Re: declare 64 bit integers?
Date: 
Message-ID: <slrnffoei7.mlp.usenet-2006@radon.home.lichteblau.com>
On 2007-09-27, Alex Mizrahi <········@users.sourceforge.net> wrote:
> i'm afraid it won't run "super fast" (if you mean using directly machine 
> registers/CPU instructions) on any available implementation.
> you can pick one -- for example, SBCL -- and ask developers if it's possible 
> to extend compiler to suport this stuff.

Yes, it is possible:

I once wrote such a contrib for SBCL implementing "long long"-style
inline (signed-byte 64) arithmetic on x86.

SBCL's register allocation is not designed for pairing of arbitrary
registers, but it was possible to make it work with minimal effort by
only pairing registers that are adjacent (according to the compiler's
idea of how the registers are numbered).
From: ······@gmail.com
Subject: Re: declare 64 bit integers?
Date: 
Message-ID: <1190952914.689605.269310@19g2000hsx.googlegroups.com>
> Yes, it is possible:
>
> I once wrote such a contrib for SBCL implementing "long long"-style
> inline (signed-byte 64) arithmetic on x86.
>
> SBCL's register allocation is not designed for pairing of arbitrary
> registers, but it was possible to make it work with minimal effort by
> only pairing registers that are adjacent (according to the compiler's
> idea of how the registers are numbered).

How in the world do I go about doing that?
From: David Lichteblau
Subject: Re: declare 64 bit integers?
Date: 
Message-ID: <slrnffsf0r.nmt.usenet-2006@radon.home.lichteblau.com>
On 2007-09-28, ······@gmail.com <······@gmail.com> wrote:
>> I once wrote such a contrib for SBCL implementing "long long"-style
>> inline (signed-byte 64) arithmetic on x86.
>>
>> SBCL's register allocation is not designed for pairing of arbitrary
>> registers, but it was possible to make it work with minimal effort by
>> only pairing registers that are adjacent (according to the compiler's
>> idea of how the registers are numbered).
>
> How in the world do I go about doing that?

Well, my solution is for SBCL, so it does not help you with LispWorks
(or whatever implementation you are on).  But you can find it in my SBCL
fork on repo.or.cz.  Use (require :sb-regpair) to load it, or see the
sources in contrib/sb-regpair/.

Other than that, I can only second the recommendation to use 64 bit
hardware together with an implementation like SBCL that supports
both untagged, inline arithmetic in general and modular arithmetic in
particular. 
From: Nathan Froyd
Subject: Re: declare 64 bit integers?
Date: 
Message-ID: <1190991108.459030.41810@22g2000hsm.googlegroups.com>
On Sep 27, 3:42 pm, "Alex Mizrahi" <········@users.sourceforge.net>
wrote:
>  j> I'm writing a chess program using rotate bitboards (64 bit integers)
>  j> (http://en.wikipedia.org/wiki/Bitboard) .  Anyways, I'm competing
>  j> against some people writing the program in Java and C++, and I want to
>  j> top them when I get mine all compiled.  So I know you can declare
>  j> fixnums (28-bit), but is there any way to declare 64-bit integers to
>  j> get compiled LISP running super fast?
>
> i'm afraid it won't run "super fast" (if you mean using directly machine
> registers/CPU instructions) on any available implementation.
> you can pick one -- for example, SBCL -- and ask developers if it's possible
> to extend compiler to suport this stuff.

The original poster didn't specify what the target machine was
(although it
sounds like he's using a 32-bit machine), but for the record, SBCL on
x86-64
can do unboxed operations on 64-bit integers just like Java or C++.

-Nathan
From: Alex Mizrahi
Subject: Re: declare 64 bit integers?
Date: 
Message-ID: <46fe1332$0$90268$14726298@news.sunsite.dk>
(message (Hello 'Nathan)
(you :wrote  :on '(Fri, 28 Sep 2007 14:51:48 -0000))
(

 ??>> i'm afraid it won't run "super fast" (if you mean using directly
 ??>> machine registers/CPU instructions) on any available
 ??>> implementation. you can pick one -- for example, SBCL -- and ask
 ??>> developers if it's possible to extend compiler to suport this stuff.

 NF> The original poster didn't specify what the target machine was
 NF> (although it
 NF> sounds like he's using a 32-bit machine), but for the record, SBCL on
 NF> x86-64
 NF> can do unboxed operations on 64-bit integers just like Java or C++.

just of curiosity -- this is how?

* (log most-positive-fixnum 2)
60.0

so fixnums are just 61 bit wide, that's not interesting. how to declare 
64-bit interger value?


)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"Hanging In The Balance Of Deceit And Blasphemy") 
From: ········@tochka.ru
Subject: Re: declare 64 bit integers?
Date: 
Message-ID: <1191067223.200967.58290@50g2000hsm.googlegroups.com>
On Sep 29, 12:56 pm, "Alex Mizrahi" <········@users.sourceforge.net>
wrote:
[for SBCL on x86_64]
> so fixnums are just 61 bit wide, that's not interesting. how to declare
> 64-bit interger value?

You can work with unboxed 64 bit integers in the same way as with
unboxed floats: do not store them into a universal storage (e.g. a
list or a non-specialized vector), do not pass as arguments to a
global function, and do not return. For example:

(defun checksum (vector result)
  (declare (type (simple-array (unsigned-byte 64) (*)) vector)
           (type (simple-array (unsigned-byte 64) ()) result))
  (loop for x of-type (unsigned-byte 64) across vector
        for s of-type (unsigned-byte 64) = x then (logxor s x)
        finally (setf (aref result) s))
  result)
From: David Lichteblau
Subject: Re: declare 64 bit integers?
Date: 
Message-ID: <slrnffselt.nmt.usenet-2006@radon.home.lichteblau.com>
On 2007-09-29, Alex Mizrahi <········@users.sourceforge.net> wrote:
>  NF> The original poster didn't specify what the target machine was
>  NF> (although it
>  NF> sounds like he's using a 32-bit machine), but for the record, SBCL on
>  NF> x86-64
>  NF> can do unboxed operations on 64-bit integers just like Java or C++.
>
> just of curiosity -- this is how?
>
> * (log most-positive-fixnum 2)
> 60.0
>
> so fixnums are just 61 bit wide, that's not interesting. how to declare 
> 64-bit interger value?

Matthias Benkard already answered your question in this thread, but I
will give you the benefit of the doubt and assume that you are asking
about how unboxed operations on 64-bit integers work, rather than the
type declaraton itself.

Here is what SBCL can do:

  - The compiler can perform unboxed operations on register-sized
    integers within a function, given suitable type declarations.

  - Specialized arrays store their elements unboxed.

  - With a suitable type declaration, structure slots are also stored "raw".

The complications, on the other hand, are:

  - no unboxed arguments across full function calls

  - type declarations are often good enough as "hints" for
    representation selection about your data, but sometimes things go
    wrong and the compiler will end up converting between tagged and
    untagged representation for no good reason, which can end up being
    more expensive than doing a tagged operation would have been
From: Alex Mizrahi
Subject: Re: declare 64 bit integers?
Date: 
Message-ID: <46fe80e1$0$90271$14726298@news.sunsite.dk>
 DL> Matthias Benkard already answered your question in this thread, but I
 DL> will give you the benefit of the doubt and assume that you are asking
 DL> about how unboxed operations on 64-bit integers work, rather than the
 DL> type declaraton itself.

 DL> Here is what SBCL can do:

thanks for explanation!