_mm_round_sd
Microsoft Specific
Emits the Streaming SIMD Extensions 4 (SSE4) instruction roundsd. This instruction rounds a 64-bit value by using the specified rounding control.
__m128d _mm_round_sd(
__m128d a,
__m128d b,
const int cntrl
);
Parameters
[in] a
A 128-bit parameter that contains two 64-bit floating point values.[in] b
A 128-bit parameter that contains a floating point value in the lowest 64 bits.[in] cntrl
A constant that specifies control fields for the rounding operation.
Return value
A 128-bit parameter. The lowest 64 bits are the result of the rounding function on b0. The higher order 64 bits are copied directly from input parameter a. The return value is described by the following equations:
r0 := RND(b0)
r1 := a1
Requirements
Intrinsic |
Architecture |
---|---|
_mm_round_sd |
x86, x64 |
Header file <smmintrin.h>
Remarks
r0-r1, a0-a1, and b0-b1 are the sequentially ordered 64-bit components of return value r and parameters a and b, respectively. r0, a0, and b0 are the least significant 64 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 ()
{
__m128d a, b;
const int cntrl = _MM_FROUND_CEIL;
a.m128d_f64[0] = 0.0;
a.m128d_f64[1] = -550.0625;
b.m128d_f64[0] = 4.125;
b.m128d_f64[1] = 0.0;
__m128d res = _mm_round_sd(a, b, cntrl);
printf_s("Original a: %f\t%f\n", a.m128d_f64[0], a.m128d_f64[1]);
printf_s("Original b: %f\t%f\n", b.m128d_f64[0], b.m128d_f64[1]);
printf_s("Result res: %f\t%f\n", res.m128d_f64[0], res.m128d_f64[1]);
return 0;
}
Original a: 0.000000 -550.062500 Original b: 4.125000 0.000000 Result res: 5.000000 -550.062500