Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interpreter: add missing arith ops #3909

Open
compor opened this issue Feb 14, 2025 · 0 comments
Open

interpreter: add missing arith ops #3909

compor opened this issue Feb 14, 2025 · 0 comments
Labels
interpreter xDSL Interpreter

Comments

@compor
Copy link
Collaborator

compor commented Feb 14, 2025

Missing interpreter functions for arith operations (split off from #3784 CC @erick-xanadu):

@interpreter.register_impls
class ArithFunctionsExt(interpreters.arith.ArithFunctions):
    @interpreter.impl(UIToFPOp)
    def run_uitofpop(self, interpreter: interpreter.Interpreter, op: UIToFPOp, args: interpreter.PythonValues) -> interpreter.PythonValues:
        """Not really semantically correct, but good enough."""
        return (float(args[0]),)

    @interpreter.impl(arith.SIToFPOp)
    def run_sitofpop(self, interpreter: interpreter.Interpreter, op: arith.SIToFPOp, args: interpreter.PythonValues) -> interpreter.PythonValues:
        """Not really semantically correct, but good enough."""
        return (float(args[0]),)

    @interpreter.impl(FPToUIOp)
    def run_fptouiop(self, interpreter: interpreter.Interpreter, op: FPToUIOp, args: interpreter.PythonValues) -> interpreter.PythonValues:
        """Not really semantically correct, but good enough."""
        return (int(args[0]),)

    @interpreter.impl(arith.FPToSIOp)
    def run_fptosiop(self, interpreter: interpreter.Interpreter, op: arith.FPToSIOp, args: interpreter.PythonValues) -> interpreter.PythonValues:
        """Not really semantically correct, but good enough."""
        return (int(args[0]),)

    @interpreter.impl(arith.ExtUIOp)
    def run_extuiop(self, interpreter: interpreter.Interpreter, op: arith.ExtUIOp, args: interpreter.PythonValues) -> interpreter.PythonValues:
        """Not really semantically correct, but good enough."""
        return args

    @interpreter.impl(arith.TruncIOp)
    def run_trunciop(self, interpreter: interpreter.Interpreter, op: arith.TruncIOp, args: interpreter.PythonValues) -> interpreter.PythonValues:
        """Not really semantically correct, but good enough."""
        return args

    @interpreter.impl(arith.DivfOp)
    def run_divfop(self, interpreter: interpreter.Interpreter, op: arith.DivfOp, args: interpreter.PythonValues) -> interpreter.PythonValues:
        """Not really semantically correct, but good enough."""
        return (args[0] / args[1],)

    @interpreter.impl(arith.FloorDivSIOp)
    def run_floordivsiop(self, interpreter: interpreter.Interpreter, op: arith.FloorDivSIOp, args: interpreter.PythonValues) -> interpreter.PythonValues:
        """Not really semantically correct, but good enough."""
        return (args[0] // args[1],)
@compor compor added the interpreter xDSL Interpreter label Feb 14, 2025
@compor compor changed the title interpreter: Add missing arith ops interpreter: add missing arith ops Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter xDSL Interpreter
Projects
None yet
Development

No branches or pull requests

1 participant