This invention relates to data processing apparatus.
It is known to arrange for instructions in a data processing apparatus to be broken down into a number of phases. For example, each instruction may have a phase in which at least one operand is read from memory, a phase in which an operation is performed on the operand, and a further phase in which a result is written into the memory. The phases of successive instructions may be overlapped, so that while one instruction is performing the write phase, the next following instruction is at the execution phase and the next again instruction is at the operand read phase. This overlapping of phases of successive instructions is usually referred to as pipelining.
The apparatus is usually controlled by a clock signal which advances each instruction to its next phase at each clock beat.
In such an arrangement, it is clear that the apparatus must be able to access two or more operands in each clock beat, i.e. it must be able to write the result from one instruction into the memory and read the operand or operands for a later instruction in the same clock beat. One way of doing this is to use a multi-port memory which allows two or more locations to be accessed simultaneously. However, such memories are complicated and expensive.
One object of the invention is to overcome this problem.
Summary of the Invention
According to the invention there is provided a pipelined data processing apparatus for obeying a sequence of instructions each of which has a read phase in which one or more operands are read from a memory, an execute phase in which an operation is performed by an execution unit, and a write phase in which a result is written to the memory, the phases of successive instructions being overlapped and the apparatus being controlled by a clock signal which advances each instruction to its next phase at the end of each clock beat, wherein each clock beat is divided into a write sub-beat during which the instruction currently in its write phase writes its result to the memory, and at least one read sub-beat during which the instruction currently in its read phase reads an operand from the memory.
It can be seen that, by dividing the clock beat into separate sub-beats, a plurality of memory accesses can be made within a single clock beat. Thus, a single-port memory can be made to act as if it were a multi-port memory.
One pipelined data processor in accordance with the invention will now be described by way of example with reference to the accompanying drawings.
Brief Description of the Drawings
FIG. 1 is a block diagram of the processor.
FIG. 2 is a timing diagram showing various timing signals produced in each clock beat.
FIG. 3 is a diagram showing the way in which instructions are overlapped.
FIG. 4 illustrates the operation of the processor.
Description of an Embodiment of the Invention
Referring to FIG. 1, the processor has an instruction fetch unit 10 for fetching sequences of instructions from a main memory (not shown).
Each instruction in turn is decoded by decode logic 11 to produce a pair of operand read addresses MA and RA, and a function code FN. The function code is fed to a register 12 where it is held until it is required. The addresses MA and RA are fed to inputs of a multiplexer 13, along with a write address WA. Each of the addresses MA, RA and WA is four bits wide.
The output of the multiplexer 13 is connected to the address input of a random access memory (RAM) 14 having sixteen individually addressable locations, which acts as a register file for the processor. The output of the multiplexer 13 is also fed to a register 15, referred to as the HOLD register, and then to a register 16, referred to as the WA register. The output of the WA register 16 provides the write address signal WA to the multiplexer 13.
The RAM 14 has a data input/output port which is connected to a bi-directional bus 17. The bus 17 is in turn connected to the inputs of two operand registers 18 and 19 referred to as the R and M registers. The output of the M register is connected by way of a byte shift circuit 20 to a register 21, referred to as the S register. The byte shift circuit 20 is capable of shifting the operand to the right or left in multiples of eight bits.
The outputs of the R and S registers are connected to inputs of an arithmetic and logic unit (ALU) 22. This can perform various operations on the two inputs, under control of the function code FN from the register 12. The output of the ALU 22 is connected to a register 23, referred to as the WR register, which is in turn connected to the bus 17 and hence to the input/output of the RAM 14 and the R and M registers.
The outputs of the RAM 14 and the WR register 23 are tristate logic; that is, if either is disabled, it adopts a neutral condition in which it has no influence on the state of the bus 17.
A comparator 24 continuously compares the output of the multiplexer 13 with the contents of the WA register 16. If they are equal, the comparator produces a control signal which enables the output of the WR register, so that it applies its contents to the bus 17. If, on the other hand, the comparator 24 detects inequality, it enables the output of the RAM 14 instead.
Clock signals (from clock circuit 25)
Referring now to FIG. 2, the processor has a basic clock beat of 120 nanoseconds, defined by a clock signal EC (end clock) which occurs at the end of each beat. A further clock signal MC (mid clock) is produced half-way through each beat, 60 nanoseconds after EC.
The beat is divided into three sub-beats, by means of clock signals 1/3C and 2/3C which occur 40 nanoseconds and 80 nanoseconds respectively after EC.
FIG. 2 also shows the way in which the multiplexer 13 (FIG. 1) is controlled. In the first, second and third sub-beats, it is switched to select the inputs WA, MA and RA respectively.
Operation
Referring to FIG. 3, this shows the progress of three successive instructions N, N+1 and N+2. Each instruction has four phases: fetch, read, execute, and write. As shown, the phases of the instructions are overlapped so that, for example while instruction N is in the write phase, instruction N+1 is in the execute phase and instruction N+2 is in the read phase. Each phase occupies one clock beat, from one EC to the next.
The operation of the processor at each phase of a particular instruction will now be described, referring again to FIG. 1.
During the fetch phase, the instruction is fetched by the circuit 10.
At the start of the read phase, the instruction is decoded by the decode logic 11, to produce the operand addresses MA and RA, and the function code FN. During the second sub-beat of the read phase, the multiplexer 13 selects the address MA, and applies it to the RAM 14, so as to address the first operand. This operand is then gated into the M register by the clock 2/3C. During the third sub-beat of the read phase, the multiplexer 13 selects the address RA, and applies it to the RAM 14, so as to address the second operand. This is then gated into the R register by the clock EC. At the same time, the contents of the M register are transferred to the S register, via the byte shift circuit 20. The clock signal EC also gates the output of the multiplexer 13 (i.e. the address RA) into the HOLD register 15.
During the first half of the execute phase, the ALU performs the operation specified by the code FN in the buffer 12. Then, at the clock MC, the result of the operation is gated into the WR register. Also, at the clock 1/3C the contents of the HOLD register 15 are transferred to the WA register 16.
In the first sub-beat of the write phase the multiplexer 13 selects the write address WA from the WA register 16, and applies it to the RAM 14 so as to address the location into which data is to be written. At the clock signal 1/3C, a write enable signal WE is generated, which causes the contents of the write register WR to be written into the RAM 14.
FIG. 4 summarises the operation described above, showing the relationship between the RAM address (from the multiplexer 13) and the contents of the HOLD and WA registers.
It can be seen that, in the first sub-beat of each clock beat, the RAM is addressed by the write address WA for a particular instruction (instruction N, say). Then, in the second and third sub-beats, the RAM is addressed by the read addresses MA and RA for the next but one instruction (N+2). Also, during the first half of the clock beat, the ALU performs the specified operation for the intermediate instruction (N+1).
It can also be seen that the read address RA for instruction N is loaded first into the HOLD register and then into the WA register so that it is available in the first beat of the write phase of instruction N, to act as the write address WA. Thus, the write address WA for each instruction is always the same as the second operand address RA.
As described above, the contents of the WA register are continuously compared with the RAM address, by means of the comparator 24. As can be seen from FIG. 4, this means that the WA register, after it is loaded with address RA for instruction N, is compared in successive sub-beats with the read addresses MA and RA for instruction N+1, and with the write address WA for instruction N. This last comparison always gives equality, of course, since the write address WA is derived from the WA register. Therefore, the output of the WR register is always enabled by the comparator 24 during the write sub-beat. This permits the contents of WR to be written to the RAM as described above.
If neither of the addresses MA or RA is equal to the WA register, the comparator 24 indicates inequality during the two read sub-beats. Thus, the comparator enables the RAM output, allowing the addressed operands to be read out of the RAM and gated into the M and R registers as described above.
Suppose now that instruction N writes an operand to the RAM, and that the following instruction N+l requires to read the same operand; i.e. one of the read addresses MA or RA for instruction N+1 is equal to the write address WA for instruction N. It can be seen from FIG. 4 that this creates a problem, since the read sub-beats for instruction N+1 occur before the write sub-beat for instruction N.
This situation is detected by the comparator circuit 24, which will find equality between the contents of the WA register and the RAM address during the MA or RA sub-beat of instruction N+1. The comparator therefore enables the output of the WR register, rather than that of the RAM. This causes the output of the WR register to be written into the M or R register when that register is clocked. Thus, the result for instruction N (which is held in the WR register) is gated directly into the M or R register, by-passing the RAM. The required operand is therefore available to instruction N+1 at the correct time.
The contents of the WR register are also written into the RAM in the normal way during the following beat.
It can be seen therefore that the comparator 24 serves a dual function:
(a) It enables the output of the WR register at the appropriate sub-beat to allow the result of an instruction to be written into the RAM.
(b) It also detects read/write clashes, by comparing the write address of each instruction with both the read addresses of the next instruction.
Thus, the comparator 24 represents a very economical use of logic.
It can also be seen that the division of the clock beat into three sub-beats permits the RAM 14 to act effectively as a three-port memory, allowing a write access and two read accesse in each clock beat.