Lines Matching full:rd

152 /* Modify rd pointer to alternate reg to avoid corrupting original reg */
153 static void emit_sextw_alt(u8 *rd, u8 ra, struct rv_jit_context *ctx)
155 emit_sextw(ra, *rd, ctx);
156 *rd = ra;
159 static void emit_zextw_alt(u8 *rd, u8 ra, struct rv_jit_context *ctx)
161 emit_zextw(ra, *rd, ctx);
162 *rd = ra;
166 static int emit_addr(u8 rd, u64 addr, bool extra_pass, struct rv_jit_context *ctx)
182 emit(rv_auipc(rd, upper), ctx);
183 emit(rv_addi(rd, rd, lower), ctx);
188 static void emit_imm(u8 rd, s64 val, struct rv_jit_context *ctx)
209 emit_lui(rd, upper, ctx);
212 emit_li(rd, lower, ctx);
216 emit_addiw(rd, rd, lower, ctx);
224 emit_imm(rd, upper, ctx);
226 emit_slli(rd, rd, shift, ctx);
228 emit_addi(rd, rd, lower, ctx);
280 static void emit_bcc(u8 cond, u8 rd, u8 rs, int rvoff,
285 emit(rv_beq(rd, rs, rvoff >> 1), ctx);
288 emit(rv_bltu(rs, rd, rvoff >> 1), ctx);
291 emit(rv_bltu(rd, rs, rvoff >> 1), ctx);
294 emit(rv_bgeu(rd, rs, rvoff >> 1), ctx);
297 emit(rv_bgeu(rs, rd, rvoff >> 1), ctx);
300 emit(rv_bne(rd, rs, rvoff >> 1), ctx);
303 emit(rv_blt(rs, rd, rvoff >> 1), ctx);
306 emit(rv_blt(rd, rs, rvoff >> 1), ctx);
309 emit(rv_bge(rd, rs, rvoff >> 1), ctx);
312 emit(rv_bge(rs, rd, rvoff >> 1), ctx);
316 static void emit_branch(u8 cond, u8 rd, u8 rs, int rvoff,
322 emit_bcc(cond, rd, rs, rvoff, ctx);
330 * bne rd,rs,foo
332 * beq rd,rs,<.L1>
339 emit_bcc(cond, rd, rs, 8, ctx);
350 emit_bcc(cond, rd, rs, 12, ctx);
406 static void init_regs(u8 *rd, u8 *rs, const struct bpf_insn *insn,
418 *rd = bpf_to_rv_reg(insn->dst_reg, ctx);
427 static int emit_jump_and_link(u8 rd, s64 rvoff, bool fixed_addr,
433 emit(rv_jal(rd, rvoff >> 1), ctx);
439 emit(rv_jalr(rd, RV_REG_T1, lower), ctx);
476 static void emit_ldx_insn(u8 rd, s16 off, u8 rs, u8 size, bool sign_ext,
481 emit(sign_ext ? rv_lb(rd, off, rs) : rv_lbu(rd, off, rs), ctx);
484 emit(sign_ext ? rv_lh(rd, off, rs) : rv_lhu(rd, off, rs), ctx);
487 emit(sign_ext ? rv_lw(rd, off, rs) : rv_lwu(rd, off, rs), ctx);
490 emit_ld(rd, off, rs, ctx);
496 static void emit_stx_insn(u8 rd, s16 off, u8 rs, u8 size, struct rv_jit_context *ctx)
500 emit(rv_sb(rd, off, rs), ctx);
503 emit(rv_sh(rd, off, rs), ctx);
506 emit_sw(rd, off, rs, ctx);
509 emit_sd(rd, off, rs, ctx);
514 static void emit_ldx(u8 rd, s16 off, u8 rs, u8 size, bool sign_ext,
519 emit_ldx_insn(rd, off, rs, size, sign_ext, ctx);
527 emit_ldx_insn(rd, 0, RV_REG_T1, size, sign_ext, ctx);
531 static void emit_st(u8 rd, s16 off, s32 imm, u8 size, struct rv_jit_context *ctx)
536 emit_stx_insn(rd, off, RV_REG_T1, size, ctx);
542 emit_add(RV_REG_T2, RV_REG_T2, rd, ctx);
548 static void emit_stx(u8 rd, s16 off, u8 rs, u8 size, struct rv_jit_context *ctx)
552 emit_stx_insn(rd, off, rs, size, ctx);
558 emit_add(RV_REG_T1, RV_REG_T1, rd, ctx);
564 static int emit_atomic_ld_st(u8 rd, u8 rs, const struct bpf_insn *insn,
579 emit_ldx(rd, off, rs, BPF_SIZE(code), false, ctx);
591 emit_add(RV_REG_T2, rd, RV_REG_ARENA, ctx);
592 rd = RV_REG_T2;
596 emit_stx(rd, off, rs, BPF_SIZE(code), ctx);
606 static int emit_atomic_rmw(u8 rd, u8 rs, const struct bpf_insn *insn,
621 emit_addi(RV_REG_T1, rd, off, ctx);
624 emit_add(RV_REG_T1, RV_REG_T1, rd, ctx);
626 rd = RV_REG_T1;
630 emit_add(RV_REG_T1, rd, RV_REG_ARENA, ctx);
631 rd = RV_REG_T1;
638 emit(is64 ? rv_amoadd_d(RV_REG_ZERO, rs, rd, 0, 0) :
639 rv_amoadd_w(RV_REG_ZERO, rs, rd, 0, 0), ctx);
644 emit(is64 ? rv_amoand_d(RV_REG_ZERO, rs, rd, 0, 0) :
645 rv_amoand_w(RV_REG_ZERO, rs, rd, 0, 0), ctx);
650 emit(is64 ? rv_amoor_d(RV_REG_ZERO, rs, rd, 0, 0) :
651 rv_amoor_w(RV_REG_ZERO, rs, rd, 0, 0), ctx);
656 emit(is64 ? rv_amoxor_d(RV_REG_ZERO, rs, rd, 0, 0) :
657 rv_amoxor_w(RV_REG_ZERO, rs, rd, 0, 0), ctx);
663 emit(is64 ? rv_amoadd_d(rs, rs, rd, 1, 1) :
664 rv_amoadd_w(rs, rs, rd, 1, 1), ctx);
671 emit(is64 ? rv_amoand_d(rs, rs, rd, 1, 1) :
672 rv_amoand_w(rs, rs, rd, 1, 1), ctx);
679 emit(is64 ? rv_amoor_d(rs, rs, rd, 1, 1) :
680 rv_amoor_w(rs, rs, rd, 1, 1), ctx);
687 emit(is64 ? rv_amoxor_d(rs, rs, rd, 1, 1) :
688 rv_amoxor_w(rs, rs, rd, 1, 1), ctx);
696 emit(is64 ? rv_amoswap_d(rs, rs, rd, 1, 1) :
697 rv_amoswap_w(rs, rs, rd, 1, 1), ctx);
704 emit_cmpxchg(rd, rs, regmap[BPF_REG_0], is64, ctx);
717 static int sign_extend(u8 rd, u8 rs, u8 sz, bool sign, struct rv_jit_context *ctx)
720 if (rd != rs)
721 emit_mv(rd, rs, ctx);
727 emit_sextb(rd, rs, ctx);
730 emit_sexth(rd, rs, ctx);
733 emit_sextw(rd, rs, ctx);
736 if (rd != rs)
737 emit_mv(rd, rs, ctx);
1326 u8 rd = -1, rs = -1, code = insn->code;
1330 init_regs(&rd, &rs, insn, ctx);
1339 emit_imm(rd, (ctx->user_vm_start >> 32) << 32, ctx);
1341 emit_or(RV_REG_T1, rd, RV_REG_T1, ctx);
1342 emit_mv(rd, RV_REG_T1, ctx);
1345 if (rd != rs)
1346 emit_mv(rd, rs, ctx);
1357 /* Add the offset to Rd */
1358 emit_add(rd, rd, RV_REG_T1, ctx);
1363 emit_zextw(rd, rd, ctx);
1368 emit_mv(rd, rs, ctx);
1371 emit_sextb(rd, rs, ctx);
1374 emit_sexth(rd, rs, ctx);
1377 emit_sextw(rd, rs, ctx);
1381 emit_zextw(rd, rd, ctx);
1387 emit_add(rd, rd, rs, ctx);
1389 emit_zextw(rd, rd, ctx);
1394 emit_sub(rd, rd, rs, ctx);
1396 emit_subw(rd, rd, rs, ctx);
1399 emit_zextw(rd, rd, ctx);
1403 emit_and(rd, rd, rs, ctx);
1405 emit_zextw(rd, rd, ctx);
1409 emit_or(rd, rd, rs, ctx);
1411 emit_zextw(rd, rd, ctx);
1415 emit_xor(rd, rd, rs, ctx);
1417 emit_zextw(rd, rd, ctx);
1421 emit(is64 ? rv_mul(rd, rd, rs) : rv_mulw(rd, rd, rs), ctx);
1423 emit_zextw(rd, rd, ctx);
1428 emit(is64 ? rv_div(rd, rd, rs) : rv_divw(rd, rd, rs), ctx);
1430 emit(is64 ? rv_divu(rd, rd, rs) : rv_divuw(rd, rd, rs), ctx);
1432 emit_zextw(rd, rd, ctx);
1437 emit(is64 ? rv_rem(rd, rd, rs) : rv_remw(rd, rd, rs), ctx);
1439 emit(is64 ? rv_remu(rd, rd, rs) : rv_remuw(rd, rd, rs), ctx);
1441 emit_zextw(rd, rd, ctx);
1445 emit(is64 ? rv_sll(rd, rd, rs) : rv_sllw(rd, rd, rs), ctx);
1447 emit_zextw(rd, rd, ctx);
1451 emit(is64 ? rv_srl(rd, rd, rs) : rv_srlw(rd, rd, rs), ctx);
1453 emit_zextw(rd, rd, ctx);
1457 emit(is64 ? rv_sra(rd, rd, rs) : rv_sraw(rd, rd, rs), ctx);
1459 emit_zextw(rd, rd, ctx);
1465 emit_sub(rd, RV_REG_ZERO, rd, ctx);
1467 emit_zextw(rd, rd, ctx);
1474 emit_zexth(rd, rd, ctx);
1478 emit_zextw(rd, rd, ctx);
1487 emit_bswap(rd, imm, ctx);
1493 emit_imm(rd, imm, ctx);
1495 emit_zextw(rd, rd, ctx);
1502 emit_addi(rd, rd, imm, ctx);
1505 emit_add(rd, rd, RV_REG_T1, ctx);
1508 emit_zextw(rd, rd, ctx);
1513 emit_addi(rd, rd, -imm, ctx);
1516 emit_sub(rd, rd, RV_REG_T1, ctx);
1519 emit_zextw(rd, rd, ctx);
1524 emit_andi(rd, rd, imm, ctx);
1527 emit_and(rd, rd, RV_REG_T1, ctx);
1530 emit_zextw(rd, rd, ctx);
1535 emit(rv_ori(rd, rd, imm), ctx);
1538 emit_or(rd, rd, RV_REG_T1, ctx);
1541 emit_zextw(rd, rd, ctx);
1546 emit(rv_xori(rd, rd, imm), ctx);
1549 emit_xor(rd, rd, RV_REG_T1, ctx);
1552 emit_zextw(rd, rd, ctx);
1557 emit(is64 ? rv_mul(rd, rd, RV_REG_T1) :
1558 rv_mulw(rd, rd, RV_REG_T1), ctx);
1560 emit_zextw(rd, rd, ctx);
1566 emit(is64 ? rv_div(rd, rd, RV_REG_T1) :
1567 rv_divw(rd, rd, RV_REG_T1), ctx);
1569 emit(is64 ? rv_divu(rd, rd, RV_REG_T1) :
1570 rv_divuw(rd, rd, RV_REG_T1), ctx);
1572 emit_zextw(rd, rd, ctx);
1578 emit(is64 ? rv_rem(rd, rd, RV_REG_T1) :
1579 rv_remw(rd, rd, RV_REG_T1), ctx);
1581 emit(is64 ? rv_remu(rd, rd, RV_REG_T1) :
1582 rv_remuw(rd, rd, RV_REG_T1), ctx);
1584 emit_zextw(rd, rd, ctx);
1588 emit_slli(rd, rd, imm, ctx);
1591 emit_zextw(rd, rd, ctx);
1596 emit_srli(rd, rd, imm, ctx);
1598 emit(rv_srliw(rd, rd, imm), ctx);
1601 emit_zextw(rd, rd, ctx);
1606 emit_srai(rd, rd, imm, ctx);
1608 emit(rv_sraiw(rd, rd, imm), ctx);
1611 emit_zextw(rd, rd, ctx);
1654 emit_sextw_alt(&rd, RV_REG_T2, ctx);
1657 emit_zextw_alt(&rd, RV_REG_T2, ctx);
1668 emit_and(RV_REG_T1, rd, rs, ctx);
1671 emit_branch(BPF_OP(code), rd, rs, rvoff, ctx);
1703 emit_sextw_alt(&rd, RV_REG_T2, ctx);
1706 emit_zextw_alt(&rd, RV_REG_T2, ctx);
1715 emit_branch(BPF_OP(code), rd, rs, rvoff, ctx);
1723 emit_andi(RV_REG_T1, rd, imm, ctx);
1726 emit_and(RV_REG_T1, rd, RV_REG_T1, ctx);
1817 ret = emit_addr(rd, imm64, extra_pass, ctx);
1821 emit_imm(rd, imm64, ctx);
1859 emit_ldx(rd, off, rs, BPF_SIZE(code), sign_ext, ctx);
1861 ret = add_exception_handler(insn, rd, ctx);
1885 emit_add(RV_REG_T3, rd, RV_REG_ARENA, ctx);
1886 rd = RV_REG_T3;
1889 emit_st(rd, off, imm, BPF_SIZE(code), ctx);
1907 emit_add(RV_REG_T2, rd, RV_REG_ARENA, ctx);
1908 rd = RV_REG_T2;
1911 emit_stx(rd, off, rs, BPF_SIZE(code), ctx);
1928 ret = emit_atomic_ld_st(rd, rs, insn, ctx);
1930 ret = emit_atomic_rmw(rd, rs, insn, ctx);