Skip to content

Adding correct vlmul shifts for all vpu modes#215

Merged
xalbertoisorna merged 2 commits intoxmos:developfrom
xalbertoisorna:fix/vpu-sim
Apr 16, 2026
Merged

Adding correct vlmul shifts for all vpu modes#215
xalbertoisorna merged 2 commits intoxmos:developfrom
xalbertoisorna:fix/vpu-sim

Conversation

@xalbertoisorna
Copy link
Copy Markdown
Contributor

@xalbertoisorna xalbertoisorna commented Dec 17, 2025

Adds the correct right shift for vlmul in vpu_sim.c in different vpu modes for vx4a other than s16 (s8, s32).

It could be implemented directly with macros, but since it will end up as an if statement at the architecture level anyway, it feels more natural to use a switch and compute each case explicitly.

I’m happy to replace the function with macros or an alternative approach if preferred; my main goal here is to ensure correct VPU rounding and saturation for all modes so I have a vpu sim to test against.

@xalbertoisorna
Copy link
Copy Markdown
Contributor Author

Comment thread lib_nn/src/c/vpu_sim.c Outdated
Comment thread lib_nn/src/c/vpu_sim.c Outdated
Comment thread lib_nn/src/c/vpu_sim.c
if (NN_ARCH == TARGET_ARCH_VX4A){
res = res >> 1;
}
int32_t res = ((int32_t)vpu->vR.s8[i] * (int32_t)val + (1L<<(shift - 1))) >> shift;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as this pattern (X + (1<<Y))>>Y comes up a lot for the rounding it might be a good idea to make it a macro if it's not already

@xalbertoisorna
Copy link
Copy Markdown
Contributor Author

@uvvpavel fyi, will be integrated in next release

@xalbertoisorna xalbertoisorna merged commit 9e8bc1d into xmos:develop Apr 16, 2026
1 check passed
@xalbertoisorna xalbertoisorna deleted the fix/vpu-sim branch April 16, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants