fpsetround.c revision 125733
110444Schegar/* $NetBSD: fpsetround.c,v 1.3 2002/01/13 21:45:48 thorpej Exp $ */ 210444Schegar 310444Schegar/* 410444Schegar * Copyright (c) 1999 The NetBSD Foundation, Inc. 510444Schegar * All rights reserved. 610444Schegar * 710444Schegar * This code is derived from software contributed to The NetBSD Foundation 810444Schegar * by Dan Winship. 910444Schegar * 1010444Schegar * Redistribution and use in source and binary forms, with or without 1110444Schegar * modification, are permitted provided that the following conditions 1210444Schegar * are met: 1310444Schegar * 1. Redistributions of source code must retain the above copyright 1410444Schegar * notice, this list of conditions and the following disclaimer. 1510444Schegar * 2. Redistributions in binary form must reproduce the above copyright 1610444Schegar * notice, this list of conditions and the following disclaimer in the 1710444Schegar * documentation and/or other materials provided with the distribution. 1810444Schegar * 3. All advertising materials mentioning features or use of this software 1910444Schegar * must display the following acknowledgement: 2010444Schegar * This product includes software developed by the NetBSD 2110444Schegar * Foundation, Inc. and its contributors. 2210444Schegar * 4. Neither the name of The NetBSD Foundation nor the names of its 2310444Schegar * contributors may be used to endorse or promote products derived 2410444Schegar * from this software without specific prior written permission. 2510444Schegar * 2610444Schegar * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2710444Schegar * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2810444Schegar * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2910444Schegar * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 3010444Schegar * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3110444Schegar * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3210444Schegar * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3310444Schegar * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3410444Schegar * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3510444Schegar * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3610444Schegar * POSSIBILITY OF SUCH DAMAGE. 3710444Schegar * 3810444Schegar */ 3910444Schegar 4010444Schegar#include <sys/cdefs.h> 4110444Schegar__FBSDID("$FreeBSD: head/lib/libc/powerpc/gen/fpsetround.c 125733 2004-02-12 09:11:06Z grehan $"); 4210444Schegar 4310444Schegar#include <sys/types.h> 4410444Schegar#include <ieeefp.h> 4510444Schegar 4610444Schegarfp_rnd_t 4710444Schegarfpsetround(fp_rnd_t rnd_dir) 4810444Schegar{ 4910444Schegar u_int64_t fpscr; 5010444Schegar fp_rnd_t old; 5110444Schegar 5210444Schegar __asm__ __volatile("mffs %0" : "=f"(fpscr)); 5310444Schegar old = (fp_rnd_t)(fpscr & 0x3); 5410444Schegar fpscr = (fpscr & 0xfffffffc) | rnd_dir; 5510444Schegar __asm__ __volatile("mtfsf 0xff,%0" :: "f"(fpscr)); 5610444Schegar return (old); 5710444Schegar} 5810444Schegar