0018-add-customer-pref-support.patch 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. From 3514789d54fb3515547a29405596d4f2cddd4585 Mon Sep 17 00:00:00 2001
  2. From: "max.ma" <max.ma@starfivetech.com>
  3. Date: Mon, 5 Sep 2022 01:17:31 -0700
  4. Subject: [PATCH 18/20] add customer pref support
  5. ---
  6. gas/config/tc-riscv.c | 44 +++++++++++++++++++++++++++++++++++++-
  7. include/opcode/riscv-opc.h | 3 +++
  8. include/opcode/riscv.h | 9 ++++++++
  9. opcodes/riscv-dis.c | 10 +++++++++
  10. opcodes/riscv-opc.c | 1 +
  11. 5 files changed, 66 insertions(+), 1 deletion(-)
  12. diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
  13. index a0e8456a0d..934eddc811 100644
  14. --- a/gas/config/tc-riscv.c
  15. +++ b/gas/config/tc-riscv.c
  16. @@ -1201,7 +1201,9 @@ validate_riscv_insn (const struct riscv_opcode *opc, int length)
  17. case ')': break;
  18. case '<': USE_BITS (OP_MASK_SHAMTW, OP_SH_SHAMTW); break;
  19. case '>': USE_BITS (OP_MASK_SHAMT, OP_SH_SHAMT); break;
  20. - case 'A': break; /* Macro operand, must be symbol. */
  21. + case '#': used_bits |= ENCODE_PREF_TIMM (-1U); break;
  22. + case '+': used_bits |= ENCODE_PREF_SIMM (-1U); break;
  23. + case 'A': break; /* Macro operand, must be symbol. */
  24. case 'B': break; /* Macro operand, must be symbol or constant. */
  25. case 'I': break; /* Macro operand, must be constant. */
  26. case 'D': /* RD, floating point. */
  27. @@ -1600,6 +1602,27 @@ check_absolute_expr (struct riscv_cl_insn *ip, expressionS *ex,
  28. normalize_constant_expr (ex);
  29. }
  30. +/* The pref type should be one of the following:
  31. + 0000 - scalar prefetch L1, fetch data as if for a normal scalar load,
  32. + and imply load into all lower cache destination levels.
  33. + 0001 - scalar prefetch L2, fetch data and place the cache-line into L2,
  34. + and imply load into all lower cache destination levels.
  35. + 0010 - scalar prefetch L3, fetch data and place the cache-line into L3,
  36. + and imply load into all lower cache destination levels.
  37. + 0011 - scalar prefetch L4, fetch data and place the cache-line into L4,
  38. + and imply load into all lower cache destination levels
  39. + (if the L5 is in the cache heirarchy).
  40. + 1000 - vector prefetch L1, fetch data as if for a normal scalar load
  41. + but place the cache-line into vector buffer (vector L1) ,
  42. + and imply load into all lower cache destination levels.
  43. +*/
  44. +
  45. +static bfd_boolean check_pref_type(unsigned long type)
  46. +{
  47. + if (type != 0 && type != 1 && type != 2 && type != 3 && type != 8)
  48. + as_bad (_("Improper pref type (%lu)"), type);
  49. +}
  50. +
  51. static symbolS *
  52. make_internal_label (void)
  53. {
  54. @@ -2906,6 +2929,25 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
  55. asarg = expr_end;
  56. continue;
  57. + case '#':
  58. + my_getExpression (imm_expr, asarg);
  59. + check_pref_type((unsigned long)imm_expr->X_add_number);
  60. + INSERT_OPERAND (PREF_TYPE, *ip, imm_expr->X_add_number);
  61. + imm_expr->X_op = O_absent;
  62. + asarg = expr_end;
  63. + continue;
  64. +
  65. + case '+':
  66. + my_getExpression (imm_expr, asarg);
  67. + check_absolute_expr (ip, imm_expr, FALSE);
  68. + if (imm_expr->X_add_number > 127 || imm_expr->X_add_number < -128)
  69. + as_bad (_("Improper pref offset value (%d)"),
  70. + (long) imm_expr->X_add_number);
  71. + INSERT_OPERAND (PREF_OFFSET, *ip, imm_expr->X_add_number);
  72. + imm_expr->X_op = O_absent;
  73. + asarg = expr_end;
  74. + continue;
  75. +
  76. case 'E': /* Control register. */
  77. insn_with_csr = true;
  78. explicit_priv_attr = true;
  79. diff --git a/include/opcode/riscv-opc.h b/include/opcode/riscv-opc.h
  80. index 88b8d7ff59..6f08c72c88 100644
  81. --- a/include/opcode/riscv-opc.h
  82. +++ b/include/opcode/riscv-opc.h
  83. @@ -255,6 +255,7 @@
  84. #define MASK_SFENCE_VMA 0xfe007fff
  85. #define MATCH_WFI 0x10500073
  86. #define MASK_WFI 0xffffffff
  87. +#define MASK_CUSTOMER_PREF 0x7fff
  88. #define MATCH_CSRRW 0x1073
  89. #define MASK_CSRRW 0x707f
  90. #define MATCH_CSRRS 0x2073
  91. @@ -2852,6 +2853,8 @@ DECLARE_INSN(cbo_clean, MATCH_CBO_CLEAN, MASK_CBO_CLEAN);
  92. DECLARE_INSN(cbo_flush, MATCH_CBO_FLUSH, MASK_CBO_FLUSH);
  93. DECLARE_INSN(cbo_inval, MATCH_CBO_INVAL, MASK_CBO_INVAL);
  94. DECLARE_INSN(cbo_zero, MATCH_CBO_ZERO, MASK_CBO_ZERO);
  95. +DECLARE_INSN(cbo_zero, MATCH_CBO_ZERO, MASK_CBO_ZERO);
  96. +
  97. #endif /* DECLARE_INSN */
  98. #ifdef DECLARE_CSR
  99. /* Unprivileged Counter/Timers CSRs. */
  100. diff --git a/include/opcode/riscv.h b/include/opcode/riscv.h
  101. index b115e338a0..4afb16c092 100644
  102. --- a/include/opcode/riscv.h
  103. +++ b/include/opcode/riscv.h
  104. @@ -156,6 +156,10 @@ static const char * const riscv_pred_succ[16] =
  105. (RV_X(x, 0, 10) << 20)
  106. #define ENCODE_RVV_VC_IMM(x) \
  107. (RV_X(x, 0, 11) << 20)
  108. +#define ENCODE_PREF_TIMM(x) \
  109. + (RV_X(x, 0, 4) << 20)
  110. +#define ENCODE_PREF_SIMM(x) \
  111. + (RV_X(x, 0, 8) << 24)
  112. #define VALID_ITYPE_IMM(x) (EXTRACT_ITYPE_IMM(ENCODE_ITYPE_IMM(x)) == (x))
  113. #define VALID_STYPE_IMM(x) (EXTRACT_STYPE_IMM(ENCODE_STYPE_IMM(x)) == (x))
  114. @@ -256,6 +260,11 @@ static const char * const riscv_pred_succ[16] =
  115. #define OP_MASK_FUNCT2 0x3
  116. #define OP_SH_FUNCT2 25
  117. +#define OP_MASK_PREF_TYPE 0x0f
  118. +#define OP_SH_PREF_TYPE 20
  119. +#define OP_MASK_PREF_OFFSET 0xff
  120. +#define OP_SH_PREF_OFFSET 24
  121. +
  122. /* RVC fields. */
  123. #define OP_MASK_OP2 0x3
  124. diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
  125. index 164fd209db..9a9660cf21 100644
  126. --- a/opcodes/riscv-dis.c
  127. +++ b/opcodes/riscv-dis.c
  128. @@ -490,6 +490,16 @@ print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info
  129. (int)EXTRACT_OPERAND (SHAMTW, l));
  130. break;
  131. + case '#':
  132. + print (info->stream, dis_style_immediate, "0x%x",
  133. + (int)EXTRACT_OPERAND (PREF_TYPE, l));
  134. + break;
  135. +
  136. + case '+':
  137. + print (info->stream, dis_style_immediate, "0x%x",
  138. + (int)EXTRACT_OPERAND (PREF_OFFSET, l));
  139. + break;
  140. +
  141. case 'S':
  142. case 'U':
  143. print (info->stream, dis_style_register, "%s", riscv_fpr_names[rs1]);
  144. diff --git a/opcodes/riscv-opc.c b/opcodes/riscv-opc.c
  145. index 2f9945aa93..5632408ebd 100644
  146. --- a/opcodes/riscv-opc.c
  147. +++ b/opcodes/riscv-opc.c
  148. @@ -401,6 +401,7 @@ const struct riscv_opcode riscv_opcodes[] =
  149. {"snez", 0, INSN_CLASS_I, "d,t", MATCH_SLTU, MASK_SLTU|MASK_RS1, match_opcode, INSN_ALIAS },
  150. {"sltz", 0, INSN_CLASS_I, "d,s", MATCH_SLT, MASK_SLT|MASK_RS2, match_opcode, INSN_ALIAS },
  151. {"sgtz", 0, INSN_CLASS_I, "d,t", MATCH_SLT, MASK_SLT|MASK_RS1, match_opcode, INSN_ALIAS },
  152. +{"pref", 0, INSN_CLASS_I, "#,+(s)", MATCH_SLTI, MASK_CUSTOMER_PREF, match_opcode, INSN_ALIAS },
  153. {"slti", 0, INSN_CLASS_I, "d,s,j", MATCH_SLTI, MASK_SLTI, match_opcode, 0 },
  154. {"slt", 0, INSN_CLASS_I, "d,s,t", MATCH_SLT, MASK_SLT, match_opcode, 0 },
  155. {"slt", 0, INSN_CLASS_I, "d,s,j", MATCH_SLTI, MASK_SLTI, match_opcode, INSN_ALIAS },
  156. --
  157. 2.25.1