133965Sjdp/* $NetBSD: fpsetmask.c,v 1.3 2002/01/13 21:45:48 thorpej Exp $ */ 260484Sobrien 360484Sobrien/* 433965Sjdp * Copyright (c) 1999 The NetBSD Foundation, Inc. 533965Sjdp * All rights reserved. 633965Sjdp * 733965Sjdp * This code is derived from software contributed to The NetBSD Foundation 833965Sjdp * by Dan Winship. 933965Sjdp * 1033965Sjdp * Redistribution and use in source and binary forms, with or without 1133965Sjdp * modification, are permitted provided that the following conditions 1233965Sjdp * are met: 1333965Sjdp * 1. Redistributions of source code must retain the above copyright 1433965Sjdp * notice, this list of conditions and the following disclaimer. 1533965Sjdp * 2. Redistributions in binary form must reproduce the above copyright 1633965Sjdp * notice, this list of conditions and the following disclaimer in the 1733965Sjdp * documentation and/or other materials provided with the distribution. 1860484Sobrien * 1960484Sobrien * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2060484Sobrien * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2133965Sjdp * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2233965Sjdp * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2333965Sjdp * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2433965Sjdp * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2533965Sjdp * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2633965Sjdp * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2733965Sjdp * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2833965Sjdp * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2933965Sjdp * POSSIBILITY OF SUCH DAMAGE. 3033965Sjdp * 3133965Sjdp */ 3233965Sjdp 3333965Sjdp#include <sys/cdefs.h> 3433965Sjdp__FBSDID("$FreeBSD$"); 3560484Sobrien 3633965Sjdp#include <sys/types.h> 3733965Sjdp#include <ieeefp.h> 3833965Sjdp 3933965Sjdp#ifndef _SOFT_FLOAT 4033965Sjdpfp_except_t 4133965Sjdpfpsetmask(fp_except_t mask) 4233965Sjdp{ 4333965Sjdp u_int64_t fpscr; 4433965Sjdp fp_rnd_t old; 4533965Sjdp 4633965Sjdp __asm__("mffs %0" : "=f"(fpscr)); 4733965Sjdp old = (fp_rnd_t)((fpscr >> 3) & 0x1f); 4833965Sjdp fpscr = (fpscr & 0xffffff07) | (mask << 3); 4933965Sjdp __asm__ __volatile("mtfsf 0xff,%0" :: "f"(fpscr)); 5033965Sjdp return (old); 5133965Sjdp} 5233965Sjdp#endif 5333965Sjdp