1209878Snwhitehorn/*	$NetBSD: fpsetmask.c,v 1.3 2002/01/13 21:45:48 thorpej Exp $	*/
2209878Snwhitehorn
3209878Snwhitehorn/*
4209878Snwhitehorn * Copyright (c) 1999 The NetBSD Foundation, Inc.
5209878Snwhitehorn * All rights reserved.
6209878Snwhitehorn *
7209878Snwhitehorn * This code is derived from software contributed to The NetBSD Foundation
8209878Snwhitehorn * by Dan Winship.
9209878Snwhitehorn *
10209878Snwhitehorn * Redistribution and use in source and binary forms, with or without
11209878Snwhitehorn * modification, are permitted provided that the following conditions
12209878Snwhitehorn * are met:
13209878Snwhitehorn * 1. Redistributions of source code must retain the above copyright
14209878Snwhitehorn *    notice, this list of conditions and the following disclaimer.
15209878Snwhitehorn * 2. Redistributions in binary form must reproduce the above copyright
16209878Snwhitehorn *    notice, this list of conditions and the following disclaimer in the
17209878Snwhitehorn *    documentation and/or other materials provided with the distribution.
18209878Snwhitehorn *
19209878Snwhitehorn * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20209878Snwhitehorn * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21209878Snwhitehorn * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22209878Snwhitehorn * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23209878Snwhitehorn * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24209878Snwhitehorn * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25209878Snwhitehorn * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26209878Snwhitehorn * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27209878Snwhitehorn * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28209878Snwhitehorn * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29209878Snwhitehorn * POSSIBILITY OF SUCH DAMAGE.
30209878Snwhitehorn *
31209878Snwhitehorn */
32209878Snwhitehorn
33209878Snwhitehorn#include <sys/cdefs.h>
34209878Snwhitehorn__FBSDID("$FreeBSD$");
35209878Snwhitehorn
36209878Snwhitehorn#include <sys/types.h>
37209878Snwhitehorn#include <ieeefp.h>
38209878Snwhitehorn
39209878Snwhitehorn#ifndef _SOFT_FLOAT
40209878Snwhitehornfp_except_t
41209878Snwhitehornfpsetmask(fp_except_t mask)
42209878Snwhitehorn{
43209878Snwhitehorn	u_int64_t fpscr;
44209878Snwhitehorn	fp_rnd_t old;
45209878Snwhitehorn
46209878Snwhitehorn	__asm__("mffs %0" : "=f"(fpscr));
47209878Snwhitehorn	old = (fp_rnd_t)((fpscr >> 3) & 0x1f);
48209878Snwhitehorn	fpscr = (fpscr & 0xffffff07) | (mask << 3);
49209878Snwhitehorn	__asm__ __volatile("mtfsf 0xff,%0" :: "f"(fpscr));
50209878Snwhitehorn	return (old);
51209878Snwhitehorn}
52209878Snwhitehorn#endif
53