summaryrefslogtreecommitdiff
path: root/lib/libm/arch/sh/e_sqrtf.c
blob: 6f7475b38380e18afec4051958fb8e2c35c3ae07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*	$OpenBSD: e_sqrtf.c,v 1.3 2016/09/12 19:47:02 guenther Exp $	*/

/*
 * Written by Martynas Venckus.  Public domain
 */

#include <sys/types.h>
#include <math.h>

#define	FPSCR_PR	(1 << 19)

float
sqrtf(float f)
{
	register_t fpscr, nfpscr;

	__asm__ volatile ("sts fpscr, %0" : "=r" (fpscr));

	/* Set floating-point mode to single-precision. */
	nfpscr = fpscr & ~FPSCR_PR;

	__asm__ volatile ("lds %0, fpscr" : : "r" (nfpscr));
	__asm__ volatile ("fsqrt %0" : "+f" (f));

	/* Restore fp status/control register. */
	__asm__ volatile ("lds %0, fpscr" : : "r" (fpscr));

	return (f);
}
DEF_STD(sqrtf);