xref: /netbsd-src/lib/libc/arch/arm/hardfloat/fpgetround.c (revision 60e851836f800c27172ddd158f61000ca8d17d34)
1*60e85183Smatt /*	$NetBSD: fpgetround.c,v 1.6 2013/01/11 13:55:26 matt Exp $	*/
25aefcfdcSbjh21 
3*60e85183Smatt /*-
4*60e85183Smatt  * Copyright (c) 2013 The NetBSD Foundation, Inc.
55aefcfdcSbjh21  * All rights reserved.
65aefcfdcSbjh21  *
7*60e85183Smatt  * This code is derived from software contributed to The NetBSD Foundation
8*60e85183Smatt  * by Matt Thomas of 3am Software Foundry.
9*60e85183Smatt  *
105aefcfdcSbjh21  * Redistribution and use in source and binary forms, with or without
115aefcfdcSbjh21  * modification, are permitted provided that the following conditions
125aefcfdcSbjh21  * are met:
135aefcfdcSbjh21  * 1. Redistributions of source code must retain the above copyright
145aefcfdcSbjh21  *    notice, this list of conditions and the following disclaimer.
155aefcfdcSbjh21  * 2. Redistributions in binary form must reproduce the above copyright
165aefcfdcSbjh21  *    notice, this list of conditions and the following disclaimer in the
175aefcfdcSbjh21  *    documentation and/or other materials provided with the distribution.
185aefcfdcSbjh21  *
19*60e85183Smatt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*60e85183Smatt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*60e85183Smatt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*60e85183Smatt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*60e85183Smatt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*60e85183Smatt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*60e85183Smatt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*60e85183Smatt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*60e85183Smatt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*60e85183Smatt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*60e85183Smatt  * POSSIBILITY OF SUCH DAMAGE.
305aefcfdcSbjh21  */
315aefcfdcSbjh21 
32*60e85183Smatt #ifndef __VFP_FP__
33*60e85183Smatt #error FPA is not supported anymore
34*60e85183Smatt #endif
35*60e85183Smatt 
365d3e8294Sthorpej #include <sys/cdefs.h>
3788c3eadbSlukem #if defined(LIBC_SCCS) && !defined(lint)
38*60e85183Smatt __RCSID("$NetBSD: fpgetround.c,v 1.6 2013/01/11 13:55:26 matt Exp $");
3988c3eadbSlukem #endif /* LIBC_SCCS and not lint */
405d3e8294Sthorpej 
415d3e8294Sthorpej #include "namespace.h"
425d3e8294Sthorpej 
435aefcfdcSbjh21 #include <sys/types.h>
445aefcfdcSbjh21 #include <ieeefp.h>
455aefcfdcSbjh21 
46*60e85183Smatt #include <arm/vfpreg.h>
47*60e85183Smatt 
485d3e8294Sthorpej #ifdef __weak_alias
__weak_alias(fpgetround,_fpgetround)495d3e8294Sthorpej __weak_alias(fpgetround,_fpgetround)
505d3e8294Sthorpej #endif
515d3e8294Sthorpej 
525aefcfdcSbjh21 /*
535aefcfdcSbjh21  * Return the current FP rounding mode
545aefcfdcSbjh21  */
555aefcfdcSbjh21 
565aefcfdcSbjh21 fp_rnd
573d365e74Schristos fpgetround(void)
585aefcfdcSbjh21 {
59*60e85183Smatt 	__CTASSERT(__SHIFTOUT(VFP_FPSCR_RN, VFP_FPSCR_RMODE) == FP_RN);
60*60e85183Smatt 	__CTASSERT(__SHIFTOUT(VFP_FPSCR_RP, VFP_FPSCR_RMODE) == FP_RP);
61*60e85183Smatt 	__CTASSERT(__SHIFTOUT(VFP_FPSCR_RM, VFP_FPSCR_RMODE) == FP_RM);
62*60e85183Smatt 	__CTASSERT(__SHIFTOUT(VFP_FPSCR_RZ, VFP_FPSCR_RMODE) == FP_RZ);
63*60e85183Smatt 	uint32_t fpscr;
64*60e85183Smatt 	__asm __volatile("vmrs %0, fpscr" : "=r" (fpscr));
65*60e85183Smatt 	return __SHIFTOUT(fpscr, VFP_FPSCR_RMODE);
665aefcfdcSbjh21 }
67