Sunday, January 12, 2014

Geek: some ARM cleverness for immediate operands...

Geek: some ARM cleverness for immediate operands...  I'm currently reading a lot on computer instruction sets, as I have a goal of building a computer from component parts.  I've chosen a simple architecture for my machine, based on my reading over the past few months: a 32 bit RISC machine.  The ARM family is good example of a successful RISC design, so I've been looking at it.  I'd never written ARM assembly language before, so the entire thing is new to me.  Yesterday I ran across this discussion of ARM's 12 bit immediate operand encoding, an ingenious approach to maximally exploiting those 12 measly bits.

If you're familiar with immediate values from other machine's instruction sets, you know that generally speaking they are simply constant values with a bit length shorter than the computer's word length (if the processor has fixed word lengths, as ARM does) or equal to the computer's word length (if the processor has variable instruction length, as the x86 does).  There are quite a few machines with variable-length instruction sets that implement both variations of immediate values.

The ARM, though, does something that is unique, so far as I'm aware: rather than use simple constant values, its 12 bit immediate value is divided into two fields: a 4 bit rotation specifier and an 8 bit integer.  The rotation specifier is internally multiplied by two, then used as a rotate right operand, with the result being 32 bits long.  For example, the immediate value 0x345 becomes 0x45 rotate right 6 = 0x14000001.  This mechanism allows that 12 bit immediate to encode quite a few values within a 32 bit space, including every possible single bit value – a very useful capability indeed, and without the need for a special bit level instruction.

Very clever, ARM folks!

PS.  The site linked above has a very nice interactive demonstrator for the ARM immediate value encoding...

No comments:

Post a Comment