fpsetmask.c revision 256281
1161370Simp/* $NetBSD: fpsetmask.c,v 1.3 2002/01/13 21:45:48 thorpej Exp $ */ 2161370Simp 3161370Simp/* 4161370Simp * Copyright (c) 1999 The NetBSD Foundation, Inc. 5161370Simp * All rights reserved. 6161370Simp * 7161370Simp * This code is derived from software contributed to The NetBSD Foundation 8161370Simp * by Dan Winship. 9161370Simp * 10161370Simp * Redistribution and use in source and binary forms, with or without 11161370Simp * modification, are permitted provided that the following conditions 12161370Simp * are met: 13161370Simp * 1. Redistributions of source code must retain the above copyright 14161370Simp * notice, this list of conditions and the following disclaimer. 15161370Simp * 2. Redistributions in binary form must reproduce the above copyright 16161370Simp * notice, this list of conditions and the following disclaimer in the 17161370Simp * documentation and/or other materials provided with the distribution. 18161370Simp * 19161370Simp * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20161370Simp * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21161370Simp * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22161370Simp * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23161370Simp * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24161370Simp * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25161370Simp * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26161370Simp * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27161370Simp * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28161370Simp * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29161370Simp * POSSIBILITY OF SUCH DAMAGE. 30161370Simp * 31161370Simp */ 32161370Simp 33161370Simp#include <sys/cdefs.h> 34161370Simp__FBSDID("$FreeBSD: stable/10/lib/libc/powerpc/gen/fpsetmask.c 204606 2010-03-02 22:11:14Z joel $"); 35161370Simp 36161370Simp#include <sys/types.h> 37161370Simp#include <ieeefp.h> 38161370Simp 39#ifndef _SOFT_FLOAT 40fp_except_t 41fpsetmask(fp_except_t mask) 42{ 43 u_int64_t fpscr; 44 fp_rnd_t old; 45 46 __asm__("mffs %0" : "=f"(fpscr)); 47 old = (fp_rnd_t)((fpscr >> 3) & 0x1f); 48 fpscr = (fpscr & 0xffffff07) | (mask << 3); 49 __asm__ __volatile("mtfsf 0xff,%0" :: "f"(fpscr)); 50 return (old); 51} 52#endif 53