In 1949, ENIAC was the primary programmable laptop to calculate a decimal growth of π. It took ENIAC 70 hours to find out 2,035 digits. Mark Ablovatskii questioned if a 1974-era four-bit Intel 4040 microprocessor may calculate digits of Pi sooner than the ENIAC. The outcomes have been shocking!

The 4-bit Intel 4040 succeeded the unique 4004 microprocessor. It ran at 740 kilohertz and will obtain 92,500 directions per second. The 4040 included a number of enhancements that helped Ablovatskii’s aim, like AND/OR directions, a barely bigger stack, eight new registers, and help for 2 banks of ROM. Nevertheless, it didn’t have multiplication, division, or shift directions!

For comparability, the ENIAC ran at 100 kilohertz and carried out about 5,000 additions or 50 multiplications per second. However its accumulators have been additionally 10 digits! The 25-year hole could make this mission seem like a mismatched contest. Nevertheless, Ablovatskii’s first effort would have the 4040 calculating digits for years!

Ablovatskii explains the algorithm used (📷: mark.engineer)

A number of strategies exist to calculate the digits of Pi. For instance, a spigot algorithm retains an array of numbers in reminiscence. The trade-off with this technique is that you simply want an quantity of reminiscence proportional to the variety of digits you propose to calculate. For the reason that 4040 solely has 1,280 bytes of RAM, it will not be potential to get 2,035 digits of Pi utilizing this kind of algorithm.

Total, Ablovatskii thought-about seven strategies earlier than selecting an algorithm from Fabrice Bellard. This one is a sensible implementation that may calculate π to the millionth place.

Earlier than growing the code to do the calculations, Ablovatskii needed to create a toolchain and emulator. Each efforts have been extensions of Ablovatskii’s earlier work on a 4004-based mission. (Additionally, a Pi calculator!) The toolchain consists of a pre-processor, compiler, and linker. The emulator implementation used JavaScript.

4040, STM32F4, and translation {hardware} (📷: mark.engineer)

This mission centered across the 4040 microprocessor. Nevertheless, a contemporary STM32 supplied an emulated reminiscence machine to the classic processor and a USB interface again to the PC so we may see the ensuing digits.

With instruments in hand, Ablovatskii’s first effort yielded 2,035 digits of Pi! Nevertheless, finishing the duty would take an estimated 14.5 years or roughly 127,000 hours on the 4040’s precise clock velocity. It doesn’t take in-depth math data to appreciate that point is barely longer than ENIAC’s 70-hour benchmark.

By means of an in depth iterative cycle of profiling and optimizing code, Ablovatskii ultimately lowered the computation time to 69 hours, 28 minutes, and 31 seconds — an enchancment of 180,000%!

Outcomes! (📷: mark.engineer)

Try Ablovatskii’s weblog put up on the mission for detailed breakdowns of the mathematics behind this achievement!