1 /* $OpenBSD: fpsetround.c,v 1.3 2014/04/18 15:09:52 guenther Exp $ */ 2 /* 3 * Copyright (c) 2006 Miodrag Vallat. 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice, this permission notice, and the disclaimer below 8 * appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #include <sys/types.h> 20 #include <ieeefp.h> 21 22 fp_rnd 23 fpsetround(fp_rnd rnd_dir) 24 { 25 register_t fpscr, nfpscr; 26 #if defined(__SH4__) && !defined(__SH4_NOFPU__) 27 extern register_t __fpscr_values[2]; 28 #endif 29 30 __asm__ volatile ("sts fpscr, %0" : "=r" (fpscr)); 31 if (rnd_dir == FP_RN || rnd_dir == FP_RZ) { 32 nfpscr = (fpscr & ~0x03) | rnd_dir; 33 #if defined(__SH4__) && !defined(__SH4_NOFPU__) 34 __fpscr_values[0] = (__fpscr_values[0] & ~0x03) | rnd_dir; 35 __fpscr_values[1] = (__fpscr_values[1] & ~0x03) | rnd_dir; 36 #endif 37 __asm__ volatile ("lds %0, fpscr" : : "r" (nfpscr)); 38 } 39 /* else how report an error? */ 40 41 return (fpscr & 0x03); 42 } 43