[llvm-exegesis] Implements a cache of Instruction objects.
[llvm-core.git] / tools / llvm-exegesis / lib / RegisterValue.cpp
blob2bf996cead48dbf91a422cb318ca3edfb57a647d
1 //===-- RegisterValue.cpp ---------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "RegisterValue.h"
11 #include "llvm/ADT/APFloat.h"
13 namespace llvm {
14 namespace exegesis {
16 static llvm::APFloat getFloatValue(const llvm::fltSemantics &FltSemantics,
17 PredefinedValues Value) {
18 switch (Value) {
19 case PredefinedValues::POS_ZERO:
20 return llvm::APFloat::getZero(FltSemantics);
21 case PredefinedValues::NEG_ZERO:
22 return llvm::APFloat::getZero(FltSemantics, true);
23 case PredefinedValues::ONE:
24 return llvm::APFloat(FltSemantics, "1");
25 case PredefinedValues::TWO:
26 return llvm::APFloat(FltSemantics, "2");
27 case PredefinedValues::INF:
28 return llvm::APFloat::getInf(FltSemantics);
29 case PredefinedValues::QNAN:
30 return llvm::APFloat::getQNaN(FltSemantics);
31 case PredefinedValues::SMALLEST_NORM:
32 return llvm::APFloat::getSmallestNormalized(FltSemantics);
33 case PredefinedValues::LARGEST:
34 return llvm::APFloat::getLargest(FltSemantics);
35 case PredefinedValues::ULP:
36 return llvm::APFloat::getSmallest(FltSemantics);
37 case PredefinedValues::ONE_PLUS_ULP:
38 auto Output = getFloatValue(FltSemantics, PredefinedValues::ONE);
39 Output.next(false);
40 return Output;
42 llvm_unreachable("Unhandled exegesis::PredefinedValues");
45 llvm::APInt bitcastFloatValue(const llvm::fltSemantics &FltSemantics,
46 PredefinedValues Value) {
47 return getFloatValue(FltSemantics, Value).bitcastToAPInt();
50 } // namespace exegesis
51 } // namespace llvm