The present invention relates to a logarithmic calculating apparatus and method, and relates particularly, but not exclusively, to a logarithmic calculating apparatus and method to be incorporated within microprocessors.
In electronic computational machines, it is known to represent real numbers upon which the machines operate using the xe2x80x9cfloating pointxe2x80x9d system, which will be familiar to persons skilled in the art. Using the xe2x80x9cfloating pointxe2x80x9d system, add, subtract and multiply operations can be exercised at reasonable speed. However, this system suffers from the drawback that divide operations take place much more slowly, and all operations are subject to a maximum rounding error of half of a least significant bit.
An alternative known approach is to represent real numbers as fixed-point logarithms, this approach generally being referred to as a Logarithmic Number System (LNS). Using such a system, multiplication and division operations may be implemented very rapidly and with no error, but this is at the expense of considerable complexity, latency and lack of accuracy in the addition and subtraction processes.
The operation of a conventional Logarithmic Number System, such as in existing arithmetic devices, is shown schematically in FIG. 1, in which addition and subtraction operations require the evaluation of:
log2(2i+2j)=i+log2(1+2jxe2x88x92i);
log2(2ixe2x88x922j)=i+log2(1xe2x88x922jxe2x88x92i);
where j is less than or equal to i.
The logarithmic function F(r=(jxe2x88x92i))=log2(1+2jxe2x88x92i) for the add operation is shown in FIG. 2. The device shown in FIG. 1 is provided with look up tables which store the value of the function F(r) for a range of discrete values of r. For practical applications, it is not possible to store the function for all values of r, as this would require a look up table of impracticable size, and so the value of the function is therefore stored at intervals of width xcex94. To further minimise the storage requirements, xcex94 is progressively increased as the function becomes more linear with decreasing r, and an intervening value of r lying in the nth interval is thus expressed as:
r=xe2x88x92xcex4{n=O}; r=xcexa3(xe2x88x92xcex94n)xe2x88x92xcex4{n greater than 0}
For clarity, however, this description omits any further reference to the variation in xcex94, and the expression may be abbreviated to r=xe2x88x92nxcex94xe2x88x92xcex4.
Alongside each value of the function F(r) is stored its derivative, or slope at that point, D(r). The function for any intermediate value of r is then obtained by interpolation with a first-order Taylor-series:
F(xe2x88x92nxcex94xe2x88x92xcex4)=F(xe2x88x92nxcex94)xe2x88x92xcex4D(xe2x88x92nxcex94)
FIG. 3 shows in detail the function F(r) within one interval of width xcex94. The error xcex5 between the true value of the Function F(r) at position xcex4 and that interpolated from the derivative at an adjacent stored position is shown. Referring to FIG. 1, the apparatus has a selector/subtracter 1 for deriving the values of i and r=jxe2x88x92i, a look up table 2 containing the value of the function F(r) at discrete values of r, and a look up table 3 containing values of the derivative D(r) at discrete values of r. A multiply stage 4 multiplies the derivative D(r) by xcex4 and a carry-save-add stage 5 adds together the outputs of the selector/subtracter 1, look up table 2 and multiplier 4. The output of the carry-save-add stage 5 is then fed to a carry-propagate-add stage 6.
It can therefore be seen that following the initial subtraction in selector/subtracter 1 to obtain r, r is partitioned into lower and higher order segments, so effectively dividing by xcex94. The higher order segment represents n and is used to access the function F(r) in look up table 2 and derivative D(r) in look up table 3, whilst the lower order segment represents xcex4. F(xe2x88x92nxcex94) stored in look up table 2 is then added in the carry-save-add stage 5 to the product xcex4.D(xe2x88x92nxcex94) obtained from the multiplier 4, so as to obtain the approximation to F(r) at the value of r of interest, to which is also added i, the addition being completed in the final carry-propagate-add stage 6, so as to yield the result.
As can be seen from FIG. 3, the prior art arrangement described with reference to FIGS. 1 to 3 includes an interpolation error:
xcex5(n,xcex4)=F(xe2x88x92nxcex94)xe2x88x92xcex4.D(xe2x88x92nxcex94)xe2x88x92F(xe2x88x92nxcex94xe2x88x92xcex4)
and for each n, xcex5 increases with xcex4 to a maximum:
E(n)=F(xe2x88x92nxcex94)xe2x88x92xcex94.D(xe2x88x92nxcex94)xe2x88x92F(xe2x88x92nxcex94xe2x88x92xcex94) approximately.
In any practical implementation, the error xcex5 must be minimised to an acceptable magnitude. This can be achieved by decreasing the increment xcex94, but at the cost of a considerable increase in the required capacity of the look up tables. Alternatively, methods are known which apply correction algorithms to minimise the error without increasing the necessary capacity of the look up tables. However, these all suffer from the drawback that they involve many extra stages in the computation process, which are executed serially, and therefore introduce speed limitations.
Preferred embodiments of the present invention seek to overcome the above disadvantages of the prior art.
According to an aspect of the present invention, there is provided a logarithmic calculating apparatus for determining the approximate value of a logarithmic function F(x) at a value of x of interest, the apparatus comprising:
first memory means for storing values of the function F(x) for a plurality of discrete values of x;
second memory means for storing values of Fxe2x80x2(x), the slope of the function F(x), for said plurality of discrete values of x;
first multiplier means, or equivalent thereof, for multiplying the value of Fxe2x80x2(x) for a said discrete value of x adjacent to the value of x of interest by xcex4, the difference between said adjacent discrete value of x and the value of x of interest;
third memory means for storing values of E (x), the approximate difference between [F(x)+xcex94.Fxe2x80x2(x)] and F(x+xcex94) where x and x+xcex94 are the adjacent pair of said discrete values of x nearest to the value of x of interest;
fourth memory means for storing values of P(xcex4), the ratio of (i) the difference between F(x+xcex4) and [F(x)+xcex4.Fxe2x80x2(x)], to (ii) E(x) for a plurality of values of xcex4;
second multiplier means, or equivalent thereof, for multiplying together the outputs of said third and fourth memory means; and
adder means for adding together the outputs of said first memory means, said first multiplier means and said second multiplier means to produce an output representing the approximate value of F(x) at the value of x of interest.
The present invention is based on the surprising observation that for many logarithmic functions, the ratio function P(xcex4) for a given value of xcex4 is almost, although not exactly, constant for all values of n. This provides the advantage that it is possible to store for a single value of n a look up table containing the values of P(xcex4) at successive points throughout an interval of width xcex94. This in turn provides the advantage of enabling the logarithmic function F(x) to be calculated accurately for a value of x of interest without significantly increasing the necessary size of look up tables in the apparatus, and without significantly decreasing the speed of calculation. For example, the necessary size of look up tables may be doubled compared with the prior art, which does not cause significant problems. It will also be appreciated by persons skilled in the art that the quantities x, F(x), Fxe2x80x2(x),xcex4, E(x) and xcex94 defined above can be positive or negative.
In a preferred embodiment, said first and second multiplier means operate substantially simultaneously in use.
This provides the advantage of not decreasing the speed at which the calculation process can be carried out.
The apparatus may further comprise further adder means.
The or each adder means may be a carry-save-add means cooperating with at least one carry-propagate add means.
This provides the advantage of minimising the extent to which further adder stages slow down the calculation process.
In a preferred embodiment, said first, second, third and fourth memory means are accessed substantially simultaneously in use.
This provides the advantage of not decreasing the speed of the calculation process.
According to another aspect of the invention, there is provided a microprocessor including a logarithmic calculating apparatus as defined above.
According to a further aspect of the present invention, there is provided a method of determining the approximate value of a logarithmic function F(x) at a value of x of interest in a logarithmic calculating apparatus, the method comprising the steps of:
storing values of the function F(x) for a plurality of discrete values of x;
storing values of Fxe2x80x2(x), the slope of the function F(x), for said plurality of discrete values of x;
multiplying the value of Fxe2x80x2(x) for a said discrete value of x adjacent to the value of x of interest by xcex4, the difference between said adjacent discrete value of x and the value of x of interest;
storing values of E(x), the approximate difference between [F(x)+xcex94.Fxe2x80x2(x)] and F(x+xcex94) where x and x+xcex94 are the adjacent pair of said discrete values of x nearest to the value of x of interest;
storing values of P(xcex4), the ratio of (i) the difference between [F(x)+xcex4.Fxe2x80x2(x)] and F(x+xcex4), to (ii) E(x) for a plurality of values of xcex4;
multiplying together the values of E(x) and P(xcex4) for the value of x of interest; and
adding together said values of F(x), xcex4.Fxe2x80x2(x) and E(x).P(xcex4) to provide the approximate value of F(x) for the value of x of interest.
In a preferred embodiment, said multiplication steps are carried out substantially simultaneously.
Said addition step may be carried out by means of a carry-save-add stage cooperating with a subsequent carry-propagate-add stage.
The stored values are preferably accessed substantially simultaneously.
This provides the advantage of not decreasing the speed of the calculation process.