GithubHelp home page GithubHelp logo

Comments (7)

kripken avatar kripken commented on July 24, 2024

It should indeed be simple to add. However, these instructions are meant to be very fast (implemented using native CPU instructions dedicated to them), and emulating them in JS will be very slow. So I am curious what optimization generates them, perhaps the best thing is to avoid it somehow.

from emscripten.

max99x avatar max99x commented on July 24, 2024

I haven't looked into it, but I'm guessing it won't be generated unless the overflow is significant, in which case doing it the fast way will simply produce incorrect code, and the unoptimized version might be doing the same extra operations as we'd be doing by implementing it.

from emscripten.

kripken avatar kripken commented on July 24, 2024

I agree. But my question is then, how does one write C/C++ code that actually cares about overflows? The C/C++ standards were very careful to not allow such things to be detected directly. Are these compiler-specific extensions perhaps? The only alternative I can think of is that the compiler detects code that manually checks for overflows, like

void func(char x) {
  x++;
  if (x == 0) printf("overflow!");
}

and optimizes that, which seems unlikely but possible. Would be simple to just tell the compiler to not perform that optimization though, since it won't help us here (in fact it will hurt).

from emscripten.

max99x avatar max99x commented on July 24, 2024

This is - again - a total guess on my part, but it might be translating int64_t additions into two manual int32_t additions with carry/overflow correction on a 32-bit machine - unoptimized is a straightforward implementation while optimized is one with intrinsics.

from emscripten.

kripken avatar kripken commented on July 24, 2024

Hmm, that could be. If so, it sounds like specialization for a very specific architecture (one that doesn't have 64-bit math ops) so hopefully something we can avoid. (Also, we should try to avoid 64-bit math anyhow because it's a poor fit for JavaScript's native types.)

No harm in implementing this stuff, though.

from emscripten.

kripken avatar kripken commented on July 24, 2024

We added support for this (but it can't be fast...)

from emscripten.

kripken avatar kripken commented on July 24, 2024

We should now have all the overflow add/mul intrinsics on incoming.

from emscripten.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.