1 /* $OpenBSD: e_sqrtf.c,v 1.1 2009/04/05 19:26:27 martynas Exp $ */ 2 3 /* 4 * Written by Martynas Venckus. Public domain 5 */ 6 7 #include <sys/types.h> 8 #include <math.h> 9 10 #define FPSCR_PR (1 << 19) 11 12 float 13 sqrtf(float f) 14 { 15 register_t fpscr, nfpscr; 16 17 __asm__ __volatile__ ("sts fpscr, %0" : "=r" (fpscr)); 18 19 /* Set floating-point mode to single-precision. */ 20 nfpscr = fpscr & ~FPSCR_PR; 21 22 __asm__ __volatile__ ("lds %0, fpscr" : : "r" (nfpscr)); 23 __asm__ __volatile__ ("fsqrt %0" : "+f" (f)); 24 25 /* Restore fp status/control register. */ 26 __asm__ __volatile__ ("lds %0, fpscr" : : "r" (fpscr)); 27 28 return (f); 29 } 30 31