1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifdef __SOFTFP__ 26 27 // Soft float function declarations 28 extern "C" { 29 extern float __aeabi_fadd(float, float); 30 extern float __aeabi_fsub(float, float); 31 extern double __aeabi_dadd(double, double); 32 extern double __aeabi_dsub(double, double); 33 34 extern float __aeabi_fadd_extlib(float, float); 35 extern float __aeabi_fsub_extlib(float, float); 36 extern double __aeabi_dadd_extlib(double, double); 37 extern double __aeabi_dsub_extlib(double, double); 38 }; 39 40 #ifdef SOFTFLOAT_EXTERNAL 41 42 extern "C" { 43 #include "softfloat.h" 44 } 45 46 #include <cstring> 47 48 static float __aeabi_float_handling(float natA, float natB, bool add) { 49 float32_t libC; 50 51 libC = add ? f32_add(reinterpret_cast<float32_t &>(natA), reinterpret_cast<float32_t &>(natB)) 52 : f32_sub(reinterpret_cast<float32_t &>(natA), reinterpret_cast<float32_t &>(natB)); 53 54 return reinterpret_cast<float &>(libC); 55 } 56 57 static double __aeabi_double_handling(double natA, double natB, bool add) { 58 float64_t libC; 59 60 libC = add ? f64_add(reinterpret_cast<float64_t &>(natA), reinterpret_cast<float64_t &>(natB)) 61 : f64_sub(reinterpret_cast<float64_t &>(natA), reinterpret_cast<float64_t &>(natB)); 62 63 return reinterpret_cast<double &>(libC); 64 } 65 66 float __aeabi_fadd_extlib(float a, float b) { 67 return __aeabi_float_handling(a, b, true); 68 } 69 70 float __aeabi_fsub_extlib(float a, float b) { 71 return __aeabi_float_handling(a, b, false); 72 } 73 74 double __aeabi_dadd_extlib(double a, double b) { 75 return __aeabi_double_handling(a, b, true); 76 } 77 78 double __aeabi_dsub_extlib(double a, double b) { 79 return __aeabi_double_handling(a, b, false); 80 } 81 82 #else 83 84 float __aeabi_fadd_extlib(float a, float b) { 85 return __aeabi_fadd(a, b); 86 } 87 88 float __aeabi_fsub_extlib(float a, float b) { 89 return __aeabi_fsub(a, b); 90 } 91 92 double __aeabi_dadd_extlib(double a, double b) { 93 return __aeabi_dadd(a, b); 94 } 95 96 double __aeabi_dsub_extlib(double a, double b) { 97 return __aeabi_dsub(a, b); 98 } 99 100 #endif 101 102 #endif // __SOFTFP__