This time I am going to cover the memory access. Because a lot of DSP algorithms are quite heavy on memory access, so the handling of the memory access has a big impact on the performance. As a result, the memory access model on SHARC is not as simple as usually found on RISC processors. Note: modern RISC processors have much more sophisticated memory systems than SHARC+, but they are usually hidden away from the programmer.
Basic Address Calculation
In SHARC, memory addresses are calculated by the DAG (Data Address Generator). When accessing memory, DAG uses 2 registers to calculate the address, one index (I) register, and one modify (M) register. The address is always index + modify. For example, if I want to access memory address 0xc0000000, I could load 0xc0000000 into the index register, then use constant 0 for the modify. The code would be as follows:
i4 = 0xc0000000; m4 = 0; r4 = dm(m4, i4);
DM refers to data memory, SHARC uses the syntax dm(modify reg, index reg) to access memory. To store into that address, just put dm on the LHS:
dm(m4, i4) = r4;
In SHARC, some modify registers always hold certain constant values: m5 is 0, m6 is 1, and m7 is -1. So the code could also be:
dm(m5, i4) = r4;
Immediate value as modify is also allowed. The width is limited to the different instruction encoding, which could be 6bit, 24bit, or 32bit. The index must come from a register.
dm(0, i4) = r4;
Say if I have two consecutive 32-bit values in the memory (for example, a complex number, or a 2D coordination) in the memory, pointed by i4, and now I want to load the first value (real part) into r4 and the second value (complex part) into r8, one way to achieve this is:
r4 = dm(m5, i4); r8 = dm(m6, i4);
The first is modified by 0, and the second one is modified by 1. The modify value is counted in words, so 4 bytes by default.
I said one way, as there is another way. In the previous example, the modify is applied to the index then used for accessing the memory. This is called pre-index mode. There is also a post-index mode, where the index value is used for accessing the memory, then the modify is added to the index, and write back to the index register. In the pre-index mode, the indexing register is not updated, but in post-index mode, the indexing register is updated with the new address. So the previous code could be written as follows as well:
r4 = dm(i4, m6); r8 = dm(i4, m6);
The pre-indexing mode is usually useful in accessing fields in a struct, while the post indexing mode is usually useful in accessing elements in an array within a loop.