Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by salva (Abbot)
on Feb 09, 2011 at 09:55 UTC ( #887161=note: print w/replies, xml ) Need Help??


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

C code:
typedef __int128 int128_t; int128_t add128(int128_t a, int128_t b) { return a + b; } int128_t sub128(int128_t a, int128_t b) { return a - b; } int128_t mul128(int128_t a, int128_t b) { return a * b; } int128_t div128(int128_t a, int128_t b) { return a / b; } int128_t rem128(int128_t a, int128_t b) { return a % b; }
Assembler generated by gcc -O3 -march=core2:
.file "lookatme.c" .text .p2align 4,,15 .globl add128 .type add128, @function add128: .LFB0: .cfi_startproc movq %rdx, %rax movq %rcx, %rdx addq %rdi, %rax adcq %rsi, %rdx ret .cfi_endproc .LFE0: .size add128, .-add128 .p2align 4,,15 .globl sub128 .type sub128, @function sub128: .LFB1: .cfi_startproc movq %rsi, %r10 movq %rdi, %rsi subq %rdx, %rsi movq %r10, %rdi sbbq %rcx, %rdi movq %rsi, %rax movq %rdi, %rdx ret .cfi_endproc .LFE1: .size sub128, .-sub128 .p2align 4,,15 .globl mul128 .type mul128, @function mul128: .LFB2: .cfi_startproc imulq %rdx, %rsi movq %rdx, %rax imulq %rdi, %rcx mulq %rdi addq %rcx, %rsi addq %rsi, %rdx ret .cfi_endproc .LFE2: .size mul128, .-mul128 .globl __divti3 .p2align 4,,15 .globl div128 .type div128, @function div128: .LFB3: .cfi_startproc subq $8, %rsp .cfi_def_cfa_offset 16 call __divti3 addq $8, %rsp .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE3: .size div128, .-div128 .globl __modti3 .p2align 4,,15 .globl rem128 .type rem128, @function rem128: .LFB4: .cfi_startproc subq $8, %rsp .cfi_def_cfa_offset 16 call __modti3 addq $8, %rsp .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE4: .size rem128, .-rem128 .ident "GCC: (GNU) 4.6.0 20110207 (experimental) [trunk revisio +n 169884]" .section .note.GNU-stack,"",@progbits
So, it uses inlined 64bits arithmetic, except for division and modulo operations that are library calls.

Replies are listed 'Best First'.
Re^9: Module for 128-bit integer math?
by BrowserUk (Pope) on Feb 09, 2011 at 20:17 UTC

    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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2020-10-26 15:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (252 votes). Check out past polls.

    Notices?