xref: /aosp_15_r20/external/llvm-libc/src/__support/FPUtil/aarch64/nearest_integer.h (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===--- Round floating point to nearest integer on aarch64 -----*- 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 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_AARCH64_NEAREST_INTEGER_H
10 #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_AARCH64_NEAREST_INTEGER_H
11 
12 #include "src/__support/common.h"
13 #include "src/__support/macros/config.h"
14 #include "src/__support/macros/properties/architectures.h"
15 
16 #if !defined(LIBC_TARGET_ARCH_IS_AARCH64)
17 #error "Invalid include"
18 #endif
19 
20 namespace LIBC_NAMESPACE_DECL {
21 namespace fputil {
22 
nearest_integer(float x)23 LIBC_INLINE float nearest_integer(float x) {
24   float result;
25   __asm__ __volatile__("frintn %s0, %s1\n\t" : "=w"(result) : "w"(x));
26   return result;
27 }
28 
nearest_integer(double x)29 LIBC_INLINE double nearest_integer(double x) {
30   double result;
31   __asm__ __volatile__("frintn %d0, %d1\n\t" : "=w"(result) : "w"(x));
32   return result;
33 }
34 
35 } // namespace fputil
36 } // namespace LIBC_NAMESPACE_DECL
37 
38 #endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_AARCH64_NEAREST_INTEGER_H
39