Commit f83e4212 authored by Cherry Zhang's avatar Cherry Zhang

cmd/internal/obj/arm, runtime: delete old ARM softfloat code

CL 106735 changed to the new softfloat support on GOARM=5.

ARM assembly code that uses FP instructions not guarded on GOARM,
if any, will break. The easiest way to fix is probably to use Go
implementation on GOARM=5, like

	MOVB	runtime·goarm(SB), R11
	CMP	$5, R11
	BEQ	arm5
	... FP instructions ...
	RET
arm5:
	CALL or JMP to Go implementation

Change-Id: I52fc76fac9c854ebe7c6c856c365fba35d3f560a
Reviewed-on: https://go-review.googlesource.com/107475
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 58b18cfd
......@@ -306,7 +306,7 @@ var armOperandTests = []operandTest{
{"g", "g"},
{"gosave<>(SB)", "gosave<>(SB)"},
{"retlo+12(FP)", "retlo+12(FP)"},
{"runtime·_sfloat2(SB)", "runtime._sfloat2(SB)"},
{"runtime·gogo(SB)", "runtime.gogo(SB)"},
{"·AddUint32(SB)", "\"\".AddUint32(SB)"},
{"(R1, R3)", "(R1, R3)"},
{"[R0,R1,g,R15", ""}, // Issue 11764 - asm hung parsing ']' missing register lists.
......
......@@ -255,8 +255,6 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
c := ctxt5{ctxt: ctxt, cursym: cursym, newprog: newprog}
c.softfloat()
p := c.cursym.Func.Text
autoffset := int32(p.To.Offset)
if autoffset == -4 {
......@@ -649,87 +647,6 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
}
}
func isfloatreg(a *obj.Addr) bool {
return a.Type == obj.TYPE_REG && REG_F0 <= a.Reg && a.Reg <= REG_F15
}
func (c *ctxt5) softfloat() {
if objabi.GOARM > 5 {
return
}
symsfloat := c.ctxt.Lookup("runtime._sfloat")
wasfloat := 0
for p := c.cursym.Func.Text; p != nil; p = p.Link {
if p.Pcond != nil {
p.Pcond.Mark |= LABEL
}
}
var next *obj.Prog
for p := c.cursym.Func.Text; p != nil; p = p.Link {
switch p.As {
case AMOVW:
if isfloatreg(&p.To) || isfloatreg(&p.From) {
goto soft
}
goto notsoft
case AMOVWD,
AMOVWF,
AMOVDW,
AMOVFW,
AMOVFD,
AMOVDF,
AMOVF,
AMOVD,
ACMPF,
ACMPD,
AADDF,
AADDD,
ASUBF,
ASUBD,
AMULF,
AMULD,
ADIVF,
ADIVD,
ASQRTF,
ASQRTD,
AABSF,
AABSD,
ANEGF,
ANEGD:
goto soft
default:
goto notsoft
}
soft:
if wasfloat == 0 || (p.Mark&LABEL != 0) {
next = c.newprog()
*next = *p
// BL runtime·_sfloat(SB)
*p = obj.Prog{}
p.Ctxt = c.ctxt
p.Link = next
p.As = ABL
p.To.Type = obj.TYPE_BRANCH
p.To.Sym = symsfloat
p.Pos = next.Pos
p = next
wasfloat = 1
}
continue
notsoft:
wasfloat = 0
}
}
func (c *ctxt5) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
// MOVW g_stackguard(g), R1
p = obj.Appendp(p, c.newprog)
......
......@@ -21,7 +21,6 @@ var F32to64 = f32to64
var Fcmp64 = fcmp64
var Fintto64 = fintto64
var F64toint = f64toint
var Sqrt = sqrt
var Entersyscall = entersyscall
var Exitsyscall = exitsyscall
......
......@@ -432,15 +432,6 @@ func gopanic(e interface{}) {
throw("panic on system stack")
}
// m.softfloat is set during software floating point.
// It increments m.locks to avoid preemption.
// We moved the memory loads out, so there shouldn't be
// any reason for it to panic anymore.
if gp.m.softfloat != 0 {
gp.m.locks--
gp.m.softfloat = 0
throw("panic during softfloat")
}
if gp.m.mallocing != 0 {
print("panic: ")
printany(e)
......@@ -787,7 +778,7 @@ func canpanic(gp *g) bool {
if gp == nil || gp != _m_.curg {
return false
}
if _m_.locks-_m_.softfloat != 0 || _m_.mallocing != 0 || _m_.throwing != 0 || _m_.preemptoff != "" || _m_.dying != 0 {
if _m_.locks != 0 || _m_.mallocing != 0 || _m_.throwing != 0 || _m_.preemptoff != "" || _m_.dying != 0 {
return false
}
status := readgstatus(gp)
......
......@@ -421,7 +421,6 @@ type m struct {
throwing int32
preemptoff string // if != "", keep curg running on this m
locks int32
softfloat int32
dying int32
profilehz int32
helpgc int32
......@@ -445,9 +444,6 @@ type m struct {
mcache *mcache
lockedg guintptr
createstack [32]uintptr // stack that created this thread.
freglo [16]uint32 // d[i] lsb and f[i]
freghi [16]uint32 // d[i] msb and f[i+16]
fflag uint32 // floating point compare flags
lockedExt uint32 // tracking for external LockOSThread
lockedInt uint32 // tracking for internal lockOSThread
nextwaitm muintptr // next m waiting for lock
......
This diff is collapsed.
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Copy of math/sqrt.go, here for use by ARM softfloat.
// Modified to not use any floating point arithmetic so
// that we don't clobber any floating-point registers
// while emulating the sqrt instruction.
package runtime
// The original C code and the long comment below are
// from FreeBSD's /usr/src/lib/msun/src/e_sqrt.c and
// came with this notice. The go code is a simplified
// version of the original C.
//
// ====================================================
// Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
//
// Developed at SunPro, a Sun Microsystems, Inc. business.
// Permission to use, copy, modify, and distribute this
// software is freely granted, provided that this notice
// is preserved.
// ====================================================
//
// __ieee754_sqrt(x)
// Return correctly rounded sqrt.
// -----------------------------------------
// | Use the hardware sqrt if you have one |
// -----------------------------------------
// Method:
// Bit by bit method using integer arithmetic. (Slow, but portable)
// 1. Normalization
// Scale x to y in [1,4) with even powers of 2:
// find an integer k such that 1 <= (y=x*2**(2k)) < 4, then
// sqrt(x) = 2**k * sqrt(y)
// 2. Bit by bit computation
// Let q = sqrt(y) truncated to i bit after binary point (q = 1),
// i 0
// i+1 2
// s = 2*q , and y = 2 * ( y - q ). (1)
// i i i i
//
// To compute q from q , one checks whether
// i+1 i
//
// -(i+1) 2
// (q + 2 ) <= y. (2)
// i
// -(i+1)
// If (2) is false, then q = q ; otherwise q = q + 2 .
// i+1 i i+1 i
//
// With some algebraic manipulation, it is not difficult to see
// that (2) is equivalent to
// -(i+1)
// s + 2 <= y (3)
// i i
//
// The advantage of (3) is that s and y can be computed by
// i i
// the following recurrence formula:
// if (3) is false
//
// s = s , y = y ; (4)
// i+1 i i+1 i
//
// otherwise,
// -i -(i+1)
// s = s + 2 , y = y - s - 2 (5)
// i+1 i i+1 i i
//
// One may easily use induction to prove (4) and (5).
// Note. Since the left hand side of (3) contain only i+2 bits,
// it does not necessary to do a full (53-bit) comparison
// in (3).
// 3. Final rounding
// After generating the 53 bits result, we compute one more bit.
// Together with the remainder, we can decide whether the
// result is exact, bigger than 1/2ulp, or less than 1/2ulp
// (it will never equal to 1/2ulp).
// The rounding mode can be detected by checking whether
// huge + tiny is equal to huge, and whether huge - tiny is
// equal to huge for some floating point number "huge" and "tiny".
//
//
// Notes: Rounding mode detection omitted.
const (
float64Mask = 0x7FF
float64Shift = 64 - 11 - 1
float64Bias = 1023
float64NaN = 0x7FF8000000000001
float64Inf = 0x7FF0000000000000
maxFloat64 = 1.797693134862315708145274237317043567981e+308 // 2**1023 * (2**53 - 1) / 2**52
)
// isnanu returns whether ix represents a NaN floating point number.
func isnanu(ix uint64) bool {
exp := (ix >> float64Shift) & float64Mask
sig := ix << (64 - float64Shift) >> (64 - float64Shift)
return exp == float64Mask && sig != 0
}
func sqrt(ix uint64) uint64 {
// special cases
switch {
case ix == 0 || ix == 1<<63: // x == 0
return ix
case isnanu(ix): // x != x
return ix
case ix&(1<<63) != 0: // x < 0
return float64NaN
case ix == float64Inf: // x > MaxFloat
return ix
}
// normalize x
exp := int((ix >> float64Shift) & float64Mask)
if exp == 0 { // subnormal x
for ix&(1<<float64Shift) == 0 {
ix <<= 1
exp--
}
exp++
}
exp -= float64Bias // unbias exponent
ix &^= float64Mask << float64Shift
ix |= 1 << float64Shift
if exp&1 == 1 { // odd exp, double x to make it even
ix <<= 1
}
exp >>= 1 // exp = exp/2, exponent of square root
// generate sqrt(x) bit by bit
ix <<= 1
var q, s uint64 // q = sqrt(x)
r := uint64(1 << (float64Shift + 1)) // r = moving bit from MSB to LSB
for r != 0 {
t := s + r
if t <= ix {
s = t + r
ix -= t
q += r
}
ix <<= 1
r >>= 1
}
// final rounding
if ix != 0 { // remainder, result not exact
q += q & 1 // round according to extra bit
}
ix = q>>1 + uint64(exp-1+float64Bias)<<float64Shift // significand + biased exponent
return ix
}
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// A copy of Sqrt tests from the math package to test the
// purely integer arithmetic implementation in sqrt.go.
package runtime_test
import (
"math"
"runtime"
"testing"
)
func SqrtRT(x float64) float64 {
return math.Float64frombits(runtime.Sqrt(math.Float64bits(x)))
}
func TestSqrt(t *testing.T) {
for i := 0; i < len(vf); i++ {
a := math.Abs(vf[i])
if f := SqrtRT(a); sqrt[i] != f {
t.Errorf("Sqrt(%g) = %g, want %g", a, f, sqrt[i])
}
}
for i := 0; i < len(vfsqrtSC); i++ {
if f := SqrtRT(vfsqrtSC[i]); !alike(sqrtSC[i], f) {
t.Errorf("Sqrt(%g) = %g, want %g", vfsqrtSC[i], f, sqrtSC[i])
}
}
}
func alike(a, b float64) bool {
switch {
case math.IsNaN(a) && math.IsNaN(b):
return true
case a == b:
return math.Signbit(a) == math.Signbit(b)
}
return false
}
var vf = []float64{
4.9790119248836735e+00,
7.7388724745781045e+00,
-2.7688005719200159e-01,
-5.0106036182710749e+00,
9.6362937071984173e+00,
2.9263772392439646e+00,
5.2290834314593066e+00,
2.7279399104360102e+00,
1.8253080916808550e+00,
-8.6859247685756013e+00,
}
var sqrt = []float64{
2.2313699659365484748756904e+00,
2.7818829009464263511285458e+00,
5.2619393496314796848143251e-01,
2.2384377628763938724244104e+00,
3.1042380236055381099288487e+00,
1.7106657298385224403917771e+00,
2.286718922705479046148059e+00,
1.6516476350711159636222979e+00,
1.3510396336454586262419247e+00,
2.9471892997524949215723329e+00,
}
var vfsqrtSC = []float64{
math.Inf(-1),
-math.Pi,
math.Copysign(0, -1),
0,
math.Inf(1),
math.NaN(),
math.Float64frombits(2),
}
var sqrtSC = []float64{
math.NaN(),
math.NaN(),
math.Copysign(0, -1),
0,
math.Inf(1),
math.NaN(),
3.1434555694052576e-162,
}
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package runtime
// Stubs to pacify vet. Not safe to call from Go.
// Calls to these functions are inserted by the compiler or assembler.
func udiv()
func _div()
func _divu()
func _mod()
func _modu()
......@@ -28,68 +28,6 @@
#include "funcdata.h"
#include "textflag.h"
// trampoline for _sfloat2. passes LR as arg0 and
// saves registers R0-R13 and CPSR on the stack. R0-R12 and CPSR flags can
// be changed by _sfloat2.
TEXT runtime·_sfloat(SB), NOSPLIT, $68-0 // 4 arg + 14*4 saved regs + cpsr + return value
MOVW R14, 4(R13)
MOVW R0, 8(R13)
MOVW $12(R13), R0
MOVM.IA.W [R1-R12], (R0)
MOVW $72(R13), R1 // correct for frame size
MOVW R1, 60(R13)
WORD $0xe10f1000 // mrs r1, cpsr
MOVW R1, 64(R13)
// Disable preemption of this goroutine during _sfloat2 by
// m->locks++ and m->locks-- around the call.
// Rescheduling this goroutine may cause the loss of the
// contents of the software floating point registers in
// m->freghi, m->freglo, m->fflag, if the goroutine is moved
// to a different m or another goroutine runs on this m.
// Rescheduling at ordinary function calls is okay because
// all registers are caller save, but _sfloat2 and the things
// that it runs are simulating the execution of individual
// program instructions, and those instructions do not expect
// the floating point registers to be lost.
// An alternative would be to move the software floating point
// registers into G, but they do not need to be kept at the
// usual places a goroutine reschedules (at function calls),
// so it would be a waste of 132 bytes per G.
MOVW g_m(g), R8
MOVW m_locks(R8), R1
ADD $1, R1
MOVW R1, m_locks(R8)
MOVW $1, R1
MOVW R1, m_softfloat(R8)
BL runtime·_sfloat2(SB)
MOVW 68(R13), R0
MOVW g_m(g), R8
MOVW m_locks(R8), R1
SUB $1, R1
MOVW R1, m_locks(R8)
MOVW $0, R1
MOVW R1, m_softfloat(R8)
MOVW R0, 0(R13)
MOVW 64(R13), R1
WORD $0xe128f001 // msr cpsr_f, r1
MOVW $12(R13), R0
// Restore R1-R12, R0.
MOVM.IA.W (R0), [R1-R12]
MOVW 8(R13), R0
RET
// trampoline for _sfloat2 panic.
// _sfloat2 instructs _sfloat to return here.
// We need to push a fake saved LR onto the stack,
// load the signal fault address into LR, and jump
// to the real sigpanic.
// This simulates what sighandler does for a memory fault.
TEXT runtime·_sfloatpanic(SB),NOSPLIT|NOFRAME,$0
MOVW $0, R0
MOVW.W R0, -4(R13)
MOVW g_sigpc(g), LR
B runtime·sigpanic(SB)
// func runtime·udiv(n, d uint32) (q, r uint32)
// compiler knowns the register usage of this function
// Reference:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment