Skip to content

Commit

Permalink
Interop improvements: remove include dirs, add macro prefixes, shorte…
Browse files Browse the repository at this point in the history
…r bswap name, remove crpc
  • Loading branch information
jan-wassenberg committed Nov 4, 2016
1 parent b3fc3a3 commit 44f30a2
Show file tree
Hide file tree
Showing 32 changed files with 498 additions and 560 deletions.
16 changes: 0 additions & 16 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ cc_library(
hdrs = [
"highwayhash/code_annotation.h",
],
includes = ["."],
visibility = ["//visibility:public"],
)

Expand All @@ -18,7 +17,6 @@ cc_library(
hdrs = [
"highwayhash/arch_specific.h",
],
includes = ["."],
visibility = ["//visibility:public"],
)

Expand All @@ -29,7 +27,6 @@ cc_library(
"highwayhash/vec.h",
"highwayhash/vec2.h",
],
includes = ["."],
visibility = ["//visibility:public"],
deps = [
":code_annotation",
Expand All @@ -54,7 +51,6 @@ cc_library(
hdrs = [
"highwayhash/os_specific.h",
],
includes = ["."],
visibility = ["//visibility:public"],
deps = [
":code_annotation",
Expand All @@ -66,7 +62,6 @@ cc_library(
hdrs = [
"highwayhash/tsc_timer.h",
],
includes = ["."],
visibility = ["//visibility:public"],
deps = [
":code_annotation",
Expand All @@ -79,7 +74,6 @@ cc_library(
hdrs = [
"highwayhash/profiler.h",
],
includes = ["."],
visibility = ["//visibility:public"],
deps = [
":code_annotation",
Expand All @@ -101,7 +95,6 @@ cc_library(
hdrs = [
"highwayhash/nanobenchmark.h",
],
includes = ["."],
visibility = ["//visibility:public"],
deps = [
":arch_specific",
Expand All @@ -116,7 +109,6 @@ cc_binary(
srcs = [
"highwayhash/nanobenchmark_example.cc",
],
includes = ["."],
deps = [
":nanobenchmark",
":os_specific",
Expand All @@ -128,7 +120,6 @@ cc_library(
hdrs = [
"highwayhash/data_parallel.h",
],
includes = ["."],
visibility = ["//visibility:public"],
)

Expand Down Expand Up @@ -169,7 +160,6 @@ cc_library(
"highwayhash/state_helpers.h",
"highwayhash/types.h",
],
includes = ["."],
visibility = ["//visibility:public"],
deps = [
":code_annotation",
Expand All @@ -180,7 +170,6 @@ cc_library(
name = "sip_tree_hash",
srcs = ["highwayhash/sip_tree_hash.cc"],
hdrs = ["highwayhash/sip_tree_hash.h"],
includes = ["."],
visibility = ["//visibility:public"],
deps = [
":code_annotation",
Expand All @@ -193,7 +182,6 @@ cc_library(
name = "scalar_sip_tree_hash",
srcs = ["highwayhash/scalar_sip_tree_hash.cc"],
hdrs = ["highwayhash/scalar_sip_tree_hash.h"],
includes = ["."],
deps = [
":code_annotation",
":sip_hash",
Expand All @@ -208,7 +196,6 @@ cc_library(
"highwayhash/highway_tree_hash.h",
"highwayhash/state_helpers.h",
],
includes = ["."],
visibility = ["//visibility:public"],
deps = [
":code_annotation",
Expand All @@ -223,7 +210,6 @@ cc_library(
"highwayhash/sse41_highway_tree_hash.h",
"highwayhash/state_helpers.h",
],
includes = ["."],
deps = [
":code_annotation",
":vector",
Expand All @@ -237,7 +223,6 @@ cc_library(
"highwayhash/scalar_highway_tree_hash.h",
"highwayhash/state_helpers.h",
],
includes = ["."],
deps = [
":code_annotation",
":vector",
Expand Down Expand Up @@ -266,7 +251,6 @@ cc_binary(
srcs = [
"highwayhash/sip_hash_main.cc",
],
includes = ["."],
deps = [
":highway_tree_hash",
":nanobenchmark",
Expand Down
8 changes: 4 additions & 4 deletions highwayhash/arch_specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#endif

#ifdef _MSC_VER
#define HIGHWAYHASH_BSWAP32(x) _byteswap_ulong(x)
#define HIGHWAYHASH_BSWAP64(x) _byteswap_uint64(x)
#define HH_BSWAP32(x) _byteswap_ulong(x)
#define HH_BSWAP64(x) _byteswap_uint64(x)
#else
#define HIGHWAYHASH_BSWAP32(x) __builtin_bswap32(x)
#define HIGHWAYHASH_BSWAP64(x) __builtin_bswap64(x)
#define HH_BSWAP32(x) __builtin_bswap32(x)
#define HH_BSWAP64(x) __builtin_bswap64(x)
#endif

#endif // HIGHWAYHASH_HIGHWAYHASH_ARCH_SPECIFIC_H_
2 changes: 1 addition & 1 deletion highwayhash/c_bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// C-callable function prototypes, documented in the other header files.

#include "highwayhash/types.h"
#include "third_party/highwayhash/highwayhash/types.h"

uint64 SipHashC(const uint64* key, const char* bytes, const uint64 size);

Expand Down
103 changes: 31 additions & 72 deletions highwayhash/code_annotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,111 +22,70 @@
// #ifdef COMPILER_MSVC, so we cannot use that same name.

#ifdef _MSC_VER
#define MSC_VERSION _MSC_VER
#define HH_MSC_VERSION _MSC_VER
#else
#define MSC_VERSION 0
#define HH_MSC_VERSION 0
#endif

#ifdef __GNUC__
#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
#define HH_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
#else
#define GCC_VERSION 0
#define HH_GCC_VERSION 0
#endif

#ifdef __clang__
#define CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
#define HH_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
#else
#define CLANG_VERSION 0
#define HH_CLANG_VERSION 0
#endif

//-----------------------------------------------------------------------------

#define NONCOPYABLE(className) \
className(const className&) = delete; \
const className& operator=(const className&) = delete;

#if MSC_VERSION
#define RESTRICT __restrict
#elif GCC_VERSION
#define RESTRICT __restrict__
#if HH_GCC_VERSION && HH_GCC_VERSION < 408
#define HH_ALIGNAS(multiple) __attribute__((aligned(multiple)))
#else
#define RESTRICT
#endif

#ifdef __cplusplus

// Pointer to const
template <typename T>
using crpc = const T* const RESTRICT;

// Pointer to non-const
template <typename T>
using crp = T* const RESTRICT;

#define HH_ALIGNAS(multiple) alignas(multiple) // C++11
#endif

#if MSC_VERSION
#define INLINE __forceinline
#define NOINLINE __declspec(noinline)
#if HH_MSC_VERSION
#define HH_RESTRICT __restrict
#elif HH_GCC_VERSION
#define HH_RESTRICT __restrict__
#else
#define INLINE inline
#define NOINLINE __attribute__((noinline))
#define HH_RESTRICT
#endif

#if MSC_VERSION
#define NORETURN __declspec(noreturn)
#elif GCC_VERSION
#define NORETURN __attribute__((noreturn))
#if HH_MSC_VERSION
#define HH_INLINE __forceinline
#define HH_NOINLINE __declspec(noinline)
#else
#define HH_INLINE inline
#define HH_NOINLINE __attribute__((noinline))
#endif

#if MSC_VERSION
#if HH_MSC_VERSION
// Unsupported, __assume is not the same.
#define UNLIKELY(expr) expr
#define HH_UNLIKELY(expr) expr
#else
#define UNLIKELY(expr) __builtin_expect(!!(expr), 0)
#define HH_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
#endif

#if MSC_VERSION
#if HH_MSC_VERSION
#include <intrin.h>
#pragma intrinsic(_ReadWriteBarrier)
#define COMPILER_FENCE _ReadWriteBarrier()
#elif GCC_VERSION
#define COMPILER_FENCE asm volatile("" : : : "memory")
#define HH_COMPILER_FENCE _ReadWriteBarrier()
#elif HH_GCC_VERSION
#define HH_COMPILER_FENCE asm volatile("" : : : "memory")
#else
#define COMPILER_FENCE
#define HH_COMPILER_FENCE
#endif

// Informs the compiler that the preceding function returns a pointer with the
// specified alignment. This may improve code generation.
#if MSC_VERSION
#define CACHE_ALIGNED_RETURN /* not supported */
#if HH_MSC_VERSION
#define HH_CACHE_ALIGNED_RETURN /* not supported */
#else
#define CACHE_ALIGNED_RETURN __attribute__((assume_aligned(64)))
#define HH_CACHE_ALIGNED_RETURN __attribute__((assume_aligned(64)))
#endif

#if MSC_VERSION
#define DEBUG_BREAK __debugbreak()
#elif CLANG_VERSION
#define DEBUG_BREAK __builtin_debugger()
#elif GCC_VERSION
#define DEBUG_BREAK __builtin_trap()
#endif

#if MSC_VERSION
#include <sal.h>
#define FORMAT_STRING(s) _Printf_format_string_ s
#else
#define FORMAT_STRING(s) s
#endif

// decltype(T)::x cannot be used directly when T is a reference type, so
// we need to remove the reference first.
#define TYPE(T) std::remove_reference<decltype(T)>::type

#define CONCAT2(a, b) a##b
#define CONCAT(a, b) CONCAT2(a, b)

// Generates a unique lvalue name.
#define UNIQUE(prefix) CONCAT(prefix, __LINE__)

#endif // #ifndef HIGHWAYHASH_HIGHWAYHASH_CODE_ANNOTATION_H_
4 changes: 2 additions & 2 deletions highwayhash/data_parallel_benchmark.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <future> //NOLINT
#include <cmath>
#include <cstdio>
#include <future> //NOLINT
#include <set>
#include "highwayhash/data_parallel.h"
#include "testing/base/public/gunit.h"
#include "third_party/highwayhash/highwayhash/data_parallel.h"
#include "thread/threadpool.h"

#if defined(_M_X64) || defined(__x86_64) || defined(__amd64) || \
Expand Down
2 changes: 1 addition & 1 deletion highwayhash/data_parallel_test.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <unistd.h>
#include <cstdint>

#include "highwayhash/data_parallel.h"
#include "testing/base/public/gunit.h"
#include "third_party/highwayhash/highwayhash/data_parallel.h"

namespace data_parallel {
namespace {
Expand Down
2 changes: 1 addition & 1 deletion highwayhash/highway_tree_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "highwayhash/highway_tree_hash.h"
#include "third_party/highwayhash/highwayhash/highway_tree_hash.h"

#ifdef __AVX2__

Expand Down

0 comments on commit 44f30a2

Please sign in to comment.