fpsetmask.c revision 330897
11573Srgrimes/* $NetBSD: fpsetmask.c,v 1.3 2002/01/13 21:45:48 thorpej Exp $ */ 21573Srgrimes 31573Srgrimes/*- 41573Srgrimes * SPDX-License-Identifier: BSD-2-Clause-NetBSD 51573Srgrimes * 61573Srgrimes * Copyright (c) 1999 The NetBSD Foundation, Inc. 71573Srgrimes * All rights reserved. 81573Srgrimes * 91573Srgrimes * This code is derived from software contributed to The NetBSD Foundation 101573Srgrimes * by Dan Winship. 111573Srgrimes * 121573Srgrimes * Redistribution and use in source and binary forms, with or without 131573Srgrimes * modification, are permitted provided that the following conditions 141573Srgrimes * are met: 151573Srgrimes * 1. Redistributions of source code must retain the above copyright 161573Srgrimes * notice, this list of conditions and the following disclaimer. 171573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 181573Srgrimes * notice, this list of conditions and the following disclaimer in the 191573Srgrimes * documentation and/or other materials provided with the distribution. 201573Srgrimes * 211573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 221573Srgrimes * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 231573Srgrimes * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 241573Srgrimes * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 251573Srgrimes * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 261573Srgrimes * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 271573Srgrimes * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 281573Srgrimes * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 291573Srgrimes * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 301573Srgrimes * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 311573Srgrimes * POSSIBILITY OF SUCH DAMAGE. 321573Srgrimes * 331573Srgrimes */ 341573Srgrimes 351573Srgrimes#include <sys/cdefs.h> 361573Srgrimes__FBSDID("$FreeBSD: stable/11/lib/libc/powerpc64/gen/fpsetmask.c 330897 2018-03-14 03:19:51Z eadler $"); 3790045Sobrien 3890045Sobrien#include <sys/types.h> 391573Srgrimes#include <ieeefp.h> 4071579Sdeischen 411573Srgrimes#ifndef _SOFT_FLOAT 421573Srgrimesfp_except_t 431573Srgrimesfpsetmask(fp_except_t mask) 441573Srgrimes{ 4513545Sjulian u_int64_t fpscr; 4610954Speter fp_rnd_t old; 4713545Sjulian 481573Srgrimes __asm__("mffs %0" : "=f"(fpscr)); 491573Srgrimes old = (fp_rnd_t)((fpscr >> 3) & 0x1f); 5013545Sjulian fpscr = (fpscr & 0xffffff07) | (mask << 3); 5171579Sdeischen __asm__ __volatile("mtfsf 0xff,%0" :: "f"(fpscr)); 5213545Sjulian return (old); 5371579Sdeischen} 5471579Sdeischen#endif 5571579Sdeischen