6 ms·
ARM immediate value encoding
- hrydgard 11y agoThis is classic 32-bit ARM immediates. Modern 32-bit arm also have movw and movt, which load the bottom and top 16 bits of a register. Combining the two you can load any 32-bit value in two instructions. Classic 8-bit+rotation immediates are still used for arithmetic immediates though. ARM64 is different. For arithmetic, you get a 12-bit value with an optional left-shift by 12, for bitwise instructions you get an arbitrary string of 1's at any position you want (including rotated), which turns out to be very useful, while for loading values, just like in modern ARM-32, you load 16 bits at a time using movw, movt and movk to reach the higher parts of a register. You have to string together four of those to load a fully general 64-bit value, but that's pretty rare in practice.
- monocasa 11y agoIn addition to those, there's PC relative loads from a literal pool. This is what you end up using 9 times out of ten to load a full register rather than filling it in piecemeal with immediates.
- ant6n 11y agoIn aarch64, the bitwise operation immediates are a bit more complicated. From the documentation Is the bitmask immediate. Such an immediate is a 32-bit or 64-bit pattern viewed as a vector of identical elements of size e = 2, 4, 8, 16, 32, or 64 bits. Each element contains the same sub-pattern: a single run of 1 to e-1 non-zero bits, rotated by 0 to e-1 bits. This mechanism can generate 5,334 unique 64-bit patterns (as 2,667 pairs of pattern and their bitwise inverse). Because the all-zeros and all-ones values cannot be described in this way, the assembler generates an error message. http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0802b/AND_log_imm.html http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.... I feel like I have a vague memory of a single byte being repeated with some specific pattern for some instruction, but I can't find it anymore.
- joosters 11y agoARM, like other RISC architectures MIPS and PowerPC, has a fixed instruction size of 32 bits. This is a good design decision, and it makes instruction decode and pipeline management much easier than with the variable instruction size of x86 or 680x0. Actually, it turned out not to be that good a decision. The generated code is far less compact than x86, and this has costs which outweigh the advantage of simpler instruction decode. CPU speeds increased far faster than memory, so the costs of storing and fetching more instruction data grew larger and larger. As a result, ARM experimented with other more compact encoding schemes, e.g. Thumb.
- arielb1 11y agox86-64 somehow manages to be less compact than ARM while still being variable-length. Thumb is still much saner than x86/x86-64.
- Narishma 11y agoYou mean Thumb-2?
- arielb1 11y agoNo, even vanilla ARM. x86-64 instructions are 3-5 bytes in size and compilers don't use complex instructions effectively.
- pcwalton 11y agoThis is correct. Thumb-2 is the only actual compact instruction set in wide use. x86-64 doesn't even come close to being as efficient; between ARM and x86-64, it's a wash. It's certainly possible to design a CISC ISA (or maybe even a RISC one) that's optimized for compactness. x86 isn't that, though. Maybe it was in the 16-bit era, in a hypothetical future where BCD instructions were used a lot.
- vegabook 11y agoInteresting. It reminds me of how (simple) compression schemes save disk space and speed throughput on modern database systems. Moving data around the memory hierarchy is the bottleneck in all systems it seems, from registers, via cache, RAM, (soon x-point,) SSDs, all the way to spinning disks and indeed offsite storage. Some form of space optimisation seems to pay off both ways across this hierarchy even if it is more compute intensive. It was not always so: in the 90s and earlier, compression tended to have had a speed tradeoff.
- kabdib 11y agoIf you want to see something truly wacky and inspired, look at how the Transputer loads constants. There's an instruction that does this, IIRC, four bits at a time, with rules for what happens to previously loaded bits in terms of shifting, sign extending and so forth. Basically you built up a constant 4 bits at a time. Most of the time you want things like 1, 2, 4, -1, 0 and so forth, so it made sense. Of course, being a stack machine, this is easier (no register to address, just a top-of-stack value). I don't know why the Transputer didn't take off. Probably Occam (which was interesting, but weird). I know of at least one TV set top box that used the T800, but don't know of any other design wins the chip had.
- PhantomGremlin 11y agoI don't know why the Transputer didn't take off. I think for two reasons. 1) "too weird". This eventually dooms all of the goofy architectures like Transputer, IA-64, Transmeta, STI Cell, etc. Nobody wants to deal with something radically different unless there are compelling long-term reasons to do so. Granted, that's a little bit of a chicken-and-egg argument. Without adoption there won't be any long-term existence of an architecture. 2) Support tools and infrastructure. Intel and ARM have an incredible variety of support software. Any new architecture is at a disadvantage unless and until all that supporting stuff is written and works well. This means compilers, IDEs, development hardware, etc. Normally the tools for a new architecture are laughably primitive compared to existing environments. Which puts early adopters at a serious disadvantage. We're in an x86-64 / ARM duopoly now. Nothing else is really relevant. Do you see anything that could change that in the near future? I sure don't.
- ant6n 11y agoWe could get a monopoly. Maybe OpenRisc/Risc-V will rise. Who'da thunk in 1990 that Linux would rise?
- pmalynin 11y agoI'd love to see an Isa that uses something like a modified Huffman coding. That way you can have jump instructions have 30 bit immediates.
- phs2501 11y agoSPARC. The CALL instruction takes a 30-bit immediate. http://www.cs.rochester.edu/~scott/456/local_only/sparcv7.pdf http://www.cs.rochester.edu/~scott/456/local_only/sparcv7.pd... Also the Mill talks seem to indicate that their (variable-length) instruction encoding is machine-generated to be as efficient as possible.