Top Banner
On-The-Fly Range Reduction Vincent Lef` evre, Jean-Michel Muller To cite this version: Vincent Lef` evre, Jean-Michel Muller. On-The-Fly Range Reduction. [Research Report] RR- 4043, INRIA. 2000. <inria-00072595> HAL Id: inria-00072595 https://hal.inria.fr/inria-00072595 Submitted on 24 May 2006 HAL is a multi-disciplinary open access archive for the deposit and dissemination of sci- entific research documents, whether they are pub- lished or not. The documents may come from teaching and research institutions in France or abroad, or from public or private research centers. L’archive ouverte pluridisciplinaire HAL, est destin´ ee au d´ epˆ ot et ` a la diffusion de documents scientifiques de niveau recherche, publi´ es ou non, ´ emanant des ´ etablissements d’enseignement et de recherche fran¸cais ou ´ etrangers, des laboratoires publics ou priv´ es.
13

On-The-Fly Range Reduction - COnnecting REpositories · 2 3 3 4 * if mod 1!65 if mod 1!87) 2 3 3 (1) * if mod 1!89 if mod 1!( 2 3 3 * ) * if mod 1!8: if mod 1!8; 2 3 3) * if mod 1!=

May 15, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: On-The-Fly Range Reduction - COnnecting REpositories · 2 3 3 4 * if mod 1!65 if mod 1!87) 2 3 3 (1) * if mod 1!89 if mod 1!( 2 3 3 * ) * if mod 1!8: if mod 1!8; 2 3 3) * if mod 1!=<

On-The-Fly Range Reduction

Vincent Lefevre, Jean-Michel Muller

To cite this version:

Vincent Lefevre, Jean-Michel Muller. On-The-Fly Range Reduction. [Research Report] RR-4043, INRIA. 2000. <inria-00072595>

HAL Id: inria-00072595

https://hal.inria.fr/inria-00072595

Submitted on 24 May 2006

HAL is a multi-disciplinary open accessarchive for the deposit and dissemination of sci-entific research documents, whether they are pub-lished or not. The documents may come fromteaching and research institutions in France orabroad, or from public or private research centers.

L’archive ouverte pluridisciplinaire HAL, estdestinee au depot et a la diffusion de documentsscientifiques de niveau recherche, publies ou non,emanant des etablissements d’enseignement et derecherche francais ou etrangers, des laboratoirespublics ou prives.

Page 2: On-The-Fly Range Reduction - COnnecting REpositories · 2 3 3 4 * if mod 1!65 if mod 1!87) 2 3 3 (1) * if mod 1!89 if mod 1!( 2 3 3 * ) * if mod 1!8: if mod 1!8; 2 3 3) * if mod 1!=<

ISS

N 0

249-

6399

ISR

N IN

RIA

/RR

--40

43--

FR

+E

NG

ap por t de r ech er ch e

INSTITUT NATIONAL DE RECHERCHE EN INFORMATIQUE ET EN AUTOMATIQUE

On-the-fly Range Reduction

Vincent Lefevre , Jean-Michel Muller

No 4043

Novembre 2000

THEME 2

Page 3: On-The-Fly Range Reduction - COnnecting REpositories · 2 3 3 4 * if mod 1!65 if mod 1!87) 2 3 3 (1) * if mod 1!89 if mod 1!( 2 3 3 * ) * if mod 1!8: if mod 1!8; 2 3 3) * if mod 1!=<
Page 4: On-The-Fly Range Reduction - COnnecting REpositories · 2 3 3 4 * if mod 1!65 if mod 1!87) 2 3 3 (1) * if mod 1!89 if mod 1!( 2 3 3 * ) * if mod 1!8: if mod 1!8; 2 3 3) * if mod 1!=<

On-the-fly Range Reduction

Vincent Lefèvre�

, Jean-Michel Muller�

Thème 2 — Génie logicielet calcul symbolique

Projet Arénaire

Rapport de recherche n˚4043 — Novembre 2000 — 9 pages

Abstract: In several cases, the input argument of an elementary function evaluation is givenbit-serially, most significant bit first. We suggest a solution for performing the first step ofthe evaluation (namely, the range reduction) on the fly: the computation is overlapped withthe reception of the input bits. This algorithm can be used for the trigonometric functions����� , �� � , �� � as well as for the exponential function.

Key-words: Range reduction, Elementary functions, Computer arithmetic.

(Résumé : tsvp)

INRIA, Projet POLKA, UR INRIA Lorraine�CNRS, Projet CNRS/ENS Lyon/INRIA ARENAIRE, Ecole Normale Supérieure de Lyon

Unite de recherche INRIA Rhone-Alpes655, avenue de l’Europe, 38330 MONTBONNOT ST MARTIN (France)

Telephone : 04 76 61 52 00 - International: +33 4 76 61 52 00Telecopie : 04 76 61 52 52 - International: +33 4 76 61 52 52

Page 5: On-The-Fly Range Reduction - COnnecting REpositories · 2 3 3 4 * if mod 1!65 if mod 1!87) 2 3 3 (1) * if mod 1!89 if mod 1!( 2 3 3 * ) * if mod 1!8: if mod 1!8; 2 3 3) * if mod 1!=<

Réduction d’argument “au vol”

Résumé : Il arrive que l’opérande dont on doit calculer une fonction élémentaire soitdisponible chiffre après chiffre, en série, en commençant par les poids forts. Nous pro-posons une solution permettant d’effectuer la première phase de l’évaluation (la réductiond’argument) au vol: le calcul et la réception des chiffres d’entrée se recouvrent. Cet al-gorithme peut être utilisé pour les fonctions trigonométriques ����� , �� � , �� � , ainsi que pourl’exponentielle.

Mots-clé : Réduction d’argument, fonctions élémentaires, arithmétique des ordinateurs.

Page 6: On-The-Fly Range Reduction - COnnecting REpositories · 2 3 3 4 * if mod 1!65 if mod 1!87) 2 3 3 (1) * if mod 1!89 if mod 1!( 2 3 3 * ) * if mod 1!8: if mod 1!8; 2 3 3) * if mod 1!=<

On-the-fly Range Reduction 3

1 Introduction

The algorithms used for evaluating the elementary functions only give a correct result ifthe argument is within some bounded interval. To evaluate an elementary function �������(sine, cosine, exponential,. . . ) for any � , one must find some “transformation” that makesit possible to deduce ������� from some value ����� , where

� , called the reduced argument, is deduced from � ;

� belongs to the convergence domain of the algorithm implemented for the evaluationof � .

With the usual functions, the only cases for which reduction is not straightforward are thecases where is equal to � ����� , where � is an integer and � a constant (for instance, forthe trigonometric functions, � is a multiple of ����� ).Example 1 (Computation of the cosine function) Assume that we want to evaluate�� � ����� , and that the convergence domain of the algorithm used to evaluate the sine andcosine of the reduced argument contains � ������������ . We choose �"!#����� , and the computa-tion of �� � ����� is decomposed in three steps:

� compute and � such that %$&� ������������ and '!(�%���)����� ;� compute ������*���+!-,

............/............0

�� � ��� if � mod �1!#�2 33 � �� � ���4� ����� ���*� if � mod �1!65� ����� ��� if � mod �1!87� 2 33 � �� � ���)� ����� ���*� if � mod �1!89� �� � ��� if � mod �1!(�2 33 �*� �� � ���)� ����� ���*� if � mod �1!8:����� ��� if � mod �1!8;2 33 � �� � ���)� ����� ���*� if � mod �1!=<

(1)

� obtain �� � �����+!>����?�*����@Example 2 (Computation of the exponential function) Assume that we want to evaluateACB in a radix-2 number system, and that the convergence domain of the algorithm usedto evaluate the exponential of the reduced argument contains � ���ED � �F7G�H . We can choose�I!(D � �F7G� , and the computation of AJB is then decomposed in three steps:

RR n˚4043

Page 7: On-The-Fly Range Reduction - COnnecting REpositories · 2 3 3 4 * if mod 1!65 if mod 1!87) 2 3 3 (1) * if mod 1!89 if mod 1!( 2 3 3 * ) * if mod 1!8: if mod 1!8; 2 3 3) * if mod 1!=<

4 Vincent Lefèvre and Jean-Michel Muller

� compute $ � ���ED � �F7G�H and � such that !(�%���1D � �F7G� ;� compute �����+! A � ;� compute ACB !87 � ����� .Unless multiple-precision arithmetic is used during the intermediate calculations, a

straightforward computation of as ���8��� is to be avoided, since this operation willlead to catastrophic cancellations (i.e., to very inaccurate estimates of ) when � is large orclose to an integer multiple of � . Many algorithms have been suggested for performing therange reduction accurately [1, 2, 3, 9, 11].

Now, there are many cases (on special-purpose systems) where the input argument ofa calculation is generated most significant digit first. This happens, for instance, when thisargument is the result of a division or a square root obtained through a digit-recurrencealgorithm [7, 10], the output of an on-line algorithm [5, 12], or when it is generated by ananalog-to-digital converter.

In the sequel of this paper, we present an adaptation of the Modular Range ReductionAlgorithm [3, 8] that accepts such digit serial inputs and performs the range reduction “onthe fly”: most of the computation is overlapped with the reception of the input bits, andthe reduced argument is produced almost immediately after reception of the last input bit.On-the-fly arithmetic algorithms have already been proposed by Ercegovac and Lang forrounding or converting a number from redundant to non-redundant representation [4, 6].

2 Notations

In the sequel of the paper, � ! ��� �������� ��� @ � ��� � � 3 E�� is the input argument,� ! ��@ � ��� � � 3 � ��� is the constant of the range reduction (with ����� � ), and-! ��@ ��� � 3 ��� is the reduced argument. We assume 5J��7�� ��� 5 . These val-ues satisfy:

� ��� ��(� ;

� � ! ��� � �*� � is an integer.

We also define, for each � , ��� (also called 7 ��� �! � ) as the unique value between � and� such that �F7 � �"�#� �*� � is an integer. These notations give some contraints on � and �(e.g., � is less than 1, � is less than 7 �%$&� ). One can easily adapt the algorithms given in thesequel of the paper to variables belonging to other domains. We chose these contraints tomake the presentation of the algorithms simpler.

INRIA

Page 8: On-The-Fly Range Reduction - COnnecting REpositories · 2 3 3 4 * if mod 1!65 if mod 1!87) 2 3 3 (1) * if mod 1!89 if mod 1!( 2 3 3 * ) * if mod 1!8: if mod 1!8; 2 3 3) * if mod 1!=<

On-the-fly Range Reduction 5

3 Non-redundant algorithm

Algorithm 1 is by far less efficient than the “redundant” algorithm given afterwards. Wegive it because it is simpler to understand, and because the other algorithm is derived fromit. The basic idea is the following: at step � of the algorithm, when we receive input bit � ��� �of � , we add ����� � ��� 7 � � �! ��� to an accumulator. If the accumulated value becomeslarger than � , we subtract � from it.

Let us call � � $&� the value obtained after this operation. One can easily check that� ��� � $&� �(� and � � $&� ��������������E����� � � 7 ��� � is an integer multiple of � . Hence thefinal value stored in the accumulator is equal to the reduced argument .

Algorithm 1 Non-redundant algorithm.

� � !#�for ��!#� to �'� � do � !� � �&��� � � � ��� �

if � �(� then

� � $&� ! �else

� � $&� ! �?� �'!� ���! $&�A possible variant consists in computing � �4!�� �?� ��� � � � � ��� � � � � in parallel with � , and then to choose � � $&� equal to � � if �&�� � , otherwise

� .

4 Redundant algorithm

Now, to accelerate the reduction, we assume that we perform the accumulations with carry-save additions. The carry-save number system allows very fast, carry-free additions. Onthe other hand, its intrinsic redundancy makes comparisons somewhat more complex. Theaccumulator will store the values � � in carry-save. In the previous algorithm, we needed“exact” comparisons between the � � ’s and � . Having the � � ’s stored in carry-save makesthese “exact” comparisons difficult. Instead of that, we will perform comparisons based onthe examination of the first three carry-save positions of � � only. This will not allow tobound the � � ’s by � . Nevertheless, we will show that the � � ’s will be upper-bounded by

RR n˚4043

Page 9: On-The-Fly Range Reduction - COnnecting REpositories · 2 3 3 4 * if mod 1!65 if mod 1!87) 2 3 3 (1) * if mod 1!89 if mod 1!( 2 3 3 * ) * if mod 1!8: if mod 1!8; 2 3 3) * if mod 1!=<

6 Vincent Lefèvre and Jean-Michel Muller

�-� �3 (therefore by �3 ), which will suffice for our purpose. We denote:

� ��! � � ��� ������ � � ��� 3 ���� � �J� ��� ������ ��� � ��� 3 ���� ��� �J� ��� ������ � 3 � ��� 3 ���� � 3 � @ @ @�J� ��� ������ ��� � ��� 3 ���� ��� �� where � � ������ � and � � 3 ���� � are in �J���C5�� and

� �)! ����� � � ��� ������ � � ���

3 ���� � �&�7 � � @

The variable � of the non-redundant algorithm is used again, and is also represented in

carry-save form:

�)! � � � ������ � � � 3 ���� � �J� � ������ ��� � � 3 ���� ��� �J� � ������ � 3 � � 3 ���� � 3 � @ @ @�J� � ������ ��� � � 3 ���� ��� �� This gives algorithm 2.

Algorithm 2 Redundant algorithm.�����������for � � � to !#"%$ do&(' �)� ' ��*,+.-./�0 '�1 /�0 '2&(' �43�5 &7698;:'=< �?> &76A@�:'B< �DCFE 5 &7698;:'B< 0 8 > &76A@�:'=< 0 8 CFE 5 &7698;:'B< 0 @ > &76A@�:'=< 0 @ CHG " �

converted to non-redundant binary using a I -bit adder

if2& 'KJ)L

then� 'NM 8 � &('else� 'NM 8 � &(' " *,+ L (or

&(' ��*,+O5;� " L C " � )P ����/�0RQ M 8 ��*,+K5H� " L CConvert

��/�0SQ M 8 andP

to non-redundant binary.

ifP JUT

thenV � � /�0RQ M 8 " �elseV � P " T

In the loop, we do not want to waste time with a full comparison to know whether weneed to subtract � from

� or not. Thus we use a rough approximation W � to � based on

the first three digits of � . Since� � � ������ � � � �

3 ���� � � � @ @ @XJ� � ������ ��� � �

3 ���� ��� �� �(7 �7 � � � 7 �7 �ZY � �� 7 �7 ��� � 57 �

INRIA

Page 10: On-The-Fly Range Reduction - COnnecting REpositories · 2 3 3 4 * if mod 1!65 if mod 1!87) 2 3 3 (1) * if mod 1!89 if mod 1!( 2 3 3 * ) * if mod 1!8: if mod 1!8; 2 3 3) * if mod 1!=<

On-the-fly Range Reduction 7

we have: W � � � � W � � 57We want to ensure that � � is always positive, that is,

�?�&� does not lead to a negativenumber. Then, the subtraction is performed only when W �� � . In this case,

� �(� W ���&�� -� .Now, we want to find an upper bound on all the � � ’s (and one on the

� ’s). Suppose thatfor a given � , we have � � ��� . Thus

� ��� � � . If W � �(� , then � � $&� ! �&� W � � �3 ��#� �3 ; otherwise, � � $&� ! �)� � ��� . If we choose � ! �#� �3 , then � � $&� ��� inboth cases. By induction, � � �(�-� �3 and

� �>7G�>� �3 for all � .The final value of is converted to non-redundant representation using a conventional

(i.e., non-redundant) addition. Another, faster, solution is to convert it on-the-fly, during thesecond loop of the algorithm, using Ercegovac and Lang’s on-the-fly algorithm [4, 6] forconversion from redundant to non-redundant representation.

5 An example: computation of ���� ��� ��� ��������� .We choose � ! ������� ��@ 5 5 � � 5 � 5 (�(! < ). Since �>! 5 � 5 ��@ 5 5 5 , we have �-! 9 and� ! � 9 ).

The values of the � � ’s are:

,......../........0

� � ! 7 � mod ����� � ��@ � � 5 � � 5 5� 3 ! 7 3 mod ����� � ��@ � � � 5 � � 5� � ! 7 � mod ����� � ��@ � 5 5 � 5 5 5� � ! 7 � mod ����� � ��@ � � 5 5 � 5 5� ��� ! 7 ��� mod ����� ! ��@ 5� � 3 ! 7 � 3 mod ����� ! ��@ � 5� � � ! 7 � � mod ����� ! ��@ � � 5

The carry-save representations of the variables � and � � generated by the redundant

algorithm are

RR n˚4043

Page 11: On-The-Fly Range Reduction - COnnecting REpositories · 2 3 3 4 * if mod 1!65 if mod 1!87) 2 3 3 (1) * if mod 1!89 if mod 1!( 2 3 3 * ) * if mod 1!8: if mod 1!8; 2 3 3) * if mod 1!=<

8 Vincent Lefèvre and Jean-Michel Muller

� � !65 � !�� 5�@ � � 5 � � 5 5��@ � � � � � � � � �#� � � !�� 5�@ � � 5 � � 5 5��@ � � � � � � �� 3 !#� � !�� 5�@ � � 5 � � 5 5��@ � � � � � � � � �#� � � !�� 5�@ � � 5 � � 5 5��@ � � � � � � �� � !65 3 ! � 5�@ � 5 � � 5 � ���@ � 5 � � 5 5 � ��@ 5 �(� � 3 ! � 5�@ � 5 � � 5 � ���@ � 5 � � 5 5 ���� !#� � ! � 5�@ � � � � � 5 ���@ 5 � � 5 � � � ��@ 5 �(� � � ! � 5�@ � � � � � 5 ���@ 5 � � 5 � � �� ��� !65 Y !�� 5�@ � � � 5 � 5 �5�@ � � � � � � � 5 #� � Y !�� 5�@ � � 5 � � � 5��@ � � 5 � 5 � �� � 3 !65 �� !�� 5�@ � 5 � � 5 � 5��@ � 5 � � � � � ��@ 5 �(� � � !�� 5�@ � 5 � � 5 � 5��@ � 5 � � � � �� � � !65 �� ! � 5�@ � � 5 � 5 � 5��@ 5 � � � � � � ��@ 5 �(� � � ! � 5�@ � � 5 � 5 � 5��@ 5 � � � � � �

We then get ! ��@ 5 � 5 � 5 � 5 , whereas the exact value of � mod ����� is��@ 5 � 5 � 5 � 5 � � � 5 @ @ @ .6 Conclusion

The redundant algorithm presented in Section 4 allows fast, on-the-fly, range reduction. Theaccuracy of this method is the same as that of the Conventional Modular range reductionmethod (see [3, 8]).

References

[1] W. Cody and W. Waite. Software Manual for the Elementary Functions. Prentice-Hall,Englewood Cliffs, NJ, 1980.

[2] W. J. Cody. Implementation and testing of function software. In P. C. Messina andA. Murli, editors, Problems and Methodologies in Mathematical Software Production,Lecture Notes in Computer Science 142. Springer-Verlag, Berlin, 1982.

[3] M. Daumas, C. Mazenc, X. Merrheim, and J. M. Muller. Modular range reduction: Anew algorithm for fast and accurate computation of the elementary functions. Journalof Universal Computer Science, 1(3):162–175, March 1995.

INRIA

Page 12: On-The-Fly Range Reduction - COnnecting REpositories · 2 3 3 4 * if mod 1!65 if mod 1!87) 2 3 3 (1) * if mod 1!89 if mod 1!( 2 3 3 * ) * if mod 1!8: if mod 1!8; 2 3 3) * if mod 1!=<

On-the-fly Range Reduction 9

[4] M. D. Ercegovac and T. Lang. On-the-fly conversion of redundant into conventionalrepresentations. IEEE Transactions on Computers, C-36(7), July 1987. Reprintedin E. E. Swartzlander, Computer Arithmetic, Vol. 2, IEEE Computer Society PressTutorial, Los Alamitos, CA, 1990.

[5] M. D. Ercegovac and T. lang. On-line arithmetic: a design methodology and appli-cations in digital signal processing. In VLSI Signal Processing III, pages 252–263,1988. Reprinted in E. E. Swartzlander, Computer Arithmetic, Vol. 2, IEEE ComputerSociety Press Tutorial, Los Alamitos, CA, 1990.

[6] M. D. Ercegovac and T. Lang. On-the-fly rounding. IEEE Transactions on Computers,41(12):1497–1503, December 1992.

[7] M. D. Ercegovac and T. Lang. Division and Square Root: Digit-Recurrence Algo-rithms and Implementations. Kluwer Academic Publishers, Boston, 1994.

[8] J.M. Muller. Elementary Functions, Algorithms and Implementation. Birkhauser,Boston, 1997.

[9] M. Payne and R. Hanek. Radian reduction for trigonometric functions. SIGNUMNewsletter, 18:19–24, 1983.

[10] J. E. Robertson. A new class of digital division methods. IRE Transactions on Elec-tronic Computers, EC-7:218–222, 1958. Reprinted in E. E. Swartzlander, ComputerArithmetic, Vol. 1, IEEE Computer Society Press Tutorial, Los Alamitos, CA, 1990.

[11] R. A. Smith. A continued-fraction analysis of trigonometric argument reduction. IEEETransactions on Computers, 44(11):1348–1351, November 1995.

[12] K. S. Trivedi and M. D. Ercegovac. On-line algorithms for division and multiplication.In 3rd IEEE Symposium on Computer Arithmetic, pages 161–167, Dallas, Texas, USA,1975. IEEE Computer Society Press, Los Alamitos, CA.

RR n˚4043

Page 13: On-The-Fly Range Reduction - COnnecting REpositories · 2 3 3 4 * if mod 1!65 if mod 1!87) 2 3 3 (1) * if mod 1!89 if mod 1!( 2 3 3 * ) * if mod 1!8: if mod 1!8; 2 3 3) * if mod 1!=<

Unit e de recherche INRIA Lorraine, Technopole de Nancy-Brabois, Campus scientifique,615 rue du Jardin Botanique, BP 101, 54600 VILLERS LES NANCY

Unit e de recherche INRIA Rennes, Irisa, Campus universitaire de Beaulieu, 35042 RENNES CedexUnit e de recherche INRIA Rhone-Alpes, 655, avenue de l’Europe, 38330 MONTBONNOT ST MARTIN

Unit e de recherche INRIA Rocquencourt, Domaine de Voluceau, Rocquencourt, BP 105, 78153 LE CHESNAY CedexUnit e de recherche INRIA Sophia-Antipolis, 2004 route des Lucioles, BP 93, 06902 SOPHIA-ANTIPOLIS Cedex

EditeurINRIA, Domaine de Voluceau, Rocquencourt, BP 105, 78153 LE CHESNAY Cedex (France)

http://www.inria.frISSN 0249-6399