Data processing apparatus, operating method and machine-readable storage medium

By using the processor to shift data and retain some data, the problem of unaligned memory address access is solved, enabling unaligned memory address access and small-granular data access.

CN116521233BActive Publication Date: 2026-11-17SHANGHAI BIREN TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310519581.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-09
Publication Date
2026-11-17
Estimated Expiration
2043-05-09

AI Technical Summary

Technical Problem

Existing technologies cannot effectively access unaligned memory addresses, especially for data access that does not support granularity smaller than memory access.

Method used

The processor performs data offsetting and partial data retention based on the aligned address of the target address, and merges data of different granularities to achieve unaligned address access to memory.

Benefits of technology

It enables data access to memory at a finer granularity that is not currently supported, and allows access to unaligned addresses, thus expanding the data access capabilities of memory.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116521233B_ABST
    Figure CN116521233B_ABST
Patent Text Reader

Abstract

This invention provides a data processing apparatus and its operating method. The data processing apparatus includes memory and a processor. The memory does not support a first access granularity but supports a second access granularity larger than the first access granularity. During the process of the processor storing first data of the first access granularity from the processor's register to a target address in memory: the processor reads second data of the second access granularity from memory based on the alignment address corresponding to the target address; the processor shifts the first data based on the target address and the alignment address to obtain shifted first data, and partially retains the second data to obtain retained second data; the processor merges the shifted first data and the retained second data of the second access granularity to obtain merged second data of the second access granularity; and the processor writes the merged second data containing the first data back to memory based on the alignment address.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to an electronic device, and more particularly to a data processing apparatus, a method of operation, and a machine-readable storage medium. Background Technology

[0002] Processors can execute load and store instructions to access data in memory. Generally, memory has a specific access granularity. This granularity refers to the minimum data length that can be accessed from this memory. For example, thread-local memory (TLM), or local memory, might have an access granularity of 4 bytes. That is, the minimum data length that the processor can access from this thread-local memory is 32 bits. Assuming each byte of memory is defined with an address, and the memory access granularity is 4 bytes, addresses 0, 4, 8, 12, ... are called aligned addresses, while other addresses are called unaligned addresses. A load (or store) instruction is valid if the address is aligned. A load (or store) instruction is invalid because memory does not support unaligned address access. Furthermore, a load (or store) instruction is also illegal when the memory does not support the granularity of the data that the instruction intends to load (or store). For example, suppose the thread-local memory (TLM) has an access granularity of 4 bytes (aligned addresses 0, 4, 8, ...), and a store instruction attempts to store 8 bits of data from the processor's register into the TLM. This store instruction is illegal because the TLM does not support 8-bit (1-byte) access granularity. How to access data in memory with an unsupported access granularity, and / or how to perform unaligned address access to memory, is one of the many technical challenges in this field. Summary of the Invention

[0003] The present invention provides a data processing apparatus and its operating method, as well as a machine-readable storage medium for accessing data in memory.

[0004] In an embodiment of the present invention, the data processing apparatus includes memory and a processor. The memory does not support access at a first access granularity, but supports access at a second access granularity greater than the first access granularity. The processor is coupled to the memory. During the process of the processor storing at least one first data of the first access granularity from at least one register of the processor to at least one first target address of the memory: the processor reads second data from the memory based on a first alignment address corresponding to the at least one first target address; the processor shifts the at least one first data based on the at least one first target address and the first alignment address to obtain shifted first data; the processor partially retains the second data based on the at least one first target address and the first alignment address to obtain retained second data; the processor merges the shifted first data and the retained second data to obtain merged second data; and the processor writes the merged second data containing the at least one first data back to the memory based on the first alignment address corresponding to the at least one first target address.

[0005] In an embodiment of the present invention, the operation method includes: storing at least one piece of first data at a first access granularity from at least one register of a processor to at least one first target address of memory that does not support access at the first access granularity. The process of storing the at least one piece of first data from the at least one register to the at least one first target address of memory includes: reading second data from memory based on a first alignment address corresponding to the at least one first target address; shifting the at least one piece of first data based on the at least one first target address and the first alignment address to obtain shifted first data; partially retaining the second data based on the at least one first target address and the first alignment address to obtain retained second data; merging the shifted first data and the retained second data to obtain merged second data; and writing the merged second data containing the at least one piece of first data back to memory based on the first alignment address corresponding to the at least one first target address.

[0006] In an embodiment of the invention, the machine-readable storage medium is used to store non-transitory machine-readable instructions. When the non-transitory machine-readable instructions are executed by a computer, the operation method of the data processing apparatus can be implemented.

[0007] Based on the above, and based on the aligned address corresponding to the target address, large-granularity (second access granularity, such as 32-bit or other granularity) second data can be read from memory into the processor. The processor can then partially retain the second data to obtain large-granularity retained second data. Furthermore, the processor can shift small-granularity (first access granularity, such as 8-bit or other granularity) first data to obtain large-granularity shifted first data. The processor can merge the shifted first data (large-granularity data containing the first data) and the retained second data to obtain large-granularity merged second data. Finally, the processor can write the merged second data containing the first data back to memory. Therefore, the processor can access memory at a small granularity (first access granularity) that it does not support, and / or perform unaligned address access to memory. Attached Figure Description

[0008] Figure 1 This is a schematic diagram of a circuit block of a data processing device according to an embodiment of the present invention.

[0009] Figure 2 This is a schematic flowchart illustrating the operation method of a data processing apparatus according to an embodiment of the present invention.

[0010] Figure 3 This is a flowchart illustrating an operation method of a data processing apparatus according to another embodiment of the present invention.

[0011] Figure 4 This is a schematic diagram illustrating, according to an embodiment of the present invention, the process by which a processor stores data at a first access granularity in a register into memory that does not support access at the first access granularity.

[0012] Figure 5 This is a schematic diagram illustrating, according to another embodiment of the present invention, the process by which a processor stores multiple destination data at a first access granularity in multiple registers to multiple target addresses of memory that does not support access at the first access granularity.

[0013] Explanation of reference numerals in the attached figures

[0014] 100: Data processing device

[0015] 110: Processor

[0016] MEM1: Memory

[0017] S210~S250, S310~S380: Steps

[0018] R0, R1: Registers

[0019] D0, D1, D2, D3, D4, D5, D6, D7, U0, V0: Data Detailed Implementation

[0020] Reference will now be made in detail to exemplary embodiments of the invention, examples of which are illustrated in the accompanying drawings. Wherever possible, the same component reference numerals are used in the drawings and description to denote the same or similar parts.

[0021] The term "coupled (or connected)" as used throughout this specification (including the claims) may refer to any direct or indirect means of connection. For example, if the text describes a first device coupled (or connected) to a second device, it should be interpreted as the first device being directly connected to the second device, or the first device being indirectly connected to the second device through other devices or some means of connection. The terms "first," "second," etc., used throughout this specification (including the claims) are used to name components, and are not intended to limit the upper or lower limit of the number of components, nor to limit the order of components. Furthermore, wherever possible, components / components / steps using the same reference numerals in the drawings and embodiments represent the same or similar parts. Components / components / steps using the same reference numerals or the same terms in different embodiments may be referred to mutually in the relevant descriptions.

[0022] Figure 1 This is a schematic diagram of a circuit block of a data processing device 100 according to an embodiment of the present invention. Figure 1 The data processing device 100 shown includes a memory MEM1 and a processor 110. Depending on different design requirements, in some embodiments, the processor 110 may be implemented as hardware circuitry. In other embodiments, the processor 110 may be implemented as a combination of hardware, firmware, and software.

[0023] In hardware terms, the processor 110 described above can be implemented as logic circuitry on an integrated circuit. For example, the functions of the processor 110 can be implemented as various logic blocks, modules, and circuits in one or more controllers, microcontrollers, microprocessors, application-specific integrated circuits (ASICs), digital signal processors (DSPs), field-programmable gate arrays (FPGAs), central processing units (CPUs), and / or other processing units. The functions of the processor 110 can be implemented as hardware circuitry, such as various logic blocks, modules, and circuits in an integrated circuit, using hardware description languages ​​(such as Verilog HDL or VHDL) or other suitable programming languages.

[0024] In software and / or firmware form, the functions of the processor 110 can be implemented as programming codes. For example, the processor 110 can be implemented using general programming languages ​​(such as C, C++, or assembly language) or other suitable programming languages. The programming codes can be recorded / stored in a non-transitory machine-readable storage medium. In some embodiments, the machine-readable storage medium includes, for example, semiconductor memory and / or a storage device. The semiconductor memory includes a memory card, read-only memory (ROM), flash memory, programmable logic circuitry, or other semiconductor memory. The storage device includes a tape, disk, hard disk drive (HDD), solid-state drive (SSD), or other storage device. An electronic device (e.g., a CPU, controller, microcontroller, or microprocessor) can read and execute the programming codes from the machine-readable storage medium to implement the functions of the processor 110. Alternatively, the programming codes can be provided to the electronic device via any transmission medium (e.g., a communication network or broadcast radio waves). The communication network is, for example, the Internet, wired communication networks, wireless communication networks, or other communication media.

[0025] Processor 110 is coupled to memory MEM1. Memory MEM1 can be off-chip memory of data processing device 100. For example, memory MEM1 can be global memory (GLM), global shared memory (GSM), thread local memory (TLM), or local memory. GSM is shared memory for a warp. Generally, memory has a specific access granularity. The access granularity refers to the minimum data length that can be accessed from this memory. For example (but not limited to), the access granularity of memory MEM1 is assumed to be 4 bytes, that is, the minimum data length unit for processor 110 to access memory MEM1 is 32 bits. Memory MEM1 supports access at a 4-byte granularity (second access granularity), but does not support access at an access granularity smaller than 4 bytes (first access granularity). For example, memory MEM1 does not support access at a 1, 2, or 3-byte granularity.

[0026] Processor 110 can execute load and store instructions to access data in memory MEM1. Assuming each byte of memory is defined by an address, and the access granularity of memory MEM1 is 4 bytes, addresses 0, 4, 8, 12, ... are called aligned addresses, while other addresses are called unaligned addresses. A load (or store) instruction is valid if its address is aligned. A load (or store) instruction is invalid because memory MEM1 does not support unaligned address access. Furthermore, a load (or store) instruction is also invalid for memory MEM1 if the granularity of the data it intends to load (or store) is not supported by memory MEM1. For example, suppose the access granularity of memory MEM1 is 4 bytes (aligned addresses 0, 4, 8, ...), and the store instruction is the following pseudocode. This means that 8 bits of data are stored from register R0 of processor 110 to address "1" of memory MEM1. The following pseudocode is an illegal instruction because address "1" is not an aligned address of memory MEM1, and the granularity of memory MEM1 does not support 8-bit (1 byte) access.

[0027] Store R0.i8 to 1.MEM1.i8

[0028] The following describes the process of "storing at least one first data of a first access granularity from at least one register of processor 110 to memory MEM1, which does not support access at the first access granularity" using different embodiments.

[0029] Figure 2 This is a flowchart illustrating an operation method of a data processing apparatus according to an embodiment of the present invention. The processor 110 can perform steps S210, S220, S230, S240, and S250 to store first data at a first access granularity (e.g., 1 byte or other granularity) from the processor 110's register to a target address of memory MEM1 that does not support access at the first access granularity (or to store the data to an unaligned address of memory MEM1). In some embodiments, Figure 2 The operation method of the data processing device shown can be implemented in firmware or software (i.e., a program). For example, Figure 2 The operations of the data processing apparatus shown can be implemented as non-transitory machine-readable instructions (programming code or program), and these non-transitory machine-readable instructions can be stored in a machine-readable storage medium. When the non-transitory machine-readable instructions are executed by a computer, they can be implemented... Figure 2 The operation method of the data processing apparatus shown is illustrated. In other embodiments, [the following is also described]: Figure 2 The operation method of the data processing device shown can be implemented in hardware, for example, implemented in... Figure 1 The processor 110 shown.

[0030] In step S210, processor 110 can read second data (e.g., 4 bytes or other granularities) from memory MEM1 based on the alignment address corresponding to the target address of the storage instruction. In step S220, processor 110 can partially retain data in the second data (e.g., row masking operation) based on the target address and the alignment address to obtain retained second data at the second access granularity. In step S230, processor 110 can shift the first data based on the target address and the alignment address to obtain shifted first data at the second access granularity. In step S240, processor 110 can merge the shifted first data (large-granularity data containing the first data) and the retained second data to obtain merged second data at the second access granularity. In step S250, processor 110 can write the merged second data containing the first data back to memory MEM1 based on the alignment address corresponding to the target address. Therefore, the processor 110 can access the memory MEM1 with a small granularity (first access granularity) that it does not support, and / or perform unaligned address access to the memory MEM1.

[0031] For example, Figure 3 This is a flowchart illustrating an operation method of a data processing apparatus 100 according to another embodiment of the present invention. The processor 110 may perform steps S310 to S380 during the process of storing first data of a first access granularity from the processor 110's register to a target address of memory MEM1. In step S310, the processor 110 may calculate the alignment address corresponding to the target address based on the target address of the stored instruction. In step S320, the processor 110 may read second data of a second access granularity (e.g., 4 bytes or other granularities) from the alignment address of memory MEM1. In step S330, the processor 110 may calculate the address offset between the target address and the alignment address to obtain a bit offset. In step S340, the processor 110 may generate a data mask based on the bit offset and the second access granularity. In step S350, the processor 110 may partially retain the second data based on the inverted mask corresponding to the data mask to obtain retained second data. In step S360, the processor 110 may shift the first data based on the bit offset to obtain shifted first data. Steps S370 and S380 can be referred to Figure 2 The relevant explanations of steps S240 and S250 shown are omitted here.

[0032] Figure 4 This is a schematic diagram illustrating, according to an embodiment of the present invention, the process by which processor 110 stores data V0 of a first access granularity (e.g., 1 byte) in register R0 to target address "0x49" in memory MEM1. Figure 4 Each small square shown represents one byte. Assuming that the second access granularity supported by memory MEM1 is 4 bytes (i.e., the minimum data length accessed by memory MEM1 is 4 bytes), then addresses 0x0, 0x4, 0x8, ..., 0x48, 0x4c, ... of memory MEM1 are called aligned addresses, while other addresses are called unaligned addresses. Because memory MEM1 does not support unaligned address access, processor 110 cannot directly store the new data V0 in register R0 to the target address "0x49" of memory MEM1 without affecting the original data "D3", "D2", and "D0" at addresses "0x4b", "0x4a", and "0x48" of memory MEM1. Furthermore, memory MEM1 does not support 8-bit (1-byte) access granularity.

[0033] During the process of processor 110 storing data V0 at the first access granularity (e.g., 1 byte) in register R0 to the target address "0x49" in memory MEM1, processor 110 can perform steps S310 to S380. In some practical examples, Figure 4The process of "processor 110 storing 1 byte of data V0 into memory MEM1" can be implemented as the following pseudocode. Line A1 of the pseudocode indicates that processor 110 calculates the alignment address Addr-align corresponding to address Addr in memory MEM1 based on the target address Addr of memory MEM1, i.e., step S310. For example, processor 110 can perform an AND operation on the target address Addr based on the alignment mask "0xFFFFFFFC" corresponding to "4 bytes" (second access granularity) to obtain the alignment address Addr-align. Assuming that the 8-bit data V0 from register R0 of processor 110 is to be written to the target address Addr of memory MEM1 is "0x49", then processor 110 can calculate Addr-align = Addr & 0xFFFFFFFC = 0x00000049 & 0xFFFFFFFC = 0x48, where "&" represents the AND operation. Since the access granularity is 4 bytes, the alignment mask is 0xFFFFFFFC. If the access granularity is 8 bytes, the alignment mask is 0xFFFFFFF8. The alignment masks for other access granularities follow the same pattern. Therefore, the processor 110 can calculate the corresponding alignment address Addr-align (e.g., address "0x48") based on the target address Addr of memory MEM1 (e.g., address "0x49").

[0034] A1: Get Addr-align of Addr.MEM1;

[0035] A2: Load data From Addr-align.MEM1 To R1.i32;

[0036] A3: Get Offset between Addr and Addr-align;

[0037] A4: Get Shiftbits Offset*8;

[0038] A5: Get DataMask From Shiftbits;

[0039] A6: Mask R1.i32 To R1.i32

[0040] A7: Shift Shiftbits R0.i32 to R0.i32;

[0041] A8: Mask R0.i32 To R0.i32;

[0042] A9: Or R1.i32 R0.i32 To R0.i32;

[0043] A10: Store R0.i32 To Addr-align.MEM1;

[0044] Line A2 of the above pseudocode indicates that processor 110 can read 4 bytes (second access granularity) of second data from the aligned address Addr-align (e.g., address "0x48") of memory MEM1 into register R1 of processor 110, i.e., step S320. Figure 4 As shown, in step S320, the processor 110 can load 4 bytes of original data "D3, D2, D1, D0" (second data of the second access granularity) from memory MEM1 to register R1 of the processor 110 based on the aligned address "0x48".

[0045] In some embodiments, step S330 can be implemented as lines A3 and A4 of the pseudocode above. Line A3 of the pseudocode indicates that processor 110 calculates the address offset Offset between the target address Addr (e.g., address "0x49") and the alignment address Addr-align (e.g., address "0x48"). Line A4 of the pseudocode indicates that processor 110 calculates the bit offset Shiftbits based on the address offset Offset and the data width of an address (e.g., 8 bits). For example, processor 110 performs a bitwise AND operation on the target address Addr based on the address mask AddrMask corresponding to the second access granularity to obtain the address offset Offset, and then processor 110 multiplies the address offset Offset based on the number of bits corresponding to the first access granularity to obtain the bit offset Shiftbits. Assuming the memory MEM1 has an access granularity of 4 bytes, the address mask AddrMask is 0x3. Processor 110 can calculate Offset = (Addr & AddrMask) = (0x00000049 & 0x00000003) = 0x1 to implement line A3 of the pseudocode above. Next, processor 110 can calculate Shiftbits = Offset << 3 = 0x1 << 3 = 0x8 to implement line A4 of the pseudocode above. Here, "<<" indicates a left shift. Shifting the address offset 3 bytes to the left is equivalent to multiplying the address offset by 8 (one address is 8 bits of data). If the memory MEM1 has an access granularity of 8 bytes, the address mask AddrMask is 0x7. The address masks AddrMask for other access granularities follow the same logic.

[0046] In step S340, the processor 110 may generate the data mask DataMask according to the bit offset Shiftbits and the mask constant ConstMask corresponding to the second access granularity. In some embodiments, step S340 may be implemented as line A5 of the above pseudocode. Line A5 of the above pseudocode indicates that the processor 110 shifts the mask constant ConstMask corresponding to the first access granularity based on the bit offset Shiftbits, so as to obtain the data mask DataMask corresponding to the second access granularity. For example, assume that the first access granularity of the data V0 is 1 byte (8 bits) and the second access granularity of the memory MEM1 is 4 bytes (32 bits). Since the data V0 is 8 bits, the mask constant ConstMask is 0xFF. The processor 110 may calculate DataMask=ConstMask<<Shiftbits=0x000000FF<<0x8=0x0000FF00, and the inverted mask corresponding to the data mask "0x0000FF00" is "0xFFFF00FF". If the data V0 is 16 bits, the mask constant ConstMask is 0xFFFF. The mask constant ConstMask for other granularities of the data V0 can be deduced by analogy.

[0047] In step S350, the processor 110 may perform partial data retention on the second data "D3, D2, D1, D0" of the register R1 based on the inverted mask DataMask' corresponding to the data mask DataMask, so as to obtain the retained second data. In some embodiments, step S350 may be implemented as line A6 of the above pseudocode. Line A6 of the above pseudocode indicates that the processor 110 performs partial data retention on the second data of the register R1 based on the inverted mask DataMask' corresponding to the data mask DataMask, and stores the retained second data into the register R1. For example, the processor 110 performs an AND operation on the second data of the register R1 based on the inverted mask DataMask', so as to obtain the retained second data. Assume that the second data of the register R1 is "D3, D2, D1, D0", then the processor 110 may calculate R1=R1&DataMask'="D3 D2 D1 D0"&0xFFFF00FF="D3 D2 0x00 D0".

[0048] In step S360, the processor 110 may shift the first data V0 of the register R0 based on the bit offset Shiftbits, to obtain the shifted first data V0'. In some embodiments, step S360 may be implemented as lines A7 and A8 of the above pseudocode. Line A7 of the above pseudocode indicates that the processor 110 shifts the data V0 (the first data) of the register R0 based on the bit offset Shiftbits, to obtain second granularity data and store the second granularity data into the register R0. For example, assuming the original data of the register R0 is "V3, V2, V1, V0", the processor 110 may calculate R0=R0<<Shiftbits="V3 V2 V1 V0"<<0x8="V2 V1 V0 0x00". Line A8 of the above pseudocode indicates that the processor 110 performs an AND operation on the second granularity data based on the data mask DataMask, to obtain the shifted first data V0' and store the shifted first data V0' into the register R0. For example, assuming the data of the register R1 is "V2, V1, V0, 0x00", the processor 110 may calculate R0=R0&DataMask="V2 V1 V0 0x00"&0x0000FF00="0x0000V0 0x00".

[0049] In step S370, the processor 110 may merge the shifted first data (the large-granularity data containing the first data) and the reserved second data, to obtain merged second data of the second access granularity. In some embodiments, step S370 may be implemented as line A9 of the above pseudocode. Line A9 of the above pseudocode indicates that the processor 110 performs an OR operation on the shifted first data of the register R0 and the reserved second data of the register R1, to obtain merged second data of the second access granularity and store the merged second data into the register R0. For example, assuming the shifted first data V0' of the register R0 is "0x00, 0x00, V0, 0x00" and the reserved second data of the register R1 is "D3, D2, 0x00, D0", the processor 110 may calculate R0=R0|R1="0x0000 V0 0x00"|"D3 D2 0x00 D0"="D3 D2 V0 D0", where "|" denotes the OR operation.

[0050] In step S380, processor 110 can write the merged second data containing the first data V0 back to memory MEM1 based on the alignment address Addr-align corresponding to the target address Addr. In some embodiments, step S380 can be implemented as line A10 of the pseudocode above. Line A10 of the pseudocode above indicates that processor 110 writes the merged second data containing the first data V0 back to the alignment address Addr-align of memory MEM1. For example, assuming the merged second data in register R0 is "D3, D2, V0, D0", then processor 110 can write the merged second data "D3, D2, V0, D0" from register R0 of processor 110 back to the alignment address Addr-align of memory MEM1. Therefore, processor 110 can store one byte of new data V0 (first data at the first access granularity) from processor 110's register R0 to address 0x49 (unaligned address) of memory MEM1, which does not support access in byte-by-byte units, without affecting the original data "D3", "D2", and "D0" at other addresses "0x4b", "0x4a", and "0x48" of memory MEM1. Processor 110 can access memory MEM1 with its unsupported small granularity (first access granularity) and / or perform unaligned address access to memory MEM1.

[0051] During the process of processor 110 loading target data of a first access granularity (e.g., 1 byte) from the target address of memory MEM1 into register R0, processor 110 may perform the following pseudocode. Line B1 of the following pseudocode indicates that processor 110 calculates the alignment address Addr-align corresponding to address Addr in memory MEM1 based on the target address Addr. Line B2 of the following pseudocode indicates that processor 110 loads 4 bytes (second access granularity) of data from the alignment address Addr-align of memory MEM1 into register R1 of processor 110. Line B3 of the following pseudocode indicates that processor 110 calculates the address offset Offset between the target address Addr and the alignment address Addr-align. Line B4 of the following pseudocode indicates that processor 110 calculates the bit offset Shiftbits based on the address offset Offset and the data width of one address (e.g., 8 bits). For example, processor 110 may calculate Shiftbits = Offset << 3 to implement line B4 of the pseudocode. In this context, the address offset is shifted left by 3, which is equivalent to multiplying the address offset by 8 (one address represents 8 bits of data). Line B5 of the following pseudocode indicates that processor 110 shifts the data in register R1 based on the bit offset Shiftbits, and then stores the shifted data back into register R1. For example, processor 110 can calculate R1 = R1 << (24 – R2), and then calculate R1 = R1 >> 24. Since the access granularity is 4 bytes and the target data is 8 bits, the shift amount is 32 - 8 = 24. If the access granularity is 8 bytes and the target data is 8 bits, the shift amount is 64 - 8 = 56.

[0052] B1: Get Addr-align of Addr.MEM1;

[0053] B2: Load data From Addr-align.MEM1 To R1.i32;

[0054] B3: Get Offset between Addr and Addr-align;

[0055] B4: Get Shiftbits Offset*8;

[0056] B5: Shift Shiftbits R1.i32 to R1.i32;

[0057] Figure 5This is a schematic diagram illustrating, according to another embodiment of the present invention, the process by which processor 110 stores multiple destination data U0 and V0 at a first access granularity (e.g., 1 byte) in multiple registers to multiple destination addresses “0x4e” and “0x48” in memory MEM1, respectively. Figure 5 Each small square shown represents one byte. Assuming that the second access granularity supported by memory MEM1 is 4 bytes, addresses 0x0, 0x4, 0x8, ..., 0x48, 0x4c, ... of memory MEM1 are called aligned addresses, while other addresses are called unaligned addresses. Because memory MEM1 does not support unaligned address access, processor 110 cannot directly store new data U0 and V0 from multiple registers into destination addresses "0x4e" and "0x48" of memory MEM1 without affecting the original data "D7", "D5", "D4", "D3", "D2", and "D1" at addresses "0x4f", "0x4d", "0x4c", "0x4b", "0x4a", and "0x49" of memory MEM1. Furthermore, memory MEM1 does not support 8-bit (1-byte) access granularity.

[0058] During the process of processor 110 storing data U0 and V0 of the first access granularity (e.g., 1 byte) from different registers to different target addresses "0x4e" and "0x48" in memory MEM1, processor 110 can perform steps S310 to S380. Processor 110 can obtain the corresponding alignment address based on the destination address "0x4e" and "0x48". Processor 110 can read 8 bytes (second access granularity) of second data "D7, D6, D5, D4, D3, D2, D1, D0" from the alignment address (e.g., address "0x48") in memory MEM1 to processor 110, i.e., step S320. In step S330, processor 110 calculates the address offset between the target address "0x4e" and the alignment address "0x48", and calculates the address offset between the target address "0x48" and the alignment address "0x48", thereby obtaining the bit offset. In step S340, processor 110 can generate a data mask based on the bit offset.

[0059] Based on the destination address "0x4e", the destination address "0x48", and the alignment address "0x48", the processor 110 partially retains the second data "D7, D6, D5, D4, D3, D2, D1, D0" to obtain the retained second data "D7, 0x00, D5, D4, D3, D2, D1, 0x00". In step S350, the processor 110 can partially retain the second data "D7, D6, D5, D4, D3, D2, D1, D0" based on the inverse mask corresponding to the data mask to obtain the retained second data "D7, 0x00, D5, D4, D3, D2, D1, 0x00".

[0060] Given the base address "0x4e", destination address "0x48", and alignment address "0x48", processor 110 shifts the destination data U0 and V0 to obtain shifted first data. In step S360, processor 110 calculates the bit offset based on the address offset and the data width of an address (e.g., 8 bits). For example, the address offset between the destination address "0x4e" and the alignment address "0x48" is 6 bytes, and the address offset between the destination address "0x48" and the alignment address "0x48" is 0 bytes. Processor 110 shifts the destination data U0 by 6 bytes and the destination data V0 by 0 bytes to obtain the shifted first data "0x00, U0, 0x00, 0x00, 0x00, 0x00, 0x00, V0".

[0061] In step S370, processor 110 can merge the shifted first data "0x00, U0, 0x00, 0x00, 0x00, 0x00, V0" and the retained second data "D7, 0x00, D5, D4, D3, D2, D1, 0x00" to obtain merged second data "D7, U0, D5, D4, D3, D2, D1, V0". In step S380, processor 110 can write the merged second data "D7, U0, D5, D4, D3, D2, D1, V0" containing destination data U0 and V0 back to memory MEM1 based on the alignment address "0x48". Therefore, processor 110 can store one byte of destination data U0 and V0 from processor 110 to the target addresses "0x4e" and "0x48" (unaligned addresses) of memory MEM1, which does not support access in units of one byte, without affecting the original data "D7", "D5", "D4", "D3", "D2" and "D1" at other addresses "0x4f", "0x4d", "0x4c", "0x4b", "0x4a" and "0x49" of memory MEM1.

[0062] In summary, based on the aligned address corresponding to the target address, large-granularity (second access granularity, such as 4 bytes, 8 bytes, or other granularities) second data can be read from memory MEM1 to processor 110. Processor 110 can then partially retain the second data to obtain large-granularity retained second data. Furthermore, processor 110 can shift small-granularity (first access granularity, such as 8 bits or other granularities) first data to obtain large-granularity shifted first data. Processor 110 can merge the shifted first data (large-granularity data containing the first data) and the retained second data to obtain large-granularity merged second data. Finally, processor 110 can write the merged second data containing the first data back to memory MEM1. Therefore, processor 110 can access memory MEM1 with its unsupported small-granularity (first access granularity) and / or perform unaligned address access to memory MEM1.

[0063] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A data processing apparatus, characterized by, The data processing device includes: Memory does not support access at a first access granularity but supports access at a second access granularity greater than the first access granularity; and A processor, coupled to the memory, wherein during the process of the processor storing at least one first data of the first access granularity from at least one register of the processor to at least one first target address of the memory, The processor reads second data from the memory based on the first aligned address corresponding to the at least one first target address; The processor shifts the at least one first data based on the at least one first target address and the first alignment address to obtain shifted first data; The processor retains a portion of the second data based on the at least one first target address and the first alignment address to obtain the retained second data. The processor merges the shifted first data and the retained second data to obtain merged second data; and The processor writes the merged second data containing the at least one first data back to the memory based on the first aligned address corresponding to the at least one first target address.

2. The data processing apparatus according to claim 1, characterized in that, During the process of the processor storing at least one first data of the first access granularity from at least one register of the processor to at least one first target address of the memory, The processor calculates the first alignment address corresponding to the at least one first target address based on the at least one first target address; The processor reads the second data at the second access granularity from the first aligned address of the memory; The processor calculates at least one address offset between the at least one first target address and the first alignment address to obtain at least one bit offset; The processor generates at least one data mask based on the at least one bit offset and the second access granularity; The processor shifts the at least one first data based on the at least one bit offset to obtain the shifted first data; as well as The processor retains a portion of the second data based on the inverse mask corresponding to the at least one data mask, to obtain the retained second data.

3. The data processing apparatus according to claim 2, characterized in that, During the process of the processor calculating the first aligned address The processor performs a bitwise AND operation on the at least one first target address based on the alignment mask corresponding to the second access granularity to obtain the first aligned address.

4. The data processing apparatus according to claim 2, characterized by During the process of the processor obtaining the at least one bit offset The processor performs a bitwise AND operation on the at least one first target address based on the address mask corresponding to the second access granularity to obtain the at least one address offset; as well as The processor performs a multiplication operation on the at least one address offset based on the number of bits corresponding to the first access granularity to obtain the at least one bit offset.

5. The data processing apparatus according to claim 2, characterized in that, During the process of the processor generating the at least one data mask, The processor shifts the mask constant corresponding to the first access granularity based on the at least one bit offset to obtain the at least one data mask.

6. The data processing apparatus according to claim 2, characterized in that, During the process of the processor obtaining the first displacement data, The processor shifts the at least one first data based on the at least one bit offset to obtain at least one second granularity data. as well as The processor performs an AND operation on the at least one second granularity data based on the at least one data mask to obtain the shifted first data.

7. The data processing apparatus according to claim 2, characterized in that, During the process of the processor obtaining the retained second data, The processor performs a bitwise AND operation on the second data based on the inverted mask to obtain the retained second data.

8. The data processing apparatus according to claim 1, characterized in that, During the process of the processor obtaining the merged second data, The processor performs an OR operation on the shifted first data and the retained second data to obtain the merged second data.

9. The data processing apparatus according to claim 1, characterized in that, During the process of the processor loading the target data of the first access granularity from the second target address of the memory into the second register The processor calculates the second alignment address in the memory corresponding to the second target address based on the second target address; The processor loads third data at the second access granularity from the second aligned address of the memory into the second register of the processor; The processor calculates the address offset between the second target address and the second aligned address; The processor calculates the bit offset based on the address offset and the address data width; as well as The processor shifts the data in the second register based on the bit offset.

10. The data processing apparatus according to claim 1, characterized in that, The at least one first data includes first destination data and second destination data; the at least one register includes a first register and a second register; the at least one first destination address includes a first destination address and a second destination address; and during the process of the processor storing the at least one first data of the first access granularity from the at least one register of the processor to the at least one first destination address of the memory, The processor reads the second data from the memory based on the first aligned address corresponding to the first destination address and the second destination address; The processor shifts the first destination data and the second destination data based on the first destination address, the second destination address, and the first alignment address to obtain the shifted first data. as well as The processor retains a portion of the second data based on the first destination address, the second destination address, and the first alignment address to obtain the retained second data.

11. A method for operating a data processing device, characterized in that, The data processing device includes a memory and a processor. The memory does not support access at a first access granularity but supports access at a second access granularity greater than the first access granularity. The operation method includes: Storing at least one piece of first data at the first access granularity from at least one register of the processor to at least one first target address of the memory that does not support access at the first access granularity, wherein the process of storing the at least one piece of first data from the at least one register to the at least one first target address of the memory includes: The second data is read from the memory based on the first alignment address corresponding to the at least one first target address; The at least one first data is shifted based on the at least one first target address and the first alignment address to obtain shifted first data; Based on the at least one first target address and the first alignment address, the second data is partially retained to obtain the retained second data; Merging the first displacement data and the second retention data to obtain the merged second data; and Based on the first alignment address corresponding to the at least one first target address, the merged second data containing the at least one first data is written back to the memory.

12. The operating method according to claim 11, characterized in that, The process of storing at least one first data of the first access granularity from the at least one register to the at least one first target address of the memory further includes: Calculate the first alignment address corresponding to the at least one first target address based on the at least one first target address; Read the second data at the second access granularity from the first aligned address of the memory; Calculate at least one address offset between the at least one first target address and the first alignment address to obtain at least one bit offset; At least one data mask is generated based on the at least one bit offset and the second access granularity; The at least one first data is shifted based on the at least one bit offset to obtain the shifted first data; and The second data is partially retained based on the inverse mask corresponding to the at least one data mask to obtain the retained second data.

13. The operating method according to claim 12, characterized in that, The process of calculating the first aligned address includes: The first aligned address is obtained by performing a bitwise AND operation on the at least one first target address based on the alignment mask corresponding to the second access granularity.

14. The operating method according to claim 12, characterized in that, The process of obtaining the at least one bit offset includes: A bitwise AND operation is performed on the at least one first target address based on the address mask corresponding to the second access granularity to obtain the at least one address offset; and The at least one address offset is multiplied based on the number of bits corresponding to the first access granularity to obtain the at least one bit offset.

15. The operating method according to claim 12, characterized in that, The process of generating the at least one data mask includes: The mask constant corresponding to the first access granularity is shifted based on the at least one bit offset to obtain the at least one data mask.

16. The operating method according to claim 12, characterized in that, The process of obtaining the first displacement data includes: The at least one first data is shifted based on the at least one bit offset to obtain at least one second granularity data; and Based on the at least one data mask, perform an AND operation on the at least one second granularity data to obtain the displacement first data.

17. The operating method according to claim 12, characterized in that, The process of obtaining the retained second data includes: The second data is ANDed with the inverse mask to obtain the retained second data.

18. The operating method according to claim 11, characterized in that, The process of obtaining the merged second data includes: The first data after displacement and the second data after retention are ORed to obtain the second data after merging.

19. The operating method according to claim 11, characterized in that, The operation method further includes: Loading target data of the first access granularity from the second target address of the memory into the second register, wherein the process of loading the target data of the first access granularity from the second target address of the memory into the second register includes: The second alignment address corresponding to the second target address in the memory is calculated based on the second target address; Third data at the second access granularity is loaded from the second aligned address of the memory into the second register of the processor; Calculate the address offset between the second target address and the second alignment address; Calculate the bit offset based on the address offset and the address data width; and The data in the second register is shifted based on the bit offset.

20. The operating method according to claim 11, characterized in that, The at least one first data includes first destination data and second destination data, the at least one register includes a first register and a second register, the at least one first destination address includes a first destination address and a second destination address, and the process of the processor storing the at least one first data of the first access granularity from the at least one register of the processor to the at least one first destination address of the memory further includes: The second data is read from the memory based on the first alignment address corresponding to the first destination address and the second destination address; Based on the first destination address, the second destination address, and the first alignment address, the first destination data and the second destination data are shifted to obtain the shifted first data; and The second data is partially retained based on the first destination address, the second destination address, and the first alignment address to obtain the retained second data.

21. A machine-readable storage medium for storing non-transitory machine-readable instructions that, when executed by a computer, can implement the operation method of the data processing apparatus according to any one of claims 11-20.

Citation Information

Patent Citations

  • Data integrity checking method and system and related equipment

    CN110955545A

  • Data processing circuit, system and method

    CN114217858A