fpsetsticky_vfp.c revision 264696
1183267Sjkoshy/*
2174397Sjkoshy * Copyright (C) 2014 Andrew Turner
3145256Sjkoshy * All rights reserved.
4145256Sjkoshy *
5174397Sjkoshy * Redistribution and use in source and binary forms, with or without
6174397Sjkoshy * modification, are permitted provided that the following conditions
7174397Sjkoshy * are met:
8145256Sjkoshy * 1. Redistributions of source code must retain the above copyright
9145256Sjkoshy *    notice, this list of conditions and the following disclaimer.
10145256Sjkoshy * 2. Redistributions in binary form must reproduce the above copyright
11145256Sjkoshy *    notice, this list of conditions and the following disclaimer in the
12145256Sjkoshy *    documentation and/or other materials provided with the distribution.
13145256Sjkoshy *
14145256Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15145256Sjkoshy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16145256Sjkoshy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17145256Sjkoshy * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18145256Sjkoshy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19145256Sjkoshy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20145256Sjkoshy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21145256Sjkoshy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22145256Sjkoshy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23145256Sjkoshy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24145256Sjkoshy * SUCH DAMAGE.
25145256Sjkoshy *
26145256Sjkoshy */
27145256Sjkoshy
28145256Sjkoshy#include <sys/cdefs.h>
29145256Sjkoshy__FBSDID("$FreeBSD: head/lib/libc/arm/gen/fpsetsticky.c 264696 2014-04-20 14:58:14Z andrew $");
30145256Sjkoshy
31242496Sjimharris#include <sys/types.h>
32145256Sjkoshy#include <ieeefp.h>
33145256Sjkoshy
34145256Sjkoshy#ifdef __weak_alias
35145256Sjkoshy__weak_alias(fpsetsticky,_fpsetsticky)
36147679Sjkoshy#endif
37145256Sjkoshy
38147679Sjkoshy#define FP_X_MASK	(FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL | FP_X_IMP)
39147679Sjkoshy
40150684Sjkoshyfp_except
41150684Sjkoshyfpsetsticky(fp_except except)
42152569Sru{
43145256Sjkoshy	fp_except old, new;
44145256Sjkoshy
45145256Sjkoshy	__asm __volatile("vmrs %0, fpscr" : "=&r"(old));
46145256Sjkoshy	new = old & ~(FP_X_MASK);
47145256Sjkoshy	new &= ~except;
48145256Sjkoshy	__asm __volatile("vmsr fpscr, %0" : : "r"(new));
49145256Sjkoshy
50145256Sjkoshy	return (old & except);
51145256Sjkoshy}
52145256Sjkoshy
53147679Sjkoshy