1 //===-- RegisterValue.cpp ---------------------------------------*- 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 #include "RegisterValue.h"
10 #include "llvm/ADT/APFloat.h"
11 #include "llvm/ADT/StringRef.h"
12
13 namespace llvm {
14 namespace exegesis {
15
getFloatValue(const fltSemantics & FltSemantics,PredefinedValues Value)16 static APFloat getFloatValue(const fltSemantics &FltSemantics,
17 PredefinedValues Value) {
18 switch (Value) {
19 case PredefinedValues::POS_ZERO:
20 return APFloat::getZero(FltSemantics);
21 case PredefinedValues::NEG_ZERO:
22 return APFloat::getZero(FltSemantics, true);
23 case PredefinedValues::ONE:
24 return APFloat(FltSemantics, "1");
25 case PredefinedValues::TWO:
26 return APFloat(FltSemantics, "2");
27 case PredefinedValues::INF:
28 return APFloat::getInf(FltSemantics);
29 case PredefinedValues::QNAN:
30 return APFloat::getQNaN(FltSemantics);
31 case PredefinedValues::SMALLEST_NORM:
32 return APFloat::getSmallestNormalized(FltSemantics);
33 case PredefinedValues::LARGEST:
34 return APFloat::getLargest(FltSemantics);
35 case PredefinedValues::ULP:
36 return APFloat::getSmallest(FltSemantics);
37 case PredefinedValues::ONE_PLUS_ULP:
38 auto Output = getFloatValue(FltSemantics, PredefinedValues::ONE);
39 Output.next(false);
40 return Output;
41 }
42 llvm_unreachable("Unhandled exegesis::PredefinedValues");
43 }
44
bitcastFloatValue(const fltSemantics & FltSemantics,PredefinedValues Value)45 APInt bitcastFloatValue(const fltSemantics &FltSemantics,
46 PredefinedValues Value) {
47 return getFloatValue(FltSemantics, Value).bitcastToAPInt();
48 }
49
50 } // namespace exegesis
51 } // namespace llvm
52