// construct table of powers of bb*leafSize to use in subdivisions
construct table of powers of bb*leafSize to use in subdivisions
// construct table of powers of bb * leafSize to use in subdivisions
func divisors(m int, b Word, ndigits int, bb Word) []divisor {
	if leafSize == 0 || m <= leafSize {
		return nil
	}
	k := 1
	for words := leafSize; words < m>>1 && k < len(cacheBase10); words <<= 1 {
		k++
	}
	var table []divisor
	var cached bool
	switch b {
	case 10:
		table = cacheBase10[0:k] 
		cached = true
	default:
		table = make([]divisor, k) 
	}
	if table[k-1].ndigits == 0 {
		if cached {
			cacheLock.Lock() 
		}
		var larger nat
		for i := 0; i < k; i++ {
			if table[i].ndigits == 0 {
				if i == 0 {
					table[i].bbb = nat(nil).expWW(bb, Word(leafSize))
					table[i].ndigits = ndigits * leafSize
				} else {
					table[i].bbb = nat(nil).mul(table[i-1].bbb, table[i-1].bbb)
					table[i].ndigits = 2 * table[i-1].ndigits
				}
				larger = nat(nil).set(table[i].bbb)
				for mulAddVWW(larger, larger, b, 0) == 0 {
					table[i].bbb = table[i].bbb.set(larger)
					table[i].ndigits++
				}
				table[i].nbits = table[i].bbb.bitLen()
			}
		}
		if cached {
			cacheLock.Unlock() 
		}
	}
	return table
}
func divisors ( m int , b Word , ndigits int , bb Word ) [ ] divisor { if leafSize == 0 || m <= leafSize { return nil } k := 1 for words := leafSize ; words < m >> 1 && k < len ( cacheBase10 ) ; words <<= 1 { k ++ } var table [ ] divisor var cached bool switch b { case 10 : table = cacheBase10 [ 0 : k ] cached = true default : table = make ( [ ] divisor , k ) } if table [ k - 1 ] . ndigits == 0 { if cached { cacheLock . Lock ( ) } var larger nat for i := 0 ; i < k ; i ++ { if table [ i ] . ndigits == 0 { if i == 0 { table [ i ] . bbb = nat ( nil ) . expWW ( bb , Word ( leafSize ) ) table [ i ] . ndigits = ndigits * leafSize } else { table [ i ] . bbb = nat ( nil ) . mul ( table [ i - 1 ] . bbb , table [ i - 1 ] . bbb ) table [ i ] . ndigits = 2 * table [ i - 1 ] . ndigits } larger = nat ( nil ) . set ( table [ i ] . bbb ) for mulAddVWW ( larger , larger , b , 0 ) == 0 { table [ i ] . bbb = table [ i ] . bbb . set ( larger ) table [ i ] . ndigits ++ } table [ i ] . nbits = table [ i ] . bbb . bitLen ( ) } } if cached { cacheLock . Unlock ( ) } } return table }
construct table of powers of bb*leafSize to use in subdivisions
construct table of powers of bb * leafSize to use in subdivisions
// only compute table when recursive conversion is enabled and x is large // determine k where (bb**leafSize)**(2**k) >= sqrt(x) // create new table of divisors or extend and reuse existing table as appropriate // reuse old table for this conversion // new table for this conversion // extend table // begin critical section // add new entries as needed // optimization: exploit aggregated extra bits in macro blocks // end critical section