Linux Assemblycollection of fast libraries

SIMD librarySIMD.h

SIMD library was designed to allow C/C++ programs to communicate with SIMD directly via simple interface, to get its status, and change unit work mode. This is common routine for any mathematics and computation algorithms. But "C" and "C++" language just provide very abstract paradigm how programs should operate with hardware units. It is because of portability of both languages. But if we need high speed calculation, we also need to operate with hardware units as close as it is possible. That is why such programs require some kind of interface functions to manipulate with hardware units state and change working mode.

Contents

Function list

C function nameFunctionsC++ function nameFunctions
ClearDenormalsAreZerosFlag1 functionClearDenormalsAreZerosFlag1 function
ClearExceptionMasks1 functionClearExceptionMasks1 function
ClearExceptions1 functionClearExceptions1 function
ClearFlushToZeroFlag1 functionClearFlushToZeroFlag1 function
GetDenormalsAreZerosFlag1 functionGetDenormalsAreZerosFlag1 function
GetExceptionMasks1 functionGetExceptionMasks1 function
GetExceptions1 functionGetExceptions1 function
GetFlushToZeroFlag1 functionGetFlushToZeroFlag1 function
GetMode1 functionGetMode1 function
GetRoundMode1 functionGetRoundMode1 function
GetStatus1 functionGetStatus1 function
Init1 functionInit1 function
SetDenormalsAreZerosFlag1 functionSetDenormalsAreZerosFlag1 function
SetExceptionMasks1 functionSetExceptionMasks1 function
SetFlushToZeroFlag1 functionSetFlushToZeroFlag1 function
SetMode1 functionSetMode1 function
SetRoundMode1 functionSetRoundMode1 function
C function nameFunctionsC++ function nameFunctions

SIMD constants

ConstantDescription
SIMD rounding modes
SIMD_RC_NEARESTRound to nearest even integer
SIMD_RC_ROND_DOWNRound down (floor)
SIMD_RC_ROND_UPRound up (ceil)
SIMD_RC_TRUNCATERound to nearest integer, toward zero (truncation)
SIMD exception masks
SIMD_PMPrecision mask
SIMD_UMUnderflow mask
SIMD_OMOverflow mask
SIMD_ZMDivide by zero mask
SIMD_DMDenormal operand mask
SIMD_IMInvalid operation mask
SIMD_ALL_MASKSAll masks
SIMD exception flags
SIMD_PEPrecision flag
SIMD_UEUnderflow flag
SIMD_OEOverflow flag
SIMD_ZEDivide by zero flag
SIMD_DEDenormal operand flag
SIMD_IEInvalid operation flag
SIMD_ALL_EXCPTSAll flags
SIMD defaults
SIMD_DEFAULTDefault SIMD mode

SIMD data types

TypeDescriptionC/C++ equivalent
simd_ctrl_tSIMD control wordint
simd_stat_tSIMD status wordint

SIMD control functions

SIMD control word provides individual mask bits for the SIMD floating-point exceptions. An exception type is masked if the corresponding mask bit is set, and it is unmasked if the bit is clear. These mask bits are set upon a power-up or reset. This causes all SIMD floating-point exceptions to be initially masked. If you clears a mask bit and sets the corresponding exception flag bit, a SIMD floating-point exception will not be generated as a result of this change. The unmasked exception will be generated only upon the execution of the next SSE instruction that detects the unmasked exception condition.

Init SIMD

Cvoid SIMD_Init (void);
C++void SIMD::Init (void);

Description: Sets the SIMD control register to its default state.

Parameters: None.

Return value: None.

Set SIMD mode

Cvoid SIMD_SetMode (simd_ctrl_t cword);
C++void SIMD::SetMode (simd_ctrl_t cword);

Description: Sets SIMD mode according to the control word value, passed to the function.

Parameters:

  • cword - SIMD control word

Return value: None.

Get SIMD mode

Csimd_ctrl_t SIMD_GetMode (void);
C++simd_ctrl_t SIMD::GetMode (void);

Description: Returns current value of the SIMD control word.

Parameters: None.

Return value: SIMD control word.

SIMD rounding mode

The rounding-control field of the SIMD control word controls how the results of SIMD floating-point instructions are rounded. The IEEE Standard 754 defines four rounding modes: round to nearest, round up, round down, and round toward zero. The default rounding mode is round to nearest. This mode provides the most accurate and statistically unbiased estimate of the true result and is suitable for most applications.

Set round mode

C/C++simd_ctrl_t SetRoundMode (simd_ctrl_t cword, int rmode);

Description: Changes round mode value into the SIMD control word.

Parameters:

Return value: SIMD control word with new round mode.

Get round mode

C/C++int GetRoundMode (simd_ctrl_t cword);

Description: Extracts round mode from the SIMD control word.

Parameters:

  • cword - SIMD control word

Return value: Round mode value (see round modes).

SIMD exception masks

The exception-flag mask bits mask the 6 floating-point exception flags in the SIMD status word. When one of these mask bits is set, its corresponding SIMD floating-point exception is blocked from being generated.

Clear exception masks

C/C++simd_ctrl_t ClearExceptionMasks (simd_ctrl_t cword, int exceptions);

Description: Clears selected exception masks into the SIMD control word.

Parameters:

Return value: SIMD control word with cleared exception masks.

Set exception masks

C/C++simd_ctrl_t SetExceptionMasks (simd_ctrl_t cword, int exceptions);

Description: Sets selected exception masks into the SIMD control word.

Parameters:

Return value: SIMD control word with new exception masks.

Get exception masks

C/C++int GetExceptionMasks (simd_ctrl_t cword, int exceptions);

Description: Extracts selected exception masks from the SIMD control word.

Parameters:

Return value: Bit set of exception masks (see exception masks).

SIMD flush to zero mode

Flush to zero flag enables the flush-to-zero mode, which controls the masked response to a SIMD floating-point underflow condition. When the underflow exception is masked and the flush-to-zero mode is enabled, the processor performs the following operations when it detects a floating-point underflow condition: returns a zero result with the sign of the true result; sets the precision and underflow exception flags. If the underflow exception is not masked, the flush-to-zero bit is ignored.

The flush-to-zero mode is not compatible with IEEE Standard 754. The IEEE-mandated masked response to underflow is to deliver the denormalized result. The flush-to-zero mode is provided primarily for performance reasons. At the cost of a slight precision loss, faster execution can be achieved for applications where underflows are common and rounding the underflow result to zero can be tolerated.

Clear flush to zero flag

C/C++simd_ctrl_t ClearFlushToZeroFlag (simd_ctrl_t cword);

Description: Clears flush to zero flag into the SIMD control word.

Parameters:

  • cword - SIMD control word

Return value: SIMD control word with cleared flush to zero flag.

Set flush to zero flag

C/C++simd_ctrl_t SetFlushToZeroFlag (simd_ctrl_t cword);

Description: Sets flush to zero flag into the SIMD control word.

Parameters:

  • cword - SIMD control word

Return value: SIMD control word with set flush to zero flag.

Get flush to zero flag

C/C++bool GetFlushToZeroFlag (simd_ctrl_t cword);

Description: Extracts flush to zero flag from the SIMD control word.

Parameters:

  • cword - SIMD control word

Return value: Flush to zero flag.

SIMD denormals are zeros

Denormals are zeros flag enables the denormals-are-zeros mode, which controls the processor’s response to a SIMD floating-point denormal operand condition. When the flag is set, the processor converts all denormal source operands to a zero with the sign of the original operand before performing any computations on them. The processor does not set the denormal-operand exception flag (DE), regardless of the setting of the denormal-operand exception mask bit (DM); and it does not generate a denormal-operand exception if the exception is unmasked.

The denormals-are-zeros mode is not compatible with IEEE Standard 754. This mode is provided to improve processor performance for applications such as streaming media processing, where rounding a denormal operand to zero does not appreciably affect the quality of the processed data.

Clear denormals are zeros flag

C/C++simd_ctrl_t ClearDenormalsAreZerosFlag (simd_ctrl_t cword);

Description: Clears denormals are zeros flag into the SIMD control word.

Parameters:

  • cword - SIMD control word

Return value: SIMD control word with cleared denormals are zeros flag.

Set denormals are zeros flag

C/C++simd_ctrl_t SetDenormalsAreZerosFlag (simd_ctrl_t cword);

Description: Sets denormals are zeros flag into the SIMD control word.

Parameters:

  • cword - SIMD control word

Return value: SIMD control word with set denormals are zeros flag.

Get denormals are zeros flag

C/C++bool GetDenormalsAreZerosFlag (simd_ctrl_t cword);

Description: Extracts denormals are zeros flag from the SIMD control word.

Parameters:

  • cword - SIMD control word

Return value: Denormals are zeros flag.

SIMD status functions

SIMD status word has exception bits which indicate whether a SIMD floating-point exception has been detected. They are "sticky" flags. That is, after a flag is set, it remains set until explicitly cleared.

Clear SIMD exceptions

Cvoid SIMD_ClearExceptions (void);
C++void SIMD::ClearExceptions (void);

Description: Clears all floating-point exception flags of the SIMD device.

Parameters: None.

Return value: None.

Get SIMD status

Csimd_stat_t SIMD_GetStatus (void);
C++simd_stat_t SIMD::GetStatus (void);

Description: Returns current value of the SIMD status word.

Parameters: None.

Return value: SIMD status word.

SIMD exception flags

C/C++int GetExceptions (simd_stat_t sword, int exceptions);

Description: The six floating-point exception flags of the SIMD status word indicate that one or more floating-point exceptions have been detected since the bits were last cleared. Each of the exception flags can be masked by an exception mask bit in the SIMD control word. This function extracts selected exception flags from the SIMD status word.

Parameters:

Return value: Bit set of SIMD exception flags (see exception flags).

Copyright 2012-2016 Jack Black. All rights reserved.