_mm_round_ps
Microsoft Specific
Emits the Streaming SIMD Extensions 4 (SSE4) instruction roundps. This instruction rounds a 32 bit value by using the specified rounding control.
__m128 _mm_round_ps(
__m128 a,
const int cntrl
);
Parameters
[in] a
A 128-bit parameter that contains four 32-bit floating point values.[in] cntrl
A constant that specifies control fields for the rounding operation.
Return value
A 128-bit parameter. The result can be expressed with the following equations:.
r0 := RND(a0)
r1 := RND(a1)
r2 := RND(a2)
r3 := RND(a3)
Requirements
Intrinsic |
Architecture |
---|---|
_mm_round_ps |
x86, x64 |
Header file <smmintrin.h>
Remarks
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 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.
Example
#include <stdio.h>
#include <smmintrin.h>
int main ()
{
__m128 a;
const int cntrl = _MM_FROUND_FLOOR;
a.m128_f32[0] = 9.9375;
a.m128_f32[1] = 5964.125;
a.m128_f32[2] = -237.875;
a.m128_f32[3] = -0.125;
__m128 res = _mm_round_ps(a, cntrl);
printf_s("Original a: %f\t%f\t%f\t%f\n",
a.m128_f32[0], a.m128_f32[1], a.m128_f32[2], a.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: 9.937500 5964.125000 -237.875000 -0.125000
Result res: 9.000000 5964.000000 -238.000000 -1.000000