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 standard library.
std › fmt › float › mul_128_256_shift Private Function mul_128_256_shift Doc Source Private Function std.fmt.float.mul_128_256_shift
fn mul_128_256_shift (a : *const [2 ]u64 , b : *const [4 ]u64 , shift : u32 , corr : u32 ) [4 ]u64 Params a : *const [2 ]u64 b : *const [4 ]u64 shift : u32 corr : u32 File fmt/float.zig: 583
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630 fn mul_128_256_shift (a : *const [2 ]u64 , b : *const [4 ]u64 , shift : u32 , corr : u32 ) [4 ]u64 {
std .debug .assert (shift > 0 );
std .debug .assert (shift < 256 );
const b00 = @as (u128 , a [0 ]) * b [0 ];
const b01 = @as (u128 , a [0 ]) * b [1 ];
const b02 = @as (u128 , a [0 ]) * b [2 ];
const b03 = @as (u128 , a [0 ]) * b [3 ];
const b10 = @as (u128 , a [1 ]) * b [0 ];
const b11 = @as (u128 , a [1 ]) * b [1 ];
const b12 = @as (u128 , a [1 ]) * b [2 ];
const b13 = @as (u128 , a [1 ]) * b [3 ];
const s0 = b00 ;
const s1 = b01 +% b10 ;
const c1 : u128 = @intFromBool (s1 < b01 );
const s2 = b02 +% b11 ;
const c2 : u128 = @intFromBool (s2 < b02 );
const s3 = b03 +% b12 ;
const c3 : u128 = @intFromBool (s3 < b03 );
const p0 = s0 +% (s1 << 64 );
const d0 : u128 = @intFromBool (p0 < b00 );
const q1 = s2 +% (s1 >> 64 ) +% (s3 << 64 );
const d1 : u128 = @intFromBool (q1 < s2 );
const p1 = q1 +% (c1 << 64 ) +% d0 ;
const d2 : u128 = @intFromBool (p1 < q1 );
const p2 = b13 +% (s3 >> 64 ) +% c2 +% (c3 << 64 ) +% d1 +% d2 ;
var r0 : u128 = undefined ;
var r1 : u128 = undefined ;
if (shift < 128 ) {
const cshift : u7 = @intCast (shift );
const sshift : u7 = @intCast (128 - shift );
r0 = corr +% ((p0 >> cshift ) | (p1 << sshift ));
r1 = ((p1 >> cshift ) | (p2 << sshift )) +% @intFromBool (r0 < corr );
} else if (shift == 128 ) {
r0 = corr +% p1 ;
r1 = p2 +% @intFromBool (r0 < corr );
} else {
const ashift : u7 = @intCast (shift - 128 );
const sshift : u7 = @intCast (256 - shift );
r0 = corr +% ((p1 >> ashift ) | (p2 << sshift ));
r1 = (p2 >> ashift ) +% @intFromBool (r0 < corr );
}
return .{ @truncate (r0 ), @truncate (r0 >> 64 ), @truncate (r1 ), @truncate (r1 >> 64 ) };
}