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/architectures.h"
13 
14 #if !defined(LLVM_LIBC_ARCH_AARCH64)
15 #error "Invalid include"
16 #endif
17 
18 namespace __llvm_libc {
19 namespace fputil {
20 
nearest_integer(float x)21 static inline float nearest_integer(float x) {
22   float result;
23   __asm__ __volatile__("frintn %s0, %s1\n\t" : "=w"(result) : "w"(x));
24   return result;
25 }
26 
nearest_integer(double x)27 static inline double nearest_integer(double x) {
28   double result;
29   __asm__ __volatile__("frintn %d0, %d1\n\t" : "=w"(result) : "w"(x));
30   return result;
31 }
32 
33 } // namespace fputil
34 } // namespace __llvm_libc
35 
36 #endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_NEAREST_INTEGER_H
37