From 4eb34b23ba5c9cd932e2ee2fd27fb1f3a6e2f4b0 Mon Sep 17 00:00:00 2001 From: David Edelsohn Date: Fri, 9 Jun 2017 15:40:40 +0000 Subject: [PATCH 1/2] Add single instruction math functions for Power8 --- src/math/powerpc64/ceil.c | 7 +++++++ src/math/powerpc64/ceilf.c | 7 +++++++ src/math/powerpc64/fabs.c | 7 +++++++ src/math/powerpc64/fabsf.c | 7 +++++++ src/math/powerpc64/floor.c | 7 +++++++ src/math/powerpc64/floorf.c | 7 +++++++ src/math/powerpc64/fma.c | 7 +++++++ src/math/powerpc64/fmaf.c | 7 +++++++ src/math/powerpc64/fmax.c | 7 +++++++ src/math/powerpc64/fmaxf.c | 7 +++++++ src/math/powerpc64/fmin.c | 7 +++++++ src/math/powerpc64/fminf.c | 7 +++++++ src/math/powerpc64/lrint.c | 10 ++++++++++ src/math/powerpc64/lrintf.c | 10 ++++++++++ src/math/powerpc64/round.c | 7 +++++++ src/math/powerpc64/roundf.c | 7 +++++++ src/math/powerpc64/sqrt.c | 7 +++++++ src/math/powerpc64/sqrtf.c | 7 +++++++ src/math/powerpc64/trunc.c | 7 +++++++ src/math/powerpc64/truncf.c | 7 +++++++ 20 files changed, 146 insertions(+) create mode 100644 src/math/powerpc64/ceil.c create mode 100644 src/math/powerpc64/ceilf.c create mode 100644 src/math/powerpc64/fabs.c create mode 100644 src/math/powerpc64/fabsf.c create mode 100644 src/math/powerpc64/floor.c create mode 100644 src/math/powerpc64/floorf.c create mode 100644 src/math/powerpc64/fma.c create mode 100644 src/math/powerpc64/fmaf.c create mode 100644 src/math/powerpc64/fmax.c create mode 100644 src/math/powerpc64/fmaxf.c create mode 100644 src/math/powerpc64/fmin.c create mode 100644 src/math/powerpc64/fminf.c create mode 100644 src/math/powerpc64/lrint.c create mode 100644 src/math/powerpc64/lrintf.c create mode 100644 src/math/powerpc64/round.c create mode 100644 src/math/powerpc64/roundf.c create mode 100644 src/math/powerpc64/sqrt.c create mode 100644 src/math/powerpc64/sqrtf.c create mode 100644 src/math/powerpc64/trunc.c create mode 100644 src/math/powerpc64/truncf.c diff --git a/src/math/powerpc64/ceil.c b/src/math/powerpc64/ceil.c new file mode 100644 index 0000000..b2e6d35 --- /dev/null +++ b/src/math/powerpc64/ceil.c @@ -0,0 +1,7 @@ +#include + +double ceil(double x) +{ + __asm__ ("frip %0, %1" : "=d"(x) : "d"(x)); + return x; +} diff --git a/src/math/powerpc64/ceilf.c b/src/math/powerpc64/ceilf.c new file mode 100644 index 0000000..97d69c7 --- /dev/null +++ b/src/math/powerpc64/ceilf.c @@ -0,0 +1,7 @@ +#include + +float ceilf(float x) +{ + __asm__ ("frip %0, %1" : "=f"(x) : "f"(x)); + return x; +} diff --git a/src/math/powerpc64/fabs.c b/src/math/powerpc64/fabs.c new file mode 100644 index 0000000..6123c75 --- /dev/null +++ b/src/math/powerpc64/fabs.c @@ -0,0 +1,7 @@ +#include + +double fabs(double x) +{ + __asm__ ("fabs %0, %1" : "=d"(x) : "d"(x)); + return x; +} diff --git a/src/math/powerpc64/fabsf.c b/src/math/powerpc64/fabsf.c new file mode 100644 index 0000000..e9e4564 --- /dev/null +++ b/src/math/powerpc64/fabsf.c @@ -0,0 +1,7 @@ +#include + +float fabsf(float x) +{ + __asm__ ("fabs %0, %1" : "=f"(x) : "f"(x)); + return x; +} diff --git a/src/math/powerpc64/floor.c b/src/math/powerpc64/floor.c new file mode 100644 index 0000000..d40ba65 --- /dev/null +++ b/src/math/powerpc64/floor.c @@ -0,0 +1,7 @@ +#include + +double floor(double x) +{ + __asm__ ("frim %0, %1" : "=d"(x) : "d"(x)); + return x; +} diff --git a/src/math/powerpc64/floorf.c b/src/math/powerpc64/floorf.c new file mode 100644 index 0000000..34ea5ee --- /dev/null +++ b/src/math/powerpc64/floorf.c @@ -0,0 +1,7 @@ +#include + +float floorf(float x) +{ + __asm__ ("frim %0, %1" : "=f"(x) : "f"(x)); + return x; +} diff --git a/src/math/powerpc64/fma.c b/src/math/powerpc64/fma.c new file mode 100644 index 0000000..5aebd1a --- /dev/null +++ b/src/math/powerpc64/fma.c @@ -0,0 +1,7 @@ +#include + +double fma(double x, double y, double z) +{ + __asm__ ("fmadd %0, %1, %2, %3" : "=d"(x) : "d"(x), "d"(y), "d"(z)); + return x; +} diff --git a/src/math/powerpc64/fmaf.c b/src/math/powerpc64/fmaf.c new file mode 100644 index 0000000..c678fef --- /dev/null +++ b/src/math/powerpc64/fmaf.c @@ -0,0 +1,7 @@ +#include + +float fmaf(float x, float y, float z) +{ + __asm__ ("fmadds %0, %1, %2, %3" : "=f"(x) : "f"(x), "f"(y), "f"(z)); + return x; +} diff --git a/src/math/powerpc64/fmax.c b/src/math/powerpc64/fmax.c new file mode 100644 index 0000000..a9c507e --- /dev/null +++ b/src/math/powerpc64/fmax.c @@ -0,0 +1,7 @@ +#include + +double fmax(double x, double y) +{ + __asm__ ("xsmaxdp %x0, %x1, %x2" : "=ws"(x) : "ws"(x), "ws"(y)); + return x; +} diff --git a/src/math/powerpc64/fmaxf.c b/src/math/powerpc64/fmaxf.c new file mode 100644 index 0000000..f2dbd4b --- /dev/null +++ b/src/math/powerpc64/fmaxf.c @@ -0,0 +1,7 @@ +#include + +float fmaxf(float x, float y) +{ + __asm__ ("xsmaxdp %x0, %x1, %x2" : "=ww"(x) : "ww"(x), "ww"(y)); + return x; +} diff --git a/src/math/powerpc64/fmin.c b/src/math/powerpc64/fmin.c new file mode 100644 index 0000000..62504d6 --- /dev/null +++ b/src/math/powerpc64/fmin.c @@ -0,0 +1,7 @@ +#include + +double fmin(double x, double y) +{ + __asm__ ("xsmindp %x0, %x1, %x2" : "=ws"(x) : "ws"(x), "ws"(y)); + return x; +} diff --git a/src/math/powerpc64/fminf.c b/src/math/powerpc64/fminf.c new file mode 100644 index 0000000..4d19262 --- /dev/null +++ b/src/math/powerpc64/fminf.c @@ -0,0 +1,7 @@ +#include + +float fminf(float x, float y) +{ + __asm__ ("xsmindp %x0, %x1, %x2" : "=ww"(x) : "ww"(x), "ww"(y)); + return x; +} diff --git a/src/math/powerpc64/lrint.c b/src/math/powerpc64/lrint.c new file mode 100644 index 0000000..3e5269d --- /dev/null +++ b/src/math/powerpc64/lrint.c @@ -0,0 +1,10 @@ +#include + +long lrint(double x) +{ + long n; + __asm__ ( + "fctid %1, %1\n" + "mfvsrd %0, %1\n" : "=r"(n), "+d"(x)); + return n; +} diff --git a/src/math/powerpc64/lrintf.c b/src/math/powerpc64/lrintf.c new file mode 100644 index 0000000..2db1a5e --- /dev/null +++ b/src/math/powerpc64/lrintf.c @@ -0,0 +1,10 @@ +#include + +long lrintf(float x) +{ + long n; + __asm__ ( + "fctid %1, %1\n" + "mfvsrd %0, %1\n" : "=r"(n), "+f"(x)); + return n; +} diff --git a/src/math/powerpc64/round.c b/src/math/powerpc64/round.c new file mode 100644 index 0000000..ea396d9 --- /dev/null +++ b/src/math/powerpc64/round.c @@ -0,0 +1,7 @@ +#include + +double round(double x) +{ + __asm__ ("frin %0, %1" : "=d"(x) : "d"(x)); + return x; +} diff --git a/src/math/powerpc64/roundf.c b/src/math/powerpc64/roundf.c new file mode 100644 index 0000000..15c3439 --- /dev/null +++ b/src/math/powerpc64/roundf.c @@ -0,0 +1,7 @@ +#include + +float roundf(float x) +{ + __asm__ ("frin %0, %1" : "=f"(x) : "f"(x)); + return x; +} diff --git a/src/math/powerpc64/sqrt.c b/src/math/powerpc64/sqrt.c new file mode 100644 index 0000000..13bb98d --- /dev/null +++ b/src/math/powerpc64/sqrt.c @@ -0,0 +1,7 @@ +#include + +double sqrt(double x) +{ + __asm__ ("fsqrt %0, %1" : "=d"(x) : "d"(x)); + return x; +} diff --git a/src/math/powerpc64/sqrtf.c b/src/math/powerpc64/sqrtf.c new file mode 100644 index 0000000..b6ecb10 --- /dev/null +++ b/src/math/powerpc64/sqrtf.c @@ -0,0 +1,7 @@ +#include + +float sqrtf(float x) +{ + __asm__ ("fsqrts %0, %1" : "=f"(x) : "f"(x)); + return x; +} diff --git a/src/math/powerpc64/trunc.c b/src/math/powerpc64/trunc.c new file mode 100644 index 0000000..abd3048 --- /dev/null +++ b/src/math/powerpc64/trunc.c @@ -0,0 +1,7 @@ +#include + +double trunc(double x) +{ + __asm__ ("friz %0, %1" : "=d"(x) : "d"(x)); + return x; +} diff --git a/src/math/powerpc64/truncf.c b/src/math/powerpc64/truncf.c new file mode 100644 index 0000000..3cd0e84 --- /dev/null +++ b/src/math/powerpc64/truncf.c @@ -0,0 +1,7 @@ +#include + +float truncf(float x) +{ + __asm__ ("friz %0, %1" : "=f"(x) : "f"(x)); + return x; +} -- 1.8.3.1