0

I am trying to compile a C project to Javascript using Emscripten, and I have very basic code which uses the GCC extension supporting __int128 as seen below:

unsigned __int128 r = (unsigned __int128)a * (unsigned __int128)b;
*hi = r >> 64;
return (uint64_t)r;

Now these variables are being cast from uint64_t pointers which I know are supported in Emscripten, but I get an error on compilation which says

error: __int128 is not supported on this target

So, either I don't know how to enable support or there is no support for this type. If the latter, does anyone have tips for how to mimic 128 bit unsigned integer multiplication without having type support for it? The code doesn't seem to actually need to keep the result in full unsigned 128 bit form, as the line right after the multiplication shifts the number down to a 64 bit unsigned int.

  • I don't think emscripten supports 128-bit int, because even gcc requires a 64-bit computer to support `__int128`. Javascript doesn't have any 64-bit int type – phuclv Jan 07 '17 at 06:37
  • Javascript does not have any such type, but emscripten supports 64-bit int types and all their operations, so they clearly have some way to get around that limitation. – Farhan Kathawala Jan 07 '17 at 06:44
  • Doing 64-bit math on 32-bit computer is very easy and any compiler should have support for maths on types double the width of the register like that. So is emscripten. Things are much different for types 4 times as wide as the basic type – phuclv Jan 07 '17 at 06:46
  • [This answer](https://stackoverflow.com/a/26855440/3386109) shows how to compute the upper 64 bits of a 64-bit x 64-bit multiplication. – user3386109 Jan 07 '17 at 06:58
  • [Efficient Multiply/Divide of two 128-bit Integers on x86 (no 64-bit)](http://stackoverflow.com/q/8776073/995714), [How can I multiply 64 bit operands and get 128 bit result portably?](http://stackoverflow.com/q/25095741/995714) – phuclv Jan 07 '17 at 07:00
  • Possible duplicate of [Reasonably portable way to get top 64-bits from 64x64 bit multiply?](https://stackoverflow.com/questions/26852435/reasonably-portable-way-to-get-top-64-bits-from-64x64-bit-multiply) – phuclv Jun 04 '17 at 15:27

0 Answers0