1289177Speter/* $NetBSD: fpsetround.c,v 1.3 2002/01/13 21:45:48 thorpej Exp $ */ 2289177Speter 3289177Speter/* 4289177Speter * Copyright (c) 1999 The NetBSD Foundation, Inc. 5289177Speter * All rights reserved. 6289177Speter * 7289177Speter * This code is derived from software contributed to The NetBSD Foundation 8289177Speter * by Dan Winship. 9289177Speter * 10289177Speter * Redistribution and use in source and binary forms, with or without 11289177Speter * modification, are permitted provided that the following conditions 12289177Speter * are met: 13289177Speter * 1. Redistributions of source code must retain the above copyright 14289177Speter * notice, this list of conditions and the following disclaimer. 15289177Speter * 2. Redistributions in binary form must reproduce the above copyright 16289177Speter * notice, this list of conditions and the following disclaimer in the 17289177Speter * documentation and/or other materials provided with the distribution. 18289177Speter * 19289177Speter * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20289177Speter * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21289177Speter * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22289177Speter * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23289177Speter * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24289177Speter * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25289177Speter * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26289177Speter * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27289177Speter * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28289177Speter * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29289177Speter * POSSIBILITY OF SUCH DAMAGE. 30289177Speter * 31289177Speter */ 32289177Speter 33289177Speter#include <sys/cdefs.h> 34289177Speter__FBSDID("$FreeBSD$"); 35289177Speter 36289177Speter#include <sys/types.h> 37289177Speter#include <ieeefp.h> 38289177Speter 39289177Speter#ifndef _SOFT_FLOAT 40289177Speterfp_rnd_t 41289177Speterfpsetround(fp_rnd_t rnd_dir) 42289177Speter{ 43289177Speter u_int64_t fpscr; 44289177Speter fp_rnd_t old; 45289177Speter 46289177Speter __asm__ __volatile("mffs %0" : "=f"(fpscr)); 47289177Speter old = (fp_rnd_t)(fpscr & 0x3); 48289177Speter fpscr = (fpscr & 0xfffffffc) | rnd_dir; 49289177Speter __asm__ __volatile("mtfsf 0xff,%0" :: "f"(fpscr)); 50289177Speter return (old); 51289177Speter} 52289177Speter#endif 53289177Speter