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

Commit 52f73f1

Browse files
committed
math: add ARM64 implementation of hypot
Add ARM64 assembly implementation of hypot. The benchmark which run on Apple Silicon M1 chip is listed as following. BenchmarkHypot BenchmarkHypot-8 2.185 ns/op 0 B/op 0 allocs/op BenchmarkHypotGo BenchmarkHypotGo-8 3.462 ns/op 0 B/op 0 allocs/op delta: -36.89%
1 parent 6e73886 commit 52f73f1

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

‎src/math/hypot_arm64.s

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2021 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+
#include "textflag.h"
6+
7+
#define PosInf 0x7FF0000000000000
8+
#define NaN 0x7FF8000000000001
9+
10+
// func archHypot(p, q float64) float64
11+
TEXT ·archHypot(SB), NOSPLIT, 0ドル-24
12+
FMOVD p+0(FP), F0
13+
FMOVD q+8(FP), F1
14+
MOVD $PosInf, R0
15+
FMOVD R0, F30 // F30 is PosInf
16+
17+
FABSD F0, F0
18+
FABSD F1, F1
19+
FCMPD F30, F0
20+
BGE isInf
21+
FCMPD F30, F1
22+
BGE isInf
23+
24+
FCMPED F0, F0
25+
BNE isNaN
26+
FCMPED F1, F1
27+
BNE isNaN
28+
29+
FMAXD F0, F1, F2 // p is greater
30+
FMIND F0, F1, F3 // q is less
31+
FCMPD F2, 0.0
32+
BEQ IsZero // if p == 0, return 0
33+
34+
// p q
35+
FDIVD F2, F3, F3
36+
FMULD F3, F3, F3
37+
FMOVD 1ドル.0, F4
38+
FADDD F4, F3, F3
39+
FSQRTD F3, F3
40+
FMULD F3, F2, F3
41+
FMOVD F3, ret+16(FP)
42+
RET
43+
44+
isNaN:
45+
MOVD $NaN, R0
46+
FMOVD R0, F29 // F29 is NaN
47+
FMOVD F29, ret+16(FP) // return NaN
48+
RET
49+
isInf:
50+
FMOVD F30, ret+16(FP) // return +Inf
51+
RET
52+
isZero:
53+
// R0 has been set to zero
54+
MOVD R0, ret+16(FP) // return 0
55+
RET

‎src/math/hypot_asm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build 386 || amd64
6-
// +build 386 amd64
5+
//go:build 386 || amd64 || arm64
6+
// +build 386 amd64 arm64
77

88
package math
99

‎src/math/hypot_noasm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !386 && !amd64
6-
// +build !386,!amd64
5+
//go:build !386 && !amd64 && !arm64
6+
// +build !386,!amd64,!arm64
77

88
package math
99

0 commit comments

Comments
(0)

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