fpsetmask.c revision 176530
1125733Sgrehan/* $NetBSD: fpsetmask.c,v 1.3 2002/01/13 21:45:48 thorpej Exp $ */ 2125733Sgrehan 3125733Sgrehan/* 4125733Sgrehan * Copyright (c) 1999 The NetBSD Foundation, Inc. 5125733Sgrehan * All rights reserved. 6125733Sgrehan * 7125733Sgrehan * This code is derived from software contributed to The NetBSD Foundation 8125733Sgrehan * by Dan Winship. 9125733Sgrehan * 10125733Sgrehan * Redistribution and use in source and binary forms, with or without 11125733Sgrehan * modification, are permitted provided that the following conditions 12125733Sgrehan * are met: 13125733Sgrehan * 1. Redistributions of source code must retain the above copyright 14125733Sgrehan * notice, this list of conditions and the following disclaimer. 15125733Sgrehan * 2. Redistributions in binary form must reproduce the above copyright 16125733Sgrehan * notice, this list of conditions and the following disclaimer in the 17125733Sgrehan * documentation and/or other materials provided with the distribution. 18125733Sgrehan * 3. All advertising materials mentioning features or use of this software 19125733Sgrehan * must display the following acknowledgement: 20125733Sgrehan * This product includes software developed by the NetBSD 21125733Sgrehan * Foundation, Inc. and its contributors. 22125733Sgrehan * 4. Neither the name of The NetBSD Foundation nor the names of its 23125733Sgrehan * contributors may be used to endorse or promote products derived 24125733Sgrehan * from this software without specific prior written permission. 25125733Sgrehan * 26125733Sgrehan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27125733Sgrehan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28125733Sgrehan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29125733Sgrehan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30125733Sgrehan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31125733Sgrehan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32125733Sgrehan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33125733Sgrehan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34125733Sgrehan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35125733Sgrehan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36125733Sgrehan * POSSIBILITY OF SUCH DAMAGE. 37125733Sgrehan * 38125733Sgrehan */ 39125733Sgrehan 40125733Sgrehan#include <sys/cdefs.h> 41125733Sgrehan__FBSDID("$FreeBSD: head/lib/libc/powerpc/gen/fpsetmask.c 176530 2008-02-24 19:22:53Z raj $"); 42125733Sgrehan 43125733Sgrehan#include <sys/types.h> 44125733Sgrehan#include <ieeefp.h> 45125733Sgrehan 46176530Sraj#ifndef _SOFT_FLOAT 47125733Sgrehanfp_except_t 48125733Sgrehanfpsetmask(fp_except_t mask) 49125733Sgrehan{ 50125733Sgrehan u_int64_t fpscr; 51125733Sgrehan fp_rnd_t old; 52125733Sgrehan 53125733Sgrehan __asm__("mffs %0" : "=f"(fpscr)); 54125733Sgrehan old = (fp_rnd_t)((fpscr >> 3) & 0x1f); 55125733Sgrehan fpscr = (fpscr & 0xffffff07) | (mask << 3); 56125733Sgrehan __asm__ __volatile("mtfsf 0xff,%0" :: "f"(fpscr)); 57125733Sgrehan return (old); 58125733Sgrehan} 59176530Sraj#endif 60