Apparatus and method for converting data between a floating-point number and an integer

An apparatus and method for converting data between a floating-point number and an integer is provided. The apparatus includes a data converter configured to determine a sign of input binary data and an output format to which to convert the input binary data and convert the input binary data into a one's complement number based on the sign and the output format of the input binary data, a bias value generator configured to determine whether the input binary data has been rounded up based on a rounding mode of the input binary data and generate a bias value accordingly; and an adder configured to convert the input binary data into a two's complement number by adding the one's complement number and the bias value.

CROSS-REFERENCE TO RELATED APPLICATION(S)

This application claims the benefit under 35 U.S.C. §119(a) of Korean Patent Application No. 10-2010-0114565, filed on Nov. 17, 2010, in the Korean Intellectual Property Office, the entire disclosure of which is incorporated herein by reference for all purposes.

BACKGROUND

The following description relates to the conversion of binary data, and, more particularly, to an apparatus and method capable of incorporating rounding and two's complementation during the conversion of data.

2. Description of the Related Art

In computing, binary data is used to represent various numeric values using different combinations of ones and zeros. Binary data can be represented in various formats. For example, floating-point units (FPUs) process binary data represented in a floating-point number format. Thus, in order for FPUs to process binary data represented in an integer or fixed-point number format, the binary data needs to be converted into a floating-point number.

Floating-point binary data is represented as a sign magnitude number, in which the most significant bit indicates whether the represented value is positive or negative, whereas integer binary data or fixed-point binary data is represented as a two's complement number, which allows for simple addition of values by encoding negative numbers into ordinary binary. Therefore, in order to convert binary data between a floating-point number and an integer, a rounding module and a two's complement module are both required. For example, a floating-point number is converted into a two's complement integer by adding one to the floating-point number if the floating-point number is rounded up, and adding one to the one's complement of the floating-point number.

Conventionally, two adders (i.e., one adder for adding one to a floating-point number if the floating-point number is rounded up and the other for adding one to the one's complement of the floating-point number) are required to realize a floating-point number-to-integer converter.

SUMMARY

The following description relates to an apparatus and method for converting data between a floating-point number and an integer, which effectively incorporates rounding and two's complementation during the conversion of data between a floating-point number and an integer.

In one general aspect, there is provided an apparatus for converting data between a floating-point number and an integer, the apparatus including a data converter configured to determine a sign of input binary data and an output format to which to convert the input binary data and convert the input binary data into a one's complement number based on the sign and the output format of the input binary data, a bias value generator configured to determine whether the input binary data has been rounded up based on a rounding mode of the input binary data and generate a bias value accordingly, and an adder configured to convert the input binary data into a two's complement number by adding the one's complement number and the bias value.

The data converter may be further configured to convert the input binary data into the one's complement number in response to the output format of the input binary data being a negative integer format.

The bias value generator may include a rounding information generator configured to generate rounding information on the input binary data based on the sign, the output format, and the rounding mode of the input binary data and rounding and sticky bits of the input binary data, and a bias value calculator configured to calculate the bias value based on the rounding information.

The apparatus may further include an overflow information generator configured to generate overflow information indicating whether overflow has occurred during the conversion of the input binary data.

The overflow information generator may include a bit determiner configured to determine whether bits of the input binary data are all one, an overflow determiner configured to determine whether overflow has occurred based on values of the bits of the input binary data and the rounding information.

The apparatus may further include a final data generator configured to generate final data based on the two's complement number and the overflow information.

The input binary data may be 32- or 64-bit binary data.

In another general aspect, there is provided a method of converting data between a floating-point number and an integer, the method including determining a sign of input binary data and an output format to which to convert the input binary data and convert the input binary data into a one's complement number based on the sign and the output format of the input binary data; determining whether the input binary data has been rounded up based on a rounding mode of the input binary data and generating a bias value accordingly, and converting the input binary data into a two's complement number by adding the one's complement number and the bias value.

The calculating the bias value may include generating rounding information on the input binary data based on the sign, the output format, and the rounding mode of the input binary data and rounding and sticky bits of the input binary data, and calculating the bias value based on the rounding information.

The method may further include generating overflow information indicating whether overflow has occurred during the conversion of the input binary data.

The generating the overflow information may include determining whether bits of the input binary data are all one, and determining whether overflow has occurred based on values of the bits of the input binary data and the rounding information.

The method may further include generating final data based on the two's complement number and the overflow information.

In another general aspect, there is provided an apparatus to convert input binary data, the apparatus including a data converter configured to convert the input binary data into a one's complement number, a bias value generator configured to generate a bias value of the input binary data, and an adder configured to add the one's complement number and the bias value to obtain a two's complement number.

The data converter may convert the input binary data into the one's complement number according to a sign of the input binary data and an output format to which to convert the input binary data.

The bias value generator may determine whether the input binary data has been rounded up based on a rounding mode of the input binary data, and may generate the bias value accordingly.

In another general aspect, there is provided a method of converting input binary data, the method including converting the input binary data into a one's complement number, generating a bias value of the input binary data, and adding the one's complement number and the bias value to obtain a two's complement number.

The converting of the input binary data into the one's complement number may be executed according to a sign of the input binary data and an output format to which to convert the input binary data.

The generating of the bias value may include determining whether the input binary data has been rounded up based on a rounding mode of the input binary data, and generating the bias value accordingly.

DETAILED DESCRIPTION

FIG. 1illustrates an example of an apparatus100for converting data between a floating-point number and an integer. Referring toFIG. 1, this example of the apparatus100includes a data converter110, a bias value generator130, an adder150, an overflow information generator170, and a final data generator190.

The data converter110may include a logic device for calculating the one's complement of binary data. In response to input binary data being received, the data converter110may determine the sign of the input binary data based on a most significant bit of the input binary data, and may determine the format (hereinafter referred to as the output format) to which to convert the input binary data. The output format of the input binary data may already be determined internally. For example, if the data converter110is a floating-point number-to-integer converter, the input binary data may be a floating-point number, and the output format of the input binary data may be an integer format. The internal precision of the input binary data will hereinafter be described in greater detail with reference toFIG. 2.

FIG. 2illustrates an example of the internal precision of input binary data. Referring toFIG. 2, a most significant bit of the input binary data, which is the leftmost bit in this example, indicates the sign of the input binary data. If the most significant bit is 0, the input binary data is a positive number. On the other hand, if the most significant bit is one, the input binary data is a negative number. Two least significant bits of the input binary data, which are the rightmost bits in this example, are a rounding bit and a sticky bit. The rounding bit and the sticky bit are used to determine a bias value based on the sign of the input binary data and a rounding mode. The rest of the input binary data, that is, the values between the most significant bit and the two least significant bits, represents the value of the input binary data. In the example illustrated inFIG. 2, the value of the input binary data is represented by 64 bits, but other examples may employ 32 bits, and so on.

According to an IEEE 754 standard, which is an internal standard for floating-point arithmetic, a single precision number is defined as a 32-bit number, and a double precision number as a 64-bit number. Therefore, the apparatus100may represent the input binary data as 67 or more-bit data (including an MSB and an LSB along with the 64 bits representing the value of the number). In an example in which the input binary data is converted from a floating-point number to an integer, the input binary data may be arranged in increasing order of significance. On the other hand, in an example in which the input binary data is converted from an integer to an integer, the input binary data may be arranged in decreasing order of significance.

Referring back toFIG. 1, the data converter110may determine whether to convert the input binary data to a one's complement number based on the sign of the input binary data and the output format of the input binary data. If the input binary data is a floating-point number, the input binary data may be represented as a sign-magnitude value. On the other hand, if the input binary data is an integer or a fixed point number, the input binary data may be represented as a two's complement number. The sign magnitude or two's complement of the input binary data is closely related to the one's complement of the input binary data. The one's complement of a negative number may be the inverse of the sign magnitude of the negative number. For example, sign magnitude numbers of 1000, 1001, and 1010 represent integers of −0, −1, and −2, respectively, whereas one's complement numbers of 1000, 1001, and 1010 represent integers of −7, −6, and −5, respectively. In other words, although the four bits in these examples may be the same, different values are represented according to whether the input binary data are sign magnitude numbers or one's complement numbers.

The two's complement of the input binary data is obtained by adding one to the one's complement of the sign magnitude of the input binary data. For example, the one's complement of a sign magnitude number of 1010 is 0101, and the two's complement of the sign magnitude number of 1010 is 0110, which is the result of adding one to 0101. A one's complement number of 1010 represents an integer of −5, and a two's complement number of 1010 represents an integer of −6. If the input binary data needs to be converted into negative integer data, the data converter110may convert the input binary data to a one's complement number. That is, if the input binary data is a floating-point number, the data converter110needs to convert the input binary data into a one's complement number to convert the input binary data into an integer.

If the input binary data is an integer, the data converter110may output the input binary data to the adder150without converting the input binary data into a one's complement number.

The input binary data that is input into the data converter110is also input into the bias value generator130. The bias value generator130performs rounding and includes a calculation module to calculate a bias value of the input binary data. The bias value generator130determines a rounding mode of the input binary data and determines whether the input binary data has been rounded up in the determined rounding mode. The bias value generator130generates a bias value based on information indicating whether the input binary data has been rounded up, and outputs the generated bias value to the adder150.

The bias value generator130may include a rounding information generator131and a bias value calculator133. The rounding information generator131generates rounding information on the input binary data based on the output format, the sign, the rounding mode, and the rounding and sticky bits of the input binary data. The output format and the rounding mode of the input binary data may be set in advance. Examples of the rounding mode of the input binary data include, but are not limited to, four rounding modes specified in the IEEE 754 standard.

The IEEE 754 standard defines the following four rounding modes: round to nearest, round to zero, round to positive infinity, and round to negative infinity. In the ‘round to zero’ mode, the input binary data is rounded to zero regardless of the rounding and sticky bits thereof. In the ‘round to positive infinity’ mode, the input binary data is rounded up if the input binary data is a positive number and at least one of the rounding and sticky bits of the input binary data is one. In the ‘round to negative infinity’ mode, the input binary data is rounded up if the input binary data is a negative number and at least one of the rounding and sticky bits of the input binary data is one.

The bias value calculator133may receive the rounding information on the input binary data from the rounding information generator133. The rounding information on the input binary data includes the sign, the rounding mode, and the rounding and sticky bits of the input binary data. The bias value calculator133calculates a bias value based on the rounding information on the input binary data. Various bias values for various rounding modes will hereinafter be described in detail with reference toFIGS. 3A through 3H.

FIGS. 3A through 3Hillustrate examples of bias value tables for various rounding modes. More specifically,FIGS. 3A through 3Dillustrate examples of bias value tables for reference in the conversion of the input binary data from a floating-point number to an integer (or a fixed-point number) for the ‘round to positive infinity,’ ‘round to negative infinity,’ ‘round to zero,’ and ‘round to nearest even’ modes, respectively.

For example, referring toFIG. 3A, if the rounding information of the input binary data indicates that the rounding and sticky bits of the input binary data are10, that the input binary data is a positive number, and that the rounding mode of the input binary data is the ‘round to positive infinity’ mode, the bias value for the input binary data may be one. Therefore, the input binary data may be converted into a one's complement number of 0001 by the data converter110, and may then be converted into a two's complement number of 0010 obtained by adding the bias value of 1 to the one's complement number of 0001.

FIGS. 3E through 3Hillustrate examples of bias value tables for reference in the conversion of the input binary data from an integer to a floating-point number for the ‘round to positive infinity,’ ‘round to negative infinity,’ ‘round to zero,’ and ‘round to nearest even’ modes, respectively.

For example, referring toFIG. 3F, if the rounding information of the input binary data indicates that the rounding and sticky bits of the input binary data are11, that the input binary data is a negative number, and that the rounding mode of the input binary data is the ‘round to negative infinity’ mode, the bias value for the input binary data may be one. Therefore, the input binary data may be rounded up, and may be converted into a one's complement number of 0001 by the data converter110, and may then be converted into a two's complement number of 0010 obtained by adding the bias value of 1 to the one's complement number of 0001.

Referring back toFIG. 1, the adder150includes a logic device that adds two input values together. The adder150is connected to the data converter110and the bias value generator130. Therefore, the adder150may receive two values of input data: one from the data converter110, and the other from the bias value generator130.

The apparatus100is characterized by including only one adder150. Conventionally, two adders (i.e., one adder for adding one to binary data in a case in which the binary data is rounded up, and the other for converting the one's complement of the binary data into a two's complement number) are required to convert binary data in a typical apparatus. However, since, in the apparatus100, the bias value generator130generates a bias value that is necessary for converting the input binary data into a two's complement number by taking into consideration whether the input binary data has been rounded up, the adder150can generate a two's complement number simply by adding a one's complement number provided by the data converter110and the bias value provided by the bias value generator130. Thus, the apparatus100requires only one adder, i.e., the adder150to convert the input binary data.

The input binary data is also input into the overflow information generator170. The overflow information generator170determines whether overflow has occurred during the conversion of the input binary data. The overflow information generator170in the example illustrated inFIG. 1includes a bit determiner171and an overflow determiner173. The internal precision of the bit determiner171includes a number of bits whose values are all one. The bit determiner171adds the bits whose values are all 1 to the input binary data. The overflow determiner173is connected to the bit determiner171and the rounding information generator131. The overflow determiner173determines whether overflow has occurred during the conversion of the input binary data.

More specifically, if the input binary data is a floating-point number, a positive integer, or a fixed-point number, and the bits of the input binary data are all one, the rounding up of the input binary data exceeds a maximum number of bits that can be represented, and, thus, overflow occurs. On the other hand, if the input binary data is a negative integer or a fixed-point number, overflow does not occur even when the bits of the input binary data are all one. In this manner, the overflow determiner173may determine whether overflow has occurred during the conversion of the input binary data.

The overflow information generator170performs post-normalization. Normalization is the process of aligning the positions of bits of data. Generally, normalization is performed twice, once before and once during the conversion of data. The overflow information generator170outputs overflow information indicating whether overflow has occurred during the conversion of the input binary data, and also outputs overflow data whose bits are all zero if it is determined that overflow has occurred during the conversion of the input binary data.

The final data generator190may include a multiplexer selecting one of multiple input data values. The final data generator190may be connected to the adder150and the overflow information generator170. The final data generator190may receive the overflow information and the overflow data from the overflow information generator170. Also, the final data generator190may receive the two's complement number provided by the adder150.

If it is determined that no overflow has occurred during the conversion of the input binary data, the final data generator190may output the two's complement number provided by the adder150as final data. On the other hand, if it is determined that overflow has occurred during the conversion of the input binary data, the final data generator190may output the overflow data provided by the overflow information generator170as the final data.

FIG. 4illustrates an example of a method of converting data between a floating-point number and an integer. Referring toFIG. 4, the sign and the output format of input binary data are determined, and the input binary data is converted into a one's complement number in operation410. The input binary data may have the internal precision illustrated inFIG. 2. In this case, the sign of the input binary data may be determined based on the most significant bit of the input binary data. The output format of the input binary data may be a floating-point format or an integer format (or a fixed-point format).

The input binary data may be converted into a one's complement number if the output format of the input binary data is a negative integer format. Otherwise, the conversion of the input binary data into a one's complement number may not be performed.

Thereafter, in operation420, it is determined whether the input binary data has been rounded up based on the rounding mode of the input binary data, and a bias value is generated based on the results of the determination. More specifically, the rounding mode of the input binary data may be determined in advance, and it may be determined whether the input binary data has been rounded up based on the sign and the rounding and sticky bits of the input binary data. The bias value may be generated based on rounding information on the input binary data.

Thereafter, in operation430, the one's complement number obtained in operation410and the bias value obtained in operation420are added together, thereby converting the input binary data into a two's complement number.

In short, the input binary data can be converted into a two's complement number obtained by converting the input binary data into a one's complement number, and adding a bias value obtained based on the rounding mode of the input binary data to the one's complement number.

A computing system or a computer may include a microprocessor that is electrically connected with a bus, a user interface, and a memory controller. It may further include a flash memory device. The flash memory device may store N-bit data via the memory controller. The N-bit data is processed or will be processed by the microprocessor and N may be 1 or an integer greater than 1. Where the computing system or computer is a mobile apparatus, a battery may be additionally provided to supply operation voltage of the computing system or computer.

It should be apparent to those of ordinary skill in the art that the computing system or computer may further include an application chipset, a camera image processor (CIS), a mobile Dynamic Random Access Memory (DRAM), and the like. The memory controller and the flash memory device may constitute a solid state drive/disk (SSD) that uses a non-volatile memory to store data.