Short and Int are different for GCC - General Discussion and Assistance - CHDK Forum supplierdeeply

Short and Int are different for GCC

  • 4 Replies
  • 4899 Views
*

Offline Lebeau

  • ***
  • 187
Short and Int are different for GCC
« on: 22 / June / 2011, 16:08:38 »
Advertisements
Well, I just get a look to dump-a650-100d.txt to see difference between -O3 and -Os gcc option.

I was extremely surprise to see how -- short get_metering_mode_for_exif( short...) -- was threat, irrelevant to -O option

Code: [Select]
unsigned short get_metering_mode_for_exif ( short metering_mode )
{
static unsigned int meter [ 3 ] = { 5, 3, 2 }; // evaluative, spot, centerweightedaverage
return ( meter [ metering_mode ] );
}
;

With -- short get_metering_mode_for_exif(short... --
Code: [Select]
000b6488 <get_metering_mode_for_exif>:
   b6488: 0402      lsls r2, r0, #16
   b648a: 4b02      ldr r3, [pc, #8] (b6494 <get_metering_mode_for_exif+0xc>)
   b648c: 1391      asrs r1, r2, #14
   b648e: 1858      adds r0, r3, r1
   b6490: 8c00      ldrh r0, [r0, #32]
   b6492: 4770      bx lr
   b6494: 000e0ec0 .word 0x000e0ec0
Get attention to lsls and asrs, and ldrh ...

With -- int get_metering_mode_for_exif(int... --
Code: [Select]
000b152c <get_metering_mode_for_exif>:
   b152c: 4b02      ldr r3, [pc, #8] (b1538 <get_metering_mode_for_exif+0xc>)
   b152e: 0081      lsls r1, r0, #2
   b1530: 1858      adds r0, r3, r1
   b1532: 6a00      ldr r0, [r0, #32]
   b1534: 4770      bx lr
   b1536: 46c0      nop (mov r8, r8)
   b1538: 000d13fc .word 0x000d13fc

Well I think short shall be replace by int at many place, no ?

*

Offline reyalp

  • ******
  • 14118
Re: Short and Int are different for GCC
« Reply #1 on: 22 / June / 2011, 22:40:19 »
For simple values (not arrays or structs) int should almost always be more efficient, both in speed and code size. I'm not sure what motivated the use of short in the original code, I suspect some of it was misguided assumption that it was smaller/faster, some of it was because the underlying canon values are actually shorts, and some of it was just copy/paste of either of those.

You do have to be careful, you can't just do s/short/int/ globally, e.g. some propcase values are are actually only 16 bits. You have to be careful with sign extension, and truncation if you pass it back to a canon function that expects a short.

Note that 'long' is also just there to confuse you. That one could (and should IMO) be eliminated since it's functionally identical to int.
Don't forget what the H stands for.

*

Offline Lebeau

  • ***
  • 187
Re: Short and Int are different for GCC
« Reply #2 on: 23 / June / 2011, 11:13:06 »
I am concentrating to optimize raw, dng and shot_histogram.
I have choice to change "static int meter" into "static short meter" to eliminate type conversion code or change param and return value to int.
I choose param and return value to int.

*

Offline reyalp

  • ******
  • 14118
Re: Short and Int are different for GCC
« Reply #3 on: 23 / June / 2011, 15:59:39 »
I am concentrating to optimize raw, dng and shot_histogram.
I have choice to change "static int meter" into "static short meter" to eliminate type conversion code or change param and return value to int.
I choose param and return value to int.
Not sure exactly what these are. If you are using an array of histogram values, I would definitely use the smallest sized value it can fit in.
Don't forget what the H stands for.


*

Offline Lebeau

  • ***
  • 187
Re: Short and Int are different for GCC
« Reply #4 on: 24 / June / 2011, 07:39:30 »
These short-int combination are in dng.c

I agree, when creating arrays, you shall use the smallest size as possible to limit mem size and optimize cache traffic.

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal