The present invention generally relates to computer technology and, more specifically, performing arithmetic operations by implementing a masked, shifted add operation.
Computers are typically used for applications that perform arithmetic operations. Several applications like cryptography, Blockchain, machine learning, image processing, computer games, e-commerce, etc., require such operations to be performed efficiently (e.g., fast). Hence, the performance of integer arithmetic has been the focus of both academic and industrial research.
Several existing techniques are used to improve the performance of the computers, particularly processors and/or arithmetic logic units by implementing the arithmetic instructions to take advantage of, or to adapt the calculation process to the architecture of the hardware. Examples of such techniques include splitting an instruction into multiple operations, where each operation is performed in parallel, two or more operations are combined to reduce memory accesses, the operations are ordered so as to reduce memory access time, storing the operands in a particular order to reduce access time, etc. With applications such as cryptography, machine learning, etc., different types of arithmetic operations can be required. There is a need to adapt operations frequently used by such applications to the hardware so that performance of such operations, and in turn, the applications is improved.
According to one or more embodiments of the present invention, a computer-implemented method includes receiving, by a processing unit, an instruction to perform a masked shift add operation with a set of operands. The method further includes performing a logical AND operation on a first pair of operands from the set of operands to obtain a first intermediate result. The method further includes shifting the first intermediate result by a first shift amount that is based on a first operand from the first pair of operands. The method further includes performing a logical AND operation on a second pair of operands from the set of operands to obtain a second intermediate result. The method further includes shifting the second intermediate result by a second shift amount that is based on a first operand from the second pair of operands. The method further includes adding the shifted first intermediate result and the shifted second intermediate result. The method further includes outputting, as a result of the masked shift add operation, an output of the adding.
In one or more embodiments of the present invention, the first shift amount is an index of a first non-zero bit in the first operand from the first pair of operands.
In one or more embodiments of the present invention, shifting the first intermediate result by the first shift amount comprises zero-padding the first intermediate result by the first shift amount.
In one or more embodiments of the present invention, shifting the second intermediate result by the second shift amount comprises zero-padding the second intermediate result by the second shift amount.
In one or more embodiments of the present invention, the method further includes updating a carry flag of the processing unit based on a carry resulting from adding the shifted first intermediate result and the shifted second intermediate result.
In one or more embodiments of the present invention, the carry flag is updated based on the instruction received to perform the masked shift add operation.
In one or more embodiments of the present invention, the processing unit performs, in parallel for two or more input values, shifting the first intermediate result and the second intermediate result, and adding the shifted first intermediate result and the second intermediate result. The output of the parallelized operations is the result of the masked shift add operation for the two or more input values.
According to one or more embodiments of the present invention, a system includes a set of registers, and one or more processing units coupled with the set of registers, the one or more processing units are configured to perform a method for performing a masked shift add operation on a set of operands. Performing the masked shift add operation includes performing a logical AND operation on a first pair of operands from the set of operands to obtain a first intermediate result. Performing the masked shift add operation further includes shifting the first intermediate result by a first shift amount that is based on a first operand from the first pair of operands. Performing the masked shift add operation further includes performing a logical AND operation on a second pair of operands from the set of operands to obtain a second intermediate result. Performing the masked shift add operation further includes shifting the second intermediate result by a second shift amount that is based on a first operand from the second pair of operands. Performing the masked shift add operation further includes adding the shifted first intermediate result and the shifted second intermediate result. Performing the masked shift add operation further includes outputting, as a result of the masked shift add operation, an output of the adding.
In one or more embodiments of the present invention, the first shift amount is an index of a first non-zero bit in the first operand from the first pair of operands.
In one or more embodiments of the present invention, shifting the first intermediate result by the first shift amount comprises zero-padding the first intermediate result by the first shift amount.
In one or more embodiments of the present invention, shifting the second intermediate result by the second shift amount comprises zero-padding the second intermediate result by the second shift amount.
In one or more embodiments of the present invention, the method further includes updating a carry flag based on a carry resulting from adding the shifted first intermediate result and the shifted second intermediate result.
In one or more embodiments of the present invention, the carry flag is updated based on an instruction received to perform the masked shift add operation.
In one or more embodiments of the present invention, the set of operands are provided in the set of registers.
According to one or more embodiments of the present invention, a computer program product includes a computer-readable memory that has computer-executable instructions stored thereupon, the computer-executable instructions when executed by a processor cause the processor to perform a method for performing an arithmetic operation using masked shift add operations in parallel. Performing each masked shift add operation on a set of operands includes receiving an instruction to perform a masked shift add operation with a set of operands. Performing each masked shift add operation further includes performing a logical AND operation on a first pair of operands from the set of operands to obtain a first intermediate result. Performing each masked shift add operation further includes shifting the first intermediate result by a first shift amount that is based on a first operand from the first pair of operands. Performing each masked shift add operation further includes performing a logical AND operation on a second pair of operands from the set of operands to obtain a second intermediate result. Performing each masked shift add operation further includes shifting the second intermediate result by a second shift amount that is based on a first operand from the second pair of operands. Performing each masked shift add operation further includes adding the shifted first intermediate result and the shifted second intermediate result. Performing each masked shift add operation further includes outputting, as a result of the masked shift add operation, an output of the adding.
In one or more embodiments of the present invention, the first shift amount is an index of a first non-zero bit in the first operand from the first pair of operands.
In one or more embodiments of the present invention, shifting the first intermediate result by the first shift amount comprises zero-padding the first intermediate result by the first shift amount.
In one or more embodiments of the present invention, shifting the second intermediate result by the second shift amount comprises zero-padding the second intermediate result by the second shift amount.
In one or more embodiments of the present invention, performing the operation further includes, updating a carry flag based on a carry resulting from adding the shifted first intermediate result and the shifted second intermediate result.
In one or more embodiments of the present invention, the operands are provided in registers.
According to one or more embodiments of the present invention a computer processor includes a set of registers, and an instruction execution unit configured to execute a masked shift add instruction on a set of operands. The execution includes performing logical AND operation on a first pair of operands to obtain a first intermediate result. The execution further includes shifting the first intermediate result by a first shift amount that is based on a first operand from the first pair of operands. The execution further includes performing logical AND operation on a second pair of operands to obtain a second intermediate result. The execution further includes shifting the second intermediate result by a second shift amount that is based on a first operand from the second pair of operands. The execution further includes adding the shifted first intermediate result and the shifted second intermediate result. The execution further includes outputting, as a result of the masked shift add operation, an output of the adding.
In one or more embodiments of the present invention, the first pair of operands and the second pair of operands are processed in parallel.
In one or more embodiments of the present invention, the operands are provided in the set of registers.
According to one or more embodiments of the present invention, a computer-implemented method for an arithmetic operation includes splitting, by a processing unit, two input values of the arithmetic operation into separate portions and performing, in parallel, a masked shift add operation with two corresponding portions from the two input values being used as part of a set of operands of the masked shift add operation. Performing each masked shift add operation includes performing logical AND operation on a first pair of operands to obtain a first intermediate result. Performing each masked shift add operation further includes shifting the first intermediate result by a first shift amount that is based on a first operand from the first pair of operands. Performing each masked shift add operation further includes performing logical AND operation on a second pair of operands to obtain a second intermediate result. Performing each masked shift add operation further includes shifting the second intermediate result by a second shift amount that is based on a first operand from the second pair of operands. Performing each masked shift add operation further includes adding the shifted first intermediate result and the shifted second intermediate result. Performing each masked shift add operation further includes outputting, as a result of the masked shift add operation, an output of the adding.
In one or more embodiments of the present invention, the first pair of operands and the second pair of operands are processed in parallel.
The above-described features can also be provided at least by a system, a computer program product, and a machine, among other types of implementations.
Embodiments of the present invention provide technical solutions to facilitate a processor that can implement instructions (e.g., add_ms, add_msc) to perform a masked shift addition in a reduced time compared to existing techniques. Embodiments of the present invention improve the time requirement by facilitating the execution of the masked, shifted add instruction with reduced dependencies across iterations. The dependencies are reduced, in one or more embodiments of the present invention, by encoding a shift amount into a mask where the shift is the index of the non-zero bit in the mask. Further, embodiments of the present invention facilitate exploiting this instruction to perform a carry ripple operation and reduce the number of carry bits in a reduced radix representation to a single bit (table 2).
Additional technical features and benefits are realized through the techniques of the present invention. Embodiments and aspects of the invention are described in detail herein and are considered a part of the claimed subject matter. For a better understanding, refer to the detailed description and to the drawings.
The specifics of the exclusive rights described herein are particularly pointed out and distinctly claimed in the claims at the conclusion of the specification. The foregoing and other features and advantages of the embodiments of the invention are apparent from the following detailed description taken in conjunction with the accompanying drawings in which:
The diagrams depicted herein are illustrative. There can be many variations to the diagrams or the operations described therein without departing from the spirit of the invention. For instance, the actions can be performed in a differing order or actions can be added, deleted or modified. Also, the term “coupled” and variations thereof describe having a communications path between two elements and do not imply a direct connection between the elements with no intervening elements/connections between them. All of these variations are considered a part of the specification.
In the accompanying figures and following detailed description of the disclosed embodiments, the various elements illustrated in the figures are provided with two or three-digit reference numbers. With minor exceptions, the leftmost digit(s) of each reference number corresponds to the figure in which its element is first illustrated.
Technical solutions are described herein to improve the efficiency of a computer processor by facilitating performance of a masked, shifted add operation. In computer systems the arithmetic operations of addition and multiplication are used frequently.
Computer systems typically use binary number representation when performing arithmetic operations. Further, the computer system, and particularly a processor and an arithmetic logic unit (ALU) of the processor, have a predefined “width” or “word size” (w), for example, 32-bit, 64-bit, 128-bit, etc. The width indicates a maximum number of bits the processor can process at one time. The width of the processor can be dictated by the size of registers, the size of the ALU processing width, or any other such processing limitation of a component associated with the processor.
A technical challenge exists when the processors are performing addition and multiplication operations with a reduced radix representation.
For example, consider that a multiplication operation is to be performed for ρ. After performing a multiplication, there will be an accumulation of carry bits 14 in each word that is stored in each register 12. The carry bits 14 need to be added into the subsequent word so that each “limb” is back to ρ bits. In existing processors, a “ripple-carry” operation is performed starting from the least significant word going to the most significant word to propagate the carry bits 14. While this operation needs to be performed sequentially, the data dependency between the words means that the operation on one word can start only after the previous word's carry bits 14 have been added and the result of that addition is available.
Embodiments of the present invention provide technical solutions to address such technical challenges. Embodiments of the present invention facilitate performing an operation to propagate the carry bits 14 in sequence with reduced data dependency between words. Consequently, the carry propagation operations can be issued one after another without having to wait for the result of the previous word's ripple operation in one or more embodiments of the present invention. Embodiments of the present invention, accordingly, improve the operation of the processor, and hence, provide an improvement to computing technology.
The result of the instruction is e=[(a & c)>>c_first_one]+[(b & d)>>d_first_one], where c_first_one is the index of the first non-zero bit in c counting from the least significant bit, and d_first_one is the index of the first non-zero bit in d counting from the least significant bit.
It is understood that the name of the instruction, the operands used, and the format of the instruction can vary in other embodiments of the present invention. Further, it is understood that in other embodiments of the present invention, the operands can be provided in a different manner such as, memory locations, direct values, address pointers, etc. Further, embodiments of the present invention are described herein with the operands in a particular order, however, in other embodiments of the present invention, the order of the operands can be different.
At block 101, the processor 10 reads the first and third operands, registers a and c 12. At block 102, the processor 10 performs a logical and operation (&) on the first and third operands, which is stored as an intermediate result. At block 103, the processor 10 determines a shift amount with the third operand, register c 12.
Referring back to the flowchart of the method in
At block 105, the processor 10 reads the second and fourth operands, b and d. At block 106, the processor 10 performs a logical and operation (&) on the second and fourth operands, which is stored as an intermediate (third) result. At block 107, the processor 10 determines a (second) shift amount with the fourth operand, d. The shift amount is determined using the same technique described in
At block 109, the processor 10 adds together the second and fourth intermediate results (from blocks 104 and 108). The result of the addition is stored in the fifth operand, e, at block 110.
At block 111, in the case the carry bit is to be recorded, the processor 10, updates the carry flag 401 depending on the carry from addition operation of the second and fourth intermediate results (at block 109).
Performing the addition in this manner reduces the time required to obtain the result in comparison to existing techniques.
As can be seen, there is dependency between instructions in a single iteration and across iterations (e.g., lines 4 and 5 in subsequent iterations depend on result of line 16 in previous iterations). The steps 3 and 4 in one iteration (see earlier paragraph) need to complete before starting the next iteration.
As described further, this latency component in a single iteration, and across iterations is reduced, and in some cases eliminated, according to one or more embodiments of the present invention.
Consider that the masked shift add operation according to one or more embodiments of the present invention uses word size w=64, Radix ρ=54. The execution of the instruction can be represented as pseudo-code/algorithm shown in Table 2.
As described herein, partial products, which overflow the radix 54 bits, but fit into the overall word, are generated. Starting from the most significant word, the processor performs add_ms pp[i], pp[i−1], MASK_54_107, MASK_108_127, res[i], where MASK_54_127=Zeros in bits 0:53, ones in bits 54:107, zeroes in 108:127; and MASK_108_127=Zeros in bits 0:107, ones in bits 108:127. This step is repeated for all partial products.
Embodiments of the present invention combine into a single instruction steps 3 and 4 from the state-of-the-art technique above. Further, once step 3 issues the instruction for one iteration, the next iteration's instruction can happen immediately in the next clock without waiting for completion of the previous iteration. In summary, with the masked shift add operation according to one or more embodiments of the present invention, the dependency is limited to instructions in a single iteration. Because there is no dependency across iterations, the loop can be unrolled to reduce the time required to obtain the result.
Embodiments of the present invention provide, for example, in the case of a 256-bit multiplication, a 40% improvement; and in case of a 2048-bit multiplication, a 25% improvement over the existing techniques. Further improvements can be gained by maintaining the processor 10 in the redundant reduced radix form if a subsequent operation is also a multiplication.
Accordingly, embodiments of the present invention provide technical solutions to facilitate a processor that can implement instructions (e.g., add_ms, add_msc) to perform a masked shift addition in a reduced time compared to existing techniques. Embodiments of the present invention improve the time requirement by facilitating the execution of the masked, shifted add instruction with reduced dependencies across iterations. The dependencies are reduced, in one or more embodiments of the present invention, by encoding a shift amount into a mask where the shift is the index of the non-zero bit in the mask. Further, embodiments of the present invention facilitate exploiting this instruction to perform a carry ripple operation and reduce the number of carry bits in a reduced radix representation to a single bit (table 2).
In one or more embodiments of the present invention, the processor 10 can be one of several computer processors in a processing unit, such as a central processing unit (CPU), a graphics processing unit (GPU), a tensor processing unit (TPU), or any other processing unit of a computer system. Alternatively, or in addition, the processor 10 can be a computing core that is part of one or more processing units.
The instruction fetch unit 601 is responsible for organizing program instructions to be fetched from memory, and executed, in an appropriate order, and for forwarding them to the instruction execution unit 603. The instruction decode operand fetch unit 602 facilitates parsing the instruction and operands, e.g., address resolution, pre-fetching, prior to forwarding an instruction to the instruction execution unit 603. The instruction execution unit 603 performs the operations and calculations as per the instruction. The memory access unit 604 facilitates accessing specific locations in a memory device that is coupled with the processor 10. The memory device can be a cache memory, a volatile memory, a non-volatile memory, etc. The write back unit 605 facilitates recording contents of the registers 12 to one or more locations in the memory device. The masked shift add executor 606 facilitates executing the masked shift add instruction as described herein.
It should be noted that the components of the processors can vary in one or more embodiments of the present invention without affecting the features of the technical solutions described herein. In some embodiments of the present invention, the components of the processor 10 can be combined, separated, or different from those described herein.
Turning now to
As shown in
The computer system 1500 comprises an input/output (I/O) adapter 1506 and a communications adapter 1507 coupled to the system bus 1502. The I/O adapter 1506 may be a small computer system interface (SCSI) adapter that communicates with a hard disk 1508 and/or any other similar component. The I/O adapter 1506 and the hard disk 1508 are collectively referred to herein as a mass storage 1510.
Software 1511 for execution on the computer system 1500 may be stored in the mass storage 1510. The mass storage 1510 is an example of a tangible storage medium readable by the processors 1501, where the software 1511 is stored as instructions for execution by the processors 1501 to cause the computer system 1500 to operate, such as is described herein below with respect to the various Figures. Examples of computer program product and the execution of such instruction is discussed herein in more detail. The communications adapter 1507 interconnects the system bus 1502 with a network 1512, which may be an outside network, enabling the computer system 1500 to communicate with other such systems. In one embodiment, a portion of the system memory 1503 and the mass storage 1510 collectively store an operating system, which may be any appropriate operating system, such as the z/OS or AIX operating system from IBM Corporation, to coordinate the functions of the various components shown in
Additional input/output devices are shown as connected to the system bus 1502 via a display adapter 1515 and an interface adapter 1516 and. In one embodiment, the adapters 1506, 1507, 1515, and 1516 may be connected to one or more I/O buses that are connected to the system bus 1502 via an intermediate bus bridge (not shown). A display 1519 (e.g., a screen or a display monitor) is connected to the system bus 1502 by a display adapter 1515, which may include a graphics controller to improve the performance of graphics intensive applications and a video controller. A keyboard 1521, a mouse 1522, a speaker 1523, etc. can be interconnected to the system bus 1502 via the interface adapter 1516, which may include, for example, a Super I/O chip integrating multiple device adapters into a single integrated circuit. Suitable I/O buses for connecting peripheral devices such as hard disk controllers, network adapters, and graphics adapters typically include common protocols, such as the Peripheral Component Interconnect (PCI). Thus, as configured in
In some embodiments, the communications adapter 1507 can transmit data using any suitable interface or protocol, such as the internet small computer system interface, among others. The network 1512 may be a cellular network, a radio network, a wide area network (WAN), a local area network (LAN), or the Internet, among others. An external computing device may connect to the computer system 1500 through the network 1512. In some examples, an external computing device may be an external webserver or a cloud computing node.
It is to be understood that the block diagram of
The present invention may be a system, a method, and/or a computer program product at any possible technical detail level of integration. The computer program product may include a computer-readable storage medium (or media) having computer-readable program instructions thereon for causing a processor to carry out aspects of the present invention.
The computer-readable storage medium can be a tangible device that can retain and store instructions for use by an instruction execution device. The computer-readable storage medium may be, for example, but is not limited to, an electronic storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. A non-exhaustive list of more specific examples of the computer-readable storage medium includes the following: a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), a static random access memory (SRAM), a portable compact disc read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanically encoded device such as punch-cards or raised structures in a groove having instructions recorded thereon, and any suitable combination of the foregoing. A computer-readable storage medium, as used herein, is not to be construed as being transitory signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide or other transmission media (e.g., light pulses passing through a fiber-optic cable), or electrical signals transmitted through a wire.
Computer-readable program instructions described herein can be downloaded to respective computing/processing devices from a computer-readable storage medium or to an external computer or external storage device via a network, for example, the Internet, a local area network, a wide area network and/or a wireless network. The network may comprise copper transmission cables, optical transmission fibers, wireless transmission, routers, firewalls, switches, gateway computers and/or edge servers. A network adapter card or network interface in each computing/processing device receives computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in a computer-readable storage medium within the respective computing/processing device.
Computer-readable program instructions for carrying out operations of the present invention may be assembler instructions, instruction-set-architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state-setting data, configuration data for integrated circuitry, or either source-code or object code written in any combination of one or more programming languages, including an object-oriented programming language such as Smalltalk, C++, or the like, and procedural programming languages, such as the “C” programming language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet Service Provider). In some embodiments, electronic circuitry including, for example, programmable logic circuitry, field-programmable gate arrays (FPGA), or programmable logic arrays (PLA) may execute the computer-readable program instruction by utilizing state information of the computer-readable program instructions to personalize the electronic circuitry, in order to perform aspects of the present invention.
Aspects of the present invention are described herein with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer-readable program instructions.
These computer-readable program instructions may be provided to a processor of a general-purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks. These computer-readable program instructions may also be stored in a computer-readable storage medium that can direct a computer, a programmable data processing apparatus, and/or other devices to function in a particular manner, such that the computer-readable storage medium having instructions stored therein comprises an article of manufacture including instructions which implement aspects of the function/act specified in the flowchart and/or block diagram block or blocks.
The computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be performed on the computer, other programmable apparatus or other device to produce a computer-implemented process, such that the instructions which execute on the computer, other programmable apparatus, or other device implement the functions/acts specified in the flowchart and/or block diagram block or blocks.
The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more executable instructions for implementing the specified logical function(s). In some alternative implementations, the functions noted in the blocks may occur out of the order noted in the Figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts or carry out combinations of special purpose hardware and computer instructions.
The descriptions of the various embodiments of the present invention have been presented for purposes of illustration, but are not intended to be exhaustive or limited to the embodiments disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The terminology used herein was chosen to best explain the principles of the embodiments, the practical application or technical improvement over technologies found in the marketplace, or to enable others of ordinary skill in the art to understand the embodiments described herein.