@@ -1377,10 +1377,14 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
13771377 case kLoong64Sub_d :
13781378 __ Sub_d (i.OutputRegister (), i.InputRegister (0 ), i.InputOperand (1 ));
13791379 break ;
1380- case kLoong64SubOvf_d :
1380+ case kLoong64SubOvf_d : {
1381+ UseScratchRegisterScope temps (masm ());
1382+ DCHECK (temps.hasAvailable ());
1383+ temps.Exclude (t8);
13811384 __ SubOverflow_d (i.OutputRegister (), i.InputRegister (0 ),
13821385 i.InputOperand (1 ), t8);
13831386 break ;
1387+ }
13841388 case kLoong64Mul_w :
13851389 __ Mul_w (i.OutputRegister (), i.InputRegister (0 ), i.InputOperand (1 ));
13861390 break ;
@@ -4617,7 +4621,7 @@ void CodeGenerator::AssembleArchBoolean(Instruction* instr,
46174621 }
46184622 return ;
46194623 } else {
4620- PrintF (" AssembleArchBranch Unimplemented arch_opcode is : %d\n " ,
4624+ PrintF (" AssembleArchBoolean Unimplemented arch_opcode is : %d\n " ,
46214625 instr->arch_opcode ());
46224626 TRACE (" UNIMPLEMENTED code_generator_loong64: %s at line %d\n " , __FUNCTION__,
46234627 __LINE__);
@@ -4672,56 +4676,49 @@ void CodeGenerator::AssembleArchSelect(Instruction* instr,
46724676 size_t output_index = instr->OutputCount () - 1 ;
46734677 // We don't know how many inputs were consumed by the condition, so we have to
46744678 // calculate the indices of the last two inputs.
4675- DCHECK_GE (instr->InputCount (), 4 );
46764679 size_t true_value_index = instr->InputCount () - 2 ;
46774680 size_t false_value_index = instr->InputCount () - 1 ;
4681+ Register result = i.OutputRegister (output_index);
4682+ Register v_true = i.InputOrZeroRegister (true_value_index);
4683+ Register v_false = i.InputOrZeroRegister (false_value_index);
4684+
4685+ DCHECK (
4686+ LocationOperand::cast (instr->OutputAt (output_index))->representation () ==
4687+ MachineRepresentation::kWord64 );
46784688
46794689 if (instr->arch_opcode () == kLoong64Tst ) {
4690+ DCHECK_GE (instr->InputCount (), 4 );
46804691 Condition cc = FlagsConditionToConditionTst (condition);
4681- Register result = i.OutputRegister (output_index);
4682- Register v_true = i.InputOrZeroRegister (true_value_index);
4683- Register v_false = i.InputOrZeroRegister (false_value_index);
4684- if (v_true == zero_reg || v_false == zero_reg) {
4685- if (v_true == zero_reg) {
4686- v_true = v_false;
4687- cc = NegateCondition (cc);
4688- }
4689- if (cc == eq)
4690- __ masknez (result, v_true, t8);
4691- else
4692- __ maskeqz (result, v_true, t8);
4693- } else if (result == v_true || result == v_false) {
4694- if (result == v_false) {
4695- v_false = v_true;
4696- cc = NegateCondition (cc);
4697- }
4698- Label done;
4699- __ Branch (&done, cc, t8, Operand (0 ));
4700- __ Move (result, v_false);
4701- __ bind (&done);
4702- } else {
4703- UseScratchRegisterScope temps (masm ());
4704- Register scratch = temps.Acquire ();
4705- if (cc == eq) {
4706- Register temp = v_true;
4707- v_true = v_false;
4708- v_false = temp;
4709- }
4710- __ maskeqz (scratch, v_true, t8);
4711- __ masknez (result, v_false, t8);
4712- __ or_ (result, scratch, result);
4692+ if (cc == eq) {
4693+ Register temp = v_true;
4694+ v_true = v_false;
4695+ v_false = temp;
47134696 }
4697+ __ SelectWord (result, t8, v_true, v_false);
47144698 UseScratchRegisterScope temps (masm ());
47154699 temps.Include (t8);
47164700 return ;
47174701 } else if (instr->arch_opcode () == kLoong64Cmp64 ||
4718- instr->arch_opcode () == kLoong64Cmp32 ) {
4702+ instr->arch_opcode () == kLoong64Cmp32 ||
4703+ instr->arch_opcode () == kArchStackPointerGreaterThan ) {
47194704 Condition cc = FlagsConditionToConditionCmp (condition);
4720- Register left = i.InputRegister (0 );
4721- Operand right = i.InputOperand (1 );
4722- Register result = i.OutputRegister (output_index);
4723- Register v_true = i.InputOrZeroRegister (true_value_index);
4724- Register v_false = i.InputOrZeroRegister (false_value_index);
4705+ Register left = no_reg;
4706+ Operand right = Operand (0 );
4707+ if (instr->arch_opcode () == kArchStackPointerGreaterThan ) {
4708+ DCHECK_GE (instr->InputCount (), 3 );
4709+ DCHECK ((cc == ls) || (cc == hi));
4710+ left = sp;
4711+ right = i.InputOperand (0 );
4712+ uint32_t offset;
4713+ if (ShouldApplyOffsetToStackCheck (instr, &offset)) {
4714+ left = i.TempRegister (1 );
4715+ __ Sub_d (left, sp, offset);
4716+ }
4717+ } else {
4718+ DCHECK_GE (instr->InputCount (), 4 );
4719+ left = i.InputRegister (0 );
4720+ right = i.InputOperand (1 );
4721+ }
47254722 if (v_true == zero_reg || v_false == zero_reg) {
47264723 if (v_true == zero_reg) {
47274724 v_true = v_false;
@@ -4751,6 +4748,108 @@ void CodeGenerator::AssembleArchSelect(Instruction* instr,
47514748 __ bind (&done);
47524749 }
47534750 return ;
4751+ } else if (instr->arch_opcode () == kLoong64Add_d ||
4752+ instr->arch_opcode () == kLoong64Sub_d ) {
4753+ DCHECK_GE (instr->InputCount (), 4 );
4754+ Condition cc = FlagsConditionToConditionOvf (condition);
4755+ if (cc == eq) {
4756+ Register temp = v_true;
4757+ v_true = v_false;
4758+ v_false = temp;
4759+ }
4760+ UseScratchRegisterScope temps (masm ());
4761+ Register scratch1 = temps.Acquire ();
4762+ Register scratch2 = temps.Acquire ();
4763+ __ srai_d (scratch1, i.OutputRegister (), 32 );
4764+ __ srai_w (scratch2, i.OutputRegister (), 31 );
4765+ if (v_false == zero_reg) {
4766+ __ xor_ (scratch1, scratch1, scratch2);
4767+ __ maskeqz (result, v_true, scratch1);
4768+ } else if (v_true == zero_reg) {
4769+ __ xor_ (scratch1, scratch1, scratch2);
4770+ __ masknez (result, v_false, scratch1);
4771+ } else if (result == v_true || result == v_false) {
4772+ if (result == v_false) {
4773+ v_false = v_true;
4774+ cc = NegateCondition (cc);
4775+ }
4776+ Label done;
4777+ __ Branch (&done, cc, scratch2, Operand (scratch1));
4778+ __ Move (result, v_false);
4779+ __ bind (&done);
4780+ } else {
4781+ Label true_label, done;
4782+ __ Branch (&true_label, cc, scratch2, Operand (scratch1));
4783+ __ Move (result, v_false);
4784+ __ Branch (&done);
4785+ __ bind (&true_label);
4786+ __ Move (result, v_true);
4787+ __ bind (&done);
4788+ }
4789+ return ;
4790+ } else if (instr->arch_opcode () == kLoong64AddOvf_d ||
4791+ instr->arch_opcode () == kLoong64SubOvf_d ) {
4792+ DCHECK_GE (instr->InputCount (), 4 );
4793+ // Overflow occurs if overflow register is negative
4794+ Condition cc = lt;
4795+ if (condition == kNotOverflow ) {
4796+ Register temp = v_true;
4797+ v_true = v_false;
4798+ v_false = temp;
4799+ }
4800+ if (v_false == zero_reg) {
4801+ __ slt (t8, t8, zero_reg);
4802+ __ maskeqz (result, v_true, t8);
4803+ } else if (v_true == zero_reg) {
4804+ __ slt (t8, t8, zero_reg);
4805+ __ masknez (result, v_false, t8);
4806+ } else if (result == v_true || result == v_false) {
4807+ if (result == v_false) {
4808+ v_false = v_true;
4809+ cc = NegateCondition (cc);
4810+ }
4811+ Label done;
4812+ __ Branch (&done, cc, t8, Operand (zero_reg));
4813+ __ Move (result, v_false);
4814+ __ bind (&done);
4815+ } else {
4816+ Label true_label, done;
4817+ __ Branch (&true_label, cc, t8, Operand (zero_reg));
4818+ __ Move (result, v_false);
4819+ __ Branch (&done);
4820+ __ bind (&true_label);
4821+ __ Move (result, v_true);
4822+ __ bind (&done);
4823+ }
4824+ UseScratchRegisterScope temps (masm ());
4825+ temps.Include (t8);
4826+ } else if (instr->arch_opcode () == kLoong64MulOvf_w ||
4827+ instr->arch_opcode () == kLoong64MulOvf_d ) {
4828+ DCHECK_GE (instr->InputCount (), 4 );
4829+ Condition cc = FlagsConditionToConditionOvf (condition);
4830+ if (cc == eq) {
4831+ Register temp = v_true;
4832+ v_true = v_false;
4833+ v_false = temp;
4834+ }
4835+ __ SelectWord (result, t8, v_true, v_false);
4836+ UseScratchRegisterScope temps (masm ());
4837+ temps.Include (t8);
4838+ return ;
4839+ } else if (instr->arch_opcode () == kLoong64Float32Cmp ||
4840+ instr->arch_opcode () == kLoong64Float64Cmp ) {
4841+ bool predicate;
4842+ FlagsConditionToConditionCmpFPU (&predicate, condition);
4843+ UseScratchRegisterScope temps (masm ());
4844+ Register scratch = temps.Acquire ();
4845+ if (!predicate) {
4846+ Register temp = v_true;
4847+ v_true = v_false;
4848+ v_false = temp;
4849+ }
4850+ __ movcf2gr (scratch, FCC0 );
4851+ __ SelectWord (result, scratch, v_true, v_false);
4852+ return ;
47544853 } else {
47554854 PrintF (" AssembleArchSelect Unimplemented arch_opcode is : %d\n " ,
47564855 instr->arch_opcode ());
0 commit comments