View source code
Display the source code in dmd/backend/divcoeff.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function dmd.backend.divcoeff.udiv_coefficients

Find coefficients for Algorithm 4.2: Optimized code generation of unsigned q=n/d for constant nonzero d

extern(C) bool udiv_coefficients (
  int N,
  ulong d,
  int* pshpre,
  ulong* pm,
  int* pshpost
) nothrow @safe;

Input

N 32 or 64 (width of divide) d divisor (not a power of 2)

Output

*pshpre pre-shift *pm factor *pshpost post-shift

Returns

true Use algorithm: t1 = MULUH(m, n) q = SRL(t1 + SRL(n - t1, 1), shpost - 1)

false Use algorithm: q = SRL(MULUH(m, SRL(n, shpre)), shpost)

Authors

Walter Bright

License

Boost License 1.0