The present invention relates generally to computer systems, and more specifically, to relative offset branching in a fixed-width reduced instruction set computing architecture.
In a computer system with a reduced instruction set computing (RISC) architecture, higher performance is achieved based on instruction simplicity to increase instruction execution rate. A RISC architecture typically includes a smaller optimized instruction set rather than a large number of specialized instructions that may be implemented in a complex instruction set computing (CISC) architecture. For RISC and CISC instructions, each instruction word typically includes an operation code (op-code) and one or more operands. One characteristic of a CISC architecture includes support for variable length instruction words. For example, a CISC architecture may include 32-bit instruction words, 48-bit instruction words, 64-bit instruction words, 80-bit instruction words, and the like. In contrast, RISC instruction words typically have a fixed instruction word width, such as 32 bits. A CISC architecture typically also supports a larger number of registers, includes complex addressing modes, and may require dozens of cycles to execute a single instruction.
A variety of branch instruction types may be defined in a RISC architecture as different branch instruction word formats. For instance, a displacement branch instruction adds a specified displacement defined in a displacement branch instruction word to the address of the displacement branch instruction. An absolute address branch instruction uses an absolute address included in an absolute address branch instruction word as an absolute address branch target address and pads remaining address bits with zeroes. A number of register-based branch instructions can also be defined where one or more registers are identified in a register-based branch instruction word, and values in the one or more registers are used to compute a branch target address. Typically, in a RISC architecture, branches that span a large address range employ register-based branch instructions, while branches that span a shorter address range or target a lower address range can employ a displacement or absolute address branch instruction. The fixed instruction word width in a RISC architecture can limit the number of address bits available for a displacement or absolute address branch instruction to the instruction word width less an op-code size.
Embodiments include a method and computer program product for relative offset branching in a reduced instruction set computing (RISC) architecture. One aspect is a method that includes fetching a branch instruction from an instruction stream having a fixed instruction width. A relative offset value is acquired from the instruction stream. The relative offset value is formatted as an offset relative to a program counter value and sized as a multiple of the fixed instruction width. The relative offset value is added with the program counter value to form a branch target address value. The branch target address value is loaded into a program counter based on the branch instruction. Execution of the instruction stream is redirected to a next instruction based on the branch target address value in the program counter.
A further aspect is a computer program product for implementing relative offset branching in a RISC architecture. The computer program product includes a computer readable storage medium having program instructions embodied therewith. The program instructions are readable by a processing circuit to cause the processing circuit to perform a method that includes fetching a branch instruction from an instruction stream having a fixed instruction width. A relative offset value is acquired from the instruction stream. The relative offset value is formatted as an offset relative to a program counter value and sized as a multiple of the fixed instruction width. The relative offset value is added with the program counter value to form a branch target address value. The branch target address value is loaded into a program counter based on the branch instruction. Execution of the instruction stream is redirected to a next instruction based on the branch target address value in the program counter.
The subject matter which is regarded as embodiments is particularly pointed out and distinctly claimed in the claims at the conclusion of the specification. The forgoing and other features, and advantages of the embodiments are apparent from the following detailed description taken in conjunction with the accompanying drawings in which:
Embodiments provide a relative offset branch instruction in a reduced instruction set computing (RISC) architecture that supports long branches. In an exemplary embodiment, a RISC processor operates according to an instruction set defined by instruction words having a fixed width for all instructions, such as 32-bit instruction words. Rather than including a relative offset value within the instruction word, the relative offset value follows the branch instruction word with which it is associated. For example, in a typical 32-bit instruction word, there may be only 26 bits available for an operand, as the remaining bits define an operation code (op-code) and/or other information. In order to support long relative branching anywhere within a full address range of a computer system, a value that is a multiple of an instruction word width is injected into a fixed-width instruction stream. For instance, if a 32-bit address range is supported and the instruction word width is 32 bits, then a 32-bit value following a relative offset branch instruction can be used as a 32-bit offset to form a target address for the branch. As a further example, if a 64-bit address range is supported and the instruction word width is 64 bits, then a 64-bit value following a relative offset branch instruction can be used as a 64-bit offset to form a target address for the branch. Embodiments may also support 64-bit offsets with 32-bit instruction words by using two instruction word slots.
Computing environments of different architectures may incorporate and use one or more aspects provided herein. For instance, environments based on the PowerPC architecture, also referred to as Power ISA, offered by International Business Machines Corporation and described in the Power ISA™ Version 2.07 specification, May 3, 2013, incorporated herein by reference in its entirety, may include one or more aspects.
Turning now to
In the example of
The program counter value 31 to which the relative offset value 20 is added can vary depending upon implementation. For example, the program counter value 31 can be address A4 (branch instruction address), address A5 (relative offset value address), or address A6 (next sequential instruction address). Using address A4 as the program counter value 31 can enable infinite looping where the relative offset value 20 is zero. Using address A5 as the program counter value 31 can simplify implementation where address A5 as a most recently accessed address. Using the next sequential instruction address A6 as the program counter value 31 can provide a larger addressable range if only positive values of the relative offset value 20 are supported, where a relative offset value 20 of zero would map to the next sequential instruction address A6. In various embodiments, the relative offset value 20 can be an unsigned value or a signed value. An unsigned value provides a greater potential range in one direction, while a signed value supports branches to both lower and higher address values.
To further expand a potentially accessible range, the relative offset value 20 may be stored as a word address rather than a byte address. For example, if the computer system supports 8-bit byte addressing and the instruction word width W is 32-bits, the relative offset value 20 can support a 34-bit range of offset by storing an address as a word address rather than a byte address. In other words, a value of “1” stored in the relative offset value 20 would map to an address of “4”, a value of “2” stored in the relative offset value 20 would map to an address of “8”, and so forth. Translation from a word address to a byte address can be performed as part of adding the relative offset value 20 to the program counter value 31. Other address translation operations may also be supported.
Similar to the example of
While the examples of
For example, in one exemplary embodiment based on the Power ISA, where two execution modes are supported for 32-bit and 64-bit addresses by selecting one of two modes with an MSR bit “SF”, when executing an instruction in MSF[SF]=0 mode (32-bit addressing) an exemplary branch instruction may have a 32-bit offset in accordance with the embodiment of
The cache and prediction hardware are accessed at approximately the same time with the same address. If the prediction hardware has prediction information available for an instruction in the instruction group, that prediction is forwarded to the ISU 150, which, in turn, issues instructions to various units for execution. The prediction may be used to update the IFAR 120 in conjunction with branch target calculation and branch target prediction hardware (such as a link register prediction stack and a count register cache). If no prediction information is available, but the instruction decoders find a branch instruction in the instruction group, a prediction is created for that instruction group, stored in the prediction hardware and forwarded to the ISU 150.
A Branch Execution Unit (BRU) 140 operates in response to instructions issued to it by the ISU 150. The BRU 140 has read access to a condition register file 160. The BRU 140 further has access to information stored by the branch scan logic in a Branch Information Queue 142, to determine the success of a branch prediction, and is operatively coupled to the instruction fetch address register(s) (IFAR) 120 corresponding to one or more threads. The BRU 140 is further operatively coupled to cause a predictor update when the BRU 140 discovers a branch misprediction.
When an instruction is executed, the BRU 140 detects if the prediction is wrong. If so, the prediction needs to be updated. For this purpose, the computer system 100 in
Referring now to a condition register file (CRF) 160, the CRF 160 is read-accessible by the BRU 140 and can be written by execution units, including but not limited to a Fixed Point Unit (FXU) 165a, Floating Point Unit (FPU) 175 and Vector Multimedia eXtension Unit (VMXU) 180. A Condition Register Logic Execution unit (CRL execution) 155 (also referred to as the CRU) and SPR handling logic have read and write access to the Condition Register File (CRF) 160 (access to CRF 160 from SPR handling logic not shown in the interest of simplifying illustration). The CRU 155 performs logical operations on the condition registers stored in the CRF 160. The FXU 165a is able to perform write updates to the CRF 160.
Instructions can be issued at the ISU 150, which is relatively far removed from the predictor hardware. In accordance with an exemplary embodiment, a prediction is made and provided in conjunction with a decode sequence, or as an immediate data word provided with the decode sequence, or an internal operation bit of an instruction.
Those skilled in the art will understand that a variety of predictor architectures can be used, and the predictors of
Access may be provided to prediction bits during an instruction fetch phase to one or more blocks of logic including a group formation unit, decoding logic, and cracking and microcode logic, which breaks up a macro instruction into a plurality of internal operations to enable such logic to modify instruction decode and cracking in response to prediction values. These blocks of logic are collectively labeled as 145a in
According to an exemplary embodiment, when a branch instruction is executed in the branch execution unit BRU 140, NRU 140 confirms correctness of prediction. In accordance with one such embodiment, the predicted target address, and/or the predicted taken/not taken decision are compared to the computed branch target address and taken/not taken decision of executing the branch instruction. When the prediction is incorrect, a branch misprediction flush occurs and a new fetch address is established in conjunction with the computed address and branch taken/not taken decision. In addition, a branch predictor is updated. In accordance with at least one embodiment, a branch predictor may also be updated when a prediction is correct to track prediction confidence.
According to an exemplary embodiment, logic is provided to establish correctness of predictions and to update predictions in response to the correctness and/or incorrectness of a prediction. This logic can include the FXU 165a, which may determine the correctness of a prediction having been used in predictive decoding. In an exemplary embodiment, the prediction is encoded in an internal operation of a checking instruction. In another embodiment, the prediction is provided as an operand to the FXU 165a by the ISU 150 when instructions are issued. In one embodiment, this dataflow is simplified, by executing a sequence adapted to transfer from the FXU 165a to a microarchitectural condition register (“eCR”) in the CR file 160 an indication about the correctness and/or incorrectness of a prediction as part of an FXU instruction determining such correctness or incorrectness. Read-access of the indication is provided in a subsequent internal operation injected by decode logic directed to the BRU 140, and an update is indicated to the predictor update logic by the subsequent internal operation based on the value recorded in an eCR and provided as input to the subsequent internal operation. In one embodiment, the FXU 165a is operatively coupled to the ISU 150 to generate a pipeline flush and force a re-decode in response to an incorrect prediction.
According to an exemplary embodiment, logic may also be provided to establish a prediction when none is found in response to encountering an instruction to be decoded using prediction-based decode, and using a default prediction when none is found. In one embodiment, this logic is coupled to group formation and decode logic.
A combination of blocks may be collectively referred to as an Instruction Fetch Unit (IFU) 104. The IFU 104 can include, among other things, the IFAR 120 and logic to control fetching of instructions from the instruction cache 125.
The program counter 30 of
Since the branch instruction 18 of
In another embodiment, microcode can be generated to fetch or load one or more words after the branch instruction 18 of
When the fetched instruction group includes a branch instruction 18 of
The predictor hardware 110a, 110b, and 110c can be used in combination with the predictor update logic 130a, link register stack 115a, count register stack 115b, and branch target calculators 108 to attempt to predict the branch target address value 21 of
In some embodiments, virtual memory is supported and address translation is performed from at least one first type of address (e.g., an effective or virtual address) to a second type of address (e.g., a physical or real address). In some embodiments, different and/or distinct architectural and microarchitectural mechanisms are employed to perform instruction and data address translation. Depending on whether the relative offset value 20 of
In one embodiment, when offset value 20 is fetched as data by the LSU 170 (e.g., in response to microcode generated responsive to a branch instruction 18 to fetch offset value 20), in at least one embodiment, the address of the instruction corresponding to the offset value is translated by data address translation facilities operatively coupled with the LSU 140. In at least one embodiment in accordance with the teachings herein, the address translation facility operatively coupled to LSU 140 is equipped to translate addresses in accordance with instruction address translation and data address translation definitions in accordance with an ISA. In accordance with one such embodiment, when LSU 140 fetches offset value 140, it transmits the address of offset value 20 to such address translation facilities and in conjunction with at least one bit to indicate translation using the architectural instruction address translation definition. In another embodiment, LSU 140 is operatively coupled to two address translation facilities, one directed at translating data address and one directed at translation instruction address, the latter possibly shared with instruction fetch unit IFU. In one such embodiment, the LSU 140 used the instruction address facility to translate the address of offset value 20. In another embodiment, an address translation facility operatively coupled to LSU 140 is equipped to translate addresses only in accordance address translation definitions in accordance with a data address accesses. In accordance with one such embodiment optimized for reduced implementation complexity, when LSU 140 fetches offset value 140, it transmits the address of offset value 20 to such address translation facilities and a translation in accordance with data address translation is returned. In one such embodiment, instruction text is mapped as accessible data to access the relative offset value 20 of
A software-based approach to keep the branch instruction 18 of
As previously described, the branch instruction 18 of
The branch instruction 18 of
It will be understood that although a number of logical blocks and connections between them are depicted in
At block 404, a relative offset value 20 is acquired from the instruction stream 10. The relative offset value 20 is formatted as an offset relative to a program counter value 31 and sized as a multiple of the fixed instruction width W, e.g., 1×W, 2×W, 3×W, 4×W, etc. The branch instruction 18 can be marked to support fetching an instruction group from memory using the marking to ensure that the instruction group is sized and aligned such that a number of words after the branch instruction 18 in the instruction group includes the relative offset value 20. Marking can be done, for instance, by the predecode unit 106. The relative offset value 20 can be acquired as part of a fetch or as a data access. For example, instruction text that includes the relative offset value 20 can be mapped as data accessible. The relative offset value 20 may be accessed via the LSU 170 using data translation. Alternatively, the relative offset value 20 can be acquired from the instruction stream 10 by LSU 170 using instruction translation.
At block 406, the relative offset value 20 is added with the program counter value 31 to form a branch target address value 21. At block 408, the branch target address value 21 is loaded into a program counter 30 based on the branch instruction 18. If the branch instruction 18 is a conditional branch, the loading of the branch target address value 21 into the program counter 30 is further based on determining that a branch condition associated with the branch instruction 18 is satisfied.
At block 410, execution of the instruction stream 10 is redirected to a next instruction, such as instruction Y 26 at address AY, based on the branch target address value 21 in the program counter 30.
When linking is supported to store a return address, a determination can be performed as to whether an update to a link register in the link register stack 115a is requested with the branch instruction 18. Based on determining that the update to the link register is requested with the branch instruction 18, an address of the branch instruction 18 plus an offset value that accounts for the fixed instruction width W and a width of the relative offset value 20 can be written to set a return address in the link register to a next sequential instruction (i.e., instruction D 22) after the branch instruction 18.
At block 506, based on determining that the instruction group includes the relative offset value 20, the program counter 30 is loaded with the program counter value 31 plus the relative offset value 20, and execution of the instruction stream 10 is redirected. At block 508, based on determining that the instruction group does not include the relative offset value 20, another fetch after the branch instruction 18 is performed. The fetch can be a single word or multiple words after the branch instruction 18 depending on the size of the relative offset value 20. At block 510, a branch is performed to the program counter value 31 plus the relative offset value 20 in the program counter 30.
At block 606, based on determining that the instruction group includes the relative offset value 20, redirecting is performed in the IFU 104 to a new address such that the program counter value 31 plus the relative offset value 20 is loaded into the program counter 30, and execution of the instruction stream 10 is redirected.
At block 608, based on determining that the instruction group does not include the relative offset value 20, an internal operation sequence is generated. The internal operation sequence can include microcode to retrieve addresses, such as a current instruction address and a next instruction address, and use the retrieved addresses to load one or more words after the branch instruction 18 depending on the size of the relative offset value 20. The generated microcode can also include an update to the program counter 30 such that the program counter value 31 plus the relative offset value 20 is loaded into the program counter 30.
At block 610, the internal operation sequence is executed in the BRU 140 and the LSU 170 to load the relative offset value 20 from the memory and update the program counter 30. For example, the BRU 140 can retrieve the addresses, the LSU 170 can load the relative offset value 20, and the BRU 140 or the LSU 170 can update the program counter 30. A branch is then performed to the program counter value 31 plus the relative offset value 20 in the program counter 30.
At block 706, based on determining that the instruction group includes the relative offset value 20, redirecting is performed in the IFU 104 to a new address such that the program counter value 31 plus the relative offset value 20 (i.e., branch target address value 21) is loaded into a program counter 30, and execution of the instruction stream 10 is redirected.
At block 708, prediction logic is used to predict the branch target address value and to speculatively start fetching and executing instructions in accordance with the predicted target address. At block 710, an internal operation sequence is generated to load a value after the branch instruction 18 and verify whether the branch target address value 21 matches the prediction of the branch target address value. The internal operation sequence can include microcode to retrieve addresses, such as a current instruction address and a next instruction address, and use the retrieved addresses to load one or more words after the branch instruction 18 depending on the size of the relative offset value 20. The internal operation sequence can also verify the prediction by comparing the prediction to the branch target address value 21.
At block 712, the internal operation sequence is executed to compute the branch target address to be loaded to the program counter 30 in accordance with the sequence of steps generated in block 710 and the architectural definition of the branch of
At block 716, based on determining that the prediction was incorrect, the prediction of the branch target address value is updated and the prediction logic is reinitialized to flush results of the incorrect prediction. The program counter 30 is also updated with the branch target address value 21. If the prediction was correct at block 714, then the process flow 700 ends. A correct prediction may also update a prediction history value to indicate an increased prediction confidence level.
In accordance with at least one embodiment, a prediction for a branch target address can be stored in a target address predictor structure targeted at predicting count registers. In another embodiment, another target address prediction structure is used.
Technical effects and benefits include relative offset branching in a reduced instruction set computing (RISC) architecture by using one or more locations after a branch instruction as a relative offset value. The relative offset value can be allocated as an integer multiple of the fixed instruction width of the RISC instruction set.
Referring now to
The present invention may be a system, a method, and/or a computer program product. 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, 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 conventional 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 instructions 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 block 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 disclosed herein.
This application is a continuation of U.S. application Ser. No. 14/291,693 filed May 30, 2014, the disclosure of which is incorporated by reference herein in its entirety.
Number | Name | Date | Kind |
---|---|---|---|
5812839 | Hoyt | Sep 1998 | A |
6336178 | Favor | Jan 2002 | B1 |
6502188 | Zuraski, Jr. | Dec 2002 | B1 |
6661534 | Ravi | Dec 2003 | B1 |
20110314265 | Ball | Dec 2011 | A1 |
20150347145 | Gschwind | Dec 2015 | A1 |
20150347146 | Gschwind | Dec 2015 | A1 |
20150347148 | Gschwind | Dec 2015 | A1 |
Entry |
---|
List of IBM Patents or Patent Applications Treated as Related; Sep. 5, 2014, 2 pages. |
U.S. Appl. No. 14/291,627, filed May 30, 2014. |
U.S. Appl. No. 14/291,693, filed May 30, 2014. |
U.S. Appl. No. 14/478,093, filed Sep. 5, 2014. |
Number | Date | Country | |
---|---|---|---|
20150347148 A1 | Dec 2015 | US |
Number | Date | Country | |
---|---|---|---|
Parent | 14291693 | May 2014 | US |
Child | 14478114 | US |