CN104216681A - CPU instruction processing method and processor - Google Patents
CPU instruction processing method and processor Download PDFInfo
- Publication number
- CN104216681A CN104216681A CN201310213735.8A CN201310213735A CN104216681A CN 104216681 A CN104216681 A CN 104216681A CN 201310213735 A CN201310213735 A CN 201310213735A CN 104216681 A CN104216681 A CN 104216681A
- Authority
- CN
- China
- Prior art keywords
- instruction
- result
- register
- unit
- execution
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/38—Concurrent instruction execution, e.g. pipeline or look ahead
- G06F9/3836—Instruction issuing, e.g. dynamic instruction scheduling or out of order instruction execution
- G06F9/3838—Dependency mechanisms, e.g. register scoreboarding
- G06F9/384—Register renaming
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/38—Concurrent instruction execution, e.g. pipeline or look ahead
- G06F9/3824—Operand accessing
- G06F9/3826—Bypassing or forwarding of data results, e.g. locally between pipeline stages or within a pipeline stage
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Advance Control (AREA)
Abstract
Description
技术领域technical field
本发明涉及计算机领域,尤其涉及一种CPU指令处理方法和处理器。The invention relates to the field of computers, in particular to a CPU instruction processing method and a processor.
背景技术Background technique
现在的处理器(Center Process Unit,CPU)中大都采用流水线技术,基本的五级流水线包括取指(即取出指令),译码(即对指令进行译码),执行(即对指令进行执行),访存(即将数据写到内存中,或者从内存中读取数据),写回(即将数据写到寄存器堆当中),同一个周期内,可以有5条指令分别处于不同的流水级。Most of the current processors (Center Process Unit, CPU) use pipeline technology. The basic five-stage pipeline includes fetching (that is, fetching instructions), decoding (that is, decoding instructions), and execution (that is, executing instructions). , memory access (that is, write data into the memory, or read data from the memory), write back (that is, write data to the register file), within the same cycle, there can be 5 instructions at different pipeline levels.
执行的指令间存在着3种相关性,即数据相关、控制相关和结构相关。而数据相关中又分为3种:读后写相关(Read After Write,RAW),即后面的指令要用到前面指令所写的数据;写后写相关(Write After Write,WAW),即两条指令同时写同一个单元;读后写相关(Write After Read,WAR),即被读取的数据将会被后面的指令所写入。数据相关有可能导致流水线的阻塞,比如,流水线要求指令在译码阶段读取寄存器时,该寄存器是流水线中前面指令的目标寄存器,并且结果还没有写回,那么该指令就要在译码阶段等待。There are three kinds of dependencies among the executed instructions, namely, data dependencies, control dependencies and structure dependencies. And there are three types of data correlation: Read After Write (RAW), that is, the data written by the previous command is used in the following instructions; Write After Write (WAW), that is, two Two instructions write to the same unit at the same time; Write After Read (WAR), that is, the read data will be written by the following instruction. Data correlation may cause the pipeline to be blocked. For example, when the pipeline requires an instruction to read a register in the decoding stage, the register is the target register of the previous instruction in the pipeline, and the result has not been written back, then the instruction must be in the decoding stage. wait.
为了解决上述阻塞问题,提高流水线的效率,目前业界的一般做法是使用前递技术(Forwarding),也称为旁路技术(Bypass),即当后面的指令用到前面指令的运算或者是访存结果时,就可以直接通过旁路获取结果,而不需要等到结果写回寄存器,并可以通过寄存器重名命来避免WAW和WAR相关,从而提高指令级并行的效率。实际上,程序中使用的寄存器是程序员可见的逻辑寄存器,这些程序员可见的寄存器又称为结构寄存器,而实际硬件执行中,会将这些寄存器重新映射到程序员不可见的微结构寄存器。In order to solve the above blocking problem and improve the efficiency of the pipeline, the current general practice in the industry is to use forwarding technology (Forwarding), also known as bypass technology (Bypass), that is, when the following instructions use the operation of the previous instruction or memory access When the result is obtained, the result can be obtained directly through the bypass without waiting for the result to be written back to the register, and the correlation between WAW and WAR can be avoided through register renaming, thereby improving the efficiency of instruction-level parallelism. In fact, the registers used in the program are logical registers visible to the programmer. These programmer-visible registers are also called structural registers. In actual hardware execution, these registers are remapped to micro-architectural registers that are not visible to the programmer.
对于一般的整数运算指令序列来说,要经过取指、译码和寄存器重命名(Rename),然后送到发射队列(Issue queue)。在发射队列的指令,假如发现它的源操作数的值已经准备好了,那么它就可以发送到空闲的整点运算单元(Fix Point Arthmetic Unit,FX),进行整数的运算。运算结果进行写回(Write Back,WB),存储到寄存器堆当中。For a general integer operation instruction sequence, it needs to go through instruction fetching, decoding, and register renaming (Rename), and then send it to the issue queue (Issue queue). Instructions in the emission queue, if it is found that the value of its source operand is ready, then it can be sent to the idle Fix Point Arthmetic Unit (FX) to perform integer operations. The operation result is written back (Write Back, WB) and stored in the register file.
其中寄存器重命名的阶段,就是将结构寄存器(程序员可见),映射到物理寄存器(程序员不可见)上的过程,该过程可以避免WRW,WAR相关。The stage of register renaming is the process of mapping structural registers (visible to programmers) to physical registers (not visible to programmers), which can avoid WRW and WAR correlation.
在实现上述解决阻塞问题的过程中,发明人发现现有技术中至少存在如下问题:In the process of realizing the above solution to the blocking problem, the inventors have found that at least the following problems exist in the prior art:
随着功能单元(Function Unit)的增多,寄存器堆(Register File)越做越大,对于寄存器堆的读写,是相当耗能的。实际上,很多指令的结果,往往只会被后面一条,或者是接下来几条指令中的其中的一条所用,而且,仅被使用一次,对于这类只被使用一次的结果,写回寄存器堆,实际上是对寄存器资源的浪费。With the increase of functional units (Function Unit), the register file (Register File) is getting bigger and bigger, and the reading and writing of the register file is quite energy-consuming. In fact, the results of many instructions are often only used by the next one, or one of the next few instructions, and are only used once. For such results that are only used once, write them back to the register file , which is actually a waste of register resources.
发明内容Contents of the invention
本发明的实施例提供一种CPU指令处理方法和处理器,能够节省寄存器资源,并且降低了读写继存器所需消耗的功耗。Embodiments of the present invention provide a CPU instruction processing method and a processor, which can save register resources and reduce the power consumption required for reading and writing relay registers.
为达到上述目的,本发明的实施例采用如下技术方案:In order to achieve the above object, embodiments of the present invention adopt the following technical solutions:
第一方面,提供一种CPU指令处理方法,所述方法包括:In a first aspect, a CPU instruction processing method is provided, the method comprising:
判断第一指令的结果是否只被所述第一指令之后的第二指令使用一次;judging whether the result of the first instruction is only used once by a second instruction following the first instruction;
若所述结果只被所述第一指令之后的第二指令使用一次,则将所述第一指令的结果不写回寄存器堆;If the result is only used once by a second instruction following the first instruction, the result of the first instruction is not written back to the register file;
将所述第一指令和第二指令发射到功能单元中进行运算,使第一指令先于第二指令执行,并将第一指令的处理结果传递给所述第二指令,作为所述第二指令的源操作数。Sending the first instruction and the second instruction to the functional unit for calculation, so that the first instruction is executed before the second instruction, and the processing result of the first instruction is transferred to the second instruction as the second instruction The source operand for the instruction.
在第一种可能的实现方式中,结合第一方面,所述判断第一指令的结果是否只被所述第一指令之后的指令使用一次包括:In a first possible implementation manner, in combination with the first aspect, the judging whether the result of the first instruction is only used once by the instruction after the first instruction includes:
在译码阶段识别所述第一指令和第二指令是否有特殊标识,如果有特殊标识则确定第一指令的结果只被所述第一指令之后的第二指令使用一次。In the decoding stage, it is identified whether the first instruction and the second instruction have a special identifier, and if there is a special identifier, it is determined that the result of the first instruction is only used once by the second instruction after the first instruction.
在第二种可能的实现方式中,结合第一方面或第一方面的第一种实现方式,所述判断第一指令的结果是否只被所述第一指令之后的指令使用一次还包括:In the second possible implementation manner, in combination with the first aspect or the first implementation manner of the first aspect, the judging whether the result of the first instruction is only used once by the instruction after the first instruction further includes:
若第一寄存器作为所述第一指令的结果的存放寄存器,同时只作为所述第二指令的源操作数,则确定所述第一指令的结果只被所述第一指令之后的指令使用一次,对所述第一指令和第二指令做特殊标识。If the first register is used as the storage register for the result of the first instruction and is only used as the source operand of the second instruction, then it is determined that the result of the first instruction is only used once by the instruction after the first instruction , specifically identify the first instruction and the second instruction.
在第三种可能的实现方式中,结合第一方面的第二种可能的实现方式,对所述第一指令和第二指令做特殊标识包括:In a third possible implementation manner, in combination with the second possible implementation manner of the first aspect, special identification of the first instruction and the second instruction includes:
将所述第一寄存器替换为特殊寄存器,且对第一指令和第二指令做特殊关系标记。The first register is replaced with a special register, and a special relationship mark is made between the first instruction and the second instruction.
在第四种可能的实现方式中,结合第一方面的第二种可能的实现方式,对所述第一指令和第二指令做特殊标识包括:In a fourth possible implementation manner, in combination with the second possible implementation manner of the first aspect, special identification of the first instruction and the second instruction includes:
在所述第一指令以及第二指令后添加特殊比特位,用于标记第一指令和第二指令的关系。A special bit is added after the first instruction and the second instruction to mark the relationship between the first instruction and the second instruction.
在第五种可能的实现方式中,结合第一方面或第一方面的第一至第四种可能的实现方式中的任意一项,所述将所述第一指令和第二指令发射到功能单元中进行运算,使第一指令先于第二指令执行,并将第一指令的处理结果传递给所述第二指令包括:In a fifth possible implementation manner, in combination with the first aspect or any one of the first to fourth possible implementation manners of the first aspect, the transmitting the first instruction and the second instruction to the function Performing operations in the unit so that the first instruction is executed prior to the second instruction, and transferring the processing result of the first instruction to the second instruction includes:
若所述第一指令和所述第二指令为连续的两条指令,则将所述第一指令的结果通过前递通路直接传递给所述第二指令,作为所述第二指令的源操作数;If the first instruction and the second instruction are two consecutive instructions, the result of the first instruction is directly passed to the second instruction through the forward path as the source operation of the second instruction number;
若所述第一指令和所述第二指令为不连续的两条指令,则在所述第一指令执行后,将所述第一指令的结果缓存在所述功能单元中,当所述第二指令执行时,将所述第一指令的结果传递给所述第二指令,作为所述第二指令的源操作数。If the first instruction and the second instruction are two discontinuous instructions, after the execution of the first instruction, cache the result of the first instruction in the functional unit, when the second instruction When the second instruction is executed, the result of the first instruction is transferred to the second instruction as a source operand of the second instruction.
在第六种可能的实现方式中,结合第一方面或第一方面的第一至第五种可能的实现方式,所述方法还包括:In a sixth possible implementation manner, in combination with the first aspect or the first to fifth possible implementation manners of the first aspect, the method further includes:
若所述结果只被所述第一指令之后的第二指令使用一次,则对所述第一指令的结果所在的寄存器在重命名阶段不进行重命名操作。If the result is only used once by the second instruction after the first instruction, no renaming operation is performed on the register where the result of the first instruction is located in the renaming stage.
在第七种可能的实现方式中,结合第一方面或第一方面的第一至第六可能的实现方式中的任意一项,所述方法还包括:In a seventh possible implementation manner, in combination with the first aspect or any one of the first to sixth possible implementation manners of the first aspect, the method further includes:
在所述第一指令执行完成后要通知重排序缓冲器,以便将所述第一指令按照所述重排序缓冲器中的排序规则进行提交;Notifying the reordering buffer after the execution of the first instruction is completed, so as to submit the first instruction according to the ordering rules in the reordering buffer;
在所述第二指令执行完成后要将所述第二指令的结果写回寄存器堆,并通知重排序缓冲器,以便将所述第二指令按照所述重排序缓冲器中的排序规则进行提交。After the execution of the second instruction is completed, the result of the second instruction is written back to the register file, and the reordering buffer is notified, so that the second instruction is submitted according to the ordering rules in the reordering buffer .
在第八种可能的实现方式中,结合第一方面或第一方面的第一至第七种可能的实现方式,所述方法还包括:In an eighth possible implementation manner, in combination with the first aspect or the first to seventh possible implementation manners of the first aspect, the method further includes:
当所述第一指令和第二指令执行完成后,将所述第一指令和所述第二指令同时提交;After the execution of the first instruction and the second instruction is completed, submit the first instruction and the second instruction at the same time;
当所述第一指令和/或第二指令执行出现异常时,将所述第一指令和所述第二指令重新执行。When an exception occurs in the execution of the first instruction and/or the second instruction, the first instruction and the second instruction are re-executed.
第二方面,提供一种处理器,所述处理器包括:In a second aspect, a processor is provided, and the processor includes:
判决单元,用于判断第一指令的结果是否只被所述第一指令之后的第二指令使用一次;a judging unit, configured to judge whether the result of the first instruction is only used once by a second instruction following the first instruction;
执行单元,用于若所述结果只被所述第一指令之后的第二指令使用一次,则将所述第一指令的结果不写回寄存器堆;并执行第一指令和第二指令;An execution unit configured to not write the result of the first instruction back to the register file if the result is only used once by a second instruction following the first instruction; and execute the first instruction and the second instruction;
发射单元,用于将所述第一指令和第二指令发射到功能单元中进行运算,使第一指令先于第二指令执行,并将第一指令的处理结果传递给所述第二指令,作为所述第二指令的源操作数。an issuing unit, configured to transmit the first instruction and the second instruction to the functional unit for calculation, so that the first instruction is executed prior to the second instruction, and the processing result of the first instruction is transferred to the second instruction, as the source operand for the second instruction.
在第一种可能的实现方式中,结合第二方面,所述判决单元具体用于:In a first possible implementation manner, in combination with the second aspect, the judgment unit is specifically configured to:
在译码阶段识别所述第一指令和第二指令是否有特殊标识,如果有特殊标识则确定第一指令的结果只被所述第一指令之后的第二指令使用一次。In the decoding stage, it is identified whether the first instruction and the second instruction have a special identifier, and if there is a special identifier, it is determined that the result of the first instruction is only used once by the second instruction after the first instruction.
在第二种可能的实现方式中,结合第二方面或第二方面的第一种实现方式,所述处理器还包括:In a second possible implementation manner, with reference to the second aspect or the first implementation manner of the second aspect, the processor further includes:
标识单元,在译码阶段识别第一寄存器作为所述第一指令的结果的存放寄存器,同时只作为所述第二指令的源操作数,则确定所述第一指令的结果只被所述第一指令之后的指令使用一次,对所述第一指令和第二指令做特殊标识。The identification unit, in the decoding stage, identifies the first register as the storage register for the result of the first instruction, and at the same time only serves as the source operand of the second instruction, then it is determined that the result of the first instruction is only used by the first instruction Instructions following an instruction are used once, and the first instruction and the second instruction are specially identified.
在第三种可能的实现方式中,结合第二方面的第二种实现方式中的任意一项,所述标识单元具体用于:In a third possible implementation manner, in combination with any one of the second implementation manners of the second aspect, the identification unit is specifically configured to:
将所述第一寄存器替换为特殊寄存器,且对第一指令和第二指令做特殊关系标记。The first register is replaced with a special register, and a special relationship mark is made between the first instruction and the second instruction.
在第四种可能的实现方式中,结合第二方面的第二种实现方式,所述判决单元具体用于:In a fourth possible implementation manner, in combination with the second implementation manner of the second aspect, the judgment unit is specifically configured to:
在所述第一指令以及第二指令后添加特殊比特位,用于标记第一指令和第二指令的关系。A special bit is added after the first instruction and the second instruction to mark the relationship between the first instruction and the second instruction.
在第五种可能的实现方式中,结合第二方面或第二方面的第一至第四种可能的实现方式中的任意一项,所述发射单元具体用于:In a fifth possible implementation manner, in combination with the second aspect or any one of the first to fourth possible implementation manners of the second aspect, the transmitting unit is specifically configured to:
若所述第一指令和所述第二指令为连续的两条指令,则将所述第一指令的结果通过前递通路直接传递给所述第二指令,作为所述第二指令的源操作数;If the first instruction and the second instruction are two consecutive instructions, the result of the first instruction is directly passed to the second instruction through the forward path as the source operation of the second instruction number;
若所述第一指令和所述第二指令为不连续的两条指令,则在所述第一指令执行后,将所述第一指令的结果缓存在所述功能单元中,当所述第二指令执行时,将所述第一指令的结果传递给所述第二指令,作为所述第二指令的源操作数;If the first instruction and the second instruction are two discontinuous instructions, after the execution of the first instruction, cache the result of the first instruction in the functional unit, when the second instruction When the second instruction is executed, the result of the first instruction is transferred to the second instruction as the source operand of the second instruction;
在第六种可能的实现方式中,结合第一方面或第一方面的第一至第五种可能的实现方式,所述处理器还包括:In a sixth possible implementation manner, with reference to the first aspect or the first to fifth possible implementation manners of the first aspect, the processor further includes:
重命名单元,用于若所述结果只被所述第一指令之后的第二指令使用一次,则对所述第一指令的结果所在的寄存器在重命名阶段不进行重命名操作。The renaming unit is configured to not perform a renaming operation on the register where the result of the first instruction is located in the renaming stage if the result is only used once by a second instruction following the first instruction.
在第七种可能的实现方式中,结合第二方面或第二方面的第一至第六种可能的实现方式中的任意一项,所述处理器还包括:In a seventh possible implementation manner, in combination with the second aspect or any one of the first to sixth possible implementation manners of the second aspect, the processor further includes:
通知单元,同于在所述第一指令执行完成后要通知重排序缓冲器,以便将所述第一指令按照所述重排序缓冲器中的排序规则进行提交;在所述第二指令执行完成后要将所述第二指令的结果写回寄存器堆,并通知重排序缓冲器,以便将所述第二指令按照所述重排序缓冲器中的排序规则进行提交。The notification unit is the same as notifying the reordering buffer after the execution of the first instruction is completed, so as to submit the first instruction according to the ordering rules in the reordering buffer; after the execution of the second instruction is completed Then write the result of the second instruction back to the register file, and notify the reordering buffer, so that the second instruction is submitted according to the ordering rules in the reordering buffer.
在第八种可能的实现方式中,结合第二方面或第二方面的第一至第七种可能的实现方式中的任意一项,所述处理器还包括:In an eighth possible implementation manner, in combination with the second aspect or any one of the first to seventh possible implementation manners of the second aspect, the processor further includes:
提交单元,用于当所述第一指令和第二指令执行完成后,将所述第一指令和所述第二指令同时提交;a submission unit, configured to submit the first instruction and the second instruction simultaneously after the execution of the first instruction and the second instruction is completed;
异常处理单元,用于当所述第一指令和/或第二指令执行出现异常时,将所述第一指令和所述第二指令重新执行。The exception processing unit is configured to re-execute the first instruction and the second instruction when an exception occurs in the execution of the first instruction and/or the second instruction.
本发明实施例提供一种CPU指令处理方法和处理器,当第一指令的结果只被第一指令之后的第二指令使用一次时,将第一指令和第二指令的中间结果不写回寄存器堆并且在寄存器重命名阶段对存储所述中间结果的寄存器不进行重命名,即不将存储所述中间结果的寄存器映射为物理寄存器,从而节省了寄存器资源,并且降低了读写继存器所需消耗的功耗。An embodiment of the present invention provides a CPU instruction processing method and a processor. When the result of the first instruction is only used once by the second instruction after the first instruction, the intermediate results of the first instruction and the second instruction are not written back to the register. In the register renaming stage, the registers storing the intermediate results are not renamed, that is, the registers storing the intermediate results are not mapped to physical registers, thereby saving register resources and reducing the cost of reading and writing successors. power consumption required.
附图说明Description of drawings
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only These are some embodiments of the present invention. Those skilled in the art can also obtain other drawings based on these drawings without creative work.
图1为本发明实施例提供的一种CPU指令处理方法的流程示意图一;FIG. 1 is a first schematic flowchart of a CPU instruction processing method provided by an embodiment of the present invention;
图2为本发明实施例提供的一种CPU指令处理方法的流程示意图二;FIG. 2 is a second schematic flow diagram of a CPU instruction processing method provided by an embodiment of the present invention;
图3为本发明实施例提供的一种处理器的结构示意图一;FIG. 3 is a first schematic structural diagram of a processor provided by an embodiment of the present invention;
图4为本发明实施例提供的一种处理器的结构示意图二;FIG. 4 is a second schematic structural diagram of a processor provided by an embodiment of the present invention;
图5为本发明实施例提供的一种处理器的结构示意图三;FIG. 5 is a schematic structural diagram III of a processor provided by an embodiment of the present invention;
图6为本发明实施例提供的一种处理器的结构示意图四;FIG. 6 is a fourth structural schematic diagram of a processor provided by an embodiment of the present invention;
图7为本发明实施例提供的一种处理器的结构示意图五;FIG. 7 is a schematic structural diagram five of a processor provided by an embodiment of the present invention;
图8为本发明实施例提供的另一种处理器的结构示意图。FIG. 8 is a schematic structural diagram of another processor provided by an embodiment of the present invention.
具体实施方式Detailed ways
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some, not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the protection scope of the present invention.
本发明实施例提供一种CPU指令处理方法,如图1所示,所述方法包括:An embodiment of the present invention provides a CPU instruction processing method, as shown in FIG. 1, the method includes:
101、判断第一指令的结果是否只被所述第一指令之后的第二指令使用一次。101. Determine whether a result of a first instruction is only used once by a second instruction subsequent to the first instruction.
需要注意的是,一条指令的结果只被该条指令之后的第二指令使用一次的关系指的是:It should be noted that the relationship that the result of an instruction is only used once by the second instruction after the instruction refers to:
当一条指令执行后的中间结果作为该条指令之后的第二指令执行时所用的源操作数,并且这种关系只存在一次。The source operand used when the intermediate result after an instruction is executed is executed as the second instruction after the instruction, and this relationship exists only once.
102、若所述结果只被所述第一指令之后的第二指令使用一次,则将所述第一指令的结果不写回寄存器堆。102. If the result is only used once by a second instruction following the first instruction, do not write the result of the first instruction back to the register file.
103、将所述第一指令和第二指令发射到功能单元中进行运算,使第一指令先于第二指令执行,并将第一指令的处理结果传递给所述第二指令,作为所述第二指令的源操作数。103. Send the first instruction and the second instruction to the functional unit for calculation, make the first instruction execute before the second instruction, and transfer the processing result of the first instruction to the second instruction as the The source operand for the second instruction.
本发明实施例提供一种CPU指令处理方法,当第一指令的结果只被第一指令之后的第二指令使用一次时,将第一指令和第二指令的中间结果不写回寄存器堆并且在寄存器重命名阶段对存储所述中间结果的寄存器不进行重命名,即不将存储所述中间结果的寄存器映射为物理寄存器,从而节省了寄存器资源,并且降低了读写继存器所需消耗的功耗。An embodiment of the present invention provides a CPU instruction processing method. When the result of the first instruction is only used once by the second instruction after the first instruction, the intermediate results of the first instruction and the second instruction are not written back to the register file and are The register renaming stage does not rename the registers storing the intermediate results, that is, does not map the registers storing the intermediate results into physical registers, thereby saving register resources and reducing the cost of reading and writing the relay registers. power consumption.
为了使本领域技术人员能够更清楚地理解本发明实施例提供的技术方案,下面通过具体的实施例,对本发明实施例提供的一种CPU指令处理方法进行详细说明,如图2所示,该方法包括:In order to enable those skilled in the art to more clearly understand the technical solutions provided by the embodiments of the present invention, a CPU instruction processing method provided by the embodiments of the present invention will be described in detail below through specific embodiments, as shown in FIG. 2 , the Methods include:
201、处理器将程序代码进行编译,并在编译完成后读入指令。201. The processor compiles the program code, and reads in instructions after the compilation is completed.
具体的,可以通过以下方法实现:Specifically, it can be achieved by the following methods:
若有程序指令需要被执行时,则处理器通过取指器将指令读入,若发现读入的两条指令的中间结果只被使用一次,则在编译器生成代码的时候可以用特殊的结构寄存器R0来存储所述中间结果。If there are program instructions that need to be executed, the processor reads the instructions through the instruction fetcher. If it is found that the intermediate results of the two instructions read are only used once, a special structure can be used when the compiler generates code. register R0 to store the intermediate results.
示例性的,若一条程序代码为a[0]=b+c+d,一般情况下编译器编译后生成的代码如下:Exemplarily, if a program code is a[0]=b+c+d, generally the code generated by the compiler after compiling is as follows:
ADD R3,R1,R2ADD R3, R1, R2
ADD R5,R3,R4ADD R5, R3, R4
STD 0(R6),R5STD 0 (R6), R5
其中R1存放b的值,R2存放c的值,R4存放d的值,R6存放a[0]的地址;Among them, R1 stores the value of b, R2 stores the value of c, R4 stores the value of d, and R6 stores the address of a[0];
假设其中第一条为指令A,第二条为指令B,其中指令A在指令B前面执行,并且指令A的执行结果存储于寄存器R3中,同时指令B的源寄存器也为R3,即指令A与指令B间的中间结果只被使用一次,那么我们可以修改编译器,将指令A与指令B的中间结果存放于特殊结构寄存器R0中,用以将存在上述特殊关系的两条指令标识出来,修改编译器后生成的代码如下:Suppose the first one is instruction A, and the second one is instruction B, where instruction A is executed before instruction B, and the execution result of instruction A is stored in register R3, and the source register of instruction B is also R3, that is, instruction A The intermediate result between instruction B and instruction B is only used once, then we can modify the compiler to store the intermediate result of instruction A and instruction B in the special structure register R0 to identify the two instructions with the above special relationship, The code generated after modifying the compiler is as follows:
ADD R0,R1,R2ADD R0, R1, R2
ADD R5,R0,R4ADD R5, R0, R4
STD 0(R6),R5STD 0 (R6), R5
或给每条指令添加一个标记位,用以标记中间结果只被使用一次的两条指令,经编译后生成的代码如下:Or add a flag bit to each instruction to mark the two instructions whose intermediate results are only used once. The code generated after compilation is as follows:
ADD R3,R1,R2 1ADD R3, R1, R2 1
ADD R5,R3,R4 1ADD R5, R3, R4 1
STD 0(R6),R5 0STD 0(R6), R5 0
其中标记位为1时,表示两条指令存在中间结果被使用一次的关系;When the flag bit is 1, it means that the two instructions have a relationship that the intermediate result is used once;
当这两条指令需要被执行时,则处理器通过IF取值器将指令A与指令B读入。When the two instructions need to be executed, the processor reads the instruction A and the instruction B through the IF getter.
202、处理器在译码阶段判断第一指令的结果是否只被第一指令之后的第二指令使用一次的情况,若存在,则对两条指令进行标识。202. In the decoding stage, the processor judges whether the result of the first instruction is only used once by the second instruction following the first instruction, and if so, identifies the two instructions.
具体的,可以通过以下方法实现:Specifically, it can be achieved by the following methods:
若在译码阶段,译码器发现第一指令使用了特殊寄存器R0作为结果寄存器,同时接下来的第二指令使用寄存器R0作为源操作数,那么译码阶段将会识别出第一指令和第二指令并对该两条指令进行特殊标识;If in the decoding stage, the decoder finds that the first instruction uses the special register R0 as the result register, and the following second instruction uses the register R0 as the source operand, then the decoding stage will identify the first instruction and the second instruction. Two instructions and special identification for the two instructions;
或译码器发现第一指令与第二指令的标记位都为1,则对该两条指令进行特殊标识。Or, if the decoder finds that the flag bits of the first instruction and the second instruction are both 1, the two instructions are specially marked.
示例性的,若发现指令A使用了特殊寄存器R0作为结果寄存器,同时接下来的某指令B使用寄存器R0中的值作为源操作数,那么译码阶段将会识别出指令A和指令B具备‘中间结果只被使用一次’的关系,对该两条指令进行特殊标识;Exemplarily, if it is found that instruction A uses special register R0 as the result register, and at the same time a following instruction B uses the value in register R0 as the source operand, then the decoding stage will recognize that instruction A and instruction B have ' The relationship between the intermediate result is only used once', and the two instructions are specially identified;
或发现指令A与指令B的标记位都为1,则对指令A与指令B进行特殊标识。Or if it is found that the flag bits of instruction A and instruction B are both 1, special identification is performed on instruction A and instruction B.
203、处理器在重命名阶段,若发现两条指令拥有特殊标记,则对存储中间结果的寄存器不进行重命名,并将指令流信息发送给重排序缓冲器和发射队列。203. In the renaming stage, if the processor finds that two instructions have special marks, the register storing the intermediate result is not renamed, and the instruction flow information is sent to the reordering buffer and the issue queue.
具体的,可通过以下方法实现:Specifically, it can be achieved by the following methods:
当指令流到达重命名阶段,若发现两条指令拥有特殊标记,则对于存储这两条指令的中间结果的寄存器不进行重命名操作,即不将其映射为物理寄存器,而存储其他信息的寄存器需要进行重命名,并映射为物理寄存器。When the instruction flow reaches the renaming stage, if two instructions are found to have special marks, the registers that store the intermediate results of the two instructions will not be renamed, that is, they will not be mapped as physical registers, but registers that store other information Need to be renamed and mapped to physical registers.
示例性的,当指令A与指令B经过重命名阶段时,发现指令A与指令B拥有特殊标记,若指令A与指令B的中间结果被存储在R0中,则不对其中的R0寄存器进行重命名工作,其他寄存器照常进行重命名工作,即将对应的结构寄存器重命名为物理寄存器,若指令A与指令B的中间结果被存储在R3中,则不对其中的R3寄存器进行重命名工作,其他寄存器照常进行重命名工作,即将对应的结构寄存器重命名为物理寄存器,;Exemplarily, when instruction A and instruction B go through the renaming stage, it is found that instruction A and instruction B have special marks, and if the intermediate results of instruction A and instruction B are stored in R0, the R0 register will not be renamed work, other registers will be renamed as usual, that is, the corresponding structural registers will be renamed as physical registers, if the intermediate results of instruction A and instruction B are stored in R3, the R3 register will not be renamed, and other registers will continue as usual Carry out the renaming work, that is, rename the corresponding structural registers to physical registers;
当重命名工作结束后,将指令流相关信息发送到重排序缓冲器与发射队列中,其中指令流信息是译码以后得到的指令信息。包括源操作数,目的操作数,需要进行的操作和命令信息。After the renaming work is completed, the instruction flow related information is sent to the reordering buffer and the issue queue, wherein the instruction flow information is the instruction information obtained after decoding. Including the source operand, the destination operand, the operation to be performed and the command information.
204、处理器在发射队列中进行等待的指令的源操作数准备就绪后,将该指令发送到功能单元中进行运算。204. After the source operand of the instruction waiting in the issue queue is ready, the processor sends the instruction to the functional unit for calculation.
具体的,可以通过以下方法实现:Specifically, it can be achieved by the following methods:
当指令在发射队列中进行等待的时候,若寄存器堆中已经保存有最新的源操作数或功能单元已经算出最新的值,但是还没有写回寄存器堆中,则表明指令的源操作数已经准备就绪,将指令发送到功能单元中进行运算。When the instruction is waiting in the emission queue, if the latest source operand has been saved in the register file or the latest value has been calculated by the functional unit, but it has not been written back to the register file, it indicates that the source operand of the instruction has been prepared Ready, send the instruction to the functional unit for operation.
可选的,在进行计算后,还可以包括以下步骤:Optionally, after calculation, the following steps may also be included:
205、若第一指令的结果只被第一指令之后的第二指令使用一次,当第一指令计算出结果时,不将所述结果发送到寄存器堆,而是缓存在功能单元中,等待第二指令执行时,将所述结果作为源操作数。205. If the result of the first instruction is only used once by the second instruction after the first instruction, when the result is calculated by the first instruction, the result is not sent to the register file, but is cached in the functional unit, waiting for the second instruction When the second instruction is executed, the result is used as a source operand.
具体的,可以通过以下方法实现:Specifically, it can be achieved by the following methods:
对于只具有一般关系的两条指令,经过功能单元计算结束后的结果直接写回寄存器堆并通知重排序缓冲器指令执行完毕等待最终提交,对于中间结果只被使用一次的两条指令,若第一指令计算出结果时,并不将所述结果发送到寄存器堆,而是缓存在功能单元中,等待第二指令执行时,将所述结果作为源操作数;For two instructions that only have a general relationship, the result after the calculation of the functional unit is directly written back to the register file and notified to the reordering buffer. When an instruction calculates a result, the result is not sent to the register file, but is cached in the functional unit, and when waiting for the second instruction to be executed, the result is used as a source operand;
假如两条指令是连续的时候,第一指令执行的结果可以通过前向通路直接传递给第二指令进行计算而不需要缓存,第一指令执行结束时需要通知重排序缓冲器,当第二指令执行结束时,需要将结果写回寄存器堆,并通知重排序缓冲器。If the two instructions are consecutive, the result of the first instruction execution can be directly passed to the second instruction through the forward path for calculation without caching, and the reordering buffer needs to be notified when the execution of the first instruction ends, when the second instruction At the end of execution, the result needs to be written back to the register file and the reorder buffer notified.
示例性的,对于中间结果被使用一次的两条指令A和B,当A指令计算出结果时,该结果并不被发送到寄存器堆,而是缓存在功能单元中,并在B指令执行时,作为B指令的源操作数;Exemplarily, for two instructions A and B whose intermediate results are used once, when the A instruction calculates the result, the result is not sent to the register file, but is cached in the functional unit, and when the B instruction is executed , as the source operand of the B instruction;
事实上,假如A指令和B指令是连续的时候,A指令执行的结果可以通过前向通路直接传递给B指令进行计算而不需要缓存,对于A指令,其经过功能单元计算结束后是需要通知重排序缓冲器的,当B指令执行结束后,需要将B指令的执行结果写回寄存器堆,并通知重排序缓冲器。In fact, if instruction A and instruction B are continuous, the result of instruction A execution can be directly passed to instruction B for calculation through the forward path without caching. For instruction A, it needs to be notified after the calculation of the functional unit is completed. For the reordering buffer, after the execution of the B instruction is completed, the execution result of the B instruction needs to be written back to the register file, and the reordering buffer is notified.
206、若第一指令的结果只被第一指令之后的第二指令使用一次,则重排序缓冲器需要在两条指令都执行完毕后同时进行提交。206. If the result of the first instruction is only used once by the second instruction following the first instruction, the reordering buffer needs to be submitted simultaneously after both instructions are executed.
具体的,可以通过以下方法实现:Specifically, it can be achieved by the following methods:
若第一指令的结果只被第一指令之后的第二指令使用一次,为了避免第一指令执行时,忽然发生异常进入异常处理程序,而导致第一指令的结果丢失的情况,重排序缓冲器需要在第二指令执行结束时才可以提交第一指令和第二指令,即保证同时提交,假如第一指令执行结束了,而第二指令还没执行结束的时候,忽然发生异常,那么此时,第一和第二指令都不能提交,需要等待重新执行。If the result of the first instruction is only used once by the second instruction after the first instruction, in order to avoid the situation that an exception suddenly occurs and enters the exception handler when the first instruction is executed, resulting in the loss of the result of the first instruction, the reorder buffer It is necessary to submit the first instruction and the second instruction when the execution of the second instruction is completed, that is, to ensure that they are submitted at the same time. , neither the first nor the second command can be submitted and needs to wait for re-execution.
示例性的,对于A、B两条指令,重排序缓冲器需要在B指令完成时才可以提交A指令和B指令,即为了保证同时提交,从而避免A执行时,忽然发生异常而进入异常处理程序导致A指令的结果丢失的情况,假如A指令执行结束,而B指令还没执行结束的时候,忽然发生异常,那么此时,A指令和B指令都不能提交,需要等待重新执行。Exemplarily, for the two instructions A and B, the reordering buffer needs to submit the A instruction and the B instruction only when the B instruction is completed, that is, in order to ensure simultaneous submission, so as to avoid a sudden exception when A is executed and enter exception processing When the program causes the result of instruction A to be lost, if an exception suddenly occurs when the execution of instruction A is completed and the execution of instruction B is not completed, then at this time, neither instruction A nor instruction B can be submitted, and it needs to wait for re-execution.
本发明实施例提供一种CPU指令处理方法,当第一指令的结果只被第一指令之后的第二指令使用一次时,将第一指令和第二指令的中间结果不写回寄存器堆并且在寄存器重命名阶段对存储所述中间结果的寄存器不进行重命名,即不将存储所述中间结果的寄存器映射为物理寄存器,从而节省了寄存器资源,并且降低了读写继存器所需消耗的功耗。An embodiment of the present invention provides a CPU instruction processing method. When the result of the first instruction is only used once by the second instruction after the first instruction, the intermediate results of the first instruction and the second instruction are not written back to the register file and are The register renaming stage does not rename the registers storing the intermediate results, that is, does not map the registers storing the intermediate results into physical registers, thereby saving register resources and reducing the cost of reading and writing the relay registers. power consumption.
本发明实施例提供一种处理器01,如图3所示,处理器01包括:An embodiment of the present invention provides a processor 01. As shown in FIG. 3, the processor 01 includes:
判决单元011,用于判断第一指令的结果是否只被第一指令之后的第二指令使用一次;Judging unit 011, configured to judge whether the result of the first instruction is only used once by the second instruction after the first instruction;
执行单元012,用于若结果只被第一指令之后的第二指令使用一次,则将第一指令的结果不写回寄存器堆;并执行第一指令和第二指令;The execution unit 012 is used to not write the result of the first instruction back to the register file if the result is only used once by the second instruction after the first instruction; and execute the first instruction and the second instruction;
发射单元013,用于将第一指令和第二指令发射到功能单元中进行运算,使第一指令先于第二指令执行,并将第一指令的处理结果传递给第二指令,作为第二指令的源操作数。The sending unit 013 is used to send the first instruction and the second instruction to the functional unit for calculation, so that the first instruction is executed before the second instruction, and the processing result of the first instruction is passed to the second instruction as the second instruction. The source operand for the instruction.
进一步的,判决单元011具体用于:Further, the judgment unit 011 is specifically used for:
在译码阶段识别第一指令和第二指令是否有特殊标识,如果有特殊标识则确定第一指令的结果只被第一指令之后的第二指令使用一次。In the decoding stage, it is identified whether the first instruction and the second instruction have a special identifier, and if there is a special identifier, it is determined that the result of the first instruction is only used once by the second instruction after the first instruction.
再进一步的,如图4所示,处理器01还包括:Further, as shown in Figure 4, the processor 01 also includes:
标识单元014,在译码阶段识别第一寄存器作为第一指令的结果的存放寄存器,同时只作为第二指令的源操作数,则确定第一指令的结果只被第一指令之后的指令使用一次,对第一指令和第二指令做特殊标识。The identification unit 014, in the decoding stage, identifies the first register as the storage register for the result of the first instruction, and at the same time only serves as the source operand of the second instruction, then it is determined that the result of the first instruction is only used once by the instruction after the first instruction , make a special mark for the first instruction and the second instruction.
再进一步的,执行单元012具体用于:Furthermore, the execution unit 012 is specifically used for:
将第一寄存器替换为特殊寄存器,且对第一指令和第二指令做特殊关系标记。The first register is replaced with a special register, and a special relationship mark is made between the first instruction and the second instruction.
再进一步的,标识单元014具体用于:Furthermore, the identification unit 014 is specifically used for:
在第一指令以及第二指令后添加特殊比特位,用于标记第一指令和第二指令的关系。A special bit is added after the first instruction and the second instruction to mark the relationship between the first instruction and the second instruction.
更进一步的,发射单元013具体用于:Furthermore, the transmitting unit 013 is specifically used for:
若第一指令和第二指令为连续的两条指令,则将第一指令的结果通过前递通路直接传递给第二指令,作为第二指令的源操作数;If the first instruction and the second instruction are two consecutive instructions, the result of the first instruction is directly passed to the second instruction through the forward path as the source operand of the second instruction;
若第一指令和第二指令为不连续的两条指令,则在第一指令执行后,将第一指令的结果缓存在功能单元中,当第二指令执行时,将第一指令的结果传递给第二指令,作为第二指令的源操作数。If the first instruction and the second instruction are two discontinuous instructions, after the first instruction is executed, the result of the first instruction is cached in the functional unit, and when the second instruction is executed, the result of the first instruction is passed to the second instruction as the source operand of the second instruction.
可选的,如图5所示,处理器01还包括:Optionally, as shown in Figure 5, the processor 01 further includes:
重命名单元015,用于若结果只被第一指令之后的第二指令使用一次,则对第一指令的结果所在的寄存器在重命名阶段不进行重命名操作。The renaming unit 015 is configured to not rename the register where the result of the first instruction is located in the renaming stage if the result is only used once by the second instruction after the first instruction.
优选的,如图6所示,处理器01还包括:Preferably, as shown in Figure 6, the processor 01 also includes:
通知单元016,同于在第一指令执行完成后要通知重排序缓冲器,以便将第一指令按照重排序缓冲器中的排序规则进行提交;在第二指令执行完成后要将第二指令的结果写回寄存器堆,并通知重排序缓冲器,以便将第二指令按照重排序缓冲器中的排序规则进行提交。The notification unit 016 is the same as notifying the reordering buffer after the execution of the first instruction is completed, so that the first instruction is submitted according to the ordering rules in the reordering buffer; after the execution of the second instruction is completed, the The result is written back to the register file, and the reorder buffer is notified, so that the second instruction is submitted according to the ordering rule in the reorder buffer.
优选的,如图7所示,处理器01还包括:Preferably, as shown in Figure 7, the processor 01 also includes:
提交单元017,用于当第一指令和第二指令执行完成后,将第一指令和第二指令同时提交;Submitting unit 017, configured to submit the first instruction and the second instruction simultaneously after the execution of the first instruction and the second instruction is completed;
异常处理单元018,用于当第一指令和/或第二指令执行出现异常时,将第一指令和第二指令重新执行。The exception processing unit 018 is configured to re-execute the first instruction and the second instruction when an exception occurs in the execution of the first instruction and/or the second instruction.
本发明实施例提供一种处理器,当第一指令的结果只被第一指令之后的第二指令使用一次时,将第一指令和第二指令的中间结果不写回寄存器堆并且在寄存器重命名阶段对存储中间结果的寄存器不进行重命名,即不将存储中间结果的寄存器映射为物理寄存器,从而节省了寄存器资源,并且降低了读写继存器所需消耗的功耗。An embodiment of the present invention provides a processor. When the result of the first instruction is only used once by the second instruction after the first instruction, the intermediate results of the first instruction and the second instruction are not written back to the register file and are rewritten in the register. In the naming stage, the registers storing intermediate results are not renamed, that is, the registers storing intermediate results are not mapped to physical registers, thereby saving register resources and reducing the power consumption required for reading and writing relay registers.
本发明实施例提供一种处理器02,如图8所示,处理器02包括:An embodiment of the present invention provides a processor 02. As shown in FIG. 8, the processor 02 includes:
取指器021、译码器022、重命名部件023、发射队列024、重排序缓冲器025、寄存器堆026以及功能单元027,其中重命名部件023与发射队列024和重排序缓冲器025相连接,寄存器堆026与重排序缓冲器025、发射队列024相互连接,寄存器堆026和发射队列024与功能单元027相连接,功能单元027与重排序缓冲器025和寄存器堆026相连接,指令首先经过取指器021后到达译码器022;其中,译码器022用于:Instruction fetcher 021, decoder 022, renaming unit 023, emission queue 024, reordering buffer 025, register file 026, and functional unit 027, wherein the renaming unit 023 is connected to the emitting queue 024 and reordering buffer 025 , the register file 026 is connected to the reordering buffer 025 and the launch queue 024, the register file 026 and the launch queue 024 are connected to the functional unit 027, the functional unit 027 is connected to the reordering buffer 025 and the register file 026, and the instruction first passes through The instruction fetcher 021 reaches the decoder 022; wherein, the decoder 022 is used for:
判断第一指令的结果是否只被第一指令之后的第二指令使用一次;Determine whether the result of the first instruction is only used once by the second instruction after the first instruction;
若结果只被第一指令之后的第二指令使用一次,则将第一指令的结果不写回寄存器堆026。If the result is only used once by the second instruction following the first instruction, the result of the first instruction is not written back to the register file 026 .
进一步的,发射队列024用于:Further, the emission queue 024 is used for:
将第一指令和第二指令发射到功能单元027中进行运算,使第一指令先于第二指令执行,并将第一指令的处理结果传递给第二指令,作为第二指令的源操作数。Send the first instruction and the second instruction to the functional unit 027 for calculation, make the first instruction execute before the second instruction, and transfer the processing result of the first instruction to the second instruction as the source operand of the second instruction .
再进一步的,译码器022具体用于:Furthermore, the decoder 022 is specifically used for:
在译码阶段识别第一指令和第二指令是否有特殊标识,如果有特殊标识则确定第一指令的结果只被第一指令之后的第二指令使用一次。In the decoding stage, it is identified whether the first instruction and the second instruction have a special identifier, and if there is a special identifier, it is determined that the result of the first instruction is only used once by the second instruction after the first instruction.
再进一步的,译码器022具体用于:Furthermore, the decoder 022 is specifically used for:
在译码阶段识别第一寄存器作为第一指令的结果的存放寄存器,同时只作为第二指令的源操作数,则确定第一指令的结果只被第一指令之后的指令使用一次,对第一指令和第二指令做特殊标识。In the decoding stage, the first register is identified as the storage register for the result of the first instruction, and at the same time it is only used as the source operand of the second instruction, then it is determined that the result of the first instruction is only used once by the instruction after the first instruction. Instructions and second instructions are specially marked.
再进一步的,译码器022具体用于:Furthermore, the decoder 022 is specifically used for:
将第一寄存器替换为特殊寄存器,且对第一指令和第二指令做特殊关系标记。The first register is replaced with a special register, and a special relationship mark is made between the first instruction and the second instruction.
再进一步的,译码器022具体用于:Furthermore, the decoder 022 is specifically used for:
在第一指令以及第二指令后添加特殊比特位,用于标记第一指令和第二指令的关系。A special bit is added after the first instruction and the second instruction to mark the relationship between the first instruction and the second instruction.
再进一步的,发射队列024具体用于:Furthermore, the emission queue 024 is specifically used for:
若第一指令和第二指令为连续的两条指令,则将第一指令的结果通过前递通路直接传递给第二指令,作为第二指令的源操作数;If the first instruction and the second instruction are two consecutive instructions, the result of the first instruction is directly passed to the second instruction through the forward path as the source operand of the second instruction;
若第一指令和第二指令为不连续的两条指令,则在第一指令执行后,将第一指令的结果缓存在功能单元027中,当第二指令执行时,将第一指令的结果传递给第二指令,作为第二指令的源操作数。If the first instruction and the second instruction are discontinuous two instructions, then after the first instruction is executed, the result of the first instruction is cached in the functional unit 027, and when the second instruction is executed, the result of the first instruction is Passed to the second instruction as the source operand of the second instruction.
再进一步的,重命名部件023具体用于:Furthermore, the renaming component 023 is specifically used for:
若结果只被第一指令之后的第二指令使用一次,则对第一指令的结果所在的寄存器在重命名阶段不进行重命名操作。If the result is only used once by the second instruction after the first instruction, no renaming operation is performed on the register where the result of the first instruction is located in the renaming stage.
再进一步的,功能单元027具体用于:Furthermore, the functional unit 027 is specifically used for:
在第一指令执行完成后要通知重排序缓冲器025,以便将第一指令按照重排序缓冲器025中的排序规则进行提交;在第二指令执行完成后要将第二指令的结果写回寄存器堆026,并通知重排序缓冲器025,以便将第二指令按照重排序缓冲器025中的排序规则进行提交。After the execution of the first instruction is completed, the reordering buffer 025 is notified so that the first instruction is submitted according to the ordering rules in the reordering buffer 025; after the execution of the second instruction is completed, the result of the second instruction is written back to the register Heap 026, and notify the reorder buffer 025, so as to submit the second instruction according to the sorting rules in the reorder buffer 025.
更进一步的,重排序缓冲器025还用于:Furthermore, the reordering buffer 025 is also used for:
当第一指令和第二指令执行完成后,将第一指令和第二指令同时提交;After the execution of the first instruction and the second instruction is completed, submit the first instruction and the second instruction at the same time;
当第一指令和/或第二指令执行出现异常时,将第一指令和第二指令重新执行。When an exception occurs in the execution of the first instruction and/or the second instruction, the first instruction and the second instruction are re-executed.
本发明实施例提供一种处理器,当第一指令的结果只被第一指令之后的第二指令使用一次时,将第一指令和第二指令的中间结果不写回寄存器堆并且在寄存器重命名阶段对存储中间结果的寄存器不进行重命名,即不将存储中间结果的寄存器映射为物理寄存器,从而节省了寄存器资源,并且降低了读写继存器所需消耗的功耗。An embodiment of the present invention provides a processor. When the result of the first instruction is only used once by the second instruction after the first instruction, the intermediate results of the first instruction and the second instruction are not written back to the register file and are rewritten in the register. In the naming stage, the registers storing intermediate results are not renamed, that is, the registers storing intermediate results are not mapped to physical registers, thereby saving register resources and reducing the power consumption required for reading and writing relay registers.
在本申请所提供的几个实施例中,应该理解到,所揭露的方法,装置和系统可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided in this application, it should be understood that the disclosed method, device and system can be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or May be integrated into another system, or some features may be ignored, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理包括,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用硬件加软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, each unit may be physically included separately, or two or more units may be integrated into one unit. The above-mentioned integrated units can be implemented in the form of hardware, or in the form of hardware plus software functional units.
上述以软件功能单元的形式实现的集成的单元,可以存储在一个计算机可读取存储介质中。上述软件功能单元存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-OnlyMemory,简称ROM)、随机存取存储器(Random Access Memory,简称RAM)、磁碟或者光盘等各种可以存储程序代码的介质。The above-mentioned integrated units implemented in the form of software functional units may be stored in a computer-readable storage medium. The above-mentioned software functional units are stored in a storage medium, and include several instructions to enable a computer device (which may be a personal computer, server, or network device, etc.) to execute some steps of the methods described in various embodiments of the present invention. The aforementioned storage media include: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as ROM), random access memory (Random Access Memory, referred to as RAM), magnetic disk or optical disc, etc., which can store program codes. medium.
以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以所述权利要求的保护范围为准。The above is only a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Anyone skilled in the art can easily think of changes or substitutions within the technical scope disclosed in the present invention. Should be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention should be determined by the protection scope of the claims.
Claims (18)
Priority Applications (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201310213735.8A CN104216681B (en) | 2013-05-31 | 2013-05-31 | A kind of cpu instruction processing method and processor |
| PCT/CN2013/088251 WO2014190699A1 (en) | 2013-05-31 | 2013-11-30 | Cpu instruction processing method and processor |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201310213735.8A CN104216681B (en) | 2013-05-31 | 2013-05-31 | A kind of cpu instruction processing method and processor |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN104216681A true CN104216681A (en) | 2014-12-17 |
| CN104216681B CN104216681B (en) | 2018-02-13 |
Family
ID=51987936
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201310213735.8A Active CN104216681B (en) | 2013-05-31 | 2013-05-31 | A kind of cpu instruction processing method and processor |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN104216681B (en) |
| WO (1) | WO2014190699A1 (en) |
Cited By (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN108614736A (en) * | 2018-04-13 | 2018-10-02 | 杭州中天微系统有限公司 | Realize device and processor that resource index is replaced |
| CN110825437A (en) * | 2018-08-10 | 2020-02-21 | 北京百度网讯科技有限公司 | Method and apparatus for processing data |
| CN111124492A (en) * | 2019-12-16 | 2020-05-08 | 海光信息技术有限公司 | Instruction generation method, apparatus, instruction execution method, processor and electronic device |
| CN111124500A (en) * | 2019-12-12 | 2020-05-08 | 浪潮(北京)电子信息产业有限公司 | Instruction execution method, device, equipment and storage medium |
| CN111209039A (en) * | 2018-11-21 | 2020-05-29 | 展讯通信(上海)有限公司 | Instruction processing method and device |
| CN117472445A (en) * | 2023-12-26 | 2024-01-30 | 睿思芯科(深圳)技术有限公司 | Superscalar processing system, method and related equipment based on emission buffering |
| CN121364891A (en) * | 2025-12-19 | 2026-01-20 | 此芯科技集团有限公司 | Operation result cache management method and superscalar processor |
Citations (10)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6145074A (en) * | 1997-08-19 | 2000-11-07 | Fujitsu Limited | Selecting register or previous instruction result bypass as source operand path based on bypass specifier field in succeeding instruction |
| WO2001061469A2 (en) * | 2000-02-16 | 2001-08-23 | Koninklijke Philips Electronics N.V. | Apparatus and method for reducing register write traffic in processors with exception routines |
| EP1199629A1 (en) * | 2000-10-17 | 2002-04-24 | STMicroelectronics S.r.l. | Processor architecture with variable-stage pipeline |
| CN1363063A (en) * | 2000-02-16 | 2002-08-07 | 皇家菲利浦电子有限公司 | Method and system for reducing write traffic in processors |
| CN1560732A (en) * | 2004-03-03 | 2005-01-05 | 浙江大学 | Processor and compiling method for statically implementing data bypass and register file data writing control |
| CN1761940A (en) * | 2003-03-19 | 2006-04-19 | 皇家飞利浦电子股份有限公司 | A pipelined instruction processor having data bypassing |
| WO2007057831A1 (en) * | 2005-11-15 | 2007-05-24 | Nxp B.V. | Data processing method and apparatus |
| US20080016327A1 (en) * | 2006-06-27 | 2008-01-17 | Amitabh Menon | Register File Bypass With Optional Results Storage and Separate Predication Register File in a VLIW Processor |
| CN101361039A (en) * | 2006-01-20 | 2009-02-04 | 松下电器产业株式会社 | processor |
| US20100199074A1 (en) * | 2009-02-05 | 2010-08-05 | International Business Machines Corporation | Instruction set architecture with decomposing operands |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101719055B (en) * | 2009-12-03 | 2012-10-10 | 杭州中天微系统有限公司 | Quick implementation, loading and storage command module |
-
2013
- 2013-05-31 CN CN201310213735.8A patent/CN104216681B/en active Active
- 2013-11-30 WO PCT/CN2013/088251 patent/WO2014190699A1/en not_active Ceased
Patent Citations (11)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6145074A (en) * | 1997-08-19 | 2000-11-07 | Fujitsu Limited | Selecting register or previous instruction result bypass as source operand path based on bypass specifier field in succeeding instruction |
| WO2001061469A2 (en) * | 2000-02-16 | 2001-08-23 | Koninklijke Philips Electronics N.V. | Apparatus and method for reducing register write traffic in processors with exception routines |
| CN1363063A (en) * | 2000-02-16 | 2002-08-07 | 皇家菲利浦电子有限公司 | Method and system for reducing write traffic in processors |
| EP1199629A1 (en) * | 2000-10-17 | 2002-04-24 | STMicroelectronics S.r.l. | Processor architecture with variable-stage pipeline |
| US20020124155A1 (en) * | 2000-10-17 | 2002-09-05 | Stmicroelectronics S.R.L. | Processor architecture |
| CN1761940A (en) * | 2003-03-19 | 2006-04-19 | 皇家飞利浦电子股份有限公司 | A pipelined instruction processor having data bypassing |
| CN1560732A (en) * | 2004-03-03 | 2005-01-05 | 浙江大学 | Processor and compiling method for statically implementing data bypass and register file data writing control |
| WO2007057831A1 (en) * | 2005-11-15 | 2007-05-24 | Nxp B.V. | Data processing method and apparatus |
| CN101361039A (en) * | 2006-01-20 | 2009-02-04 | 松下电器产业株式会社 | processor |
| US20080016327A1 (en) * | 2006-06-27 | 2008-01-17 | Amitabh Menon | Register File Bypass With Optional Results Storage and Separate Predication Register File in a VLIW Processor |
| US20100199074A1 (en) * | 2009-02-05 | 2010-08-05 | International Business Machines Corporation | Instruction set architecture with decomposing operands |
Cited By (13)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US11734014B2 (en) | 2018-04-13 | 2023-08-22 | C-Sky Microsystems Co., Ltd. | Device and processor for implementing resource index replacement |
| CN108614736A (en) * | 2018-04-13 | 2018-10-02 | 杭州中天微系统有限公司 | Realize device and processor that resource index is replaced |
| US11340905B2 (en) | 2018-04-13 | 2022-05-24 | C-Sky Microsystems Co., Ltd. | Device and processor for implementing resource index replacement |
| CN110825437B (en) * | 2018-08-10 | 2022-04-29 | 昆仑芯(北京)科技有限公司 | Method and apparatus for processing data |
| CN110825437A (en) * | 2018-08-10 | 2020-02-21 | 北京百度网讯科技有限公司 | Method and apparatus for processing data |
| CN111209039A (en) * | 2018-11-21 | 2020-05-29 | 展讯通信(上海)有限公司 | Instruction processing method and device |
| CN111124500A (en) * | 2019-12-12 | 2020-05-08 | 浪潮(北京)电子信息产业有限公司 | Instruction execution method, device, equipment and storage medium |
| CN111124500B (en) * | 2019-12-12 | 2022-03-08 | 浪潮(北京)电子信息产业有限公司 | Instruction execution method, apparatus, device and storage medium |
| WO2021120712A1 (en) * | 2019-12-16 | 2021-06-24 | 成都海光微电子技术有限公司 | Instruction generation method and apparatus, instruction execution method, processor, electronic device, and storage medium |
| CN111124492A (en) * | 2019-12-16 | 2020-05-08 | 海光信息技术有限公司 | Instruction generation method, apparatus, instruction execution method, processor and electronic device |
| CN117472445A (en) * | 2023-12-26 | 2024-01-30 | 睿思芯科(深圳)技术有限公司 | Superscalar processing system, method and related equipment based on emission buffering |
| CN117472445B (en) * | 2023-12-26 | 2024-04-23 | 睿思芯科(深圳)技术有限公司 | Superscalar processing system, method and related equipment based on emission buffering |
| CN121364891A (en) * | 2025-12-19 | 2026-01-20 | 此芯科技集团有限公司 | Operation result cache management method and superscalar processor |
Also Published As
| Publication number | Publication date |
|---|---|
| WO2014190699A1 (en) | 2014-12-04 |
| CN104216681B (en) | 2018-02-13 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| TWI681333B (en) | Reliability enhancement systems, methods and computer readable medium | |
| CN104216681B (en) | A kind of cpu instruction processing method and processor | |
| CN101916180B (en) | Method and system for executing register type instruction in RISC (Reduced Instruction-Set Computer) processor | |
| US9286072B2 (en) | Using register last use infomation to perform decode-time computer instruction optimization | |
| CN108694056B (en) | Hybrid atomicity support for binary translation-based microprocessors | |
| TWI502500B (en) | Microprocessors, microprocessor operation methods, and computer program products thereof | |
| TWI658407B (en) | Managing instruction order in a processor pipeline | |
| TWI733760B (en) | Memory copy instructions, processors, methods, and systems | |
| CN107810483A (en) | Verify the jump target in block-based processor | |
| TWI730312B (en) | Managing instruction order in a processor pipeline | |
| US8266411B2 (en) | Instruction set architecture with instruction characteristic bit indicating a result is not of architectural importance | |
| CN110515656B (en) | A kind of execution method of CASP instruction, microprocessor and computer equipment | |
| CN102103482B (en) | Adaptive Optimized Compare-Swap Operation | |
| CN103207776B (en) | Out-of-order gene issuing processor core | |
| CN105164637A (en) | Dynamic optimization of pipelined software | |
| CN116134417A (en) | Register renaming for power saving | |
| WO2026016845A1 (en) | Processor, graphics card, computer device, and dependency release method | |
| CN101147125A (en) | Writable Fragmented Word Architected Registers for Direct Accumulation of Unaligned Data | |
| CN111857830B (en) | Method, system and storage medium for designing path for forwarding instruction data in advance | |
| US11451241B2 (en) | Setting values of portions of registers based on bit values | |
| CN100476744C (en) | Apparatus and method for detecting transient fault of assembly line based on time redundancy | |
| US20030182538A1 (en) | Method and system for managing registers | |
| CN105302639A (en) | Dynamic scheduling method in Power PC vector co-processor decoding circuit | |
| US20140365751A1 (en) | Operand generation in at least one processing pipeline | |
| US6922760B2 (en) | Distributed result system for high-performance wide-issue superscalar processor |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| C06 | Publication | ||
| PB01 | Publication | ||
| C10 | Entry into substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |