fpsetround_vfp.c revision 264721
191094Sdes/* 292289Sdes * Copyright (C) 2014 Andrew Turner 391094Sdes * All rights reserved. 491094Sdes * 591094Sdes * Redistribution and use in source and binary forms, with or without 699158Sdes * modification, are permitted provided that the following conditions 799158Sdes * are met: 899158Sdes * 1. Redistributions of source code must retain the above copyright 991094Sdes * notice, this list of conditions and the following disclaimer. 1091094Sdes * 2. Redistributions in binary form must reproduce the above copyright 1191094Sdes * notice, this list of conditions and the following disclaimer in the 1291094Sdes * documentation and/or other materials provided with the distribution. 1391094Sdes * 1491094Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1591094Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1691094Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1791094Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1891094Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1991094Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2091094Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2191094Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2291094Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2391094Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2491094Sdes * SUCH DAMAGE. 2591094Sdes * 2691094Sdes */ 2791094Sdes 2891094Sdes#include <sys/cdefs.h> 2991094Sdes__FBSDID("$FreeBSD: head/lib/libc/arm/gen/fpsetround_vfp.c 264721 2014-04-21 09:43:22Z andrew $"); 3091094Sdes 3191094Sdes#include <sys/types.h> 3291094Sdes#include <ieeefp.h> 3391094Sdes 3499158Sdes#ifdef __weak_alias 3591094Sdes__weak_alias(fpsetround,_fpsetround) 3691094Sdes#endif 3791094Sdes 3891094Sdesfp_rnd_t 3991094Sdesfpsetround(fp_rnd_t rnd_dir) 4091094Sdes{ 4191094Sdes uint32_t old, new; 4291094Sdes 4391094Sdes __asm __volatile("vmrs %0, fpscr" : "=&r"(old)); 4491094Sdes new = old & ~(3 << 22); 4591094Sdes new |= rnd_dir << 22; 4691094Sdes __asm __volatile("vmsr fpscr, %0" : : "r"(new)); 4791094Sdes 4891094Sdes return ((old >> 22) & 3); 4991094Sdes} 5091094Sdes 5191094Sdes