r/computerscience • • Feb 14 '26

Annotate instruction level parallelism at compile time

I'm building a research stack (Virtual ISA + OS + VM + compiler + language, most of which has been shamelessly copied from WASM) and I'm trying to find a way to annotate ILP in the assembly at compile time.

Let's say we have some assembly that roughly translates to:

1. a=d+e
2. b=f+g
3. c=a+b

And let's ignore for the sake of simplicity that a smart compiler could merge these operations.

How can I annotate the assembly so that the CPU knows that instruction 1 and 2 can be executed in a parallel fashion, while instruction 3 needs to wait for 1 and 2?

Today superscalar CPUs have hardware dedicated to find instruction dependency, but I can't count on that. I would also prefer to avoid VLIW-like approaches as they are very inefficient.

My current approach is to have a 4 bit prefix before each instruction to store this information:

  • 0 means that the instruction can never be executed in a parallel fashion
  • a number different than 0 is shared by instructions that are dependent on each other, so instruction with different prefixes can be executed at the same time

But maybe there's a smarter way? What do you think?

3 Upvotes

10 comments sorted by

View all comments

Show parent comment

4

u/Plastic_Fig9225 Feb 14 '26

Say your CPU's ALU has N integer dividers. Division tends to take much longer than most other instructions. You can quickly feed N parallel division instructions into the ALU, but division N+1 must then wait until a previous division is completed and a divider becomes available.

1

u/servermeta_net Feb 14 '26

Ok, I already take account of this. I was afraid instructions might have a variable latency, e.g.: integer division or some other exotic instruction could take 3 or 4 cycles, depending on other execution units being full, because of sharing of some hardware logic.