Avatar ·

How does Rust handle 128-bit integers `i128` on a 64-bit system? Does it affect performance?

Hi everyone! I'm learning Rust and came across the `i128` type (128-bit signed integer). I'm writing a parser for large numbers from JSON, and I need to store values like `2^64` and larger. I'm used to x86-64 processors having 64-bit registers, and I don't understand how the processor performs operations with 128-bit numbers at all. I wrote a simple benchmark (using `cargo bench`) that measures addition of two `i128` and two `i64`: ```rust #![feature(test)] extern crate test; #[bench] fn add_i64(b: &mut test::Bencher) { let a: i64 = 1234567890123456789; let b_val: i64 = 987654321098765432; b.iter(|| { let c = a + b_val; test::black_box(c); }); } #[bench] fn add_i128(b: &mut test::Bencher) { let a: i128 = 123456789012345678901234567890123456789;