@@ -1401,10 +1401,14 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
14011401 case kLoong64Sub_d :
14021402 __ Sub_d (i.OutputRegister (), i.InputRegister (0 ), i.InputOperand (1 ));
14031403 break ;
1404- case kLoong64SubOvf_d :
1404+ case kLoong64SubOvf_d : {
1405+ UseScratchRegisterScope temps (masm ());
1406+ DCHECK (temps.hasAvailable ());
1407+ temps.Exclude (t8);
14051408 __ SubOverflow_d (i.OutputRegister (), i.InputRegister (0 ),
14061409 i.InputOperand (1 ), t8);
14071410 break ;
1411+ }
14081412 case kLoong64Sub128 : {
14091413 UseScratchRegisterScope temps (masm ());
14101414 Register scratch = temps.Acquire ();
@@ -4701,7 +4705,7 @@ void CodeGenerator::AssembleArchBoolean(Instruction* instr,
47014705 }
47024706 return ;
47034707 } else {
4704- PrintF (" AssembleArchBranch Unimplemented arch_opcode is : %d\n " ,
4708+ PrintF (" AssembleArchBoolean Unimplemented arch_opcode is : %d\n " ,
47054709 instr->arch_opcode ());
47064710 TRACE (" UNIMPLEMENTED code_generator_loong64: %s at line %d\n " , __FUNCTION__,
47074711 __LINE__);
@@ -4756,56 +4760,49 @@ void CodeGenerator::AssembleArchSelect(Instruction* instr,
47564760 size_t output_index = instr->OutputCount () - 1 ;
47574761 // We don't know how many inputs were consumed by the condition, so we have to
47584762 // calculate the indices of the last two inputs.
4759- DCHECK_GE (instr->InputCount (), 4 );
47604763 size_t true_value_index = instr->InputCount () - 2 ;
47614764 size_t false_value_index = instr->InputCount () - 1 ;
4765+ Register result = i.OutputRegister (output_index);
4766+ Register v_true = i.InputOrZeroRegister (true_value_index);
4767+ Register v_false = i.InputOrZeroRegister (false_value_index);
4768+
4769+ DCHECK (
4770+ LocationOperand::cast (instr->OutputAt (output_index))->representation () ==
4771+ MachineRepresentation::kWord64 );
47624772
47634773 if (instr->arch_opcode () == kLoong64Tst ) {
4774+ DCHECK_GE (instr->InputCount (), 4 );
47644775 Condition cc = FlagsConditionToConditionTst (condition);
4765- Register result = i.OutputRegister (output_index);
4766- Register v_true = i.InputOrZeroRegister (true_value_index);
4767- Register v_false = i.InputOrZeroRegister (false_value_index);
4768- if (v_true == zero_reg || v_false == zero_reg) {
4769- if (v_true == zero_reg) {
4770- v_true = v_false;
4771- cc = NegateCondition (cc);
4772- }
4773- if (cc == eq)
4774- __ masknez (result, v_true, t8);
4775- else
4776- __ maskeqz (result, v_true, t8);
4777- } else if (result == v_true || result == v_false) {
4778- if (result == v_false) {
4779- v_false = v_true;
4780- cc = NegateCondition (cc);
4781- }
4782- Label done;
4783- __ Branch (&done, cc, t8, Operand (0 ));
4784- __ Move (result, v_false);
4785- __ bind (&done);
4786- } else {
4787- UseScratchRegisterScope temps (masm ());
4788- Register scratch = temps.Acquire ();
4789- if (cc == eq) {
4790- Register temp = v_true;
4791- v_true = v_false;
4792- v_false = temp;
4793- }
4794- __ maskeqz (scratch, v_true, t8);
4795- __ masknez (result, v_false, t8);
4796- __ or_ (result, scratch, result);
4776+ if (cc == eq) {
4777+ Register temp = v_true;
4778+ v_true = v_false;
4779+ v_false = temp;
47974780 }
4781+ __ SelectWord (result, t8, v_true, v_false);
47984782 UseScratchRegisterScope temps (masm ());
47994783 temps.Include (t8);
48004784 return ;
48014785 } else if (instr->arch_opcode () == kLoong64Cmp64 ||
4802- instr->arch_opcode () == kLoong64Cmp32 ) {
4786+ instr->arch_opcode () == kLoong64Cmp32 ||
4787+ instr->arch_opcode () == kArchStackPointerGreaterThan ) {
48034788 Condition cc = FlagsConditionToConditionCmp (condition);
4804- Register left = i.InputRegister (0 );
4805- Operand right = i.InputOperand (1 );
4806- Register result = i.OutputRegister (output_index);
4807- Register v_true = i.InputOrZeroRegister (true_value_index);
4808- Register v_false = i.InputOrZeroRegister (false_value_index);
4789+ Register left = no_reg;
4790+ Operand right = Operand (0 );
4791+ if (instr->arch_opcode () == kArchStackPointerGreaterThan ) {
4792+ DCHECK_GE (instr->InputCount (), 3 );
4793+ DCHECK ((cc == ls) || (cc == hi));
4794+ left = sp;
4795+ right = i.InputOperand (0 );
4796+ uint32_t offset;
4797+ if (ShouldApplyOffsetToStackCheck (instr, &offset)) {
4798+ left = i.TempRegister (1 );
4799+ __ Sub_d (left, sp, offset);
4800+ }
4801+ } else {
4802+ DCHECK_GE (instr->InputCount (), 4 );
4803+ left = i.InputRegister (0 );
4804+ right = i.InputOperand (1 );
4805+ }
48094806 if (v_true == zero_reg || v_false == zero_reg) {
48104807 if (v_true == zero_reg) {
48114808 v_true = v_false;
@@ -4835,6 +4832,108 @@ void CodeGenerator::AssembleArchSelect(Instruction* instr,
48354832 __ bind (&done);
48364833 }
48374834 return ;
4835+ } else if (instr->arch_opcode () == kLoong64Add_d ||
4836+ instr->arch_opcode () == kLoong64Sub_d ) {
4837+ DCHECK_GE (instr->InputCount (), 4 );
4838+ Condition cc = FlagsConditionToConditionOvf (condition);
4839+ if (cc == eq) {
4840+ Register temp = v_true;
4841+ v_true = v_false;
4842+ v_false = temp;
4843+ }
4844+ UseScratchRegisterScope temps (masm ());
4845+ Register scratch1 = temps.Acquire ();
4846+ Register scratch2 = temps.Acquire ();
4847+ __ srai_d (scratch1, i.OutputRegister (), 32 );
4848+ __ srai_w (scratch2, i.OutputRegister (), 31 );
4849+ if (v_false == zero_reg) {
4850+ __ xor_ (scratch1, scratch1, scratch2);
4851+ __ maskeqz (result, v_true, scratch1);
4852+ } else if (v_true == zero_reg) {
4853+ __ xor_ (scratch1, scratch1, scratch2);
4854+ __ masknez (result, v_false, scratch1);
4855+ } else if (result == v_true || result == v_false) {
4856+ if (result == v_false) {
4857+ v_false = v_true;
4858+ cc = NegateCondition (cc);
4859+ }
4860+ Label done;
4861+ __ Branch (&done, cc, scratch2, Operand (scratch1));
4862+ __ Move (result, v_false);
4863+ __ bind (&done);
4864+ } else {
4865+ Label true_label, done;
4866+ __ Branch (&true_label, cc, scratch2, Operand (scratch1));
4867+ __ Move (result, v_false);
4868+ __ Branch (&done);
4869+ __ bind (&true_label);
4870+ __ Move (result, v_true);
4871+ __ bind (&done);
4872+ }
4873+ return ;
4874+ } else if (instr->arch_opcode () == kLoong64AddOvf_d ||
4875+ instr->arch_opcode () == kLoong64SubOvf_d ) {
4876+ DCHECK_GE (instr->InputCount (), 4 );
4877+ // Overflow occurs if overflow register is negative
4878+ Condition cc = lt;
4879+ if (condition == kNotOverflow ) {
4880+ Register temp = v_true;
4881+ v_true = v_false;
4882+ v_false = temp;
4883+ }
4884+ if (v_false == zero_reg) {
4885+ __ slt (t8, t8, zero_reg);
4886+ __ maskeqz (result, v_true, t8);
4887+ } else if (v_true == zero_reg) {
4888+ __ slt (t8, t8, zero_reg);
4889+ __ masknez (result, v_false, t8);
4890+ } else if (result == v_true || result == v_false) {
4891+ if (result == v_false) {
4892+ v_false = v_true;
4893+ cc = NegateCondition (cc);
4894+ }
4895+ Label done;
4896+ __ Branch (&done, cc, t8, Operand (zero_reg));
4897+ __ Move (result, v_false);
4898+ __ bind (&done);
4899+ } else {
4900+ Label true_label, done;
4901+ __ Branch (&true_label, cc, t8, Operand (zero_reg));
4902+ __ Move (result, v_false);
4903+ __ Branch (&done);
4904+ __ bind (&true_label);
4905+ __ Move (result, v_true);
4906+ __ bind (&done);
4907+ }
4908+ UseScratchRegisterScope temps (masm ());
4909+ temps.Include (t8);
4910+ } else if (instr->arch_opcode () == kLoong64MulOvf_w ||
4911+ instr->arch_opcode () == kLoong64MulOvf_d ) {
4912+ DCHECK_GE (instr->InputCount (), 4 );
4913+ Condition cc = FlagsConditionToConditionOvf (condition);
4914+ if (cc == eq) {
4915+ Register temp = v_true;
4916+ v_true = v_false;
4917+ v_false = temp;
4918+ }
4919+ __ SelectWord (result, t8, v_true, v_false);
4920+ UseScratchRegisterScope temps (masm ());
4921+ temps.Include (t8);
4922+ return ;
4923+ } else if (instr->arch_opcode () == kLoong64Float32Cmp ||
4924+ instr->arch_opcode () == kLoong64Float64Cmp ) {
4925+ bool predicate;
4926+ FlagsConditionToConditionCmpFPU (&predicate, condition);
4927+ UseScratchRegisterScope temps (masm ());
4928+ Register scratch = temps.Acquire ();
4929+ if (!predicate) {
4930+ Register temp = v_true;
4931+ v_true = v_false;
4932+ v_false = temp;
4933+ }
4934+ __ movcf2gr (scratch, FCC0 );
4935+ __ SelectWord (result, scratch, v_true, v_false);
4936+ return ;
48384937 } else {
48394938 PrintF (" AssembleArchSelect Unimplemented arch_opcode is : %d\n " ,
48404939 instr->arch_opcode ());
0 commit comments