OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DecodersImpl.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
23 #ifndef QUERYENGINE_DECODERSIMPL_H
24 #define QUERYENGINE_DECODERSIMPL_H
25 
26 #include <cstdint>
27 #include "../Shared/funcannotations.h"
28 #include "ExtractFromTime.h"
29 
30 extern "C" DEVICE ALWAYS_INLINE int64_t
31 SUFFIX(fixed_width_int_decode)(const int8_t* byte_stream,
32  const int32_t byte_width,
33  const int64_t pos) {
34 #ifdef WITH_DECODERS_BOUNDS_CHECKING
35  assert(pos >= 0);
36 #endif // WITH_DECODERS_BOUNDS_CHECKING
37  switch (byte_width) {
38  case 1:
39  return static_cast<int64_t>(byte_stream[pos * byte_width]);
40  case 2:
41  return *(reinterpret_cast<const int16_t*>(&byte_stream[pos * byte_width]));
42  case 4:
43  return *(reinterpret_cast<const int32_t*>(&byte_stream[pos * byte_width]));
44  case 8:
45  return *(reinterpret_cast<const int64_t*>(&byte_stream[pos * byte_width]));
46  default:
47 // TODO(alex)
48 #ifdef __CUDACC__
49  return -1;
50 #else
51 #ifdef _WIN32
52  return LLONG_MIN + 1;
53 #else
54  return std::numeric_limits<int64_t>::min() + 1;
55 #endif
56 #endif
57  }
58 }
59 
60 extern "C" DEVICE ALWAYS_INLINE int64_t
61 SUFFIX(fixed_width_unsigned_decode)(const int8_t* byte_stream,
62  const int32_t byte_width,
63  const int64_t pos) {
64 #ifdef WITH_DECODERS_BOUNDS_CHECKING
65  assert(pos >= 0);
66 #endif // WITH_DECODERS_BOUNDS_CHECKING
67  switch (byte_width) {
68  case 1:
69  return reinterpret_cast<const uint8_t*>(byte_stream)[pos * byte_width];
70  case 2:
71  return *(reinterpret_cast<const uint16_t*>(&byte_stream[pos * byte_width]));
72  case 4:
73  return *(reinterpret_cast<const uint32_t*>(&byte_stream[pos * byte_width]));
74  case 8:
75  return *(reinterpret_cast<const uint64_t*>(&byte_stream[pos * byte_width]));
76  default:
77 // TODO(alex)
78 #ifdef __CUDACC__
79  return -1;
80 #else
81 #ifdef _WIN32
82  return LLONG_MIN + 1;
83 #else
84  return std::numeric_limits<int64_t>::min() + 1;
85 #endif
86 #endif
87  }
88 }
89 
90 extern "C" DEVICE NEVER_INLINE int64_t
91 SUFFIX(fixed_width_int_decode_noinline)(const int8_t* byte_stream,
92  const int32_t byte_width,
93  const int64_t pos) {
94  return SUFFIX(fixed_width_int_decode)(byte_stream, byte_width, pos);
95 }
96 
97 extern "C" DEVICE NEVER_INLINE int64_t
98 SUFFIX(fixed_width_unsigned_decode_noinline)(const int8_t* byte_stream,
99  const int32_t byte_width,
100  const int64_t pos) {
101  return SUFFIX(fixed_width_unsigned_decode)(byte_stream, byte_width, pos);
102 }
103 
104 extern "C" DEVICE ALWAYS_INLINE int64_t
105 SUFFIX(diff_fixed_width_int_decode)(const int8_t* byte_stream,
106  const int32_t byte_width,
107  const int64_t baseline,
108  const int64_t pos) {
109  return SUFFIX(fixed_width_int_decode)(byte_stream, byte_width, pos) + baseline;
110 }
111 
112 extern "C" DEVICE ALWAYS_INLINE float SUFFIX(
113  fixed_width_float_decode)(const int8_t* byte_stream, const int64_t pos) {
114 #ifdef WITH_DECODERS_BOUNDS_CHECKING
115  assert(pos >= 0);
116 #endif // WITH_DECODERS_BOUNDS_CHECKING
117  return *(reinterpret_cast<const float*>(&byte_stream[pos * sizeof(float)]));
118 }
119 
120 extern "C" DEVICE NEVER_INLINE float SUFFIX(
121  fixed_width_float_decode_noinline)(const int8_t* byte_stream, const int64_t pos) {
122  return SUFFIX(fixed_width_float_decode)(byte_stream, pos);
123 }
124 
125 extern "C" DEVICE ALWAYS_INLINE double SUFFIX(
126  fixed_width_double_decode)(const int8_t* byte_stream, const int64_t pos) {
127 #ifdef WITH_DECODERS_BOUNDS_CHECKING
128  assert(pos >= 0);
129 #endif // WITH_DECODERS_BOUNDS_CHECKING
130  return *(reinterpret_cast<const double*>(&byte_stream[pos * sizeof(double)]));
131 }
132 
133 extern "C" DEVICE NEVER_INLINE double SUFFIX(
134  fixed_width_double_decode_noinline)(const int8_t* byte_stream, const int64_t pos) {
135  return SUFFIX(fixed_width_double_decode)(byte_stream, pos);
136 }
137 
138 extern "C" DEVICE ALWAYS_INLINE int64_t
139 SUFFIX(fixed_width_small_date_decode)(const int8_t* byte_stream,
140  const int32_t byte_width,
141  const int32_t null_val,
142  const int64_t ret_null_val,
143  const int64_t pos) {
144  auto val = SUFFIX(fixed_width_int_decode)(byte_stream, byte_width, pos);
145  return val == null_val ? ret_null_val : val * kSecsPerDay;
146 }
147 
148 extern "C" DEVICE NEVER_INLINE int64_t
150  const int32_t byte_width,
151  const int32_t null_val,
152  const int64_t ret_null_val,
153  const int64_t pos) {
155  byte_stream, byte_width, null_val, ret_null_val, pos);
156 }
157 
158 extern "C" DEVICE ALWAYS_INLINE int64_t
159 SUFFIX(fixed_width_date_encode)(const int64_t cur_col_val,
160  const int32_t ret_null_val,
161  const int64_t null_val) {
162  return cur_col_val == null_val ? ret_null_val : cur_col_val / kSecsPerDay;
163 }
164 
165 extern "C" DEVICE ALWAYS_INLINE int64_t
166 SUFFIX(fixed_width_date_decode)(const int64_t cur_col_val,
167  const int32_t ret_null_val,
168  const int64_t null_val) {
169  return cur_col_val == null_val ? ret_null_val : cur_col_val * kSecsPerDay;
170 }
171 
172 extern "C" DEVICE NEVER_INLINE int64_t
173 SUFFIX(fixed_width_date_encode_noinline)(const int64_t cur_col_val,
174  const int32_t ret_null_val,
175  const int64_t null_val) {
176  return SUFFIX(fixed_width_date_encode)(cur_col_val, ret_null_val, null_val);
177 }
178 
179 #undef SUFFIX
180 
181 #endif // QUERYENGINE_DECODERSIMPL_H
static constexpr int64_t kSecsPerDay
DEVICE ALWAYS_INLINE int64_t SUFFIX() fixed_width_int_decode(const int8_t *byte_stream, const int32_t byte_width, const int64_t pos)
Definition: DecodersImpl.h:31
DEVICE NEVER_INLINE int64_t SUFFIX() fixed_width_int_decode_noinline(const int8_t *byte_stream, const int32_t byte_width, const int64_t pos)
Definition: DecodersImpl.h:91
#define SUFFIX(name)
DEVICE ALWAYS_INLINE double SUFFIX() fixed_width_double_decode(const int8_t *byte_stream, const int64_t pos)
Definition: DecodersImpl.h:126
#define DEVICE
DEVICE ALWAYS_INLINE int64_t SUFFIX() fixed_width_small_date_decode(const int8_t *byte_stream, const int32_t byte_width, const int32_t null_val, const int64_t ret_null_val, const int64_t pos)
Definition: DecodersImpl.h:139
DEVICE ALWAYS_INLINE int64_t SUFFIX() fixed_width_unsigned_decode(const int8_t *byte_stream, const int32_t byte_width, const int64_t pos)
Definition: DecodersImpl.h:61
DEVICE NEVER_INLINE int64_t SUFFIX() fixed_width_unsigned_decode_noinline(const int8_t *byte_stream, const int32_t byte_width, const int64_t pos)
Definition: DecodersImpl.h:98
DEVICE ALWAYS_INLINE int64_t SUFFIX() fixed_width_date_decode(const int64_t cur_col_val, const int32_t ret_null_val, const int64_t null_val)
Definition: DecodersImpl.h:166
DEVICE NEVER_INLINE int64_t SUFFIX() fixed_width_small_date_decode_noinline(const int8_t *byte_stream, const int32_t byte_width, const int32_t null_val, const int64_t ret_null_val, const int64_t pos)
Definition: DecodersImpl.h:149
DEVICE ALWAYS_INLINE int64_t SUFFIX() fixed_width_date_encode(const int64_t cur_col_val, const int32_t ret_null_val, const int64_t null_val)
Definition: DecodersImpl.h:159
#define NEVER_INLINE
DEVICE NEVER_INLINE float SUFFIX() fixed_width_float_decode_noinline(const int8_t *byte_stream, const int64_t pos)
Definition: DecodersImpl.h:121
DEVICE NEVER_INLINE double SUFFIX() fixed_width_double_decode_noinline(const int8_t *byte_stream, const int64_t pos)
Definition: DecodersImpl.h:134
#define ALWAYS_INLINE
DEVICE ALWAYS_INLINE float SUFFIX() fixed_width_float_decode(const int8_t *byte_stream, const int64_t pos)
Definition: DecodersImpl.h:113
DEVICE NEVER_INLINE int64_t SUFFIX() fixed_width_date_encode_noinline(const int64_t cur_col_val, const int32_t ret_null_val, const int64_t null_val)
Definition: DecodersImpl.h:173
DEVICE ALWAYS_INLINE int64_t SUFFIX() diff_fixed_width_int_decode(const int8_t *byte_stream, const int32_t byte_width, const int64_t baseline, const int64_t pos)
Definition: DecodersImpl.h:105