aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/ignite
diff options
context:
space:
mode:
authorGravatar Anton Dmitriev <dmitrievanthony@gmail.com>2018-09-13 11:24:37 +0300
committerGravatar Anton Dmitriev <dmitrievanthony@gmail.com>2018-09-13 11:24:37 +0300
commitce9b23070638094022036656e5d1fbf3e23b74c6 (patch)
tree0865dc4d352c4b80d73f4072f2b8f06ef77da703 /tensorflow/contrib/ignite
parent9ec9c8b24cca5f1e746fef8cd351b3cae6d5a740 (diff)
Add forgotten ignite_byte_swapper.h
Diffstat (limited to 'tensorflow/contrib/ignite')
-rw-r--r--tensorflow/contrib/ignite/kernels/ignite_byte_swapper.h129
1 files changed, 129 insertions, 0 deletions
diff --git a/tensorflow/contrib/ignite/kernels/ignite_byte_swapper.h b/tensorflow/contrib/ignite/kernels/ignite_byte_swapper.h
new file mode 100644
index 0000000000..986bedcf69
--- /dev/null
+++ b/tensorflow/contrib/ignite/kernels/ignite_byte_swapper.h
@@ -0,0 +1,129 @@
+/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
+
+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.
+==============================================================================*/
+
+#ifndef TENSORFLOW_CONTRIB_IGNITE_KERNELS_IGNITE_BYTE_SWAPPER_H_
+#define TENSORFLOW_CONTRIB_IGNITE_KERNELS_IGNITE_BYTE_SWAPPER_H_
+
+#include <stdint.h>
+
+namespace tensorflow {
+
+class ByteSwapper {
+ public:
+ ByteSwapper(bool big_endian) {
+ int x = 1;
+ bool is_little_endian = (*(char *)&x == 1);
+ swap_ = big_endian == is_little_endian;
+ }
+
+ inline void SwapIfRequiredInt16(int16_t *x) const {
+ if (swap_) {
+ Swap16(x);
+ }
+ }
+
+ inline void SwapIfRequiredUnsignedInt16(uint16_t *x) const {
+ if (swap_) {
+ Swap16(reinterpret_cast<int16_t*>(x));
+ }
+ }
+
+ inline void SwapIfRequiredInt32(int32_t *x) const {
+ if (swap_) {
+ Swap32(x);
+ }
+ }
+
+ inline void SwapIfRequiredFloat(float *x) const {
+ if (swap_) {
+ Swap32(reinterpret_cast<int32_t*>(x));
+ }
+ }
+
+ inline void SwapIfRequiredInt64(int64_t *x) const {
+ if (swap_) {
+ Swap64(x);
+ }
+ }
+
+ inline void SwapIfRequiredDouble(double *x) const {
+ if (swap_) {
+ Swap64(reinterpret_cast<int64_t*>(x));
+ }
+ }
+
+ inline void SwapIfRequiredInt16Arr(int16_t *x, int32_t length) const {
+ if (swap_) {
+ for (int32_t i = 0; i < length; i++) Swap16(&x[i]);
+ }
+ }
+
+ inline void SwapIfRequiredUnsignedInt16Arr(uint16_t *x,
+ int32_t length) const {
+ if (swap_) {
+ for (int32_t i = 0; i < length; i++)
+ Swap16(reinterpret_cast<int16_t*>(&x[i]));
+ }
+ }
+
+ inline void SwapIfRequiredInt32Arr(int32_t *x, int32_t length) const {
+ if (swap_) {
+ for (int32_t i = 0; i < length; i++) Swap32(&x[i]);
+ }
+ }
+
+ inline void SwapIfRequiredFloatArr(float *x, int32_t length) const {
+ if (swap_) {
+ for (int32_t i = 0; i < length; i++)
+ Swap32(reinterpret_cast<int32_t*>(&x[i]));
+ }
+ }
+
+ inline void SwapIfRequiredInt64Arr(int64_t *x, int32_t length) const {
+ if (swap_) {
+ for (int32_t i = 0; i < length; i++) Swap64(&x[i]);
+ }
+ }
+
+ inline void SwapIfRequiredDoubleArr(double *x, int32_t length) const {
+ if (swap_) {
+ for (int32_t i = 0; i < length; i++)
+ Swap64(reinterpret_cast<int64_t*>(&x[i]));
+ }
+ }
+
+ private:
+ inline void Swap16(int16_t *x) const {
+ *x = ((*x & 0xFF) << 8) | ((*x >> 8) & 0xFF);
+ }
+
+ inline void Swap32(int32_t *x) const {
+ *x = ((*x & 0xFF) << 24) | (((*x >> 8) & 0xFF) << 16) |
+ (((*x >> 16) & 0xFF) << 8) | ((*x >> 24) & 0xFF);
+ }
+
+ inline void Swap64(int64_t *x) const {
+ *x = ((*x & 0xFF) << 56) | (((*x >> 8) & 0xFF) << 48) |
+ (((*x >> 16) & 0xFF) << 40) | (((*x >> 24) & 0xFF) << 32) |
+ (((*x >> 32) & 0xFF) << 24) | (((*x >> 40) & 0xFF) << 16) |
+ (((*x >> 48) & 0xFF) << 8) | ((*x >> 56) & 0xFF);
+ }
+
+ bool swap_;
+};
+
+} // namespace tensorflow
+
+#endif // TENSORFLOW_CONTRIB_IGNITE_KERNELS_IGNITE_BYTE_SWAPPER_H_