WO2019134376A1 - Virtual address determining method and apparatus, processor, and storage medium - Google Patents

Virtual address determining method and apparatus, processor, and storage medium Download PDF

Info

Publication number
WO2019134376A1
WO2019134376A1 PCT/CN2018/102225 CN2018102225W WO2019134376A1 WO 2019134376 A1 WO2019134376 A1 WO 2019134376A1 CN 2018102225 W CN2018102225 W CN 2018102225W WO 2019134376 A1 WO2019134376 A1 WO 2019134376A1
Authority
WO
WIPO (PCT)
Prior art keywords
address
instruction
previous
target
offset
Prior art date
Application number
PCT/CN2018/102225
Other languages
French (fr)
Chinese (zh)
Inventor
劳咏仪
Original Assignee
华为技术有限公司
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2019134376A1 publication Critical patent/WO2019134376A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/0802Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches
    • G06F12/0875Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches with dedicated cache, e.g. instruction or stack
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/30Arrangements for executing machine instructions, e.g. instruction decode
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/38Concurrent instruction execution, e.g. pipeline or look ahead
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/38Concurrent instruction execution, e.g. pipeline or look ahead
    • G06F9/3867Concurrent instruction execution, e.g. pipeline or look ahead using instruction pipelines

Definitions

  • the present application relates to the field of processor technologies, and in particular, to a virtual address determining method and apparatus, a processor, and a storage medium.
  • a typical operational pipeline of the central processing unit is: fetching instructions (ie, fetching instructions), decoding instructions, transmitting instructions, executing instructions, accessing memory and submitting results, fetching instructions, decoding instructions, transmitting instructions, executing instructions, and accessing memory. Any of the body and the submitted results is called a pipeline stage.
  • the central processing unit includes units corresponding to each pipeline stage, each unit is configured to perform a corresponding pipeline stage operation, for example, the central processing unit includes an instruction fetch unit, and the instruction fetch unit performs an instruction fetch operation, and the fetched instruction is required.
  • branch instructions may include direct branch instructions and non-direct branch instructions.
  • the fetching unit first needs to determine the virtual address of the target instruction to be acquired, and then acquires the target instruction based on the virtual address.
  • the virtual address may be a program counter (PC) address.
  • the instruction fetch unit determines the virtual address of the target instruction according to the virtual address of the previous instruction of the target instruction, and then determines the physical address of the target instruction according to the virtual address and address mapping of the target instruction, and finally stores the physical address according to the target instruction.
  • the target instruction is fetched from the space (for example, the level one instruction cache).
  • the previous instruction of the target instruction is an instruction that the instruction instruction unit has taken out.
  • the previous instruction is a direct branch instruction
  • the previous instruction includes an offset address
  • the instruction unit is virtualized according to the previous instruction of the target instruction.
  • the address determining the virtual address of the target instruction may include: the instruction fetch unit decodes the previous instruction to obtain an offset address included in the previous instruction, and then performs sign extend on the offset address to obtain an extended bias. The address is shifted, the extended offset address is aligned with the virtual address of the previous instruction, and the width is equal. Finally, the instruction fetch unit adds the extended offset address to the virtual address of the previous instruction to obtain the virtual address of the target instruction. .
  • the address width of the processor increases, the amount of calculation for adding the offset address to the virtual address is larger and larger. Therefore, the delay of determining the virtual address of the target instruction is large, and the processing speed of the central processing unit is slow.
  • the present application provides a virtual address determining method and apparatus, a processor, and a storage medium, which are helpful in solving the problem that the delay of determining a virtual address is large and the processing speed of the processor is slow.
  • the technical solution of the present application is as follows:
  • a virtual address determining method comprising:
  • Determining the remaining address of the target instruction the sum of the width of the remaining address of the target instruction and the width of the lower address of the target instruction being equal to the width of the virtual address of the previous instruction;
  • the lower address of the target instruction is combined with the remaining address of the target instruction to obtain the virtual address of the target instruction.
  • the lower address stored in the instruction space of different instructions is aligned in the 0th bit of the instruction space.
  • the solution provided by the present application since it is not necessary to calculate the lower address of the target instruction in determining the virtual address of the target instruction, only the remaining address of the target instruction needs to be calculated (the remaining address is the virtual address of the target instruction except the lower address) The address), and then the remaining address of the target instruction is combined with the lower address of the target instruction to obtain the virtual address of the target instruction, so that the delay of determining the virtual address of the target instruction can be reduced, and the processing speed of the processor can be improved.
  • the method further includes:
  • the lower address of the target instruction is stored into the instruction space of the previous instruction.
  • the solution provided by the present application can facilitate the determination of the virtual address of the target instruction by pre-calculating the lower address of the target instruction and storing the lower address of the target instruction to the instruction space of the previous instruction of the target instruction.
  • the instruction space of an instruction reads the lower address of the target instruction.
  • the lower address of the target instruction is calculated, including:
  • the lower address of the previous instruction is added to the lower address of the offset address to obtain the lower address of the target instruction, and the lower address of the target instruction is aligned with the lower address of the previous instruction and the width is equal.
  • the solution provided by the present application generates the lower address of the target instruction by adding the lower address of the previous instruction of the target instruction to the lower address of the included offset address of the target instruction, thereby facilitating the determination of the lower address of the target instruction.
  • the method further includes: storing the low carry into the extended instruction space, the low bit The carry is a carry generated by adding the lower address of the previous instruction to the lower address of the offset address, and the extended instruction space is an instruction space obtained by expanding the instruction space of the previous instruction.
  • the solution provided by the present application can facilitate reading the lower carry from the extended instruction space in the process of determining the virtual address of the target instruction by storing the lower carry into the extended instruction space.
  • the remaining address includes a median address and a high address
  • determining a remaining address of the target instruction includes:
  • the offset address is composed of the upper address of the offset address and the lower address of the offset address
  • the upper address of the target instruction is determined according to the median carry, the upper address of the previous instruction, and the sign of the offset address.
  • the median carry is the median address of the previous instruction, the upper address of the offset address, and the lower carry phase. Add the resulting carry.
  • determining a high-order address of the target instruction according to a median carry, a high-order address of the previous instruction, and a symbol of the offset address including:
  • the lower address of the target instruction is calculated, including:
  • the lower address of the previous instruction is added to the offset address to obtain the lower address of the target instruction, and the lower address of the target instruction is aligned with the lower address of the previous instruction and the width is equal.
  • the solution provided by the present application generates the lower address of the target instruction by adding the lower address of the previous instruction of the target instruction to the offset address, thereby facilitating the determination of the lower address of the target instruction.
  • the remaining address includes a high-order address
  • the method further includes:
  • Determining the upper address of the target instruction according to the lower carry, the upper address of the previous instruction, and the sign of the offset address, and the lower carry is a carry generated by adding the lower address and the offset address of the previous instruction;
  • the address indication symbol is stored in an extended instruction space, which is an instruction space obtained by expanding the instruction space of the previous instruction.
  • the solution provided by the present application can store the address indication symbol into the extended instruction space by predetermining the upper address of the target instruction and generating the address indication symbol, which can facilitate reading the address from the extended instruction space in the process of determining the virtual address of the target instruction.
  • determining a remaining address of the target instruction includes:
  • the upper address of the target instruction is determined according to the address indication symbol.
  • the solution provided by the present application can save the delay of calculating the upper address of the target instruction and improve the processing speed of the processor by determining the upper address of the target instruction according to the address indication symbol.
  • determining a high-order address of the target instruction according to a low-order carry, a high-order address of the previous instruction, and a symbol of the offset address including:
  • a virtual address determining apparatus comprising at least one module, the at least one module configured to implement the virtual address determination provided by the foregoing first aspect or any of the optional aspects of the first aspect method.
  • a processor comprising the virtual address determining apparatus provided by the second aspect or the optional aspect of the second aspect.
  • a computer readable storage medium having stored therein instructions that, when executed on a processor of a computer, cause the processor to perform the first aspect or the first aspect The virtual address determination method provided by any of the alternatives.
  • a computer program product comprising instructions for causing a processor to perform the virtualization provided by the first aspect or any of the alternatives of the first aspect when the computer program product is run on a processor of the computer Address determination method.
  • a processing apparatus comprising at least one circuit for performing the virtual address determining method provided by the first aspect or any alternative of the first aspect.
  • a chip comprising programmable logic circuitry and/or program instructions for implementing virtual address determination provided by the first aspect or any of the alternatives of the first aspect when the chip is running method.
  • the virtual address determining method and apparatus, processor, and storage medium provided by the present application in the process of determining the virtual address of the target instruction, because the lower address of the target instruction is read from the instruction space of the previous instruction of the target instruction No need to calculate the lower address of the target instruction, only need to calculate the remaining address of the target instruction (the remaining address is the address of the virtual address of the target instruction except the lower address), and then merge the remaining address of the target instruction with the lower address of the target instruction.
  • the virtual address of the target instruction can be obtained, so that the calculation amount of the virtual address of the target instruction can be reduced, which helps to solve the problem that the delay of determining the virtual address of the target instruction is large, and the processing speed of the processor is slow. Small determines the delay of the virtual address of the target instruction, and improves the processing speed of the processor.
  • FIG. 1 is a schematic diagram of a pipeline of a processor according to an embodiment of the present application.
  • FIG. 2 is a schematic diagram of address mapping involved in an embodiment of the present application.
  • FIG. 3 is another schematic diagram of address mapping according to an embodiment of the present application.
  • FIG. 4 is a schematic diagram of an instruction space of a direct branch instruction according to an embodiment of the present application.
  • FIG. 5 is a flowchart of a method for determining a virtual address according to an embodiment of the present application
  • FIG. 6 is a flowchart of a method for determining another virtual address provided by an embodiment of the present application.
  • FIG. 7 is a schematic diagram of an instruction space provided by an embodiment of the present application.
  • FIG. 8 is a schematic diagram of calculating a virtual address according to an embodiment of the present application.
  • FIG. 9 is a schematic diagram of another computing virtual address provided by an embodiment of the present application.
  • FIG. 10 is a flowchart of a method for determining a virtual address determining method according to an embodiment of the present application
  • FIG. 11 is a schematic diagram of another instruction space provided by an embodiment of the present application.
  • FIG. 12 is a schematic diagram of still another computing virtual address provided by an embodiment of the present application.
  • FIG. 13 is a schematic diagram of still another computing virtual address provided by an embodiment of the present application.
  • FIG. 14 is a block diagram of a virtual address determining apparatus according to an embodiment of the present application.
  • FIG. 15 is a block diagram of another virtual address determining apparatus according to an embodiment of the present application.
  • 16 is a block diagram of a first determining module according to an embodiment of the present application.
  • FIG. 17 is a block diagram of still another virtual address determining apparatus according to an embodiment of the present application.
  • the central processing unit is a typical processor. Most of the central processing units operate in a pipeline.
  • the pipeline consists of a number of different pipeline stages.
  • the central processing unit includes units corresponding to each pipeline stage. Used to perform the corresponding pipeline-level operations, and different pipelines contain different pipeline stages depending on the speed requirements of the central processor and the chip process. As shown in FIG. 1, it shows a typical operation pipeline of the central processing unit. Referring to FIG.
  • the pipeline includes: fetching instructions, decoding instructions, transmitting instructions, executing instructions, accessing memory and submitting results, fetching instructions,
  • Each of the decoding instruction, the transmission instruction, the execution instruction, the access memory, and the submission result may be referred to as a pipeline stage, and the central processing unit may include an instruction fetch unit, a decoding unit, a transmitting unit, an execution unit, The access unit and the submitting unit, the fetching unit is configured to perform the fetching operation, and after fetching the fetching instruction, the instruction unit transmits the instruction to the decoding unit, the decoding unit decodes the instruction, and transmits the decoded instruction to the transmitting unit, and transmits The unit transmits the instruction to the execution unit. After the execution unit executes the instruction, the instruction is transmitted to the access unit, and the access unit accesses the memory according to the instruction, and then the submit unit submits the result.
  • the embodiment of the present application mainly relates to fetching instructions in the above pipeline. Therefore, the process of fetching instructions by the fetching unit is mainly described herein.
  • the instruction fetch unit may first determine the virtual address of the target instruction to be acquired, and then acquire the target instruction according to the virtual address of the target instruction (that is, fetch the instruction according to the virtual address).
  • a virtual address is also called a logical address.
  • a virtual address can be a PC address.
  • the instruction unit adds an address value to the virtual address of the previous instruction of the target instruction (the address value) Depending on how many instructions are fetched in one cycle and the width of each instruction, the virtual address of the target instruction is obtained, and the target instruction is obtained according to the virtual address of the target instruction. If the previous instruction of the target instruction is a branch instruction, the target instruction may or may not jump, and the instruction instruction unit may predict whether the target instruction jumps.
  • the fetch unit adds an address value to the virtual address of the previous instruction of the target instruction to obtain the virtual address of the target instruction, and fetches the instruction according to the virtual address of the target instruction. If the instruction fetch unit predicts the target instruction jump, the fetch unit needs to calculate a branch target address, and then fetches the instruction according to the jump destination address, which is also the virtual address of the target instruction. . Generally, the instruction fetch unit can add an offset address to the virtual address of the previous instruction of the target instruction to obtain the jump destination address. The offset address may be located in the previous instruction of the target instruction, or may be located in the register.
  • the previous instruction of the target instruction may be referred to as a direct branch (directbranch).
  • the instruction if the offset address is in a register, the previous instruction of the target instruction may be referred to as an indirect branch instruction.
  • the instruction fetch unit can decode the previous instruction of the target instruction to obtain an offset address, and then compare the virtual address of the previous instruction of the target instruction with the decoded offset address. Add the jump destination address.
  • the instruction instruction unit may use a branch target buffer (BTB) to predict the jump destination address, or The instruction unit waits until the subsequent execution unit reads the offset address from the register according to the previous instruction of the target instruction, and adds the virtual address of the previous instruction of the target instruction to the offset address read from the register, and then The address obtained by adding the execution units is determined as the jump destination address.
  • BTB branch target buffer
  • the execution unit may identify the instruction, and when the execution unit recognizes that the instruction is an indirect branch instruction, the execution unit reads the offset address from the register, and may be based on the offset address.
  • the jump destination address is calculated and the jump destination address is fed back to the instruction fetch unit. It should be noted that after the processor is powered on, the address reset may be performed, and the instruction fetch unit may acquire the first instruction after the processor is powered on according to the reset virtual address, and then the processor fetches the instruction according to the above method.
  • the fetching instruction unit fetching the instruction according to the virtual address of the target instruction may include: the fetching instruction unit determines the physical address of the target instruction according to the virtual address and the address mapping of the target instruction, and acquires the target from the storage space according to the physical address of the target instruction.
  • the address mapping may be a physical index physical tag (PIPT) address mapping or a virtual index physical tag (VIPT) address mapping, or may be a direct mapping.
  • FIG. 2 is a schematic diagram of address mapping involved in the embodiment of the present application.
  • the address mapping diagram may represent a PIPT address mapping or a VIPT address mapping. Referring to FIG.
  • a virtual address is stored in a virtual address space, and physical
  • the address is stored in the physical address space, where the physical address space is usually a level one instruction cache of the processor, and the mapping table is used to record the mapping relationship between the virtual address stored in the virtual address space and the physical address stored in the physical address space, and fetch instructions.
  • the unit can obtain the physical address of the target instruction according to the virtual address lookup mapping table of the target instruction. As shown in FIG. 2, in a PIPT address mapping or a VIPT address mapping, different virtual addresses can be mapped to the same physical address, and the same physical address stores the same instruction, so that the different virtual addresses have the same offset address.
  • the jump destination address obtained by adding the different virtual addresses to the offset address is different.
  • the lower address of the virtual address is equal to the lower address of the physical address, and therefore, the different virtual addresses are respectively the same.
  • FIG. 3 is another schematic diagram of address mapping involved in the embodiment of the present application.
  • the address mapping diagram may represent direct mapping.
  • the virtual address is stored in the virtual address space
  • the physical address is stored in the physical address.
  • the physical address space is usually the processor's level one instruction cache.
  • the lower address of the virtual address of the target instruction can be determined as the physical address of the target instruction.
  • determining the virtual address of the target instruction as the physical address of the target instruction specifically determining the lower address of the virtual address of the target instruction as the physical address of the target instruction, or determining the virtual address of the target instruction as the physical address of the target instruction. , can be determined according to the width of the physical address of the target instruction.
  • the address width of the processor increases continuously (for example, the address width of the processor increases from 32 bits to 64 bits), so that the calculation amount of adding the offset address to the virtual address is correspondingly increased, The delay of determining the virtual address of the target instruction is large.
  • the offset addresses included in different direct branch instructions may be different.
  • the offset addresses contained in different direct branch instructions may not be aligned in the instruction space.
  • the width of the offset address is the virtual address of the previous instruction of the target instruction. The width may be different. Before adding the offset address to the virtual address of the previous instruction of the target instruction, the offset address needs to be sign-extended so that the width of the offset address is the virtual address of the previous instruction of the target instruction.
  • the width is equal, and the offset address is aligned with the virtual address of the previous instruction of the target instruction, and then the bit address is added by bit to the virtual address of the previous instruction of the target instruction to obtain the virtual address of the target instruction, which results in The delay in determining the virtual address of the target instruction is further increased.
  • FIG. 4 shows a schematic diagram of a direct branch instruction according to an embodiment of the present application.
  • the instruction BL is a direct branch instruction, and the instruction field of each instruction is the 0th bit to the 31st bit, imm* represents the instruction space in which the offset address is stored, and * represents the width of the offset address. As shown in FIG.
  • the width of the offset address included in the instruction B.cond, the width of the offset address included in the instruction CBNZ, and the width of the offset address included in the instruction CBZ are both 19 bits, and the instruction B.cond
  • the instruction space in which the offset address is stored, the instruction space in which the offset address is stored in the instruction CBNZ, and the instruction space in which the offset address is stored in the instruction CBZ are the 5th to 23rd bits, and the width of the offset address included in the instruction TBNZ
  • the offset address included in the instruction TBZ is 14 bits wide, and the instruction space in which the offset address is stored in the instruction TBNZ and the instruction space in which the offset address is stored in the instruction TBZ are all 5th to 18th bits, and the instruction B is
  • the width of the included offset address and the width of the offset address included in the instruction BL are both 26 bits, and the instruction space in which the offset address is stored in the instruction B and the instruction space in which the offset address is stored in the instruction BL are all the 0
  • the instruction fetch unit symbolically expands the offset address, and then adds the offset address to the virtual address of the previous instruction of the target instruction by bit to obtain the virtual of the target instruction.
  • the address can be expressed by the following equation (1):
  • br_trgt[63:0] represents the virtual address of the target instruction (that is, the jump destination address)
  • cur_pc[63:0] represents the virtual address of the previous instruction of the target instruction
  • * indicates a partial The width of the shift address
  • imm[*] indicates the sign of the offset address (that is, the sign of the highest bit of the offset address)
  • imm[(*-1):0] indicates the offset address
  • ⁇ (64-*) ⁇ imm[*] ⁇ is a sign extension of the offset address, indicating that imm[*] is copied (64-*) bits
  • imm[(*-1) :0] ⁇ indicates the extended offset address.
  • imm[(*-1):0] 10101010101010101010
  • imm[*] 1
  • ⁇ (64-*) ⁇ imm[*] ⁇ imm[(*-1):0] ⁇ indicates that the copied 50-bit 1 is added to the high bit of 101010101010 to obtain an extended offset. address.
  • imm[*] if imm[*] is 0, the equation (1) represents a 64-bit virtual address (ie, the virtual address of the previous instruction of the target instruction) and 64 bits.
  • the offset addresses (ie, the extended offset addresses) are added to obtain a 64-bit virtual address (ie, the virtual address of the target instruction). If imm[*] is 1, the equation (1) represents 64 bits. The virtual address is subtracted from the 64-bit offset address to obtain a 64-bit virtual address.
  • the jump target address is calculated by the instruction unit according to the offset address in the direct branch instruction and the virtual address of the previous instruction of the target instruction, or is the execution unit according to the offset address and the target instruction.
  • the virtual address of the previous instruction is calculated, or the instruction fetch unit is predicted by the BTB. Due to the increase of the address width of the processor, the delay of determining the jump destination address is large, and in addition, in the same stage pipeline. In addition to determining the jump destination address, other logical operations are required, which causes the processor to process the instruction with a large delay, which directly affects the processing speed of the processor.
  • the virtual address determining method and apparatus, the processor, and the storage medium provided by the embodiments of the present application predict to calculate a partial address in the virtual address of the target instruction before fetching the instruction, and only need to calculate the virtual address of the target instruction in the process of fetching instructions.
  • the remaining address in the middle and then combine the predicted partial address with the remaining address to obtain the virtual address of the target instruction (that is, the jump destination address). Since the partial address is expected to be calculated, the address to be calculated in the process of fetching the instruction is required.
  • the smaller width can reduce the delay of determining the jump destination address and improve the processing speed of the processor.
  • the target instruction is an instruction that needs to be acquired
  • the “previous instruction” is a noun
  • the previous instruction is the previous instruction of the target instruction
  • the previous instruction is before the target instruction is acquired. It has been obtained, and in the following embodiments, all lower address, all median address, all upper address and all offset addresses refer to a virtual address, and the offset address refers to the previous instruction. Offset address.
  • FIG. 5 is a flowchart of a method for determining a virtual address according to an embodiment of the present application.
  • the virtual address determining method may be used to determine a virtual address of a target instruction. Referring to Figure 5, the method includes:
  • Step 501 Calculate a lower address of the target instruction to be acquired.
  • the instruction fetch unit may calculate the lower address of the target instruction according to the lower address of the virtual address of the previous instruction of the target instruction and the offset address included in the previous instruction of the target instruction.
  • the width of the lower address may be determined according to the address mapping method, the size of the page table, and the width of the offset address included in the previous instruction of the target instruction.
  • the instruction fetch unit can calculate the lower address of the target instruction in a different manner.
  • the address mapping is a PIPT address mapping or a VIPT address mapping
  • the instruction fetch unit may calculate the target instruction according to the lower address of the previous instruction of the target instruction and the lower address of the offset address included in the previous instruction of the target instruction.
  • the calculation process can refer to the following embodiment shown in FIG. 6.
  • the instruction fetch unit can be based on the lower address of the previous instruction of the target instruction and the bias of the previous instruction of the target instruction.
  • the address of the target address is calculated by shifting the address.
  • Step 502 Store the lower address of the target instruction to the instruction space of the previous instruction of the target instruction.
  • the instruction fetch unit can store the lower address of the target instruction to the instruction space of the previous instruction of the target instruction, so as to directly read the low address of the target instruction from the instruction space of the previous instruction of the target instruction when subsequently determining the virtual address of the target instruction.
  • the address thereby saving the time for calculating the lower address of the target instruction, and reducing the delay of determining the virtual address of the target instruction.
  • Step 503 Write the previous instruction of the target instruction into the first-level instruction cache.
  • the first level instruction cache is a level 1 cache for storing instructions, and the level 1 cache and the main memory (the instruction fetch unit can be a unit in the main memory) have a faster interaction speed. Therefore, the instruction fetch unit can target the instruction.
  • the previous instruction is written to the level one instruction cache so that the previous instruction of the target instruction can be quickly read during the instruction fetching process.
  • the lower address stored in the instruction space of the different instruction is aligned in the 0th bit of the instruction space, and therefore, the lower address stored in the instruction space of the previous instruction of the target instruction is in the The 0th bit of the instruction space of the previous instruction is aligned, that is, the lower address of the target instruction is aligned with the 0th bit of the instruction space of the previous instruction of the target instruction.
  • Step 504 Read the lower address of the target instruction from the instruction space of the previous instruction of the target instruction.
  • the fetching unit can read the lower address of the target instruction from the instruction space of the previous instruction of the target instruction. According to steps 501 to 503, it is not difficult to understand that the lower address of the target instruction is The address of the instruction instruction space of the previous instruction is calculated and stored before the previous instruction of the target instruction is written to the level one instruction cache.
  • Step 505 Determine the remaining address of the target instruction, the sum of the width of the remaining address of the target instruction and the width of the lower address of the target instruction is equal to the width of the virtual address of the previous instruction of the target instruction.
  • the instruction fetch unit After the instruction fetch unit reads the lower address of the target instruction from the instruction space of the previous instruction of the target instruction, the remaining address of the target instruction can be determined, and the instruction fetch unit can use the width of the virtual address of the previous instruction of the target instruction minus the target.
  • the width of the lower address of the instruction gets the width of the remaining address of the target instruction, which in turn determines the remaining address of the target instruction.
  • the primary instruction cache uses the PIPT address mapping or the VIPT address mapping
  • the remaining address includes a median address and a high address
  • the process of the instruction unit determining the remaining address of the target instruction may be implemented by using the following FIG.
  • the remaining address includes a high-order address
  • the process of the instruction unit determining the remaining address of the target instruction may refer to the embodiment shown in FIG. 10 described below.
  • Step 506 Combine the lower address of the target instruction with the remaining address of the target instruction to obtain a virtual address of the target instruction.
  • the instruction fetch unit reads the lower address of the target instruction from the instruction space of the previous instruction of the target instruction, and after determining the remaining address of the target instruction, the lower address of the target instruction can be merged with the remaining address of the target instruction to obtain the target instruction.
  • Virtual address the instruction fetch unit may merge the lower address of the target instruction with the remaining address of the target instruction according to the address bit, and in the same virtual address, the address bits are sequentially raised from right to left. For example, the instruction fetch unit arranges the remaining address of the target instruction at the upper bit of the lower address of the target instruction to obtain the virtual address of the target instruction.
  • the virtual address determining method provided by the embodiment of the present application in the process of determining the virtual address of the target instruction, is that the lower address of the target instruction is read from the instruction space of the previous instruction of the target instruction. There is no need to calculate the lower address of the target instruction, only the remaining address of the target instruction (the remaining address is the address other than the lower address in the virtual address of the target instruction), and then the remaining address of the target instruction is merged with the lower address of the target instruction.
  • the virtual address of the target instruction can be obtained, so that the calculation amount of the virtual address of the target instruction can be reduced, which helps to solve the problem that the delay of determining the virtual address of the target instruction is large, and the processing speed of the processor is slow, and the problem is reduced. Determine the delay of the virtual address of the target instruction and increase the processing speed of the processor.
  • FIG. 6 is a flowchart of another method for determining a virtual address according to an embodiment of the present application.
  • the virtual address determining method may be used to determine a virtual address of a target instruction, and FIG. 6 maps the address to a PIPT.
  • the address mapping or the VIPT address mapping is described as an example.
  • the remaining addresses of the target instruction may include a median address and a high address. Referring to Figure 6, the method includes:
  • Step 601 Determine a virtual address of a previous instruction of the target instruction and an offset address included in a previous instruction of the target instruction.
  • the fetching unit usually fetches an instruction according to the virtual address of the instruction. Therefore, when the fetching unit fetches the previous instruction of the target instruction, the virtual address of the previous instruction of the target instruction is for the fetching unit.
  • the previous instruction of the target instruction includes an offset address, and the instruction fetch unit can decode the previous instruction of the target instruction to obtain the offset address included in the previous instruction of the target instruction.
  • Step 602 Determine, according to the size of the page table, the lower address of the previous instruction of the target instruction from the virtual address of the previous instruction of the target instruction, and determine the target instruction from the offset address included in the previous instruction of the target instruction. The lower address of the offset address contained in the previous instruction.
  • the lower address of the previous instruction of the target instruction is aligned with the lower address of the offset address included in the previous instruction of the target instruction and has the same width.
  • the size of the page table is also the granularity of the page table, and the size of the page table may be represented as 2n, where n is an integer greater than or equal to 1, and the n is the width of the lower address.
  • the instruction fetch unit may determine the lowest n bits of the virtual address of the previous instruction of the target instruction as the lower address of the previous instruction of the target instruction, and determine the lowest n bits of the offset address included in the previous instruction of the target instruction.
  • the lower address of the offset address where the virtual address is a PC address.
  • n is equal to 12
  • the fetch unit can determine the lowest 12 bits of the virtual address of the previous instruction of the target instruction as the lower address of the previous instruction, and the target instruction is The lowest 12 bits of the offset address contained in an instruction are determined as the lower address of the offset address.
  • cur_pc represents the virtual address of the last instruction of the target instruction (since the virtual address of the previous instruction of the target instruction is known when determining the virtual address of the target instruction, the target instruction
  • the virtual address of the previous instruction can be represented by cur_pc)
  • imm represents the offset address contained in the previous instruction of the target instruction
  • cur_pc_lo represents the lower address of the previous instruction of the target instruction
  • imm_lo represents the previous instruction included in the target instruction.
  • cur_pc_lo can be the lowest n bits of cur_pc
  • imm_lo can be the lowest n bits of imm.
  • Step 603 adding the lower address of the previous instruction of the target instruction to the lower address of the offset address included in the previous instruction of the target instruction to obtain the lower address of the target instruction.
  • the instruction fetch unit can add the lower address of the previous instruction of the target instruction to the lower address of the offset address included in the previous instruction of the target instruction to obtain the lower address of the target instruction, and the lower address and the target of the target instruction.
  • the lower address of the previous instruction of the instruction is aligned and the width is equal. For example, when the lower address of the previous instruction of the target instruction is the lowest 12 bits of the virtual address of the previous instruction of the target instruction, and the lower address of the offset address is the lowest 12 bits of the offset address, the low order of the target instruction The address is also 12 bits, and the lower address of the target instruction is aligned with the lower address of the previous instruction of the target instruction.
  • the virtual address is a PC address
  • br_trgt represents a virtual address of the target instruction
  • br_trgt_lo represents a lower address of the target instruction
  • cur_pc_lo represents a lower address of a previous instruction of the target instruction
  • imm_lo represents a previous instruction included in the target instruction.
  • the lower address of the offset address, br_trgt_lo is the lower address of the target instruction obtained by adding cur_pc_lo and imm_lo
  • br_trgt_lo is aligned with cur_pc_lo and has the same width.
  • steps 601 to 603 can be understood as the refinement of step 501 in the embodiment shown in FIG. 5 when the address mapping is a PIPT address mapping or a VIPT address mapping.
  • Step 604 Store the lower address of the target instruction to the instruction space of the previous instruction of the target instruction.
  • the lower address stored in the instruction space of different instructions is aligned in the 0th bit of the instruction space.
  • the instruction fetching unit may first adjust the offset address stored in the instruction space of the previous instruction of the target instruction, so that the offset address is aligned in the 0th bit of the instruction space of the previous instruction, and then Deleting the lower address of the offset address results in an idle instruction space, and stores the lower address of the target instruction into the free instruction space, thereby aligning the lower address stored in the instruction space of the different instructions in the 0th bit of the instruction space.
  • FIG. 7 shows a schematic diagram of an instruction space provided by an embodiment of the present application.
  • an instruction B.cond an instruction CBNZ, an instruction CBZ, an instruction TBNZ, an instruction TBZ, an instruction B, and an instruction.
  • the instruction space of each instruction is the 0th bit to the 31st bit
  • the instruction B.cond, the instruction CBNZ, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B, and the instruction BL all store the lower address, and the different instructions
  • the lower address stored in the instruction space can be the lower address of the instruction target space.
  • the lower address stored in the instruction space of the instruction B.cond, the instruction CBNZ, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B and the instruction BL is aligned in the 0th bit of the instruction space.
  • the previous instruction of the target instruction may be the instruction B.cond in FIG. 7, and the lower address of the target instruction may be br_trgt_lo[11:0] in the instruction space of the instruction B.cond, br_trgt_lo[11 :0] indicates that the lower address of the target instruction has a width of 12 bits, and the lower address of the target instruction starts from the 0th bit of the previous instruction of the target instruction. 4 and FIG.
  • the instruction fetch unit adjusts the offset address stored in the instruction space of the instruction B.cond shown in FIG. 4 from the 5th bit to the 23rd bit to the 0th bit to the 18th bit. And deleting the lowest 12 bits of the offset address to obtain an idle instruction space, the free instruction space is from the 0th bit to the 11th bit of the instruction B.cond, and the fetching unit stores br_trgt_lo[11:0] to the Free instruction space.
  • the case of the instruction CBNZ, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B, and the instruction BL is similar to the instruction B.cond, and will not be described herein.
  • the instruction fetch unit in the process of storing the lower address of the target instruction to the instruction space of the previous instruction of the target instruction, for the remaining address of the offset address, usually only adjusts the remaining address of the offset address in the instruction space.
  • imm_hi[6:0] represents the upper address of the offset address
  • br_trgt_lo[11:0] into the instruction space of the instruction B.cond, the instruction unit is fetched.
  • Step 605 Store the lower carry into the extended instruction space.
  • the lower carry is a carry generated by adding the lower address of the previous instruction of the target instruction to the lower address of the offset address included in the previous instruction of the target instruction, and the lower carry can be 0 or 1, When the lower carry is 0, it can be understood that the carry is not generated in the process of adding the lower address of the previous instruction of the target instruction to the lower address of the offset address included in the previous instruction of the target instruction.
  • the extended instruction space is an instruction space obtained by expanding the instruction space of the previous instruction.
  • the fetching unit may expand the instruction space of the previous instruction of the target instruction to expand the instruction space, and then store the lower carry into the extended instruction space.
  • the instruction instruction unit may expand the instruction space of the instruction B.cond to obtain the instruction space of the 32nd bit, and store the low-order carry to In the instruction space of the 32nd bit of the instruction B.cond.
  • the lower carry is stored in the extended instruction space, and the lower carry can be added to the remaining address of the previous instruction of the target instruction in the process of determining the remaining address of the target instruction, thereby quickly calculating The remaining address of the target instruction.
  • Step 606 Write the previous instruction of the target instruction into the first level instruction cache.
  • the lower address stored in the instruction space of different instructions is aligned in the 0th bit of the instruction space.
  • the instruction B.cond, the instruction CBNZ, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B, and the instruction BL shown in FIG. 7 may all be instructions in the level one instruction cache, the instruction CBNZ, the instruction CBZ, the instruction TBNZ, The lower bits stored in the instruction TBZ, instruction B, and instruction BL are aligned in the 0th bit of the instruction space.
  • the instruction fetching unit may call the write command of the processor to write the previous instruction of the target instruction to the first-level instruction cache. For detailed writing process, reference may be made to related technologies, and details are not described herein again.
  • steps 601 to 606 are generally performed before the instruction fetch unit acquires the target instruction, and the following steps 607 to 614 are processes for determining the virtual address of the target instruction by the fetching unit, and the steps 607 to 614 are performed. This can occur during the fetch unit's acquisition of the target instruction.
  • Step 607 Read the lower address of the target instruction from the instruction space of the previous instruction of the target instruction.
  • the lower address of the target instruction is an address calculated and stored in the instruction space of the previous instruction before the previous instruction of the target instruction is written into the level one instruction cache.
  • the fetching instruction unit may call the read command of the processor to read the lower address of the target instruction from the instruction space of the previous instruction of the target instruction, and the detailed reading process may refer to related technologies, and the embodiment does not stop here. Narration.
  • Step 608 Determine an upper address of an offset address included in a previous instruction of the target instruction from an offset address included in a previous instruction of the target instruction.
  • the offset address included in the previous instruction of the target instruction is composed of the upper address of the offset address and the lower address of the offset address.
  • the instruction fetch unit may determine, in the offset address, an address other than the lower address of the offset address determined in the above step 602 as the upper address of the offset address. For example, if the previous instruction of the target instruction includes an offset address of 19 bits, and the lower address of the offset address included in the previous instruction of the target instruction is the lowest 12 bits of the offset address, the target instruction
  • the upper address of the offset address included in the previous instruction is the address of the 19-bit offset address except the lowest 12 bits, that is, the high bit of the offset address included in the previous instruction of the target instruction.
  • the address is the highest 7 bits of the offset address.
  • the virtual address is a PC address
  • imm represents an offset address included in a previous instruction of the target instruction
  • imm_lo represents a lower address of the offset address included in the previous instruction of the target instruction
  • imm_hi represents the target instruction.
  • the upper address of the offset address contained in an instruction, imm_hi can be an address other than imm_lo in imm.
  • the relationship of imm, imm_hi, and imm_lo can be expressed by the following equation (2):
  • Step 609 Determine a median address of a previous instruction of the target instruction from the virtual address of the previous instruction of the target instruction according to the upper address of the offset address included in the previous instruction of the target instruction.
  • the median address of the previous instruction of the target instruction is aligned with the upper address of the offset address included in the previous instruction of the target instruction and has the same width.
  • the instruction fetching unit may determine, in the virtual address of the previous instruction of the target instruction, a portion aligned with the upper address of the offset address and having the same width as the median address of the previous instruction of the target instruction, and the instruction of the previous instruction of the target instruction The median address is contiguous with the lower address of the previous instruction of the target instruction.
  • the fetching unit may determine the d bit adjacent to the lower address of the previous instruction of the target instruction as the median address of the previous instruction of the target instruction, and d represents the width of the upper address of the offset address.
  • the instruction fetch unit can set the virtual address of the previous instruction of the target instruction with the previous one of the target instruction.
  • the 7 bits adjacent to the lower address of the instruction are determined as the median address of the previous instruction of the target instruction.
  • cur_pc represents the virtual address of the previous instruction of the target instruction
  • cur_pc_lo represents the lower address of the previous instruction of the target instruction
  • cur_pc_mid represents the median address of the previous instruction of the target instruction
  • imm_hi represents The upper address of the offset address contained in the previous instruction of the target instruction
  • cur_pc_mid is the d bit adjacent to cur_pc_lo in cur_pc
  • cur_pc_mid is aligned with imm_hi and the width is equal.
  • Step 610 Read a low carry from the extended instruction space.
  • the extended instruction space is an instruction space obtained by extending the instruction space of the previous instruction, and the extended instruction space is an instruction space in the first-level instruction cache, and the low-level carry is also stored in the extended instruction space in step 605. carry.
  • the instruction fetch unit can call the read command of the processor to read the lower carry from the extended instruction space.
  • Step 611 adding the median address of the previous instruction of the target instruction, the upper address of the offset address included in the previous instruction of the target instruction, and the lower carry, to obtain the median address of the target instruction.
  • the instruction fetch unit may add the median address of the previous instruction of the target instruction, the upper address and the lower carry of the offset address included in the previous instruction of the target instruction, and add the bitwise address to obtain the median address of the target instruction.
  • the median address of the target instruction is aligned with the median address of the previous instruction of the target instruction and the width is equal. For example, when the median address of the previous instruction of the target instruction is the virtual address of the previous instruction of the target instruction, 7 bits adjacent to the lower address of the previous instruction, and the upper address of the offset address is offset When the address is the highest 7 bits, the median address of the target instruction is also 7 bits, and the median address of the target instruction is aligned with the median address of the previous instruction of the target instruction.
  • the virtual address is a PC address
  • br_trgt represents the virtual address of the target instruction
  • br_trgt_mid represents the median address of the target instruction
  • cur_pc_mid represents the median address of the previous instruction of the target instruction
  • imm_hi represents the previous instruction of the target instruction.
  • the upper address of the included offset address, C1 represents the low carry
  • br_trgt_mid is the median address of the target instruction obtained by adding cur_pc_mid, imm_hi and C1
  • br_trgt_mid is aligned with cur_pc_mid and the width is equal.
  • Step 612 Determine a high address of a previous instruction of the target instruction from a virtual address of a previous instruction of the target instruction.
  • the virtual address of the previous instruction of the target instruction is composed of the upper address of the previous instruction of the target instruction, the median address of the previous instruction of the target instruction, and the lower address of the previous instruction of the target instruction.
  • the fetching unit may set the virtual address of the previous instruction of the target instruction, in addition to the lower address of the previous instruction of the target instruction determined by 602 above, and the median address of the previous instruction of the target instruction determined in step 609 above.
  • the address is determined as the upper address of the previous instruction of the target instruction. For example, assuming that the virtual address of the previous instruction of the target instruction is 64 bits, the lower address of the previous instruction of the target instruction is the lowest 12 bits of the virtual address of the previous instruction, and the median address of the previous instruction of the target instruction. For the 7 bits adjacent to the lowest 12 bits of the virtual address of the previous instruction, the upper address of the previous instruction of the target instruction is the highest 45 bits of the virtual address of the previous instruction of the target instruction.
  • cur_pc_lo the lower address of the previous instruction of the target instruction
  • cur_pc_mid the median address of the previous instruction of the target instruction
  • cur_pc_hi The upper address of the previous instruction of the target instruction
  • cur_pc_hi the address in cur_pc except for cur_pc_lo and cur_pc_mid.
  • equation (3) the relationship of cur_pc, cur_pc_lo, cur_pc_mid, and cur_pc_hi can be expressed by the following equation (3):
  • cur_pc ⁇ cur_pc_hi, cur_pc_mid, cur_pc_lo ⁇ .
  • Step 613 Determine a high-order address of the target instruction according to the median carry, the upper address of the previous instruction of the target instruction, and the symbol of the offset address included in the previous instruction of the target instruction.
  • the median carry is a carry generated by adding the median address of the previous instruction of the target instruction, the upper address of the offset address included in the previous instruction of the target instruction, and the lower carry.
  • the median carry can be 0 or 1.
  • the median carry it can be understood as: adding the median address of the previous instruction of the target instruction, the upper address and the lower carry of the offset address included in the previous instruction of the target instruction by bit. There is no carry in the process.
  • the sign of the offset address is the sign of the most significant bit of the offset address, and the sign of the offset address may be 0 or 1.
  • the instruction fetch unit determines, according to the median carry, the upper address of the previous instruction of the target instruction, and the symbol of the offset address included in the previous instruction of the target instruction, the upper address of the target instruction may include: the median carry is 1 and the offset address symbol is 0, the instruction fetch unit determines that the upper address of the target instruction is equal to the upper address of the previous instruction of the target instruction plus one; the middle carry is 0 and the sign of the offset address is 0, or, When the bit carry is 1 and the sign of the offset address is 1, the instruction fetch unit determines that the upper address of the target instruction is equal to the upper address of the previous instruction of the target instruction; when the median carry is 0 and the sign of the offset address is 1, The instruction unit determines that the upper address of the target instruction is equal to the upper address of the previous instruction of the target instruction minus one.
  • the virtual address is a PC address
  • br_trgt represents a virtual address of the target instruction
  • br_trgt_hi represents a high-order address of the target instruction
  • imm[*] represents a symbol of the offset address
  • cur_pc_hi represents a high-order address of a previous instruction of the target instruction
  • C2 represents the median carry
  • steps 608 to 613 can be understood as the refinement of step 505 in the embodiment shown in FIG. 5 when the address mapping is a PIPT address mapping or a VIPT address mapping.
  • Step 614 Combine the lower address of the target instruction, the median address of the target instruction, and the upper address of the target instruction to obtain a virtual address of the target instruction.
  • the instruction fetch unit may combine the lower address of the target instruction, the median address of the target instruction, and the upper address of the target instruction according to the address bit to obtain a virtual address of the target instruction, and in the same virtual address, the address bit Raise from right to left.
  • the instruction fetch unit arranges the median address of the target instruction at the upper bit of the lower address of the target instruction, and arranges the upper address of the target instruction at the upper bit of the median address of the target instruction to obtain the virtual address of the target instruction.
  • br_trgt represents a virtual address of the target instruction
  • br_trgt_lo represents a lower address of the target instruction
  • br_trgt_mid represents a median address of the target instruction
  • br_trgt_hi represents a high-order address of the target instruction
  • br_trgt ⁇ br_trgt_hi, br_trgt_mid, br_trgt_lo ⁇ .
  • the virtual address determining method provided by the embodiment of the present application in the process of determining the virtual address of the target instruction, is that the lower address of the target instruction is read from the instruction space of the previous instruction of the target instruction. There is no need to calculate the lower address of the target instruction, only the remaining address of the target instruction (the remaining address is the address other than the lower address in the virtual address of the target instruction), and then the remaining address of the target instruction is merged with the lower address of the target instruction.
  • the virtual address of the target instruction can be obtained, so that the calculation amount of the virtual address of the target instruction can be reduced, which helps to solve the problem that the delay of determining the virtual address of the target instruction is large, and the processing speed of the processor is slow, and the problem is reduced. Determine the delay of the virtual address of the target instruction and increase the processing speed of the processor.
  • the virtual address determining method provided in the embodiment of the present invention greatly reduces the address width of the virtual address in the process of determining the virtual address, and reduces the delay of determining the virtual address.
  • the solution provided by the embodiment of the present application does not need to increase the pipeline level. To avoid delays due to increased pipeline levels and to avoid processor performance degradation due to exceptions, prediction errors, and cache misses.
  • FIG. 6 The solution provided by the embodiment shown in FIG. 6 is exemplified below with reference to FIG. 8 and FIG. 9.
  • 8 and 9 show the virtual address as the PC address, and FIG. 8 shows the offset address as 0, and FIG. 9 shows the offset address as 1 as an example.
  • cur_pc represents the PC address of the previous instruction of the target instruction
  • cur_pc_lo represents the lower address of the previous instruction of the target instruction
  • cur_pc_mid represents the median address of the previous instruction of the target instruction
  • cur_pc_hi represents the target.
  • the upper address of the previous instruction of the instruction; imm indicates the offset address contained in the previous instruction of the target instruction
  • imm_lo indicates the lower address of the offset address contained in the previous instruction of the target instruction
  • imm_hi indicates the previous instruction of the target instruction.
  • br_trgt represents the PC address of the target instruction
  • br_trgt_lo represents the lower address of the target instruction
  • br_trgt_mid represents the median address of the target instruction
  • br_trgt_hi represents the upper address of the target instruction
  • the imm may be first sign extended according to the symbol of imm so that the width of the imm is equal to the width of the cur_pc.
  • the scheme stores br_trgt_lo to the instruction space of the previous instruction of the target instruction, and stores C1 into the extended instruction space according to the scheme provided in step 605; finally, writes the previous instruction of the target instruction to the first-level instruction cache according to the scheme provided in step 606. .
  • br_trgt_hi cur_pc_hi
  • br_trgt_lo in the process of determining br_trgt, br_trgt_lo can be read from the instruction space of the previous instruction of the target instruction, and br_trgt_hi can be based on C2 and the symbols of the offset address in cur_pc_hi+1, cur_pc_hi, and cur_pc_hi-1.
  • br_trgt_mid needs to be calculated, and br_trgt_lo, br_trgt_mid and br_trgt_hi can be combined to obtain br_trgt, which greatly reduces the delay of determining br_trgt.
  • FIG. 10 is a flowchart of still another method for determining a virtual address according to an embodiment of the present application.
  • the virtual address determining method may be used to determine a virtual address of a target instruction.
  • the mapping is described as an example. In the direct mapping, the remaining address of the target instruction may include a high address.
  • the method includes:
  • Step 1001 Determine a virtual address of a previous instruction of the target instruction and an offset address included in a previous instruction of the target instruction.
  • step 100 For the implementation of the step 1001, reference may be made to the step 601 of the embodiment shown in FIG. 6, which is not described herein again.
  • Step 1002 Determine a lower address of a previous instruction of the target instruction according to an offset address included in a previous instruction of the target instruction.
  • the lower address of the previous instruction of the target instruction is aligned with the offset address included in the previous instruction of the target instruction and has the same width.
  • the instruction fetch unit may be the lowest w of the virtual address of the previous instruction of the target instruction.
  • the bit is determined as the lower address of the previous instruction of the target instruction, wherein the virtual address is a PC address.
  • cur_pc_lo can be the lowest w bit of cur_pc, which is aligned with imm and has the same width.
  • Step 1003 Add the lower address of the previous instruction of the target instruction and the offset address included in the previous instruction of the target instruction to obtain the lower address of the target instruction.
  • the instruction fetch unit may add the lower address of the previous instruction of the target instruction to the offset address included in the previous instruction of the target instruction to obtain the lower address of the target instruction, and the lower address of the target instruction and the target instruction
  • the lower address of an instruction is aligned and the width is equal.
  • the lower address of the previous instruction of the target instruction is the lowest w bit of the virtual address of the previous instruction of the target instruction, and the offset address is w bits
  • the lower address of the target instruction is also w bits.
  • the lower address of the target instruction is aligned with the lower address of the previous instruction of the target instruction.
  • br_trgt represents a virtual address of the target instruction
  • br_trgt_lo represents a lower address of the target instruction
  • imm represents an offset address included in a previous instruction of the target instruction
  • br_trgt_lo is added to the im_cur_pc_lo and the imm
  • the lower address of the resulting target instruction, br_trgt_lo is aligned with cur_pc_lo and has the same width.
  • steps 1001 to 1003 can be understood as the refinement of step 501 in the embodiment shown in FIG. 5 when the address mapping is direct mapping.
  • Step 1004 Store the lower address of the target instruction to the instruction space of the previous instruction of the target instruction.
  • the lower address stored in the instruction space of different instructions is aligned in the 0th bit of the instruction space.
  • the instruction fetching unit may first adjust the offset address stored in the instruction space of the previous instruction of the target instruction, so that the offset address is aligned in the 0th bit of the instruction space of the previous instruction, and then Deleting the lower address of the offset address results in an idle instruction space, and stores the lower address of the target instruction into the free instruction space, thereby aligning the lower address stored in the instruction space of the different instructions in the 0th bit of the instruction space.
  • FIG. 11 shows a schematic diagram of an instruction space provided by an embodiment of the present application.
  • an instruction B.cond an instruction CBNZ, an instruction CBZ, an instruction TBNZ, an instruction TBZ, an instruction B, and an instruction.
  • the instruction space of each instruction is the 0th bit to the 31st bit
  • the instruction B.cond, the instruction CBNZ, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B, and the instruction BL all store the lower address, and the different instructions
  • the lower address stored in the instruction space can be the lower address of the instruction target space.
  • the lower address stored in the instruction space of the instruction B.cond, the instruction CBNZ, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B and the instruction BL is aligned in the 0th bit of the instruction space.
  • the previous instruction of the target instruction may be the instruction CBNZ in FIG. 11, and the lower address of the target instruction may be br_trgt_lo[18:0] in the instruction space of the instruction CBNZ, and br_trgt_lo[18:0] represents
  • the lower address of the target instruction has a width of 19 bits, and the lower address of the target instruction starts from the 0th bit of the previous instruction of the target instruction. 4 and FIG.
  • the instruction fetch unit adjusts the offset address stored in the instruction space of the instruction CBNZ shown in FIG. 4 from the 5th bit to the 23rd bit to the 0th bit to the 18th bit, and deletes The offset address obtains an idle instruction space, which is the space from the 0th bit to the 18th bit of the instruction CBNZ, and the fetching unit stores br_trgt_lo[18:0] into the idle instruction space.
  • the case of the instruction B.cond, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B, and the instruction BL is similar to the case of the instruction CBNZ, and will not be described herein.
  • Step 1005 Determine a high address of a previous instruction of the target instruction from a virtual address of a previous instruction of the target instruction.
  • the virtual address of the previous instruction of the target instruction is composed of the upper address of the previous instruction and the lower address of the previous instruction.
  • the instruction fetch unit may determine, in the virtual address of the previous instruction of the target instruction, an address other than the lower address determined in the above step 1002 as the upper address of the previous instruction of the target instruction. For example, assuming that the virtual address of the previous instruction of the target instruction is 64 bits, and the lower address of the previous instruction of the target instruction is the lowest 19 bits of the virtual address of the previous instruction, the upper address of the previous instruction of the target instruction For the 64 bits, the address other than the lowest 19 bits, that is, the upper address of the previous instruction of the target instruction is the highest 45 bits of the virtual address of the previous instruction.
  • cur_pc_hi is An address other than cur_pc_lo in cur_pc.
  • the relationship of cur_pc, cur_pc_lo, and cur_pc_hi can be expressed by the following equation (5):
  • cur_pc ⁇ cur_pc_hi, cur_pc_lo ⁇ .
  • Step 1006 Determine the upper address of the target instruction according to the lower carry, the upper address of the previous instruction of the target instruction, and the symbol of the offset address included in the previous instruction of the target instruction.
  • the lower carry is a carry generated by adding the lower address of the previous instruction of the target instruction and the offset address included in the previous instruction of the target instruction, and the lower carry can be 0 or 1, when the low bit is When the carry is 0, it can be understood that there is no carry in the process of adding the lower address of the previous instruction of the target instruction to the offset address included in the previous instruction of the target instruction.
  • the sign of the offset address is the sign of the most significant bit of the offset address, and the sign of the offset address may be 0 or 1.
  • the instruction fetch unit determines, according to the lower carry, the upper address of the previous instruction of the target instruction, and the symbol of the offset address included in the previous instruction of the target instruction, determining that the upper address of the target instruction may include: when the low carry is 1 And when the sign of the offset address is 0, the instruction fetch unit determines that the upper address of the target instruction is equal to the upper address of the previous instruction of the target instruction plus one; when the lower carry is 0 and the sign of the offset address is 0, or the low carry
  • the instruction fetch unit determines that the upper address of the target instruction is equal to the upper address of the previous instruction of the target instruction; when the lower carry is 0 and the sign of the offset address is 1, the instruction fetch unit It is determined that the upper address of the target instruction is equal to the upper address of the previous instruction of the target instruction minus one.
  • the virtual address is a PC address
  • br_trgt represents a virtual address of the target instruction
  • br_trgt_hi represents a high-order address of the target instruction
  • imm[*] represents a symbol of the offset address
  • cur_pc_hi represents a high-order address of a previous instruction of the target instruction
  • C1 represents a low carry
  • Step 1007 Generate an address indication symbol, and the address indication symbol indicates a high address of the target instruction.
  • the fetching unit may generate an address indication symbol indicating the upper address of the target instruction.
  • the address indication symbol may be represented by br_trgt_hi_sel, and the address indication symbol may be 2 bits.
  • the address indication symbol may be 00, 01 or 10, 00 indicating that the upper address of the target instruction is equal to cur_pc_hi, 01 indicates the target instruction.
  • the upper address is equal to cur_pc_hi+1, and 10 indicates that the upper address of the target instruction is equal to cur_pc_hi-1.
  • the address indication symbol provided by the embodiment of the present application is merely exemplary. In an actual application, the address indication symbol may be embodied in other forms. The embodiment of the present application does not limit the address indication symbol.
  • Step 1008 Store the address indication symbol into the extended instruction space.
  • the instruction space of the previous instruction of the target instruction may be extended to expand the instruction space, and then the address indication symbol is stored in the extended instruction space, so as to facilitate the process of subsequently determining the virtual address of the target instruction.
  • the address indication symbol is read from the extended instruction space, and the upper address of the target instruction is determined according to the address indication symbol, the delay of calculating the upper address of the target instruction is saved, and the delay of determining the virtual address of the target instruction is reduced.
  • the instruction instruction unit may expand the instruction space of the instruction CBNZ to obtain the instruction space of the 32nd bit and the 33rd bit, and store the address indication symbol. Up to the instruction space of the 32nd and 33rd bits of the instruction CBNZ.
  • Step 1009 Write the previous instruction of the target instruction into the level one instruction cache.
  • step 1009 For the implementation process of the step 1009, reference may be made to the step 606 of the embodiment shown in FIG. 6, which is not described herein again.
  • steps 1001 to 1009 are generally performed before the instruction fetch unit acquires the target instruction, and the following steps 1010 to 1013 are processes for determining the virtual address of the target instruction for the fetching unit, and the step 1010 to step 1013 are performed. This can occur during the fetch unit's acquisition of the target instruction.
  • Step 1010 Read the lower address of the target instruction from the instruction space of the previous instruction of the target instruction.
  • step 1010 For the implementation of the step 1010, reference may be made to the step 607 of the embodiment shown in FIG. 6, which is not described herein again.
  • Step 1011 Read an address indication symbol from the extended instruction space.
  • the extended instruction space is also the extended instruction space in step 1008.
  • the instruction fetch unit can call the read command of the processor to read the address indication symbol from the extended instruction space.
  • Step 1012 Determine a high address of the target instruction according to the address indication symbol.
  • the instruction fetch unit may determine the upper address of the target instruction based on the indication of the address indication symbol.
  • the instruction fetch unit determines that the upper address of the target instruction is equal to cur_pc_hi, and when the address indication symbol is 01, the instruction fetch unit determines that the upper address of the target instruction is equal to cur_pc_hi+1, when the address indication symbol When it is 10, the instruction fetch unit determines that the upper address of the target instruction is equal to cur_pc_hi-1.
  • steps 1011 to 1012 can be understood as the refinement of step 505 in the embodiment shown in FIG. 5 when the address mapping is direct mapping.
  • Step 1013 Combine the lower address of the target instruction with the upper address of the target instruction to obtain a virtual address of the target instruction.
  • the instruction fetch unit may combine the lower address of the target instruction with the upper address of the target instruction according to the address bit to obtain a virtual address of the target instruction, and in the same virtual address, the address bit is sequentially raised from right to left. .
  • the instruction fetch unit arranges the upper address of the target instruction at the upper bit of the lower address of the target instruction to obtain the virtual address of the target instruction.
  • br_trgt represents a virtual address of the target instruction
  • br_trgt_lo represents a lower address of the target instruction
  • br_trgt_hi represents a higher address of the target instruction
  • br_trgt ⁇ br_trgt_hi, br_trgt_lo ⁇ .
  • the virtual address determining method provided by the embodiment of the present application in the process of determining the virtual address of the target instruction, is that the lower address of the target instruction is read from the instruction space of the previous instruction of the target instruction. There is no need to calculate the lower address of the target instruction, only the remaining address of the target instruction (the remaining address is the address other than the lower address in the virtual address of the target instruction), and then the remaining address of the target instruction is merged with the lower address of the target instruction.
  • the virtual address of the target instruction can be obtained, so that the calculation amount of the virtual address of the target instruction can be reduced, which helps to solve the problem that the delay of determining the virtual address of the target instruction is large, and the processing speed of the processor is slow, and the problem is reduced. Determine the delay of the virtual address of the target instruction and increase the processing speed of the processor.
  • the virtual address determining method provided by the embodiment of the present invention greatly reduces the address width of the virtual address in the process of determining the virtual address, and reduces the delay of determining the virtual address.
  • the solution provided by the embodiment of the present application does not need to increase the pipeline level. Avoid delays due to increased pipeline levels and avoid processor performance degradation due to exceptions, prediction errors, and cache misses.
  • FIG. 10 The solution provided by the embodiment shown in FIG. 10 is exemplified below with reference to FIG. 12 and FIG. 12 and FIG. 13 show the virtual address as the PC address, and FIG. 12 shows the offset address as 0.
  • FIG. 13 illustrates the offset address as 1 as an example.
  • cur_pc represents the PC address of the previous instruction of the target instruction
  • cur_pc_lo represents the lower address of the previous instruction of the target instruction
  • cur_pc_hi represents the upper address of the previous instruction of the target instruction
  • imm represents the target instruction.
  • the offset address included in the previous instruction; br_trgt indicates the PC address of the target instruction
  • br_trgt_lo indicates the lower address of the target instruction
  • br_trgt_hi indicates the upper address of the target instruction
  • C1 indicates the lower carry, and the scheme of the embodiment shown in FIG. 10 is executed. Before, you can first extend the imm according to the symbol of imm, so that the width of imm is equal to the width of cur_pc.
  • cur_pc is split into cur_pc_lo and cur_pc_hi, and cur_pc_lo is aligned with imm. This process may correspond to steps 1001 and 1002 of the embodiment shown in FIG.
  • br_trgt_lo is read from the instruction space of the previous instruction of the target instruction according to the scheme provided in step 1010; then, the extended instruction is obtained according to the scheme provided in step 1011.
  • the address indication symbol is read in space, and br_trgt_hi is determined according to the scheme provided in step 1012.
  • br_trgt_lo in the process of determining br_trgt, can be read from the instruction space of the previous instruction of the target instruction, and br_trgt_hi can be determined from the address indication symbol read from the instruction space of the previous instruction of the target instruction. Combining br_trgt_lo and br_trgt_hi to obtain br_trgt, so that in the process of determining br_trgt, no addition operation is required, and the delay for determining br_trgt is greatly reduced.
  • FIG. 14 is a block diagram of a virtual address determining apparatus 1400 provided by an embodiment of the present application.
  • the virtual address determining apparatus 1400 may be an instruction fetching unit in a processor.
  • the virtual address determining apparatus 1400 includes:
  • the first reading module 1401 is configured to read the lower address of the target instruction from the instruction space of the previous instruction of the target instruction to be acquired, and the lower address of the target instruction is calculated before writing the previous instruction to the first instruction cache. And storing the address in the instruction space of the previous instruction;
  • a first determining module 1402 configured to determine a remaining address of the target instruction, a sum of a width of a remaining address of the target instruction and a width of a lower address of the target instruction is equal to a width of a virtual address of the previous instruction;
  • the merging module 1403 is configured to combine the lower address of the target instruction with the remaining address of the target instruction to obtain a virtual address of the target instruction.
  • the virtual address determining apparatus in the process of determining the virtual address of the target instruction, is that the lower address of the target instruction is read from the instruction space of the previous instruction of the target instruction. There is no need to calculate the lower address of the target instruction, only the remaining address of the target instruction (the address other than the lower address in the virtual address of the target instruction) is calculated, and then the remaining address of the target instruction is merged with the lower address of the target instruction to obtain the target.
  • the virtual address of the instruction so that the calculation amount of the virtual address of the target instruction can be reduced, which helps to solve the problem that the delay of determining the virtual address of the target instruction is large, the processing speed of the processor is slow, and the determination target instruction is reduced.
  • the latency of the virtual address increases the processing speed of the processor.
  • FIG. 15 is a block diagram of another virtual address determining apparatus 1400 provided by an embodiment of the present application.
  • the virtual address determining apparatus 1400 further includes:
  • a calculation module 1404 configured to calculate a lower address of the target instruction
  • the first storage module 1405 is configured to store the lower address of the target instruction to the instruction space of the previous instruction.
  • calculation module 1404 is configured to:
  • the lower address of the previous instruction is determined from the virtual address of the previous instruction, and the lower address of the offset address is determined from the offset address, and the lower address of the previous instruction is aligned with the lower address of the offset address.
  • the width is equal;
  • the lower address of the previous instruction is added to the lower address of the offset address to obtain the lower address of the target instruction, and the lower address of the target instruction is aligned with the lower address of the previous instruction and the width is equal.
  • the virtual address determining apparatus 1400 further includes:
  • the second storage module 1406 is configured to store the lower carry into the extended instruction space, and the lower carry is a carry generated by adding the lower address of the previous instruction and the lower address of the offset address, and the extended instruction space is the instruction for the previous instruction.
  • the instruction space obtained by expanding the space.
  • the remaining address includes a median address and a high-order address.
  • FIG. 16 is a block diagram of a first determining module 1402 according to an embodiment of the present application.
  • the first determining module 1402 includes:
  • the first determining sub-module 14021 is configured to determine, from the offset address, a high-order address of the offset address, where the offset address is composed of a high-order address of the offset address and a low-order address of the offset address;
  • the second determining sub-module 14022 is configured to determine, according to the upper address of the offset address, the median address of the previous instruction from the virtual address of the previous instruction, where the median address of the previous instruction is aligned with the upper address of the offset address and Equal in width;
  • a reading submodule 14023 configured to read the lower carry from the extended instruction space
  • the adding sub-module 14024 is configured to add the median address of the previous instruction, the upper address of the offset address, and the lower carry, to obtain a median address of the target instruction;
  • the third determining sub-module 14025 is configured to determine a high-order address of the previous instruction from the virtual address of the previous instruction, where the virtual address of the previous instruction is the upper address of the previous instruction, the median address of the previous instruction, and the previous instruction. Composition of the lower address;
  • the fourth determining sub-module 14026 is configured to determine a high-order address of the target instruction according to a median carry, a high-order address of the previous instruction, and a symbol of the offset address, and the median carry is a median address and an offset address of the previous instruction. The higher address and the lower carry add up the resulting carry.
  • the fourth determining submodule 10426 is configured to:
  • calculation module 1404 is configured to:
  • the lower address of the previous instruction is aligned with the offset address and the width is equal;
  • the lower address of the previous instruction is added to the offset address to obtain the lower address of the target instruction, and the lower address of the target instruction is aligned with the lower address of the previous instruction and the width is equal.
  • the remaining address includes a high-order address.
  • FIG. 17 shows a block diagram of another virtual address determining apparatus 1400 provided by an embodiment of the present application. Referring to FIG. 17, on the basis of FIG. 15, the virtual address is used.
  • the determining device 1400 further includes:
  • a second determining module 1407 configured to determine a high-order address of the previous instruction from a virtual address of the previous instruction, where the virtual address of the previous instruction is composed of a high-order address of the previous instruction and a lower-order address of the previous instruction;
  • the third determining module 1408 is configured to determine, according to the lower carry, the upper address of the previous instruction, and the sign of the offset address, the upper address of the target instruction, and the lower carry is generated by adding the lower address and the offset address of the previous instruction. carry;
  • a generating module 1409 configured to generate an address indication symbol, where the address indication symbol indicates a high-order address of the target instruction
  • the third storage module 1410 is configured to store the address indication symbol into the extended instruction space, where the extended instruction space is an instruction space obtained by expanding the instruction space of the previous instruction.
  • the first determining module 1402 is configured to:
  • the upper address of the target instruction is determined according to the address indication symbol.
  • the third determining module 1408 is configured to:
  • the lower address stored in the instruction space of the different instructions is aligned in the 0th bit of the instruction space.
  • the virtual address determining apparatus in the process of determining the virtual address of the target instruction, is that the lower address of the target instruction is read from the instruction space of the previous instruction of the target instruction. There is no need to calculate the lower address of the target instruction, only the remaining address of the target instruction (the address other than the lower address in the virtual address of the target instruction) is calculated, and then the remaining address of the target instruction is merged with the lower address of the target instruction to obtain the target.
  • the virtual address of the instruction so that the calculation amount of the virtual address of the target instruction can be reduced, which helps to solve the problem that the delay of determining the virtual address of the target instruction is large, the processing speed of the processor is slow, and the determination target instruction is reduced.
  • the latency of the virtual address increases the processing speed of the processor.
  • the virtual address determining apparatus when determining the virtual address of the target instruction, only exemplifies the division of each functional unit. In actual applications, the function may be assigned differently according to needs.
  • the functional unit is completed, that is, the internal structure of the device is divided into different functional units to complete all or part of the functions described above.
  • the virtual address determining apparatus and the virtual address determining method are provided in the same embodiment. For details, refer to the method embodiment, and details are not described herein.
  • the embodiment of the present application further provides a processor including the virtual address determining apparatus 1400 shown in FIG. 14, FIG. 15, or FIG.
  • the embodiment of the present application further provides a computer readable storage medium, where the instructions are stored, when the instruction is run on a processor of the computer, causing the processor to execute the above FIG. 5, FIG. 6 or The virtual address determination method described in 10.
  • the embodiment of the present application further provides a computer program product comprising instructions for causing a processor to execute the virtual address determining method described in FIG. 5, FIG. 6, or FIG. 10 above when the computer program product runs on a processor of the computer.
  • the embodiment of the present application further provides a processing apparatus, where the processing apparatus includes at least one circuit for performing the virtual address determining method described in FIG. 5, FIG. 6, or FIG.
  • the embodiment of the present application further provides a chip, which includes programmable logic circuits and/or program instructions, and is used to implement the virtual address determining method described in FIG. 5, FIG. 6, or FIG.
  • a person skilled in the art may understand that all or part of the steps of implementing the above embodiments may be completed by hardware, or may be instructed by a program to execute related hardware, and the program may be stored in a computer readable storage medium.
  • the storage medium mentioned may be a read only memory, a magnetic disk or an optical disk or the like.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System Of A Hierarchy Structure (AREA)
  • Executing Machine-Instructions (AREA)
  • Advance Control (AREA)

Abstract

A virtual address determining method and apparatus, a processor, and a storage medium, relating to the technical field of processors. The method comprises: reading, from an instruction space of the previous instruction of a target instruction to be obtained, a low address of the target instruction, the low address of the target instruction being an address calculated before the previous instruction is written to a first-stage instruction cache and stored in the instruction space of the previous instruction; determining the remaining address of the target instruction, the sum of the width of the remaining address of the target instruction and the width of the low address of the target instruction being equal to the width of the virtual address of the previous instruction (505); and combining the low address of the target instruction with the remaining address of the target instruction to obtain the virtual address of the target instruction (506). The method solves the problem of long delay in determining virtual addresses and low processing speed of processors, reduces the delay in determining virtual addresses, and improves the processing speeds of the processors.

Description

虚拟地址确定方法及装置、处理器、存储介质Method and device for determining virtual address, processor, and storage medium
本申请要求于2018年01月03日提交中国国家知识产权局、申请号为201810005947.X、发明名称为“虚拟地址确定方法及装置、处理器、存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims priority from the Chinese Patent Application of the State Intellectual Property Office of China, Application No. 201810005947.X, and the invention titled "Virtual Address Determination Method and Apparatus, Processor, Storage Medium" on January 3, 2018, The entire contents are incorporated herein by reference.
技术领域Technical field
本申请涉及处理器技术领域,特别涉及一种虚拟地址确定方法及装置、处理器、存储介质。The present application relates to the field of processor technologies, and in particular, to a virtual address determining method and apparatus, a processor, and a storage medium.
背景技术Background technique
中央处理器的一个典型的运作流水线为:取指令(即,获取指令)、解码指令、发射指令、执行指令、访问记忆体和提交结果,取指令、解码指令、发射指令、执行指令、访问记忆体和提交结果中的任一项称为一个流水线级。中央处理器包括与每个流水线级对应的单元,每个单元用于执行相应的流水线级的操作,例如,中央处理器包括取指令单元,由取指令单元执行取指令的操作,需要获取的指令通常可以包括分支指令和非分支指令两种类型,且分支指令可以包括直接分支指令和非直接分支指令。在取指令的过程中,取指令单元首先需要确定待获取的目标指令的虚拟地址,然后基于该虚拟地址进行目标指令的获取。其中,虚拟地址可以为程序计数器(program counter,PC)地址。A typical operational pipeline of the central processing unit is: fetching instructions (ie, fetching instructions), decoding instructions, transmitting instructions, executing instructions, accessing memory and submitting results, fetching instructions, decoding instructions, transmitting instructions, executing instructions, and accessing memory. Any of the body and the submitted results is called a pipeline stage. The central processing unit includes units corresponding to each pipeline stage, each unit is configured to perform a corresponding pipeline stage operation, for example, the central processing unit includes an instruction fetch unit, and the instruction fetch unit performs an instruction fetch operation, and the fetched instruction is required. There may be two types of branch instructions and non-branch instructions, and branch instructions may include direct branch instructions and non-direct branch instructions. In the process of fetching instructions, the fetching unit first needs to determine the virtual address of the target instruction to be acquired, and then acquires the target instruction based on the virtual address. The virtual address may be a program counter (PC) address.
相关技术中,取指令单元根据目标指令的上一指令的虚拟地址确定目标指令的虚拟地址,然后根据目标指令的虚拟地址和地址映射确定目标指令的物理地址,最后根据目标指令的物理地址从存储空间(例如一级指令缓存)中取出目标指令。其中,目标指令的上一指令为取指令单元已经取出的指令,当该上一指令为直接分支指令时,该上一指令中包含偏移地址,取指令单元根据目标指令的上一指令的虚拟地址确定目标指令的虚拟地址可以包括:取指令单元对该上一指令进行解码得到该上一指令所包含的偏移地址,然后对该偏移地址进行符号扩展(sign extend)得到扩展后的偏移地址,该扩展后的偏移地址与该上一指令的虚拟地址对齐且宽度相等,最后取指令单元将扩展后的偏移地址与该上一指令的虚拟地址相加得到目标指令的虚拟地址。In the related art, the instruction fetch unit determines the virtual address of the target instruction according to the virtual address of the previous instruction of the target instruction, and then determines the physical address of the target instruction according to the virtual address and address mapping of the target instruction, and finally stores the physical address according to the target instruction. The target instruction is fetched from the space (for example, the level one instruction cache). The previous instruction of the target instruction is an instruction that the instruction instruction unit has taken out. When the previous instruction is a direct branch instruction, the previous instruction includes an offset address, and the instruction unit is virtualized according to the previous instruction of the target instruction. The address determining the virtual address of the target instruction may include: the instruction fetch unit decodes the previous instruction to obtain an offset address included in the previous instruction, and then performs sign extend on the offset address to obtain an extended bias. The address is shifted, the extended offset address is aligned with the virtual address of the previous instruction, and the width is equal. Finally, the instruction fetch unit adds the extended offset address to the virtual address of the previous instruction to obtain the virtual address of the target instruction. .
在实现本申请的过程中,发明人发现相关技术至少存在以下问题:In the process of implementing the present application, the inventors found that the related art has at least the following problems:
随着处理器的地址宽度的增加,将偏移地址与虚拟地址相加的计算量越来越大,因此,确定目标指令的虚拟地址的时延较大,中央处理器的处理速度较慢。As the address width of the processor increases, the amount of calculation for adding the offset address to the virtual address is larger and larger. Therefore, the delay of determining the virtual address of the target instruction is large, and the processing speed of the central processing unit is slow.
发明内容Summary of the invention
本申请提供了一种虚拟地址确定方法及装置、处理器、存储介质,有助于解决确定虚拟地址的时延较大,处理器的处理速度较慢的问题。本申请的技术方案如下:The present application provides a virtual address determining method and apparatus, a processor, and a storage medium, which are helpful in solving the problem that the delay of determining a virtual address is large and the processing speed of the processor is slow. The technical solution of the present application is as follows:
第一方面,提供了一种虚拟地址确定方法,该方法包括:In a first aspect, a virtual address determining method is provided, the method comprising:
从待获取的目标指令的上一指令的指令空间中读取目标指令的低位地址,目标指令的低位地址为将该上一指令写入一级指令缓存之前计算得到并存储在该上一指令的指令空间中的地址;Reading the lower address of the target instruction from the instruction space of the previous instruction of the target instruction to be acquired, and the lower address of the target instruction is calculated and stored in the previous instruction before the previous instruction is written into the first instruction cache. The address in the instruction space;
确定目标指令的剩余地址,目标指令的剩余地址的宽度与目标指令的低位地址的宽度之和等于该上一指令的虚拟地址的宽度;Determining the remaining address of the target instruction, the sum of the width of the remaining address of the target instruction and the width of the lower address of the target instruction being equal to the width of the virtual address of the previous instruction;
将目标指令的低位地址与目标指令的剩余地址合并,得到目标指令的虚拟地址。其中,一级指令缓存中,不同指令的指令空间中存储的低位地址在指令空间的第0比特对齐。The lower address of the target instruction is combined with the remaining address of the target instruction to obtain the virtual address of the target instruction. Among them, in the first-level instruction cache, the lower address stored in the instruction space of different instructions is aligned in the 0th bit of the instruction space.
本申请提供的方案,由于在确定目标指令的虚拟地址的过程中,无需计算目标指令的低位地址,只需要计算目标指令的剩余地址(剩余地址为目标指令的虚拟地址中除低位地址之外的地址),然后将目标指令的剩余地址与目标指令的低位地址合并就可以得到目标指令的虚拟地址,因此可以减小确定目标指令的虚拟地址的时延,提高处理器的处理速度。The solution provided by the present application, since it is not necessary to calculate the lower address of the target instruction in determining the virtual address of the target instruction, only the remaining address of the target instruction needs to be calculated (the remaining address is the virtual address of the target instruction except the lower address) The address), and then the remaining address of the target instruction is combined with the lower address of the target instruction to obtain the virtual address of the target instruction, so that the delay of determining the virtual address of the target instruction can be reduced, and the processing speed of the processor can be improved.
可选地,在从待获取的目标指令的上一指令的指令空间中读取目标指令的低位地址之前,该方法还包括:Optionally, before the lower address of the target instruction is read from the instruction space of the previous instruction of the target instruction to be acquired, the method further includes:
计算目标指令的低位地址;Calculate the lower address of the target instruction;
将目标指令的低位地址存储至该上一指令的指令空间。The lower address of the target instruction is stored into the instruction space of the previous instruction.
本申请提供的方案,通过预计算目标指令的低位地址,并将目标指令的低位地址存储至目标指令的上一指令的指令空间,可以便于在确定目标指令的虚拟地址的过程中,从该上一指令的指令空间读取目标指令的低位地址。The solution provided by the present application can facilitate the determination of the virtual address of the target instruction by pre-calculating the lower address of the target instruction and storing the lower address of the target instruction to the instruction space of the previous instruction of the target instruction. The instruction space of an instruction reads the lower address of the target instruction.
在第一种可能的实现方案中,计算目标指令的低位地址,包括:In a first possible implementation, the lower address of the target instruction is calculated, including:
确定该上一指令的虚拟地址和该上一指令所包含的偏移地址;Determining a virtual address of the previous instruction and an offset address included in the previous instruction;
根据页表的大小,从该上一指令的虚拟地址中确定该上一指令的低位地址,并从偏移地址中确定该偏移地址的低位地址,该上一指令的低位地址与该偏移地址的低位地址对齐且宽度相等;Determining, according to the size of the page table, the lower address of the previous instruction from the virtual address of the previous instruction, and determining the lower address of the offset address from the offset address, the lower address of the previous instruction and the offset The lower address of the address is aligned and the width is equal;
将该上一指令的低位地址与该偏移地址的低位地址相加,得到目标指令的低位地址,目标指令的低位地址与该上一指令的低位地址对齐且宽度相等。The lower address of the previous instruction is added to the lower address of the offset address to obtain the lower address of the target instruction, and the lower address of the target instruction is aligned with the lower address of the previous instruction and the width is equal.
本申请提供的方案,通过将目标指令的上一指令的低位地址与目标指令的所包含的偏移地址的低位地址相加产生目标指令的低位地址,便于目标指令的低位地址的确定。The solution provided by the present application generates the lower address of the target instruction by adding the lower address of the previous instruction of the target instruction to the lower address of the included offset address of the target instruction, thereby facilitating the determination of the lower address of the target instruction.
可选地,在第一种可能的实现方案中,在将该上一指令的低位地址与该偏移地址的低位地址相加之后,该方法还包括:将低位进位存储至扩展指令空间,低位进位为将该上一指令的低位地址与该偏移地址的低位地址相加产生的进位,扩展指令空间为对该上一指令的指令空间进行扩展得到的指令空间。Optionally, in a first possible implementation, after adding the lower address of the previous instruction to the lower address of the offset address, the method further includes: storing the low carry into the extended instruction space, the low bit The carry is a carry generated by adding the lower address of the previous instruction to the lower address of the offset address, and the extended instruction space is an instruction space obtained by expanding the instruction space of the previous instruction.
本申请提供的方案,通过将低位进位存储至扩展指令空间,可以便于在确定目标指令的虚拟地址的过程中,从该扩展指令空间读取低位进位。The solution provided by the present application can facilitate reading the lower carry from the extended instruction space in the process of determining the virtual address of the target instruction by storing the lower carry into the extended instruction space.
可选地,在第一种可能的实现方案中,剩余地址包括中位地址和高位地址,确定目标指令的剩余地址,包括:Optionally, in the first possible implementation, the remaining address includes a median address and a high address, and determining a remaining address of the target instruction includes:
从偏移地址中确定偏移地址的高位地址,偏移地址由偏移地址的高位地址和偏移地址的低位地址组成;Determining the upper address of the offset address from the offset address, the offset address is composed of the upper address of the offset address and the lower address of the offset address;
根据偏移地址的高位地址,从该上一指令的虚拟地址中确定该上一指令的中位地址,上该一指令的中位地址与偏移地址的高位地址对齐且宽度相等;Determining, according to the upper address of the offset address, the median address of the previous instruction from the virtual address of the previous instruction, where the median address of the instruction is aligned with the upper address of the offset address and the width is equal;
从扩展指令空间中读取低位进位;Reading the lower carry from the extended instruction space;
将该上一指令的中位地址、偏移地址的高位地址和低位进位相加,得到目标指令的中位地址;Adding the median address of the previous instruction, the upper address of the offset address, and the lower carry to obtain the median address of the target instruction;
从该上一指令的虚拟地址中确定该上一指令的高位地址,该上一指令的虚拟地址由该上一指令的高位地址、该上一指令的中位地址和该上一指令的低位地址组成;Determining, from a virtual address of the previous instruction, a higher address of the previous instruction, the virtual address of the previous instruction being a higher address of the previous instruction, a median address of the previous instruction, and a lower address of the previous instruction composition;
根据中位进位、该上一指令的高位地址和偏移地址的符号,确定目标指令的高位地址,中位进位为将该上一指令的中位地址、偏移地址的高位地址和低位进位相加产生的进位。The upper address of the target instruction is determined according to the median carry, the upper address of the previous instruction, and the sign of the offset address. The median carry is the median address of the previous instruction, the upper address of the offset address, and the lower carry phase. Add the resulting carry.
可选地,在第一种可能的实现方案中,根据中位进位、该上一指令的高位地址和偏移地址的符号,确定目标指令的高位地址,包括:Optionally, in the first possible implementation, determining a high-order address of the target instruction according to a median carry, a high-order address of the previous instruction, and a symbol of the offset address, including:
当中位进位为1且偏移地址的符号为0时,确定目标指令的高位地址等于该上一指令的高位地址加1;When the median carry is 1 and the sign of the offset address is 0, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction plus one;
当中位进位为0且偏移地址的符号为0,或者,中位进位为1且偏移地址的符号为1时,确定目标指令的高位地址等于该上一指令的高位地址;When the median carry is 0 and the sign of the offset address is 0, or the median carry is 1 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction;
当中位进位为0且偏移地址的符号为1时,确定目标指令的高位地址等于该上一指令的高位地址减1。When the median carry is 0 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction minus one.
在第二种可能的实现方案中,计算目标指令的低位地址,包括:In a second possible implementation, the lower address of the target instruction is calculated, including:
确定该上一指令的虚拟地址和该上一指令所包含的偏移地址;Determining a virtual address of the previous instruction and an offset address included in the previous instruction;
根据偏移地址确定该上一指令的低位地址,该上一指令的低位地址与偏移地址对齐且宽度相等;Determining, according to the offset address, a lower address of the previous instruction, the lower address of the previous instruction being aligned with the offset address and having the same width;
将该上一指令的低位地址与偏移地址相加,得到目标指令的低位地址,目标指令的低位地址与该上一指令的低位地址对齐且宽度相等。The lower address of the previous instruction is added to the offset address to obtain the lower address of the target instruction, and the lower address of the target instruction is aligned with the lower address of the previous instruction and the width is equal.
本申请提供的方案,通过将目标指令的上一指令的低位地址与偏移地址相加产生目标指令的低位地址,便于目标指令的低位地址的确定。The solution provided by the present application generates the lower address of the target instruction by adding the lower address of the previous instruction of the target instruction to the offset address, thereby facilitating the determination of the lower address of the target instruction.
可选地,在第二种可能的实现方案中,剩余地址包括高位地址,在将该上一指令的低位地址与偏移地址相加之后,该方法还包括:Optionally, in a second possible implementation, the remaining address includes a high-order address, and after adding the low-order address of the previous instruction to the offset address, the method further includes:
从该上一指令的虚拟地址中确定该上一指令的高位地址,该上一指令的虚拟地址由该上一指令的高位地址和该上一指令的低位地址组成;Determining, from a virtual address of the previous instruction, a high-order address of the previous instruction, where a virtual address of the previous instruction is composed of a high-order address of the previous instruction and a lower-order address of the previous instruction;
根据低位进位、该上一指令的高位地址和偏移地址的符号,确定目标指令的高位地址,低位进位为将该上一指令的低位地址和偏移地址相加产生的进位;Determining the upper address of the target instruction according to the lower carry, the upper address of the previous instruction, and the sign of the offset address, and the lower carry is a carry generated by adding the lower address and the offset address of the previous instruction;
生成地址指示符号,地址指示符号指示目标指令的高位地址;Generating an address indicator, the address indicator indicating a high address of the target instruction;
将地址指示符号存储至扩展指令空间,该扩展指令空间为对该上一指令的指令空间进行扩展得到的指令空间。The address indication symbol is stored in an extended instruction space, which is an instruction space obtained by expanding the instruction space of the previous instruction.
本申请提供的方案,通过预确定目标指令的高位地址并生成地址指示符号,将地址指示符号存储至扩展指令空间,可以便于在确定目标指令的虚拟地址的过程中,从扩展指令空间读取地址指示符号,并根据地址指示符号确定目标指令的高位地址。The solution provided by the present application can store the address indication symbol into the extended instruction space by predetermining the upper address of the target instruction and generating the address indication symbol, which can facilitate reading the address from the extended instruction space in the process of determining the virtual address of the target instruction. An indicator and determine the upper address of the target instruction based on the address indicator.
可选地,在第二种可能的实现方案中,确定目标指令的剩余地址,包括:Optionally, in the second possible implementation, determining a remaining address of the target instruction includes:
从扩展指令空间中读取地址指示符号;Reading the address indicator from the extended instruction space;
根据地址指示符号确定目标指令的高位地址。The upper address of the target instruction is determined according to the address indication symbol.
本申请提供的方案,通过根据地址指示符号确定目标指令的高位地址,可以节省计算目标指令的高位地址的时延,提高处理器的处理速度。The solution provided by the present application can save the delay of calculating the upper address of the target instruction and improve the processing speed of the processor by determining the upper address of the target instruction according to the address indication symbol.
可选地,在第二种可能的实现方案中,根据低位进位、该上一指令的高位地址和偏移地址的符号,确定目标指令的高位地址,包括:Optionally, in a second possible implementation, determining a high-order address of the target instruction according to a low-order carry, a high-order address of the previous instruction, and a symbol of the offset address, including:
当低位进位为1且偏移地址的符号为0时,确定目标指令的高位地址等于该上一指令的高位地址加1;When the lower carry is 1 and the sign of the offset address is 0, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction plus one;
当低位进位为0且偏移地址的符号为0,或者,低位进位为1且偏移地址的符号为1时,确定目标指令的高位地址等于该上一指令的高位地址;When the lower carry is 0 and the sign of the offset address is 0, or the lower carry is 1 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction;
当低位进位为0且偏移地址的符号为1时,确定目标指令的高位地址等于该上一指令的高位地址减1。When the lower carry is 0 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction minus one.
第二方面,提供了一种虚拟地址确定装置,该虚拟地址确定装置包括至少一个模块,该至少一个模块用于实现上述第一方面或第一方面的任一可选方式所提供的虚拟地址确定方法。In a second aspect, a virtual address determining apparatus is provided, the virtual address determining apparatus comprising at least one module, the at least one module configured to implement the virtual address determination provided by the foregoing first aspect or any of the optional aspects of the first aspect method.
第三方面,提供了一种处理器,该处理器包括第二方面或第二方面的任一可选方式所提供的虚拟地址确定装置。In a third aspect, a processor is provided, the processor comprising the virtual address determining apparatus provided by the second aspect or the optional aspect of the second aspect.
第四方面,提供了一种计算机可读存储介质,该计算机可读存储介质中存储有指令,当该指令在计算机的处理器上运行时,使得该处理器执行第一方面或第一方面的任一可选方式所提供的虚拟地址确定方法。In a fourth aspect, a computer readable storage medium is provided having stored therein instructions that, when executed on a processor of a computer, cause the processor to perform the first aspect or the first aspect The virtual address determination method provided by any of the alternatives.
第五方面,提供了一种包含指令的计算机程序产品,当计算机程序产品在计算机的处理器上运行时,使得该处理器执行第一方面或第一方面的任一可选方式所提供的虚拟地址确定方法。In a fifth aspect, a computer program product comprising instructions for causing a processor to perform the virtualization provided by the first aspect or any of the alternatives of the first aspect when the computer program product is run on a processor of the computer Address determination method.
第六方面,提供了一种处理装置,该处理装置包括至少一个电路,该至少一个电路用于执行第一方面或第一方面的任一可选方式所提供的虚拟地址确定方法。In a sixth aspect, a processing apparatus is provided, the processing apparatus comprising at least one circuit for performing the virtual address determining method provided by the first aspect or any alternative of the first aspect.
第七方面,提供了一种芯片,该芯片包括可编程逻辑电路和/或程序指令,当该芯片运行时用于实现第一方面或第一方面的任一可选方式所提供的虚拟地址确定方法。In a seventh aspect, a chip is provided, the chip comprising programmable logic circuitry and/or program instructions for implementing virtual address determination provided by the first aspect or any of the alternatives of the first aspect when the chip is running method.
本申请提供的技术方案带来的有益效果是:The beneficial effects brought by the technical solutions provided by the present application are:
本申请提供的虚拟地址确定方法及装置、处理器、存储介质,由于目标指令的低位地址是从目标指令的上一指令的指令空间中读取到的,在确定目标指令的虚拟地址的过程中,无需计算目标指令的低位地址,只需要计算目标指令的剩余地址(剩余地址为目标指令的虚拟地址中除低位地址之外的地址),然后将目标指令的剩余地址与目标指令的低位地址合并就可以得到目标指令的虚拟地址,因此可以减小确定目标指令的虚拟地址的计算量,有助于解决确定目标指令的虚拟地址的时延较大,处理器的处理速度较慢的问题,减小确定目标指令的虚拟地址的时延,提高处理器的处理速度。The virtual address determining method and apparatus, processor, and storage medium provided by the present application, in the process of determining the virtual address of the target instruction, because the lower address of the target instruction is read from the instruction space of the previous instruction of the target instruction No need to calculate the lower address of the target instruction, only need to calculate the remaining address of the target instruction (the remaining address is the address of the virtual address of the target instruction except the lower address), and then merge the remaining address of the target instruction with the lower address of the target instruction. The virtual address of the target instruction can be obtained, so that the calculation amount of the virtual address of the target instruction can be reduced, which helps to solve the problem that the delay of determining the virtual address of the target instruction is large, and the processing speed of the processor is slow. Small determines the delay of the virtual address of the target instruction, and improves the processing speed of the processor.
附图说明DRAWINGS
图1是本申请实施例所涉及的一种处理器的流水线的示意图;1 is a schematic diagram of a pipeline of a processor according to an embodiment of the present application;
图2是本申请实施例所涉及的一种地址映射示意图;2 is a schematic diagram of address mapping involved in an embodiment of the present application;
图3是本申请实施例所涉及的另一种地址映射示意图;FIG. 3 is another schematic diagram of address mapping according to an embodiment of the present application; FIG.
图4是本申请实施例所涉及的一种直接分支指令的指令空间的示意图;4 is a schematic diagram of an instruction space of a direct branch instruction according to an embodiment of the present application;
图5是本申请实施例提供的一种虚拟地址确定方法的方法流程图;FIG. 5 is a flowchart of a method for determining a virtual address according to an embodiment of the present application;
图6是本申请实施例提供的另一种虚拟地址确定方法的方法流程图;6 is a flowchart of a method for determining another virtual address provided by an embodiment of the present application;
图7是本申请实施例提供的一种指令空间的示意图;7 is a schematic diagram of an instruction space provided by an embodiment of the present application;
图8是本申请实施例提供的一种计算虚拟地址的示意图;FIG. 8 is a schematic diagram of calculating a virtual address according to an embodiment of the present application; FIG.
图9是本申请实施例提供的另一种计算虚拟地址的示意图;FIG. 9 is a schematic diagram of another computing virtual address provided by an embodiment of the present application; FIG.
图10是本申请实施例提供的再一种虚拟地址确定方法的方法流程图;10 is a flowchart of a method for determining a virtual address determining method according to an embodiment of the present application;
图11是本申请实施例提供的另一种指令空间的示意图;11 is a schematic diagram of another instruction space provided by an embodiment of the present application;
图12是本申请实施例提供的再一种计算虚拟地址的示意图;FIG. 12 is a schematic diagram of still another computing virtual address provided by an embodiment of the present application; FIG.
图13是本申请实施例提供的又一种计算虚拟地址的示意图;FIG. 13 is a schematic diagram of still another computing virtual address provided by an embodiment of the present application; FIG.
图14是本申请实施例提供的一种虚拟地址确定装置的框图;FIG. 14 is a block diagram of a virtual address determining apparatus according to an embodiment of the present application;
图15是本申请实施例提供的另一种虚拟地址确定装置的框图;FIG. 15 is a block diagram of another virtual address determining apparatus according to an embodiment of the present application; FIG.
图16是本申请实施例提供的一种第一确定模块的框图;16 is a block diagram of a first determining module according to an embodiment of the present application;
图17是本申请实施例提供的再一种虚拟地址确定装置的框图。FIG. 17 is a block diagram of still another virtual address determining apparatus according to an embodiment of the present application.
具体实施方式Detailed ways
中央处理器是一种典型的处理器,大多数的中央处理器都以流水线的形式运作,流水线由多个不同的流水线级组成,中央处理器包括与每个流水线级对应的单元,每个单元用于执行相应的流水线级的操作,且根据中央处理器的速度需求的不同以及芯片工艺的不同,不同的流水线所包含的流水线级不同。如图1所示,其示出了中央处理器的一个典型的运作流水线,参见图1,该流水线包括:取指令、解码指令、发射指令、执行指令、访问记忆体和提交结果,取指令、解码指令、发射指令、执行指令、访问记忆体和提交结果中的每一项可以称为一个流水线级,中央处理器可以包括取指令单元(instruction fetch unit)、解码单元、发射单元、执行单元、访问单元和提交单元,取指令单元用于执行取指令操作,取指令单元取出指令后,将指令传送给解码单元,解码单元对指令进行解码,并将解码后的指令传送给发射单元,由发射单元将指令发射至执行单元,执行单元执行指令之后,将指令传送给访问单元,访问单元根据指令访问记忆体,之后提交单元提交结果。The central processing unit is a typical processor. Most of the central processing units operate in a pipeline. The pipeline consists of a number of different pipeline stages. The central processing unit includes units corresponding to each pipeline stage. Used to perform the corresponding pipeline-level operations, and different pipelines contain different pipeline stages depending on the speed requirements of the central processor and the chip process. As shown in FIG. 1, it shows a typical operation pipeline of the central processing unit. Referring to FIG. 1, the pipeline includes: fetching instructions, decoding instructions, transmitting instructions, executing instructions, accessing memory and submitting results, fetching instructions, Each of the decoding instruction, the transmission instruction, the execution instruction, the access memory, and the submission result may be referred to as a pipeline stage, and the central processing unit may include an instruction fetch unit, a decoding unit, a transmitting unit, an execution unit, The access unit and the submitting unit, the fetching unit is configured to perform the fetching operation, and after fetching the fetching instruction, the instruction unit transmits the instruction to the decoding unit, the decoding unit decodes the instruction, and transmits the decoded instruction to the transmitting unit, and transmits The unit transmits the instruction to the execution unit. After the execution unit executes the instruction, the instruction is transmitted to the access unit, and the access unit accesses the memory according to the instruction, and then the submit unit submits the result.
本申请实施例主要涉及到上述流水线中的取指令,因此,这里主要对取指令单元取指令的过程进行说明。通常,取指令单元可以先确定待获取的目标指令的虚拟地址,然后根据目标指令的虚拟地址获取目标指令(也即是根据虚拟地址取指令)。虚拟地址又称为逻辑地址,例如,虚拟地址可以为PC地址。以下对取指令单元取指令的过程进行说明。The embodiment of the present application mainly relates to fetching instructions in the above pipeline. Therefore, the process of fetching instructions by the fetching unit is mainly described herein. Generally, the instruction fetch unit may first determine the virtual address of the target instruction to be acquired, and then acquire the target instruction according to the virtual address of the target instruction (that is, fetch the instruction according to the virtual address). A virtual address is also called a logical address. For example, a virtual address can be a PC address. The following describes the process of fetching instructions from the instruction fetch unit.
取指令单元在获取目标指令的过程中,如果目标指令的上一指令不是分支指令(branch instruction),则取指令单元在目标指令的上一指令的虚拟地址上加上一个地址数值(该地址数值取决于取指令单元一个周期内取多少条指令以及每条指令的宽度)得到目标指令的虚拟地址,并根据目标指令的虚拟地址获取目标指令。如果目标指令的上一指令是分支指令时,则目标指令可以跳转或不跳转,取指令单元可以对目标指令是否跳转进行预测。如果取指令单元预测出目标指令不跳转,则取指令单元在目标指令的上一指令的虚拟地址上加上一个地址数值得到目标指令的虚拟地址,并根据目标指令的虚拟地址取指令。如果取指令单元预测出目标指令跳转,则取指令单元需要计算出跳转目标地址(branch target address),然后根据跳转目标地址取指令,该跳转目标地址也即是目标指令的虚拟地址。通常,取指令单元可以在目标指令的上一指令的虚拟地址上加上一个偏移地址(offset address)得到跳转目标地址。其中,偏移地址可以位于目标指令的上一指令中,也可以位于寄存器中,如果偏移地址位于目标指令的上一指令中,则该目标指令的上一指令可以称为直接分支(directbranch)指令,如果偏移地址位于寄存器中,则该目标指令的上一指令可以称为 非直接分支指令。当目标指令的上一指令是直接分支指令时,取指令单元可以对目标指令的上一指令进行解码得到偏移地址,然后将目标指令的上一指令的虚拟地址与解码得到的偏移地址相加得到跳转目标地址。当目标指令的上一指令是非直接分支指令时,由于取指令单元不能直接访问寄存器,因此,取指令单元可以采用分支目标缓冲器(branch target buffer,BTB)来预测跳转目标地址,或者,取指令单元等到后续的执行单元根据目标指令的上一指令从寄存器中读取出偏移地址,并将目标指令的上一指令的虚拟地址与从寄存器中读取出偏移地址相加之后,将执行单元相加得到的地址确定为跳转目标地址。需要说明的是,在处理器的流水线中,执行单元可以对指令进行识别,当执行单元识别出指令为非直接分支指令时,执行单元从寄存器中读取出偏移地址,可以根据偏移地址计算跳转目标地址,并向取指令单元反馈跳转目标地址。还需要说明的是,处理器上电之后,可以进行地址复位,取指令单元可以根据复位虚拟地址获取处理器上电之后的第一条指令,之后处理器按照上述方法取指令。In the process of acquiring the target instruction, if the previous instruction of the target instruction is not a branch instruction, the instruction unit adds an address value to the virtual address of the previous instruction of the target instruction (the address value) Depending on how many instructions are fetched in one cycle and the width of each instruction, the virtual address of the target instruction is obtained, and the target instruction is obtained according to the virtual address of the target instruction. If the previous instruction of the target instruction is a branch instruction, the target instruction may or may not jump, and the instruction instruction unit may predict whether the target instruction jumps. If the instruction fetch unit predicts that the target instruction does not jump, the fetch unit adds an address value to the virtual address of the previous instruction of the target instruction to obtain the virtual address of the target instruction, and fetches the instruction according to the virtual address of the target instruction. If the instruction fetch unit predicts the target instruction jump, the fetch unit needs to calculate a branch target address, and then fetches the instruction according to the jump destination address, which is also the virtual address of the target instruction. . Generally, the instruction fetch unit can add an offset address to the virtual address of the previous instruction of the target instruction to obtain the jump destination address. The offset address may be located in the previous instruction of the target instruction, or may be located in the register. If the offset address is in the previous instruction of the target instruction, the previous instruction of the target instruction may be referred to as a direct branch (directbranch). The instruction, if the offset address is in a register, the previous instruction of the target instruction may be referred to as an indirect branch instruction. When the previous instruction of the target instruction is a direct branch instruction, the instruction fetch unit can decode the previous instruction of the target instruction to obtain an offset address, and then compare the virtual address of the previous instruction of the target instruction with the decoded offset address. Add the jump destination address. When the previous instruction of the target instruction is a non-direct branch instruction, since the instruction instruction unit cannot directly access the register, the instruction instruction unit may use a branch target buffer (BTB) to predict the jump destination address, or The instruction unit waits until the subsequent execution unit reads the offset address from the register according to the previous instruction of the target instruction, and adds the virtual address of the previous instruction of the target instruction to the offset address read from the register, and then The address obtained by adding the execution units is determined as the jump destination address. It should be noted that, in the pipeline of the processor, the execution unit may identify the instruction, and when the execution unit recognizes that the instruction is an indirect branch instruction, the execution unit reads the offset address from the register, and may be based on the offset address. The jump destination address is calculated and the jump destination address is fed back to the instruction fetch unit. It should be noted that after the processor is powered on, the address reset may be performed, and the instruction fetch unit may acquire the first instruction after the processor is powered on according to the reset virtual address, and then the processor fetches the instruction according to the above method.
在本申请中,取指令单元根据目标指令的虚拟地址取指令可以包括:取指令单元根据目标指令的虚拟地址和地址映射确定目标指令的物理地址,根据目标指令的物理地址从存储空间中获取目标指令。其中,地址映射可以为物理指标物理标记(Physical Index Physical Tag,PIPT)地址映射或虚拟索引物理标记(Virtual Index Physical Tag,VIPT)地址映射,也可以为直接映射(direct map)。请参考图2,其示出了本申请实施例所涉及的一种地址映射示意图,该地址映射示意图可以表示PIPT地址映射或VIPT地址映射,参见图2,虚拟地址存储在虚拟地址空间中,物理地址存储在物理地址空间中,该物理地址空间通常为处理器的一级指令缓存,映射表用于记录虚拟地址空间中存储的虚拟地址与物理地址空间中存储的物理地址的映射关系,取指令单元可以根据目标指令的虚拟地址查找映射表得到目标指令的物理地址。如图2所示,在PIPT地址映射或VIPT地址映射中,不同的虚拟地址可以映射到相同的物理地址,相同的物理地址存储着相同的指令,从而该不同的虚拟地址存在相同的偏移地址,将该不同的虚拟地址分别与该偏移地址相加得到的跳转目标地址不同。但是需要说明的是,在PIPT地址映射或VIPT地址映射中,相互对应的虚拟地址和物理地址中,虚拟地址的低位地址等于物理地址的低位地址,因此,将该不同的虚拟地址分别与该相同的偏移地址相加得到的不同的跳转目标地址中,低位地址是相同的,该低位地址的宽度可以根据页表的大小(或称为页表的粒度)确定,示例地,当页表的大小为4KB(千字节)时,该低位地址的宽度等于12比特(bit)(4KB=212bit),也即是,虚拟地址中最低的12比特与物理地址中最低的12比特相同,当页表的大小为64KB时,该低位地址的宽度等于16比特(64KB=216bit),也即是,虚拟地址中最低的16比特与物理地址中最低的16比特相同。请参考图3,其示出了本申请实施例所涉及的另一种地址映射示意图,该地址映射示意图可以表示直接映射,参见图3,虚拟地址存储在虚拟地址空间中,物理地址存储在物理地址空间中,该物理地址空间通常为处理器的一级指令缓存。在直接映射中,无需根据采用映射表来查找物理地址,在根据目标指令的虚拟地址和地址映射确定目标指令的物理地址时,可以将目标指令的虚拟地址的低位地址确定为目标指令的物理地址,或者,将目标指令的虚拟地址确定为目标指令的物理地址,具体是将目标指令的虚拟地址的低位地址确定为目标指令的物理地址,还是将目标指令的虚拟地址确定为目标指令的物理地址,可以根据目标指令的物理地址的宽度来确定。In the present application, the fetching instruction unit fetching the instruction according to the virtual address of the target instruction may include: the fetching instruction unit determines the physical address of the target instruction according to the virtual address and the address mapping of the target instruction, and acquires the target from the storage space according to the physical address of the target instruction. instruction. The address mapping may be a physical index physical tag (PIPT) address mapping or a virtual index physical tag (VIPT) address mapping, or may be a direct mapping. Please refer to FIG. 2, which is a schematic diagram of address mapping involved in the embodiment of the present application. The address mapping diagram may represent a PIPT address mapping or a VIPT address mapping. Referring to FIG. 2, a virtual address is stored in a virtual address space, and physical The address is stored in the physical address space, where the physical address space is usually a level one instruction cache of the processor, and the mapping table is used to record the mapping relationship between the virtual address stored in the virtual address space and the physical address stored in the physical address space, and fetch instructions. The unit can obtain the physical address of the target instruction according to the virtual address lookup mapping table of the target instruction. As shown in FIG. 2, in a PIPT address mapping or a VIPT address mapping, different virtual addresses can be mapped to the same physical address, and the same physical address stores the same instruction, so that the different virtual addresses have the same offset address. The jump destination address obtained by adding the different virtual addresses to the offset address is different. However, it should be noted that in the PIPT address mapping or the VIPT address mapping, among the virtual addresses and physical addresses corresponding to each other, the lower address of the virtual address is equal to the lower address of the physical address, and therefore, the different virtual addresses are respectively the same. Among the different jump destination addresses obtained by adding the offset addresses, the lower address is the same, and the width of the lower address can be determined according to the size of the page table (or the granularity of the page table), for example, when the page table When the size is 4 KB (kilobytes), the width of the lower address is equal to 12 bits (4 KB = 212 bits), that is, the lowest 12 bits of the virtual address are the same as the lowest 12 bits of the physical address. When the size of the page table is 64 KB, the width of the lower address is equal to 16 bits (64 KB = 216 bits), that is, the lowest 16 bits of the virtual address are the same as the lowest 16 bits of the physical address. Please refer to FIG. 3, which is another schematic diagram of address mapping involved in the embodiment of the present application. The address mapping diagram may represent direct mapping. Referring to FIG. 3, the virtual address is stored in the virtual address space, and the physical address is stored in the physical address. In the address space, the physical address space is usually the processor's level one instruction cache. In the direct mapping, it is not necessary to find the physical address according to the mapping table, and when determining the physical address of the target instruction according to the virtual address and address mapping of the target instruction, the lower address of the virtual address of the target instruction can be determined as the physical address of the target instruction. Or determining the virtual address of the target instruction as the physical address of the target instruction, specifically determining the lower address of the virtual address of the target instruction as the physical address of the target instruction, or determining the virtual address of the target instruction as the physical address of the target instruction. , can be determined according to the width of the physical address of the target instruction.
随着应用需求的增加,处理器的地址宽度不断的增加(例如处理器的地址宽度从32比特增加至64比特),使得将偏移地址与虚拟地址相加的计算量也相应增大,因此确定目标指令的虚拟地址的时延较大。此外,不同直接分支指令所包含的偏移地址的宽度可能不同,不同直接分支指令所包含的偏移地址在指令空间中可能没有对齐,偏移地址的宽度与目标指令的上一指令的虚拟地址的宽度可能不同,在将偏移地址与目标指令的上一指令的虚拟地址相加之前,需要先对偏移地址进行符号扩展,使偏移地址的宽度与目标指令的上一指令的虚拟地址的宽度相等,且偏移地址与目标指令的上一指令的虚拟地址对齐,然后再按位将偏移地址与目标指令的上一指令的虚拟地址相加得到目标指令的虚拟地址,这就导致确定目标指令的虚拟地址的时延进一步增大。示例地,请参考图4,其示出了本申请实施例所涉及的一种直接分支指令的示意图,参见图4,指令B.cond、指令CBNZ、指令CBZ、指令TBNZ、指令TBZ、指令B和指令BL均为直接分支指令,每个指令的指令空间(instruction field)为第0比特至第31比特,imm*表示存储偏移地址的指令空间,*表示偏移地址的宽度。如图4所示,指令B.cond所包含的偏移地址的宽度、指令CBNZ所包含的偏移地址的宽度和指令CBZ所包含的偏移地址的宽度均为19比特,且指令B.cond中存储偏移地址的指令空间、指令CBNZ中存储偏移地址的指令空间和指令CBZ中存储偏移地址的指令空间均为第5比特至第23比特,指令TBNZ所包含的偏移地址的宽度和指令TBZ所包含的偏移地址的宽度均为14比特,且指令TBNZ中存储偏移地址的指令空间和指令TBZ中存储偏移地址的指令空间均为第5比特至18比特,指令B所包含的偏移地址的宽度和指令BL所包含的偏移地址的宽度均为26比特,且指令B中存储偏移地址的指令空间和指令BL中存储偏移地址的指令空间均为第0比特至第25比特。根据图4不难理解,指令B.cond、指令TBNZ以及指令B所包含的偏移地址在指令空间中没有对齐。As the application requirements increase, the address width of the processor increases continuously (for example, the address width of the processor increases from 32 bits to 64 bits), so that the calculation amount of adding the offset address to the virtual address is correspondingly increased, The delay of determining the virtual address of the target instruction is large. In addition, the offset addresses included in different direct branch instructions may be different. The offset addresses contained in different direct branch instructions may not be aligned in the instruction space. The width of the offset address is the virtual address of the previous instruction of the target instruction. The width may be different. Before adding the offset address to the virtual address of the previous instruction of the target instruction, the offset address needs to be sign-extended so that the width of the offset address is the virtual address of the previous instruction of the target instruction. The width is equal, and the offset address is aligned with the virtual address of the previous instruction of the target instruction, and then the bit address is added by bit to the virtual address of the previous instruction of the target instruction to obtain the virtual address of the target instruction, which results in The delay in determining the virtual address of the target instruction is further increased. For example, please refer to FIG. 4, which shows a schematic diagram of a direct branch instruction according to an embodiment of the present application. Referring to FIG. 4, the instruction B.cond, the instruction CBNZ, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B The instruction BL is a direct branch instruction, and the instruction field of each instruction is the 0th bit to the 31st bit, imm* represents the instruction space in which the offset address is stored, and * represents the width of the offset address. As shown in FIG. 4, the width of the offset address included in the instruction B.cond, the width of the offset address included in the instruction CBNZ, and the width of the offset address included in the instruction CBZ are both 19 bits, and the instruction B.cond The instruction space in which the offset address is stored, the instruction space in which the offset address is stored in the instruction CBNZ, and the instruction space in which the offset address is stored in the instruction CBZ are the 5th to 23rd bits, and the width of the offset address included in the instruction TBNZ The offset address included in the instruction TBZ is 14 bits wide, and the instruction space in which the offset address is stored in the instruction TBNZ and the instruction space in which the offset address is stored in the instruction TBZ are all 5th to 18th bits, and the instruction B is The width of the included offset address and the width of the offset address included in the instruction BL are both 26 bits, and the instruction space in which the offset address is stored in the instruction B and the instruction space in which the offset address is stored in the instruction BL are all the 0th bit. To the 25th bit. According to FIG. 4, it is not difficult to understand that the offset addresses contained in the instruction B.cond, the instruction TBNZ, and the instruction B are not aligned in the instruction space.
假设目标指令的上一指令的虚拟地址的宽度为64,取指令单元对偏移地址进行符号扩展,再按位将偏移地址与目标指令的上一指令的虚拟地址相加得到目标指令的虚拟地址可以采用下述方程式(1)来表示:Assume that the width of the virtual address of the previous instruction of the target instruction is 64, the instruction fetch unit symbolically expands the offset address, and then adds the offset address to the virtual address of the previous instruction of the target instruction by bit to obtain the virtual of the target instruction. The address can be expressed by the following equation (1):
方程式(1)br_trgt[63:0]=cur_pc[63:0]+{{(64-*){imm[*]}},imm[(*-1):0]}Equation (1) br_trgt[63:0]=cur_pc[63:0]+{{(64-*){imm[*]}},imm[(*-1):0]}
在该方程式(1)中,br_trgt[63:0]表示目标指令的虚拟地址(也即是跳转目标地址),cur_pc[63:0]表示目标指令的上一指令的虚拟地址,*表示偏移地址的宽度,imm[*]表示偏移地址的符号(也即是偏移地址的最高位的符号),imm[(*-1):0]表示偏移地址,{(64-*){imm[*]}是偏移地址的符号扩展,表示将imm[*]复制(64-*)比特,{{(64-*){imm[*]}},imm[(*-1):0]}表示扩展后的偏移地址。示例地,假设*=14,imm[(*-1):0]=10101010101010,则imm[*]=1,{(64-*){imm[*]}表示将1复制50(50=64-14)比特,{{(64-*){imm[*]}},imm[(*-1):0]}表示将复制的50比特的1添加在10101010101010的高位得到扩展后的偏移地址。需要说明的是,在该方程式(1)中,如果imm[*]为0,则该方程式(1)表示把64比特的虚拟地址(即,目标指令的上一指令的虚拟地址)与64比特的偏移地址(即,扩展后的偏移地址)相加得到64比特的虚拟地址(即,目标指令的虚拟地址),如果imm[*]为1,则该方程式(1)表示把64比特的虚拟地址与64比特的偏移地址相减得到64比特的虚拟地址。In the equation (1), br_trgt[63:0] represents the virtual address of the target instruction (that is, the jump destination address), cur_pc[63:0] represents the virtual address of the previous instruction of the target instruction, and * indicates a partial The width of the shift address, imm[*] indicates the sign of the offset address (that is, the sign of the highest bit of the offset address), imm[(*-1):0] indicates the offset address, {(64-*) {imm[*]} is a sign extension of the offset address, indicating that imm[*] is copied (64-*) bits, {{(64-*){imm[*]}}, imm[(*-1) :0]} indicates the extended offset address. For example, suppose *=14, imm[(*-1):0]=10101010101010, then imm[*]=1, {(64-*){imm[*]} means copy 1 to 50 (50=64) -14) bit, {{(64-*){imm[*]}}, imm[(*-1):0]} indicates that the copied 50-bit 1 is added to the high bit of 10101010101010 to obtain an extended offset. address. It should be noted that, in the equation (1), if imm[*] is 0, the equation (1) represents a 64-bit virtual address (ie, the virtual address of the previous instruction of the target instruction) and 64 bits. The offset addresses (ie, the extended offset addresses) are added to obtain a 64-bit virtual address (ie, the virtual address of the target instruction). If imm[*] is 1, the equation (1) represents 64 bits. The virtual address is subtracted from the 64-bit offset address to obtain a 64-bit virtual address.
根据以上描述不难理解,无论跳转目标地址是取指令单元根据直接分支指令中的偏移地址与目标指令的上一指令的虚拟地址计算得到的,还是执行单元根据偏移地址与目标指令的上一指令的虚拟地址计算得到的,或者,是取指令单元采用BTB预测出来的,由于处 理器的地址宽度的增加,确定跳转目标地址的时延很大,此外,在同一级流水线的中,除了确定跳转目标地址之外,还需要做其他逻辑运算,导致处理器处理指令的时延很大,直接影响处理器的处理速度。According to the above description, it is not difficult to understand whether the jump target address is calculated by the instruction unit according to the offset address in the direct branch instruction and the virtual address of the previous instruction of the target instruction, or is the execution unit according to the offset address and the target instruction. The virtual address of the previous instruction is calculated, or the instruction fetch unit is predicted by the BTB. Due to the increase of the address width of the processor, the delay of determining the jump destination address is large, and in addition, in the same stage pipeline. In addition to determining the jump destination address, other logical operations are required, which causes the processor to process the instruction with a large delay, which directly affects the processing speed of the processor.
为了减小确定跳转目标地址的时延,相关技术中,在将指令写入缓存之前,预先将指令解码,然后再用简单的方法对指令进行重新编码,因此在取指令的过程中,只需对该重新编码后的指令进行简单的解码,可以节省取指令过程中对指令解码占用的时间,缩短确定跳转目标地址的时延,提高处理器的处理速度。但是该方案减小确定跳转目标地址的时延的力度较低。相关技术中,还可以在流水线中增加流水线级,以将部分的计算逻辑分配到增加的流水线级中,但是,增加流水线级会使整个流水线的长度增加,导致时延较大,且还会由于异常、预测错误和缓存丢失(cache miss)等导致处理器的性能下降。In order to reduce the delay of determining the jump destination address, in the related art, before the instruction is written into the cache, the instruction is decoded in advance, and then the instruction is re-encoded in a simple manner, so in the process of fetching the instruction, only The re-encoded instruction needs to be simply decoded, which can save the time required for decoding the instruction during the instruction fetching process, shorten the delay of determining the jump destination address, and improve the processing speed of the processor. However, this scheme reduces the delay of determining the delay of the jump destination address. In the related art, it is also possible to add a pipeline stage in the pipeline to allocate part of the calculation logic to the increased pipeline stage. However, increasing the pipeline stage increases the length of the entire pipeline, resulting in a large delay and also due to Exceptions, prediction errors, and cache misses cause processor performance degradation.
本申请实施例提供的虚拟地址确定方法及装置、处理器、存储介质,在取指令之前预计算出目标指令的虚拟地址中的部分地址,在取指令的过程中,只需要计算目标指令的虚拟地址中的剩余地址,然后将预计算出的部分地址与剩余地址合并得到目标指令的虚拟地址(也即是跳转目标地址),由于预计算出了部分地址,因此在取指令的过程中需要计算的地址的宽度较小,可以减少确定跳转目标地址的时延,提高处理器的处理速度。本申请实施例提供的方案请参考下述各个实施例。需要说明的是,在下述各个实施例中,目标指令为需要获取的指令,“上一指令”为一名词,上一指令为目标指令的上一个指令,在获取目标指令之前,该上一指令已经获取,且在下述实施例中,所有的低位地址、所有的中位地址、所有的高位地址和所有的偏移地址等均指的是虚拟地址,偏移地址指的是上一指令所包含的偏移地址。The virtual address determining method and apparatus, the processor, and the storage medium provided by the embodiments of the present application predict to calculate a partial address in the virtual address of the target instruction before fetching the instruction, and only need to calculate the virtual address of the target instruction in the process of fetching instructions. The remaining address in the middle, and then combine the predicted partial address with the remaining address to obtain the virtual address of the target instruction (that is, the jump destination address). Since the partial address is expected to be calculated, the address to be calculated in the process of fetching the instruction is required. The smaller width can reduce the delay of determining the jump destination address and improve the processing speed of the processor. For the solutions provided by the embodiments of the present application, please refer to the following embodiments. It should be noted that, in each of the following embodiments, the target instruction is an instruction that needs to be acquired, the “previous instruction” is a noun, and the previous instruction is the previous instruction of the target instruction, and the previous instruction is before the target instruction is acquired. It has been obtained, and in the following embodiments, all lower address, all median address, all upper address and all offset addresses refer to a virtual address, and the offset address refers to the previous instruction. Offset address.
请参考图5,其示出了本申请实施例提供的一种虚拟地址确定方法的方法流程图,该虚拟地址确定方法可以用于确定目标指令的虚拟地址。参见图5,该方法包括:Please refer to FIG. 5, which is a flowchart of a method for determining a virtual address according to an embodiment of the present application. The virtual address determining method may be used to determine a virtual address of a target instruction. Referring to Figure 5, the method includes:
步骤501、计算待获取的目标指令的低位地址。Step 501: Calculate a lower address of the target instruction to be acquired.
在本申请实施例中,取指令单元可以根据目标指令的上一指令的虚拟地址的低位地址和目标指令的上一指令所包含的偏移地址计算目标指令的低位地址。其中,低位地址的宽度可以根据地址映射方法、页表的大小以及目标指令的上一指令所包含的偏移地址的宽度等确定。根据地址映射的不同,取指令单元可以采用不同的方式计算目标指令的低位地址。可选地,当地址映射为PIPT地址映射或VIPT地址映射时,取指令单元可以根据目标指令的上一指令的低位地址和目标指令的上一指令所包含的偏移地址的低位地址计算目标指令的低位地址,计算过程可以参考下述图6所示实施例;当地址映射为直接映射时,取指令单元可以根据目标指令的上一指令的低位地址和目标指令的上一指令所包含的偏移地址计算目标指令的低位地址,计算过程可以参考下述图10所示实施例。In the embodiment of the present application, the instruction fetch unit may calculate the lower address of the target instruction according to the lower address of the virtual address of the previous instruction of the target instruction and the offset address included in the previous instruction of the target instruction. The width of the lower address may be determined according to the address mapping method, the size of the page table, and the width of the offset address included in the previous instruction of the target instruction. Depending on the address mapping, the instruction fetch unit can calculate the lower address of the target instruction in a different manner. Optionally, when the address mapping is a PIPT address mapping or a VIPT address mapping, the instruction fetch unit may calculate the target instruction according to the lower address of the previous instruction of the target instruction and the lower address of the offset address included in the previous instruction of the target instruction. For the lower address, the calculation process can refer to the following embodiment shown in FIG. 6. When the address mapping is direct mapping, the instruction fetch unit can be based on the lower address of the previous instruction of the target instruction and the bias of the previous instruction of the target instruction. The address of the target address is calculated by shifting the address. For the calculation process, reference may be made to the embodiment shown in FIG. 10 below.
步骤502、将目标指令的低位地址存储至目标指令的上一指令的指令空间。Step 502: Store the lower address of the target instruction to the instruction space of the previous instruction of the target instruction.
取指令单元可以将目标指令的低位地址存储至目标指令的上一指令的指令空间,以便于后续确定目标指令的虚拟地址时,直接从目标指令的上一指令的指令空间读取目标指令的低位地址,从而节省计算目标指令的低位地址的时间,减小确定目标指令的虚拟地址的时延。The instruction fetch unit can store the lower address of the target instruction to the instruction space of the previous instruction of the target instruction, so as to directly read the low address of the target instruction from the instruction space of the previous instruction of the target instruction when subsequently determining the virtual address of the target instruction. The address, thereby saving the time for calculating the lower address of the target instruction, and reducing the delay of determining the virtual address of the target instruction.
步骤503、将目标指令的上一指令写入一级指令缓存。Step 503: Write the previous instruction of the target instruction into the first-level instruction cache.
其中,一级指令缓存为用于存储指令的一级缓存,一级缓存与主存(取指令单元可以 为主存中的单元)的交互速度较快,因此,取指令单元可以将目标指令的上一指令写入一级指令缓存,以便于取指令过程中能够快速的读取到目标指令的上一指令。在本申请实施例中,一级指令缓存中,不同指令的指令空间中存储的低位地址在指令空间的第0比特对齐,因此,目标指令的上一指令的指令空间中存储的低位地址在该上一指令的指令空间的第0比特对齐,也即是,目标指令的低位地址与目标指令的上一指令的指令空间的第0比特对齐。The first level instruction cache is a level 1 cache for storing instructions, and the level 1 cache and the main memory (the instruction fetch unit can be a unit in the main memory) have a faster interaction speed. Therefore, the instruction fetch unit can target the instruction. The previous instruction is written to the level one instruction cache so that the previous instruction of the target instruction can be quickly read during the instruction fetching process. In the embodiment of the present application, in the first-level instruction cache, the lower address stored in the instruction space of the different instruction is aligned in the 0th bit of the instruction space, and therefore, the lower address stored in the instruction space of the previous instruction of the target instruction is in the The 0th bit of the instruction space of the previous instruction is aligned, that is, the lower address of the target instruction is aligned with the 0th bit of the instruction space of the previous instruction of the target instruction.
步骤504、从目标指令的上一指令的指令空间中读取目标指令的低位地址。Step 504: Read the lower address of the target instruction from the instruction space of the previous instruction of the target instruction.
当取指令单元需要获取目标指令时,取指令单元可以从目标指令的上一指令的指令空间中读取目标指令的低位地址,根据步骤501至步骤503不难理解,该目标指令的低位地址为将目标指令的上一指令写入一级指令缓存之前计算得到并存储在该上一指令的指令空间中的地址。When the fetching unit needs to acquire the target instruction, the fetching unit can read the lower address of the target instruction from the instruction space of the previous instruction of the target instruction. According to steps 501 to 503, it is not difficult to understand that the lower address of the target instruction is The address of the instruction instruction space of the previous instruction is calculated and stored before the previous instruction of the target instruction is written to the level one instruction cache.
步骤505、确定目标指令的剩余地址,目标指令的剩余地址的宽度与目标指令的低位地址的宽度之和等于目标指令的上一指令的虚拟地址的宽度。Step 505: Determine the remaining address of the target instruction, the sum of the width of the remaining address of the target instruction and the width of the lower address of the target instruction is equal to the width of the virtual address of the previous instruction of the target instruction.
取指令单元从目标指令的上一指令的指令空间中读取目标指令的低位地址后,可以确定目标指令的剩余地址,取指令单元可以采用目标指令的上一指令的虚拟地址的宽度减去目标指令的低位地址的宽度得到目标指令的剩余地址的宽度,进而确定目标指令的剩余地址。可选地,当一级指令缓存采用PIPT地址映射或VIPT地址映射时,该剩余地址包括中位地址和高位地址,取指令单元确定目标指令的剩余地址的过程可以参考下述图6所示实施例,当一级指令缓存采用直接映射时,该剩余地址包括高位地址,取指令单元确定目标指令的剩余地址的过程可以参考下述图10所示实施例。After the instruction fetch unit reads the lower address of the target instruction from the instruction space of the previous instruction of the target instruction, the remaining address of the target instruction can be determined, and the instruction fetch unit can use the width of the virtual address of the previous instruction of the target instruction minus the target. The width of the lower address of the instruction gets the width of the remaining address of the target instruction, which in turn determines the remaining address of the target instruction. Optionally, when the primary instruction cache uses the PIPT address mapping or the VIPT address mapping, the remaining address includes a median address and a high address, and the process of the instruction unit determining the remaining address of the target instruction may be implemented by using the following FIG. For example, when the first-level instruction cache adopts direct mapping, the remaining address includes a high-order address, and the process of the instruction unit determining the remaining address of the target instruction may refer to the embodiment shown in FIG. 10 described below.
步骤506、将目标指令的低位地址与目标指令的剩余地址合并,得到目标指令的虚拟地址。Step 506: Combine the lower address of the target instruction with the remaining address of the target instruction to obtain a virtual address of the target instruction.
取指令单元从目标指令的上一指令的指令空间中读取目标指令的低位地址,且确定出目标指令的剩余地址后,可以将目标指令的低位地址与目标指令的剩余地址合并,得到目标指令的虚拟地址。可选地,取指令单元可以按照地址位的高低将目标指令的低位地址与目标指令的剩余地址合并,且在同一虚拟地址中,地址位从右向左依次升高。例如,取指令单元将目标指令的剩余地址排布在目标指令的低位地址的高位,得到目标指令的虚拟地址。The instruction fetch unit reads the lower address of the target instruction from the instruction space of the previous instruction of the target instruction, and after determining the remaining address of the target instruction, the lower address of the target instruction can be merged with the remaining address of the target instruction to obtain the target instruction. Virtual address. Optionally, the instruction fetch unit may merge the lower address of the target instruction with the remaining address of the target instruction according to the address bit, and in the same virtual address, the address bits are sequentially raised from right to left. For example, the instruction fetch unit arranges the remaining address of the target instruction at the upper bit of the lower address of the target instruction to obtain the virtual address of the target instruction.
综上所述,本申请实施例提供的虚拟地址确定方法,由于目标指令的低位地址是从目标指令的上一指令的指令空间中读取到的,在确定目标指令的虚拟地址的过程中,无需计算目标指令的低位地址,只需要计算目标指令的剩余地址(剩余地址为目标指令的虚拟地址中除低位地址之外的地址),然后将目标指令的剩余地址与目标指令的低位地址合并就可以得到目标指令的虚拟地址,因此可以减小确定目标指令的虚拟地址的计算量,有助于解决确定目标指令的虚拟地址的时延较大,处理器的处理速度较慢的问题,减小确定目标指令的虚拟地址的时延,提高处理器的处理速度。In summary, the virtual address determining method provided by the embodiment of the present application, in the process of determining the virtual address of the target instruction, is that the lower address of the target instruction is read from the instruction space of the previous instruction of the target instruction. There is no need to calculate the lower address of the target instruction, only the remaining address of the target instruction (the remaining address is the address other than the lower address in the virtual address of the target instruction), and then the remaining address of the target instruction is merged with the lower address of the target instruction. The virtual address of the target instruction can be obtained, so that the calculation amount of the virtual address of the target instruction can be reduced, which helps to solve the problem that the delay of determining the virtual address of the target instruction is large, and the processing speed of the processor is slow, and the problem is reduced. Determine the delay of the virtual address of the target instruction and increase the processing speed of the processor.
请参考图6,其示出了本申请实施例提供的另一种虚拟地址确定方法的方法流程图,该虚拟地址确定方法可以用于确定目标指令的虚拟地址,该图6以地址映射为PIPT地址映射或VIPT地址映射为例进行说明,在PIPT地址映射或VIPT地址映射中,目标指令的剩余地址可以包括中位地址和高位地址。参见图6,该方法包括:Please refer to FIG. 6 , which is a flowchart of another method for determining a virtual address according to an embodiment of the present application. The virtual address determining method may be used to determine a virtual address of a target instruction, and FIG. 6 maps the address to a PIPT. The address mapping or the VIPT address mapping is described as an example. In the PIPT address mapping or the VIPT address mapping, the remaining addresses of the target instruction may include a median address and a high address. Referring to Figure 6, the method includes:
步骤601、确定目标指令的上一指令的虚拟地址和目标指令的上一指令所包含的偏移地址。Step 601: Determine a virtual address of a previous instruction of the target instruction and an offset address included in a previous instruction of the target instruction.
根据上文的描述不难理解,取指令单元通常根据指令的虚拟地址取指令,因此,当取指令单元取出目标指令的上一指令时,目标指令的上一指令的虚拟地址对于取指令单元而言是已知的。在本申请实施例中,目标指令的上一指令中包含偏移地址,取指令单元可以对目标指令的上一指令解码得到目标指令的上一指令所包含的偏移地址。According to the above description, it is not difficult to understand that the fetching unit usually fetches an instruction according to the virtual address of the instruction. Therefore, when the fetching unit fetches the previous instruction of the target instruction, the virtual address of the previous instruction of the target instruction is for the fetching unit. The words are known. In the embodiment of the present application, the previous instruction of the target instruction includes an offset address, and the instruction fetch unit can decode the previous instruction of the target instruction to obtain the offset address included in the previous instruction of the target instruction.
步骤602、根据页表的大小,从目标指令的上一指令的虚拟地址中确定目标指令的上一指令的低位地址,并从目标指令的上一指令所包含的偏移地址中确定目标指令的上一指令所包含的偏移地址的低位地址。Step 602: Determine, according to the size of the page table, the lower address of the previous instruction of the target instruction from the virtual address of the previous instruction of the target instruction, and determine the target instruction from the offset address included in the previous instruction of the target instruction. The lower address of the offset address contained in the previous instruction.
其中,目标指令的上一指令的低位地址与目标指令的上一指令所包含的偏移地址的低位地址对齐且宽度相等。在本申请实施例中,页表的大小也即是页表的粒度,页表的大小可以表示为2n,n为大于或等于1的整数,该n即为低位地址的宽度。取指令单元可以将目标指令的上一指令的虚拟地址中最低的n比特确定为目标指令的上一指令的低位地址,将目标指令的上一指令所包含的偏移地址中最低的n比特确定为该偏移地址的低位地址,其中,虚拟地址为可以PC地址。示例地,假设页表的大小为4KB,则n等于12,取指令单元可以将目标指令的上一指令的虚拟地址中最低的12比特确定为该上一指令的低位地址,将目标指令的上一指令所包含的偏移地址中最低的12比特确定为该偏移地址的低位地址。The lower address of the previous instruction of the target instruction is aligned with the lower address of the offset address included in the previous instruction of the target instruction and has the same width. In the embodiment of the present application, the size of the page table is also the granularity of the page table, and the size of the page table may be represented as 2n, where n is an integer greater than or equal to 1, and the n is the width of the lower address. The instruction fetch unit may determine the lowest n bits of the virtual address of the previous instruction of the target instruction as the lower address of the previous instruction of the target instruction, and determine the lowest n bits of the offset address included in the previous instruction of the target instruction. The lower address of the offset address, where the virtual address is a PC address. For example, assuming that the size of the page table is 4 KB, then n is equal to 12, and the fetch unit can determine the lowest 12 bits of the virtual address of the previous instruction of the target instruction as the lower address of the previous instruction, and the target instruction is The lowest 12 bits of the offset address contained in an instruction are determined as the lower address of the offset address.
示例地,假设虚拟地址为PC地址,cur_pc表示目标指令的上一指令的虚拟地址(由于在确定目标指令的虚拟地址时,目标指令的上一指令的虚拟地址是已知的,因此目标指令的上一指令的虚拟地址可以采用cur_pc表示),imm表示目标指令的上一指令所包含的偏移地址,cur_pc_lo表示目标指令的上一指令的低位地址,imm_lo表示目标指令的上一指令所包含的偏移地址的低位地址,则cur_pc_lo可以为cur_pc最低的n比特,imm_lo可以为imm最低的n比特。For example, suppose the virtual address is a PC address, and cur_pc represents the virtual address of the last instruction of the target instruction (since the virtual address of the previous instruction of the target instruction is known when determining the virtual address of the target instruction, the target instruction The virtual address of the previous instruction can be represented by cur_pc), imm represents the offset address contained in the previous instruction of the target instruction, cur_pc_lo represents the lower address of the previous instruction of the target instruction, and imm_lo represents the previous instruction included in the target instruction. For the lower address of the offset address, cur_pc_lo can be the lowest n bits of cur_pc, and imm_lo can be the lowest n bits of imm.
步骤603、将目标指令的上一指令的低位地址与目标指令的上一指令所包含的偏移地址的低位地址相加,得到目标指令的低位地址。Step 603: adding the lower address of the previous instruction of the target instruction to the lower address of the offset address included in the previous instruction of the target instruction to obtain the lower address of the target instruction.
取指令单元可以将目标指令的上一指令的低位地址与目标指令的上一指令所包含的偏移地址的低位地址按位相加,得到目标指令的低位地址,该目标指令的低位地址与目标指令的上一指令的低位地址对齐且宽度相等。示例地,当目标指令的上一指令的低位地址为目标指令的上一指令的虚拟地址中最低的12比特,且偏移地址的低位地址为偏移地址最低的12比特时,目标指令的低位地址也为12比特,且目标指令的低位地址与目标指令的上一指令的低位地址对齐。The instruction fetch unit can add the lower address of the previous instruction of the target instruction to the lower address of the offset address included in the previous instruction of the target instruction to obtain the lower address of the target instruction, and the lower address and the target of the target instruction. The lower address of the previous instruction of the instruction is aligned and the width is equal. For example, when the lower address of the previous instruction of the target instruction is the lowest 12 bits of the virtual address of the previous instruction of the target instruction, and the lower address of the offset address is the lowest 12 bits of the offset address, the low order of the target instruction The address is also 12 bits, and the lower address of the target instruction is aligned with the lower address of the previous instruction of the target instruction.
可选地,假设虚拟地址为PC地址,br_trgt表示目标指令的虚拟地址,br_trgt_lo表示目标指令的低位地址,cur_pc_lo表示目标指令的上一指令的低位地址,imm_lo表示目标指令的上一指令所包含的偏移地址的低位地址,则br_trgt_lo为cur_pc_lo与imm_lo相加得到的目标指令的低位地址,br_trgt_lo与cur_pc_lo对齐且宽度相等。Optionally, assuming that the virtual address is a PC address, br_trgt represents a virtual address of the target instruction, br_trgt_lo represents a lower address of the target instruction, cur_pc_lo represents a lower address of a previous instruction of the target instruction, and imm_lo represents a previous instruction included in the target instruction. The lower address of the offset address, br_trgt_lo is the lower address of the target instruction obtained by adding cur_pc_lo and imm_lo, and br_trgt_lo is aligned with cur_pc_lo and has the same width.
需要说明的是,上述步骤601至步骤603可以理解为,在地址映射为PIPT地址映射或VIPT地址映射时,对图5所示实施例中的步骤501的细化。It should be noted that the above steps 601 to 603 can be understood as the refinement of step 501 in the embodiment shown in FIG. 5 when the address mapping is a PIPT address mapping or a VIPT address mapping.
步骤604、将目标指令的低位地址存储至目标指令的上一指令的指令空间。Step 604: Store the lower address of the target instruction to the instruction space of the previous instruction of the target instruction.
其中,不同指令的指令空间中存储的低位地址在指令空间的第0比特对齐。The lower address stored in the instruction space of different instructions is aligned in the 0th bit of the instruction space.
可选地,取指令单元可以先对目标指令的上一指令的指令空间中存储的偏移地址进行位置调整,使该偏移地址在该上一指令的指令空间的第0比特对齐,然后再删除该偏移地址的低位地址得到空闲指令空间,将目标指令的低位地址存储至该空闲指令空间,从而使不同指令的指令空间中存储的低位地址在指令空间的第0比特对齐。Optionally, the instruction fetching unit may first adjust the offset address stored in the instruction space of the previous instruction of the target instruction, so that the offset address is aligned in the 0th bit of the instruction space of the previous instruction, and then Deleting the lower address of the offset address results in an idle instruction space, and stores the lower address of the target instruction into the free instruction space, thereby aligning the lower address stored in the instruction space of the different instructions in the 0th bit of the instruction space.
示例地,请参考图7,其示出了本申请实施例提供的一种指令空间的示意图,参见图7,指令B.cond、指令CBNZ、指令CBZ、指令TBNZ、指令TBZ、指令B和指令BL中,每个指令的指令空间为第0比特至第31比特,指令B.cond、指令CBNZ、指令CBZ、指令TBNZ、指令TBZ、指令B和指令BL中均存储有低位地址,且不同指令中存储的可以是不同目标指令的低位地址,指令B.cond、指令CBNZ、指令CBZ、指令TBNZ、指令TBZ、指令B和指令BL的指令空间中存储的低位地址在指令空间的第0比特对齐。在本申请实施例中,目标指令的上一指令可以为图7中的指令B.cond,目标指令的低位地址可以为指令B.cond的指令空间中的br_trgt_lo[11:0],br_trgt_lo[11:0]表示目标指令的低位地址的宽度为12比特,且目标指令的低位地址从目标指令的上一指令的第0比特开始。对比图4和图7可以看出,取指令单元将图4所示的指令B.cond的指令空间中存储的偏移地址从第5比特至第23比特调整至第0比特至第18比特,且删除了偏移地址的最低的12比特得到空闲指令空间,该空闲指令空间为从指令B.cond的第0比特至第11比特的空间,取指令单元将br_trgt_lo[11:0]存储至该空闲指令空间。指令CBNZ、指令CBZ、指令TBNZ、指令TBZ、指令B和指令BL的情况与指令B.cond的类似,在此不再赘述。For example, please refer to FIG. 7 , which shows a schematic diagram of an instruction space provided by an embodiment of the present application. Referring to FIG. 7 , an instruction B.cond, an instruction CBNZ, an instruction CBZ, an instruction TBNZ, an instruction TBZ, an instruction B, and an instruction. In BL, the instruction space of each instruction is the 0th bit to the 31st bit, and the instruction B.cond, the instruction CBNZ, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B, and the instruction BL all store the lower address, and the different instructions The lower address stored in the instruction space can be the lower address of the instruction target space. The lower address stored in the instruction space of the instruction B.cond, the instruction CBNZ, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B and the instruction BL is aligned in the 0th bit of the instruction space. . In the embodiment of the present application, the previous instruction of the target instruction may be the instruction B.cond in FIG. 7, and the lower address of the target instruction may be br_trgt_lo[11:0] in the instruction space of the instruction B.cond, br_trgt_lo[11 :0] indicates that the lower address of the target instruction has a width of 12 bits, and the lower address of the target instruction starts from the 0th bit of the previous instruction of the target instruction. 4 and FIG. 7, the instruction fetch unit adjusts the offset address stored in the instruction space of the instruction B.cond shown in FIG. 4 from the 5th bit to the 23rd bit to the 0th bit to the 18th bit. And deleting the lowest 12 bits of the offset address to obtain an idle instruction space, the free instruction space is from the 0th bit to the 11th bit of the instruction B.cond, and the fetching unit stores br_trgt_lo[11:0] to the Free instruction space. The case of the instruction CBNZ, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B, and the instruction BL is similar to the instruction B.cond, and will not be described herein.
需要说明的是,在将目标指令的低位地址存储至目标指令的上一指令的指令空间的过程中,对于偏移地址的剩余地址,取指令单元通常仅调整偏移地址的剩余地址在指令空间中的位置,而不对该偏移地址的剩余地址进行修改,通常可以将偏移地址拆分为低位地址和高位地址,因此偏移地址的剩余地址也即是偏移地址的高位地址。示例地,请继续对比图4和图7,imm_hi[6:0]表示偏移地址的高位地址,在将br_trgt_lo[11:0]存储至指令B.cond的指令空间的过程中,取指令单元仅对imm_hi[6:0]的位置进行了调整。指令CBNZ、指令CBZ、指令TBNZ、指令TBZ、指令B和指令BL的情况与指令B.cond的情况类似,在此不再赘述。It should be noted that, in the process of storing the lower address of the target instruction to the instruction space of the previous instruction of the target instruction, for the remaining address of the offset address, the instruction fetch unit usually only adjusts the remaining address of the offset address in the instruction space. The location in the middle, without modifying the remaining address of the offset address, can usually split the offset address into a lower address and a higher address, so the remaining address of the offset address is the upper address of the offset address. For example, please continue to compare FIG. 4 and FIG. 7. imm_hi[6:0] represents the upper address of the offset address, and in the process of storing br_trgt_lo[11:0] into the instruction space of the instruction B.cond, the instruction unit is fetched. Only the position of imm_hi[6:0] has been adjusted. The case of the instruction CBNZ, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B, and the instruction BL is similar to the case of the instruction B.cond, and will not be described herein.
步骤605、将低位进位存储至扩展指令空间。Step 605: Store the lower carry into the extended instruction space.
在本实施例中,低位进位为将目标指令的上一指令的低位地址与目标指令的上一指令所包含的偏移地址的低位地址相加产生的进位,该低位进位可以为0或1,当该低位进位为0时,可以理解为:在将目标指令的上一指令的低位地址与目标指令的上一指令所包含的偏移地址的低位地址按位相加的过程中没有产生进位。In this embodiment, the lower carry is a carry generated by adding the lower address of the previous instruction of the target instruction to the lower address of the offset address included in the previous instruction of the target instruction, and the lower carry can be 0 or 1, When the lower carry is 0, it can be understood that the carry is not generated in the process of adding the lower address of the previous instruction of the target instruction to the lower address of the offset address included in the previous instruction of the target instruction.
其中,扩展指令空间为对上一指令的指令空间进行扩展得到的指令空间。可选地,取指令单元可以对目标指令的上一指令的指令空间进行扩展得扩展指令空间,然后将低位进位存储至扩展指令空间中。示例地,当目标指令的上一指令为图7中的指令B.cond时,取指令单元可以对指令B.cond的指令空间进行扩展,得到第32比特的指令空间,并将低位进位存储至指令B.cond的第32比特的指令空间中。The extended instruction space is an instruction space obtained by expanding the instruction space of the previous instruction. Optionally, the fetching unit may expand the instruction space of the previous instruction of the target instruction to expand the instruction space, and then store the lower carry into the extended instruction space. For example, when the previous instruction of the target instruction is the instruction B.cond in FIG. 7, the instruction instruction unit may expand the instruction space of the instruction B.cond to obtain the instruction space of the 32nd bit, and store the low-order carry to In the instruction space of the 32nd bit of the instruction B.cond.
需要说明的是,本申请实施例将低位进位存储至扩展指令空间,可以便于确定目标指令的剩余地址的过程中,将低位进位与目标指令的上一指令的剩余地址相加,从而快速计 算出目标指令的剩余地址。It should be noted that, in the embodiment of the present application, the lower carry is stored in the extended instruction space, and the lower carry can be added to the remaining address of the previous instruction of the target instruction in the process of determining the remaining address of the target instruction, thereby quickly calculating The remaining address of the target instruction.
步骤606、将目标指令的上一指令写入一级指令缓存。Step 606: Write the previous instruction of the target instruction into the first level instruction cache.
其中,一级指令缓存中,不同指令的指令空间中存储的低位地址在指令空间的第0比特对齐。示例地,图7所示的指令B.cond、指令CBNZ、指令CBZ、指令TBNZ、指令TBZ、指令B和指令BL均可以为一级指令缓存中的指令,指令CBNZ、指令CBZ、指令TBNZ、指令TBZ、指令B和指令BL中存储的低位地址均在指令空间的第0比特对齐。可选地,取指令单元可以调用处理器的写命令将目标指令的上一指令写入一级指令缓存,详细的写入过程可以参考相关技术,本实施例在此不再赘述。Among them, in the first-level instruction cache, the lower address stored in the instruction space of different instructions is aligned in the 0th bit of the instruction space. For example, the instruction B.cond, the instruction CBNZ, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B, and the instruction BL shown in FIG. 7 may all be instructions in the level one instruction cache, the instruction CBNZ, the instruction CBZ, the instruction TBNZ, The lower bits stored in the instruction TBZ, instruction B, and instruction BL are aligned in the 0th bit of the instruction space. Optionally, the instruction fetching unit may call the write command of the processor to write the previous instruction of the target instruction to the first-level instruction cache. For detailed writing process, reference may be made to related technologies, and details are not described herein again.
需要说明的是,上述步骤601至步骤606通常是在取指令单元获取目标指令之前进行的,下述步骤607至步骤614为取指令单元确定目标指令的虚拟地址的过程,该步骤607至步骤614可以发生在取指令单元获取目标指令的过程中。It should be noted that the foregoing steps 601 to 606 are generally performed before the instruction fetch unit acquires the target instruction, and the following steps 607 to 614 are processes for determining the virtual address of the target instruction by the fetching unit, and the steps 607 to 614 are performed. This can occur during the fetch unit's acquisition of the target instruction.
步骤607、从目标指令的上一指令的指令空间中读取目标指令的低位地址。Step 607: Read the lower address of the target instruction from the instruction space of the previous instruction of the target instruction.
根据步骤601至步骤606的描述不难理解,该目标指令的低位地址为将目标指令的上一指令写入一级指令缓存之前计算得到并存储在上一指令的指令空间中的地址。According to the description of steps 601 to 606, it is not difficult to understand that the lower address of the target instruction is an address calculated and stored in the instruction space of the previous instruction before the previous instruction of the target instruction is written into the level one instruction cache.
可选地,取指令单元可以调用处理器的读命令从目标指令的上一指令的指令空间中读取目标指令的低位地址,详细的读取过程可以参考相关技术,本实施例在此不再赘述。Optionally, the fetching instruction unit may call the read command of the processor to read the lower address of the target instruction from the instruction space of the previous instruction of the target instruction, and the detailed reading process may refer to related technologies, and the embodiment does not stop here. Narration.
步骤608、从目标指令的上一指令所包含的偏移地址中确定目标指令的上一指令所包含的偏移地址的高位地址。Step 608: Determine an upper address of an offset address included in a previous instruction of the target instruction from an offset address included in a previous instruction of the target instruction.
其中,目标指令的上一指令所包含的偏移地址由该偏移地址的高位地址和该偏移地址的低位地址组成。取指令单元可以将该偏移地址中,除上述步骤602中确定的偏移地址的低位地址之外的地址确定为该偏移地址的高位地址。示例地,假设目标指令的上一指令所包含的偏移地址为19比特,目标指令的上一指令所包含的偏移地址的低位地址为该偏移地址中最低的12比特,则目标指令的上一指令所包含的偏移地址的高位地址为该19比特的偏移地址中,除最低的12比特之外的地址,也即是,目标指令的上一指令所包含的偏移地址的高位地址为该偏移地址中最高的7比特。The offset address included in the previous instruction of the target instruction is composed of the upper address of the offset address and the lower address of the offset address. The instruction fetch unit may determine, in the offset address, an address other than the lower address of the offset address determined in the above step 602 as the upper address of the offset address. For example, if the previous instruction of the target instruction includes an offset address of 19 bits, and the lower address of the offset address included in the previous instruction of the target instruction is the lowest 12 bits of the offset address, the target instruction The upper address of the offset address included in the previous instruction is the address of the 19-bit offset address except the lowest 12 bits, that is, the high bit of the offset address included in the previous instruction of the target instruction. The address is the highest 7 bits of the offset address.
可选地,假设虚拟地址为PC地址,imm表示目标指令的上一指令所包含的偏移地址,imm_lo表示目标指令的上一指令所包含的偏移地址的低位地址,imm_hi表示目标指令的上一指令所包含的偏移地址的高位地址,则imm_hi可以为imm中除imm_lo之外的地址。在本实施例中,imm、imm_hi和imm_lo的关系可以采用下述方程式(2)表示:Optionally, it is assumed that the virtual address is a PC address, imm represents an offset address included in a previous instruction of the target instruction, imm_lo represents a lower address of the offset address included in the previous instruction of the target instruction, and imm_hi represents the target instruction. The upper address of the offset address contained in an instruction, imm_hi can be an address other than imm_lo in imm. In the present embodiment, the relationship of imm, imm_hi, and imm_lo can be expressed by the following equation (2):
方程式(2)imm={imm_hi,imm_lo}。Equation (2) imm = {imm_hi, imm_lo}.
步骤609、根据目标指令的上一指令所包含的偏移地址的高位地址,从目标指令的上一指令的虚拟地址中确定目标指令的上一指令的中位地址。Step 609: Determine a median address of a previous instruction of the target instruction from the virtual address of the previous instruction of the target instruction according to the upper address of the offset address included in the previous instruction of the target instruction.
其中,目标指令的上一指令的中位地址与目标指令的上一指令所包含的偏移地址的高位地址对齐且宽度相等。取指令单元可以将目标指令的上一指令的虚拟地址中,与偏移地址的高位地址对齐且宽度相等的部分确定为目标指令的上一指令的中位地址,该目标指令的上一指令的中位地址与目标指令的上一指令的低位地址连续。可选地,取指令单元可以将与目标指令的上一指令的低位地址相邻的d比特确定为目标指令的上一指令的中位地址,d表示偏移地址的高位地址的宽度。示例地,假设目标指令的上一指令所包含的偏移地址为该偏移地址中最高的7比特,则取指令单元可以将目标指令的上一指令的虚拟地址中,与 目标指令的上一指令的低位地址相邻的7比特确定为目标指令的上一指令的中位地址。The median address of the previous instruction of the target instruction is aligned with the upper address of the offset address included in the previous instruction of the target instruction and has the same width. The instruction fetching unit may determine, in the virtual address of the previous instruction of the target instruction, a portion aligned with the upper address of the offset address and having the same width as the median address of the previous instruction of the target instruction, and the instruction of the previous instruction of the target instruction The median address is contiguous with the lower address of the previous instruction of the target instruction. Alternatively, the fetching unit may determine the d bit adjacent to the lower address of the previous instruction of the target instruction as the median address of the previous instruction of the target instruction, and d represents the width of the upper address of the offset address. For example, if the offset instruction included in the previous instruction of the target instruction is the highest 7 bits in the offset address, the instruction fetch unit can set the virtual address of the previous instruction of the target instruction with the previous one of the target instruction. The 7 bits adjacent to the lower address of the instruction are determined as the median address of the previous instruction of the target instruction.
可选地,假设虚拟地址为PC地址,cur_pc表示目标指令的上一指令的虚拟地址,cur_pc_lo表示目标指令的上一指令的低位地址,cur_pc_mid表示目标指令的上一指令的中位地址,imm_hi表示目标指令的上一指令所包含的偏移地址的高位地址,则cur_pc_mid为cur_pc中与cur_pc_lo相邻的d比特,cur_pc_mid与imm_hi对齐且宽度相等。Optionally, assume that the virtual address is a PC address, cur_pc represents the virtual address of the previous instruction of the target instruction, cur_pc_lo represents the lower address of the previous instruction of the target instruction, cur_pc_mid represents the median address of the previous instruction of the target instruction, and imm_hi represents The upper address of the offset address contained in the previous instruction of the target instruction, cur_pc_mid is the d bit adjacent to cur_pc_lo in cur_pc, and cur_pc_mid is aligned with imm_hi and the width is equal.
步骤610、从扩展指令空间中读取低位进位。Step 610: Read a low carry from the extended instruction space.
其中,扩展指令空间为对上一指令的指令空间进行扩展得到的指令空间,该扩展指令空间为一级指令缓存中的指令空间,该低位进位也即是步骤605中,存储至扩展指令空间的进位。可选地,取指令单元可以调用处理器的读命令从扩展指令空间中读取低位进位,详细的读取过程可以参考相关技术,本实施例在此不再赘述。The extended instruction space is an instruction space obtained by extending the instruction space of the previous instruction, and the extended instruction space is an instruction space in the first-level instruction cache, and the low-level carry is also stored in the extended instruction space in step 605. carry. Optionally, the instruction fetch unit can call the read command of the processor to read the lower carry from the extended instruction space. For a detailed read process, reference may be made to the related art, and details are not described herein again.
步骤611、将目标指令的上一指令的中位地址、目标指令的上一指令所包含的偏移地址的高位地址和该低位进位相加,得到目标指令的中位地址。 Step 611, adding the median address of the previous instruction of the target instruction, the upper address of the offset address included in the previous instruction of the target instruction, and the lower carry, to obtain the median address of the target instruction.
取指令单元可以将目标指令的上一指令的中位地址、目标指令的上一指令所包含的偏移地址的高位地址和低位进位相加按位相加,得到目标指令的中位地址,该目标指令的中位地址与目标指令的上一指令的中位地址对齐且宽度相等。示例地,当目标指令的上一指令的中位地址为目标指令的上一指令的虚拟地址中,与该上一指令的低位地址相邻的7比特,且偏移地址的高位地址为偏移地址最高的7比特时,目标指令的中位地址也为7比特,且目标指令的中位地址与目标指令的上一指令的中位地址对齐。The instruction fetch unit may add the median address of the previous instruction of the target instruction, the upper address and the lower carry of the offset address included in the previous instruction of the target instruction, and add the bitwise address to obtain the median address of the target instruction. The median address of the target instruction is aligned with the median address of the previous instruction of the target instruction and the width is equal. For example, when the median address of the previous instruction of the target instruction is the virtual address of the previous instruction of the target instruction, 7 bits adjacent to the lower address of the previous instruction, and the upper address of the offset address is offset When the address is the highest 7 bits, the median address of the target instruction is also 7 bits, and the median address of the target instruction is aligned with the median address of the previous instruction of the target instruction.
可选地,假设虚拟地址为PC地址,br_trgt表示目标指令的虚拟地址,br_trgt_mid表示目标指令的中位地址,cur_pc_mid表示目标指令的上一指令的中位地址,imm_hi表示目标指令的上一指令所包含的偏移地址的高位地址,C1表示低位进位,则br_trgt_mid为cur_pc_mid、imm_hi与C1相加得到的目标指令的中位地址,br_trgt_mid与cur_pc_mid对齐且宽度相等。Optionally, assume that the virtual address is a PC address, br_trgt represents the virtual address of the target instruction, br_trgt_mid represents the median address of the target instruction, cur_pc_mid represents the median address of the previous instruction of the target instruction, and imm_hi represents the previous instruction of the target instruction. The upper address of the included offset address, C1 represents the low carry, then br_trgt_mid is the median address of the target instruction obtained by adding cur_pc_mid, imm_hi and C1, and br_trgt_mid is aligned with cur_pc_mid and the width is equal.
步骤612、从目标指令的上一指令的虚拟地址中确定目标指令的上一指令的高位地址。Step 612: Determine a high address of a previous instruction of the target instruction from a virtual address of a previous instruction of the target instruction.
其中,目标指令的上一指令的虚拟地址由目标指令的上一指令的高位地址、目标指令的上一指令的中位地址和目标指令的上一指令的低位地址组成。The virtual address of the previous instruction of the target instruction is composed of the upper address of the previous instruction of the target instruction, the median address of the previous instruction of the target instruction, and the lower address of the previous instruction of the target instruction.
取指令单元可以将目标指令的上一指令的虚拟地址中,除上述602确定的目标指令的上一指令的低位地址,以及上述步骤609中确定的目标指令的上一指令的中位地址之外的地址确定为目标指令的上一指令的高位地址。示例地,假设目标指令的上一指令的虚拟地址为64比特,目标指令的上一指令的低位地址为该上一指令的虚拟地址中最低的12比特,目标指令的上一指令的中位地址为该上一指令的虚拟地址中与该最低的12比特相邻的7比特,则目标指令的上一指令的高位地址为目标指令的上一指令的虚拟地址中最高的45比特。The fetching unit may set the virtual address of the previous instruction of the target instruction, in addition to the lower address of the previous instruction of the target instruction determined by 602 above, and the median address of the previous instruction of the target instruction determined in step 609 above. The address is determined as the upper address of the previous instruction of the target instruction. For example, assuming that the virtual address of the previous instruction of the target instruction is 64 bits, the lower address of the previous instruction of the target instruction is the lowest 12 bits of the virtual address of the previous instruction, and the median address of the previous instruction of the target instruction. For the 7 bits adjacent to the lowest 12 bits of the virtual address of the previous instruction, the upper address of the previous instruction of the target instruction is the highest 45 bits of the virtual address of the previous instruction of the target instruction.
可选地,假设虚拟地址为PC地址,cur_pc表示目标指令的上一指令的虚拟地址,cur_pc_lo表示目标指令的上一指令的低位地址,cur_pc_mid表示目标指令的上一指令的中位地址,cur_pc_hi表示目标指令的上一指令的高位地址,则cur_pc_hi为cur_pc中,除cur_pc_lo和cur_pc_mid之外的地址。在本实施例中,cur_pc、cur_pc_lo、cur_pc_mid和cur_pc_hi的关系可以采用下述方程式(3)表示:Optionally, assume that the virtual address is a PC address, cur_pc represents the virtual address of the previous instruction of the target instruction, cur_pc_lo represents the lower address of the previous instruction of the target instruction, cur_pc_mid represents the median address of the previous instruction of the target instruction, and cur_pc_hi represents The upper address of the previous instruction of the target instruction, then cur_pc_hi is the address in cur_pc except for cur_pc_lo and cur_pc_mid. In the present embodiment, the relationship of cur_pc, cur_pc_lo, cur_pc_mid, and cur_pc_hi can be expressed by the following equation (3):
方程式(3)cur_pc={cur_pc_hi,cur_pc_mid,cur_pc_lo}。Equation (3) cur_pc = {cur_pc_hi, cur_pc_mid, cur_pc_lo}.
步骤613、根据中位进位、目标指令的上一指令的高位地址和目标指令的上一指令所包 含的偏移地址的符号,确定目标指令的高位地址。Step 613: Determine a high-order address of the target instruction according to the median carry, the upper address of the previous instruction of the target instruction, and the symbol of the offset address included in the previous instruction of the target instruction.
其中,中位进位为将目标指令的上一指令的中位地址、目标指令的上一指令所包含的偏移地址的高位地址和低位进位相加产生的进位,中位进位可以为0或1,当该中位进位为0时,可以理解为:在将目标指令的上一指令的中位地址、目标指令的上一指令所包含的偏移地址的高位地址和低位进位按位相加的过程中没有产生进位。偏移地址的符号为偏移地址的最高位的符号,偏移地址的符号可以为0或1。The median carry is a carry generated by adding the median address of the previous instruction of the target instruction, the upper address of the offset address included in the previous instruction of the target instruction, and the lower carry. The median carry can be 0 or 1. When the median carry is 0, it can be understood as: adding the median address of the previous instruction of the target instruction, the upper address and the lower carry of the offset address included in the previous instruction of the target instruction by bit. There is no carry in the process. The sign of the offset address is the sign of the most significant bit of the offset address, and the sign of the offset address may be 0 or 1.
可选地,取指令单元根据中位进位、目标指令的上一指令的高位地址和目标指令的上一指令所包含的偏移地址的符号,确定目标指令的高位地址可以包括:当中位进位为1且偏移地址的符号为0时,取指令单元确定目标指令的高位地址等于目标指令的上一指令的高位地址加1;当中位进位为0且偏移地址的符号为0,或者,中位进位为1且偏移地址的符号为1时,取指令单元确定目标指令的高位地址等于目标指令的上一指令的高位地址;当中位进位为0且偏移地址的符号为1时,取指令单元确定目标指令的高位地址等于目标指令上一指令的高位地址减1。Optionally, the instruction fetch unit determines, according to the median carry, the upper address of the previous instruction of the target instruction, and the symbol of the offset address included in the previous instruction of the target instruction, the upper address of the target instruction may include: the median carry is 1 and the offset address symbol is 0, the instruction fetch unit determines that the upper address of the target instruction is equal to the upper address of the previous instruction of the target instruction plus one; the middle carry is 0 and the sign of the offset address is 0, or, When the bit carry is 1 and the sign of the offset address is 1, the instruction fetch unit determines that the upper address of the target instruction is equal to the upper address of the previous instruction of the target instruction; when the median carry is 0 and the sign of the offset address is 1, The instruction unit determines that the upper address of the target instruction is equal to the upper address of the previous instruction of the target instruction minus one.
可选地,假设虚拟地址为PC地址,br_trgt表示目标指令的虚拟地址,br_trgt_hi表示目标指令的高位地址,imm[*]表示偏移地址的符号,cur_pc_hi表示目标指令的上一指令的高位地址,C2表示中位进位,则当C2=1且imm[*]=0时,br_trgt_hi=cur_pc_hi+1;当C2=0且imm[*]=0,或者,C2=1且imm[*]=1时,br_trgt_hi=cur_pc_hi;当C2=0且imm[*]=1时,br_trgt_hi=cur_pc_hi-1。Optionally, assuming that the virtual address is a PC address, br_trgt represents a virtual address of the target instruction, br_trgt_hi represents a high-order address of the target instruction, imm[*] represents a symbol of the offset address, and cur_pc_hi represents a high-order address of a previous instruction of the target instruction, C2 represents the median carry, then when C2=1 and imm[*]=0, br_trgt_hi=cur_pc_hi+1; when C2=0 and imm[*]=0, or, C2=1 and imm[*]=1 When br_trgt_hi=cur_pc_hi; when C2=0 and imm[*]=1, br_trgt_hi=cur_pc_hi-1.
需要说明的是,上述步骤608至步骤613可以理解为,在地址映射为PIPT地址映射或VIPT地址映射时,对图5所示实施例中的步骤505的细化。It should be noted that the above steps 608 to 613 can be understood as the refinement of step 505 in the embodiment shown in FIG. 5 when the address mapping is a PIPT address mapping or a VIPT address mapping.
步骤614、将目标指令的低位地址、目标指令的中位地址与目标指令的高位地址合并,得到目标指令的虚拟地址。Step 614: Combine the lower address of the target instruction, the median address of the target instruction, and the upper address of the target instruction to obtain a virtual address of the target instruction.
可选地,取指令单元可以按照地址位的高低将目标指令的低位地址、目标指令的中位地址与目标指令的高位地址合并,得到目标指令的虚拟地址,且在同一虚拟地址中,地址位从右向左依次升高。例如,取指令单元将目标指令的中位地址排布在目标指令的低位地址的高位,将目标指令的高位地址排布在目标指令的中位地址的高位,得到目标指令的虚拟地址。Optionally, the instruction fetch unit may combine the lower address of the target instruction, the median address of the target instruction, and the upper address of the target instruction according to the address bit to obtain a virtual address of the target instruction, and in the same virtual address, the address bit Raise from right to left. For example, the instruction fetch unit arranges the median address of the target instruction at the upper bit of the lower address of the target instruction, and arranges the upper address of the target instruction at the upper bit of the median address of the target instruction to obtain the virtual address of the target instruction.
可选地,假设虚拟地址为PC地址,br_trgt表示目标指令的虚拟地址,br_trgt_lo表示目标指令的低位地址,br_trgt_mid表示目标指令的中位地址,br_trgt_hi表示目标指令的高位地址,则在本实施例中,br_trgt、br_trgt_lo、br_trgt_mid和br_trgt_hi的关系可以采用下述方程式(4)表示:Optionally, assuming that the virtual address is a PC address, br_trgt represents a virtual address of the target instruction, br_trgt_lo represents a lower address of the target instruction, br_trgt_mid represents a median address of the target instruction, and br_trgt_hi represents a high-order address of the target instruction, in this embodiment The relationship of br_trgt, br_trgt_lo, br_trgt_mid, and br_trgt_hi can be expressed by the following equation (4):
方程式(4)br_trgt={br_trgt_hi,br_trgt_mid,br_trgt_lo}。Equation (4) br_trgt = {br_trgt_hi, br_trgt_mid, br_trgt_lo}.
需要说明的是,本申请实施例提供的虚拟地址确定方法步骤的先后顺序可以进行适当调整,步骤也可以根据情况进行相应增减,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化的方法,都应涵盖在本申请的保护范围之内,因此不再赘述。It should be noted that the sequence of the steps of the virtual address determining method provided by the embodiment of the present application may be appropriately adjusted, and the steps may also be correspondingly increased or decreased according to the situation, and any person skilled in the art may be within the technical scope disclosed in the present application. The methods that can be easily thought of as changes are covered by the scope of protection of the present application, and therefore will not be described again.
综上所述,本申请实施例提供的虚拟地址确定方法,由于目标指令的低位地址是从目标指令的上一指令的指令空间中读取到的,在确定目标指令的虚拟地址的过程中,无需计算目标指令的低位地址,只需要计算目标指令的剩余地址(剩余地址为目标指令的虚拟地 址中除低位地址之外的地址),然后将目标指令的剩余地址与目标指令的低位地址合并就可以得到目标指令的虚拟地址,因此可以减小确定目标指令的虚拟地址的计算量,有助于解决确定目标指令的虚拟地址的时延较大,处理器的处理速度较慢的问题,减小确定目标指令的虚拟地址的时延,提高处理器的处理速度。In summary, the virtual address determining method provided by the embodiment of the present application, in the process of determining the virtual address of the target instruction, is that the lower address of the target instruction is read from the instruction space of the previous instruction of the target instruction. There is no need to calculate the lower address of the target instruction, only the remaining address of the target instruction (the remaining address is the address other than the lower address in the virtual address of the target instruction), and then the remaining address of the target instruction is merged with the lower address of the target instruction. The virtual address of the target instruction can be obtained, so that the calculation amount of the virtual address of the target instruction can be reduced, which helps to solve the problem that the delay of determining the virtual address of the target instruction is large, and the processing speed of the processor is slow, and the problem is reduced. Determine the delay of the virtual address of the target instruction and increase the processing speed of the processor.
本申请实施例提供的虚拟地址确定方法,大大减少了确定虚拟地址过程中,需要进行加法运算的地址宽度,减少了确定虚拟地址的时延;此外,本申请实施例提供的方案无需增加流水线级,避免由于增加流水线级导致的时延,以及避免由于异常、预测错误和缓存丢失等导致处理器的性能下降。The virtual address determining method provided in the embodiment of the present invention greatly reduces the address width of the virtual address in the process of determining the virtual address, and reduces the delay of determining the virtual address. In addition, the solution provided by the embodiment of the present application does not need to increase the pipeline level. To avoid delays due to increased pipeline levels and to avoid processor performance degradation due to exceptions, prediction errors, and cache misses.
以下结合图8和图9对图6所示实施例提供的方案进行举例说明。该图8和图9以虚拟地址为PC地址,且图8以偏移地址的符号为0,图9以偏移地址的符号为1为例进行说明。The solution provided by the embodiment shown in FIG. 6 is exemplified below with reference to FIG. 8 and FIG. 9. 8 and 9 show the virtual address as the PC address, and FIG. 8 shows the offset address as 0, and FIG. 9 shows the offset address as 1 as an example.
其中,在图8和图9中,cur_pc表示目标指令的上一指令的PC地址,cur_pc_lo表示目标指令的上一指令的低位地址,cur_pc_mid表示目标指令的上一指令的中位地址,cur_pc_hi表示目标指令的上一指令的高位地址;imm表示目标指令的上一指令所包含的偏移地址,imm_lo表示目标指令的上一指令所包含的偏移地址的低位地址,imm_hi表示目标指令的上一指令所包含的偏移地址的高位地址;br_trgt表示目标指令的PC地址,br_trgt_lo表示目标指令的低位地址,br_trgt_mid表示目标指令的中位地址,br_trgt_hi表示目标指令的高位地址;In FIG. 8 and FIG. 9, cur_pc represents the PC address of the previous instruction of the target instruction, cur_pc_lo represents the lower address of the previous instruction of the target instruction, cur_pc_mid represents the median address of the previous instruction of the target instruction, and cur_pc_hi represents the target. The upper address of the previous instruction of the instruction; imm indicates the offset address contained in the previous instruction of the target instruction, imm_lo indicates the lower address of the offset address contained in the previous instruction of the target instruction, and imm_hi indicates the previous instruction of the target instruction. The upper address of the included offset address; br_trgt represents the PC address of the target instruction, br_trgt_lo represents the lower address of the target instruction, br_trgt_mid represents the median address of the target instruction, and br_trgt_hi represents the upper address of the target instruction;
C1表示低位进位,C2表示中位进位,在执行图6所示实施例的方案之前,可以先根据imm的符号对imm进行符号扩展,使imm的宽度与cur_pc的宽度相等。C1 represents a low carry, and C2 represents a median carry. Before performing the scheme of the embodiment shown in FIG. 6, the imm may be first sign extended according to the symbol of imm so that the width of the imm is equal to the width of the cur_pc.
如图8和图9所示,在确定br_trgt之前,首先将cur_pc拆分成cur_pc_lo、cur_pc_mid和cur_pc_hi,将imm拆分成imm_lo和imm_hi,cur_pc_lo与imm_lo对齐,cur_pc_mid与imm_hi对齐,此过程可以与图6所示实施例的步骤601和步骤602部分对应;接着,根据步骤603提供的方案,采用公式{C1,br_trgt_lo}=cur_pc_lo+imm_lo计算得到br_trgt_lo并产生低位进位C1;之后,根据步骤604提供的方案将br_trgt_lo存储至目标指令的上一指令的指令空间,根据步骤605提供的方案将C1存储至扩展指令空间;最后,根据步骤606提供的方案将目标指令的上一指令写入一级指令缓存。As shown in Figure 8 and Figure 9, before determining br_trgt, first split cur_pc into cur_pc_lo, cur_pc_mid and cur_pc_hi, split imm into imm_lo and imm_hi, cur_pc_lo is aligned with imm_lo, and cur_pc_mid is aligned with imm_hi. Step 601 and step 602 of the embodiment shown in FIG. 6 correspond to each other; then, according to the scheme provided in step 603, br_trgt_lo is calculated by using the formula {C1, br_trgt_lo}=cur_pc_lo+imm_lo and a lower carry C1 is generated; after that, according to step 604 The scheme stores br_trgt_lo to the instruction space of the previous instruction of the target instruction, and stores C1 into the extended instruction space according to the scheme provided in step 605; finally, writes the previous instruction of the target instruction to the first-level instruction cache according to the scheme provided in step 606. .
如图8和图9所示,在确定br_trgt的过程中,首先,根据步骤607提供的方案从目标指令的上一指令的指令空间中读取br_trgt_lo;接着,根据步骤608提供的方案确定imm_hi,并根据步骤609提供的方案确定cur_pc_mid;之后,步骤610提供的方案从扩展指令空间中读取C1;然后,根据步骤611提供的方案,采用公式{C2,br_trgt_mid}=cur_pc_mid+imm_hi+C1计算得到br_trgt_mid并产生中位进位C2;之后,根据步骤612提供的方案确定cur_pc_hi,并根据步骤613提供的方案,根据cur_pc_hi、偏移地址的符号和C2确定br_trgt_hi,如图8所示,如果C2=1且偏移地址的符号为0,则br_trgt_hi=cur_pc_hi+1,如果C2=0且偏移地址的符号为0,则br_trgt_hi=cur_pc_hi,如图9所示,如果C2=1且偏移地址的符号为1,则br_trgt_hi=cur_pc_hi,如果C2=0且偏移地址的符号为1,则br_trgt_hi=cur_pc_hi-1;最后,根据步骤614提供的方案将br_trgt_lo、br_trgt_mid和br_trgt_hi合并得到br_trgt,br_trgt={br_trgt_hi,br_trgt_mid,br_trgt_lo}。As shown in FIG. 8 and FIG. 9, in the process of determining br_trgt, first, br_trgt_lo is read from the instruction space of the previous instruction of the target instruction according to the scheme provided in step 607; then, imm_hi is determined according to the scheme provided in step 608, And determining cur_pc_mid according to the scheme provided in step 609; afterwards, the scheme provided in step 610 reads C1 from the extended instruction space; then, according to the scheme provided in step 611, using the formula {C2, br_trgt_mid}=cur_pc_mid+imm_hi+C1 Br_trgt_mid and generate a median carry C2; thereafter, determine cur_pc_hi according to the scheme provided in step 612, and according to the scheme provided in step 613, determine br_trgt_hi according to cur_pc_hi, the sign of the offset address, and C2, as shown in FIG. 8, if C2=1 And the sign of the offset address is 0, then br_trgt_hi=cur_pc_hi+1, if C2=0 and the sign of the offset address is 0, then br_trgt_hi=cur_pc_hi, as shown in FIG. 9, if C2=1 and the symbol of the offset address Is 1, then br_trgt_hi=cur_pc_hi, if C2=0 and the sign of the offset address is 1, then br_trgt_hi=cur_pc_hi-1; finally, according to the scheme provided in step 614, br_t Rgt_lo, br_trgt_mid, and br_trgt_hi are combined to obtain br_trgt, br_trgt={br_trgt_hi, br_trgt_mid, br_trgt_lo}.
根据以上描述可知,在确定br_trgt的过程中,br_trgt_lo可以从目标指令的上一指令的 指令空间中读取到,br_trgt_hi可以根据C2以及偏移地址的符号在cur_pc_hi+1、cur_pc_hi和cur_pc_hi-1中选择,只需要计算出br_trgt_mid,就可以将br_trgt_lo、br_trgt_mid和br_trgt_hi合并得到br_trgt,大大减少了确定br_trgt的时延。例如,当cur_pc为一个64比特的虚拟地址,页表的大小为4KB(4KB=212bit),偏移地址的宽度为26比特时,由于12比特的br_trgt_lo可以预计算并存储目标指令的上一指令的指令空间中,38(38=64-26)比特的br_trgt_hi可以在前一级流水线级预先确定,因此,计算br_trgt的过程由相关技术中的宽度为64比特的cur_pc+imm的运算变成宽度为14(14=26-12,)比特的cur_pc_mid+imm_hi的运算,大大减少了确定br_trgt的时延。According to the above description, in the process of determining br_trgt, br_trgt_lo can be read from the instruction space of the previous instruction of the target instruction, and br_trgt_hi can be based on C2 and the symbols of the offset address in cur_pc_hi+1, cur_pc_hi, and cur_pc_hi-1. Alternatively, only br_trgt_mid needs to be calculated, and br_trgt_lo, br_trgt_mid and br_trgt_hi can be combined to obtain br_trgt, which greatly reduces the delay of determining br_trgt. For example, when cur_pc is a 64-bit virtual address, the size of the page table is 4 KB (4 KB = 212 bits), and the width of the offset address is 26 bits, since the 12-bit br_trgt_lo can pre-calculate and store the previous instruction of the target instruction. In the instruction space, the br_trgt_hi of 38 (38=64-26) bits can be predetermined at the previous stage of the pipeline stage, and therefore, the process of calculating br_trgt is changed to the width by the operation of the 64-bit width of cur_pc+imm in the related art. The operation of cur_pc_mid+imm_hi of 14 (14=26-12,) bits greatly reduces the delay in determining br_trgt.
请参考图10,其示出了本申请实施例提供的又一种虚拟地址确定方法的方法流程图,该虚拟地址确定方法可以用于确定目标指令的虚拟地址,该图10以地址映射为直接映射为例进行说明,在直接映射中,目标指令的剩余地址可以包括高位地址。参见图10,该方法包括:Please refer to FIG. 10, which is a flowchart of still another method for determining a virtual address according to an embodiment of the present application. The virtual address determining method may be used to determine a virtual address of a target instruction. The mapping is described as an example. In the direct mapping, the remaining address of the target instruction may include a high address. Referring to Figure 10, the method includes:
步骤1001、确定目标指令的上一指令的虚拟地址和目标指令的上一指令所包含的偏移地址。Step 1001: Determine a virtual address of a previous instruction of the target instruction and an offset address included in a previous instruction of the target instruction.
该步骤1001的实现过程可以参考图6所示实施例的步骤601,本实施例在此不再赘述。For the implementation of the step 1001, reference may be made to the step 601 of the embodiment shown in FIG. 6, which is not described herein again.
步骤1002、根据目标指令的上一指令所包含的偏移地址确定目标指令的上一指令的低位地址。Step 1002: Determine a lower address of a previous instruction of the target instruction according to an offset address included in a previous instruction of the target instruction.
其中,目标指令的上一指令的低位地址与目标指令的上一指令所包含的偏移地址对齐且宽度相等。可选地,假设目标指令的上一指令所包含的偏移地址的宽度为w,w为大于或等于1的整数,则取指令单元可以将目标指令的上一指令的虚拟地址中最低的w比特确定为目标指令的上一指令的低位地址,其中,虚拟地址为可以PC地址。The lower address of the previous instruction of the target instruction is aligned with the offset address included in the previous instruction of the target instruction and has the same width. Optionally, assuming that the offset of the previous instruction included in the target instruction is w, w is an integer greater than or equal to 1, the instruction fetch unit may be the lowest w of the virtual address of the previous instruction of the target instruction. The bit is determined as the lower address of the previous instruction of the target instruction, wherein the virtual address is a PC address.
可选地,假设虚拟地址为PC地址,cur_pc表示目标指令的上一指令的虚拟地址,imm表示目标指令的上一指令所包含的偏移地址,cur_pc_lo表示目标指令的上一指令的低位地址,则cur_pc_lo可以为cur_pc最低的w比特,该cur_pc_lo与imm对齐且宽度相等。Optionally, assuming that the virtual address is a PC address, cur_pc represents a virtual address of a previous instruction of the target instruction, imm represents an offset address included in a previous instruction of the target instruction, and cur_pc_lo represents a lower address of a previous instruction of the target instruction, Then cur_pc_lo can be the lowest w bit of cur_pc, which is aligned with imm and has the same width.
步骤1003、将目标指令的上一指令的低位地址与目标指令的上一指令所包含的偏移地址相加,得到目标指令的低位地址。Step 1003: Add the lower address of the previous instruction of the target instruction and the offset address included in the previous instruction of the target instruction to obtain the lower address of the target instruction.
取指令单元可以将目标指令的上一指令的低位地址与目标指令的上一指令所包含的偏移地址按位相加,得到目标指令的低位地址,该目标指令的低位地址与目标指令的上一指令的低位地址对齐且宽度相等。可选地,当目标指令的上一指令的低位地址为目标指令的上一指令的虚拟地址中最低的w比特,且偏移地址为w比特时,则目标指令的低位地址也为w比特,且目标指令的低位地址与目标指令的上一指令的低位地址对齐。The instruction fetch unit may add the lower address of the previous instruction of the target instruction to the offset address included in the previous instruction of the target instruction to obtain the lower address of the target instruction, and the lower address of the target instruction and the target instruction The lower address of an instruction is aligned and the width is equal. Optionally, when the lower address of the previous instruction of the target instruction is the lowest w bit of the virtual address of the previous instruction of the target instruction, and the offset address is w bits, the lower address of the target instruction is also w bits. And the lower address of the target instruction is aligned with the lower address of the previous instruction of the target instruction.
可选地,假设虚拟地址为PC地址,br_trgt表示目标指令的虚拟地址,br_trgt_lo表示目标指令的低位地址,imm表示目标指令的上一指令所包含的偏移地址,则br_trgt_lo为cur_pc_lo与imm相加得到的目标指令的低位地址,br_trgt_lo与cur_pc_lo对齐且宽度相等。Optionally, assuming that the virtual address is a PC address, br_trgt represents a virtual address of the target instruction, br_trgt_lo represents a lower address of the target instruction, and imm represents an offset address included in a previous instruction of the target instruction, and br_trgt_lo is added to the im_cur_pc_lo and the imm The lower address of the resulting target instruction, br_trgt_lo is aligned with cur_pc_lo and has the same width.
需要说明的是,上述步骤1001至步骤1003可以理解为,在地址映射为直接映射时,对图5所示实施例中的步骤501的细化。It should be noted that the above steps 1001 to 1003 can be understood as the refinement of step 501 in the embodiment shown in FIG. 5 when the address mapping is direct mapping.
步骤1004、将目标指令的低位地址存储至目标指令的上一指令的指令空间。Step 1004: Store the lower address of the target instruction to the instruction space of the previous instruction of the target instruction.
其中,不同指令的指令空间中存储的低位地址在指令空间的第0比特对齐。The lower address stored in the instruction space of different instructions is aligned in the 0th bit of the instruction space.
可选地,取指令单元可以先对目标指令的上一指令的指令空间中存储的偏移地址进行 位置调整,使该偏移地址在该上一指令的指令空间的第0比特对齐,然后再删除该偏移地址的低位地址得到空闲指令空间,将目标指令的低位地址存储至该空闲指令空间,从而使不同指令的指令空间中存储的低位地址在指令空间的第0比特对齐。Optionally, the instruction fetching unit may first adjust the offset address stored in the instruction space of the previous instruction of the target instruction, so that the offset address is aligned in the 0th bit of the instruction space of the previous instruction, and then Deleting the lower address of the offset address results in an idle instruction space, and stores the lower address of the target instruction into the free instruction space, thereby aligning the lower address stored in the instruction space of the different instructions in the 0th bit of the instruction space.
示例地,请参考图11,其示出了本申请实施例提供的一种指令空间的示意图,参见图11,指令B.cond、指令CBNZ、指令CBZ、指令TBNZ、指令TBZ、指令B和指令BL中,每个指令的指令空间为第0比特至第31比特,指令B.cond、指令CBNZ、指令CBZ、指令TBNZ、指令TBZ、指令B和指令BL中均存储有低位地址,且不同指令中存储的可以是不同目标指令的低位地址,指令B.cond、指令CBNZ、指令CBZ、指令TBNZ、指令TBZ、指令B和指令BL的指令空间中存储的低位地址在指令空间的第0比特对齐。在本申请实施例中,目标指令的上一指令可以为图11中的指令CBNZ,目标指令的低位地址可以为指令CBNZ的指令空间中的br_trgt_lo[18:0],br_trgt_lo[18:0]表示目标指令的低位地址的宽度为19比特,且目标指令的低位地址从目标指令的上一指令的第0比特开始。对比图4和图11可以看出,取指令单元将图4所示的指令CBNZ的指令空间中存储的偏移地址从第5比特至第23比特调整至第0比特至第18比特,且删除了偏移地址得到空闲指令空间,该空闲指令空间为从指令CBNZ的第0比特至第18比特的空间,取指令单元将br_trgt_lo[18:0]存储至该空闲指令空间。指令B.cond、指令CBZ、指令TBNZ、指令TBZ、指令B和指令BL的情况与指令CBNZ的情况类似,在此不再赘述。For example, please refer to FIG. 11 , which shows a schematic diagram of an instruction space provided by an embodiment of the present application. Referring to FIG. 11 , an instruction B.cond, an instruction CBNZ, an instruction CBZ, an instruction TBNZ, an instruction TBZ, an instruction B, and an instruction. In BL, the instruction space of each instruction is the 0th bit to the 31st bit, and the instruction B.cond, the instruction CBNZ, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B, and the instruction BL all store the lower address, and the different instructions The lower address stored in the instruction space can be the lower address of the instruction target space. The lower address stored in the instruction space of the instruction B.cond, the instruction CBNZ, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B and the instruction BL is aligned in the 0th bit of the instruction space. . In the embodiment of the present application, the previous instruction of the target instruction may be the instruction CBNZ in FIG. 11, and the lower address of the target instruction may be br_trgt_lo[18:0] in the instruction space of the instruction CBNZ, and br_trgt_lo[18:0] represents The lower address of the target instruction has a width of 19 bits, and the lower address of the target instruction starts from the 0th bit of the previous instruction of the target instruction. 4 and FIG. 11, the instruction fetch unit adjusts the offset address stored in the instruction space of the instruction CBNZ shown in FIG. 4 from the 5th bit to the 23rd bit to the 0th bit to the 18th bit, and deletes The offset address obtains an idle instruction space, which is the space from the 0th bit to the 18th bit of the instruction CBNZ, and the fetching unit stores br_trgt_lo[18:0] into the idle instruction space. The case of the instruction B.cond, the instruction CBZ, the instruction TBNZ, the instruction TBZ, the instruction B, and the instruction BL is similar to the case of the instruction CBNZ, and will not be described herein.
步骤1005、从目标指令的上一指令的虚拟地址中确定目标指令的上一指令的高位地址。Step 1005: Determine a high address of a previous instruction of the target instruction from a virtual address of a previous instruction of the target instruction.
其中,目标指令的上一指令的虚拟地址由该上一指令的高位地址和该上一指令的低位地址组成。取指令单元可以将目标指令的上一指令的虚拟地址中,除上述步骤1002中确定的低位地址之外的地址确定为目标指令的上一指令的高位地址。示例地,假设目标指令的上一指令的虚拟地址为64比特,目标指令的上一指令的低位地址为该上一指令的虚拟地址中最低的19比特,则目标指令的上一指令的高位地址为该64比特中,除最低的19比特之外的地址,也即是,目标指令的上一指令的高位地址为该上一指令的虚拟地址中最高的45比特。The virtual address of the previous instruction of the target instruction is composed of the upper address of the previous instruction and the lower address of the previous instruction. The instruction fetch unit may determine, in the virtual address of the previous instruction of the target instruction, an address other than the lower address determined in the above step 1002 as the upper address of the previous instruction of the target instruction. For example, assuming that the virtual address of the previous instruction of the target instruction is 64 bits, and the lower address of the previous instruction of the target instruction is the lowest 19 bits of the virtual address of the previous instruction, the upper address of the previous instruction of the target instruction For the 64 bits, the address other than the lowest 19 bits, that is, the upper address of the previous instruction of the target instruction is the highest 45 bits of the virtual address of the previous instruction.
可选地,假设虚拟地址为PC地址,cur_pc表示目标指令的上一指令的虚拟地址,cur_pc_lo表示目标指令的上一指令的低位地址,cur_pc_hi表示目标指令的上一指令的高位地址,则cur_pc_hi为cur_pc中除cur_pc_lo之外的地址。在本实施例中,cur_pc、cur_pc_lo和cur_pc_hi的关系可以采用下述方程式(5)表示:Optionally, assuming that the virtual address is a PC address, cur_pc represents the virtual address of the previous instruction of the target instruction, cur_pc_lo represents the lower address of the previous instruction of the target instruction, and cur_pc_hi represents the upper address of the previous instruction of the target instruction, then cur_pc_hi is An address other than cur_pc_lo in cur_pc. In the present embodiment, the relationship of cur_pc, cur_pc_lo, and cur_pc_hi can be expressed by the following equation (5):
方程式(5)cur_pc={cur_pc_hi,cur_pc_lo}。Equation (5) cur_pc={cur_pc_hi, cur_pc_lo}.
步骤1006、根据低位进位、目标指令的上一指令的高位地址和目标指令的上一指令所包含的偏移地址的符号,确定目标指令的高位地址。Step 1006: Determine the upper address of the target instruction according to the lower carry, the upper address of the previous instruction of the target instruction, and the symbol of the offset address included in the previous instruction of the target instruction.
在本实施例中,低位进位为将目标指令的上一指令的低位地址和目标指令的上一指令所包含的偏移地址相加产生的进位,该低位进位可以为0或1,当该低位进位为0时,可以理解为:在将目标指令的上一指令的低位地址与目标指令的上一指令所包含的偏移地址按位相加的过程中没有产生进位。偏移地址的符号为偏移地址的最高位的符号,该偏移地址的符号可以为0或1。In this embodiment, the lower carry is a carry generated by adding the lower address of the previous instruction of the target instruction and the offset address included in the previous instruction of the target instruction, and the lower carry can be 0 or 1, when the low bit is When the carry is 0, it can be understood that there is no carry in the process of adding the lower address of the previous instruction of the target instruction to the offset address included in the previous instruction of the target instruction. The sign of the offset address is the sign of the most significant bit of the offset address, and the sign of the offset address may be 0 or 1.
可选地,取指令单元根据低位进位、目标指令的上一指令的高位地址和目标指令的上一指令所包含的偏移地址的符号,确定目标指令的高位地址可以包括:当低位进位为1且 偏移地址的符号为0时,取指令单元确定目标指令的高位地址等于目标指令的上一指令的高位地址加1;当低位进位为0且偏移地址的符号为0,或者,低位进位为1且偏移地址的符号为1时,取指令单元确定目标指令的高位地址等于目标指令的上一指令的高位地址;当低位进位为0且偏移地址的符号为1时,取指令单元确定目标指令的高位地址等于目标指令的上一指令的高位地址减1。Optionally, the instruction fetch unit determines, according to the lower carry, the upper address of the previous instruction of the target instruction, and the symbol of the offset address included in the previous instruction of the target instruction, determining that the upper address of the target instruction may include: when the low carry is 1 And when the sign of the offset address is 0, the instruction fetch unit determines that the upper address of the target instruction is equal to the upper address of the previous instruction of the target instruction plus one; when the lower carry is 0 and the sign of the offset address is 0, or the low carry When the symbol of the offset address is 1, the instruction fetch unit determines that the upper address of the target instruction is equal to the upper address of the previous instruction of the target instruction; when the lower carry is 0 and the sign of the offset address is 1, the instruction fetch unit It is determined that the upper address of the target instruction is equal to the upper address of the previous instruction of the target instruction minus one.
可选地,假设虚拟地址为PC地址,br_trgt表示目标指令的虚拟地址,br_trgt_hi表示目标指令的高位地址,imm[*]表示偏移地址的符号,cur_pc_hi表示目标指令的上一指令的高位地址,C1表示低位进位,则当C1=1且imm[*]=0时,br_trgt_hi=cur_pc_hi+1;当C1=0且imm[*]=0,或者,C1=1且imm[*]=1时,br_trgt_hi=cur_pc_hi;当C1=0且imm[*]=1时,br_trgt_hi=cur_pc_hi-1。Optionally, assuming that the virtual address is a PC address, br_trgt represents a virtual address of the target instruction, br_trgt_hi represents a high-order address of the target instruction, imm[*] represents a symbol of the offset address, and cur_pc_hi represents a high-order address of a previous instruction of the target instruction, C1 represents a low carry, then when C1=1 and imm[*]=0, br_trgt_hi=cur_pc_hi+1; when C1=0 and imm[*]=0, or C1=1 and imm[*]=1 , br_trgt_hi=cur_pc_hi; when C1=0 and imm[*]=1, br_trgt_hi=cur_pc_hi-1.
步骤1007、生成地址指示符号,地址指示符号指示目标指令的高位地址。Step 1007: Generate an address indication symbol, and the address indication symbol indicates a high address of the target instruction.
取指令单元确定目标指令的高位地址后,由于目标指令的高位地址等于cur_pc_hi+1、cur_pc_hi或cur_pc_hi-1,因此取指令单元可以生成地址指示符号,该地址指示符号指示目标指令的高位地址。可选地,地址指示符号可以采用br_trgt_hi_sel来表示,且地址指示符号可以为2比特,例如,该地址指示符号可以为00、01或10,00指示目标指令的高位地址等于cur_pc_hi,01指示目标指令的高位地址等于cur_pc_hi+1,10指示目标指令的高位地址等于cur_pc_hi-1。需要说明的是,本申请实施例提供的地址指示符号仅仅是示例性的,实际应用中,地址指示符号还可以以其他形式体现,本申请实施例不对地址指示符号进行限定。After the instruction fetch unit determines the upper address of the target instruction, since the upper address of the target instruction is equal to cur_pc_hi+1, cur_pc_hi or cur_pc_hi-1, the fetching unit may generate an address indication symbol indicating the upper address of the target instruction. Optionally, the address indication symbol may be represented by br_trgt_hi_sel, and the address indication symbol may be 2 bits. For example, the address indication symbol may be 00, 01 or 10, 00 indicating that the upper address of the target instruction is equal to cur_pc_hi, 01 indicates the target instruction. The upper address is equal to cur_pc_hi+1, and 10 indicates that the upper address of the target instruction is equal to cur_pc_hi-1. It should be noted that the address indication symbol provided by the embodiment of the present application is merely exemplary. In an actual application, the address indication symbol may be embodied in other forms. The embodiment of the present application does not limit the address indication symbol.
步骤1008、将地址指示符号存储至扩展指令空间。Step 1008: Store the address indication symbol into the extended instruction space.
取指令单元生成地址指示符号后,可以对目标指令的上一指令的指令空间进行扩展得扩展指令空间,然后将地址指示符号存储至该扩展指令空间,以便于后续确定目标指令的虚拟地址的过程中,从扩展指令空间中读取地址指示符号,并根据地址指示符号确定目标指令的高位地址,节省计算目标指令的高位地址的时延,减小确定目标指令的虚拟地址的时延。After the instruction fetch unit generates the address indication symbol, the instruction space of the previous instruction of the target instruction may be extended to expand the instruction space, and then the address indication symbol is stored in the extended instruction space, so as to facilitate the process of subsequently determining the virtual address of the target instruction. The address indication symbol is read from the extended instruction space, and the upper address of the target instruction is determined according to the address indication symbol, the delay of calculating the upper address of the target instruction is saved, and the delay of determining the virtual address of the target instruction is reduced.
示例地,当目标指令的上一指令为图11中的指令CBNZ时,取指令单元可以对指令CBNZ的指令空间进行扩展,得到第32比特和第33比特的指令空间,并将地址指示符号存储至指令CBNZ的第32比特和第33比特的指令空间中。For example, when the previous instruction of the target instruction is the instruction CBNZ in FIG. 11, the instruction instruction unit may expand the instruction space of the instruction CBNZ to obtain the instruction space of the 32nd bit and the 33rd bit, and store the address indication symbol. Up to the instruction space of the 32nd and 33rd bits of the instruction CBNZ.
步骤1009、将目标指令的上一指令写入一级指令缓存。Step 1009: Write the previous instruction of the target instruction into the level one instruction cache.
该步骤1009的实现过程可以参考图6所示实施例的步骤606,本实施例在此不再赘述。For the implementation process of the step 1009, reference may be made to the step 606 of the embodiment shown in FIG. 6, which is not described herein again.
需要说明的是,上述步骤1001至步骤1009通常是在取指令单元获取目标指令之前进行的,下述步骤1010至步骤1013为取指令单元确定目标指令的虚拟地址的过程,该步骤1010至步骤1013可以发生在取指令单元获取目标指令的过程中。It should be noted that the foregoing steps 1001 to 1009 are generally performed before the instruction fetch unit acquires the target instruction, and the following steps 1010 to 1013 are processes for determining the virtual address of the target instruction for the fetching unit, and the step 1010 to step 1013 are performed. This can occur during the fetch unit's acquisition of the target instruction.
步骤1010、从目标指令的上一指令的指令空间中读取目标指令的低位地址。Step 1010: Read the lower address of the target instruction from the instruction space of the previous instruction of the target instruction.
该步骤1010的实现过程可以参考图6所示实施例的步骤607,本实施例在此不再赘述。For the implementation of the step 1010, reference may be made to the step 607 of the embodiment shown in FIG. 6, which is not described herein again.
步骤1011、从扩展指令空间中读取地址指示符号。Step 1011: Read an address indication symbol from the extended instruction space.
其中,该扩展指令空间也即是步骤1008中的扩展指令空间。可选地,取指令单元可以调用处理器的读命令从扩展指令空间中读取地址指示符号,详细的读取过程可以参考相关技术,本实施例在此不再赘述。The extended instruction space is also the extended instruction space in step 1008. Optionally, the instruction fetch unit can call the read command of the processor to read the address indication symbol from the extended instruction space. For a detailed read process, reference may be made to the related art, and details are not described herein again.
步骤1012、根据地址指示符号确定目标指令的高位地址。Step 1012: Determine a high address of the target instruction according to the address indication symbol.
取指令单元可以根据地址指示符号的指示确定目标指令的高位地址。The instruction fetch unit may determine the upper address of the target instruction based on the indication of the address indication symbol.
可选地,当地址指示符号为00时,取指令单元确定目标指令的高位地址等于cur_pc_hi,当地址指示符号为01时,取指令单元确定目标指令的高位地址等于cur_pc_hi+1,当地址指示符号为10时,取指令单元确定目标指令的高位地址等于cur_pc_hi-1。Optionally, when the address indication symbol is 00, the instruction fetch unit determines that the upper address of the target instruction is equal to cur_pc_hi, and when the address indication symbol is 01, the instruction fetch unit determines that the upper address of the target instruction is equal to cur_pc_hi+1, when the address indication symbol When it is 10, the instruction fetch unit determines that the upper address of the target instruction is equal to cur_pc_hi-1.
需要说明的是,上述步骤1011至步骤1012可以理解为,在地址映射为直接映射时,对图5所示实施例中的步骤505的细化。It should be noted that the above steps 1011 to 1012 can be understood as the refinement of step 505 in the embodiment shown in FIG. 5 when the address mapping is direct mapping.
步骤1013、将目标指令的低位地址与目标指令的高位地址合并,得到目标指令的虚拟地址。Step 1013: Combine the lower address of the target instruction with the upper address of the target instruction to obtain a virtual address of the target instruction.
可选地,取指令单元可以按照地址位的高低将目标指令的低位地址与目标指令的高位地址合并,得到目标指令的虚拟地址,且在同一虚拟地址中,地址位从右向左依次升高。例如,取指令单元将目标指令的高位地址排布在目标指令的低位地址的高位得到目标指令的虚拟地址。Optionally, the instruction fetch unit may combine the lower address of the target instruction with the upper address of the target instruction according to the address bit to obtain a virtual address of the target instruction, and in the same virtual address, the address bit is sequentially raised from right to left. . For example, the instruction fetch unit arranges the upper address of the target instruction at the upper bit of the lower address of the target instruction to obtain the virtual address of the target instruction.
可选地,假设虚拟地址为PC地址,br_trgt表示目标指令的虚拟地址,br_trgt_lo表示目标指令的低位地址,br_trgt_hi表示目标指令的高位地址,则在本实施例中,br_trgt、br_trgt_lo和br_trgt_hi的关系可以采用下述方程式(6)表示:Optionally, assuming that the virtual address is a PC address, br_trgt represents a virtual address of the target instruction, br_trgt_lo represents a lower address of the target instruction, and br_trgt_hi represents a higher address of the target instruction, in this embodiment, the relationship of br_trgt, br_trgt_lo, and br_trgt_hi may be Expressed by the following equation (6):
方程式(6)br_trgt={br_trgt_hi,br_trgt_lo}。Equation (6) br_trgt = {br_trgt_hi, br_trgt_lo}.
需要说明的是,本申请实施例提供的虚拟地址确定方法步骤的先后顺序可以进行适当调整,步骤也可以根据情况进行相应增减,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化的方法,都应涵盖在本申请的保护范围之内,因此不再赘述。It should be noted that the sequence of the steps of the virtual address determining method provided by the embodiment of the present application may be appropriately adjusted, and the steps may also be correspondingly increased or decreased according to the situation, and any person skilled in the art may be within the technical scope disclosed in the present application. The methods that can be easily thought of as changes are covered by the scope of protection of the present application, and therefore will not be described again.
综上所述,本申请实施例提供的虚拟地址确定方法,由于目标指令的低位地址是从目标指令的上一指令的指令空间中读取到的,在确定目标指令的虚拟地址的过程中,无需计算目标指令的低位地址,只需要计算目标指令的剩余地址(剩余地址为目标指令的虚拟地址中除低位地址之外的地址),然后将目标指令的剩余地址与目标指令的低位地址合并就可以得到目标指令的虚拟地址,因此可以减小确定目标指令的虚拟地址的计算量,有助于解决确定目标指令的虚拟地址的时延较大,处理器的处理速度较慢的问题,减小确定目标指令的虚拟地址的时延,提高处理器的处理速度。In summary, the virtual address determining method provided by the embodiment of the present application, in the process of determining the virtual address of the target instruction, is that the lower address of the target instruction is read from the instruction space of the previous instruction of the target instruction. There is no need to calculate the lower address of the target instruction, only the remaining address of the target instruction (the remaining address is the address other than the lower address in the virtual address of the target instruction), and then the remaining address of the target instruction is merged with the lower address of the target instruction. The virtual address of the target instruction can be obtained, so that the calculation amount of the virtual address of the target instruction can be reduced, which helps to solve the problem that the delay of determining the virtual address of the target instruction is large, and the processing speed of the processor is slow, and the problem is reduced. Determine the delay of the virtual address of the target instruction and increase the processing speed of the processor.
本申请实施例提供的虚拟地址确定方法,大大减少了确定虚拟地址过程中,需要进行加法运算的地址宽度,减少确定虚拟地址的时延;此外,本申请实施例提供的方案无需增加流水线级,避免由于增加流水线级导致的时延,以及避免由于异常、预测错误和缓存丢失等导致处理器的性能下降。The virtual address determining method provided by the embodiment of the present invention greatly reduces the address width of the virtual address in the process of determining the virtual address, and reduces the delay of determining the virtual address. In addition, the solution provided by the embodiment of the present application does not need to increase the pipeline level. Avoid delays due to increased pipeline levels and avoid processor performance degradation due to exceptions, prediction errors, and cache misses.
以下结合图12和图13对图10所示实施例提供的方案进行举例说明。该图12和图13以虚拟地址为PC地址,且图12以偏移地址的符号为0,图13以偏移地址的符号为1为例进行说明。The solution provided by the embodiment shown in FIG. 10 is exemplified below with reference to FIG. 12 and FIG. 12 and FIG. 13 show the virtual address as the PC address, and FIG. 12 shows the offset address as 0. FIG. 13 illustrates the offset address as 1 as an example.
其中,在图12和图13中,cur_pc表示目标指令的上一指令的PC地址,cur_pc_lo表示目标指令的上一指令的低位地址,cur_pc_hi表示目标指令的上一指令的高位地址;imm表示目标指令的上一指令所包含的偏移地址;br_trgt表示目标指令的PC地址,br_trgt_lo表示目标指令的低位地址,br_trgt_hi表示目标指令的高位地址;C1表示低位进位,在执行图10 所示实施例的方案之前,可以先根据imm的符号对imm进行符号扩展,使imm的宽度与cur_pc的宽度相等。12 and 13, cur_pc represents the PC address of the previous instruction of the target instruction, cur_pc_lo represents the lower address of the previous instruction of the target instruction, cur_pc_hi represents the upper address of the previous instruction of the target instruction, and imm represents the target instruction. The offset address included in the previous instruction; br_trgt indicates the PC address of the target instruction, br_trgt_lo indicates the lower address of the target instruction, br_trgt_hi indicates the upper address of the target instruction; C1 indicates the lower carry, and the scheme of the embodiment shown in FIG. 10 is executed. Before, you can first extend the imm according to the symbol of imm, so that the width of imm is equal to the width of cur_pc.
如图12和图13所示,在确定br_trgt之前,首先将cur_pc拆分成cur_pc_lo和cur_pc_hi,cur_pc_lo与imm对齐,此过程可以与图10所示实施例的步骤1001和步骤1002部分对应;接着,根据步骤1003提供的方案,采用公式{C1,br_trgt_lo}=cur_pc_lo+imm计算得到br_trgt_lo并产生低位进位C1;之后,根据步骤1004提供的方案将br_trgt_lo存储至目标指令的上一指令的指令空间,根据步骤1005提供的方案确定cur_pc_hi;接着,根据步骤1006提供的方案,根据cur_pc_hi、偏移地址的符号和C1确定br_trgt_hi,如图12所示,如果C1=1且偏移地址的符号为0,则br_trgt_hi=cur_pc_hi+1,如果C1=0且偏移地址的符号为0,则br_trgt_hi=cur_pc_hi,如图13所示,如果C1=1且偏移地址的符号为1,则br_trgt_hi=cur_pc_hi,如果C1=0且偏移地址的符号为1,则br_trgt_hi=cur_pc_hi-1;之后,根据步骤1007提供的方案,生成地址指示符号,并根据步骤1008提供的方案将地址指示符号存储至扩展指令空间;最后,根据步骤1009提供的方案将目标指令的上一指令写入一级指令缓存。As shown in FIG. 12 and FIG. 13, before determining br_trgt, first, cur_pc is split into cur_pc_lo and cur_pc_hi, and cur_pc_lo is aligned with imm. This process may correspond to steps 1001 and 1002 of the embodiment shown in FIG. 10; According to the solution provided in step 1003, br_trgt_lo is calculated by using the formula {C1, br_trgt_lo}=cur_pc_lo+imm and a lower carry C1 is generated; afterwards, br_trgt_lo is stored in the instruction space of the previous instruction of the target instruction according to the scheme provided in step 1004, according to The scheme provided by step 1005 determines cur_pc_hi; then, according to the scheme provided in step 1006, br_trgt_hi is determined according to cur_pc_hi, the sign of the offset address, and C1, as shown in FIG. 12, if C1=1 and the sign of the offset address is 0, then Br_trgt_hi=cur_pc_hi+1, if C1=0 and the sign of the offset address is 0, then br_trgt_hi=cur_pc_hi, as shown in Figure 13, if C1=1 and the sign of the offset address is 1, then br_trgt_hi=cur_pc_hi, if C1 =0 and the sign of the offset address is 1, then br_trgt_hi=cur_pc_hi-1; after that, according to the scheme provided in step 1007, an address indicator is generated, and according to The scheme provided by step 1008 stores the address indication symbol into the extended instruction space; finally, the previous instruction of the target instruction is written to the level one instruction cache according to the scheme provided in step 1009.
如图12和图13所示,在确定br_trgt的过程中,首先,根据步骤1010提供的方案从目标指令的上一指令的指令空间中读取br_trgt_lo;接着,根据步骤1011提供的方案从扩展指令空间中读取地址指示符号,并根据步骤1012提供的方案确定br_trgt_hi;最后,根据步骤1013提供的方案将br_trgt_lo和br_trgt_hi合并得到br_trgt,br_trgt={br_trgt_hi,br_trgt_lo}。As shown in FIG. 12 and FIG. 13, in the process of determining br_trgt, first, br_trgt_lo is read from the instruction space of the previous instruction of the target instruction according to the scheme provided in step 1010; then, the extended instruction is obtained according to the scheme provided in step 1011. The address indication symbol is read in space, and br_trgt_hi is determined according to the scheme provided in step 1012. Finally, br_trgt_lo and br_trgt_hi are combined according to the scheme provided in step 1013 to obtain br_trgt, br_trgt={br_trgt_hi, br_trgt_lo}.
根据以上描述可知,在确定br_trgt的过程中,br_trgt_lo可以从目标指令的上一指令的指令空间中读取到,br_trgt_hi可以从目标指令的上一指令的指令空间中读取到的地址指示符号确定,将br_trgt_lo和br_trgt_hi合并得到br_trgt,从而在确定br_trgt的过程中,无需进行加法运算,大大减少了确定br_trgt的时延。According to the above description, in the process of determining br_trgt, br_trgt_lo can be read from the instruction space of the previous instruction of the target instruction, and br_trgt_hi can be determined from the address indication symbol read from the instruction space of the previous instruction of the target instruction. Combining br_trgt_lo and br_trgt_hi to obtain br_trgt, so that in the process of determining br_trgt, no addition operation is required, and the delay for determining br_trgt is greatly reduced.
下述为本申请的装置实施例,可以用于执行本申请的方法实施例。对于本申请装置实施例中未披露的细节,请参照本申请方法实施例。The following is an apparatus embodiment of the present application, which can be used to implement the method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.
请参考图14,其示出了本申请实施例提供的一种虚拟地址确定装置1400的框图,该虚拟地址确定装置1400可以为处理器中的取指令单元。参见图14,该虚拟地址确定装置1400包括:Please refer to FIG. 14 , which is a block diagram of a virtual address determining apparatus 1400 provided by an embodiment of the present application. The virtual address determining apparatus 1400 may be an instruction fetching unit in a processor. Referring to FIG. 14, the virtual address determining apparatus 1400 includes:
第一读取模块1401,用于从待获取的目标指令的上一指令的指令空间中读取目标指令的低位地址,目标指令的低位地址为将上一指令写入一级指令缓存之前计算得到并存储在上一指令的指令空间中的地址;The first reading module 1401 is configured to read the lower address of the target instruction from the instruction space of the previous instruction of the target instruction to be acquired, and the lower address of the target instruction is calculated before writing the previous instruction to the first instruction cache. And storing the address in the instruction space of the previous instruction;
第一确定模块1402,用于确定目标指令的剩余地址,目标指令的剩余地址的宽度与目标指令的低位地址的宽度之和等于上一指令的虚拟地址的宽度;a first determining module 1402, configured to determine a remaining address of the target instruction, a sum of a width of a remaining address of the target instruction and a width of a lower address of the target instruction is equal to a width of a virtual address of the previous instruction;
合并模块1403,用于将目标指令的低位地址与目标指令的剩余地址合并,得到目标指令的虚拟地址。The merging module 1403 is configured to combine the lower address of the target instruction with the remaining address of the target instruction to obtain a virtual address of the target instruction.
综上所述,本申请实施例提供的虚拟地址确定装置,由于目标指令的低位地址是从目标指令的上一指令的指令空间中读取到的,在确定目标指令的虚拟地址的过程中,无需计算目标指令的低位地址,只需要计算目标指令的剩余地址(目标指令的虚拟地址中除低位地址之外的地址),然后将目标指令的剩余地址与目标指令的低位地址合并就可以得到目标 指令的虚拟地址,因此可以减小确定目标指令的虚拟地址的计算量,有助于解决确定目标指令的虚拟地址的时延较大,处理器的处理速度较慢的问题,减小确定目标指令的虚拟地址的时延,提高处理器的处理速度。In summary, the virtual address determining apparatus provided by the embodiment of the present application, in the process of determining the virtual address of the target instruction, is that the lower address of the target instruction is read from the instruction space of the previous instruction of the target instruction. There is no need to calculate the lower address of the target instruction, only the remaining address of the target instruction (the address other than the lower address in the virtual address of the target instruction) is calculated, and then the remaining address of the target instruction is merged with the lower address of the target instruction to obtain the target. The virtual address of the instruction, so that the calculation amount of the virtual address of the target instruction can be reduced, which helps to solve the problem that the delay of determining the virtual address of the target instruction is large, the processing speed of the processor is slow, and the determination target instruction is reduced. The latency of the virtual address increases the processing speed of the processor.
进一步地,请参考图15,其示出了本申请实施例提供的另一种虚拟地址确定装置1400的框图,参见图15,在图14的基础上,该虚拟地址确定装置1400还包括:Further, please refer to FIG. 15 , which is a block diagram of another virtual address determining apparatus 1400 provided by an embodiment of the present application. Referring to FIG. 15 , the virtual address determining apparatus 1400 further includes:
计算模块1404,用于计算目标指令的低位地址;a calculation module 1404, configured to calculate a lower address of the target instruction;
第一存储模块1405,用于将目标指令的低位地址存储至上一指令的指令空间。The first storage module 1405 is configured to store the lower address of the target instruction to the instruction space of the previous instruction.
可选地,计算模块1404,用于:Optionally, the calculation module 1404 is configured to:
确定上一指令的虚拟地址和上一指令所包含的偏移地址;Determining the virtual address of the previous instruction and the offset address included in the previous instruction;
根据页表的大小,从上一指令的虚拟地址中确定上一指令的低位地址,并从偏移地址中确定偏移地址的低位地址,上一指令的低位地址与偏移地址的低位地址对齐且宽度相等;According to the size of the page table, the lower address of the previous instruction is determined from the virtual address of the previous instruction, and the lower address of the offset address is determined from the offset address, and the lower address of the previous instruction is aligned with the lower address of the offset address. And the width is equal;
将上一指令的低位地址与偏移地址的低位地址相加,得到目标指令的低位地址,目标指令的低位地址与上一指令的低位地址对齐且宽度相等。The lower address of the previous instruction is added to the lower address of the offset address to obtain the lower address of the target instruction, and the lower address of the target instruction is aligned with the lower address of the previous instruction and the width is equal.
进一步地,请继续参考图15,虚拟地址确定装置1400还包括:Further, referring to FIG. 15, the virtual address determining apparatus 1400 further includes:
第二存储模块1406,用于将低位进位存储至扩展指令空间,低位进位为将上一指令的低位地址与偏移地址的低位地址相加产生的进位,扩展指令空间为对上一指令的指令空间进行扩展得到的指令空间。The second storage module 1406 is configured to store the lower carry into the extended instruction space, and the lower carry is a carry generated by adding the lower address of the previous instruction and the lower address of the offset address, and the extended instruction space is the instruction for the previous instruction. The instruction space obtained by expanding the space.
可选地,剩余地址包括中位地址和高位地址,请参考图16,其示出了本申请实施例提供的一种第一确定模块1402的框图,参见图16,第一确定模块1402包括:Optionally, the remaining address includes a median address and a high-order address. Please refer to FIG. 16 , which is a block diagram of a first determining module 1402 according to an embodiment of the present application. Referring to FIG. 16 , the first determining module 1402 includes:
第一确定子模块14021,用于从偏移地址中确定偏移地址的高位地址,偏移地址由偏移地址的高位地址和偏移地址的低位地址组成;The first determining sub-module 14021 is configured to determine, from the offset address, a high-order address of the offset address, where the offset address is composed of a high-order address of the offset address and a low-order address of the offset address;
第二确定子模块14022,用于根据偏移地址的高位地址,从上一指令的虚拟地址中确定上一指令的中位地址,上一指令的中位地址与偏移地址的高位地址对齐且宽度相等;The second determining sub-module 14022 is configured to determine, according to the upper address of the offset address, the median address of the previous instruction from the virtual address of the previous instruction, where the median address of the previous instruction is aligned with the upper address of the offset address and Equal in width;
读取子模块14023,用于从扩展指令空间中读取所述低位进位;a reading submodule 14023, configured to read the lower carry from the extended instruction space;
相加子模块14024,用于将上一指令的中位地址、偏移地址的高位地址和低位进位相加,得到目标指令的中位地址;The adding sub-module 14024 is configured to add the median address of the previous instruction, the upper address of the offset address, and the lower carry, to obtain a median address of the target instruction;
第三确定子模块14025,用于从上一指令的虚拟地址中确定上一指令的高位地址,上一指令的虚拟地址由上一指令的高位地址、上一指令的中位地址和上一指令的低位地址组成;The third determining sub-module 14025 is configured to determine a high-order address of the previous instruction from the virtual address of the previous instruction, where the virtual address of the previous instruction is the upper address of the previous instruction, the median address of the previous instruction, and the previous instruction. Composition of the lower address;
第四确定子模块14026,用于根据中位进位、上一指令的高位地址和偏移地址的符号,确定目标指令的高位地址,中位进位为将上一指令的中位地址、偏移地址的高位地址和低位进位相加产生的进位。The fourth determining sub-module 14026 is configured to determine a high-order address of the target instruction according to a median carry, a high-order address of the previous instruction, and a symbol of the offset address, and the median carry is a median address and an offset address of the previous instruction. The higher address and the lower carry add up the resulting carry.
可选地,第四确定子模块10426,用于:Optionally, the fourth determining submodule 10426 is configured to:
当中位进位为1且偏移地址的符号为0时,确定目标指令的高位地址等于上一指令的高位地址加1;When the median carry is 1 and the sign of the offset address is 0, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction plus one;
当中位进位为0且偏移地址的符号为0,或者,中位进位为1且偏移地址的符号为1时,确定目标指令的高位地址等于上一指令的高位地址;When the median carry is 0 and the sign of the offset address is 0, or the median carry is 1 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction;
当中位进位为0且偏移地址的符号为1时,确定目标指令的高位地址等于上一指令的高位地址减1。When the median carry is 0 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction minus one.
可选地,计算模块1404,用于:Optionally, the calculation module 1404 is configured to:
确定上一指令的虚拟地址和上一指令所包含的偏移地址;Determining the virtual address of the previous instruction and the offset address included in the previous instruction;
根据偏移地址确定上一指令的低位地址,上一指令的低位地址与偏移地址对齐且宽度相等;Determining the lower address of the previous instruction according to the offset address, the lower address of the previous instruction is aligned with the offset address and the width is equal;
将上一指令的低位地址与偏移地址相加,得到目标指令的低位地址,目标指令的低位地址与上一指令的低位地址对齐且宽度相等。The lower address of the previous instruction is added to the offset address to obtain the lower address of the target instruction, and the lower address of the target instruction is aligned with the lower address of the previous instruction and the width is equal.
可选地,剩余地址包括高位地址,请参考图17,其示出了本申请实施例提供的再一种虚拟地址确定装置1400的框图,参见图17,在图15的基础上,该虚拟地址确定装置1400还包括:Optionally, the remaining address includes a high-order address. Please refer to FIG. 17, which shows a block diagram of another virtual address determining apparatus 1400 provided by an embodiment of the present application. Referring to FIG. 17, on the basis of FIG. 15, the virtual address is used. The determining device 1400 further includes:
第二确定模块1407,用于从上一指令的虚拟地址中确定上一指令的高位地址,上一指令的虚拟地址由上一指令的高位地址和上一指令的低位地址组成;a second determining module 1407, configured to determine a high-order address of the previous instruction from a virtual address of the previous instruction, where the virtual address of the previous instruction is composed of a high-order address of the previous instruction and a lower-order address of the previous instruction;
第三确定模块1408,用于根据低位进位、上一指令的高位地址和偏移地址的符号,确定目标指令的高位地址,低位进位为将上一指令的低位地址和偏移地址相加产生的进位;The third determining module 1408 is configured to determine, according to the lower carry, the upper address of the previous instruction, and the sign of the offset address, the upper address of the target instruction, and the lower carry is generated by adding the lower address and the offset address of the previous instruction. carry;
生成模块1409,用于生成地址指示符号,地址指示符号指示目标指令的高位地址;a generating module 1409, configured to generate an address indication symbol, where the address indication symbol indicates a high-order address of the target instruction;
第三存储模块1410,用于将地址指示符号存储至扩展指令空间,扩展指令空间为对上一指令的指令空间进行扩展得到的指令空间。The third storage module 1410 is configured to store the address indication symbol into the extended instruction space, where the extended instruction space is an instruction space obtained by expanding the instruction space of the previous instruction.
可选地,第一确定模块1402,用于:Optionally, the first determining module 1402 is configured to:
从扩展指令空间中读取地址指示符号;Reading the address indicator from the extended instruction space;
根据地址指示符号确定目标指令的高位地址。The upper address of the target instruction is determined according to the address indication symbol.
可选地,第三确定模块1408,用于:Optionally, the third determining module 1408 is configured to:
当低位进位为1且偏移地址的符号为0时,确定目标指令的高位地址等于上一指令的高位地址加1;When the lower carry is 1 and the sign of the offset address is 0, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction plus one;
当低位进位为0且偏移地址的符号为0,或者,低位进位为1且偏移地址的符号为1时,确定目标指令的高位地址等于上一指令的高位地址;When the lower carry is 0 and the sign of the offset address is 0, or the lower carry is 1 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction;
当低位进位为0且偏移地址的符号为1时,确定目标指令的高位地址等于上一指令的高位地址减1。When the lower carry is 0 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction minus one.
可选地,一级指令缓存中,不同指令的指令空间中存储的低位地址在指令空间的第0比特对齐。Optionally, in the level one instruction cache, the lower address stored in the instruction space of the different instructions is aligned in the 0th bit of the instruction space.
综上所述,本申请实施例提供的虚拟地址确定装置,由于目标指令的低位地址是从目标指令的上一指令的指令空间中读取到的,在确定目标指令的虚拟地址的过程中,无需计算目标指令的低位地址,只需要计算目标指令的剩余地址(目标指令的虚拟地址中除低位地址之外的地址),然后将目标指令的剩余地址与目标指令的低位地址合并就可以得到目标指令的虚拟地址,因此可以减小确定目标指令的虚拟地址的计算量,有助于解决确定目标指令的虚拟地址的时延较大,处理器的处理速度较慢的问题,减小确定目标指令的虚拟地址的时延,提高处理器的处理速度。In summary, the virtual address determining apparatus provided by the embodiment of the present application, in the process of determining the virtual address of the target instruction, is that the lower address of the target instruction is read from the instruction space of the previous instruction of the target instruction. There is no need to calculate the lower address of the target instruction, only the remaining address of the target instruction (the address other than the lower address in the virtual address of the target instruction) is calculated, and then the remaining address of the target instruction is merged with the lower address of the target instruction to obtain the target. The virtual address of the instruction, so that the calculation amount of the virtual address of the target instruction can be reduced, which helps to solve the problem that the delay of determining the virtual address of the target instruction is large, the processing speed of the processor is slow, and the determination target instruction is reduced. The latency of the virtual address increases the processing speed of the processor.
需要说明的是:上述实施例提供的虚拟地址确定装置在确定目标指令的虚拟地址时,仅以上述各功能单元的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能单元完成,即将设备的内部结构划分成不同的功能单元,以完成以上描述的全部或者部分功能。另外,上述实施例提供的虚拟地址确定装置与虚拟地址确定方法实施例属于同一构思,其具体实现过程详见方法实施例,这里不再赘述。It should be noted that, when determining the virtual address of the target instruction, the virtual address determining apparatus provided by the foregoing embodiment only exemplifies the division of each functional unit. In actual applications, the function may be assigned differently according to needs. The functional unit is completed, that is, the internal structure of the device is divided into different functional units to complete all or part of the functions described above. In addition, the virtual address determining apparatus and the virtual address determining method are provided in the same embodiment. For details, refer to the method embodiment, and details are not described herein.
本申请实施例还提供了一种处理器,该处理器包括图14、图15或图17所示的虚拟地址确定装置1400。The embodiment of the present application further provides a processor including the virtual address determining apparatus 1400 shown in FIG. 14, FIG. 15, or FIG.
本申请实施例还提供了一种计算机可读存储介质,该计算机可读存储介质中存储有指令,当该指令在计算机的处理器上运行时,使得处理器执行上述图5、图6或图10所描述的虚拟地址确定方法。The embodiment of the present application further provides a computer readable storage medium, where the instructions are stored, when the instruction is run on a processor of the computer, causing the processor to execute the above FIG. 5, FIG. 6 or The virtual address determination method described in 10.
本申请实施例还提供了一种包含指令的计算机程序产品,当计算机程序产品在计算机的处理器上运行时,使得处理器执行上述图5、图6或图10所描述的虚拟地址确定方法。The embodiment of the present application further provides a computer program product comprising instructions for causing a processor to execute the virtual address determining method described in FIG. 5, FIG. 6, or FIG. 10 above when the computer program product runs on a processor of the computer.
本申请实施例还提供了一种处理装置,该处理装置包括至少一个电路,该至少一个电路用于执行上述图5、图6或图10所描述的虚拟地址确定方法。The embodiment of the present application further provides a processing apparatus, where the processing apparatus includes at least one circuit for performing the virtual address determining method described in FIG. 5, FIG. 6, or FIG.
本申请实施例还提供了一种一种芯片,该芯片包括可编程逻辑电路和/或程序指令,当该芯片运行时用于实现图5、图6或图10所描述的虚拟地址确定方法。The embodiment of the present application further provides a chip, which includes programmable logic circuits and/or program instructions, and is used to implement the virtual address determining method described in FIG. 5, FIG. 6, or FIG.
本申请中术语“和/或”,仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。另外,本文中字符“/”,一般表示前后关联对象是一种“或”的关系。The term “and/or” in the present application is merely an association relationship describing an associated object, indicating that there may be three relationships, for example, A and/or B, which may indicate that A exists separately, and A and B exist simultaneously. There are three cases of B. In addition, the character "/" in this article generally indicates that the contextual object is an "or" relationship.
上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。The serial numbers of the embodiments of the present application are merely for the description, and do not represent the advantages and disadvantages of the embodiments.
本领域普通技术人员可以理解实现上述实施例的全部或部分步骤可以通过硬件来完成,也可以通过程序来指令相关的硬件完成,所述的程序可以存储于一种计算机可读存储介质中,上述提到的存储介质可以是只读存储器,磁盘或光盘等。A person skilled in the art may understand that all or part of the steps of implementing the above embodiments may be completed by hardware, or may be instructed by a program to execute related hardware, and the program may be stored in a computer readable storage medium. The storage medium mentioned may be a read only memory, a magnetic disk or an optical disk or the like.
以上所述仅为本申请的可选实施例,并不用以限制本申请,凡在本申请的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本申请的保护范围之内。The above description is only an optional embodiment of the present application, and is not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application are included in the protection of the present application. Within the scope.

Claims (28)

  1. 一种虚拟地址确定方法,其特征在于,所述方法包括:A virtual address determining method, the method comprising:
    从待获取的目标指令的上一指令的指令空间中读取所述目标指令的低位地址,所述目标指令的低位地址为将所述上一指令写入一级指令缓存之前计算得到并存储在所述上一指令的指令空间中的地址;Reading a lower address of the target instruction from an instruction space of a previous instruction of the target instruction to be acquired, where the lower address of the target instruction is calculated and stored before the previous instruction is written into the first instruction cache. An address in an instruction space of the previous instruction;
    确定所述目标指令的剩余地址,所述目标指令的剩余地址的宽度与所述目标指令的低位地址的宽度之和等于所述上一指令的虚拟地址的宽度;Determining a remaining address of the target instruction, a sum of a width of a remaining address of the target instruction and a width of a lower address of the target instruction being equal to a width of a virtual address of the previous instruction;
    将所述目标指令的低位地址与所述目标指令的剩余地址合并,得到所述目标指令的虚拟地址。Merging the lower address of the target instruction with the remaining address of the target instruction to obtain a virtual address of the target instruction.
  2. 根据权利要求1所述的方法,其特征在于,在所述从待获取的目标指令的上一指令的指令空间中读取所述目标指令的低位地址之前,所述方法还包括:The method according to claim 1, wherein before the reading of the lower address of the target instruction in the instruction space of the last instruction of the target instruction to be acquired, the method further comprises:
    计算所述目标指令的低位地址;Calculating a lower address of the target instruction;
    将所述目标指令的低位地址存储至所述上一指令的指令空间。The lower address of the target instruction is stored into the instruction space of the previous instruction.
  3. 根据权利要求2所述的方法,其特征在于,所述计算所述目标指令的低位地址,包括:The method according to claim 2, wherein said calculating a lower address of said target instruction comprises:
    确定所述上一指令的虚拟地址和所述上一指令所包含的偏移地址;Determining a virtual address of the previous instruction and an offset address included in the previous instruction;
    根据页表的大小,从所述上一指令的虚拟地址中确定所述上一指令的低位地址,并从所述偏移地址中确定所述偏移地址的低位地址,所述上一指令的低位地址与所述偏移地址的低位地址对齐且宽度相等;Determining, according to the size of the page table, a lower address of the previous instruction from a virtual address of the previous instruction, and determining a lower address of the offset address from the offset address, the previous instruction The lower address is aligned with the lower address of the offset address and has the same width;
    将所述上一指令的低位地址与所述偏移地址的低位地址相加,得到所述目标指令的低位地址,所述目标指令的低位地址与所述上一指令的低位地址对齐且宽度相等。Adding a lower address of the previous instruction to a lower address of the offset address to obtain a lower address of the target instruction, and a lower address of the target instruction is aligned with a lower address of the previous instruction and has an equal width .
  4. 根据权利要求3所述的方法,其特征在于,在将所述上一指令的低位地址与所述偏移地址的低位地址相加之后,所述方法还包括:The method according to claim 3, wherein after adding the lower address of the last instruction to the lower address of the offset address, the method further comprises:
    将低位进位存储至扩展指令空间,所述低位进位为将所述上一指令的低位地址与所述偏移地址的低位地址相加产生的进位,所述扩展指令空间为对所述上一指令的指令空间进行扩展得到的指令空间。Storing a lower carry into an extended instruction space, the lower carry being a carry generated by adding a lower address of the previous instruction and a lower address of the offset address, the extended instruction space being the previous instruction The instruction space is expanded to get the instruction space.
  5. 根据权利要求4所述的方法,其特征在于,所述剩余地址包括中位地址和高位地址,所述确定所述目标指令的剩余地址,包括:The method according to claim 4, wherein the remaining address comprises a median address and a high address, and the determining the remaining address of the target instruction comprises:
    从所述偏移地址中确定所述偏移地址的高位地址,所述偏移地址由所述偏移地址的高位地址和所述偏移地址的低位地址组成;Determining, from the offset address, an upper address of the offset address, the offset address being composed of a high address of the offset address and a lower address of the offset address;
    根据所述偏移地址的高位地址,从所述上一指令的虚拟地址中确定所述上一指令的中位地址,所述上一指令的中位地址与所述偏移地址的高位地址对齐且宽度相等;Determining, according to the upper address of the offset address, a median address of the previous instruction from a virtual address of the previous instruction, the median address of the previous instruction being aligned with a high address of the offset address And the width is equal;
    从所述扩展指令空间中读取所述低位进位;Reading the lower carry from the extended instruction space;
    将所述上一指令的中位地址、所述偏移地址的高位地址和所述低位进位相加,得到所述目标指令的中位地址;Adding a median address of the previous instruction, a high-order address of the offset address, and the low-order carry to obtain a median address of the target instruction;
    从所述上一指令的虚拟地址中确定所述上一指令的高位地址,所述上一指令的虚拟地址由所述上一指令的高位地址、所述上一指令的中位地址和所述上一指令的低位地址组成;Determining a higher address of the previous instruction from a virtual address of the previous instruction, the virtual address of the previous instruction being a higher address of the previous instruction, a median address of the previous instruction, and the The lower address of the previous instruction is composed;
    根据中位进位、所述上一指令的高位地址和所述偏移地址的符号,确定所述目标指令的高位地址,所述中位进位为将所述上一指令的中位地址、所述偏移地址的高位地址和所述低 位进位相加产生的进位。Determining a high address of the target instruction according to a median carry, a high address of the previous instruction, and a sign of the offset address, the median carry being a median address of the previous instruction, the The carry generated by the addition of the upper address of the offset address and the lower carry.
  6. 根据权利要求5所述的方法,其特征在于,所述根据中位进位、所述上一指令的高位地址和所述偏移地址的符号,确定所述目标指令的高位地址,包括:The method according to claim 5, wherein the determining a high-order address of the target instruction according to a median carry, a high-order address of the previous instruction, and a sign of the offset address, including:
    当所述中位进位为1且所述偏移地址的符号为0时,确定所述目标指令的高位地址等于所述上一指令的高位地址加1;When the median carry is 1 and the sign of the offset address is 0, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction plus one;
    当所述中位进位为0且所述偏移地址的符号为0,或者,所述中位进位为1且所述偏移地址的符号为1时,确定所述目标指令的高位地址等于所述上一指令的高位地址;When the median carry is 0 and the sign of the offset address is 0, or the median carry is 1 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to State the upper address of an instruction;
    当所述中位进位为0且所述偏移地址的符号为1时,确定所述目标指令的高位地址等于所述上一指令的高位地址减1。When the median carry is 0 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction minus one.
  7. 根据权利要求2所述的方法,其特征在于,所述计算所述目标指令的低位地址,包括:The method according to claim 2, wherein said calculating a lower address of said target instruction comprises:
    确定所述上一指令的虚拟地址和所述上一指令所包含的偏移地址;Determining a virtual address of the previous instruction and an offset address included in the previous instruction;
    根据所述偏移地址确定所述上一指令的低位地址,所述上一指令的低位地址与所述偏移地址对齐且宽度相等;Determining, according to the offset address, a lower address of the previous instruction, where a lower address of the previous instruction is aligned with the offset address and the width is equal;
    将所述上一指令的低位地址与所述偏移地址相加,得到所述目标指令的低位地址,所述目标指令的低位地址与所述上一指令的低位地址对齐且宽度相等。And adding the lower address of the previous instruction to the offset address to obtain a lower address of the target instruction, and the lower address of the target instruction is aligned with the lower address of the previous instruction and the width is equal.
  8. 根据权利要求7所述的方法,其特征在于,所述剩余地址包括高位地址,在将所述上一指令的低位地址与所述偏移地址相加之后,所述方法还包括:The method of claim 7, wherein the remaining address comprises a high-order address, and after adding the lower-order address of the previous instruction to the offset address, the method further comprises:
    从所述上一指令的虚拟地址中确定所述上一指令的高位地址,所述上一指令的虚拟地址由所述上一指令的高位地址和所述上一指令的低位地址组成;Determining, from a virtual address of the previous instruction, a high-order address of the previous instruction, where a virtual address of the previous instruction is composed of a high-order address of the previous instruction and a lower-order address of the previous instruction;
    根据低位进位、所述上一指令的高位地址和所述偏移地址的符号,确定所述目标指令的高位地址,所述低位进位为将所述上一指令的低位地址和所述偏移地址相加产生的进位;Determining, according to a lower carry, a higher address of the previous instruction, and a sign of the offset address, a higher address of the target instruction, the lower carry being a lower address of the previous instruction and the offset address Adding the resulting carry;
    生成地址指示符号,所述地址指示符号指示所述目标指令的高位地址;Generating an address indicator symbol indicating a high address of the target instruction;
    将所述地址指示符号存储至扩展指令空间,所述扩展指令空间为对所述上一指令的指令空间进行扩展得到的指令空间。And storing the address indication symbol into an extended instruction space, where the extended instruction space is an instruction space obtained by expanding an instruction space of the previous instruction.
  9. 根据权利要求8所述的方法,其特征在于,所述确定所述目标指令的剩余地址,包括:The method according to claim 8, wherein said determining a remaining address of said target instruction comprises:
    从所述扩展指令空间中读取所述地址指示符号;Reading the address indication symbol from the extended instruction space;
    根据所述地址指示符号确定所述目标指令的高位地址。Determining a high address of the target instruction based on the address indication symbol.
  10. 根据权利要求8所述的方法,其特征在于,所述根据低位进位、所述上一指令的高位地址和所述偏移地址的符号,确定所述目标指令的高位地址,包括:The method according to claim 8, wherein the determining the upper address of the target instruction according to the lower carry, the upper address of the previous instruction, and the sign of the offset address, including:
    当所述低位进位为1且所述偏移地址的符号为0时,确定所述目标指令的高位地址等于所述上一指令的高位地址加1;When the lower carry is 1 and the sign of the offset address is 0, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction plus one;
    当所述低位进位为0且所述偏移地址的符号为0,或者,所述低位进位为1且所述偏移地址的符号为1时,确定所述目标指令的高位地址等于所述上一指令的高位地址;When the lower carry is 0 and the sign of the offset address is 0, or the lower carry is 1 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to the upper The high address of an instruction;
    当所述低位进位为0且所述偏移地址的符号为1时,确定所述目标指令的高位地址等于所述上一指令的高位地址减1。When the lower carry is 0 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction minus one.
  11. 根据权利要求1至10任一所述的方法,其特征在于,所述一级指令缓存中,不同指令的指令空间中存储的低位地址在所述指令空间的第0比特对齐。The method according to any one of claims 1 to 10, characterized in that in the first-level instruction cache, the lower address stored in the instruction space of the different instructions is aligned at the 0th bit of the instruction space.
  12. 一种虚拟地址确定装置,其特征在于,所述装置包括:A virtual address determining apparatus, the apparatus comprising:
    第一读取模块,用于从待获取的目标指令的上一指令的指令空间中读取所述目标指令的 低位地址,所述目标指令的低位地址为将所述上一指令写入一级指令缓存之前计算得到并存储在所述上一指令的指令空间中的地址;a first reading module, configured to read a lower address of the target instruction from an instruction space of a previous instruction of the target instruction to be acquired, where the lower address of the target instruction is to write the previous instruction to the first level An address calculated before the instruction cache and stored in the instruction space of the previous instruction;
    第一确定模块,用于确定所述目标指令的剩余地址,所述目标指令的剩余地址的宽度与所述目标指令的低位地址的宽度之和等于所述上一指令的虚拟地址的宽度;a first determining module, configured to determine a remaining address of the target instruction, a sum of a width of a remaining address of the target instruction and a width of a lower address of the target instruction is equal to a width of a virtual address of the previous instruction;
    合并模块,用于将所述目标指令的低位地址与所述目标指令的剩余地址合并,得到所述目标指令的虚拟地址。And a merging module, configured to combine a lower address of the target instruction with a remaining address of the target instruction to obtain a virtual address of the target instruction.
  13. 根据权利要求12所述的装置,其特征在于,所述装置还包括:The device of claim 12, wherein the device further comprises:
    计算模块,用于计算所述目标指令的低位地址;a calculation module, configured to calculate a lower address of the target instruction;
    第一存储模块,用于将所述目标指令的低位地址存储至所述上一指令的指令空间。And a first storage module, configured to store a lower address of the target instruction to an instruction space of the previous instruction.
  14. 根据权利要求13所述的装置,其特征在于,所述计算模块,用于:The device according to claim 13, wherein the calculation module is configured to:
    确定所述上一指令的虚拟地址和所述上一指令所包含的偏移地址;Determining a virtual address of the previous instruction and an offset address included in the previous instruction;
    根据页表的大小,从所述上一指令的虚拟地址中确定所述上一指令的低位地址,并从所述偏移地址中确定所述偏移地址的低位地址,所述上一指令的低位地址与所述偏移地址的低位地址对齐且宽度相等;Determining, according to the size of the page table, a lower address of the previous instruction from a virtual address of the previous instruction, and determining a lower address of the offset address from the offset address, the previous instruction The lower address is aligned with the lower address of the offset address and has the same width;
    将所述上一指令的低位地址与所述偏移地址的低位地址相加,得到所述目标指令的低位地址,所述目标指令的低位地址与所述上一指令的低位地址对齐且宽度相等。Adding a lower address of the previous instruction to a lower address of the offset address to obtain a lower address of the target instruction, and a lower address of the target instruction is aligned with a lower address of the previous instruction and has an equal width .
  15. 根据权利要求14所述的装置,其特征在于,所述装置还包括:The device according to claim 14, wherein the device further comprises:
    第二存储模块,用于将低位进位存储至扩展指令空间,所述低位进位为将所述上一指令的低位地址与所述偏移地址的低位地址相加产生的进位,所述扩展指令空间为对所述上一指令的指令空间进行扩展得到的指令空间。a second storage module, configured to store a lower carry into an extended instruction space, where the lower carry is a carry generated by adding a lower address of the previous instruction and a lower address of the offset address, the extended instruction space An instruction space obtained by expanding the instruction space of the previous instruction.
  16. 根据权利要求15所述的装置,其特征在于,所述剩余地址包括中位地址和高位地址,所述第一确定模块,包括:The device according to claim 15, wherein the remaining address comprises a median address and a high-order address, and the first determining module comprises:
    第一确定子模块,用于从所述偏移地址中确定所述偏移地址的高位地址,所述偏移地址由所述偏移地址的高位地址和所述偏移地址的低位地址组成;a first determining submodule, configured to determine, from the offset address, a high address of the offset address, where the offset address is composed of a high address of the offset address and a lower address of the offset address;
    第二确定子模块,用于根据所述偏移地址的高位地址,从所述上一指令的虚拟地址中确定所述上一指令的中位地址,所述上一指令的中位地址与所述偏移地址的高位地址对齐且宽度相等;a second determining submodule, configured to determine, according to the upper address of the offset address, a median address of the previous instruction from a virtual address of the previous instruction, and a median address of the previous instruction The upper address of the offset address is aligned and the width is equal;
    读取子模块,用于从所述扩展指令空间中读取所述低位进位;Reading a submodule for reading the lower carry from the extended instruction space;
    相加子模块,用于将所述上一指令的中位地址、所述偏移地址的高位地址和所述低位进位相加,得到所述目标指令的中位地址;Adding a sub-module, configured to add a median address of the previous instruction, a high-order address of the offset address, and the low-order carry to obtain a median address of the target instruction;
    第三确定子模块,用于从所述上一指令的虚拟地址中确定所述上一指令的高位地址,所述上一指令的虚拟地址由所述上一指令的高位地址、所述上一指令的中位地址和所述上一指令的低位地址组成;a third determining submodule, configured to determine a high address of the previous instruction from a virtual address of the previous instruction, where a virtual address of the previous instruction is a higher address of the previous instruction, the previous one The median address of the instruction and the lower address of the previous instruction are composed;
    第四确定子模块,用于根据中位进位、所述上一指令的高位地址和所述偏移地址的符号,确定所述目标指令的高位地址,所述中位进位为将所述上一指令的中位地址、所述偏移地址的高位地址和所述低位进位相加产生的进位。a fourth determining submodule, configured to determine a high address of the target instruction according to a median carry, a high address of the previous instruction, and a sign of the offset address, where the median carry is the previous one The median address of the instruction, the upper address of the offset address, and the carry of the lower carry are added.
  17. 根据权利要求16所述的装置,其特征在于,所述第四确定子模块,用于:The apparatus according to claim 16, wherein said fourth determining submodule is configured to:
    当所述中位进位为1且所述偏移地址的符号为0时,确定所述目标指令的高位地址等于所述上一指令的高位地址加1;When the median carry is 1 and the sign of the offset address is 0, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction plus one;
    当所述中位进位为0且所述偏移地址的符号为0,或者,所述中位进位为1且所述偏移地址的符号为1时,确定所述目标指令的高位地址等于所述上一指令的高位地址;When the median carry is 0 and the sign of the offset address is 0, or the median carry is 1 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to State the upper address of an instruction;
    当所述中位进位为0且所述偏移地址的符号为1时,确定所述目标指令的高位地址等于所述上一指令的高位地址减1。When the median carry is 0 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction minus one.
  18. 根据权利要求13所述的装置,其特征在于,所述计算模块,用于:The device according to claim 13, wherein the calculation module is configured to:
    确定所述上一指令的虚拟地址和所述上一指令所包含的偏移地址;Determining a virtual address of the previous instruction and an offset address included in the previous instruction;
    根据所述偏移地址确定所述上一指令的低位地址,所述上一指令的低位地址与所述偏移地址对齐且宽度相等;Determining, according to the offset address, a lower address of the previous instruction, where a lower address of the previous instruction is aligned with the offset address and the width is equal;
    将所述上一指令的低位地址与所述偏移地址相加,得到所述目标指令的低位地址,所述目标指令的低位地址与所述上一指令的低位地址对齐且宽度相等。And adding the lower address of the previous instruction to the offset address to obtain a lower address of the target instruction, and the lower address of the target instruction is aligned with the lower address of the previous instruction and the width is equal.
  19. 根据权利要求18所述的装置,其特征在于,所述剩余地址包括高位地址,所述装置还包括:The device of claim 18, wherein the remaining address comprises a high address, the device further comprising:
    第二确定模块,用于从所述上一指令的虚拟地址中确定所述上一指令的高位地址,所述上一指令的虚拟地址由所述上一指令的高位地址和所述上一指令的低位地址组成;a second determining module, configured to determine, from a virtual address of the previous instruction, a high-order address of the previous instruction, where a virtual address of the previous instruction is a higher-order address of the previous instruction and the previous instruction Composition of the lower address;
    第三确定模块,用于根据低位进位、所述上一指令的高位地址和所述偏移地址的符号,确定所述目标指令的高位地址,所述低位进位为将所述上一指令的低位地址和所述偏移地址相加产生的进位;a third determining module, configured to determine a high address of the target instruction according to a lower carry, a higher address of the previous instruction, and a sign of the offset address, where the lower carry is a lower bit of the previous instruction a carry generated by adding the address and the offset address;
    生成模块,用于生成地址指示符号,所述地址指示符号指示所述目标指令的高位地址;Generating a module, configured to generate an address indicator, the address indicator indicating a high address of the target instruction;
    第三存储模块,用于将所述地址指示符号存储至扩展指令空间,所述扩展指令空间为对所述上一指令的指令空间进行扩展得到的指令空间。And a third storage module, configured to store the address indication symbol into an extended instruction space, where the extended instruction space is an instruction space obtained by expanding an instruction space of the previous instruction.
  20. 根据权利要求19所述的装置,其特征在于,所述第一确定模块,用于:The device according to claim 19, wherein the first determining module is configured to:
    从所述扩展指令空间中读取所述地址指示符号;Reading the address indication symbol from the extended instruction space;
    根据所述地址指示符号确定所述目标指令的高位地址。Determining a high address of the target instruction based on the address indication symbol.
  21. 根据权利要求19所述的装置,其特征在于,所述第三确定模块,用于:The device according to claim 19, wherein the third determining module is configured to:
    当所述低位进位为1且所述偏移地址的符号为0时,确定所述目标指令的高位地址等于所述上一指令的高位地址加1;When the lower carry is 1 and the sign of the offset address is 0, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction plus one;
    当所述低位进位为0且所述偏移地址的符号为0,或者,所述低位进位为1且所述偏移地址的符号为1时,确定所述目标指令的高位地址等于所述上一指令的高位地址;When the lower carry is 0 and the sign of the offset address is 0, or the lower carry is 1 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to the upper The high address of an instruction;
    当所述低位进位为0且所述偏移地址的符号为1时,确定所述目标指令的高位地址等于所述上一指令的高位地址减1。When the lower carry is 0 and the sign of the offset address is 1, it is determined that the upper address of the target instruction is equal to the upper address of the previous instruction minus one.
  22. 根据权利要求12至21任一所述的装置,其特征在于,所述一级指令缓存中,不同指令的指令空间中存储的低位地址在所述指令空间的第0比特对齐。The apparatus according to any one of claims 12 to 21, wherein in the primary instruction cache, the lower address stored in the instruction space of the different instructions is aligned at the 0th bit of the instruction space.
  23. 一种处理器,其特征在于,所述处理器包括权利要求12至22任一所述的虚拟地址确定装置。A processor, comprising the virtual address determining apparatus according to any one of claims 12 to 22.
  24. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中存储有指令,当所述指令在计算机的处理器上运行时,使得所述处理器执行权利要求1至11任一所述的虚拟地址确定方法。A computer readable storage medium, wherein the computer readable storage medium stores instructions that, when executed on a processor of a computer, cause the processor to perform any of claims 1 to The virtual address determining method.
  25. 一种包含指令的计算机程序产品,其特征在于,当所述计算机程序产品在计算机的处理器上运行时,使得所述处理器执行权利要求1至11任一所述的虚拟地址确定方法。A computer program product comprising instructions, wherein the computer program product, when run on a processor of a computer, causes the processor to perform the virtual address determining method of any of claims 1-11.
  26. 一种处理装置,其特征在于,所述处理装置包括至少一个电路,所述至少一个电路用于执行权利要求1至11任一所述的虚拟地址确定方法。A processing apparatus, characterized in that the processing means comprises at least one circuit for performing the virtual address determining method according to any one of claims 1 to 11.
  27. 一种芯片,其特征在于,所述芯片包括可编程逻辑电路和/或程序指令,当所述芯片运行时用于实现权利要求1至11任一所述的虚拟地址确定方法。A chip, characterized in that the chip comprises programmable logic circuitry and/or program instructions for implementing the virtual address determination method of any of claims 1 to 11 when the chip is in operation.
  28. 一种处理装置,其特征在于,所述处理装置用于实现权利要求1至11任一所述的虚拟地址确定方法。A processing device, characterized in that the processing device is configured to implement the virtual address determining method according to any one of claims 1 to 11.
PCT/CN2018/102225 2018-01-03 2018-08-24 Virtual address determining method and apparatus, processor, and storage medium WO2019134376A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201810005947.X 2018-01-03
CN201810005947.XA CN109992529B (en) 2018-01-03 2018-01-03 Virtual address determination method and device, processor and storage medium

Publications (1)

Publication Number Publication Date
WO2019134376A1 true WO2019134376A1 (en) 2019-07-11

Family

ID=67128625

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/102225 WO2019134376A1 (en) 2018-01-03 2018-08-24 Virtual address determining method and apparatus, processor, and storage medium

Country Status (2)

Country Link
CN (1) CN109992529B (en)
WO (1) WO2019134376A1 (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6374342B1 (en) * 2000-01-31 2002-04-16 Kabushiki Kaisha Toshiba Translation lookaside buffer match detection using carry of lower side bit string of address addition
CN1536493A (en) * 2003-04-11 2004-10-13 ������������ʽ���� Information processing device and method, storage medium, program and camera device
CN103885893A (en) * 2012-12-19 2014-06-25 辉达公司 Technique For Accessing Content-Addressable Memory
CN103970507A (en) * 2014-05-21 2014-08-06 龙芯中科技术有限公司 Method and device for 64-bit virtual machine to process memory-reference instrument

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPS623338A (en) * 1985-06-28 1987-01-09 Yokogawa Hewlett Packard Ltd Direct value processing system
JPH06231047A (en) * 1993-02-05 1994-08-19 Fujitsu Ltd Address converting method and device
US6592449B2 (en) * 2001-02-24 2003-07-15 International Business Machines Corporation Smart fan modules and system
JP4484630B2 (en) * 2004-01-29 2010-06-16 パナソニック株式会社 Variable length decoding apparatus, variable length decoding method and playback system
CN102841865B (en) * 2011-06-24 2016-02-10 上海芯豪微电子有限公司 High-performance cache system and method
US10108424B2 (en) * 2013-03-14 2018-10-23 Nvidia Corporation Profiling code portions to generate translations
CN104679481B (en) * 2013-11-27 2020-04-28 上海芯豪微电子有限公司 Instruction set conversion system and method

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6374342B1 (en) * 2000-01-31 2002-04-16 Kabushiki Kaisha Toshiba Translation lookaside buffer match detection using carry of lower side bit string of address addition
CN1536493A (en) * 2003-04-11 2004-10-13 ������������ʽ���� Information processing device and method, storage medium, program and camera device
CN103885893A (en) * 2012-12-19 2014-06-25 辉达公司 Technique For Accessing Content-Addressable Memory
CN103970507A (en) * 2014-05-21 2014-08-06 龙芯中科技术有限公司 Method and device for 64-bit virtual machine to process memory-reference instrument

Also Published As

Publication number Publication date
CN109992529B (en) 2021-07-16
CN109992529A (en) 2019-07-09

Similar Documents

Publication Publication Date Title
JP7284199B2 (en) Backwards compatibility through algorithm matching, feature disablement, or performance limitations
JP5539432B2 (en) Vector mask setting technology
JP7159223B2 (en) Method and system for managing cache contention
TWI499973B (en) Managing and implementing metadata in central processing unit using register extensions
EP2542973B1 (en) Gpu support for garbage collection
KR101839479B1 (en) Mode dependent partial width load to wider register processors, methods, and systems
JP6467605B2 (en) Instruction processing system and method
WO2018027839A1 (en) Method for accessing table entry in translation lookaside buffer (tlb) and processing chip
US5621896A (en) Data processor with unified store queue permitting hit under miss memory accesses
CN112631657B (en) Byte comparison method for character string processing and instruction processing device
JP3837289B2 (en) Microprocessor containing multiple register files occupying the same logical space
US8095775B1 (en) Instruction pointers in very long instruction words
US11436146B2 (en) Storage control apparatus, processing apparatus, computer system, and storage control method
JP2004133935A (en) Memory system for calculation circuit having pipeline and method for providing pipeline function unit with data
JP3811140B2 (en) Information processing device
WO2019134376A1 (en) Virtual address determining method and apparatus, processor, and storage medium
US20210089305A1 (en) Instruction executing method and apparatus
JPH08249178A (en) Method and apparatus for formation of modifier bit at inside of annex of processor
US20140365751A1 (en) Operand generation in at least one processing pipeline
WO2016201699A1 (en) Instruction processing method and device
US8645791B2 (en) Data cache controller, devices having the same, and method of operating the same
CN113885943A (en) Processing unit, system on chip, computing device and method
JP2003202981A (en) Address range checking circuit and method of operation
KR101635856B1 (en) Systems, apparatuses, and methods for zeroing of bits in a data element
JP4002288B2 (en) Information processing device

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18898538

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 18898538

Country of ref document: EP

Kind code of ref document: A1