Open petrokarashchenko opened 4 years ago
That is a good observation, however, the implementation of this direct access is just a piggyback on volatile flag. Hence, the compiler optimizes the stores (which is correct) into the volatile one.
A work around is to use a very low optimization level like Og
for this function like this:
__attribute__ ((optimize("Og")))
int test(uint8_t * my_ptr,
volatile uint8_t * v_ptr)
This is a good example which shows us that a proper uncached
directive implementation should use memory spaces concept. In your example the two write to memory operations are not equivalent because they are happening in different memory spaces. However, the compiler thinks that both writes are in the same unitary memory space.
Another observation if you use -Os
with -fdata-sections
will result in worst code size due to section anchors which are enabled by default when compiling with Os
. So, you use either data-sections or section-anchors (i.e. -fno-section-anchors).
@claziss I was just developing code with workaround suggested in https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/issues/246 because I can't use __attribute__((uncached))
with a full power.
This is one of the findings :) But potentially there might be many "Easter eggs" due to -mno-volatile-cache
.
Thanks for the hint about -Os
and -fdata-sections
. I will read more about -fno-section-anchors
. The reason why I'm using -fdata-sections
is that I use it in pair with -ffunction-sections
and -Wl,--gc-sections
to reduce binary size
@claziss is there anything we might want to do here? @petrokarashchenko I guess this one is not blocking you, or does it?
Probably a proper fix will slip to the next release.
@claziss do you mean arc-2021.03
?
@abrodkin I think we are looking for https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/issues/246 fix actually. This issue comes as a result of a workaround that we are currently using.
For now we have changed the code to avoid such optimization. But we really looking forward to start using uncached
attribue.
I have next code snippet
I compile it with next options with toolchain
2020.03
:I'm getting next output:
The issue is that I'm expecting to see both uncached (
stb.di
) and cached (stb
) access, but only uncached access is generated.