An Error Estimation Model for Fixed-Point Number

12 downloads 0 Views 430KB Size Report
ics devices such as PDA's and mobile phones can display various multimedia contents, they still need to reduce re- quired computing power. In this paper, we ...
An Error Estimation Model for Fixed-Point Number Representations Hwanyong Lee Solution Division HUONE Inc. Daegu 702-250, Korea [email protected]

Nakhoon Baek∗ School of EECS Kyungpook Nat’l Univ. Daegu 702-701, Korea [email protected]

ABSTRACT Recently, we need to display multimedia contents on relatively low-powered devices such as mobile phones and PDA’s. To support the multimedia capability on these devices, we fundamentally need efficient way of performing various mathematical operations. Although most devices use floating-point number representation formats such as IEEE754, recent application programs often use fixed-point number representation formats for more efficient real number calculations. Currently, mobile devices without floating-point processing units and/or having relatively low computing powers tend to use it mostly due to its efficiency. In contrast, we cannot avoid greater numerical errors in comparison to the widely used floating-point number representation. In this paper, we analyze the numerical errors in the fixed-point number calculations and investigate the suitability of fixed-point number formats and its operations. We also show experimental results for various choices of fixed-point location in the real number representation. Keywords: Numerical Error, Fixed-point Number Representation, Error Propagation.

1

Youngsul Shin School of EECS Kyungpook Nat’l Univ. Daegu 702-701, Korea [email protected]

Kee Hyun Park Dept. of Comp. Eng. Keimyung Univ. Daegu 704-701, Korea [email protected]

In the area of recent mobile phone applications, for example, the vector graphics facility such as SVG(scalable vector graphics)[1] and Flash Lite[2] become widely used due to their remarkable graphics features for variety of applications, as shown in Figure 1. This vector graphics facility basically requires geometric operations based on the floating-point number calculations. Since we should meet the problem of numerical errors and their accumulations for almost all types of geometric operations, they have tried to overcome these difficulties for several decades. As the results of various previous works, we already have some solutions such as symbolic computations, rational number computations, etc. We also know the epsilon geometry[3] to derive some numerical algorithms to pre-calculate the error ranges. All these theoretically excellent methods, however, cannot be efficiently used on the small-scale computing devices such as mobile phones, PDA’s, etc. In this paper, we show the difficulties in the numerical and geometric operations in the small-scale computing devices, and show that fixed-point number representations are more suitable for this purpose. And then, our theoretical calculations and experimental results show the errors in the typical geometric operations and their propagation models.

Introduction

Nowadays, multimedia contents can be displayed on the more and more small devices. Although small electronics devices such as PDA’s and mobile phones can display various multimedia contents, they still need to reduce required computing power. In this paper, we focused on a fundamental data representation model for real numbers. Most applications need to handle real number data. In contrast, as we know, real number computation usually requires relatively heavy computing power, and thus, most mobile devices are hard to use generic computational models for the real numbers. ∗ corresponding

author

2

Background

Along to the advances in the computer technology, the computing powers of mobile and small-scale devices have been rapidly upgraded. In these days, typical mobile phones have the following computing powers[4]: • • • •

200 to 500 MHz 32bit RISC CPU, without floating-point number co-processors, with more than 64MB RAM and with more than 512MB flash memory.

As an example of commercial products, ARM11 corebased CPU’s are now available, and they will include

Figure 2: Qm.n format

Figure 1: Application programs based on the vector graphics facility. floating-point co-processors into this CPU family in near future. However, the floating-point operations require more computing time, more resources, and more electric powers in comparison to the integer operations and its variations including the fixed-point operations. Thus, especially for small-scale computing devices, we prefer the fixed-point operations for real number calculations, if possible. In most computers, real number calculations are performed based on the floating-point number representation. The IEEE754 format is the international standard for the floating-point number representation, and consists of sign, mantissa and exponent parts, for each of 32bit and 64bit formats, resepectively[5]. Fixed-point number representations are originally based on the integer operations. For current mobile devices, 32bit integers are typically used for this representation. As shown in Figure 2, the fixed-point numbers are regarded to have the imaginary point in their representation. Since there are multiple choices for the location of this imaginary point, they usually denote the general fixed-point number representation format as Qm.n, which uses m-bit integer portion and n-bit fractional portion. The actual value of a number in Qm.n format can be calculated as follows[6]: value = B · 2−n =

(bm+n 2m+n + bm+n−1 2m+n−1 + · · · + b1 21 + b0 20 ) · 2−n

= bm+n 2m + bm+n−1 2m−1 + · · · + b1 2−n+1 + b0 2−n where B = (bm+n bm+n−1 · · · b1 b0 ) is the whole bit pattern in (m + n) bits. We can implement mathematical operations on the Qm.n format through combining integer operations as shown in Figure 3. In its actual implementation, intermediate results may easily show overflows, and many software implementations require 64bit internal registers to avoid potential overflows.

operation x+y x+a xa xy x/a a/b x/y sqrt(x)

code x+y x + (a  q) x∗a (x ∗ y)  q x/a (a  q)/b (x  q)/y integer sqrt(x  q)

x, y: fixed-point number, a, b: integer, q: exponent

Figure 3: Fixed-point numerical operations In the fixed-point number representation of Qm.n format, one of the most important factors is to decide the value of n, which is the number of bits in the fractional portion. Since most recent small-scale computing devices have 32bit architectures, we also focus on the 32bit machines. The SVG-tiny specification[1] is an international standard for mobile vector graphics, and uses Q16.16 format for internal calculations. In the case of ARM-based architectures, they encourages Q18.14 format especially for digital signal processing[6]. When we use n = 14 on a 32bit architecture, we can avoid potential numerical overflows for input values in the range of [−1.0, +1.0]. The choice of n value in Qm.n format results in various values of final errors, and additionally, the error propagation speed is also affected. Since the fixed-point number representation is not suitable for very large or very small real numbers, the choice of n value also affects the range of representable numerical values. For this reason, some fixed-point implementations, including Intel Graphics Performance Primitives library[7], allow the user to select the n values and thus the internal location of the imaginary binary point. In any case, we need to provide reasonable choices of n values. One of the most complex real value operations on small-scale devices would be the 2D and 3D graphics operations. Graphics pipelines typically include several coordinate transformations and the final pixel painting stage. Over the whole OpenVG graphics pipeline[8], the 3×3 or 4 × 4 matrix multiplication is the major operations to be carefully considered. In this paper, we focus on the matrix

multiplication processes to analyze the error propagation.

3

Error Estimation Model

In this section, we will investigate the reasonable choice of n values from a set of different view points.

3.1

Range of representable numbers

In the Qm.n format, the range of representable numerical values and operations are decided by the value of n. Using the minimum and maximum of these values, we can theoretically estimate the range of potential overflows. When the result of arithmetic operation goes out of the minimum and maximum ranges, there is an overflow or underflow. We can also calculate the minimum number of bits from the traditional situations as follows: • On the QVGA displays with 320 × 240 resolutions which are typical for most mobile p devices, to calculate the geometric distance of x2 + y 2 without any overflow, we need the n value of at least 13. In other words, Q19.13 will be the best choice considering the representable number ranges. • For real numbers in the range of [−1.0, +1.0], to calculate the squared sum of x2 + y 2 , without any overflow, there should be at least 14 bits in the fractional portion.

3.2

Transformations in graphics pipelines

Typical transformations in the graphics pipeline can be classified into three categories: translation, scaling and rotation[9]. As shown in Figure 3, addition and multiplication with integer values can be implemented using simple integer addition and integer multiplication, respectively. Thus, translation and scaling with integer values would be trivially implemented. In the case of rotation, we need trigonometric functions and 3 × 3 or 4 × 4 matrix multiplications. Thus, we mainly focus on the rotation from now on. As the first step, we calculated the ratio of numerical errors with respect to the number of fractional bits, n. As a real example, we choose a vector of (x, y) = (160, 120) which is exactly the half of the QVGA screen resolution. Now, this vector is rotated for each of uniform 90 samples from 0 to 89 degree, using the following equation:   cos θ sin θ (xnew , ynew ) = (x, y) − sin θ cos θ The rotated pixel position is compared to the result of 64bit floating point numerical calculation. We consider

Figure 4: Average error distance for various fractional portions.

Figure 5: Average error distance for a range of vectors. the error case as the case when final pixel positions are different from the exact position. We use the Manhattan distance to measure the error distance. The average distance for the whole cases are calculated, as shown in Figure 4. Analyzing the experimental results, for n values less than 7, they show more than 1 pixel error distance in average, and so, we should avoid these n values at least for reasonable rotations in the graphics pipeline. From the viewpoint of error distances, n values greater than 11 show ignorable error distances. As an extension of this experiment, we extended the initial vector to the range of (1, 1) to (320, 240), and rotate all these 76,800 cases to 0 to 89 degree. We also calculated the average error distance, as shown in Figure 5. Since the average error distance downs to less than 0.10 pixels, 15 or more fractional bits can be candidates for reasonable fixed-point formats. To examine more large magnitude vectors, we increases the input vector coordinates from (0, 0) to (1000, 1000) using the step size of 40. As shown in Figure 6, the vectors beyond (12, 12) shows numerical errors.

Figure 6: Average error distance for large magnitude vectors.

of the fixed-point format. To check the expected errors in a specific fixed-point number format, we established a set of situations and simulated the result of several choices of fractional bits. Our experimental results show that 16 bits are the most reasonable choice especially for the graphics pipeline applications. Since the matrix multiplication example is actually one of the most complex real-number calculations in most of multimedia applications, we expect that the 16 fractional bits would be also acceptable for most of other multimedia application programs. Though we have checked a variety of situations for the fixed-point calculations, we plan to check more complex cases and their experimental results. First, we will investigate the effect of optimization for fixed-point operations. As an example, for the Qm.n fixed-point numbers x, y and z, the operation of x ∗ y/z can be directly implemented as: (((x ∗ y)  n)  n)/z, where  and  are binary shift operations. This operation can be optimized as: (x ∗ y)/z,

Figure 7: Accumulated error distance for 720 degree rotation.

3.3

Accumulated errors

One of the major reasons for the significant errors is the repeated calculation. To measure the effect of repeated evaluations in the fixed-point format, we rotate the vector of (160, 120), 10 degree, for totally 72 times, to achieve 720 degree rotation. Figure 7 shows the result of accumulated errors after these sequences of rotations. As shown in Figure 7, the error distances are ignorable for 14 or more fractional bits. In some cases, the accumulated errors show some vibrations with respect to the exact locations. In some cases, the positive accumulated errors are canceled out by the following negative errors, and vice versa.

4

Conclusion

We need to select the effective fixed-point number representation format based on the various points of view, including usage, range of input data, required accuracy, etc. For efficient calculations on most mobile devices, they usually suggest 14 bits for general purpose or 16 bits for more accurate calculations, for the fractional portions

where the two binary shift operations are cancelled out. In this case, of course, we get the more efficient and more accurate result. As shown in this example, the optimization of the overall fixed-point equation is relatively important to other factors. We will focus on this factor in near future.

References [1] W3C SVG Workgroup, W3C: Scalable Vector Graphics (SVG) Tiny 1.2 Specification, Draft 13, (2005). [2] http://www.adobe.com/products/flashlite/ [3] L. Guibas, D. Selesin, J. Stolfi: “Epsilon Geometry: Building Robust Algorithms from Imprecise Computations”, ACM Ann. Symp. Comp. Geom., (1989). [4] ARM, ARM 926EJ-S Technical Reference Manual, (2004). [5] D. Hough, “Applications of the Proposed IEEE-754 Standard for Floating Point Arithmetic”, IEEE Computer, 14(3):70–74, (1981). [6] ARM, Fixed Point Arithmetic on the ARM, Application Note 33, (1996). [7] Intel, Intel Graphics Performance Primitives for Intel PCA with Intel Wireless MMX Technology, Ver.4, (2003). [8] Khronos Group, OpenVG Specification, Draft 0.8, (2005). [9] E. Angel, Interactive Computer Graphcis, 4th Ed., (2005).

Suggest Documents