cpubase.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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. { Q-extension }
  140. A_FLQ,A_FSQ,
  141. // A_FMADD_D,A_FMSUB_D,A_FNMSUB_D,A_FNMADD_D,
  142. // A_FADD_D,A_FSUB_D,A_FMUL_D,A_FDIV_D,
  143. // A_FSQRT_D,A_FSGNJ_D,A_FSGNJN_D,A_FSGNJX_D,
  144. A_FMIN_Q,A_FMAX_Q,
  145. // A_FEQ_D,A_FLT_D,A_FLE_D,A_FCLASS_D,
  146. // A_FCVT_D_S,A_FCVT_S_D,
  147. // A_FCVT_W_D,A_FCVT_WU_D,A_FCVT_D_W,A_FCVT_D_WU,
  148. { Machine mode }
  149. A_MRET,A_HRET,A_SRET,A_URET,
  150. A_WFI,
  151. { Supervisor }
  152. A_SFENCE_VM,
  153. { pseudo instructions for accessiong control and status registers }
  154. A_RDINSTRET,A_RDINSTRETH,A_RDCYCLE,A_RDCYCLEH,A_RDTIME,A_RDTIMEH,A_CSRR,A_CSRW,A_CSRS,A_CSRC,A_CSRWI,
  155. A_CSRSI,A_CSRCI
  156. );
  157. { This should define the array of instructions as string }
  158. op2strtable=array[tasmop] of string[8];
  159. Const
  160. { First value of opcode enumeration }
  161. firstop = low(tasmop);
  162. { Last value of opcode enumeration }
  163. lastop = high(tasmop);
  164. { Last value of opcode for TCommonAsmOps set below }
  165. LastCommonAsmOp = A_MRET;
  166. Type
  167. TCommonAsmOps = Set of A_None .. LastCommonAsmOp;
  168. {*****************************************************************************
  169. Registers
  170. *****************************************************************************}
  171. {$ifdef riscv32}
  172. type
  173. { Number of registers used for indexing in tables }
  174. tregisterindex=0..{$i rrv32nor.inc}-1;
  175. const
  176. maxvarregs = 32-6; { 32 int registers - r0 - stackpointer - r2 - 3 scratch registers }
  177. maxfpuvarregs = 28; { 32 fpuregisters - some scratch registers (minimally 2) }
  178. { Available Superregisters }
  179. {$i rrv32sup.inc}
  180. { No Subregisters }
  181. R_SUBWHOLE=R_SUBNONE;
  182. { Available Registers }
  183. {$i rrv32con.inc}
  184. { Integer Super registers first and last }
  185. first_int_imreg = $20;
  186. { Float Super register first and last }
  187. first_fpu_imreg = $20;
  188. { MM Super register first and last }
  189. first_mm_imreg = $20;
  190. { TODO: Calculate bsstart}
  191. regnumber_count_bsstart = 64;
  192. regnumber_table : array[tregisterindex] of tregister = (
  193. {$i rrv32num.inc}
  194. );
  195. regstabs_table : array[tregisterindex] of shortint = (
  196. {$i rrv32sta.inc}
  197. );
  198. regdwarf_table : array[tregisterindex] of shortint = (
  199. {$i rrv32dwa.inc}
  200. );
  201. {$endif riscv32}
  202. {$ifdef riscv64}
  203. type
  204. { Number of registers used for indexing in tables }
  205. tregisterindex=0..{$i rrv64nor.inc}-1;
  206. const
  207. maxvarregs = 32-6; { 32 int registers - r0 - stackpointer - r2 - 3 scratch registers }
  208. maxfpuvarregs = 28; { 32 fpuregisters - some scratch registers (minimally 2) }
  209. { Available Superregisters }
  210. {$i rrv64sup.inc}
  211. { No Subregisters }
  212. R_SUBWHOLE=R_SUBNONE;
  213. { Available Registers }
  214. {$i rrv64con.inc}
  215. { Integer Super registers first and last }
  216. first_int_imreg = $20;
  217. { Float Super register first and last }
  218. first_fpu_imreg = $20;
  219. { MM Super register first and last }
  220. first_mm_imreg = $20;
  221. { TODO: Calculate bsstart}
  222. regnumber_count_bsstart = 64;
  223. regnumber_table : array[tregisterindex] of tregister = (
  224. {$i rrv64num.inc}
  225. );
  226. regstabs_table : array[tregisterindex] of shortint = (
  227. {$i rrv64sta.inc}
  228. );
  229. regdwarf_table : array[tregisterindex] of shortint = (
  230. {$i rrv64dwa.inc}
  231. );
  232. {$endif riscv32}
  233. {*****************************************************************************
  234. Conditions
  235. *****************************************************************************}
  236. type
  237. TAsmCond = (C_None { unconditional jumps },
  238. C_LT,C_LTU,C_GE,C_GEU,C_NE,C_EQ);
  239. TAsmConds = set of TAsmCond;
  240. const
  241. cond2str: Array[TAsmCond] of string[4] = ({cf_none}'',
  242. { conditions when not using ctr decrement etc}
  243. 'lt','ltu','ge','geu','ne','eq');
  244. uppercond2str: Array[TAsmCond] of string[4] = ({cf_none}'',
  245. { conditions when not using ctr decrement etc}
  246. 'LT','LTU','GE','GEU','NE','EQ');
  247. {*****************************************************************************
  248. Flags
  249. *****************************************************************************}
  250. type
  251. TResFlagsEnum = (F_EQ,F_NE,F_LT,F_LTU,F_GE,F_GEU);
  252. {*****************************************************************************
  253. Reference
  254. *****************************************************************************}
  255. {*****************************************************************************
  256. Operands
  257. *****************************************************************************}
  258. type
  259. TMemoryOrderingFlag = (moRl, moAq);
  260. TMemoryOrdering = set of TMemoryOrderingFlag;
  261. TFenceFlag = (ffI, ffO, ffR, ffW);
  262. TFenceFlags = set of TFenceFlag;
  263. TRoundingMode = (RM_Default,
  264. RM_RNE,
  265. RM_RTZ,
  266. RM_RDN,
  267. RM_RUP,
  268. RM_RMM);
  269. const
  270. roundingmode2str : array[TRoundingMode] of string[3] = ('',
  271. 'rne','rtz','rdn','rup','rmm');
  272. {*****************************************************************************
  273. Constants
  274. *****************************************************************************}
  275. const
  276. max_operands = 5;
  277. {*****************************************************************************
  278. Default generic sizes
  279. *****************************************************************************}
  280. {# Defines the default address size for a processor, }
  281. {$ifdef RISCV64}
  282. OS_ADDR = OS_64;
  283. {# the natural int size for a processor,
  284. has to match osuinttype/ossinttype as initialized in psystem }
  285. OS_INT = OS_64;
  286. OS_SINT = OS_S64;
  287. {$endif RISCV64}
  288. {$ifdef RISCV32}
  289. OS_ADDR = OS_32;
  290. {# the natural int size for a processor,
  291. has to match osuinttype/ossinttype as initialized in psystem }
  292. OS_INT = OS_32;
  293. OS_SINT = OS_S32;
  294. {$endif RISCV64}
  295. {# the maximum float size for a processor, }
  296. OS_FLOAT = OS_F64;
  297. {# the size of a vector register for a processor }
  298. OS_VECTOR = OS_M128;
  299. {*****************************************************************************
  300. GDB Information
  301. *****************************************************************************}
  302. {$ifdef riscv32}
  303. stab_regindex : array[tregisterindex] of shortint = (
  304. {$i rrv32sta.inc}
  305. );
  306. {$endif riscv32}
  307. {$ifdef riscv64}
  308. stab_regindex : array[tregisterindex] of shortint = (
  309. {$i rrv64sta.inc}
  310. );
  311. {$endif riscv64}
  312. {*****************************************************************************
  313. Generic Register names
  314. *****************************************************************************}
  315. {# Stack pointer register }
  316. NR_STACK_POINTER_REG = NR_X2;
  317. RS_STACK_POINTER_REG = RS_X2;
  318. {# Frame pointer register }
  319. NR_FRAME_POINTER_REG = NR_X8;
  320. RS_FRAME_POINTER_REG = RS_X8;
  321. NR_PIC_OFFSET_REG = NR_X3;
  322. { Return address of a function }
  323. NR_RETURN_ADDRESS_REG = NR_X1;
  324. RS_RETURN_ADDRESS_REG = RS_X1;
  325. { Results are returned in this register (32-bit values) }
  326. NR_FUNCTION_RETURN_REG = NR_X10;
  327. RS_FUNCTION_RETURN_REG = RS_X10;
  328. { Low part of 64bit return value }
  329. NR_FUNCTION_RETURN64_LOW_REG = NR_X10;
  330. RS_FUNCTION_RETURN64_LOW_REG = RS_X10;
  331. { High part of 64bit return value }
  332. NR_FUNCTION_RETURN64_HIGH_REG = NR_X11;
  333. RS_FUNCTION_RETURN64_HIGH_REG = RS_X11;
  334. { The value returned from a function is available in this register }
  335. NR_FUNCTION_RESULT_REG = NR_FUNCTION_RETURN_REG;
  336. RS_FUNCTION_RESULT_REG = RS_FUNCTION_RETURN_REG;
  337. { The lowh part of 64bit value returned from a function }
  338. NR_FUNCTION_RESULT64_LOW_REG = NR_FUNCTION_RETURN64_LOW_REG;
  339. RS_FUNCTION_RESULT64_LOW_REG = RS_FUNCTION_RETURN64_LOW_REG;
  340. { The high part of 64bit value returned from a function }
  341. NR_FUNCTION_RESULT64_HIGH_REG = NR_FUNCTION_RETURN64_HIGH_REG;
  342. RS_FUNCTION_RESULT64_HIGH_REG = RS_FUNCTION_RETURN64_HIGH_REG;
  343. NR_FPU_RESULT_REG = NR_F10;
  344. NR_MM_RESULT_REG = NR_NO;
  345. NR_DEFAULTFLAGS = NR_NO;
  346. RS_DEFAULTFLAGS = RS_NO;
  347. {*****************************************************************************
  348. GCC /ABI linking information
  349. *****************************************************************************}
  350. {# Registers which must be saved when calling a routine declared as
  351. cppdecl, cdecl, stdcall, safecall, palmossyscall. The registers
  352. saved should be the ones as defined in the target ABI and / or GCC.
  353. This value can be deduced from CALLED_USED_REGISTERS array in the
  354. GCC source.
  355. }
  356. saved_standard_registers : array[0..12] of tsuperregister = (
  357. RS_X2,
  358. RS_X8,RS_X9,
  359. RS_X18,RS_X19,
  360. RS_X20,RS_X21,RS_X22,RS_X23,RS_X24,RS_X25,RS_X26,RS_X27
  361. );
  362. { this is only for the generic code which is not used for this architecture }
  363. saved_address_registers : array[0..0] of tsuperregister = (RS_INVALID);
  364. saved_mm_registers : array[0..0] of tsuperregister = (RS_INVALID);
  365. {# Required parameter alignment when calling a routine declared as
  366. stdcall and cdecl. The alignment value should be the one defined
  367. by GCC or the target ABI.
  368. The value of this constant is equal to the constant
  369. PARM_BOUNDARY / BITS_PER_UNIT in the GCC source.
  370. }
  371. {$ifdef RISCV64}
  372. std_param_align = 8;
  373. {$endif RISCV64}
  374. {$ifdef RISCV32}
  375. std_param_align = 4;
  376. {$endif RISCV32}
  377. {*****************************************************************************
  378. CPU Dependent Constants
  379. *****************************************************************************}
  380. maxfpuregs = 8;
  381. {*****************************************************************************
  382. Helpers
  383. *****************************************************************************}
  384. function is_imm12(value: tcgint): boolean;
  385. function is_lui_imm(value: tcgint): boolean;
  386. function is_calljmp(o:tasmop):boolean;
  387. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  388. { Returns the tcgsize corresponding with the size of reg.}
  389. function reg_cgsize(const reg: tregister) : tcgsize;
  390. function findreg_by_number(r:Tregister):tregisterindex;
  391. function std_regnum_search(const s:string):Tregister;
  392. function std_regname(r:Tregister):string;
  393. function inverse_cond(const c: TAsmCond): Tasmcond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  394. function dwarf_reg(r:tregister):shortint;
  395. function dwarf_reg_no_error(r:tregister):shortint;
  396. function eh_return_data_regno(nr: longint): longint;
  397. function conditions_equal(const c1,c2: TAsmCond): boolean;
  398. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  399. function condition_in(const Subset, c: TAsmCond): Boolean;
  400. function is_extra_reg(const s : string) : tregister;
  401. implementation
  402. uses
  403. rgbase,verbose;
  404. {$ifdef riscv32}
  405. const
  406. std_regname_table : TRegNameTable = (
  407. {$i rrv32std.inc}
  408. );
  409. regnumber_index : array[tregisterindex] of tregisterindex = (
  410. {$i rrv32rni.inc}
  411. );
  412. std_regname_index : array[tregisterindex] of tregisterindex = (
  413. {$i rrv32sri.inc}
  414. );
  415. {$endif riscv32}
  416. {$ifdef riscv64}
  417. const
  418. std_regname_table : TRegNameTable = (
  419. {$i rrv64std.inc}
  420. );
  421. regnumber_index : array[tregisterindex] of tregisterindex = (
  422. {$i rrv64rni.inc}
  423. );
  424. std_regname_index : array[tregisterindex] of tregisterindex = (
  425. {$i rrv64sri.inc}
  426. );
  427. {$endif riscv64}
  428. {*****************************************************************************
  429. Helpers
  430. *****************************************************************************}
  431. function is_imm12(value: tcgint): boolean;
  432. begin
  433. result:=(value >= -2048) and (value <= 2047);
  434. end;
  435. function is_lui_imm(value: tcgint): boolean;
  436. begin
  437. result:=SarInt64((value and $FFFFF000) shl 32, 32) = value;
  438. end;
  439. function is_calljmp(o:tasmop):boolean;
  440. begin
  441. is_calljmp:=false;
  442. case o of
  443. A_BEQZ,A_BNEZ,A_BLEZ,A_BGEZ,A_BLTZ,A_BGTZ,A_BGT,A_BLE,
  444. A_BGTU,A_BLEU,A_J,A_JR,
  445. A_JAL,A_JALR,A_Bxx,A_CALL:
  446. is_calljmp:=true;
  447. else
  448. ;
  449. end;
  450. end;
  451. function inverse_cond(const c: TAsmCond): Tasmcond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
  452. const
  453. inv_condflags:array[TAsmCond] of TAsmCond=(C_None,
  454. C_GE,C_GEU,C_LT,C_LTU,C_EQ,C_NE);
  455. begin
  456. result := inv_condflags[c];
  457. end;
  458. function reg_cgsize(const reg: tregister): tcgsize;
  459. begin
  460. case getregtype(reg) of
  461. R_INTREGISTER :
  462. result:=OS_INT;
  463. R_MMREGISTER:
  464. result:=OS_M128;
  465. R_FPUREGISTER:
  466. result:=OS_F64;
  467. else
  468. internalerror(200303181);
  469. end;
  470. end;
  471. function cgsize2subreg(regtype: tregistertype; s:Tcgsize):Tsubregister;
  472. begin
  473. cgsize2subreg:=R_SUBWHOLE;
  474. end;
  475. function findreg_by_number(r:Tregister):tregisterindex;
  476. begin
  477. result:=rgBase.findreg_by_number_table(r,regnumber_index);
  478. end;
  479. function std_regnum_search(const s:string):Tregister;
  480. begin
  481. result:=regnumber_table[findreg_by_name_table(s,std_regname_table,std_regname_index)];
  482. end;
  483. function std_regname(r:Tregister):string;
  484. var
  485. p : tregisterindex;
  486. begin
  487. p:=findreg_by_number_table(r,regnumber_index);
  488. if p<>0 then
  489. result:=std_regname_table[p]
  490. else
  491. result:=generic_regname(r);
  492. end;
  493. function dwarf_reg(r:tregister):shortint;
  494. begin
  495. result:=regdwarf_table[findreg_by_number(r)];
  496. if result=-1 then
  497. internalerror(200603251);
  498. end;
  499. function dwarf_reg_no_error(r:tregister):shortint;
  500. begin
  501. result:=regdwarf_table[findreg_by_number(r)];
  502. end;
  503. function eh_return_data_regno(nr: longint): longint;
  504. begin
  505. if (nr>=0) and (nr<4) then
  506. result:=nr+10
  507. else
  508. result:=-1;
  509. end;
  510. function conditions_equal(const c1, c2: TAsmCond): boolean;
  511. begin
  512. result:=c1=c2;
  513. end;
  514. { Checks if Subset is a subset of c (e.g. "less than" is a subset of "less than or equal" }
  515. function condition_in(const Subset, c: TAsmCond): Boolean;
  516. begin
  517. Result := (c = C_None) or conditions_equal(Subset, c);
  518. if not Result then
  519. case Subset of
  520. C_EQ:
  521. Result := (c in [C_GE, C_GEU]);
  522. else
  523. Result := False;
  524. end;
  525. end;
  526. function is_extra_reg(const s: string): tregister;
  527. type
  528. treg2str = record
  529. name : string[4];
  530. reg : tregister;
  531. end;
  532. const
  533. extraregs : array[0..32] of treg2str = (
  534. (name: 'A0'; reg : NR_X10),
  535. (name: 'A1'; reg : NR_X11),
  536. (name: 'A2'; reg : NR_X12),
  537. (name: 'A3'; reg : NR_X13),
  538. (name: 'A4'; reg : NR_X14),
  539. (name: 'A5'; reg : NR_X15),
  540. (name: 'A6'; reg : NR_X16),
  541. (name: 'A7'; reg : NR_X17),
  542. (name: 'ZERO'; reg : NR_X0),
  543. (name: 'RA'; reg : NR_X1),
  544. (name: 'SP'; reg : NR_X2),
  545. (name: 'GP'; reg : NR_X3),
  546. (name: 'TP'; reg : NR_X4),
  547. (name: 'T0'; reg : NR_X5),
  548. (name: 'T1'; reg : NR_X6),
  549. (name: 'T2'; reg : NR_X7),
  550. (name: 'S0'; reg : NR_X8),
  551. (name: 'FP'; reg : NR_X8),
  552. (name: 'S1'; reg : NR_X9),
  553. (name: 'S2'; reg : NR_X18),
  554. (name: 'S3'; reg : NR_X19),
  555. (name: 'S4'; reg : NR_X20),
  556. (name: 'S5'; reg : NR_X21),
  557. (name: 'S6'; reg : NR_X22),
  558. (name: 'S7'; reg : NR_X23),
  559. (name: 'S8'; reg : NR_X24),
  560. (name: 'S9'; reg : NR_X25),
  561. (name: 'S10';reg : NR_X26),
  562. (name: 'S11';reg : NR_X27),
  563. (name: 'T3'; reg : NR_X28),
  564. (name: 'T4'; reg : NR_X29),
  565. (name: 'T5'; reg : NR_X30),
  566. (name: 'T6'; reg : NR_X31)
  567. );
  568. var
  569. i : longint;
  570. begin
  571. result:=NR_NO;
  572. { reg found?
  573. possible aliases are always 2 to 4 chars
  574. }
  575. if not (length(s) in [2..4]) then
  576. exit;
  577. for i:=low(extraregs) to high(extraregs) do
  578. begin
  579. if s=extraregs[i].name then
  580. begin
  581. result:=extraregs[i].reg;
  582. exit;
  583. end;
  584. end;
  585. end;
  586. end.