Chip, method and device for modulo multiplication
The method improves hardware area and power efficiency in modulo multiplication by using reduction and split operations to process compounds without explicit carry bit processing, specifically for special moduli, achieving 14% less hardware area and 20% less power consumption.
Patent Information
- Application Number
- PCT/RU2023/000056
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-03-07
- Publication Date
- 2024-09-12
AI Technical Summary
Existing modulo multiplication methods in residual number systems face challenges in reducing hardware area and improving power efficiency, particularly for special moduli m = 2n— 2p+ 1 and m = 2n+ 2p+ 1, where the complexity and size of the reduction step are significant limitations.
A method for modulo multiplication that involves receiving two inputs, performing binary multiplication, acquiring compounds with a correction term through reduction and split operations, and then processing these compounds to reduce the bit width, thereby reducing hardware area and power consumption by avoiding explicit carry bit processing and repeating reduction and split operations.
The proposed method reduces hardware area by 14% and power consumption by 20% compared to existing solutions, effectively addressing the limitations of hardware area and power efficiency for modulo multiplication, especially for special moduli within the specified ranges.
Smart Images

Figure RU2023000056_12092024_PF_FP
Abstract
Description
CHIP, METHOD AND DEVICE FOR MODULO MULTIPLICATIONTECHNICAL FIELD
[0001] Embodiments of the present application relate to the field of residual number system (RNS), and more specifically, to a method and device for modulo multiplication.BACKGROUND
[0002] In a residual number system (RNS), a modulo multiplication unit for arbitrary modulo is usually done by a binary multiplication unit followed by a modulo reduction unit. The target goal of almost all the improvements for modulo multiplication is to reduce the complexity and the size of a reduction step.
[0003] A naive way to computing modulo reduction c = a mod m would be to use a division algorithm: c = a — [a / m] • m. Another way is a Barrett reduction algorithm, which was designed to replace very expensive divisions by multiplications. It became less expensive than the naive one, but still requires two multiplications to get the result. Another way is partitioning reduction, and in partitioning reduction, the result of multiplication is split into a set of digits under a special algorithm which replaces expensive multiplication operations by additions and small cheap constant multipliers. Lei Li et al. proposed a partitioning reduction solution for special moduli m = 2n— 2p+ 1. His idea is based on the basic modulo property |Am + B|m= |B|mto simplify the partitioning. Lei Li’s design shows better hardware area and power efficiency for special moduli m = 2n— 2p± 1 with small p compared to an arbitrary modulo reduction design. However, it has significant limitations, that is, the design can be implemented only if The hardware area and power efficiency of modulomultiplication are still a main problem that needs to be solved. iSUMMARY
[0004] Embodiments of the present application provide a method for modulo multiplication, which can reduce hardware area and improve power efficiency.
[0005] According to a first aspect, provided is a method for modulo multiplication, including: receiving two inputs, where the two inputs are remainders on which binary multiplication needs to be performed; acquiring a multiplication result by performing the binary multiplication on the two inputs, where a bit width of the multiplication result is greater than n, n is an integer; acquiring a set of compounds with a correction term (CT) by performing a reduction operation and a split operation based on the multiplication result, where a bit width of each compound in the set is equal to or less than n; acquiring two n + w bit width partial sums by joining the set of the compounds and the CT together, where w is determined according to m, and m is a modulo of the modulo multiplication; acquiring an intermediate result by performing an arithmetic addition on the two n + w bit width partial sums, where a bit width of the intermediate result is greater than n; acquiring two parts by performing a reduction operation on the intermediate result, where an addition result of the two parts is less than 2m; and outputting a reduction result by comparing the addition result of the two parts with m.
[0006] The solution proposed by the present application uses the basic modulo property and does not explicitly process a carry bit. An intermediate result undergoes a reduction operation and a split operation repeatedly to reduce the complexity and the size of a reduction step of the prior art, and hardware area can be reduced and power efficiency can be improved.
[0007] The solution proposed by the present application extends special moduli count in range (2,256) to 1.5X. It has been tested that, the solution proposed by the present application would occupy 14% less hardware area and consumes 20% less power compared with already exist solutions.
[0008] In an embodiment of the first aspect, m = 2n— 2p+ 1, and bit widths of the two inputs are both n, and 2 < p < n, p is an integer; orwhere m = 2n+ 2p± 1, and bit widths of the two inputs are both n + 1, n^4 and 3 < p < n, p is an integer.
[0009] In an embodiment of the first aspect, a range of p is for m =2n— 2p+ 1 and the range of p is
[0010] The range of p proposed in this embodiment gets better benefits in terms of reducing hardware area and improving power efficiency.
[0011] In an embodiment of the first aspect, the acquiring a set of compounds with a CT by performing a reduction operation and a split operation based on the multiplication result includes: splitting the multiplication result by a low part and a high part; acquiring the set of the compounds with the CT by performing the reduction operations t times and a split operation(s) t — 1 times based on the high part of the multiplication result, where t ≥ 2 and t is an integer; where a first t — 1 times of reduction operation(s) is in one to one correspondence with the t — 1 times of the split operation(s), each of the first t — 1 times of the reduction operation(s) generates a low part and a high part, and the i-th of the t — 1 times of the split operation(s) is performed for a high part which is generated in the i-th of the first t — 1 times of the reduction operation(s), the i-th of the t — 1 times of the split operation(s) generates a first part and a second part, the first part generated in the i-th split operation is used as an operand of the (i+l)-th reduction operation, where the first part generated in the i-th split operation is a part that excludes a part of lower n bits of the high part generated in the i-th reduction operation from the high part generated in the i-th reduction operation, and the second part generated in the i-th split operation is a part of lower n bits of the high part generated in the i-th reduction operation, where 1 ≤ i ≤ t — 1 and i is an integer; where an operand of the first of the first t — 1 times of the reduction operation(s) is the high part of the multiplication result; the set of the compounds are determined after the t-th of t times of the reductionoperations is performed, where the set of the compounds comprises the low part of the multiplication result, a low part(s) generated in the first t — 1 times of the reduction operation(s), a second part(s) generated in the t — 1 times of the split operation(s), and a low part and a high part generated in the t-th of the t times of the reduction operations.
[0012] In an embodiment of the first aspect, the multiplication result is of a n + z bit width, and the low part of the multiplication result and the high part of the multiplication result are determined as follows:where P[n + z — 1: 0] is the multiplication result, P[n — 1: 0] is the low part of the multiplication result, 2nP[n + z — 1: n] is the high part of the multiplication result, a bit width of 2nP[n + z — 1: n] is n + z and is greater than n; a low part and a high part are generated by performing the first of the t — 1 times of the reduction operation(s) on the high part of the multiplication result as follows:where 2nP[n + z — 1: n] is the high part of the multiplication result, P[n + z — l: n] is a low part generated in the first of the t — 1 times of the reduction operation(s) , 2pP[n + z — l:n] is a high part generated in the first of the t — 1 times of the reduction operation(s), a bit width of 2pP[n + z — 1 : n] is p + z, and the first of the t — 1 times of the split operation(s) is performed on 2pP[n + z — 1: n] in a case that p + z is greater than n.
[0013] In an embodiment of the first aspect, each of the two inputs is of a n bit width for m = 2n— 2P+ 1, the multiplication result is of a 2n bit width, and the set of the compounds are as follows:where P0~P6arethe set of compounds, and a symbol # is used to concatenate bits.
[0014] In an embodiment of the first aspect, the intermediate result is as follows:where R is the intermediate result, is a ones’ complement of Pi
[0015] In an embodiment of the first aspect, each of the two inputs is of a n + 1 bit width for m = 2n+ 2P± 1, the multiplication result is of a 2n + 1 bit width, and the set of the compounds are as follows:where P0~P6are the compounds in the set, and a symbol # is used to concatenate bits.
[0016] In an embodiment of the first aspect, the intermediate result is as follows:where R is the intermediate result, and P; is a one’s complement of Pt.
[0017] In an embodiment of the first aspect, w is determined according to m based on a formula as follows:
[0018] In an embodiment of the first aspect, the acquiring two parts by performing a reduction operation on the intermediate result, includes: acquiring the two parts by performing the reduction operation on the intermediate result as follows:where R is the intermediate result, R1and R2are the two parts, and a symbol # is used to concatenated bits.
[0019] In an embodiment of the first aspect, the outputting a reduction result by comparing the addition result of the two parts with m includes:where Y is the reduction result, R1and R2are the two parts.
[0020] According to a second aspect, a chip (or a chip system) is provided. The chip has a function of implementing the method in the first aspect, and any embodiment of the first aspect. The function may be implemented by using hardware structures. Alternatively, the chip or chip system includes an interface and a plurality of circuits.
[0021] According to a third aspect, a chip (or a chip system) is provided. The chip includes a binary multiplier, hardware unit(s), a plurality of CSAs, an arithmetic adder and a multiplexer. The chip has a function of implementing the method in the first aspect, and any embodiment of the first aspect. The function may be implemented by using the foregoing hardware structures.
[0022] According to a fourth aspect, a device is provided, including a chip or a chip system of the third aspect.DESCRIPTION OF DRAWINGS
[0023] One or more embodiments are exemplarily described by corresponding accompanying drawings, and these exemplary illustrations and the accompanying drawings constitute no limitation on the embodiments. Elements with the same reference numerals in theaccompanying drawings are illustrated as similar elements, and the drawings are not limited to scale, in which:
[0024] FIG. 1 is a regular modular multiplication structure.
[0025] FIG. 2 is a schematic diagram of a method for modulo multiplication of the present application.
[0026] FIG. 3 is a high level structure of modulo multiplication for m = 2n± 2p± 1.
[0027] FIG. 4 is an example of compound generation for m = 2n— 2p+ 1.
[0028] FIG. 5 is an example of compound generation for m = 2n+ 2p+ 1.
[0029] FIG. 6 is a schematic block diagram of a chip or chip system according to an embodiment of the present application.
[0030] FIG. 7 is a schematic block diagram of a chip or a chip system according to another embodiment of the present application.DESCRIPTION OF EMBODIMENTS
[0031] In order to understand features and technical contents of embodiments of the present disclosure in detail, implementations of the embodiments of the present disclosure will be described in detail below with reference to the accompanying drawings, and the attached drawings are only for reference and illustration purposes, and are not intended to limit the embodiments of the present disclosure. In the following technical descriptions, for ease of explanation, numerous details are set forth to provide a thorough understanding of the disclosed embodiments. One or more embodiments, however, may be practiced without these details. In other cases, well-known structures and apparatuses may be simplified in order to simplify the drawings.
[0032] Related technologies and concepts are introduced here firstly in order to better understand the technical solution proposed by the present application.
[0033] A residual number system (RNS) is defined by a set of k integers m2, ... , mk} called a moduli set. Any two integers in the moduli set must be pairwise coprime, i.e., GCD(mi, mj) = 1, i,j ∈ [1, k], i #= j. Let M be a product of all mi:. M = then aninteger x in a range of [0, M — 1] is uniquely represented in the RNS by a set of its remaindersx {x1, x2.. xk} under Euclidean division by the moduli set; that is, xi= x mod and 0 < Xi < mtfor each i.
[0034] According to the Chinese Remainder Theorem (CRT), x can be reconstructed from RNS as:
[0035] The RNS has many advantages, such as independent (parallel) addition, subtraction and multiplication operations between corresponding remainders:
[0036] One of the greatest RNS features is that addition and multiplication operations between pairs of corresponding remainders are independent and can be performed in parallel as there is no need to propagate carry between the remainders. Area consumption and power efficiency of modulo multiplication highly depend on the magnitude of the highest modulo in a moduli set and the efficiency of every modulo multiplication operation. A modulo multiplication unit for arbitrary modulo is usually done via a regular multiplication block followed by a modulo reduction unit. FIG. 1 shows a regular modular multiplication structure. As shown in FIG. 1, two n bit width remainders are multiplied with a regular binary multiplication block, and a multiplication result is of a 2n bit width. The multiplication result is processed in a reduction block followed by the binary multiplication block, and a reduction result | A • B |mis outputted as shown in FIG. 1. The target goal of almost all the improvements for modulo multiplication is to reduce the complexity and the size of the reduction step.
[0037] The present application proposes a method for modulo multiplication for special moduli m = 2n— 2p± 1, where n > 3 and 2 < p < n and m = 2n+ 2p+ 1, where n > 4 and 3 < p < n, and n and p are integers. A range of p that can achieve better technical effects is that2p+ 1. It can be seen that a lower limit of p is slightly different for m = 2n— 2p+ 1 and m = 2n+ 2p+ 1. The method for modulo multiplication proposed by present application canreduce hardware area and improve power efficiency.
[0038] Proposed solution of the present application uses the basic property of modulo m = 2n+ 2P+ 1 and does not process a carry bit, which is opposite to other solutions. The proposed solution covers the moduli m = 2n± 2p+ 1 and it is not limited by a range of p. Specifically, p is less than n and p can be up to n — 1, and better technical effects are achieved with p < - + 1, as described above.2
[0039] The present application can be used in matrix multiplication hardware accelerators by switching all the multiplication and accumulation operations to the RNS. As there are n3modular multipliers required for a matrix multiplication device, a single improvement for one modulo multiplier gives hardware area reduction and power efficiency improvement in an entire device.
[0040] The following describes the proposed solution of the present application in more details.
[0041] FIG. 2 is a schematic diagram of a method (200) for modulo multiplication of the present application. The method (200) specifically includes the following steps:
[0042] Step 210: receiving two inputs, where the two inputs are two remainders on which binary multiplication needs to be performed.
[0043] For an example, the two inputs are A and B shown in FIG. 1. As mentioned above, the moduli proposed by the present application cover m = 2n± 2p+ 1. Both the two inputs are of a n bit width for m — 2n— 2p+ 1 and of a n+1 bit width for m = 2n+ 2p+ 1.
[0044] Step 220: acquiring a multiplication result by performing the binary multiplication on the two inputs, where a bit width of the multiplication result is greater than n.
[0045] The multiplication result is of a 2n bit width in a case that the two inputs are of a n bit width, and the multiplication result is of a 2n + 2 bit width in a case that the two inputs are of a n + 1 bit width. Note that the multiplication result is 2n + 2 bit width for generic A • B, where A < m and B < m. But if p is limited by in the present application, the multiplication result of A • B will not exceed 2n + 1 bits. Therefore, in the present application, a wording “modulo multiplication result is 2n + 1 bit width” is used in a case that m = 2n+ 2p± 1.
[0046] Step 230: acquiring a set of compounds with a correction term (CT) by performing a reduction operation and a split operation based on the multiplication result, where a bit width of each compound in the set is equal to or less than n.
[0047] Specifically, the multiplication result is represented by a low part and a high part, and then the reduction operation can be performed on the high part of the multiplication result in a case that a bit width of the high part of the multiplication result is greater than n. The reduction operation performed on the high part of the multiplication result is the first reduction operation, and generates a low part and a high part. A bit width of the high part generated in the first reduction operation is determined, and a first split operation is performed on the high part generated in the first reduction operation in a case that a bit width of the high part generated in the first reduction is greater than n. The first split operation generates a first part and a second part, where the second part is a part of lower n bits of the high part generated in the first reduction operation, and the first part is a part that excludes a part of lower n bits of the high part generated in the first reduction operation from the high part generated in the first reduction operation. A second reduction operation is performed on the first part generated in the first split operation, and generates a low part and a high part. A second split operation is performed on the high part generated in the second reduction operation in a case that a bit width of the high part generated in the second reduction operation is greater than n. The second split operation generates a first part and a second part, where the first part generated in the second split operation is a part that excludes a part of lower n bits of of the high part generated in the second reduction operation from the high part generated in the second reduction operation, and the second part generated in the second split operation is a part of lower n bits of the high part generated in the second reduction.
[0048] Suppose that a split operation is performed t — 1 times, it can be understood that a reduction operation is performed t — 1 times correspondingly, each of the t — 1 times of the split operation(s) is performed after a corresponding reduction operation is performed, and each of the t — 1 times of the split operation(s) is performed in a case that a bit width of a high part generated in the corresponding reduction operation is greater than n. The i-th of the t — 1 times of the split operation(s) generates a first part and a second part, the first part generated in the i-th split operation is used as an operand of the (i+ 1 )-th reduction operation. A high partgenerated in the (i'+ 1 )-th reduction operation is used as an operand of the (i+ 1 )-th split operation, where l < i + l < t — 1 and i is an integer, and so on. A t-th split operation does not exist until that a bit width of a high part generated in the t-th reduction operation is equal to or less than n. The set of the compounds are determined after the t-th reduction operation is performed. That is, a first t — 1 times of the reduction operation(s) is in one to one correspondence with the t — 1 times of the split operation(s). The set of the compounds include the low part of the multiplication result, a low part(s) generated in the first t — 1 times of the reduction operation(s), a second part(s) generated in the t — 1 times of the split operation(s), and both a low part and a high part generated in the t-th reduction operation.
[0049] Given all that, the set of the compounds are determined by performing the reduction operation t times and the split operation t — 1 times based on the high part of the multiplication result, where t > 2 and t is an integer.
[0050] Alternatively, the reduction operation also can be called a shift operation, and it is not restricted in the present application.
[0051] The determination of the CT will be introduced in following text.
[0052] Step 240: acquiring two n + w bit width partial sums by joining the set of the compounds and the CT together, where w is determined according to m, m is a modulo of the modulo multiplication.
[0053] Specifically, w is determined according to m based on a formula as follows:
[0054] Step 250: acquiring an intermediate result by performing an arithmetic addition on the two n + w bit width partial sums, where a bit width of the intermediate result is greater than n.
[0055] Step 260: acquiring two parts by performing a reduction operation on the intermediate result, where a bit width of an addition result of the two parts is less than 2m.
[0056] The reduction operation is performed on the intermediate result in a case that the bit width of the intermediate result exceeds n bits. The intermediate result is represented by the two parts which are determined by performing the reduction operation on the intermediate result. Note that the reduction operation in step 260 is similar to that in step 230, and differs in operandsof the reduction operation. Reduction operations mentioned in step 230 are performed on the high part of the multiplication result and the high parts generated in the split operations, and the reduction operation mentioned in step 260 is performed on the intermediate result.
[0057] Step 270: outputting a reduction result by comparing the addition result of the two parts with m.
[0058] The proposed solution of the present application uses the basic property of special moduli (m = 2n± 2P± 1) and does not process a carry bit. The intermediate result undergoes the reduction operation and the split operation repeatedly to reduce the complexity and the size of a reduction step. Therefore, hardware area can be reduced and power efficiency can be improved.
[0059] FIG. 3 is a high level structure of modulo multiplication according to the present application. As shown in FIG. 3, first of all, two remainders, that is, A and B, are multiplied with a binary multiplication block (for example, a binary multiplier) and the binary multiplication block outputs a multiplication result, that is, P shown in FIG. 3. The multiplication result is split into a set of compounds with a CT by a reduction operation and a split operation, where the set of compounds are represented by P1~P6. In addition, FIG. 3 uses m = 2n— 2p+ 1 as an example, P2is concatenated with P3, and P5is concatenated with P6, which is represented as P23 and P56respectively. On level- 1 addition, addition operations are performed on the set of the compounds and the CT, and the intermediate result, that is, R, is obtained. On level-2 addition, the intermediate result R is split into two parts, for example, Ri and R2, by the reduction operation, where R1+ R2< 2m. On the last level, a reduction result, that is, T, is obtained by comparing the addition result of the two parts with m. Note that, a CSA tree provides two parts that are sum and carry. Carry is of a n + w bit width, sum is of a n + w — 1 bit width but implicitly expanded to a n + w bit width with leading zero. The addition result of sum and carry is also of a n + w bit width due to the resulted number of the compounds in the set.
[0060] A multiplication result of the two inputs (for example, A and B in FIG. 3) can be represented by a low part and a high part. Take m = 2n— 2p± 1 as an example, both A and B are of a n bit width in this case, and the multiplication result of the two inputs is of a 2n bit width. P can be represented by a low part and a high part as follows:M[n - 1: 0] X B[n - 1: 0]|m= |P[2n - 1: 0] |m|P[n — 1: 0] + 2nP[2n — where P[n — 1: 0] is the low part of P, and 2nP[2n — l: n] is the high part of P.
[0061] The basic modulo property mentioned in the present application is as follows:\Am + B\m= |B|m
[0062] According to the modulo property, the high part of the multiplication result is reduced if we add and subtract ( as follows:]2nP[2n — l: n]\m= |(2n- 2p± l)P[2n - l: n] + (2p+ l)P[2n - l: n]|m= |2pP[2n — l: n] + lP[2n - l:n]|m
[0063] For m = 2n+ 2P± 1, the multiplication result P also can be represented by a low part and a high part, and the high part is reduced by a way which is similar to that of m = 2n— 2p± 1.
[0064] We call the above reducing process a reduction operation in the present application. It can be seen that, the multiplication result is split into a high part 2pP[2n — 1: n] and a low part P[2n — 1: n] by the reduction operation.
[0065] The high part 2pP[2n — 1: n] is a n+p bit width and exceeds a n bit width, and can be split into a first part and a second part by performing a split operation according to the present application.
[0066] Therefore, based on the special moduli proposed by the present application, the binary multiplication result can be split into a set of compounds with constant correction terms (CTs). As long as the bit width of the current number is greater than n, take the current number being a n + z bit width as an example, the current number can be represented as a low part and a high part as follows:|P[n + z — 1: 0]|m= |P[n - 1: 0] + 2nP[n + z - l: n]|m(1)
[0067] The high part is reduced with adding and subtractingThe first compound is vanished due to the modulo property |Am + F|m= |B|m:(2)If P0= P[n — 1: 0], Pt= P[n + z — 1: n], and P2= 2pP[n + z — 1: n], formula(1) can be described as:
[0068] The formulas (1)~(3) have no limitation on n or p. If a bit width of any of new compounds P1, P2in formula (3) is greater than n, each of the new compounds can be split into a first part and a second part by performing a split operation, where the first part of a new compound is a part that excludes a part of lower n bits of the new compound from the new compound, and the second part of a new compound is a part of the lower n bit of the new compound. Next, if a bit width of the first part of a new compound is greater than n bit width, a reduction operation can be performed on the first part of the new compound, and so on. The reduction operation and the split operation are repeated until all the parts are equal to or less than n bits.
[0069] For m = 2n— 2p+ 1, A and B are both of a n bit width, the multiplication result P is of a 2n bit width. Through the reduction operation and the split operation proposed by the present application, P is split into a set of compounds with the correction terms, and the compounds in the set can be represented as follows:
[0070] Obviously, for P with a 2n bit width, a first split operation is required as P2is of a n+p bit width, and new compounds P3, P4are created. If4will have extra kbits, a second split operation is required and P5, P6are created, etc.
[0071] It should be understood that, if k=0, P5and P6do not exist according to the formulas (4) and (5).
[0072] As a bit width of P3is equal to p, a bit width of P6is less than p, and they canbe concatenated with P2and P5respectively to reduce the final number of compounds. For p = + 1, the reduction operation is performed three times and the split operation is performed twice until each of the compounds is equal to or less than a n bit width and five compounds are generated.
[0073] For m = 2n— 2p+ 1 in formula (6), some parts such as -P1?-P3or -P6have a negative sign. To avoid subtraction operations, the parts which have a negative sign can be converted to the positive ones. For m = 2n— 2p+ 1, a conversion can be used: -Pi=Pt + 1 + 2p+ 1 = Pi + CTi, where Pi is a one’s complement of Pi. For shifted Pi, all zeros should be replaced with ones which will interfere with the combination of the compounds in the set of the present application. But it is more useful to invert only significant bits of Pi and add additional (2p— 1) instead of right zeros to CTtand (2n— 2p+k) instead of left ones. For example:
[0074] The CT is a sum of and the CT is a constant value anddepends only on m.
[0075] The formula (6) is changed to a formula (7) as follows:where R is the intermediate result.
[0076] A multiple- input adder compresses five / six compounds and the CT, and obtains two n + w bit width partial sums. Then a two- input adder performs an arithmetic addition operation on two partial sums and outputs the intermediate result R, where w is determined as follows:
[0077] The intermediate result can be split into two parts as follows:
[0078] Simple modulo addition with two adders and one multiplexer is used to get a final result, that is, the reduction result Y.
[0079] For m = 2n— 2p— 1 and all compound joints in formula (7) would bepositive and combined to comply with a limitation of n bit width for each part of the multiplication result:
[0080] The reduction result is calculated by a subtract operation and a comparing operation according to the formula (11), and is not repeated here.
[0081]
[0082] The CT includes CTtfrom all reduction-split operations and would be:
[0083] The same reduction operation and split operation can be applied to m = 2n+ 2p±1 with no difference. The multiplication result can be split into a set of compounds with a CT, and the compounds are P0~P6as follows:p
[0084] For m = 2n+ 2p+ 1, the remainders A and B are both of a n+1 bit width, and the multiplication result of the modulo multiplication is of a 2n+2 bit width, the multiplication result is not represented by two parts with an equal bit width.
[0085] For m = 2n+ 2p+ 1, the reduction operation or the split operation becomes more complex due to additional parts combined. Parts P2and P3can’t be concatenated due to gap and part widths mismatch. But P5and P6can be concatenated to one joint. As additional width of an adder is w > 2 bits, a split of Pxis not required. Formula for the intermediate result calculation contains seven compounds as follows:
[0086] To avoid subtraction, formula (15) is transformed into formula (16) as follows:
[0087] In the cases m = 2n+ 2p+ 1, the main problem is to identify the correction terms.For shifted parts, we need to fill all empty bits in an original value with ones in CT. To do this we may add (2p— 1) instead of right zeros to CTi and (2n— 2p+x) instead of left ones. As we use ones’ complement variables, additional 2p+ 1+1 is required for modulo invert operation.CTi can be simplified by reducing explicit m = 2n+ 2p+ 1.
[0088] For m = 2n+ 2p— 1, the CT is determined by following CTi:
[0089] For m — 2n+ 2p+ 1 , because R1< 4m , regular n bit ones’ complement is incorrect. The CT can be virtually split into four parts and each part requires additional 2p+1 correction terms:
[0090] For better understanding of the present application, two detailed examples are given below for m = 2n— 2p± 1 and m = 2n+ 2p+ 1, respectively.
[0091] FIG. 4 is an example of compound generation for m = 2n— 2p± 1 . In this example, the two remainders A and B are of a n bit width, and the multiplication result P is of a 2n bit width, where n=7, p=4, and 2n=14. The multiplication result is represented as P, where P = [dcba9876543210] = P[b13: b0]. P is of a 2n bit width and is greater than n bit width. P can be represented by a low part and a high part. P[b13: b0]=P[b6: b0]+27P[b13: b7]. That is to say, the low part of P[b13: b0] is P[b6-. b0], that is, P0, and the high part of F[b13: b0] is 27P[b13: b7] . P0is of a 7 bit width and 27P [b13: b7] is of a 14 bit width. 27P[b13: b7] is wider than 7 bits and is reduced byperforming a first reduction operation to acquire a high part and a low part, which are 24P [b13: b7] and P[b13: b7], respectively, where P[b13: b7] = P1. 24P[b13: b7] can be split into a first part and a second part by performing the first split operation, the first part of 24P [b13: b7] is 27P[b13: b10] , and the second part of 24P[b13: b7] is P[b9: b7] , that is, P2.The first part of 24P[b13: b7], that is 27P[b13: b10], is of a 11 bit width and can be reduced by performing the second reduction operation, and acquires a low part and a high part, which are P[b13: b10] and 24P[b13: b10], respectively, where P[b13: b10] = P3. 24P[b13: b10] is of a 8 bit width which is wider than 7 bits and can be split into a first part and a second part by performing the second split operation, where the first part of 24P[b13: b10] is 27P[b13], and the second part of 24P[b13: b10] is P[b12: b10], that is, P4. The first part of 24P[b13: b10], that is, 27P[b13], is of a 8 bit width and can be reduced by performing a third reduction operation and acquires a low part and a high part, which are P [b13] and 24P [b13], respectively, where P[b13] = P6, and 24P[b13] = P5. The high part 24P[b13] is of a 5 bit width and is less than n(n = 7) bit width, and the set of the compounds can be determined after the third reduction operation is performed. In other words, the third reduction operation generates a high part 24P[b13] (that is, P5) and a low part P[b13], that is, P6. Since a bit width of the high part generated in the third reduction operation is less than n, a third split operation does not exist. It can be seen that, the set of compounds include the low part of the multiplication result, that is, P0, the low parts generated in the first reduction operation and the second reduction operation, that is, Ptand P3, the second parts generated in the first split operation and the second split operation, that is, P2and P4, and the high part generated in the third reduction operation and the low part generated in the third reduction operation, that is, P5and P6. In addition, all empty cells are filled with zeros. Obviously, in case of k=0, only P0~P4arecreated as no bugled bits exist after the second reduction operation, so P5and P6will not exist.
[0092] FIG. 5 is an example of compound generation for m = 2n+ 2p+ 1 . In this example, the two remainders A and B are of a n + 1 bit width, and the multiplication result P is of a 2n + 1 bit width, where n=7 and n=4. P = [fedcba9876543210] = P[b15: b0]. P can be represented by a low part and a high part. P[b15-. b0]= P[b6: b0]+ 27P[b15: b7]. The low part of P[b15: b0] is P[b6: b0] = P0, and the high part of P[b15: b0] is 27P[b15: b7]. P0isof a 7 bit width and 27P[b15: b7] is of a 16 bit width. 27P[b15: b7] is wider than 7 bits and is reduced by performing the first reduction operation to acquire a high part and a low part, which are 24P[b15: b7] and P[b15: b7], respectively, where P[b15: b7] = P124P [b15: b7] can be split into a first part and a second part by performing the first split operation, the first part of 24P[b15: b7] is 27P[b15: b10], and the second part of 24P[b15: b7] is P[b9: b7] = P2. The first part of 24P[b15: b7], that is, 27P[b15: b10], is of a 13 bit width and can be reduced by performing the second reduction operation, and acquires a low part and a high part, which are P[b15: b10] and 24P[b15: b10], respectively, where P[b15: b10] = P3. 24P[b15: b10] is of a 10 bit width which is wider than 7 bits and can be split into a first part and a second part by performing the second split operation, where the first part of 24P[b15: b10] is 27P[bis : b13] , and the second part of 24P[b15: b10] is P[b12: b10] that is, P4. The first part of 24P[b15: b10], that is, 27P[b15: b13], is of a 10 bit width and can be reduced by performing a third reduction operation and acquires a low part and a high part, which are P[b15: b13] and 24P[b15: b13], respectively, where P[b15: b13] = P&, and 24P[b15: b13] = P5. The high part 24P[b15: b13] is of a 7 bit width, and the set of the compounds are determined after the third reduction operation is performed. Since a bit width of the high part generated in the third reduction operation is equal to n, a third split operation does not exist. Similarly, the set of compounds include the low part of the multiplication result, that is, P0, the low parts generated in the first reduction operation and the second reduction operation, that is, Ptand P3, the second parts generated in the first split operation and the second split operation, that is, P2and P4, and the high part generated in the third reduction operation and the low part generated in the third reduction operation, that is, P5and P6. All empty cells are filled with zeros.
[0093] It has been mentioned above that the reduction operation also can be called the shift operation. Alternatively, the operation representing the multiplication result into a high part and a low part also can be regarded as a split operation, and the operation representing the multiplication result into the low part and the high part is the first split operation. The first reduction operation is the first shift operation, and the first split operation marked in FIG. 4 or FIG. 5 becomes the second split operation. The second reduction operation is the second split operation, and the second split operation marked in FIG. 4 or FIG. 5 becomes the third split operation. The third reduction operation is the third shift operation. In this way, a shift-splitprocess shown in FIG. 4 includes three split operations and three shift operations, and a shiftsplit process shown in FIG. 5 also includes three split operations and three shift operations, which can be understand by the person skilled in the art, and is not repeated here.
[0094] FIG. 6 is a schematic block diagram of a chip or a chip system 10 of the present application.
[0095] As shown in FIG. 6, the chip (or the chip system) may include an interface 11 and a plurality of circuits 12. Alternatively, the interface 11 is configured to receive two inputs and transmit the two inputs to the plurality of circuits 12. The plurality of circuits 12 perform the method 200, to output a reduction result based on the two inputs.
[0096] Alternatively, the interface 11 includes an input interface and an output interface, where the input interface is configured to receive the two inputs, and the output interface is configured to output the reduction result from the plurality of circuits 12. As an embodiment, the interface 11 is an interface circuit.
[0097] As an embodiment, the function of the chip is implemented by hardware, such as the plurality of circuits 12, and the hardware includes one or more corresponding structures, such as binary multipliers, hardware unit(s), arithmetic adders, CSAs, multiplexers, and so on.
[0098] FIG. 7 is a schematic block diagram of a chip (or a chip system) 20 according to another embodiment of the present application. As shown in FIG. 7, the chip 20 includes: a binary multiplier (21), configured to: receive two inputs and acquire a multiplication result by performing binary multiplication on the two inputs, where a bit width of the multiplication result is greater than n, and n is an integer; a first hardware unit (22) for reduction and split operations, configured to: acquire a set of compounds with a correction term (CT) by performing a reduction operation and a split operation based on the multiplication result, where a bit width of each compound in the set is equal to or less than n a plurality of carry-save adders (CSAs) (23), configured to: receive the compounds in the set and the CT ; output two n + w bit width partial sums by joining the compounds in the set and the CT together, where w is determined according to m, and tn is a modulo of the modulomultiplication; an arithmetic adder (24), configured to: receive the two n + w bit width partial sums and output an intermediate result by performing an arithmetic addition on the two n + w bit width partial sums, where a bit width of the intermediate result is greater than n; a second hardware unit (25) for a reduction operation, configured to: acquire two parts by performing a reduction operation on the intermediate result, where an addition result of the two parts is less than 2m; and a multiplexer (26), configured to: output a reduction result by comparing an addition result of the two parts with m.
[0099] Alternatively, the first hardware unit (22) and the second hardware unit (25) are the same one or different ones.
[0100] For description of the corresponding operations in apparatus embodiments, reference can be made to related content of the steps in the foregoing method embodiment.
[0101] The foregoing descriptions of the implementations allow a person skilled in the art to clearly understand that, for ease and brevity of description, division into the foregoing functional modules is used as an example for illustration. In actual application, the foregoing functions may be allocated to and implemented by different modules depending on a requirement, that is, an inner structure of an apparatus is divided into different functional modules to implement all or some of the functions described above. For detailed working processes of the foregoing apparatus and unit, refer to corresponding processes in the foregoing method embodiments, and details are not described herein.
[0102] In the several embodiments provided in this application, it should be understood that the disclosed system and method may be implemented in other manners. For example, the described apparatus embodiment is merely an example. For example, the unit division is merely logical function division and may be other division in actual implementation. For example, a plurality of units or components may be combined or integrated into another system, or some features may be ignored or not performed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections may be implemented through some interfaces. The indirect couplings or communication connections between the apparatusesor units may be implemented in electronic, mechanical, or other forms.
[0103] The units described as separate parts may be or may not be physically separate, and parts displayed as units may be or may not be physical units, may be located in one position, or may be distributed on a plurality of network units. Some or all of the units may be selected based on actual requirements to achieve the objectives of the solutions of the embodiments. In addition, functional units in the embodiments of this application may be integrated into one processing unit, or each of the units may exist alone physically, or two or more units are integrated into one unit.
[0104] The foregoing descriptions are merely specific implementations of this application, but are not intended to limit the protection scope of this application. Any variation or replacement readily figured out by a person skilled in the art within the technical scope disclosed in this application shall fall within the protection scope of this application. Therefore, the protection scope of this application shall be subject to the protection scope of the claims.
Claims
CLAIMSWhat is claimed is:
1. A chip or a chip system, comprising: a binary multiplier, configured to: receive two inputs and acquire a multiplication result by performing binary multiplication on the two inputs, wherein a bit width of the multiplication result is greater than n, and n is an integer; a first hardware unit for reduction and split operations, configured to: acquire a set of compounds with a correction term (CT) by performing a reduction operation and a split operation based on the multiplication result, wherein a bit width of each compound in the set is equal to or less than n; a plurality of carry-save adders (CSAs), configured to: receive the set of the compounds and the CT; output two n + w bit width partial sums by joining the set of the compounds and the CT together, wherein w is determined according to m, and m is a modulo of the modulo multiplication; an arithmetic adder, configured to: receive the two n + w bit width partial sums and output an intermediate result by performing an arithmetic addition on the two n + w bit width partial sums, wherein a bit width of the intermediate result is greater than n; a second hardware unit for a reduction operation, configured to: acquire two parts by performing a reduction operation on the intermediate result, wherein an addition result of the two parts is less than 2m; and a multiplexer, configured to: output a reduction result according to an addition result of the two parts with m.
2. The chip or the chip system according to claim 1, wherein m = 2n— 2p+ 1, and bit widths of the two inputs are both n, where n^3 and 2 < p < n, and p is an integer; or wherein m = 2n+ 2p± 1, and bit widths of the two inputs are both n + 1, where4 and 3 < p < n, and p is an integer.
3. The chip or the chip system according to claim 2, wherein a range of p is 2 < p < ^ + 1 for m = 2n— 2p+ 1 and the range of p is 3 < p < ^ + 1 for m = 2n+ 2P± 1.
4. The chip or the chip system according to any one of claims 1 to 3, wherein the first hardware unit is configured to: split the multiplication result into a low part and a high part; acquire the set of the compounds with the CT by performing the reduction operations t times and a split operation(s) t — 1 times based on the high part of the multiplication result, where t > 2 and t is an integer; wherein a first t — 1 times of reduction operation(s) is in one to one correspondence with the t — 1 times of the split operation(s), each of the first t — 1 times of the reduction operation(s) generates a low part and a high part, and the i-th of the t — 1 times of the split operation(s) is performed for a high part which is generated in the i-th of the first t — 1 times of the reduction operation(s), the i-th of the t — 1 times of the split operation(s) generates a first part and a second part, the first part generated in the i-th split operation is used as an operand of the (i+ 1 )-th reduction operation, the first part generated in the i-th split operation is a part that excludes a part of lower n bits of the high part generated in the i-th reduction operation from the high part generated in the i-th reduction operation, and the second part generated in the i-th split operation is a part of lower n bits of the high part generated in the i-th reduction operation, where 1 ≤ i ≤ t — 1 and i is an integer, wherein an operand of the first of the first t — 1 times of the reduction operation(s) is the high part of the multiplication result; the set of the compounds are determined after the t-th of t times of the reduction operations is performed, wherein the set of the compounds comprise the low part of the multiplication result, a low part(s) generated in the first t — 1 times of the reduction operation(s), a second part(s) generated in the t — 1 times of the split operation(s), and a low part and a high part generated in the t-th of the t times of the reduction operations.
5. The chip or the chip system according to claim 4, wherein the multiplication result is of a n + z bit width, and the low part of the multiplication result and the high part of themultiplication result are determined as follows:|P[n + z — 1: 0]|m= |P[n — 1: 0] + 2nP[n + z — l: n] [mwherein P[n + z — 1: 0] is the multiplication result, P[n — 1: 0] is the low part of the multiplication result, 2nP[n + z — 1: n] is the high part of the multiplication result, a bit width of 2nP[n + z — 1: n] is n + z and is greater than n; a low part and a high part are generated by performing the first of the t — 1 times of the reduction operation(s) on the high part of the multiplication result as follows:wherein 2nP[n + z — 1: n] is the high part of the multiplication result, P[n + z — 1: n] is a low part generated in the first of the t — 1 times of the reduction operation(s), 2pP [n + z — 1 : n] is a high part generated in the first of the t — 1 times of the reduction operation(s), a bit width of 2pP[n + z — l: n ] is p + z , and the first of the t — 1 times of the split operation(s) is performed on 2pP[n + z — 1: n] in a case that p + z is greater than n.
6. The chip or the chip system according to claim 5, wherein each of the two inputs is of a n bit width for m = 2n— 2p+ 1, the multiplication result is of a 2n bit width, and the set of the compounds are as follows:wherein P0~P6are the set of the compounds, and a symbol # is used to concatenate bits.
7. The chip or the chip system according to claim 6, wherein the intermediate result is as follows:wherein R is the intermediate result, andis a ones’ complement of Pi.
8. The chip or the chip system according to claim 5, wherein each of the two inputs is of a n + 1 bit width for m = 2n+ 2p+ 1, the multiplication result is of a 2n + 1 bit width, and the set of the compounds are as follows:wherein P0~P6are the compounds in the set, and a symbol # is used to concatenate bits.
9. The chip or the chip system according to claim 8, wherein the intermediate result is as follows:wherein R is the intermediate result, and is a ones’ complement of Pi.
10. The chip or the chip system according to any one of claims 1 to 9, wherein w is determined according to m based on a formula as follows:
11. The chip or the chip system according to any one of claims 1 to 10, wherein the second hardware unit is configured to: acquire the two parts by performing the reduction operation on the intermediate result as follows:wherein R is the intermediate result, and R2are the two parts, and a symbol # is used to concatenated bits.
12. The chip or the chip system according to claim 11, wherein the multiplexer is configured to: output a reduction result by comparing the addition result of the two parts with m as follows:wherein Y is the reduction result.
13. A chip or a chip system, comprising: an input interface, configured to: receive two inputs, wherein the two inputs are remainders on which binary multiplication needs to be performed; a plurality of circuits, configured to: acquire a multiplication result by performing the binary multiplication on the two inputs, wherein a bit width of the multiplication result is greater than n, and n is an integer; acquire a set of compounds with a correction term (CT) by performing a reduction operation and a split operation based on the multiplication result, wherein a bit width of each compound in the set is equal to or less than n; acquire two n + w bit width partial sums by joining together all compounds in the set and the CT, wherein w is determined according to m, and m is a modulo of the modulo multiplication; acquire an intermediate result by performing a binary adding on the two n + w bit width partial sums, wherein a bit width of the intermediate result is greater than n; acquire two parts by performing a reduction operation on the intermediate result, wherein an addition result of the two parts is less than 2m; andan output interface, configured to: output a reduction result by comparing the addition result of the two parts with m.
14. A method for modulo multiplication, comprising: receiving two inputs, wherein the two inputs are remainders on which binary multiplication needs to be performed; acquiring a multiplication result by performing the binary multiplication on the two inputs, wherein a bit width of the multiplication result is greater than n, and n is an integer; acquiring a set of compounds with a correction term (CT) by performing a reduction operation and a split operation based on the multiplication result, wherein a bit width of each compound in the set is equal to or less than n; acquiring two n + w bit width partial sums by joining together all compounds in the set and the CT, wherein w is determined according to m, and m is a modulo of the modulo multiplication; acquiring an intermediate result by performing an arithmetic addition on the two n + w bit width partial sums, wherein a bit width of the intermediate result is greater than n; acquiring two parts by performing a reduction operation on the intermediate result, wherein a bit width of an addition result of the two parts is less than 2m; and outputting a reduction result by comparing the addition result of the two parts with m.
15. The method according to claim 14, wherein m = 2n— 2p+ 1, and bit widths of the two inputs are both n, where n^3 and 2 < p < n, p is an integer; or wherein m = 2n+ 2p+ 1, and bit widths of the two inputs are both n + 1, where4 and 3 < p < n, and p is an integer.
16. The method according to claim 15, wherein a range ofp is 2 < p < ^ + 1 for m = 2n— 2p+ 1 and the range of p is 3 < p < j + 1 for m — 2n+ 2p± 1.
17. The method according to any one of claims 14 to 16, wherein each of the two inputs is of a n bit width for m = 2n— 2p+ 1, the multiplication result is of a 2n bit width, and the set of the compounds are as follows:wherein P0~P6are the set of the compounds, and a symbol # is used to concatenate bits.
18. The method according to claim 17, wherein the intermediate result is as follows:wherein R is the intermediate result, and Pzis a ones’ complement of Pi.
19. The method according to any one of claims 14 to 16, wherein each of the two inputs is of a n + 1 bit width for m = 2n+ 2P+ 1, the multiplication result is of a 2n + 1 bit width, and the set of the compounds are as follows:p wherein P0~P6are the compounds in the set, and a symbol # is used to concatenate bits.
20. The method according to claim 19, wherein the intermediate result is as follows:wherein R is the intermediate result, and is a ones’ complement of Pi.
21. The method according to any one of claims 14 to 20, wherein w is determined according to m based on a formula as follows:
22. The method according to any one of claims 14 to 21, wherein the acquiring two parts by performing a reduction operation on the intermediate result comprises: acquiring the two parts by performing the reduction operation on the intermediate result as follows:wherein R is the intermediate result, R1and R2are the two parts, and a symbol # is used to concatenated bits.
23. The method according to claim 22, wherein the outputting a reduction result by comparing the addition result of the two parts with m comprises:wherein Y is the reduction result.
24. A device for modulo multiplication, comprising a chip or a chip system according to any one of claims 1 to 12 or claim 13.
