DSP Processors We have seen that the Multiply

  • Slides: 9
Download presentation
DSP Processors We have seen that the Multiply and Accumulate (MAC) operation is very

DSP Processors We have seen that the Multiply and Accumulate (MAC) operation is very prevalent in DSP computation n computation of energy n MA filters n AR filters n correlation of two signals x DSP n FFT A Digital Signal Processor (DSP) is a CPU that can compute each MAC tap in 1 clock cycle Thus the entire L coefficient MAC takes (about) L clock cycles For in real-time the time between input of 2 x values must be more than L clock cycles y XTAL t ALU with ADD, MULT, etc bus memory registers PC a b c d 1

the basic MAC loop is MACs loop over all times n initialize yn 0

the basic MAC loop is MACs loop over all times n initialize yn 0 loop over i from 1 to number of coefficients yn + ai * xj (j related to i) output yn in order to implement in low-level programming n for real-time we need to update the static buffer – from now on, we'll assume that x values in pre-prepared vector n for efficiency we don't use array indexing, rather pointers n we must explicitly increment the pointers n we must place values into registers in order to do arithmetic loop over all times n clear y register set number of iterations to n loop update a pointer update x pointer multiply z a * x (indirect addressing) increment y y + z (register operations) output y 2

Cycle counting We still can’t count cycles n need to take fetch and decode

Cycle counting We still can’t count cycles n need to take fetch and decode into account n need to take loading and storing of registers into account n we need to know number of cycles for each arithmetic operation – let's assume each takes 1 cycle (multiplication typically takes more) n assume zero-overhead loop (clears y register, sets loop counter, etc. ) Then the operations inside the outer loop look something like this: 1. Update pointer to ai 2. Update pointer to xj 3. Load contents of ai into register a 4. Load contents of xj into register x 5. Fetch operation (MULT) 6. Decode operation (MULT) 7. MULT a*x with result in register z 8. Fetch operation (INC) 9. Decode operation (INC) 10. INC register y by contents of register z So it takes at least 10 cycles to perform each MAC using a regular CPU 3

Step 1 - new opcode To build a DSP we need to enhance the

Step 1 - new opcode To build a DSP we need to enhance the basic CPU with new hardware (silicon) The easiest step is to define a new opcode called MAC Note that the result needs a special register Example: if registers are 16 bit product needs 32 bits And when summing many need 40 bits ALU with ADD, MULT, MAC, etc The code now looks like this: PC 1. 2. 3. 4. 5. 6. 7. bus p-registers accumulator pa memory px registers Update pointer to ai y a x Update pointer to xj Load contents of ai into register a Load contents of xj into register x Fetch operation (MAC) Decode operation (MAC) MAC a*x with incremented to accumulator y However 7 > 1, so this is still NOT a DSP ! 4

Step 2 - register arithmetic The two operations Update pointer to ai n Update

Step 2 - register arithmetic The two operations Update pointer to ai n Update pointer to xj could be performed in parallel but both performed by the ALU n So we add pointer arithmetic units one for each register Special sign || used in assembler to mean operations in parallel ALU with ADD, MULT, MAC, etc bus p-registers PC pa px INC/DEC accumulator registers y a x 2. 3. 4. 5. 6. Update pointer to ai || Update pointer to xj Load contents of ai into register a Load contents of xj into register x Fetch operation (MAC) Decode operation (MAC) MAC a*x with incremented to accumulator y 7. However 6 > 1, so this is still NOT a DSP ! 1. memory 5

Step 3 - memory banks and buses We would like to perform the loads

Step 3 - memory banks and buses We would like to perform the loads in parallel but we can't since they both have to go over the same bus So we add another bus ALU with ADD, MULT, and we need to define memory banks MAC, etc bus so that no contention ! p-registers bank 1 There is dual-port memory but it has an arbitrator which adds delay bank 2 PC pa px bus INC/DEC accumulator registers y a x Update pointer to ai || Update pointer to xj Load ai into a || Load xj into x Fetch operation (MAC) Decode operation (MAC) MAC a*x with incremented to accumulator y However 5 > 1, so this is still NOT a DSP ! 1. 2. 3. 4. 5. 6

Step 4 - Harvard architecture Van Neumann architecture n n Harvard architecture (predates VN)

Step 4 - Harvard architecture Van Neumann architecture n n Harvard architecture (predates VN) n n one memory for program one memory (or more) for data needn't count fetch since in parallel we can remove decode as well (see later) bus ALU with ADD, MULT, MAC, etc one memory for data and program can change program during run-time p-registers PC pa px data 1 bus data 2 INC/DEC accumulator registers y a bus program x 1. 2. 3. Update pointer to ai || Update pointer to xj Load ai into a || Load xj into x MAC a*x with incremented to accumulator y 4. However 3 > 1, so this is still NOT a DSP ! 7

Step 5 - pipelines We seem to be stuck n Update MUST be before

Step 5 - pipelines We seem to be stuck n Update MUST be before Load n Load MUST be before MAC But we can use a pipelined approach Then, on average, it takes 1 tick per tap actually, if pipeline depth is D, N taps take N+D-1 ticks For large N >> D or when we fill the pipeline the number of ticks per tap is 1 (this is a DSP) op U 1 1 U 2 U 3 U 4 U 5 L 1 L 2 L 3 L 4 L 5 M 1 M 2 M 3 M 4 2 3 4 5 6 M 5 7 t 8

Fixed point Most DSPs are fixed point, i. e. handle integer (2 s complement)

Fixed point Most DSPs are fixed point, i. e. handle integer (2 s complement) numbers only n floating point is more expensive and slower n floating point numbers can underflow n fixed point numbers can overflow Accumulators have guard bits to protect against overflow When regular fixed point CPUs overflow n numbers greater than MAXINT become negative n numbers smaller than -MAXINT become positive Most fixed point DSPs have a saturation arithmetic mode n numbers larger than MAXINT become MAXINT n numbers smaller than -MAXINT become -MAXINT this is still an error, but a smaller error There is a tradeoff between safety from overflow and SNR 9