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

big: Get rid of function pointers and init function

R=rsc, gri
CC=golang-dev
https://golang.org/cl/929041
This commit is contained in:
Evan Shaw 2010-04-19 19:07:22 -07:00 committed by Robert Griesemer
parent 8df3121353
commit 73374c93a6
4 changed files with 43 additions and 89 deletions

View File

@ -267,58 +267,12 @@ func divWW_g(x1, x0, y Word) (q, r Word) {
}
// ----------------------------------------------------------------------------
// Elementary operations on vectors
// All higher-level functions use these elementary vector operations.
// The function pointers f are initialized with default implementations
// f_g, written in Go for portability. The corresponding assembly routines
// f_s should be installed if they exist.
var (
// addVV sets z and returns c such that z+c = x+y.
addVV func(z, x, y *Word, n int) (c Word) = addVV_g
// subVV sets z and returns c such that z-c = x-y.
subVV func(z, x, y *Word, n int) (c Word) = subVV_g
// addVW sets z and returns c such that z+c = x-y.
addVW func(z, x *Word, y Word, n int) (c Word) = addVW_g
// subVW sets z and returns c such that z-c = x-y.
subVW func(z, x *Word, y Word, n int) (c Word) = subVW_g
// mulAddVWW sets z and returns c such that z+c = x*y + r.
mulAddVWW func(z, x *Word, y, r Word, n int) (c Word) = mulAddVWW_g
// addMulVVW sets z and returns c such that z+c = z + x*y.
addMulVVW func(z, x *Word, y Word, n int) (c Word) = addMulVVW_g
// divWVW sets z and returns r such that z-r = (xn<<(n*_W) + x) / y.
divWVW func(z *Word, xn Word, x *Word, y Word, n int) (r Word) = divWVW_g
)
func init() {
// Uncomment to use generic routines.
//return;
// Install assembly routines.
addVV = addVV_s
subVV = subVV_s
addVW = addVW_s
subVW = subVW_s
mulAddVWW = mulAddVWW_s
addMulVVW = addMulVVW_s
divWVW = divWVW_s
}
func (p *Word) at(i int) *Word {
return (*Word)(unsafe.Pointer(uintptr(unsafe.Pointer(p)) + uintptr(i)*_S))
}
func addVV_s(z, x, y *Word, n int) (c Word)
func addVV(z, x, y *Word, n int) (c Word)
func addVV_g(z, x, y *Word, n int) (c Word) {
for i := 0; i < n; i++ {
c, *z.at(i) = addWW_g(*x.at(i), *y.at(i), c)
@ -327,7 +281,7 @@ func addVV_g(z, x, y *Word, n int) (c Word) {
}
func subVV_s(z, x, y *Word, n int) (c Word)
func subVV(z, x, y *Word, n int) (c Word)
func subVV_g(z, x, y *Word, n int) (c Word) {
for i := 0; i < n; i++ {
c, *z.at(i) = subWW_g(*x.at(i), *y.at(i), c)
@ -336,7 +290,7 @@ func subVV_g(z, x, y *Word, n int) (c Word) {
}
func addVW_s(z, x *Word, y Word, n int) (c Word)
func addVW(z, x *Word, y Word, n int) (c Word)
func addVW_g(z, x *Word, y Word, n int) (c Word) {
c = y
for i := 0; i < n; i++ {
@ -346,7 +300,7 @@ func addVW_g(z, x *Word, y Word, n int) (c Word) {
}
func subVW_s(z, x *Word, y Word, n int) (c Word)
func subVW(z, x *Word, y Word, n int) (c Word)
func subVW_g(z, x *Word, y Word, n int) (c Word) {
c = y
for i := 0; i < n; i++ {
@ -356,7 +310,7 @@ func subVW_g(z, x *Word, y Word, n int) (c Word) {
}
func mulAddVWW_s(z, x *Word, y, r Word, n int) (c Word)
func mulAddVWW(z, x *Word, y, r Word, n int) (c Word)
func mulAddVWW_g(z, x *Word, y, r Word, n int) (c Word) {
c = r
for i := 0; i < n; i++ {
@ -366,7 +320,7 @@ func mulAddVWW_g(z, x *Word, y, r Word, n int) (c Word) {
}
func addMulVVW_s(z, x *Word, y Word, n int) (c Word)
func addMulVVW(z, x *Word, y Word, n int) (c Word)
func addMulVVW_g(z, x *Word, y Word, n int) (c Word) {
for i := 0; i < n; i++ {
z1, z0 := mulAddWWW_g(*x.at(i), y, *z.at(i))
@ -377,7 +331,7 @@ func addMulVVW_g(z, x *Word, y Word, n int) (c Word) {
}
func divWVW_s(z *Word, xn Word, x *Word, y Word, n int) (r Word)
func divWVW(z *Word, xn Word, x *Word, y Word, n int) (r Word)
func divWVW_g(z *Word, xn Word, x *Word, y Word, n int) (r Word) {
r = xn
for i := n - 1; i >= 0; i-- {

View File

@ -5,8 +5,8 @@
// This file provides fast assembly versions for the elementary
// arithmetic operations on vectors implemented in arith.go.
// func addVV_s(z, x, y *Word, n int) (c Word)
TEXT ·addVV_s(SB),7,$0
// func addVV(z, x, y *Word, n int) (c Word)
TEXT ·addVV(SB),7,$0
MOVL z+0(FP), DI
MOVL x+4(FP), SI
MOVL y+8(FP), CX
@ -29,9 +29,9 @@ E1: CMPL BX, BP // i < n
RET
// func subVV_s(z, x, y *Word, n int) (c Word)
// (same as addVV_s except for SBBL instead of ADCL and label names)
TEXT ·subVV_s(SB),7,$0
// func subVV(z, x, y *Word, n int) (c Word)
// (same as addVV except for SBBL instead of ADCL and label names)
TEXT ·subVV(SB),7,$0
MOVL z+0(FP), DI
MOVL x+4(FP), SI
MOVL y+8(FP), CX
@ -54,8 +54,8 @@ E2: CMPL BX, BP // i < n
RET
// func addVW_s(z, x *Word, y Word, n int) (c Word)
TEXT ·addVW_s(SB),7,$0
// func addVW(z, x *Word, y Word, n int) (c Word)
TEXT ·addVW(SB),7,$0
MOVL z+0(FP), DI
MOVL x+4(FP), SI
MOVL y+8(FP), AX // c = y
@ -76,8 +76,8 @@ E3: CMPL BX, BP // i < n
RET
// func subVW_s(z, x *Word, y Word, n int) (c Word)
TEXT ·subVW_s(SB),7,$0
// func subVW(z, x *Word, y Word, n int) (c Word)
TEXT ·subVW(SB),7,$0
MOVL z+0(FP), DI
MOVL x+4(FP), SI
MOVL y+8(FP), AX // c = y
@ -99,8 +99,8 @@ E4: CMPL BX, BP // i < n
RET
// func mulAddVWW_s(z, x *Word, y, r Word, n int) (c Word)
TEXT ·mulAddVWW_s(SB),7,$0
// func mulAddVWW(z, x *Word, y, r Word, n int) (c Word)
TEXT ·mulAddVWW(SB),7,$0
MOVL z+0(FP), DI
MOVL x+4(FP), SI
MOVL y+8(FP), BP
@ -126,8 +126,8 @@ E5: CMPL BX, $0 // i < 0
RET
// func addMulVVW_s(z, x *Word, y Word, n int) (c Word)
TEXT ·addMulVVW_s(SB),7,$0
// func addMulVVW(z, x *Word, y Word, n int) (c Word)
TEXT ·addMulVVW(SB),7,$0
MOVL z+0(FP), DI
MOVL x+4(FP), SI
MOVL y+8(FP), BP
@ -155,8 +155,8 @@ E6: CMPL BX, $0 // i < 0
RET
// divWVW_s(z* Word, xn Word, x *Word, y Word, n int) (r Word)
TEXT ·divWVW_s(SB),7,$0
// divWVW(z* Word, xn Word, x *Word, y Word, n int) (r Word)
TEXT ·divWVW(SB),7,$0
MOVL z+0(FP), DI
MOVL xn+4(FP), DX // r = xn
MOVL x+8(FP), SI

View File

@ -7,8 +7,8 @@
// TODO(gri) - experiment with unrolled loops for faster execution
// func addVV_s(z, x, y *Word, n int) (c Word)
TEXT ·addVV_s(SB),7,$0
// func addVV(z, x, y *Word, n int) (c Word)
TEXT ·addVV(SB),7,$0
MOVQ z+0(FP), R10
MOVQ x+8(FP), R8
MOVQ y+16(FP), R9
@ -31,9 +31,9 @@ E1: CMPQ BX, R11 // i < n
RET
// func subVV_s(z, x, y *Word, n int) (c Word)
// func subVV(z, x, y *Word, n int) (c Word)
// (same as addVV_s except for SBBQ instead of ADCQ and label names)
TEXT ·subVV_s(SB),7,$0
TEXT ·subVV(SB),7,$0
MOVQ z+0(FP), R10
MOVQ x+8(FP), R8
MOVQ y+16(FP), R9
@ -56,8 +56,8 @@ E2: CMPQ BX, R11 // i < n
RET
// func addVW_s(z, x *Word, y Word, n int) (c Word)
TEXT ·addVW_s(SB),7,$0
// func addVW(z, x *Word, y Word, n int) (c Word)
TEXT ·addVW(SB),7,$0
MOVQ z+0(FP), R10
MOVQ x+8(FP), R8
MOVQ y+16(FP), AX // c = y
@ -78,8 +78,8 @@ E3: CMPQ BX, R11 // i < n
RET
// func subVW_s(z, x *Word, y Word, n int) (c Word)
TEXT ·subVW_s(SB),7,$0
// func subVW(z, x *Word, y Word, n int) (c Word)
TEXT ·subVW(SB),7,$0
MOVQ z+0(FP), R10
MOVQ x+8(FP), R8
MOVQ y+16(FP), AX // c = y
@ -101,8 +101,8 @@ E4: CMPQ BX, R11 // i < n
RET
// func mulAddVWW_s(z, x *Word, y, r Word, n int) (c Word)
TEXT ·mulAddVWW_s(SB),7,$0
// func mulAddVWW(z, x *Word, y, r Word, n int) (c Word)
TEXT ·mulAddVWW(SB),7,$0
MOVQ z+0(FP), R10
MOVQ x+8(FP), R8
MOVQ y+16(FP), R9
@ -126,8 +126,8 @@ E5: CMPQ BX, R11 // i < n
RET
// func addMulVVW_s(z, x *Word, y Word, n int) (c Word)
TEXT ·addMulVVW_s(SB),7,$0
// func addMulVVW(z, x *Word, y Word, n int) (c Word)
TEXT ·addMulVVW(SB),7,$0
MOVQ z+0(FP), R10
MOVQ x+8(FP), R8
MOVQ y+16(FP), R9
@ -153,8 +153,8 @@ E6: CMPQ BX, R11 // i < n
RET
// divWVW_s(z* Word, xn Word, x *Word, y Word, n int) (r Word)
TEXT ·divWVW_s(SB),7,$0
// divWVW(z* Word, xn Word, x *Word, y Word, n int) (r Word)
TEXT ·divWVW(SB),7,$0
MOVQ z+0(FP), R10
MOVQ xn+8(FP), DX // r = xn
MOVQ x+16(FP), R8

View File

@ -6,24 +6,24 @@
// arithmetic operations on vectors implemented in arith.go.
// TODO(gri) Implement these routines.
TEXT ·addVV_s(SB),7,$0
TEXT ·addVV(SB),7,$0
B ·addVV_g(SB)
TEXT ·subVV_s(SB),7,$0
TEXT ·subVV(SB),7,$0
B ·subVV_g(SB)
TEXT ·addVW_s(SB),7,$0
TEXT ·addVW(SB),7,$0
B ·addVW_g(SB)
TEXT ·subVW_s(SB),7,$0
TEXT ·subVW(SB),7,$0
B ·subVW_g(SB)
TEXT ·mulAddVWW_s(SB),7,$0
TEXT ·mulAddVWW(SB),7,$0
B ·mulAddVWW_g(SB)
TEXT ·addMulVVW_s(SB),7,$0
TEXT ·addMulVVW(SB),7,$0
B ·addMulVVW_g(SB)
TEXT ·divWVW_s(SB),7,$0
TEXT ·divWVW(SB),7,$0
B ·divWVW_g(SB)