It is currently Wed Jul 06, 2011 7:46 pm

All times are UTC - 8 hours




 Page 1 of 1 [ 2 posts ] 
Author Message
 Post subject: Preferred data types?
PostPosted: Fri Apr 08, 2011 9:59 am 

Joined: Thu Apr 07, 2011 7:11 pm
Posts: 6
So I've also run into the code size issue. I am a bit curious about what sort of data types are preferred for one's working set. (Obviously in RAM and constants we want as small as possible) My brief experimentation changing one of my types was:
type - bytes free
u8 - 427
u16 - 387
s16 - 355
u32 - 435
s32 - 435

Thus, I'd conclude that full ints are the best thing to use for all your temporary calculations - it would seem extra code has to be emitted to deal with passing around 16-bit integers.

Is this correct?


Offline
 Profile  
 
 Post subject: Re: Preferred data types?
PostPosted: Mon Apr 11, 2011 10:32 am 

Joined: Mon Feb 21, 2011 10:03 am
Posts: 26
Location: San Diego, CA
That's correct - the "native" type for the processor is 32-bits. When you use 16-bit integers, the compiler will typically generate extra instructions to sign-extend, mask, etc to enforce the limitations of 16-bits and make comparisons and other operations work correctly. Ironically, these types of processors will often handle 8-bit integers better than they handle 16-bit ones since byte operations are more common and necessary.

However, if you have large tables of integers that fall within the range of 16-bits, it's sometimes better to go ahead and store them that way, since the additional storage used by the table can exceed the savings in the instructions.

One trick some people do it simple abstract the types and once the code is done, fiddle with them to get the best storage/speed/code size tradeoff.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 2 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: