This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Speed optimisation: use char or int?

Genius 5820 points
Other Parts Discussed in Thread: AM3358

Hi,

I'm using TIs ARM compiler for AM3358 CPU and currently optimise existing code for speed. Now there is a variable that can be eiter "1" or "-1" (defining a direction). This variable is used for addition only (evaluating the position dependent on direction).

So what results in faster code: when I use a "signed char" for this variable (which is shorter and saves memory) or when I use a "signed int" (which has same width like data bus and does not result in odd address access)?

The whole software is bare-metal and has a size of 130 kBytes, so it should run from internal cache completely.

Thanks!

  • I am pretty sure it won't make a difference - but why don't you simply give it a try?

  • Another solution to consider ... Use the type int _fast8_t from the standard header file <stdint.h>.

    Thanks and regards,

    -George

  • Hans M��ller said:
    The whole software is bare-metal and has a size of 130 kBytes, so it should run from internal cache completely.

    If need to optimize for speed, does the initialization code for the bare-metal application enable the cache and set the processor speed to the highest possible?

    I would expect the processor clock speed and enabling cache would have more of a performance boost that the type of a variable - but that timing measurements should be made to check.

  • Chester Gillon said:
    I would expect the processor clock speed and enabling cache would have more of a performance boost that the type of a variable

    These types of optimisation that offer a huge boost are already done (enabling all caches, using highest optimisation level, optimising for speed rather than for size, optimising code for internal cache usage, avoiding float/double calculations).

    Now I'm looking for possibilities to improve some more things - with of course not such a big boost but with a minor improvement (which are therefore not easy to measure).