23 #ifndef HIP_INCLUDE_HIP_HCC_DETAIL_HIP_COMPLEX_H 24 #define HIP_INCLUDE_HIP_HCC_DETAIL_HIP_COMPLEX_H 30 #define COMPLEX_ADD_OP_OVERLOAD(type) \ 31 __device__ __host__ static inline type operator + (const type& lhs, const type& rhs) { \ 33 ret.x = lhs.x + rhs.x ; \ 34 ret.y = lhs.y + rhs.y ; \ 38 #define COMPLEX_SUB_OP_OVERLOAD(type) \ 39 __device__ __host__ static inline type operator - (const type& lhs, const type& rhs) { \ 41 ret.x = lhs.x - rhs.x; \ 42 ret.y = lhs.y - rhs.y; \ 46 #define COMPLEX_MUL_OP_OVERLOAD(type) \ 47 __device__ __host__ static inline type operator * (const type& lhs, const type& rhs) { \ 49 ret.x = lhs.x * rhs.x - lhs.y * rhs.y; \ 50 ret.y = lhs.x * rhs.y + lhs.y * rhs.x; \ 54 #define COMPLEX_DIV_OP_OVERLOAD(type) \ 55 __device__ __host__ static inline type operator / (const type& lhs, const type& rhs) { \ 57 ret.x = (lhs.x * rhs.x + lhs.y * rhs.y); \ 58 ret.y = (rhs.x * lhs.y - lhs.x * rhs.y); \ 59 ret.x = ret.x / (rhs.x * rhs.x + rhs.y * rhs.y); \ 60 ret.y = ret.y / (rhs.x * rhs.x + rhs.y * rhs.y); \ 64 #define COMPLEX_ADD_PREOP_OVERLOAD(type) \ 65 __device__ __host__ static inline type& operator += (type& lhs, const type& rhs) { \ 71 #define COMPLEX_SUB_PREOP_OVERLOAD(type) \ 72 __device__ __host__ static inline type& operator -= (type& lhs, const type& rhs) { \ 78 #define COMPLEX_MUL_PREOP_OVERLOAD(type) \ 79 __device__ __host__ static inline type& operator *= (type& lhs, const type& rhs) { \ 84 #define COMPLEX_DIV_PREOP_OVERLOAD(type) \ 85 __device__ __host__ static inline type& operator /= (type& lhs, const type& rhs) { \ 90 #define COMPLEX_SCALAR_PRODUCT(type, type1) \ 91 __device__ __host__ static inline type operator * (const type& lhs, type1 rhs) { \ 93 ret.x = lhs.x * rhs; \ 94 ret.y = lhs.y * rhs; \ 104 __device__
__host__ hipFloatComplex(
float x) : x(x), y(0.0f) {}
105 __device__
__host__ hipFloatComplex(
float x,
float y) : x(x), y(y) {}
106 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipFloatComplex,
unsigned short)
107 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipFloatComplex,
signed short)
108 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipFloatComplex,
unsigned int)
109 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipFloatComplex,
signed int)
110 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipFloatComplex,
double)
111 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipFloatComplex,
unsigned long)
112 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipFloatComplex,
signed long)
113 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipFloatComplex,
unsigned long long)
114 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipFloatComplex,
signed long long)
117 } __attribute__((aligned(8)));
123 __device__
__host__ hipDoubleComplex(
double x) : x(x), y(0.0f) {}
124 __device__
__host__ hipDoubleComplex(
double x,
double y) : x(x), y(y) {}
125 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipDoubleComplex,
unsigned short)
126 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipDoubleComplex,
signed short)
127 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipDoubleComplex,
unsigned int)
128 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipDoubleComplex,
signed int)
129 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipDoubleComplex,
float)
130 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipDoubleComplex,
unsigned long)
131 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipDoubleComplex,
signed long)
132 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipDoubleComplex,
unsigned long long)
133 MAKE_COMPONENT_CONSTRUCTOR_TWO_COMPONENT(hipDoubleComplex,
signed long long)
136 } __attribute__((aligned(16)));
203 return z.x * z.x + z.y * z.y;
207 return make_hipFloatComplex(p.x + q.x, p.y + q.y);
211 return make_hipFloatComplex(p.x - q.x, p.y - q.y);
215 return make_hipFloatComplex(p.x * q.x - p.y * q.y, p.y * q.x + p.x * q.y);
219 float sqabs = hipCsqabsf(q);
221 ret.x = (p.x * q.x + p.y * q.y)/sqabs;
222 ret.y = (p.y * q.x - p.x * q.y)/sqabs;
227 return sqrtf(hipCsqabsf(z));
255 return z.x * z.x + z.y * z.y;
259 return make_hipDoubleComplex(p.x + q.x, p.y + q.y);
263 return make_hipDoubleComplex(p.x - q.x, p.y - q.y);
267 return make_hipDoubleComplex(p.x * q.x - p.y * q.y, p.y * q.x + p.x * q.y);
271 double sqabs = hipCsqabs(q);
273 ret.x = (p.x * q.x + p.y * q.y)/sqabs;
274 ret.y = (p.y * q.x - p.x * q.y)/sqabs;
279 return sqrtf(hipCsqabs(z));
286 return make_hipFloatComplex(x, y);
291 return make_hipFloatComplex((
float)z.x, (
float)z.y);
296 return make_hipDoubleComplex((
double)z.x, (
double)z.y);
300 float real = (p.x * q.x) + r.x;
301 float imag = (q.x * p.y) + r.y;
303 real = -(p.y * q.y) + real;
304 imag = (p.x * q.y) + imag;
306 return make_hipComplex(real, imag);
310 float real = (p.x * q.x) + r.x;
311 float imag = (q.x * p.y) + r.y;
313 real = -(p.y * q.y) + real;
314 imag = (p.x * q.y) + imag;
316 return make_hipDoubleComplex(real, imag);
Definition: hip_complex.h:100
#define __host__
Definition: host_defines.h:41
Definition: hip_complex.h:119
Defines the different newt vector types for HIP runtime.