3 ms·
> Unfortunately, this requires writing assembly, because writing high-performance arithmetic is not possible in Go — it's simply not a design goal of the langua
by smegel 9y ago
> Unfortunately, this requires writing assembly, because writing high-performance arithmetic is not possible in Go — it's simply not a design goal of the language. (There are a few reasons, most notably that there's no way to directly compute the (128-bit) product of 64-bit integers.)
Can any language do this, without also calling through some library that has hand-crafted assembly in it? Will assigning the product of 2 longs in C to a long long result in the correct instructions?
- hmrten 9y agoForth has great support for double width and mixed width intermediate operations like / which does xy/z with x*y being 128 bits on a 64 bit Forth. Was mainly intended for fixed point operations.
- ekiru 9y agoIn nightly builds of Rust (on 64-bit x86 platforms; no idea about support elsewhere), `(a as u128) * (b as u128)` where `a` and `b` are 64-bit integers will compile to a single `mul` instruction: see https://godbolt.org/g/Be7ncs https://godbolt.org/g/Be7ncs
- giovannibajo1 9y agoGCC supports 128 bit integers as an extension to the language.