forked from heavyai/heavydb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecodersImpl.h
More file actions
113 lines (99 loc) · 4.7 KB
/
DecodersImpl.h
File metadata and controls
113 lines (99 loc) · 4.7 KB
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
/*
* Copyright 2017 MapD Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @file DecodersImpl.h
* @author Alex Suhan <alex@mapd.com>
*
* Copyright (c) 2015 MapD Technologies, Inc. All rights reserved.
*/
#ifndef QUERYENGINE_DECODERSIMPL_H
#define QUERYENGINE_DECODERSIMPL_H
#include "../Shared/funcannotations.h"
#include <stdint.h>
extern "C" DEVICE ALWAYS_INLINE int64_t SUFFIX(fixed_width_int_decode)(const int8_t* byte_stream,
const int32_t byte_width,
const int64_t pos) {
switch (byte_width) {
case 1:
return static_cast<int64_t>(byte_stream[pos * byte_width]);
case 2:
return *(reinterpret_cast<const int16_t*>(&byte_stream[pos * byte_width]));
case 4:
return *(reinterpret_cast<const int32_t*>(&byte_stream[pos * byte_width]));
case 8:
return *(reinterpret_cast<const int64_t*>(&byte_stream[pos * byte_width]));
default:
// TODO(alex)
#ifdef __CUDACC__
return -1;
#else
return std::numeric_limits<int64_t>::min() + 1;
#endif
}
}
extern "C" DEVICE ALWAYS_INLINE int64_t SUFFIX(fixed_width_unsigned_decode)(const int8_t* byte_stream,
const int32_t byte_width,
const int64_t pos) {
switch (byte_width) {
case 1:
return reinterpret_cast<const uint8_t*>(byte_stream)[pos * byte_width];
case 2:
return *(reinterpret_cast<const uint16_t*>(&byte_stream[pos * byte_width]));
case 4:
return *(reinterpret_cast<const uint32_t*>(&byte_stream[pos * byte_width]));
case 8:
return *(reinterpret_cast<const uint64_t*>(&byte_stream[pos * byte_width]));
default:
// TODO(alex)
#ifdef __CUDACC__
return -1;
#else
return std::numeric_limits<int64_t>::min() + 1;
#endif
}
}
extern "C" 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) {
return SUFFIX(fixed_width_int_decode)(byte_stream, byte_width, pos);
}
extern "C" 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) {
return SUFFIX(fixed_width_unsigned_decode)(byte_stream, byte_width, pos);
}
extern "C" 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) {
return SUFFIX(fixed_width_int_decode)(byte_stream, byte_width, pos) + baseline;
}
extern "C" DEVICE ALWAYS_INLINE float SUFFIX(fixed_width_float_decode)(const int8_t* byte_stream, const int64_t pos) {
return *(reinterpret_cast<const float*>(&byte_stream[pos * sizeof(float)]));
}
extern "C" DEVICE NEVER_INLINE float SUFFIX(fixed_width_float_decode_noinline)(const int8_t* byte_stream,
const int64_t pos) {
return SUFFIX(fixed_width_float_decode)(byte_stream, pos);
}
extern "C" DEVICE ALWAYS_INLINE double SUFFIX(fixed_width_double_decode)(const int8_t* byte_stream, const int64_t pos) {
return *(reinterpret_cast<const double*>(&byte_stream[pos * sizeof(double)]));
}
extern "C" DEVICE NEVER_INLINE double SUFFIX(fixed_width_double_decode_noinline)(const int8_t* byte_stream,
const int64_t pos) {
return SUFFIX(fixed_width_double_decode)(byte_stream, pos);
}
#undef SUFFIX
#endif // QUERYENGINE_DECODERSIMPL_H