MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / DivideThreeWordsByTwo

Function DivideThreeWordsByTwo

extra/yassl/taocrypt/src/integer.cpp:358–388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

356// do a 3 word by 2 word divide, returns quotient and leaves remainder in A
357template <class S, class D>
358S DivideThreeWordsByTwo(S* A, S B0, S B1, D* dummy_VC6_WorkAround = 0)
359{
360 // estimate the quotient: do a 2 S by 1 S divide
361 S Q;
362 if (S(B1+1) == 0)
363 Q = A[2];
364 else
365 Q = D(A[1], A[2]) / S(B1+1);
366
367 // now subtract Q*B from A
368 D p = D::Multiply(B0, Q);
369 D u = (D) A[0] - p.GetLowHalf();
370 A[0] = u.GetLowHalf();
371 u = (D) A[1] - p.GetHighHalf() - u.GetHighHalfAsBorrow() -
372 D::Multiply(B1, Q);
373 A[1] = u.GetLowHalf();
374 A[2] += u.GetHighHalf();
375
376 // Q <= actual quotient, so fix it
377 while (A[2] || A[1] > B1 || (A[1]==B1 && A[0]>=B0))
378 {
379 u = (D) A[0] - B0;
380 A[0] = u.GetLowHalf();
381 u = (D) A[1] - B1 - u.GetHighHalfAsBorrow();
382 A[1] = u.GetLowHalf();
383 A[2] += u.GetHighHalf();
384 Q++;
385 }
386
387 return Q;
388}
389
390
391// do a 4 word by 2 word divide, returns 2 word quotient in Q0 and Q1

Callers

nothing calls this directly

Calls 3

GetLowHalfMethod · 0.45
GetHighHalfMethod · 0.45
GetHighHalfAsBorrowMethod · 0.45

Tested by

no test coverage detected