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

Powdr/RISCV executor #679

Merged
merged 1 commit into from
Nov 24, 2023
Merged

Powdr/RISCV executor #679

merged 1 commit into from
Nov 24, 2023

Conversation

lvella
Copy link
Member

@lvella lvella commented Oct 6, 2023

No description provided.

@lvella lvella force-pushed the riscv-executor-tmp-base branch from b53d14f to 22f76ec Compare October 11, 2023 14:51
@lvella lvella force-pushed the riscv-executor branch 2 times, most recently from b4071e1 to d2a1bf3 Compare October 13, 2023 17:27
@lvella lvella force-pushed the riscv-executor-tmp-base branch from 91d16b6 to 5731b7b Compare October 13, 2023 17:34
@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[features]
default = [] # halo2 is disabled by default
default = [] # halo2 is disabled by default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the extra space?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code formatter did this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you undo it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked chatgpt how to disable code formatting for Cargo.toml.

// remove all asm (except external instructions)
log::debug!("Run asm_to_pil analysis step");
let file = asm_to_pil::compile(file);
monitor.push(&file);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the best point to perform the execution, so the last step was separated into another function.

use number::{BigInt, FieldElement};

#[derive(Clone, Copy)]
pub union Elem {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not an enum?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the same binary string must be interpreted as either unsigned or signed, depending on the context.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see

@leonardoalt
Copy link
Member

There must be something weird going on: I ran this on an empty Rust main function, and at the end the trace.reg_map is:

Executing...
{"addr": 41, "x7": 16, "x25": 34, "x0": 9, "x19": 28, "x23": 32, "lr_sc_reservation": 8, "x5": 14, "x28": 37, "x11": 20, "Y": 2, "x30": 39, "x31": 40, "x4": 13, "x2": 11, "x13": 22, "x15": 24, "W": 4, "x18": 27, "x20": 29, "x12": 21, "pc": 0, "x27": 36, "tmp2": 6, "x6": 15, "Z": 3, "x9": 18, "x29": 38, "x17": 26, "x21": 30, "x8": 17, "x10": 19, "x16": 25, "x22": 31, "x24": 33, "x1": 10, "tmp1": 5, "tmp3": 7, "x3": 12, "x14": 23, "x26": 35, "X": 1}

A few weird things:

  • x0 should always be 0
  • actually all registers should be 0
  • pc should be something like 100 or so
  • probably more?

maybe I just don't understand yet how this works

@leonardoalt
Copy link
Member

    function main {
		ret;
    }

If I run it on this it seems to get into an infinite loop and runs OOM.

@leonardoalt
Copy link
Member

(rebased)

@leonardoalt
Copy link
Member

maybe I just don't understand yet how this works

ok it looks like reg_map is a map from register names to indices in the table.

@leonardoalt
Copy link
Member

Ok if I print everything at the end properly it seems correct, although I don't know why pc=1 at the end:

pc=0 X=0 Y=0 Z=0 W=0 tmp1=0 tmp2=0 tmp3=0 lr_sc_reservation=0 x0=0 x1=0 x2=0 x3=0 x4=0 x5=0 x6=0 x7=0 x8=0 x9=0 x10=0 x11=0 x12=0 x13=0 x14=0 x15=0 x16=0 x17=0 x18=0 x19=0 x20=0 x21=0 x22=0 x23=0 x24=0 x25=0 x26=0 x27=0 x28=0 x29=0 x30=0 x31=0 addr=0

pc=0 X=0 Y=0 Z=0 W=0 tmp1=0 tmp2=0 tmp3=0 lr_sc_reservation=0 x0=0 x1=0 x2=0 x3=0 x4=0 x5=0 x6=0 x7=0 x8=0 x9=0 x10=0 x11=0 x12=0 x13=0 x14=0 x15=0 x16=0 x17=0 x18=0 x19=0 x20=0 x21=0 x22=0 x23=0 x24=0 x25=0 x26=0 x27=0 x28=0 x29=0 x30=0 x31=0 addr=0

pc=1 X=0 Y=0 Z=0 W=0 tmp1=0 tmp2=0 tmp3=0 lr_sc_reservation=0 x0=0 x1=0 x2=0 x3=0 x4=0 x5=0 x6=0 x7=0 x8=0 x9=0 x10=0 x11=0 x12=0 x13=0 x14=0 x15=0 x16=0 x17=0 x18=0 x19=0 x20=0 x21=0 x22=0 x23=0 x24=0 x25=0 x26=0 x27=0 x28=0 x29=0 x30=0 x31=0 addr=0

@lvella
Copy link
Member Author

lvella commented Oct 23, 2023

Ok if I print everything at the end properly it seems correct, although I don't know why pc=1 at the end:

pc=0 X=0 Y=0 Z=0 W=0 tmp1=0 tmp2=0 tmp3=0 lr_sc_reservation=0 x0=0 x1=0 x2=0 x3=0 x4=0 x5=0 x6=0 x7=0 x8=0 x9=0 x10=0 x11=0 x12=0 x13=0 x14=0 x15=0 x16=0 x17=0 x18=0 x19=0 x20=0 x21=0 x22=0 x23=0 x24=0 x25=0 x26=0 x27=0 x28=0 x29=0 x30=0 x31=0 addr=0

pc=0 X=0 Y=0 Z=0 W=0 tmp1=0 tmp2=0 tmp3=0 lr_sc_reservation=0 x0=0 x1=0 x2=0 x3=0 x4=0 x5=0 x6=0 x7=0 x8=0 x9=0 x10=0 x11=0 x12=0 x13=0 x14=0 x15=0 x16=0 x17=0 x18=0 x19=0 x20=0 x21=0 x22=0 x23=0 x24=0 x25=0 x26=0 x27=0 x28=0 x29=0 x30=0 x31=0 addr=0

pc=1 X=0 Y=0 Z=0 W=0 tmp1=0 tmp2=0 tmp3=0 lr_sc_reservation=0 x0=0 x1=0 x2=0 x3=0 x4=0 x5=0 x6=0 x7=0 x8=0 x9=0 x10=0 x11=0 x12=0 x13=0 x14=0 x15=0 x16=0 x17=0 x18=0 x19=0 x20=0 x21=0 x22=0 x23=0 x24=0 x25=0 x26=0 x27=0 x28=0 x29=0 x30=0 x31=0 addr=0

I don't understand why there are 2 pc=0. pc is incremented on every instruction.

@lvella lvella force-pushed the riscv-executor-tmp-base branch from 5731b7b to 9130a65 Compare October 23, 2023 08:02
@leonardoalt
Copy link
Member

I don't understand why there are 2 pc=0. pc is incremented on every instruction.

Each line is a row

Ok(file)
}

pub fn consume_asm<T: FieldElement>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consume is kind of weird because it does not say what it converts it to.
What about calling this convert_analyzed_to_pil and the other convert_asm_to_pil or something?

}

/// set next value of register
pub(crate) fn s(&mut self, idx: &str, value: impl Into<Elem>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be much better readable if s would return a mutable reference to the value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my subjective opinion, no.

Instead of:

obj.s("pc", x + 42);

it would be

*obj.s("pc") = (x + 42).into();

or more conventionally

*obj.g_mut("pc") = (x + 42).into();

But most importantly, I can't have the logic to handle PC or x0 if I return a mut reference.

@lvella lvella changed the base branch from riscv-executor-tmp-base to main October 26, 2023 13:15
@lvella lvella force-pushed the riscv-executor branch 2 times, most recently from d9ecec4 to a08fc5a Compare October 26, 2023 18:17
@leonardoalt
Copy link
Member

rebased, last commit needs to be doubled checked because of some AST changes

@leonardoalt leonardoalt force-pushed the riscv-executor branch 3 times, most recently from a0df34f to 9ca3665 Compare November 6, 2023 19:36
@lvella lvella force-pushed the riscv-executor branch 4 times, most recently from ce31e9f to 80e2f87 Compare November 10, 2023 16:54
"jump_and_link_dyn" => {
let pc = self.proc.g("pc");
self.proc.s("x1", pc.u() + 1);
self.proc.s("pc", args[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also add a set_pc function? Is it actually legal to set the PC in a regular instruction? If not, we could remove the special case in the s function.

Copy link
Member Author

@lvella lvella Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean, like in addi pc,pc,42? Some random interwebs slides says it is not possible. I'll do it.

But still find the s(key, value) solution more elegant than returning mut &, and I still need to handle the special case of x0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@lvella lvella marked this pull request as ready for review November 16, 2023 17:18
@lvella lvella force-pushed the riscv-executor branch 11 times, most recently from f4c5077 to 070b6df Compare November 20, 2023 18:26
@leonardoalt leonardoalt force-pushed the riscv-executor branch 2 times, most recently from feeb9ba to edd1f10 Compare November 24, 2023 09:56
@leonardoalt
Copy link
Member

rebased & squashed

leonardoalt
leonardoalt previously approved these changes Nov 24, 2023
@leonardoalt leonardoalt added this pull request to the merge queue Nov 24, 2023
Merged via the queue into main with commit 99979a8 Nov 24, 2023
2 checks passed
@leonardoalt leonardoalt deleted the riscv-executor branch November 24, 2023 11:48
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