File acc_q8_core.h¶
FileList > acc_q8 > acc_q8_core.h
Go to the source code of this file
AccQ8 — a running 32-bit integer accumulator for Q8 (int8_t) samples. Internally sums each sample into a 32-bit accumulator, which can hold up to 2^24 maximum-magnitude Q8 samples before overflow. Use get() for a non-destructive read, or dump() to read-and-reset in one atomic call. More...
#include "clib_common.h"#include "jm_perf.h"#include "dp_state.h"
Classes¶
| Type | Name |
|---|---|
| struct | acc_q8_state_t AccQ8 state. |
Public Functions¶
| Type | Name |
|---|---|
| acc_q8_state_t * | acc_q8_create (int32_t acc) Allocate and initialise an AccQ8 accumulator. The accumulator starts at the supplied initial value and accepts Q8 (int8_t) samples via step(), steps(), or madd(). The 32-bit internal register handles up to roughly 16 million max-magnitude samples before wrap — sufficient for all standard DSP block sizes. |
| void | acc_q8_destroy (acc_q8_state_t * state) Destroy an AccQ8 instance and release all memory. Safe to call with NULL. |
| int32_t | acc_q8_dump (acc_q8_state_t * state) Return the accumulated value and atomically reset it to zero. Avoids the need for a separate reset() call when processing a stream of non-overlapping blocks. |
| int32_t | acc_q8_get (acc_q8_state_t * state) Return the current accumulated value without resetting it. Mirrors get_acc() but exposed under the name used consistently across all Acc-family objects in the Python API. |
| int32_t | acc_q8_get_acc (const acc_q8_state_t * state) Read the current accumulator value without modifying it. Permits repeated snapshots of the running sum mid-stream. |
| void | acc_q8_get_state (const acc_q8_state_t * state, void * blob) |
| void | acc_q8_madd (acc_q8_state_t * state, const int8_t * a, size_t a_len, const int8_t * b, size_t b_len) Multiply-accumulate over the shorter of the two arrays. Computes acc += sum( a[i] *b[i] ), widening int8_t inputs to int32_t before accumulation to prevent intermediate overflow. |
| void | acc_q8_reset (acc_q8_state_t * state) Reset the accumulator to zero, mirroring the post-create state. Always resets to zero regardless of the original constructor value, so it is safe to call at the start of any new accumulation window. |
| void | acc_q8_set_acc (acc_q8_state_t * state, int32_t val) Overwrite the accumulator with a new value. Useful for applying a bias before a new accumulation window, or for restoring a checkpointed accumulator state. |
| int | acc_q8_set_state (acc_q8_state_t * state, const void * blob) |
| size_t | acc_q8_state_bytes (const acc_q8_state_t * state) |
| JM_FORCEINLINE JM_HOT void | acc_q8_step (acc_q8_state_t * state, int8_t x) Accumulate one Q8 sample into the running total. The sample is sign-extended to 32 bits before addition so negative samples correctly subtract from the accumulator. |
| void | acc_q8_steps (acc_q8_state_t * state, const int8_t * input, size_t n) Accumulate a contiguous block of Q8 samples. Equivalent to calling step() n times; the single loop is more amenable to auto-vectorisation than repeated method calls. |
Macros¶
| Type | Name |
|---|---|
| define | ACC_Q8_STATE_MAGIC [**DP\_FOURCC**](dp__state_8h.md#define-dp_fourcc) ('A', 'C', 'C', '8') |
| define | ACC_Q8_STATE_VERSION 1u |
Detailed Description¶
Lifecycle: create -> [step / steps / madd / reset]* -> [get / dump]* -> destroy
Public Functions Documentation¶
function acc_q8_create¶
Allocate and initialise an AccQ8 accumulator. The accumulator starts at the supplied initial value and accepts Q8 (int8_t) samples via step(), steps(), or madd(). The 32-bit internal register handles up to roughly 16 million max-magnitude samples before wrap — sufficient for all standard DSP block sizes.
Parameters:
accInitial accumulator value (default: 0).
Returns:
Heap-allocated state, or NULL on allocation failure.
Note:
Caller must call acc_q8_destroy() when done.
function acc_q8_destroy¶
Destroy an AccQ8 instance and release all memory. Safe to call with NULL.
Parameters:
stateMay be NULL.
function acc_q8_dump¶
Return the accumulated value and atomically reset it to zero. Avoids the need for a separate reset() call when processing a stream of non-overlapping blocks.
Parameters:
stateMust be non-NULL.
Returns:
Accumulator value before the reset (int32_t).
>>> from doppler.arith import AccQ8
>>> import numpy as np
>>> obj = AccQ8(0)
>>> obj.steps(np.array([1, 2, 3, 4, 5], dtype=np.int8))
>>> obj.dump()
15
>>> obj.get()
0
function acc_q8_get¶
Return the current accumulated value without resetting it. Mirrors get_acc() but exposed under the name used consistently across all Acc-family objects in the Python API.
Parameters:
stateMust be non-NULL.
Returns:
Current accumulator value (int32_t).
>>> from doppler.arith import AccQ8
>>> import numpy as np
>>> obj = AccQ8(0)
>>> obj.steps(np.array([10, 20, 30], dtype=np.int8))
>>> obj.get()
60
function acc_q8_get_acc¶
Read the current accumulator value without modifying it. Permits repeated snapshots of the running sum mid-stream.
Parameters:
stateMust be non-NULL.
function acc_q8_get_state¶
function acc_q8_madd¶
Multiply-accumulate over the shorter of the two arrays. Computes acc += sum( a[i] *b[i] ), widening int8_t inputs to int32_t before accumulation to prevent intermediate overflow.
void acc_q8_madd (
acc_q8_state_t * state,
const int8_t * a,
size_t a_len,
const int8_t * b,
size_t b_len
)
Parameters:
stateMust be non-NULL.aFirst input array (int8_t).a_lenNumber of elements in a.bSecond input array (int8_t), same length as a.b_lenNumber of elements in b.
>>> from doppler.arith import AccQ8
>>> import numpy as np
>>> obj = AccQ8(0)
>>> a = np.array([10, 20, 30], dtype=np.int8)
>>> b = np.array([1, 2, 3], dtype=np.int8)
>>> obj.madd(a, b)
>>> obj.get()
140
function acc_q8_reset¶
Reset the accumulator to zero, mirroring the post-create state. Always resets to zero regardless of the original constructor value, so it is safe to call at the start of any new accumulation window.
Parameters:
stateMust be non-NULL.
>>> from doppler.arith import AccQ8
>>> obj = AccQ8(0)
>>> obj.step(42)
>>> obj.reset()
>>> obj.get()
0
function acc_q8_set_acc¶
Overwrite the accumulator with a new value. Useful for applying a bias before a new accumulation window, or for restoring a checkpointed accumulator state.
Parameters:
stateMust be non-NULL.valReplacement accumulator value.
function acc_q8_set_state¶
function acc_q8_state_bytes¶
function acc_q8_step¶
Accumulate one Q8 sample into the running total. The sample is sign-extended to 32 bits before addition so negative samples correctly subtract from the accumulator.
Parameters:
stateMust be non-NULL.xQ8 input sample (int8_t, range[-128, 127]).
>>> from doppler.arith import AccQ8
>>> obj = AccQ8(0)
>>> obj.step(10)
>>> obj.step(20)
>>> obj.get()
30
function acc_q8_steps¶
Accumulate a contiguous block of Q8 samples. Equivalent to calling step() n times; the single loop is more amenable to auto-vectorisation than repeated method calls.
Parameters:
stateMust be non-NULL.inputInput array of int8_t samples.nNumber of samples in input.
>>> from doppler.arith import AccQ8
>>> import numpy as np
>>> obj = AccQ8(0)
>>> obj.steps(np.array([1, 2, 3, 4, 5], dtype=np.int8))
>>> obj.get()
15
Macro Definition Documentation¶
define ACC_Q8_STATE_MAGIC¶
define ACC_Q8_STATE_VERSION¶
The documentation for this class was generated from the following file native/inc/acc_q8/acc_q8_core.h