aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/includes/hicn/transport/portability
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport/includes/hicn/transport/portability')
-rw-r--r--libtransport/includes/hicn/transport/portability/CMakeLists.txt5
-rw-r--r--libtransport/includes/hicn/transport/portability/c_portability.h2
-rw-r--r--libtransport/includes/hicn/transport/portability/cache.h87
-rw-r--r--libtransport/includes/hicn/transport/portability/cpu.h40
-rw-r--r--libtransport/includes/hicn/transport/portability/endianess.h86
-rw-r--r--libtransport/includes/hicn/transport/portability/portability.h7
-rw-r--r--libtransport/includes/hicn/transport/portability/win_portability.h86
7 files changed, 264 insertions, 49 deletions
diff --git a/libtransport/includes/hicn/transport/portability/CMakeLists.txt b/libtransport/includes/hicn/transport/portability/CMakeLists.txt
index 8094c0661..d29ec737c 100644
--- a/libtransport/includes/hicn/transport/portability/CMakeLists.txt
+++ b/libtransport/includes/hicn/transport/portability/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Copyright (c) 2021 Cisco and/or its affiliates.
# 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:
@@ -14,6 +14,9 @@
list(APPEND HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/c_portability.h
${CMAKE_CURRENT_SOURCE_DIR}/portability.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/cpu.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/cache.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/endianess.h
)
list(APPEND SOURCE_FILES
diff --git a/libtransport/includes/hicn/transport/portability/c_portability.h b/libtransport/includes/hicn/transport/portability/c_portability.h
index 2675de000..bc697d8b1 100644
--- a/libtransport/includes/hicn/transport/portability/c_portability.h
+++ b/libtransport/includes/hicn/transport/portability/c_portability.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 Cisco and/or its affiliates.
* Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/libtransport/includes/hicn/transport/portability/cache.h b/libtransport/includes/hicn/transport/portability/cache.h
new file mode 100644
index 000000000..ae113c7d6
--- /dev/null
+++ b/libtransport/includes/hicn/transport/portability/cache.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2022 Cisco and/or its affiliates.
+ *
+ * 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.
+ */
+
+#pragma once
+
+#include <hicn/transport/portability/platform.h>
+
+namespace transport {
+namespace portability {
+namespace cache {
+
+/**
+ * @Prefetch utilities
+ */
+
+/* Default cache line size of 64 bytes. */
+#ifndef LOG2_CACHE_LINE_BYTES
+static constexpr const std::size_t klog2_cache_line_bytes = 6;
+#else
+static constexpr const std::size_t klog2_cache_line_bytes =
+ LOG2_CACHE_LINE_BYTES;
+#endif
+
+/* How much data prefetch instruction prefetches */
+#ifndef LOG2_CACHE_PREFETCH_BYTES
+static constexpr const std::size_t klog2_cache_prefetch_bytes =
+ klog2_cache_line_bytes;
+#else
+static constexpr const std::size_t klog2_cache_prefetch_bytes =
+ LOG2_CACHE_PREFETCH_BYTES;
+#endif
+
+/* Default cache line fill buffers. */
+#ifndef N_PREFETCHES
+static constexpr const std::size_t kn_prefetches = 16;
+#else
+static constexpr const std::size_t kn_prefetches = N_PREFETCHES;
+#endif
+
+static constexpr const std::size_t kcache_line_bytes =
+ (1 << klog2_cache_line_bytes);
+static constexpr const std::size_t kcache_prefetch_bytes =
+ (1 << klog2_cache_prefetch_bytes);
+
+static constexpr const int READ = 0;
+static constexpr const int LOAD = 0; /* alias for read */
+static constexpr const int WRITE = 1;
+static constexpr const int STORE = 1; /* alias for write */
+
+#if defined(__GNUC__) || defined(__clang__)
+// Clang & GCC
+
+template <int type>
+static inline void _prefetch(uint8_t *addr, std::size_t n, std::size_t size) {
+ if (size > n * kcache_prefetch_bytes) {
+ __builtin_prefetch(addr + n * kcache_prefetch_bytes, type,
+ /* locality */ 3);
+ }
+}
+
+template <typename T, int type>
+static inline void prefetch(T *addr, std::size_t size) {
+ uint8_t *_addr = reinterpret_cast<uint8_t *>(addr);
+
+ _prefetch<type>(_addr, 0, size);
+ _prefetch<type>(_addr, 1, size);
+ _prefetch<type>(_addr, 2, size);
+ _prefetch<type>(_addr, 3, size);
+}
+#endif
+
+} // namespace cache
+} // namespace portability
+} // namespace transport \ No newline at end of file
diff --git a/libtransport/includes/hicn/transport/portability/cpu.h b/libtransport/includes/hicn/transport/portability/cpu.h
new file mode 100644
index 000000000..036bf9cd9
--- /dev/null
+++ b/libtransport/includes/hicn/transport/portability/cpu.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2022 Cisco and/or its affiliates.
+ *
+ * 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.
+ */
+
+#pragma once
+
+#if defined(__aarch64__) && defined(__ARM_NEON) || defined(__i686__)
+#define TRANSPORT_HAVE_VEC128
+#endif
+
+#if defined(__SSE4_2__) && __GNUC__ >= 4
+#define TRANSPORT_HAVE_VEC128
+#endif
+
+#if defined(__ALTIVEC__)
+#define TRANSPORT_HAVE_VEC128
+#endif
+
+#if defined(__AVX2__)
+#define TRANSPORT_HAVE_VEC256
+#if defined(__clang__) && __clang_major__ < 4
+#undef TRANSPORT_HAVE_VEC256
+#endif
+#endif
+
+#if defined(__AVX512BITALG__)
+#define TRANSPORT_HAVE_VEC512
+#endif
diff --git a/libtransport/includes/hicn/transport/portability/endianess.h b/libtransport/includes/hicn/transport/portability/endianess.h
new file mode 100644
index 000000000..c18ac82cf
--- /dev/null
+++ b/libtransport/includes/hicn/transport/portability/endianess.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2022 Cisco and/or its affiliates.
+ *
+ * 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.
+ */
+
+#pragma once
+
+#include <hicn/transport/errors/errors.h>
+
+namespace transport {
+namespace portability {
+
+#if (__BYTE_ORDER__) == (__ORDER_LITTLE_ENDIAN__)
+static constexpr const bool kIsBigEndian = false;
+static constexpr const bool kIsLittleEndian = true;
+#else
+static constexpr const bool kIsBigEndian = true;
+static constexpr const bool kIsLittleEndian = false;
+#endif
+
+template <typename T>
+inline T bswap(T value) {
+ throw errors::RuntimeException("Not implemented");
+}
+
+template <>
+inline int16_t bswap(int16_t value) {
+ return __builtin_bswap16(value);
+}
+
+template <>
+inline int32_t bswap(int32_t value) {
+ return __builtin_bswap32(value);
+}
+
+template <>
+inline int64_t bswap(int64_t value) {
+ return __builtin_bswap64(value);
+}
+
+template <>
+inline uint16_t bswap(uint16_t value) {
+ return __builtin_bswap16(value);
+}
+
+template <>
+inline uint32_t bswap(uint32_t value) {
+ return __builtin_bswap32(value);
+}
+
+template <>
+inline uint64_t bswap(uint64_t value) {
+ return __builtin_bswap64(value);
+}
+
+template <typename T>
+inline T host_to_net(T value) {
+ if constexpr (kIsLittleEndian) {
+ return bswap(value);
+ }
+
+ return value;
+}
+
+template <typename T>
+inline T net_to_host(T value) {
+ if constexpr (kIsLittleEndian) {
+ return bswap(value);
+ }
+
+ return value;
+}
+
+} // namespace portability
+} // namespace transport \ No newline at end of file
diff --git a/libtransport/includes/hicn/transport/portability/portability.h b/libtransport/includes/hicn/transport/portability/portability.h
index 24ef012f7..fd6eca4de 100644
--- a/libtransport/includes/hicn/transport/portability/portability.h
+++ b/libtransport/includes/hicn/transport/portability/portability.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 Cisco and/or its affiliates.
* Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,11 +26,9 @@
#include <cstddef>
+namespace transport {
namespace portability {
-constexpr bool little_endian_arch = __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__;
-constexpr bool big_endian_arch = !little_endian_arch;
-
// Generalize warning push/pop.
#if defined(__GNUC__) || defined(__clang__)
// Clang & GCC
@@ -69,3 +67,4 @@ constexpr bool big_endian_arch = !little_endian_arch;
#endif
} // namespace portability
+} // namespace transport \ No newline at end of file
diff --git a/libtransport/includes/hicn/transport/portability/win_portability.h b/libtransport/includes/hicn/transport/portability/win_portability.h
index 24c7a932a..81aa828cd 100644
--- a/libtransport/includes/hicn/transport/portability/win_portability.h
+++ b/libtransport/includes/hicn/transport/portability/win_portability.h
@@ -1,44 +1,44 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Copyright 2017 Facebook, 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.
- */
-
-#pragma once
-#define WIN32_LEAN_AND_MEAN
-#ifndef NOMINMAX
-#define NOMINMAX
-#endif
-#include <fcntl.h>
-#include <io.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <time.h>
-#include <windows.h>
-#include <winsock2.h>
-#include <ws2ipdef.h>
-#include <ws2tcpip.h>
-
-#include <algorithm>
-
-#define __ORDER_LITTLE_ENDIAN__ 0x41424344UL
-#define __ORDER_BIG_ENDIAN__ 0x44434241UL
-#define __BYTE_ORDER__ ('ABCD')
-#undef DELETE
-
-#define HAVE_STRUCT_TIMESPEC
+/*
+ * Copyright (c) 2021 Cisco and/or its affiliates.
+ * Copyright 2017 Facebook, 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.
+ */
+
+#pragma once
+#define WIN32_LEAN_AND_MEAN
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif
+#include <fcntl.h>
+#include <io.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <time.h>
+#include <windows.h>
+#include <winsock2.h>
+#include <ws2ipdef.h>
+#include <ws2tcpip.h>
+
+#include <algorithm>
+
+#define __ORDER_LITTLE_ENDIAN__ 0x41424344UL
+#define __ORDER_BIG_ENDIAN__ 0x44434241UL
+#define __BYTE_ORDER__ ('ABCD')
+#undef DELETE
+
+#define HAVE_STRUCT_TIMESPEC
#include <pthread.h> \ No newline at end of file