diff options
| author | Matthias Springer <me@m-sp.org> | 2025-11-04 23:45:35 +0000 |
|---|---|---|
| committer | Matthias Springer <me@m-sp.org> | 2025-11-05 12:29:25 +0000 |
| commit | f3d28c4ffd949c6b2807d165b20184ead6445da9 (patch) | |
| tree | d6c65ac461b9cf36c8d8be0c9012a63904ba3898 /mlir/lib/ExecutionEngine/APFloatWrappers.cpp | |
| parent | 6c640b86e6e03298385231cb7e77d2f3524bc643 (diff) | |
Prototype: APFloat CPU runnerusers/matthias-springer/apfloat_runner
Diffstat (limited to 'mlir/lib/ExecutionEngine/APFloatWrappers.cpp')
| -rw-r--r-- | mlir/lib/ExecutionEngine/APFloatWrappers.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/mlir/lib/ExecutionEngine/APFloatWrappers.cpp b/mlir/lib/ExecutionEngine/APFloatWrappers.cpp new file mode 100644 index 000000000000..7879c7580335 --- /dev/null +++ b/mlir/lib/ExecutionEngine/APFloatWrappers.cpp @@ -0,0 +1,40 @@ +//===- ArmRunnerUtils.cpp - Utilities for configuring architecture properties // +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/APFloat.h" +#include <iostream> + +#if (defined(_WIN32) || defined(__CYGWIN__)) +#define MLIR_APFLOAT_WRAPPERS_EXPORTED __declspec(dllexport) +#else +#define MLIR_APFLOAT_WRAPPERS_EXPORTED __attribute__((visibility("default"))) +#endif + +extern "C" { + +int64_t MLIR_APFLOAT_WRAPPERS_EXPORTED APFloat_add(int32_t semantics, + uint64_t a, uint64_t b) { + const llvm::fltSemantics &sem = llvm::APFloatBase::EnumToSemantics( + static_cast<llvm::APFloatBase::Semantics>(semantics)); + unsigned bitWidth = llvm::APFloatBase::semanticsSizeInBits(sem); + llvm::APFloat lhs(sem, llvm::APInt(bitWidth, a)); + llvm::APFloat rhs(sem, llvm::APInt(bitWidth, b)); + auto status = lhs.add(rhs, llvm::RoundingMode::NearestTiesToEven); + return lhs.bitcastToAPInt().getZExtValue(); +} + +void MLIR_APFLOAT_WRAPPERS_EXPORTED printApFloat(int32_t semantics, + uint64_t a) { + const llvm::fltSemantics &sem = llvm::APFloatBase::EnumToSemantics( + static_cast<llvm::APFloatBase::Semantics>(semantics)); + unsigned bitWidth = llvm::APFloatBase::semanticsSizeInBits(sem); + llvm::APFloat x(sem, llvm::APInt(bitWidth, a)); + double d = x.convertToDouble(); + std::cout << d << std::endl; +} +} |
