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 34 typedef __uint64_t fenv_t; 35 typedef __uint64_t fexcept_t; 36 37 /* Exception flags */ 38 #define FE_INVALID 0x00000001 39 #define FE_DIVBYZERO 0x00000002 40 #define FE_OVERFLOW 0x00000004 41 #define FE_UNDERFLOW 0x00000008 42 #define FE_INEXACT 0x00000010 43 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \ 44 FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) 45 46 /* 47 * Rounding modes 48 * 49 * We can't just use the hardware bit values here, because that would 50 * make FE_UPWARD and FE_DOWNWARD negative, which is not allowed. 51 */ 52 #define FE_TONEAREST 0x0 53 #define FE_UPWARD 0x1 54 #define FE_DOWNWARD 0x2 55 #define FE_TOWARDZERO 0x3 56 #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \ 57 FE_UPWARD | FE_TOWARDZERO) 58 #define _ROUND_SHIFT 22 59 60 /* We need to be able to map status flag positions to mask flag positions */ 61 #define _FPUSW_SHIFT 8 62 #define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT) 63 64 #define __mrs_fpcr(__r) __asm __volatile("mrs %0, fpcr" : "=r" (__r)) 65 #define __msr_fpcr(__r) __asm __volatile("msr fpcr, %0" : : "r" (__r)) 66 67 #define __mrs_fpsr(__r) __asm __volatile("mrs %0, fpsr" : "=r" (__r)) 68 #define __msr_fpsr(__r) __asm __volatile("msr fpsr, %0" : : "r" (__r)) 69 70 #ifndef __fenv_static 71 #define __fenv_static static 72 #include <machine/fenv-fp.h> 73 #endif 74 75 #endif /* !_FENV_H_ */ 76