public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/54680] New: [SH] Unnecessary int-float-int conversion of fsca fixed point input
@ 2012-09-23 12:25 olegendo at gcc dot gnu.org
  2012-09-23 12:40 ` [Bug target/54680] " olegendo at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: olegendo at gcc dot gnu.org @ 2012-09-23 12:25 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54680

             Bug #: 54680
           Summary: [SH] Unnecessary int-float-int conversion of fsca
                    fixed point input
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: target
        AssignedTo: olegendo@gcc.gnu.org
        ReportedBy: olegendo@gcc.gnu.org
            Target: sh4*-*-*


SH4's fsca insn works on 16.16 fixed point inputs.  When a SFmode input is used
it must be first scaled, which is done by multiplying the input with a
constant.  It is also possible to use fixed point inputs directly to the
standard sinf / cosf functions, to avoid the scaling.

#include <math.h>
const float pi = 3.14159265359f;

float test02 (int x)
{
  return sinf (x * (2*pi) / 65536);
}

This will result in:

        lds     r4,fpul    ! 32    movsi_ie/19
        float   fpul,fr2   ! 10    floatsisf2_i4
        ftrc    fr2,fpul   ! 11    fix_truncsfsi2_i4
        fsca    fpul,dr2   ! 12    fsca
        rts                ! 35    *return_i
        fmov    fr3,fr0       ! 14    movsf_ie/1

... which is already good, but the int -> float -> int conversions can be
eliminated.
The fsca pattern is actually already prepared to support this case.  Looking at
the combine log it seems this issue could be resolved by making the fpul input
a bit more flexible:

Failed to match this instruction:
(parallel [
        (set (reg:V2SF 172)
            (vec_concat:V2SF (unspec:SF [
                        (mult:SF (float:SF (fix:SI (float:SF (reg/v:SI 164 [ x
]))))
                            (const_double:SF
9.58737992428525700000000000000000000000000000002e-5
[0x0.c90fdaa22168be2882b78df4b0b1803b8a353e85p-13]))
                    ] 16)
                (unspec:SF [
                        (mult:SF (float:SF (fix:SI (float:SF (reg/v:SI 164 [ x
]))))
                            (const_double:SF
9.58737992428525700000000000000000000000000000002e-5
[0x0.c90fdaa22168be2882b78df4b0b1803b8a353e85p-13]))
                    ] 14)))
        (use (reg/v:PSI 151 ))
    ])


Another scenario that does not work however is:

float test03 (int x)
{
  return sinf ( x * 2 * pi / 65536 );
}

(Notice the missing ( ) around 2 * pi).

It seems this is caused by the fact that the fsca pattern checks for a valid
scaling constant by doing:

   && operands[2] == sh_fsca_int2sf ()"

.. instead of looking at the values of the const_double rtx.


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

end of thread, other threads:[~2012-10-30  1:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-23 12:25 [Bug target/54680] New: [SH] Unnecessary int-float-int conversion of fsca fixed point input olegendo at gcc dot gnu.org
2012-09-23 12:40 ` [Bug target/54680] " olegendo at gcc dot gnu.org
2012-10-09 19:57 ` olegendo at gcc dot gnu.org
2012-10-12 23:19 ` olegendo at gcc dot gnu.org
2012-10-30  1:28 ` olegendo at gcc dot gnu.org

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