fpsetround.c revision 125733
10Sstevel@tonic-gate/* $NetBSD: fpsetround.c,v 1.3 2002/01/13 21:45:48 thorpej Exp $ */ 20Sstevel@tonic-gate 30Sstevel@tonic-gate/* 40Sstevel@tonic-gate * Copyright (c) 1999 The NetBSD Foundation, Inc. 50Sstevel@tonic-gate * All rights reserved. 60Sstevel@tonic-gate * 70Sstevel@tonic-gate * This code is derived from software contributed to The NetBSD Foundation 80Sstevel@tonic-gate * by Dan Winship. 90Sstevel@tonic-gate * 100Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 110Sstevel@tonic-gate * modification, are permitted provided that the following conditions 120Sstevel@tonic-gate * are met: 130Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 140Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 150Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 160Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 170Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 180Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software 190Sstevel@tonic-gate * must display the following acknowledgement: 200Sstevel@tonic-gate * This product includes software developed by the NetBSD 210Sstevel@tonic-gate * Foundation, Inc. and its contributors. 220Sstevel@tonic-gate * 4. Neither the name of The NetBSD Foundation nor the names of its 230Sstevel@tonic-gate * contributors may be used to endorse or promote products derived 240Sstevel@tonic-gate * from this software without specific prior written permission. 250Sstevel@tonic-gate * 260Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 270Sstevel@tonic-gate * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 280Sstevel@tonic-gate * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 290Sstevel@tonic-gate * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 300Sstevel@tonic-gate * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 310Sstevel@tonic-gate * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 320Sstevel@tonic-gate * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 330Sstevel@tonic-gate * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 340Sstevel@tonic-gate * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 350Sstevel@tonic-gate * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 360Sstevel@tonic-gate * POSSIBILITY OF SUCH DAMAGE. 370Sstevel@tonic-gate * 380Sstevel@tonic-gate */ 390Sstevel@tonic-gate 400Sstevel@tonic-gate#include <sys/cdefs.h> 410Sstevel@tonic-gate__FBSDID("$FreeBSD: head/lib/libc/powerpc/gen/fpsetround.c 125733 2004-02-12 09:11:06Z grehan $"); 420Sstevel@tonic-gate 430Sstevel@tonic-gate#include <sys/types.h> 440Sstevel@tonic-gate#include <ieeefp.h> 450Sstevel@tonic-gate 460Sstevel@tonic-gatefp_rnd_t 470Sstevel@tonic-gatefpsetround(fp_rnd_t rnd_dir) 480Sstevel@tonic-gate{ 490Sstevel@tonic-gate u_int64_t fpscr; 500Sstevel@tonic-gate fp_rnd_t old; 510Sstevel@tonic-gate 520Sstevel@tonic-gate __asm__ __volatile("mffs %0" : "=f"(fpscr)); 530Sstevel@tonic-gate old = (fp_rnd_t)(fpscr & 0x3); 540Sstevel@tonic-gate fpscr = (fpscr & 0xfffffffc) | rnd_dir; 550Sstevel@tonic-gate __asm__ __volatile("mtfsf 0xff,%0" :: "f"(fpscr)); 560Sstevel@tonic-gate return (old); 570Sstevel@tonic-gate} 580Sstevel@tonic-gate