1. Field of the Invention
The present invention relates to a leading-zero counter, a method to count leading zeros and a corresponding computer program product.
2. Description and Disadvantages of Prior Art
Current circuit technologies allow building gates with more than two inputs that have only slightly higher delay compared to gates with only two inputs. Especially multiplexers with many inputs and low delay can be built with current circuit technologies, e.g., using transmission gates. Using these multiplexers one can build for example shifter circuits or arbiter circuits with fewer stages than before since every stage can select between more than two inputs. This reduces the overall delay of the shifter, arbiter, etc.
The control wires for each stage of such “few-stage” circuits usually need to be hot-one-encoded. This means that exactly one of the control wires carries a ON-signal (high), and the others an OFF-signal (low). A hot-one-encoded signal string consisting of N signals (0, . . . , N-1) is called N-bit digit in the following.
In a case of a 4-input shifter stage for example a 4-bit digit is needed. The location of the ON-signal wire within the 4-bit digit indicates directly the shift amount. Thus, if the 0th wire is ON, the shift amount will be 0, if the 2nd wire is ON, the shift amount will be 2, etc. In an arbiter circuit a respective input is selected from the total number of input wires.
With reference to the focus of the present invention there is a close relationship between a leading zero counter (LZC) and such shifter within a floating point unit, as the mantissa of a floating point operand must be shifted according to the result calculated by the leading zero counter. Thus, the present invention focuses on circuits comprising an LZC sub-circuit which controls a further sub-circuit, such as a shifter sub-circuit, arbiter, etc.
With reference to
Thus, in order to control the before-mentioned “few stage” shifter 12 with the output of a prior art leading zero counter, the output of the LZC 10 must be recoded as depicted in
Thus, if for example a shifter sub-circuit may be assumed to have its best performance when having a design implementing a first 3-input stage, a second 4-inputs stage, and a third 5-inputs stage, then the driving prior art LZC sub-circuit should be implemented with a respective recoder circuitry 14, which causes quite a lot of design work for implementing it, and which involves a considerable delay during operation thereof.
It is thus an objective of the present invention to provide an improved leading zero circuit having an output which allows a simpler control of a post-connected sub-circuit having two or more stages and having at least one stage with three or more input wires.
This objective of the invention is achieved by the features stated in enclosed independent claims. Further advantageous arrangements and embodiments of the invention are set forth in the dependent claims. Reference should now be made to the appended claims.
According to the broadest aspect of the invention a leading zero counter (LZC) circuit is disclosed that is characterized by a circuitry providing an output that defines the number of leading zeros in a format consisting of two or more unary encoded substrings, wherein at least one substring comprises at least three bits, which output preferably consists of three or more digits in the above described sense, i.e., a hot-one-encoded signal string consisting of N (N=3, 4, . . . ) signals.
In a simple case defining the minimal requirements (6 inputs) such an output may look like:
First substring: “001” for hot-encoding the bit 2 in an N=3 bit signal,
Second substring: “10” for hot-encoding the bit 0 in an N=2 bit signal.
In a more realistic case with 27 inputs the output may look like:
First substring: “010” for hot-encoding the bit 1 in an N=3 bit signal,
Second substring: “001” for hot-encoding the bit 2 in an N=3 bit signal,
Third substring: “100” for hot-encoding the bit 0 in an N=3 bit signal.
These substrings would encode the number (1*3ˆ2)+(2*3ˆ1)+(0*3ˆ0)=15.
This feature is the main feature for an inventive concept, which allows an easy adaptation of the LZC circuit to any particular design of a post-connected multiple stage sub-circuit, which may have basically any number of input wires in any stage. For example, a first stage having 3 inputs, a second having 5, and a third having 7 inputs, to denote a quite “exotic” example.
Preferably, if the output of the above circuitry consists of only one digit, it is built using a core circuit structure with N ( N=3, 4, . . . ) inputs, that further comprises:
This core structure can be used in a recursively repeated form to construct a multiple stage LZC circuit with an output that consists of i digits (i>1). This recursively repeated circuit structure, comprises preferably:
It should be noted that P may be equal to N, but in general can be freely selected independently from N. This allows to construct an LZC output bit string, of which the MSB string is an N-bit digit, dedicated to feed for example a first shifter stage, the next significant bit string is a M-bit digit to feed a second stage of a shifter, and so on. This may end up in any number of stages with any individual digit width. This option enables for an easy adaptation of the LZC to any constraint given by the design of the post-connected circuit, as e.g. the before-mentioned shifter.
The above LZC circuit can be preferably applied in a circuit comprising this LZC circuit as a sub-circuit and driving a second sub-circuit with the outputs of the LZC sub-circuit, wherein:
This saves the above-mentioned re-coding in a recoder (
When the driven circuit has a number of stages which is equal to the number of hierarchy levels of the driving LZC circuit, and the bit width of a respective driven circuit stage coincides with the width of the leading-zero calculation sub-circuit of the core circuit structure in the respective LZC circuit level, then a fast implementation is provided.
The basic advantages are as follows: First, the delay of the prior art decoder in
Both advantages speed up the LZC and the shifter; both components are often timing-critical in floating-point-designs, for example. Additionally, the leading-zero-counter eases the use of such shifters for which the width of the multiplexers is not a power-of-two.
The present invention is illustrated by way of example and is not limited by the shape of the figures of the drawings in which:
With general reference to the figures and with special reference now to
As an instructive example, a 3-stage shifter 12 may be assumed, which has 3 input bits in each stage, which are all delivered by the LZC circuit. The shifter 12 controlled by the leading zero counter (LZC) 20 thus selects between three inputs in each stage. Thus, one stage shifts by 0, 1, or 2; a second stage shifts by 0, 3, or 6; and a third stage shifts by 0, 9, or 18, and so on. The leading zero counter then must compute 3-bit digit control signals per stage.
The first 3-bit digit defines whether the input should be shifted by 0, 1, or 2; another 3-bit digit defines whether the input should be shifted by 0, 3, or 6 and so on. It should be noted that the sum of the selected shift distances must equal the number of leading zeros of the input to the LZC.
Details how the bit string between LZC 20 and shifter 12 is structured and which substring is fed to which shifter stage are described also later with respect to
The basic functions of a preferred LZC embodiment are described next with reference to
First, with special reference to
In a sub-circuit 34 the signal x(0) is fed directly through as output 1z(0). Further, the sub-circuit 34 comprises N-1=2 AND gates 36-1 and 36-2 computing the outputs 1z(1) and 1z(2) for the purpose of leading zero calculation. AND gate 36-1 has the negation of x(0) and x(1) as inputs. AND gate 36-2 has the negation of x(0) and of x(1) and x(2) as inputs. They operate on x such that 36-1 outputs an ON-signal, if x(0) is OFF and x(1) is ON, and 36-2 outputs an ON-signal if x(0) and x(1) are OFF but x(2) is ON.
The core 30 thus computes two types of outputs denoted as “1z” and “nzero” from the input “x”. The output “nzero” is ON, or “active” if the “x” input bit string does not consist of zeros only. This signal is preferably used for an advantageous recursive design of the LZC. The output “1z” encodes the number of leading zeros of “x” in the bits 1z(0), 1z(1), 1z(2). Thus, OR gate 32 acts as not-all-zero calculation element, and sub-circuit 34 acts as leading zero calculation sub-circuit.
If the LZC circuit 20 controls a shifter with a number of i stages having each j=3 inputs, then the LZC circuit 20 must compute i j-bit digits. Thus the output 1z consists of j*i bits where the last j bits are the least significant digit, i.e., the digit that selects between the shift distances 0, 1, and 2. Of course, i and j can be varied independently from each other, e.g i=4, j=5, etc.
As j=3 in this example, an LZC circuit 20, which computes i 3-bit digits is called LZC(i) in the following.
Having introduced the core 30 of the LZC circuit the construction of an LZC(1) is straight-forward as illustrated in
An LZC(i) for i>1 can be built from three LZC(i-1) 42 and one LZC(1) 30, see
A person skilled in the art will appreciate the recursive principle of the invention which may be understood by combining the elements shown in
The circuits 42 in
Respective three blocks in LZC-row 54 form the input of the 9-bit leading zero counters LZC(2) which are within frame 56, and form the middle hierarchy level.
The overall 27 bit leading zero counter LZC(3) depicted with reference sign 58 is built using 3 LZC(2) outputs as inputs at multiplexer 57 taking into account all 27 input bits.
Since the most significant outputs of the leading zero counter (bit 0 to 2) are least timing critical, they control the first stage 121 of the shifter. Thus, this shifter stage selects between shift distances of 0, 9, and 18. The next stage 122 uses the bits 3 to 5 of the leading zero counter output and therefore selects between shift distances of 0, 3, and 6. The least significant outputs of the leading zero counter (bits 6 to 8) select between shift distances of 0, 1, and 2 in shifter stage 123.
It should be appreciated further that the design of the LZC circuit 20 is not limited to the controlling of a shifter or arbiter. This design can be easily extended such that it counts leading ones, trailing zeros, or trailing ones. In order to do that one just needs to modify the polarity or the numbering of the inputs.
Or, it may be extended that it uses different encodings for the digits than the unary hot-one-encoding, or hot-zero-encoding, such as half-unary-encoding, etc.
Or, that a binary encoding is used for a digit with width N=2 by dropping the bit 0 of the digit,
Or, that the polarity of any intermediate signals is modified, e.g., using an all-zero signal instead of a not-all-zero signal,
Or, that the width of the digits is different to three, as it was shown in the figures. This was already described with examples i and j further above.
Further, the width of the digits is not restricted to be the same for all stages, as it was mentioned further above.
The present invention can be realized in hardware, software, or a combination of hardware and software. A leading zero detection tool according to the present invention can be realized in a centralized fashion in one computer system, or in a distributed fashion where different elements are spread across several interconnected computer systems. Any kind of computer system or other apparatus adapted for carrying out the methods described herein is suited. A typical combination of hardware and software could be a general purpose computer system with a computer program that, when being loaded and executed, controls the computer system such that it carries out the methods described herein.
The present invention can also be embedded in a computer program product, which comprises all the features enabling the implementation of the methods described herein, and which—when loaded in a computer system—is able to carry out these methods.
Computer program means or computer program in the present context mean any expression, in any language, code or notation, of a set of instructions intended to cause a system having an information processing capability to perform a particular function either directly or after either or both of the following
Number | Date | Country | Kind |
---|---|---|---|
05107934.1 | Aug 2005 | EP | regional |