xref: /netbsd-src/lib/libc/arch/m68k/hardfloat/fpsetround.c (revision d35c388600ff73bdce0be50b2aa368e96cee373f)
1*d35c3886Smatt /*-
2*d35c3886Smatt  * Copyright (c) 2013 The NetBSD Foundation, Inc.
3*d35c3886Smatt  * All rights reserved.
4*d35c3886Smatt  *
5*d35c3886Smatt  * This code is derived from software contributed to The NetBSD Foundation
6*d35c3886Smatt  * by Matt Thomas of 3am Software Foundry.
7*d35c3886Smatt  *
8*d35c3886Smatt  * Redistribution and use in source and binary forms, with or without
9*d35c3886Smatt  * modification, are permitted provided that the following conditions
10*d35c3886Smatt  * are met:
11*d35c3886Smatt  * 1. Redistributions of source code must retain the above copyright
12*d35c3886Smatt  *    notice, this list of conditions and the following disclaimer.
13*d35c3886Smatt  * 2. Redistributions in binary form must reproduce the above copyright
14*d35c3886Smatt  *    notice, this list of conditions and the following disclaimer in the
15*d35c3886Smatt  *    documentation and/or other materials provided with the distribution.
16*d35c3886Smatt  *
17*d35c3886Smatt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18*d35c3886Smatt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19*d35c3886Smatt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20*d35c3886Smatt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21*d35c3886Smatt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*d35c3886Smatt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*d35c3886Smatt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*d35c3886Smatt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25*d35c3886Smatt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26*d35c3886Smatt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27*d35c3886Smatt  * POSSIBILITY OF SUCH DAMAGE.
28*d35c3886Smatt  */
29*d35c3886Smatt 
30*d35c3886Smatt #include "namespace.h"
31*d35c3886Smatt 
32*d35c3886Smatt #include <ieeefp.h>
33*d35c3886Smatt #include <m68k/fpreg.h>
34*d35c3886Smatt 
35*d35c3886Smatt #ifdef __weak_alias
__weak_alias(fpsetround,_fpsetround)36*d35c3886Smatt __weak_alias(fpsetround,_fpsetround)
37*d35c3886Smatt #endif
38*d35c3886Smatt 
39*d35c3886Smatt fp_rnd
40*d35c3886Smatt _fpsetround(fp_rnd new)
41*d35c3886Smatt {
42*d35c3886Smatt 	int old_fpcr, new_fpcr;
43*d35c3886Smatt 
44*d35c3886Smatt 	__asm("fmovel %%fpcr,%0" : "=d"(old_fpcr));
45*d35c3886Smatt 
46*d35c3886Smatt 	new_fpcr = (old_fpcr & ~FPCR_ROUND) | __SHIFTIN(new, FPCR_ROUND);
47*d35c3886Smatt 
48*d35c3886Smatt 	__asm("fmovel %0,%%fpcr" :: "d"(new_fpcr));
49*d35c3886Smatt 
50*d35c3886Smatt 	return __SHIFTOUT(old_fpcr, FPCR_ROUND);
51*d35c3886Smatt }
52