7#define STRCAT_INNER(a, b) a##b
8#define STRCAT(a, b) STRCAT_INNER(a, b)
11concept NUM = std::integral<X> || std::floating_point<X>;
15 CF
abs(
const CF &cf) {
16 auto i = cf.__get() > 0;
25 template<
typename T,
unsigned char BITS = sizeof(T) * 8,
unsigned char ALIGNMENT = alignof(T)>
requires std::is_floating_point_v<T>
31 std::uint64_t byte_data;
35 static_assert(
sizeof(T) * 8 >= BITS);
37 auto dataLocal = this->data;
39 U.byte_data = dataLocal << (
sizeof(T) * 8 - BITS);
40 auto float_data = U.float_data;
46 std::uint64_t byte_data;
50 U.float_data = float_data;
51 this->data = U.byte_data >> (
sizeof(T) * 8 - BITS);
67 this->__set((T) value);
71#define UNARY_PREFIX_OP(op) \
72 CompressedFloat &operator op() { \
73 auto f = this->__get(); \
82#define UNARY_POSTFIX_OP(op) \
83 const CompressedFloat operator op(std::int32_t) { \
84 auto oldThis = CompressedFloat(*this); \
85 this->operator op(); \
92 T operator -()
const {
93 return -this->__get();
96#undef UNARY_POSTFIX_OP
98#define ARITHMETIC_OP(op) \
100 CompressedFloat &operator STRCAT(op, =) (const X &scalar) { \
101 this->__set(this->__get() op scalar); \
106 T operator op (const X &scalar) const { \
107 return this->__get() op scalar; \
111 friend X& operator STRCAT(op, =) (X &scalar, const CompressedFloat cf) { \
112 scalar STRCAT(op, =) cf.__get(); \
117 friend X operator op (const X &scalar, const CompressedFloat cf) { \
118 return scalar op cf.__get(); \
128#define SELF_ARITHMETIC_OP(op) \
129 CompressedFloat &operator STRCAT(op, =) (const CompressedFloat &scalar) { \
130 this->__set(this->__get() op scalar.__get()); \
134 T operator op (const CompressedFloat &scalar) const { \
135 return this->__get() op scalar; \
143#undef SELF_ARITHMETIC_OP
145 bool operator !()
const {
149#define COMPARISON_OP(op) \
151 bool operator op (const X &scalar) const { \
152 return this->__get() op scalar; \
156 friend bool operator op (const X &scalar, const CompressedFloat &cf) { \
157 return scalar op cf.__get(); \
169#define SELF_COMPARISON_OP(op) \
170 bool operator op (const CompressedFloat &cf) const { \
171 return this->__get() op cf.__get(); \
181#undef SELF_COMPARISON_OP
185 return (X) this->__get();
#define SELF_ARITHMETIC_OP(op)
#define UNARY_PREFIX_OP(op)
#define ARITHMETIC_OP(op)
#define COMPARISON_OP(op)
#define UNARY_POSTFIX_OP(op)
#define SELF_COMPARISON_OP(op)
int __attribute__((optimize("O0"))) toolbox
CompressedFloat & operator=(const X &value)
CompressedFloat(const CompressedFloat ©)=default
CompressedFloat & operator=(const CompressedFloat &other)=default
CompressedFloat()=default
CompressedFloat(const T &value)
__attribute__((packed)) std T __get() const
Have to include this header, as I need access to the SYCL_EXTERNAL keyword.