Or to reformulate the question: is there a performance penalty in using unsigned values?
And in general: what is the most performant type (16bit signed?, 32bit signed? etc.) on the IPhone ARM processor?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It always depends:
For loops signed integers as counters and limits are a tad faster because in C the compiler is free to assume that overflow never happends.
Consider this: You have a loop with an unsigned loop counter like this:
In this loop the compiler must make sure that the loop even terminates if first is greater than last because I will wrap from UINT_MAX to 0 on overflow (just to name one example – there are other cases as well). This removes the opportunity for some loop optimizations. With signed loop counters the compiler assumes that wrap-around does not occur and may generate better code.
For integer division otoh unsigned integers are a tad faster on the ARM. The ARM does not has a hardware divide unit, so division is done in software, and is always done on unsigned values. You’ll save some cycles for the extra-code required to turn a signed division into an unsigned division.
For all other things like arithmetic, logic, load and write to memory the choice of sign-ness will not make any difference.
Regarding the data-size: As Rune pointed out they are more or less of equal speed with 32 bit types beeing the fastest. Bytes and words sometimes need to be adjusted after processing as they reside in a 32 bit register and the upper (unused) bits need to be sign or zero extended.
However, the ARM CPU’s have a relative small data-cache and are often connected to relative slow memory. If you’re able to utilize the cache more efficient by choosing smaller data-types the code may executes faster even if the theoretical cycle-count goes up.
You have to experiment here.