From patchwork Mon Sep 19 13:34:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Greenhalgh X-Patchwork-Id: 15770 Received: (qmail 64465 invoked by alias); 19 Sep 2016 13:35:04 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 64436 invoked by uid 89); 19 Sep 2016 13:35:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=2007-2016, 20072016, nickel, Half X-HELO: eu-smtp-delivery-143.mimecast.com From: James Greenhalgh To: CC: , Subject: Re: [Patch soft-fp] Add support for various half-precision conversion routines Date: Mon, 19 Sep 2016 14:34:20 +0100 Message-ID: <1474292060-6401-1-git-send-email-james.greenhalgh@arm.com> In-Reply-To: References: MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:217.140.96.140; IPV:CAL; SCL:-1; CTRY:GB; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(438002)(377424004)(51444003)(24454002)(199003)(54534003)(189002)(11100500001)(189998001)(4326007)(50986999)(76176999)(92566002)(2351001)(50226002)(7846002)(2950100001)(246002)(4610100001)(305945005)(8676002)(5890100001)(19580405001)(356003)(19580395003)(8936002)(36756003)(33646002)(26826002)(106466001)(2906002)(104016004)(87936001)(84326002)(2476003)(512874002)(5660300001)(110136003)(626004)(86362001)(568964002)(586003)(77096005)(15975445007); DIR:OUT; SFP:1101; SCL:1; SRVR:AM2PR08MB0369; H:nebula.arm.com; FPR:; SPF:Pass; PTR:fw-tnat.cambridge.arm.com; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; AM1FFO11FD002; 1:sfiam1jbDgYxrlViB45MoVjkHxyC5BA5I9zK5tqLf3hKdVYL2L527Q+T9IYD1NPxyL7NNtdYTXh40QVMzpzLFJQRSJozvkwvAU9PPrOj4rVWdJXYFkQFW7TtqpdXyYuObj6cnRXAVUsfVckle7zpwnYEszjKYCchC36oxDEJfXH3ysRWKJ4W1WJGjbE85+b57WiL2Fx19nWGqwMZB7+8fygvmZGlYTf3bABJtRyAlIAvrOkvSXQyvbXs/gSkiX2HU5V8XRBRsugAJHjHtMEZMwl2AB5Dx1AaI3E6xzer3mMlPgL5d5FyiWNd1tw1tNBkgBuOon6as8QZFGIz4QfXh9uLn6JGFeqhKt4z29NW9mg8LmC2FFGhMbpLN9s383pAxuX1j6PnFzr4SRGXECQOQfW3xqXRQgUZe279rJGkXPnFDtRCHWDaNk1F7TyMS2vDxIYBulMBOncIWbhbZPsHX+/rY2VyKTmzrAHftalm0Jmvu5i+IpOMnmoxQvufC+9HOEaY7KZSt6H2c3Cz20NqphnL0+r5TpKKYYbSY0sehcmysiNziaxbTt7fVgSjsB2JszV8ruCdg6lT4D3D4OftgYeDTSGQyXpglspwT+/m45I= X-MS-Office365-Filtering-Correlation-Id: d1fb0cf3-01b0-4e0a-076e-08d3e091b7c9 X-Microsoft-Exchange-Diagnostics: 1; AM2PR08MB0369; 2:e+j/kWH7xn3kaKGTOViCsudtMfJlc0NzJB24mWp8hNaeD7maQDPLX83MMRDrYbtlUpYLSn/C+cVfx+Afii+IE7Hl0detRoYnoWntwDm/A5t9mIaKQ74TIBKFxHSkn4H8DG/r/6hQQZKqS+cnlTp5WqBzYlupL/PRk/rB8QL2z0ftZcKPQlE63IWt0Lig7vFq; 3:61xJT+mUA35Lyt7931BvhCowFS/8ZwNFbgfFCIpDm8i6lydMKvvRYSQVlzW3VPWHeStBUU68YKettZGsnPrgaGFlq96JeMfQI7ZilZXrtf1JzqQZ46vIJpSjOHvheAbzO2vkA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ekfLZVh3L0wubGNAv+EZUXR3EgEjyunjXe1WpvAP7TGCLoJvhQa1oEl00xnDo0J1BzwbYq98MIkfIc+w0iQ6YITbgkytKGJISAMDcMj12L5X6Km1YHHWhstPlDSce7fwS576/YmwNLDjKXaT+ac6Qh0hj8bh71eEpiQ+d1Iqen0FWmjLO1UT9ZKjt8ad7pv/ABuNMe+gzk NoDisclaimer: True X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(22074186197030)(183786458502308); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(102415321)(6040176)(601004)(2401047)(13020025)(13013025)(13024025)(13023025)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:AM2PR08MB0369; BCL:0; PCL:0; RULEID:; SRVR:AM2PR08MB0369; X-Microsoft-Exchange-Diagnostics: 1; AM2PR08MB0369; 4:IH7AjsvZ5UX5ZYeG1qTrHngh+SPsbCuyOn7vo/FPVKEde5BX+EBVCi3HQtaDiOuvmxyd5Goik2KPBD34vvXmO0zaKgPiWVoWpsWwPfQVd8c6wAwdslWrjlye+rKX6GdKPJZW1VDyTxczze4bV5w8Dv/ZOFmKwY1hVhtXSxPinxXAsNynFxZifdG7dRwuYyPi7ZFP/wcvqH4LZBWVO2fuLLMYr1h9+RgzTudmZ7C8md7cXrT2Q3EuoK7Pd9NBGbIJrwU02c/OcdAW9Td/C6bMaL/DfO8RT2Fi6qMWiBM+qeDjOjgzbV6rZLW4ULc4Pe7MRYw2cCIFpOLknuANHmc4KHtM5/PiYyobMX9aCZ3WtWIRumAiYjZunGM7rXCwzmV64nuTTPe4OaC1GR3sfmUmazw9kBShe+0JAc9v+t60zwfrlUAm59+ZodDNoG5FTpby3LzkbhkTd3wIiBkxH0Jm1Bvj5lslXULYbzZxVUUyglwOL/B4o88bduECvT6/W2f3bZCETL43kDB4bFIlXYpALFFKZK9ZozUb4Hltc9F4NyB9qsZNYzfjDJUGvj6ZZBYXTGO0OzAWNEjgyjB7Zf656Fb7iZSMNqjvoP5mV7uBXT8= X-Forefront-PRVS: 0070A8666B X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM2PR08MB0369; 23:gfsZ5NiKICnKIp7Peapj55Am6mK08Dd/is6cnuB5e?= =?us-ascii?Q?crwwVmcy2S2Jt5ojivWqYMz6+qWqc26i+KwK/1CxOXThcuqoeWwsah4d0siX?= =?us-ascii?Q?TV55AYxIOp22LpJKP4knjDpvoj07lW1DFwpHQm2mgvPkI98YiCq7wiEsTjKo?= =?us-ascii?Q?9E/BELnJKsg716lLfg6TyixCGxaB9gJIdCiWszNW6R8TUaHcq/oBji21F6Dz?= =?us-ascii?Q?QeIicsFnrfrnS1yV4ITTvBj/84aFNssZsaXE6ZUMvxu3yudCuUaeoU3ocdgQ?= =?us-ascii?Q?MEh285EpT0tbjagmMlKwEVO8AKgoQUat5ErUnJUdniw7k4eYPXC3Q/BaLsDv?= =?us-ascii?Q?reGpSpw35djWtF5+6RsCpOIOf2IQEuu2fms2NN8y+fWkuFMshTRJlnizeefK?= =?us-ascii?Q?3jOKjku48L3rQGqH56AE0m/1Z50MtN+NUVsyhidMZ5Swb800qCaLVtxshFCK?= =?us-ascii?Q?8BgoXZjNA+Ee8I1OY7QeTU9Dz6Tzmc2WnvCMFOdFFq4XAgNSMTHFbGJyN/dY?= =?us-ascii?Q?KyXeYofqCiFc8lUa/N9OQj3Rc60HdL4KPDBvbsx788Vd9DR8B40MvHJYsowx?= =?us-ascii?Q?F7OYK3pEdauxsfFm/NA8PEqSyDkaKZtM5yqQpiVNvU2QW+vIOJYGxtiuTjKr?= =?us-ascii?Q?llcWutZCvPHOMRWYXQm/Y9SR4Uxy8mwGt82zwC0wTa/aTl5m+Ty/aWEhs7Ij?= =?us-ascii?Q?aAgI/wfuNH8RTSka18CgF2lpKOPN+1zVgWHNLwcjfQpX3hCEz33PhomS3QXN?= =?us-ascii?Q?MOj6EBCf77LfCLdXxQcT24/Oq5027tROvjdErJhc6Q99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qvUNz93I+nwvQ10ayk8kZdCm5u8aMvfa3FDH8777FOs49tesKP1xYW53CSZ4NjWlW2YVWw=; 7:W2msAssejyw4qV6SFvpuwv0edWZux8f6aSSp3BfIVqGaWqYkckwChn/33FRHjxjswvPYAODe7SuTZWqPeC4ry5TKsq88nyfanfkfO29zYVTS8QLhNyQObe4f/IlcUOkR+d1auPctJhP69ih1Q283w+5AB/1h9gumHfDsDeRx5u2a/VoNtxch3620V+gihkNYNUGwqsmDsnEoHHNguS1nGqUJvUbH1O1aND4bTD4uzabytg87gzeZooAMSIjWr7LQPlVL4ub7/5X/jCZH1WO8aOn8TI3orepfyZNDUfs3/GiQhg5Jm4PFYne15gh5qQqC SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM2PR08MB0369; 20:H/OqQuK4mhASbwlIlkD9BdleBkAFxu6bpmsN58tE4Yw+jtxT7eVDnO7K6YgGyGtF8LzGWofMBLbYe1cGB3FrulzPEru7Ny+fRepRnJPiMUEXZSLXgxWrJoe+adaQVhYRFx+p3dXWsRxhMHHkGMd7lseal/N2kEBMq56/+ajh60E= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2016 13:34:44.5316 (UTC) X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[217.140.96.140]; Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM2PR08MB0369 X-MC-Unique: tp_8sl9eO_WoZIl1Vofgqg-1 On Wed, Sep 07, 2016 at 04:20:43PM +0000, Joseph Myers wrote: > On Wed, 7 Sep 2016, James Greenhalgh wrote: > > > What I'm not clear about is whether this patch is sufficient on the glibc > > side, or if I also need to wire something up in a Makefile over here? > > No, it's not expected to be wired up in a Makefile, and testing in GCC is > appropriate in this case. > > > In the patch below, soft-fp/half.h is derived from soft-fp/single.h . > > You are, correctly, not including the various macros for arithmetic > operations not using this code, but I think that means a comment to that > effect as in is > appropriate. Thanks. The pointer to this patch was very helpful for resolving your other comments. I've applied the suggested changes, and re-run the GCC testing, which showed no issues in a native bootstrap and test with the _Float16 type enabled, and using these library functions. > But is DF to HF is handled *correctly* by GCC proper (avoiding double > rounding), or is such a libgcc call actually needed to get correct > conversions rather than going via SFmode (or is that double rounding issue > only an issue for AArch32 or for older instruction set variants you're not > dealing with in this patch)? Yes, the instruction emitted is: fcvt d0, h0 Which is a one-step conversion from DFmode to HFmode. As you correctly identify, the older AArch32 instruction sets do not provide this one-step conversion. I expect I'll need to add truncdfhf2 when I start work on the ARM support for _Float16. > It's reasonable to include just the functions you need, as long as the > write-up, the ChangeLog and the patch itself are consistent. Hopefully I've squashed such bugs for this submission. --- This patch adds conversion routines required for _Float16 support in AArch64. These are one-step conversions to and from TImode and TFmode. We need these on AArch64 regardless of presence of the ARMv8.2-A 16-bit floating-point extensions. In the patch below, soft-fp/half.h is derived from soft-fp/single.h . The conversion routines are derivatives of their respective SFmode variants. OK? If so, I'll need help applying the patch to glibc, as I have no commit rights over here. Thanks, James --- 2016-09-19 James Greenhalgh * soft-fp/extendhftf2.c: New. * soft-fp/fixhfti.c: Likewise. * soft-fp/fixunshfti.c: Likewise. * soft-fp/floattihf.c: Likewise. * soft-fp/floatuntihf.c: Likewise. * soft-fp/half.h: Likewise. * soft-fp/trunctfhf2.c: Likewise. diff --git a/soft-fp/extendhftf2.c b/soft-fp/extendhftf2.c new file mode 100644 index 0000000..6ff6438 --- /dev/null +++ b/soft-fp/extendhftf2.c @@ -0,0 +1,53 @@ +/* Software floating-point emulation. + Return an IEEE half converted to IEEE quad + Copyright (C) 1997-2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + In addition to the permissions in the GNU Lesser General Public + License, the Free Software Foundation gives you unlimited + permission to link the compiled version of this file into + combinations with other programs, and to distribute those + combinations without any restriction coming from the use of this + file. (The Lesser General Public License restrictions do apply in + other respects; for example, they cover modification of the file, + and distribution when not linked into a combine executable.) + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define FP_NO_EXACT_UNDERFLOW +#include "soft-fp.h" +#include "half.h" +#include "quad.h" + +TFtype +__extendhftf2 (HFtype a) +{ + FP_DECL_EX; + FP_DECL_H (A); + FP_DECL_Q (R); + TFtype r; + + FP_INIT_EXCEPTIONS; + FP_UNPACK_RAW_H (A, a); +#if (2 * _FP_W_TYPE_SIZE) < _FP_FRACBITS_Q + FP_EXTEND (Q, H, 4, 1, R, A); +#else + FP_EXTEND (Q, H, 2, 1, R, A); +#endif + FP_PACK_RAW_Q (r, R); + FP_HANDLE_EXCEPTIONS; + + return r; +} diff --git a/soft-fp/fixhfti.c b/soft-fp/fixhfti.c new file mode 100644 index 0000000..3610f4c --- /dev/null +++ b/soft-fp/fixhfti.c @@ -0,0 +1,45 @@ +/* Software floating-point emulation. + Convert IEEE half to 128bit signed integer + Copyright (C) 2007-2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + In addition to the permissions in the GNU Lesser General Public + License, the Free Software Foundation gives you unlimited + permission to link the compiled version of this file into + combinations with other programs, and to distribute those + combinations without any restriction coming from the use of this + file. (The Lesser General Public License restrictions do apply in + other respects; for example, they cover modification of the file, + and distribution when not linked into a combine executable.) + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include "soft-fp.h" +#include "half.h" + +TItype +__fixhfti (HFtype a) +{ + FP_DECL_EX; + FP_DECL_H (A); + UTItype r; + + FP_INIT_EXCEPTIONS; + FP_UNPACK_RAW_H (A, a); + FP_TO_INT_H (r, A, TI_BITS, 1); + FP_HANDLE_EXCEPTIONS; + + return r; +} diff --git a/soft-fp/fixunshfti.c b/soft-fp/fixunshfti.c new file mode 100644 index 0000000..30edbfe --- /dev/null +++ b/soft-fp/fixunshfti.c @@ -0,0 +1,45 @@ +/* Software floating-point emulation. + Convert IEEE half to 128bit unsigned integer + Copyright (C) 2007-2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + In addition to the permissions in the GNU Lesser General Public + License, the Free Software Foundation gives you unlimited + permission to link the compiled version of this file into + combinations with other programs, and to distribute those + combinations without any restriction coming from the use of this + file. (The Lesser General Public License restrictions do apply in + other respects; for example, they cover modification of the file, + and distribution when not linked into a combine executable.) + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include "soft-fp.h" +#include "half.h" + +UTItype +__fixunshfti (HFtype a) +{ + FP_DECL_EX; + FP_DECL_H (A); + UTItype r; + + FP_INIT_EXCEPTIONS; + FP_UNPACK_RAW_H (A, a); + FP_TO_INT_H (r, A, TI_BITS, 0); + FP_HANDLE_EXCEPTIONS; + + return r; +} diff --git a/soft-fp/floattihf.c b/soft-fp/floattihf.c new file mode 100644 index 0000000..74ac83a --- /dev/null +++ b/soft-fp/floattihf.c @@ -0,0 +1,45 @@ +/* Software floating-point emulation. + Convert a 128bit signed integer to IEEE half + Copyright (C) 2007-2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + In addition to the permissions in the GNU Lesser General Public + License, the Free Software Foundation gives you unlimited + permission to link the compiled version of this file into + combinations with other programs, and to distribute those + combinations without any restriction coming from the use of this + file. (The Lesser General Public License restrictions do apply in + other respects; for example, they cover modification of the file, + and distribution when not linked into a combine executable.) + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include "soft-fp.h" +#include "half.h" + +HFtype +__floattihf (TItype i) +{ + FP_DECL_EX; + FP_DECL_H (A); + HFtype a; + + FP_INIT_ROUNDMODE; + FP_FROM_INT_H (A, i, TI_BITS, UTItype); + FP_PACK_RAW_H (a, A); + FP_HANDLE_EXCEPTIONS; + + return a; +} diff --git a/soft-fp/floatuntihf.c b/soft-fp/floatuntihf.c new file mode 100644 index 0000000..90e77c2 --- /dev/null +++ b/soft-fp/floatuntihf.c @@ -0,0 +1,45 @@ +/* Software floating-point emulation. + Convert a 128bit unsigned integer to IEEE half. + Copyright (C) 2007-2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + In addition to the permissions in the GNU Lesser General Public + License, the Free Software Foundation gives you unlimited + permission to link the compiled version of this file into + combinations with other programs, and to distribute those + combinations without any restriction coming from the use of this + file. (The Lesser General Public License restrictions do apply in + other respects; for example, they cover modification of the file, + and distribution when not linked into a combine executable.) + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include "soft-fp.h" +#include "half.h" + +HFtype +__floatuntihf (UTItype i) +{ + FP_DECL_EX; + FP_DECL_H (A); + HFtype a; + + FP_INIT_ROUNDMODE; + FP_FROM_INT_H (A, i, TI_BITS, UTItype); + FP_PACK_RAW_H (a, A); + FP_HANDLE_EXCEPTIONS; + + return a; +} diff --git a/soft-fp/half.h b/soft-fp/half.h new file mode 100644 index 0000000..ba75297 --- /dev/null +++ b/soft-fp/half.h @@ -0,0 +1,170 @@ +/* Software floating-point emulation. + Definitions for IEEE Half Precision. + Copyright (C) 1997-2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + In addition to the permissions in the GNU Lesser General Public + License, the Free Software Foundation gives you unlimited + permission to link the compiled version of this file into + combinations with other programs, and to distribute those + combinations without any restriction coming from the use of this + file. (The Lesser General Public License restrictions do apply in + other respects; for example, they cover modification of the file, + and distribution when not linked into a combine executable.) + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef SOFT_FP_HALF_H +#define SOFT_FP_HALF_H 1 + +#if _FP_W_TYPE_SIZE < 32 +# error "Here's a nickel kid. Go buy yourself a real computer." +#endif + +#define _FP_FRACTBITS_H (_FP_W_TYPE_SIZE) + +#define _FP_FRACTBITS_DW_H (_FP_W_TYPE_SIZE) + +#define _FP_FRACBITS_H 11 +#define _FP_FRACXBITS_H (_FP_FRACTBITS_H - _FP_FRACBITS_H) +#define _FP_WFRACBITS_H (_FP_WORKBITS + _FP_FRACBITS_H) +#define _FP_WFRACXBITS_H (_FP_FRACTBITS_H - _FP_WFRACBITS_H) +#define _FP_EXPBITS_H 5 +#define _FP_EXPBIAS_H 15 +#define _FP_EXPMAX_H 31 + +#define _FP_QNANBIT_H ((_FP_W_TYPE) 1 << (_FP_FRACBITS_H-2)) +#define _FP_QNANBIT_SH_H ((_FP_W_TYPE) 1 << (_FP_FRACBITS_H-2+_FP_WORKBITS)) +#define _FP_IMPLBIT_H ((_FP_W_TYPE) 1 << (_FP_FRACBITS_H-1)) +#define _FP_IMPLBIT_SH_H ((_FP_W_TYPE) 1 << (_FP_FRACBITS_H-1+_FP_WORKBITS)) +#define _FP_OVERFLOW_H ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_H)) + +#define _FP_WFRACBITS_DW_H (2 * _FP_WFRACBITS_H) +#define _FP_WFRACXBITS_DW_H (_FP_FRACTBITS_DW_H - _FP_WFRACBITS_DW_H) +#define _FP_HIGHBIT_DW_H \ + ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_DW_H - 1) % _FP_W_TYPE_SIZE) + +/* The implementation of _FP_MUL_MEAT_H and _FP_DIV_MEAT_H should be + chosen by the target machine. */ + +typedef float HFtype __attribute__ ((mode (HF))); + +union _FP_UNION_H +{ + HFtype flt; + struct _FP_STRUCT_LAYOUT + { +#if __BYTE_ORDER == __BIG_ENDIAN + unsigned sign : 1; + unsigned exp : _FP_EXPBITS_H; + unsigned frac : _FP_FRACBITS_H - (_FP_IMPLBIT_H != 0); +#else + unsigned frac : _FP_FRACBITS_H - (_FP_IMPLBIT_H != 0); + unsigned exp : _FP_EXPBITS_H; + unsigned sign : 1; +#endif + } bits __attribute__ ((packed)); +}; + +#define FP_DECL_H(X) _FP_DECL (1, X) +#define FP_UNPACK_RAW_H(X, val) _FP_UNPACK_RAW_1 (H, X, (val)) +#define FP_UNPACK_RAW_HP(X, val) _FP_UNPACK_RAW_1_P (H, X, (val)) +#define FP_PACK_RAW_H(val, X) _FP_PACK_RAW_1 (H, (val), X) +#define FP_PACK_RAW_HP(val, X) \ + do \ + { \ + if (!FP_INHIBIT_RESULTS) \ + _FP_PACK_RAW_1_P (H, (val), X); \ + } \ + while (0) + +#define FP_UNPACK_H(X, val) \ + do \ + { \ + _FP_UNPACK_RAW_1 (H, X, (val)); \ + _FP_UNPACK_CANONICAL (H, 1, X); \ + } \ + while (0) + +#define FP_UNPACK_HP(X, val) \ + do \ + { \ + _FP_UNPACK_RAW_1_P (H, X, (val)); \ + _FP_UNPACK_CANONICAL (H, 1, X); \ + } \ + while (0) + +#define FP_UNPACK_SEMIRAW_H(X, val) \ + do \ + { \ + _FP_UNPACK_RAW_1 (H, X, (val)); \ + _FP_UNPACK_SEMIRAW (H, 1, X); \ + } \ + while (0) + +#define FP_UNPACK_SEMIRAW_HP(X, val) \ + do \ + { \ + _FP_UNPACK_RAW_1_P (H, X, (val)); \ + _FP_UNPACK_SEMIRAW (H, 1, X); \ + } \ + while (0) + +#define FP_PACK_H(val, X) \ + do \ + { \ + _FP_PACK_CANONICAL (H, 1, X); \ + _FP_PACK_RAW_1 (H, (val), X); \ + } \ + while (0) + +#define FP_PACK_HP(val, X) \ + do \ + { \ + _FP_PACK_CANONICAL (H, 1, X); \ + if (!FP_INHIBIT_RESULTS) \ + _FP_PACK_RAW_1_P (H, (val), X); \ + } \ + while (0) + +#define FP_PACK_SEMIRAW_H(val, X) \ + do \ + { \ + _FP_PACK_SEMIRAW (H, 1, X); \ + _FP_PACK_RAW_1 (H, (val), X); \ + } \ + while (0) + +#define FP_PACK_SEMIRAW_HP(val, X) \ + do \ + { \ + _FP_PACK_SEMIRAW (H, 1, X); \ + if (!FP_INHIBIT_RESULTS) \ + _FP_PACK_RAW_1_P (H, (val), X); \ + } \ + while (0) + +#define FP_TO_INT_H(r, X, rsz, rsg) _FP_TO_INT (H, 1, (r), X, (rsz), (rsg)) +#define FP_TO_INT_ROUND_H(r, X, rsz, rsg) \ + _FP_TO_INT_ROUND (H, 1, (r), X, (rsz), (rsg)) +#define FP_FROM_INT_H(X, r, rs, rt) _FP_FROM_INT (H, 1, X, (r), (rs), rt) + +/* HFmode arithmetic is not implemented. */ + +#define _FP_FRAC_HIGH_H(X) _FP_FRAC_HIGH_1 (X) +#define _FP_FRAC_HIGH_RAW_H(X) _FP_FRAC_HIGH_1 (X) +#define _FP_FRAC_HIGH_DW_H(X) _FP_FRAC_HIGH_1 (X) + +#endif /* !SOFT_FP_HALF_H */ diff --git a/soft-fp/trunctfhf2.c b/soft-fp/trunctfhf2.c new file mode 100644 index 0000000..0500b14 --- /dev/null +++ b/soft-fp/trunctfhf2.c @@ -0,0 +1,52 @@ +/* Software floating-point emulation. + Truncate IEEE quad into IEEE half. + Copyright (C) 1997-2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + In addition to the permissions in the GNU Lesser General Public + License, the Free Software Foundation gives you unlimited + permission to link the compiled version of this file into + combinations with other programs, and to distribute those + combinations without any restriction coming from the use of this + file. (The Lesser General Public License restrictions do apply in + other respects; for example, they cover modification of the file, + and distribution when not linked into a combine executable.) + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include "soft-fp.h" +#include "half.h" +#include "quad.h" + +HFtype +__trunctfhf2 (TFtype a) +{ + FP_DECL_EX; + FP_DECL_Q (A); + FP_DECL_H (R); + HFtype r; + + FP_INIT_ROUNDMODE; + FP_UNPACK_SEMIRAW_Q (A, a); +#if (2 * _FP_W_TYPE_SIZE) < _FP_FRACBITS_Q + FP_TRUNC (H, Q, 1, 4, R, A); +#else + FP_TRUNC (H, Q, 1, 2, R, A); +#endif + FP_PACK_SEMIRAW_H (r, R); + FP_HANDLE_EXCEPTIONS; + + return r; +}