_mm_round_ss
Microsoft Specific
Emits the Streaming SIMD Extensions 4 (SSE4) instruction roundss. This instruction rounds a 32-bit value and inserts the result into a 128-bit parameter.
__m128 _mm_round_ss( __m128 a, __m128 b, const int cntrl );
r0-r3, a0-a3, and b0-b3 are the sequentially ordered 32-bit components of return value r and parameters a and b, respectively. r0, a0, and b0 are the least significant 32 bits.
The rounding function uses the cntrl parameter to determine how to compute a new value. The following table indicates what rounding mode will be used.
Rounding mode | Value | Description |
|---|---|---|
_MM_FROUND_TO_NEAREST_INT | 0x0 | Round to nearest (even). |
_MM_FROUND_TO_NEG_INF | 0x1 | Round down (toward -∞). |
_MM_FROUND_TO_POS_INF | 0x2 | Round up (toward +∞). |
_MM_FROUND_TO_ZERO | 0x3 | Round toward zero (truncate). |
_MM_FROUND_CUR_DIRECTION | 0x4 | Use current MXCSR setting. |
This table shows how cntrl determines whether an exception should be signaled when a SNaN is detected.
Precision exception handling | Value | Description |
|---|---|---|
_MM_FROUND_RAISE_EXC | 0x0 | Signal precision exception on Signaling Not a Number (SNaN). |
_MM_FROUND_NO_EXC | 0x8 | Do not signal precision exception on SNaN. |
The following macros are also available to combine the above two fields:
Rounding mode and precision exception handling | Value |
|---|---|
_MM_FROUND_NINT | MM_FROUND_TO_NEAREST_INT | _MM_FROUND_RAISE_EXC |
_MM_FROUND_FLOOR | _MM_FROUND_TO_NEG_INF | _MM_FROUND_RAISE_EXC |
_MM_FROUND_CEIL | _MM_FROUND_TO_POS_INF | _MM_FROUND_RAISE_EXC |
_MM_FROUND_TRUNC | _MM_FROUND_TO_ZERO | _MM_FROUND_RAISE_EXC |
_MM_FROUND_RINT | _MM_FROUND_CUR_DIRECTION | _MM_FROUND_RAISE_EXC |
_MM_FROUND_NEARBYINT | _MM_FROUND_CUR_DIRECTION | _MM_FROUND_NO_EXC |
Before you use this intrinsic, software must ensure that the underlying processor supports the instruction.
#include <stdio.h>
#include <smmintrin.h>
int main ()
{
__m128 a, b;
const int cntrl = _MM_FROUND_TRUNC;
a.m128_f32[0] = 0.0;
a.m128_f32[1] = 501.125;
a.m128_f32[2] = -793.5;
a.m128_f32[3] = 8560.125;
b.m128_f32[0] = 5.5;
b.m128_f32[1] = 0.0;
b.m128_f32[2] = 0.0;
b.m128_f32[3] = 0.0;
__m128 res = _mm_round_ss(a, b, cntrl);
printf_s("Original a: %f\t%f\t%f\t%f\nOriginal b: %f\t%f\t%f\t%f\n",
a.m128_f32[0], a.m128_f32[1], a.m128_f32[2], a.m128_f32[3],
b.m128_f32[0], b.m128_f32[1], b.m128_f32[2], b.m128_f32[3]);
printf_s("Result res: %f\t%f\t%f\t%f\n",
res.m128_f32[0], res.m128_f32[1], res.m128_f32[2], res.m128_f32[3]);
return 0;
}
Original a: 0.000000 501.125000 -793.500000 8560.125000 Original b: 5.500000 0.000000 0.000000 0.000000 Result res: 5.000000 501.125000 -793.500000 8560.125000