int ProbableCunninghamChainTest(vec_uint4 n[3], int fSophieGermain, int fFermatTest, int *chainLength) { vec_uint4 one[3] = { {0,0,0,0}, {0,0,0,0}, { 0,0,0,1 } }; *chainLength = 0; if (fSophieGermain) { _mpm_sub(n, n, one, 3); } else { _mpm_add(n, n, one, 3); } if (!FermatPrimeProbabilityTest(n)) { return 0; } while (1) { (*chainLength)++; // n = n * 2 MPM_SHL_BITS_SMALL(n, n, 3, 1); if (fSophieGermain) { // n = n * 2 + 1 n[2] = si_or(n[2], one[2]); } else { // n = n * 2 - 1 _mpm_sub(n, n, one, 3); } if (!EulerLagrangeLifchitzPrimalityTest(n, fSophieGermain)) { return 1; } #if 0 if ( if fFermatTest: c, f = FermatPrimeProbabilityTest(n) else: c, f = EulerLagrangeLifchitzPrimalityTest(n, fSophieGermain) if not c: return True, chainLength, f #endif } }
UTItype __udivmodti4 (UTItype num, UTItype den, UTItype * rp) { qword shift = si_from_uint (count_leading_zeros (den) - count_leading_zeros (num)); qword n0 = si_from_UTItype (num); qword d0 = si_from_UTItype (den); qword bit = si_andi (si_fsmbi (1), 1); qword r0 = si_il (0); qword m1 = si_fsmbi (0x000f); qword mask, r1, n1; d0 = si_shlqbybi (si_shlqbi (d0, shift), shift); bit = si_shlqbybi (si_shlqbi (bit, shift), shift); do { r1 = si_or (r0, bit); // n1 = n0 - d0 in TImode n1 = si_bg (d0, n0); n1 = si_shlqbyi (n1, 4); n1 = si_sf (m1, n1); n1 = si_bgx (d0, n0, n1); n1 = si_shlqbyi (n1, 4); n1 = si_sf (m1, n1); n1 = si_bgx (d0, n0, n1); n1 = si_shlqbyi (n1, 4); n1 = si_sf (m1, n1); n1 = si_sfx (d0, n0, n1); mask = si_fsm (si_cgti (n1, -1)); r0 = si_selb (r0, r1, mask); n0 = si_selb (n0, n1, mask); bit = si_rotqmbii (bit, -1); d0 = si_rotqmbii (d0, -1); } while (si_to_uint (si_orx (bit))); if (rp) *rp = si_to_UTItype (n0); return si_to_UTItype (r0); }