T = round_half_up(M / dv) clamped to kPolyOne, for M = (mhi, mlo) and 0 < dv < 2^63 (polyLineT28's quotient step).
Exact: the 64-bit remainder state s of the shift-subtract below satisfies s < dv at the start of every step, so s <- 2s + bit never reaches 2^64 and the loop computes q = floor(M/dv), r = M mod dv. Requires dv > 0: polyLineT28 never passes 0 (D == 0 makes M == 0, which returns before the call). Kept out of line so polyLineT28's two call sites (normal and huge edges) share one copy: on AVR that measured smaller AND faster than one inlined loop with a runtime-selected divisor (the register allocator spills inside it). External-linkage inline (not static), like the polyClz32/polyTopBit128 helpers it calls, so the inline polyLineT28 refers to the same entity in every TU (ODR); kPolyOne is only read as a constant (no odr-use).
437 {
438 fl::u32 m3 = (fl::u32)(mhi >> 32), m2 = (fl::u32)mhi;
439 fl::u32 m1 = (fl::u32)(mlo >> 32), m0 = (fl::u32)mlo;
441
442
443
444 const int t = (top < 94) ? top : 93;
445
446
447
448
449 const int k = 127 -
t;
450 const int kl = k >> 5;
451 const int kb = k & 31;
452 {
453 fl::u32 n3, n2, n1, n0;
454 if (kl >= 3) { n3 = m0; n2 = 0; n1 = 0; n0 = 0; }
455 else if (kl == 2) { n3 = m1; n2 = m0; n1 = 0; n0 = 0; }
456 else if (kl == 1) { n3 = m2; n2 = m1; n1 = m0; n0 = 0; }
457 else { n3 = m3; n2 = m2; n1 = m1; n0 = m0; }
458 if (kb) {
459 const fl::u32 h3 = n2 >> (32 - kb);
460 const fl::u32 h2 = n1 >> (32 - kb);
461 const fl::u32 h1 = n0 >> (32 - kb);
462 n3 = (n3 << kb) | h3;
463 n2 = (n2 << kb) | h2;
464 n1 = (n1 << kb) | h1;
465 n0 = n0 << kb;
466 }
467 m3 = n3; m2 = n2; m1 = n1; m0 = n0;
468 }
469
470
471
472
473
474
475 const fl::u32 d1 = (fl::u32)(dv >> 32), d0 = (fl::u32)dv;
476 fl::u32 s1 = 0, s0 = 0;
477 fl::u32 q1 = 0, q0 = 0;
478 for (
int i =
t; i >= 0; --i) {
479 const fl::u32 bit = m3 >> 31;
480 m3 = (m3 << 1) | (m2 >> 31);
481 m2 = (m2 << 1) | (m1 >> 31);
482 m1 = (m1 << 1) | (m0 >> 31);
483 m0 = m0 << 1;
484 const fl::u32 sh = s1 << 1, sl = s0 << 1;
485 s1 = sh | (s0 >> 31);
486 s0 = sl | bit;
487 const fl::u32 ge = (s1 > d1) || (s1 == d1 && s0 >= d0);
488 if (ge) {
489 const fl::u32 sb = s0 - d0;
490 s1 -= d1 + (fl::u32)(sb > s0);
491 s0 = sb;
492 }
493 const fl::u32 qh = q1 << 1, ql = q0 << 1;
494 q1 = qh | (q0 >> 31);
495 q0 = ql | ge;
496 }
497
498
499 const fl::u32 r1 = (s1 << 1) | (s0 >> 31), r0 = s0 << 1;
500 if ((s1 >> 31) != 0 || r1 > d1 || (r1 == d1 && r0 >= d0)) {
501 const fl::u32 qb = q0 + 1;
502 q1 += (fl::u32)(qb < q0);
503 q0 = qb;
504 }
507 return (fl::i32)q;
508}
int polyTopBit128(fl::u32 m3, fl::u32 m2, fl::u32 m1, fl::u32 m0) FL_NO_EXCEPT
Index (0..127) of the highest set bit of a 128-bit value held in four 32-bit lanes (m3 most significa...
static const fl::i32 kPolyOne
Full-pixel coverage in T units (see polyLineT28).