n2_new = (n_old + (1 << bit))^2 = n2_old + (n_old << (bit + 1)) + (1 << (bit*2))
Then compare it with the source operand, and if it's greater or equal: 1) set the bit in the result 2) update n2_old with n2_new
It can be done in n/2 or perhaps n clock cycles with a suitable microcode instruction set and ALU. With some effort it can be optimized to reduce n to the index of the leftmost set bit in the operand.
[1] https://www.masswerk.at/spacewar/inside/insidespacewar-pt6-g...
do lookups in large tables ever (practically, not theoretically) take one clock cycle?
If there's a large lookup table, it would have to come from memory, which might mean cache and memory hierarchy delays, right?
IIRC IBM z/Arch processors (AFAIK they are internally similar to POWER) have clock limited to around 5 GHz or so, so that L1 cache lookup costs only one cycle (a design requirement).
For example, z14 has 5.2 GHz clock rate and 2x128 kB data and instruction L1 caches.
:-D
It's a topic that has been explored quite a bit in science fiction literature.
[1] Britannica: Silicon
Yes, this solves the stated issue about huge lookup tables.
> A planet size CPU that runs at .5 hz but can work on impossibly large numbers.
This doesn't make much sense to me, though.
If your goal is "any algorithm", you'll often have to go a lot slower than .5Hz. A hash-calculating circuit that's built out of a single mountain of silicon could have a critical path that's light-years long.
But if your goal is just "work on impossibly large numbers", but it's okay to take multiple ticks, then there's no reason to drag the frequency down that low. You can run a planet-scale CPU at 1GHz. CPUs have no need for signals to go all the way across inside a single tick.
Forty-two for example?
Such tables may be infeasible, though. While a int8 -> int8 table only needs 256 bytes, an int32 -> int32 needs 16 gigabytes.