An Efficient Overflow Detection and Correction Scheme in RNS Addition through Magnitude Evaluation

Number Systems are media for representing numbers; the popular ones being the Weighted Number Systems (WNS), which sometimes propagate carries during arithmetic computations. The other category, Un-Weighted Number Systems, of which the Residue Number System (RNS) belongs, do not carry weights but have not yet found widespread usage in general purpose computing as a result of some challenges; one of the main challenges of RNS is overflow detection and correction. The presence of errors in calculated values due to such factors as overflow means that systems built on this number system will continue to fail until serious steps are taken to resolve the issue. In this paper, a scheme for detecting and correcting overflow during RNS addition is presented. The proposed scheme used mixed radix digits to evaluate the magnitude of the addends in order to detect the occurrence of overflow in their sum. The scheme also demonstrated a simplified technique of correcting the overflow in the event that it occurs. An analysis of the hardware requirements and speed limitations of the scheme showed that it performs considerably better in relation to similar state of art schemes.


Introduction
The Residue Number System (RNS) has gained prominence in recent years due to its seemingly inherent features such as parallelism and carry-propagation free arithmetic computations.Notwithstanding the fact that, RNS is currently being applied in Digital Signal Processing (DSP) intensive computations like digital filtering, convolutions, correlations, Discrete Fourier Transform (DFT) computations, Fast Fourier Transform (FFT) computations and Direct Digital Frequency synthesis [1] [2] [3]; researchers in the area are still working hard around the clock in order that the RNS becomes a general purpose processor.These efforts have not completely come to fruition because of challenges, including conversion to and from RNS and decimal/binary number systems, the moduli sets to use, overflow detection and correction, magnitude evaluation, and scaling.
An RNS number X, is represented as , where , , ,  is uniquely represented provided X lies within the legitimate range [ ] 0, 1 M − where is the Dynamic Range (DR) for the chosen moduli set.Let X and Y be two different integers within the DR, if X Y  , (  are the arithmetic operations , , , + − × ÷ ), results in a value that is outside the legitimate range, then overflow is said to have occurred.
Overflow in general computing occurs if a calculated value is greater than its intended storage location in memory [4] [5]; this relates to the DR in RNS which situation usually arises during addition and multiplication operations and failure to detect it will lead to improper or wrong representation of numbers and calculated results.Thus detecting overflow is one of the fundamental issues in the design of efficient RNS systems [6].
The conversion of an RNS number into its decimal/binary equivalent number (a process called reverse conversion) has long been mainly based on the Chinese Remainder Theorem (CRT) and the Mixed Radix Conversion (MRC) techniques with few modifications being their variants of recent times.Whiles the former deals with the modulo-M operation, the later does not but computes sequentially which tends to reduce the complexity of the architecture.Computations can be done using the MRC as follows:

X e e m e m m e m m m −
where , 1, 2, ,  are the Mixed Radix Digits (MRDs) and computed as follows: The MRDs i e are within the range 0 i i e m ≤ ≤ , and a positive number, X, in the interval [ ] 0, M can be uniquely represented.The magnitude of a number can become crucial in the determination overflow in RNS.The sign of an RNS number is determined by partitioning M into two parts: (for negative integers).
Recently, some techniques have been developed to detect overflow without necessarily completing the reverse conversion process; in [7], an algorithm to detect overflow in the moduli set ( ) are distributed among several groups.Then, by using the groupings, the scheme is able to diagnose in the process of addition of two numbers, whether overflow has occurred or not.The scheme in [3] evaluated the sign of the sum of two numbers X and Y and used it to detect overflow but adopted a residue-to-binary converter proposed by [9].The scheme in [10] presented a scheme by an Operands Examination Method for overflow detection for the moduli set ( ) All these schemes either relied on complete reverse conversion process as in the case of [3], or other costly and time consuming procedures such as base extension, group number and sign detection as in [8] and [10].
In this paper, a new technique for detecting and correcting overflow during the addition of two RNS numbers for the moduli set { } − + is presented; the technique evaluates the sign of an RNS number by performing a partial reverse conversion using the mixed radix conversion method.The sign of the addends is evaluated using only the MRDs, which is then used to detect the occurrence of overflow during RNS addition.The rest of the paper is organized as follows: Section 2 presents the proposed method, an anticipated hardware implementation (albeit theoretical) is presented in Section 3 with its realization in Section 4. Numerical illustrations are shown in Section 5 whiles the performance of the proposed scheme is evaluated in Section 6.The final part of this paper is the conclusion in Section 7.

Proposed Method
Given the moduli set { } This implies ( )( ) ( )( ) Lemma 1: Given the moduli set { } Therefore, we can re-write (2) as; Proof: If it can be shown that by substituting ( 9) and (10) into Equation (4) that, ( )( ) ) 9) and (10), it is possible to determine the sign of an RNS number X; whether 2 X M ≥ (for a negative number) or 2 X M < (for a positive number).
The proposed method uses comparison by computing the MRDs of each of the addends to determine which half of the RNS range it belongs rather than performing a full reverse conversion.To detect overflow during addition of two addends X and Y based on the moduli set { } dicates the sign of that addend is defined.Now, based on this bit, three cases will then be considered: 1) Overflow will definitely occur if both of the addends are equal to or greater than half of the dynamic range (M/2).
2) Overflow will not occur if both of the addends are less than M/2.
3) Overflow may or may not occur if only one of the addends is equal or greater than M/2 and will require further processing to determine whether over-Journal of Computer and Communications flow will occur or not.
Let the magnitude evaluation of the addends ( ) , X Y be represented by β , such that if 1 β = or 0 β = represents a positive number or a negative num- ber respectively as shown in Equation (11).The evaluation of the undetermined case in (3) is also represented by a single bit λ in (12). and, The proposed method will then detect overflow as follows: where ( ) , , + ⋅ ⊕ refer to the logical operations (OR, AND, XOR), respectively.For clarity, "1" means overflow occurs whilst "0" means no overflow.

Correction Unit
Let Z be the sum of the two addends.By substituting the individual MRDs for both addends (X and Y), Z can be obtained as follows;

Z X Y e X e X m e X m m e Y e Y m e Y m m e X e Y e X e Y m e X e Y mm
e X e Y ψ = + , we shall have Thus by adding the individual MRDs of the two addends, we obtain the sum Z according to (1) without having to compute separately for its MRDs.The value of Z obtained from ( 14) is the correct result of the addition whether overflow occurs or not.In case of overflow occurrence, the redundant modulus is employed by shifting M one bit to the left in order to accommodate the value.

Hardware Implementation
From Equation ( 8), the MRD's 1 e , 2 e and 3 e can be represented in binary as;  15) to (17) can further be simplified as follows; where, and ) x is a number that is smaller than 2 1 n + , two cases are considered for 1 x .First, when 1 x is smaller than 2 n , and second, when 1 x is equal to Else if 1, 1 n x = , the following binary vector can be obtained as Therefore, 3 t is calculated as And finally, ( ) Thus from equations ( 19) to (21), we have which implies and so, Z is implemented as; 1, 1,0 3,3 1 3,0 4,2 1 4,0 where,

Hardware Realization
The hardware realization of the proposed scheme is divided into four parts as Journal of Computer and Communications shown in Figures 1-4 19) and ( 21) with their parameters clearly defined according to (20) and ( 21) -( 27).The PCP begins with an Operands Preparation Unit (OPU) which prepares the operands in (20), ( 22) and ( 26) by simply manipulating the routing of the bits of the residues.Also, an n-bit 2:1 Multiplexer (MUX) is used for obtaining (26).ADD1 is an n-bit Carry Propagate Adder (CPA) and is used to compute (19), meanwhile (21) is obtained by using an ( ) 1 n − -bit CPA as ADD2 whose save ( 1 s ) and carry ( 1 c ) are then added using ADD3 which is also an ( ) 1 n − -bit CPA.These MRDs are used to determine the sign of the RNS number in Figure 2. Thus, the critical path for the PCP unit is made up of one ( ) 2 n modulo adder and two ( )    Second, is the Magnitude Evaluation Part (MEP) shown in Figure 2, which evaluates whether an RNS number is positive or negative according to Equation (11).The MEP uses one AND gate and an OR gate.These are both two input monotonic gates.Next, is the Overflow Detection Part (ODP) which compares the sign bits of the two addends by using an AND gate according to (13) which is then ORed with the evaluated bit of the undetermined case in (12) as shown in Figure 3.This is where the scheme detects the occurrence of overflow during the addition of two numbers.
Lastly, in Figure 4 is the Overflow Correction Part (OCP).The OCP evaluates the individual MRDs of the two addends separately to achieve the sum Z in (14).This is done using five adders; four regular CPAs and one carry save adder (CSA).This is computed according to (29) -(36).ADD4, ADD5 and ADD6 add separately the MRDs 1 2 , e e and 3 e respectively for the two addends.The re- sult of ADD4 is of importance because it is used in evaluating the undetermined case in (12). 2 z is a result of concatenation as well as 3 z which do not require any hardware.ADD7 is a CSA which computes the result of 1 2 , z z and 3 z whose save ( 2 s ) and carry ( 2 c ) are added using ADD 8 which is a CPA in order to get accurate sum Z whether overflow occurs or not.The schematic diagrams for the proposed scheme are presented in Figures 1-4.
The area (A) and time (D) requirements of the proposed scheme are estimated based on the unit-gate model as used in [12] and [13] for fair comparison.In this model, each two-input monotonic gate such as AND, OR, NAND, NOR has The area and delay of an inverter is a negligible fraction of a unit, and it is thus assumed to require zero units of area and delay [14].A 2:1 multiplexer has an area 3 A = and delay 2 D = ; A full adder has an area of seven gates and a delay of four gates but a CSA has a constant delay.Also, the adder requirements based on this model as presented in [14] is adopted for the comparison since the adopted adders are similar to the adders used for the proposed scheme.The results state that an estimation modulo; ( ) Therefore, the hardware requirements of the scheme are as follows: 63 14 The estimated delay of the scheme will be as follows:  Now, in order to make an effective comparison, the proposed scheme is divided into two: Proposed Scheme I for when the OCP is not included in the comparison and Proposed Scheme II for the OCP being included in the comparison.The delay of the OCP overrides the delay of the delays of the MEP and the ODP if Proposed Scheme II is consider since they will all be computed in parallel and the critical path in that case will be dictated by the OCP.The area for the PCP and the MEP is double for two numbers X and Y but this is not the case for the delay of the two numbers since they are computed in parallel.Thus, the total area and delay of the proposed schemes are:

Numerical Illustrations
This subsection presents numerical illustrations of the proposed scheme.
Checking overflow in the sum of 49 and 21 using RNS moduli set {3, Thus, from (13) 0 overflow = , which implies no overflow has occurred ac- cording to the proposed scheme after processing.

Performance Evaluation
The performance of the proposed scheme is compared to schemes in [3] and [8]; the scheme in [8] does not contain a correction unit; the scheme by [3] has a correction unit but is not included in the comparison.And so both schemes do not have the correction component in the comparison.Table 1 shows the analysis of the proposed scheme with that of similar state-of-the art schemes.
As shown in Table 1, the proposed scheme for detecting overflow (Proposed Scheme I) in the given moduli set is very cheap in terms of hardware resources and faster than the scheme by [8] but requires a little hardware resources than the scheme by [3] albeit slower than the Proposed Scheme I.However, the complete proposed scheme (Proposed Scheme II) for detecting and correcting overflow requires more hardware resources than the other compared schemes but faster than both schemes by [3] and [8].
Clearly, Proposed Scheme I completely outperforms the similar state-of-the-art scheme by [8] for detecting overflow, but the trust of this work is to detect and correct overflow anytime it occurs; in so doing it has made tremendous gains in speed as shown in Table 1.
Table 2 shows a detailed analysis of the complexities and delay of the proposed scheme with that of the similar state-of-the-art schemes.
Table 2 reveals interesting results theoretically, from the analysis it is clear that the Proposed Scheme I requires less resources than what is required by [8].
From the table, smaller values of n shows that Proposed Scheme II requires more resources than that by [8] but drastically improves upon this requirements up to over 51% better than [8] for higher values of n (i.e.n > 4), this is clearly shown in the graph in Figure 5.The analysis from the table also shows that whilst for smaller values of n (say n = 1), the Proposed Scheme I is better than the scheme by [3] in terms of hardware resources, it tends to require up to about 18% resources more than that by [3].
From Figure 5, the scheme by [8] sharply increases for higher values of n followed by the Proposed Scheme II whilst the scheme by [3] requires the lesser resources.Regarding the delay, the proposed schemes (Proposed I and Proposed II) completely outperforms both schemes by up to over 35% than the scheme by [8] and over 90% faster than the scheme by [3] as shown in Table 2 and in Figure 5.It is worth noting that whiles the scheme by [3] performs better in terms of hardware resources, it tends to be the worst performer for speed and the  percentage difference shows that Proposed I is more efficient.It is clear from the graphs that in terms of delay, the scheme in [3] sharply increases with increasing values of n whiles the marginal increase of the rest of the schemes are minimal.

Conclusion
Detecting overflow in RNS arithmetic computations is very important but can be difficult, more so, if it has to be corrected.In this paper, an ingenious technique of detecting overflow by use of the MRC method through magnitude evaluation as well correcting the overflow when it occurs was presented.This technique did not require full reverse conversion but used the MRDs to evaluate the sign of a number to detect the occurrence of overflow.With this technique, the correct value of the sum of two numbers is guaranteed whether overflow occurred or not.The scheme has been demonstrated theoretically to be very fast than similar-state-of-the-art scheme but required a little more hardware resources.However, the Proposed Scheme I, which is the one without the correction component completely outperformed the scheme in [8] in terms of both area and delay requirements.Also, results from Table 2 and Figure 5 showed that for higher values of n, the Proposed Scheme II also outperformed the scheme by [8].Future works will focus on simulating the theoretical results and implementing it on FPGA boards.

( 2 )
Journal of Computer and Communications for every integer 1 n > , the following hold true[10]: Journal of Computer and Communications (17) Journal of Computer and Communications Equations ( 25) Journal of Computer and Communications ω represent the MRDs of the two integers X and Y respectively.
. First is the Partial Conversion Part (PCP) shown in Figure 1, which evaluates the MRDs based on (18), (
Journal of Computer and Communications RNSwill result in the decimal number 10. Whilst the sum of the decimal numbers 49 and 21 is 70 which is obvious of overflow occurring.Checking for RNS overflow using the proposed technique > − , the scheme detects overflow oc- curring after processing.Checking overflow in the sum of 10 and 11 using RNS moduli set {3, RNS will result in the decimal number 21, which is correct result of 10 + 11.Checking for RNS overflow using the proposed algorithm

Figure 5 .
Figure 5. Graphs of area and delay analysis of the various compared schemes.

Table 2 .
Area, delay analysis for various values of n.