@@ -312,25 +312,23 @@ void asm_rv32_emit_call_ind(asm_rv32_t *state, mp_uint_t index) {
312
312
if (FIT_UNSIGNED (offset , 11 )) {
313
313
// lw temporary, offset(fun_table)
314
314
// c.jalr temporary
315
- asm_rv32_opcode_lw (state , INTERNAL_TEMPORARY , REG_FUN_TABLE , offset );
316
- asm_rv32_opcode_cjalr (state , INTERNAL_TEMPORARY );
315
+ asm_rv32_opcode_lw (state , REG_TEMP2 , REG_FUN_TABLE , offset );
316
+ asm_rv32_opcode_cjalr (state , REG_TEMP2 );
317
317
return ;
318
318
}
319
319
320
320
mp_uint_t upper = 0 ;
321
321
mp_uint_t lower = 0 ;
322
322
split_immediate (offset , & upper , & lower );
323
323
324
- // TODO: Can this clobber REG_TEMP[0:2]?
325
-
326
324
// lui temporary, HI(index) ; Or c.lui if possible
327
325
// c.add temporary, fun_table
328
326
// lw temporary, LO(index)(temporary)
329
327
// c.jalr temporary
330
- load_upper_immediate (state , INTERNAL_TEMPORARY , upper );
331
- asm_rv32_opcode_cadd (state , INTERNAL_TEMPORARY , REG_FUN_TABLE );
332
- asm_rv32_opcode_lw (state , INTERNAL_TEMPORARY , INTERNAL_TEMPORARY , lower );
333
- asm_rv32_opcode_cjalr (state , INTERNAL_TEMPORARY );
328
+ load_upper_immediate (state , REG_TEMP2 , upper );
329
+ asm_rv32_opcode_cadd (state , REG_TEMP2 , REG_FUN_TABLE );
330
+ asm_rv32_opcode_lw (state , REG_TEMP2 , REG_TEMP2 , lower );
331
+ asm_rv32_opcode_cjalr (state , REG_TEMP2 );
334
332
}
335
333
336
334
void asm_rv32_emit_jump_if_reg_eq (asm_rv32_t * state , mp_uint_t rs1 , mp_uint_t rs2 , mp_uint_t label ) {
@@ -350,15 +348,13 @@ void asm_rv32_emit_jump_if_reg_eq(asm_rv32_t *state, mp_uint_t rs1, mp_uint_t rs
350
348
mp_uint_t lower = 0 ;
351
349
split_immediate (displacement , & upper , & lower );
352
350
353
- // TODO: Can this clobber REG_TEMP[0:2]?
354
-
355
351
// bne rs1, rs2, 12 ; PC + 0
356
352
// auipc temporary, HI(displacement) ; PC + 4
357
353
// jalr zero, temporary, LO(displacement) ; PC + 8
358
354
// ... ; PC + 12
359
355
asm_rv32_opcode_bne (state , rs1 , rs2 , 12 );
360
- asm_rv32_opcode_auipc (state , INTERNAL_TEMPORARY , upper );
361
- asm_rv32_opcode_jalr (state , ASM_RV32_REG_ZERO , INTERNAL_TEMPORARY , lower );
356
+ asm_rv32_opcode_auipc (state , REG_TEMP2 , upper );
357
+ asm_rv32_opcode_jalr (state , ASM_RV32_REG_ZERO , REG_TEMP2 , lower );
362
358
}
363
359
364
360
void asm_rv32_emit_jump_if_reg_nonzero (asm_rv32_t * state , mp_uint_t rs , mp_uint_t label ) {
@@ -377,8 +373,6 @@ void asm_rv32_emit_jump_if_reg_nonzero(asm_rv32_t *state, mp_uint_t rs, mp_uint_
377
373
return ;
378
374
}
379
375
380
- // TODO: Can this clobber REG_TEMP[0:2]?
381
-
382
376
// if rs1 in C window and displacement is negative:
383
377
// c.beqz rs', 10 ; PC + 0
384
378
// auipc temporary, HI(displacement) ; PC + 2
@@ -403,8 +397,8 @@ void asm_rv32_emit_jump_if_reg_nonzero(asm_rv32_t *state, mp_uint_t rs, mp_uint_
403
397
mp_uint_t upper = 0 ;
404
398
mp_uint_t lower = 0 ;
405
399
split_immediate (displacement , & upper , & lower );
406
- asm_rv32_opcode_auipc (state , INTERNAL_TEMPORARY , upper );
407
- asm_rv32_opcode_jalr (state , ASM_RV32_REG_ZERO , INTERNAL_TEMPORARY , lower );
400
+ asm_rv32_opcode_auipc (state , REG_TEMP2 , upper );
401
+ asm_rv32_opcode_jalr (state , ASM_RV32_REG_ZERO , REG_TEMP2 , lower );
408
402
}
409
403
410
404
void asm_rv32_emit_mov_local_reg (asm_rv32_t * state , mp_uint_t local , mp_uint_t rs ) {
@@ -426,14 +420,12 @@ void asm_rv32_emit_mov_local_reg(asm_rv32_t *state, mp_uint_t local, mp_uint_t r
426
420
mp_uint_t lower = 0 ;
427
421
split_immediate (offset , & upper , & lower );
428
422
429
- // TODO: Can this clobber REG_TEMP[0:2]?
430
-
431
423
// lui temporary, HI(offset) ; Or c.lui if possible
432
424
// c.add temporary, sp
433
425
// sw rs, LO(offset)(temporary)
434
- load_upper_immediate (state , INTERNAL_TEMPORARY , upper );
435
- asm_rv32_opcode_cadd (state , INTERNAL_TEMPORARY , ASM_RV32_REG_SP );
436
- asm_rv32_opcode_sw (state , rs , INTERNAL_TEMPORARY , lower );
426
+ load_upper_immediate (state , REG_TEMP2 , upper );
427
+ asm_rv32_opcode_cadd (state , REG_TEMP2 , ASM_RV32_REG_SP );
428
+ asm_rv32_opcode_sw (state , rs , REG_TEMP2 , lower );
437
429
}
438
430
439
431
void asm_rv32_emit_mov_reg_local (asm_rv32_t * state , mp_uint_t rd , mp_uint_t local ) {
@@ -525,12 +517,10 @@ void asm_rv32_emit_jump(asm_rv32_t *state, mp_uint_t label) {
525
517
mp_uint_t lower = 0 ;
526
518
split_immediate (displacement , & upper , & lower );
527
519
528
- // TODO: Can this clobber REG_TEMP[0:2]?
529
-
530
520
// auipc temporary, HI(displacement)
531
521
// jalr zero, temporary, LO(displacement)
532
- asm_rv32_opcode_auipc (state , INTERNAL_TEMPORARY , upper );
533
- asm_rv32_opcode_jalr (state , ASM_RV32_REG_ZERO , INTERNAL_TEMPORARY , lower );
522
+ asm_rv32_opcode_auipc (state , REG_TEMP2 , upper );
523
+ asm_rv32_opcode_jalr (state , ASM_RV32_REG_ZERO , REG_TEMP2 , lower );
534
524
}
535
525
536
526
void asm_rv32_emit_store_reg_reg_offset (asm_rv32_t * state , mp_uint_t rd , mp_uint_t rs , mp_int_t offset ) {
@@ -549,9 +539,9 @@ void asm_rv32_emit_store_reg_reg_offset(asm_rv32_t *state, mp_uint_t rd, mp_uint
549
539
// lui temporary, HI(offset) ; Or c.lui if possible
550
540
// c.add temporary, rs
551
541
// sw rd, LO(offset)(temporary)
552
- load_upper_immediate (state , INTERNAL_TEMPORARY , upper );
553
- asm_rv32_opcode_cadd (state , INTERNAL_TEMPORARY , rs );
554
- asm_rv32_opcode_sw (state , rd , INTERNAL_TEMPORARY , lower );
542
+ load_upper_immediate (state , REG_TEMP2 , upper );
543
+ asm_rv32_opcode_cadd (state , REG_TEMP2 , rs );
544
+ asm_rv32_opcode_sw (state , rd , REG_TEMP2 , lower );
555
545
}
556
546
557
547
void asm_rv32_emit_mov_reg_pcrel (asm_rv32_t * state , mp_uint_t rd , mp_uint_t label ) {
0 commit comments