Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

math: improve math.Log to handle subnormal floating number on amd64 #56601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
liu-du wants to merge 1 commit into golang:master
base: master
Choose a base branch
Loading
from liu-du:master
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/math/all_test.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,27 @@ var logSC = []float64{
NaN(),
}

var vflogBC = []float64{
SmallestNonzeroFloat64,
LargestSubnormalFloat64,
SmallestNormalFloat64,
MaxFloat64,
-SmallestNonzeroFloat64,
-LargestSubnormalFloat64,
-SmallestNormalFloat64,
-MaxFloat64,
}
var logBC = []float64{
-744.4400719213812,
-708.3964185322641,
-708.3964185322641,
709.782712893384,
NaN(),
NaN(),
NaN(),
NaN(),
}

var vflogbSC = []float64{
Inf(-1),
0,
Expand Down Expand Up @@ -2717,6 +2738,12 @@ func TestLog(t *testing.T) {
t.Errorf("Log(%g) = %g, want %g", vflogSC[i], f, logSC[i])
}
}

for i := 0; i < len(vflogBC); i++ {
if f := Log(vflogBC[i]); !alike(logBC[i], f) {
t.Errorf("Log(%g) = %g, want %g", vflogBC[i], f, logBC[i])
}
}
}

func TestLogb(t *testing.T) {
Expand Down
11 changes: 11 additions & 0 deletions src/math/log_amd64.s
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define L5 1.818357216161805012e-01 // 0x3FC7466496CB03DE
#define L6 1.531383769920937332e-01 // 0x3FC39A09D078C69F
#define L7 1.479819860511658591e-01 // 0x3FC2F112DF3E5244
#define Two52 4.503599627370496e15 // 0x4330000000000000 (2**52)
#define NaN 0x7FF8000000000001
#define NegInf 0xFFF0000000000000
#define PosInf 0x7FF0000000000000
Expand All @@ -32,7 +33,16 @@ TEXT ·archLog(SB),NOSPLIT,0ドル
CMPQ AX, BX
JLE isInfOrNaN
// f1, ki := math.Frexp(x); k := float64(ki)
MOVQ 0,ドル CX
MOVQ BX, X0
ANDQ BX, AX
JNE isNormal
// f, exp = normalize(f)
MOVSD $Two52, X1
MULSD X1, X0
MOVQ X0, BX
MOVQ $-52, CX
isNormal:
MOVQ 0ドルx000FFFFFFFFFFFFF, AX
MOVQ AX, X2
ANDPD X0, X2
Expand All @@ -41,6 +51,7 @@ TEXT ·archLog(SB),NOSPLIT,0ドル
SHRQ 52,ドル BX
ANDL 0ドルx7FF, BX
SUBL 0ドルx3FE, BX
ADDQ CX, BX
XORPS X1, X1 // break dependency for CVTSL2SD
CVTSL2SD BX, X1 // x1= k, x2= f1
// if f1 < math.Sqrt2/2 { k -= 1; f1 *= 2 }
Expand Down

AltStyle によって変換されたページ (->オリジナル) /