Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Shorts vs Ints

patf2000
Beginner
307 Views

Just a question for someone that knows the compiler, I can use shorts in many place of my code where I use ints.

I understood ints were better for compiling. Using the Intel Compiler is there any advantage to using shorts instead

of ints and if I do is there an optimized compiler setting that will take advantage of short vs ints ?

I guess I will try it, but figure someone might know before hand.

Thanks

Pat

0 Kudos
2 Replies
levicki
Valued Contributor I
307 Views

There is the theoretical advantage of being able to process 2x more elements per instruction provided that your code can be automatically vectorized. As you may know, 128-bit XMM register can hold 4 ints or 8 shorts.

Shorts may be batter choice if the arithmetic operations you are performing cannot overflow. Speed gain however will vary with the processor used. Core 2 and newer should have faster SIMD integer units.

The best thing would be to perform a test. Keep in mind though that unsigned shorts have limited support at the instruction level so some loops which can be vecotrized using short cannot if you change data to unsigned short.

I doubt you will see much speedup unless you process a lot of data though.

0 Kudos
barsmonster
Beginner
307 Views
You may get an advantage only if your code is bandwidth-limited. Also, you may get benefit when you are doing div's.
0 Kudos
Reply