1264696Sandrew/*
2264696Sandrew * Copyright (C) 2014 Andrew Turner
3264696Sandrew * All rights reserved.
4264696Sandrew *
5264696Sandrew * Redistribution and use in source and binary forms, with or without
6264696Sandrew * modification, are permitted provided that the following conditions
7264696Sandrew * are met:
8264696Sandrew * 1. Redistributions of source code must retain the above copyright
9264696Sandrew *    notice, this list of conditions and the following disclaimer.
10264696Sandrew * 2. Redistributions in binary form must reproduce the above copyright
11264696Sandrew *    notice, this list of conditions and the following disclaimer in the
12264696Sandrew *    documentation and/or other materials provided with the distribution.
13264696Sandrew *
14264696Sandrew * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15264696Sandrew * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16264696Sandrew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17264696Sandrew * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18264696Sandrew * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19264696Sandrew * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20264696Sandrew * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21264696Sandrew * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22264696Sandrew * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23264696Sandrew * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24264696Sandrew * SUCH DAMAGE.
25264696Sandrew *
26264696Sandrew */
27264696Sandrew
28264696Sandrew#include <sys/cdefs.h>
29264696Sandrew__FBSDID("$FreeBSD$");
30264696Sandrew
31264696Sandrew#include <sys/types.h>
32264696Sandrew#include <ieeefp.h>
33264696Sandrew
34264696Sandrew#ifdef __weak_alias
35264696Sandrew__weak_alias(fpgetsticky,_fpgetsticky)
36264696Sandrew#endif
37264696Sandrew
38264696Sandrew#define FP_X_MASK	(FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP)
39264696Sandrew
40264696Sandrewfp_except
41264696Sandrewfpgetsticky(void)
42264696Sandrew{
43264696Sandrew	fp_except old;
44264696Sandrew
45264696Sandrew	__asm __volatile("vmrs %0, fpscr" : "=&r"(old));
46264696Sandrew
47264696Sandrew	return (old & FP_X_MASK);
48264696Sandrew}
49264696Sandrew
50