3 ms·
Wow, this is very cool and I had no idea it was part of the architecture. It's from 2014, but still news to me! I find myself using (apparently unnecessary) 'L
by leggomylibro 9y ago
Wow, this is very cool and I had no idea it was part of the architecture. It's from 2014, but still news to me!
I find myself using (apparently unnecessary) 'LDR' instructions because of this sort of thing all the time. And that adds up, in Cortex-M chips with kilobytes of program memory.
- pm215 9y agoNote that the Cortex-M chips implement only the Thumb/Thumb2 encodings. Those have different rules for encoding immediates -- the rules this article describes are for the 32-bit ARM (A32) encoding.
- leggomylibro 9y agoOh...well, thanks. That is slightly less exciting, but still probably worth looking into.
- dmitrygr 9y agoThumb-2 immediate encoding is even better (and cooler)! The following classes of constant are available in Thumb-2: •Any constant that can be produced by shifting an 8-bit value left by any number of bits. •Any replicated halfword constant of the form 0x00XY00XY •Any replicated halfword constant of the form 0xXY00XY00 •Any replicated byte constant of the form 0xXYXYXYXY See page 92 here: http://hermes.wings.cs.wisc.edu/files/Thumb-2SupplementReferenceManual.pdf http://hermes.wings.cs.wisc.edu/files/Thumb-2SupplementRefer... There is also MOVT which will set the top 16 bits of a register to any 16-bit value and not affect the bottom 16bits And there is MOVW (MOV.W) which will set the bottom 16 bits to any value and zero the top 16 bits MOVW + MOVT allows loading any 32-bit value in 2 instructions (8 bytes)
- to3m 9y agoI did some off-the-cuff analysis of some random code a couple of years ago and found the traditional ARM constant encoding to be not as good - for that code, at least - as the MIPS-/POWER-style load low/or high business. So if my code is at all representative I'm not surprised they went for MOVW+MOVT in the end: https://news.ycombinator.com/item?id=11607119#11608650 https://news.ycombinator.com/item?id=11607119#11608650 Regarding the 00XY00XY and XY00XY00 forms: I'm going to have to sleep on this, but this is a bit of mystery to me so far. I'm going to have to keep an eye out for those sorts of constants now! Maybe they're actually quite common?? - I suppose this will certainly let you form many kinds of mask useful for SIMD operations.