fpgetround_vfp.c revision 264696
1264696Sandrew/* 2264696Sandrew * Copyright (C) 2014 Andrew Turner 3264696Sandrew * All rights reserved. 4264696Sandrew * 5264696Sandrew * Redistribution and use in source and binary forms, with or without 6264696Sandrew * modification, are permitted provided that the following conditions 7264696Sandrew * are met: 8264696Sandrew * 1. Redistributions of source code must retain the above copyright 9264696Sandrew * notice, this list of conditions and the following disclaimer. 10264696Sandrew * 2. Redistributions in binary form must reproduce the above copyright 11264696Sandrew * notice, this list of conditions and the following disclaimer in the 12264696Sandrew * documentation and/or other materials provided with the distribution. 13264696Sandrew * 14264696Sandrew * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15264696Sandrew * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16264696Sandrew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17264696Sandrew * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18264696Sandrew * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19264696Sandrew * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20264696Sandrew * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21264696Sandrew * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22264696Sandrew * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23264696Sandrew * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24264696Sandrew * SUCH DAMAGE. 25264696Sandrew * 26264696Sandrew */ 27264696Sandrew 28264696Sandrew#include <sys/cdefs.h> 29264696Sandrew__FBSDID("$FreeBSD: head/lib/libc/arm/gen/fpgetround.c 264696 2014-04-20 14:58:14Z andrew $"); 30264696Sandrew 31264696Sandrew#include <sys/types.h> 32264696Sandrew#include <ieeefp.h> 33264696Sandrew 34264696Sandrew#ifdef __weak_alias 35264696Sandrew__weak_alias(fpgetround,_fpgetround) 36264696Sandrew#endif 37264696Sandrew 38264696Sandrewfp_rnd_t 39264696Sandrewfpgetround(void) 40264696Sandrew{ 41264696Sandrew uint32_t fpscr; 42264696Sandrew 43264696Sandrew __asm __volatile("vmrs %0, fpscr" : "=&r"(fpscr)); 44264696Sandrew 45264696Sandrew return ((fpscr >> 22) & 3); 46264696Sandrew} 47264696Sandrew 48