Hi,
I've pulled out my dusty coding hat and started reviewing years old code I was working on. I have a set of functions that perform bitwise rotate operations using various combinations of ROR/ROL/SWAP:
namespace Machine {
// ...
template<const uint32 N> inline uint32 rotRight32(uint32 val)
{
// N is shift size
if (!(N&31)) {
return val;
}
if (N<9) {
asm("ror.l %1, %0" : "=d"(val) : "I"(N), "0"(val) : "cc");
}
else if (N==16) {
asm("swap %0" : "=d"(val) : "0"(val) : "cc");
}
else if (N>23) {
asm("rol.l %1, %0" : "=d"(val) : "I"(32-N), "0"(val) : "cc");
}
else {
asm("ror.l %1, %0" : "=d"(val) : "d"(N), "0"(val) : "cc");
}
return val;
}
// ...
}
Now, without getting too much into it, the above template function is designed to emit optimal rotate code for compile-time known shift values. Despite the seemingly large chain of if/else, the fact the code is inline and N is constant means the basic assembler is emitted fine, for all values of N from 0-32. It goes without saying that the behaviour for N>32 is not well defined (actually it is the last branch of the code but that might not be the expected behaviour for all N), but as N is a compile time constant, that doesn't matter. If you need a variable rotate, there is a different non-template function.
Unfortunately, you do get a lot of warning diagnostics of the form "asm operand 0 probably doesn't match constraints" when compiling with gcc.
Does anybody know what option there is to suppress this particular warning or just warnings emitted from the use of asm() in general?