summaryrefslogtreecommitdiffstats
path: root/floattypes.h
blob: 426b23abe441e70dc254074430fc7b6f6ea9c6a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// -*-C++-*-

#ifndef FLOATTYPES_H
#define FLOATTYPES_H

#ifndef VML_BROKEN_STL

// The STL works fine
#include <cstdint>

#else

// The STL has problems with C++11 features

#include <stdint.h>
namespace std {
  typedef unsigned char uint8_t;
  typedef signed char int8_t;
  typedef unsigned short uint16_t;
  typedef short int16_t;
  typedef unsigned int uint32_t;
  typedef int int32_t;
  typedef unsigned long long uint64_t;
  typedef long long int64_t;
}

#include <cstdlib>
#define static_assert(x,y)
#define __builtin_unreachable() (assert(0))

#include <math.h>
namespace std {
  template<typename T> int my_signbit(T x) { return signbit(x); }
#undef signbit
  
  float asinh(float x) { return ::asinh(x); }
  float acosh(float x) { return ::acosh(x); }
  float atanh(float x) { return ::atanh(x); }
  float cbrt(float x) { return ::cbrtf(x); }
  // float ceil(float x) { return ::ceilf(x); }
  float copysign(float x, float y) { return ::copysignf(x, y); }
  float exp2(float x) { return ::exp2f(x); }
  float expm1(float x) { return ::expm1f(x); }
  float fdim(float x, float y) { return ::fdimf(x, y); }
  // float floor(float x) { return ::floorf(x); }
  float fma(float x, float y, float z) { return ::fmaf(x, y, z); }
  float fmax(float x, float y) { return ::fmaxf(x, y); }
  float fmin(float x, float y) { return ::fminf(x, y); }
  float frexp(float x, int* r) { return ::frexp(x, r); }
  float hypot(float x, float y) { return ::hypotf(x, y); }
  int ilogb(float x) { return ::ilogbf(x); }
  float log1p(float x) { return ::log1pf(x); }
  float log2(float x) { return ::log2f(x); }
  float nextafter(float x, float y) { return ::nextafterf(x, y); }
  float remainder(float x, float y) { return ::remainderf(x, y); }
  float rint(float x) { return ::rintf(x); }
  float round(float x) { return ::roundf(x); }
  bool signbit(float x) { return my_signbit(x); }
  float trunc(float x) { return ::truncf(x); }
  
  double asinh(double x) { return ::asinh(x); }
  double acosh(double x) { return ::acosh(x); }
  double atanh(double x) { return ::atanh(x); }
  double cbrt(double x) { return ::cbrt(x); }
  // double ceil(double x) { return ::ceil(x); }
  double copysign(double x, double y) { return ::copysign(x, y); }
  double exp2(double x) { return ::exp2(x); }
  double expm1(double x) { return ::expm1(x); }
  double fdim(double x, double y) { return ::fdim(x, y); }
  // double floor(double x) { return ::floor(x); }
  double fma(double x, double y, double z) { return ::fma(x, y, z); }
  double fmax(double x, double y) { return ::fmax(x, y); }
  double fmin(double x, double y) { return ::fmin(x, y); }
  double frexp(double x, int* r) { return ::frexp(x, r); }
  double hypot(double x, double y) { return ::hypot(x, y); }
  int ilogb(double x) { return ::ilogb(x); }
  double log1p(double x) { return ::log1p(x); }
  double log2(double x) { return ::log2(x); }
  double nextafter(double x, double y) { return ::nextafter(x, y); }
  double remainder(double x, double y) { return ::remainder(x, y); }
  double rint(double x) { return ::rint(x); }
  double round(double x) { return ::round(x); }
  bool signbit(double x) { return my_signbit(x); }
  double trunc(double x) { return ::trunc(x); }
}

#endif



namespace vecmathlib {
  
  struct fp8 {
    // 1 bit sign, 4 bits exponent, 3 bits mantissa
    std::uint8_t val;
  };
  
  struct fp16 {
    // 1 bit sign, 5 bits exponent, 10 bits mantissa
    std::uint16_t val;
  };
  
} // namespace vecmathlib

#endif  // #ifndef FLOATTYPES_H
OpenPOWER on IntegriCloud