Background of the Invention
1. Field of the Invention
The present invention relates to a squaring circuit for raising to the second power a binary number of n bits and more particularly to such a circuit including a table of squared numbers, which is stored in a nonvolatile memory element (i.e. ROM).
2. Discussion of the Related Art
Conventionally, a circuit for raising to the second power a binary number X is achieved by multiplying X by itself with a binary multiplying circuit. A binary circuit for multiplying 8-bit numbers requires approximately 1,500 transistors in conventional technologies and architectures. Such a conventional circuit is called a multiplier and a common drawback includes the large surface area used.
An alternative for achieving a squaring circuit of an 8-bit binary number X is to store in a ROM memory element all of the squares of n-hi t numbers and to select one of these squares by addressing one of the squares. This addressing occurs by applying number X on the address lines of the ROM. If number X is composed of n bits, 2.sup.n numbers of 2n bits will have to be stored in the ROM (the square of an n-bit number is a number including, at the most, 2n bits). Hence, in this example, a ROM of 2.sup.n .times.2n bits is required. A ROM including all the squares of 8-bit numbers includes approximately 1,900 transistors. Since these transistors are very orderly arranged, the ROM can be easily devised so as to occupy, for n<10, an equal or even smaller silicon surface than an equivalent conventional multiplier circuit (using the same technology).
Summary of the Invention
Accordingly, an object of the present invention is to provide a squaring circuit including a ROM having a size at least four times smaller than the size of a ROM used in a conventional equivalent squaring circuit.
This object and other advantages and features of the invention is achieved with a circuit for providing the square of a binary number X having n bits with weights increasing from 0 to n-1, the circuit includes a table of the squares of binary numbers p. Each number p is constituted only by the bits of weight 1 to n-2 of number X. The circuit further includes: an adder, for adding numbers of 2n-3 bits, receiving at a first input a number constituted by the bit of weight n-1 of number X, positioned on the left of the square p2 provided by the table; a first switching element receiving the number p and providing same to the n-2 lines of low weight of a second input of the adder if the low weight bit of number X is equal to 1; a second switching element receiving the number p and providing same to the n-2 lines of high weight of the second input of the adder if the bit of weight n-1 of number X is 1; a third switching element providing a 1 to the remaining line of the second input of the adder if the bits of weight 0 and n-1 of number X are both 1. The square X.sup.2 of number X is constituted by the adder output, to which output are positioned on the right side a bit 0 and the lowest weight bit of number X.
According to an embodiment of the invention, the table is a memory element storing only the 2(n-2)-2 high weight bits of number p.sup.2. Number p.sup.2 is constituted by the memory output to which are positioned on the right side a bit 0 and the bit of weight 1 of number X.
According to this embodiment of the invention, the first switching element includes n-2 AND gates, the first inputs of which receive the lowest weight bit of number X and the second inputs of which respectively receive one of the bits of number p.
According to this embodiment of the invention, the second switching element includes n-2 AND gates, the first inputs of which receive the bit of weight n-1 of number X and the second inputs of which respectively receive one of the bits of number p.
According to this embodiment of the invention, the third switching element is comprised of an AND gate, receiving at the inputs the bits of weight 0 and n-1 of number X.
The foregoing and other objects, features, aspects and advantages of the invention will become apparent from a reading of the following detailed description of the present invention when taken in conjunction with the accompanying drawings.
Brief Description of Drawings
FIG. 1 symbolically and graphically illustrates a calculation method used by a squaring circuit according to the present invention; and
FIG. 2 illustrates in block diagram, schematic form, an embodiment of a squaring circuit according to the present invention.
Detailed Description
Assuming that it is desired to provide the square of a number X including n bits,
where x0 . . . x.sub.n-1 designate respectively the bits of weights 0 to n-1 of number X.
A circuit according to the invention provides the square of this number, as described below.
Number X can be written in the form:
where p=2.sup.n-3 x.sub.n-2 + . . . +2.sup.1 x.sub.2 +2.sup.0 x.sub.1.
Thus, by raising equation (1) to the second power and by simplifying the resulting equation, taking into account that x.sub.i.sup.2 =x.sub.i since x.sub.i =1 or 0, one obtains: ##EQU1##
FIG. 1 symbolically and graphically illustrates equation (2). Various binary numbers are shown in the form of rectangles divided into cells corresponding to bits. Each cell of the rectangles is disposed in a column which cot-responds to the weight of the bit of the particular cell. In FIG. 1, columns 0 to 2.sub.n-1 are numbered from right to left, the bits with the lowest weight corresponding to the rightmost column. An ordinary binary number expressed in the form 2.sup.i z, where z is a binary value of n.sub.z bits, can be represented by a rectangle having n.sub.z cells, the cell having the lowest weight being in column i. The cells of the rectangle are occupied by the bits of value z, which is indicated by writing this value in the rectangle. The column(s) that are not occupied by a rectangle correspond to null bits.
Rectangle X represents equation (1). The bits x.sub.0 to x.sub.n-1 of number X appear in columns 0 to n-1. Number p is formed by bits x.sub.1 to x.sub.n-2 of number X and appears in the rectangle X within the appropriate columns.
The six following rectangles represent terms T1-T6 of the right side of equation (2); the last rectangle represents result X.sup.2.
Rectangle T1 represents the term
T1=2.sup.n+1 x.sub.n-1 p
of equation (2). This rectangle, as shown, occupies the n-2 columns n+1 to 2n-2. Value x.sub.n-1 p includes as many bits as number p since this value is obtained by a simple logic ANDing of each of the bits of number p and bit x.sub.n-1.
of equation (2). As shown, rectangle T2 occupies the n-2 columns 2 to n-1.
As shown, rectangle T3 occupies column n only (x.sub.0 x.sub.n-1 corresponds to one bit).
In viewing rectangles T1, T2 and T3, it can be seen that the sum T1+T2+T3 is in fact equal to a number formed by the juxtaposition of values x.sub.n-1 p, x.sub.0 x.sub.n-1 p and x.sub.0 p followed by two 0s. Hence, a binary adder is not required to sum terms T1-T3 since, physically, a corresponding juxtaposition of the columns carrying the above value bits simply forms the sum.
Rectangle T4 represents the term
of equation (2). As shown, rectangle T4 occupies the 2(n-2) columns 2 to 2.sub.n-3.
As shown, rectangle T5 occupies column 2.sub.n-2.
Rectangle T6 represents the term T6=x.sub.0 and, as shown, occupies column 0. The sum of terms T4, T5 and T6 is obtainable by a simple juxtaposition of values x.sub.n-1 p.sup.2, 0 and x0, which operation avoids the use of a binary adder.
In addition, FIG. 1 shows that for any value of number X, the bit of weight 1 of number X.sup.2 (represented by rectangle X.sup.2) is always null and that the bit of weight 0 is always equal to bit x.sub.0 of weight 0 of number X. Thus, it is not necessary to store the bits of weight 0 and 1 of number p.sup.2 because they are known to be respectively equal to the bit x.sub.1 of number p (which is the bit of weight 1 of number X) and to 0. Number p.sup.2 can thus be obtained, as shown in rectangle T4, by positioning the numbers 0 and x.sub.1 on the right of its 2(n-2)-2 bits of higher weight.
The sum of the six terms T1-T6 is reduced to a single sum of the number corresponding to the juxtaposition of rectangles T1-T3 and of the number corresponding to the juxtaposition of rectangles T4 and T5. A null bit and bit x.sub.0 (T6) are then positioned on the right of this sum to provide number X.sup.2. These last two bits are known to exist in their respective positions for all values of X, as described above.
This analysis teaches that instead of storing 2.sup.n squares of X, it is merely necessary to store 2.sup.n-2 squares of p. Thus, the amount of squares necessary to store is one quarter of that of the conventional binary multiplier. Moreover, only the 2(n-2)-2=2n-6 high weight bits of numbers p.sup.2, as opposed to the 2n bits of number X.sup.2 as is done with conventional binary multipliers, are stored. The total amount of memory bits is therefore 2.sup.n-2 (2n-6)=2.sup.n-1 (n-3), which provides a gain of surface area ("chip real estate") of 4n/(n-3) over the conventional binary multiplier. This gain approaches 4 as n approaches infinity. For 8-bit numbers X (a=8), this gain is 6.4.
According to the invention, in addition to the memory needed, additional circuits are required to carry out the digital logic. Such circuits include a (2n-3)-bit adder for summing values (T1+T2+T3) and (T4+T5) and logic gates for calculating the values x.sub.n-1 p, x.sub.0 p and x.sub.0 x.sub.n-1. Those skilled in the art will appreciate that these circuits occupy a small surface area in comparison to the surface spared by the use of a smaller memory.
FIG. 2 is a block diagram showing a preferred embodiment of the squaring circuit according to the present invention. Bits x.sub.0 to x.sub.n-1 of a number X, the square of which is to be calculated, are introduced into the circuit at lines x.sub.0 to x.sub.n-1. The n-2 lines x.sub.1 to x.sub.n-2 which carry the bits of number p, are connected to the address lines of ROM 20. ROM 20 outputs the 2n-6 high weight bits (p.sup.2).sub.2 to (p.sup.2).sub.2n-5 of number p.sup.2. The remaining low weight bit lines (p.sup.2).sub.1 and (p.sup.2).sub.0 are connected to line 0 and line x.sub.1 respectively.
The circuit includes an adder ADD for adding the 2n-3 bit numbers. Adder ADD comprises 2n-3 elementary adders ADD.sub.2 to ADD.sub.2n-2 which respectively provide the bits of weight 2 to 2n-2 of number X.sup.2 Each elementary adder includes two bit inputs a and b and each carries an output c for transmitting a carry bit to an elementary adder having an immediately higher weight. The carry output of adder ADD.sub.2n-2 provides the bit of weight 2n-1 of number X.sup.2. The carry outputs of the other adders are not shown.
Bits (p.sup.2).sub.0 to (p2).sub.2n-5 are provided to inputs b of adders ADD.sub.2 to ADD.sub.2n-3. Input b of adder ADD.sub.2n-2 is connected to line x.sub.n-1. The bits of weight 0 and 1 of number X.sup.2 are provided by line x.sub.0 and a line connected to 0, respectively.
Input a of adders ADD.sub.2 to ADD.sub.2n-2 are connected to the output of AND gates &.sub.2 to &.sub.2n-2, respectively. A first input of AND gates &.sub.2 to &.sub.n-1 is connected to line x.sub.0. Bits x.sub.1 to x.sub.n-2 of number p are provided to a second input of AND gates &.sub.2 to &.sub.n-1, respectively. AND gates &.sub.2 to &.sub.n-1 provide value x.sub.0 p to adders ADD.sub.z to ADD.sub.n-1, respectively.
A first input of AND gates &.sub.n+1 to &.sub.2n-2 is connected to line x.sub.n-1 and bits x.sub.1 to x.sub.n-2 of number p are respectively provided to a second input of these AND gates. AND gates &.sub.n+1 to &.sub.2n-2, respectively, provide value x.sub.n-1 p to adders ADD.sub.n+1 to ADD.sub.2n-z.
The two inputs of gate &.sub.n are connected to line x.sub.0 and line x.sub.n-1. AND gate &.sub.n provides the number x.sub.0 x.sub.n-1 to adder ADD.sub.1.
FIG. 2 shows that the arrangement of the AND gates and elementary adders is very orderly, permitting ease of placement of such elements on a small surface.
As will be apparent to those skilled in the art, various modifications can be made to the above disclosed preferred embodiment. In particular, AND gates &.sub.2 to &.sub.n-1 can be replaced with a multiplexer controlled by line x.sub.0 and receiving a null binary number as one input and the number p as another input. A similar multiplexer, controlled by line x.sub.n-1 can be substituted for AND gates &.sub.n+1 to &.sub.2n-2. The ROM can be replaced with any equivalent circuit, such as a programmable logic array (PLA), the output bits of which correspond to preprogrammed equations of the bits present at the input (on the address lines). Adder ADD.sub.2 can be replaced with an AND gate receiving bit x.sub.1 and the complementary of bit x.sub.0 since (X.sup.2)2=x.sub.1.x.sub.0.
The foregoing description is provided by way of example only and in no way is intended on being limiting. The scope of the present invention is defined by the appended claims and equivalents thereto.