Intrinsics Samples

These samples illustrate in a general way how to use the intrinsics and macros supported in the compiler.

See Included Samples for other samples included with the compiler.

Sample files and locations

Source

Locations

intrin_double_sample.c

intrin_dot_sample.c

intrin_time_sample.c

intrin_ftz_sample.c

Linux* and Mac OS*

<install-dir>/samples/intrinsic_samples/

Windows*

<install-dir>\samples\intrinsic_samples\

Description

These samples illustrate different aspects of intrinsics and macro support in the compiler.

File Name

Description

intrin_double_sample.c

Demonstrates using Streaming SIMD Extensions 3 (SSE3) and Streaming SIMD Extensions 2 (SSE2), and C intrinsics to multiply two complex numbers.

SSE3 and SSE2 intrinsics do not run on processors that do not support SSE3 instruction sets.

intrin_dot_sample.c

Demonstrates using Streaming SIMD Extensions 3 (SSE3), C, and MMX™ technology intrinsics to calculate the dot product of two vectors.

SSE3 intrinsics do not run on processors that do not support SSE3 instruction sets.

intrin_time_sample.c

Demonstrates using the _rdtsc()intrinsic to read the time stamp counter. The output is the current value of the 64-bit time stamp counter, and therefore varies each time you compile the code.

intrin_ftz_sample.c

Demonstrates using compiler macros to read the FTZ and DAZ flags in the MXCSR control register.

Compile the samples

None of the samples require special options to compile; however, the example commands include the compiler option for specifying the file name to avoid overwriting the executables on Linux and Mac OS. Windows compilation automatically uses the source file name for the executable name.

The SSE3 and SSE2 samples must be run on a processor that supports those instruction sets.

Platform

Commands

Linux and Mac OS

icpc intrin_double_sample.c -o intrin_double_sample

icpc intrin_dot_sample.c -o intrin_dot_sample

icpc intrin_time_sample.c -o intrin_time_sample

icpc intrin_ftz_sample.c -o intrin_ftz_sample

Windows

icl intrin_double_sample.c

icl intrin_dot_sample.c

icl intrin_time_sample.c

icl intrin_ftz_sample.c

Run the executables

Run the complex numbers executable

Platform

Commands

Linux and Mac OS

./intrin_double_sample

Windows

intrin_double_sample

The application should generate results similar to the following:

Commands

Complex Product(C):    23.00+ -2.00i

Complex Product(SSE3): 23.00+ -2.00i

Complex Product(SSE2): 23.00+ -2.00i

If you run this sample on a processor that does not support SSE2 and SSE3, the executable will fail and throw an exception error.

Run the dot product executable

Platform

Commands

Linux and Mac OS

./intrin_dot_sample

Windows

intrin_dot_sample

The application should generate results similar to the following:

Commands

Dot Product computed by C: 506.000000

Dot Product computed by SSE2 intrinsics:  506.000000

Dot Product computed by MMX intrinsics:  506

If you run this sample on a processor that does not support SSE2 the executable will fail and throw an exception error.

Run the time executable

Platform

Commands

Linux and Mac OS

./intrin_time_sample

Windows

intrin_time_sample

The application should generate results similar to the following; however, the final number might change each time you run the program.

Commands

Processor cycles                                                           15280

Run the macro executable

Platform

Commands

Linux and Mac OS

./intrin_ftz_sample

Windows

intrin_ftz_sample

The application should generate results similar to the following:

Commands

FTZ is set.

DAZ is set.