[NFC][Py Reformat] Added more commits to .git-blame-ignore-revs
[llvm-project.git] / libc / src / __support / FPUtil / x86_64 / nearest_integer.h
blob4541dbf10dc567e29592d4a356c3b1b273957a43
1 //===--- Round floating point to nearest integer on x86-64 ------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_NEAREST_INTEGER_H
10 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_NEAREST_INTEGER_H
12 #include "src/__support/common.h"
13 #include "src/__support/macros/properties/architectures.h"
15 #if !defined(LIBC_TARGET_ARCH_IS_X86_64)
16 #error "Invalid include"
17 #endif
19 #if !defined(__SSE4_2__)
20 #error "SSE4.2 instruction set is not supported"
21 #endif
23 #include <immintrin.h>
25 namespace __llvm_libc {
26 namespace fputil {
28 LIBC_INLINE float nearest_integer(float x) {
29 __m128 xmm = _mm_set_ss(x); // NOLINT
30 __m128 ymm =
31 _mm_round_ss(xmm, xmm, _MM_ROUND_NEAREST | _MM_FROUND_NO_EXC); // NOLINT
32 return ymm[0];
35 LIBC_INLINE double nearest_integer(double x) {
36 __m128d xmm = _mm_set_sd(x); // NOLINT
37 __m128d ymm =
38 _mm_round_sd(xmm, xmm, _MM_ROUND_NEAREST | _MM_FROUND_NO_EXC); // NOLINT
39 return ymm[0];
42 } // namespace fputil
43 } // namespace __llvm_libc
45 #endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_NEAREST_INTEGER_H