-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
Use of bitfield structures with "reserved" components needlessly defeats compiler optimizations. (IDFGH-13822) #14674
Comments
This is also the case for esp32s3 |
Hi, this issue is already in the backlog of one of the teams. I think it didn't get picked up quickly because the scope mentioned in the title (coming up with a different approach to reserved fields) is pretty broad, while the effect of the issue in the case of GPIO registers is only reduced performance. Besides, LL layer is considered to be a private API, not something that applications will generally use. Based on these factors, the priority of this issue was seen as low. Let me see if we can first pick up the simpler task of fixing gpio_ll_set_level to use |
by avoid "read-modify-write" operation. The registers designed to be write only. Related to #14674
by avoid "read-modify-write" operation. The registers designed to be write only. Related to #14674
by avoid "read-modify-write" operation. The registers designed to be write only. Related to #14674
by avoid "read-modify-write" operation. The registers designed to be write only. Related to #14674
Answers checklist.
General issue report
The SOC include files xxx_struct.h are careful to define "reserved" fields for unused bits in registers, but this can force the compiler to do unnecessary read/modify/write sequences on the whole register when a simple store is sufficient and more correct. It may also interfere with atomicity when accessing registers that are specifically design to provide atomic access.
I first noticed this in
gpio_ll_set_level()
for ESP32C3, which reads (esp-idf/components/hal/esp32c3/include/hal/gpio_ll.h
Line 339 in 46acfdc
This SHOULD compile to a simple store of a constant to the GPIO_OUT_W1TS/GPIO_OUT_W1TC registers, but instead compiles to (slow, long, and not atomic)
This is because the low-level structure definition ( https://github.com/espressif/esp-idf/blob/master/components/soc/esp32c3/include/soc/gpio_struct.h#L37 ) has:
forcing the compiler to read the 32bit quantity at hw->out_w1tc so that it can modify JUST the unreserved bitfield.
(also, this happens to be a write-only register. Hopefully, it reads as 0.)
This is defeating the whole purpose of the out_w1tc and similar registers.
For this particular function (
gpio_ll_set_level
), a fix is to change the code to use the full 32bit version of the register:Which then compiles to the expected:
However, I notice that there are 1000+ uses of "reserved" in the various */xxx_struct.h files that may be causing similar non-optimal code, so it might be worth looking into as a more general issue.
The text was updated successfully, but these errors were encountered: