by adrian_b · 2y ago · 0 comments
Those 4 instructions, with their mnemonics in the Intel/AMD x86 CPUs are:
LZCNT (leading zero bits count), which was named "The position of the most significant digit" in this manual.
POPCNT (population count), which was named "Sideways adder" in Mark I (it is listed in a table at the end of this manual).
RDRAND (read random number), which was named "The random numbers generator" in this manual.
RDTSC (read time stamp counter), "The clock" in this manual.
It is said that some or even all of these less usual instructions had been suggested by Alan Turing himself to the designers of Ferranti Mark I.
Another notable instruction of Ferranti Mark I was used to produce an audible beep, like the internal loudspeaker of the older IBM PC compatibles, "The hooter" in this manual.
I've heard this a few times, do you have anything that explains this?
The condition has remained in force later, so all its successors, like CDC 7600 (1969) or Cray-1 (1976), have included POPCNT.
POPCNT has been added to the x86 ISA by AMD, in "Barcelona", in 2007, presumably because some customer for AMD Opteron has requested it. This happened during the period when the AMD server CPUs were much better than the Intel Xeons, so any wise customer was buying Opterons, not Xeons. Intel has followed AMD and it has added POPCNT to Nehalem, in 2008/2009 (for server CPUs, Nehalem has been the first that was better for any purpose than the AMD server CPUs, unlike for consumer CPUs, where Intel had surpassed AMD already since the middle of 2007, with Core 2).
Might have been Cray, they were using Opteron in that era.
Anyway.... if you have cipher text that has been scrambled by a linear-feedback shift register, you can take two copies of the cipher text, shift one copy by N bits, XOR them together, and do a pop count on the result. Repeat for bunch of different N's. For some N that corresponds to the length of the LFSR the auto-correlation will be much better. So now you have at least that to go on... of course you don't know the feedback equation and you don't know the initialization constant, but you have the start of a handle.
It has you start programming in binary, and then just tells you how to make your own mnemonics to substitute for having to write out each 8-bit input. So you end up picking them based on what commands appear most often in practice.
One instruction I ended up creating was JNEQCI, "jump if not equal, comparing to immediate". (jump if not equal where the first operand is treated as a register and the second as a constant/immediate value)
[1] from LevelHead, and similar to nand2tetris in that you build a computer from its circuits and then program it
Exapunks and Opus Magnum are probably the more casual ones to get into, but everything they make is awesome and pretty challenging.
The 8 index registers ("B-tube") are called B0 to B7 in this manual.
The B0 index register is hardwired to have the read-only value "0".
A read-only null register continues to be used in many modern instruction sets, e.g. in POWER or in Aarch64.
popcnt of a word counts the number of bits that are "1"
https://www.talkchess.com/forum3/viewtopic.php?t=38521
the NSA wanted to do cryptanalysis on intercepted messages, and since the CDC 6000 had 60-bit words, one word was enough to store most alphabets they were interested in. They were able to:
Split a message into lines
Set a bit for each unique character they encountered per line
Use popcount to count the distinct characters
Use the count as a hash for further cryptanalysis
Curiously, popcount seems to have disappeared from instruction sets between the mid-1970s and the mid-2000s.(of course for all we know this could be NSA disinformation ;)
That's the answer to the NSA question. There are other uses described here https://vaibhavsagar.com/blog/2019/09/08/popcount/ including for Hamming codes and Neural nets and more.