RegisterValue.cpp 1.7 KB

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