3 ms·
If we’re talk old arm, then my favorite is the if-then instructions, which would conditionally execute up to three instructions based on a 1-3 bit field indicat
by olliej 6y ago
If we’re talk old arm, then my favorite is the if-then instructions, which would conditionally execute up to three instructions based on a 1-3 bit field indicating which instructions to execute if the control was true or false.
I believe they could be mixed so you could have it.tft - in which case you’d execute the first and third instructions if the condition was true, and the second if it was false.
Needless to say this is challenging instruction to deal with any kind of out of order processor, or any kind of branch predictor (logically a single instruction could produce multiple branches).
I know that in modern arm processors the performance is much worse than a short jump, so I’m guessing that they just give up when they see it instructions and do it in order.
Alas this instruction is gone in arm64. It’s obviously better for cpu designers, but I will miss it forever.
- fanf2 6y agoThat isn’t quite how it worked: every instruction has a 4 bit condition code field. It is usually AL “always” which is omitted in assembler. There wasn’t any limit on how many conditional instructions you could have in sequence, but a branch is usually faster than three or so conditionals. It gets really fun when you combine condition codes with comparisons, or with ALU instructions that set the processor status bits: you can do some quite intricate logic in very little space.
- mtklein 6y agoYou're both right... the 32-bit ARM encoding gives every instruction a 4-bit condition field, but the 16-bit Thumb and mostly-16-bit Thumb2 encodings use the IT instruction to carry the conditions for the next few instructions.
- olliej 6y agoAh cheers! I didn't think about it being thumb only (I never used raw arm32, so in my brain thumb2 is all that existed :D )