This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: How to implement conditional execution
- From: Paul Brook <paul at codesourcery dot com>
- To: gcc at gcc dot gnu dot org
- Cc: Julian Brown <julian at codesourcery dot com>, "Mohamed Shafi" <shafitvm at gmail dot com>
- Date: Thu, 17 Jul 2008 17:51:04 +0100
- Subject: Re: How to implement conditional execution
- References: <ba0bd44d0806270322l75c11548ke204e58e78b4e70b@mail.gmail.com> <20080627120855.4b4e1fbf@boris.athome>
On Friday 27 June 2008, Julian Brown wrote:
> On Fri, 27 Jun 2008 15:52:22 +0530
>
> "Mohamed Shafi" <shafitvm@gmail.com> wrote:
> > If the condition in the 'if' instruction is satisfied the processor
> > will execute the next instruction or it will replace with a nop. So
> > this means that i can instructions similar to:
> >
> > if eq Rx, Ry
> > add Rx, Ry
> > add Rx, 2
> >
> > Will it be possible to implement this in the Gcc backend ?
> > Does any other targets have similar instructions?
>
> This is very much like (a simpler version of) the ARM Thumb-2 IT
> instruction. Look how config/arm/thumb2.md handles that. I think the
> basic idea should be that you should define conditional instruction
> patterns which emit assembly for both instructions simultaneously.
Not quite. For Thumb-2 we describe most instruction as having conditional
variants using define_cond_exec. Then arrange for the necessary IfThen
instructions to be generated via ASM_OUTPUT_OPCODE. Multiple assembly
instructions from the same pattern are either a historical leftover, or when
it's inconvenient to describe the operation with proper cond_exec RTL.
Thumb-2 is a bit different to the machine described above because because the
conditional execution is based on the condition code register, with the
comparison occurring as a separate instruction, and the IT instruction can
skip multiple subsequent instructions. I'd expect the same technique to be
applicable though.
Paul