cpubase.pas 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Contains the base types for the Risc-V32
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. { This Unit contains the base types for the Risc-V32
  18. }
  19. unit cpubase;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. strings,globtype,
  24. cutils,cclasses,aasmbase,cpuinfo,cgbase;
  25. {*****************************************************************************
  26. Assembler Opcodes
  27. *****************************************************************************}
  28. type
  29. TAsmOp=(A_None,
  30. { Pseudo instructions }
  31. A_NOP,A_CALL,A_LA,A_LLA,A_LGA,A_LI,A_MV,A_NOT,A_NEG,A_NEGW,
  32. A_SEXT_B,A_SEXT_H,A_ZEXT_B,A_ZEXT_H,A_SEQZ,A_SNEG,A_SLTZ,A_SGTZ,
  33. A_FMV_S,A_FABS_S,A_FNEG_S,A_FMV_D,A_FABS_D,A_FNEG_D,A_FNEG_Q,
  34. A_BEQZ,A_BNEZ,A_BLEZ,A_BGEZ,A_BLTZ,A_BGTZ,A_BGT,A_BLE,
  35. A_BGTU,A_BLEU,A_J,A_JR,A_RET,A_TAIL,
  36. { normal opcodes }
  37. A_LUI,A_AUIPC,A_JAL,A_JALR,
  38. A_Bxx,A_LB,A_LH,A_LW,A_LBU,A_LHU,
  39. A_SB,A_SH,A_SW,
  40. A_ADDI,A_SLTI,A_SLTIU,
  41. A_XORI,A_ORI,A_ANDI,
  42. A_SLLI,A_SRLI,A_SRAI,
  43. A_ADD,A_SUB,A_SLL,A_SLT,A_SLTU,
  44. A_XOR,A_SRL,A_SRA,A_OR,A_AND,
  45. A_FENCE,A_FENCE_I,
  46. A_ECALL,A_EBREAK,
  47. A_CSRRW,A_CSRRS,A_CSRRC,A_CSRRWI,A_CSRRSI,A_CSRRCI,
  48. {$ifdef RISCV64}
  49. { 64-bit }
  50. A_ADDIW,A_SLLIW,A_SRLIW,A_SRAIW,
  51. A_ADDW,A_SLLW,A_SRLW,A_SUBW,A_SRAW,
  52. A_LD,A_SD,A_LWU,A_SEXT_W,A_ZEXT_W,
  53. {$endif RISCV64}
  54. { M-extension }
  55. A_MUL,A_MULH,A_MULHSU,A_MULHU,
  56. A_DIV,A_DIVU,A_REM,A_REMU,
  57. {$ifdef RISCV64}
  58. { 64-bit }
  59. A_MULW,
  60. A_DIVW,A_DIVUW,A_REMW,A_REMUW,
  61. {$endif RISCV64}
  62. { A-extension }
  63. A_LR_W,A_SC_W,A_AMOSWAP_W,A_AMOADD_W,A_AMOXOR_W,A_AMOAND_W,
  64. A_AMOOR_W,A_AMOMIN_W,A_AMOMAX_W,A_AMOMINU_W,A_AMOMAXU_W,
  65. {$ifdef RISCV64}
  66. { 64-bit }
  67. A_LR_D,A_SC_D,A_AMOSWAP_D,A_AMOADD_D,A_AMOXOR_D,A_AMOAND_D,
  68. A_AMOOR_D,A_AMOMIN_D,A_AMOMAX_D,A_AMOMINU_D,A_AMOMAXU_D,
  69. {$endif RISCV64}
  70. { B-extension }
  71. A_ADD_UW,A_ANDN,A_CLMUL,A_CLMULH,A_CLMULR,A_CLZ,
  72. {$ifdef RISCV64}
  73. A_CLZW,
  74. {$endif RISCV64}
  75. A_CPOP,
  76. {$ifdef RISCV64}
  77. A_CPOPW,
  78. {$endif RISCV64}
  79. A_CTZ,
  80. {$ifdef RISCV64}
  81. A_CTZW,
  82. {$endif RISCV64}
  83. A_MAX,A_MAXU,A_MIN,A_MINU,A_ORC_B,A_ORN,A_REV8,A_ROL,
  84. {$ifdef RISCV64}
  85. A_ROLW,
  86. {$endif RISCV64}
  87. A_ROR,A_RORI,
  88. {$ifdef RISCV64}
  89. A_RORIW,
  90. A_RORW,
  91. {$endif RISCV64}
  92. A_BCLR,A_BCLRI,A_BEXT,A_BEXTI,A_BINV,A_BINVI,A_BSET,A_SETI,{ A_SEXT_B,A_SEXT_H, }
  93. A_SH1ADD,
  94. {$ifdef RISCV64}
  95. A_SH1ADD_UW,
  96. {$endif RISCV64}
  97. A_SH2ADD,
  98. {$ifdef RISCV64}
  99. A_SH2ADD_UW,
  100. {$endif RISCV64}
  101. A_SH3ADD,
  102. {$ifdef RISCV64}
  103. A_SH3ADD_UW,
  104. A_SLLI_UW,
  105. {$endif RISCV64}
  106. A_XNOR,
  107. { A_ZEXT_H, }
  108. { F-extension }
  109. A_FLW,A_FSW,
  110. A_FMADD_S,A_FMSUB_S,A_FNMSUB_S,A_FNMADD_S,
  111. A_FADD_S,A_FSUB_S,A_FMUL_S,A_FDIV_S,
  112. A_FSQRT_S,A_FSGNJ_S,A_FSGNJN_S,A_FSGNJX_S,
  113. A_FMIN_S,A_FMAX_S,
  114. A_FMV_X_S,A_FMV_X_W,
  115. A_FEQ_S,A_FLT_S,A_FLE_S,A_FCLASS_S,
  116. A_FCVT_W_S,A_FCVT_WU_S,A_FCVT_S_W,A_FCVT_S_WU,
  117. A_FMV_S_X,A_FMV_W_X,
  118. A_FRCSR,A_FRRM,A_FRFLAGS,A_FSCSR,A_FSRM,
  119. A_FSFLAGS,A_FSRMI,A_FSFLAGSI,
  120. {$ifdef RISCV64}
  121. { 64-bit }
  122. A_FCVT_L_S,A_FCVT_LU_S,
  123. A_FCVT_S_L,A_FCVT_S_LU,
  124. {$endif RISCV64}
  125. { D-extension }
  126. A_FLD,A_FSD,
  127. A_FMADD_D,A_FMSUB_D,A_FNMSUB_D,A_FNMADD_D,
  128. A_FADD_D,A_FSUB_D,A_FMUL_D,A_FDIV_D,
  129. A_FSQRT_D,A_FSGNJ_D,A_FSGNJN_D,A_FSGNJX_D,
  130. A_FMIN_D,A_FMAX_D,
  131. A_FEQ_D,A_FLT_D,A_FLE_D,A_FCLASS_D,
  132. A_FCVT_D_S,A_FCVT_S_D,
  133. A_FCVT_W_D,A_FCVT_WU_D,A_FCVT_D_W,A_FCVT_D_WU,
  134. {$ifdef RISCV64}
  135. { 64-bit }
  136. A_FCVT_L_D,A_FCVT_LU_D,A_FMV_X_D,
  137. A_FCVT_D_L,A_FCVT_D_LU,A_FMV_D_X,
  138. {$endif RISCV64}
  139. { Zfa extension }
  140. A_FLI_S,
  141. A_FMINM_S,A_FMAXM_S,A_FMINM_D,A_FMAXM_D,A_FMINM_H,A_FMAXM_H,A_FMINM_Q,A_FMAXM_Q,
  142. A_FROUND_S,A_FROUNDNX_S,A_FROUND_D,A_FROUNDNX_D,A_FROUND_H,A_FROUNDNX_H,A_FROUND_Q,A_FROUNDNX_Q,
  143. A_FCVTMOD_W_D,
  144. A_FMVH_X_D,A_FMVP_D_X,A_FMVH_X_Q,A_FMVP_Q_X,
  145. A_FLEQ_S,A_FLTQ_S,
  146. A_FLEQ_D,A_FLTQ_D,
  147. A_FLEQ_H,A_FLTQ_H,
  148. A_FLEQ_Q,A_FLTQ_Q,
  149. { Q-extension }
  150. A_FLQ,A_FSQ,
  151. // A_FMADD_D,A_FMSUB_D,A_FNMSUB_D,A_FNMADD_D,
  152. // A_FADD_D,A_FSUB_D,A_FMUL_D,A_FDIV_D,
  153. // A_FSQRT_D,A_FSGNJ_D,A_FSGNJN_D,A_FSGNJX_D,
  154. A_FMIN_Q,A_FMAX_Q,
  155. // A_FEQ_D,A_FLT_D,A_FLE_D,A_FCLASS_D,
  156. // A_FCVT_D_S,A_FCVT_S_D,
  157. // A_FCVT_W_D,A_FCVT_WU_D,A_FCVT_D_W,A_FCVT_D_WU,
  158. { Machine mode }
  159. A_MRET,A_HRET,A_SRET,A_URET,
  160. A_WFI,
  161. { Supervisor }
  162. A_SFENCE_VM,
  163. { pseudo instructions for accessiong control and status registers }
  164. A_RDINSTRET,A_RDINSTRETH,A_RDCYCLE,A_RDCYCLEH,A_RDTIME,A_RDTIMEH,A_CSRR,A_CSRW,A_CSRS,A_CSRC,A_CSRWI,
  165. A_CSRSI,A_CSRCI
  166. );
  167. { This should define the array of instructions as string }
  168. op2strtable=array[tasmop] of string[8];
  169. Const
  170. { First value of opcode enumeration }
  171. firstop = low(tasmop);
  172. { Last value of opcode enumeration }
  173. lastop = high(tasmop);
  174. {*****************************************************************************
  175. Registers
  176. *****************************************************************************}
  177. {$ifdef riscv32}
  178. type
  179. { Number of registers used for indexing in tables }
  180. tregisterindex=0..{$i rrv32nor.inc}-1;
  181. const
  182. maxvarregs = 32-6; { 32 int registers - r0 - stackpointer - r2 - 3 scratch registers }
  183. maxfpuvarregs = 28; { 32 fpuregisters - some scratch registers (minimally 2) }
  184. { Available Superregisters }
  185. {$i rrv32sup.inc}
  186. { No Subregisters }
  187. R_SUBWHOLE=R_SUBNONE;
  188. { Available Registers }
  189. {$i rrv32con.inc}
  190. { Integer Super registers first and last }
  191. first_int_imreg = $20;
  192. { Float Super register first and last }
  193. first_fpu_imreg = $20;
  194. { MM Super register first and last }
  195. first_mm_imreg = $20;
  196. { TODO: Calculate bsstart}
  197. regnumber_count_bsstart = 64;
  198. regnumber_table : array[tregisterindex] of tregister = (
  199. {$i rrv32num.inc}
  200. );
  201. regstabs_table : array[tregisterindex] of shortint = (
  202. {$i rrv32sta.inc}
  203. );
  204. regdwarf_table : array[tregisterindex] of shortint = (
  205. {$i rrv32dwa.inc}
  206. );
  207. {$endif riscv32}
  208. {$ifdef riscv64}
  209. type
  210. { Number of registers used for indexing in tables }
  211. tregisterindex=0..{$i rrv64nor.inc}-1;
  212. const
  213. maxvarregs = 32-6; { 32 int registers - r0 - stackpointer - r2 - 3 scratch registers }
  214. maxfpuvarregs = 28; { 32 fpuregisters - some scratch registers (minimally 2) }
  215. { Available Superregisters }
  216. {$i rrv64sup.inc}
  217. { No Subregisters }
  218. R_SUBWHOLE=R_SUBNONE;
  219. { Available Registers }
  220. {$i rrv64con.inc}
  221. { Integer Super registers first and last }
  222. first_int_imreg = $20;
  223. { Float Super register first and last }
  224. first_fpu_imreg = $20;
  225. { MM Super register first and last }
  226. first_mm_imreg = $20;
  227. { TODO: Calculate bsstart}
  228. regnumber_count_bsstart = 64;
  229. regnumber_table : array[tregisterindex] of tregister = (
  230. {$i rrv64num.inc}
  231. );
  232. regstabs_table : array[tregisterindex] of shortint = (
  233. {$i rrv64sta.inc}
  234. );
  235. regdwarf_table : array[tregisterindex] of shortint = (
  236. {$i rrv64dwa.inc}
  237. );
  238. {$endif riscv32}
  239. {*****************************************************************************
  240. Conditions
  241. *****************************************************************************}
  242. type
  243. TAsmCond = (C_None { unconditional jumps },
  244. C_LT,C_LTU,C_GE,C_GEU,C_NE,C_EQ);
  245. TAsmConds = set of TAsmCond;
  246. const
  247. cond2str: Array[TAsmCond] of string[4] = ({cf_none}'',
  248. { conditions when not using ctr decrement etc}
  249. 'lt','ltu','ge','geu','ne','eq');
  250. uppercond2str: Array[TAsmCond] of string[4] = ({cf_none}'',
  251. { conditions when not using ctr decrement etc}
  252. 'LT','LTU','GE','GEU','NE','EQ');
  253. {*****************************************************************************
  254. Flags
  255. *****************************************************************************}
  256. type
  257. TResFlagsEnum = (F_EQ,F_NE,F_LT,F_LTU,F_GE,F_GEU);
  258. {*****************************************************************************
  259. Reference
  260. *****************************************************************************}
  261. {*****************************************************************************
  262. Operands
  263. *****************************************************************************}
  264. type
  265. TMemoryOrderingFlag = (moRl, moAq);
  266. TMemoryOrdering = set of TMemoryOrderingFlag;
  267. TFenceFlag = (ffI, ffO, ffR, ffW);
  268. TFenceFlags = set of TFenceFlag;
  269. TRoundingMode = (RM_Default,
  270. RM_RNE,
  271. RM_RTZ,
  272. RM_RDN,
  273. RM_RUP,
  274. RM_RMM);
  275. const
  276. roundingmode2str : array[TRoundingMode] of string[3] = ('',
  277. 'rne','rtz','rdn','rup','rmm');
  278. {*****************************************************************************
  279. Constants
  280. *****************************************************************************}
  281. const
  282. max_operands = 5;
  283. {*****************************************************************************
  284. Default generic sizes
  285. *****************************************************************************}
  286. {# Defines the default address size for a processor, }
  287. {$ifdef RISCV64}
  288. OS_ADDR = OS_64;
  289. {# the natural int size for a processor,
  290. has to match osuinttype/ossinttype as initialized in psystem }
  291. OS_INT = OS_64;
  292. OS_SINT = OS_S64;
  293. {$endif RISCV64}
  294. {$ifdef RISCV32}
  295. OS_ADDR = OS_32;
  296. {# the natural int size for a processor,
  297. has to match osuinttype/ossinttype as initialized in psystem }
  298. OS_INT = OS_32;
  299. OS_SINT = OS_S32;
  300. {$endif RISCV64}
  301. {# the maximum float size for a processor, }
  302. OS_FLOAT = OS_F64;
  303. {# the size of a vector register for a processor }
  304. OS_VECTOR = OS_M128;
  305. {*****************************************************************************
  306. GDB Information
  307. *****************************************************************************}
  308. {$ifdef riscv32}
  309. stab_regindex : array[tregisterindex] of shortint = (
  310. {$i rrv32sta.inc}
  311. );
  312. {$endif riscv32}
  313. {$ifdef riscv64}
  314. stab_regindex : array[tregisterindex] of shortint = (
  315. {$i rrv64sta.inc}
  316. );
  317. {$endif riscv64}
  318. {*****************************************************************************
  319. Generic Register names
  320. *****************************************************************************}
  321. {# Stack pointer register }
  322. NR_STACK_POINTER_REG = NR_X2;
  323. RS_STACK_POINTER_REG = RS_X2;
  324. {# Frame pointer register }
  325. NR_FRAME_POINTER_REG = NR_X8;
  326. RS_FRAME_POINTER_REG = RS_X8;
  327. NR_PIC_OFFSET_REG = NR_X3;
  328. { Return address of a function }
  329. NR_RETURN_ADDRESS_REG = NR_X1;
  330. RS_RETURN_ADDRESS_REG = RS_X1;
  331. { Results are returned in this register (32-bit values) }
  332. NR_FUNCTION_RETURN_REG = NR_X10;
  333. RS_FUNCTION_RETURN_REG = RS_X10;
  334. { Low part of 64bit return value }
  335. NR_FUNCTION_RETURN64_LOW_REG = NR_X10;
  336. RS_FUNCTION_RETURN64_LOW_REG = RS_X10;
  337. { High part of 64bit return value }
  338. NR_FUNCTION_RETURN64_HIGH_REG = NR_X11;
  339. RS_FUNCTION_RETURN64_HIGH_REG = RS_X11;
  340. { The value returned from a function is available in this register }
  341. NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
  342. RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
  343. { The lowh part of 64bit value returned from a function }
  344. NR_FUNCTION_RESULT64_LOW_REG = NR_FUNCTION_RETURN64_LOW_REG;
  345. RS_FUNCTION_RESULT64_LOW_REG = RS_FUNCTION_RETURN64_LOW_REG;
  346. { The high part of 64bit value returned from a function }
  347. NR_FUNCTION_RESULT64_HIGH_REG = NR_FUNCTION_RETURN64_HIGH_REG;
  348. RS_FUNCTION_RESULT64_HIGH_REG = RS_FUNCTION_RETURN64_HIGH_REG;
  349. NR_FPU_RESULT_REG = NR_F10;
  350. NR_MM_RESULT_REG = NR_NO;
  351. NR_DEFAULTFLAGS = NR_NO;
  352. RS_DEFAULTFLAGS = RS_NO;
  353. {*****************************************************************************
  354. GCC /ABI linking information
  355. *****************************************************************************}
  356. {# Registers which must be saved when calling a routine declared as
  357. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  358. saved should be the ones as defined in the target ABI and / or GCC.
  359. This value can be deduced from CALLED_USED_REGISTERS array in the
  360. GCC source.
  361. }
  362. saved_standard_registers : array[0..12] of tsuperregister = (
  363. RS_X2,
  364. RS_X8,RS_X9,
  365. RS_X18,RS_X19,
  366. RS_X20,RS_X21,RS_X22,RS_X23,RS_X24,RS_X25,RS_X26,RS_X27
  367. );
  368. { this is only for the generic code which is not used for this architecture }
  369. saved_address_registers : array[0..0] of tsuperregister = (RS_INVALID);
  370. saved_mm_registers : array[0..0] of tsuperregister = (RS_INVALID);
  371. {# Required parameter alignment when calling a routine declared as
  372. stdcall and cdecl. The alignment value should be the one defined
  373. by GCC or the target ABI.
  374. The value of this constant is equal to the constant
  375. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  376. }
  377. {$ifdef RISCV64}
  378. std_param_align = 8;
  379. {$endif RISCV64}
  380. {$ifdef RISCV32}
  381. std_param_align = 4;
  382. {$endif RISCV32}
  383. {*****************************************************************************
  384. CPU Dependent Constants
  385. *****************************************************************************}
  386. maxfpuregs = 8;
  387. {*****************************************************************************
  388. Helpers
  389. *****************************************************************************}
  390. function is_imm12(value: tcgint): boolean;
  391. function is_lui_imm(value: tcgint): boolean;
  392. function is_calljmp(o:tasmop):boolean;
  393. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  394. { Returns the tcgsize corresponding with the size of reg.}
  395. function reg_cgsize(const reg: tregister) : tcgsize;
  396. function findreg_by_number(r:Tregister):tregisterindex;
  397. function std_regnum_search(const s:string):Tregister;
  398. function std_regname(r:Tregister):string;
  399. function inverse_cond(const c: TAsmCond): Tasmcond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  400. function dwarf_reg(r:tregister):shortint;
  401. function dwarf_reg_no_error(r:tregister):shortint;
  402. function eh_return_data_regno(nr: longint): longint;
  403. function conditions_equal(const c1,c2: TAsmCond): boolean;
  404. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  405. function condition_in(const Subset, c: TAsmCond): Boolean;
  406. function is_extra_reg(const s : string) : tregister;
  407. implementation
  408. uses
  409. rgbase,verbose;
  410. {$ifdef riscv32}
  411. const
  412. std_regname_table : TRegNameTable = (
  413. {$i rrv32std.inc}
  414. );
  415. regnumber_index : array[tregisterindex] of tregisterindex = (
  416. {$i rrv32rni.inc}
  417. );
  418. std_regname_index : array[tregisterindex] of tregisterindex = (
  419. {$i rrv32sri.inc}
  420. );
  421. {$endif riscv32}
  422. {$ifdef riscv64}
  423. const
  424. std_regname_table : TRegNameTable = (
  425. {$i rrv64std.inc}
  426. );
  427. regnumber_index : array[tregisterindex] of tregisterindex = (
  428. {$i rrv64rni.inc}
  429. );
  430. std_regname_index : array[tregisterindex] of tregisterindex = (
  431. {$i rrv64sri.inc}
  432. );
  433. {$endif riscv64}
  434. {*****************************************************************************
  435. Helpers
  436. *****************************************************************************}
  437. function is_imm12(value: tcgint): boolean;
  438. begin
  439. result:=(value >= -2048) and (value <= 2047);
  440. end;
  441. function is_lui_imm(value: tcgint): boolean;
  442. begin
  443. result:=SarInt64((value and $FFFFF000) shl 32, 32) = value;
  444. end;
  445. function is_calljmp(o:tasmop):boolean;
  446. begin
  447. is_calljmp:=false;
  448. case o of
  449. A_BEQZ,A_BNEZ,A_BLEZ,A_BGEZ,A_BLTZ,A_BGTZ,A_BGT,A_BLE,
  450. A_BGTU,A_BLEU,A_J,A_JR,
  451. A_JAL,A_JALR,A_Bxx,A_CALL:
  452. is_calljmp:=true;
  453. else
  454. ;
  455. end;
  456. end;
  457. function inverse_cond(const c: TAsmCond): Tasmcond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  458. const
  459. inv_condflags:array[TAsmCond] of TAsmCond=(C_None,
  460. C_GE,C_GEU,C_LT,C_LTU,C_EQ,C_NE);
  461. begin
  462. result := inv_condflags[c];
  463. end;
  464. function reg_cgsize(const reg: tregister): tcgsize;
  465. begin
  466. case getregtype(reg) of
  467. R_INTREGISTER :
  468. result:=OS_INT;
  469. R_MMREGISTER:
  470. result:=OS_M128;
  471. R_FPUREGISTER:
  472. result:=OS_F64;
  473. else
  474. internalerror(200303181);
  475. end;
  476. end;
  477. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  478. begin
  479. cgsize2subreg:=R_SUBWHOLE;
  480. end;
  481. function findreg_by_number(r:Tregister):tregisterindex;
  482. begin
  483. result:=rgBase.findreg_by_number_table(r,regnumber_index);
  484. end;
  485. function std_regnum_search(const s:string):Tregister;
  486. begin
  487. result:=regnumber_table[findreg_by_name_table(s,std_regname_table,std_regname_index)];
  488. end;
  489. function std_regname(r:Tregister):string;
  490. var
  491. p : tregisterindex;
  492. begin
  493. p:=findreg_by_number_table(r,regnumber_index);
  494. if p<>0 then
  495. result:=std_regname_table[p]
  496. else
  497. result:=generic_regname(r);
  498. end;
  499. function dwarf_reg(r:tregister):shortint;
  500. begin
  501. result:=regdwarf_table[findreg_by_number(r)];
  502. if result=-1 then
  503. internalerror(200603251);
  504. end;
  505. function dwarf_reg_no_error(r:tregister):shortint;
  506. begin
  507. result:=regdwarf_table[findreg_by_number(r)];
  508. end;
  509. function eh_return_data_regno(nr: longint): longint;
  510. begin
  511. if (nr>=0) and (nr<4) then
  512. result:=nr+10
  513. else
  514. result:=-1;
  515. end;
  516. function conditions_equal(const c1, c2: TAsmCond): boolean;
  517. begin
  518. result:=c1=c2;
  519. end;
  520. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  521. function condition_in(const Subset, c: TAsmCond): Boolean;
  522. begin
  523. Result := (c = C_None) or conditions_equal(Subset, c);
  524. if not Result then
  525. case Subset of
  526. C_EQ:
  527. Result := (c in [C_GE, C_GEU]);
  528. else
  529. Result := False;
  530. end;
  531. end;
  532. function is_extra_reg(const s: string): tregister;
  533. type
  534. treg2str = record
  535. name : string[4];
  536. reg : tregister;
  537. end;
  538. const
  539. extraregs : array[0..32] of treg2str = (
  540. (name: 'A0'; reg : NR_X10),
  541. (name: 'A1'; reg : NR_X11),
  542. (name: 'A2'; reg : NR_X12),
  543. (name: 'A3'; reg : NR_X13),
  544. (name: 'A4'; reg : NR_X14),
  545. (name: 'A5'; reg : NR_X15),
  546. (name: 'A6'; reg : NR_X16),
  547. (name: 'A7'; reg : NR_X17),
  548. (name: 'ZERO'; reg : NR_X0),
  549. (name: 'RA'; reg : NR_X1),
  550. (name: 'SP'; reg : NR_X2),
  551. (name: 'GP'; reg : NR_X3),
  552. (name: 'TP'; reg : NR_X4),
  553. (name: 'T0'; reg : NR_X5),
  554. (name: 'T1'; reg : NR_X6),
  555. (name: 'T2'; reg : NR_X7),
  556. (name: 'S0'; reg : NR_X8),
  557. (name: 'FP'; reg : NR_X8),
  558. (name: 'S1'; reg : NR_X9),
  559. (name: 'S2'; reg : NR_X18),
  560. (name: 'S3'; reg : NR_X19),
  561. (name: 'S4'; reg : NR_X20),
  562. (name: 'S5'; reg : NR_X21),
  563. (name: 'S6'; reg : NR_X22),
  564. (name: 'S7'; reg : NR_X23),
  565. (name: 'S8'; reg : NR_X24),
  566. (name: 'S9'; reg : NR_X25),
  567. (name: 'S10';reg : NR_X26),
  568. (name: 'S11';reg : NR_X27),
  569. (name: 'T3'; reg : NR_X28),
  570. (name: 'T4'; reg : NR_X29),
  571. (name: 'T5'; reg : NR_X30),
  572. (name: 'T6'; reg : NR_X31)
  573. );
  574. var
  575. i : longint;
  576. begin
  577. result:=NR_NO;
  578. { reg found?
  579. possible aliases are always 2 to 4 chars
  580. }
  581. if not (length(s) in [2..4]) then
  582. exit;
  583. for i:=low(extraregs) to high(extraregs) do
  584. begin
  585. if s=extraregs[i].name then
  586. begin
  587. result:=extraregs[i].reg;
  588. exit;
  589. end;
  590. end;
  591. end;
  592. end.