The disclosed embodiments are generally directed to electronic circuits.
Processors, (e.g., central processing units (CPUs), graphics processing units (GPUs), and the like), use multiple cores and pipeline architectures in order to achieve faster processing speeds. To facilitate faster execution throughput, “pipeline” execution of operations within decoder and execution units of a processor core is used. However, there is a continuing demand for faster and efficient throughput for processors.
Described herein are some embodiments of methods and processors for flag renaming in groups to eliminate dependencies of instructions. Decoder and execution units in the processor may be configured to rename flags into groups that allow each group to be treated separately as appropriate. This flag renaming eliminates flag dependencies with respect to instructions. This allows an instruction to write exactly the flags that the instruction wants without having to create merge dependencies.
Described herein are some embodiments of methods and processors for handling immediate values embedded in instructions. In an embodiment, the handling of immediate values embedded in instructions may be achieved by adding a 16 bit immediate bus and a 4 bit encoding/control bus at the interface between decode and execution units in the processor. The encoding space is minimized by overloading encoding information onto the 16 bit immediate bus, thus efficiently using storage and route resource while transferring information from the decode and execution units. In the event of an 8 or 12 bit immediate, the upper 4 bits of the immediate bus may contain the encoding bits and the encoding/control bus may indicate the ISA type. In the event of a 16 bit immediate, the encoding/control bus contains the encoding bits. The encoding/control bus will have the information of when to look at the top four bits of the immediate bus and when the data should be used as a whole. Thus, the overall encoding space is increased without needing additional bits at the interface.
A more detailed understanding may be had from the following description, given by way of example in conjunction with the accompanying drawings wherein:
For the sake of brevity, conventional techniques related to integrated circuit design, caching, memory operations, memory controllers, and other functional aspects of the systems (and the individual operating components of the systems) have not been described in detail herein. Furthermore, the connecting lines shown in the various figures contained herein are intended to represent exemplary functional relationships and/or physical couplings between the various elements. It should be noted that many alternative or additional functional relationships or physical connections may be present in an embodiment of the subject matter. In addition, certain terminology may also be used in the following description for the purpose of reference only, and thus are not intended to be limiting, and the terms “first”, “second” and other such numerical terms referring to structures do not imply a sequence or order unless clearly indicated by the context.
The following description refers to elements or nodes or features being “connected” or “coupled” together. As used herein, unless expressly stated otherwise, “connected” means that one element/node/feature is directly joined to (or directly communicates with) another element/node/feature, and not necessarily mechanically. Likewise, unless expressly stated otherwise, “coupled” means that one element/node/feature is directly or indirectly joined to (or directly or indirectly communicates with) another element/node/feature, and not necessarily mechanically. Thus, although the figures may depict one exemplary arrangement of elements, additional intervening elements, devices, features, or components may be present in an embodiment of the depicted subject matter.
While at least one exemplary embodiment has been presented in the following description, it should be appreciated that a vast number of variations exist. It will also be appreciated that the exemplary embodiment or embodiments described herein are not intended to limit the scope, applicability, or configuration of the claimed subject matter in any way. Rather, the foregoing detailed description will provide those skilled in the art with a guide for implementing the described embodiment or embodiments. It will be understood that various changes may be made in the function and arrangement of elements without departing from the scope defined by the claims.
The processor 102 may include a central processing unit (CPU), a graphics processing unit (GPU), a CPU and GPU located on the same die, or one or more processor cores, wherein each processor core may be a CPU or a GPU. The memory 104 may be located on the same die as the processor 102, or may be located separately from the processor 102. The memory 104 may include a volatile or non-volatile memory, for example, random access memory (RAM), dynamic RAM, or a cache.
The storage 106 may include a fixed or removable storage, for example, a hard disk drive, a solid state drive, an optical disk, or a flash drive. The input devices 108 may include a keyboard, a keypad, a touch screen, a touch pad, a detector, a microphone, an accelerometer, a gyroscope, a biometric scanner, or a network connection (e.g., a wireless local area network card for transmission and/or reception of wireless IEEE 802 signals). The output devices 110 may include a display, a speaker, a printer, a haptic feedback device, one or more lights, an antenna, or a network connection (e.g., a wireless local area network card for transmission and/or reception of wireless IEEE 802 signals).
The input driver 112 communicates with the processor 102 and the input devices 108, and permits the processor 102 to receive input from the input devices 108. The output driver 114 communicates with the processor 102 and the output devices 110, and permits the processor 102 to send output to the output devices 110. It is noted that the input driver 112 and the output driver 114 are optional components, and that the device 100 will operate in the same manner if the input driver 112 and the output driver 114 are not present.
An instruction set architecture (ISA) defines at least an instruction set that may be decoded and executed by a processor. There are a number of ISAs including, but not limited to Intel's x86 ISA and ARM's standard ARM ISA, and Thumb ISA. Although the embodiments described herein refer to the ARM or Thumb ISAs as illustrative examples, the methods and apparatus are equally applicable to other ISAs and associated system and processor architectures.
Processors are conventionally designed to process operations or instructions that are typically identified by operation (Op) codes (OpCodes) or instruction codes. Instructions represent the actual work to be performed and represent the issuing of operands to implicit (such as add) or explicit (such as divide) functional units. Instructions may be moved around by a scheduler queue. Operands are the arguments to instructions and may include expressions, registers or constants.
Most ISAs, such as for example the ARM ISA, utilize a variety of flags for conditional instruction execution. The ARM ISA flags may include N for a sign condition, Z for a zero condition, C for a carry condition, V for an overflow condition, Q for a saturation condition and GE, bits 3:0, which is a byte specific carry condition.
Typically, certain types of ARM instructions generate or write specific combinations of flags. For example, a NZ (sign and zero) flag combination may be written by most AArch32 instructions, (where AArch32 is a ARMv8 32-bit execution state, that uses 32-bit general purpose registers, and a 32-bit program counter (PC), stack pointer (SP), and link register (LR) and provides a choice of two instruction sets, A32 and T32). These may include, for example, multiplication (MUL) and multiplication+addition (MLA) which only write these 2 flags. In addition, some varieties of move (MOV) instruction and logical instructions only write these 2 flags. The NZC (sign, zero and carry) flag combination are written by some flavors of MOV and logical instructions such as AArch32 AND, logical shift left (LSL), rotate right register (ROR), MOV, and the like. The NZCV (sign, zero, carry and overflow) flag combination are all written by arithmetic instructions such as AArch32 ADD, SUB, and the like and by all AArch64 ops which write flags. The Q flag is only written by saturating arithmetic instructions such as signal saturation (SSAT), saturation addition (QADD), saturation subtraction (QSUB) and the like. The GE flag, (which is a group of 4 flags), is written by Single Instruction Multiple Data (SIMD) instructions executed over the execution unit general purpose registers and include instructions such as ADD16, SUB16, and the like. In 64 bit ARM instructions (AArch64), flags Q and GE cannot be written and are always 0.
It is noted that most ARM instructions read flags in either one or two groups. All condition codes require 2 groups only. The two exceptions are predication and flag copy. With respect to predication, the condition codes for predication can be created from 2 groups only. For a predicated instruction which writes flags, the old flag values must be copied when the predicate is false. Between the flags used in the condition codes and the ones that need to be copied, these instructions can require upto 3 flag sources. With respect to flag copy, some instructions are capable of copying all flags.
It is noted that AArch64 ISA instructions can only write all condition flags at the same time (NZCV) and no additional dependencies are created between different instructions which write flags, therefore a single flag group may be provided.
Described herein are embodiments of methods and processors for flag renaming in groups to eliminate dependencies of instructions. The elimination of the dependencies improves performance and out-of-order scheduling. In general, decoder and execution units in the processor may be configured to rename flags into groups that allow each group to be treated separately as appropriate. This flag renaming eliminates flag dependencies with respect to instructions. For example, the ARM ISA flags may be renamed into 5 groups, namely, NZ, C, V, Q and GE. This allows any 32 bit ARM instruction (AArch32) to write exactly the flags that the instruction wants without having to create merge dependencies.
Typically, for flag handling purposes, the N, Z, C, V, Q and GE flags are handled as a single entity or combination. This causes a lot of merge dependencies between instructions which partially write flags. For example, if there were instructions writing flag Z only, then flag N would need to be carried as a dependency (sourced and copied unchanged into the result). For the ARM and Thumb32 ISAs, the effect is somewhat limited since the compiler can decide which instructions need to produce flags, (and thus get extra source dependencies). For the Thumb16 ISA, the flag destination is implicit so there is no way to limit the penalty.
The execution unit 310, during rename cycle 360, uses a rename circuit 315 to rename the flags in Flag Dest 1, Flag Dest 2, Flag Dest 3, and Flag Dest 4, by assigning a Free Flag Register Number (FRN) to each of the destination flags and writes the newly renamed flags to an Out of Order Flag Mapping Table 320, affecting only the flag groups currently written to and keeping the other flag groups intact. For purposes of illustration, the flag renaming may use 4 flag groups, namely, NZ, C, V, and GE. Other flag groups may be used. Similarly each of the flag sources A and B from INSTR1, INSTR2, INSTR3 and INSTR4 are renamed to their corresponding FRNs based on the flag groups. Flags associated with instructions or operations are tracked as entries in a flag register file 325, where the respective entry is assigned a FRN. The execution unit 310 reads the flag values from the flag register file 325 during a flag read cycle 370 and executes instructions out of order (330), (during execution cycle 380), based on true data dependencies since the flags are handled in separate groups as described herein. The execution unit 310 writes the resulting flags back to the flag register file 325 and also to the In Order Flag Mapping Table 335 during a retirement cycle 390. The operational aspects of
In an illustrative example with reference to
Described herein are methods and apparatus for handling a shift-by-zero (SBZ). Typically, regular shift/rotate instructions write NZC flags, leaving the V flag unmodified. The N flag copies the sign bit, (bit 31 of the result), the Z flag is set if the result is all zero, and the C flag copies the last bit shifted by the operation. In the event the shift amount is 0, the C flag is left unmodified. This same behavior is carried over to many instructions which allow a shifted second operand, and the C flag is generated from the shift. Typical examples are the logical instructions such as AND, ORR, BIC, and the like. These instructions set the N and Z flags based on the result of the logical operation, but they set the C flag based on the result of the optional second-source shift. If the shift amount is non-zero, the instructions create a new C flag. If the shift amount is zero, these instructions must preserve the old C flag. Counterexamples are arithmetic instructions such as ADD, SUB, and the like. These instructions allow a shifted second operand, but they do not set the C flag based on the result of the shift. The C flag is set based on the ALU result, (bit 33 of the computation).
The AArch32 ISA provides multiple encodings for each of these instructions. In some cases, the shift amount comes from an immediate embedded in the instruction encoding. In other cases, the shift amount comes from a register.
When the shift amount is explicitly encoded in the instruction, the decoder unit can decide what the instruction needs to do prior to renaming. For example, if the shift amount is zero, the instruction decodes with no explicit shift operation and the instruction only writes NZ. If the shift amount is 1, 2 or 3, the instruction decodes without an explicit shift op, but the instruction will write NZC. The execution unit will have the capability to shift the operand by up to 3 positions and also select the C flag for these cases. If the shift amount is greater than 3, the instruction decodes with an explicit shift operation. The shift operation gets the C flag as destination, while the logical operation, (which uses the shifted data), only writes NZ.
When the shift amount is obtained from a general purpose register (GPR), the decoder unit cannot decide upfront whether the amount is zero or not. For example, the instruction AND r0, r1, r2 may be decoded as a single uop, writing NZ only. In another example, the instruction AND r0, r1, r2 LSL #1 may be decoded as a single uop, writing NZ and C. In another example, the instruction AND r0, r1, r2 LSL #5 may be decoded as a double uop, (LSL followed by AND). The LSL instruction writes the C flag, while the AND instruction writes the NZ flag combination. In another example, the instruction AND r0, r1, r2 LSL r3 may be decoded as a double uop, (LSL followed by AND). The LSL instruction writes the C flag and can have SBZ behavior, while the AND instructions writes a NZ flag combination.
For cases when the shift amount cannot be determined during decode, a flag poisoning solution may be implemented as described herein below with respect to FIGS. 3 and 9-12. In the figures, the shaded boxes in the Out of Order Table refer to the flag groups that the current instruction or operation is updating. All of the other flag groups are left untouched and retain the previous value. The shaded boxes in the In Order Table refer to the valid flag groups for the current architectural state. The latest values for all the flags, N, Z, C, V, and GE, are derived from these valid groups only. The contents of the non-shaded boxes in the In Order Table are not relevant. The status of whether a group is valid is maintained using a valid bit in the In Order Table.
Referring now to
As mentioned, in most SBZ cases, a valid C flag is over written before there is an opportunity to source the poisoned C flag. This is a good result. In this example, the very next instruction, also an LSL instruction writes a valid C flag. Since the second LSL instruction is not a shift by zero case, the C flag is no longer poisoned. Hence, when the second LSL instruction retires, the LSL instruction updates the NZC mapping in the In Order Table and also invalidates the Poison Flag from the In Order Table. Therefore, when the ADC instruction sources the C flag, the ADC instruction gets register F8 as the source register for the C flag and retires normally.
Referring now to
The poisoned flag indicator is set to 1 only for flags produced by a shift/rotate instruction/operation with the shift amount equal to zero. All other operations write the poisoned flag indicator as 0. The In Order Table is also responsible for returning the previous FRN held to the Free FRN list. That is, the FRN is re-circulated for use by the renaming circuit 315. For example, when an operation producing the flags NZCV retires, the FRN held by the NZCV flags are returned to a free FRN list and the retired operation's FRN is updated to the new FRN for the retiring operation. The flush restore relies on the In Order Table to restore the Out Of Order Table to that of the operation before the operation that caused the resync (340).
This mechanism relies on the fact that shifts by zero are infrequent, and flags produced by shifts are generally not sourced. Accordingly, the need to resync occurs very infrequently resulting in a minimal impact on performance. Also, any logical instruction which uses a “shift-by-register” second operand may decode into a shift operation followed by the regular logical operation. The shift operation will have the same SBZ behavior as the shift/rotate operations coming from shift/rotate instructions.
In another embodiment, an alternative to poisoning flags is to source the C flag in all shift operations which write flags, (when the shift amount comes from a register), and MUX it to the output flags if the shift amount turns out to be zero. This introduces a new data dependency and can reduce performance significantly if these cases are common.
Described herein are methods and apparatus for handling immediate values embedded in instructions in accordance with some embodiments. In some ISAs, such as the ARM and the Thumb ISAs, there are some instructions which need immediate modification based on some fields from the instruction itself. Both the immediate constant and encoding are bit fields coming from the instruction. For example, for the instruction ADD Rd, Ra, 1 mm32, the value for 1 mm32 is derived from an 8 bit field of the instruction and encoding bits.
There are many encodings that need to be passed on to an execution unit. It would be hard to encode them in opcode space and then do this modification at execution time. Moreover, extra cycles would be needed to do the immediate modification. If the expansion is done in the decode unit, then the number of wires will increase substantially across the execution and decode units. This will increase the power and area requirements and also lead to timing problems as there are limited route resources.
In an embodiment, the handling of immediate values embedded in instructions may be achieved by adding a 16 bit immediate bus and a 4 bit encoding/control bus, (shown as SrcBCtl in
In general, a processor includes at least a decode unit and an execution unit. The decode unit receives instructions from a fetch unit. Each instruction includes at least an operand A, operand B, operand C and other bits. A 16 bit immediate bus and a 4 bit encoding/control bus is added from the decode unit to the execution unit for handling some immediate values embedded in the instructions. In effect, the immediate bus and encoding/control bus tells how to expand the data bits to generate the final immediate data which gets consumed. The immediate data is stored directly into an array after shift and alignment, i.e., after modification and/or expansion. For example, circuitry, (including at least the 16 bit immediate bus and the 4 bit encoding/control bus), can be configured such that expanded immediates, e.g. modified immediates expanded to 64 bits, can only go to a specific source, whereas uops reference multiple sources.
As described herein above, depending on the nature of the immediate, i.e., whether it is an 8, 12 or 16 bit immediate, the appropriate control or encoding bits, (i.e., Immediate Ctrl [3:0] and/or Immediate Data [15:12]), will determine the nature of the processing during the expansion cycle. For example, the control or encoding bits may require a Thumb expansion 1650, a shifter 1652, a zero extension 1654, a sign extension 1656, a decode bit mask 1658, a rotator 1660 and/or a byte copy 1662. The output of these operations 1650-1662 and the appropriate control or encoding bits are directed to a multiplexer 1670, which in turn are stored in immediate storage 1680 during a selection cycle 1698. The expansion cycle is not an extra execution cycle but is performed nearly simultaneously and/or in parallel with the processing of the actual instruction or operation. As a result, the immediate constant value is available in the immediate storage 1680 for use and execution by the actual instruction.
Described herein are methods and apparatus to handle carry flag from modified immediates. There are some instructions that write out a carry flag based on the rotation of the immediates which is done at dispatch time from the decode unit. Most of them are logical instructions. For ARM ISA v7, there are roughly 8 instructions, for example AND, EOR, TST, TEQ, ORR, MOV, BIC, MVN, which are in this category. As most of the regular logical instructions do not update the carry flag, a carry flag generated by immediate rotation may simply be forwarded to the execution unit and can be written into a FRF (flag register file) at execute time. An extra bit of storage in an immediate storage to store this carry flag generated by modified immediates may not be needed where the circuitry is configured to always do rotate right and the data size is 32, since it is guaranteed that bit 31 of the immediate storage read data will be the final carry flag that needs to updated for that particular uop.
The only case to which this may not apply is the shift by zero case as discussed herein above. As rotation amount is coming from the operation code, the shift by zero can be detected early and disabling a destflag enable for the C flag can be performed so that it is immaterial what is been written in FRF and the next operation will be sourced with proper carry which was generated previously. In the case of ARM v8, however, there are AND and BIC instructions which update carry flag as “0”. For such cases, two operations, ANDv8, and BICV8, may be provided to differentiate the ones which writes the C flag and the ones in ARM v7 which write a carry flag generated by actual rotation of the immediate.
In general, a method for flag handling includes determining at least one destination flag from dispatched instructions; and renaming the at least one destination flag by assigning a free flag register number that is associated with at least one flag group corresponding to the at least one destination flag, wherein a flag group corresponds to an independent flag. The method may include writing each renamed flag to an out of order flag mapping table, wherein flag groups not corresponding to the at least one destination flag are unaffected. The method may include executing the dispatched instructions out of order based on data dependency. The method may include writing flags resulting from the out of order execution to an in order flag mapping table during a retirement cycle, wherein the in order table tracks mapping of flags to retired dispatched instructions. The in order flag mapping table may maintain whether a specific flag group is valid. The out of order flag mapping table may be indexed by source flag groups. The in order flag mapping table may restore a flushed out of order table. The in order flag mapping table may maintain a poison bit for a shift by zero condition. The method may include setting a poison bit on a condition that a shift by zero occurs; consuming the poison bit on a condition that a second shift by zero occurs; flushing the out of order flag mapping table on a condition that the poison bit is consumed; and re-dispatching and re-executing an instruction that resulted in the consumption of the poison bit.
In general, a processor includes an execution unit configured to determine at least one destination flag from dispatched instructions; and a renaming circuit configured to rename the at least one destination flag by assigning a free flag register number that is associated with at least one flag group corresponding to the at least one destination flag, wherein a flag group corresponds to an independent flag. The processor may include an out of order flag mapping table, wherein the execution unit is further configured to write each renamed flag to the out of order flag mapping table, wherein flag groups not corresponding to the at least one destination flag are unaffected. The execution unit may be further configured to execute the dispatched instructions out of order based on data dependency. The processor may further include an in order flag mapping table, wherein the execution unit is further configured to write flags resulting from the out of order execution to the in order flag mapping table during a retirement cycle, wherein the in order flag mapping table tracks mapping of flags to retired dispatched instructions. The in order flag mapping table may maintain whether a specific flag group is valid. The out of order flag mapping table may be indexed by source flag groups. The in order flag mapping table may restore a flushed out of order table. The in order flag mapping table may maintain a poison bit for a shift by zero condition. The execution unit may be configured to set a poison bit on a condition that a shift by zero occurs, to consume the poison bit on a condition that a second shift by zero occurs, to flush the out of order flag mapping table on a condition that the poison bit is consumed and to re-execute a re-dispatched instruction that resulted in the consumption of the poison bit. The processor may include a decode unit; a 16 bit immediate bus configured to interface between the decode unit and the execution unit; and a 4 bit control bus configured to interface between the decode unit and the execution unit, wherein a combination of the 16 bit immediate bus and the 4 bit control bus is configured to carry encoding information for instructions having an immediate constant and wherein the 16 bit immediate bus is configured to carry the immediate constant.
A non-transitory computer-readable storage medium storing a set of instructions for execution by a general purpose computer to perform flag handling in a processor includes a determining code segment for determining at least one destination flag from dispatched instructions; and a renaming code segment for renaming the at least one destination flag by assigning a free flag register number that is associated with at least one flag group corresponding to the at least one destination flag, wherein a flag group corresponds to an independent flag. The instructions are hardware description language (HDL) instructions used for the manufacture of a device.
In general, a processor includes a decode unit; a 16 bit immediate bus configured to interface between the decode unit and the execution unit; and a 4 bit control bus configured to interface between the decode unit and the execution unit, wherein a combination of the 16 bit immediate bus and the 4 bit control bus is configured to carry encoding information for instructions having an immediate constant and wherein the 16 bit immediate bus is configured to carry the immediate constant. The encoding information for instructions having an immediate constant is compressed into the combination of the 16 bit immediate bus and the 4 bit control bus using a multiplexor. The upper 4 bits of the 16 bit immediate bus may be used for carrying the encoding information for certain instructions. The encoding information determines that at least one of Thumb expansion, shifting, zero extension, sign extension, decode bit mask, rotation and byte copy operation/expansion is performed. The output of the operation/expansion and the encoding information are multiplexed and stored in immediate storage for availability by the instruction. A carry flag generated during an operation/expansion is forwarded to a flag register file.
It should be understood that many variations are possible based on the disclosure herein. Although features and elements are described above in particular combinations, each feature or element may be used alone without the other features and elements or in various combinations with or without other features and elements.
The methods provided may be implemented in a general purpose computer, a processor, or a processor core. Suitable processors include, by way of example, a general purpose processor, a special purpose processor, a conventional processor, a digital signal processor (DSP), a plurality of microprocessors, one or more microprocessors in association with a DSP core, a controller, a microcontroller, Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) circuits, any other type of integrated circuit (IC), and/or a state machine. Such processors may be manufactured by configuring a manufacturing process using the results of processed hardware description language (HDL) instructions and other intermediary data including netlists (such instructions capable of being stored on a computer readable media). The results of such processing may be maskworks that are then used in a semiconductor manufacturing process to manufacture a processor which implements aspects of the embodiments.
The methods or flow charts provided herein may be implemented in a computer program, software, or firmware incorporated in a non-transitory computer-readable storage medium for execution by a general purpose computer or a processor. Examples of non-transitory computer-readable storage mediums include a read only memory (ROM), a random access memory (RAM), a register, cache memory, semiconductor memory devices, magnetic media such as internal hard disks and removable disks, magneto-optical media, and optical media such as CD-ROM disks, and digital versatile disks (DVDs).
This application claims the benefit of U.S. provisional application No. 61/895,715 filed Oct. 25, 2014, the contents of which are hereby incorporated by reference herein.
Number | Date | Country | |
---|---|---|---|
61895715 | Oct 2013 | US |