I am trying to optimize a code on esp32 which uses xtensa LX6 microprocessors , I wanted to know the cost of wsr and rsr instructions which are used to read or wirte in the special registers .
Asked
Active
Viewed 95 times
0

Peter Cordes
- 328,167
- 45
- 605
- 847

flying_raijin
- 39
- 6
-
after wchich I can decide whether using rsr and wsr is costly or not !! – flying_raijin Aug 13 '19 at 14:23
-
Have you read the reference manual? – Thomas Jager Aug 13 '19 at 14:26
-
1You need to measure and identify the bottleneck before anything else. First **write code that is simple to understand**. Then measure, then write convoluted code and measure. Then keep the "easy" code regardless. – pmg Aug 13 '19 at 14:28
1 Answers
0
First of all, optimize only after you have profiled, and came to the conclusion that this is your bottleneck.
In rare cases (like a function that accesses registers) it might be a good idea to optimize code generated by the compiler, but usually, that is not where the bottleneck is.
In general, when optimizing compiler-generated code:
- write a very simple function (that produces the asm you think you can optimize)
- create TESTS for this function (people tend to introduce weird bugs when writing their own asm)
- run & measure
- replace the generated asm with your optimizations
- test you haven't screwed up the logic
- run & measure again
Even if you managed to optimize, think about readability, portability, maintenance, etc. before choosing your optimized version.

Saeed Zhiany
- 2,051
- 9
- 30
- 41

hazirovich
- 170
- 7