Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Add complex arc functions
Browse files Browse the repository at this point in the history
Change-Id: I2fa1987f25d1ca275ffd7c3a79d83a565a36b0d0
  • Loading branch information
b-sumner committed Jul 18, 2019
1 parent eb80f4f commit 20236fe
Show file tree
Hide file tree
Showing 22 changed files with 561 additions and 18 deletions.
18 changes: 18 additions & 0 deletions ocml/inc/ocml.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,24 @@ DECL_CONST_OCML_UNARY_F16(native_log2)
extern __attribute__((const)) float OCML_MANGLE_F32(cabs)(float2);
extern __attribute__((const)) double OCML_MANGLE_F64(cabs)(double2);

extern __attribute__((const)) float2 OCML_MANGLE_F32(cacos)(float2);
extern __attribute__((const)) double2 OCML_MANGLE_F64(cacos)(double2);

extern __attribute__((const)) float2 OCML_MANGLE_F32(cacosh)(float2);
extern __attribute__((const)) double2 OCML_MANGLE_F64(cacosh)(double2);

extern __attribute__((const)) float2 OCML_MANGLE_F32(casin)(float2);
extern __attribute__((const)) double2 OCML_MANGLE_F64(casin)(double2);

extern __attribute__((const)) float2 OCML_MANGLE_F32(casinh)(float2);
extern __attribute__((const)) double2 OCML_MANGLE_F64(casinh)(double2);

extern __attribute__((const)) float2 OCML_MANGLE_F32(catan)(float2);
extern __attribute__((const)) double2 OCML_MANGLE_F64(catan)(double2);

extern __attribute__((const)) float2 OCML_MANGLE_F32(catanh)(float2);
extern __attribute__((const)) double2 OCML_MANGLE_F64(catanh)(double2);

extern __attribute__((const)) float2 OCML_MANGLE_F32(cexp)(float2);
extern __attribute__((const)) double2 OCML_MANGLE_F64(cexp)(double2);

Expand Down
2 changes: 0 additions & 2 deletions ocml/src/acoshD.cl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ MATH_MANGLE(acosh)(double x)
double2 a = add(sx, root2(sub(sqr(sx), s*s)));
double z = MATH_PRIVATE(lnep)(a, b ? 512 : 0);

z = x == 1.0 ? 0.0 : z;

if (!FINITE_ONLY_OPT()) {
z = BUILTIN_CLASS_F64(x, CLASS_PINF) ? x : z;
z = x < 1.0 ? AS_DOUBLE(QNANBITPATT_DP64) : z;
Expand Down
2 changes: 0 additions & 2 deletions ocml/src/acoshF.cl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ MATH_MANGLE(acosh)(float x)
float2 a = add(sx, root2(sub(sqr(sx), s*s)));
float z = MATH_PRIVATE(lnep)(a, b ? 64 : 0);

z = x == 1.0f ? 0.0f : z;

if (!FINITE_ONLY_OPT()) {
z = BUILTIN_CLASS_F32(x, CLASS_PINF) ? x : z;
z = x < 1.0f ? AS_FLOAT(QNANBITPATT_SP32) : z;
Expand Down
17 changes: 17 additions & 0 deletions ocml/src/cacosD.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*===--------------------------------------------------------------------------
* ROCm Device Libraries
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*===------------------------------------------------------------------------*/

#include "mathD.h"

CONSTATTR double2
MATH_MANGLE(cacos)(double2 z)
{
double2 a = MATH_MANGLE(cacosh)(z);
bool b = AS_INT2(z.y).hi < 0;
return (double2)(b ? -a.y : a.y, b ? a.x : -a.x);
}

17 changes: 17 additions & 0 deletions ocml/src/cacosF.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*===--------------------------------------------------------------------------
* ROCm Device Libraries
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*===------------------------------------------------------------------------*/

#include "mathF.h"

CONSTATTR float2
MATH_MANGLE(cacos)(float2 z)
{
float2 a = MATH_MANGLE(cacosh)(z);
bool b = AS_INT(z.y) < 0;
return (float2)(b ? -a.y : a.y, b ? a.x : -a.x);
}

64 changes: 64 additions & 0 deletions ocml/src/cacoshD.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*===--------------------------------------------------------------------------
* ROCm Device Libraries
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*===------------------------------------------------------------------------*/

#include "mathD.h"

#define DOUBLE_SPECIALIZATION
#include "ep.h"

extern CONSTATTR double4 MATH_PRIVATE(epcsqrtep)(double4 z);
extern CONSTATTR double MATH_PRIVATE(lnep)(double2 a, int ea);

CONSTATTR double2
MATH_MANGLE(cacosh)(double2 z)
{
double x = BUILTIN_ABS_F64(z.x);
double y = BUILTIN_ABS_F64(z.y);

double2 l2, t;
int e = 0;
bool b = true;

if (x < 0x1.0p+54 && y < 0x1.0p+54) {
if (x >= 1.0 || y >= 0x1.0p-53 || y > (1.0 - x)*0x1.0p-26) {
double4 z2p1 = (double4)(add(mul(add(y,x), sub(y,x)), 1.0), mul(y,x)*2.0);
double4 rz2m1 = MATH_PRIVATE(epcsqrtep)(z2p1);
rz2m1 = (double4)(csgn(rz2m1.hi, (double2)z.x), csgn(rz2m1.lo, (double2)z.y));
double4 s = (double4)(add(rz2m1.lo, z.x), add(rz2m1.hi, z.y));
l2 = add(sqr(s.lo), sqr(s.hi));
t = (double2)(s.s1, z.y == 0.0 ? z.y : s.s3);
} else {
b = false;
double r = MATH_FAST_SQRT(BUILTIN_FMA_F64(-x, x, 1.0));
l2 = con(MATH_DIV(y, r), 0.0);
t = (double2)(z.x, BUILTIN_COPYSIGN_F64(r, z.y));
}
} else {
e = BUILTIN_FREXP_EXP_F64(BUILTIN_MAX_F64(x,y));
x = BUILTIN_FLDEXP_F64(x, -e);
y = BUILTIN_FLDEXP_F64(y, -e);
l2 = add(sqr(x), sqr(y));
e = 2*e + 2;
t = z;
}

double rr;
if (b) {
rr = 0.5 * MATH_PRIVATE(lnep)(l2, e);
} else {
rr = l2.hi;
}

double ri = MATH_MANGLE(atan2)(t.y, t.x);

if (!FINITE_ONLY_OPT()) {
rr = (BUILTIN_ISINF_F64(z.x) | BUILTIN_ISINF_F64(z.y)) ? AS_DOUBLE(PINFBITPATT_DP64) : rr;
}

return (double2)(rr, ri);
}

64 changes: 64 additions & 0 deletions ocml/src/cacoshF.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*===--------------------------------------------------------------------------
* ROCm Device Libraries
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*===------------------------------------------------------------------------*/

#include "mathF.h"

#define FLOAT_SPECIALIZATION
#include "ep.h"

extern CONSTATTR float4 MATH_PRIVATE(epcsqrtep)(float4 z);
extern CONSTATTR float MATH_PRIVATE(lnep)(float2 a, int ea);

CONSTATTR float2
MATH_MANGLE(cacosh)(float2 z)
{
float x = BUILTIN_ABS_F32(z.x);
float y = BUILTIN_ABS_F32(z.y);

float2 l2, t;
int e = 0;
bool b = true;

if (x < 0x1.0p+25f && y < 0x1.0p+25f) {
if (x >= 1.0f || y >= 0x1.0p-24f || y > (1.0f - x)*0x1.0p-12f) {
float4 z2p1 = (float4)(add(mul(add(y,x), sub(y,x)), 1.0f), mul(y,x)*2.0f);
float4 rz2m1 = MATH_PRIVATE(epcsqrtep)(z2p1);
rz2m1 = (float4)(csgn(rz2m1.hi, (float2)z.x), csgn(rz2m1.lo, (float2)z.y));
float4 s = (float4)(add(rz2m1.lo, z.x), add(rz2m1.hi, z.y));
l2 = add(sqr(s.lo), sqr(s.hi));
t = (float2)(s.s1, z.y == 0.0f ? z.y : s.s3);
} else {
b = false;
float r = MATH_SQRT(BUILTIN_FMA_F32(-x, x, 1.0f));
l2 = con(MATH_DIV(y, r), 0.0f);
t = (float2)(z.x, BUILTIN_COPYSIGN_F32(r, z.y));
}
} else {
e = BUILTIN_FREXP_EXP_F32(AS_FLOAT(BUILTIN_MAX_U32(AS_UINT(x), AS_UINT(y))));
x = BUILTIN_FLDEXP_F32(x, -e);
y = BUILTIN_FLDEXP_F32(y, -e);
l2 = add(sqr(x), sqr(y));
e = 2*e + 2;
t = z;
}

float rr;
if (b) {
rr = 0.5f * MATH_PRIVATE(lnep)(l2, e);
} else {
rr = l2.hi;
}

float ri = MATH_MANGLE(atan2)(t.y, t.x);

if (!FINITE_ONLY_OPT()) {
rr = (BUILTIN_ISINF_F32(z.x) | BUILTIN_ISINF_F32(z.y)) ? AS_FLOAT(PINFBITPATT_SP32) : rr;
}

return (float2)(rr, ri);
}

16 changes: 16 additions & 0 deletions ocml/src/casinD.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*===--------------------------------------------------------------------------
* ROCm Device Libraries
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*===------------------------------------------------------------------------*/

#include "mathD.h"

CONSTATTR double2
MATH_MANGLE(casin)(double2 z)
{
double2 a = MATH_MANGLE(casinh)((double2)(-z.y, z.x));
return (double2)(a.y, -a.x);
}

16 changes: 16 additions & 0 deletions ocml/src/casinF.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*===--------------------------------------------------------------------------
* ROCm Device Libraries
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*===------------------------------------------------------------------------*/

#include "mathF.h"

CONSTATTR float2
MATH_MANGLE(casin)(float2 z)
{
float2 a = MATH_MANGLE(casinh)((float2)(-z.y, z.x));
return (float2)(a.y, -a.x);
}

65 changes: 65 additions & 0 deletions ocml/src/casinhD.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*===--------------------------------------------------------------------------
* ROCm Device Libraries
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*===------------------------------------------------------------------------*/

#include "mathD.h"

#define DOUBLE_SPECIALIZATION
#include "ep.h"

extern CONSTATTR double4 MATH_PRIVATE(epcsqrtep)(double4 z);
extern CONSTATTR double MATH_PRIVATE(lnep)(double2 a, int ea);

CONSTATTR double2
MATH_MANGLE(casinh)(double2 z)
{
double x = BUILTIN_ABS_F64(z.x);
double y = BUILTIN_ABS_F64(z.y);

double2 l2, t;
int e = 0;
bool b = true;

if (x < 0x1.0p+54 && y < 0x1.0p+54) {
if (y >= 1.0 || x >= 0x1.0p-53 || x > (1.0 - y)*0x1.0p-26f) {
double4 z2p1 = (double4)(add(mul(add(x,y), sub(x,y)), 1.0), mul(y,x)*2.0);
double4 rz2p1 = MATH_PRIVATE(epcsqrtep)(z2p1);
double4 s = (double4)(add(rz2p1.lo, x), add(rz2p1.hi, y));
l2 = add(sqr(s.lo), sqr(s.hi));
t = (double2)(s.s1, s.s3);
} else {
b = false;
double r = MATH_SQRT(BUILTIN_FMA_F64(-y, y, 1.0));
l2 = con(MATH_DIV(x, r), 0.0);
t = (double2)(r, y);
}
} else {
t = (double2)(x, y);
e = BUILTIN_FREXP_EXP_F64(BUILTIN_MAX_F64(x, y));
x = BUILTIN_FLDEXP_F64(x, -e);
y = BUILTIN_FLDEXP_F64(y, -e);
l2 = add(sqr(x), sqr(y));
e = 2*e + 2;
}

double rr;
if (b) {
rr = 0.5 * MATH_PRIVATE(lnep)(l2, e);
} else {
rr = l2.hi;
}

rr = BUILTIN_COPYSIGN_F64(rr, z.x);
double ri = BUILTIN_COPYSIGN_F64(MATH_MANGLE(atan2)(t.y, t.x), z.y);

if (!FINITE_ONLY_OPT()) {
double i = BUILTIN_COPYSIGN_F64(AS_DOUBLE(PINFBITPATT_DP64), z.x);
rr = (BUILTIN_ISINF_F64(z.x) | BUILTIN_ISINF_F64(z.y)) ? i : rr;
}

return (double2)(rr, ri);
}

65 changes: 65 additions & 0 deletions ocml/src/casinhF.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*===--------------------------------------------------------------------------
* ROCm Device Libraries
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*===------------------------------------------------------------------------*/

#include "mathF.h"

#define FLOAT_SPECIALIZATION
#include "ep.h"

extern CONSTATTR float4 MATH_PRIVATE(epcsqrtep)(float4 z);
extern CONSTATTR float MATH_PRIVATE(lnep)(float2 a, int ea);

CONSTATTR float2
MATH_MANGLE(casinh)(float2 z)
{
float x = BUILTIN_ABS_F32(z.x);
float y = BUILTIN_ABS_F32(z.y);

float2 l2, t;
int e = 0;
bool b = true;

if (x < 0x1.0p+25f && y < 0x1.0p+25f) {
if (y >= 1.0f || x >= 0x1.0p-24f || x > (1.0f - y)*0x1.0p-12f) {
float4 z2p1 = (float4)(add(mul(add(x,y), sub(x,y)), 1.0f), mul(y,x)*2.0f);
float4 rz2p1 = MATH_PRIVATE(epcsqrtep)(z2p1);
float4 s = (float4)(add(rz2p1.lo, x), add(rz2p1.hi, y));
l2 = add(sqr(s.lo), sqr(s.hi));
t = (float2)(s.s1, s.s3);
} else {
b = false;
float r = MATH_SQRT(BUILTIN_FMA_F32(-y, y, 1.0f));
l2 = con(MATH_DIV(x, r), 0.0f);
t = (float2)(r, y);
}
} else {
t = (float2)(x, y);
e = BUILTIN_FREXP_EXP_F32(AS_FLOAT(BUILTIN_MAX_U32(AS_UINT(x), AS_UINT(y))));
x = BUILTIN_FLDEXP_F32(x, -e);
y = BUILTIN_FLDEXP_F32(y, -e);
l2 = add(sqr(x), sqr(y));
e = 2*e + 2;
}

float rr;
if (b) {
rr = 0.5f * MATH_PRIVATE(lnep)(l2, e);
} else {
rr = l2.hi;
}

rr = BUILTIN_COPYSIGN_F32(rr, z.x);
float ri = BUILTIN_COPYSIGN_F32(MATH_MANGLE(atan2)(t.y, t.x), z.y);

if (!FINITE_ONLY_OPT()) {
float i = BUILTIN_COPYSIGN_F32(AS_FLOAT(PINFBITPATT_SP32), z.x);
rr = (BUILTIN_ISINF_F32(z.x) | BUILTIN_ISINF_F32(z.y)) ? i : rr;
}

return (float2)(rr, ri);
}

16 changes: 16 additions & 0 deletions ocml/src/catanD.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*===--------------------------------------------------------------------------
* ROCm Device Libraries
*
* This file is distributed under the University of Illinois Open Source
* License. See LICENSE.TXT for details.
*===------------------------------------------------------------------------*/

#include "mathD.h"

CONSTATTR double2
MATH_MANGLE(catan)(double2 z)
{
double2 a = MATH_MANGLE(catanh)((double2)(-z.y, z.x));
return (double2)(a.y, -a.x);
}

Loading

0 comments on commit 20236fe

Please sign in to comment.