On Thu, Feb 12, 2009 at 9:15 AM, Eliot Miranda <eliot.miranda@gmail.com> wrote:


On Thu, Feb 12, 2009 at 1:32 AM, Andreas Raab <andreas.raab@gmx.de> wrote:

Folks -

Has anyone tried porting the FFI to 64 bit? I'm loosely considering using a 64bit VM for our servers but I do need the FFI (mostly for ODBC integration) and I've never looked at any of the ABIs. Alternatively, is it reasonable to try to use 64bit libs from within a 32bit Squeak VM?

Depends on what one wants to pass through the FFI.  On x86-64/EMT64 structure passing conventions are efficient and complex, distributing structure fields across integer and floating-point registers.  It is possible to interpret such calls given a type signature for the structure to be passed (I did it for VisualWorks) but it is not easy and it is slow.  I would counsel writing a proper ABI compiler in Smalltalk that generates e.g. RTL that is either interpreted or compiled by the VM to make the actual call.

In theory the use of 64-bit libs, provided one has the relevant FFI support should work fine.  Smalltalk has the ability to deal with 64-bit and 128-bit values easily.  But one does have to write all the support.

I should expand on this, and could be completely wrong.  One would have to use a 64-bit address space, which implies compiling the 32-bit VM using a 64-bit compiler.  When DEC and ParcPlace co-implemented 32-bit VisualWorks (my first job on joining ParcPlace was to productise this port) we used the DEC C compiler's ability to define "short" (32-bit) pointers and put the executable in the lower 32-bits of the address space (google for e.g. -xtaso or taso).  Hence the VM was a 64-bit executable which had a 32-bit Smalltalk living in the bottom 32-bits.  If x86-64 compilers have the same short pointer support then the compilation of a 32-bit Squeak VM should be relatively easy.  Otherwise one will have to define the longAt: longAt:put: et al machinery to extend 32-bit addresses into full 64-bit pointers and genuflect to the linker and/or memory allocator to get it to place the heap low in the address space.


To get acquainted with the de facto standard x86-64 ABI read the
System V Application Binary Interface AMD64 Architecture Processor Supplement 
pages 13 through 22 (section Function Calling Sequence) paying particular attention to the 3 1/2 page algorithm for marshalling :)

and start going to bed earlier ;)



Thanks for any info!

Cheers,
 - Andreas