[backend]将内联MEMSET函数的步长改为4字节
This commit is contained in:
@ -1216,14 +1216,12 @@ void RISCv64ISel::selectNode(DAGNode* node) {
|
|||||||
std::string remainder_label = MFunc->getName() + "_memset_remainder_" + std::to_string(unique_id);
|
std::string remainder_label = MFunc->getName() + "_memset_remainder_" + std::to_string(unique_id);
|
||||||
std::string done_label = MFunc->getName() + "_memset_done_" + std::to_string(unique_id);
|
std::string done_label = MFunc->getName() + "_memset_done_" + std::to_string(unique_id);
|
||||||
|
|
||||||
// 构造64位的填充值
|
// 构造32位的填充值 (将一个字节复制4次)
|
||||||
addi_instr(RVOpcodes::ANDI, r_temp_val, r_value_byte, 255);
|
addi_instr(RVOpcodes::ANDI, r_temp_val, r_value_byte, 255); // 提取低8位: 000000XX
|
||||||
addi_instr(RVOpcodes::SLLI, r_value_byte, r_temp_val, 8);
|
addi_instr(RVOpcodes::SLLI, r_value_byte, r_temp_val, 8); // 左移8位: 0000XX00
|
||||||
add_instr(RVOpcodes::OR, r_temp_val, r_temp_val, r_value_byte);
|
add_instr(RVOpcodes::OR, r_temp_val, r_temp_val, r_value_byte); // 合并得到: 0000XXXX
|
||||||
addi_instr(RVOpcodes::SLLI, r_value_byte, r_temp_val, 16);
|
addi_instr(RVOpcodes::SLLI, r_value_byte, r_temp_val, 16); // 左移16位: XXXX0000
|
||||||
add_instr(RVOpcodes::OR, r_temp_val, r_temp_val, r_value_byte);
|
add_instr(RVOpcodes::OR, r_temp_val, r_temp_val, r_value_byte); // 合并得到完整的32位值: XXXXXXXX
|
||||||
addi_instr(RVOpcodes::SLLI, r_value_byte, r_temp_val, 32);
|
|
||||||
add_instr(RVOpcodes::OR, r_temp_val, r_temp_val, r_value_byte);
|
|
||||||
|
|
||||||
// 计算循环边界
|
// 计算循环边界
|
||||||
add_instr(RVOpcodes::ADD, r_end_addr, r_dest_addr, r_num_bytes);
|
add_instr(RVOpcodes::ADD, r_end_addr, r_dest_addr, r_num_bytes);
|
||||||
@ -1231,14 +1229,16 @@ void RISCv64ISel::selectNode(DAGNode* node) {
|
|||||||
mv->addOperand(std::make_unique<RegOperand>(r_current_addr));
|
mv->addOperand(std::make_unique<RegOperand>(r_current_addr));
|
||||||
mv->addOperand(std::make_unique<RegOperand>(r_dest_addr));
|
mv->addOperand(std::make_unique<RegOperand>(r_dest_addr));
|
||||||
CurMBB->addInstruction(std::move(mv));
|
CurMBB->addInstruction(std::move(mv));
|
||||||
addi_instr(RVOpcodes::ANDI, r_counter, r_num_bytes, -8);
|
// 计算主循环部分的总字节数 (向下舍入到4的倍数)
|
||||||
|
addi_instr(RVOpcodes::ANDI, r_counter, r_num_bytes, -4);
|
||||||
|
// 计算主循环的结束地址
|
||||||
add_instr(RVOpcodes::ADD, r_counter, r_dest_addr, r_counter);
|
add_instr(RVOpcodes::ADD, r_counter, r_dest_addr, r_counter);
|
||||||
|
|
||||||
// 8字节主循环
|
// 4字节主循环
|
||||||
label_instr(loop_start_label);
|
label_instr(loop_start_label);
|
||||||
branch_instr(RVOpcodes::BGEU, r_current_addr, r_counter, loop_end_label);
|
branch_instr(RVOpcodes::BGEU, r_current_addr, r_counter, loop_end_label);
|
||||||
store_instr(RVOpcodes::SD, r_temp_val, r_current_addr, 0);
|
store_instr(RVOpcodes::SW, r_temp_val, r_current_addr, 0); // 使用 sw (存储字)
|
||||||
addi_instr(RVOpcodes::ADDI, r_current_addr, r_current_addr, 8);
|
addi_instr(RVOpcodes::ADDI, r_current_addr, r_current_addr, 4); // 步长改为4
|
||||||
jump_instr(loop_start_label);
|
jump_instr(loop_start_label);
|
||||||
|
|
||||||
// 1字节收尾循环
|
// 1字节收尾循环
|
||||||
|
|||||||
Reference in New Issue
Block a user