-
Notifications
You must be signed in to change notification settings - Fork 4
/
p3a_quantity.hpp
174 lines (146 loc) · 4.13 KB
/
p3a_quantity.hpp
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#pragma once
#include "p3a_scalar.hpp"
#include "p3a_constants.hpp"
#include "kul.hpp"
#include "p3a_simd.hpp"
namespace p3a {
// unit types
using kul::reciprocal;
using kul::second;
using kul::meter;
using kul::cubic_meter;
using kul::kilogram;
using kul::kelvin;
using kul::pascal;
using kul::gigapascal;
using kul::joule;
using kul::watt;
using kul::kilogram_per_cubic_meter;
using kul::joule_per_kilogram;
using kul::joule_per_kilogram_per_kelvin;
using kul::siemens;
using kul::siemens_per_meter;
using kul::quantity;
using kul::unitless;
// quantity alias templates
using kul::seconds;
using kul::reciprocal_seconds;
using kul::meters;
using kul::reciprocal_meters;
using kul::square_meters;
using kul::cubic_meters;
using kul::kilograms;
using kul::meters_per_second;
using kul::meters_per_second_squared;
using kul::kelvins;
using kul::amperes;
using kul::pascals;
using kul::gigapascals;
using kul::joules;
using kul::watts;
using kul::newtons;
using kul::kilograms_per_cubic_meter;
using kul::kilogram_meters_per_second;
using kul::grams_per_cubic_centimeter;
using kul::joules_per_cubic_meter;
using kul::joules_per_kilogram;
using kul::joules_per_kilogram_per_kelvin;
using kul::megajoules_per_kilogram;
using kul::volts;
using kul::ohms;
using kul::siemens_quantity;
using kul::farads;
using kul::henries;
using kul::siemens_per_meter_quantity;
using kul::temperature_electronvolts;
using kul::gaussian_conductivity;
using kul::pascal_seconds;
template <class A, class B>
using unit_divide = kul::divide<A, B>;
namespace quantity_literals = kul::literals;
using kul::abs;
using kul::min;
using kul::max;
using kul::pow;
using kul::exp;
using kul::log;
using kul::sqrt;
using kul::cbrt;
using kul::sin;
using kul::cos;
using kul::asin;
using kul::acos;
namespace details {
template <class T, class Unit>
struct is_scalar<quantity<T, Unit>> {
inline static constexpr bool value = true;
};
}
namespace constants {
template <class T, class Unit>
struct epsilon<quantity<T, Unit>> {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
quantity<T, Unit> value() { return quantity<T, Unit>(epsilon_value<T>()); }
};
template <class T, class Unit>
struct zero<quantity<T, Unit>> {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
quantity<T, Unit> value() { return quantity<T, Unit>(zero_value<T>()); }
};
template <class T, class Unit>
struct maximum<quantity<T, Unit>> {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
quantity<T, Unit> value() { return quantity<T, Unit>(maximum_value<T>()); }
};
template <class T, class Unit>
struct minimum<quantity<T, Unit>> {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
quantity<T, Unit> value() { return quantity<T, Unit>(minimum_value<T>()); }
};
}
template <class M, class T, class Unit,
std::enable_if_t<!std::is_same_v<M, bool>, bool> = false>
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline
auto condition(M const& mask, quantity<T, Unit> const& a, quantity<T, Unit> const& b)
{
return quantity<T, Unit>(condition(mask, a.value(), b.value()));
}
template <class T, class Unit, class Abi>
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline
auto load(
quantity<T, Unit> const* ptr,
int offset,
simd_mask<T, Abi> const& mask)
{
return quantity<simd<T, Abi>, Unit>(load(&(ptr->value()), offset, mask));
}
template <class T, class Unit, class Abi>
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline
void store(
quantity<simd<T, Abi>, Unit> const& q,
quantity<T, Unit>* ptr,
int offset,
simd_mask<T, Abi> const& mask)
{
store(q.value(), &(ptr->value()), offset, mask);
}
template <class T, class Unit, class Abi, class Integral>
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline
auto load(
quantity<T, Unit> const* ptr,
simd<Integral, Abi> const& offset,
simd_mask<T, Abi> const& mask)
{
return quantity<simd<T, Abi>, Unit>(load(&(ptr->value()), offset, mask));
}
template <class T, class Unit, class Abi, class Integral>
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline
void store(
quantity<simd<T, Abi>, Unit> const& q,
quantity<T, Unit>* ptr,
simd<Integral, Abi> const& offset,
simd_mask<T, Abi> const& mask)
{
store(q.value(), &(ptr->value()), offset, mask);
}
}