Abstract:
A trigonometric function preprocessing system used for calculating a value of a given trigonometric function of a given numerical data, including a dividend register coupled to store the given numerical data as a dividend; a divisor register coupled store a divisor; and an arithmetic divider having a pair of inputs coupled to the dividend and divisor registers for generating a quotient and a remainder. A quotient register is coupled to store the quotient and first, second and third flags are provided to be coupled to the quotient register so as to store three least significant bits of the quotient. Further, a fourth flag is provided for storing information indicative of a sign of the given numerical data. A first logic circuit is coupled to at least two of the first to fourth flags for determining a sign of an output value of the given trigonometric function. A second logic circuit is coupled to at least two of the first to third flags for selecting one of a sine function and a cosine function to be executed.

Description:
BACKGROUND OF THE INVENTION 
     1. Field of the invention 
     The present invention relates to a trigonometric function preprocessing system. 
     2. Description of related art 
     Heretofore, in order to obtain the value of trigonometric functions such as sin X and cos Y, there have been known a variety of algorithms such as series expansions, for example Taylor expansion or Chebyshev expansion, or so-called CORDIC. However, since it is not useful to use these algorithms in a broadly defined area in view of precision and time of operation, it is an ordinary practice to first execute a residue arithmetic operation so that the remainder of X comes under an extent of 0 to π/4 and then to apply the algorithms to only a narrow extent of 0&lt;×&lt;π/4. 
     In brief, a conventional trigonometric function processing system has executed the following steps by means of microprograms. Specifically, in the case of obtaining trigonometric functions such as Y=sin X and Y=cos X, the residue arithmetic operation is carried out by putting X as a dividend and π/4 as a divisor so that the remainder R fulfils a condition of 0&lt;R&lt;π/4. Then, three least significant bits of a quotient of the residue arithmetic operation are examined bit by bit so as to sequentially set corresponding three flags. Two values are selected from the three flags thus set and another flag indicative of a sign of a given input X and a sign of the solution Y is determined on the basis of the selected two values. Further, another pair of values are selected from the three flags thus set, and the type of a trigonometric function operation to be executed is selected on the selected pair of values. Thereafter, the selected trigonometric function operation is executed so as to obtain an absolute value of the solution Y, and then, the absolute value thus obtained and the sign of the solution already obtained are combined to give a value of the solution Y. 
     As seen from the above, since the conventional system processes the above mentioned various steps by means of microprograms, it has required a large number of program steps, particularly for the sequential process for setting the three flags, the sequential process for determining the sign of the solution and the sequential process for selecting the type of trigonometric function operation to be executed. Therefore, the conventional system has needed a long execution time. 
     SUMMARY OF THE INVENTION 
     Accordingly, it is an object of the present invention to provide a trigonometric function preprocessing system which has overcome the above mentioned defect of the conventional one. 
     Another object of the present invention is to provide a trigonometric function preprocessing system capable of obtaining the value of the trigonometric function with a decreased number of program steps and with a reduced execution time. 
     A further object of the present invention is to provide such a trigonometric function preprocessing system which is capable of obtaining the value of the trigonometric function at a reduced execution time, only with a small number of additional circuit elements. 
     The above and other objects of the present invention are achieved in accordance with the present invention by a trigonometric function preprocessing system used for calculating a value of a given trigonometric function of a given numerical data comprising a dividend register coupled to store the given numerical data as a dividend; a divisor register coupled store a divisor; an arithmetic divider having a pair of inputs coupled to the dividend and divisor registers for generating a quotient and a remainder; a quotient register coupled to store the quotient; first, second and third flags coupled to the quotient register so as to store the three least significant bits of the quotient; a fourth flag for storing information indicative of a sign of the given numerical data; first logic unit coupled to at least two of the first to fourth flags for determining a sign of an output value of the given trigonometric function; and a second logic unit coupled to at least two of the first to third flags for selecting one of a sine function and a cosine function to be executed. 
     As seen from the above mentioned arrangement, in a system for calculating a trigonometric function by executing a residue arithmetic operation, the present invention provides a hardware means for setting the three least significant bits of an obtained quotient Q to three corresponding flags. Further, there are provided a logic circuit for determining the sign of the output on the basis of the sign of the input and/or the values of the flags and for selecting the type of the trigonometric function to be executed on the basis of the values of the flags. Therefore, the present invention will make it unnecessary to carry out the setting of the flags, determination of the sign of the output and the type of the trigonometric function to executed. Thus, the system in accordance with the present invention can execute a calculation of a trigonometric function with a decreased number of program steps, and hence at a reduced time of execution. 
     The above and other objects, features and advantages of the present invention will be apparent from the following description of a preferred embodiment of the invention with reference to the accompanying drawings. 
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS 
     FIG. 1 is a graph showing one example of a trigonometric function &#34;sin X&#34;; 
     FIG. 2 is a flowchart of an example of a calculation of &#34;sin X&#34; executed in a conventional trigonometric function calculation system; 
     FIG. 3 is a graph showing one example of a trigonometric function &#34;cos X&#34;; 
     FIG. 4 is a flowchart of an example of a calculation of &#34;cos X&#34; executed in a conventional trigonometric function calculation system; 
     FIG. 5 is a block diagram of one embodiment of the trigonometric function preprocessing system in accordance with the present invention; 
     FIG. 6 is a flowchart of an example of a calculation of &#34;sin X&#34; executed in the trigonometric function calculation system shown in FIG. 5; and 
     FIG. 7 is a flowchart of an example of a calculation of &#34;cos X&#34; executed in the trigonometric function calculation system shown in FIG. 5; 
    
    
     DESCRIPTION OF THE PREFERRED EMBODIMENT 
     First, description will be made on one example of an algorithm for calculating the trigonometric function &#34;Y=sin X&#34; with reference to FIG. 1. A first step is to execute a residue arithmetic operation by putting X as a dividend and π/4 as a divisor so that a remainder R and a quotient Q are obtained, respectively. Specifically, R=X·mod (π/4). A flag &#34;fc&#34; is set on the basis of the least significant bit of the quotient Q obtained as the result of the residue arithmetic operation, and thereafter, two flags &#34;fb&#34; and &#34;fa&#34; are sequentially set on the next and third least significant bits of the quotient Q, respectively. Specifically, if the least significant bit of the quotient Q is &#34;1&#34;, the flag &#34;fc&#34; is set to &#34;1&#34;. If the second significant bit is &#34;1&#34;, the flag &#34;fb&#34; is set to &#34;1&#34;. If the third significant bit is &#34;1&#34;, the flag &#34;fa&#34; is set to &#34;1&#34;. Moreover, a sign flag SF is set in accordance with the sign of the given number X. 
     In this situation, the relation between the value and the sign SF of X and the values of flags &#34;fa&#34;, &#34;fb&#34;, &#34;fc&#34; can be expressed as shown in the following table 1. 
     
                                           TABLE 1__________________________________________________________________________ X    ##STR1##__________________________________________________________________________SF 1111111100000000fa 1111000000001111fb 1100110000110011fc 1010101001010101__________________________________________________________________________ 
    
     As seen from comparison between the above table 1 and FIG. 1, if &#34;fc&#34; is &#34;1&#34;, a replacement of R=π/4-R is made. An exclusive-OR between &#34;fb&#34; and &#34;fc&#34; is sought. If fc  ○+  fb=&#34;1&#34;, &#34;cos R&#34; is calculated. Otherwise, if fc  ○+  fb=&#34;0&#34;, &#34;sin R&#34; is calculated. The calculation of the trigonometric function is carried out by means of CORDIC or series expansion. As a result, an absolute value |Y| is obtained. On the assumption that SF of &#34;1&#34; indicates that X is negative and SF of &#34;0&#34; shows that X is positive, on the other hand, the sign of Y is determined from an exclusive-OR between the sign SF of X and the flag &#34;fa&#34;. Thus, Y=sin X is obtained. 
     Next, description will be made on a conventional calculation method of Y=sin X with reference to the flowchart shown in FIG. 2. 
     In an initialized condition, the flags &#34;fa&#34;, &#34;fb&#34; and &#34;fc&#34; are at &#34;0&#34;, and then, the flag SF is set in accordance with the sign of X. First, as shown in a step 202, X is divided by π/4 to seek a remainder &#34;R&#34; and a quotient &#34;Q&#34;. Namely, the residue arithmetic operation &#34;R=X mod π/4&#34; is executed, and then, three least significant bits of an obtained quotient &#34;Q&#34; are sequentially examined as shown in steps 203, 205 and 207. If the least significant bit &#34;b0&#34; of the quotient &#34;Q&#34; is &#34;1&#34;, the flag &#34;fc&#34; is set to &#34;1&#34; in a step 204. If the next least significant bit &#34;b1&#34; of the quotient &#34;Q&#34; is &#34;1&#34;, the flag &#34;fb&#34; is set to &#34;1&#34; in a step 206. Further, if the third least significant bit &#34;b2&#34; of the quotient &#34;Q&#34; is &#34; 1&#34;, the flag &#34;fa&#34; is set to &#34;1&#34; in a step 208. 
     Then, in a step 209, a decision is made on whether or not &#34;fc&#34; is &#34;1&#34;. If &#34;fc&#34; is &#34;1&#34;, the replacement of R=π/4-R is performed in a step 210. Further, the flag SF and &#34;fc&#34; are examined in steps 211, 212 and 213. If the sign flag SF is &#34;0&#34; indicating that the sign of the input X is positive and if &#34;fa&#34;=&#34;1&#34;, or if the sign flag SF is &#34;1&#34; indicating that the sign of the input X is negative and if &#34;fa&#34;=&#34;0, the sign of Y is then determined as a minus as indicated in a step 214. Otherwise, the sign of Y is determined as a plus as indicated in a step 215. 
     Thereafter, &#34;fb&#34; and &#34;fc&#34; are examined in steps 216, 217 and 218. If &#34;fb&#34;=&#34;1&#34; and &#34;fc&#34;=&#34;0&#34;, or if &#34;fb&#34;=&#34;0&#34; and &#34;fc&#34;=&#34;1&#34;, the trigonometric function &#34;cos R&#34; is derived by using the CORDIC or series expansion. Otherwise, the trigonometric function &#34;sin R&#34; is calculated by using the CORDIC or series expansion. Thus, the result obtained from the calculation is deemed as a solution of sin X. 
     Next, description will be made on one example of an algorithm for calculating the trigonometric function &#34;Y=cos X&#34; with reference to FIG. 3. A first step is to execute a residue arithmetic operation by putting X as a dividend and π/4 as a divisor so that a remainder R and a quotient Q are obtained, respectively. Specifically, R=X·mod (π/4). Similarly to the case of sin X, a flag &#34;fc&#34; is set on the basis of the least significant bit of the quotient Q obtained as the result of the residue arithmetic operation, and thereafter, two flags &#34;fb&#34; and &#34;fa&#34; are sequentially set on next and third least significant bits of the quotient Q, respectively. 
     In this situation, the relation between the value and the sign SF of X and the values of flags &#34;fa&#34;, &#34;fb, &#34;fc&#34; can be expressed as shown in the following table 2. 
     
                                           TABLE 2__________________________________________________________________________ X    ##STR2##__________________________________________________________________________SF 1111111100000000fa 1111000000011111fb 1100110000110011fc 1010101001010101__________________________________________________________________________ 
    
     As seen from comparison between the above table 2 and FIG. 3, if &#34;fc&#34; is &#34;1&#34;, a replacement of R=π/4 -R is made. An exclusive-OR between &#34;fb&#34; and &#34;fc&#34; is sought. If fc  ○+  fb=&#34;0&#34;, cos R is calculated. Otherwise, if fc  ○+  fb=&#34;1&#34;, sin R is calculated. The calculation of the trigonometric function is carried out by means of CORDIC or series expansion. As a result, an absolute value |Y| is obtained. On the other hand, the sign of Y is determined from an exclusive-OR between the flags &#34;fa&#34; and &#34;fb&#34;. Thus, Y=cos X is obtained. 
     Then, description will be made on a conventional calculation method of Y=cos X with reference with a flowchart shown in FIG. 4. 
     In an initialized condition, the flags &#34;fa&#34;, &#34;fb&#34; and &#34;fc&#34; are at &#34;0. First, as shown in a step 402, X is divided by π/4 to seek a remainder &#34;R&#34; and a quotient &#34;Q&#34;. Specifically, the residue arithmetic operation &#34;R=X mod π/4 is executed, and then, the three least significant bits of an obtained quotient &#34;Q&#34; are sequentially examined as shown in steps 403, 405 and 407. If the least significant bit &#34;b0&#34;  of the quotient &#34;Q&#34; is &#34;1&#34;, the flag &#34;fc&#34; is set to &#34;1&#34; in a step 404. If the next least significant bit &#34;b1&#34; of the quotient &#34;Q&#34; is &#34;1&#34;, the flag &#34;fb&#34; is set to &#34;1&#34; in a step 406. Further, if the third least significant bit &#34;b2&#34; of the quotient &#34;Q&#34; is &#34;1&#34;, the flag &#34;fa&#34; is set to &#34;1&#34; in a step 408. 
     Then, in a step 409, a decision is made as to whether or not &#34;fc&#34; is &#34;1&#34;. If &#34;fc&#34; is &#34;1&#34;, the replacement of R=π/4-R is performed in a step 410. Further, the flag &#34;fa&#34; and &#34;fb&#34; are examined in steps 411, 412 and 413. If &#34;fa&#34;=&#34;1&#34; and &#34;fb&#34;=&#34;1&#34;, or if &#34;fa&#34;=&#34;0&#34; and &#34;fb&#34;=&#34;0&#34;, the sign of Y is then determined as a plus as indicated in a step 414. Otherwise, the sign of Y is determined as a minus as indicated in a step 415. 
     Thereafter, &#34;fb&#34; and &#34;fc&#34; are examined in steps 416, 417 and 418. If &#34;fb&#34;=&#34;1&#34; and &#34;fc&#34;=&#34;0&#34;, or if &#34;fb&#34;32 &#34;0&#34; and &#34;fc&#34;=&#34;1&#34;, the trigonometric function &#34;sin R &#34; is calculated by using the CORDIC or series expansion. Otherwise, the trigonometric function &#34;cos R &#34; is calculated by using the CORDIC or series expansion. Thus, the result obtained from the calculation is deemed as a solution of cos X. 
     As seen from the above mentioned description, the conventional system for calculating the trigonometric function will need a large number of program steps, since the flags &#34;fa&#34;, &#34;fb&#34; and &#34;fc&#34; are set in the course of a programmed process, while examining the three least significant bits of the quotient of the residue arithmetic operation &#34;R=X modπ/4, and since the sign of the output and the type of trigonometric function to be executed are determined in the course of a programmed process. Therefore, the conventional method inevitably requires a long execution time. 
     Referring to FIG. 5, there is shown a block diagram of one embodiment of the trigonometric function preprocessing system in accordance with the present invention. The shown system comprises a dividend register 10 coupled to an internal bus 12 to receive a dividend X through the bus 12, and divisor register 14 coupled to the bus 12 to receive a divisor, for example π/4. These registers 10 and 14 are coupled to a pair of inputs of an adder-subtracter 16 composed of for example an arithmetic and logic unit (called &#34;ALU&#34; hereinafter). An output of the ALU 16 is coupled to a remainder register 18, which is in turn coupled to the bus 12 so as to feed back a remainder to the dividend register 10 for cyclic operation of subtraction. In addition, the most significant bit of the remainder register 18 is connected through an invertor 20 to a quotient register 22. Three least significant bits of the quotient registers 22 are coupled to three flags &#34;fa&#34;, &#34;fb&#34; and &#34;fc&#34;, 24, 26 and 28, respectively. Further, another flag &#34;SF&#34; 30 is provided for hold the information indicative of the sign of an input data X of an output data Y. 
     Moreover, there are provided three exclusive-OR gates 32, 34 and 36. The exclusive-OR gate 32 is connected to receive outputs of the flag &#34;fa&#34; 24 and the flag &#34;SF&#34; 30 and has an output connected to a selector 38. The exclusive-OR gate 34 is connected to receive outputs of the flag &#34;fa&#34; 24 and the flag &#34;fb&#34; 26 and has the output connected to a selector 38. The exclusive-OR gate 36 is connected to receive outputs of the flag &#34;fb&#34; 26 and the flag &#34;fc&#34; 28. The selector 38 is adapted to respond the outputs of the exclusive-OR gates so as to select the type of the trigonometric function to be calculated. 
     Turning to FIG. 6, there is shown a flowchart of a calculation example of &#34;sin X &#34; executed in the trigonometric function calculation system shown in FIG. 5. 
     First, the dividend X is stored in the dividend register 10, and the divisor π/4 is set to the divisor register 14. A residue arithmetic operation of R=X·mod (π/4) is executed by the ALU 16 in a step 602, so that a remainder R and a quotient Q are stored in the remainder register 18 and the quotient register 22, respectively. In a next step 603, the three flags &#34;fa&#34;, &#34;fb&#34; and &#34;fc&#34;, 24, 26 and 28, are set by the three least significant bits of the quotient Q stored in the register 22, respectively. 
     Then, examination is made as to whether or not the flag &#34;fc&#34; is &#34;1&#34; in a step 604. If &#34;fc&#34; is &#34;1&#34;, π/4-R is set in the remainder register 18 in place of R in a step 605. An exclusive-OR between &#34;fa&#34; and &#34;SF&#34; is sought by the exclusive-OR gate 32. Specifically, the output of the exclusive-OR gate 32 determines the sign of the output Y. In response to the output of the exclusive-OR gate 32, the selector 38 will set the sign flag SF so that it indicates the sign of the output Y. 
     Thereafter, in a further step 407, the exclusive-OR between &#34;fb&#34; and &#34;fc&#34; is obtained by the exclusive-OR gate 36. If fc +fb =&#34;1&#34;, the selector 38 instructs to cause &#34;cos R&#34; to be calculated. Otherwise, the selector 38 instructs to cause &#34;sin R&#34; to be calculated. Thereafter, the calculation of the selected trigonometric function is carried out in a known manner by means of CORDIC or series expansion. 
     Next, description will be made on a calculation example of &#34;cos X &#34; with reference to shown in FIG. 7. 
     First, the dividend X is stored in the dividend register 10, and the divisor π/4 is set to the divisor register 14. A residue arithmetic operation of R=X·mod (π/4) is executed by the ALU 16 in a step 702, so that a remainder R and a quotient Q are stored in the remainder register 18 and the quotient register 22, respectively. In a next step 703, the three flags &#34;fa&#34;, &#34;fb&#34; and &#34;fc&#34;, 24, 26 and 28, are set by the three least significant bits of the quotient Q stored in the register 22, respectively. 
     Then, examination is made as to whether or not the flag &#34;fc&#34; is &#34;1&#34; in a step 704. If &#34;fc&#34; is &#34;1&#34;, the remainder register 18 is set as R=π/4-R in a step 705. An exclusive-OR between &#34;fa&#34; and &#34;fb&#34; is sought by the exclusive-OR gate 34. Specifically, the output of the exclusive-OR gate 34 determines the sign of the output Y. In response to the output of the exclusive-OR gate 34, the selector 38 will set the sign flag SF so that it indicates the sign of the output Y. 
     Thereafter, in a further step 407, the exclusive-OR between &#34;fb&#34; and &#34;fc&#34; is outputted from the exclusive-OR gate 36. If fc+fb=&#34;0&#34;, the selector 38 instructs to cause &#34;cos R&#34; to be calculated. Otherwise, the selector 38 instructs to cause &#34;sin R&#34; to be calculated. The calculation of the selected trigonometric function is carried out in known manner by means of CORDIC or series expansion. 
     As seen from the above mentioned description, in a system for calculating a trigonometric function such as sin X and cos Y by executing a residue arithmetic operation putting X as a dividend and π/4 as a divisor so that a remainder R becomes larger than &#34;0&#34; but less than &#34;π/4&#34;, the embodiments of the present invention provide a hardware means for setting three least significant bits of the obtained quotient Q to three corresponding flags. Further, the above mentioned embodiments provide a logic circuit means for determining the sign of the output Y on the basis of the sign of the input X and/or the values of the flags and for selecting the type of the trigonometric function to executed on the basis of the values of the flags. Therefore, the embodiments will not require the steps 203 to 208, 211 to 213, 216 to 218, 403 to 408, 411 to 413 and 416 to 418 which are executed by microprograms in the conventional system. Thus, the embodiments can execute a calculation of a trigonometric function with a decreased number of program steps, and hence at a reduced time of execution. 
     The invention has thus been shown and described with reference to the specific embodiments. However, it should be noted that the present invention is in no way limited to the details of the illustrated structures but changes and modifications may be made within the scope of the appended claims.