This directory contains examples demonstrating how to use the Highway SIMD library.
sum_array_simple.ccMinimal code demonstrating how to sum an array of float, with a simple scalar fallback for remainders.
sum_array_advanced.ccHigher-performance array sum, including:
LoadN with FirstN mask for remainder handling without scalar fallbacksdot_product_unroll.ccSimilar to sum_array_advanced, but for dot products. Adds:
MulAddReduceSum.dot_product_mixed_precision.ccSimilar to array simple but uses type promotion to allow for a greater range in resulting integer sum values before an overflow occurs.
mandelbrot.ccDemonstrates:
baker_mix.ccPermutting entries in an integer array showing:
IotaPrintSlideUpLanes and SlideDownLanesOrStoreInterleaved2matrix_transpose_scatter_gather.ccMatrix transposition via Gather and Scatter, showing:
GatherIndex and ScatterIndexLoadN/StoreN and GatherIndexN/ScatterIndexNIota and Mul.stream_triad.ccAddition of a vector to a scaled copy of another vector, showing:
game_of_life.ccExample stencil computation showing:
Slide1UpOr/Slide1DownOrbenchmark.ccDot product and delta coding, with benchmarking infrastructure and aligned allocation.
profiler_example.ccShows how to use the our built-in profiler for measuring the elapsed time in annotated zones, deducting the time spent in nested zones.
skeleton*A complete example of a module with support for runtime dispatch, and a ‘per-target header’ for inlining SIMD into multiple .cc files.
masks_and_logic.ccASCII art renderer, demonstrating:
And, AndNot)IfThenElse for nested conditionsHWY_ATTR for SIMD operations.ctf_aes.ccBrute-force password guessing, with:
FixedTag for fixed-length vectorsAESRound)FirstN and masked comparisons via MaskedEq.To run the examples using Bazel:
bazel run //::sum_array_simple bazel run //::sum_array_advanced # etc; see BUILD file for the other build targets
If you are building Highway with CMake (from the root of the highway directory):
mkdir build && cd build cmake .. -DHWY_ENABLE_EXAMPLES=ON make ./examples/sum_array_simple ./examples/sum_array_advanced # etc; see CMakeLists.txt for the other build targets
To compile and run using clang++ (from the root of the highway directory):
clang++ -std=c++17 -O3 -I. hwy/examples/sum_array_simple.cc hwy/targets.cc hwy/per_target.cc hwy/print.cc hwy/abort.cc hwy/aligned_allocator.cc -o sum_array_simple ./sum_array_simple
To compile and run using g++ (from the root of the highway directory):
g++ -std=c++17 -O3 -I. hwy/examples/sum_array_simple.cc hwy/targets.cc hwy/per_target.cc hwy/print.cc hwy/abort.cc hwy/aligned_allocator.cc -o sum_array_simple ./sum_array_simple
Note: g++ might emit some assembler warnings like no SFrame FDE emitted, which are benign and can be ignored.