SPRUIG3C January 2018 – August 2019 TDA4VM , TDA4VM-Q1
The general form of a lookup table operation in VCOP Kernel-C is:
Vdst = base[Agen].lookup(Vindex);
The Agen is added to the base address of the table before adding the index offsets. In typical usage, the Agen remains fixed at zero, and no adjustment is needed. However some kernels may use non-zero or varying Agens as an additional addend to vary the table base dynamically. To account for this, the migration tool adds the offset from the Agen to each lane of the index vector prior to indexing the table. The adjustment calculation is:
Sadj = ((Agen / Ntables) / Elemsz); // scale bytes -> table index
Vindex_adj = Vindex + Sadj; // add to each lane vector
The division by
Ntables
accounts for the fact that when there are multiple parallel tables, the Agen represents an offset into the combined table data, not an offset into each table. The division by
Elemsz
accounts for the fact that the Agen is a byte offset, while the index values are element offsets. Both are compile-time constants so the two divisions typically simplify to a single shift instruction. Furthermore, if the Agen does not vary inside the loop, the computation of
Sadj
can be hoisted outside the loop.
In summary, if the Agen used in a LHT operation varies inside the loop, two additional instructions are required in the loop (shift and add).