CPU capable of quickly processing memory copy instructions and method thereof
By designing a CPU that supports arbitrary alignment of source and target addresses, and using a state machine to manage read and write operations, the problem of low memory copy efficiency is solved, efficient memory copy and interrupt processing are achieved, and instruction bus delays are avoided.
Patent Information
- Application Number
- CN202411074915.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2044-08-07
AI Technical Summary
The memory copy efficiency in the existing technology is low, and it is limited by the CPU register width and cannot maximize the use of memory bandwidth. Moreover, the hardware-based DMA does not support arbitrary alignment of source/destination addresses, and cannot implement DMA suspend in scenarios such as interruption/thread switching. .
Design a CPU that includes an instruction decoder, a memory copy controller, a general-purpose register, a bus interface and a buffer. It manages read and write operations through a state machine, supports arbitrary alignment of source and target addresses, and uses adders and comparators to update addresses. , realizes fast memory copy and supports interrupt processing.
Maximizes the use of memory bandwidth, improves memory copy efficiency, supports interrupt processing, avoids repeated instruction fetching and instruction bus delays, has a simple structure, and reuses the original logic units of the CPU.
Smart Images

Figure CN118605941B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and in particular relates to a CPU capable of quickly processing memory copy instructions and a method thereof. Background Art
[0002] Memory copy (memcpy) is a simple and diverse operation, which is generally implemented in two ways: software method and hardware method.
[0003] Software method: There are many types of codes that can be implemented, but all require running a loop program, which requires repeated instruction fetching and consumes more power. At the same time, the overall copy performance is affected by the instruction bus latency. The CPU's branch instruction prediction failure will introduce bubbles in the pipeline, reducing execution efficiency. The minimum value needs to be selected from the source address alignment byte number, the target address alignment byte number and the CPU register width as the maximum number of bytes for a single copy (n). For memory copies of any address, the latency fluctuates greatly. Since a single copy is limited by the maximum width of the CPU register, the memory bandwidth cannot be maximized, resulting in low memory copy efficiency.
[0004] Hardware method: Rely on DMA implementation, but DMA generally does not support arbitrary alignment of source / destination addresses; in addition, the software needs to wait for the last DMA to complete before the next DMA operation can be performed, and DMA suspension cannot be implemented in scenarios such as interrupts / thread switching. In addition, DMA is a non-standard hardware resource, and the DMA usage and register addresses designed by each design manufacturer are different. Applications that need to ensure compatibility often use software to copy memory, such as operating systems, protocol stacks, system libraries, etc. Summary of the invention
[0005] Purpose of the invention: In order to solve the problem of low memory copy efficiency in the prior art, the present invention provides a CPU and a method thereof that can quickly process memory copy instructions.
[0006] Technical solution: A CPU capable of quickly processing memory copy instructions, comprising:
[0007] An instruction decoder, the input end of which inputs the CPU instruction, and the output end of which is connected to the read port of the general register and the memory copy controller, is used to decode a valid memory copy instruction, wherein the valid memory copy instruction includes a source address register number, a target address register number and a copy end information register number;
[0008] General register, connected to the memory copy controller, used to store source address, target address, and copy end information;
[0009] The memory copy controller includes a state machine, wherein the state machine includes an idle state, a read state, and a write state. In the idle state, the controller waits to receive a valid memory copy instruction; in the read state, the controller controls the bus interface to read data from the source address and temporarily stores the data in the buffer; in the write state, the controller controls the bus interface to write the data temporarily stored in the buffer to the target address;
[0010] A bus interface, connected to a memory copy controller and a buffer, and connected to an external memory;
[0011] Buffer, connected to the memory copy controller;
[0012] An adder, the input end of which is connected to the read port of the general register and the memory copy controller, and the output end of which is connected to the write port of the general register, for updating the source address and the target address;
[0013] A comparator, whose input end is connected to the read port of the general register and whose output end is connected to the memory copy controller, is used to determine whether the copy is completed according to the copy end information.
[0014] Furthermore, the buffer space is M*2 N Bytes, where M is a positive integer, 2 N is the bus interface width.
[0015] Furthermore, the copy end information is one or more of the end address of the source address, the end address of the target address, and the total copy length.
[0016] Furthermore, the state machine, adder, and bus interface each have one; occupying a write port of a general register, which is used to write the updated source address or target address in time-sharing; occupying two read ports of the general register, the first read port is used to read the copy end information, and the second read port is used to read the current source address and target address in time-sharing; also includes a first selector, the two input ends of the first selector respectively input the source address register number and the target address register number, the control end is connected to the memory copy controller, and the output end is connected to the second read port and write port of the general register; in the read state, the first selector outputs the source address register number; in the write state, the first selector outputs the target address register number.
[0017] Furthermore, there are two state machines, adders, and bus interfaces, including a read state machine, a read adder, and a read bus interface for read operations, and a write state machine, a write adder, and a write bus interface for write operations. The read state machine includes an idle state and a read state, and the write state machine includes an idle state and a write state; two write ports of the general register are occupied, which are respectively used to write the updated source address and target address; three read ports of the general register are occupied, and the first read port, the second read port, and the third read port are respectively used to read the copy end information, the source address, and the target address.
[0018] A method for quickly processing a memory copy instruction using the CPU capable of quickly processing a memory copy instruction comprises the following steps:
[0019] The state machine of the memory copy controller is initially in an idle state;
[0020] When the instruction decoder receives a valid memory copy instruction, it reads the source address register number, the target address register number, and the copy end information register number from the valid memory copy instruction to the general register, and sends a start signal to the memory copy controller at the same time. The general register obtains and outputs the initial values of the source address and the target address and the copy end information through the source address register number, the target address register number, and the copy end information register number;
[0021] When the memory copy controller receives the start signal, the state machine jumps to the read state, reads data from the source address through the bus interface and temporarily stores it in the buffer, and jumps to the write state after reading the data at least once; in the write state, the data in the buffer is written to the target address in sequence through the bus interface according to the first-in-first-out principle, and the written data in the buffer is cleared, and the data is jumped to the read state after writing at least once; it continuously switches between the read state and the write state, uses the adder to update the source address and the target address, and uses the comparator to determine whether the copy is completed according to the copy end information, and returns to the idle state if the copy is completed.
[0022] Furthermore, in the read state, each time 1~2 N Byte data; in write state, write 1~2 each time N Byte data, 2 N is the bus interface width.
[0023] Furthermore, in the read state, if the buffer space is less than 2 N Byte, jump to write state, otherwise stay in read state; in write state, if the buffer valid bit is less than 2 N Byte, jumps to the read state, otherwise remains in the write state.
[0024] Furthermore, the method for judging whether the copying is completed according to the copying end information is as follows:
[0025] In the read state, the comparator is used to predict whether the read operation is about to be completed according to the source address and the copy end information. If the read operation is about to be completed, the clear state is entered instead of the write state after the read, otherwise the read operation is performed normally and jumps to the write operation;
[0026] In the clear state, the data in the buffer is written to the target address and the written data is cleared until the buffer is cleared and the memory copy is completed.
[0027] Furthermore, if the state machine is in a non-idle state, when the memory copy controller receives an interrupt request signal or a debug signal from the instruction decoder, the state machine first jumps to the clear state, and after the state machine returns to the idle state, the processor responds to the interrupt or debug request normally; if the state machine is in an idle state, when the memory copy controller receives an interrupt request signal or a debug signal from the instruction decoder, the processor responds to the interrupt or debug request normally; during the interrupt or debug response process, the return program pointer is saved as the program pointer of the current memory copy instruction, and the general registers are saved and restored in software and hardware according to the application binary interface; after the interrupt or debug exits, the program pointer is restored to the return program pointer, the processor re-executes the memory copy instruction, and continues to execute from the memory copy breakpoint to complete the remaining copy.
[0028] A method for quickly processing a memory copy instruction using the CPU capable of quickly processing a memory copy instruction comprises the following steps:
[0029] The read state machine and the write state machine of the memory copy controller are both in the idle state initially;
[0030] When the instruction decoder receives a valid memory copy instruction, it reads the source address register number, the target address register number, and the copy end information register number from the valid memory copy instruction to the general register, and sends a start signal to the memory copy controller at the same time; the general register obtains and outputs the initial values of the source address and the target address and the copy end information through the source address register number, the target address register number, and the copy end information register number;
[0031] After the memory copy controller receives the start signal, the read state machine jumps to the read state, continuously reads data from the source address through the read bus interface and temporarily stores it in the buffer, and uses the read adder to update the source address until the read operation is completed, and the read state machine jumps to the idle state;
[0032] At the same time, the write state machine of the memory copy controller jumps to the write state, and writes the data in the buffer to the target address in sequence through the write bus interface according to the first-in-first-out principle, clears the written data in the buffer, and uses the write adder to update the target address until the write operation is completed and the write state machine jumps to the idle state.
[0033] Furthermore, in the read state, each time 1~2 N Byte data; in write state, write 1~2 each time N Byte data, 2 N is the bus interface width.
[0034] Further, the method for determining the end of the read operation is: using a comparator to determine whether the read operation is completed according to the source address and the copy end information;
[0035] The method for judging the end of the write operation is: when the read state machine is idle, if the buffer is cleared, the write operation is completed; if it is not cleared, the write operation continues until the buffer is cleared; if the read state machine is not idle, the write state machine always maintains the write state.
[0036] Furthermore, if at least one of the read state machine and the write state machine is in a non-idle state, when the memory copy controller receives an interrupt request signal or a debug signal from the instruction decoder, the read state machine first jumps to the idle state, and after the write state machine also jumps to the idle state, the processor responds to the interrupt or debug request normally; if both the read state machine and the write state machine are in the idle state, when the memory copy controller receives an interrupt request signal or a debug signal from the instruction decoder, the processor responds to the interrupt or debug request normally; during the interrupt or debug response process, the return program pointer is saved as the program pointer of the current memory copy instruction, and the general registers are saved and restored in software and hardware according to the application binary interface; after the interrupt or debug exits, the program pointer is restored to the return program pointer, the processor re-executes the memory copy instruction, and continues execution from the memory copy breakpoint to complete the remaining copy.
[0037] Compared with the prior art, the CPU and method thereof provided by the present invention that can quickly process memory copy instructions have the following beneficial effects:
[0038] (1) Maximize the use of memory bandwidth and significantly improve memory copy efficiency;
[0039] (2) There is no requirement for source address alignment and target address alignment, and they can be aligned arbitrarily;
[0040] (3) No branch instruction overhead;
[0041] (4) Support interruption, and return to continue the unfinished memory copy after the interruption is processed;
[0042] (5) Avoid repeated instruction fetching, reduce instruction fetching power consumption, and avoid the impact of instruction bus latency;
[0043] (6) The original logic units of the CPU can be fully reused, with few new units and a simple structure. For example, adders, comparators, and bus interfaces can be implemented by reusing the original functional units in the CPU, and selectors can be added to select memory copy instructions or original paths. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 This is a schematic diagram of the structure of a CPU capable of quickly processing a memory copy instruction in Example 1;
[0045] Figure 2 This is a diagram showing the changes in data in the buffer during the memory copy process;
[0046] Figure 3 This is a schematic diagram of the structure of a CPU capable of quickly processing memory copy instructions according to Embodiment 2. DETAILED DESCRIPTION
[0047] The present invention is further explained below in conjunction with the accompanying drawings and specific embodiments.
[0048] Embodiment 1:
[0049] A CPU that can quickly process memory copy instructions, such as Figure 1 As shown, it includes an instruction decoder (DEC), a memory copy controller, a general purpose register (GPR), a bus interface, a buffer, an adder and a comparator.
[0050] Instruction decoder: The input end inputs CPU instructions, and the output end is connected to the read port of the general register and the memory copy controller, which is used to decode valid memory copy instructions. Valid memory copy instructions include the source address register number, the target address register number and the copy end information register number; the source address register number, the target address register number and the copy end information register number can be used to obtain the location where the source address, the target address and the copy end information are stored in the general register.
[0051] Memory copy controller: includes a state machine, which includes an idle state, a read state, and a write state. In the idle state, it waits to receive a valid memory copy instruction; in the read state, it reads data from the source address through the bus interface and temporarily stores the data in the buffer; in the write state, it writes the data temporarily stored in the buffer to the target address through the bus interface.
[0052] General register: connected to the memory copy controller, used to store the source address and the target address. In this embodiment, the general register includes a write port 1 (write port 1 address, write port 1 data, write port 1 enable), two read ports, read port 0 (read port 0 address, read port 0 data) and read port 1 (read port 1 address, read port 1 data). The write port 1 address is used to write the source address or target address register number, the write port 1 data is used to write the source address or target address updated by the adder, and the write port 1 enable is connected to the memory copy controller to control the write enable of write port 1. The read port 1 address selects the register number of the source address or the register number of the target address to be read in under the selection of the selector, and the read port 0 address is used to read the copy end information. The copy end information can be the total length of the copy or the end address (the end address includes the end address relative to the source address and the end address relative to the target address). For example, in this embodiment, the copy end information is the end address of the source address.
[0053] The general register is a register stack for storing temporary results inside the CPU, which pre-stores the source address, target address and copy end information. The source address register number in the memory copy instruction points to a register in the GPR, and the value corresponding to the register is the initial value of the source address, which is the first read address; the target address register number points to a register in the GPR, and the value corresponding to the register is the initial value of the target address, which is the first write address; the copy end information register number points to a register in the GPR, and the value corresponding to the register is the end address of the source address. During the operation of the memory copy controller, the adder will update the source address / target address according to the number of bytes read / written each time (read / write increment). If the copy end information is the total copy length, the remaining copy length needs to be updated each time it is read and written. The controller will write the latest read address to the register pointed to by the source address register number SA_IDX, the latest write address to the register pointed to by the target address register number DA_IDX, and the latest copy end information to the register pointed to by the copy end information register number EA_IDX in real time. That is, the register pointed to by SA_IDX always reflects the latest read address, the register pointed to by DA_IDX always reflects the latest write address, and the register pointed to by EA_IDX always reflects the latest copy end information. The read and write state machines use the addresses to access the memory and generate the end signal.
[0054] Bus interface: connects the memory copy controller and buffer, receives the read and write requests from the memory copy controller, and feeds back the bus response. The bus interface is connected to the external memory. The memory copy controller controls the bus interface to read / write the external memory according to the current source address / target address.
[0055] Buffer: connected to the memory copy controller; buffer space is M*2 N Bytes, where M is a positive integer, 2 N is the bus interface width. For example, in this embodiment, the bus interface width is 4 bytes, the buffer space is 8 bytes, and M is 2.
[0056] Adder: One input end is connected to the read port 1 data (source address / target address) of the general register, and the other input end is connected to the memory copy controller. The memory copy controller provides an address increment for updating the source address and the target address. For example, in the read state, each time 4 bytes of data are read, the source address needs to be +4 bytes, and the increment is 4 bytes. The source address is updated by the adder to the offset address, and is written back to the general register through the output end of the adder, or it can be written back through the write back unit (WB). The update process of the target address is the same. The adder is time-division multiplexed through the first selector. The two input ends of the first selector are respectively connected to the register number of the source address and the register number of the target address. The control end is connected to the memory copy controller, and the output end is connected to the general register. In the read state, the first selector outputs the register number of the source address; in the write state, the first selector outputs the register number of the target address. Therefore, this embodiment requires an adder with a selector to be implemented.
[0057] Comparator: One input end is connected to the read port 1 data of the general register (source address / destination address). In this scheme, comparison is only performed when the source address is input. The other input end is connected to the read port 0 data of the general register (the end address of the source address). The output end is connected to the memory copy controller to determine whether the copy is completed.
[0058] In this embodiment, the adder, comparator, and bus interface each have only one group, and occupy a write port of the general register, and also include a first selector. When it is necessary to use them in the read state and the write state respectively, the first selector is used for time-sharing multiplexing. In addition, the adder, comparator, and bus interface can also reuse the original functional units in the CPU, and the structure is simpler by adding a selector to select the memory copy instruction or the original path. Therefore, the connection between the various parts in the CPU includes direct connection and indirect connection.
[0059] In this embodiment, the memory copy controller includes only one state machine, which includes at least an idle state, a read state, and a write state, and may also include a clear state for use in determining when the copy is finished.
[0060] A method for quickly processing a memory copy instruction using the CPU capable of quickly processing a memory copy instruction comprises the following steps:
[0061] The state machine of the memory copy controller is initially in an idle state;
[0062] When the instruction decoder receives a valid memory copy instruction, it reads the source address register number, the target address register number, and the copy end information register number from the valid memory copy instruction to the general register, and sends a start signal to the memory copy controller at the same time. The general register can obtain and output the initial values of the source address and the target address and the copy end information through the source address register number, the target address register number, and the copy end information register number;
[0063] When the memory copy controller receives the start signal, the state machine jumps to the read state and reads data from the source address through the bus interface and temporarily stores it in the buffer. Each time 1~2 N Byte data, jump to the write state after reading the data at least once; in the write state, the data in the buffer is written to the target address in sequence through the bus interface according to the first-in first-out principle, and the written data in the buffer is cleared, and 1~2 are written each time N Byte data, jump to the read state after writing the data at least once; continuously switch between the read state and the write state, use the adder to update the source address and the target address, use the comparator to determine whether the copy is completed according to the copy end information, and return to the idle state if the copy is completed.
[0064] In order to maximize the efficiency of memory copying, read operations usually have a higher priority than write operations, that is, in the read state, if the buffer space is less than 2 N Byte, jump to write state, otherwise stay in read state; in write state, if the buffer valid bit is less than 2 N Bytes, jump to the read state, otherwise stay in the write state. Among them, empty bits + valid bits = M*2 N This ensures that there is no idle waiting time during the read-write switching process, and can maximize the efficiency of memory copying.
[0065] To determine whether the copying is completed, you can make the determination in the read state or the write state. It is preferred to make the determination in the read state. In this case, you need to set the fourth state, i.e., the clear state. The specific method is:
[0066] In the read state, the comparator is used to predict whether the read operation is about to be completed based on the source address and the copy end information (the end address of the source address). The prediction means that before the current read operation starts, it is first determined whether the source address after reading reaches or exceeds the end address. If it is determined that the read operation is about to be completed after reading the data once, it enters the clear state instead of the write state after the read operation. Otherwise, the read operation is performed normally and jumps to the write operation;
[0067] In the clear state, the data in the buffer is written to the target address and the written data is cleared until the buffer is cleared and the memory copy is completed. The difference between the clear state and the write state is that in the write state, the buffer will be cleared if the buffer space reaches or exceeds 2. N Bytes are read and the program jumps to the read state. In the clear state, all data in the buffer will be written out, and the program jumps to the idle state after the buffer is cleared.
[0068] This embodiment supports interruption. If the state machine is in a non-idle state, when the memory copy controller receives an interrupt request signal or a debug signal from the instruction decoder, the state machine first jumps to the clear state, and after the state machine returns to the idle state, the processor responds to the interrupt or debug request normally; if the state machine is in an idle state, when the memory copy controller receives an interrupt request signal or a debug signal from the instruction decoder, the processor responds to the interrupt or debug request normally; during the interrupt or debug response process, the return program pointer is saved as the program pointer of the current memory copy instruction, and the general register is saved and restored in software and hardware according to the application binary interface; after the interrupt or debug exits, the program pointer is restored to the return program pointer, and the processor re-executes the memory copy instruction, and continues to execute from the memory copy breakpoint to complete the remaining copy.
[0069] In addition to setting the clear state, the same effect can also be achieved through an end flag. When the end flag is valid, it is equivalent to entering the clear state. Each time before reading, a comparison is made. If the prediction result is that the read operation is about to be completed, the end flag is recorded as valid, otherwise the end flag is recorded as invalid. After the read state, it switches to the write state. When the end flag is valid, all data in the buffer will be written and the buffer will be cleared in the write state, and it will not jump to the read state again; when the end flag is invalid, the write state is an ordinary write operation. After the write operation, it will still need to jump to the read state according to the buffer vacancy.
[0070] like Figure 2 The following diagram shows the changes in the data in the buffer during a memory copy. In this example, EA=0x1009, SA=0x1001, DA=0x2003, and the total copy length is 8 bytes. IDLE is the idle state, LOAD is the read state, STORE is the write state, and CLEAN is the clear state. In the read state, 4 bytes of data are read each time, and the data can also be marked. In the write state, the maximum alignment principle (maximum size principle) is used.
[0071] In this embodiment, the maximum number of bytes in a single read operation can reach the bus interface width 2 N , write operations can be performed using the maximum alignment principle without restrictions, so the memory copy efficiency can be improved as much as possible.
[0072] Embodiment 2:
[0073] The difference between the second embodiment and the first embodiment is that in the second embodiment, reading and writing can be performed at the same time. Figure 3 As shown, in this case, the memory copy controller needs two state machines for controlling read operations and write operations respectively, including a read state machine and a write state machine. The read state machine includes an idle state and a read state for read operations; the write state machine includes an idle state and a write state for write operations. This embodiment can perform reading and writing at the same time, so the memory copy efficiency is higher.
[0074] In addition to the state machine, there are two groups of adders and bus interfaces, one group of read adders and read bus interfaces for read operations, and one group of write adders and write bus interfaces for write operations. Two write ports and three read ports of general registers are required. One input end of the read adder is connected to the read port 1 data of the general register, the other input end is connected to the read state machine of the memory copy controller (to obtain the read increment), and the output end is connected to the write port 1 data. One input end of the write adder is connected to the read port 2 data of the general register, the other input end is connected to the write state machine of the memory copy controller (to obtain the write increment), and the output end is connected to the write port 2 data. The read port 1 address and write port 1 address of the general register are both connected to SA_IDX, the read port 2 address and write port 2 address are both connected to DA_IDX, and the read port 0 address is connected to SA_IDX. Write port 1 enable is connected to the read state machine to control the write enable of write port 1, and write port 2 enable is connected to the write state machine to control the write enable of write port 2.
[0075] A method for quickly processing a memory copy instruction using the CPU capable of quickly processing a memory copy instruction comprises the following steps:
[0076] The read state machine and the write state machine of the memory copy controller are both in the idle state initially;
[0077] When the instruction decoder receives a valid memory copy instruction, it reads the source address register number, the target address register number, and the copy end information register number from the valid memory copy instruction to the general register, obtains the initial value of the source address and the target address and the copy end information through the source address register number, the target address register number, and the copy end information register number, and sends a start signal to the memory copy controller at the same time, and the read operation and the write operation are performed simultaneously;
[0078] The read state machine of the memory copy controller jumps to the read state, and continuously reads data from the source address through the read bus interface and temporarily stores it in the buffer, and uses the read adder to update the source address until the read operation is completed, and the read state machine jumps to the idle state;
[0079] At the same time, the write state machine of the memory copy controller jumps to the write state, writes the data in the buffer to the target address through the write bus interface, clears the written data in the buffer, and uses the write adder to update the target address until the write operation is completed and the write state machine jumps to the idle state.
[0080] The method for determining the end of the read operation is: using a comparator to determine whether the read operation is completed according to the source address and the copy end information;
[0081] The method for judging the end of the write operation is: when the read state machine is idle, if the buffer is cleared, the write operation is completed; if it is not cleared, the write operation continues until the buffer is cleared; when the read state machine is in a non-idle state, the write state machine is always in a write state.
[0082] This embodiment supports interruption. If at least one of the read state machine and the write state machine is in a non-idle state, when the memory copy controller receives an interrupt request signal or a debug signal from the instruction decoder, the read state machine first jumps to the idle state, and after the write state machine also jumps to the idle state, the processor responds to the interrupt or debug request normally; if both the read state machine and the write state machine are in an idle state, when the memory copy controller receives an interrupt request signal or a debug signal from the instruction decoder, the processor responds to the interrupt or debug request normally; during the interrupt or debug response process, the return program pointer is saved as the program pointer of the current memory copy instruction, and the general register is saved and restored in software and hardware according to the application binary interface; after the interrupt or debug exits, the program pointer is restored to the return program pointer, and the processor re-executes the memory copy instruction, and continues to execute from the memory copy breakpoint to complete the remaining copy.
Claims
1. A CPU capable of quickly processing memory copy instructions, characterized in that: include: An instruction decoder, the input end of which inputs the CPU instruction, and the output end of which is connected to the read port of the general register and the memory copy controller, is used to decode a valid memory copy instruction, wherein the valid memory copy instruction includes a source address register number, a target address register number and a copy end information register number; General register, connected to the memory copy controller, used to store source address, target address, and copy end information; The memory copy controller includes a state machine, wherein the state machine includes an idle state, a read state, and a write state. In the idle state, the controller waits to receive a valid memory copy instruction; in the read state, the controller controls the bus interface to read data from the source address and temporarily stores the data in the buffer; in the write state, the controller controls the bus interface to write the data temporarily stored in the buffer to the target address; A bus interface, connected to a memory copy controller and a buffer, and connected to an external memory; Buffer, connected to the memory copy controller; An adder, the input end of which is connected to the read port of the general register and the memory copy controller, and the output end of which is connected to the write port of the general register, for updating the source address and the target address; A comparator, whose input end is connected to the read port of the general register and whose output end is connected to the memory copy controller, is used to determine whether the copy is completed according to the copy end information.
2. The CPU capable of quickly processing memory copy instructions according to claim 1, characterized in that: The buffer space is M*2 N Bytes, where M is a positive integer, 2 N is the bus interface width.
3. The CPU capable of quickly processing memory copy instructions according to claim 1, characterized in that: The copy end information is one or more of the end address of the source address, the end address of the target address, and the total copy length.
4. The CPU capable of quickly processing memory copy instructions according to any one of claims 1 to 3, characterized in that: The state machine, adder and bus interface each have one; one write port of the general register is occupied, which is used to write the updated source address or target address in time sharing; two read ports of the general register are occupied, the first read port is used to read the copy end information, and the second read port is used to read the current source address and target address in time sharing; it also includes a first selector, the two input ends of the first selector respectively input the source address register number and the target address register number, the control end is connected to the memory copy controller, and the output end is connected to the second read port and write port of the general register; in the read state, the first selector outputs the source address register number; in the write state, the first selector outputs the target address register number.
5. The CPU capable of quickly processing memory copy instructions according to any one of claims 1 to 3, characterized in that: The state machine, adder, and bus interface each have two, including a read state machine, a read adder, and a read bus interface for read operations, and a write state machine, a write adder, and a write bus interface for write operations, the read state machine includes an idle state and a read state, and the write state machine includes an idle state and a write state; Two write ports of the general register are occupied, which are used to write the updated source address and target address respectively; three read ports of the general register are occupied, and the first read port, the second read port and the third read port are used to read the copy end information, the source address and the target address respectively.
6. A method for quickly processing a memory copy instruction using a CPU capable of quickly processing a memory copy instruction as described in any one of claims 1 to 4, characterized in that: The following steps are involved: The state machine of the memory copy controller is initially in an idle state; When the instruction decoder receives a valid memory copy instruction, it reads the source address register number, the target address register number, and the copy end information register number from the valid memory copy instruction to the general register, and sends a start signal to the memory copy controller at the same time. The general register obtains and outputs the initial values of the source address and the target address and the copy end information through the source address register number, the target address register number, and the copy end information register number; When the memory copy controller receives the start signal, the state machine jumps to the read state, reads data from the source address through the bus interface and temporarily stores it in the buffer, and jumps to the write state after reading the data at least once; In the write state, the data in the buffer is written to the target address in sequence through the bus interface according to the first-in-first-out principle, and the written data in the buffer is cleared. After writing the data at least once, it jumps to the read state; it continuously switches between the read state and the write state, uses the adder to update the source address and the target address, and uses the comparator to determine whether the copy is completed according to the copy end information. If the copy is completed, it returns to the idle state.
7. The method for quickly processing a memory copy instruction according to claim 6, characterized in that: In the read state, each read 1~2 N Byte data; in write state, write 1~2 each time N Byte data, 2 N is the bus interface width.
8. The method for quickly processing a memory copy instruction according to claim 7, characterized in that: In the read state, if the buffer space is less than 2 N Byte, jump to write state, otherwise stay in read state; in write state, if the buffer valid bit is less than 2 N Byte, jumps to the read state, otherwise remains in the write state.
9. The method for quickly processing a memory copy instruction according to any one of claims 6 to 8, characterized in that: The method to determine whether the copy is completed according to the copy end information is: In the read state, the comparator is used to predict whether the read operation is about to be completed according to the source address and the copy end information. If the read operation is about to be completed, the clear state is entered instead of the write state after the read, otherwise the read operation is performed normally and jumps to the write operation; In the clear state, the data in the buffer is written to the target address and the written data is cleared until the buffer is cleared and the memory copy is completed.
10. The method for quickly processing a memory copy instruction according to claim 9, characterized in that: If the state machine is in a non-idle state, when the memory copy controller receives an interrupt request signal or a debug signal from the instruction decoder, the state machine first jumps to the clear state, and after the state machine returns to the idle state, the processor responds to the interrupt or debug request normally; If the state machine is in idle state, when the memory copy controller receives an interrupt request signal or debug signal from the instruction decoder, the processor responds to the interrupt or debug request normally; during the interrupt or debug response process, the return program pointer is saved as the program pointer of the current memory copy instruction, and the general registers are saved and restored in software and hardware according to the application binary interface; after the interrupt or debug exits, the program pointer is restored to the return program pointer, and the processor re-executes the memory copy instruction and continues execution from the memory copy breakpoint to complete the remaining copy.
11. A method for quickly processing a memory copy instruction using the CPU capable of quickly processing a memory copy instruction as claimed in claim 5, characterized in that: The following steps are involved: The read state machine and the write state machine of the memory copy controller are both in the idle state initially; When the instruction decoder receives a valid memory copy instruction, it reads the source address register number, the target address register number, and the copy end information register number from the valid memory copy instruction to the general register, and sends a start signal to the memory copy controller at the same time; the general register obtains and outputs the initial values of the source address and the target address and the copy end information through the source address register number, the target address register number, and the copy end information register number; After the memory copy controller receives the start signal, the read state machine jumps to the read state, continuously reads data from the source address through the read bus interface and temporarily stores it in the buffer, and uses the read adder to update the source address until the read operation is completed, and the read state machine jumps to the idle state; At the same time, the write state machine of the memory copy controller jumps to the write state, and writes the data in the buffer to the target address in sequence through the write bus interface according to the first-in-first-out principle, clears the written data in the buffer, and uses the write adder to update the target address until the write operation is completed and the write state machine jumps to the idle state.
12. The method for quickly processing a memory copy instruction according to claim 11, characterized in that: In the read state, each read 1~2 N Byte data; in write state, write 1~2 each time N Byte data, 2 N is the bus interface width.
13. The method for quickly processing a memory copy instruction according to claim 11 or 12, characterized in that: The method for judging the end of the read operation is: using a comparator to judge whether the read operation is completed according to the source address and the copy end information; The method for judging the end of the write operation is: when the read state machine is idle, if the buffer is cleared, the write operation is completed; if it is not cleared, the write operation continues until the buffer is cleared; if the read state machine is not idle, the write state machine always maintains the write state.
14. The method for quickly processing a memory copy instruction according to claim 13, characterized in that: If at least one of the read state machine and the write state machine is in a non-idle state, when the memory copy controller receives an interrupt request signal or a debug signal from the instruction decoder, the read state machine first jumps to the idle state, and after the write state machine also jumps to the idle state, the processor responds to the interrupt or debug request normally; if both the read state machine and the write state machine are in an idle state, when the memory copy controller receives an interrupt request signal or a debug signal from the instruction decoder, the processor responds to the interrupt or debug request normally; during the interrupt or debug response process, the return program pointer is saved as the program pointer of the current memory copy instruction, and the general registers are saved and restored in software and hardware according to the application binary interface; after the interrupt or debug exits, the program pointer is restored to the return program pointer, the processor re-executes the memory copy instruction, and continues to execute from the memory copy breakpoint to complete the remaining copies.
