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

Xtensa asm! implementation #68

Merged
merged 1 commit into from
Aug 12, 2021
Merged

Xtensa asm! implementation #68

merged 1 commit into from
Aug 12, 2021

Conversation

MabezDev
Copy link
Member

@MabezDev MabezDev commented Aug 5, 2021

Status

Mostly working but a few oddities. @KerryRJ kindly provided ports for the asm in the xtensa-lx & xtensa-lx so we know the core use case is solved.

However there are a few things left to do.

TODO

@KerryRJ
Copy link

KerryRJ commented Aug 5, 2021

Where is this assembly?

@MabezDev
Copy link
Member Author

MabezDev commented Aug 5, 2021

Where is this assembly?

Just some random asm I created to test the feature gating of the registers. I don't think this will stop us from implementing xtensa-lx-rt or anything.

@KerryRJ
Copy link

KerryRJ commented Aug 5, 2021

xtensa-lx-rt builds fine but I'm getting the same errors on xtensa-lx.

@MabezDev
Copy link
Member Author

MabezDev commented Aug 5, 2021

@KerryRJ I see you have ported the asm in xtensa-lx, would you mind PR'ing that?

Are you porting xtensa-lx-rt as well or should I take a look?

@KerryRJ
Copy link

KerryRJ commented Aug 5, 2021

Both are ported. Busy trying to figure why xtensa-lx is failing.

@MabezDev
Copy link
Member Author

MabezDev commented Aug 5, 2021

Both are ported. Busy trying to figure why xtensa-lx is failing.

I tried it and I don't think there is an issue, just running cargo build in xtensa-lx errors because the target is not set to xtensa via .cargo/config, which results in errors like this:

error: invalid register `a0`: unknown register
  --> src/lib.rs:37:24
   |
37 |         in(reg) stack, out("a0") _, options(nostack)
   |                        ^^^^^^^^^^^

error: invalid register `a0`: unknown register
  --> src/lib.rs:54:41
   |
54 |             ", out(reg) x, out(reg) _y, out("a0") _, options(nostack))
   |                                         ^^^^^^^^^^^

error: could not compile `xtensa-lx` due to 2 previous errors

My machine is x86 hence a0 is an unknown register.

Building using cargo +esp-dev build --target xtensa-esp32-none-elf -Zbuild-std=core results in sucessfull compilation.

I fell into a similar trap earlier today, it turns outs only input/output registers are validated on the rust side (source: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/asm!.20register.20filter/near/248466515), hence why it only failed on those select few functions where we had to mark a0 as clobbered.

If that was your issue would you mind PR'ing both your xtensa-lx & xtensa-lx-rt changes?

@KerryRJ
Copy link

KerryRJ commented Aug 5, 2021

I can't believe I tripped over that again and wasted so much time! Completely forgot about the target as I usually add a config.toml to the builds so that I don't have to pass them on the command line. Good catch!

Getting a lot of these now when using cargo build --target xtensa-esp32-none-elf -Zbuild-std=core

'+memctl' is not a recognized feature for this target (ignoring feature)

I will PR both of them.

@MabezDev
Copy link
Member Author

MabezDev commented Aug 5, 2021

'+memctl' is not a recognized feature for this target (ignoring feature)

Nothing to worry about, it's a small typo in the llvm fork: espressif/llvm-project#47

I will PR both of them.

Thank you!

@KerryRJ
Copy link

KerryRJ commented Aug 8, 2021

I have just tried the following snippet in the xtensa-rust-quickstart and it is building without any problems:-

    let o: u32;
    unsafe {
        asm!(
            "mov {0}, {1}",
            "add {0}, {number}",
            out(reg) o,
            in(reg) i,
            number = const 5,
        );
    }
    assert_eq!(o, 8);

    let _x: f32;
    unsafe {
        asm!(
            "lsi {}, a0, 152", out(freg) _x
        );
    };`

Additional TODOs to consider?

- Update documentation.

- Add types tests.

@MabezDev
Copy link
Member Author

MabezDev commented Aug 8, 2021

unsafe {
    asm!(
        "mov {0}, {1}",
        "add {0}, {number}",
        out(reg) o,
        in(reg) i,
        number = const 5,
    );
}

This is not valid Xtensa assembly, what target are you building for? It should look like this instead:

unsafe {
  asm!(
    "mov {0}, {1}",
    "addi {0}, {0}, {number}",
    out(reg) o,
    in(reg) i,
    number = const 5,
  );
}

@MabezDev MabezDev force-pushed the xtensa-asm-impl branch 4 times, most recently from 2900760 to ab82ad9 Compare August 11, 2021 10:27
MabezDev added a commit that referenced this pull request Jul 19, 2022
MabezDev added a commit that referenced this pull request Aug 19, 2022
MabezDev added a commit that referenced this pull request Aug 24, 2022
MabezDev added a commit that referenced this pull request Sep 20, 2022
MabezDev added a commit that referenced this pull request May 16, 2023
MabezDev added a commit that referenced this pull request May 30, 2023
MabezDev added a commit that referenced this pull request May 31, 2023
MabezDev added a commit that referenced this pull request Jul 11, 2023
MabezDev added a commit that referenced this pull request Jul 13, 2023
MabezDev added a commit that referenced this pull request Sep 15, 2023
MabezDev added a commit that referenced this pull request Nov 15, 2023
MabezDev added a commit that referenced this pull request Jan 2, 2024
MabezDev added a commit that referenced this pull request Feb 5, 2024
MabezDev added a commit that referenced this pull request Feb 9, 2024
MabezDev added a commit that referenced this pull request Apr 30, 2024
MabezDev added a commit that referenced this pull request Jun 11, 2024
MabezDev added a commit that referenced this pull request Jul 22, 2024
MabezDev added a commit that referenced this pull request Sep 3, 2024
MabezDev added a commit that referenced this pull request Oct 16, 2024
MabezDev added a commit that referenced this pull request Oct 21, 2024
MabezDev added a commit that referenced this pull request Oct 22, 2024
MabezDev added a commit that referenced this pull request Oct 25, 2024
MabezDev added a commit that referenced this pull request Oct 28, 2024
MabezDev added a commit that referenced this pull request Oct 28, 2024
MabezDev added a commit that referenced this pull request Oct 28, 2024
Co-authored-by: Taiki Endo <te316e89@gmail.com>
MabezDev added a commit that referenced this pull request Oct 30, 2024
Co-authored-by: Taiki Endo <te316e89@gmail.com>
MabezDev added a commit that referenced this pull request Nov 6, 2024
Co-authored-by: Taiki Endo <te316e89@gmail.com>
MabezDev added a commit that referenced this pull request Nov 26, 2024
Co-authored-by: Taiki Endo <te316e89@gmail.com>
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.

5 participants