OmniSciDB  6686921089
 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 2017 MapD Technologies, 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 
17 /*
18  * @file DecodersImpl.h
19  * @author Alex Suhan <alex@mapd.com>
20  *
21  * Copyright (c) 2015 MapD Technologies, Inc. All rights reserved.
22  */
23 
24 #ifndef QUERYENGINE_DECODERSIMPL_H
25 #define QUERYENGINE_DECODERSIMPL_H
26 
27 #include <cstdint>
28 #include "../Shared/funcannotations.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 * 86400;
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 #undef SUFFIX
159 
160 #endif // QUERYENGINE_DECODERSIMPL_H
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 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
#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 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