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

writer offset as a struct field #751

Merged
merged 2 commits into from
Nov 20, 2023
Merged

writer offset as a struct field #751

merged 2 commits into from
Nov 20, 2023

Conversation

burrbull
Copy link
Member

@burrbull burrbull commented Oct 18, 2023

This is retry of one of my old experiments.

It does 2 things:

  1. Moves offset from field writer generic to struct field.
  2. Always index field array from 0 (slightly confusing but much easier to work).

Generated code is much simpler.

The main advantage is you can now simply use .write(|w| w.fname(3).set_bit() for write/modify field arrays (previously only reading was accepted) same as .write(|w| w.fname3().set_bit().

The main disadvantage is bigger firmware size in debug mode.

cc @kossnikita, @therealprof and anyone who want to help.

I tried several examples from stm32f4xx-hal:

                   before PR vs after PR
blinky-timer-irq  41984/1172 vs 42628/1172
pwm-sinus         49672/8628 vs 50608/8632
rtc-alarm         63704/4680 vs 65648/4680
rtic-usart-shell 88024/17548 vs 88904/17548

So it is 2-3% bigger on debug mode for me.

cargo build --release -j1 --timings. time of stm32f4(f411) compilation on my machine, dependencies not included and peak memory usage during rtic-usart-shell compilation:

0.14.0    4.73s   758860k
0.15.1    3.00s   530916k
before PR 2.67s   476400k
after PR  2.47s   450996k

@kossnikita
Copy link

kossnikita commented Oct 20, 2023

My crate is very similar to yours, and the PAC is also similar. So I don't think there will be a big difference. I don't understand how I can measure the compile time. Just the example build or HAL and PAС?

                   before PR vs after PR
qei               29656/9504 vs 30268/9504
pwm               35004/9524 vs 35612/9524

Sorry, I haven't finished the more complex examples yet.

@burrbull
Copy link
Member Author

I don't understand how I can measure the compile time

You just need to cargo clean and then

cargo build --timings

(+ --release). After finish cargo generates html report and prints a link to it. Doesn't matter what you are building example or HAL. It show compilation time of each dependency.

@kossnikita
Copy link

Got it. I mean what time do you need? HAL compile or PAC + HAL?

@burrbull
Copy link
Member Author

I've measured just a PAC compilation time.
Sure a full time is also interesting, as this PR may also affect on linking time. But I don't see good way to estimate difference.

@kossnikita
Copy link

cargo build --release -j1 --timings --example qei --features at32f415

PAC compile time:

6.7±0.15s vs 6.5±0.05s

@burrbull burrbull marked this pull request as ready for review October 22, 2023 15:13
@burrbull burrbull requested a review from a team as a code owner October 22, 2023 15:13
@burrbull burrbull force-pushed the writer-offset branch 2 times, most recently from ac95746 to c8e8c1b Compare November 19, 2023 17:43
Copy link
Member

@Emilgardis Emilgardis left a comment

Choose a reason for hiding this comment

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

i'm fine with this new interface and zero indexing, but I think we need to signal the break a little better, not sure how though

src/generate/generic.rs Outdated Show resolved Hide resolved
Copy link
Member

@Emilgardis Emilgardis left a comment

Choose a reason for hiding this comment

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

lgtm! I'd like it if someone else on @rust-embedded/tools could also review

Copy link
Contributor

@therealprof therealprof left a comment

Choose a reason for hiding this comment

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

I don't quite understand why we want to do this but I'm fine in general.

@burrbull burrbull added this pull request to the merge queue Nov 20, 2023
Merged via the queue into master with commit f8a5479 Nov 20, 2023
43 checks passed
@burrbull burrbull deleted the writer-offset branch November 20, 2023 03:54
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.

4 participants