OmniSciDB  04ee39c94c
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  return std::numeric_limits<int64_t>::min() + 1;
52 #endif
53  }
54 }
55 
56 extern "C" DEVICE ALWAYS_INLINE int64_t
57 SUFFIX(fixed_width_unsigned_decode)(const int8_t* byte_stream,
58  const int32_t byte_width,
59  const int64_t pos) {
60 #ifdef WITH_DECODERS_BOUNDS_CHECKING
61  assert(pos >= 0);
62 #endif // WITH_DECODERS_BOUNDS_CHECKING
63  switch (byte_width) {
64  case 1:
65  return reinterpret_cast<const uint8_t*>(byte_stream)[pos * byte_width];
66  case 2:
67  return *(reinterpret_cast<const uint16_t*>(&byte_stream[pos * byte_width]));
68  case 4:
69  return *(reinterpret_cast<const uint32_t*>(&byte_stream[pos * byte_width]));
70  case 8:
71  return *(reinterpret_cast<const uint64_t*>(&byte_stream[pos * byte_width]));
72  default:
73 // TODO(alex)
74 #ifdef __CUDACC__
75  return -1;
76 #else
77  return std::numeric_limits<int64_t>::min() + 1;
78 #endif
79  }
80 }
81 
82 extern "C" DEVICE NEVER_INLINE int64_t
83 SUFFIX(fixed_width_int_decode_noinline)(const int8_t* byte_stream,
84  const int32_t byte_width,
85  const int64_t pos) {
86  return SUFFIX(fixed_width_int_decode)(byte_stream, byte_width, pos);
87 }
88 
89 extern "C" DEVICE NEVER_INLINE int64_t
90 SUFFIX(fixed_width_unsigned_decode_noinline)(const int8_t* byte_stream,
91  const int32_t byte_width,
92  const int64_t pos) {
93  return SUFFIX(fixed_width_unsigned_decode)(byte_stream, byte_width, pos);
94 }
95 
96 extern "C" DEVICE ALWAYS_INLINE int64_t
97 SUFFIX(diff_fixed_width_int_decode)(const int8_t* byte_stream,
98  const int32_t byte_width,
99  const int64_t baseline,
100  const int64_t pos) {
101  return SUFFIX(fixed_width_int_decode)(byte_stream, byte_width, pos) + baseline;
102 }
103 
104 extern "C" DEVICE ALWAYS_INLINE float SUFFIX(
105  fixed_width_float_decode)(const int8_t* byte_stream, const int64_t pos) {
106 #ifdef WITH_DECODERS_BOUNDS_CHECKING
107  assert(pos >= 0);
108 #endif // WITH_DECODERS_BOUNDS_CHECKING
109  return *(reinterpret_cast<const float*>(&byte_stream[pos * sizeof(float)]));
110 }
111 
112 extern "C" DEVICE NEVER_INLINE float SUFFIX(
113  fixed_width_float_decode_noinline)(const int8_t* byte_stream, const int64_t pos) {
114  return SUFFIX(fixed_width_float_decode)(byte_stream, pos);
115 }
116 
117 extern "C" DEVICE ALWAYS_INLINE double SUFFIX(
118  fixed_width_double_decode)(const int8_t* byte_stream, const int64_t pos) {
119 #ifdef WITH_DECODERS_BOUNDS_CHECKING
120  assert(pos >= 0);
121 #endif // WITH_DECODERS_BOUNDS_CHECKING
122  return *(reinterpret_cast<const double*>(&byte_stream[pos * sizeof(double)]));
123 }
124 
125 extern "C" DEVICE NEVER_INLINE double SUFFIX(
126  fixed_width_double_decode_noinline)(const int8_t* byte_stream, const int64_t pos) {
127  return SUFFIX(fixed_width_double_decode)(byte_stream, pos);
128 }
129 
130 extern "C" DEVICE ALWAYS_INLINE int64_t
131 SUFFIX(fixed_width_small_date_decode)(const int8_t* byte_stream,
132  const int32_t byte_width,
133  const int32_t null_val,
134  const int64_t ret_null_val,
135  const int64_t pos) {
136  auto val = SUFFIX(fixed_width_int_decode)(byte_stream, byte_width, pos);
137  return val == null_val ? ret_null_val : val * 86400;
138 }
139 
140 extern "C" DEVICE NEVER_INLINE int64_t
142  const int32_t byte_width,
143  const int32_t null_val,
144  const int64_t ret_null_val,
145  const int64_t pos) {
147  byte_stream, byte_width, null_val, ret_null_val, pos);
148 }
149 
150 #undef SUFFIX
151 
152 #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:83
#define SUFFIX(name)
DEVICE ALWAYS_INLINE double SUFFIX() fixed_width_double_decode(const int8_t *byte_stream, const int64_t pos)
Definition: DecodersImpl.h:118
#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:131
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:57
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:90
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:141
#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:113
DEVICE NEVER_INLINE double SUFFIX() fixed_width_double_decode_noinline(const int8_t *byte_stream, const int64_t pos)
Definition: DecodersImpl.h:126
#define ALWAYS_INLINE
DEVICE ALWAYS_INLINE float SUFFIX() fixed_width_float_decode(const int8_t *byte_stream, const int64_t pos)
Definition: DecodersImpl.h:105
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:97