This project compares different implementations of Tnum (三值数) multiplication algorithms in both Rust and C. It provides a framework to evaluate the correctness and performance of each implementation against a C reference implementation.
Tnum is a three-valued numeric type used in abstract interpretation that combines a concrete value (value) and a mask (mask) indicating which bits are known. This project compares several implementation strategies for Tnum multiplication:
C_tnum_mul: C reference implementationtnum_mul: Basic Rust implementationtnum_mul_opt: Optimized Rust implementationxtnum_mul_top: Extended Rust implementationxtnum_mul_high_top: High-level extended Rust implementation
tnum/
├── src/ # Source code
│ ├── test.rs # Rust test generation
│ ├── tnum.c # C implementation of Tnum operations
│ ├── tnum_mul.c # C multiplication implementation
│ └── compare.rs # Results comparison tool
├── include/ # Header files
│ └── tnum.h # Tnum structs and function declarations
├── build/ # Build artifacts (created during build)
├── Cargo.toml # Rust package configuration
├── Makefile # Build automation
└── README.md # This file
- Rust (cargo)
- GCC
- json-c library
- Make
# Run the complete test suite with default parameters
make test
# Run with custom parameters
make test N=5000 ITERATIONS=1000# Only generate Rust test cases
make rust-test [N=100] [ITERATIONS=100]
# Only run C implementation tests
make c-test [ITERATIONS=100]
# Compare results (requires previous steps to be completed)
make compare-results
# Clean all build artifacts
make cleanN: Number of test cases to generate (default: 100)ITERATIONS: Number of iterations for each test case (default: 100)
The test process generates several output files:
build/rust_test_cases.json: Test cases generated by Rustbuild/c_test_results.json: Results from C implementationinconsistencies_*.json: Any inconsistencies found between implementations (with timestamp)
The comparison tool provides:
- Performance metrics for each implementation
- Correctness rates compared to the C reference implementation
- Detailed reports of any inconsistent results
To add a new implementation:
- Add your implementation to the appropriate Rust or C file
- Update the
METHOD_NAMESarray incompare.c - Ensure your method name matches in both implementation and comparison