Use instruction of multiply adding addition to realize the device and method of long data multiplication
Technical field
The present invention relates to the safe processor technical field, relate in particular to a kind of device and method that uses instruction of multiply adding addition to realize the long data multiplication.
Background technology
Along with the development and the widespread use of computing machine and infotech, information security seems and becomes more and more important that this makes just needs the support of consideration to the information security specific operation when chip design.
A lot of operations that information security is handled are based on carries out encryption and decryption to numerical information, in order to improve the efficient of this generic operation, is necessary to design special safe processor.
Cryptographic algorithm often need be realized the multiplication between the big data, and the length of these big data often exceeded the word length of safe processor, claims that generally this big number is a long data.So how to realize on the long safe processor of short word that the long data multiplication becomes one of gordian technique of safe processor design.
Usually way is that the decomposition long data is the sequence of a plurality of machine word-lengths, adopts common multiplying order to obtain partial product and carry respectively then, and corresponding sum of products carry then adds up.
In this way and since each intermediate result and carry all need one independently add instruction handle, so the efficient of computing is very low when having caused carrying out the long data multiplication on the long safe processor of short word, the speed of computing is also very low.
Summary of the invention
(1) technical matters that will solve
In view of this, one object of the present invention is to provide a kind of device that uses instruction of multiply adding addition to realize the long data multiplication, to improve the operation efficiency and the speed of safe processor when the multiplying of executive chairman's data.
Another object of the present invention is to provide a kind of method of using instruction of multiply adding addition to realize the long data multiplication, to improve operation efficiency and the speed of safe processor when the multiplying of executive chairman's data.
(2) technical scheme
For achieving the above object, the invention provides a kind of device that uses instruction of multiply adding addition to realize the long data multiplication, this device comprises:
The partial product generation unit is used to realize the product of first source operand and second source operand, and the product that obtains is exported to compression unit;
Compression unit is used to realize the compression of partial product, the 3rd source operand and the 4th source operand of the input of partial product generation unit, and compression result is exported to adder unit; Described the 3rd source operand is the intermediate result of respective weights, and the 4th source operand adds the carry that computing produces for last taking advantage of;
Adder unit is used for the compression result that is received from compression unit is carried out final add operation, the long-pending and carry of output.
Described partial product generation unit is one group and gate logic.
Described compression unit is made of 3 grades of compression assemblies, is respectively the 0th grade of compression assembly, the 1st grade of compression assembly and the 2nd grade of compression assembly.
Described the 0th grade of compression assembly is 3, and the 1st grade of compression assembly is 2, and the 2nd grade of compression assembly is 1.
Described first source operand, second source operand and the 3rd source operand leave in the random access memory, can adopt many bodies memory technology to obtain simultaneously.
Described the 4th source operand is fixed as carry storage register.
For reaching above-mentioned another purpose, the invention provides a kind of method of using instruction of multiply adding addition to realize the long data multiplication, this method comprises:
A, two long datas needs being done multiplication are decomposed into the first source operand sequence and the second source operand sequence by machine word-length, the various piece of the various piece of the first source operand sequence and the second source operand sequence carried out to take advantage of successively add computing, the intermediate result that described the 3rd source operand in the computing is a respective weights, the 4th source operand adds the carry that computing produces for last taking advantage of;
B, when the various piece of part of the first source operand sequence and the second source operand sequence execute take advantage of for one time add computing after, the value in the carry storage register is saved in the random access memory;
C, when the first source operand sequence various piece and the second source operand sequence various piece all execute take advantage of add computing after, in random access memory, just obtain net result.
Described instruction of multiply adding addition is: operational code first source operand, second source operand, the 3rd source operand, destination operand.
Described instruction of multiply adding addition is used for realizing { carry storage register, destination operand } ← first source operand * second source operand+the 3rd source operand+the 4th source operand; Wherein, described first source operand, second source operand and described the 3rd source operand leave in the random access memory, and described the 4th source operand is a carry storage register, lies in the operational code.
The result space size that is used to preserve net result in the described random access memory is the twice of source operand length.
Be used to preserve the result space of net result in the described random access memory, preserve the intermediate result that produces in calculating process, the result who deposits in the result space after computing is finished is exactly a net result.
Described intermediate result leaves in the described result space units corresponding according to the weights of self.
(3) beneficial effect
From technique scheme as can be seen, the present invention has following beneficial effect:
1, utilize use instruction of multiply adding addition provided by the invention to realize the device and method of long data multiplication, the corresponding unit of corresponding power is as the source operand of instruction of multiply adding addition in can be carry and result space when realizing the long data multiplication, avoid the execution of twice add instruction, improved operation efficiency and the speed of safe processor when the multiplying of executive chairman's data greatly.
2, utilize use instruction of multiply adding addition provided by the invention to realize the device and method of long data multiplication, owing to when carrying out the long data multiplication, allow the intermediate result and the carry that produce in the computing in time participate in computing as the 3rd source operand and the 4th source operand, do not need to carry out in addition add instruction and handle, so improved the speed of on the long safe processor of short word, carrying out the long data multiplication.
3, utilize use instruction of multiply adding addition provided by the invention to realize the device and method of long data multiplication, owing to directly leave the intermediate result of calculating in be used to preserve net result in the random access memory result space, needn't utilize other storage spaces to deposit intermediate result, so saved the parking space of intermediate result, also reduced the complicacy of control simultaneously.
Description of drawings
Fig. 1 is the structural representation that use instruction of multiply adding addition provided by the invention is realized the device of long data multiplication.
Fig. 2 is the method flow diagram that use instruction of multiply adding addition provided by the invention is realized the long data multiplication.
Fig. 3 uses ordinary instruction to realize the synoptic diagram of long data multiplication in the prior art; Herein, the operand with the twice word length is an example.
Fig. 4 is the data flow diagram that use instruction of multiply adding addition provided by the invention is realized the long data multiplication.
Fig. 5 uses instruction of multiply adding addition to realize the synoptic diagram of long data multiplication according to the embodiment of the invention; Herein, the operand with the twice word length is an example.
Embodiment
For making the purpose, technical solutions and advantages of the present invention clearer, below in conjunction with specific embodiment, and with reference to accompanying drawing, the present invention is described in more detail.
As shown in Figure 1, Fig. 1 is the structural representation that use instruction of multiply adding addition provided by the invention is realized the device of long data multiplication.The function that this device is realized is: { carry storage register, destination operand } ← first source operand * second source operand+the 3rd source operand+the 4th source operand.This device comprises partial product generation unit 10, compression unit 11 and adder unit 12.Wherein, partial product generation unit 10 is one group and gate logic, is used to realize the product of first source operand and second source operand, and the product that obtains is exported to compression unit 11.Compression unit 11 is made of 3 grades of compression assemblies, be respectively 3 the 0th grade of compression assemblies, 2 the 1st grade of compression assemblies and 1 the 2nd grade of compression assembly, be used to realize product, the 3rd source operand and the 4th source operand three's of 10 inputs of partial product generation unit compression, compression result is exported to adder unit 12.Described the 3rd source operand is the intermediate result of respective weights, and the 4th source operand adds the carry that computing produces for last taking advantage of.Adder unit 12 is used for the compression result that is received from compression unit 11 is carried out add operation, the long-pending and carry of output.
Described first source operand, second source operand and the 3rd source operand leave in random access memory (Random Access Memory, RAM) in, adopt many bodies memory technology to obtain simultaneously, can not increase the operand fetch time; The 4th source operand is fixed as carry storage register, and (Carry Register CR), lies in the operational code, and this operand need not show and provides when using instruction.
Realize the structural representation of the device of long data multiplication based on use instruction of multiply adding addition shown in Figure 1, Fig. 2 shows the method flow diagram that use instruction of multiply adding addition provided by the invention is realized the long data multiplication.This method uses instruction of multiply adding addition to realize the long data multiplication, amasss with carry in the middle of allowing and in time participates in computing, has improved arithmetic speed greatly, specifically may further comprise the steps:
Step 201: two long datas needs being done multiplication decompose the first source operand sequence and the second source operand sequence by machine word-length, the various piece of the first source operand sequence and various piece, intermediate result and the carry of the second source operand sequence are carried out instruction of multiply adding addition successively, the intermediate result that described the 3rd source operand in the computing is a respective weights, the 4th source operand adds the carry that computing produces for last taking advantage of;
Step 202: when various piece, intermediate result and the carry of part of the first source operand sequence and the second source operand sequence execute take advantage of for one time add computing after, the value in the carry storage register is saved in the random access memory;
Step 203: when the first source operand sequence various piece and the second source operand sequence various piece, intermediate result and carry all execute take advantage of add computing after, in random access memory, just obtain net result.
The form of above-mentioned instruction of multiply adding addition is: operational code first source operand, second source operand, the 3rd source operand, destination operand.Described instruction of multiply adding addition is used to be achieved as follows function: { carry storage register, destination operand } ← first source operand * second source operand+the 3rd source operand+the 4th source operand; Wherein, described first source operand, second source operand and described the 3rd source operand leave in the random access memory, and described the 4th source operand is fixed as carry storage register, lies in the operational code.
The result space size that is used to preserve net result in the above-mentioned random access memory is the twice of source operand length.Be used to preserve the result space of net result in the random access memory, preserve the intermediate result that produces in calculating process, the result who deposits in the result space after computing is finished is exactly a net result.Intermediate result leaves in the described result space units corresponding according to the weights of self.
Common multiplying order and add instruction be two source operands normally.Introduce the flow process of using ordinary instruction to realize the long data multiplication with an example below.
As shown in Figure 3, Fig. 3 uses ordinary instruction to realize the synoptic diagram of long data multiplication in the prior art.Herein, the operand with the twice word length is an example.Machine word-length is a byte, and A, B length are two bytes, will realize A * B now.A, B are decomposed into sequence A 1A0, the B1B0 that length is a byte.False code among Fig. 3 has been represented the flow process details of computing, at first removes to take advantage of A1A0 with B0, is capped for preventing the value in the carry storage register, needs in time to shift the value in the carry storage register before next bar multiplying order is carried out, and realizes with an ADD instruction in this example; Take advantage of A1A0 with B1 then.Except multiplying each other, all need with ADD instruction partial product that adds up with A0.
Use the realization long data multiplication of instruction of multiply adding addition, the instruction number that needs will be less than common multiplying order.As shown in Figure 4, Fig. 4 is the data flow diagram that use instruction of multiply adding addition provided by the invention is realized the long data multiplication.Two numbers of n machine word-length multiply each other, and they leave in respectively in n the ram cell; Have 2n unit to deposit the result among the RAM in addition, intermediate result and net result all leave in this 2n internal storage location.Carry storage register is deposited to take advantage of at every turn and is added the carry that computing produces.
Fig. 5 uses instruction of multiply adding addition to realize the synoptic diagram of long data multiplication according to the embodiment of the invention.Herein, be example also with the operand of twice word length.A, B length are two bytes, will realize A * B now.A, B are decomposed into sequence A 1A0, the B1B0 that length is a byte.This process can be divided into following 6 steps:
(1), MACA0, B0,0, E0, expression E0 ← A0*B0+0, this moment is the value of add carry register not;
(2), MAAA1, B0,0, E1, the expression E1 ← A1*B0+0+CR;
(3), MAA0,0,0, E2, the expression E2 ← 0*0+0+CR, promptly the value of carry storage register CR is saved in E2;
(4), MACA0, B1, E1, E1, the expression E1 ← A0*B1+E1;
(5), MAAA1, B1, E2, E2, the expression E2 ← A1*B1+E2+CR;
(6), MAA0,0,0, E3, the expression E3 ← 0*0+0+CR, promptly the value of carry storage register CR is saved in E3.
Through after above-mentioned 6 steps, the value of depositing among the E3E2E1E0 is the net result of long A * B.
Above-described specific embodiment; purpose of the present invention, technical scheme and beneficial effect are further described; institute is understood that; the above only is specific embodiments of the invention; be not limited to the present invention; within the spirit and principles in the present invention all, any modification of being made, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.