资 源 简 介
性能和代码空间的折衷
通常嵌入式系统程序员和拳击手不进行很多比较。然而,在一个方面,他们确实。拳击运动员需要在特定的体重范围内进行战斗,所以他们的挑战是在规定的允许范围内最大限度地发挥他们的效能。嵌入式系统是相似的——你只有有限的内存,你需要在这些限制下最大化你的性能。
通常,提高性能的代码优化也会减少内存大小(通过减少必须存储的代码量)。然而,一些优化要求你做一个权衡-它可以走得更快,也可以更小。做出这个决定是困难的,取决于你正在写的应用程序,但值得注意的是什么是优化属于这一类。本文将介绍您可能遇到的一些主要的空间与速度权衡优化。
Tables vs. calculaTIon
Suppose you want to calculate sin(x/256) for an unsigned 8-bit value x - i.e. the input represents values in the range 0.0 to 1.0. One method would be to calculate a polynomial approximaTIon of the funcTIon. This is likely to be in the order of 5-20 instrucTIons (depending on the architecture)。
Another option would be to have a lookup table. The size of this table will depend on the required output precision. If you wanted 16 bits of output, then the table would be 256 * 16 bits = 512 bytes. This could reduce the calculation to 1 or 2 instructions but at the expense of memory.