Microprocessor with a cache memory

Abstract: When the access is effected sequentially such as the prefetching of an instruction or the restoration of a register in the stack region, the retrieval is effected simultaneously for the consecutive addresses and the result is stored. When the consecutive addresses are to be accessed, the hit is determined relying upon the result that is stored without effecting the cache memory (1) reference. In the case of mishit, the external memory (204) is readily accessed to shorten the overhead time required for the cache memory reference. Therefore, the access time can be shortened in average.

Description: Background of the Invention The present invention relates to a microprocessor, and more specifically to a cache memory adapted to operating at high speeds a one-chip microprocessor in which the cache memory is mounted on a chip. A cache memory has heretofore been extensively known as a high-speed memory that is to be installed between a central processing unit (CPU) and a main memory. The cache memory usually has a capacity smaller than that of the main memory and its high-speed characteristics lend itself well for operating a computer at an increased speed. That is, the data having a high frequency of access by the CPU are transferred in advance from the main memory to the cache memory, in order to shorten the memory access time by the CPU. The cache memory system has been widely used ranging from general-purpose computers through up to mini-computers. For example, a 32-bit microprocessor MC68020 disclosed in The Motorola MC68020 IEEE, Micro, August, 1984, pp. 101-118 has a cache memory on the chip. In the cache memory, the data consisting of 32 bits is corresponded to an address memory. According to the above prior art, however, the address must be retrieved every time when the data consisting of 32 bits is accessed in order to determine whether it hits the cache memory or not. Therefore, when it is attempted to access an external memory without hitting the cache memory, the time required for the address retrieval becomes an overhead. Another prior art related to the cache memory has been taught in Japanese Patent Laid-Open No. 214039/1986, according to which a row of cache memory is constituted by a data part which consists of an address data of an associative part and a plurality of words with an external data bus width as a unit, and a flag (valid flag) is provided to indicate whether the data stored in the word is effective or not for each of the words in the data part. Since a data part consisting of a plurality of words is corresponded to an address data, the area of an associative part can be reduced in the cache memory per a word of data stored therein. By using the flag, furthermore, the corresponding data only is written in case of mishit, without increasing the overhead. Summary of the Invention The object of the present invention is to provide a microprocessor with a cache memory which is capable of reducing the overhead required for the cache memory reference for consecutive addresses at the time when the cache memory is sequentially accessed, that may happen when an instruction is prefetched or when a register that had been evacuated in the stack region is recovered. In order to achieve the above object, the microprocessor with a cache memory of the present invention is constituted as defined in claim 1 At the time of retrieving the data areas other than the data area accessed for the first time, there is no need of sequentially effecting the cache memory reference, yet making it possible to immediately determine the hit or mishit relying upon the result that is held in the holding means. Therefore, the overhead time required for the cache memory reference can be shortened. Brief Description of the Drawings Fig. 1 is a diagram illustrating the structure of a microprocessor according to an embodiment of the present invention; Fig. 2 is a diagram which schematically illustrates the interior of a cache memory shown in Fig. 1; Fig. 3 is a diagram illustrating the internal structure of the cache memory shown in Fig. 1; Fig. 4 is a diagram illustrating the internal structure of a read/write control circuit for cache memory of Fig. 1; Fig. 5 is a diagram illustrating the internal structure of a portion of the cache memory control circuit of Fig. 1; and Fig. 6 is a flow chart which illustrates the operation of the cache memory control circuit of Fig. 1. Description of the Preferred Embodiment Fig. 1 is a diagram which illustrates the structure of a microprocessor according to an embodiment of the present invention. A microprocessor 200 containing a cache memory 1 is capable of addressing the data of a memory with the byte as a unit, and has an address space of 32 bits, and transfers the data to the memory with 32 bits as a basic unit (word). To simplify the description, furthermore, the cache memory does not store the data but stores the instructions only. The microprocessor 200 consists of an instruction execution block 201, a cache memory 1, a control circuit 202 for cache memory, and a read/write control circuit 100 for cache memory. Further, the microprocessor 200 is connected to an external memory 204, and executes the process using programs and data stored in the external memory. First, operation of the cache memory will be roughly described in conjunction with Fig. 2 which schematically illustrates the interior of the cache memory of Fig. 1. Two data areas 403a and 403b having consecutive word addresses are corresponded to a tag address 402 of an associative part, thereby to form a row. The thus formed rows are stacked in a plurality of numbers in the direction of column to form a cache memory in the form of a matrix. Of the above two data areas, an even-number word address is assigned to a first data area 403a of the left side, and an odd-number word address is assigned to a second data area 403b of the right side. The two data areas are provided with valid flags 403′ and 403b′ that indicate whether effective data is stored or not. The present invention exhibits its characteristic operation when the above consecutive data areas are to be accessed. That is, when the first data area 403a is to be read out in response to the tag address, not only the flag 403a′ of the area but also the flag 403b′ of the second data area are read out and the data of the flag 403b′ is stored in the holding means. The second data area has a large probability of being accessed following the first data area when the access is effected sequentially. Then, when the second data area 403b is to be read out, it is determined whether the cache memory is hit or not relying upon the data of the flag 304b′. Owing to the above-mentioned operation, whether the cache memory is hit or not is readily determined based upon the flag data that has been stored already in the holding means at the time when the second data area is being read out. Therefore, the access time can be shortened compared with when the flag of the second data area is newly read out at the time of reading the second data area. Determination of hit based upon the flag data stored in the holding means will be explained later with reference to the cache memory control circuit. The internal structure of each of the structural elements of Fig. 1 and the operation thereof will now be described. First, the structure of the cache memory 1 will be described in conjunction with Fig. 3. The cache memory 1 chiefly consists of an associative memory 2, and RAM's 3a, 3b. Here, as mentioned with reference to Fig. 2, the two data areas (stored in 3a and 3b) having consecutive word addresses are corresponded to an associated tag address in the associative memory 2. The data areas of the RAM's 3a and 3b are provided with flag portions (3a′, 3b′). In this embodiment, furthermore, a flag portion 2′ is provided even in the associative memory 2 to indicate that the address has been stored in an effective condition. The cache memory 1 receives a signal 11 of the thirtieth bit (A2) and a signal 12 consisting of upper 29 bits (A31 to A3) as an instruction fetch address among the address signals of 32 bits. The signal 11 indicates whether the instruction address is of an even number or an odd number. The signal 11 which is zero represents an address of an even number. The signal 11 which is 1 represents an address of an odd number. Further, a signal 14 consisting of 32 bits is input as an instruction input. Control signals 18, 19, 20, 21 and 22 are further input. The instruction consisting of 32 bits read from the cache memory is produced as a signal 13. The data related to the hit and mishit are formed based upon the signals from the flag portions 3a′, 3b′ of the data areas, and are produced as valid flag signals 15, 16 and 17. The valid flag signal 15 is produced when the cache memory reference indicates that no associated tag address is contained in the associative part 2. The valid flag signal 16 is produced when an effective instruction is stored in an instruction address during the access operation. The valid flag signal 17 is produced when there exists in an effective form in the RAM 3b an instruction of an odd-number instruction address that has a high probability of being accessed in the next time under the condition where an instruction address being accessed has an even number. The associative memory 2 receives the signal 12 as an associative write input and receives the signal 18 as a valid flag. The associated result, i.e., hit/mishit is produced as a signal 33, and which row is hit is produced as a signal 40. The RAM's 3a and 3b are addressed by the signal 40, and signals 14, 34 and 11 are input thereto as write inputs. Signals 31, 32, 35 and 36 are produced as read outputs. The signal 31 is produced in response to the signal 14 input to the RAM 3a, the signal 35 is produced in response to the input signal 34, the signal 32 is produced in response to the signal 14 input to the RAM 3b, and the signal 36 is produced in response to the input signal 11. The signals 31 and 32 input to the selector 4 are selected by the signal 11. When the signal 11 is zero, a value of the signal 31 is produced as the signal 13 and when the signal 11 is 1, a value of the signal 32 is produced as the signal 13. The signal 19 is a wirte designation signal of the associative memory 2, and the signal 20 is a row designation signal that is to be written. The signal 21 is a write designation signal of RAM 3a, and the signal 22 is a write designation signal of RAM 3b. The associative memory 2 stores associative data consisting of 29 bits and a valid flag consisting of one bit. Depending upon the write designation signal 19, the associative memory 2 operates as described below. When the signal 19 is "0", the signal 12 is compared with the associated address stored in each of the rows. When there is found a row that is in agreement and when the valid flag 2′ of that row is 1 (i.e., when there exists no corresponding address is an effective form), the signal 33 is rendered to be "1" and the line of the signal 40 corresponding to the row is rendered to be "1". The valid flag signal "0" taken from the signal 33 via an inverter 5 indicates that an associated effective tag address is contained in the associative part 2. Next, when the signal 19 is "1", a value of the signal 12 as an associated tag address and a value of the signal 18 as a valid flag are written onto the row that is specified by the signal 20. The RAM's 3a and 3b, respectively, hold instructions of an even-number word address and an odd-number word address. The cache memory 1 further comprises inverters 5 and 6, AND gates 7, 8 and 9, and an OR gate 10. Reading operation of the cache memory 1 is carried out as described below under the control of the read/write control circuit 100 for cache memory that is shown in Fig. 1. Fig. 4 shows an example of the read/write control circuit for cache memory. A write signal 50 is rendered to be "0", and an address of a read instruction is input in the form of the aforementioned signals 11 and 12. Since the write signal 50 is "0", signals 19, 21 and 22, too, assume the level "0" to designate the writing of data onto the associative memory 2 and onto the RAM's 3a, 3b through AND gates 106, 107 and 108 of the write control circuit. Since the signal 19 is "0", the associative memory 2 performs the association with a signal 12, and the result is produced as signals 33 and 40. The characteristic reading operation of the present invention is carried out by the cache memory control circuit 202 in a manner as described below. Fig. 5 illustrates the structure of the instruction cache control circuit 202 which commences its operation upon receipt of a branch request signal 211 or a prefetch request signal 212 sent from the instruction execution block 201. The branch request signal 211 is input from the instruction execution block to the instruction cache control circuit when a branch is generated in the flow of a program, and the prefetch request signal 212 is input from the instruction execution block to the instruction cache control circuit when there is generated no branch but when the program is to be executed sequentially. First, when the instruction execution block 201 requests the branch (signal 211 is "1" and signal 212 is "0"), and when the prefetch is requested and the instruction address has an even number (signal 211 is "0", signal 212 is "1", and signal 11 is "0"), an OR gate 225 produces an output "1" due to inverter 222, AND gates 223 and 224, and OR gate 225. Therefore, when the valid flag signal 16 is "1" (or is stored) that indicates that an effective instruction is stored in an instruction address during the access operation, an AND gate 231 produces an output "1" and whereby a cache memory access request signal 215 is produced via an OR gate 233. When the valid flag signal is "0" (not stored), on the other hand, an external memory access request signal 214 is produced via inverter 226, AND gate 228, and OR gate 230. At this moment, the output of the OR gate 225 is also input to a clock input CK of a D flip-flop (D-FF) 221. To the D-input of the D-FF is input a valid flag signal 17 that indicates that an instruction of an odd-number address having a high probability of being accessed next is present in an effective form in the RAM 3b when the instruction address being accessed is an even-number address. That is, while the even-number address is being accessed, existence of data on the side of an odd-number address is input as a valid flag signal 17 to the D-input of the D-FF 221. When the instruction execution block 201 produces a prefetch request and when the instruction address is changed from the previous even-number condition to an odd-number condition (signal 211 becomes "0", signal 212 becomes "1", and signal 11 becomes "1"), the instruction cache control circuit 202 fabricated with the D-FF 221 as a center exhibits its operation which is characteristic to the present invention. First, as the signal 11 becomes "1", the OR gate 225 applies a signal "0" to the clock input CK of the D-FF 221. The data of valid flag signal 17 is produced from the output Q of D-FF at a timing of the change of clock input. When the valid flag signal 17 is "1" (an instruction exists in an odd-number address), the output Q becomes "1" and a cache memory access request signal 215 is produced via an AND gate 232 and an OR gate 233. On the other hand, when the valid flag signal 17 is "0" (no instruction exists in the odd-number address), the output Q becomes "0", and an external memory access request signal 214 is produed via inverter 227, AND gate 229 and OR gate 230. Fig. 6 is a flow chart that illustrates the above-mentioned operation. When the branch request signal 211 is "1", the instruction execution block commences the program from a step 302. When the instruction prefetch request signal 212 is "1", the instruction execution block commences the program from a step 301 where it is examined whether the instruction address has an odd number or an even number. When the instruction address has an even number, the program proceeds to a step 302 and when the instruction address has an odd number, the program proceeds to a step 306. Here, the instruction address (word address) having an even number indicates that access is made to a data area that is to be accessed at first among a plurality of data areas (two areas in this case) for a tag address of the associative part. When the instruction address has an odd number, on the other hand, it means that access is made to other data areas. In the next step 302, the cache memory 1 performs the associative operation, i.e., cache memory reference. As will be comprehended from the flow chart, the step 302 is carried out (1) when the instruction execution block 201 is producing the branch request signal 211, and (2) when the instruction execution block 201 is producing the prefetch request signal 212 and when the instruction address has an even number (i.e., when access is made to a data area that is to be accessed at first). When it is confirmed (hit) in a step 303 using a valid flag 16 that an instruction to be accessed exists in the cache memory 1, the program proceeds to a step 304. When it does not exist (mishit), on the other hand, the program proceeds to a step 305. In the step 304, the instruction is read from the cache memory 1, the signal 215 is asserted, and the instruction 13 that is read out is sent onto a data bus 213 via a tri-state buffer 203. The step 305 asserts the external memory access request signal 214, reads an instruction from the external memory 204 and sends it onto the data bus 213. The instruction sent onto the data bus 213 in the above steps 304 and 305, is received by the instruction execution block 201 and is executed. When the instruction address has an odd number in the step 301, the program proceeds to the step 306 which forms a characteristic portion of the present invention and which is carried out when the instruction execution block 201 is producing a prefetch request signal 212 and when the instruction address has an odd number (i.e., when access is made to data areas other than the data area that is to be accessed at first). The program proceeds to the step 304 when it is confirmed (hit) in the step 306 using the valid flag 17 that an instruction that is to be accessed exists in the cache memory 1. That is, the ordinary cache memory reference is not effected in the step 306 but is effected in the preceding step 302 of addressing an even-number instruction, and wherein the hit or mishit is determined using the data of the valid flag 17 that is stored. In the foregoing was described the operation at the time of prefetching the instruction. It will, however, be obvious that the present invention can be adapted even when the register that had been evacuated in the stack region is restored. In the embodiments, furthermore, the number of words (number of data areas) of the RAM corresponding to the associative part was set to be 2. It will, however, be obvious that the present invention can be easily expanded to cover the number of words (number of data areas) which is an exponential power of 2.

Claims: A microprocessor comprising: a cache memory (1) having a tag address portion (2) for storing a plurality of tag addresses (402) each consisting of a plurality of bits, and a data portion including a plurality of rows forming a matrix, each row being constituted by a plurality of consecutive data areas (3a,3b) accessed in common by an associative tag address (402), with any one of said plurality of data areas (3a,3b) being selectively specified by at least one bit of the associated tag address (402); an instruction execution block (201) which executes instructions based upon the data (3a,3b) stored in said cache memory (1) or in an external memory (204), and a cache memory control circuit (202) for controlling the operation of the cache memory (1), characterized in that first and second data areas (3a,3b) of said consecutive data areas in said cache memory (1) are commonly accessed by an upper bit signal (signal 12, upper bits thereof A31-A3) of an instruction fetch address (11,12) generated from said instruction execution block (201), that any one of said first and second data areas (3a,3b) in said cache memory (1) is selectively specified by a lower bit signal (11,A2) of said instruction fetch address, that each area of said first and second data areas (3a,3b) in said cache memory (1) includes a flag portion (3a',3b') for storing a flag (403',403b') that indicates whether or not valid data are stored therein, that said cache memory control circuit (202) includes; first means (7,8,9,10) for reading out said flag (3b') in said second data area (3b) when said flag (3a') in said first data area (3a) is read out in response to said upper bit signal (12) and said lower bit signal (11) of said instruction fetch address, second means (221) for holding information related to said flag (3b') of said second data area (3b) read out by said first means (9), and third means (223-225,227,230,232,233) for reading out said information from said second means (221) in response to said lower bit signal (11) of said instruction address when said second data (3b) is consecutively accessed after said first data area (3a) was accessed, and that whether or not the cache memory is hit is determined depending upon the flag (3b') held in said second means (221) concerning said second data area (3a,3b) of the row selectively designated by said lower bit signal (11 ,A2) of said instruction fetch address (11,12). A microprocessor of Claim 1, wherein said cache memory (1) includes; a first stack (3) of a plurality of rows forming a column, each rows including said first and second data areas (3a,3b), and a second stack (2) of a plurality of rows forming a column, each row of said second stack including address information which are corresponding to data stored in a corresponding row of said first and second data areas (3a,3b). A microprocessor of Claim 2, wherein said upper bit signal (12) of said instruction fetch address is compared with said address information stored in said plurality of rows of said second stack (3), and wherein any one of said plurality of rows in said first stack (3) is selected in accordance with an agreement in the comparison of said upper bit signal (12) with said address information stored in said plurality of rows of said second stack (3).

Inventors: HANAWA MAKOTO, HASEGAWA ATSUSHI, NISHIMUKAI TADAHIKO, HANAWA, MAKOTO, HASEGAWA, ATSUSHI, NISHIMUKAI, TADAHIKO
Applicants: HITACHI LTD, HITACHI MICROCOMPUTER SYST, HITACHI MICROCOMPUTER SYSTEM LTD., HITACHI, LTD.
Application year: 1987
Main classification: G06F12
IPC codes: G06F9, G06F12