Support for w*ndows

Torbjorn Granlund tg at gmplib.org
Sat Nov 26 14:17:54 CET 2011


How exactly does W64_ENTRY look like?  (I suppose W64_EXIT is tiny.)

While this idea is appealing, I worry that the overhead might hurt
"small bignum" performance, compared to even the C code.

Have you considered I more sophisticated approach with renaming
registers?

Something along these lines:

include(`../config.m4')
RENAME_REGISTERS
ASM_START()
PROLOGUE(mpn_foo)
        PUSH_RDI
        PUSH_RSI
        EXTRA_GET_PARAMETERS
        ...
        function body
        ...
        POP_RSI
        POP_RDI
        ret
EPILOGUE()
ASM_END()


Here, RENAME_REGISTERS should expand to nothing on ELF ABI compliant
systems, and lots of

  define(`_tmp1', rcx)
  define(`_tmp2', rdx)
  define(`_tmp3', r8)
  define(`_tmp4', r9)
  ...
  define(`rdi', _tmp1)
  define(`rsi', _tmp2)
  define(`rdx', _tmp3)
  define(`rcx', _tmp4)
  ...

for W64 (and perhaps other systems with homegrown ABIs).

The macros PUSH_RDI/RSI saves the register if this function uses more
callee-saves registers than W64 provides.  These should really push rdi
and rsi, respectively, not logically renamed registers.  Note that the
logical register "rdi" will use the physical register rcx.

The macro EXTRA_GET_PARAMETERS probably needs some argument; it should
copy a 5th and 6th parameter from the stack frame to (logical) register
r8 ad r9.  Perhaps it simply should be split into COPY_PARAMETER_5 and
and COPY_PARAMETER_6, copying to (logical) registers r8 and r9,
respectively.

Does anybody see problems with this proposal?  It should add very little
overhead compared to specially written code, and will not clutter up the
code too much.

We could let configure identify W64-ready code by grepping some symbol
in assembly files, thus allowing a gradual code adoption.

Having written this far, I realise one snag: GMP assembly files using
the rcx register for shift counts will not work.  Similarly, file using
the MUL instruction puts part of the product in the physical register
rdx, but we well have renamed rsi to rdx (and thus rdx to some other
register).  Hmm.

There will be one remaining compatibility issue: Intel syntax vs MIT
assembly syntax.  While cygwin and mingw have no problems with the MIT
syntax, M$'s assembler almost surely does.  I have no problems with
Intel's syntax but I suspect it will not work with all Unix assembler
(Solaris, Darwin?).  It might also lack syntax for some relocs we need
in ELF.  Therefore, let's stick to just the MIT syntax for the time
being.

-- 
Torbjörn


Short summary of W64 ABI (from M$'s site):

The registers RAX, RCX, RDX, R8, R9, R10, R11 are considered volatile
and must be considered destroyed on function calls.

The registers RBX, RBP, RDI, RSI, R12, R13, R14, and R15 are considered
nonvolatile and must be saved and restored by a function that uses them.

The arguments are passed in registers RCX, RDX, R8, and R9.


More information about the gmp-devel mailing list