Skip to content

Conversation

@marchioa
Copy link
Contributor

pulp_zero_mem zeros a memory region with the following loop:

  for (int i=0; i<(size>>2); i++) {
    *((v4u *)pBuffer) = (v4u){0,0,0,0};
    MemoryFence();
    pBuffer+=4;
  }

This code may be translated into assembly similar to

lp.setup  0x0, a1, 0x4
p.sw  a3, 4(a0!)

On cores with more than one pipeline stage, this sequence can result in an illegal hardware loop configuration. In particular, one of the hardware loop constraints
requires the loop body to contain more than one instruction. Additionally, hardware loops do not allow memory ordering instructions (fence, fence.i) in the loop body.

The presence of MemoryFence() appears to prevent the compiler from correctly deriving the hardware loop properties, potentially leading to an invalid loop configuration. While this issue does not manifest in GVSoC simulation, it may cause unexpected behavior in RTL simulations.

A potential solution is to remove the MemoryFence() from the loop. Doing so allows the compiler to correctly generate a valid hardware loop, typically inserting a nop before the store instruction and thus avoiding the illegal configuration.

This PR removes the MemoryFence() from the main loop in pulp_zero_mem to prevent the generation of illegal hardware loops.

@yvantor yvantor requested review from ABurrello and Xeratec December 15, 2025 08:12
@yvantor yvantor assigned yvantor and marchioa and unassigned yvantor Dec 15, 2025
@ABurrello ABurrello merged commit faed38c into pulp-platform:main Dec 15, 2025
Xeratec pushed a commit to pulp-platform/Deeploy that referenced this pull request Jan 6, 2026
This PR updates the `pulp-nn-mixed` submodule to include the fix for an illegal hardware loop configuration related to the `pulp_zero_mem` utility function [PR10](pulp-platform/pulp-nn-mixed#10). The updated submodule removes the MemoryFence() from the loop, allowing the compiler to correctly generate a valid HW loop and preventing illegal configurations.

## Changed
- `pulp-nn-mixed` submodule
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.

3 participants