CodeDensity

From SEGGER Wiki
Revision as of 20:53, 24 September 2023 by Rolf (talk | contribs) (Created page with "Category:Knowledge Base == What is Code density? == Code density is a measure to grasp how much functionality can be put a certain memory size, or the other way round, ho...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


What is Code density?

Code density is a measure to grasp how much functionality can be put a certain memory size, or the other way round, how much memory is required for a certain functionality.

Benefits of high Code density

In general, a high code density is desirable. There is no down side to high code density. A program with higher code density has various advantages

  • Program size is smaller - less program memory is required
  • Program size is smaller - a given amount of memory can be used to store a more capable program with more functionality
  • Power consumption is lower - This is typically so as fetching the instruction costs a significant amount of the systems power
  • Instruction Cache (where available) is used more efficiently, as it covers more code

What does Code density depend on?

Code density depends primarily on the CPU's instruction set (which instructions are available) and its encoding, so which instruction uses how many bytes. In addition, it does depend on the coding convention used and the compiler used. The most important factor is the the CPU's instruction set and its encoding.

How is Code density measured?

There is no standard for this. Or at least no standard that is widely accepted. Basically, the same program can be compiled for different CPUs on different compilers, and the system that generates the smallest program has the highest code density (wins...). The engineering unit for code density is bytes^-1, as it is the inverse of program size (for a given functionality).