RE: GCC-How does the coding style affect the insv pattern recognization?

2010-01-13 Thread Bingfeng Mei
Your instruction is likely too specific to be picked up by GCC. 
You may use an intrinisc for it. 

Bingfeng 

> -Original Message-
> From: gcc-ow...@gcc.gnu.org [mailto:gcc-ow...@gcc.gnu.org] On 
> Behalf Of fanqifei
> Sent: 12 January 2010 12:50
> To: gcc@gcc.gnu.org
> Subject: GCC-How does the coding style affect the insv 
> pattern recognization?
> 
> Hi,
> I am working on a micro controller and trying to port 
> gcc(4.3.2) for it.
> There is insv instruction in our micro controller and I have add
> define_insn to machine description file.
> However, the insv instruction can only be generated when the code
> is written like below.  If the code is written using logical shift and
> or operators, the insv instruction will not be generated.
> For the statement: x= (x&0xFF00) | ((i<<16)&0x00FF);
> 6 RTL instructions are generated after combine pass and 8
> instructions are generated in the assembly file.
> Paolo Bonzini said that insv instruction might be synthesized
> later by combine. But combine only works on at most 3 instructions and
> insv is not generated in such case.
> So exactly when will the insv pattern be recognized and how does
> the coding style affect it?
> Is there any open bug report about this?
> 
> struct test_foo {
> unsigned int a:18;
> unsigned int b:2;
> unsigned int c:12;
> };
> 
> struct test_foo x;
> 
> unsigned int foo()
> {
> unsigned int a=x.b;
> x.b=2;
> return a;
> }
> 
> Thanks!
> fanqifei
> 
> 


Re: GCC-How does the coding style affect the insv pattern recognization?

2010-01-13 Thread fanqifei
2010/1/13 Bingfeng Mei :
> Your instruction is likely too specific to be picked up by GCC.
> You may use an intrinisc for it.
>
> Bingfeng

but insv is a standard pattern name.
the semantics of expression x= (x&0xFF00) | ((i<<16)&0x00FF);
is exactly what insv can do.
I all tried mips gcc cross compiler, and ins is also not generated.
Intrinsic is a way to resolve this though. Maybe there is no other better way.

BTW,
There is a special case(the bit position is 0):
235: f0 97 fc mvi a9 -0x4;  #move immediate to reg
238: ff e9 94 and a9 a14 a9;
23b: f0 95 02 or a9 0x2;
The above three instructions can be replaced by mvi and insv. But the
fact is not in the combine pass.

Qifei Fan


RE: GCC-How does the coding style affect the insv pattern recognization?

2010-01-13 Thread Bingfeng Mei
OOPs, I don't know that. Anyway, I won't count on GCC to 
reliably pick up these complex patterns.  In our port, we 
implemented clz/ffs/etc as intrinsics though they are present as 
standard patterns. 

Bingfeng

> -Original Message-
> From: fanqifei [mailto:fanqi...@gmail.com] 
> Sent: 13 January 2010 10:26
> To: Bingfeng Mei
> Cc: gcc@gcc.gnu.org
> Subject: Re: GCC-How does the coding style affect the insv 
> pattern recognization?
> 
> 2010/1/13 Bingfeng Mei :
> > Your instruction is likely too specific to be picked up by GCC.
> > You may use an intrinisc for it.
> >
> > Bingfeng
> 
> but insv is a standard pattern name.
> the semantics of expression x= (x&0xFF00) | ((i<<16)&0x00FF);
> is exactly what insv can do.
> I all tried mips gcc cross compiler, and ins is also not generated.
> Intrinsic is a way to resolve this though. Maybe there is no 
> other better way.
> 
> BTW,
> There is a special case(the bit position is 0):
> 235: f0 97 fc mvi a9 -0x4;  #move immediate to reg
> 238: ff e9 94 and a9 a14 a9;
> 23b: f0 95 02 or a9 0x2;
> The above three instructions can be replaced by mvi and insv. But the
> fact is not in the combine pass.
> 
> Qifei Fan
> 
> 


Re: GCC-How does the coding style affect the insv pattern recognization?

2010-01-13 Thread fanqifei
2010/1/13 Bingfeng Mei :
> OOPs, I don't know that. Anyway, I won't count on GCC to
> reliably pick up these complex patterns.  In our port, we
> implemented clz/ffs/etc as intrinsics though they are present as
> standard patterns.
>
> Bingfeng
Could you please show me the path of the source code that implement
clz/ffs intrinsics of your processor?
I would like to take it as a reference.
Thank very much!

Qifei Fan


Re: GCC-How does the coding style affect the insv pattern recognization?

2010-01-14 Thread David Daney

fanqifei wrote:

2010/1/13 Bingfeng Mei :

Your instruction is likely too specific to be picked up by GCC.
You may use an intrinisc for it.

Bingfeng


but insv is a standard pattern name.
the semantics of expression x= (x&0xFF00) | ((i<<16)&0x00FF);
is exactly what insv can do.
I all tried mips gcc cross compiler, and ins is also not generated.


You must be doing something wrong:

$ cat fanqifei.c
struct test_foo {
  unsigned int a:18;
  unsigned int b:2;
  unsigned int c:12;
};

struct test_foo x;

unsigned int foo()
{
  unsigned int a=x.b;
  x.b=2;
  return a;
}

$ mips64-linux-gcc -O3 -march=mips32r2 -mabi=32 -mno-abicalls -S fanqifei.c
$ cat fanqifei.s
.file   1 "fanqifei.c"
.section .mdebug.abi32
.previous
.gnu_attribute 4, 1
.text
.align  2
.globl  foo
.setnomips16
.entfoo
.type   foo, @function
foo:
.frame  $sp,0,$31   # vars= 0, regs= 0/0, args= 0, gp= 0
.mask   0x,0
.fmask  0x,0
.setnoreorder
.setnomacro
lui $3,%hi(x)
lw  $2,%lo(x)($3)
li  $5,2# 0x2
move$4,$2
ins $4,$5,12,2 #<<< Here it is.
sw  $4,%lo(x)($3)
j   $31
ext $2,$2,12,2

.setmacro
.setreorder
.endfoo
.size   foo, .-foo

.comm   x,4,4
.ident  "GCC: (GNU) 4.5.0 20091223 (experimental) [trunk revision 
155414]"


Re: GCC-How does the coding style affect the insv pattern recognization?

2010-01-14 Thread Ian Lance Taylor
David Daney  writes:

>> but insv is a standard pattern name.
>> the semantics of expression x= (x&0xFF00) | ((i<<16)&0x00FF);
>> is exactly what insv can do.
>> I all tried mips gcc cross compiler, and ins is also not generated.
>
> You must be doing something wrong:
>
> $ cat fanqifei.c
> struct test_foo {
>   unsigned int a:18;
>   unsigned int b:2;
>   unsigned int c:12;
> };

It's relatively easy for gcc to use insv for a bitfield in a struct.

It's quite a bit harder for it to use it for bit manipulation as in
the above example of x = (x&0xFF00) | ((i<<16)&0x00FF).  This
case requires recognizing that insv applies at all.

Ian


Re: GCC-How does the coding style affect the insv pattern recognization?

2010-01-17 Thread Adam Nemet
fanqifei  writes:
> Paolo Bonzini said that insv instruction might be synthesized
> later by combine. But combine only works on at most 3 instructions and
> insv is not generated in such case.
> So exactly when will the insv pattern be recognized and how does
> the coding style affect it?

Sorry for jumping in late.  See make_file_assigment in combine.c.

The problem usually is that:

 (set A (ior (and B C1) OTHER))

can only be turned into a bit-insertion if A and B happen to be the same
pseudos.

Adam


Re: GCC-How does the coding style affect the insv pattern recognization?

2010-01-18 Thread fanqifei
2010/1/18 Adam Nemet :
> Sorry for jumping in late.  See make_file_assigment in combine.c.
>
> The problem usually is that:
>
>  (set A (ior (and B C1) OTHER))
>
> can only be turned into a bit-insertion if A and B happen to be the same
> pseudos.
>
> Adam
>
Thank you, Adam.  The problem is that before combine pass the
statement is expressed in 6 insns. The insns can't be combined into
the expected pattern (set A (ior (and B C1) OTHER)). Otherwise,
make_field_assignment can do the job of simplifying the SET insn.

Qifei Fan


Re: GCC-How does the coding style affect the insv pattern recognization?

2010-01-18 Thread Jeff Law

On 01/18/10 03:39, fanqifei wrote:

2010/1/18 Adam Nemet:
   

Sorry for jumping in late.  See make_file_assigment in combine.c.

The problem usually is that:

  (set A (ior (and B C1) OTHER))

can only be turned into a bit-insertion if A and B happen to be the same
pseudos.

Adam

 

Thank you, Adam.  The problem is that before combine pass the
statement is expressed in 6 insns. The insns can't be combined into
the expected pattern (set A (ior (and B C1) OTHER)). Otherwise,
make_field_assignment can do the job of simplifying the SET insn.
   
It is sometimes possible to create intermediate patterns to allow the 
combiner to see a larger window of insns.  Obviously if you create these 
intermediate patterns you should split them if they survive beyond the 
combiner phase.


jeff




Re: GCC-How does the coding style affect the insv pattern recognization?

2010-01-29 Thread fanqifei
2010/1/18 Adam Nemet :
> fanqifei  writes:
>>     Paolo Bonzini said that insv instruction might be synthesized
>> later by combine. But combine only works on at most 3 instructions and
>> insv is not generated in such case.
>>     So exactly when will the insv pattern be recognized and how does
>> the coding style affect it?
>
> Sorry for jumping in late.  See make_file_assigment in combine.c.
>
> The problem usually is that:
>
>  (set A (ior (and B C1) OTHER))
>
> can only be turned into a bit-insertion if A and B happen to be the same
> pseudos.
>
> Adam
>
I did found such kind of pattern for some simple C statements in rtl dump.
Unfortunately, A and B are not same.
Is it possible and easy to move B to A firstly and replace B with A in the insn?
Anyway, this is not required if it's impracticable.

Qifei Fan


Re: GCC-How does the coding style affect the insv pattern recognization?

2010-02-01 Thread Adam Nemet
fanqifei writes:
> 2010/1/18 Adam Nemet :
> > Sorry for jumping in late.  See make_file_assigment in combine.c.
> >
> > The problem usually is that:
> >
> >  (set A (ior (and B C1) OTHER))
> >
> > can only be turned into a bit-insertion if A and B happen to be the same
> > pseudos.
> >
> > Adam
> >
> I did found such kind of pattern for some simple C statements in rtl dump.
> Unfortunately, A and B are not same.
> Is it possible and easy to move B to A firstly and replace B with A in the 
> insn?
> Anyway, this is not required if it's impracticable.

It might work.  You could experiment with a define_split to do that.  Note
however that in terms of combine's notion of profitability, you will need to
have at the end eliminated some instructions.  (Also the overall cost of the
the new insns should be lower than the old ones.)

Alternatively you can recognize the above pattern, use a contraint to force
the pseudos to be allocated to the same hard register.  If successful you can
generate bit-inseration otherwise you split the pattern into the original
insns after reload.

Adam