Skip to content

Commit

Permalink
asm/c128: Changed int parameters to uintptr.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunde21 committed Aug 20, 2017
1 parent 2df3f3a commit 377873c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 50 deletions.
2 changes: 1 addition & 1 deletion internal/asm/c128/dscalinc_amd64.s
Expand Up @@ -17,7 +17,7 @@

#define MOVDDUP_ALPHA LONG $0x44120FF2; WORD $0x0824 // MOVDDUP 8(SP), X0

// func DscalInc(alpha float64, x []complex128, n, inc int)
// func DscalInc(alpha float64, x []complex128, n, inc uintptr)
TEXT ·DscalInc(SB), NOSPLIT, $0
MOVQ x_base+8(FP), SRC // SRC = &x
MOVQ n+32(FP), LEN // LEN = n
Expand Down
2 changes: 1 addition & 1 deletion internal/asm/c128/scalinc_amd64.s
Expand Up @@ -27,7 +27,7 @@
#define ADDSUBPD_X6_X7 LONG $0xFED00F66 // ADDSUBPD X6, X7
#define ADDSUBPD_X8_X9 LONG $0xD00F4566; BYTE $0xC8 // ADDSUBPD X8, X9

// func ScalInc(alpha complex128, x []complex128, n, inc int)
// func ScalInc(alpha complex128, x []complex128, n, inc uintptr)
TEXT ·ScalInc(SB), NOSPLIT, $0
MOVQ x_base+16(FP), SRC // SRC = &x
MOVQ n+40(FP), LEN // LEN = len(x)
Expand Down
10 changes: 6 additions & 4 deletions internal/asm/c128/stubs_amd64.go
Expand Up @@ -42,18 +42,20 @@ func AxpyIncTo(dst []complex128, incDst, idst uintptr, alpha complex128, x, y []
func DscalUnitary(alpha float64, x []complex128)

// DscalInc is
// for i := 0; i < n; i++ {
// x[i*inc] = complex(real(x[i*inc])*alpha, imag(x[i*inc]))
// var ix uintptr
// for i := 0; i < int(n); i++ {
// x[ix] = complex(real(x[ix])*alpha, imag(x[ix])*alpha)
// ix += inc
// }
func DscalInc(alpha float64, x []complex128, n, inc int)
func DscalInc(alpha float64, x []complex128, n, inc uintptr)

// ScalInc is
// var ix uintptr
// for i := 0; i < int(n); i++ {
// x[ix] *= alpha
// ix += incX
// }
func ScalInc(alpha complex128, x []complex128, n, inc int)
func ScalInc(alpha complex128, x []complex128, n, inc uintptr)

// ScalUnitary is
// for i := range x {
Expand Down
18 changes: 11 additions & 7 deletions internal/asm/c128/stubs_noasm.go
Expand Up @@ -67,12 +67,16 @@ func DscalUnitary(alpha float64, x []complex128) {
}

// DscalInc is
// for i := 0; i < n; i++ {
// x[i*inc] = complex(real(x[i*inc])*alpha, imag(x[i*inc]))
// var ix uintptr
// for i := 0; i < int(n); i++ {
// x[ix] = complex(real(x[ix])*alpha, imag(x[ix])*alpha)
// ix += inc
// }
func DscalInc(alpha float64, x []complex128, n, inc int) {
for i := 0; i < n; i++ {
x[i*inc] = complex(real(x[i*inc])*alpha, imag(x[i*inc])*alpha)
func DscalInc(alpha float64, x []complex128, n, inc uintptr) {
var ix uintptr
for i := 0; i < int(n); i++ {
x[ix] = complex(real(x[ix])*alpha, imag(x[ix])*alpha)
ix += inc
}
}

Expand All @@ -82,8 +86,8 @@ func DscalInc(alpha float64, x []complex128, n, inc int) {
// x[ix] *= alpha
// ix += incX
// }
func ScalInc(alpha complex128, x []complex128, n, inc int) {
var ix int
func ScalInc(alpha complex128, x []complex128, n, inc uintptr) {
var ix uintptr
for i := 0; i < int(n); i++ {
x[ix] *= alpha
ix += inc
Expand Down
74 changes: 37 additions & 37 deletions internal/asm/c128/stubs_test.go
Expand Up @@ -86,87 +86,87 @@ var tests = []struct {
}

func TestAxpyUnitary(t *testing.T) {
var x_gd, y_gd complex128 = 1, 1
const xGdVal, yGdVal = 1, 1
for cas, test := range tests {
xg_ln, yg_ln := 4+cas%2, 4+cas%3
test.x, test.y = guardVector(test.x, x_gd, xg_ln), guardVector(test.y, y_gd, yg_ln)
x, y := test.x[xg_ln:len(test.x)-xg_ln], test.y[yg_ln:len(test.y)-yg_ln]
xgLn, ygLn := 4+cas%2, 4+cas%3
test.x, test.y = guardVector(test.x, xGdVal, xgLn), guardVector(test.y, yGdVal, ygLn)
x, y := test.x[xgLn:len(test.x)-xgLn], test.y[ygLn:len(test.y)-ygLn]
AxpyUnitary(test.a, x, y)
for i := range test.ex {
if y[i] != test.ex[i] {
t.Errorf("Test %d Unexpected result at %d Got: %v Expected: %v", cas, i, y[i], test.ex[i])
}
}
if !isValidGuard(test.x, x_gd, xg_ln) {
t.Errorf("Test %d Guard violated in x vector %v %v", cas, test.x[:xg_ln], test.x[len(test.x)-xg_ln:])
if !isValidGuard(test.x, xGdVal, xgLn) {
t.Errorf("Test %d Guard violated in x vector %v %v", cas, test.x[:xgLn], test.x[len(test.x)-xgLn:])
}
if !isValidGuard(test.y, y_gd, yg_ln) {
t.Errorf("Test %d Guard violated in y vector %v %v", cas, test.y[:yg_ln], test.y[len(test.y)-yg_ln:])
if !isValidGuard(test.y, yGdVal, ygLn) {
t.Errorf("Test %d Guard violated in y vector %v %v", cas, test.y[:ygLn], test.y[len(test.y)-ygLn:])
}
}
}

func TestAxpyUnitaryTo(t *testing.T) {
var x_gd, y_gd, dst_gd complex128 = 1, 1, 0
const xGdVal, yGdVal, dstGdVal = 1, 1, 0
for cas, test := range tests {
xg_ln, yg_ln := 4+cas%2, 4+cas%3
test.x, test.y = guardVector(test.x, x_gd, xg_ln), guardVector(test.y, y_gd, yg_ln)
test.dst = guardVector(test.dst, dst_gd, xg_ln)
x, y := test.x[xg_ln:len(test.x)-xg_ln], test.y[yg_ln:len(test.y)-yg_ln]
dst := test.dst[xg_ln : len(test.dst)-xg_ln]
xgLn, ygLn := 4+cas%2, 4+cas%3
test.x, test.y = guardVector(test.x, xGdVal, xgLn), guardVector(test.y, yGdVal, ygLn)
test.dst = guardVector(test.dst, dstGdVal, xgLn)
x, y := test.x[xgLn:len(test.x)-xgLn], test.y[ygLn:len(test.y)-ygLn]
dst := test.dst[xgLn : len(test.dst)-xgLn]
AxpyUnitaryTo(dst, test.a, x, y)
for i := range test.ex {
if dst[i] != test.ex[i] {
t.Errorf("Test %d Unexpected result at %d Got: %v Expected: %v", cas, i, dst[i], test.ex[i])
}
}
if !isValidGuard(test.x, x_gd, xg_ln) {
t.Errorf("Test %d Guard violated in x vector %v %v", cas, test.x[:xg_ln], test.x[len(test.x)-xg_ln:])
if !isValidGuard(test.x, xGdVal, xgLn) {
t.Errorf("Test %d Guard violated in x vector %v %v", cas, test.x[:xgLn], test.x[len(test.x)-xgLn:])
}
if !isValidGuard(test.y, y_gd, yg_ln) {
t.Errorf("Test %d Guard violated in y vector %v %v", cas, test.y[:yg_ln], test.y[len(test.y)-yg_ln:])
if !isValidGuard(test.y, yGdVal, ygLn) {
t.Errorf("Test %d Guard violated in y vector %v %v", cas, test.y[:ygLn], test.y[len(test.y)-ygLn:])
}
if !isValidGuard(test.dst, dst_gd, xg_ln) {
t.Errorf("Test %d Guard violated in dst vector %v %v", cas, test.dst[:xg_ln], test.dst[len(test.dst)-xg_ln:])
if !isValidGuard(test.dst, dstGdVal, xgLn) {
t.Errorf("Test %d Guard violated in dst vector %v %v", cas, test.dst[:xgLn], test.dst[len(test.dst)-xgLn:])
}

}
}

func TestAxpyInc(t *testing.T) {
var x_gd, y_gd complex128 = 1, 1
const xGdVal, yGdVal = 1, 1
for cas, test := range tests {
xg_ln, yg_ln := 4+cas%2, 4+cas%3
test.x, test.y = guardIncVector(test.x, x_gd, test.incX, xg_ln), guardIncVector(test.y, y_gd, test.incY, yg_ln)
x, y := test.x[xg_ln:len(test.x)-xg_ln], test.y[yg_ln:len(test.y)-yg_ln]
xgLn, ygLn := 4+cas%2, 4+cas%3
test.x, test.y = guardIncVector(test.x, xGdVal, test.incX, xgLn), guardIncVector(test.y, yGdVal, test.incY, ygLn)
x, y := test.x[xgLn:len(test.x)-xgLn], test.y[ygLn:len(test.y)-ygLn]
AxpyInc(test.a, x, y, uintptr(len(test.ex)), uintptr(test.incX), uintptr(test.incY), test.ix, test.iy)
for i := range test.ex {
if y[int(test.iy)+i*int(test.incY)] != test.ex[i] {
t.Errorf("Test %d Unexpected result at %d Got: %v Expected: %v", cas, i, y[i*int(test.incY)], test.ex[i])
}
}
checkValidIncGuard(t, test.x, x_gd, test.incX, xg_ln)
checkValidIncGuard(t, test.y, y_gd, test.incY, yg_ln)
checkValidIncGuard(t, test.x, xGdVal, test.incX, xgLn)
checkValidIncGuard(t, test.y, yGdVal, test.incY, ygLn)
}
}

func TestAxpyIncTo(t *testing.T) {
var x_gd, y_gd, dst_gd complex128 = 1, 1, 0
const xGdVal, yGdVal, dstGdVal = 1, 1, 0
for cas, test := range tests {
xg_ln, yg_ln := 4+cas%2, 4+cas%3
test.x, test.y = guardIncVector(test.x, x_gd, test.incX, xg_ln), guardIncVector(test.y, y_gd, test.incY, yg_ln)
test.dst = guardIncVector(test.dst, dst_gd, test.incDst, xg_ln)
x, y := test.x[xg_ln:len(test.x)-xg_ln], test.y[yg_ln:len(test.y)-yg_ln]
dst := test.dst[xg_ln : len(test.dst)-xg_ln]
xgLn, ygLn := 4+cas%2, 4+cas%3
test.x, test.y = guardIncVector(test.x, xGdVal, test.incX, xgLn), guardIncVector(test.y, yGdVal, test.incY, ygLn)
test.dst = guardIncVector(test.dst, dstGdVal, test.incDst, xgLn)
x, y := test.x[xgLn:len(test.x)-xgLn], test.y[ygLn:len(test.y)-ygLn]
dst := test.dst[xgLn : len(test.dst)-xgLn]
AxpyIncTo(dst, uintptr(test.incDst), test.idst, test.a, x, y, uintptr(len(test.ex)), uintptr(test.incX), uintptr(test.incY), test.ix, test.iy)
for i := range test.ex {
if dst[int(test.idst)+i*int(test.incDst)] != test.ex[i] {
t.Errorf("Test %d Unexpected result at %d Got: %v Expected: %v", cas, i, dst[i*int(test.incDst)], test.ex[i])
}
}
checkValidIncGuard(t, test.x, x_gd, test.incX, xg_ln)
checkValidIncGuard(t, test.y, y_gd, test.incY, yg_ln)
checkValidIncGuard(t, test.dst, dst_gd, test.incDst, xg_ln)
checkValidIncGuard(t, test.x, xGdVal, test.incX, xgLn)
checkValidIncGuard(t, test.y, yGdVal, test.incY, ygLn)
checkValidIncGuard(t, test.dst, dstGdVal, test.incDst, xgLn)
}
}

Expand Down Expand Up @@ -240,7 +240,7 @@ func TestDscalInc(t *testing.T) {
xg := guardIncVector(test.x, xGdVal, incX, gdLn)
x := xg[gdLn : len(xg)-gdLn]

DscalInc(test.alpha, x, n, incX)
DscalInc(test.alpha, x, uintptr(n), uintptr(incX))

for i := range test.want {
if !same(x[i*incX], test.want[i]) {
Expand Down Expand Up @@ -322,7 +322,7 @@ func TestScalInc(t *testing.T) {
xg := guardIncVector(test.x, xGdVal, inc, gdLn)
x := xg[gdLn : len(xg)-gdLn]

ScalInc(test.alpha, x, n, inc)
ScalInc(test.alpha, x, uintptr(n), uintptr(inc))

for i := range test.want {
if !same(x[i*inc], test.want[i]) {
Expand Down

0 comments on commit 377873c

Please sign in to comment.