1. Technical Field
The present invention relates generally to the data processing field and, more particularly, to a method, system and computer program product for converting an integer to a floating point value in a data processing system.
2. Description of Related Art
Floating point values are commonly used to represent real numbers on a computer. Many modern computer architectures, however, tend to be very slow when converting between integers and floating point values. For example, in data processing systems having a PowerPC architecture, conversion is accomplished by storing an integer value into a known pattern in memory, and then loading the result back as a floating point value. This conversion technique, referred to as a store/reload conversion technique, can be very time consuming as it involves memory traffic, and stores into only part of reloaded memory. With the PowerPC system, however, there is no faster way to convert a general integer to a floating point value.
Other computer architectures have direct conversion instructions, but may be costly in terms of chip area or time required to execute.
It would, accordingly, be advantageous to provide a mechanism, in a data processing system, for converting an integer to a floating point value that permits a reduction in both processing time and memory traffic.
The present invention provides a method, system and computer program product for converting an integer to a floating point value in a data processing system. The method utilizes data flow analysis and control flow analysis to recognize that a particular integer that is to be converted contains only a limited range of values. Knowledge of this limited range is used to establish a table of floating point values indexed by the integer value. By using the table of floating point values, conversion of an integer to a floating point value can be performed faster and with reduced memory traffic.
The novel features believed characteristic of the invention are set forth in the appended claims. The invention itself, however, as well as a preferred mode of use, further objectives and advantages thereof, will best be understood by reference to the following detailed description of an illustrative embodiment when read in conjunction with the accompanying drawings, wherein:
With reference now to the figures and in particular with reference to
With reference now to
An operating system runs on processor 202 and is used to coordinate and provide control of various components within data processing system 200 in
Those of ordinary skill in the art will appreciate that the hardware in
For example, data processing system 200, if optionally configured as a network computer, may not include SCSI host bus adapter 212, hard disk drive 226, tape drive 228, and CD-ROM 230. In that case, the computer, to be properly called a client computer, includes some type of network communication interface, such as LAN adapter 210, modem 222, or the like. As another example, data processing system 200 may be a stand-alone system configured to be bootable without relying on some type of network communication interface, whether or not data processing system 200 comprises some type of network communication interface. As a further example, data processing system 200 may be a personal digital assistant (PDA), which is configured with ROM and/or flash ROM to provide non-volatile memory for storing operating system files and/or user-generated data.
The depicted example in
The processes of the present invention are performed by processor 202 using computer implemented instructions, which may be located in a memory such as, for example, main memory 204, memory 224, or in one or more peripheral devices 226-230.
The present invention provides a mechanism for converting an integer to a floating point value using a data processing system such as data processing systems 100 and 200 illustrated in
In accordance with a preferred embodiment of the present invention, a method for converting an integer to a floating point value is provided that utilizes data flow analysis and control flow analysis to determine if a given integer that is to be converted has a relatively limited range of known values (i.e., to determine if the value of the integer must be one of a relatively small range of possible values). An example of such an integer is an integer used to subscript an array whose bounds range from 0 to 10. In many languages, it would be invalid or undefined to index the array with a value outside this limited range; and data flow and control flow analysis can be used to determine that the integer must fall somewhere within a known range.
If it is determined that the value of an integer must fall somewhere within a limited range, a table of floating point values is built in memory that is initialized with each of the possible integer values. The table is then used to more efficiently convert the integer to a floating point value.
The invention can be better understood by the following example.
Consider a C sample program fragment as follows:
Data flow analysis reveals that at the point of conversion, i must have a value between −1 and 8 in order for this to be a valid C program. A compiler/optimizer of the data processing system will build a table of floating point values in memory initialized with the values of −1.0, 0.0, 1.0, 2.0 . . . up to 8.0:
A determination is then made if there is an integer that is to be converted to floating point value (step 310). If there is an integer to be converted to floating point value (Yes output of step 310), a determination is made whether the conversion to be performed has a known integer range using information computed during the initial optimization performed in step 308 or from the semantics of the programming language (step 312). If the conversion to be performed does not have a known range (No output of step 312), the method returns to step 310 to determine whether there is another integer to be converted to a floating point value. If the conversion to be performed has a known range (Yes output of step 312), a determination is made if the known range of integer values is “small enough” to permit efficient conversion (step 314). If the known range of integer values is not small enough to permit efficient conversion (No output of step 314), the method returns to step 310 to determine if there is another integer to be converted to a floating point value. If the range of integer values is small enough to permit efficient conversion (Yes output of step 314), the table values and lower bound are calculated (step 316), and a table is created and the conversion expression is rewritten to use the table and the lower bound of the integer range (step 318).
After the table is created and the conversion expression is rewritten to use the table and the lower bound of the integer range for the integer, the method returns to step 310 to determine if there is another integer to be converted to a floating point value. The method continues to cycle back to step 310 until it is determined that there are no more integers to be converted to floating point values (No output of Step 310), at which time the process of converting from integer to floating point value ends (step 320).
Following creation of a table and rewriting of the conversion expression to use the table and the lower bound of the integer range for each conversion in which the range of integer values is small enough to permit efficient conversion, the compilation/optimization process is then completed (step 322), and an optimized program is output from compiler/optimizer 304 (step 324).
The determination in step 314 of whether a known range of integer values is small enough to permit efficient conversion is made because if the integer range becomes too large, the table will also be very large; and if the table is very large, the advantages of reduced conversion time and reduced memory traffic provided by the present invention may be lost. In such circumstances, it may be preferable to convert the integer to a floating point value using conventional conversion techniques. In accordance with a preferred embodiment of the present invention, a “small enough” range of legal integer values to permit efficient conversion of an integer to a floating point value is, for example, a range that has up to about 256 possible values, thus allowing an integer stored in an 8-bit byte to be efficiently converted to floating point.
When practicing the conversion method illustrated in
The present invention thus provides a method, system and computer program product for converting an integer to a floating point value in a data processing system. The method utilizes data flow analysis and control flow analysis to recognize that a particular integer that is to be converted contains only a limited range of values. Knowledge of this limited range is used to establish a table of floating point values indexed by the integer value. By using the table of floating point values, conversion of an integer to a floating point value can be performed faster and with reduced memory traffic.
It is important to note that while the present invention has been described in the context of a fully functioning data processing system, those of ordinary skill in the art will appreciate that the processes of the present invention are capable of being distributed in the form of a computer readable medium of instructions and a variety of forms and that the present invention applies equally regardless of the particular type of signal bearing media actually used to carry out the distribution. Examples of computer readable media include recordable-type media, such as a floppy disk, a hard disk drive, a RAM, CD-ROMs, DVD-ROMs, and transmission-type media, such as digital and analog communications links, wired or wireless communications links using transmission forms, such as, for example, radio frequency and light wave transmissions. The computer readable media may take the form of coded formats that are decoded for actual use in a particular data processing system.
The description of the present invention has been presented for purposes of illustration and description, and is not intended to be exhaustive or limited to the invention in the form disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art. The embodiment was chosen and described in order to best explain the principles of the invention, the practical application, and to enable others of ordinary skill in the art to understand the invention for various embodiments with various modifications as are suited to the particular use contemplated.