public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: naga raj <gnuuser.raj@gmail.com>
To: Ian Lance Taylor <iant@google.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: swap instruction generation
Date: Wed, 21 Sep 2011 06:24:00 -0000	[thread overview]
Message-ID: <CAKuVEhCQy7P2DZDbgJog-uj7fM0kcy+-O8aax3rS5aoFgPOzkw@mail.gmail.com> (raw)
In-Reply-To: <mcrzknnfkxw.fsf@google.com>

Hi Ian,

   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.

Thanks in Advance,
Nag

On Tue, Apr 19, 2011 at 12:25 AM, Ian Lance Taylor <iant@google.com> wrote:
> naga raj <gnuuser.raj@gmail.com> writes:
>
>>   I need to emit a swap instruction from a embedded target which is
>> using Gcc-4.1.2.
>>
>>   I am trying to emit a instruction which will perform following operation
>>
>>   R0=0x12345678;
>>
>>   swap R1,R0
>>
>>   Then after this R1 should contain R1= 0x00007856;
>
> Not 0x78563421?
>
>>  As there is no bswap rtl expression in Gcc-4.1.2 I have tried various
>> alternatives like:
>>
>>  1. Used rotate rtl expression
>>
>>   2. ashift,ashiftrt and or to generate the above instruction
>>
>>
>>  but compiler is not generating(emitting) swap instruction.
>
> Current gcc has a bswap RTL pattern which swaps bytes in a word.  It was
> added in gcc 4.3.  That's the thing to use if your instruction actually
> swaps bytes in a word.  For versions of gcc before that you will have to
> use an intrinsic function.
>
> Ian
>

  reply	other threads:[~2011-09-21  6:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-18 13:21 naga raj
2011-04-18 18:59 ` Ian Lance Taylor
2011-09-21  6:24   ` naga raj [this message]
2011-09-21 13:27     ` Ian Lance Taylor
2011-09-22  9:03       ` naga raj
2011-09-22 16:08         ` Ian Lance Taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKuVEhCQy7P2DZDbgJog-uj7fM0kcy+-O8aax3rS5aoFgPOzkw@mail.gmail.com \
    --to=gnuuser.raj@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=iant@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).