Given a number x, how can we tell that it can be represented as 32-bit immediate. Does any kind of formula exists? If yes, is that formula exhaustive, i.e., covers all the possible cases? ARM decomposes the rightmost 12 bits in the instruction set as 4 bit rotate-bit and 8 bit value bit.
I would look into open source compilers and how they do it...
/* Return TRUE if int I is a valid immediate ARM constant. */
int
const_ok_for_arm (HOST_WIDE_INT i)
{
...