Effective Floating-Point Analysis Via Weak-Distance

Effective Floating-Point Analysis Via Weak-Distance

Effective Floating-Point Analysis via Weak-Distance Minimization Zhoulai Fu Zhendong Su IT University of Copenhagen, Denmark ETH Zurich, Switzerland [email protected] [email protected] Abstract ACM Reference Format: This work studies the connection between the problem of Zhoulai Fu and Zhendong Su. 2019. Effective Floating-Point Analy- analyzing floating-point code and that of function minimiza- sis via Weak-Distance Minimization. In Proceedings of the 40th ACM SIGPLAN Conference on Programming Language Design and Imple- tion. It formalizes this connection as a reduction theory, mentation (PLDI ’19), June 22–26, 2019, Phoenix, AZ, USA. ACM, New where the semantics of a floating-point program is measured York, NY, USA, 14 pages. https://doi.org/10.1145/3314221.3314632 as a generalized metric, called weak distance, which faith- fully captures any given analysis objective. It is theoretically guaranteed that minimizing the weak distance (e.g., via math- 1 Introduction ematical optimization) solves the underlying problem. This Modern infrastructures, from aerospace and robotics to fi- reduction theory provides a general framework for analyzing nance and physics, heavily rely on floating-point code. How- numerical code. Two important separate analyses from the ever, floating-point code is error-prone, and reasoning about literature, branch-coverage-based testing and quantifier-free its correctness has been a long-standing challenge. The main floating-point satisfiability, are its instances. difficulty stems from the subtle, albeit well-known, semantic To further demonstrate our reduction theory’s generality discrepancies between floating-point and real arithmetic. For and power, we develop three additional applications, includ- example, the associativity rule in real arithmetic a + ¹b +cº = ing boundary value analysis, path reachability and overflow ¹a + bº + c does not hold in floating-point arithmetic.1 Con- detection. Critically, these analyses do not rely on the mod- sider the C code in Fig.1(a) for a further motivating exam- eling or abstraction of floating-point semantics; rather, they ple. We assume the rounding mode is the default round-to- explore a program’s input space guided by runtime compu- nearest as defined in the IEEE-754 standard. The code may tation and minimization of the weak distance. This design, appear correct upon first sight. However, if we set the input combined with the aforementioned theoretical guarantee, to 0:999 999 999 999 999 9, the branch “if (x < 1)” will be enables the application of the reduction theory to real-world taken, but the subsequent “assert (x + 1 < 2)” will fail floating-point code. In our experiments, our boundary value (x + 1 = 2 in this case). Now, if we run the same code un- analysis is able to find all reachable boundary conditions der a different rounding mode, say round-toward-zero, the of the GNU sin function, which is complex with several assertion becomes valid. hundred lines of code, and our floating-point overflow de- tection detects a range of overflows and inconsistencies in void Prog(double x) { void Prog(double x) { the widely-used numerical library GSL, including two latent if (x < 1){ if (x < 1){ bugs that developers have already confirmed. x = x + 1; x = x + tan(x); assert(x < 2); assert(x < 2); CCS Concepts • Theory of computation → Program }} }} analysis. (a) (b) Keywords Program Analysis, Mathematical Optimization, Theoretical Guarantee, Floating-point Code Figure 1. Motivating examples: Do the assertions hold? Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not To reason about such counterintuitive floating-point be- made or distributed for profit or commercial advantage and that copies bear havior, one may believe that a formal semantic analysis is this notice and the full citation on the first page. Copyrights for components necessary. Indeed, state-of-the-art SMT solvers such as Math- of this work owned by others than ACM must be honored. Abstracting with SAT [10] can determine that the floating-point constraint credit is permitted. To copy otherwise, or republish, to post on servers or to x < ^ x + ≥ redistribute to lists, requires prior specific permission and/or a fee. Request 1 1 2 is satisfiable under the round-to-nearest permissions from [email protected]. mode and unsatisfiable under the round-toward-zero mode. PLDI ’19, June 22–26, 2019, Phoenix, AZ, USA However, the tight coupling between analysis and semantics © 2019 Association for Computing Machinery. ACM ISBN 978-1-4503-6712-7/19/06...$15.00 1One may verify that, on a typical x86-64 machine with the round-to-nearest https://doi.org/10.1145/3314221.3314632 mode, 0:1+¹0:2+0:3º = 0:6, but ¹0:1+0:2º+0:3 = 0:600 000 000 000 000 1. PLDI ’19, June 22–26, 2019, Phoenix, AZ, USA Zhoulai Fu and Zhendong Su can quickly become problematic for real-world code involv- program equivalently as the optimization problem of an- ing floating-point arithmetic operations, nonlinear relations, other floating-point program. or transcendental functions. Suppose we change “x = x + • We study three instances of the theory, including bound- 1” to “x = x + tan(x)” as shown in Fig.1(b). SMT-based ary value analysis, path reachability, and floating-point methods will find it difficult to reason about tan(x) because overflow detection. These problems are known to beim- the implementation of tan(x) is system-dependent, and its portant, challenging, and have been treated separately in semantics is not standardized in IEEE-754 [1]. the literature. The proposed reduction technique allows us Recent work has introduced two highly effective floating- to approach these distinct problems uniformly in the same point analyses that do not need to directly reason about theory and to effectively realize them under a common program logic [16, 17]. Both analyses drastically outper- implementation architecture. form traditional techniques. The first is for achieving high • We conduct a set of experiments to empirically validate branch coverage in floating-point code [17]. It transforms the our approach. Our boundary value analysis is able to trig- program under test into another program whose minimum ger all reachable boundary conditions of the GNU sin points trigger uncovered conditional branches. The analysis function, which is complex with several hundred lines of achieves an average of 90%+ branch coverage within seconds code. Our floating-point overflow detection has detected a on Sun’s math library code. The second concerns floating- range of overflows, inconsistencies, and two latent, already point constraint satisfiability [16]. A floating-point formula confirmed bugs in the widely-used GSL. in conjunctive normal form (CNF) is transformed into a pro- To facilitate the exposition of our approach and its repro- gram whose minimum points correspond to the models of duction, we provide a variety of examples throughout the the formula. A Monte Carlo optimization backend is applied paper. We believe that these examples also help inform the to find these models, if any. The solver produces consistent reader both our approach’s strengths and limitations. satisfiability results as both MathSAT and Z3 with average The rest of the paper is organized as follows. Section2 for- speedups of over 700X on SMT-competition benchmarks. mulates the problem, and Section3 develops our reduction This work generalizes these ideas and develops a unified theory. Section4 illustrates the theory with three examples. theory that applies to a broad category of floating-point anal- Section5 lays out the implementation architecture and dis- ysis problems. The theory consists of a faithful reduction cuss the limitations of our approach, while Section6 presents procedure from the problem domain of floating-point anal- our experiments and results. Section7 surveys related work, ysis to the problem domain of mathematical optimization. and finally Section8 concludes. At the core of theory, floating-point program semantics is measured as a generalized metric called weak distance, and it Notation. As usual, we denote the set of integers and real is guaranteed that minimizing the weak distance, such as via numbers by Z and R respectively. We write F for the set of mathematical optimization (MO), leads to a solution to the floating-point numbers of the IEEE-754 binary64 format. underlying floating-point analysis problem, and vice versa. We will often write x® to represent an N-dimensional floating- Our reduction offers a key practical benefit. As modern N point vectors ¹x1;:::; xN º in F . MO techniques work by executing an objective function, our approach does not need to analyze floating-point program se- 2 Floating-Point Analysis mantics, an intractable and potentially cost-ineffective task. Instead, it directs input space exploration by executing an- The term floating-point analysis in this paper refers to a other, potentially simpler floating-point program that models broad class of problems in program analysis, testing, and the weak distance to capture the desired analysis objective. verification, where the goal is to determine if floating-point It is a common misconception that MO is useful only for program is correct or has some desired properties. In this continuous objective functions — continuity is preferred, but section, we first briefly review the semantic constructs of not necessary. Modern, advanced algorithms exist that can the problem, formulate, and then frame it as a problem of handle functions with discontinuity, high-dimensionality, finding unsafe inputs. We show five instances of the defined or time-consuming computation. Our approach uses MO problem, three of which will be studied in later sections (the techniques as black-boxes and can directly benefit from the other two were explored in the literature). state-of-the-art. Our main contributions follow: 2.1 Problem Formulation • We develop a reduction theory for floating-point analysis A large body of research on floating-point analysis can be via mathematical optimization.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    14 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us