Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^6: Module for 128-bit integer math?

by BrowserUk (Pope)
on Feb 08, 2011 at 18:47 UTC ( #887028=note: print w/replies, xml ) Need Help??


in reply to Re^5: Module for 128-bit integer math?
in thread Module for 128-bit integer math?

Wow! That was fast!

Unfortunately, I don't think I'll be able to make use of it :(

Whilst I have MinGW for 32-bit setup and working, I've never succeeded in getting a 64-bit version to work in conjunction with my 64-perl. And I need this to work there.

I will download it and see if I can build it for 32-bit, but it won't be for a couple of days as I'm out tomorrow. I'll also try to knock up a test script, though it won't use Test::*. For this kind of thing I favour a random testing mechanism. Eg. generate a couple of numbers; multiply them; divide the results by one of them and check that result matches the other. Similarly for add/subract, shift-left/right etc.

I've started to develop a my own using MSC and a struct containing two 64-bit ints. Add/subtract and multiply work--albeit that the latter uses a slow algorithm. I'm a bit hung up on div/mod at the moment.

For a first pass I'm doing this using standard C math. In theory, it should be quicker using the 128-bit XMM registers, but the docs for the SSE/SSE2/SSE3 et al. intrinsics are less than detailed. Counter to my understanding earlier in this thread, those instructions don't support 128-bit math directly. They do support SIMD operations on pairs of 64-bit ints/uints, which in theory should speed up multiplication/division no end, but the combinations of incantations required are not at all clear. I've failed completely to turn up any examples on the web.

Maybe if I can get it something to fly here, we could look at adding it to your module; or making a Win module that yours can defer to on this platform?

One thing that might be useful to me if you have the time, is an assembler dump of the sources. Can gcc do that? And if it can, would it show the actual operations involved, or just calls to system library routines? Are they inlined?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^7: Module for 128-bit integer math?
by ikegami (Pope) on Feb 09, 2011 at 02:04 UTC

    One thing that might be useful to me if you have the time, is an assembler dump of the sources. Can gcc do that?

    gcc -S a.c

    And if it can, would it show the actual operations involved, or just calls to system library routines?

    It provides the assembler code for the code you are compiling, which would include inlined functions, but I don't see why it would disassemble existing objects.

    $ cat a.c #include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }
    $ cat a.s .file "a.c" .section .rodata .LC0: .string "Hello, World!" .text .globl main .type main, @function main: leal 4(%esp), %ecx andl $-16, %esp pushl -4(%ecx) pushl %ebp movl %esp, %ebp pushl %ecx subl $4, %esp movl $.LC0, (%esp) call puts movl $0, %eax addl $4, %esp popl %ecx popl %ebp leal -4(%ecx), %esp ret .size main, .-main .ident "GCC: (Debian 4.3.2-1.1) 4.3.2" .section .note.GNU-stack,"",@progbits

    Are they inlined?

    I can't try to install the dev gcc needed for Math::Int128 at this moment.

      C code: Assembler generated by gcc -O3 -march=core2: So, it uses inlined 64bits arithmetic, except for division and modulo operations that are library calls.

        Cool! Many thanks for that. I may just translate those sequences to MASM and use them directly until I work if using SSE* will improve performance.

        Shame about the div/mod cos those are the ones I've had trouble getting right. But I should be able to look them up in the gcc library sources?


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
      but I don't see why it would disassemble existing objects.

      It obviously wouldn't disassemble anything.

      But if the 128-bit math functions were marked inline, their implementation would show up.

      If not inlined, then the names of the routines called to perform it should be visible, and that would aid tracking down their implementation in the library sources.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        It obviously wouldn't disassemble anything.

        Then it will obviously just show the calls to system library routines.

        then the names of the routines called to perform it should be visible

        Confirmed by the demonstration I posted.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://887028]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2020-10-30 13:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (279 votes). Check out past polls.

    Notices?