Coder Social home page Coder Social logo

Comments (10)

bobbinth avatar bobbinth commented on May 22, 2024 1

That would be awesome! I do want to say that this might be a fairly involved task. So, maybe worth splitting it into a couple of PRs. For example, the first (simpler) PR could be to add u32assert2 instruction to Miden assembly, and only after that add it to the VM's instruction set.

from miden-vm.

0xkanekiken avatar 0xkanekiken commented on May 22, 2024

If no one else is looking into it, then I'd like to pick this up?

from miden-vm.

0xkanekiken avatar 0xkanekiken commented on May 22, 2024

Actually, that's the plan! I will start working on adding u32assert2 instruction to Miden assembly and submit a PR. Just wanted to know your thoughts on how are we planning to reduce the overall VM cycles. For ex: adding two u32 value unsafely will require 1 VM cycle and likewise doing it safely would costs us 7 VM cycles (1 for addition and 3 each for asserting u32). How can we do this in 2 VM cycles("we'd be able to do must safe operations at just 2x the cost of the unsafe ones.")? Are we planning to do the operation unsafely first and then check of the output is u32 or not? Again this method will cost 4 VM cycles. Apologies if I'm missing something. Thanks.

from miden-vm.

bobbinth avatar bobbinth commented on May 22, 2024

Actually, that's the plan! I will start working on adding u32assert2 instruction to Miden assembly and submit a PR.

Great!

For ex: adding two u32 value unsafely will require 1 VM cycle and likewise doing it safely would costs us 7 VM cycles

Once u32assert2 is implemented as a native VM operation (i.e., an operation which takes 1 cycle) the cost of safe operations will be reduced significantly. But you are right, for operations where we need to check that output is in the right range, it will still take more than 2 cycles. To take a u32add operation as an example.

Plain u32add would take 4 cycles and would look like this:

u32assert2
u32add.unsafe
eq.0
assert

But u32add.full would take only 2 cycles and would look like this:

u32assert2
u32add.unsafe

PS: There is a typo in "we'd be able to do must safe operations at just 2x the cost of the unsafe ones" - "must" should be "most" :)

from miden-vm.

0xkanekiken avatar 0xkanekiken commented on May 22, 2024

Thanks for the explanation. Makes sense now. What opcode shall I use for U32assert2?

from miden-vm.

bobbinth avatar bobbinth commented on May 22, 2024

For the assembly instruction let's call it u32assert.2.

As discussed above, as a part of the first PR there is no need to change the actual opcodes of the VM. But once we get there, the opcode could be just u32assert2.

from miden-vm.

0xkanekiken avatar 0xkanekiken commented on May 22, 2024

I'll start working on adding u32assert2 to the core VM instruction set, given it's already been added to the assembly. @bobbinth What binary literal shall I use for u32assert2?

from miden-vm.

bobbinth avatar bobbinth commented on May 22, 2024

@0xkanekiken - yep, u32assert2 sounds good.

from miden-vm.

0xkanekiken avatar 0xkanekiken commented on May 22, 2024

@bobbinth - I've introduced u32assert2 opcode to the VM instruction. Let me know your thought on the pull request.

from miden-vm.

bobbinth avatar bobbinth commented on May 22, 2024

Closed by #202

from miden-vm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.