Skip to content

ziyefbk/tnum_verification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TNUM Multiplication Implementation Comparison

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.

Overview

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 implementation
  • tnum_mul: Basic Rust implementation
  • tnum_mul_opt: Optimized Rust implementation
  • xtnum_mul_top: Extended Rust implementation
  • xtnum_mul_high_top: High-level extended Rust implementation

Project Structure

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

Requirements

  • Rust (cargo)
  • GCC
  • json-c library
  • Make

Building and Running Tests

Basic Usage

# Run the complete test suite with default parameters
make test

# Run with custom parameters
make test N=5000 ITERATIONS=1000

Available Commands

# 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 clean

Parameters

  • N: Number of test cases to generate (default: 100)
  • ITERATIONS: Number of iterations for each test case (default: 100)

Output

The test process generates several output files:

  • build/rust_test_cases.json: Test cases generated by Rust
  • build/c_test_results.json: Results from C implementation
  • inconsistencies_*.json: Any inconsistencies found between implementations (with timestamp)

Analysis

The comparison tool provides:

  1. Performance metrics for each implementation
  2. Correctness rates compared to the C reference implementation
  3. Detailed reports of any inconsistent results

Extending

To add a new implementation:

  1. Add your implementation to the appropriate Rust or C file
  2. Update the METHOD_NAMES array in compare.c
  3. Ensure your method name matches in both implementation and comparison

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors