public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* RS6000 emitting sign extention for unsigned type
@ 2019-01-14 18:41 kamlesh kumar
  2019-01-15 11:18 ` kamlesh kumar
  0 siblings, 1 reply; 4+ messages in thread
From: kamlesh kumar @ 2019-01-14 18:41 UTC (permalink / raw)
  To: gcc; +Cc: jakub

Hi devs,
consider below testcase:
$cat test.c
void foo(){
unsigned int x=-1;
double d=x;
}
$./cc1 test.c -msoft-float -m64
$cat test.s

.foo:
.LFB0:
        mflr 0
        std 0,16(1)
        stdu 1,-128(1)
.LCFI0:
        li 9,-1
        stw 9,112(1)
        lwa 9,112(1)
        mr 3,9
        bl .__floatunsidf
        nop
        mr 9,3
        std 9,120(1)
        nop
        addi 1,1,128
.LCFI1:
        ld 0,16(1)
        mtlr 0
        blr
        .long 0
        .byte 0,0,0,1,128,0,0,1

Here, you can see sign extension before calling the __floatunsidf routine.
As per my understanding it should emit zero extension here because
__floatunsidf  has  it argument as unsigned type.

Like to know ,  Reason behind doing  sign extension here , rather than zero
extension.
or if this is a bug?
is there Any work around or hook?
Even you can point me to the right direction in the source? where we need
to do modification?

Thanks
~Kamlesh


Thanks !
Kamlesh

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

* Re: RS6000 emitting sign extention for unsigned type
  2019-01-14 18:41 RS6000 emitting sign extention for unsigned type kamlesh kumar
@ 2019-01-15 11:18 ` kamlesh kumar
  2019-01-18 12:33   ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: kamlesh kumar @ 2019-01-15 11:18 UTC (permalink / raw)
  To: gcc, Umesh Kalappa, jakub

Hi all,

Analysed it further and find out that
function ' rs6000_promote_function_mode ' (rs6000.c) needs modifcation.
"""
static machine_mode
rs6000_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
                              machine_mode mode,
                              int *punsignedp ATTRIBUTE_UNUSED,
                              const_tree, int)
{
  PROMOTE_MODE (mode, *punsignedp, type);
  return mode;
}
"""
Here, This function is promoting the mode but
it is not even touching 'punsignedp' and it is always initialized to zero
by default.
So in all cases 'punsignedp' remain zero even if it is for unsigned type.
which cause the sign extension to happen  even for unsigned type.

is there any way to set 'punsignedp' appropriately here.

Thanks


On Tue, Jan 15, 2019 at 12:11 AM kamlesh kumar <kamleshbhalui@gmail.com>
wrote:

> Hi devs,
> consider below testcase:
> $cat test.c
> void foo(){
> unsigned int x=-1;
> double d=x;
> }
> $./cc1 test.c -msoft-float -m64
> $cat test.s
>
> .foo:
> .LFB0:
>         mflr 0
>         std 0,16(1)
>         stdu 1,-128(1)
> .LCFI0:
>         li 9,-1
>         stw 9,112(1)
>         lwa 9,112(1)
>         mr 3,9
>         bl .__floatunsidf
>         nop
>         mr 9,3
>         std 9,120(1)
>         nop
>         addi 1,1,128
> .LCFI1:
>         ld 0,16(1)
>         mtlr 0
>         blr
>         .long 0
>         .byte 0,0,0,1,128,0,0,1
>
> Here, you can see sign extension before calling the __floatunsidf routine.
> As per my understanding it should emit zero extension here because
> __floatunsidf  has  it argument as unsigned type.
>
> Like to know ,  Reason behind doing  sign extension here , rather than
> zero extension.
> or if this is a bug?
> is there Any work around or hook?
> Even you can point me to the right direction in the source? where we need
> to do modification?
>
> Thanks
> ~Kamlesh
>
>
> Thanks !
> Kamlesh
>

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

* Re: RS6000 emitting sign extention for unsigned type
  2019-01-15 11:18 ` kamlesh kumar
@ 2019-01-18 12:33   ` Alan Modra
  2019-01-18 12:44     ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Modra @ 2019-01-18 12:33 UTC (permalink / raw)
  To: kamlesh kumar; +Cc: gcc, Umesh Kalappa, jakub

On Tue, Jan 15, 2019 at 04:48:27PM +0530, kamlesh kumar wrote:
> Hi all,
> 
> Analysed it further and find out that
> function ' rs6000_promote_function_mode ' (rs6000.c) needs modifcation.
> """
> static machine_mode
> rs6000_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
>                               machine_mode mode,
>                               int *punsignedp ATTRIBUTE_UNUSED,
>                               const_tree, int)
> {
>   PROMOTE_MODE (mode, *punsignedp, type);
>   return mode;
> }
> """
> Here, This function is promoting the mode but
> it is not even touching 'punsignedp' and it is always initialized to zero
> by default.
> So in all cases 'punsignedp' remain zero even if it is for unsigned type.
> which cause the sign extension to happen  even for unsigned type.
> 
> is there any way to set 'punsignedp' appropriately here.

No.  The call to promote_function_mode in emit_library_call_value_1
does not pass type info (because it isn't available for libcalls).

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: RS6000 emitting sign extention for unsigned type
  2019-01-18 12:33   ` Alan Modra
@ 2019-01-18 12:44     ` Jakub Jelinek
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2019-01-18 12:44 UTC (permalink / raw)
  To: Alan Modra; +Cc: kamlesh kumar, gcc, Umesh Kalappa

On Fri, Jan 18, 2019 at 11:03:28PM +1030, Alan Modra wrote:
> On Tue, Jan 15, 2019 at 04:48:27PM +0530, kamlesh kumar wrote:
> > Hi all,
> > 
> > Analysed it further and find out that
> > function ' rs6000_promote_function_mode ' (rs6000.c) needs modifcation.
> > """
> > static machine_mode
> > rs6000_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
> >                               machine_mode mode,
> >                               int *punsignedp ATTRIBUTE_UNUSED,
> >                               const_tree, int)
> > {
> >   PROMOTE_MODE (mode, *punsignedp, type);
> >   return mode;
> > }
> > """
> > Here, This function is promoting the mode but
> > it is not even touching 'punsignedp' and it is always initialized to zero
> > by default.
> > So in all cases 'punsignedp' remain zero even if it is for unsigned type.
> > which cause the sign extension to happen  even for unsigned type.
> > 
> > is there any way to set 'punsignedp' appropriately here.
> 
> No.  The call to promote_function_mode in emit_library_call_value_1
> does not pass type info (because it isn't available for libcalls).

Yeah, all the callers of emit_library_call* would need to be changed to pass
triplets rtx, machine_mode, int/bool /*unsignedp*/, instead of just
rtx_mode_t pair or add a new set of emit_library_call* APIs that would take
those triplets.

	Jakub

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

end of thread, other threads:[~2019-01-18 12:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-14 18:41 RS6000 emitting sign extention for unsigned type kamlesh kumar
2019-01-15 11:18 ` kamlesh kumar
2019-01-18 12:33   ` Alan Modra
2019-01-18 12:44     ` Jakub Jelinek

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