473,396 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Efficiency of int vs. unsigned int.

Hello - Someone recently mentioned there may be a difference in efficiency between an int and an unsigned int. Has anyone heard this or have more information? My boss wants me to experiement with them to check, but not sure what to look at. Thank you..
Dec 1 '08 #1
7 6047
JosAH
11,448 Expert 8TB
@dissectcode
That all depends on your processor; check its specifications and see if any operations on (un)signed ints are slower or faster than the others.

kind regards,

Jos
Dec 1 '08 #2
Thanks for the reply - what would be a good way to test the efficiency of the processor?
Dec 1 '08 #3
JosAH
11,448 Expert 8TB
@dissectcode
As I wrote: read its specifications and see how many cycles are taken by the (un)signed int operators.

kind regards,

Jos
Dec 1 '08 #4
I found an answer to this question in case anyone else needs to know. The docs of the processor only discuss front end stuff. So, to test the behavior of the entire compiler, create global variables of signed and also unsigned, and create for loops for each type. Run the compiler with a switch (-S for ARM) which gives the assembly language output. In the output, you can see the instructions for each of the loops, and how the compiler processes the different types.
Dec 2 '08 #5
disown
17
In order to get the complete picture, you also probably want to find out how many cpu cycles each one of those assembler instructions take, as JosAH pointed out.
Dec 3 '08 #6
jtgd
2
I can tell you one huge difference when it comes to ARM code, and it may apply to other architectures.

When you are using C in ARM, you should have all autos be 32 bits. If you use shorts or chars then after every operation it will do a shift-left, shift-right to either zero-extend or sign-extend the word to an int so that it is always a proper 32 bit int. This is of course horribly inefficient. If your autos are 32 bit then there is nothing to do to normalize it. In ARM the only time you should use shorts or chars is for storing in memory.

Depending on the compiler and the architecture, it may be that it will want to sign extend a signed int but not extend an unsigned int, though I have not seen this.
Dec 5 '08 #7
Banfa
9,065 Expert Mod 8TB
@jtgd
Strictly you should use an int (the arm is a 32 bit processor so int will be 32 bits).

For any platform int should be the most efficient type for the platform to process (that is how it is defined in the standard). Obviously you have to offset that with support portability given the possible limitations in size of int.

This is why of all the integer types int is the one that is found to be different sizes most often when examining different platforms.
Dec 5 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

24
by: JKop | last post by:
Your program begins at: int main(void); Now, in main, you want to call a function. This particular function you want to call defines a local object of type Taste, and then returns this local...
31
by: mark | last post by:
Hello- i am trying to make the function addbitwise more efficient. the code below takes an array of binary numbers (of size 5) and performs bitwise addition. it looks ugly and it is not elegant...
49
by: Neil Zanella | last post by:
Hello, Often I happen to be dealing with nonnegative integers and since I know I won't need negative numbers here I declare them as unsigned simply to make the program somewhat clearer....
77
by: Aman JIANG | last post by:
THE GAME : Write a C function to swap the bits of a char so that its bits would become the mirror image of the char.MSBs become its LSBs etc. E.g. 11001100 binary would become 00110011 binary....
34
by: Frederick Gotham | last post by:
I'm trying to write extremely efficient, fully portable algorithms to determine if an integer is odd or even. The most basic algorithms would be: #define IS_ODD(x) ((x) % 2) #define IS_EVEN(x)...
9
by: anon.asdf | last post by:
In terms of efficieny: Is it better to use multiple putchar()'s after one another as one gets to new char's OR is it better to collect the characters to a char-array first, and then use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.