naga raj <gnuuser.raj@xxxxxxxxx> writes: > I am using Gcc-4.6.0 and I have used bswap RTL pattern for both SI > and HI modes to generate swapb & swaph instructions respectively. > > (define_insn "bswapsi2" > [(set (match_operand:SI 0 "register_operand" "=r") > (bswap:SI (match_operand:SI 1 "register_operand" "r")))] > "" > "swapb %0, %1" > ) > > (define_insn "bswaphi2" > [(set (match_operand:HI 0 "register_operand" "=r") > (bswap:HI (match_operand:HI 1 "register_operand" "r")))] > "" > "swaph %0, %1" > ) > > > > I have written a sample example to generate these instructions.. > int swapb(int n) > { > return ((((n) & 0xff000000) >> 24) > | (((n) & 0x00ff0000) >> 8) > | (((n) & 0x0000ff00) << 8) > | (((n) & 0x000000ff) << 24)); > > } > short int swaph(short int n) > { > return ((((n) & 0xff00) >> 8) > | (((n) & 0xff) << 8)); > } > int main() > { > volatile int a=0x12345678; > volatile short int b=0x1234; > a=swapb(a); > b=swaph(b); > return 0; > } > > with this example "swapb" instruction has generated but I am unable to > generate "swaph"(HI mode of bswap RTL pattern) instruction > > I have tried all possibilities that I know. > Am I missing something or this approach is wrong. > Please guide me to generate swaph instruction. I'm surprised that you even get swapb when using a volatile variable. I would remove the volatile. Just make them global variables or function arguments or something. Also you should make b an unsigned short, so that gcc doesn't have to worry about sign extending the result when the expression is implicitly calculated in type int. Good luck. Ian