@@ -15,6 +15,7 @@ import (
15
15
"cmd/compile/internal/types"
16
16
"cmd/internal/obj"
17
17
"cmd/internal/obj/mips"
18
+ "internal/abi"
18
19
)
19
20
20
21
// isFPreg reports whether r is an FP register.
@@ -486,18 +487,167 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
486
487
p .To .Name = obj .NAME_EXTERN
487
488
// AuxInt encodes how many buffer entries we need.
488
489
p .To .Sym = ir .Syms .GCWriteBarrier [v .AuxInt - 1 ]
489
- case ssa .OpMIPSLoweredPanicBoundsA , ssa .OpMIPSLoweredPanicBoundsB , ssa .OpMIPSLoweredPanicBoundsC :
490
- p := s .Prog (obj .ACALL )
491
- p .To .Type = obj .TYPE_MEM
492
- p .To .Name = obj .NAME_EXTERN
493
- p .To .Sym = ssagen .BoundsCheckFunc [v .AuxInt ]
494
- s .UseArgs (8 ) // space used in callee args area by assembly stubs
495
- case ssa .OpMIPSLoweredPanicExtendA , ssa .OpMIPSLoweredPanicExtendB , ssa .OpMIPSLoweredPanicExtendC :
496
- p := s .Prog (obj .ACALL )
490
+
491
+ case ssa .OpMIPSLoweredPanicBoundsRR , ssa .OpMIPSLoweredPanicBoundsRC , ssa .OpMIPSLoweredPanicBoundsCR , ssa .OpMIPSLoweredPanicBoundsCC ,
492
+ ssa .OpMIPSLoweredPanicExtendRR , ssa .OpMIPSLoweredPanicExtendRC :
493
+ // Compute the constant we put in the PCData entry for this call.
494
+ code , signed := ssa .BoundsKind (v .AuxInt ).Code ()
495
+ xIsReg := false
496
+ yIsReg := false
497
+ xVal := 0
498
+ yVal := 0
499
+ extend := false
500
+ switch v .Op {
501
+ case ssa .OpMIPSLoweredPanicBoundsRR :
502
+ xIsReg = true
503
+ xVal = int (v .Args [0 ].Reg () - mips .REG_R1 )
504
+ yIsReg = true
505
+ yVal = int (v .Args [1 ].Reg () - mips .REG_R1 )
506
+ case ssa .OpMIPSLoweredPanicExtendRR :
507
+ extend = true
508
+ xIsReg = true
509
+ hi := int (v .Args [0 ].Reg () - mips .REG_R1 )
510
+ lo := int (v .Args [1 ].Reg () - mips .REG_R1 )
511
+ xVal = hi << 2 + lo // encode 2 register numbers
512
+ yIsReg = true
513
+ yVal = int (v .Args [2 ].Reg () - mips .REG_R1 )
514
+ case ssa .OpMIPSLoweredPanicBoundsRC :
515
+ xIsReg = true
516
+ xVal = int (v .Args [0 ].Reg () - mips .REG_R1 )
517
+ c := v .Aux .(ssa.PanicBoundsC ).C
518
+ if c >= 0 && c <= abi .BoundsMaxConst {
519
+ yVal = int (c )
520
+ } else {
521
+ // Move constant to a register
522
+ yIsReg = true
523
+ if yVal == xVal {
524
+ yVal = 1
525
+ }
526
+ p := s .Prog (mips .AMOVW )
527
+ p .From .Type = obj .TYPE_CONST
528
+ p .From .Offset = c
529
+ p .To .Type = obj .TYPE_REG
530
+ p .To .Reg = mips .REG_R1 + int16 (yVal )
531
+ }
532
+ case ssa .OpMIPSLoweredPanicExtendRC :
533
+ extend = true
534
+ xIsReg = true
535
+ hi := int (v .Args [0 ].Reg () - mips .REG_R1 )
536
+ lo := int (v .Args [1 ].Reg () - mips .REG_R1 )
537
+ xVal = hi << 2 + lo // encode 2 register numbers
538
+ c := v .Aux .(ssa.PanicBoundsC ).C
539
+ if c >= 0 && c <= abi .BoundsMaxConst {
540
+ yVal = int (c )
541
+ } else {
542
+ // Move constant to a register
543
+ for yVal == hi || yVal == lo {
544
+ yVal ++
545
+ }
546
+ p := s .Prog (mips .AMOVW )
547
+ p .From .Type = obj .TYPE_CONST
548
+ p .From .Offset = c
549
+ p .To .Type = obj .TYPE_REG
550
+ p .To .Reg = mips .REG_R1 + int16 (yVal )
551
+ }
552
+ case ssa .OpMIPSLoweredPanicBoundsCR :
553
+ yIsReg = true
554
+ yVal := int (v .Args [0 ].Reg () - mips .REG_R1 )
555
+ c := v .Aux .(ssa.PanicBoundsC ).C
556
+ if c >= 0 && c <= abi .BoundsMaxConst {
557
+ xVal = int (c )
558
+ } else if signed && int64 (int32 (c )) == c || ! signed && int64 (uint32 (c )) == c {
559
+ // Move constant to a register
560
+ xIsReg = true
561
+ if xVal == yVal {
562
+ xVal = 1
563
+ }
564
+ p := s .Prog (mips .AMOVW )
565
+ p .From .Type = obj .TYPE_CONST
566
+ p .From .Offset = c
567
+ p .To .Type = obj .TYPE_REG
568
+ p .To .Reg = mips .REG_R1 + int16 (xVal )
569
+ } else {
570
+ // Move constant to two registers
571
+ extend = true
572
+ xIsReg = true
573
+ hi := 0
574
+ lo := 1
575
+ if hi == yVal {
576
+ hi = 2
577
+ }
578
+ if lo == yVal {
579
+ lo = 2
580
+ }
581
+ xVal = hi << 2 + lo
582
+ p := s .Prog (mips .AMOVW )
583
+ p .From .Type = obj .TYPE_CONST
584
+ p .From .Offset = c >> 32
585
+ p .To .Type = obj .TYPE_REG
586
+ p .To .Reg = mips .REG_R1 + int16 (hi )
587
+ p = s .Prog (mips .AMOVW )
588
+ p .From .Type = obj .TYPE_CONST
589
+ p .From .Offset = int64 (int32 (c ))
590
+ p .To .Type = obj .TYPE_REG
591
+ p .To .Reg = mips .REG_R1 + int16 (lo )
592
+ }
593
+ case ssa .OpMIPSLoweredPanicBoundsCC :
594
+ c := v .Aux .(ssa.PanicBoundsCC ).Cx
595
+ if c >= 0 && c <= abi .BoundsMaxConst {
596
+ xVal = int (c )
597
+ } else if signed && int64 (int32 (c )) == c || ! signed && int64 (uint32 (c )) == c {
598
+ // Move constant to a register
599
+ xIsReg = true
600
+ p := s .Prog (mips .AMOVW )
601
+ p .From .Type = obj .TYPE_CONST
602
+ p .From .Offset = c
603
+ p .To .Type = obj .TYPE_REG
604
+ p .To .Reg = mips .REG_R1 + int16 (xVal )
605
+ } else {
606
+ // Move constant to two registers
607
+ extend = true
608
+ xIsReg = true
609
+ hi := 0
610
+ lo := 1
611
+ xVal = hi << 2 + lo
612
+ p := s .Prog (mips .AMOVW )
613
+ p .From .Type = obj .TYPE_CONST
614
+ p .From .Offset = c >> 32
615
+ p .To .Type = obj .TYPE_REG
616
+ p .To .Reg = mips .REG_R1 + int16 (hi )
617
+ p = s .Prog (mips .AMOVW )
618
+ p .From .Type = obj .TYPE_CONST
619
+ p .From .Offset = int64 (int32 (c ))
620
+ p .To .Type = obj .TYPE_REG
621
+ p .To .Reg = mips .REG_R1 + int16 (lo )
622
+ }
623
+ c = v .Aux .(ssa.PanicBoundsCC ).Cy
624
+ if c >= 0 && c <= abi .BoundsMaxConst {
625
+ yVal = int (c )
626
+ } else {
627
+ // Move constant to a register
628
+ yIsReg = true
629
+ yVal = 2
630
+ p := s .Prog (mips .AMOVW )
631
+ p .From .Type = obj .TYPE_CONST
632
+ p .From .Offset = c
633
+ p .To .Type = obj .TYPE_REG
634
+ p .To .Reg = mips .REG_R1 + int16 (yVal )
635
+ }
636
+ }
637
+ c := abi .BoundsEncode (code , signed , xIsReg , yIsReg , xVal , yVal )
638
+
639
+ p := s .Prog (obj .APCDATA )
640
+ p .From .SetConst (abi .PCDATA_PanicBounds )
641
+ p .To .SetConst (int64 (c ))
642
+ p = s .Prog (obj .ACALL )
497
643
p .To .Type = obj .TYPE_MEM
498
644
p .To .Name = obj .NAME_EXTERN
499
- p .To .Sym = ssagen .ExtendCheckFunc [v .AuxInt ]
500
- s .UseArgs (12 ) // space used in callee args area by assembly stubs
645
+ if extend {
646
+ p .To .Sym = ir .Syms .PanicExtend
647
+ } else {
648
+ p .To .Sym = ir .Syms .PanicBounds
649
+ }
650
+
501
651
case ssa .OpMIPSLoweredAtomicLoad8 ,
502
652
ssa .OpMIPSLoweredAtomicLoad32 :
503
653
s .Prog (mips .ASYNC )
0 commit comments