Avoiding Mixed Data Type Arithmetic Expressions

Avoid mixing integer and floating-point (float,double, or long double) data in the same computation. Expressing all numbers in a floating-point arithmetic expression (assignment statement) as floating-point values eliminates the need to convert data between fixed and floating-point formats. Expressing all numbers in an integer arithmetic expression as integer values also achieves this. This improves run-time performance.

For example, assuming that I and J are both int variables, expressing a constant number (2.) as an integer value (2) eliminates the need to convert the data. The following examples demonstrate inefficient and efficient code.

Examples

Example 1: Inefficient Code

int I, J;
I = J / 2.;

Example 2: Efficient Code

int I, J;
I = J / 2;

Special Considerations for Auto-Vectorization of the Innermost Loops

Auto-vectorization of an innermost loop packs multiple data elements from consecutive loop iterations into a vector register, each of which is 128-bit in size.

Consider a loop that uses different sized data, for example, REAL and DOUBLE PRECISION. For REAL data, the compiler tries to pack data elements from four (4) consecutive iterations (32 bits x 4 = 128 bits). For DOUBLE PRECISION data, the compiler tries to pack data elements from two (2) consecutive iterations (64 bits x 2 = 128 bits). Because of the mismatched number of iterations, the compiler sometimes fails to perform auto-vectorization of the loop, after trying to automatically remedy the situation.

If your attempt to auto-vectorize an innermost loop fails, it is a good practice to try using the same sized data. INTEGER and REAL are considered same sized data since both are 32-bit in size.

Examples

Example 1: Non-autovectorizable code

DOUBLE PRECISION A(N), B(N)
REAL C(N), D(N)
DO I=1, N
   A(I)=D(I)
   C(I)=B(I)
ENDDO

Example 2: Auto-vectorizable after automatic distribution into two loops

DOUBLE PRECISION A(N), B(N)
REAL C(N), D(N)
DO I=1, N
   A(I)=B(I)
   C(I)=D(I)
ENDDO

Example 3: Auto-vectorizable as one loop

REAL A(N), B(N)
REAL C(N), D(N)
DO I=1, N
   A(I)=B(I)
   C(I)=D(I)
ENDDO

Submit feedback on this help topic

Copyright © 1996-2010, Intel Corporation. All rights reserved.