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
- SIMD constants
- SIMD rounding modes
- SIMD exception masks
- SIMD exception flags
- SIMD data types
- SIMD control functions
- Init SIMD
- Set SIMD mode
- Get SIMD mode
- SIMD rounding mode
- Set round mode
- Get round mode
- SIMD exception masks
- Clear exception masks
- Set exception masks
- Get exception masks
- SIMD flush to zero mode
- Clear flush to zero flag
- Set flush to zero flag
- Get flush to zero flag
- SIMD denormals are zeros
- Clear denormals are zeros flag
- Set denormals are zeros flag
- Get denormals are zeros flag
- SIMD status functions
- Clear SIMD exceptions
- Get SIMD status
- SIMD exception flags
Function list
C function name | Functions | C++ function name | Functions |
---|---|---|---|
ClearDenormalsAreZerosFlag | 1 function | ClearDenormalsAreZerosFlag | 1 function |
ClearExceptionMasks | 1 function | ClearExceptionMasks | 1 function |
ClearExceptions | 1 function | ClearExceptions | 1 function |
ClearFlushToZeroFlag | 1 function | ClearFlushToZeroFlag | 1 function |
GetDenormalsAreZerosFlag | 1 function | GetDenormalsAreZerosFlag | 1 function |
GetExceptionMasks | 1 function | GetExceptionMasks | 1 function |
GetExceptions | 1 function | GetExceptions | 1 function |
GetFlushToZeroFlag | 1 function | GetFlushToZeroFlag | 1 function |
GetMode | 1 function | GetMode | 1 function |
GetRoundMode | 1 function | GetRoundMode | 1 function |
GetStatus | 1 function | GetStatus | 1 function |
Init | 1 function | Init | 1 function |
SetDenormalsAreZerosFlag | 1 function | SetDenormalsAreZerosFlag | 1 function |
SetExceptionMasks | 1 function | SetExceptionMasks | 1 function |
SetFlushToZeroFlag | 1 function | SetFlushToZeroFlag | 1 function |
SetMode | 1 function | SetMode | 1 function |
SetRoundMode | 1 function | SetRoundMode | 1 function |
C function name | Functions | C++ function name | Functions |
SIMD constants
SIMD data types
Type | Description | C/C++ equivalent |
---|---|---|
simd_ctrl_t | SIMD control word | int |
simd_stat_t | SIMD status word | int |
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:
- cword - SIMD control word
- rmode - new round mode value (see available modes)
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:
- cword - SIMD control word
- exceptions - exception masks to clear (see available exceptions)
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:
- cword - SIMD control word
- exceptions - exception masks to set (see available exceptions)
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:
- cword - SIMD control word
- exceptions - exception masks to extract (see available exceptions)
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:
- sword - SIMD status word
- exceptions - exception flags to extract (see available exceptions)
Return value: Bit set of SIMD exception flags (see exception flags).