Program Rust
parse_8digits
This Rust is the input prepared for Aeneas. Modeling choices explains the adaptations from the production source.
15 ///16 /// This is based off the algorithm described in "Fast numeric string to17 /// int", available here: <https://johnnylee-sde.github.io/Fast-numeric-string-to-int/>.18 fn parse_8digits(mut v: u64) -> u64 {19 const MASK: u64 = 0x0000_00FF_0000_00FF;20 const MUL1: u64 = 0x000F_4240_0000_0064;21 const MUL2: u64 = 0x0000_2710_0000_0001;22 v -= 0x3030_3030_3030_3030;23 v = (v * 10) + (v >> 8); // will not overflow, fits in 63 bits24 let v1 = (v & MASK).wrapping_mul(MUL1);25 let v2 = ((v >> 16) & MASK).wrapping_mul(MUL2);26 ((v1.wrapping_add(v2) >> 32) as u32) as u6427 }28 29 /// Parse digits until a non-digit character is found.30 fn try_parse_digits(mut s: &[u8], mut x: u64) -> (&[u8], u64) {Aeneas declaration
The Lean below was mechanically extracted by Aeneas from Rust.
def num.imp.dec2flt.parse.parse_8digits (v : Std.U64) : Result Std.U64 := do
let v1 ← v - 3472328296227680304#u64
let i ← v1 * 10#u64
let i1 ← v1 >>> 8#i32
let v2 ← i + i1
let i2 ← lift (v2 &&& num.imp.dec2flt.parse.parse_8digits.MASK)
let v11 ←
lift (core.num.U64.wrapping_mul i2
num.imp.dec2flt.parse.parse_8digits.MUL1)
let i3 ← v2 >>> 16#i32
let i4 ← lift (i3 &&& num.imp.dec2flt.parse.parse_8digits.MASK)
let v21 ←
lift (core.num.U64.wrapping_mul i4
num.imp.dec2flt.parse.parse_8digits.MUL2)
let i5 ← lift (core.num.U64.wrapping_add v11 v21)
let i6 ← i5 >>> 32#i32
let i7 ← lift (UScalar.cast .U32 i6)
ok (UScalar.cast .U64 i7)Source details
| Declaration | num.imp.dec2flt.parse.parse_8digits |
|---|---|
| File | num/imp/../../dec2flt/parse.rs |
| Lines | 18:0–27:1 |
| Program version | Original program |