From f15e7f41ac8c557516503343f8284f25e954dd9d Mon Sep 17 00:00:00 2001 From: David Edelsohn Date: Wed, 21 Jun 2017 14:32:34 +0000 Subject: [PATCH 2/2] Add lround implementations. Protect implementations with fallback for older architectures. --- src/math/powerpc64/ceil.c | 8 ++++++++ src/math/powerpc64/ceilf.c | 8 ++++++++ src/math/powerpc64/floor.c | 8 ++++++++ src/math/powerpc64/floorf.c | 8 ++++++++ src/math/powerpc64/fmax.c | 8 ++++++++ src/math/powerpc64/fmaxf.c | 8 ++++++++ src/math/powerpc64/fmin.c | 8 ++++++++ src/math/powerpc64/fminf.c | 8 ++++++++ src/math/powerpc64/lrint.c | 12 +++++++++--- src/math/powerpc64/lrintf.c | 12 +++++++++--- src/math/powerpc64/lround.c | 18 ++++++++++++++++++ src/math/powerpc64/lroundf.c | 18 ++++++++++++++++++ src/math/powerpc64/round.c | 8 ++++++++ src/math/powerpc64/roundf.c | 8 ++++++++ src/math/powerpc64/trunc.c | 8 ++++++++ src/math/powerpc64/truncf.c | 8 ++++++++ 16 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 src/math/powerpc64/lround.c create mode 100644 src/math/powerpc64/lroundf.c diff --git a/src/math/powerpc64/ceil.c b/src/math/powerpc64/ceil.c index b2e6d35..4b01133 100644 --- a/src/math/powerpc64/ceil.c +++ b/src/math/powerpc64/ceil.c @@ -1,7 +1,15 @@ #include +#ifdef _ARCH_PWR5X + double ceil(double x) { __asm__ ("frip %0, %1" : "=d"(x) : "d"(x)); return x; } + +#else + +#include "../ceil.c" + +#endif diff --git a/src/math/powerpc64/ceilf.c b/src/math/powerpc64/ceilf.c index 97d69c7..59ba396 100644 --- a/src/math/powerpc64/ceilf.c +++ b/src/math/powerpc64/ceilf.c @@ -1,7 +1,15 @@ #include +#ifdef _ARCH_PWR5X + float ceilf(float x) { __asm__ ("frip %0, %1" : "=f"(x) : "f"(x)); return x; } + +#else + +#include "../ceilf.c" + +#endif diff --git a/src/math/powerpc64/floor.c b/src/math/powerpc64/floor.c index d40ba65..4e68044 100644 --- a/src/math/powerpc64/floor.c +++ b/src/math/powerpc64/floor.c @@ -1,7 +1,15 @@ #include +#ifdef _ARCH_PWR5X + double floor(double x) { __asm__ ("frim %0, %1" : "=d"(x) : "d"(x)); return x; } + +#else + +#include "../floor.c" + +#endif diff --git a/src/math/powerpc64/floorf.c b/src/math/powerpc64/floorf.c index 34ea5ee..e1031ef 100644 --- a/src/math/powerpc64/floorf.c +++ b/src/math/powerpc64/floorf.c @@ -1,7 +1,15 @@ #include +#ifdef _ARCH_PWR5X + float floorf(float x) { __asm__ ("frim %0, %1" : "=f"(x) : "f"(x)); return x; } + +#else + +#include "../floorf.c" + +#endif diff --git a/src/math/powerpc64/fmax.c b/src/math/powerpc64/fmax.c index a9c507e..992df7f 100644 --- a/src/math/powerpc64/fmax.c +++ b/src/math/powerpc64/fmax.c @@ -1,7 +1,15 @@ #include +#ifdef __VSX__ + double fmax(double x, double y) { __asm__ ("xsmaxdp %x0, %x1, %x2" : "=ws"(x) : "ws"(x), "ws"(y)); return x; } + +#else + +#include "../fmax.c" + +#endif diff --git a/src/math/powerpc64/fmaxf.c b/src/math/powerpc64/fmaxf.c index f2dbd4b..345a234 100644 --- a/src/math/powerpc64/fmaxf.c +++ b/src/math/powerpc64/fmaxf.c @@ -1,7 +1,15 @@ #include +#ifdef __VSX__ + float fmaxf(float x, float y) { __asm__ ("xsmaxdp %x0, %x1, %x2" : "=ww"(x) : "ww"(x), "ww"(y)); return x; } + +#else + +#include "../fmaxf.c" + +#endif diff --git a/src/math/powerpc64/fmin.c b/src/math/powerpc64/fmin.c index 62504d6..adf71ba 100644 --- a/src/math/powerpc64/fmin.c +++ b/src/math/powerpc64/fmin.c @@ -1,7 +1,15 @@ #include +#ifdef __VSX__ + double fmin(double x, double y) { __asm__ ("xsmindp %x0, %x1, %x2" : "=ws"(x) : "ws"(x), "ws"(y)); return x; } + +#else + +#include "../fmin.c" + +#endif diff --git a/src/math/powerpc64/fminf.c b/src/math/powerpc64/fminf.c index 4d19262..faf0e47 100644 --- a/src/math/powerpc64/fminf.c +++ b/src/math/powerpc64/fminf.c @@ -1,7 +1,15 @@ #include +#ifdef __VSX__ + float fminf(float x, float y) { __asm__ ("xsmindp %x0, %x1, %x2" : "=ww"(x) : "ww"(x), "ww"(y)); return x; } + +#else + +#include "../fminf.c" + +#endif diff --git a/src/math/powerpc64/lrint.c b/src/math/powerpc64/lrint.c index 3e5269d..4e4b2e0 100644 --- a/src/math/powerpc64/lrint.c +++ b/src/math/powerpc64/lrint.c @@ -1,10 +1,16 @@ #include +#ifdef _ARCH_PWR5X + long lrint(double x) { long n; - __asm__ ( - "fctid %1, %1\n" - "mfvsrd %0, %1\n" : "=r"(n), "+d"(x)); + __asm__ ("fctid %0, %1" : "=d"(n) : "d"(x)); return n; } + +#else + +#include "../lrint.c" + +#endif diff --git a/src/math/powerpc64/lrintf.c b/src/math/powerpc64/lrintf.c index 2db1a5e..9070fc0 100644 --- a/src/math/powerpc64/lrintf.c +++ b/src/math/powerpc64/lrintf.c @@ -1,10 +1,16 @@ #include +#ifdef _ARCH_PWR5X + long lrintf(float x) { long n; - __asm__ ( - "fctid %1, %1\n" - "mfvsrd %0, %1\n" : "=r"(n), "+f"(x)); + __asm__ ("fctid %0, %1" : "=d"(n) : "f"(x)); return n; } + +#else + +#include "../lrintf.c" + +#endif diff --git a/src/math/powerpc64/lround.c b/src/math/powerpc64/lround.c new file mode 100644 index 0000000..ee4d114 --- /dev/null +++ b/src/math/powerpc64/lround.c @@ -0,0 +1,18 @@ +#include + +#ifdef __VSX__ + +long lround(double x) +{ + long n; + __asm__ ( + "xsrdpi %1, %1\n" + "fctid %0, %1\n" : "=d"(n), "+d"(x)); + return n; +} + +#else + +#include "../lround.c" + +#endif diff --git a/src/math/powerpc64/lroundf.c b/src/math/powerpc64/lroundf.c new file mode 100644 index 0000000..033094f --- /dev/null +++ b/src/math/powerpc64/lroundf.c @@ -0,0 +1,18 @@ +#include + +#ifdef __VSX__ + +long lroundf(float x) +{ + long n; + __asm__ ( + "xsrdpi %1, %1\n" + "fctid %0, %1\n" : "=d"(n), "+f"(x)); + return n; +} + +#else + +#include "../lroundf.c" + +#endif diff --git a/src/math/powerpc64/round.c b/src/math/powerpc64/round.c index ea396d9..4b9318e 100644 --- a/src/math/powerpc64/round.c +++ b/src/math/powerpc64/round.c @@ -1,7 +1,15 @@ #include +#ifdef _ARCH_PWR5X + double round(double x) { __asm__ ("frin %0, %1" : "=d"(x) : "d"(x)); return x; } + +#else + +#include "../round.c" + +#endif diff --git a/src/math/powerpc64/roundf.c b/src/math/powerpc64/roundf.c index 15c3439..ae93f99 100644 --- a/src/math/powerpc64/roundf.c +++ b/src/math/powerpc64/roundf.c @@ -1,7 +1,15 @@ #include +#ifdef _ARCH_PWR5X + float roundf(float x) { __asm__ ("frin %0, %1" : "=f"(x) : "f"(x)); return x; } + +#else + +#include "../roundf.c" + +#endif diff --git a/src/math/powerpc64/trunc.c b/src/math/powerpc64/trunc.c index abd3048..5791854 100644 --- a/src/math/powerpc64/trunc.c +++ b/src/math/powerpc64/trunc.c @@ -1,7 +1,15 @@ #include +#ifdef _ARCH_PWR5X + double trunc(double x) { __asm__ ("friz %0, %1" : "=d"(x) : "d"(x)); return x; } + +#else + +#include "../trunc.c" + +#endif diff --git a/src/math/powerpc64/truncf.c b/src/math/powerpc64/truncf.c index 3cd0e84..94e638f 100644 --- a/src/math/powerpc64/truncf.c +++ b/src/math/powerpc64/truncf.c @@ -1,7 +1,15 @@ #include +#ifdef _ARCH_PWR5X + float truncf(float x) { __asm__ ("friz %0, %1" : "=f"(x) : "f"(x)); return x; } + +#else + +#include "../truncf.c" + +#endif -- 1.8.3.1