Fix altivec defines, reduce dependencies (#66)
diff --git a/highwayhash/hh_vsx.h b/highwayhash/hh_vsx.h index 1e32cfe..578caa7 100644 --- a/highwayhash/hh_vsx.h +++ b/highwayhash/hh_vsx.h
@@ -30,13 +30,15 @@ #ifndef HH_DISABLE_TARGET_SPECIFIC #include <altivec.h> -#include <string> +#undef vector +#undef pixel +#undef bool namespace highwayhash { -typedef vector unsigned long long PPC_VEC_U64; // NOLINT -typedef vector unsigned int PPC_VEC_U32; -typedef vector unsigned char PPC_VEC_U8; +typedef __vector unsigned long long PPC_VEC_U64; // NOLINT +typedef __vector unsigned int PPC_VEC_U32; +typedef __vector unsigned char PPC_VEC_U8; // See vector128.h for why this namespace is necessary; namespace HH_TARGET_NAME { @@ -186,7 +188,9 @@ } static HH_INLINE void ZeroInitialize(char* HH_RESTRICT buffer_bytes) { - memset(buffer_bytes, 0, sizeof(HHPacket)); + for (size_t i = 0; i < sizeof(HHPacket); ++i) { + buffer_bytes[i] = 0; + } } static HH_INLINE void CopyPartial(const char* HH_RESTRICT from,
diff --git a/highwayhash/highwayhash_test.cc b/highwayhash/highwayhash_test.cc index 4687b5e..aed9a9e 100644 --- a/highwayhash/highwayhash_test.cc +++ b/highwayhash/highwayhash_test.cc
@@ -21,7 +21,6 @@ #include <atomic> #include <cstdio> #include <cstdlib> -#include <vector> #ifdef HH_GOOGLETEST #include "testing/base/public/gunit.h" @@ -113,11 +112,10 @@ 0x0F0E0D0C0B0A0908ULL, 0x0706050403020100ULL}; const size_t kMaxSize = 3 * 35; - std::vector<char> flat; - flat.reserve(kMaxSize); + char flat[kMaxSize]; srand(129); for (size_t size = 0; size < kMaxSize; ++size) { - flat.push_back(static_cast<char>(rand() & 0xFF)); + flat[size] = static_cast<char>(rand() & 0xFF); } std::atomic<TargetBits> targets{~0U}; @@ -125,7 +123,7 @@ pool->Run(0, kMaxSize, [&key, &flat, &targets](const uint32_t i) { Result dummy; targets.fetch_and(InstructionSets::RunAll<HighwayHashCatTest>( - key, flat.data(), i, &dummy, &OnCatFailure)); + key, flat, i, &dummy, &OnCatFailure)); }); return targets.load(); }
diff --git a/highwayhash/scalar.h b/highwayhash/scalar.h index 3c56247..21181e7 100644 --- a/highwayhash/scalar.h +++ b/highwayhash/scalar.h
@@ -114,7 +114,7 @@ HH_INLINE Scalar& operator<<=(const int count) { // In C, int64_t << 64 is undefined, but we want to match the sensible // behavior of SSE2 (zeroing). - if (count >= sizeof(T) * 8) { + if (count >= static_cast<int>(sizeof(T)) * 8) { v_ = 0; } else { v_ <<= count;
diff --git a/highwayhash/vector_test.cc b/highwayhash/vector_test.cc index 94e4532..8ecd89f 100644 --- a/highwayhash/vector_test.cc +++ b/highwayhash/vector_test.cc
@@ -25,6 +25,10 @@ namespace highwayhash { namespace { +#ifdef HH_DISABLE_TARGET_SPECIFIC +void RunTests() {} +#else + void NotifyFailure(const char* target, const size_t size) { const size_t lane_bits = (size & 0xFF) * 8; const size_t lane_index = (size >> 8) & 0xFF; @@ -39,14 +43,14 @@ } void RunTests() { -#ifndef HH_DISABLE_TARGET_SPECIFIC const TargetBits tested = InstructionSets::RunAll<VectorTest>(&NotifyFailure); HH_TARGET_NAME::ForeachTarget(tested, [](const TargetBits target) { printf("%10s: done\n", TargetName(target)); }); -#endif } +#endif // HH_DISABLE_TARGET_SPECIFIC + #ifdef HH_GOOGLETEST TEST(VectorTest, Run) { RunTests(); } #endif