Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
malaterre committed Jul 11, 2023
1 parent 6bb1ecf commit 771ca57
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ check_cxx_source_compiles(
if (HWY_ENABLE_CONTRIB)
# Glob all the traits so we don't need to modify this file when adding
# additional special cases.
file(GLOB HWY_CONTRIB_SOURCES "hwy/contrib/sort/vqsort_*.cc")
#file(GLOB HWY_CONTRIB_SOURCES "hwy/contrib/sort/vqsort_*.cc")
list(APPEND HWY_CONTRIB_SOURCES
hwy/contrib/dot/dot-inl.h
hwy/contrib/image/image.cc
Expand Down Expand Up @@ -446,12 +446,14 @@ if (HWY_ENABLE_EXAMPLES)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

# Programming exercise with integrated benchmark
add_executable(log1p hwy/examples/log1p.cc)
add_executable(hwy_benchmark hwy/examples/benchmark.cc)
target_sources(hwy_benchmark PRIVATE
hwy/nanobenchmark.h)
# Try adding one of -DHWY_COMPILE_ONLY_SCALAR, -DHWY_COMPILE_ONLY_EMU128 or
# -DHWY_COMPILE_ONLY_STATIC to observe the difference in targets printed.
target_compile_options(hwy_benchmark PRIVATE ${HWY_FLAGS})
target_link_libraries(log1p PRIVATE hwy)
target_link_libraries(hwy_benchmark PRIVATE hwy)
target_link_libraries(hwy_benchmark PRIVATE ${ATOMICS_LIBRARIES})
set_target_properties(hwy_benchmark
Expand Down
38 changes: 19 additions & 19 deletions hwy/contrib/math/math_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ HWY_NOINLINE void TestMath(const char* name, T (*fx1)(T),
const auto ulp = hwy::detail::ComputeUlpDelta(actual, expected);
max_ulp = HWY_MAX(max_ulp, ulp);
if (ulp > max_error_ulp) {
fprintf(stderr, "%s: %s(%f) expected %f actual %f ulp %g max ulp %u\n",
fprintf(stderr, "%s: %s(%.17g) expected %.17g actual %.17g ulp %g max ulp %u\n",
hwy::TypeName(T(), Lanes(d)).c_str(), name, value, expected,
actual, static_cast<double>(ulp),
static_cast<uint32_t>(max_error_ulp));
Expand Down Expand Up @@ -371,25 +371,25 @@ HWY_AFTER_NAMESPACE();

namespace hwy {
HWY_BEFORE_TEST(HwyMathTest);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAcos);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAcosh);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAsin);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAsinh);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAtan);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAtanh);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllCos);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllExp);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllExpm1);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllLog);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllLog10);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAcos);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAcosh);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAsin);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAsinh);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAtan);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAtanh);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllCos);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllExp);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllExpm1);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllLog);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllLog10);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllLog1p);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllLog2);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllSin);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllSinh);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllTanh);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAtan2);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllSinCosSin);
HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllSinCosCos);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllLog2);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllSin);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllSinh);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllTanh);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllAtan2);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllSinCosSin);
//HWY_EXPORT_AND_TEST_P(HwyMathTest, TestAllSinCosCos);
} // namespace hwy

#endif
30 changes: 30 additions & 0 deletions hwy/examples/log1p.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "hwy/highway.h"
#include "hwy/contrib/math/math-inl.h"

#include <cstdio>
#include <cmath>

int main()
{
#if 1
//const double value = 9.8046570862201476e-17;
//const double value = 5.526720574244119e-20;
const double value = 5.5968112995194757e-20;
hwy::N_EMU128::Simd<double, 2u, 0> a;
hwy::N_EMU128::Vec128<double, 2u> b = hwy::N_EMU128::Set(a, value);
hwy::N_EMU128::Vec128<double, 2> ret = hwy::N_EMU128::Log1p(a, b);
const double actual = hwy::N_EMU128::GetLane(ret);
const double expected = std::log1p( value );
std::printf("%.17g vs %.17g\n", actual, expected );
#else
//const double value = 0.28195148706436157; // clang-16
const double value = 6.0400722645681526e-08;
hwy::N_EMU128::Simd<float, 4u, 0> a;
hwy::N_EMU128::Vec128<float, 4u> b = hwy::N_EMU128::Set(a, value);
hwy::N_EMU128::Vec128<float, 4> ret = hwy::N_EMU128::Log1p(a, b);
const double actual = hwy::N_EMU128::GetLane(ret);
const double expected = std::log1p( value );
std::printf("%.17g vs %.17g\n", actual, expected );
#endif
return 0;
}

0 comments on commit 771ca57

Please sign in to comment.