1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:24:40 -07:00

math: add sqrt_arm.s and sqrtGoC.go as fallback to soft fp emulation

5a: add SQRTF and SQRTD
5l: add ASQRTF and ASQRTD

Use ARMv7 VFP VSQRT instruction to speed up math.Sqrt

R=rsc, dave, m
CC=golang-dev
https://golang.org/cl/4551082
This commit is contained in:
Fan Hongjian 2011-06-09 17:19:08 -04:00 committed by Russ Cox
parent 965ff4bb3a
commit fc41e621e8
10 changed files with 38 additions and 1 deletions

View File

@ -338,6 +338,8 @@ struct
"NRMD", LTYPEI, ANRMD, "NRMD", LTYPEI, ANRMD,
*/ */
"SQRTF", LTYPEI, ASQRTF,
"SQRTD", LTYPEI, ASQRTD,
"CMPF", LTYPEL, ACMPF, "CMPF", LTYPEL, ACMPF,
"CMPD", LTYPEL, ACMPD, "CMPD", LTYPEL, ACMPD,
"ADDF", LTYPEK, AADDF, "ADDF", LTYPEK, AADDF,

View File

@ -126,6 +126,8 @@ enum as
AMULD, AMULD,
ADIVF, ADIVF,
ADIVD, ADIVD,
ASQRTF,
ASQRTD,
ASRL, ASRL,
ASRA, ASRA,

View File

@ -1186,7 +1186,7 @@ if(debug['G']) print("%ux: %s: arm %d %d %d\n", (uint32)(p->pc), p->from.sym->na
r = p->reg; r = p->reg;
if(r == NREG) { if(r == NREG) {
r = rt; r = rt;
if(p->as == AMOVF || p->as == AMOVD) if(p->as == AMOVF || p->as == AMOVD || p->as == ASQRTF || p->as == ASQRTD)
r = 0; r = 0;
} }
o1 |= rf | (r<<16) | (rt<<12); o1 |= rf | (r<<16) | (rt<<12);
@ -1620,6 +1620,8 @@ oprrr(int a, int sc)
case AMULF: return o | (0xe<<24) | (0x2<<20) | (0xa<<8) | (0<<4); case AMULF: return o | (0xe<<24) | (0x2<<20) | (0xa<<8) | (0<<4);
case ADIVD: return o | (0xe<<24) | (0x8<<20) | (0xb<<8) | (0<<4); case ADIVD: return o | (0xe<<24) | (0x8<<20) | (0xb<<8) | (0<<4);
case ADIVF: return o | (0xe<<24) | (0x8<<20) | (0xa<<8) | (0<<4); case ADIVF: return o | (0xe<<24) | (0x8<<20) | (0xa<<8) | (0<<4);
case ASQRTD: return o | (0xe<<24) | (0xb<<20) | (1<<16) | (0xb<<8) | (0xc<<4);
case ASQRTF: return o | (0xe<<24) | (0xb<<20) | (1<<16) | (0xa<<8) | (0xc<<4);
case ACMPD: return o | (0xe<<24) | (0xb<<20) | (4<<16) | (0xb<<8) | (0xc<<4); case ACMPD: return o | (0xe<<24) | (0xb<<20) | (4<<16) | (0xb<<8) | (0xc<<4);
case ACMPF: return o | (0xe<<24) | (0xb<<20) | (4<<16) | (0xa<<8) | (0xc<<4); case ACMPF: return o | (0xe<<24) | (0xb<<20) | (4<<16) | (0xa<<8) | (0xc<<4);

View File

@ -67,6 +67,7 @@ static char*
linkername[] = linkername[] =
{ {
"runtime.softfloat", "runtime.softfloat",
"math.sqrtGoC",
}; };
void void

View File

@ -54,6 +54,8 @@ softfloat(void)
case AMULD: case AMULD:
case ADIVF: case ADIVF:
case ADIVD: case ADIVD:
case ASQRTF:
case ASQRTD:
goto soft; goto soft;
default: default:

View File

@ -1023,6 +1023,8 @@ buildop(void)
oprange[AMULD] = oprange[r]; oprange[AMULD] = oprange[r];
oprange[ADIVF] = oprange[r]; oprange[ADIVF] = oprange[r];
oprange[ADIVD] = oprange[r]; oprange[ADIVD] = oprange[r];
oprange[ASQRTF] = oprange[r];
oprange[ASQRTD] = oprange[r];
oprange[AMOVFD] = oprange[r]; oprange[AMOVFD] = oprange[r];
oprange[AMOVDF] = oprange[r]; oprange[AMOVDF] = oprange[r];
break; break;

View File

@ -6,6 +6,9 @@ include ../../Make.inc
TARG=math TARG=math
OFILES_arm=\
sqrt_arm.$O\
OFILES_amd64=\ OFILES_amd64=\
exp_amd64.$O\ exp_amd64.$O\
fabs_amd64.$O\ fabs_amd64.$O\

10
src/pkg/math/sqrt_arm.s Normal file
View File

@ -0,0 +1,10 @@
// Copyright 2011 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.
// func Sqrt(x float64) float64
TEXT ·Sqrt(SB),7,$0
MOVD x+0(FP),F0
SQRTD F0,F0
MOVD F0,r+8(FP)
RET

View File

@ -141,3 +141,7 @@ func sqrtGo(x float64) float64 {
ix = q>>1 + uint64(exp-1+bias)<<shift // significand + biased exponent ix = q>>1 + uint64(exp-1+bias)<<shift // significand + biased exponent
return Float64frombits(ix) return Float64frombits(ix)
} }
func sqrtGoC(f float64, r *float64) {
*r = sqrtGo(f)
}

View File

@ -357,6 +357,15 @@ stage3: // regd, regm are 4bit variables
regd, regm, m->freghi[regd], m->freglo[regd]); regd, regm, m->freghi[regd], m->freglo[regd]);
break; break;
case 0xeeb10bc0: // D[regd] = sqrt D[regm]
math·sqrtGoC(getd(regm), &uval);
putd(regd, uval);
if(trace)
runtime·printf("*** D[%d] = sqrt D[%d] %x-%x\n",
regd, regm, m->freghi[regd], m->freglo[regd]);
break;
case 0xeeb40bc0: // D[regd] :: D[regm] (CMPD) case 0xeeb40bc0: // D[regd] :: D[regm] (CMPD)
runtime·fcmp64c(getd(regd), getd(regm), &cmp, &nan); runtime·fcmp64c(getd(regd), getd(regm), &cmp, &nan);
m->fflag = fstatus(nan, cmp); m->fflag = fstatus(nan, cmp);