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$");
29230191Sdas
30230191Sdas#include <fenv.h>
31230191Sdas#include <float.h>
32230191Sdas
33266337Sian#ifndef __ARM_PCS_VFP
34230367Sdas#include "softfloat-for-gcc.h"
35230367Sdas#include "milieu.h"
36230191Sdas#include "softfloat.h"
37266337Sian#endif
38230191Sdas
39230191Sdasint
40230191Sdas__flt_rounds(void)
41230191Sdas{
42266337Sian	int mode;
43230191Sdas
44266337Sian#ifndef __ARM_PCS_VFP
45230191Sdas	/*
46230191Sdas	 * Translate our rounding modes to the unnamed
47230191Sdas	 * manifest constants required by C99 et. al.
48230191Sdas	 */
49266337Sian	mode = __softfloat_float_rounding_mode;
50266337Sian#else /* __ARM_PCS_VFP */
51266337Sian	/*
52266337Sian	 * Read the floating-point status and control register
53266337Sian	 */
54266337Sian	__asm __volatile("vmrs %0, fpscr" : "=&r"(mode));
55266337Sian	mode &= _ROUND_MASK;
56266337Sian#endif /* __ARM_PCS_VFP */
57266337Sian
58266337Sian	switch (mode) {
59230191Sdas	case FE_TOWARDZERO:
60230191Sdas		return (0);
61230191Sdas	case FE_TONEAREST:
62230191Sdas		return (1);
63230191Sdas	case FE_UPWARD:
64230191Sdas		return (2);
65230191Sdas	case FE_DOWNWARD:
66230191Sdas		return (3);
67230191Sdas	}
68230191Sdas	return (-1);
69230191Sdas}
70