do a 4 word by 2 word divide, returns 2 word quotient in Q0 and Q1
| 857 | |
| 858 | // do a 4 word by 2 word divide, returns 2 word quotient in Q0 and Q1 |
| 859 | static inline void AtomicDivide(word &Q0, word &Q1, const word *A, word B0, word B1) |
| 860 | { |
| 861 | if (!B0 && !B1) // if divisor is 0, we assume divisor==2**(2*WORD_BITS) |
| 862 | { |
| 863 | Q0 = A[2]; |
| 864 | Q1 = A[3]; |
| 865 | } |
| 866 | else |
| 867 | { |
| 868 | word T[4]; |
| 869 | T[0] = A[0]; T[1] = A[1]; T[2] = A[2]; T[3] = A[3]; |
| 870 | Q1 = SubatomicDivide(T+1, B0, B1); |
| 871 | Q0 = SubatomicDivide(T, B0, B1); |
| 872 | |
| 873 | #ifdef DEBUG |
| 874 | // multiply quotient and divisor and add remainder, make sure it equals dividend |
| 875 | assert(!T[2] && !T[3] && (T[1] < B1 || (T[1]==B1 && T[0]<B0))); |
| 876 | word P[4]; |
| 877 | AtomicMultiply(P, Q0, Q1, B0, B1); |
| 878 | Add(P, P, T, 4); |
| 879 | assert(memcmp(P, A, 4*WORD_SIZE)==0); |
| 880 | #endif |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | // for use by Divide(), corrects the underestimated quotient {Q1,Q0} |
| 885 | static void CorrectQuotientEstimate(word *R, word *T, word &Q0, word &Q1, const word *B, unsigned int N) |
no test coverage detected