1125733Sgrehan/* $NetBSD: fpsetround.c,v 1.3 2002/01/13 21:45:48 thorpej Exp $ */ 2125733Sgrehan 3125733Sgrehan/* 4125733Sgrehan * Copyright (c) 1999 The NetBSD Foundation, Inc. 5125733Sgrehan * All rights reserved. 6125733Sgrehan * 7125733Sgrehan * This code is derived from software contributed to The NetBSD Foundation 8125733Sgrehan * by Dan Winship. 9125733Sgrehan * 10125733Sgrehan * Redistribution and use in source and binary forms, with or without 11125733Sgrehan * modification, are permitted provided that the following conditions 12125733Sgrehan * are met: 13125733Sgrehan * 1. Redistributions of source code must retain the above copyright 14125733Sgrehan * notice, this list of conditions and the following disclaimer. 15125733Sgrehan * 2. Redistributions in binary form must reproduce the above copyright 16125733Sgrehan * notice, this list of conditions and the following disclaimer in the 17125733Sgrehan * documentation and/or other materials provided with the distribution. 18125733Sgrehan * 19125733Sgrehan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20125733Sgrehan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21125733Sgrehan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22125733Sgrehan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23125733Sgrehan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24125733Sgrehan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25125733Sgrehan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26125733Sgrehan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27125733Sgrehan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28125733Sgrehan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29125733Sgrehan * POSSIBILITY OF SUCH DAMAGE. 30125733Sgrehan * 31125733Sgrehan */ 32125733Sgrehan 33125733Sgrehan#include <sys/cdefs.h> 34125733Sgrehan__FBSDID("$FreeBSD: releng/10.3/lib/libc/powerpc/gen/fpsetround.c 204606 2010-03-02 22:11:14Z joel $"); 35125733Sgrehan 36125733Sgrehan#include <sys/types.h> 37125733Sgrehan#include <ieeefp.h> 38125733Sgrehan 39176530Sraj#ifndef _SOFT_FLOAT 40125733Sgrehanfp_rnd_t 41125733Sgrehanfpsetround(fp_rnd_t rnd_dir) 42125733Sgrehan{ 43125733Sgrehan u_int64_t fpscr; 44125733Sgrehan fp_rnd_t old; 45125733Sgrehan 46125733Sgrehan __asm__ __volatile("mffs %0" : "=f"(fpscr)); 47125733Sgrehan old = (fp_rnd_t)(fpscr & 0x3); 48125733Sgrehan fpscr = (fpscr & 0xfffffffc) | rnd_dir; 49125733Sgrehan __asm__ __volatile("mtfsf 0xff,%0" :: "f"(fpscr)); 50125733Sgrehan return (old); 51125733Sgrehan} 52176530Sraj#endif 53