public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* ins instruction is not produced in the assembly code (mips32r2)
@ 2009-12-16  8:11 fanqifei
  0 siblings, 0 replies; 13+ messages in thread
From: fanqifei @ 2009-12-16  8:11 UTC (permalink / raw)
  To: gcc-help

Hello,
I am tring to compile a small c file using gcc4.1.2.
The source code:
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;
}

the command: mipsel-linux-gcc -mips32r2 -O2 -c -Wall foo.c -o foo.o

The corresponding disassembly code:
foo.o:     file format elf32-tradlittlemips
Disassembly of section .text:
00000000 <foo>:
   0:   3c1c0000    lui gp,0x0
   4:   279c0000    addiu   gp,gp,0
   8:   0399e021    addu    gp,gp,t9
   c:   8f850000    lw  a1,0(gp)
  10:   3c03fff3    lui v1,0xfff3
  14:   3463ffff    ori v1,v1,0xffff
  18:   8ca20000    lw  v0,0(a1)
  1c:   3c040008    lui a0,0x8
  20:   00431824    and v1,v0,v1
  24:   00641825    or  v1,v1,a0
  28:   7c420c80    ext v0,v0,0x12,0x2
  2c:   03e00008    jr  ra
  30:   aca30000    sw  v1,0(a1)

The statement x.b=2 can be simply translated to lb and ins
instructions( ins is in mips32r2).

I wonder how ins instrution can be produced.
More specifically, how can gcc generates the insv pattern in RTL?
Is it related to the coding style -- using bit filed or logical
operations(shift, and ...)?

Thanks.
Qifei

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ins instruction is not produced in the assembly code (mips32r2)
  2010-01-12  7:28             ` fanqifei
@ 2010-01-12 10:11               ` Andrew Haley
  0 siblings, 0 replies; 13+ messages in thread
From: Andrew Haley @ 2010-01-12 10:11 UTC (permalink / raw)
  To: fanqifei; +Cc: gcc-help

On 01/12/2010 07:28 AM, fanqifei wrote:
>>> I still not understand when the insn "insv" in target.md can be used
>>> in the RTL representation of the code.
>>
>> I already told you in my previous message.  Did you not see it?

> 
> Hi Andrew, I did see it. But that's not exactly what I want.
> Is the builtin function the only way to utilize ins instruction?
> According to the webpage
> http://gcc.gnu.org/ml/gcc-patches/2005-05/msg02430.html, the builtin
> functions are introduced for the DSP extension. As INS instruction is
> introduced in MIPS32 R2 too(not exactly the same as in DSP extension),
> I guess there must be another method to utilize ins instruction of
> MIPS32R2 except inline asm or builtin functions.

I grepped through the gcc back-end.  There is code to use insv and
extv in bitfield accesses.  I'm not really sure what is going on in
your case.

I think David Daney is right: make sure that with the latest
development version of gcc and the correct options this still happens,
and file a bug report.

Andrew.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ins instruction is not produced in the assembly code (mips32r2)
  2009-12-18 15:10           ` Andrew Haley
@ 2010-01-12  7:28             ` fanqifei
  2010-01-12 10:11               ` Andrew Haley
  0 siblings, 1 reply; 13+ messages in thread
From: fanqifei @ 2010-01-12  7:28 UTC (permalink / raw)
  To: gcc-help, aph

> > I still not understand when the insn "insv" in target.md can be used
> > in the RTL representation of the code.
>
> I already told you in my previous message.  Did you not see it?
>
>  __builtin_mips_insv
>
> Andrew.
>

Hi Andrew, I did see it. But that's not exactly what I want.
Is the builtin function the only way to utilize ins instruction?
According to the webpage
http://gcc.gnu.org/ml/gcc-patches/2005-05/msg02430.html, the builtin
functions are introduced for the DSP extension. As INS instruction is
introduced in MIPS32 R2 too(not exactly the same as in DSP extension),
I guess there must be another method to utilize ins instruction of
MIPS32R2 except inline asm or builtin functions.
More specifically, can gcc recognize the pattern of ins and output ins
instruction in the assembly file? Even for other cpu architecture(not
MIPS) which has similar instruction like ins.
I really appreciate your help.

-fanqifei

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ins instruction is not produced in the assembly code (mips32r2)
  2009-12-18 10:57 ` fanqifei
  2009-12-18 11:00   ` Andrew Haley
  2009-12-18 13:46   ` Ineiev
@ 2009-12-18 18:12   ` David Daney
  2 siblings, 0 replies; 13+ messages in thread
From: David Daney @ 2009-12-18 18:12 UTC (permalink / raw)
  To: fanqifei; +Cc: gcc-help

fanqifei wrote:
> Is there anyone can help?
> I am curious about how the insv pattern can be used in the compiling process.
> Otherwise, I have to write inline assembly code.
> Thanks very much!
> 

You don't state which compiler version you are using.  I would suggest 
trying a GCC-4.5 snapshot.  I know that some work has been recently done 
to make better use of INS.

If GCC-4.5 doesn't help, you could file a GCC bug report about this 
missed optimization.

David Daney



> 2009/12/16 fanqifei <fanqifei@gmail.com>:
>> Hello,
>> I am tring to compile a small c file using gcc4.1.2.
>> The source code:
>> 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;
>> }
>>
>> the command: mipsel-linux-gcc -mips32r2 -O2 -c -Wall foo.c -o foo.o
>>
>> The corresponding disassembly code:
>> foo.o:     file format elf32-tradlittlemips
>> Disassembly of section .text:
>> 00000000 <foo>:
>>    0:   3c1c0000    lui gp,0x0
>>    4:   279c0000    addiu   gp,gp,0
>>    8:   0399e021    addu    gp,gp,t9
>>    c:   8f850000    lw  a1,0(gp)
>>   10:   3c03fff3    lui v1,0xfff3
>>   14:   3463ffff    ori v1,v1,0xffff
>>   18:   8ca20000    lw  v0,0(a1)
>>   1c:   3c040008    lui a0,0x8
>>   20:   00431824    and v1,v0,v1
>>   24:   00641825    or  v1,v1,a0
>>   28:   7c420c80    ext v0,v0,0x12,0x2
>>   2c:   03e00008    jr  ra
>>   30:   aca30000    sw  v1,0(a1)
>> The statement x.b=2 can be simply translated to lb and ins instructions( ins
>> is in mips32r2).
>>
>> I wonder how ins instrution can be produced.
>> More specifically, how can gcc generates the insv pattern in RTL?
>> Is it related to the coding style -- using bit filed or logical
>> operations(shift, and ...)?
>> Thanks.
>> Qifei
>>
>>
> 
> 
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ins instruction is not produced in the assembly code (mips32r2)
  2009-12-18 14:54         ` fanqifei
@ 2009-12-18 15:10           ` Andrew Haley
  2010-01-12  7:28             ` fanqifei
  0 siblings, 1 reply; 13+ messages in thread
From: Andrew Haley @ 2009-12-18 15:10 UTC (permalink / raw)
  To: fanqifei; +Cc: gcc-help

fanqifei wrote:
> Thanks, Andrew.

Please don't top-post.

> I still not understand when the insn "insv" in target.md can be used
> in the RTL representation of the code.

I already told you in my previous message.  Did you not see it?

 __builtin_mips_insv

Andrew.


> 2009/12/18 Andrew Haley <aph@redhat.com>:
>> fanqifei wrote:
>>> The instruction sequence generated by gcc can be simply rewritten by
>>> three instructions.
>>> Apparently gcc should find the expression storing to bit-field and use
>>> pattern insv. But it didn't.
>>>
>>> gcc:
>>>  10:   3c03fff3    lui v1,0xfff3
>>>  14:   3463ffff    ori v1,v1,0xffff
>>>  18:   8ca20000    lw  v0,0(a1)
>>>  1c:   3c040008    lui a0,0x8
>>>  20:   00431824    and v1,v0,v1
>>>  24:   00641825    or  v1,v1,a0
>>>
>>> with ins:
>>> lw v0,0(a1)
>>> ori a0, $0, 2
>>> ins v0,v0,19,18
>> I can't see anything in gcc that would use an ins instruction to do that.
>>
>> Andrew.
>>
> 
> 
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ins instruction is not produced in the assembly code (mips32r2)
  2009-12-18 14:39       ` Andrew Haley
@ 2009-12-18 14:54         ` fanqifei
  2009-12-18 15:10           ` Andrew Haley
  0 siblings, 1 reply; 13+ messages in thread
From: fanqifei @ 2009-12-18 14:54 UTC (permalink / raw)
  To: gcc-help, aph

Thanks, Andrew.
I still not understand when the insn "insv" in target.md can be used
in the RTL representation of the code.

2009/12/18 Andrew Haley <aph@redhat.com>:
> fanqifei wrote:
>> The instruction sequence generated by gcc can be simply rewritten by
>> three instructions.
>> Apparently gcc should find the expression storing to bit-field and use
>> pattern insv. But it didn't.
>>
>> gcc:
>>  10:   3c03fff3    lui v1,0xfff3
>>  14:   3463ffff    ori v1,v1,0xffff
>>  18:   8ca20000    lw  v0,0(a1)
>>  1c:   3c040008    lui a0,0x8
>>  20:   00431824    and v1,v0,v1
>>  24:   00641825    or  v1,v1,a0
>>
>> with ins:
>> lw v0,0(a1)
>> ori a0, $0, 2
>> ins v0,v0,19,18
>
> I can't see anything in gcc that would use an ins instruction to do that.
>
> Andrew.
>



-- 
        Qifei Fan

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ins instruction is not produced in the assembly code (mips32r2)
  2009-12-18 13:58     ` fanqifei
  2009-12-18 14:19       ` Ineiev
@ 2009-12-18 14:39       ` Andrew Haley
  2009-12-18 14:54         ` fanqifei
  1 sibling, 1 reply; 13+ messages in thread
From: Andrew Haley @ 2009-12-18 14:39 UTC (permalink / raw)
  To: fanqifei; +Cc: gcc-help

fanqifei wrote:
> The instruction sequence generated by gcc can be simply rewritten by
> three instructions.
> Apparently gcc should find the expression storing to bit-field and use
> pattern insv. But it didn't.
> 
> gcc:
>  10:   3c03fff3    lui v1,0xfff3
>  14:   3463ffff    ori v1,v1,0xffff
>  18:   8ca20000    lw  v0,0(a1)
>  1c:   3c040008    lui a0,0x8
>  20:   00431824    and v1,v0,v1
>  24:   00641825    or  v1,v1,a0
> 
> with ins:
> lw v0,0(a1)
> ori a0, $0, 2
> ins v0,v0,19,18

I can't see anything in gcc that would use an ins instruction to do that.

Andrew.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ins instruction is not produced in the assembly code (mips32r2)
  2009-12-18 14:19       ` Ineiev
@ 2009-12-18 14:21         ` fanqifei
  0 siblings, 0 replies; 13+ messages in thread
From: fanqifei @ 2009-12-18 14:21 UTC (permalink / raw)
  To: gcc-help; +Cc: ineiev

code size and execution time can be saved if ins is used in the assembly code.
I don't want to write assembly code by hand. But hope gcc can generate
it automatically.
My code is not all such assignments but contains some.

2009/12/18 Ineiev <ineiev@gmail.com>:
> On 12/18/09, fanqifei <fanqifei@gmail.com> wrote:
>> 2009/12/18 Ineiev <ineiev@gmail.com>:
>>> On 12/18/09, fanqifei <fanqifei@gmail.com> wrote:
>>>> Otherwise, I have to write inline assembly code.
>>>
>>> Out of curiosity --- why do you think your executable has to use this
>>> pattern?
>> The instruction sequence generated by gcc can be simply rewritten by
>> three instructions.
>
> I see, thank you.
>
>> Apparently gcc should find the expression storing to bit-field and use
>> pattern insv. But it didn't.
>
> I'm sorry (really), as I know nothing about the target architecture,
> this is not apparent _for me_.
>
> What I don't understand is why you _has_ to code it in assembler?
> is your program essentially nothing but such assignments?
> or the code gcc provides assigns something wrong?
>
> I bag your pardon if this is too off-topic,
> Ineiev
>



-- 
        Qifei Fan

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ins instruction is not produced in the assembly code (mips32r2)
  2009-12-18 13:58     ` fanqifei
@ 2009-12-18 14:19       ` Ineiev
  2009-12-18 14:21         ` fanqifei
  2009-12-18 14:39       ` Andrew Haley
  1 sibling, 1 reply; 13+ messages in thread
From: Ineiev @ 2009-12-18 14:19 UTC (permalink / raw)
  To: fanqifei; +Cc: gcc-help

On 12/18/09, fanqifei <fanqifei@gmail.com> wrote:
> 2009/12/18 Ineiev <ineiev@gmail.com>:
>> On 12/18/09, fanqifei <fanqifei@gmail.com> wrote:
>>> Otherwise, I have to write inline assembly code.
>>
>> Out of curiosity --- why do you think your executable has to use this
>> pattern?
> The instruction sequence generated by gcc can be simply rewritten by
> three instructions.

I see, thank you.

> Apparently gcc should find the expression storing to bit-field and use
> pattern insv. But it didn't.

I'm sorry (really), as I know nothing about the target architecture,
this is not apparent _for me_.

What I don't understand is why you _has_ to code it in assembler?
is your program essentially nothing but such assignments?
or the code gcc provides assigns something wrong?

I bag your pardon if this is too off-topic,
Ineiev

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ins instruction is not produced in the assembly code (mips32r2)
  2009-12-18 13:46   ` Ineiev
@ 2009-12-18 13:58     ` fanqifei
  2009-12-18 14:19       ` Ineiev
  2009-12-18 14:39       ` Andrew Haley
  0 siblings, 2 replies; 13+ messages in thread
From: fanqifei @ 2009-12-18 13:58 UTC (permalink / raw)
  To: gcc-help

The instruction sequence generated by gcc can be simply rewritten by
three instructions.
Apparently gcc should find the expression storing to bit-field and use
pattern insv. But it didn't.

gcc:
 10:   3c03fff3    lui v1,0xfff3
 14:   3463ffff    ori v1,v1,0xffff
 18:   8ca20000    lw  v0,0(a1)
 1c:   3c040008    lui a0,0x8
 20:   00431824    and v1,v0,v1
 24:   00641825    or  v1,v1,a0

with ins:
lw v0,0(a1)
ori a0, $0, 2
ins v0,v0,19,18


2009/12/18 Ineiev <ineiev@gmail.com>:
> On 12/18/09, fanqifei <fanqifei@gmail.com> wrote:
>> Is there anyone can help?
>> I am curious about how the insv pattern can be used in the compiling
>> process.
>> Otherwise, I have to write inline assembly code.
>
> Out of curiosity --- why do you think your executable has to use this pattern?
>
> Regards,
> Ineiev
>

-- 
        Qifei Fan

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ins instruction is not produced in the assembly code (mips32r2)
  2009-12-18 10:57 ` fanqifei
  2009-12-18 11:00   ` Andrew Haley
@ 2009-12-18 13:46   ` Ineiev
  2009-12-18 13:58     ` fanqifei
  2009-12-18 18:12   ` David Daney
  2 siblings, 1 reply; 13+ messages in thread
From: Ineiev @ 2009-12-18 13:46 UTC (permalink / raw)
  To: fanqifei; +Cc: gcc-help

On 12/18/09, fanqifei <fanqifei@gmail.com> wrote:
> Is there anyone can help?
> I am curious about how the insv pattern can be used in the compiling
> process.
> Otherwise, I have to write inline assembly code.

Out of curiosity --- why do you think your executable has to use this pattern?

Regards,
Ineiev

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ins instruction is not produced in the assembly code (mips32r2)
  2009-12-18 10:57 ` fanqifei
@ 2009-12-18 11:00   ` Andrew Haley
  2009-12-18 13:46   ` Ineiev
  2009-12-18 18:12   ` David Daney
  2 siblings, 0 replies; 13+ messages in thread
From: Andrew Haley @ 2009-12-18 11:00 UTC (permalink / raw)
  To: fanqifei; +Cc: gcc-help

fanqifei wrote:
> Is there anyone can help?
> I am curious about how the insv pattern can be used in the compiling process.
> Otherwise, I have to write inline assembly code.

Use __builtin_mips_insv (i32, i32)

Andrew.


> Thanks very much!
> 
> 2009/12/16 fanqifei <fanqifei@gmail.com>:
>> Hello,
>> I am tring to compile a small c file using gcc4.1.2.
>> The source code:
>> 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;
>> }
>>
>> the command: mipsel-linux-gcc -mips32r2 -O2 -c -Wall foo.c -o foo.o
>>
>> The corresponding disassembly code:
>> foo.o:     file format elf32-tradlittlemips
>> Disassembly of section .text:
>> 00000000 <foo>:
>>    0:   3c1c0000    lui gp,0x0
>>    4:   279c0000    addiu   gp,gp,0
>>    8:   0399e021    addu    gp,gp,t9
>>    c:   8f850000    lw  a1,0(gp)
>>   10:   3c03fff3    lui v1,0xfff3
>>   14:   3463ffff    ori v1,v1,0xffff
>>   18:   8ca20000    lw  v0,0(a1)
>>   1c:   3c040008    lui a0,0x8
>>   20:   00431824    and v1,v0,v1
>>   24:   00641825    or  v1,v1,a0
>>   28:   7c420c80    ext v0,v0,0x12,0x2
>>   2c:   03e00008    jr  ra
>>   30:   aca30000    sw  v1,0(a1)
>> The statement x.b=2 can be simply translated to lb and ins instructions( ins
>> is in mips32r2).
>>
>> I wonder how ins instrution can be produced.
>> More specifically, how can gcc generates the insv pattern in RTL?
>> Is it related to the coding style -- using bit filed or logical
>> operations(shift, and ...)?
>> Thanks.
>> Qifei
>>
>>
> 
> 
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: ins instruction is not produced in the assembly code (mips32r2)
       [not found] <f94afa700912152309r5d60f85cx943c5c2a98592383@mail.gmail.com>
@ 2009-12-18 10:57 ` fanqifei
  2009-12-18 11:00   ` Andrew Haley
                     ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: fanqifei @ 2009-12-18 10:57 UTC (permalink / raw)
  To: gcc-help

Is there anyone can help?
I am curious about how the insv pattern can be used in the compiling process.
Otherwise, I have to write inline assembly code.
Thanks very much!

2009/12/16 fanqifei <fanqifei@gmail.com>:
> Hello,
> I am tring to compile a small c file using gcc4.1.2.
> The source code:
> 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;
> }
>
> the command: mipsel-linux-gcc -mips32r2 -O2 -c -Wall foo.c -o foo.o
>
> The corresponding disassembly code:
> foo.o:     file format elf32-tradlittlemips
> Disassembly of section .text:
> 00000000 <foo>:
>    0:   3c1c0000    lui gp,0x0
>    4:   279c0000    addiu   gp,gp,0
>    8:   0399e021    addu    gp,gp,t9
>    c:   8f850000    lw  a1,0(gp)
>   10:   3c03fff3    lui v1,0xfff3
>   14:   3463ffff    ori v1,v1,0xffff
>   18:   8ca20000    lw  v0,0(a1)
>   1c:   3c040008    lui a0,0x8
>   20:   00431824    and v1,v0,v1
>   24:   00641825    or  v1,v1,a0
>   28:   7c420c80    ext v0,v0,0x12,0x2
>   2c:   03e00008    jr  ra
>   30:   aca30000    sw  v1,0(a1)
> The statement x.b=2 can be simply translated to lb and ins instructions( ins
> is in mips32r2).
>
> I wonder how ins instrution can be produced.
> More specifically, how can gcc generates the insv pattern in RTL?
> Is it related to the coding style -- using bit filed or logical
> operations(shift, and ...)?
> Thanks.
> Qifei
>
>



-- 
        Qifei Fan

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2010-01-12 10:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-16  8:11 ins instruction is not produced in the assembly code (mips32r2) fanqifei
     [not found] <f94afa700912152309r5d60f85cx943c5c2a98592383@mail.gmail.com>
2009-12-18 10:57 ` fanqifei
2009-12-18 11:00   ` Andrew Haley
2009-12-18 13:46   ` Ineiev
2009-12-18 13:58     ` fanqifei
2009-12-18 14:19       ` Ineiev
2009-12-18 14:21         ` fanqifei
2009-12-18 14:39       ` Andrew Haley
2009-12-18 14:54         ` fanqifei
2009-12-18 15:10           ` Andrew Haley
2010-01-12  7:28             ` fanqifei
2010-01-12 10:11               ` Andrew Haley
2009-12-18 18:12   ` David Daney

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).