flt_rounds.c revision 230191
1230191Sdas/*-
2230191Sdas * Copyright (c) 2012 Ian Lepore <freebsd@damnhippie.dyndns.org>
3230191Sdas * All rights reserved.
4230191Sdas *
5230191Sdas * Redistribution and use in source and binary forms, with or without
6230191Sdas * modification, are permitted provided that the following conditions
7230191Sdas * are met:
8230191Sdas * 1. Redistributions of source code must retain the above copyright
9230191Sdas *    notice, this list of conditions and the following disclaimer.
10230191Sdas * 2. Redistributions in binary form must reproduce the above copyright
11230191Sdas *    notice, this list of conditions and the following disclaimer in the
12230191Sdas *    documentation and/or other materials provided with the distribution.
13230191Sdas *
14230191Sdas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15230191Sdas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16230191Sdas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17230191Sdas * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18230191Sdas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19230191Sdas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20230191Sdas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21230191Sdas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22230191Sdas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23230191Sdas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24230191Sdas * SUCH DAMAGE.
25230191Sdas */
26230191Sdas
27230191Sdas#include <sys/cdefs.h>
28230191Sdas__FBSDID("$FreeBSD: head/lib/libc/arm/gen/flt_rounds.c 230191 2012-01-16 04:08:29Z das $");
29230191Sdas
30230191Sdas#include <fenv.h>
31230191Sdas#include <float.h>
32230191Sdas
33230191Sdas#include "softfloat.h"
34230191Sdas
35230191Sdasint
36230191Sdas__flt_rounds(void)
37230191Sdas{
38230191Sdas
39230191Sdas#ifndef ARM_HARD_FLOAT
40230191Sdas	/*
41230191Sdas	 * Translate our rounding modes to the unnamed
42230191Sdas	 * manifest constants required by C99 et. al.
43230191Sdas	 */
44230191Sdas	switch (__softfloat_float_rounding_mode) {
45230191Sdas	case FE_TOWARDZERO:
46230191Sdas		return (0);
47230191Sdas	case FE_TONEAREST:
48230191Sdas		return (1);
49230191Sdas	case FE_UPWARD:
50230191Sdas		return (2);
51230191Sdas	case FE_DOWNWARD:
52230191Sdas		return (3);
53230191Sdas	}
54230191Sdas	return (-1);
55230191Sdas#else /* ARM_HARD_FLOAT */
56230191Sdas	/*
57230191Sdas	 * Apparently, the rounding mode is specified as part of the
58230191Sdas	 * instruction format on ARM, so the dynamic rounding mode is
59230191Sdas	 * indeterminate.  Some FPUs may differ.
60230191Sdas	 */
61230191Sdas	return (-1);
62230191Sdas#endif /* ARM_HARD_FLOAT */
63230191Sdas}
64