SWATI: Synthesizing Wordlengths Automatically Using Testing and Induction

Susmit Jha, Sanjit A. SeshiaarXiv 2013

Abstract

Embedded systems often require the conversion of high-level floating-point algorithms into fixed-point implementations to optimize for cost, power, and area. However, determining the optimal bit-width (wordlength) for each variable is a complex task that balances precision against hardware constraints. This paper introduces SWATI, an automated tool that utilizes Counter-Example Guided Inductive Synthesis (CEGIS) to find minimal wordlengths that satisfy specific accuracy targets. By combining greedy inductive synthesis with optimization-based testing using the Nelder-Mead method, SWATI identifies critical "edge case" inputs to ensure robust implementations. Evaluation across digital signal processing and control benchmarks demonstrates that SWATI achieves more reliable and cost-effective results than traditional random sampling methods.

Introduction

Numerical algorithms in fields like robotics and signal processing are typically developed using floating-point arithmetic for its ease of use and wide dynamic range. Yet, many embedded processors lack dedicated floating-point units (FPUs) to minimize production costs and power consumption. Engineers must therefore convert these algorithms to fixed-point arithmetic. This conversion presents a significant "Goldilocks" challenge: wordlengths that are too small lead to inaccuracy or overflow, while excessively large wordlengths result in inefficient, power-hungry hardware.

Comparison of range and precision for various 32-bit number systems.

Manual optimization is error-prone, and existing automated tools often rely on random sampling—which can miss rare edge cases—or overly conservative analytical methods that produce unnecessarily large wordlengths.

Methodology

SWATI addresses the wordlength optimization problem through a framework called Counter-Example Guided Inductive Synthesis (CEGIS). The process iterates between two primary components:

  1. Inductive Synthesis (optInduce): Instead of optimizing for the entire input space at once, SWATI maintains a small set of "interesting" inputs. It performs a greedy search to find the minimum wordlengths required to meet accuracy targets for this specific subset.
  2. Optimization-Based Testing (testErr): Once a candidate fixed-point implementation is generated, SWATI employs the Nelder-Mead optimization method to search the input domain for cases that maximize the error relative to the floating-point original. If an input is found that violates the accuracy threshold, it is added to the "interesting" set, and the synthesis step is repeated.

By treating verification as an active search problem, SWATI turns the hunt for accuracy violations into a directed mathematical optimization, allowing it to represent complex constraints with a very small number of inputs (often fewer than 150).

Evaluation and Results

The authors evaluated SWATI on several representative benchmarks, including IIR/FIR filters and non-linear controllers for DC motors and Two-Wheeled Welding Mobile Robots (WMR).

Error analysis showing absolute and relative differences across the input domain.

Key findings include:

  • Reliability: In a circle area calculation example, SWATI produced a globally correct implementation using only 34 directed inputs, whereas a random sampling approach with 100 inputs failed to meet accuracy thresholds across the entire domain.
  • Efficiency: For a DC motor controller, SWATI successfully synthesized a solution using 127 inputs, while random sampling failed even with 635 inputs (a 5x increase in sample size).
  • Hardware Cost: SWATI consistently identified configurations with lower hardware "cost" (a metric combining area and delay) while strictly adhering to user-defined error bounds, such as a 1% relative error limit.

Conclusion

SWATI demonstrates that a small, intelligently selected set of inputs can effectively constrain the wordlength optimization problem for complex numerical programs. By leveraging the monotonicity of wordlengths and directed optimization-based testing, the tool bridges the gap between high-level design and efficient hardware implementation. While the current reliance on local optimization (Nelder-Mead) may struggle with highly discontinuous error functions, the inductive synthesis approach significantly outperforms traditional random testing. Future work may involve integrating global optimization routines or SMT solvers to enhance scalability and provide even stronger correctness guarantees.

Summary updated

BibTeX
@misc{jha2013swati,
  author = {Susmit Jha and Sanjit A. Seshia},
  title = {{SWATI: Synthesizing Wordlengths Automatically Using Testing and Induction}},
  year = {2013},
  eprint = {1302.1920},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1302.1920},
}
Figure