0

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 .

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 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
  • 1
    You 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 Answers1

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:

  1. write a very simple function (that produces the asm you think you can optimize)
  2. create TESTS for this function (people tend to introduce weird bugs when writing their own asm)
  3. run & measure
  4. replace the generated asm with your optimizations
  5. test you haven't screwed up the logic
  6. 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