float128-hw.c revision 1.1.1.8
1/* Automatic switching between software and hardware IEEE 128-bit 2 floating-point emulation for PowerPC. 3 4 Copyright (C) 2016-2022 Free Software Foundation, Inc. 5 This file is part of the GNU C Library. 6 Contributed by Michael Meissner (meissner@linux.vnet.ibm.com) 7 Code is based on the main soft-fp library written by: 8 Richard Henderson (rth@cygnus.com) and 9 Jakub Jelinek (jj@ultra.linux.cz). 10 11 The GNU C Library is free software; you can redistribute it and/or 12 modify it under the terms of the GNU Lesser General Public 13 License as published by the Free Software Foundation; either 14 version 2.1 of the License, or (at your option) any later version. 15 16 In addition to the permissions in the GNU Lesser General Public 17 License, the Free Software Foundation gives you unlimited 18 permission to link the compiled version of this file into 19 combinations with other programs, and to distribute those 20 combinations without any restriction coming from the use of this 21 file. (The Lesser General Public License restrictions do apply in 22 other respects; for example, they cover modification of the file, 23 and distribution when not linked into a combine executable.) 24 25 The GNU C Library is distributed in the hope that it will be useful, 26 but WITHOUT ANY WARRANTY; without even the implied warranty of 27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 28 Lesser General Public License for more details. 29 30 You should have received a copy of the GNU Lesser General Public 31 License along with the GNU C Library; if not, see 32 <http://www.gnu.org/licenses/>. */ 33 34#include <soft-fp.h> 35#include <quad-float128.h> 36 37#ifndef __FLOAT128_HARDWARE__ 38#error "This module must be compiled with IEEE 128-bit hardware support" 39#endif 40 41TFtype 42__addkf3_hw (TFtype a, TFtype b) 43{ 44 return a + b; 45} 46 47TFtype 48__subkf3_hw (TFtype a, TFtype b) 49{ 50 return a - b; 51} 52 53TFtype 54__mulkf3_hw (TFtype a, TFtype b) 55{ 56 return a * b; 57} 58 59TFtype 60__divkf3_hw (TFtype a, TFtype b) 61{ 62 return a / b; 63} 64 65TFtype 66__negkf2_hw (TFtype a) 67{ 68 return -a; 69} 70 71TFtype 72__floatsikf_hw (SItype_ppc a) 73{ 74 return (TFtype) a; 75} 76 77TFtype 78__floatunsikf_hw (USItype_ppc a) 79{ 80 return (TFtype) a; 81} 82 83TFtype 84__floatdikf_hw (DItype_ppc a) 85{ 86 return (TFtype) a; 87} 88 89TFtype 90__floatundikf_hw (UDItype_ppc a) 91{ 92 return (TFtype) a; 93} 94 95SItype_ppc 96__fixkfsi_hw (TFtype a) 97{ 98 return (SItype_ppc) a; 99} 100 101USItype_ppc 102__fixunskfsi_hw (TFtype a) 103{ 104 return (USItype_ppc) a; 105} 106 107DItype_ppc 108__fixkfdi_hw (TFtype a) 109{ 110 return (DItype_ppc) a; 111} 112 113UDItype_ppc 114__fixunskfdi_hw (TFtype a) 115{ 116 return (UDItype_ppc) a; 117} 118 119TFtype 120__extendsfkf2_hw (float a) 121{ 122 return (TFtype) a; 123} 124 125TFtype 126__extenddfkf2_hw (double a) 127{ 128 return (TFtype) a; 129} 130 131float 132__trunckfsf2_hw (TFtype a) 133{ 134 return (float) a; 135} 136 137double 138__trunckfdf2_hw (TFtype a) 139{ 140 return (double) a; 141} 142 143/* __eqkf2 returns 0 if equal, or 1 if not equal or NaN. */ 144CMPtype 145__eqkf2_hw (TFtype a, TFtype b) 146{ 147 return (a != b); 148} 149 150/* __gekf2 returns -1 if a < b, 0 if a == b, +1 if a > b, or -2 if NaN. */ 151CMPtype 152__gekf2_hw (TFtype a, TFtype b) 153{ 154 if (a < b) 155 return -1; 156 157 else if (__builtin_isunordered (a, b)) 158 return -2; 159 160 else if (a == b) 161 return 0; 162 163 return 1; 164} 165 166/* __lekf2 returns -1 if a < b, 0 if a == b, +1 if a > b, or +2 if NaN. */ 167CMPtype 168__lekf2_hw (TFtype a, TFtype b) 169{ 170 if (a < b) 171 return -1; 172 173 else if (__builtin_isunordered (a, b)) 174 return 2; 175 176 else if (a == b) 177 return 0; 178 179 return 1; 180} 181 182/* __unordkf2 returns 1 if NaN or 0 otherwise. */ 183CMPtype 184__unordkf2_hw (TFtype a, TFtype b) 185{ 186 return (__builtin_isunordered (a, b)) ? 1 : 0; 187} 188 189/* Convert __float128 to __ibm128. */ 190IBM128_TYPE 191__extendkftf2_hw (TFtype value) 192{ 193 IBM128_TYPE ret; 194 195 CVT_FLOAT128_TO_IBM128 (ret, value); 196 return ret; 197} 198 199/* Convert __ibm128 to __float128. */ 200TFtype 201__trunctfkf2_hw (IBM128_TYPE value) 202{ 203 TFtype ret; 204 205 CVT_IBM128_TO_FLOAT128 (ret, value); 206 return ret; 207} 208