Configuring floating point operations in a programmable device |
|||||||
申请号 | US12625800 | 申请日 | 2009-11-25 | 公开(公告)号 | US08650231B1 | 公开(公告)日 | 2014-02-11 |
申请人 | Martin Langhammer; | 发明人 | Martin Langhammer; | ||||
摘要 | A programmable device is programmed to perform arithmetic operations in an internal format that, unlike known standard formats that store numbers in normalized form and require normalization after each computational step, stores numbers in unnormalized form and does not require normalization after each step. Numbers are converted into unnormalized form at the beginning of an operation and converted back to normalized form at the end of the operation. If necessary to avoid data loss, a number may be normalized after an intermediate step. To conserve resources, rather than configuring the every intermediate operation to have the same mantissa size, in the internal format the mantissa size may start out smaller and grow after each operation. | ||||||
权利要求 | What is claimed is: |
||||||
说明书全文 | This is a continuation-in-part of copending, commonly-assigned U.S. patent application Ser. No. 11/625,655, filed Jan. 22, 2007, which is hereby incorporated by reference herein in its entirety. This invention relates to performing floating point arithmetic operations in programmable devices, such as programmable logic devices (PLDs), including the use of specialized processing blocks, which may be included in such devices, to perform floating point operations. As applications for which PLDs are used increase in complexity, it has become more common to design PLDs to include specialized processing blocks in addition to blocks of generic programmable logic resources. Such specialized processing blocks may include a concentration of circuitry on a PLD that has been partly or fully hardwired to perform one or more specific tasks, such as a logical or a mathematical operation. A specialized processing block may also contain one or more specialized structures, such as an array of configurable memory elements. Examples of structures that are commonly implemented in such specialized processing blocks include: multipliers, arithmetic logic units (ALUs), barrel-shifters, various memory elements (such as FIFO/LIFO/SIPO/RAM/ROM/CAM blocks and register files), AND/NAND/OR/NOR arrays, etc., or combinations thereof. One particularly useful type of specialized processing block that has been provided on PLDs is a digital signal processing (DSP) block, which may be used to process, e.g., audio signals. Such blocks are frequently also referred to as multiply-accumulate (“MAC”) blocks, because they include structures to perform multiplication operations, and sums and/or accumulations of multiplication operations. For example, PLDs sold by Altera Corporation, of San Jose, Calif., under the family name STRATIX® includes DSP blocks, each of which includes a plurality of multipliers (e.g., four 18-bit-by-18-bit multipliers). Each of those DSP blocks also includes adders and registers, as well as programmable connectors (e.g., multiplexers) that allow the various components to be configured in different ways. In each such block, the multipliers can be configured not only as individual multipliers, but also as four smaller multipliers, or as one larger multiplier (e.g., one 36-bit-by-36-bit multiplier in the case of four 18-bit-by-18-bit multipliers). In addition, e.g., one complex multiplication (which decomposes into two multiplication operations for each of the real and imaginary parts) can be performed. In order to support four 18-bit-by-18-bit multiplication operations, a block in a member of the aforementioned STRATIX® device family may have 4×(18+18)=144 inputs. Similarly, the output of an 18-bit-by-18-bit multiplication is 36 bits wide, so to support the output of four such multiplication operations, such a block would have 36×4=144 outputs. The arithmetic operations to be performed by a PLD frequently are floating point operations. However, to the extent that known PLDs, with or without DSP blocks or other specialized blocks or structures, including the aforementioned STRATIX® family of PLDs, can perform floating point operations at all, they operate in accordance with the IEEE754-1985 standard, which requires that values be normalized at all times because it implies a leading “1”. However, that leads to certain inefficiencies as described below. The present invention relates to programmable devices having improved floating point operation capabilities. In particular, the present invention carries out floating point operations without normalization, although the results may be normalized if IEEE754-1985 compliance is required. In addition, normalization may be performed in intermediate steps if loss of data might otherwise result. Therefore, in accordance with the present invention, there is provided a method of configuring a programmable device to perform floating point operations on input values formatted in accordance with a standard requiring a first mantissa size and a first exponent size. The method includes configuring logic of the programmable device to reformat the input values to have an initial mantissa size different from the first mantissa size. Logic of said programmable device also is configured to perform a tree of successive operations to compute a final result. Each respective operation in a first level of the tree of successive operations has a first number of the reformatted input values as inputs and provides a respective first intermediate result having a mantissa size increased by at least one bit left of its binal point as compared to the initial mantissa size. Each operation in a respective successive level of the tree of successive operations after the first level of said tree of successive operations, other than a final level, has the first number of inputs and provides a respective intermediate result and the final level provides the final result. Each of the respective intermediate results and the final result is unnormalized and has a mantissa size increased by at least one bit left of its binal point as compared to an intermediate result on an immediately preceding level. Logic of the programmable device also is configured to reformat the result in accordance with the standard to the first mantissa size. A programmable device so configured, and a machine-readable data storage medium encoded with software for performing the method, are also provided. The above and other objects and advantages of the invention will be apparent upon consideration of the following detailed description, taken in conjunction with the accompanying drawings, in which like reference characters refer to like parts throughout, and in which: Floating point numbers are commonplace for representing real numbers in scientific notation in computing systems. Examples of real numbers in scientific notation are:
The first two examples are real numbers in the range of the lower integers, the third example represents a very small fraction, and the fourth example represents a very large integer. Floating point numbers in computing systems are designed to cover the large numeric range and diverse precision requirements shown in these examples. Fixed point number systems have a very limited window of representation which prevents them from representing very large or very small numbers simultaneously. The position of the notional binary-point in fixed point numbers addresses this numeric range problem to a certain extent but does so at the expense of precision. With a floating point number the window of representation can move, which allows the appropriate amount of precision for the scale of the number. Floating point representation is generally preferred over fixed point representation in computing systems because it permits an ideal balance of numeric range and precision. However, floating point representation requires more complex implementation compared to fixed point representation. The IEEE754-1985 standard is commonly used for floating point numbers. A floating point number includes three different parts: the sign of the number, its mantissa and its exponent. Each of these parts may be represented by a binary number and, in the IEEE754-1985 format, have the following bit sizes: The exponent preferably is an unsigned binary number which, for the single precision format, ranges from 0 to 255. In order to represent a very small number, it is necessary to use negative exponents. To achieve this the exponent preferably has a negative bias associated with it. For single-precision numbers, the bias preferably is −127. For example a value of 140 for the exponent actually represents (140-127)=13, and a value of 100 represents (100-127)=−27. For double precision numbers, the exponent bias preferably is −1023. As discussed above, according to the standard, the mantissa is a normalized number—i.e., it has no leading zeroes and represents the precision component of a floating point number. Because the mantissa is stored in binary format, the leading bit can either be a 0 or a 1, but for a normalized number it will always be a 1. Therefore, in a system where numbers are always normalized, the leading bit need not be stored and can be implied, effectively giving the mantissa one extra bit of precision. Therefore, in single precision format, the mantissa typically includes 24 bits of precision. However, the IEEE754-1985 standard requires continuous normalization—i.e., normalization after every step of a multistep computation—to maintain the leading “1” to preserve accuracy. This is expensive in terms of PLD resources, as each normalization operation requires two steps—(1) finding the position of the “1”, and (2) shifting the fractional part to get a leading “1” (which is then eliminated, because it is implied). In accordance with the invention, there is no implied leading “1”, so that normalization is not required. Although this requires that one bit of precision be given up, because all bits must be kept, rather than implied, this greatly reduces the required logic, particularly shifting logic, and therefore the latency of the floating point operations. Moreover, in a PLD that already has dedicated arithmetic circuits, such as multipliers and/or adders, that are capable of handling the extra bits, there is no additional cost in terms of logic resources to handle those extra bits. Preferably, the floating point representation in accordance with the invention uses a signed fractional component, with greater precision. Some operations may be configured in general-purpose logic of the programmable logic device. However, multiplication, at least, is more efficiently performed in a dedicated multiplier such as may be available in the aforementioned DSP block. The extra precision in accordance with the invention requires large multipliers, which heretofore have consumed more resources than the shifting logic required for normalization. However, in the aforementioned STRATIX® II PLDs, as well as those described in copending, commonly-assigned U.S. patent application Ser. Nos. 11/447,329, 11/447,370, 11/447,472 and 11/447,474, all filed Jun. 5, 2006, 11/426,403, filed Jun. 26, 2006, and 11/458,361, filed Jul. 18, 2006, each of which is hereby incorporated herein in its respective entirety, large dedicated multipliers are available, and are more efficient than shifting logic. This allows the efficient use of a signed fractional component. Specifically, according to a preferred method according to the invention for configuring a programmable logic device to perform floating point operations, the programmable logic device preferably is configured so that floating point values in accordance with a first format, such as the IEEE754-1985 standard format, preferably are converted to an internal format for calculation purposes, and are reconverted to the standard format upon completion of the operations. Whereas the IEEE754-1985 standard format includes a 24-bit unsigned mantissa (23 bits plus the implied “1”) and an 8-bit exponent, the internal format according to the invention preferably includes a 32-bit signed mantissa and a 10-bit exponent. When converting from the standard 24-bit format to the 32-bit format of the invention, the implied leading “1” of the mantissa is made explicit and preferably is initially positioned at the 28th bit location. This leaves the four most significant bits of the 32-bit number available for overflows as operations progress. For example, 16 additions could be performed before any overflow would consume all four bits. Similarly, because the original standard representation is only 24 bits wide, the four least significant bits also are available for any underflows that may occur. If this method is implemented on the aforementioned STRATIX® II PLD, or on a PLD of any of the above-incorporated patent applications, which include DSP blocks capable of 36-bit multiplications, then the multiplications of the 32-bit mantissas can be accomplished within the 36-bit dedicated multipliers, making the multipliers more efficient. Moreover, the mantissa size could be expanded to 36 bits if necessary or desired. However, the invention could be implemented even where no dedicated multipliers are available, using programmed general-purpose logic. Moreover, if dedicated multipliers are available, but are only large enough for IEEE754-1985-compliant operations, computations other than multiplications could be performed in programmed general-purpose logic, with the multiplications being performed in the dedicated multipliers. In such a case, the values would have to be renormalized before each multiplication step, but would not have to be normalized for other steps either before or after a multiplication step, except at the end of the operation. As stated above, preferably, and ordinarily, during floating point operations in accordance with the invention, the operands remain in the format according to the invention, and are converted back to their original format only upon completion of operations. Because of the initial presence of the leading and trailing bits, as well as the larger exponent size, during operations it is possible to continue beyond conditions that might have led to overflows or underflows in the original format, because of the possibility that the accumulation of further results may reverse the overflow or underflow condition. However, if during operation the accumulation of underflows or overflows reaches the point that information may be lost—e.g., there would be an overflow if the data were converted back to the standard format, or an underflow would be approached such that fewer than three significant bits beyond the required mantissa precision (i.e., in this example, fewer than 1+23+3=27 bits) would remain—it may be desirable in accordance with the invention to normalize the data at an intermediate step to prevent lost of precision. In such a case, subsequent operations preferably would not include further normalization until the final result is achieved (unless a condition again arises in which data may be lost). Alternatively, if overflow or underflow is likely (e.g., there will be many operations in a calculation), then the start position of the mantissa can be changed from the 28th bit position to another position (to the right to prevent overflows; to the left to prevent underflows). The correct result can be maintained by adjusting the exponents accordingly. The larger exponent size (10 bits instead of 8 bits) allows room for the necessary exponent adjustments. The examples that follow illustrate configurations, in accordance with the invention, of a programmable logic device to perform a number of different arithmetic operations. For simplicity, these examples do not show pipelining between stages, nor do they show circuitry for handling special cases, such as zero, infinity or not-a-number (NAN) situations. The examples include conversions in both directions between the format of the IEEE754-1985 standard and the internal format according to a preferred embodiment of this invention. Preferred embodiments of those conversions are illustrated in As shown in Sign bit 110 and 23-bit-wide mantissa 111 (carrying 24 bits of precision) convert to four sign bits 122 and 24-bit mantissa portion 123 with the aid of exclusive-OR (XOR) 124. Four trailing bits 125 (because again the value cannot change in the conversion) are added to provide 32-bit mantissa 120. The trailing bits are zeroes for positive numbers, and ones for negative numbers (which are inverted). The operation of XOR 124 preferably is as follows: If sign bit 110 is a “0”, then XOR 124 has no effect. If sign bit 110 is a “1” (signifying a negative number), then XOR 124 inverts the mantissa—i.e., it converts the mantissa to a one's-complement number. The actual computation requires a two's-complement number. The one's-complement number can be converted to a two's-complement number by adding a “1” to the least significant bit of the one's-complement number. An adder can be provided as part of each conversion 10. However, such adders are very large, and because the precision of the mantissa in the format according to the present invention is greater than that of the IEEE754-1985 mantissa, it is also possible to omit this addition completely without significantly affecting the result. As a third alternative, a single adder can be provided after a group of conversions 10, which adds to the result a number equal to the total number of negative numbers within that group of conversions 10. For example, if in an addition of eight numbers (meaning there are eight conversions), five of those numbers are negative, the value 510 (1012) can be added to the one's-complement result to give the two's-complement result. This becomes more complicated in the case of multiplications, but can still be used where there is a local cluster of operations. In ALU 33, operating in the internal format, is simpler than a corresponding ALU operating in the IEEE754-1985 standard format because it does not have include the shifting logic needed to deal with the implied leading “1” and therefore is about half the size of a standard-format ALU. However, conversion 34 adds about the same amount of logic as ALU 33, while conversions 31, 32 add a negligible amount of logic. Therefore, in this simple example of adding two numbers, the net result is approximately the same under either format in terms of circuit size and latency, because one standard-format ALU is replaced with two blocks each about half the size of the standard-format ALU. As in case 30, each of conversions 41-44 adds negligible logic, while each of ALUs 45-47, as well as conversion 34, adds half the logic of a standard-format ALU. Using the standard format, the operation of case 40 could have been performed with three standard-format ALUs, while in case 40, it is performed with four blocks (three ALUs 45-47 and conversion 34) approximating in total the size of two standard-format ALUs. Thus, the circuit is about two-thirds the size using the format according to the invention as compared to the standard format. According to another aspect of the invention, instead of having a fixed internal format, with a fixed mantissa size, the mantissa size is adjusted for each step of a calculation. A normalized mantissa represents a magnitude of between 1.010 and 1.999 . . . 9910 at some given exponent. The number with the smaller exponent is has its mantissa (including the leading “1”) right shifted by the difference between the two exponents. If the exponents are the same, then there is no shift. As a consequence, for two-input operations, the largest unnormalized mantissa at any node can be 3.99999, while the smallest can be 0 (the subtraction of two equal numbers). 3.999 . . . 999 in binary 11.11111 . . . 1112. If two of these unnormalized numbers were added, the maximum result would be 7.9999 . . . 999910, represented in binary as 111.111 . . . 1112. A tree of 16 numbers would have a maximum value of 31.999 . . . 99910, or 11111.111 . . . 1112. In signed magnitude format, there will be an additional bit to represent the sign. Thus, for a multi-level addition using a binary tree (i.e., a tree of two-input adders), the mantissa size at the first, input, level is set according to the expected input values. At each level, the number of bits at the most-significant end—i.e., to the left of the “binal” point (the binary equivalent of a decimal point, separating places signifying values less than 1 from places signifying values greater than or equal to 1)—is increased by 1. Starting with a normalized input, with one bit to the left of the binal point (or two bits if there is a sign bit), at the first level and performing the first-level additions, the number of bits in the second-level input to the left of the binal point if there is no further normalization would be two (or three if there is a sign bit). After the second-level additions, there would be three (or four) bits to the left of the binal point in the third-level inputs. At the inputs to the nth level, then, the number of bits of wordgrowth as compared to the inputs to first level (n=1), is n−1. For multi-input adders, the number of bits of wordgrowth at each level may be greater. Generally, if the “base,” or number of inputs per adder, is m, then when m is a power of 2, the number of bits of wordgrowth per level is m/2. However, if the base is not a power of 2, the number of bits of wordgrowth will be irregular (although on average it may be m/2). For example, if using four-input adders (a “quaternary” tree), the number of bits of wordgrowth would be 2 per level. However, if using, e.g., three-input adders (a “ternary” tree), the number of bits of wordgrowth would be 2 per level in some cases and 1 per level in other cases. Specifically, a three-input adder has three inputs, each of which may have a maximum value of 1.999910. Therefore, the output of each first level adder has a maximum value of 3×1.999910=5.999910 which requires 3 bits to the left of the binal point in binary representation, or 2 bits of growth over the input level. At the next level, the inputs have a maximum value of 5.999910, so with three inputs the maximum output value would be 3×5.999910=17.999910, which requires 5 bits to the left of the binal point in binary representation, or again 2 bits of growth over the previous level. At the level after that, the inputs have a maximum value of 17.999910, so with three inputs the maximum output value would be 3×17.999910=53.999910, which requires 6 bits to the left of the binal point in binary representation, or in this case only 1 bit of growth over the previous level. To generalize, then, for a base m, the number of bits at the nth level would be ceil(log2(mn)), meaning that the wordgrowth to the left of the binal point at the nth level, as compared to the (n−1)st level, is ceil(log2(mn)−ceil(log2(mn-1). And for an n-level tree of adders having a total of M inputs, regardless of base, the total wordgrowth to the left of the binal point over the entire tree would be ceil(log2M)−1. Taking the example of binary tree 700 shown in In that example, each input 711 has two bits (including one sign bit) to the left of the binal point 740, second level result 721 has three bits to the left of the binal point 740, and third-level result 731 has four bits to the left of the binal point 740, for an increase, for the tree as a whole, of two bits, over the number of bits in the input level. This is expected, insofar as ceil(log2(3))=ceil(1.585)=2. The foregoing increases in mantissa size to the left of the binal point prevent overflow. On the other hand, increases in mantissa size to the right of the binal point are generally more flexible, based on the user's tolerance for underflow (i.e., tolerance for loss of data as values become so small that they underflow to zero because of insufficient mantissa size to the right of the binal point) or the user's tolerance for bit cancellation (i.e., the loss of data when numbers very close to one another are subtracted). Although underflow could be handled using a “sticky bit” as is common in IEEE754 applications, growth in mantissa size to the right of the binal point might preserve lost data resulting from underflow or bit cancellation. According to this aspect of the invention, because it is a matter of user tolerance, growth in mantissa size to the right of the binal point may be less deterministic than growth to the left of the binal point. Specifically, any growth 750 to the right of the binal point may be arbitrary as determined by the user, or may be subject to heuristic rules. For example, one bit may be added to the right of the binal point for every n bits added to left of the binal point, optionally subject to a maximum number of added bits. This aspect of the invention can be implemented with both signed numbers and signed magnitude numbers. The use of signed numbers will make the individual adder/subtractor nodes smaller, and have a lower latency, because a potentially negative number in the fixed-point addition/subtraction portion of the operation will not have to be converted to a positive number and sign bit. If signed numbers are used, more processing may be required to convert between signed magnitude and signed number formats, as well as for some internal functions such as negation or absolute values. However, a common application of this aspect of the invention for large floating point datapaths will likely be dot or inner products, so use of negation or absolute value functions should be infrequent. As before, the results of any calculation not formatted according to the foregoing standard will be renormalized to meet the standard when necessary to output a value in accordance with the standard, or at intermediate points as discussed above. However, because the mantissa size at each level or step of each calculation need not be the same according to this aspect of the invention, implementation of any user design can be expected to save up to about 15% of resources as compared to the initial aspect of the invention discussed above. For example, to add 16 numbers, a tree of 15 adders may be used. If a 32-bit result is needed and all adders are 32 bits wide, then 15×32=480 resource units are needed. However, according to this aspect of the invention, assuming wordgrowth of two bits per node (e.g., one bit on each side of the binal point), the number of resource units needed might be 8×26=208 plus 4×28=112 plus 2×30=60 plus 1×32=32 for a total of 412 resource units, which is just under 86% of 480 resource units, for a savings of over 14%. Although in the foregoing discussion, the only standard referred to is the IEEE754-1985 standard, it should be noted the invention applies regardless of what the standard is, and moreover the output standard may not be the same as the input standard. Moreover, any reference herein, or in the claims that follow, to “input,” “output,” “initial” or “final” may refer to an intermediate point at which renormalization is performed, as discussed above, rather than to an absolute input or output. Instructions for carrying out a method according to this invention may be encoded on a machine-readable medium, to be executed by a suitable computer or similar device to implement the method of the invention for programming or configuring PLDs to perform arithmetic operations in accordance with the format describe above. For example, a personal computer may be equipped with an interface to which a PLD can be connected, and the personal computer can be used by a user to program the PLD using a suitable software tool, such as the QUARTUS® II software available from Altera Corporation, of San Jose, Calif. The magnetic domains of coating 602 of medium 600 are polarized or oriented so as to encode, in manner which may be conventional, a machine-executable program, for execution by a programming system such as a personal computer or other computer or similar system, having a socket or peripheral attachment into which the PLD to be programmed may be inserted, to configure appropriate portions of the PLD, including its specialized processing blocks, if any, in accordance with the invention. In the case of a CD-based or DVD-based medium, as is well known, coating 702 is reflective and is impressed with a plurality of pits 703, arranged on one or more layers, to encode the machine-executable program. The arrangement of pits is read by reflecting laser light off the surface of coating 702. A protective coating 704, which preferably is substantially transparent, is provided on top of coating 702. In the case of magneto-optical disk, as is well known, coating 702 has no pits 703, but has a plurality of magnetic domains whose polarity or orientation can be changed magnetically when heated above a certain temperature, as by a laser (not shown). The orientation of the domains can be read by measuring the polarization of laser light reflected from coating 702. The arrangement of the domains encodes the program as described above. Thus it is seen that a method for carrying out floating point operations, a programmable device programmed to perform the method, and software for carrying out the programming, have been provided. A programmable device, such as a PLD 90, programmed according to the present invention may be used in many kinds of electronic devices. One possible use is in a data processing system 900 shown in System 900 can be used in a wide variety of applications, such as computer networking, data networking, instrumentation, video processing, digital signal processing, or any other application where the advantage of using programmable or reprogrammable logic is desirable. PLD 90 can be used to perform a variety of different logic functions. For example, PLD 90 can be configured as a processor or controller that works in cooperation with processor 901. PLD 90 may also be used as an arbiter for arbitrating access to a shared resources in system 900. In yet another example, PLD 90 can be configured as an interface between processor 901 and one of the other components in system 900. It should be noted that system 900 is only exemplary, and that the true scope and spirit of the invention should be indicated by the following claims. Various technologies can be used to implement programmable devices, such as PLDs 90, as described above and incorporating this invention. It will be understood that the foregoing is only illustrative of the principles of the invention, and that various modifications can be made by those skilled in the art without departing from the scope and spirit of the invention. For example, the various elements of this invention can be provided on a programmable device in any desired number and/or arrangement. One skilled in the art will appreciate that the present invention can be practiced by other than the described embodiments, which are presented for purposes of illustration and not of limitation, and the present invention is limited only by the claims that follow. |