]> granicus.if.org Git - musl/commitdiff
mips: add single-instruction math functions
authorinfo@mobile-stream.com <info@mobile-stream.com>
Wed, 11 Sep 2019 10:05:04 +0000 (13:05 +0300)
committerRich Felker <dalias@aerifal.cx>
Mon, 14 Oct 2019 14:04:47 +0000 (10:04 -0400)
SQRT.fmt exists on MIPS II+ (float), MIPS III+ (double).

ABS.fmt exists on MIPS I+ but only cores with ABS2008 flag in FCSR
implement the required behaviour.

src/math/mips/fabs.c [new file with mode: 0644]
src/math/mips/fabsf.c [new file with mode: 0644]
src/math/mips/sqrt.c [new file with mode: 0644]
src/math/mips/sqrtf.c [new file with mode: 0644]

diff --git a/src/math/mips/fabs.c b/src/math/mips/fabs.c
new file mode 100644 (file)
index 0000000..0a5aa3b
--- /dev/null
@@ -0,0 +1,16 @@
+#if !defined(__mips_soft_float) && defined(__mips_abs2008)
+
+#include <math.h>
+
+double fabs(double x)
+{
+       double r;
+       __asm__("abs.d %0,%1" : "=f"(r) : "f"(x));
+       return r;
+}
+
+#else
+
+#include "../fabs.c"
+
+#endif
diff --git a/src/math/mips/fabsf.c b/src/math/mips/fabsf.c
new file mode 100644 (file)
index 0000000..35307be
--- /dev/null
@@ -0,0 +1,16 @@
+#if !defined(__mips_soft_float) && defined(__mips_abs2008)
+
+#include <math.h>
+
+float fabsf(float x)
+{
+       float r;
+       __asm__("abs.s %0,%1" : "=f"(r) : "f"(x));
+       return r;
+}
+
+#else
+
+#include "../fabsf.c"
+
+#endif
diff --git a/src/math/mips/sqrt.c b/src/math/mips/sqrt.c
new file mode 100644 (file)
index 0000000..595c9db
--- /dev/null
@@ -0,0 +1,16 @@
+#if !defined(__mips_soft_float) && __mips >= 3
+
+#include <math.h>
+
+double sqrt(double x)
+{
+       double r;
+       __asm__("sqrt.d %0,%1" : "=f"(r) : "f"(x));
+       return r;
+}
+
+#else
+
+#include "../sqrt.c"
+
+#endif
diff --git a/src/math/mips/sqrtf.c b/src/math/mips/sqrtf.c
new file mode 100644 (file)
index 0000000..84090d2
--- /dev/null
@@ -0,0 +1,16 @@
+#if !defined(__mips_soft_float) && __mips >= 2
+
+#include <math.h>
+
+float sqrtf(float x)
+{
+       float r;
+       __asm__("sqrt.s %0,%1" : "=f"(r) : "f"(x));
+       return r;
+}
+
+#else
+
+#include "../sqrtf.c"
+
+#endif