Repository: go
Issue: math: math.Log does not handle subnormal floating point number on amd64
Labels: NeedsInvestigation

<!--
Please answer these questions before submitting your issue. Thanks!
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.18.3 darwin/amd64
</pre>

### Does this issue reproduce with the latest release?
Yes


### What operating system and processor architecture are you using (`go env`)?
macOS and amd64
<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/$USER/Library/Caches/go-build"
GOENV="/Users/$USER/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/$USER/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/$USER/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.18.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.18.3/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/$USER/code/go/src/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/nn/pgfwsh7d0kn99mpmf7fd35_r0000gn/T/go-build681644206=/tmp/go-build -gno-record-gcc-switches -fno-common"
</pre></details>

### What did you do?

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on go.dev/play is best.
-->

I tried `math.Log` on very small float64 (subnormal IEEE floating point number), it gives incorrect result. This only happens on amd64, when `math/log_amd64.S` is used. 

Running the same go code on, for example, arm64 gives correct results. I found `math/log_amd64.S` doesn't normalize subnormal floating number, whereas the go implementation of [math.log](https://github.com/golang/go/blob/master/src/math/log.go#L88) (which calls math.Frexp) [does normalise](https://github.com/golang/go/blob/master/src/math/frexp.go#L32) the floating point number. Hence different arch gives different results.

### What did you expect to see?

The natural log for subnormal floating number should be correct. The equivalent c code gives correct result (python/java also gives the same results as c, although they possibly just call the c implementation):

```c
#include <stdio.h>
#include <math.h>

int main() {
    printf("%f\n", log(pow(2, -1074))); // -744.440072
    printf("%f\n", log(exp(1) * pow(2, -1074))); // -743.341460
    printf("%f\n", log(exp(2) * pow(2, -1074))); // -742.494162
    printf("%f\n", log(exp(3) * pow(2, -1074))); // -741.444340
}
```


### What did you see instead?
```go
// x should be around -744 but it's -709
x := math.Log(math.SmallestNonzeroFloat64) // -709.0895657128241

// should be around x + 1, but it's equal x
fmt.Println(math.Log(math.Exp(1) * math.SmallestNonzeroFloat64))// -709.0895657128241

// should be around x + 2, but it's equal x
fmt.Println(math.Log(math.Exp(2) * math.SmallestNonzeroFloat64)) // -709.0895657128241

// should be around x + 3, but it's equal x
fmt.Println(math.Log(math.Exp(3) * math.SmallestNonzeroFloat64)) // -709.0895657128241
```

go.dev/play link: https://go.dev/play/p/uksqrp1Zq0-