GithubHelp home page GithubHelp logo

Comments (4)

kripken avatar kripken commented on July 24, 2024

Nice stuff!

I would support adding this as an option here in upstream. If you can, please file a pull request with the proper commit(s).

Note that something very close to this is already possible, with TYPED_ARRAYS == 2. In that case, typed arrays are used with a shared buffer so that you can mix reads and writes of different types, using normal C-style heap access. The generated code is endian-dependent though, and requires a browser that supports typed arrays, which is why I am in favor of adding your approach as an option.

from emscripten.

opichals avatar opichals commented on July 24, 2024

Thanks! Will prepare a proper pull request to get this into master as an option.

Eh... good that I didn't invest time to understand what the HAS_TYPED_ARRAYS did before as otherwise I might have not cared to implement anything. On the other hand I think that wouldn't work in my case anyway as there could have been unaligned heap accesses for 16 and 32 bit numbers (though I could have adjusted the C code of course - which I tried to stay away, the only thing I added is a check for not doing malloc(0)... but for compatibility I would recommend returning a valid pointer in such a case, just as libc does).

Also I think the generated code my patch is producing is endian dependent as well as it stores the multibyte datatypes in big-endian format and I am not 100% sure it would work as is when compiled from a little-endian machine LLVM output. Like for example how would the ntohl() call work in such a case. I assume it would not flip the endianess correctly and therefore the fact I use big-endian heap would not work correctly. I am thinking right here?

from emscripten.

kripken avatar kripken commented on July 24, 2024

Yes, endianness is a problem with that kind of code.

I just added a runtime check for the typed arrays = 2 case, since it also depends on endianness. Your new code should do the same I guess.

from emscripten.

juj avatar juj commented on July 24, 2024

Type punning pointers is guaranteed in the typed arrays=2 mode, which asm.js is based on, and we require little endian support (out of practicality and visibility on our dev platforms, not out of necessity really), so it looks like the items discussed here are implemented. If someone wants to champion to add big endian support, let's operate on that as a separate item.

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.