0xPolygonMiden / miden-vm

STARK-based virtual machine
MIT License
612 stars 150 forks source link

MASM arithmetic instructions should accept constants #1299

Open hackaugusto opened 3 months ago

hackaugusto commented 3 months ago

The following code snippet doesn't assemble:

const.V=2

begin
    push.1 mul.V
    push.1 div.V
    push.1 sub.V
    push.1 exp.V
end

It fails with:

malformed instruction `mul.V`: parameter 'V' is invalid

All the above instructions should accept a constants.

Motivation:

I want to implement a bitshift to the right with a division, and to make the code more readable I want to write:

const.SHIFT_RIGHT_8=256  # dividing by this constants is equivalent to a >>8

begin
    push.1 div.SHIFT_RIGHT_8
end
hackaugusto commented 3 months ago

Note: I'm aware the transformation from >>8 to /256 doesn't work for all situations. Nevertheless, for the cases it does work, the constants is best for readability.

bitwalker commented 3 months ago

This is implemented in #1277. Just making a note here so I revisit this issue once that's merged.

hackaugusto commented 2 months ago

@bitwalker maybe this can be closed?