Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

parse8Digits

Parse 8 digits, loaded as bytes in little-endian order.

This uses the trick where every digit is in [0x030, 0x39], and therefore can be parsed in 3 multiplications, much faster than the normal 8.

This is based off the algorithm described in "Fast numeric string to int", available here: https://johnnylee-sde.github.io/Fast-numeric-string-to-int/.

parse.parse8Digits
fn parse8Digits(v_: u64) u64

File

Code

fn parse8Digits(v_: u64) u64 {
    var v = v_;
    const mask = 0x0000_00ff_0000_00ff;
    const mul1 = 0x000f_4240_0000_0064;
    const mul2 = 0x0000_2710_0000_0001;
    v -= 0x3030_3030_3030_3030;
    v = (v * 10) + (v >> 8); // will not overflow, fits in 63 bits
    const v1 = (v & mask) *% mul1;
    const v2 = ((v >> 16) & mask) *% mul2;
    return @as(u64, @as(u32, @truncate((v1 +% v2) >> 32)));
}