github.com/epfl-dcsl/gotee@v0.0.0-20200909122901-014b35f5e5e9/src/cmd/compile/internal/ssa/softfloat.go (about)

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package ssa
     6  
     7  import "math"
     8  
     9  func softfloat(f *Func) {
    10  	if !f.Config.SoftFloat {
    11  		return
    12  	}
    13  	newInt64 := false
    14  
    15  	for _, b := range f.Blocks {
    16  		for _, v := range b.Values {
    17  			if v.Type.IsFloat() {
    18  				switch v.Op {
    19  				case OpPhi, OpLoad, OpArg:
    20  					if v.Type.Size() == 4 {
    21  						v.Type = f.Config.Types.UInt32
    22  					} else {
    23  						v.Type = f.Config.Types.UInt64
    24  					}
    25  				case OpConst32F:
    26  					v.Op = OpConst32
    27  					v.Type = f.Config.Types.UInt32
    28  					v.AuxInt = int64(int32(math.Float32bits(i2f32(v.AuxInt))))
    29  				case OpConst64F:
    30  					v.Op = OpConst64
    31  					v.Type = f.Config.Types.UInt64
    32  				case OpNeg32F:
    33  					arg0 := v.Args[0]
    34  					v.reset(OpXor32)
    35  					v.Type = f.Config.Types.UInt32
    36  					v.AddArg(arg0)
    37  					mask := v.Block.NewValue0(v.Pos, OpConst32, v.Type)
    38  					mask.AuxInt = -0x80000000
    39  					v.AddArg(mask)
    40  				case OpNeg64F:
    41  					arg0 := v.Args[0]
    42  					v.reset(OpXor64)
    43  					v.Type = f.Config.Types.UInt64
    44  					v.AddArg(arg0)
    45  					mask := v.Block.NewValue0(v.Pos, OpConst64, v.Type)
    46  					mask.AuxInt = -0x8000000000000000
    47  					v.AddArg(mask)
    48  				case OpRound32F:
    49  					v.Op = OpCopy
    50  					v.Type = f.Config.Types.UInt32
    51  				case OpRound64F:
    52  					v.Op = OpCopy
    53  					v.Type = f.Config.Types.UInt64
    54  				}
    55  				newInt64 = newInt64 || v.Type.Size() == 8
    56  			}
    57  		}
    58  	}
    59  
    60  	if newInt64 && f.Config.RegSize == 4 {
    61  		// On 32bit arch, decompose Uint64 introduced in the switch above.
    62  		decomposeBuiltIn(f)
    63  		applyRewrite(f, rewriteBlockdec64, rewriteValuedec64)
    64  	}
    65  
    66  }