1 /*- 2 * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG> 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 * $FreeBSD$ 27 */ 28 29 #ifndef _FENV_H_ 30 #define _FENV_H_ 31 32 #include <sys/_types.h> 33 #include <sys/cdefs.h> 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 typedef __uint64_t fenv_t; 40 typedef __uint64_t fexcept_t; 41 42 /* Exception flags */ 43 #define FE_INVALID 0x00000001 44 #define FE_DIVBYZERO 0x00000002 45 #define FE_OVERFLOW 0x00000004 46 #define FE_UNDERFLOW 0x00000008 47 #define FE_INEXACT 0x00000010 48 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \ 49 FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) 50 51 /* 52 * Rounding modes 53 * 54 * We can't just use the hardware bit values here, because that would 55 * make FE_UPWARD and FE_DOWNWARD negative, which is not allowed. 56 */ 57 #define FE_TONEAREST 0x0 58 #define FE_UPWARD 0x1 59 #define FE_DOWNWARD 0x2 60 #define FE_TOWARDZERO 0x3 61 #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \ 62 FE_UPWARD | FE_TOWARDZERO) 63 #define _ROUND_SHIFT 22 64 65 /* We need to be able to map status flag positions to mask flag positions */ 66 #define _FPUSW_SHIFT 8 67 #define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT) 68 69 #define __mrs_fpcr(__r) __asm __volatile("mrs %0, fpcr" : "=r" (__r)) 70 #define __msr_fpcr(__r) __asm __volatile("msr fpcr, %0" : : "r" (__r)) 71 72 #define __mrs_fpsr(__r) __asm __volatile("mrs %0, fpsr" : "=r" (__r)) 73 #define __msr_fpsr(__r) __asm __volatile("msr fpsr, %0" : : "r" (__r)) 74 75 #if !defined(__declare_fenv_inline) && defined(__declare_extern_inline) 76 #define __declare_fenv_inline(type) __declare_extern_inline(type) 77 #endif 78 79 #ifdef __declare_fenv_inline 80 #include <machine/fenv-fp.h> 81 #endif 82 83 #ifdef __cplusplus 84 } 85 #endif 86 87 #endif /* !_FENV_H_ */ 88