From 5b84ddfb9d3e72d73b8de858c97650be140935c0 Mon Sep 17 00:00:00 2001 From: kortschak Date: Mon, 9 Feb 2015 21:34:03 +1030 Subject: [PATCH] Make generated complex drop-ins Again this is to allow simpler code generation of other BLAS routines. --- asm/caxpy.go | 22 +++++++++++++++++ asm/cdotc.go | 23 ++++++++++++++++++ asm/cdotu.go | 23 ++++++++++++++++++ asm/complex | 58 ++++++++++++++++++++++++++++++++++++++++++++ asm/conj.go | 7 ++++++ asm/generate.go | 1 + asm/single_precision | 4 +++ asm/zaxpy.go | 22 +++++++++++++++++ asm/zdotc.go | 25 +++++++++++++++++++ asm/zdotu.go | 23 ++++++++++++++++++ 10 files changed, 208 insertions(+) create mode 100644 asm/caxpy.go create mode 100644 asm/cdotc.go create mode 100644 asm/cdotu.go create mode 100755 asm/complex create mode 100644 asm/conj.go create mode 100644 asm/zaxpy.go create mode 100644 asm/zdotc.go create mode 100644 asm/zdotu.go diff --git a/asm/caxpy.go b/asm/caxpy.go new file mode 100644 index 00000000..80d802ad --- /dev/null +++ b/asm/caxpy.go @@ -0,0 +1,22 @@ +// Generated code do not edit. Run `go generate`. + +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package asm + +// The extra z parameter is needed because of floats.AddScaledTo +func CaxpyUnitary(alpha complex64, x, y, z []complex64) { + for i, v := range x { + z[i] = alpha*v + y[i] + } +} + +func CaxpyInc(alpha complex64, x, y []complex64, n, incX, incY, ix, iy uintptr) { + for i := 0; i < int(n); i++ { + y[iy] += alpha * x[ix] + ix += incX + iy += incY + } +} diff --git a/asm/cdotc.go b/asm/cdotc.go new file mode 100644 index 00000000..ed999e5f --- /dev/null +++ b/asm/cdotc.go @@ -0,0 +1,23 @@ +// Generated code do not edit. Run `go generate`. + +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package asm + +func CdotcUnitary(x, y []complex64) (sum complex64) { + for i, v := range x { + sum += y[i] * conj(v) + } + return +} + +func CdotcInc(x, y []complex64, n, incX, incY, ix, iy uintptr) (sum complex64) { + for i := 0; i < int(n); i++ { + sum += y[iy] * conj(x[ix]) + ix += incX + iy += incY + } + return +} diff --git a/asm/cdotu.go b/asm/cdotu.go new file mode 100644 index 00000000..3392ee25 --- /dev/null +++ b/asm/cdotu.go @@ -0,0 +1,23 @@ +// Generated code do not edit. Run `go generate`. + +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package asm + +func CdotuUnitary(x, y []complex64) (sum complex64) { + for i, v := range x { + sum += y[i] * v + } + return +} + +func CdotuInc(x, y []complex64, n, incX, incY, ix, iy uintptr) (sum complex64) { + for i := 0; i < int(n); i++ { + sum += y[iy] * x[ix] + ix += incX + iy += incY + } + return +} diff --git a/asm/complex b/asm/complex new file mode 100755 index 00000000..b26e4e60 --- /dev/null +++ b/asm/complex @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +# Copyright ©2015 The gonum Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +echo Generating zdotu.go +echo -e '// Generated code do not edit. Run `go generate`.\n' > zdotu.go +cat ddot.go \ +| grep -v '//+build' \ +| gofmt -r 'float64 -> complex128' \ +| sed 's/Ddot/Zdotu/' \ +>> zdotu.go + +echo Generating zdotc.go +echo -e '// Generated code do not edit. Run `go generate`.\n' > zdotc.go +cat ddot.go \ +| grep -v '//+build' \ +| gofmt -r 'float64 -> complex128' \ +| gofmt -r 'y[i] * v -> y[i] * cmplx.Conj(v)' \ +| sed 's/Ddot/Zdotc/' \ +| goimports \ +>> zdotc.go + +echo Generating zaxpy.go +echo -e '// Generated code do not edit. Run `go generate`.\n' > zaxpy.go +cat daxpy.go \ +| grep -v '//+build' \ +| gofmt -r 'float64 -> complex128' \ +| sed 's/Daxpy/Zaxpy/' \ +>> zaxpy.go + +echo Generating cdotu.go +echo -e '// Generated code do not edit. Run `go generate`.\n' > cdotu.go +cat ddot.go \ +| grep -v '//+build' \ +| gofmt -r 'float64 -> complex64' \ +| sed 's/Ddot/Cdotu/' \ +>> cdotu.go + +echo Generating cdotc.go +echo -e '// Generated code do not edit. Run `go generate`.\n' > cdotc.go +cat ddot.go \ +| grep -v '//+build' \ +| gofmt -r 'float64 -> complex64' \ +| gofmt -r 'y[i] * v -> y[i] * conj(v)' \ +| sed 's/Ddot/Cdotc/' \ +| goimports \ +>> cdotc.go + +echo Generating caxpy.go +echo -e '// Generated code do not edit. Run `go generate`.\n' > caxpy.go +cat daxpy.go \ +| grep -v '//+build' \ +| gofmt -r 'float64 -> complex64' \ +| sed 's/Daxpy/Caxpy/' \ +>> caxpy.go + diff --git a/asm/conj.go b/asm/conj.go new file mode 100644 index 00000000..1cadb2a5 --- /dev/null +++ b/asm/conj.go @@ -0,0 +1,7 @@ +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package asm + +func conj(c complex64) complex64 { return complex(real(c), -imag(c)) } diff --git a/asm/generate.go b/asm/generate.go index bbd3f682..e2521405 100644 --- a/asm/generate.go +++ b/asm/generate.go @@ -3,5 +3,6 @@ // license that can be found in the LICENSE file. //go:generate ./single_precision +//go:generate ./complex package asm diff --git a/asm/single_precision b/asm/single_precision index a185884d..a937a977 100755 --- a/asm/single_precision +++ b/asm/single_precision @@ -1,5 +1,9 @@ #!/usr/bin/env bash +# Copyright ©2015 The gonum Authors. All rights reserved. +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + echo Generating dsdot.go echo -e '// Generated code do not edit. Run `go generate`.\n' > dsdot.go cat ddot.go \ diff --git a/asm/zaxpy.go b/asm/zaxpy.go new file mode 100644 index 00000000..9478f257 --- /dev/null +++ b/asm/zaxpy.go @@ -0,0 +1,22 @@ +// Generated code do not edit. Run `go generate`. + +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package asm + +// The extra z parameter is needed because of floats.AddScaledTo +func ZaxpyUnitary(alpha complex128, x, y, z []complex128) { + for i, v := range x { + z[i] = alpha*v + y[i] + } +} + +func ZaxpyInc(alpha complex128, x, y []complex128, n, incX, incY, ix, iy uintptr) { + for i := 0; i < int(n); i++ { + y[iy] += alpha * x[ix] + ix += incX + iy += incY + } +} diff --git a/asm/zdotc.go b/asm/zdotc.go new file mode 100644 index 00000000..7b8febcc --- /dev/null +++ b/asm/zdotc.go @@ -0,0 +1,25 @@ +// Generated code do not edit. Run `go generate`. + +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package asm + +import "math/cmplx" + +func ZdotcUnitary(x, y []complex128) (sum complex128) { + for i, v := range x { + sum += y[i] * cmplx.Conj(v) + } + return +} + +func ZdotcInc(x, y []complex128, n, incX, incY, ix, iy uintptr) (sum complex128) { + for i := 0; i < int(n); i++ { + sum += y[iy] * cmplx.Conj(x[ix]) + ix += incX + iy += incY + } + return +} diff --git a/asm/zdotu.go b/asm/zdotu.go new file mode 100644 index 00000000..82c1fe2c --- /dev/null +++ b/asm/zdotu.go @@ -0,0 +1,23 @@ +// Generated code do not edit. Run `go generate`. + +// Copyright ©2015 The gonum Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package asm + +func ZdotuUnitary(x, y []complex128) (sum complex128) { + for i, v := range x { + sum += y[i] * v + } + return +} + +func ZdotuInc(x, y []complex128, n, incX, incY, ix, iy uintptr) (sum complex128) { + for i := 0; i < int(n); i++ { + sum += y[iy] * x[ix] + ix += incX + iy += incY + } + return +}