1 /* 2 * Copyright (C) 2013 Andrew Turner 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 */ 27 28 #ifndef AEABI_VFP_H 29 #define AEABI_VFP_H 30 31 #include <machine/acle-compat.h> 32 33 /* 34 * ASM helper macros. These allow the functions to be changed depending on 35 * the endian-ness we are building for. 36 */ 37 38 /* Allow the name of the function to be changed depending on the ABI */ 39 #ifndef __ARM_PCS_VFP 40 #define AEABI_ENTRY(x) ENTRY(__aeabi_ ## x ## _vfp) 41 #define AEABI_END(x) END(__aeabi_ ## x ## _vfp) 42 #else 43 #define AEABI_ENTRY(x) ENTRY(__aeabi_ ## x) 44 #define AEABI_END(x) END(__aeabi_ ## x) 45 #endif 46 47 /* 48 * These should be used when a function either takes, or returns a floating 49 * point falue. They will load the data from an ARM to a VFP register(s), 50 * or from a VFP to an ARM register 51 */ 52 #ifdef __ARM_BIG_ENDIAN 53 #define LOAD_DREG(vreg, reg0, reg1) vmov vreg, reg1, reg0 54 #define UNLOAD_DREG(reg0, reg1, vreg) vmov reg1, reg0, vreg 55 #else 56 #define LOAD_DREG(vreg, reg0, reg1) vmov vreg, reg0, reg1 57 #define UNLOAD_DREG(reg0, reg1, vreg) vmov reg0, reg1, vreg 58 #endif 59 60 #define LOAD_SREGS(vreg0, vreg1, reg0, reg1) vmov vreg0, vreg1, reg0, reg1 61 #define LOAD_SREG(vreg, reg) vmov vreg, reg 62 #define UNLOAD_SREG(reg, vreg) vmov reg, vreg 63 64 /* 65 * C Helper macros 66 */ 67 68 #if __ARM_ARCH >= 6 && !defined(SOFTFLOAT_FOR_GCC) 69 /* 70 * Generate a function that will either call into the VFP implementation, 71 * or the soft float version for a given __aeabi_* helper. The function 72 * will take a single argument of the type given by in_type. 73 */ 74 #define AEABI_FUNC(name, in_type, soft_func) \ 75 __aeabi_ ## name(in_type a) \ 76 { \ 77 if (_libc_arm_fpu_present) \ 78 return __aeabi_ ## name ## _vfp(a); \ 79 else \ 80 return soft_func (a); \ 81 } 82 83 /* As above, but takes two arguments of the same type */ 84 #define AEABI_FUNC2(name, in_type, soft_func) \ 85 __aeabi_ ## name(in_type a, in_type b) \ 86 { \ 87 if (_libc_arm_fpu_present) \ 88 return __aeabi_ ## name ## _vfp(a, b); \ 89 else \ 90 return soft_func (a, b); \ 91 } 92 93 /* As above, but with the soft float arguments reversed */ 94 #define AEABI_FUNC2_REV(name, in_type, soft_func) \ 95 __aeabi_ ## name(in_type a, in_type b) \ 96 { \ 97 if (_libc_arm_fpu_present) \ 98 return __aeabi_ ## name ## _vfp(a, b); \ 99 else \ 100 return soft_func (b, a); \ 101 } 102 #else 103 /* 104 * Helper macros for when we are only able to use the softfloat 105 * version of these functions, i.e. on arm before armv6. 106 */ 107 #define AEABI_FUNC(name, in_type, soft_func) \ 108 __aeabi_ ## name(in_type a) \ 109 { \ 110 return soft_func (a); \ 111 } 112 113 /* As above, but takes two arguments of the same type */ 114 #define AEABI_FUNC2(name, in_type, soft_func) \ 115 __aeabi_ ## name(in_type a, in_type b) \ 116 { \ 117 return soft_func (a, b); \ 118 } 119 120 /* As above, but with the soft float arguments reversed */ 121 #define AEABI_FUNC2_REV(name, in_type, soft_func) \ 122 __aeabi_ ## name(in_type a, in_type b) \ 123 { \ 124 return soft_func (b, a); \ 125 } 126 #endif 127 128 #endif 129 130