aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm12/tools/llvm-exegesis/lib/RegisterValue.cpp
blob: f881aa6d5388c3c4d34dc982d144661d08eaca83 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//===-- RegisterValue.cpp ---------------------------------------*- C++ -*-===//
//
// 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 "RegisterValue.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/StringRef.h"

namespace llvm {
namespace exegesis {

static APFloat getFloatValue(const fltSemantics &FltSemantics,
                             PredefinedValues Value) {
  switch (Value) {
  case PredefinedValues::POS_ZERO:
    return APFloat::getZero(FltSemantics);
  case PredefinedValues::NEG_ZERO:
    return APFloat::getZero(FltSemantics, true);
  case PredefinedValues::ONE:
    return APFloat(FltSemantics, "1");
  case PredefinedValues::TWO:
    return APFloat(FltSemantics, "2");
  case PredefinedValues::INF:
    return APFloat::getInf(FltSemantics);
  case PredefinedValues::QNAN:
    return APFloat::getQNaN(FltSemantics);
  case PredefinedValues::SMALLEST_NORM:
    return APFloat::getSmallestNormalized(FltSemantics);
  case PredefinedValues::LARGEST:
    return APFloat::getLargest(FltSemantics);
  case PredefinedValues::ULP:
    return APFloat::getSmallest(FltSemantics);
  case PredefinedValues::ONE_PLUS_ULP:
    auto Output = getFloatValue(FltSemantics, PredefinedValues::ONE);
    Output.next(false);
    return Output;
  }
  llvm_unreachable("Unhandled exegesis::PredefinedValues");
}

APInt bitcastFloatValue(const fltSemantics &FltSemantics,
                        PredefinedValues Value) {
  return getFloatValue(FltSemantics, Value).bitcastToAPInt();
}

} // namespace exegesis
} // namespace llvm