Open keleshev opened 8 years ago
Hi
I agree, this and your idea of selectable behavior in #4 are nice suggestions. Currently I don't have the necessary time to work on stdint, but if you want to send a patch (or if @mwweissmann wants to do it) I'm all for it.
Most of the <= int64 stuff is pure OCaml already; I'm not quite sure how to elegantly implement the int128 stuff that relies on special amd64 commands via gcc
@mwweissmann what do you mean by "pure OCaml"? What I meant by it is "non-C". The interest in avoiding C is to be able to work with Js_of_ocaml.
All integers <= 64 Bit are stored as "int" or "int64"; we should be able to rewrite all functions on them in "pure OCaml -- without C". The > 64 Bit integers (currently only 128 Bit) use some 64 Bit stuff we cannot tap into in pure OCaml. We would need a "pure OCaml" version of the 128 Bit integer which would also be nice for 32 Bit processors. I currently have no need for rewriting nor implementing the 128-Bit-pure-OCaml stuff but I'm not opposed to either (as long as we do use the 64-Bit CPU on 64 Bit systems).
For the record, the original implementation of Uint128 in the old ocaml-uint library was in pure OCaml. The code is still up in the old repository: https://github.com/andrenth/ocaml-uint/blob/master/lib/uint128.ml
I have some interest in making this happen (this library is a dependency of something I want to run in the browser). From skimming the implementation, this seems pretty doable but I have some questions:
min_int
implementations, as I can't imagine a concrete advantage there. Was this just done for uniformity or was there a more specific reason? If the former, it seems like it might make sense to just toss the C implementations where applicable, if we're writing ones in OCaml anyway.I'm a little unsure how to go about conditional compilation with dune, for the bits where we do need to keep around a C implementation; if anyone has any pointers that would be helpful.
Maybe digestif could be a good example of that: https://github.com/mirage/digestif. It provides two implementations—one in C and one in OCaml.
It would be nice if
stdint
had a fall-back on pure OCaml code for targets that don't support C bindings, e.g. Js_of_ocaml.I just open-sourced my pure OCaml integer implementation, which might be helpful for that:
https://github.com/keleshev/Integers.ml