Accumulator-Based Math¶
Description¶
40-bit accumulator supporting multiplication, addition and shift
This resource allows for multiplication and 32-bit arithmetic, which are not inherently supported by the Sensor Controller’s instruction set. This functionality is not integrated into the task code programming language, by use of special operators and variable types. Instead the functionality must be accessed through procedure calls, in the same way as for other task resources.
The accumulator register is divided into three parts:
Extension [39:32] | High part [31:16] | Low part [15:0] |
The following multiplication, addition and shift operations are supported:
- 16 x 16 signed and unsigned multiply
- 16 x 16 signed and unsigned multiply and accumulate
- 16-bit add with and without sign extension
- 32-bit add with and without sign extension
- 1-bit logical and arithmetic left and right shift
- Count leading sign or zero bits
The accumulator can be written as follows:
- Reset to 0
- 16-bit write with and without sign extension
- 32-bit write with and without sign extension
- Write the entire accumulator
- Write the accumulator extension
The accumulator can be read as follows:
- 16-bit read from any bit position between 0 and 24
- 32-bit read from any bit position between 0 and 8
- Read the entire accumulator
- Read the accumulator extension
Examples¶
Multiplication¶
// Multiply unsigned variables x and y
accMul16u16u(x, y);
// Store bits [19:4] of the result in variable z
accGet16(4; z);
Procedures Overview¶
Name | Brief description |
accAdd16s() |
Adds a 16-bit value to the accumulator with sign-extension. More … |
accAdd16u() |
Adds a 16-bit value to the accumulator with zero-extension. More … |
accAdd32s() |
Adds a 32-bit value to the accumulator with sign-extension. More … |
accAdd32u() |
Adds a 32-bit value to the accumulator with zero-extension. More … |
accCountLeadingSignBits() |
Returns the number of leading sign bits in the accumulator. More … |
accCountLeadingZeroBits() |
Returns the number of leading zero bits in the accumulator. More … |
accGet16() |
Returns 16 consecutive bits from the accumulator. More … |
accGet32() |
Returns 32 consecutive bits from the accumulator. More … |
accGetAll() |
Returns all bits of the accumulator. More … |
accGetExt() |
Returns the extension bits of the accumulator. More … |
accMac16s16s() |
Multiplies factors A (signed) and B (signed), and adds the product (signed) to the accumulator. More … |
accMac16s16u() |
Multiplies factors A (signed) and B (unsigned), and adds the product (signed) to the accumulator. More … |
accMac16u16s() |
Multiplies factors A (unsigned) and B (signed), and adds the product (signed) to the accumulator. More … |
accMac16u16u() |
Multiplies factors A (unsigned) and B (unsigned), and adds the product (unsigned) to the accumulator. More … |
accMul16s16s() |
Multiplies factors A (signed) and B (signed), and stores the product (signed) in the accumulator. More … |
accMul16s16u() |
Multiplies factors A (signed) and B (unsigned), and stores the product (signed) in the accumulator. More … |
accMul16u16s() |
Multiplies factors A (unsigned) and B (signed), and stores the product (signed) in the accumulator. More … |
accMul16u16u() |
Multiplies factors A (unsigned) and B (unsigned), and stores the product (unsigned) in the accumulator. More … |
accReset() |
Resets the accumulator to 0. More … |
accSet16s() |
Loads a 16-bit value into the accumulator with sign-extension. More … |
accSet16u() |
Loads a 16-bit value into the accumulator with zero-extension. More … |
accSet32s() |
Loads a 32-bit value into the accumulator with sign-extension. More … |
accSet32u() |
Loads a 32-bit value into the accumulator with zero-extension. More … |
accSetAll() |
Sets all bits in the accumulator. More … |
accSetExt() |
Loads an 8-bit value into the accumulator extension part. More … |
accShiftLeft() |
Shifts the accumulator the specified number of bits to the left. More … |
accShiftRightArith() |
Shifts the accumulator arithmetically (with sign-extension) the specified number of bits to the right. More … |
accShiftRightLogic() |
Shifts the accumulator logically (with zero-extension) the specified number of bits to the right. More … |
Constants¶
None.
Global Variables¶
None.
Procedures¶
accAdd16s¶
Prototype: accAdd16s(value)
Adds a 16-bit value to the accumulator with sign-extension.
Parameter value(s)¶
- value : Added value
accAdd16u¶
Prototype: accAdd16u(value)
Adds a 16-bit value to the accumulator with zero-extension.
Parameter value(s)¶
- value : Added value
accAdd32s¶
Prototype: accAdd32s(valueH, valueL)
Adds a 32-bit value to the accumulator with sign-extension.
Parameter value(s)¶
- valueH : Added value, bits [32 : 16]
- valueL : Added value, bits [15 : 0]
accAdd32u¶
Prototype: accAdd32u(valueH, valueL)
Adds a 32-bit value to the accumulator with zero-extension.
Parameter value(s)¶
- valueH : Added value, bits [32 : 16]
- valueL : Added value, bits [15 : 0]
accCountLeadingSignBits¶
Prototype: accCountLeadingSignBits(value)
Returns the number of leading sign bits in the accumulator.
Return value(s)¶
- value : Number of leading sign bits (1 to 40)
accCountLeadingZeroBits¶
Prototype: accCountLeadingZeroBits(value)
Returns the number of leading zero bits in the accumulator.
Return value(s)¶
- value : Number of leading zero bits (0 to 40)
accGet16¶
Prototype: accGet16(accIndex; value)
Returns 16 consecutive bits from the accumulator.
Note: This procedure is more efficient if the accIndex parameter is specifed as a constant (rather than a variable).
Parameter value(s)¶
- accIndex : Accumulator bit index corresponding to lsb in the returned value (0-24)
Return value(s)¶
- value : Accumulator value, bits [accIndex + 15 : accIndex + 0]
accGet32¶
Prototype: accGet32(accIndex; valueH, valueL)
Returns 32 consecutive bits from the accumulator.
Note: This procedure is more efficient if the accIndex parameter is specifed as a constant (rather than a variable).
Parameter value(s)¶
- accIndex : Accumulator bit index corresponding to lsb in the returned value (0-8)
Return value(s)¶
- valueH : Accumulator value, bits [accIndex + 31 : accIndex + 16]
- valueL : Accumulator value, bits [accIndex + 15 : accIndex + 0]
accGetAll¶
Prototype: accGetAll(valueExt, valueH, valueL)
Returns all bits of the accumulator.
Return value(s)¶
- valueExt : Accumulator extension value, bits [39 : 32]
- valueH : Accumulator high word value, bits [31 : 16]
- valueL : Accumulator low word value, bits [15 : 0]
accGetExt¶
Prototype: accGetExt(value)
Returns the extension bits of the accumulator.
Return value(s)¶
- value : Accumulator extension value, bits [39 : 32]
accMac16s16s¶
Prototype: accMac16s16s(a, b)
Multiplies factors A (signed) and B (signed), and adds the product (signed) to the accumulator.
Parameter value(s)¶
- a : Factor A (signed, -32768 to 32767)
- b : Factor B (signed, -32768 to 32767)
accMac16s16u¶
Prototype: accMac16s16u(a, b)
Multiplies factors A (signed) and B (unsigned), and adds the product (signed) to the accumulator.
Parameter value(s)¶
- a : Factor A (signed, -32768 to 32767)
- b : Factor B (unsigned, 0 to 65535)
accMac16u16s¶
Prototype: accMac16u16s(a, b)
Multiplies factors A (unsigned) and B (signed), and adds the product (signed) to the accumulator.
Parameter value(s)¶
- a : Factor A (unsigned, 0 to 65535)
- b : Factor B (signed, -32768 to 32767)
accMac16u16u¶
Prototype: accMac16u16u(a, b)
Multiplies factors A (unsigned) and B (unsigned), and adds the product (unsigned) to the accumulator.
Parameter value(s)¶
- a : Factor A (unsigned, 0 to 65535)
- b : Factor B (unsigned, 0 to 65535)
accMul16s16s¶
Prototype: accMul16s16s(a, b)
Multiplies factors A (signed) and B (signed), and stores the product (signed) in the accumulator.
Parameter value(s)¶
- a : Factor A (signed, -32768 to 32767)
- b : Factor B (signed, -32768 to 32767)
accMul16s16u¶
Prototype: accMul16s16u(a, b)
Multiplies factors A (signed) and B (unsigned), and stores the product (signed) in the accumulator.
Parameter value(s)¶
- a : Factor A (signed, -32768 to 32767)
- b : Factor B (unsigned, 0 to 65535)
accMul16u16s¶
Prototype: accMul16u16s(a, b)
Multiplies factors A (unsigned) and B (signed), and stores the product (signed) in the accumulator.
Parameter value(s)¶
- a : Factor A (unsigned, 0 to 65535)
- b : Factor B (signed, -32768 to 32767)
accMul16u16u¶
Prototype: accMul16u16u(a, b)
Multiplies factors A (unsigned) and B (unsigned), and stores the product (unsigned) in the accumulator.
Parameter value(s)¶
- a : Factor A (unsigned, 0 to 65535)
- b : Factor B (unsigned, 0 to 65535)
accSet16s¶
Prototype: accSet16s(value)
Loads a 16-bit value into the accumulator with sign-extension.
Parameter value(s)¶
- value : Value
accSet16u¶
Prototype: accSet16u(value)
Loads a 16-bit value into the accumulator with zero-extension.
Parameter value(s)¶
- value : Value
accSet32s¶
Prototype: accSet32s(valueH, valueL)
Loads a 32-bit value into the accumulator with sign-extension.
Parameter value(s)¶
- valueH : Value, bits [23 : 16]
- valueL : Value, bits [15 : 0]
accSet32u¶
Prototype: accSet32u(valueH, valueL)
Loads a 32-bit value into the accumulator with zero-extension.
Parameter value(s)¶
- valueH : Value, bits [23 : 16]
- valueL : Value, bits [15 : 0]
accSetAll¶
Prototype: accSetAll(valueExt, valueH, valueL)
Sets all bits in the accumulator.
Parameter value(s)¶
- valueExt : Accumulator extension value, bits [39 : 32]
- valueH : Accumulator high word value, bits [31 : 16]
- valueL : Accumulator low word value, bits [15 : 0]
accSetExt¶
Prototype: accSetExt(value)
Loads an 8-bit value into the accumulator extension part.
Parameter value(s)¶
- value : Value, bits [39 : 32]
accShiftLeft¶
Prototype: accShiftLeft(shiftCount)
Shifts the accumulator the specified number of bits to the left.
Parameter value(s)¶
- shiftCount : Shift count