1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:04:39 -07:00

math: implement arch{Floor, Ceil, Trunc} in hardware on loong64

benchmark:

goos: linux
goarch: loong64
pkg: math
cpu: Loongson-3A6000 @ 2500.00MHz
        │  bench.old   │              bench.new              │
        │    sec/op    │   sec/op     vs base                │
Ceil      10.810n ± 0%   2.578n ± 0%  -76.15% (p=0.000 n=20)
Floor     10.810n ± 0%   2.531n ± 0%  -76.59% (p=0.000 n=20)
Trunc      9.606n ± 0%   2.530n ± 0%  -73.67% (p=0.000 n=20)
geomean    10.39n        2.546n       -75.50%

goos: linux
goarch: loong64
pkg: math
cpu: Loongson-3A5000 @ 2500.00MHz
        │  bench.old   │              bench.new              │
        │    sec/op    │   sec/op     vs base                │
Ceil      13.220n ± 0%   7.703n ± 8%  -41.73% (p=0.000 n=20)
Floor     12.410n ± 0%   7.248n ± 2%  -41.59% (p=0.000 n=20)
Trunc     11.210n ± 0%   7.757n ± 4%  -30.80% (p=0.000 n=20)
geomean    12.25n        7.566n       -38.25%

Change-Id: I3af51e9852e9cf5f965fed895d68945a2e8675f4
Reviewed-on: https://go-review.googlesource.com/c/go/+/612615
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: abner chenc <chenguoqi@loongson.cn>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Xiaolin Zhao 2024-09-12 11:37:45 +08:00 committed by abner chenc
parent 7e0159c50b
commit b521ebb55a
3 changed files with 43 additions and 2 deletions

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build 386 || amd64 || arm64 || ppc64 || ppc64le || riscv64 || s390x || wasm
//go:build 386 || amd64 || arm64 || loong64 || ppc64 || ppc64le || riscv64 || s390x || wasm
package math

41
src/math/floor_loong64.s Normal file
View File

@ -0,0 +1,41 @@
// Copyright 2024 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.
//
// derived from math/floor_riscv64.s
#include "textflag.h"
#define ROUNDFN(NAME, FUNC) \
TEXT NAME(SB),NOSPLIT,$0; \
MOVD x+0(FP), F0; \
MOVV F0, R11; \
/* 1023: bias of exponent, [-2^53, 2^53]: exactly integer represent range */; \
MOVV $1023+53, R12; \
/* Drop all fraction bits */; \
SRLV $52, R11, R11; \
/* Remove sign bit */; \
AND $0x7FF, R11, R11; \
BLTU R12, R11, isExtremum; \
normal:; \
FUNC F0, F2; \
MOVV F2, R10; \
BEQ R10, R0, is0; \
FFINTDV F2, F0; \
/* Return either input is +-Inf, NaN(0x7FF) or out of precision limitation */; \
isExtremum:; \
MOVD F0, ret+8(FP); \
RET; \
is0:; \
FCOPYSGD F0, F2, F2; \
MOVD F2, ret+8(FP); \
RET
// func archFloor(x float64) float64
ROUNDFN(·archFloor, FTINTRMVD)
// func archCeil(x float64) float64
ROUNDFN(·archCeil, FTINTRPVD)
// func archTrunc(x float64) float64
ROUNDFN(·archTrunc, FTINTRZVD)

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !386 && !amd64 && !arm64 && !ppc64 && !ppc64le && !riscv64 && !s390x && !wasm
//go:build !386 && !amd64 && !arm64 && !loong64 && !ppc64 && !ppc64le && !riscv64 && !s390x && !wasm
package math