Lines Matching +full:3 +full:rd
25 RV_REG_GP = 3, /* Global pointer */
224 static inline u32 rv_r_insn(u8 funct7, u8 rs2, u8 rs1, u8 funct3, u8 rd, in rv_r_insn() argument
228 (rd << 7) | opcode; in rv_r_insn()
231 static inline u32 rv_i_insn(u16 imm11_0, u8 rs1, u8 funct3, u8 rd, u8 opcode) in rv_i_insn() argument
233 return (imm11_0 << 20) | (rs1 << 15) | (funct3 << 12) | (rd << 7) | in rv_i_insn()
254 static inline u32 rv_u_insn(u32 imm31_12, u8 rd, u8 opcode) in rv_u_insn() argument
256 return (imm31_12 << 12) | (rd << 7) | opcode; in rv_u_insn()
259 static inline u32 rv_j_insn(u32 imm20_1, u8 rd, u8 opcode) in rv_j_insn() argument
266 return (imm << 12) | (rd << 7) | opcode; in rv_j_insn()
270 u8 funct3, u8 rd, u8 opcode) in rv_amo_insn() argument
274 return rv_r_insn(funct7, rs2, rs1, funct3, rd, opcode); in rv_amo_insn()
279 static inline u16 rv_cr_insn(u8 funct4, u8 rd, u8 rs2, u8 op) in rv_cr_insn() argument
281 return (funct4 << 12) | (rd << 7) | (rs2 << 2) | op; in rv_cr_insn()
284 static inline u16 rv_ci_insn(u8 funct3, u32 imm6, u8 rd, u8 op) in rv_ci_insn() argument
289 return (funct3 << 13) | (rd << 7) | op | imm; in rv_ci_insn()
297 static inline u16 rv_ciw_insn(u8 funct3, u32 uimm, u8 rd, u8 op) in rv_ciw_insn() argument
299 return (funct3 << 13) | (uimm << 5) | ((rd & 0x7) << 2) | op; in rv_ciw_insn()
302 static inline u16 rv_cl_insn(u8 funct3, u32 imm_hi, u8 rs1, u32 imm_lo, u8 rd, in rv_cl_insn() argument
306 (imm_lo << 5) | ((rd & 0x7) << 2) | op; in rv_cl_insn()
316 static inline u16 rv_ca_insn(u8 funct6, u8 rd, u8 funct2, u8 rs2, u8 op) in rv_ca_insn() argument
318 return (funct6 << 10) | ((rd & 0x7) << 7) | (funct2 << 5) | in rv_ca_insn()
322 static inline u16 rv_cb_insn(u8 funct3, u32 imm6, u8 funct2, u8 rd, u8 op) in rv_cb_insn() argument
327 return (funct3 << 13) | (funct2 << 10) | ((rd & 0x7) << 7) | op | imm; in rv_cb_insn()
332 static inline u32 rv_addi(u8 rd, u8 rs1, u16 imm11_0) in rv_addi() argument
334 return rv_i_insn(imm11_0, rs1, 0, rd, 0x13); in rv_addi()
337 static inline u32 rv_andi(u8 rd, u8 rs1, u16 imm11_0) in rv_andi() argument
339 return rv_i_insn(imm11_0, rs1, 7, rd, 0x13); in rv_andi()
342 static inline u32 rv_ori(u8 rd, u8 rs1, u16 imm11_0) in rv_ori() argument
344 return rv_i_insn(imm11_0, rs1, 6, rd, 0x13); in rv_ori()
347 static inline u32 rv_xori(u8 rd, u8 rs1, u16 imm11_0) in rv_xori() argument
349 return rv_i_insn(imm11_0, rs1, 4, rd, 0x13); in rv_xori()
352 static inline u32 rv_slli(u8 rd, u8 rs1, u16 imm11_0) in rv_slli() argument
354 return rv_i_insn(imm11_0, rs1, 1, rd, 0x13); in rv_slli()
357 static inline u32 rv_srli(u8 rd, u8 rs1, u16 imm11_0) in rv_srli() argument
359 return rv_i_insn(imm11_0, rs1, 5, rd, 0x13); in rv_srli()
362 static inline u32 rv_srai(u8 rd, u8 rs1, u16 imm11_0) in rv_srai() argument
364 return rv_i_insn(0x400 | imm11_0, rs1, 5, rd, 0x13); in rv_srai()
367 static inline u32 rv_lui(u8 rd, u32 imm31_12) in rv_lui() argument
369 return rv_u_insn(imm31_12, rd, 0x37); in rv_lui()
372 static inline u32 rv_auipc(u8 rd, u32 imm31_12) in rv_auipc() argument
374 return rv_u_insn(imm31_12, rd, 0x17); in rv_auipc()
377 static inline u32 rv_add(u8 rd, u8 rs1, u8 rs2) in rv_add() argument
379 return rv_r_insn(0, rs2, rs1, 0, rd, 0x33); in rv_add()
382 static inline u32 rv_sub(u8 rd, u8 rs1, u8 rs2) in rv_sub() argument
384 return rv_r_insn(0x20, rs2, rs1, 0, rd, 0x33); in rv_sub()
387 static inline u32 rv_sltu(u8 rd, u8 rs1, u8 rs2) in rv_sltu() argument
389 return rv_r_insn(0, rs2, rs1, 3, rd, 0x33); in rv_sltu()
392 static inline u32 rv_and(u8 rd, u8 rs1, u8 rs2) in rv_and() argument
394 return rv_r_insn(0, rs2, rs1, 7, rd, 0x33); in rv_and()
397 static inline u32 rv_or(u8 rd, u8 rs1, u8 rs2) in rv_or() argument
399 return rv_r_insn(0, rs2, rs1, 6, rd, 0x33); in rv_or()
402 static inline u32 rv_xor(u8 rd, u8 rs1, u8 rs2) in rv_xor() argument
404 return rv_r_insn(0, rs2, rs1, 4, rd, 0x33); in rv_xor()
407 static inline u32 rv_sll(u8 rd, u8 rs1, u8 rs2) in rv_sll() argument
409 return rv_r_insn(0, rs2, rs1, 1, rd, 0x33); in rv_sll()
412 static inline u32 rv_srl(u8 rd, u8 rs1, u8 rs2) in rv_srl() argument
414 return rv_r_insn(0, rs2, rs1, 5, rd, 0x33); in rv_srl()
417 static inline u32 rv_sra(u8 rd, u8 rs1, u8 rs2) in rv_sra() argument
419 return rv_r_insn(0x20, rs2, rs1, 5, rd, 0x33); in rv_sra()
422 static inline u32 rv_mul(u8 rd, u8 rs1, u8 rs2) in rv_mul() argument
424 return rv_r_insn(1, rs2, rs1, 0, rd, 0x33); in rv_mul()
427 static inline u32 rv_mulhu(u8 rd, u8 rs1, u8 rs2) in rv_mulhu() argument
429 return rv_r_insn(1, rs2, rs1, 3, rd, 0x33); in rv_mulhu()
432 static inline u32 rv_divu(u8 rd, u8 rs1, u8 rs2) in rv_divu() argument
434 return rv_r_insn(1, rs2, rs1, 5, rd, 0x33); in rv_divu()
437 static inline u32 rv_remu(u8 rd, u8 rs1, u8 rs2) in rv_remu() argument
439 return rv_r_insn(1, rs2, rs1, 7, rd, 0x33); in rv_remu()
442 static inline u32 rv_jal(u8 rd, u32 imm20_1) in rv_jal() argument
444 return rv_j_insn(imm20_1, rd, 0x6f); in rv_jal()
447 static inline u32 rv_jalr(u8 rd, u8 rs1, u16 imm11_0) in rv_jalr() argument
449 return rv_i_insn(imm11_0, rs1, 0, rd, 0x67); in rv_jalr()
502 static inline u32 rv_lw(u8 rd, u16 imm11_0, u8 rs1) in rv_lw() argument
504 return rv_i_insn(imm11_0, rs1, 2, rd, 0x03); in rv_lw()
507 static inline u32 rv_lbu(u8 rd, u16 imm11_0, u8 rs1) in rv_lbu() argument
509 return rv_i_insn(imm11_0, rs1, 4, rd, 0x03); in rv_lbu()
512 static inline u32 rv_lhu(u8 rd, u16 imm11_0, u8 rs1) in rv_lhu() argument
514 return rv_i_insn(imm11_0, rs1, 5, rd, 0x03); in rv_lhu()
532 static inline u32 rv_amoadd_w(u8 rd, u8 rs2, u8 rs1, u8 aq, u8 rl) in rv_amoadd_w() argument
534 return rv_amo_insn(0, aq, rl, rs2, rs1, 2, rd, 0x2f); in rv_amoadd_w()
539 static inline u16 rvc_addi4spn(u8 rd, u32 imm10) in rvc_addi4spn() argument
544 ((imm10 & 0x4) >> 1) | ((imm10 & 0x8) >> 3); in rvc_addi4spn()
545 return rv_ciw_insn(0x0, imm, rd, 0x0); in rvc_addi4spn()
548 static inline u16 rvc_lw(u8 rd, u32 imm7, u8 rs1) in rvc_lw() argument
552 imm_hi = (imm7 & 0x38) >> 3; in rvc_lw()
554 return rv_cl_insn(0x2, imm_hi, rs1, imm_lo, rd, 0x0); in rvc_lw()
561 imm_hi = (imm7 & 0x38) >> 3; in rvc_sw()
566 static inline u16 rvc_addi(u8 rd, u32 imm6) in rvc_addi() argument
568 return rv_ci_insn(0, imm6, rd, 0x1); in rvc_addi()
571 static inline u16 rvc_li(u8 rd, u32 imm6) in rvc_li() argument
573 return rv_ci_insn(0x2, imm6, rd, 0x1); in rvc_li()
580 imm = ((imm10 & 0x200) >> 4) | (imm10 & 0x10) | ((imm10 & 0x40) >> 3) | in rvc_addi16sp()
585 static inline u16 rvc_lui(u8 rd, u32 imm6) in rvc_lui() argument
587 return rv_ci_insn(0x3, imm6, rd, 0x1); in rvc_lui()
590 static inline u16 rvc_srli(u8 rd, u32 imm6) in rvc_srli() argument
592 return rv_cb_insn(0x4, imm6, 0, rd, 0x1); in rvc_srli()
595 static inline u16 rvc_srai(u8 rd, u32 imm6) in rvc_srai() argument
597 return rv_cb_insn(0x4, imm6, 0x1, rd, 0x1); in rvc_srai()
600 static inline u16 rvc_andi(u8 rd, u32 imm6) in rvc_andi() argument
602 return rv_cb_insn(0x4, imm6, 0x2, rd, 0x1); in rvc_andi()
605 static inline u16 rvc_sub(u8 rd, u8 rs) in rvc_sub() argument
607 return rv_ca_insn(0x23, rd, 0, rs, 0x1); in rvc_sub()
610 static inline u16 rvc_xor(u8 rd, u8 rs) in rvc_xor() argument
612 return rv_ca_insn(0x23, rd, 0x1, rs, 0x1); in rvc_xor()
615 static inline u16 rvc_or(u8 rd, u8 rs) in rvc_or() argument
617 return rv_ca_insn(0x23, rd, 0x2, rs, 0x1); in rvc_or()
620 static inline u16 rvc_and(u8 rd, u8 rs) in rvc_and() argument
622 return rv_ca_insn(0x23, rd, 0x3, rs, 0x1); in rvc_and()
625 static inline u16 rvc_slli(u8 rd, u32 imm6) in rvc_slli() argument
627 return rv_ci_insn(0, imm6, rd, 0x2); in rvc_slli()
630 static inline u16 rvc_lwsp(u8 rd, u32 imm8) in rvc_lwsp() argument
635 return rv_ci_insn(0x2, imm, rd, 0x2); in rvc_lwsp()
643 static inline u16 rvc_mv(u8 rd, u8 rs) in rvc_mv() argument
645 return rv_cr_insn(0x8, rd, rs, 0x2); in rvc_mv()
653 static inline u16 rvc_add(u8 rd, u8 rs) in rvc_add() argument
655 return rv_cr_insn(0x9, rd, rs, 0x2); in rvc_add()
675 static inline u32 rv_addiw(u8 rd, u8 rs1, u16 imm11_0) in rv_addiw() argument
677 return rv_i_insn(imm11_0, rs1, 0, rd, 0x1b); in rv_addiw()
680 static inline u32 rv_slliw(u8 rd, u8 rs1, u16 imm11_0) in rv_slliw() argument
682 return rv_i_insn(imm11_0, rs1, 1, rd, 0x1b); in rv_slliw()
685 static inline u32 rv_srliw(u8 rd, u8 rs1, u16 imm11_0) in rv_srliw() argument
687 return rv_i_insn(imm11_0, rs1, 5, rd, 0x1b); in rv_srliw()
690 static inline u32 rv_sraiw(u8 rd, u8 rs1, u16 imm11_0) in rv_sraiw() argument
692 return rv_i_insn(0x400 | imm11_0, rs1, 5, rd, 0x1b); in rv_sraiw()
695 static inline u32 rv_addw(u8 rd, u8 rs1, u8 rs2) in rv_addw() argument
697 return rv_r_insn(0, rs2, rs1, 0, rd, 0x3b); in rv_addw()
700 static inline u32 rv_subw(u8 rd, u8 rs1, u8 rs2) in rv_subw() argument
702 return rv_r_insn(0x20, rs2, rs1, 0, rd, 0x3b); in rv_subw()
705 static inline u32 rv_sllw(u8 rd, u8 rs1, u8 rs2) in rv_sllw() argument
707 return rv_r_insn(0, rs2, rs1, 1, rd, 0x3b); in rv_sllw()
710 static inline u32 rv_srlw(u8 rd, u8 rs1, u8 rs2) in rv_srlw() argument
712 return rv_r_insn(0, rs2, rs1, 5, rd, 0x3b); in rv_srlw()
715 static inline u32 rv_sraw(u8 rd, u8 rs1, u8 rs2) in rv_sraw() argument
717 return rv_r_insn(0x20, rs2, rs1, 5, rd, 0x3b); in rv_sraw()
720 static inline u32 rv_mulw(u8 rd, u8 rs1, u8 rs2) in rv_mulw() argument
722 return rv_r_insn(1, rs2, rs1, 0, rd, 0x3b); in rv_mulw()
725 static inline u32 rv_divuw(u8 rd, u8 rs1, u8 rs2) in rv_divuw() argument
727 return rv_r_insn(1, rs2, rs1, 5, rd, 0x3b); in rv_divuw()
730 static inline u32 rv_remuw(u8 rd, u8 rs1, u8 rs2) in rv_remuw() argument
732 return rv_r_insn(1, rs2, rs1, 7, rd, 0x3b); in rv_remuw()
735 static inline u32 rv_ld(u8 rd, u16 imm11_0, u8 rs1) in rv_ld() argument
737 return rv_i_insn(imm11_0, rs1, 3, rd, 0x03); in rv_ld()
740 static inline u32 rv_lwu(u8 rd, u16 imm11_0, u8 rs1) in rv_lwu() argument
742 return rv_i_insn(imm11_0, rs1, 6, rd, 0x03); in rv_lwu()
747 return rv_s_insn(imm11_0, rs2, rs1, 3, 0x23); in rv_sd()
750 static inline u32 rv_amoadd_d(u8 rd, u8 rs2, u8 rs1, u8 aq, u8 rl) in rv_amoadd_d() argument
752 return rv_amo_insn(0, aq, rl, rs2, rs1, 3, rd, 0x2f); in rv_amoadd_d()
757 static inline u16 rvc_ld(u8 rd, u32 imm8, u8 rs1) in rvc_ld() argument
761 imm_hi = (imm8 & 0x38) >> 3; in rvc_ld()
763 return rv_cl_insn(0x3, imm_hi, rs1, imm_lo, rd, 0x0); in rvc_ld()
770 imm_hi = (imm8 & 0x38) >> 3; in rvc_sd()
775 static inline u16 rvc_subw(u8 rd, u8 rs) in rvc_subw() argument
777 return rv_ca_insn(0x27, rd, 0, rs, 0x1); in rvc_subw()
780 static inline u16 rvc_addiw(u8 rd, u32 imm6) in rvc_addiw() argument
782 return rv_ci_insn(0x1, imm6, rd, 0x1); in rvc_addiw()
785 static inline u16 rvc_ldsp(u8 rd, u32 imm9) in rvc_ldsp() argument
790 return rv_ci_insn(0x3, imm, rd, 0x2); in rvc_ldsp()
805 static inline void emit_jalr(u8 rd, u8 rs, s32 imm, struct rv_jit_context *ctx) in emit_jalr() argument
807 if (rvc_enabled() && rd == RV_REG_RA && rs && !imm) in emit_jalr()
809 else if (rvc_enabled() && !rd && rs && !imm) in emit_jalr()
812 emit(rv_jalr(rd, rs, imm), ctx); in emit_jalr()
815 static inline void emit_mv(u8 rd, u8 rs, struct rv_jit_context *ctx) in emit_mv() argument
817 if (rvc_enabled() && rd && rs) in emit_mv()
818 emitc(rvc_mv(rd, rs), ctx); in emit_mv()
820 emit(rv_addi(rd, rs, 0), ctx); in emit_mv()
823 static inline void emit_add(u8 rd, u8 rs1, u8 rs2, struct rv_jit_context *ctx) in emit_add() argument
825 if (rvc_enabled() && rd && rd == rs1 && rs2) in emit_add()
826 emitc(rvc_add(rd, rs2), ctx); in emit_add()
828 emit(rv_add(rd, rs1, rs2), ctx); in emit_add()
831 static inline void emit_addi(u8 rd, u8 rs, s32 imm, struct rv_jit_context *ctx) in emit_addi() argument
833 if (rvc_enabled() && rd == RV_REG_SP && rd == rs && is_10b_int(imm) && imm && !(imm & 0xf)) in emit_addi()
835 else if (rvc_enabled() && is_creg(rd) && rs == RV_REG_SP && is_10b_uint(imm) && in emit_addi()
837 emitc(rvc_addi4spn(rd, imm), ctx); in emit_addi()
838 else if (rvc_enabled() && rd && rd == rs && imm && is_6b_int(imm)) in emit_addi()
839 emitc(rvc_addi(rd, imm), ctx); in emit_addi()
841 emit(rv_addi(rd, rs, imm), ctx); in emit_addi()
844 static inline void emit_li(u8 rd, s32 imm, struct rv_jit_context *ctx) in emit_li() argument
846 if (rvc_enabled() && rd && is_6b_int(imm)) in emit_li()
847 emitc(rvc_li(rd, imm), ctx); in emit_li()
849 emit(rv_addi(rd, RV_REG_ZERO, imm), ctx); in emit_li()
852 static inline void emit_lui(u8 rd, s32 imm, struct rv_jit_context *ctx) in emit_lui() argument
854 if (rvc_enabled() && rd && rd != RV_REG_SP && is_6b_int(imm) && imm) in emit_lui()
855 emitc(rvc_lui(rd, imm), ctx); in emit_lui()
857 emit(rv_lui(rd, imm), ctx); in emit_lui()
860 static inline void emit_slli(u8 rd, u8 rs, s32 imm, struct rv_jit_context *ctx) in emit_slli() argument
862 if (rvc_enabled() && rd && rd == rs && imm && (u32)imm < __riscv_xlen) in emit_slli()
863 emitc(rvc_slli(rd, imm), ctx); in emit_slli()
865 emit(rv_slli(rd, rs, imm), ctx); in emit_slli()
868 static inline void emit_andi(u8 rd, u8 rs, s32 imm, struct rv_jit_context *ctx) in emit_andi() argument
870 if (rvc_enabled() && is_creg(rd) && rd == rs && is_6b_int(imm)) in emit_andi()
871 emitc(rvc_andi(rd, imm), ctx); in emit_andi()
873 emit(rv_andi(rd, rs, imm), ctx); in emit_andi()
876 static inline void emit_srli(u8 rd, u8 rs, s32 imm, struct rv_jit_context *ctx) in emit_srli() argument
878 if (rvc_enabled() && is_creg(rd) && rd == rs && imm && (u32)imm < __riscv_xlen) in emit_srli()
879 emitc(rvc_srli(rd, imm), ctx); in emit_srli()
881 emit(rv_srli(rd, rs, imm), ctx); in emit_srli()
884 static inline void emit_srai(u8 rd, u8 rs, s32 imm, struct rv_jit_context *ctx) in emit_srai() argument
886 if (rvc_enabled() && is_creg(rd) && rd == rs && imm && (u32)imm < __riscv_xlen) in emit_srai()
887 emitc(rvc_srai(rd, imm), ctx); in emit_srai()
889 emit(rv_srai(rd, rs, imm), ctx); in emit_srai()
892 static inline void emit_sub(u8 rd, u8 rs1, u8 rs2, struct rv_jit_context *ctx) in emit_sub() argument
894 if (rvc_enabled() && is_creg(rd) && rd == rs1 && is_creg(rs2)) in emit_sub()
895 emitc(rvc_sub(rd, rs2), ctx); in emit_sub()
897 emit(rv_sub(rd, rs1, rs2), ctx); in emit_sub()
900 static inline void emit_or(u8 rd, u8 rs1, u8 rs2, struct rv_jit_context *ctx) in emit_or() argument
902 if (rvc_enabled() && is_creg(rd) && rd == rs1 && is_creg(rs2)) in emit_or()
903 emitc(rvc_or(rd, rs2), ctx); in emit_or()
905 emit(rv_or(rd, rs1, rs2), ctx); in emit_or()
908 static inline void emit_and(u8 rd, u8 rs1, u8 rs2, struct rv_jit_context *ctx) in emit_and() argument
910 if (rvc_enabled() && is_creg(rd) && rd == rs1 && is_creg(rs2)) in emit_and()
911 emitc(rvc_and(rd, rs2), ctx); in emit_and()
913 emit(rv_and(rd, rs1, rs2), ctx); in emit_and()
916 static inline void emit_xor(u8 rd, u8 rs1, u8 rs2, struct rv_jit_context *ctx) in emit_xor() argument
918 if (rvc_enabled() && is_creg(rd) && rd == rs1 && is_creg(rs2)) in emit_xor()
919 emitc(rvc_xor(rd, rs2), ctx); in emit_xor()
921 emit(rv_xor(rd, rs1, rs2), ctx); in emit_xor()
924 static inline void emit_lw(u8 rd, s32 off, u8 rs1, struct rv_jit_context *ctx) in emit_lw() argument
926 if (rvc_enabled() && rs1 == RV_REG_SP && rd && is_8b_uint(off) && !(off & 0x3)) in emit_lw()
927 emitc(rvc_lwsp(rd, off), ctx); in emit_lw()
928 else if (rvc_enabled() && is_creg(rd) && is_creg(rs1) && is_7b_uint(off) && !(off & 0x3)) in emit_lw()
929 emitc(rvc_lw(rd, off, rs1), ctx); in emit_lw()
931 emit(rv_lw(rd, off, rs1), ctx); in emit_lw()
947 static inline void emit_addiw(u8 rd, u8 rs, s32 imm, struct rv_jit_context *ctx) in emit_addiw() argument
949 if (rvc_enabled() && rd && rd == rs && is_6b_int(imm)) in emit_addiw()
950 emitc(rvc_addiw(rd, imm), ctx); in emit_addiw()
952 emit(rv_addiw(rd, rs, imm), ctx); in emit_addiw()
955 static inline void emit_ld(u8 rd, s32 off, u8 rs1, struct rv_jit_context *ctx) in emit_ld() argument
957 if (rvc_enabled() && rs1 == RV_REG_SP && rd && is_9b_uint(off) && !(off & 0x7)) in emit_ld()
958 emitc(rvc_ldsp(rd, off), ctx); in emit_ld()
959 else if (rvc_enabled() && is_creg(rd) && is_creg(rs1) && is_8b_uint(off) && !(off & 0x7)) in emit_ld()
960 emitc(rvc_ld(rd, off, rs1), ctx); in emit_ld()
962 emit(rv_ld(rd, off, rs1), ctx); in emit_ld()
975 static inline void emit_subw(u8 rd, u8 rs1, u8 rs2, struct rv_jit_context *ctx) in emit_subw() argument
977 if (rvc_enabled() && is_creg(rd) && rd == rs1 && is_creg(rs2)) in emit_subw()
978 emitc(rvc_subw(rd, rs2), ctx); in emit_subw()
980 emit(rv_subw(rd, rs1, rs2), ctx); in emit_subw()