News for hackers. Stuff that matters.
Re:ARM immediate value encoding (2014) by pm215 on Tuesday January 30, 2018 @05:12PM (#16269583)
Note 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.
Re:ARM immediate value encoding (2014) by leggomylibro on Tuesday January 30, 2018 @06:27PM (#16270074)
Oh...well, thanks. That is slightly less exciting, but still probably worth looking into.
Re:ARM immediate value encoding (2014) by dmitrygr on Tuesday January 30, 2018 @06:40PM (#16270143)
Thumb-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-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)

Re:ARM immediate value encoding (2014) by to3m on Tuesday January 30, 2018 @08:12PM (#16270544)
I 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

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.