fpsetmask.c revision 125733
113877Swosch/*	$NetBSD: fpsetmask.c,v 1.3 2002/01/13 21:45:48 thorpej Exp $	*/
213877Swosch
313877Swosch/*
413877Swosch * Copyright (c) 1999 The NetBSD Foundation, Inc.
513877Swosch * All rights reserved.
613877Swosch *
713877Swosch * This code is derived from software contributed to The NetBSD Foundation
813877Swosch * by Dan Winship.
913877Swosch *
1013877Swosch * Redistribution and use in source and binary forms, with or without
1113877Swosch * modification, are permitted provided that the following conditions
1213877Swosch * are met:
1313877Swosch * 1. Redistributions of source code must retain the above copyright
1413877Swosch *    notice, this list of conditions and the following disclaimer.
1513877Swosch * 2. Redistributions in binary form must reproduce the above copyright
1613877Swosch *    notice, this list of conditions and the following disclaimer in the
1713877Swosch *    documentation and/or other materials provided with the distribution.
1813877Swosch * 3. All advertising materials mentioning features or use of this software
1913877Swosch *    must display the following acknowledgement:
2013877Swosch *	This product includes software developed by the NetBSD
2113877Swosch *	Foundation, Inc. and its contributors.
2213877Swosch * 4. Neither the name of The NetBSD Foundation nor the names of its
2313877Swosch *    contributors may be used to endorse or promote products derived
2413877Swosch *    from this software without specific prior written permission.
2513877Swosch *
2613877Swosch * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2713877Swosch * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2813877Swosch * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2913877Swosch * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
3013877Swosch * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3113877Swosch * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3259945Sphantom * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3359945Sphantom * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3413877Swosch * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3513877Swosch * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36129814Sstefanf * POSSIBILITY OF SUCH DAMAGE.
37129814Sstefanf *
3813877Swosch */
3913877Swosch
4013877Swosch#include <sys/cdefs.h>
4113877Swosch__FBSDID("$FreeBSD: head/lib/libc/powerpc/gen/fpsetmask.c 125733 2004-02-12 09:11:06Z grehan $");
4213877Swosch
4387235Smarkm#include <sys/types.h>
4413877Swosch#include <ieeefp.h>
4513877Swosch
4692920Simpfp_except_t
4792920Simpfpsetmask(fp_except_t mask)
4892920Simp{
4992920Simp	u_int64_t fpscr;
5092920Simp	fp_rnd_t old;
5192920Simp
5292920Simp	__asm__("mffs %0" : "=f"(fpscr));
5392920Simp	old = (fp_rnd_t)((fpscr >> 3) & 0x1f);
5492920Simp	fpscr = (fpscr & 0xffffff07) | (mask << 3);
5592920Simp	__asm__ __volatile("mtfsf 0xff,%0" :: "f"(fpscr));
5692920Simp	return (old);
5792920Simp}
5892920Simp