S12XDP512 more efficient between char and int

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

S12XDP512 more efficient between char and int

2,981件の閲覧回数
calou
Contributor III
Hello,
 
I use CW 4.5 for s12x
 
if i declare a function like it
 
void f(char i, char j)
{
 return(i+j)
}
 
and the same function like that
 
void f(int i, int j)
{
 return(i+j)
}
 
What is the best déclaration for the micro (for speed)? I don't really need 16 bit variables but i am translating old functions to a new application for 9s12x and a lot of functions are declared with int for char really needed. If i change all my declarations functions, will my program will work faster?
 
Regards 
ラベル(1)
0 件の賞賛
返信
3 返答(返信)

1,595件の閲覧回数
calou
Contributor III
Thank you for help
 
Regards
0 件の賞賛
返信

1,595件の閲覧回数
Alban
Senior Contributor II
Hello,

To know the exact speed, you need to refer to the assembly generated.
The number of instruction will depend on where your values are stored.
S12XCPUVx will give a decomposition of instructions used.

With a char (byte), values can be stored in CPU registers A and B.
But int (word), values will not fit.

As the Guru said, an int will take more memory space.
If it is practical, I advise you to .use the smallest side.
After all, an addition between two "int" can give a "long".

Cheers,
Alban.
0 件の賞賛
返信

1,595件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee
I'm not sure, but my feeling is that for the HC12, using unsigned char or unsigned int wont differ a lot in speed.
Some arithmetic operations (or, and,) are faster with unsigned char's but on the other side C rules often require int arithmetic so char's may have to be explicitly zero extended in other cases.
Probably you wont see a huge difference in speed (but in memory usage :smileyhappy:

Daniel
0 件の賞賛
返信