提交 298bc25c 编写于 作者: Z Zihao Yu

rtl: remove unnecessary basic rtl instructions

上级 85ef00c7
...@@ -8,20 +8,21 @@ ...@@ -8,20 +8,21 @@
#define c_xor(a, b) ((a) ^ (b)) #define c_xor(a, b) ((a) ^ (b))
#define c_shl(a, b) ((a) << (b)) #define c_shl(a, b) ((a) << (b))
#define c_shr(a, b) ((a) >> (b)) #define c_shr(a, b) ((a) >> (b))
#define c_shr64(a, b) ((uint32_t)(a) >> (b)) #define c_sar(a, b) ((sword_t)(a) >> (b))
#define c_sar(a, b) ((int32_t)(a) >> (b))
#define c_sar64(a, b) ((int64_t)(a) >> (b))
#define c_mul_lo(a, b) ((a) * (b)) #define c_mul_lo(a, b) ((a) * (b))
#define c_mul_hi(a, b) (((uint64_t)(a) * (uint64_t)(b)) >> 32) #define c_imul_lo(a, b) ((sword_t)(a) * (sword_t)(b))
#define c_imul_lo(a, b) ((int32_t)(a) * (int32_t)(b)) #ifdef ISA64
#define c_imul_hi(a, b) (((int64_t)(int32_t)(a) * (int64_t)(int32_t)(b)) >> 32) # define c_mul_hi(a, b) (((__uint128_t)(a) * (__uint128_t)(b)) >> 64)
# define c_imul_hi(a, b) (((__int128_t)(sword_t)(a) * (__int128_t)(sword_t)(b)) >> 64)
#else
# define c_mul_hi(a, b) (((uint64_t)(a) * (uint64_t)(b)) >> 32)
# define c_imul_hi(a, b) (((int64_t)(sword_t)(a) * (int64_t)(sword_t)(b)) >> 32)
#endif
#define c_div_q(a, b) ((a) / (b)) #define c_div_q(a, b) ((a) / (b))
#define c_div_q64(a, b) (((a) & 0xffffffff) / ((b) & 0xffffffff))
#define c_div_r(a, b) ((a) % (b)) #define c_div_r(a, b) ((a) % (b))
#define c_div_r64(a, b) (((a) & 0xffffffff) % ((b) & 0xffffffff)) #define c_idiv_q(a, b) ((sword_t)(a) / (sword_t)(b))
#define c_idiv_q(a, b) ((int32_t)(a) / (int32_t)(b)) #define c_idiv_r(a, b) ((sword_t)(a) % (sword_t)(b))
#define c_idiv_q64(a, b) ((int32_t)((uint32_t)((a) & 0xffffffff)) / (int32_t)((uint32_t)((b) & 0xffffffff)))
#define c_idiv_r(a, b) ((int32_t)(a) % (int32_t)(b))
#define c_idiv_r64(a, b) ((int32_t)((uint32_t)((a) & 0xffffffff)) % (int32_t)((uint32_t)((b) & 0xffffffff)))
#endif #endif
...@@ -14,21 +14,15 @@ ...@@ -14,21 +14,15 @@
#define rtl_xor concat(RTL_PREFIX, _rtl_xor ) #define rtl_xor concat(RTL_PREFIX, _rtl_xor )
#define rtl_shl concat(RTL_PREFIX, _rtl_shl ) #define rtl_shl concat(RTL_PREFIX, _rtl_shl )
#define rtl_shr concat(RTL_PREFIX, _rtl_shr ) #define rtl_shr concat(RTL_PREFIX, _rtl_shr )
#define rtl_shr64 concat(RTL_PREFIX, _rtl_shr64 )
#define rtl_sar concat(RTL_PREFIX, _rtl_sar ) #define rtl_sar concat(RTL_PREFIX, _rtl_sar )
#define rtl_sar64 concat(RTL_PREFIX, _rtl_sar64 )
#define rtl_mul_lo concat(RTL_PREFIX, _rtl_mul_lo ) #define rtl_mul_lo concat(RTL_PREFIX, _rtl_mul_lo )
#define rtl_mul_hi concat(RTL_PREFIX, _rtl_mul_hi ) #define rtl_mul_hi concat(RTL_PREFIX, _rtl_mul_hi )
#define rtl_imul_lo concat(RTL_PREFIX, _rtl_imul_lo ) #define rtl_imul_lo concat(RTL_PREFIX, _rtl_imul_lo )
#define rtl_imul_hi concat(RTL_PREFIX, _rtl_imul_hi ) #define rtl_imul_hi concat(RTL_PREFIX, _rtl_imul_hi )
#define rtl_div_q concat(RTL_PREFIX, _rtl_div_q ) #define rtl_div_q concat(RTL_PREFIX, _rtl_div_q )
#define rtl_div_q64 concat(RTL_PREFIX, _rtl_div_q64 )
#define rtl_div_r concat(RTL_PREFIX, _rtl_div_r ) #define rtl_div_r concat(RTL_PREFIX, _rtl_div_r )
#define rtl_div_r64 concat(RTL_PREFIX, _rtl_div_r64 )
#define rtl_idiv_q concat(RTL_PREFIX, _rtl_idiv_q ) #define rtl_idiv_q concat(RTL_PREFIX, _rtl_idiv_q )
#define rtl_idiv_q64 concat(RTL_PREFIX, _rtl_idiv_q64)
#define rtl_idiv_r concat(RTL_PREFIX, _rtl_idiv_r ) #define rtl_idiv_r concat(RTL_PREFIX, _rtl_idiv_r )
#define rtl_idiv_r64 concat(RTL_PREFIX, _rtl_idiv_r64)
#define rtl_div64_q concat(RTL_PREFIX, _rtl_div64_q ) #define rtl_div64_q concat(RTL_PREFIX, _rtl_div64_q )
#define rtl_div64_r concat(RTL_PREFIX, _rtl_div64_r ) #define rtl_div64_r concat(RTL_PREFIX, _rtl_div64_r )
#define rtl_idiv64_q concat(RTL_PREFIX, _rtl_idiv64_q) #define rtl_idiv64_q concat(RTL_PREFIX, _rtl_idiv64_q)
......
...@@ -49,15 +49,6 @@ make_rtl_arith_logic(div_r) ...@@ -49,15 +49,6 @@ make_rtl_arith_logic(div_r)
make_rtl_arith_logic(idiv_q) make_rtl_arith_logic(idiv_q)
make_rtl_arith_logic(idiv_r) make_rtl_arith_logic(idiv_r)
#ifdef ISA64
make_rtl_arith_logic(shr64)
make_rtl_arith_logic(sar64)
make_rtl_arith_logic(div_q64)
make_rtl_arith_logic(div_r64)
make_rtl_arith_logic(idiv_q64)
make_rtl_arith_logic(idiv_r64)
#endif
static inline void interpret_rtl_div64_q(rtlreg_t* dest, static inline void interpret_rtl_div64_q(rtlreg_t* dest,
const rtlreg_t* src1_hi, const rtlreg_t* src1_lo, const rtlreg_t* src2) { const rtlreg_t* src1_hi, const rtlreg_t* src1_lo, const rtlreg_t* src2) {
uint64_t dividend = ((uint64_t)(*src1_hi) << 32) | (*src1_lo); uint64_t dividend = ((uint64_t)(*src1_hi) << 32) | (*src1_lo);
...@@ -155,7 +146,7 @@ static inline void rtl_sext(rtlreg_t* dest, const rtlreg_t* src1, int width) { ...@@ -155,7 +146,7 @@ static inline void rtl_sext(rtlreg_t* dest, const rtlreg_t* src1, int width) {
} else { } else {
assert(width == 1 || width == 2 || width == 4); assert(width == 1 || width == 2 || width == 4);
rtl_shli(dest, src1, (8 - width) * 8); rtl_shli(dest, src1, (8 - width) * 8);
rtl_sar64i(dest, dest, (8 - width) * 8); rtl_sari(dest, dest, (8 - width) * 8);
} }
#else #else
if (width == 4) { if (width == 4) {
......
...@@ -117,6 +117,7 @@ make_EHelper(sllw) { ...@@ -117,6 +117,7 @@ make_EHelper(sllw) {
} }
make_EHelper(srlw) { make_EHelper(srlw) {
rtl_andi(&id_src2->val, &id_src2->val, 0x1f);
if (decinfo.isa.instr.funct7 == 32) { if (decinfo.isa.instr.funct7 == 32) {
// sraw // sraw
rtl_sar(&s0, &id_src->val, &id_src2->val); rtl_sar(&s0, &id_src->val, &id_src2->val);
...@@ -125,9 +126,8 @@ make_EHelper(srlw) { ...@@ -125,9 +126,8 @@ make_EHelper(srlw) {
} }
else { else {
// srlw // srlw
rtl_andi(&id_src2->val, &id_src2->val, 0x1f); rtl_andi(&id_src->val, &id_src->val, 0xffffffffu);
rtl_shr(&s0, &id_src->val, &id_src2->val);
rtl_shr64(&s0, &id_src->val, &id_src2->val);
rtl_sext(&s0, &s0, 4); rtl_sext(&s0, &s0, 4);
print_asm_template3(srlw); print_asm_template3(srlw);
} }
......
#include "cpu/exec.h" #include "cpu/exec.h"
make_EHelper(mul) { make_EHelper(mul) {
#ifdef ISA64
rtl_mul_lo(&s0, &id_src->val, &id_src2->val); rtl_mul_lo(&s0, &id_src->val, &id_src2->val);
#else
rtl_imul_lo(&s0, &id_src->val, &id_src2->val);
#endif
rtl_sr(id_dest->reg, &s0, 4); rtl_sr(id_dest->reg, &s0, 4);
print_asm_template3(mul); print_asm_template3(mul);
...@@ -54,7 +50,7 @@ make_EHelper(remu) { ...@@ -54,7 +50,7 @@ make_EHelper(remu) {
} }
make_EHelper(mulw) { make_EHelper(mulw) {
rtl_imul_lo(&s0, &id_src->val, &id_src2->val); rtl_mul_lo(&s0, &id_src->val, &id_src2->val);
rtl_sext(&s0, &s0, 4); rtl_sext(&s0, &s0, 4);
rtl_sr(id_dest->reg, &s0, 4); rtl_sr(id_dest->reg, &s0, 4);
...@@ -62,15 +58,19 @@ make_EHelper(mulw) { ...@@ -62,15 +58,19 @@ make_EHelper(mulw) {
} }
make_EHelper(divw) { make_EHelper(divw) {
rtl_idiv_q64(&s0, &id_src->val, &id_src2->val); rtl_sext(&s0, &id_src->val, 4);
rtl_sext(&s1, &id_src2->val, 4);
rtl_idiv_q(&s0, &s0, &s1);
rtl_sext(&s0, &s0, 4); rtl_sext(&s0, &s0, 4);
rtl_sr(id_dest->reg, &s0, 4); rtl_sr(id_dest->reg, &s0, 4);
print_asm_template3(div); print_asm_template3(divw);
} }
make_EHelper(remw) { make_EHelper(remw) {
rtl_idiv_r64(&s0, &id_src->val, &id_src2->val); rtl_sext(&s0, &id_src->val, 4);
rtl_sext(&s1, &id_src2->val, 4);
rtl_idiv_r(&s0, &s0, &s1);
rtl_sext(&s0, &s0, 4); rtl_sext(&s0, &s0, 4);
rtl_sr(id_dest->reg, &s0, 4); rtl_sr(id_dest->reg, &s0, 4);
...@@ -78,7 +78,9 @@ make_EHelper(remw) { ...@@ -78,7 +78,9 @@ make_EHelper(remw) {
} }
make_EHelper(divuw) { make_EHelper(divuw) {
rtl_div_q64(&s0, &id_src->val, &id_src2->val); rtl_andi(&s0, &id_src->val, 0xffffffffu);
rtl_andi(&s1, &id_src2->val, 0xffffffffu);
rtl_div_q(&s0, &s0, &s1);
rtl_sext(&s0, &s0, 4); rtl_sext(&s0, &s0, 4);
rtl_sr(id_dest->reg, &s0, 4); rtl_sr(id_dest->reg, &s0, 4);
...@@ -86,9 +88,11 @@ make_EHelper(divuw) { ...@@ -86,9 +88,11 @@ make_EHelper(divuw) {
} }
make_EHelper(remuw) { make_EHelper(remuw) {
rtl_idiv_r64(&s0, &id_src->val, &id_src2->val); rtl_andi(&s0, &id_src->val, 0xffffffffu);
rtl_andi(&s1, &id_src2->val, 0xffffffffu);
rtl_div_r(&s0, &s0, &s1);
rtl_sext(&s0, &s0, 4); rtl_sext(&s0, &s0, 4);
rtl_sr(id_dest->reg, &s0, 4); rtl_sr(id_dest->reg, &s0, 4);
print_asm_template3(remuw); print_asm_template3(remuw);
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册