Skip to content

Commit

Permalink
convert most of core to header only
Browse files Browse the repository at this point in the history
  • Loading branch information
boxerab committed May 5, 2024
1 parent 45404a4 commit be8573d
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if(POLICY CMP0128)
cmake_policy(SET CMP0128 NEW)
endif()

project(hwy VERSION 1.2.0) # Keep in sync with highway.h version
project(hwy VERSION 1.2.0 LANGUAGES CXX) # Keep in sync with highway.h version
# `hwy` is lowercase to handle find_package() in Config mode:
set(namespace "${PROJECT_NAME}::")

Expand Down Expand Up @@ -179,13 +179,14 @@ if (NOT HWY_CMAKE_HEADER_ONLY)
hwy/abort.cc
hwy/aligned_allocator.cc
hwy/nanobenchmark.cc
hwy/per_target.cc
hwy/print.cc
hwy/targets.cc
hwy/timer.cc
)
endif()

list(APPEND HWY_SOURCES hwy/per_target.cc)

set(HWY_TEST_SOURCES
hwy/tests/hwy_gtest.h
hwy/tests/test_util-inl.h
Expand Down
4 changes: 4 additions & 0 deletions hwy/abort.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
namespace hwy {

namespace {

#ifdef HWY_HEADER_ONLY
inline
#endif
std::string GetBaseName(std::string const& file_name) {
auto last_slash = file_name.find_last_of("/\\");
return file_name.substr(last_slash + 1);
Expand Down
4 changes: 4 additions & 0 deletions hwy/abort.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ AbortFunc SetAbortFunc(AbortFunc func);

} // namespace hwy

#ifdef HWY_HEADER_ONLY
#include "abort.cc"
#endif

#endif // HIGHWAY_HWY_ABORT_H_
2 changes: 2 additions & 0 deletions hwy/abort_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
namespace hwy {

#ifdef GTEST_HAS_DEATH_TEST
#ifndef HWY_HEADER_ONLY
namespace {
std::string GetBaseName(std::string const& file_name) {
auto last_slash = file_name.find_last_of("/\\");
return file_name.substr(last_slash + 1);
}
} // namespace
#endif

TEST(AbortDeathTest, AbortDefault) {
std::string expected = std::string("Abort at ") + GetBaseName(__FILE__) +
Expand Down
4 changes: 4 additions & 0 deletions hwy/aligned_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include <limits>

#include "hwy/base.h"
#ifdef HWY_HEADER_ONLY
#include "hwy/abort.h"
#endif


namespace hwy {
namespace {
Expand Down
5 changes: 5 additions & 0 deletions hwy/aligned_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,9 @@ class AlignedNDArray {
};

} // namespace hwy

#ifdef HWY_HEADER_ONLY
#include "aligned_allocator.cc"
#endif

#endif // HIGHWAY_HWY_ALIGNED_ALLOCATOR_H_
3 changes: 3 additions & 0 deletions hwy/aligned_allocator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include <vector>

#include "hwy/base.h"
#ifdef HWY_HEADER_ONLY
#include "hwy/abort.h"
#endif
#include "hwy/per_target.h"
#include "hwy/tests/hwy_gtest.h"
#include "hwy/tests/test_util-inl.h" // HWY_ASSERT_EQ
Expand Down
3 changes: 3 additions & 0 deletions hwy/base_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// limitations under the License.

#include "hwy/base.h"
#ifdef HWY_HEADER_ONLY
#include "hwy/abort.h"
#endif

#include <limits>

Expand Down
3 changes: 3 additions & 0 deletions hwy/examples/profiler_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include "hwy/base.h" // Abort
#include "hwy/profiler.h"
#include "hwy/timer.h"
#ifdef HWY_HEADER_ONLY
#include "hwy/abort.h"
#endif

namespace hwy {
namespace {
Expand Down
3 changes: 3 additions & 0 deletions hwy/nanobenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "hwy/robust_statistics.h"
#include "hwy/timer-inl.h"
#include "hwy/timer.h"
#ifdef HWY_HEADER_ONLY
#include "hwy/abort.h"
#endif

namespace hwy {
namespace {
Expand Down
4 changes: 4 additions & 0 deletions hwy/nanobenchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,8 @@ static inline size_t MeasureClosure(const Closure& closure,

} // namespace hwy

#ifdef HWY_HEADER_ONLY
#include "nanobenchmark.cc"
#endif

#endif // HIGHWAY_HWY_NANOBENCHMARK_H_
9 changes: 9 additions & 0 deletions hwy/print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
namespace hwy {
namespace detail {

#ifdef HWY_HEADER_ONLY
inline
#endif
HWY_DLLEXPORT void TypeName(const TypeInfo& info, size_t N, char* string100) {
const char prefix = info.is_float ? 'f' : (info.is_signed ? 'i' : 'u');
// Omit the xN suffix for scalars.
Expand All @@ -37,6 +40,9 @@ HWY_DLLEXPORT void TypeName(const TypeInfo& info, size_t N, char* string100) {
}
}

#ifdef HWY_HEADER_ONLY
inline
#endif
HWY_DLLEXPORT void ToString(const TypeInfo& info, const void* ptr,
char* string100) {
if (info.sizeof_t == 1) {
Expand Down Expand Up @@ -105,6 +111,9 @@ HWY_DLLEXPORT void ToString(const TypeInfo& info, const void* ptr,
}
}

#ifdef HWY_HEADER_ONLY
inline
#endif
HWY_DLLEXPORT void PrintArray(const TypeInfo& info, const char* caption,
const void* array_void, size_t N, size_t lane_u,
size_t max_lanes) {
Expand Down
4 changes: 4 additions & 0 deletions hwy/print.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ HWY_NOINLINE void PrintArray(const T* value, size_t count) {

} // namespace hwy

#ifdef HWY_HEADER_ONLY
#include "print.cc"
#endif

#endif // HWY_PRINT_H_
12 changes: 12 additions & 0 deletions hwy/targets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,9 @@ int64_t DetectTargets() {

} // namespace

#ifdef HWY_HEADER_ONLY
inline
#endif
HWY_DLLEXPORT void DisableTargets(int64_t disabled_targets) {
supported_mask_ = static_cast<int64_t>(~disabled_targets);
// This will take effect on the next call to SupportedTargets, which is
Expand All @@ -699,11 +702,17 @@ HWY_DLLEXPORT void DisableTargets(int64_t disabled_targets) {
GetChosenTarget().DeInit();
}

#ifdef HWY_HEADER_ONLY
inline
#endif
HWY_DLLEXPORT void SetSupportedTargetsForTest(int64_t targets) {
supported_targets_for_test_ = targets;
GetChosenTarget().DeInit(); // see comment above
}

#ifdef HWY_HEADER_ONLY
inline
#endif
HWY_DLLEXPORT int64_t SupportedTargets() {
int64_t targets = supported_targets_for_test_;
if (HWY_LIKELY(targets == 0)) {
Expand Down Expand Up @@ -738,6 +747,9 @@ HWY_DLLEXPORT int64_t SupportedTargets() {
return targets == 0 ? HWY_STATIC_TARGET : targets;
}

#ifdef HWY_HEADER_ONLY
inline
#endif
HWY_DLLEXPORT ChosenTarget& GetChosenTarget() {
static ChosenTarget chosen_target;
return chosen_target;
Expand Down
4 changes: 4 additions & 0 deletions hwy/targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,8 @@ HWY_DLLEXPORT ChosenTarget& GetChosenTarget();

} // namespace hwy

#ifdef HWY_HEADER_ONLY
#include "targets.cc"
#endif

#endif // HIGHWAY_HWY_TARGETS_H_
13 changes: 12 additions & 1 deletion hwy/timer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,17 @@ void GetBrandString(char* cpu100) {

} // namespace

#ifdef HWY_HEADER_ONLY
inline
#endif
HWY_DLLEXPORT double Now() {
static const double mul = 1.0 / InvariantTicksPerSecond();
return static_cast<double>(timer::Start()) * mul;
}

#ifdef HWY_HEADER_ONLY
inline
#endif
HWY_DLLEXPORT bool HaveTimerStop(char* cpu100) {
#if HWY_ARCH_X86
if (!HasRDTSCP()) {
Expand All @@ -132,7 +138,9 @@ HWY_DLLEXPORT bool HaveTimerStop(char* cpu100) {
cpu100[1] = '\0';
return true;
}

#ifdef HWY_HEADER_ONLY
inline
#endif
HWY_DLLEXPORT double InvariantTicksPerSecond() {
#if HWY_ARCH_PPC && defined(__GLIBC__) && defined(__powerpc64__)
return static_cast<double>(__ppc_get_timebase_freq());
Expand All @@ -154,6 +162,9 @@ HWY_DLLEXPORT double InvariantTicksPerSecond() {
#endif
}

#ifdef HWY_HEADER_ONLY
inline
#endif
HWY_DLLEXPORT uint64_t TimerResolution() {
char cpu100[100];
bool can_use_stop = HaveTimerStop(cpu100);
Expand Down
6 changes: 6 additions & 0 deletions hwy/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ static inline double SecondsSince(const Timestamp& t0) {

} // namespace hwy

#ifdef HWY_HEADER_ONLY
#include "timer.cc"
#endif

#endif // HIGHWAY_HWY_TIMER_H_


0 comments on commit be8573d

Please sign in to comment.