Solving Constraints on the Intermediate Result of Decimal Floating-Point Operations
Total Page:16
File Type:pdf, Size:1020Kb
Solving Constraints on the Intermediate Result of Decimal Floating-Point Operations Merav Aharoni, Ron Maharik, Abraham Ziv IBM Research Lab in Haifa email: [email protected] Abstract hard to understand and debug; therefore decimal arithmetic is supported through software on most machines. Recently, The draft revision of the IEEE Standard for Floating- there is renewed interest in usage of decimal FP implemen- Point Arithmetic (IEEE P754) includes a definition for dec- tations both in software [5], [7] and hardware [8], [10]. imal floating-point (FP) in addition to the widely used bi- Verification of binary FP hardware is known to be an in- nary FP specification. tricate problem. Both formal methods and simulation meth- The decimal standard raises new concerns with regard ods have been developed to deal with this challenge. Veri- to the verification of hardware- and software-based designs. fication by simulation cannot cover the entire FP domain, The verification process normally emphasizes intricate cor- which is huge and involves many corner cases. For this ner cases and uncommon events. The decimal format intro- purpose, coverage models are developed [17], that define duces several new classes of such events in addition to those interesting cases for verification purposes. A coverage case characteristic of binary FP. is said to be covered if we have at least one test that hits Our work addresses the following problem: Given a dec- this case. Coverage cases can be defined on different levels: imal floating-point operation, a constraint on the interme- they can be defined in English, in terms of the implementa- diate result, and a constraint on the representation selected tion signals, or in some formal or mathematical expression for the result, find random inputs for the operation that yield language. The language determines to a great extent the an intermediate result compatible with these specifications. kind of cases that can be covered. The paper supplies efficient analytic solutions for addi- Generating the test cases is often a manual process, tion and for some cases of multiplication and division. We which is quite difficult and limits the number of test cases provide probabilistic algorithms for the remaining cases. that can be produced. Software tools have been devel- These algorithms prove to be efficient in the actual imple- oped in order to cope with this problem, for example mentation. [4,11,13,15,16,19]. Several papers propose algorithms that generate random solutions for interesting special cases of constraints on bi- nary FP operations. One example can be found in [12], 1 Introduction which describes algorithms for solving constraints on the unbounded intermediate result of arithmetic operations on The previous IEEE standard 754 [2] specified the for- binary FP numbers. mats and behavior for binary floating-point (FP). The draft As decimal FP is a newly defined format, it lacks the for the revised standard P754 [3] specifies them both for existing technology developed for binary FP verification. binary and decimal FP. Many of the earliest computers Decimal FP has several notable differences as compared to used decimal arithmetic, but computer hardware gradually binary FP. The most obvious is that the significand com- evolved toward usage of binary arithmetic, to the point that prises decimal digits rather than binary bits. The second today most computers support only binary arithmetic in major difference is that for decimal FP numbers, the repre- hardware [6]. sentation of the number is deemed important, in addition to Decimal arithmetic, both integer and FP, has widespread its numerical value. The set of all representations of a single applications, primarily financial and commercial. Usage of numerical value is known as the cohort of this value. binary FP in these applications implies inexact conversions The standard allow two representations: a normalized µ between binary and decimal representations, and roundoff format, in which the significand is in the range 0 10 and in binary operations, which change the data in ways that are has the form d0 d1 dp 1,andanunnormalized format,in p which the significand is an integer in the range 0 10 1 . first selecting a specific value from the set of allowed inter- In the discussion that follows, we choose to use the unnor- mediate results and then calling the suggested algorithms. malized representation. Since most of the algorithms in this We provide algorithms that, given a specific intermedi- paper involve calculations on the significand, it is more con- ate result and difference between actual and preferred ex- venient to deal with it as an integer, rather than as a fraction. ponents, provide two inputs that yield the specified result. Trailing zeros in the significand of a decimal FP number We provide algorithms for addition, multiplication, and di- 0 0 0 ¡ µ ¡ ´ ¡ µ ¡ are meaningful; for example, ´2 10 3 10 6 10 ,but vision. These algorithms are random, in that successive us- 1 1 2 ¡ µ ¡ ´ ¡ µ ¡ ´20 10 30 10 600 10 . The numerical value age potentially yields different pairs of inputs that generate of these two results is the same, but the values are consid- the same result. This is important for verification purposes, ered different in the sense that they represent different de- allowing more complete coverage of the scenario space and grees of precision in the result. To quantify the definition of faster uncovering of design bugs. We try to keep the selec- the precision of the result, the IEEE Standard P754 [3] de- tion of different inputs within the solution space as uniform fines a preferred exponent for the result of every arithmetic as possible, and demand that no solutions be lost. operation. The preferred exponent uniquely defines the rep- These algorithms were implemented in the context of a resentation selected for the result among all members of its custom verification tool for FP designs, named FPgen [4]. cohort. The tool was used for the verification of the decimal FP im- When defining test cases for FP, input constraints pro- plemented in millicode in IBM System z9 [9] and in veri- vide only limited capabilities. Targeting outputs, or in par- fication of decimal FP hardware in IBM Power6 [14]. Test ticular, intermediate results, allows much better control over cases generated by this tool proved effective in uncovering FP corner cases. In this paper, we define constraints on the design bugs, as well as in attaining functional coverage. intermediate result of arithmetic operations. FPgen was also used to generate a test suite for the IEEE For example, in a decimal FP system with 4 digits of standard for binary and decimal FP. The test suite is based precision, an intermediate result of 9999.9 may have to be on a set of coverage models described in a document that shifted one digit to the right after it is rounded to the tar- can be found on the FPgen web site [1]. Each model in get precision, therefore this is an interesting result for test- the document describes a set of interesting cases for testing. ing the shifter mechanism. An intermediate result such as The full test suite for decimal FP has not yet been made 2222.50 can be used test the rounding mechanism, as it is on public. A preliminary version of the decimal test suite can the threshold between results that are rounded up and those be found on the web site. rounded down. In Section 2, we provide some necessary definitions and In addition to a constraint on the intermediate result, we formally define the problem. In Sections 3, 4, and 5, we define a constraint over the difference between the actual present algorithms for addition, multiplication, and division exponent of the intermediate result and the preferred ex- operations, respectively. Section 6 provides a summary of ponent. This allows us to test various uncommon scenar- the results and suggestions for future work in this area. ios and to verify that the correct representation of the result value is selected. 2 Problem Definition As an example, consider a coverage model that tests all possible values of the exponent difference in a division op- eration. Suppose that the decimal format in question sup- We will need the following definitions before we proceed ports 4 digits of precision. As we shall see in Section 5, to define the problem: the exponent difference in this case is between 0 and 7. To Decimal Floating-point number: Using the notation of IEEE standard P754, a decimal floating-point num- generate the extreme case where the difference is 7, the div- s e ´ µ ´ µ idend’s significand must be selected so that it has 3 leading ber is defined by 1 10 d0d1d2 dp 1 where s is the zeros and only 1 significant digit. The divisor must have sign, e is the (unbiased) exponent, Emin e Emax,and 4 significant digits, and the resulting quotient must have d0d1d2 dp 1 is the significand with di each representing at least 4 significant digits. Here is one possible solution: a decimal digit, di 0 1 2 9 . Unlike binary FP, deci- 0 0 mal FP numbers are not normalized and as a result a single ¤ ¡ ¡ 1 ¡ 10 3200 10 = 3125 0 10 7. The preferred expo- nent, as defined in Section 2, is 0. value may have multiple representations. Constraints on the allowed intermediate results and ex- p (precision): The maximal number of digits in the sig- ponent differences can appear as ranges, masks, or other set nificand. definitions. We choose to deal with the strictest constraint Unbounded intermediate result: The result of a among these, namely a specific intermediate result and a floating-point operation, assuming unbounded precision specific difference between actual and preferred exponents.