LoongArchMatInt.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //===- LoongArchMatInt.cpp - Immediate materialisation ---------*- 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 "LoongArchMatInt.h"
  9. #include "MCTargetDesc/LoongArchMCTargetDesc.h"
  10. #include "llvm/Support/MathExtras.h"
  11. using namespace llvm;
  12. LoongArchMatInt::InstSeq LoongArchMatInt::generateInstSeq(int64_t Val) {
  13. // Val:
  14. // | hi32 | lo32 |
  15. // +-----------+------------------+------------------+-----------+
  16. // | Highest12 | Higher20 | Hi20 | Lo12 |
  17. // +-----------+------------------+------------------+-----------+
  18. // 63 52 51 32 31 12 11 0
  19. //
  20. const int64_t Highest12 = Val >> 52 & 0xFFF;
  21. const int64_t Higher20 = Val >> 32 & 0xFFFFF;
  22. const int64_t Hi20 = Val >> 12 & 0xFFFFF;
  23. const int64_t Lo12 = Val & 0xFFF;
  24. InstSeq Insts;
  25. if (Highest12 != 0 && SignExtend64<52>(Val) == 0) {
  26. Insts.push_back(Inst(LoongArch::LU52I_D, SignExtend64<12>(Highest12)));
  27. return Insts;
  28. }
  29. if (Hi20 == 0)
  30. Insts.push_back(Inst(LoongArch::ORI, Lo12));
  31. else if (SignExtend32<1>(Lo12 >> 11) == SignExtend32<20>(Hi20))
  32. Insts.push_back(Inst(LoongArch::ADDI_W, SignExtend64<12>(Lo12)));
  33. else {
  34. Insts.push_back(Inst(LoongArch::LU12I_W, SignExtend64<20>(Hi20)));
  35. if (Lo12 != 0)
  36. Insts.push_back(Inst(LoongArch::ORI, Lo12));
  37. }
  38. if (SignExtend32<1>(Hi20 >> 19) != SignExtend32<20>(Higher20))
  39. Insts.push_back(Inst(LoongArch::LU32I_D, SignExtend64<20>(Higher20)));
  40. if (SignExtend32<1>(Higher20 >> 19) != SignExtend32<12>(Highest12))
  41. Insts.push_back(Inst(LoongArch::LU52I_D, SignExtend64<12>(Highest12)));
  42. return Insts;
  43. }