From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26933 invoked by alias); 2 Mar 2013 16:17:02 -0000 Received: (qmail 26884 invoked by uid 48); 2 Mar 2013 16:16:44 -0000 From: "olegendo at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/55303] [SH] Add support for clips / clipu instructions Date: Sat, 02 Mar 2013 16:17:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: olegendo at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: olegendo at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Status Last reconfirmed AssignedTo Ever Confirmed Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2013-03/txt/msg00125.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D55303 Oleg Endo changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |ASSIGNED Last reconfirmed| |2013-03-02 AssignedTo|unassigned at gcc dot |olegendo at gcc dot gnu.org |gnu.org | Ever Confirmed|0 |1 --- Comment #1 from Oleg Endo 2013-03-02 16:1= 6:41 UTC --- Created attachment 29567 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=3D29567 Working patch with a thinko. This patch, albeit working, has a thinko. The idea was to reduce the constraints of the clips/clipu insn comparison constants by adding/subtracting a constant offset value before/after the ac= tual clipping insn. For example: int test_02 (int a) { return max (0, min (255, a)); } becomes: _test_02: movi20 #128,r1 sub r1,r4 mov r4,r0 clips.b r0 rts add r1,r0 The problem with this is that it won't work for values that will wrap-around before/after the offset subtraction/addition. E.g. plugging the value 0x80000000 (=E2=88=922147483648) into the above cas= e: movi20 #128,r1 sub r1,r4 // r4 =3D 0x80000000 - 128 =3D 0x7FFFFF80 mov r4,r0 clips.b r0 // !(r0 < -128) && (r0 > 127) -> r0 =3D 127 rts add r1,r0 // r0 =3D 127 + 128 =3D 255 // expected result: 0 Maybe this case could be handled by using subv/addv insns to catch over/underflows somehow, but probably the resulting code would be more comp= lex (and thus slower) than two straight forward compare-and-branch sequences. On the other hand, if it is known that the input value is in a certain range (e.g. a sign/zero extended HImode or QImode), the offset approach should wo= rk fine. I will modify the attached patch so that it will allow only the HW clip constants for now.