186d131a0SDavid Schultz /*- 286d131a0SDavid Schultz * Copyright (c) 2012 Ian Lepore <freebsd@damnhippie.dyndns.org> 386d131a0SDavid Schultz * All rights reserved. 486d131a0SDavid Schultz * 586d131a0SDavid Schultz * Redistribution and use in source and binary forms, with or without 686d131a0SDavid Schultz * modification, are permitted provided that the following conditions 786d131a0SDavid Schultz * are met: 886d131a0SDavid Schultz * 1. Redistributions of source code must retain the above copyright 986d131a0SDavid Schultz * notice, this list of conditions and the following disclaimer. 1086d131a0SDavid Schultz * 2. Redistributions in binary form must reproduce the above copyright 1186d131a0SDavid Schultz * notice, this list of conditions and the following disclaimer in the 1286d131a0SDavid Schultz * documentation and/or other materials provided with the distribution. 1386d131a0SDavid Schultz * 1486d131a0SDavid Schultz * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1586d131a0SDavid Schultz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1686d131a0SDavid Schultz * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1786d131a0SDavid Schultz * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1886d131a0SDavid Schultz * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1986d131a0SDavid Schultz * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2086d131a0SDavid Schultz * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2186d131a0SDavid Schultz * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2286d131a0SDavid Schultz * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2386d131a0SDavid Schultz * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2486d131a0SDavid Schultz * SUCH DAMAGE. 2586d131a0SDavid Schultz */ 2686d131a0SDavid Schultz 2786d131a0SDavid Schultz #include <sys/cdefs.h> 2886d131a0SDavid Schultz __FBSDID("$FreeBSD$"); 2986d131a0SDavid Schultz 3086d131a0SDavid Schultz #include <fenv.h> 3186d131a0SDavid Schultz #include <float.h> 3286d131a0SDavid Schultz 33*7082a2cfSDavid Schultz #include "softfloat-for-gcc.h" 34*7082a2cfSDavid Schultz #include "milieu.h" 3586d131a0SDavid Schultz #include "softfloat.h" 3686d131a0SDavid Schultz 3786d131a0SDavid Schultz int 3886d131a0SDavid Schultz __flt_rounds(void) 3986d131a0SDavid Schultz { 4086d131a0SDavid Schultz 4186d131a0SDavid Schultz #ifndef ARM_HARD_FLOAT 4286d131a0SDavid Schultz /* 4386d131a0SDavid Schultz * Translate our rounding modes to the unnamed 4486d131a0SDavid Schultz * manifest constants required by C99 et. al. 4586d131a0SDavid Schultz */ 4686d131a0SDavid Schultz switch (__softfloat_float_rounding_mode) { 4786d131a0SDavid Schultz case FE_TOWARDZERO: 4886d131a0SDavid Schultz return (0); 4986d131a0SDavid Schultz case FE_TONEAREST: 5086d131a0SDavid Schultz return (1); 5186d131a0SDavid Schultz case FE_UPWARD: 5286d131a0SDavid Schultz return (2); 5386d131a0SDavid Schultz case FE_DOWNWARD: 5486d131a0SDavid Schultz return (3); 5586d131a0SDavid Schultz } 5686d131a0SDavid Schultz return (-1); 5786d131a0SDavid Schultz #else /* ARM_HARD_FLOAT */ 5886d131a0SDavid Schultz /* 5986d131a0SDavid Schultz * Apparently, the rounding mode is specified as part of the 6086d131a0SDavid Schultz * instruction format on ARM, so the dynamic rounding mode is 6186d131a0SDavid Schultz * indeterminate. Some FPUs may differ. 6286d131a0SDavid Schultz */ 6386d131a0SDavid Schultz return (-1); 6486d131a0SDavid Schultz #endif /* ARM_HARD_FLOAT */ 6586d131a0SDavid Schultz } 66