public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "olegendo at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/54680] New: [SH] Unnecessary int-float-int conversion of fsca fixed point input
Date: Sun, 23 Sep 2012 12:25:00 -0000	[thread overview]
Message-ID: <bug-54680-4@http.gcc.gnu.org/bugzilla/> (raw)


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.


             reply	other threads:[~2012-09-23 12:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-23 12:25 olegendo at gcc dot gnu.org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-54680-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).