0

In an ARM Processor with 32-bit instruction size, I understand that ARM can use 8-bit to store the value and 4-bits for bit rotation instructions (bit-shift the 8-bit value by multiples of 2) in order to gain a much better range than just simple 8/12-bit representation for immediate values.

While I understand the process of how ARM can get the extended range, I am interested to know if there is a way to easily check if our chosen immediate value is valid under this scheme. What kind of characteristics of the number (be it in binary or hex) are we looking out for that can help us determine if this value is valid under ARM's bit-rotation scheme?

Edit: Here is a link to the concept I am talking about.

Ymi
  • 609
  • 6
  • 18
  • Note that for `mov`, most ARM assemblers will silently assemble it into `mvn` if the bitwise inverse of the constant fits. And there's `movw` on newer processor. And Thumb mode can use repeating-bit-pattern immediates for MOV, I think. ([How can ARM's MOV instruction work with a large number as the second operand?](https://stackoverflow.com/a/26762878)). Are you just wanting to check for the simple classic case of rotation? I'd go for `rbit` / `clz` (GNU C __builtin_ctz) and use that as a shift count to bring the non-zero bits to the bottom of the register, and check that it's `<= 0xffU` – Peter Cordes Apr 23 '21 at 08:55
  • Except you need to check that it works for an *even* rotate-count, among other problems with my first idea :P. PaulR's deleted answer on the linked duplicate had the same problem. [ARM MOV and MVN operand](https://stackoverflow.com/q/27963312) has some actual working examples extracted from real assemblers and compilers. – Peter Cordes Apr 23 '21 at 08:58
  • @PeterCordes Hi, yes I just need to know conceptually if we are able to find some that is rotatable to get our immediate value; is there any sequence of steps/thoughts that we can use to check if such a value exists? – Ymi Apr 23 '21 at 09:01
  • Ok good, then [ARM MOV and MVN operand](https://stackoverflow.com/q/27963312) is an exact duplicate if you don't care about other encoding strategies that the assembler can choose from for some instructions. In your head, look at how far apart the set bits are (including wrapping around the top because it's a rotate), i.e. whether you can rotate them to the bottom such that they all fit in the low 8 bits. (With an even rotate count). – Peter Cordes Apr 23 '21 at 09:11
  • Yes, you seem to already know how the instruction works so simply check for that if most of the bits are zeros from the lowest 1 to the top is that on an even boundary and less than 8 bits or on an odd and less than 7 bits? and vice versa for mvn – old_timer Apr 23 '21 at 14:40

0 Answers0