| 1 | /* _Decimal32 nearbyintd32 implementation. |
| 2 | |
| 3 | Copyright (C) 2018 Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of the Decimal Floating Point C Library. |
| 6 | |
| 7 | The Decimal Floating Point C Library is free software; you can |
| 8 | redistribute it and/or modify it under the terms of the GNU Lesser |
| 9 | General Public License version 2.1. |
| 10 | |
| 11 | The Decimal Floating Point C Library is distributed in the hope that |
| 12 | it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
| 13 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 14 | the GNU Lesser General Public License version 2.1 for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU Lesser General Public |
| 17 | License version 2.1 along with the Decimal Floating Point C Library; |
| 18 | if not, write to the Free Software Foundation, Inc., 51 Franklin |
| 19 | Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | |
| 21 | Please see libdfp/COPYING.txt for more information. */ |
| 22 | |
| 23 | #ifndef _DECIMAL_SIZE |
| 24 | # define _DECIMAL_SIZE 32 |
| 25 | #endif |
| 26 | |
| 27 | #include <math.h> |
| 28 | |
| 29 | #define FUNCTION_NAME nearbyint |
| 30 | #include <dfpmacro.h> |
| 31 | |
| 32 | DEC_TYPE |
| 33 | INTERNAL_FUNCTION_NAME (DEC_TYPE x) |
| 34 | { |
| 35 | #if _DECIMAL_SIZE == 128 |
| 36 | _Decimal128 tmp = x; |
| 37 | #else |
| 38 | _Decimal64 tmp = (_Decimal64) x; |
| 39 | #endif |
| 40 | |
| 41 | /* Round according current dfp rounding mode without inexact exception. */ |
| 42 | __asm__ ( |
| 43 | #if _DECIMAL_SIZE == 128 |
| 44 | "fixtr %0,0,%0,4" |
| 45 | #else |
| 46 | "fidtr %0,0,%0,4" |
| 47 | #endif |
| 48 | : "+f" (tmp)); |
| 49 | return (DEC_TYPE) tmp; |
| 50 | } |
| 51 | weak_alias (INTERNAL_FUNCTION_NAME, EXTERNAL_FUNCTION_NAME) |