This project demonstrates the use of Single Instruction, Multiple Data (SIMD) operations for Intel/AMD (using SSE) and ARM (using NEON) architectures in C, along with unit testing using the Criterion testing framework.
simd_operations.c
andsimd_operations.h
: Contain the implementation of SIMD operations.test_simd_operations.c
: Contains the Criterion-based unit tests for the SIMD operations.Makefile
(Optional): Can be used to automate compilation and testing.
Criterion is a cross-platform C and C++ testing framework. Follow these steps to install Criterion:
-
Using a Package Manager (Debian/Ubuntu):
sudo apt-get install libcriterion-dev
-
From Source:
- Install the necessary dependencies.
- Clone the Criterion repository:
git clone --recursive https://github.com/Snaipe/Criterion.git
- Build and install:
mkdir Criterion/build && cd Criterion/build cmake .. make sudo make install
gcc -o test_simd test_simd_operations.c simd_operations.c -lcriterion
-
Write Tests:
- Place your tests in
test_simd_operations.c
. Use the Criterion API to define test cases.
- Place your tests in
-
Compile the Tests:
- Ensure Criterion is installed and accessible to your compiler.
- Compile the test file along with the SIMD operation sources and link against Criterion:
gcc -o test_simd test_simd_operations.c simd_operations.c -lcriterion
-
Run the Tests:
- Execute the compiled test binary:
./test_simd
- Execute the compiled test binary:
- This example includes code paths for both SSE (Intel/AMD) and NEON (ARM). Ensure your compiler supports the SIMD instructions for your target architecture.
- Use appropriate compiler flags if necessary, e.g.,
-msse2
for SSE2 or-march=armv8-a+simd
for ARM NEON.
For more detailed information about Criterion and its usage, refer to the official Criterion documentation.