go/src/math
Brian Kessler 7818b82fc8 math/big: clean up z.div(z, x, y) calls
Updates #22830

Due to not checking if the output slices alias in divLarge,
calls of the form z.div(z, x, y) caused the slice z
to attempt to be used to store both the quotient and the
remainder of the division.  CL 78995 applies an alias
check to correct that error.  This CL cleans up the
additional div calls that attempt to supply the same slice
to hold both the quotient and remainder.

Note that the call in expNN was responsible for the reported
error in r.Exp(x, 1, m) when r was initialized to a non-zero value.

The second instance in expNNMontgomery did not result in an error
due to the size of the arguments.

	// RR = 2**(2*_W*len(m)) mod m
	RR := nat(nil).setWord(1)
	zz := nat(nil).shl(RR, uint(2*numWords*_W))
	_, RR = RR.div(RR, zz, m)

Specifically,

cap(RR) == 5 after setWord(1) due to const e = 4 in z.make(1)
len(zz) == 2*len(m) + 1 after shifting left, numWords = len(m)

Reusing the backing array for z and z2 in div was only triggered if
cap(RR) >= len(zz) + 1 and len(m) > 1 so that divLarge was called.

But, 5 < 2*len(m) + 2 if len(m) > 1, so new arrays were allocated
and the error was never triggered in this case.

Change-Id: Iedac80dbbde13216c94659e84d28f6f4be3aaf24
Reviewed-on: https://go-review.googlesource.com/81055
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-04-05 22:02:33 +00:00
..
big math/big: clean up z.div(z, x, y) calls 2018-04-05 22:02:33 +00:00
bits math/bits: add examples for right rotation 2017-11-03 20:12:07 +00:00
cmplx math/cmplx: use signed zero to correct branch cuts 2017-11-27 07:44:00 +00:00
rand go/printer, gofmt: tuned table alignment for better results 2018-04-04 13:39:34 -07:00
abs.go cmd/compile,math: improve code generation for math.Abs 2017-08-25 19:15:01 +00:00
acos_s390x.s math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
acosh.go math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
acosh_s390x.s cmd/asm, math: add s390x floating point test instructions 2018-04-03 16:08:04 +00:00
all_test.go math: fix Ldexp when result is below ldexp(2, -1075) 2018-03-29 23:14:13 +00:00
arith_s390x.go math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
arith_s390x_test.go math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
asin.go
asin_386.s
asin_amd64.s
asin_amd64p32.s
asin_arm.s
asin_s390x.s math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
asinh.go math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
asinh_s390x.s cmd/asm, math: add s390x floating point test instructions 2018-04-03 16:08:04 +00:00
asinh_stub.s math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
atan.go
atan2.go
atan2_386.s
atan2_amd64.s
atan2_amd64p32.s
atan2_arm.s
atan2_s390x.s cmd/asm, math: add s390x floating point test instructions 2018-04-03 16:08:04 +00:00
atan_386.s
atan_amd64.s
atan_amd64p32.s
atan_arm.s
atan_s390x.s math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
atanh.go math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
atanh_s390x.s math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
bits.go math: add RoundToEven function 2017-10-24 22:33:09 +00:00
cbrt.go math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
cbrt_s390x.s cmd/asm, math: add s390x floating point test instructions 2018-04-03 16:08:04 +00:00
cbrt_stub.s math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
const.go math: change oeis.org urls to https 2017-08-08 08:56:40 +00:00
copysign.go
cosh_s390x.s cmd/asm, math: add s390x floating point test instructions 2018-04-03 16:08:04 +00:00
dim.go math: remove asm version of Dim 2017-11-30 21:00:33 +00:00
dim_386.s math: remove asm version of Dim 2017-11-30 21:00:33 +00:00
dim_amd64.s math: remove asm version of Dim 2017-11-30 21:00:33 +00:00
dim_amd64p32.s
dim_arm.s math: remove asm version of Dim 2017-11-30 21:00:33 +00:00
dim_arm64.s math: remove asm version of Dim 2017-11-30 21:00:33 +00:00
dim_s390x.s math: optimize dim and remove s390x assembly implementation 2017-10-30 19:05:51 +00:00
erf.go math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
erf_s390x.s math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
erf_stub.s math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
erfc_s390x.s cmd/asm, math: add s390x floating point test instructions 2018-04-03 16:08:04 +00:00
erfinv.go math: implement the erfcinv function 2017-08-22 13:13:20 +00:00
example_test.go math: add examples for trig functions 2017-08-25 20:26:19 +00:00
exp.go math: fix inaccurate result of Exp(1) 2017-08-17 09:01:27 +00:00
exp2_386.s
exp2_amd64.s
exp2_amd64p32.s
exp2_arm.s
exp_386.s math: use portable Exp instead of 387 instructions on 386 2016-10-05 03:53:11 +00:00
exp_amd64.s math: handle denormals in AMD64 Exp 2018-03-29 07:03:09 +00:00
exp_amd64p32.s
exp_arm.s
exp_arm64.s math: optimize Exp and Exp2 on arm64 2018-03-27 19:55:02 +00:00
exp_asm.go math: implement fast path for Exp 2017-09-20 21:43:00 +00:00
exp_s390x.s cmd/asm, math: add s390x floating point test instructions 2018-04-03 16:08:04 +00:00
expm1.go all: unindent some big chunks of code 2017-08-18 06:59:48 +00:00
expm1_386.s
expm1_amd64.s
expm1_amd64p32.s
expm1_arm.s
expm1_s390x.s cmd/asm, math: add s390x floating point test instructions 2018-04-03 16:08:04 +00:00
export_s390x_test.go math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
export_test.go
floor.go math: add RoundToEven function 2017-10-24 22:33:09 +00:00
floor_386.s
floor_amd64.s cmd/compile: intrinsify math.{Trunc/Ceil/Floor} on amd64 2017-10-31 19:30:54 +00:00
floor_amd64p32.s
floor_arm.s
floor_arm64.s math: add some assembly implementations on ARM64 2016-09-27 23:52:12 +00:00
floor_ppc64x.s math, cmd/internal/obj/ppc64: improve floor, ceil, trunc with asm 2016-09-23 13:03:08 +00:00
floor_s390x.s math: optimize Ceil, Floor and Trunc on s390x 2016-08-26 17:27:13 +00:00
frexp.go
frexp_386.s
frexp_amd64.s
frexp_amd64p32.s
frexp_arm.s
gamma.go math: speed up Gamma(+Inf) 2016-10-18 22:12:03 +00:00
hypot.go math: use Abs rather than if x < 0 { x = -x } 2018-02-13 20:12:23 +00:00
hypot_386.s
hypot_amd64.s
hypot_amd64p32.s
hypot_arm.s
j0.go math: use Abs rather than if x < 0 { x = -x } 2018-02-13 20:12:23 +00:00
j1.go math: speed up bessel functions on AMD64 2016-08-31 14:45:29 +00:00
jn.go math: fix typos in Bessel function docs 2017-02-16 22:41:34 +00:00
ldexp.go math: fix Ldexp when result is below ldexp(2, -1075) 2018-03-29 23:14:13 +00:00
ldexp_386.s
ldexp_amd64.s
ldexp_amd64p32.s
ldexp_arm.s
lgamma.go go/printer, gofmt: tuned table alignment for better results 2018-04-04 13:39:34 -07:00
log.go
log1p.go math,math/cmplx: fix linter issues 2016-10-24 23:25:46 +00:00
log1p_386.s
log1p_amd64.s
log1p_amd64p32.s
log1p_arm.s
log1p_s390x.s math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
log10.go
log10_386.s
log10_amd64.s
log10_amd64p32.s
log10_arm.s
log10_s390x.s cmd/asm, math: add s390x floating point test instructions 2018-04-03 16:08:04 +00:00
log_386.s
log_amd64.s math: speed up Log on amd64 2017-03-29 20:36:29 +00:00
log_amd64p32.s
log_arm.s
log_s390x.s cmd/asm, math: add s390x floating point test instructions 2018-04-03 16:08:04 +00:00
logb.go
mod.go
mod_386.s
mod_amd64.s
mod_amd64p32.s
mod_arm.s
modf.go
modf_386.s all: fix assembly vet issues 2016-08-25 18:52:31 +00:00
modf_amd64.s
modf_amd64p32.s
modf_arm.s
modf_arm64.s all: minor vet fixes 2016-10-24 17:27:37 +00:00
modf_ppc64x.s math: implement asm modf for ppc64x 2017-11-02 13:24:32 +00:00
nextafter.go
pow.go math: correct result for Pow(x, ±.5) 2018-01-02 18:10:43 +00:00
pow10.go math: speed up and improve accuracy of Pow10 2017-02-22 19:17:04 +00:00
pow_s390x.s cmd/asm, math: add s390x floating point test instructions 2018-04-03 16:08:04 +00:00
pow_stub.s math: use SIMD to accelerate additional scalar math functions on s390x 2017-05-08 19:52:30 +00:00
remainder.go
remainder_386.s
remainder_amd64.s
remainder_amd64p32.s
remainder_arm.s
signbit.go
sin.go math: use Abs rather than if x < 0 { x = -x } 2018-02-13 20:12:23 +00:00
sin_386.s
sin_amd64.s
sin_amd64p32.s
sin_arm.s
sin_s390x.s cmd/asm, math: add s390x floating point test instructions 2018-04-03 16:08:04 +00:00
sincos.go math: remove asm version of sincos everywhere, except 386 2017-04-24 15:09:18 +00:00
sincos_386.go math: remove asm version of sincos everywhere, except 386 2017-04-24 15:09:18 +00:00
sincos_386.s
sinh.go math: optimize sinh and cosh 2018-02-27 04:34:37 +00:00
sinh_s390x.s cmd/asm, math: add s390x floating point test instructions 2018-04-03 16:08:04 +00:00
sinh_stub.s math: use SIMD to accelerate some scalar math functions on s390x 2016-11-11 20:20:23 +00:00
sqrt.go
sqrt_386.s
sqrt_amd64.s math: make sqrt smaller on AMD64 2016-09-29 15:56:52 +00:00
sqrt_amd64p32.s
sqrt_arm.s
sqrt_arm64.s
sqrt_mipsx.s runtime/cgo, math: don't use FP instructions for soft-float mips{,le} 2017-11-30 17:12:32 +00:00
sqrt_ppc64x.s all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
sqrt_s390x.s
stubs_arm64.s math: optimize Exp and Exp2 on arm64 2018-03-27 19:55:02 +00:00
stubs_mips64x.s math: remove asm version of Dim 2017-11-30 21:00:33 +00:00
stubs_mipsx.s math: remove asm version of Dim 2017-11-30 21:00:33 +00:00
stubs_ppc64x.s math: remove asm version of Dim 2017-11-30 21:00:33 +00:00
stubs_s390x.s math: remove asm version of Dim 2017-11-30 21:00:33 +00:00
tan.go math,math/cmplx: fix linter issues 2016-10-24 23:25:46 +00:00
tan_386.s
tan_amd64.s
tan_amd64p32.s
tan_arm.s
tan_s390x.s cmd/asm, math: add s390x floating point test instructions 2018-04-03 16:08:04 +00:00
tanh.go math: use SIMD to accelerate some scalar math functions on s390x 2016-11-11 20:20:23 +00:00
tanh_s390x.s cmd/asm, math: add s390x floating point test instructions 2018-04-03 16:08:04 +00:00
unsafe.go