0

I have two unsigned long long ints (64 bit integers) that I am multiplying together. However, (this makes sense) there is no built-in 128bit data type (and I am certainly not rich enough to afford a 128bit processor) so I am only getting back the lower 64 bits of the result. Is there a way to get the rest (perhaps it is stored in another register)?

I am not afraid of embedded assembly. Because this might be important: Other times when I have tried to use the %rax register, gcc complained that there was no such register. Does GAS use a different syntax that I am not aware of?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Marco Merlini
  • 875
  • 7
  • 29
  • 1
    @DavidHeffernan the supposed "duplicate" is (a) not a duplicate, (b) closed as -5, unclear – M.M Sep 02 '14 at 02:07
  • 2
    Here is a duplicate: http://stackoverflow.com/questions/13187629/gcc-intrinsic-for-extended-division-multiplication – M.M Sep 02 '14 at 02:08
  • @Matt it certainly is a dupe – David Heffernan Sep 02 '14 at 02:08
  • 1
    @DavidHeffernan This question asks about 128bit mul, the linked question asks about 64bit mul. – M.M Sep 02 '14 at 02:08
  • @matt nope, you read it wrong. Both cover mult of two 64 bit values with 128 bit output – David Heffernan Sep 02 '14 at 02:09
  • I don't see how you get from "how to 64bit multiplication 32bit" to "how to do 128bit multiplication" but apparently the OP accepted your answer, so your gibberish-interpretation skills are better than mine! – M.M Sep 02 '14 at 02:11
  • @Matt Perhaps I should have fixed that Q once I'd decoded the gibberish. All the same, my answer there does the job here too. – David Heffernan Sep 02 '14 at 02:12
  • Just because two questions cover the same material doesn't make them dupes. They need to be substantially the same question to be duplicates. This and the others aren't. – Russia Must Remove Putin Sep 02 '14 at 02:38
  • @Aaron Difficult to see how this is not a dupe. Multiply two 64 bit operands and return 128 bit result. Where is the difference? – David Heffernan Sep 02 '14 at 02:41
  • Maybe I'm wrong, the other question seems concerned with portability, but I've already voted. – Russia Must Remove Putin Sep 02 '14 at 02:45
  • If you want to use assembly you must include the exact architecture. Obviously you're not on x86_64 because there's no RAX register, and not some other 64-bit platforms since on those architectures gcc and clang already have __int128_t available – phuclv Sep 02 '14 at 03:36
  • Even if you're richer than Bill Gates, there's no 128-bit CPU available for you. If you're using a 64-bit system, change the target to 64 bit and use __int128_t – phuclv Sep 02 '14 at 03:45
  • 'Long multiplication'? I'm sure I learned how to do that in school. – Martin James Sep 02 '14 at 08:04
  • on x86 use [this](http://stackoverflow.com/questions/8776073/efficient-multiply-divide-of-two-128-bit-integers-on-x86-no-64-bit), on x86_64 use [this](http://stackoverflow.com/questions/13187629/gcc-intrinsic-for-extended-division-multiplication) – phuclv Sep 06 '14 at 05:51

1 Answers1

-1

I think you should take a look at https://gmplib.org which allow to make computation on potentially infinite numbers.

Or you could reimplement a multiplication algorithm, which shouldn't take more than a few hours :p

Antzi
  • 12,831
  • 7
  • 48
  • 74
  • 4
    This is pretty weak. GMP over the top. And second paragraph says nothing at all useful. Effectively you say "solve the problem by writing some code". – David Heffernan Sep 02 '14 at 02:08
  • 2
    why use a arbitrary precision while you only need fixed precision? – phuclv Sep 04 '14 at 04:13