summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authornagendra modadugu <ngm@google.com>2016-04-22 14:35:07 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-04-22 20:40:03 -0700
commit28827163c57390278a54ee10153c064cd6c18133 (patch)
tree9fd5a8c0ebce27fa47914e394074f8ba76e598ab /builtin
parente54d1284ffbd1d7c3b1f77a2a696ce275c527de4 (diff)
downloadchrome-ec-28827163c57390278a54ee10153c064cd6c18133.tar.gz
Move include/byteorder.h -> builtin/endian.h
Move endian routines to builtin/ so that portable third_party code may build without glibc. BRANCH=none BUG=chrome-os-partner:43025,chrome-os-partner:47524 TEST=none Change-Id: Icb900d1e9c56dc68ec1ef4b536ebc9dcf6ebcd69 Signed-off-by: nagendra modadugu <ngm@google.com> Reviewed-on: https://chromium-review.googlesource.com/340432 Commit-Ready: Nagendra Modadugu <ngm@google.com> Tested-by: Nagendra Modadugu <ngm@google.com> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/endian.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/builtin/endian.h b/builtin/endian.h
new file mode 100644
index 0000000000..b27b7cd496
--- /dev/null
+++ b/builtin/endian.h
@@ -0,0 +1,38 @@
+/* Copyright 2016 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef __EC_BUILTIN_ENDIAN_H
+#define __EC_BUILTIN_ENDIAN_H
+
+#include <stdint.h>
+
+/*
+ * Functions to convert byte order in various sized big endian integers to
+ * host byte order. Note that the code currently does not require functions
+ * for converting little endian integers.
+ */
+#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+
+static inline uint16_t be16toh(uint16_t in)
+{
+ return __builtin_bswap16(in);
+}
+static inline uint32_t be32toh(uint32_t in)
+{
+ return __builtin_bswap32(in);
+}
+static inline uint64_t be64toh(uint64_t in)
+{
+ return __builtin_bswap64(in);
+}
+
+#define htobe16 be16toh
+#define htobe32 be32toh
+#define htobe64 be64toh
+
+#endif /* __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ */
+
+
+#endif /* __EC_BUILTIN_ENDIAN_H */