This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: swap instruction generation


Hi Ian,

On Wed, Sep 21, 2011 at 6:57 PM, Ian Lance Taylor <iant@google.com> wrote:
> naga raj <gnuuser.raj@gmail.com> 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.
>
 I have tried with all the possibilities that you have mentioned but
swaph instruction was not generated.
Instead of swaph compiler is generating

 1f0:   64640408        bslli   r3, r4, 8   (left shift )

 1f4:   64840008        bsrli   r4, r4, 8  (right shift)

 1f8:   80632000        or      r3, r3, r4 (or operation)


Thanks,
Nagaraju


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]