History

riscv: jal: Add pseudo instruction support

Ekaitz Zarraga committed 2 years ago

Commit e2d8eb31 parent 409007c1 file · +23 −4Browse files

Unified · Split

riscv64-asm.c+23−4
@@ -267,6 +267,26 @@ static void parse_mem_access_operands(TCCState *s1, Operand* ops){ · 266 unmodified lines
267 }267 }
268}268}
269 269
270/* This is special: First operand is optional */
271static void asm_jal_opcode(TCCState *s1, int token){
272 static const Operand ra = {.type = OP_REG, .reg = 1};
273 Operand ops[2];
274 parse_operand(s1, &ops[0]);
275 if ( tok == ',')
276 next();
277 else {
278 /* no more operands, it's the pseudoinstruction:
279 * jal rs
280 * Expand to:
281 * jal ra, rs
282 */
283 asm_emit_j(token, 0x6f, &ra, &ops[0]);
284 return;
285 }
286 parse_operand(s1, &ops[1]);
287 asm_emit_j(token, 0x6f, &ops[0], &ops[1]);
288}
289
270/* This is special: It can be a pseudointruction or a instruction */290/* This is special: It can be a pseudointruction or a instruction */
271static void asm_jalr_opcode(TCCState *s1, int token){291static void asm_jalr_opcode(TCCState *s1, int token){
272 static const Operand zimm = {.type = OP_IM12S};292 static const Operand zimm = {.type = OP_IM12S};
@@ -418,9 +438,6 @@ static void asm_binary_opcode(TCCState* s1, int token) · 145 unmodified lines
418 case TOK_ASM_auipc:438 case TOK_ASM_auipc:
419 asm_emit_u(token, (0x05 << 2) | 3, &ops[0], &ops[1]);439 asm_emit_u(token, (0x05 << 2) | 3, &ops[0], &ops[1]);
420 return;440 return;
421 case TOK_ASM_jal:
422 asm_emit_j(token, 0x6f, ops, ops + 1);
423 return;
424 441
425 /* C extension */442 /* C extension */
426 case TOK_ASM_c_add:443 case TOK_ASM_c_add:
@@ -1100,7 +1117,6 @@ ST_FUNC void asm_opcode(TCCState *s1, int token) · 673 unmodified lines
1100 1117
1101 case TOK_ASM_lui:1118 case TOK_ASM_lui:
1102 case TOK_ASM_auipc:1119 case TOK_ASM_auipc:
1103 case TOK_ASM_jal:
1104 asm_binary_opcode(s1, token);1120 asm_binary_opcode(s1, token);
1105 return;1121 return;
1106 1122
@@ -1121,6 +1137,9 @@ ST_FUNC void asm_opcode(TCCState *s1, int token) · 14 unmodified lines
1121 case TOK_ASM_jalr:1137 case TOK_ASM_jalr:
1122 asm_jalr_opcode(s1, token); /* it can be a pseudo instruction too*/1138 asm_jalr_opcode(s1, token); /* it can be a pseudo instruction too*/
1123 break;1139 break;
1140 case TOK_ASM_jal:
1141 asm_jal_opcode(s1, token); /* it can be a pseudo instruction too*/
1142 break;
1124 1143
1125 case TOK_ASM_add:1144 case TOK_ASM_add:
1126 case TOK_ASM_addi:1145 case TOK_ASM_addi:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t