Live data from Hacker News

Rust: 128 bit integers preparing to be released

github.com

121–130 of 173 posts

Re: Rust: 128 bit integers preparing to be released

#121

Earlier quoted context omitted.

LLVM supports arbitrarily sized integer types, but sadly it's not exposed in Rust. The only language I've seen where this is possible is Julia (which uses LLVM too).

However, Julia is a dynamic language and Rust is a static one.

As of? Would you mind elaborating?

Re: Rust: 128 bit integers preparing to be released

#122
post #3

What sorts of applications/domains need or benefit from having 128 bit integers?

One example I know of is the Poly1305 MAC algorithm, which at its core multiplies two numbers and reduces the result modulo 2^130-5. The C implementation at https://github.com/floodyberry/poly1305-donna shows three ways to represent the 130-bit numbers during the calculation: as ten 13-bit limbs, as five 26-bit limbs, or as two 44-bit limbs plus one 42-bit limb. In the middle of the multiplication, before the carries are propagated, you need twice the number of bits: the first option needs 26 bits, which can be done with a 16x16->32 bit multiplication. The second option needs 52 bits, which can be done with a 32x32->64 bit multiplication. The last option, however, needs 88 bits, which won't fit in 64 bits; you need a 128-bit integer, so you can do a 64x64->128 bit multiplication.

At least on x86-64, the 64x64->128 bit multiplication is a single instruction, like the 32x32->64 bit and the 16x16->32 bit multiplications. Doing the calculation with only three limbs is clearly faster than doing it with five limbs; to start with, using 3 limbs you need 9 multiplies, while with 5 limbs you have to do 25 multiplies. The carry propagation and reduction steps also take time proportional to the number of limbs.

Re: Rust: 128 bit integers preparing to be released

#123
post #106

Earlier quoted context omitted.

It's built into the type system and checked statically at compile time. In rust, there can only be one 'owner' of a stored value. Ownership can be transferred, borrowed by multiple readers, or borrowed by a single writer. This ensures (at compile time) that there at any given time there is only ever one single writer OR multiple readers. Rust programs are guaranteed to be free of race conditions at compile-time. The…

Right - I get that the compiler ensures it is only accessed by one thread at a time. But what I was asking was at runtime, when ownership transfers how does Rust ensure that writes to the value by the previous owner appear to the new owner before the transfer of ownership appears to the new owner? You can statically guarantee that only one thread owns the object, but you can't statically guarantee the order in which…

> you need to ensure that there is an explicit memory barrier yourself when you transfer the object

To add to/clarify this: I don't think you can transfer an object to another thread in safe Rust code without a primitive that will handle the barriers for you. Static ownership tracing doesn't actually know what threads are, because it doesn't even need to.

Re: Rust: 128 bit integers preparing to be released

#124
post #112

Earlier quoted context omitted.

Yes, really. I mean, I add to IP addresses regularly. How else do you enumerate a subnet (like, what do you think nmap does)? How else do you place, say, twelve machines at 172.17.0.120 through .131? If you're doing string concatenation, you are screwing up. Perhaps it's not enough of a screwup to impact what you do--but definitely wrong enough to impact what I do unless I were to do a lot of extra work in modeling a…

You're not adding addresses together, that doesn't make sense. You're adding ints to addresses, it's a completely different property, even if the representation happens to fit into the same amount of bits. Nothing more than a convenient coincidence.

You're right, I'm not adding addresses together. If you read my post, I say I'm adding to addresses, which you do to--now hold onto your hat--find the next one in sequence. And that, quite obviously, works because they are integers and map to an address space that matches the complete space, from 0x00000000 to 0xFFFFFFFF (and the equivalent 128-bit space for IPv6) of their bit length. It's not "a convenient coincidence". It's the definition of the thing in question.

It's like saying a pointer to RAM isn't an integer. Of course it is, and you add to them every time you de-reference an array in C. That it has additional semantic meaning doesn't mean it stops being a integer. The pedantry you're peddling doesn't fly.

Re: Rust: 128 bit integers preparing to be released

#125
post #100
post #77

Earlier quoted context omitted.

IP addresses are used like integers all the time. Ask your friendly neighborhood sysadmin how a network mask works. (Maybe you want to foreach over an array every time you want to apply one. I'd rather not.)

Not really. They are never added, subtracted, multiplied, or divided. They are never compared for greater-than or less-than. Possibly they are compared for equality. About the only mathematical operations I can think of which are ever done to them are bitwise-anding, bitwise-inclusive-oring, and testing for zero (and, as mentioned, equality).

>They are never compared for greater-than or less-than.

    if ip >= IP(10.34.12.3) && ip 
> They are never added, subtracted,

    if abs(atk1.ip - atk2.ip) 
Netmask are useful, but sometimes doing regular math is a better fit for your problem. Adding an integer to an IP, subtracting IPs or comparing IPs all yield meaningful results.

Re: Rust: 128 bit integers preparing to be released

#126
post #9
post #4

Earlier quoted context omitted.

Finance and scientific computing.

Is this for implementing faster high precision floating point? It didn't mention 128 bit float.

POWER9 has hardware 128 bit float, so likely to start becoming relevant soon.

Re: Rust: 128 bit integers preparing to be released

#128
post #88

Perhaps a stupid question, but can't this be generalized to arbitrary size integers?

It could (there are 3rd party Rust libraries for arbitrary-size integers), but Rust focuses more on low-level features.

Types that have fixed size at compile time are more useful in Rust and can be optimized much better.

Re: Rust: 128 bit integers preparing to be released

#129
post #128
post #88

Perhaps a stupid question, but can't this be generalized to arbitrary size integers?

It could (there are 3rd party Rust libraries for arbitrary-size integers), but Rust focuses more on low-level features. Types that have fixed size at compile time are more useful in Rust and can be optimized much better.

I didn't mean dynamically sized integers. I meant at-compile-time-arbitrarily-sized-integers ;)

Re: Rust: 128 bit integers preparing to be released

#130

Earlier quoted context omitted.

I can think of astronomical measures from a couple hundred years ago that are at least second-accurate. Do you want to have DurationSecondsOnly and Duration as types? =)

It's more an argument for floating point.

Floating point is awful if you care about precision.
Post reply on HN