Method and apparatus for providing fast switching between floating point and multimedia instructions using any combination of a first register file set and a second register file set6145049Abstract A system and method is provided that adds another floating point register set in the floating point execution unit of a microprocessor. Thus, when the floating point state, or environment is stored as an image into memory, it is also stored as a copy in the additional internal registers. When the state, or environment, is to be restored the necessary information (data and/or instructions) is normally present in the additional registers, thus saving CPU cycles by avoiding reloading the image from memory. The present invention allows for either of the two register sets (or a combination thereof) to be, at a given point in time, the working set, with the other being a shadow register set. All of the memory write cycles are monitored (snooped) to determine if the information in the on-chip image has been altered, since the last store operation. The shadowed register file will allow the state of the floating point register file to be kept "as is" on the occurrence of a task switch. Claims What is claimed is: Description BACKGROUND OF THE INVENTION
______________________________________
ENV[.about.env.sub.-- ptr] = INIT.sub.-- ENVIRONMENT
REG[.about.reg.sub.-- ptr] = REG[reg.sub.-- ptr]
SNOOP.sub.-- REG.address = FNSAVE.sub.-- address
env.sub.-- tr = .about.env.sub.-- ptr
reg.sub.-- tr = .about.reg.sub.-- ptr
env.sub.-- dirty = 0
reg.sub.-- dirty = 0
______________________________________
Next, the store environment instruction (FSTENV) will be described. Again, the working set will initially be set ={ENV[env.sub.-- ptr], REG[reg.sub.-- ptr]}. The FNSTENV instruction is then processed and the CPU prepares switching over to the new working set by setting the previous environment pointer bit value for the working set as the new environment bit pointer in register 121, ENV[env.sub.-- ptr] to ENV[.about.env.sub.-- ptr]. Again, this copy-over is a requirement FSTENV at the instruction level to ensure compatibility. The CPU then overwrites the snoop address register 120 with the address from the FSTENV instruction. The ENV pointer bit is then flipped and a new working set={ENV[env.sub.-- ptr], REG[reg.sub.-- ptr]} is formed. It should be noted that the FSTENV instruction only stores the environment and not the register file, therefore, only the ENV pointer bit in register 121 is flipped to create the new working set. Next, the ENV dirty bit in register 122 is turned off (0) and the REG dirty bit is register 124 is turned on (1) and a new on-chip image is formed={ENV[.about.env.sub.-- ptr]}. Again, since FSTENV only stores the environment registers, the ENV dirty bit is the only one that is set=0. Therefore, the new on-chip image will include only the environment registers, as shown in FIG. 3. These operations associated with execution of the FSTENV instruction all occur in a single CPU cycle. Pseudo-code for FSTENV:
______________________________________
ENV[.about.env.sub.-- ptr] = ENV[env.sub.-- ptr]
SNOOP.sub.-- REG.address = FNSTENV.sub.-- address
env.sub.-- ptr = .about.env.sub.-- ptr
env.sub.-- dirty = 0
reg.sub.-- dirty = 1
______________________________________
When the state of the execution unit is to be restored an FRSTOR instruction is processed. Initially, the working set={ENV[env.sub.-- ptr], REG[reg.sub.-- ptr]} and FRSTOR is then processed. The CPU compares the data address from the FRSTOR instruction encoding against the address in snoop register 120. The CPU also looks up the values in both the ENV dirty bit register 122 and REG dirty bit register 124. The ENV pointer bit in register 121 and REG pointer bit in register 123 are then flipped, and the ENV dirty bit in register 122 and REG dirty bit in register 124 are turned on, only when: (1) the address comparison between snoop address register 120 and FRSTOR instruction is a match; and (2) both the dirty bits in registers 122, 124 are determined to be off (0). This indicates that neither the memory image nor the on-chip image has not been modified and the state and be restored from the shadowed register set. A new working set={ENV[env.sub.-- ptr], REG[reg.sub.-- ptr]}, and a new shadowed set={ENV[.about.env.sub.-- ptr], REG[.about.reg.sub.-- ptr] } are formed. These operations associated with FRSTOR all happen within one CPU clock cycle If either the snoop address does not match the FRSTOR address, or either of the dirty bits in registers 122, 124 are turned on (1), then the pointer and dirty bits are not changed and the state is loaded from memory. Pseudo-code for FRSTOR:
______________________________________
if((SNOOP.sub.-- REG.address == FRSTOR.sub.-- address) &&!(env.sub.--
dirty
.parallel. reg.sub.-- dirty)) then
env.sub.-- ptr = .about.env.sub.-- ptr
reg.sub.-- ptr = .about.reg.sub.-- ptr
env.sub.-- dirty = 1
reg.sub.-- dirty = 1
else
ENV[env.sub.-- ptr] = MEMOR[FRSTOR.sub.-- address].ENV
REG[reg.sub.-- ptr] = MEMORY[FRSTOR.sub.-- address].REG
endif
______________________________________
The operation of the present invention for loading the save environment by processing the FLDENV instruction will now be described. Initially, the working set={ENV[env.sub.-- ptr], REG[reg.sub.-- ptr]}. The FLDENV instruction is then processed. The CPU compares the data address from the FLDENV instruction encoding against the address in snoop register 120. The CPU also looks up the ENV dirty bit in register 122 to determine if it is still off. The ENV pointer bit in register 121 is flipped and both the ENV dirty bit and REG dirty bits are turned on (1), only when: (1) the address comparison between the FLDENV address and the address in snoop register 120 is a match; and (2) the ENV dirty bit in register 122 is turned off (0). A new working set={ENV[env.sub.-- ptr], REG[reg.sub.-- ptr]} and a new shadowed set ={ENV[.about.env.sub.-- ptr], REG[.about.reg.sub.-- ptr]} are then formed. These operations, associated with the FLDENV instruction, all occur in a single CPU cycle. If the snoop address comparison with the FLDENV address in not a match, or the ENV dirty bit in register 122 is on (1), then the pointer and dirty bits are not changed and the environment is loaded from memory. Pseudo-code for FLDENV:
______________________________________
if((SNOOP.sub.-- REG.address == FLDENV.sub.-- adress) &&!env.sub.--
dirty)) then
env.sub.-- ptr = .about.env.sub.-- ptr
env.sub.-- dirty = 1
reg.sub.-- dirty = 1
else
ENV[env.sub.-- ptr] = MEMORY[FLDENV.sub.-- adress}.ENV
endif
______________________________________
The CPU is reset with the control bits initialized as follows: (1) ENV pointer in register 121=0; (2) ENV dirty bit in register 122=0; (3) REG pointer in register 123=0; and (4) REG dirty bit in register 124=1. These bits are initially set to these values and will remain there until one of either the FNSAVE, FRSTOR, FSTENV or FLDENV instructions are executed. Basically, the pointer bits set=0 indicate that the initial working set for the CPU will be register set 0, 100 (FIGS. 2 and 4). By initializing the dirty bits=1 this means that data will initially be loaded from memory into the current working set (register 0 at initialization), if either the FRSTOR or FLDENV instruction were the first instructions to be executed. Pseudo-code for CPU reset:
______________________________________
ENV[0] = RESET.sub.-- ENVIRONMENT
REG[0] = RESET.sub.-- REGISTERS
env.sub.-- dirty = 1
reg.sub.-- dirty = 1
SNOOP.sub.-- REG.address = XXXXXXXX
env.sub.-- ptr = 0
reg.sub.-- ptr = 0
______________________________________
When snooping the address register 120, the CPU looks at every memory write cycle. If the floating point state memory image (ENV and REG) is being written, both the ENV dirty bit in register 122 and REG dirty bit in register 124 will be turned on (1) in the same CPU cycle. If the floating point environment memory image (ENV only) is being written to, the ENV dirty bit in register 122 will be turned on (1) in a single CPU cycle. Referring to FIG. 5, the present invention is shown with register set 0, 110 as the working set. The working set 110 includes ENV registers 112 and REG file 111. In FIG. 5, the FSTENV instruction has been executed thereby storing the ENV to a location 132 in memory 13. Register set 1, 100, including ENV registers 102 is the shadowed register set and constitutes the on-chip image. For an FSTENV instruction the on-chip image will be the ENV only, since that is what is stored. When an FNSAVE instruction is executed, the on-chip image will be both the ENV and REG, since the entire FP state is saved by this instruction. Therefore, it can be seen that the on-chip image is a subset of the shadowed registers. If there is no snoop address match and if the ENV dirty bit in register 122 is turned off, then the floating point environment can be restored from the ENV registers 102 of the on-chip image when the previous state is loaded (FLDENV) due to the occurrence of a context switch (pointer bits flip). FIG. 6 illustrates the relationship of the working set, memory and shadowed set when the entire state is saved, i.e. FNSAVE instruction is executed. Again, it is assumed that register set 0, 110 is the working set and the CPU is accessing ENV registers 112 and REG file 111 to execute instructions, such as floating point or MMX (depending on the context). When the context is to switch an FNSAVE instruction is executed and both the ENV 112 and REG 111 (state) are stored in memory 13 at locations 132, 131, respectively. In this case the on-chip image is a copy of the memory image, with ENV registers 102 including the same information as memory location 132 and REG file 101 having identical information to memory location 131. Upon execution of an FRSTOR instruction, the CPU checks the snoop address with the FRSTOR address and determines if the ENV and REG dirty bits are off. If there have been no snoop hits and the dirty bits are off, then the context can be restored from the on-chip image. For the purposes of clarity it has been shown in FIGS. 5 and 6 that the working set includes ENV and REG registers corresponding to register set 0 and the shadowed set includes ENV and REG registers that are physically part of register set 1 . As described above, either register set 0 or register set 1 will be designated as the working or shadowed set. However, the present invention also comprehends the configuration where a working set may include the ENV registers from register set 0 and the REG register from register set 1, i.e. the working set may consist of ENV 112 and REG 101. This would occur if ENV pointer bit is set=0 and REG pointer bit is set=1. In this case, ENV 102 and REG 111 would be the shadowed set. Of course, ENV register 102 and REG register 111 could also be designated as the working set with ENV 112 and REG 101 being the shadowed set, when the ENV pointer bit is set=1 and the REG pointer bit is set=0. This preferred embodiment is shown in FIG. 7. When both the ENV and REG pointer bits are set=0, then register set 0, 110 is the working set and ENV 112 operates with REG 111 as shown by reference numeral 150. If both pointer bits are set=1, then register set 100 is the working set, as can be seen by reference numeral 151. However, when ENV bit is set=0 and REG bit is set=1, then the working set is ENV 112 and REG 101, as shown by reference 152. Similarly, reference numeral 153 shows the instance when the ENV pointer is set=1 and REG pointer is set=0. Thus, the present invention provides a great deal of flexibility by enabling dynamic selection of the registers that will make up the working set and shadowed set. Referring to FIG. 8, a 2 bit, pointer bit state machine is shown which will be used to explain the operation of the present invention relative to how the ENV and REG pointer bits in registers 121 and 123, respectively, are set. The state machine is organized as "Current State", "Inputs" and "Next State", "X" refers to a "don't care" value (can be either logical 0 or logical 1). There will be four possible current states, i.e., register set 0 is the working set; register set 1 is the working set; the ENV of register set 0 and REG of register set 1 is the working set; and the ENV of register set 1 and REG of register set 0 is the working set. The state machine does not address the case where a snoop hit occurs and the saved address does not match the restore address. This is because the state must be restored from memory and all pointer and dirty bits are unchanged. ENV and REG dirty bits are provided by the present invention to address the situation of a snoop hit occurring wherein the saved information is modified. The pointer state machine of FIG. 8 provides an implementation of the process previously described with reference to the pseudo-code corresponding to each of the FNSAVE, FRSTOR, FSTENV, FLDENV instructions. The current state values correspond to the present ENV and REG pointer bits, the next state values correspond to the logical value that the ENV and REG pointer are driven to, based on the instructions being executed. The input values correspond to which instructions are being executed (FNSAVE, FRSTOR, FSTENV, FLDENV), whether a snoop hit occurs and the state of the ENV and REG dirty bits. In the initial current state (of the pointer bit registers 121, 123) both the REG and ENV bits are set=0 (0, 0) such that the working set is register set 0, 110. When a store ENV (FSTENV) instruction is executed there is no snoop hit (is.sub.-- match) because the storing of the ENV is being implemented and the env.sub.-- dirty bit and reg.sub.-- dirty bits are don't care. Therefore, when only the ENV is saved, the ENV pointer bit in register 121 is the only pointer affected. Thus, the next state is (1, 0). When a load ENV (FLDENV) is executed and the snooping mechanism determines that the saved ENV address is the same (match) as the address in the load instruction, then the next state remains at (1, 0) because the ENV can be loaded from the "on-chip" image. Next, for the case of an FNSAVE instructions, both the REG and ENV pointer bits are flipped from (0, 0) to (1, 1) because this instruction saves both the REG and ENV states. When the saved state is to be restored by an FRSTOR instructions and an address match occurs, then the ENV and REG bits remain in the next state of (1, 1). If none of the above conditions are met (ELSE), then there is no change in ENV and REG pointer bit values. It should be noted that the FNSAVE, FRSTOR, FSTENV and FLDENV instructions execute in a mutually exclusive manner such that only one of the fields corresponding to these instructions in the state machine can be active at one time. The next possible current state is when the ENV is from register set 0 and the REG is from register set (1, 0). Again, the FSTENV instruction will only affect the ENV pointer bit and the next state is flipped to the ENV from register set 1, with the REG pointer remaining the same. Thus, the next state will be (1, 1). The FLDENV instruction will also only affect the ENV pointer bit and for address matches the next state will also be (1, 1). For the FNSAVE and FRSTOR instructions, both the ENV and REG pointer bits are affected and will be flipped such that the next state for both of these cases is (1, 0). If none of the above conditions occur, then the current state is unchanged. When the current state uses the ENV from register set 1 and REG from register set 0 (1, 0), the FSTENV and FLDENV instructions will flip the ENV pointer bits to cause the next state to be (0, 0). While, the FNSAVE and FRSTOR instructions affect both the ENV and REG pointer bits causing them to be changed to (0, 1) for the next state. If these conditions do not occur, then there is no change. Finally, when the working set is register set 1 (ENV and REG set=1), (1, 1), the FSTENV and FLDENV instructions will save and restore only the ENV state and the ENV pointer bit will be flipped to 0, causing the next state to be (0, 1). Again, the FNSAVE and FRSTOR instructions will cause both the ENV and REG bits to be flipped and the next state will becomes (0, 0). Otherwise, there is no change in the REG and ENV pointer bit values and they will remain at (1, 1). As previously noted, there are four states in this state machine--state 00, state 01, state 10 and state 11. The states are encoded so that the encoded state bits are the pointer-bits. The most significant bit (leftmost bit) corresponds to ENV pointer bit while the least significant bit (rightmost bit) corresponds to REG pointer bit. For instance if the state machine is in state 10, then the working set comprises environment registers from register set 1, data register file from register set 0. The input signals used to drive the state machine are is.sub.-- fnsave, is.sub.-- frstor, is.sub.-- fnstenv, is.sub.-- fldenv, is.sub.-- match, env.sub.-- dirty and reg.sub.-- dirty. The signals is.sub.-- fnsave, is.sub.-- frstor, is.sub.-- fnstenv, is.sub.-- fldenv are generated from fetch/decode/issue stage 18, and only one of them can be high (1) at a time. Signal is.sub.-- match signifies that an address match is found between the address from snoop register and the address from the source operand of either FRSTOR or FLDENV instructions. Signals env.sub.-- dirty and reg.sub.-- dirty is the current state bits of the dirty-bit state machine. The pointer bit state machine makes a transition out of a state if either: (1) the FNSAVE instruction is found at the decode stage; or (2) the FRSTOR instruction is found at the decode stage. It can also be seen that the on-chip image has the state which FRSTOR intended to restore (signified by signal is.sub.-- match) and the memory content of the on-chip image has not been modified since last state saving operation (signified by both signal env.sub.-- dirty and reg.sub.-- dirty being low). In the state diagram (FIG. 10) conditions (1) and (2) are "ORed" together as signal "s" signifying it is state related. The pointer bit state machine also makes a transition out of a state when: (3) an FNSTENV instruction is found at the decode stage; or (4) an FLDENV instruction is found at the decode stage. It is also found that the on-chip image includes the environment data which FLDENV intended to restore (signified by signal is.sub.-- match) and the memory content of the on-chip image has not been modified since last state saving (signified by signal env.sub.-- dirty being low). In the state diagram (FIG. 10) conditions (3) and (4) are "ORed" together as signal "e" signifying it is environment data related. The state machine stays in its original state in all other cases. The state transition conditions are associated with each state transition arc in FIG. 10. Referring to FIG. 9, a 2 bit, dirty bit state machine is shown and will now be described. As with the pointer state machine of FIG. 8, the FNSAVE, FRSTOR, FSTENV and FLDENV instructions are mutually exclusive and only on can be active at a single time. In general, the dirty bits attach to the shadowed working set. When the ENV dirty bit from register 122 and/or the REG dirty bit from register 124 is on, set=1, then the corresponding environment or register information must be retrieved from memory. For example, when ENV dirty bit 122 is logical 1, then, upon a task switch, the ENV for the task being switched to must be restored from memory. The actual bits in dirty bit registers 122, 124 become a logical 1 for two reasons: (1) the bits are set=1 for some "don't care" instances to prevent its use; and (2) when an actual snoop hit occurs. The dirty bit state machine of FIG. 9 shows an implementation of the process previously described with reference to the pseudo-code corresponding to each of the FNSAVE, FRSTOR, FSTENV, FLDENV instructions. Many of the "don't care" situations for the dirty bit state machine have been deleted from FIG. 9. For the first current state shown in FIG. 9, the ENV dirty bit in register 122 and REG dirty bit in register 124 are set=0, indicating that there has been no snoop hit and the saved information from the previous state has not been modified. For the FSTENV instruction it does not matter if the address of the saved ENV information is a match, since there is not any information being restored. The CPU overwrites the snoop address register 120 with the FSTENV store address and the ENV dirty bit remains off with the REG dirty bit turned on to create a new on-chip image that consists of the stored ENV information. When the FLDENV instruction is executed, the CPU compares the FLDENV data address with the snoop address and looks up the ENV dirty bit. The ENV and REG dirty bits are turned on (1) when the address comparison is a match and the ENV dirty bit is off (0). Since the current state has the ENV dirty bit set=0 and a match did occur (is.sub.-- match), then both the ENV and REG dirty bits are set=1 (1, 1). When an FRSTOR instruction executes the CPU compares the data address in the restore instruction with the address in the snoop register 120. Both the ENV and REG dirty bits are turned on to the next state (1, 1) when they are both initially off and an address match has occurred. When none of the above conditions occur (ELSE), then there is no change and the next state of the ENV and REG dirty bits remains at (0, 0). The next current state of the dirty bits is when the ENV dirty bit is set=0 and the REG dirty is set=1, indicating that the stored REG state has been modified. In this case, when an FLDENV instruction occurs and there is an address match, and the ENV dirty bit is off (0), then both the ENV and REG dirty bits are turned on (set=1), (1, 1) to the next state. For an FNSAVE instruction it does not matter whether an address match occurs, because the address of the snoop register 120 is being overwritten with the FNSAVE address. The ENV and REG dirty bits are both turned off and a new on-chip image is formed. If neither of the above conditions are met when the current state of the ENV and REG dirty bits is (0, 1), then the next state is unchanged from the current state and remains at (0, 1). When the current state of the ENV and REG dirty bits is (1, 1), and a FSTENV instruction is executed, the CPU overwrites the snoop register 120 with the store address from the FSTENV instruction. The ENV dirty bit is turned off (0) and the REG dirty bit is turned on (1). Therefore, the next state is the ENV dirty bit set=0 with the REG dirty bit remaining set=1, i.e. (0, 1). For an FNSAVE instruction, the address of the snoop register is also overwritten with the store address from the FNSAVE instruction. The ENV and REG dirty bits are set=0, (0, 0). If these conditions are not met (ELSE), then no change occurs and the next state is the same as the current state, i.e. (1, 1). There are three states in this dirty bit state machine--state 00, state 01 and state 11. The states are encoded so that the encoded state bits are the dirty-bits. The most significant bit (leftmost bit) corresponds to ENV dirty bit while the least significant bit (rightmost bit) corresponds to REG dirty bit. For instance if the state machine is in state 01, then environment registers in the shadowed set are marked non-dirty and the data register file in the shadowed set is marked dirty. The input signals used to drive the state machine are is.sub.-- fnsave, is.sub.-- frstor, is.sub.-- fnstenv, is.sub.-- fldenv, is.sub.-- match. The signals is.sub.-- fnsave, is.sub.-- frstor, is.sub.-- fnstenv, is.sub.-- fldenv are generated from fetch/decode/issue stage 18, and only one of them can be high (1) at a time. Signal is.sub.-- match signifies that an address match is found between the address from snoop register and the address from the source operand of either FRSTOR or FLDENV instructions. The dirty bit state machine makes transition from state 00 to state 11 if either FRSTOR or FLDENV instruction is found at decode stage and the on-chip image has the state or environment data which either the FRSTOR or FLDENV instruction intended to restore. Both the environment dirty bit and register dirty bit are marked high to signify that the shadowed set does not have a valid on-chip image after the restoration. Transition from state 00 to state 01 is made if the FSTENV instruction is found at the decode stage. The environment dirty bit is marked low to signify that the environment registers from the shadowed set are part of the on-chip image. The register dirty bit is marked high to signify that the register file in the shadowed set is not part of the on-chip image. Otherwise, the state machine stays in state 00. The dirty bit state machine makes the transition from state 11 to state 00 if an FNSAVE instruction is found at the decode stage. Both the environment dirty bit and register dirty bit are marked low to signify that both the environment registers and register file in the shadowed set are part of the on-chip image. Transition from state 11 to state 01 is made if the FSTENV instruction is found at the decode stage. The environment dirty bit is marked low to signify that the environment registers from the shadowed set are part of the on-chip image. The register dirty bit is marked high to signify that the register file in the shadowed set is not part of the on-chip image. Otherwise, the state machine stays in state 11. The dirty bit state machine makes the transition from state 01 to state 00 if the FNSAVE instruction is found at the decode stage. Both the environment dirty bit and register dirty bit are marked low to signify that both environment registers and register file from the shadowed set are part of the on-chip image. Transition from state 01 to state 11 occurs if the FLDENV instruction is found at the decode stage and the on-chip image includes the environment data which FLDENV intends to restore. Both the environment dirty bit and register dirty bit are marked high to signify that the shadowed set does not have a valid on-chip image. Otherwise, the state machine stays in state 01. Referring to FIG. 10, a state diagram is shown for the pointer bit state machine of FIG. 8. Each of the four possible pointer bit states are shown, with the first character representing the ENV pointer in register 121 and the second character representing the REG pointer in register 123. For example, state (0, 0) indicates that the ENV pointer and REG pointer are both set=0 such that register set 0 is the working set. State (1, 1) indicates that register set 1 is the working set, since both the ENV and REG pointers reference ENV register 102 and REG register 101. State (1, 0) means that the working set includes ENV register 102 and REG 111, or a combination of register sets 1 and 0. Similarly, state (0, 1) includes ENV register 112 and REG 101 such that a combination of register 1 and 0 is designated as the working set. The three signals used in the state diagram of FIG. 10 are defined as: (s)--where the instruction is an FNSAVE and the FRSTOR instruction address matches the snoop register address and both the ENV and REG dirty bits are off {is.sub.-- fnsave .parallel. (is.sub.-- frstor && is.sub.-- match && !env.sub.-- dirty && !reg.sub.-- dirty)}; (e)--the instruction is FNSTENV and the FLDENV instruction address matches the snoop register address and the ENV dirty bit is off {is.sub.-- fnstenv .parallel. (is.sub.-- fldenv && is.sub.-- match && !env.sub.-- dirty)}; and (r)--the result of the functions (s) and (r) is 0, {!(s .parallel. e)}, and no change in state will occur. It can be seen from the state diagram of FIG. 10 that the FNSAVE instruction and corresponding FRSTOR instruction, as embodied in signal (s) will cause both of the ENV and REG pointer bits to change state. For example, state (0, 0) will change to state (1, 1) when signal (s) is applied. Also, state (1, 1) will change to (0, 0) when signal (s) is applied. Similarly, state (0, 1) will become (1, 0) and state (1, 0) will become (0, 1) in response to signal (s). As previously described the FNSAVE instruction and FRSTOR instruction will save and restore both the ENV registers and REG register file, thus both the ENV and REG pointer bits must change state in response to these instructions. However, the FNSTENV and FLDENV instructions only store and load the ENV state information. Thus, only the ENV pointer bit will change state in response to the application of signal (e). From FIG. 10, it can seen that state (1, 1) will become state (0, 1) and state (0, 1) will return to state (1, 1) in response to signal (e). Also, state (0, 0) will become state (1, 0) when signal (e) is applied. Likewise, signal (e) will cause (1, 0) to become (0, 0). In each case where signal (e) is utilized, the FNSTENV and FLDENV instructions cause only the first pointer bit (ENV) in register 121 to be changed, while the REG pointer bit in register 123 remains constant. In all cases the (r) signal will not cause any change in the state of the ENV and REG pointer bits. Referring to FIG. 11, a state diagram is shown which represents the dirty bit state machine of FIG. 9. The three possible states are shown, i.e. (0, 0), (0, 1) and (1, 1). In order to change states from (0, 0) to (1, 1), the state machine determines that a match exists between either the FRSTOR or FLDENV encoded address and the address in snoop address register 120 {is.sub.-- match && (is.sub.-- frstor .parallel. is.sub.-- fldenv)}. In this case both the ENV and REG dirty bits are set=1. A state change from (1, 1) to (0, 0), occurs when the instruction is determined to be an FNSAVE (is.sub.-- fnsave). A state change from (0, 1) to (1, 1) occurs when the address in an FLDENV instruction and the snoop address in register 120 are a match (is.sub.-- fldenv && is.sub.-- match). The state change from (1, 1) to (0, 1) will occur upon the execution of an FNSTENV instructions (is.sub.-- fnstenv). State (0, 1) becomes (0, 0) upon the occurrence of a save instruction (is.sub.-- fnsave), while the state change form (0, 0) to (0, 1) occurs when a store environment instruction is executed (is.sub.-- fnstenv). State (0, 0) will be maintained when the instruction is a store environment (FNSTENV) and the address encoded in either of a corresponding restore instruction or load environment instruction (FRSTOR, FLDENV) matches the address in the snoop register {!(is.sub.-- fnstenv .parallel. (is.sub.-- match && (is.sub.-- frstor .parallel. is.sub.-- fldenv)))}. State (1, 1) will remain unchanged when the instruction is a save state or save environment instruction (FNSAVE or FNSTENV), {!(is.sub.-- fnsave .parallel. is.sub.-- fnstenv)}. Finally, state (0, 1) will be unchanged when the save instruction is being executed (FNSAVE) and the encoded address in a load environment (FLDENV) instruction matches the address in the snoop register 120 {!(is.sub.-- fnsave .parallel. (is.sub.-- fldenv && is.sub.-- match))}. Some examples of the operation of a microprocessor implementing the present invention will now be described. For these exemplary scenarios, it is noted that programmers do not have to follow the memory stack model of the Intel architecture. Under the memory stack model, the instructions FNSAVE/FRSTOR or FNSTENV/FLDENV, appear in pairs. The inner most store always being followed by a load retrieving data from the store address. In these examples, the following notations will apply: (1) Snoop Reg. for the Snoop Address Register; (2) ENV ptr for ENV pointer; (3) ENV drt for ENV dirty bit; (4) REG ptr for REG pointer; (5) REG drt for REG dirty bit; (6) What Happened means that when something in this column happened, its results to the Snoop Reg., ENV ptr, or the like will be recorded on the corresponding row; (7) Load from Memory indicates the source of the image being loaded, "No" means the image is loaded from internal private registers (restored from the shadowed register set) and "Yes" means the image is loaded from memory; (8) "X" means the value is "don't care"; and (9) [Address] means that the symbol inside the brackets [ ] is an address. The first example will follow the previously described memory stack model: EXAMPLE 1
______________________________________
Snoop Reg What Load from
ENV ptr ENV drt REG ptr REG drt
Happened
Memory
______________________________________
X 0 1 0 1 reset
A 1 0 1 0 fnsave[A]
A 0 1 0 1 frstor[A]
No
B 1 0 1 0 fnsave[B]
B 1 0 1 1 Store to
REG
memory
image
B 1 0 1 1 frstor[B]
Yes
______________________________________
In this example, the restore instruction (frstor[A]) loads the floating point state from internal private registers ENV and REG (shadowed set that maintained the state of the previous task, which is now being resumed). Both dirty bits get turned on (set=1) by frstor[A], as well. However the restore instruction that includes address B (frstor[B]), loads the floating point state from memory since the REG image in memory has been modified (snoop hit). The frstor[B] instruction does not advance the circular buffer since it loads the image from memory. The next example also follows the memory stack model. EXAMPLE 2
______________________________________
Snoop Reg What Load from
ENV ptr ENV drt REG ptr REG drt
Happened
Memory
______________________________________
X 0 1 0 1 reset
A 1 0 0 1 fnstenv[A]
A 0 1 0 1 fldenv[A]
No
B 1 0 0 1 fnstenv[B]
B 0 1 0 1 fldenv[B]
No
______________________________________
In this case, the load environment instruction "fldenv[A]" loads the floating point environment from the internal private registers of the on-chip image (ENV). Since there was an intervening store environment instruction to address B, the load environment instruction (fldenv[B}) can also load the floating point environment from the private internal registers of the on-chip image. The third example, does not follow the memory stack model and consecutive save and load instructions are permitted. EXAMPLE 3
______________________________________
Snoop Reg What Load from
ENV ptr ENV drt REG ptr REG drt
Happened
Memory
______________________________________
X 0 1 0 1 reset
B 1 0 0 1 fnsave[B]
A 0 0 0 0 fnsave[A]
B 1 0 0 1 fnstenv[B]
B 0 1 0 1 frstor[B]
Yes,
re-load
from
memory
image
______________________________________
In this example, by the time the store environment to address B (fnstenv[B]) is executed, the working set is the ENV of register set 1 and the REG file of register set 0. Therefore, the on-chip image is the opposite combination of the ENV register of register set 0 and the REG file for register 1, which corresponds to the shadowed set. The ENV register of the on-chip image/shadowed set (ENV register of set 0) is marked dirty after the store environment instruction (fstenv[B]) is executed. The REG file of register set 1 remains unmodified because it is not affected by the store environment instruction, FSTENV and will maintain its portion of the on-chip image which occurred due to the execution of the save instruction to address A (fnsave[A]). Thus, the frstor[B] instruction will have to re-load the floating point state from memory even though an address match is present, i.e. it must reload from memory because the on-chip image of the REG file is controlled by the previous fnsave[A] instruction and the subsequent fstenv instruction does not affect the REG file. Example four does not follow the memory stack model and also addresses the possibility of consecutive save/store instructions. EXAMPLE 4
______________________________________
Snoop Reg What Load from
ENV ptr ENV drt REG ptr REG drt
Happened
Memory
______________________________________
X 0 1 0 1 reset
A 1 0 1 0 fnsave[A]
A 0 1 1 0 fldenv[A]
No
A 0 1 1 0 frstor[A]
Yes
______________________________________
In this case, the load environment instruction (fldenv[A]) attempts to re-load the ENV image that was previously saved by the save instruction (fnsave[A]). The load environment instruction is able to obtain the ENV image from the CPU internal private registers (on-chip image). Subsequent to the fldenv[A] instruction the working set is made up of the ENV registers from register set 0 and the REG file from register set 1. The ENV on-chip image of the save instruction fnsave[A] overlaps with the ENV register of the working set. Thus, it is possible that subsequent floating point instructions will alter the ENV on-chip image (due to its overlap with the working set) of the save instruction at address A (fnsave[A]). Therefore, the restore instruction (frstor[A]) loads the state image from memory to ensure program integrity. As can be seen, the present invention provides a system and method for efficiently handling floating point save and restore instructions. At the instruction level, MMX instruction can be mixed with the FNSAVE, FRSTOR, FNSTENV and FLDENV instructions without any adverse consequences. The present invention contemplates that the FNSAVE, FRSTOR, FNSTENV and FLDENV instructions can be used to save/restore MMX state (environment and register file) and environment information in exactly the same way they are used in accordance with floating point state and environment. Therefore, the present invention is applicable to task switches between different contexts (MMX and Floating Point), as well as task switches within a single context (different tasks within the MMX or Floating Point context). Rapid switching between floating point and MMX instructions is a relatively new problem facing the computer industry. The preferred embodiment of the present invention addresses this problem as presently defined. However, those skilled in the art will understand that as software vendors develop applications utilizing MMX instructions, other problems may arise. The scope of the claims of the present invention are intended to include any situation where system performance can be improved when switching from a first context to a second context and vice versa. Although certain preferred embodiments have been shown and described, it should be understood that many changes and modifications can be made therein without departing from the scope of the appended claims.
|
Same subclass Same class Consider this |
||||||||||
