From 0382a30dd6cd78efd9fb27bfed50dd1d6d7f722b Mon Sep 17 00:00:00 2001 From: Michael Munday Date: Sun, 20 Mar 2016 21:44:31 -0400 Subject: math: add functions and stubs for s390x Includes assembly implementations of Sqrt and Dim. Change-Id: I57472e8d31e2ee74bcebf9f8e818f765eb9b8abf Reviewed-on: https://go-review.googlesource.com/20936 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/math/dim_s390x.s | 132 +++++++++++++++++++++++++++++++++++++++++++++++++ src/math/sqrt_s390x.s | 12 +++++ src/math/stubs_s390x.s | 77 +++++++++++++++++++++++++++++ 3 files changed, 221 insertions(+) create mode 100644 src/math/dim_s390x.s create mode 100644 src/math/sqrt_s390x.s create mode 100644 src/math/stubs_s390x.s (limited to 'src/math') diff --git a/src/math/dim_s390x.s b/src/math/dim_s390x.s new file mode 100644 index 0000000000..503d2611f8 --- /dev/null +++ b/src/math/dim_s390x.s @@ -0,0 +1,132 @@ +// Copyright 2016 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. + +// Based on dim_amd64.s + +#include "textflag.h" + +#define PosInf 0x7FF0000000000000 +#define NaN 0x7FF8000000000001 +#define NegInf 0xFFF0000000000000 + +// func Dim(x, y float64) float64 +TEXT ·Dim(SB),NOSPLIT,$0 + // (+Inf, +Inf) special case + MOVD x+0(FP), R2 + MOVD y+8(FP), R3 + MOVD $PosInf, R4 + CMPUBNE R4, R2, dim2 + CMPUBEQ R4, R3, bothInf +dim2: // (-Inf, -Inf) special case + MOVD $NegInf, R4 + CMPUBNE R4, R2, dim3 + CMPUBEQ R4, R3, bothInf +dim3: // (NaN, x) or (x, NaN) + MOVD $~(1<<63), R5 + MOVD $PosInf, R4 + AND R5, R2 // x = |x| + CMPUBLT R4, R2, isDimNaN + AND R5, R3 // y = |y| + CMPUBLT R4, R3, isDimNaN + + FMOVD x+0(FP), F1 + FMOVD y+8(FP), F2 + FSUB F2, F1 + FMOVD $(0.0), F2 + FCMPU F2, F1 + BGE +3(PC) + FMOVD F1, ret+16(FP) + RET + FMOVD F2, ret+16(FP) + RET +bothInf: // Dim(-Inf, -Inf) or Dim(+Inf, +Inf) +isDimNaN: + MOVD $NaN, R4 + MOVD R4, ret+16(FP) + RET + +// func ·Max(x, y float64) float64 +TEXT ·Max(SB),NOSPLIT,$0 + // +Inf special cases + MOVD $PosInf, R4 + MOVD x+0(FP), R8 + CMPUBEQ R4, R8, isPosInf + MOVD y+8(FP), R9 + CMPUBEQ R4, R9, isPosInf + // NaN special cases + MOVD $~(1<<63), R5 // bit mask + MOVD $PosInf, R4 + MOVD R8, R2 + AND R5, R2 // x = |x| + CMPUBLT R4, R2, isMaxNaN + MOVD R9, R3 + AND R5, R3 // y = |y| + CMPUBLT R4, R3, isMaxNaN + // ±0 special cases + OR R3, R2 + BEQ isMaxZero + + FMOVD x+0(FP), F1 + FMOVD y+8(FP), F2 + FCMPU F2, F1 + BGT +3(PC) + FMOVD F1, ret+16(FP) + RET + FMOVD F2, ret+16(FP) + RET +isMaxNaN: // return NaN + MOVD $NaN, R4 +isPosInf: // return +Inf + MOVD R4, ret+16(FP) + RET +isMaxZero: + MOVD $(1<<63), R4 // -0.0 + CMPUBEQ R4, R8, +3(PC) + MOVD R8, ret+16(FP) // return 0 + RET + MOVD R9, ret+16(FP) // return other 0 + RET + +// func Min(x, y float64) float64 +TEXT ·Min(SB),NOSPLIT,$0 + // -Inf special cases + MOVD $NegInf, R4 + MOVD x+0(FP), R8 + CMPUBEQ R4, R8, isNegInf + MOVD y+8(FP), R9 + CMPUBEQ R4, R9, isNegInf + // NaN special cases + MOVD $~(1<<63), R5 + MOVD $PosInf, R4 + MOVD R8, R2 + AND R5, R2 // x = |x| + CMPUBLT R4, R2, isMinNaN + MOVD R9, R3 + AND R5, R3 // y = |y| + CMPUBLT R4, R3, isMinNaN + // ±0 special cases + OR R3, R2 + BEQ isMinZero + + FMOVD x+0(FP), F1 + FMOVD y+8(FP), F2 + FCMPU F2, F1 + BLT +3(PC) + FMOVD F1, ret+16(FP) + RET + FMOVD F2, ret+16(FP) + RET +isMinNaN: // return NaN + MOVD $NaN, R4 +isNegInf: // return -Inf + MOVD R4, ret+16(FP) + RET +isMinZero: + MOVD $(1<<63), R4 // -0.0 + CMPUBEQ R4, R8, +3(PC) + MOVD R9, ret+16(FP) // return other 0 + RET + MOVD R8, ret+16(FP) // return -0 + RET + diff --git a/src/math/sqrt_s390x.s b/src/math/sqrt_s390x.s new file mode 100644 index 0000000000..37ca0bec91 --- /dev/null +++ b/src/math/sqrt_s390x.s @@ -0,0 +1,12 @@ +// Copyright 2016 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. + +#include "textflag.h" + +// func Sqrt(x float64) float64 +TEXT ·Sqrt(SB),NOSPLIT,$0 + FMOVD x+0(FP), F1 + FSQRT F1, F1 + FMOVD F1, ret+8(FP) + RET diff --git a/src/math/stubs_s390x.s b/src/math/stubs_s390x.s new file mode 100644 index 0000000000..76868447cd --- /dev/null +++ b/src/math/stubs_s390x.s @@ -0,0 +1,77 @@ +// Copyright 2016 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. + +#include "../runtime/textflag.h" + +TEXT ·Asin(SB),NOSPLIT,$0 + BR ·asin(SB) + +TEXT ·Acos(SB),NOSPLIT,$0 + BR ·acos(SB) + +TEXT ·Atan2(SB),NOSPLIT,$0 + BR ·atan2(SB) + +TEXT ·Atan(SB),NOSPLIT,$0 + BR ·atan(SB) + +TEXT ·Exp2(SB),NOSPLIT,$0 + BR ·exp2(SB) + +TEXT ·Expm1(SB),NOSPLIT,$0 + BR ·expm1(SB) + +TEXT ·Exp(SB),NOSPLIT,$0 + BR ·exp(SB) + +TEXT ·Floor(SB),NOSPLIT,$0 + BR ·floor(SB) + +TEXT ·Ceil(SB),NOSPLIT,$0 + BR ·ceil(SB) + +TEXT ·Trunc(SB),NOSPLIT,$0 + BR ·trunc(SB) + +TEXT ·Frexp(SB),NOSPLIT,$0 + BR ·frexp(SB) + +TEXT ·Hypot(SB),NOSPLIT,$0 + BR ·hypot(SB) + +TEXT ·Ldexp(SB),NOSPLIT,$0 + BR ·ldexp(SB) + +TEXT ·Log10(SB),NOSPLIT,$0 + BR ·log10(SB) + +TEXT ·Log2(SB),NOSPLIT,$0 + BR ·log2(SB) + +TEXT ·Log1p(SB),NOSPLIT,$0 + BR ·log1p(SB) + +TEXT ·Log(SB),NOSPLIT,$0 + BR ·log(SB) + +TEXT ·Modf(SB),NOSPLIT,$0 + BR ·modf(SB) + +TEXT ·Mod(SB),NOSPLIT,$0 + BR ·mod(SB) + +TEXT ·Remainder(SB),NOSPLIT,$0 + BR ·remainder(SB) + +TEXT ·Sincos(SB),NOSPLIT,$0 + BR ·sincos(SB) + +TEXT ·Sin(SB),NOSPLIT,$0 + BR ·sin(SB) + +TEXT ·Cos(SB),NOSPLIT,$0 + BR ·cos(SB) + +TEXT ·Tan(SB),NOSPLIT,$0 + BR ·tan(SB) -- cgit v1.3 From 1e7c61d8c3fc0916b73cb7411afa45e99b50aac4 Mon Sep 17 00:00:00 2001 From: Michael Munday Date: Sun, 20 Mar 2016 21:49:52 -0400 Subject: math/big: add s390x function implementations Change-Id: I2aadc885d6330460e494c687757f07c5e006f3b0 Reviewed-on: https://go-review.googlesource.com/20937 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/math/big/arith_s390x.s | 565 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 565 insertions(+) create mode 100644 src/math/big/arith_s390x.s (limited to 'src/math') diff --git a/src/math/big/arith_s390x.s b/src/math/big/arith_s390x.s new file mode 100644 index 0000000000..a691970810 --- /dev/null +++ b/src/math/big/arith_s390x.s @@ -0,0 +1,565 @@ +// Copyright 2016 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. + +// +build !math_big_pure_go,s390x + +#include "textflag.h" + +// This file provides fast assembly versions for the elementary +// arithmetic operations on vectors implemented in arith.go. + +TEXT ·mulWW(SB),NOSPLIT,$0 + MOVD x+0(FP), R3 + MOVD y+8(FP), R4 + MULHDU R3, R4 + MOVD R10, z1+16(FP) + MOVD R11, z0+24(FP) + RET + +// func divWW(x1, x0, y Word) (q, r Word) +TEXT ·divWW(SB),NOSPLIT,$0 + MOVD x1+0(FP), R10 + MOVD x0+8(FP), R11 + MOVD y+16(FP), R5 + WORD $0xb98700a5 // dlgr r10,r5 + MOVD R11, q+24(FP) + MOVD R10, r+32(FP) + RET + +// DI = R3, CX = R4, SI = r10, r8 = r8, r9=r9, r10 = r2 , r11 = r5, r12 = r6, r13 = r7, r14 = r1 (R0 set to 0) + use R11 +// func addVV(z, x, y []Word) (c Word) +TEXT ·addVV(SB),NOSPLIT,$0 + MOVD z_len+8(FP), R3 + MOVD x+24(FP), R8 + MOVD y+48(FP), R9 + MOVD z+0(FP), R2 + + MOVD $0, R4 // c = 0 + MOVD $0, R0 // make sure it's zero + MOVD $0, R10 // i = 0 + + // s/JL/JMP/ below to disable the unrolled loop + SUB $4, R3 // n -= 4 + BLT v1 // if n < 0 goto v1 + +U1: // n >= 0 + // regular loop body unrolled 4x + MOVD 0(R8)(R10*1), R5 + MOVD 8(R8)(R10*1), R6 + MOVD 16(R8)(R10*1), R7 + MOVD 24(R8)(R10*1), R1 + ADDC R4, R4 // restore CF + MOVD 0(R9)(R10*1), R11 + ADDE R11, R5 + MOVD 8(R9)(R10*1), R11 + ADDE R11, R6 + MOVD 16(R9)(R10*1), R11 + ADDE R11, R7 + MOVD 24(R9)(R10*1), R11 + ADDE R11, R1 + MOVD R0, R4 + ADDE R4, R4 // save CF + NEG R4, R4 + MOVD R5, 0(R2)(R10*1) + MOVD R6, 8(R2)(R10*1) + MOVD R7, 16(R2)(R10*1) + MOVD R1, 24(R2)(R10*1) + + + ADD $32, R10 // i += 4 + SUB $4, R3 // n -= 4 + BGE U1 // if n >= 0 goto U1 + +v1: ADD $4, R3 // n += 4 + BLE E1 // if n <= 0 goto E1 + +L1: // n > 0 + ADDC R4, R4 // restore CF + MOVD 0(R8)(R10*1), R5 + MOVD 0(R9)(R10*1), R11 + ADDE R11, R5 + MOVD R5, 0(R2)(R10*1) + MOVD R0, R4 + ADDE R4, R4 // save CF + NEG R4, R4 + + ADD $8, R10 // i++ + SUB $1, R3 // n-- + BGT L1 // if n > 0 goto L1 + +E1: NEG R4, R4 + MOVD R4, c+72(FP) // return c + RET + +// DI = R3, CX = R4, SI = r10, r8 = r8, r9=r9, r10 = r2 , r11 = r5, r12 = r6, r13 = r7, r14 = r1 (R0 set to 0) + use R11 +// func subVV(z, x, y []Word) (c Word) +// (same as addVV except for SUBC/SUBE instead of ADDC/ADDE and label names) +TEXT ·subVV(SB),NOSPLIT,$0 + MOVD z_len+8(FP), R3 + MOVD x+24(FP), R8 + MOVD y+48(FP), R9 + MOVD z+0(FP), R2 + + MOVD $0, R4 // c = 0 + MOVD $0, R0 // make sure it's zero + MOVD $0, R10 // i = 0 + + // s/JL/JMP/ below to disable the unrolled loop + SUB $4, R3 // n -= 4 + BLT v1 // if n < 0 goto v1 + +U1: // n >= 0 + // regular loop body unrolled 4x + MOVD 0(R8)(R10*1), R5 + MOVD 8(R8)(R10*1), R6 + MOVD 16(R8)(R10*1), R7 + MOVD 24(R8)(R10*1), R1 + MOVD R0, R11 + SUBC R4, R11 // restore CF + MOVD 0(R9)(R10*1), R11 + SUBE R11, R5 + MOVD 8(R9)(R10*1), R11 + SUBE R11, R6 + MOVD 16(R9)(R10*1), R11 + SUBE R11, R7 + MOVD 24(R9)(R10*1), R11 + SUBE R11, R1 + MOVD R0, R4 + SUBE R4, R4 // save CF + MOVD R5, 0(R2)(R10*1) + MOVD R6, 8(R2)(R10*1) + MOVD R7, 16(R2)(R10*1) + MOVD R1, 24(R2)(R10*1) + + + ADD $32, R10 // i += 4 + SUB $4, R3 // n -= 4 + BGE U1 // if n >= 0 goto U1 + +v1: ADD $4, R3 // n += 4 + BLE E1 // if n <= 0 goto E1 + +L1: // n > 0 + MOVD R0, R11 + SUBC R4, R11 // restore CF + MOVD 0(R8)(R10*1), R5 + MOVD 0(R9)(R10*1), R11 + SUBE R11, R5 + MOVD R5, 0(R2)(R10*1) + MOVD R0, R4 + SUBE R4, R4 // save CF + + ADD $8, R10 // i++ + SUB $1, R3 // n-- + BGT L1 // if n > 0 goto L1 + +E1: NEG R4, R4 + MOVD R4, c+72(FP) // return c + RET + + +// func addVW(z, x []Word, y Word) (c Word) +TEXT ·addVW(SB),NOSPLIT,$0 +//DI = R3, CX = R4, SI = r10, r8 = r8, r10 = r2 , r11 = r5, r12 = r6, r13 = r7, r14 = r1 (R0 set to 0) + MOVD z_len+8(FP), R3 + MOVD x+24(FP), R8 + MOVD y+48(FP), R4 // c = y + MOVD z+0(FP), R2 + MOVD $0, R0 // make sure it's 0 + MOVD $0, R10 // i = 0 + + // s/JL/JMP/ below to disable the unrolled loop + SUB $4, R3 // n -= 4 + BLT v4 // if n < 4 goto v4 + +U4: // n >= 0 + // regular loop body unrolled 4x + MOVD 0(R8)(R10*1), R5 + MOVD 8(R8)(R10*1), R6 + MOVD 16(R8)(R10*1), R7 + MOVD 24(R8)(R10*1), R1 + ADDC R4, R5 + ADDE R0, R6 + ADDE R0, R7 + ADDE R0, R1 + ADDE R0, R0 + MOVD R0, R4 // save CF + SUB R0, R0 + MOVD R5, 0(R2)(R10*1) + MOVD R6, 8(R2)(R10*1) + MOVD R7, 16(R2)(R10*1) + MOVD R1, 24(R2)(R10*1) + + ADD $32, R10 // i += 4 -> i +=32 + SUB $4, R3 // n -= 4 + BGE U4 // if n >= 0 goto U4 + +v4: ADD $4, R3 // n += 4 + BLE E4 // if n <= 0 goto E4 + +L4: // n > 0 + MOVD 0(R8)(R10*1), R5 + ADDC R4, R5 + ADDE R0, R0 + MOVD R0, R4 // save CF + SUB R0, R0 + MOVD R5, 0(R2)(R10*1) + + ADD $8, R10 // i++ + SUB $1, R3 // n-- + BGT L4 // if n > 0 goto L4 + +E4: MOVD R4, c+56(FP) // return c + + RET + +//DI = R3, CX = R4, SI = r10, r8 = r8, r10 = r2 , r11 = r5, r12 = r6, r13 = r7, r14 = r1 (R0 set to 0) +// func subVW(z, x []Word, y Word) (c Word) +// (same as addVW except for SUBC/SUBE instead of ADDC/ADDE and label names) +TEXT ·subVW(SB),NOSPLIT,$0 + MOVD z_len+8(FP), R3 + MOVD x+24(FP), R8 + MOVD y+48(FP), R4 // c = y + MOVD z+0(FP), R2 + MOVD $0, R0 // make sure it's 0 + MOVD $0, R10 // i = 0 + + // s/JL/JMP/ below to disable the unrolled loop + SUB $4, R3 // n -= 4 + BLT v4 // if n < 4 goto v4 + +U4: // n >= 0 + // regular loop body unrolled 4x + MOVD 0(R8)(R10*1), R5 + MOVD 8(R8)(R10*1), R6 + MOVD 16(R8)(R10*1), R7 + MOVD 24(R8)(R10*1), R1 + SUBC R4, R5 //SLGR -> SUBC + SUBE R0, R6 //SLBGR -> SUBE + SUBE R0, R7 + SUBE R0, R1 + SUBE R4, R4 // save CF + NEG R4, R4 + MOVD R5, 0(R2)(R10*1) + MOVD R6, 8(R2)(R10*1) + MOVD R7, 16(R2)(R10*1) + MOVD R1, 24(R2)(R10*1) + + ADD $32, R10 // i += 4 -> i +=32 + SUB $4, R3 // n -= 4 + BGE U4 // if n >= 0 goto U4 + +v4: ADD $4, R3 // n += 4 + BLE E4 // if n <= 0 goto E4 + +L4: // n > 0 + MOVD 0(R8)(R10*1), R5 + SUBC R4, R5 + SUBE R4, R4 // save CF + NEG R4, R4 + MOVD R5, 0(R2)(R10*1) + + ADD $8, R10 // i++ + SUB $1, R3 // n-- + BGT L4 // if n > 0 goto L4 + +E4: MOVD R4, c+56(FP) // return c + + RET + +// func shlVU(z, x []Word, s uint) (c Word) +TEXT ·shlVU(SB),NOSPLIT,$0 + MOVD z_len+8(FP), R5 + SUB $1, R5 // n-- + BLT X8b // n < 0 (n <= 0) + + // n > 0 + MOVD s+48(FP), R4 + CMPBEQ R0, R4, Z80 //handle 0 case beq + MOVD $64, R6 + CMPBEQ R6, R4, Z864 //handle 64 case beq + MOVD z+0(FP), R2 + MOVD x+24(FP), R8 + SLD $3, R5 // n = n*8 + SUB R4, R6, R7 + MOVD (R8)(R5*1), R10 // w1 = x[i-1] + SRD R7, R10, R3 + MOVD R3, c+56(FP) + + MOVD $0, R1 // i = 0 + BR E8 + + // i < n-1 +L8: MOVD R10, R3 // w = w1 + MOVD -8(R8)(R5*1), R10 // w1 = x[i+1] + + SLD R4, R3 // w<>ŝ + SRD R7, R10, R6 + OR R6, R3 + MOVD R3, (R2)(R5*1) // z[i] = w<>ŝ + SUB $8, R5 // i-- + +E8: CMPBGT R5, R0, L8 // i < n-1 + + // i >= n-1 +X8a: SLD R4, R10 // w1<= n-1 + MOVD R10, (R2)(R5*1) + RET + +Z864: MOVD z+0(FP), R2 + MOVD x+24(FP), R8 + SLD $3, R5 // n = n*8 + MOVD (R8)(R5*1), R3 // w1 = x[n-1] + MOVD R3, c+56(FP) // z[i] = x[n-1] + + BR E864 + + // i < n-1 +L864: MOVD -8(R8)(R5*1), R3 + + MOVD R3, (R2)(R5*1) // z[i] = x[n-1] + SUB $8, R5 // i-- + +E864: CMPBGT R5, R0, L864 // i < n-1 + + MOVD R0, (R2) // z[n-1] = 0 + RET + + +// CX = R4, r8 = r8, r10 = r2 , r11 = r5, DX = r3, AX = r10 , BX = R1 , 64-count = r7 (R0 set to 0) temp = R6 +// func shrVU(z, x []Word, s uint) (c Word) +TEXT ·shrVU(SB),NOSPLIT,$0 + MOVD z_len+8(FP), R5 + SUB $1, R5 // n-- + BLT X9b // n < 0 (n <= 0) + + // n > 0 + MOVD s+48(FP), R4 + CMPBEQ R0, R4, ZB0 //handle 0 case beq + MOVD $64, R6 + CMPBEQ R6, R4, ZB64 //handle 64 case beq + MOVD z+0(FP), R2 + MOVD x+24(FP), R8 + SLD $3, R5 // n = n*8 + SUB R4, R6, R7 + MOVD (R8), R10 // w1 = x[0] + SLD R7, R10, R3 + MOVD R3, c+56(FP) + + MOVD $0, R1 // i = 0 + BR E9 + + // i < n-1 +L9: MOVD R10, R3 // w = w1 + MOVD 8(R8)(R1*1), R10 // w1 = x[i+1] + + SRD R4, R3 // w>>s | w1<>s | w1<= n-1 +X9a: SRD R4, R10 // w1>>s + MOVD R10, (R2)(R5*1) // z[n-1] = w1>>s + RET + +X9b: MOVD R0, c+56(FP) + RET + +ZB0: MOVD z+0(FP), R2 + MOVD x+24(FP), R8 + SLD $3, R5 // n = n*8 + + MOVD (R8), R10 // w1 = x[0] + MOVD $0, R3 // R10 << 64 + MOVD R3, c+56(FP) + + MOVD $0, R1 // i = 0 + BR E9Z + + // i < n-1 +L9Z: MOVD R10, R3 // w = w1 + MOVD 8(R8)(R1*1), R10 // w1 = x[i+1] + + MOVD R3, (R2)(R1*1) // z[i] = w>>s | w1<= n-1 + MOVD R10, (R2)(R5*1) // z[n-1] = w1>>s + RET + +ZB64: MOVD z+0(FP), R2 + MOVD x+24(FP), R8 + SLD $3, R5 // n = n*8 + MOVD (R8), R3 // w1 = x[0] + MOVD R3, c+56(FP) + + MOVD $0, R1 // i = 0 + BR E964 + + // i < n-1 +L964: MOVD 8(R8)(R1*1), R3 // w1 = x[i+1] + + MOVD R3, (R2)(R1*1) // z[i] = w>>s | w1<= n-1 + MOVD $0, R10 // w1>>s + MOVD R10, (R2)(R5*1) // z[n-1] = w1>>s + RET + +// CX = R4, r8 = r8, r9=r9, r10 = r2 , r11 = r5, DX = r3, AX = r6 , BX = R1 , (R0 set to 0) + use R11 + use R7 for i +// func mulAddVWW(z, x []Word, y, r Word) (c Word) +TEXT ·mulAddVWW(SB),NOSPLIT,$0 + MOVD z+0(FP), R2 + MOVD x+24(FP), R8 + MOVD y+48(FP), R9 + MOVD r+56(FP), R4 // c = r + MOVD z_len+8(FP), R5 + MOVD $0, R1 // i = 0 + MOVD $0, R7 // i*8 = 0 + MOVD $0, R0 // make sure it's zero + BR E5 + +L5: MOVD (R8)(R1*1), R6 + MULHDU R9, R6 + ADDC R4, R11 //add to low order bits + ADDE R0, R6 + MOVD R11, (R2)(R1*1) + MOVD R6, R4 + ADD $8, R1 // i*8 + 8 + ADD $1, R7 // i++ + +E5: CMPBLT R7, R5, L5 // i < n + + MOVD R4, c+64(FP) + RET + +// func addMulVVW(z, x []Word, y Word) (c Word) +// CX = R4, r8 = r8, r9=r9, r10 = r2 , r11 = r5, AX = r11, DX = R6, r12=r12, BX = R1 , (R0 set to 0) + use R11 + use R7 for i +TEXT ·addMulVVW(SB),NOSPLIT,$0 + MOVD z+0(FP), R2 + MOVD x+24(FP), R8 + MOVD y+48(FP), R9 + MOVD z_len+8(FP), R5 + + MOVD $0, R1 // i*8 = 0 + MOVD $0, R7 // i = 0 + MOVD $0, R0 // make sure it's zero + MOVD $0, R4 // c = 0 + + MOVD R5, R12 + AND $-2, R12 + CMPBGE R5, $2, A6 + BR E6 + +A6: MOVD (R8)(R1*1), R6 + MULHDU R9, R6 + MOVD (R2)(R1*1), R10 + ADDC R10, R11 //add to low order bits + ADDE R0, R6 + ADDC R4, R11 + ADDE R0, R6 + MOVD R6, R4 + MOVD R11, (R2)(R1*1) + + MOVD (8)(R8)(R1*1), R6 + MULHDU R9, R6 + MOVD (8)(R2)(R1*1), R10 + ADDC R10, R11 //add to low order bits + ADDE R0, R6 + ADDC R4, R11 + ADDE R0, R6 + MOVD R6, R4 + MOVD R11, (8)(R2)(R1*1) + + ADD $16, R1 // i*8 + 8 + ADD $2, R7 // i++ + + CMPBLT R7, R12, A6 + BR E6 + +L6: MOVD (R8)(R1*1), R6 + MULHDU R9, R6 + MOVD (R2)(R1*1), R10 + ADDC R10, R11 //add to low order bits + ADDE R0, R6 + ADDC R4, R11 + ADDE R0, R6 + MOVD R6, R4 + MOVD R11, (R2)(R1*1) + + ADD $8, R1 // i*8 + 8 + ADD $1, R7 // i++ + +E6: CMPBLT R7, R5, L6 // i < n + + MOVD R4, c+56(FP) + RET + +// func divWVW(z []Word, xn Word, x []Word, y Word) (r Word) +// CX = R4, r8 = r8, r9=r9, r10 = r2 , r11 = r5, AX = r11, DX = R6, r12=r12, BX = R1(*8) , (R0 set to 0) + use R11 + use R7 for i +TEXT ·divWVW(SB),NOSPLIT,$0 + MOVD z+0(FP), R2 + MOVD xn+24(FP), R10 // r = xn + MOVD x+32(FP), R8 + MOVD y+56(FP), R9 + MOVD z_len+8(FP), R7 // i = z + SLD $3, R7, R1 // i*8 + MOVD $0, R0 // make sure it's zero + BR E7 + +L7: MOVD (R8)(R1*1), R11 + WORD $0xB98700A9 //DLGR R10,R9 + MOVD R11, (R2)(R1*1) + +E7: SUB $1, R7 // i-- + SUB $8, R1 + BGE L7 // i >= 0 + + MOVD R10, r+64(FP) + RET + +// func bitLen(x Word) (n int) +TEXT ·bitLen(SB),NOSPLIT,$0 + MOVD x+0(FP), R2 + WORD $0xb9830022 // FLOGR R2,R2 + MOVD $64, R3 + SUB R2, R3 + MOVD R3, n+8(FP) + RET -- cgit v1.3 From 187afdebef7953295189d4531e7dccdc0cb64500 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 4 Apr 2016 19:28:15 +0300 Subject: math/big: re-use memory in Int.GCD This improves TLS handshake performance. benchmark old ns/op new ns/op delta BenchmarkGCD10x10/WithoutXY-4 965 968 +0.31% BenchmarkGCD10x10/WithXY-4 1813 1391 -23.28% BenchmarkGCD10x100/WithoutXY-4 1093 1075 -1.65% BenchmarkGCD10x100/WithXY-4 2348 1676 -28.62% BenchmarkGCD10x1000/WithoutXY-4 1569 1565 -0.25% BenchmarkGCD10x1000/WithXY-4 4262 3242 -23.93% BenchmarkGCD10x10000/WithoutXY-4 6069 6066 -0.05% BenchmarkGCD10x10000/WithXY-4 12123 11331 -6.53% BenchmarkGCD10x100000/WithoutXY-4 52664 52610 -0.10% BenchmarkGCD10x100000/WithXY-4 97494 95649 -1.89% BenchmarkGCD100x100/WithoutXY-4 5244 5228 -0.31% BenchmarkGCD100x100/WithXY-4 22572 18630 -17.46% BenchmarkGCD100x1000/WithoutXY-4 6143 6233 +1.47% BenchmarkGCD100x1000/WithXY-4 24652 19357 -21.48% BenchmarkGCD100x10000/WithoutXY-4 15725 15804 +0.50% BenchmarkGCD100x10000/WithXY-4 60552 55973 -7.56% BenchmarkGCD100x100000/WithoutXY-4 107008 107853 +0.79% BenchmarkGCD100x100000/WithXY-4 349597 340994 -2.46% BenchmarkGCD1000x1000/WithoutXY-4 63785 64434 +1.02% BenchmarkGCD1000x1000/WithXY-4 373186 334035 -10.49% BenchmarkGCD1000x10000/WithoutXY-4 78038 78241 +0.26% BenchmarkGCD1000x10000/WithXY-4 543692 507034 -6.74% BenchmarkGCD1000x100000/WithoutXY-4 205607 207727 +1.03% BenchmarkGCD1000x100000/WithXY-4 2488113 2415323 -2.93% BenchmarkGCD10000x10000/WithoutXY-4 1731340 1714992 -0.94% BenchmarkGCD10000x10000/WithXY-4 10601046 7111329 -32.92% BenchmarkGCD10000x100000/WithoutXY-4 2239155 2212173 -1.21% BenchmarkGCD10000x100000/WithXY-4 30097040 26538887 -11.82% BenchmarkGCD100000x100000/WithoutXY-4 119845326 119863916 +0.02% BenchmarkGCD100000x100000/WithXY-4 768006543 426795966 -44.43% benchmark old allocs new allocs delta BenchmarkGCD10x10/WithoutXY-4 5 5 +0.00% BenchmarkGCD10x10/WithXY-4 17 9 -47.06% BenchmarkGCD10x100/WithoutXY-4 6 6 +0.00% BenchmarkGCD10x100/WithXY-4 21 9 -57.14% BenchmarkGCD10x1000/WithoutXY-4 6 6 +0.00% BenchmarkGCD10x1000/WithXY-4 30 12 -60.00% BenchmarkGCD10x10000/WithoutXY-4 6 6 +0.00% BenchmarkGCD10x10000/WithXY-4 26 12 -53.85% BenchmarkGCD10x100000/WithoutXY-4 6 6 +0.00% BenchmarkGCD10x100000/WithXY-4 28 12 -57.14% BenchmarkGCD100x100/WithoutXY-4 5 5 +0.00% BenchmarkGCD100x100/WithXY-4 183 61 -66.67% BenchmarkGCD100x1000/WithoutXY-4 8 8 +0.00% BenchmarkGCD100x1000/WithXY-4 170 47 -72.35% BenchmarkGCD100x10000/WithoutXY-4 8 8 +0.00% BenchmarkGCD100x10000/WithXY-4 200 67 -66.50% BenchmarkGCD100x100000/WithoutXY-4 8 8 +0.00% BenchmarkGCD100x100000/WithXY-4 188 65 -65.43% BenchmarkGCD1000x1000/WithoutXY-4 5 5 +0.00% BenchmarkGCD1000x1000/WithXY-4 2435 1193 -51.01% BenchmarkGCD1000x10000/WithoutXY-4 8 8 +0.00% BenchmarkGCD1000x10000/WithXY-4 2211 1076 -51.33% BenchmarkGCD1000x100000/WithoutXY-4 8 8 +0.00% BenchmarkGCD1000x100000/WithXY-4 2271 1108 -51.21% BenchmarkGCD10000x10000/WithoutXY-4 5 5 +0.00% BenchmarkGCD10000x10000/WithXY-4 23183 11605 -49.94% BenchmarkGCD10000x100000/WithoutXY-4 8 8 +0.00% BenchmarkGCD10000x100000/WithXY-4 23421 11717 -49.97% BenchmarkGCD100000x100000/WithoutXY-4 5 5 +0.00% BenchmarkGCD100000x100000/WithXY-4 232976 116815 -49.86% benchmark old bytes new bytes delta BenchmarkGCD10x10/WithoutXY-4 208 208 +0.00% BenchmarkGCD10x10/WithXY-4 736 432 -41.30% BenchmarkGCD10x100/WithoutXY-4 256 256 +0.00% BenchmarkGCD10x100/WithXY-4 896 432 -51.79% BenchmarkGCD10x1000/WithoutXY-4 368 368 +0.00% BenchmarkGCD10x1000/WithXY-4 1856 1152 -37.93% BenchmarkGCD10x10000/WithoutXY-4 1616 1616 +0.00% BenchmarkGCD10x10000/WithXY-4 7920 7376 -6.87% BenchmarkGCD10x100000/WithoutXY-4 13776 13776 +0.00% BenchmarkGCD10x100000/WithXY-4 68800 68176 -0.91% BenchmarkGCD100x100/WithoutXY-4 208 208 +0.00% BenchmarkGCD100x100/WithXY-4 6960 2112 -69.66% BenchmarkGCD100x1000/WithoutXY-4 544 560 +2.94% BenchmarkGCD100x1000/WithXY-4 7280 2400 -67.03% BenchmarkGCD100x10000/WithoutXY-4 2896 2912 +0.55% BenchmarkGCD100x10000/WithXY-4 15280 10002 -34.54% BenchmarkGCD100x100000/WithoutXY-4 27344 27365 +0.08% BenchmarkGCD100x100000/WithXY-4 88288 83427 -5.51% BenchmarkGCD1000x1000/WithoutXY-4 544 544 +0.00% BenchmarkGCD1000x1000/WithXY-4 178288 40043 -77.54% BenchmarkGCD1000x10000/WithoutXY-4 3344 3136 -6.22% BenchmarkGCD1000x10000/WithXY-4 188720 54432 -71.16% BenchmarkGCD1000x100000/WithoutXY-4 27792 27592 -0.72% BenchmarkGCD1000x100000/WithXY-4 373872 239447 -35.95% BenchmarkGCD10000x10000/WithoutXY-4 4288 4288 +0.00% BenchmarkGCD10000x10000/WithXY-4 11935584 481875 -95.96% BenchmarkGCD10000x100000/WithoutXY-4 31296 28834 -7.87% BenchmarkGCD10000x100000/WithXY-4 13237088 1662620 -87.44% BenchmarkGCD100000x100000/WithoutXY-4 40768 40768 +0.00% BenchmarkGCD100000x100000/WithXY-4 1165518864 14256010 -98.78% Change-Id: I652b3244bd074a03f3bc9a87c282330f9e5f1507 Reviewed-on: https://go-review.googlesource.com/21506 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/math/big/gcd_test.go | 16 +++++++++++++++- src/math/big/int.go | 4 ++-- src/math/big/nat.go | 29 ++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 6 deletions(-) (limited to 'src/math') diff --git a/src/math/big/gcd_test.go b/src/math/big/gcd_test.go index c0b9f58300..a929bf597f 100644 --- a/src/math/big/gcd_test.go +++ b/src/math/big/gcd_test.go @@ -20,13 +20,27 @@ func randInt(r *rand.Rand, size uint) *Int { } func runGCD(b *testing.B, aSize, bSize uint) { + b.Run("WithoutXY", func(b *testing.B) { + runGCDExt(b, aSize, bSize, false) + }) + b.Run("WithXY", func(b *testing.B) { + runGCDExt(b, aSize, bSize, true) + }) +} + +func runGCDExt(b *testing.B, aSize, bSize uint, calcXY bool) { b.StopTimer() var r = rand.New(rand.NewSource(1234)) aa := randInt(r, aSize) bb := randInt(r, bSize) + var x, y *Int + if calcXY { + x = new(Int) + y = new(Int) + } b.StartTimer() for i := 0; i < b.N; i++ { - new(Int).GCD(nil, nil, aa, bb) + new(Int).GCD(x, y, aa, bb) } } diff --git a/src/math/big/int.go b/src/math/big/int.go index 67ab7042ff..f2a75d1cd5 100644 --- a/src/math/big/int.go +++ b/src/math/big/int.go @@ -459,11 +459,11 @@ func (z *Int) GCD(x, y, a, b *Int) *Int { q := new(Int) temp := new(Int) + r := new(Int) for len(B.abs) > 0 { - r := new(Int) q, r = q.QuoRem(A, B, r) - A, B = B, r + A, B, r = B, r, A temp.Set(X) X.Mul(X, q) diff --git a/src/math/big/nat.go b/src/math/big/nat.go index 7668b6481b..2e65d2a7ef 100644 --- a/src/math/big/nat.go +++ b/src/math/big/nat.go @@ -8,7 +8,10 @@ package big -import "math/rand" +import ( + "math/rand" + "sync" +) // An unsigned integer x of the form // @@ -539,6 +542,21 @@ func (z nat) div(z2, u, v nat) (q, r nat) { return } +// getNat returns a nat of len n. The contents may not be zero. +func getNat(n int) nat { + var z nat + if v := natPool.Get(); v != nil { + z = v.(nat) + } + return z.make(n) +} + +func putNat(x nat) { + natPool.Put(x) +} + +var natPool sync.Pool + // q = (uIn-r)/v, with 0 <= r < y // Uses z as storage for q, and u as storage for r if possible. // See Knuth, Volume 2, section 4.3.1, Algorithm D. @@ -557,7 +575,7 @@ func (z nat) divLarge(u, uIn, v nat) (q, r nat) { } q = z.make(m + 1) - qhatv := make(nat, n+1) + qhatv := getNat(n + 1) if alias(u, uIn) || alias(u, v) { u = nil // u is an alias for uIn or v - cannot reuse } @@ -565,10 +583,11 @@ func (z nat) divLarge(u, uIn, v nat) (q, r nat) { u.clear() // TODO(gri) no need to clear if we allocated a new u // D1. + var v1 nat shift := nlz(v[n-1]) if shift > 0 { // do not modify v, it may be used by another goroutine simultaneously - v1 := make(nat, n) + v1 = getNat(n) shlVU(v1, v, shift) v = v1 } @@ -609,6 +628,10 @@ func (z nat) divLarge(u, uIn, v nat) (q, r nat) { q[j] = qhat } + if v1 != nil { + putNat(v1) + } + putNat(qhatv) q = q.norm() shrVU(u, u, shift) -- cgit v1.3 From 0da4dbe2322eb3b6224df35ce3e9fc83f104762b Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Thu, 14 Apr 2016 19:09:36 -0700 Subject: all: remove unnecessary type conversions cmd and runtime were handled separately, and I'm intentionally skipped syscall. This is the rest of the standard library. CL generated mechanically with github.com/mdempsky/unconvert. Change-Id: I9e0eff886974dedc37adb93f602064b83e469122 Reviewed-on: https://go-review.googlesource.com/22104 Reviewed-by: Brad Fitzpatrick Run-TryBot: Matthew Dempsky TryBot-Result: Gobot Gobot --- src/archive/tar/reader.go | 8 ++++---- src/archive/tar/writer.go | 2 +- src/bytes/reader.go | 2 +- src/compress/bzip2/bzip2.go | 8 ++++---- src/compress/flate/huffman_bit_writer.go | 2 +- src/compress/flate/reverse_bits.go | 2 +- src/compress/lzw/writer.go | 2 +- src/crypto/des/block.go | 2 +- src/crypto/tls/handshake_messages.go | 4 ++-- src/debug/dwarf/buf.go | 2 +- src/debug/dwarf/line.go | 2 +- src/debug/dwarf/typeunit.go | 4 ++-- src/debug/elf/elf.go | 4 ++-- src/debug/elf/file.go | 32 ++++++++++++++++---------------- src/debug/gosym/pclntab.go | 4 ++-- src/debug/gosym/symtab.go | 4 ++-- src/encoding/asn1/marshal.go | 6 +++--- src/encoding/binary/binary.go | 2 +- src/encoding/gob/encode.go | 2 +- src/go/ast/ast.go | 2 +- src/image/color/ycbcr.go | 18 +++++++++--------- src/image/draw/draw.go | 8 ++++---- src/math/big/float.go | 4 ++-- src/math/big/natconv.go | 2 +- src/math/big/ratconv.go | 2 +- src/net/interface_bsd.go | 4 ++-- src/net/mail/message.go | 2 +- src/net/parse.go | 4 ++-- src/os/exec_windows.go | 2 +- src/os/file_windows.go | 14 +++++++------- src/os/stat_darwin.go | 2 +- src/os/stat_dragonfly.go | 4 ++-- src/os/stat_freebsd.go | 2 +- src/os/stat_linux.go | 2 +- src/os/stat_nacl.go | 2 +- src/os/stat_netbsd.go | 4 ++-- src/os/stat_openbsd.go | 4 ++-- src/os/stat_plan9.go | 2 +- src/os/stat_solaris.go | 4 ++-- src/os/stat_windows.go | 2 +- src/os/types_windows.go | 2 +- src/reflect/type.go | 4 ++-- src/reflect/value.go | 26 +++++++++++++------------- src/regexp/onepass.go | 2 +- src/strconv/extfloat.go | 4 ++-- src/strings/reader.go | 2 +- src/sync/pool.go | 4 ++-- src/time/time.go | 8 ++++---- src/time/zoneinfo_windows.go | 2 +- src/unicode/letter.go | 2 +- 50 files changed, 120 insertions(+), 120 deletions(-) (limited to 'src/math') diff --git a/src/archive/tar/reader.go b/src/archive/tar/reader.go index 741fe0152b..b924eeb568 100644 --- a/src/archive/tar/reader.go +++ b/src/archive/tar/reader.go @@ -306,7 +306,7 @@ func mergePAX(hdr *Header, headers map[string]string) error { if err != nil { return err } - hdr.Size = int64(size) + hdr.Size = size default: if strings.HasPrefix(k, paxXattr) { if hdr.Xattrs == nil { @@ -346,7 +346,7 @@ func parsePAXTime(t string) (time.Time, error) { // Right truncate nano_buf = nano_buf[:maxNanoSecondIntSize] } - nanoseconds, err = strconv.ParseInt(string(nano_buf), 10, 0) + nanoseconds, err = strconv.ParseInt(nano_buf, 10, 0) if err != nil { return time.Time{}, err } @@ -378,14 +378,14 @@ func parsePAX(r io.Reader) (map[string]string, error) { } sbuf = residual - keyStr := string(key) + keyStr := key if keyStr == paxGNUSparseOffset || keyStr == paxGNUSparseNumBytes { // GNU sparse format 0.0 special key. Write to sparseMap instead of using the headers map. sparseMap.WriteString(value) sparseMap.Write([]byte{','}) } else { // Normal key. Set the value in the headers map. - headers[keyStr] = string(value) + headers[keyStr] = value } } if sparseMap.Len() != 0 { diff --git a/src/archive/tar/writer.go b/src/archive/tar/writer.go index 600ee4be09..944b2d4952 100644 --- a/src/archive/tar/writer.go +++ b/src/archive/tar/writer.go @@ -278,7 +278,7 @@ func (tw *Writer) writeHeader(hdr *Header, allowPax bool) error { return err } } - tw.nb = int64(hdr.Size) + tw.nb = hdr.Size tw.pad = (blockSize - (tw.nb % blockSize)) % blockSize _, tw.err = tw.w.Write(header) diff --git a/src/bytes/reader.go b/src/bytes/reader.go index 7aa30578b3..aa39890f3b 100644 --- a/src/bytes/reader.go +++ b/src/bytes/reader.go @@ -114,7 +114,7 @@ func (r *Reader) Seek(offset int64, whence int) (int64, error) { case 0: abs = offset case 1: - abs = int64(r.i) + offset + abs = r.i + offset case 2: abs = int64(len(r.s)) + offset default: diff --git a/src/compress/bzip2/bzip2.go b/src/compress/bzip2/bzip2.go index 90e9aebab6..42788443bc 100644 --- a/src/compress/bzip2/bzip2.go +++ b/src/compress/bzip2/bzip2.go @@ -75,7 +75,7 @@ func (bz2 *reader) setup(needMagic bool) error { } bz2.fileCRC = 0 - bz2.blockSize = 100 * 1000 * (int(level) - '0') + bz2.blockSize = 100 * 1000 * (level - '0') if bz2.blockSize > len(bz2.tt) { bz2.tt = make([]uint32, bz2.blockSize) } @@ -293,7 +293,7 @@ func (bz2 *reader) readBlock() (err error) { if c >= numHuffmanTrees { return StructuralError("tree index too large") } - treeIndexes[i] = uint8(mtfTreeDecoder.Decode(c)) + treeIndexes[i] = mtfTreeDecoder.Decode(c) } // The list of symbols for the move-to-front transform is taken from @@ -399,7 +399,7 @@ func (bz2 *reader) readBlock() (err error) { return StructuralError("repeats past end of block") } for i := 0; i < repeat; i++ { - b := byte(mtf.First()) + b := mtf.First() bz2.tt[bufIndex] = uint32(b) bz2.c[b]++ bufIndex++ @@ -420,7 +420,7 @@ func (bz2 *reader) readBlock() (err error) { // it's always referenced with a run-length of 1. Thus 0 // doesn't need to be encoded and we have |v-1| in the next // line. - b := byte(mtf.Decode(int(v - 1))) + b := mtf.Decode(int(v - 1)) if bufIndex >= bz2.blockSize { return StructuralError("data exceeds block size") } diff --git a/src/compress/flate/huffman_bit_writer.go b/src/compress/flate/huffman_bit_writer.go index 23f242f88e..d0206e59cf 100644 --- a/src/compress/flate/huffman_bit_writer.go +++ b/src/compress/flate/huffman_bit_writer.go @@ -436,7 +436,7 @@ func (w *huffmanBitWriter) writeBlock(tokens []token, eof bool, input []byte) { } dynamicHeader := int64(3+5+5+4+(3*numCodegens)) + w.codegenEncoding.bitLength(w.codegenFreq[:]) + - int64(extraBits) + + extraBits + int64(w.codegenFreq[16]*2) + int64(w.codegenFreq[17]*3) + int64(w.codegenFreq[18]*7) diff --git a/src/compress/flate/reverse_bits.go b/src/compress/flate/reverse_bits.go index c1a02720d1..6b222900c1 100644 --- a/src/compress/flate/reverse_bits.go +++ b/src/compress/flate/reverse_bits.go @@ -44,5 +44,5 @@ func reverseUint16(v uint16) uint16 { } func reverseBits(number uint16, bitLength byte) uint16 { - return reverseUint16(number << uint8(16-bitLength)) + return reverseUint16(number << (16 - bitLength)) } diff --git a/src/compress/lzw/writer.go b/src/compress/lzw/writer.go index 7367c29651..6ddb335f31 100644 --- a/src/compress/lzw/writer.go +++ b/src/compress/lzw/writer.go @@ -119,7 +119,7 @@ func (e *encoder) incHi() error { if err := e.write(e, clear); err != nil { return err } - e.width = uint(e.litWidth) + 1 + e.width = e.litWidth + 1 e.hi = clear + 1 e.overflow = clear << 1 for i := range e.table { diff --git a/src/crypto/des/block.go b/src/crypto/des/block.go index 26355a22e7..99338d62a6 100644 --- a/src/crypto/des/block.go +++ b/src/crypto/des/block.go @@ -72,7 +72,7 @@ func init() { for i := 0; i < 4; i++ { for j := 0; j < 16; j++ { f := uint64(sBoxes[s][i][j]) << (4 * (7 - uint(s))) - f = permuteBlock(uint64(f), permutationFunction[:]) + f = permuteBlock(f, permutationFunction[:]) feistelBox[s][16*i+j] = uint32(f) } } diff --git a/src/crypto/tls/handshake_messages.go b/src/crypto/tls/handshake_messages.go index 13d013a594..3f9a63b110 100644 --- a/src/crypto/tls/handshake_messages.go +++ b/src/crypto/tls/handshake_messages.go @@ -214,7 +214,7 @@ func (m *clientHelloMsg) marshal() []byte { z[4] = byte(l) z = z[5:] for _, pointFormat := range m.supportedPoints { - z[0] = byte(pointFormat) + z[0] = pointFormat z = z[1:] } } @@ -589,7 +589,7 @@ func (m *serverHelloMsg) marshal() []byte { z := x[39+len(m.sessionId):] z[0] = uint8(m.cipherSuite >> 8) z[1] = uint8(m.cipherSuite) - z[2] = uint8(m.compressionMethod) + z[2] = m.compressionMethod z = z[3:] if numExtensions > 0 { diff --git a/src/debug/dwarf/buf.go b/src/debug/dwarf/buf.go index 7443043c11..24d266db10 100644 --- a/src/debug/dwarf/buf.go +++ b/src/debug/dwarf/buf.go @@ -157,7 +157,7 @@ func (b *buf) addr() uint64 { case 4: return uint64(b.uint32()) case 8: - return uint64(b.uint64()) + return b.uint64() } b.error("unknown address size") return 0 diff --git a/src/debug/dwarf/line.go b/src/debug/dwarf/line.go index b3b91ade62..ed82feef92 100644 --- a/src/debug/dwarf/line.go +++ b/src/debug/dwarf/line.go @@ -361,7 +361,7 @@ func (r *LineReader) step(entry *LineEntry) bool { // Special opcode [DWARF2 6.2.5.1, DWARF4 6.2.5.1] adjustedOpcode := opcode - r.opcodeBase r.advancePC(adjustedOpcode / r.lineRange) - lineDelta := r.lineBase + int(adjustedOpcode)%r.lineRange + lineDelta := r.lineBase + adjustedOpcode%r.lineRange r.state.Line += lineDelta goto emit } diff --git a/src/debug/dwarf/typeunit.go b/src/debug/dwarf/typeunit.go index ed42547386..652e02d917 100644 --- a/src/debug/dwarf/typeunit.go +++ b/src/debug/dwarf/typeunit.go @@ -76,7 +76,7 @@ func (d *Data) parseTypes(name string, types []byte) error { data: b.bytes(int(n - (b.off - hdroff))), atable: atable, asize: int(asize), - vers: int(vers), + vers: vers, is64: dwarf64, }, toff: Offset(toff), @@ -101,7 +101,7 @@ func (d *Data) sigToType(sig uint64) (Type, error) { b := makeBuf(d, tu, tu.name, tu.off, tu.data) r := &typeUnitReader{d: d, tu: tu, b: b} - t, err := d.readType(tu.name, r, Offset(tu.toff), make(map[Offset]Type), nil) + t, err := d.readType(tu.name, r, tu.toff, make(map[Offset]Type), nil) if err != nil { return nil, err } diff --git a/src/debug/elf/elf.go b/src/debug/elf/elf.go index af881c2495..3f43d4d896 100644 --- a/src/debug/elf/elf.go +++ b/src/debug/elf/elf.go @@ -2060,8 +2060,8 @@ type Rela32 struct { Addend int32 /* Addend. */ } -func R_SYM32(info uint32) uint32 { return uint32(info >> 8) } -func R_TYPE32(info uint32) uint32 { return uint32(info & 0xff) } +func R_SYM32(info uint32) uint32 { return info >> 8 } +func R_TYPE32(info uint32) uint32 { return info & 0xff } func R_INFO32(sym, typ uint32) uint32 { return sym<<8 | typ } // ELF32 Symbol. diff --git a/src/debug/elf/file.go b/src/debug/elf/file.go index 8fbf23fe5a..c173ea9331 100644 --- a/src/debug/elf/file.go +++ b/src/debug/elf/file.go @@ -294,7 +294,7 @@ func NewFile(r io.ReaderAt) (*File, error) { } f.Type = Type(hdr.Type) f.Machine = Machine(hdr.Machine) - f.Entry = uint64(hdr.Entry) + f.Entry = hdr.Entry if v := Version(hdr.Version); v != f.Version { return nil, &FormatError{0, "mismatched ELF version", v} } @@ -341,12 +341,12 @@ func NewFile(r io.ReaderAt) (*File, error) { p.ProgHeader = ProgHeader{ Type: ProgType(ph.Type), Flags: ProgFlag(ph.Flags), - Off: uint64(ph.Off), - Vaddr: uint64(ph.Vaddr), - Paddr: uint64(ph.Paddr), - Filesz: uint64(ph.Filesz), - Memsz: uint64(ph.Memsz), - Align: uint64(ph.Align), + Off: ph.Off, + Vaddr: ph.Vaddr, + Paddr: ph.Paddr, + Filesz: ph.Filesz, + Memsz: ph.Memsz, + Align: ph.Align, } } p.sr = io.NewSectionReader(r, int64(p.Off), int64(p.Filesz)) @@ -374,8 +374,8 @@ func NewFile(r io.ReaderAt) (*File, error) { Addr: uint64(sh.Addr), Offset: uint64(sh.Off), FileSize: uint64(sh.Size), - Link: uint32(sh.Link), - Info: uint32(sh.Info), + Link: sh.Link, + Info: sh.Info, Addralign: uint64(sh.Addralign), Entsize: uint64(sh.Entsize), } @@ -388,13 +388,13 @@ func NewFile(r io.ReaderAt) (*File, error) { s.SectionHeader = SectionHeader{ Type: SectionType(sh.Type), Flags: SectionFlag(sh.Flags), - Offset: uint64(sh.Off), - FileSize: uint64(sh.Size), - Addr: uint64(sh.Addr), - Link: uint32(sh.Link), - Info: uint32(sh.Info), - Addralign: uint64(sh.Addralign), - Entsize: uint64(sh.Entsize), + Offset: sh.Off, + FileSize: sh.Size, + Addr: sh.Addr, + Link: sh.Link, + Info: sh.Info, + Addralign: sh.Addralign, + Entsize: sh.Entsize, } } s.sr = io.NewSectionReader(r, int64(s.Offset), int64(s.FileSize)) diff --git a/src/debug/gosym/pclntab.go b/src/debug/gosym/pclntab.go index 291f102262..e859d5aed5 100644 --- a/src/debug/gosym/pclntab.go +++ b/src/debug/gosym/pclntab.go @@ -207,8 +207,8 @@ func (t *LineTable) go12Funcs() []Func { funcs := make([]Func, n) for i := range funcs { f := &funcs[i] - f.Entry = uint64(t.uintptr(t.functab[2*i*int(t.ptrsize):])) - f.End = uint64(t.uintptr(t.functab[(2*i+2)*int(t.ptrsize):])) + f.Entry = t.uintptr(t.functab[2*i*int(t.ptrsize):]) + f.End = t.uintptr(t.functab[(2*i+2)*int(t.ptrsize):]) info := t.Data[t.uintptr(t.functab[(2*i+1)*int(t.ptrsize):]):] f.LineTable = t f.FrameSize = int(t.binary.Uint32(info[t.ptrsize+2*4:])) diff --git a/src/debug/gosym/symtab.go b/src/debug/gosym/symtab.go index 49e154fd8e..c8fa9a0b38 100644 --- a/src/debug/gosym/symtab.go +++ b/src/debug/gosym/symtab.go @@ -294,8 +294,8 @@ func NewTable(symtab []byte, pcln *LineTable) (*Table, error) { t.Syms = t.Syms[0 : n+1] ts := &t.Syms[n] ts.Type = s.typ - ts.Value = uint64(s.value) - ts.GoType = uint64(s.gotype) + ts.Value = s.value + ts.GoType = s.gotype switch s.typ { default: // rewrite name to use . instead of · (c2 b7) diff --git a/src/encoding/asn1/marshal.go b/src/encoding/asn1/marshal.go index 2b796c4e75..30797ef099 100644 --- a/src/encoding/asn1/marshal.go +++ b/src/encoding/asn1/marshal.go @@ -315,9 +315,9 @@ func marshalUTCTime(out *forkableWriter, t time.Time) (err error) { switch { case 1950 <= year && year < 2000: - err = marshalTwoDigits(out, int(year-1900)) + err = marshalTwoDigits(out, year-1900) case 2000 <= year && year < 2050: - err = marshalTwoDigits(out, int(year-2000)) + err = marshalTwoDigits(out, year-2000) default: return StructuralError{"cannot represent time as UTCTime"} } @@ -435,7 +435,7 @@ func marshalBody(out *forkableWriter, value reflect.Value, params fieldParameter return out.WriteByte(0) } case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return marshalInt64(out, int64(v.Int())) + return marshalInt64(out, v.Int()) case reflect.Struct: t := v.Type() diff --git a/src/encoding/binary/binary.go b/src/encoding/binary/binary.go index ada5768695..46c6add062 100644 --- a/src/encoding/binary/binary.go +++ b/src/encoding/binary/binary.go @@ -269,7 +269,7 @@ func Write(w io.Writer, order ByteOrder, data interface{}) error { case *uint8: b[0] = *v case uint8: - b[0] = byte(v) + b[0] = v case []uint8: bs = v case *int16: diff --git a/src/encoding/gob/encode.go b/src/encoding/gob/encode.go index 2b3a556eac..50cd6adb46 100644 --- a/src/encoding/gob/encode.go +++ b/src/encoding/gob/encode.go @@ -127,7 +127,7 @@ func (state *encoderState) encodeInt(i int64) { } else { x = uint64(i << 1) } - state.encodeUint(uint64(x)) + state.encodeUint(x) } // encOp is the signature of an encoding operator for a given type. diff --git a/src/go/ast/ast.go b/src/go/ast/ast.go index 5ab4283826..cca2d48bbd 100644 --- a/src/go/ast/ast.go +++ b/src/go/ast/ast.go @@ -99,7 +99,7 @@ func (g *CommentGroup) Text() string { } comments := make([]string, len(g.List)) for i, c := range g.List { - comments[i] = string(c.Text) + comments[i] = c.Text } lines := make([]string, 0, 10) // most comments are less than 10 lines diff --git a/src/image/color/ycbcr.go b/src/image/color/ycbcr.go index d2c5b569a7..2e985fece1 100644 --- a/src/image/color/ycbcr.go +++ b/src/image/color/ycbcr.go @@ -237,10 +237,10 @@ func RGBToCMYK(r, g, b uint8) (uint8, uint8, uint8, uint8) { // CMYKToRGB converts a CMYK quadruple to an RGB triple. func CMYKToRGB(c, m, y, k uint8) (uint8, uint8, uint8) { - w := uint32(0xffff - uint32(k)*0x101) - r := uint32(0xffff-uint32(c)*0x101) * w / 0xffff - g := uint32(0xffff-uint32(m)*0x101) * w / 0xffff - b := uint32(0xffff-uint32(y)*0x101) * w / 0xffff + w := 0xffff - uint32(k)*0x101 + r := (0xffff - uint32(c)*0x101) * w / 0xffff + g := (0xffff - uint32(m)*0x101) * w / 0xffff + b := (0xffff - uint32(y)*0x101) * w / 0xffff return uint8(r >> 8), uint8(g >> 8), uint8(b >> 8) } @@ -256,11 +256,11 @@ func (c CMYK) RGBA() (uint32, uint32, uint32, uint32) { // This code is a copy of the CMYKToRGB function above, except that it // returns values in the range [0, 0xffff] instead of [0, 0xff]. - w := uint32(0xffff - uint32(c.K)*0x101) - r := uint32(0xffff-uint32(c.C)*0x101) * w / 0xffff - g := uint32(0xffff-uint32(c.M)*0x101) * w / 0xffff - b := uint32(0xffff-uint32(c.Y)*0x101) * w / 0xffff - return uint32(r), uint32(g), uint32(b), 0xffff + w := 0xffff - uint32(c.K)*0x101 + r := (0xffff - uint32(c.C)*0x101) * w / 0xffff + g := (0xffff - uint32(c.M)*0x101) * w / 0xffff + b := (0xffff - uint32(c.Y)*0x101) * w / 0xffff + return r, g, b, 0xffff } // CMYKModel is the Model for CMYK colors. diff --git a/src/image/draw/draw.go b/src/image/draw/draw.go index 94e3575663..6a16cd39cf 100644 --- a/src/image/draw/draw.go +++ b/src/image/draw/draw.go @@ -634,10 +634,10 @@ func drawPaletted(dst Image, r image.Rectangle, src image.Image, sp image.Point, if !floydSteinberg { continue } - er -= int32(palette[bestIndex][0]) - eg -= int32(palette[bestIndex][1]) - eb -= int32(palette[bestIndex][2]) - ea -= int32(palette[bestIndex][3]) + er -= palette[bestIndex][0] + eg -= palette[bestIndex][1] + eb -= palette[bestIndex][2] + ea -= palette[bestIndex][3] } else { out.R = uint16(er) diff --git a/src/math/big/float.go b/src/math/big/float.go index 4b8ad388d3..7a9c2b3dfb 100644 --- a/src/math/big/float.go +++ b/src/math/big/float.go @@ -1008,9 +1008,9 @@ func (x *Float) Float64() (float64, Accuracy) { if r.form == inf || e > emax { // overflow if x.neg { - return float64(math.Inf(-1)), Below + return math.Inf(-1), Below } - return float64(math.Inf(+1)), Above + return math.Inf(+1), Above } // e <= emax diff --git a/src/math/big/natconv.go b/src/math/big/natconv.go index d2ce667fb6..e216bd288c 100644 --- a/src/math/big/natconv.go +++ b/src/math/big/natconv.go @@ -302,7 +302,7 @@ func (x nat) itoa(neg bool, base int) []byte { } } else { - bb, ndigits := maxPow(Word(b)) + bb, ndigits := maxPow(b) // construct table of successive squares of bb*leafSize to use in subdivisions // result (table != nil) <=> (len(x) > leafSize > 0) diff --git a/src/math/big/ratconv.go b/src/math/big/ratconv.go index 57df124e88..7c127f8585 100644 --- a/src/math/big/ratconv.go +++ b/src/math/big/ratconv.go @@ -178,7 +178,7 @@ func scanExponent(r io.ByteScanner, binExpOk bool) (exp int64, base int, err err } break // i > 0 } - digits = append(digits, byte(ch)) + digits = append(digits, ch) } // i > 0 => we have at least one digit diff --git a/src/net/interface_bsd.go b/src/net/interface_bsd.go index b173fbcefc..17c6dd3dcd 100644 --- a/src/net/interface_bsd.go +++ b/src/net/interface_bsd.go @@ -61,13 +61,13 @@ func newLink(m *syscall.InterfaceMessage) (*Interface, error) { m.Data = m.Data[unsafe.Offsetof(sa.Data):] var name [syscall.IFNAMSIZ]byte for i := 0; i < int(sa.Nlen); i++ { - name[i] = byte(m.Data[i]) + name[i] = m.Data[i] } ifi.Name = string(name[:sa.Nlen]) ifi.MTU = int(m.Header.Data.Mtu) addr := make([]byte, sa.Alen) for i := 0; i < int(sa.Alen); i++ { - addr[i] = byte(m.Data[int(sa.Nlen)+i]) + addr[i] = m.Data[int(sa.Nlen)+i] } ifi.HardwareAddr = addr[:sa.Alen] } diff --git a/src/net/mail/message.go b/src/net/mail/message.go index 9e3a103a4f..b40a314e33 100644 --- a/src/net/mail/message.go +++ b/src/net/mail/message.go @@ -477,7 +477,7 @@ func (p *addrParser) consumeAtom(dot bool, permissive bool) (atom string, err er if i < p.len() && p.s[i] > 127 { return "", errNonASCII } - atom, p.s = string(p.s[:i]), p.s[i:] + atom, p.s = p.s[:i], p.s[i:] if !permissive { if strings.HasPrefix(atom, ".") { return "", errors.New("mail: leading dot in atom") diff --git a/src/net/parse.go b/src/net/parse.go index eaaa1edf30..ed82a7769b 100644 --- a/src/net/parse.go +++ b/src/net/parse.go @@ -105,14 +105,14 @@ func splitAtBytes(s string, t string) []string { for i := 0; i < len(s); i++ { if byteIndex(t, s[i]) >= 0 { if last < i { - a[n] = string(s[last:i]) + a[n] = s[last:i] n++ } last = i + 1 } } if last < len(s) { - a[n] = string(s[last:]) + a[n] = s[last:] n++ } return a[0:n] diff --git a/src/os/exec_windows.go b/src/os/exec_windows.go index 3264271b2e..72b5a93199 100644 --- a/src/os/exec_windows.go +++ b/src/os/exec_windows.go @@ -104,7 +104,7 @@ func init() { defer syscall.LocalFree(syscall.Handle(uintptr(unsafe.Pointer(argv)))) Args = make([]string, argc) for i, v := range (*argv)[:argc] { - Args[i] = string(syscall.UTF16ToString((*v)[:])) + Args[i] = syscall.UTF16ToString((*v)[:]) } } diff --git a/src/os/file_windows.go b/src/os/file_windows.go index 7d04477d42..137f24a0a9 100644 --- a/src/os/file_windows.go +++ b/src/os/file_windows.go @@ -181,9 +181,9 @@ func (file *file) close() error { } var e error if file.isdir() { - e = syscall.FindClose(syscall.Handle(file.fd)) + e = syscall.FindClose(file.fd) } else { - e = syscall.CloseHandle(syscall.Handle(file.fd)) + e = syscall.CloseHandle(file.fd) } var err error if e != nil { @@ -216,7 +216,7 @@ func (file *File) readdir(n int) (fi []FileInfo, err error) { d := &file.dirinfo.data for n != 0 && !file.dirinfo.isempty { if file.dirinfo.needdata { - e := syscall.FindNextFile(syscall.Handle(file.fd), d) + e := syscall.FindNextFile(file.fd, d) if e != nil { if e == syscall.ERROR_NO_MORE_FILES { break @@ -230,7 +230,7 @@ func (file *File) readdir(n int) (fi []FileInfo, err error) { } } file.dirinfo.needdata = true - name := string(syscall.UTF16ToString(d.FileName[0:])) + name := syscall.UTF16ToString(d.FileName[0:]) if name == "." || name == ".." { // Useless names continue } @@ -288,7 +288,7 @@ func (f *File) readConsole(b []byte) (n int, err error) { } wchars := make([]uint16, nwc) pwc := &wchars[0] - nwc, err = windows.MultiByteToWideChar(acp, 2, pmb, int32(nmb), pwc, int32(nwc)) + nwc, err = windows.MultiByteToWideChar(acp, 2, pmb, int32(nmb), pwc, nwc) if err != nil { return 0, err } @@ -335,7 +335,7 @@ func (f *File) pread(b []byte, off int64) (n int, err error) { Offset: uint32(off), } var done uint32 - e = syscall.ReadFile(syscall.Handle(f.fd), b, &done, &o) + e = syscall.ReadFile(f.fd, b, &done, &o) if e != nil { if e == syscall.ERROR_HANDLE_EOF { // end of file @@ -415,7 +415,7 @@ func (f *File) pwrite(b []byte, off int64) (n int, err error) { Offset: uint32(off), } var done uint32 - e = syscall.WriteFile(syscall.Handle(f.fd), b, &done, &o) + e = syscall.WriteFile(f.fd, b, &done, &o) if e != nil { return 0, e } diff --git a/src/os/stat_darwin.go b/src/os/stat_darwin.go index 9dc7a99fb7..74214cefa4 100644 --- a/src/os/stat_darwin.go +++ b/src/os/stat_darwin.go @@ -11,7 +11,7 @@ import ( func fillFileStatFromSys(fs *fileStat, name string) { fs.name = basename(name) - fs.size = int64(fs.sys.Size) + fs.size = fs.sys.Size fs.modTime = timespecToTime(fs.sys.Mtimespec) fs.mode = FileMode(fs.sys.Mode & 0777) switch fs.sys.Mode & syscall.S_IFMT { diff --git a/src/os/stat_dragonfly.go b/src/os/stat_dragonfly.go index 69e63230eb..217bc6726d 100644 --- a/src/os/stat_dragonfly.go +++ b/src/os/stat_dragonfly.go @@ -11,7 +11,7 @@ import ( func fillFileStatFromSys(fs *fileStat, name string) { fs.name = basename(name) - fs.size = int64(fs.sys.Size) + fs.size = fs.sys.Size fs.modTime = timespecToTime(fs.sys.Mtim) fs.mode = FileMode(fs.sys.Mode & 0777) switch fs.sys.Mode & syscall.S_IFMT { @@ -42,7 +42,7 @@ func fillFileStatFromSys(fs *fileStat, name string) { } func timespecToTime(ts syscall.Timespec) time.Time { - return time.Unix(int64(ts.Sec), int64(ts.Nsec)) + return time.Unix(ts.Sec, ts.Nsec) } // For testing. diff --git a/src/os/stat_freebsd.go b/src/os/stat_freebsd.go index e9d38aa722..bab4ffa798 100644 --- a/src/os/stat_freebsd.go +++ b/src/os/stat_freebsd.go @@ -11,7 +11,7 @@ import ( func fillFileStatFromSys(fs *fileStat, name string) { fs.name = basename(name) - fs.size = int64(fs.sys.Size) + fs.size = fs.sys.Size fs.modTime = timespecToTime(fs.sys.Mtimespec) fs.mode = FileMode(fs.sys.Mode & 0777) switch fs.sys.Mode & syscall.S_IFMT { diff --git a/src/os/stat_linux.go b/src/os/stat_linux.go index 69e63230eb..d36afa9ffd 100644 --- a/src/os/stat_linux.go +++ b/src/os/stat_linux.go @@ -11,7 +11,7 @@ import ( func fillFileStatFromSys(fs *fileStat, name string) { fs.name = basename(name) - fs.size = int64(fs.sys.Size) + fs.size = fs.sys.Size fs.modTime = timespecToTime(fs.sys.Mtim) fs.mode = FileMode(fs.sys.Mode & 0777) switch fs.sys.Mode & syscall.S_IFMT { diff --git a/src/os/stat_nacl.go b/src/os/stat_nacl.go index d3bed14e43..0c53f2faa4 100644 --- a/src/os/stat_nacl.go +++ b/src/os/stat_nacl.go @@ -11,7 +11,7 @@ import ( func fillFileStatFromSys(fs *fileStat, name string) { fs.name = basename(name) - fs.size = int64(fs.sys.Size) + fs.size = fs.sys.Size fs.modTime = timespecToTime(fs.sys.Mtime, fs.sys.MtimeNsec) fs.mode = FileMode(fs.sys.Mode & 0777) switch fs.sys.Mode & syscall.S_IFMT { diff --git a/src/os/stat_netbsd.go b/src/os/stat_netbsd.go index e9d38aa722..11ebcacab8 100644 --- a/src/os/stat_netbsd.go +++ b/src/os/stat_netbsd.go @@ -11,7 +11,7 @@ import ( func fillFileStatFromSys(fs *fileStat, name string) { fs.name = basename(name) - fs.size = int64(fs.sys.Size) + fs.size = fs.sys.Size fs.modTime = timespecToTime(fs.sys.Mtimespec) fs.mode = FileMode(fs.sys.Mode & 0777) switch fs.sys.Mode & syscall.S_IFMT { @@ -42,7 +42,7 @@ func fillFileStatFromSys(fs *fileStat, name string) { } func timespecToTime(ts syscall.Timespec) time.Time { - return time.Unix(int64(ts.Sec), int64(ts.Nsec)) + return time.Unix(ts.Sec, int64(ts.Nsec)) } // For testing. diff --git a/src/os/stat_openbsd.go b/src/os/stat_openbsd.go index 69e63230eb..9df2d7f773 100644 --- a/src/os/stat_openbsd.go +++ b/src/os/stat_openbsd.go @@ -11,7 +11,7 @@ import ( func fillFileStatFromSys(fs *fileStat, name string) { fs.name = basename(name) - fs.size = int64(fs.sys.Size) + fs.size = fs.sys.Size fs.modTime = timespecToTime(fs.sys.Mtim) fs.mode = FileMode(fs.sys.Mode & 0777) switch fs.sys.Mode & syscall.S_IFMT { @@ -42,7 +42,7 @@ func fillFileStatFromSys(fs *fileStat, name string) { } func timespecToTime(ts syscall.Timespec) time.Time { - return time.Unix(int64(ts.Sec), int64(ts.Nsec)) + return time.Unix(ts.Sec, int64(ts.Nsec)) } // For testing. diff --git a/src/os/stat_plan9.go b/src/os/stat_plan9.go index a2df5fe139..96f056c111 100644 --- a/src/os/stat_plan9.go +++ b/src/os/stat_plan9.go @@ -20,7 +20,7 @@ func sameFile(fs1, fs2 *fileStat) bool { func fileInfoFromStat(d *syscall.Dir) FileInfo { fs := &fileStat{ name: d.Name, - size: int64(d.Length), + size: d.Length, modTime: time.Unix(int64(d.Mtime), 0), sys: d, } diff --git a/src/os/stat_solaris.go b/src/os/stat_solaris.go index 69e63230eb..217bc6726d 100644 --- a/src/os/stat_solaris.go +++ b/src/os/stat_solaris.go @@ -11,7 +11,7 @@ import ( func fillFileStatFromSys(fs *fileStat, name string) { fs.name = basename(name) - fs.size = int64(fs.sys.Size) + fs.size = fs.sys.Size fs.modTime = timespecToTime(fs.sys.Mtim) fs.mode = FileMode(fs.sys.Mode & 0777) switch fs.sys.Mode & syscall.S_IFMT { @@ -42,7 +42,7 @@ func fillFileStatFromSys(fs *fileStat, name string) { } func timespecToTime(ts syscall.Timespec) time.Time { - return time.Unix(int64(ts.Sec), int64(ts.Nsec)) + return time.Unix(ts.Sec, ts.Nsec) } // For testing. diff --git a/src/os/stat_windows.go b/src/os/stat_windows.go index b8f97ad60a..e55eeb0fdd 100644 --- a/src/os/stat_windows.go +++ b/src/os/stat_windows.go @@ -35,7 +35,7 @@ func (file *File) Stat() (FileInfo, error) { } var d syscall.ByHandleFileInformation - err = syscall.GetFileInformationByHandle(syscall.Handle(file.fd), &d) + err = syscall.GetFileInformationByHandle(file.fd, &d) if err != nil { return nil, &PathError{"GetFileInformationByHandle", file.name, err} } diff --git a/src/os/types_windows.go b/src/os/types_windows.go index 900d444b0e..ad4e863fcb 100644 --- a/src/os/types_windows.go +++ b/src/os/types_windows.go @@ -73,7 +73,7 @@ func (fs *fileStat) loadFileId() error { } defer syscall.CloseHandle(h) var i syscall.ByHandleFileInformation - err = syscall.GetFileInformationByHandle(syscall.Handle(h), &i) + err = syscall.GetFileInformationByHandle(h, &i) if err != nil { return err } diff --git a/src/reflect/type.go b/src/reflect/type.go index 3c7affcd7f..b8c778cc2b 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -967,7 +967,7 @@ func (t *rtype) Out(i int) Type { } func (t *funcType) in() []*rtype { - uadd := uintptr(unsafe.Sizeof(*t)) + uadd := unsafe.Sizeof(*t) if t.tflag&tflagUncommon != 0 { uadd += unsafe.Sizeof(uncommonType{}) } @@ -975,7 +975,7 @@ func (t *funcType) in() []*rtype { } func (t *funcType) out() []*rtype { - uadd := uintptr(unsafe.Sizeof(*t)) + uadd := unsafe.Sizeof(*t) if t.tflag&tflagUncommon != 0 { uadd += unsafe.Sizeof(uncommonType{}) } diff --git a/src/reflect/value.go b/src/reflect/value.go index d72c14e9e1..d4d317436a 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -666,7 +666,7 @@ func (v Value) Cap() int { case Array: return v.typ.Len() case Chan: - return int(chancap(v.pointer())) + return chancap(v.pointer()) case Slice: // Slice is always bigger than a word; assume flagIndir. return (*sliceHeader)(v.ptr).Cap @@ -885,7 +885,7 @@ func (v Value) Int() int64 { case Int32: return int64(*(*int32)(p)) case Int64: - return int64(*(*int64)(p)) + return *(*int64)(p) } panic(&ValueError{"reflect.Value.Int", v.kind()}) } @@ -1436,7 +1436,7 @@ func (v Value) SetCap(n int) { v.mustBeAssignable() v.mustBe(Slice) s := (*sliceHeader)(v.ptr) - if n < int(s.Len) || n > int(s.Cap) { + if n < s.Len || n > s.Cap { panic("reflect: slice capacity out of range in SetCap") } s.Cap = n @@ -1538,7 +1538,7 @@ func (v Value) Slice(i, j int) Value { case Slice: typ = (*sliceType)(unsafe.Pointer(v.typ)) s := (*sliceHeader)(v.ptr) - base = unsafe.Pointer(s.Data) + base = s.Data cap = s.Cap case String: @@ -1710,7 +1710,7 @@ func (v Value) Uint() uint64 { case Uint32: return uint64(*(*uint32)(p)) case Uint64: - return uint64(*(*uint64)(p)) + return *(*uint64)(p) case Uintptr: return uint64(*(*uintptr)(p)) } @@ -2267,13 +2267,13 @@ func makeInt(f flag, bits uint64, t Type) Value { ptr := unsafe_New(typ) switch typ.size { case 1: - *(*uint8)(unsafe.Pointer(ptr)) = uint8(bits) + *(*uint8)(ptr) = uint8(bits) case 2: - *(*uint16)(unsafe.Pointer(ptr)) = uint16(bits) + *(*uint16)(ptr) = uint16(bits) case 4: - *(*uint32)(unsafe.Pointer(ptr)) = uint32(bits) + *(*uint32)(ptr) = uint32(bits) case 8: - *(*uint64)(unsafe.Pointer(ptr)) = bits + *(*uint64)(ptr) = bits } return Value{typ, ptr, f | flagIndir | flag(typ.Kind())} } @@ -2285,9 +2285,9 @@ func makeFloat(f flag, v float64, t Type) Value { ptr := unsafe_New(typ) switch typ.size { case 4: - *(*float32)(unsafe.Pointer(ptr)) = float32(v) + *(*float32)(ptr) = float32(v) case 8: - *(*float64)(unsafe.Pointer(ptr)) = v + *(*float64)(ptr) = v } return Value{typ, ptr, f | flagIndir | flag(typ.Kind())} } @@ -2299,9 +2299,9 @@ func makeComplex(f flag, v complex128, t Type) Value { ptr := unsafe_New(typ) switch typ.size { case 8: - *(*complex64)(unsafe.Pointer(ptr)) = complex64(v) + *(*complex64)(ptr) = complex64(v) case 16: - *(*complex128)(unsafe.Pointer(ptr)) = v + *(*complex128)(ptr) = v } return Value{typ, ptr, f | flagIndir | flag(typ.Kind())} } diff --git a/src/regexp/onepass.go b/src/regexp/onepass.go index 5b82f9666e..4991954820 100644 --- a/src/regexp/onepass.go +++ b/src/regexp/onepass.go @@ -450,7 +450,7 @@ func makeOnePass(p *onePassProg) *onePassProg { for !instQueue.empty() { visitQueue.clear() pc := instQueue.next() - if !check(uint32(pc), m) { + if !check(pc, m) { p = notOnePass break } diff --git a/src/strconv/extfloat.go b/src/strconv/extfloat.go index 019b4eebdc..7033e96c39 100644 --- a/src/strconv/extfloat.go +++ b/src/strconv/extfloat.go @@ -311,9 +311,9 @@ func (f *extFloat) AssignDecimal(mantissa uint64, exp10 int, neg bool, trunc boo var extrabits uint if f.exp <= denormalExp { // f.mant * 2^f.exp is smaller than 2^(flt.bias+1). - extrabits = uint(63 - flt.mantbits + 1 + uint(denormalExp-f.exp)) + extrabits = 63 - flt.mantbits + 1 + uint(denormalExp-f.exp) } else { - extrabits = uint(63 - flt.mantbits) + extrabits = 63 - flt.mantbits } halfway := uint64(1) << (extrabits - 1) diff --git a/src/strings/reader.go b/src/strings/reader.go index 737873c099..74eed4d574 100644 --- a/src/strings/reader.go +++ b/src/strings/reader.go @@ -113,7 +113,7 @@ func (r *Reader) Seek(offset int64, whence int) (int64, error) { case 0: abs = offset case 1: - abs = int64(r.i) + offset + abs = r.i + offset case 2: abs = int64(len(r.s)) + offset default: diff --git a/src/sync/pool.go b/src/sync/pool.go index 4fb1a1af9d..2acf505f3c 100644 --- a/src/sync/pool.go +++ b/src/sync/pool.go @@ -179,8 +179,8 @@ func (p *Pool) pinSlow() *poolLocal { // If GOMAXPROCS changes between GCs, we re-allocate the array and lose the old one. size := runtime.GOMAXPROCS(0) local := make([]poolLocal, size) - atomic.StorePointer((*unsafe.Pointer)(&p.local), unsafe.Pointer(&local[0])) // store-release - atomic.StoreUintptr(&p.localSize, uintptr(size)) // store-release + atomic.StorePointer(&p.local, unsafe.Pointer(&local[0])) // store-release + atomic.StoreUintptr(&p.localSize, uintptr(size)) // store-release return &local[pid] } diff --git a/src/time/time.go b/src/time/time.go index 4b9a0db730..92d635eec5 100644 --- a/src/time/time.go +++ b/src/time/time.go @@ -606,7 +606,7 @@ func (d Duration) Hours() float64 { // Add returns the time t+d. func (t Time) Add(d Duration) Time { t.sec += int64(d / 1e9) - nsec := int32(t.nsec) + int32(d%1e9) + nsec := t.nsec + int32(d%1e9) if nsec >= 1e9 { t.sec++ nsec -= 1e9 @@ -623,7 +623,7 @@ func (t Time) Add(d Duration) Time { // will be returned. // To compute t-d for a duration d, use t.Add(-d). func (t Time) Sub(u Time) Duration { - d := Duration(t.sec-u.sec)*Second + Duration(int32(t.nsec)-int32(u.nsec)) + d := Duration(t.sec-u.sec)*Second + Duration(t.nsec-u.nsec) // Check for overflow or underflow. switch { case u.Add(d).Equal(t): @@ -1125,7 +1125,7 @@ func (t Time) Round(d Duration) Time { // but it's still here in case we change our minds. func div(t Time, d Duration) (qmod2 int, r Duration) { neg := false - nsec := int32(t.nsec) + nsec := t.nsec if t.sec < 0 { // Operate on absolute value. neg = true @@ -1159,7 +1159,7 @@ func div(t Time, d Duration) (qmod2 int, r Duration) { tmp := (sec >> 32) * 1e9 u1 := tmp >> 32 u0 := tmp << 32 - tmp = uint64(sec&0xFFFFFFFF) * 1e9 + tmp = (sec & 0xFFFFFFFF) * 1e9 u0x, u0 := u0, u0+tmp if u0 < u0x { u1++ diff --git a/src/time/zoneinfo_windows.go b/src/time/zoneinfo_windows.go index bcb8ccd563..c753119d5d 100644 --- a/src/time/zoneinfo_windows.go +++ b/src/time/zoneinfo_windows.go @@ -83,7 +83,7 @@ func extractCAPS(desc string) string { var short []rune for _, c := range desc { if 'A' <= c && c <= 'Z' { - short = append(short, rune(c)) + short = append(short, c) } } return string(short) diff --git a/src/unicode/letter.go b/src/unicode/letter.go index 8443ee51a2..ffa083eb57 100644 --- a/src/unicode/letter.go +++ b/src/unicode/letter.go @@ -217,7 +217,7 @@ func to(_case int, r rune, caseRange []CaseRange) rune { m := lo + (hi-lo)/2 cr := caseRange[m] if rune(cr.Lo) <= r && r <= rune(cr.Hi) { - delta := rune(cr.Delta[_case]) + delta := cr.Delta[_case] if delta > MaxRune { // In an Upper-Lower sequence, which always starts with // an UpperCase letter, the real deltas always look like: -- cgit v1.3 From d8c9dd604801958c649a32511deef373adeecfe0 Mon Sep 17 00:00:00 2001 From: OneOfOne Date: Sun, 10 Apr 2016 03:50:11 +0200 Subject: math/big: implement GobDecode/Encode for big.Float Added GobEncode/Decode and a test for them. Fixes #14593 Change-Id: Ic8d3efd24d0313a1a66f01da293c4c1fd39764a8 Reviewed-on: https://go-review.googlesource.com/21755 Reviewed-by: Robert Griesemer --- src/math/big/floatmarsh.go | 65 ++++++++++++++++++++++++++++++++++++++++- src/math/big/floatmarsh_test.go | 63 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 1 deletion(-) (limited to 'src/math') diff --git a/src/math/big/floatmarsh.go b/src/math/big/floatmarsh.go index 44987ee03a..6127aa2e83 100644 --- a/src/math/big/floatmarsh.go +++ b/src/math/big/floatmarsh.go @@ -6,7 +6,70 @@ package big -import "fmt" +import ( + "encoding/binary" + "fmt" +) + +// Gob codec version. Permits backward-compatible changes to the encoding. +const floatGobVersion byte = 1 + +// GobEncode implements the gob.GobEncoder interface. +func (x *Float) GobEncode() ([]byte, error) { + if x == nil { + return nil, nil + } + sz := 1 + 1 + 4 // version + mode|acc|form|neg (3+2+2+1bit) + prec + if x.form == finite { + sz += 4 + int((x.prec+(_W-1))/_W)*_S // exp + mant + } + buf := make([]byte, sz) + + buf[0] = floatGobVersion + b := byte(x.mode&7)<<5 | byte((x.acc+1)&3)<<3 | byte(x.form&3)<<1 + if x.neg { + b |= 1 + } + buf[1] = b + binary.BigEndian.PutUint32(buf[2:], x.prec) + if x.form == finite { + binary.BigEndian.PutUint32(buf[6:], uint32(x.exp)) + x.mant.bytes(buf[10:]) + } + return buf, nil +} + +// GobDecode implements the gob.GobDecoder interface. +func (z *Float) GobDecode(buf []byte) error { + if len(buf) == 0 { + // Other side sent a nil or default value. + *z = Float{} + return nil + } + + if buf[0] != floatGobVersion { + return fmt.Errorf("Float.GobDecode: encoding version %d not supported", buf[0]) + } + + b := buf[1] + z.mode = RoundingMode((b >> 5) & 7) + z.acc = Accuracy((b>>3)&3) - 1 + z.form = form((b >> 1) & 3) + z.neg = b&1 != 0 + + oldPrec := uint(z.prec) + z.prec = binary.BigEndian.Uint32(buf[2:]) + + if z.form == finite { + z.exp = int32(binary.BigEndian.Uint32(buf[6:])) + z.mant = z.mant.setBytes(buf[10:]) + } + + if oldPrec != 0 { + z.SetPrec(oldPrec) + } + return nil +} // MarshalText implements the encoding.TextMarshaler interface. // Only the Float value is marshaled (in full precision), other diff --git a/src/math/big/floatmarsh_test.go b/src/math/big/floatmarsh_test.go index d7ef2fca68..f726c35e99 100644 --- a/src/math/big/floatmarsh_test.go +++ b/src/math/big/floatmarsh_test.go @@ -5,7 +5,10 @@ package big import ( + "bytes" + "encoding/gob" "encoding/json" + "io" "testing" ) @@ -23,6 +26,66 @@ var floatVals = []string{ "Inf", } +func TestFloatGobEncoding(t *testing.T) { + var medium bytes.Buffer + for _, test := range floatVals { + for _, sign := range []string{"", "+", "-"} { + for _, prec := range []uint{0, 1, 2, 10, 53, 64, 100, 1000} { + medium.Reset() // empty buffer for each test case (in case of failures) + enc := gob.NewEncoder(&medium) + dec := gob.NewDecoder(&medium) + x := sign + test + var tx Float + _, _, err := tx.SetPrec(prec).Parse(x, 0) + if err != nil { + t.Errorf("parsing of %s (prec = %d) failed (invalid test case): %v", x, prec, err) + continue + } + tx.SetMode(ToPositiveInf) + if err := enc.Encode(&tx); err != nil { + t.Errorf("encoding of %v (prec = %d) failed: %v", &tx, prec, err) + continue + } + + var rx Float + if err := dec.Decode(&rx); err != nil { + t.Errorf("decoding of %v (prec = %d) failed: %v", &tx, prec, err) + continue + } + + if rx.Cmp(&tx) != 0 { + t.Errorf("transmission of %s failed: got %s want %s", x, rx.String(), tx.String()) + continue + } + + if rx.Mode() != ToPositiveInf { + t.Errorf("transmission of %s's mode failed: got %s want %s", x, rx.Mode(), ToPositiveInf) + } + } + } + } +} +func TestFloatCorruptGob(t *testing.T) { + var buf bytes.Buffer + tx := NewFloat(4 / 3).SetPrec(1000).SetMode(ToPositiveInf) + if err := gob.NewEncoder(&buf).Encode(tx); err != nil { + t.Fatal(err) + } + b := buf.Bytes() + var rx Float + if err := gob.NewDecoder(bytes.NewReader(b)).Decode(&rx); err != nil { + t.Fatal(err) + } + var rx2 Float + if err := gob.NewDecoder(bytes.NewReader(b[:10])).Decode(&rx2); err != io.ErrUnexpectedEOF { + t.Errorf("expected io.ErrUnexpectedEOF, got %v", err) + } + b[1] = 0 + if err := gob.NewDecoder(bytes.NewReader(b)).Decode(&rx); err == nil { + t.Fatal("expected a version error, got nil") + } + +} func TestFloatJSONEncoding(t *testing.T) { for _, test := range floatVals { for _, sign := range []string{"", "+", "-"} { -- cgit v1.3 From aea224386ea7c10c07490bb6cdef12a51fa9a9cf Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 20 Apr 2016 13:40:55 -0700 Subject: math/big: more tests, documentation for Flot gob marshalling Follow-up to https://golang.org/cl/21755. This turned out to be a bit more than just a few nits as originally expected in that CL. 1) The actual mantissa may be shorter than required for the given precision (because of trailing 0's): no need to allocate space for it (and transmit 0's). This can save a lot of space when the precision is high: E.g., for prec == 1000, 16 words or 128 bytes are required at the most, but if the actual number is short, it may be much less (for the test cases present, it's significantly less). 2) The actual mantissa may be longer than the number of words required for the given precision: make sure to not overflow when encoding in bytes. 3) Add more documentation. 4) Add more tests. Change-Id: I9f40c408cfdd9183a8e81076d2f7d6c75e7a00e9 Reviewed-on: https://go-review.googlesource.com/22324 Reviewed-by: Alan Donovan --- src/math/big/floatmarsh.go | 34 ++++++++++++++--- src/math/big/floatmarsh_test.go | 81 +++++++++++++++++++++++++---------------- 2 files changed, 79 insertions(+), 36 deletions(-) (limited to 'src/math') diff --git a/src/math/big/floatmarsh.go b/src/math/big/floatmarsh.go index 6127aa2e83..3725d4b834 100644 --- a/src/math/big/floatmarsh.go +++ b/src/math/big/floatmarsh.go @@ -15,13 +15,29 @@ import ( const floatGobVersion byte = 1 // GobEncode implements the gob.GobEncoder interface. +// The Float value and all its attributes (precision, +// rounding mode, accuracy) are marshalled. func (x *Float) GobEncode() ([]byte, error) { if x == nil { return nil, nil } + + // determine max. space (bytes) required for encoding sz := 1 + 1 + 4 // version + mode|acc|form|neg (3+2+2+1bit) + prec + n := 0 // number of mantissa words if x.form == finite { - sz += 4 + int((x.prec+(_W-1))/_W)*_S // exp + mant + // add space for mantissa and exponent + n = int((x.prec + (_W - 1)) / _W) // required mantissa length in words for given precision + // actual mantissa slice could be shorter (trailing 0's) or longer (unused bits): + // - if shorter, only encode the words present + // - if longer, cut off unused words when encoding in bytes + // (in practice, this should never happen since rounding + // takes care of it, but be safe and do it always) + if len(x.mant) < n { + n = len(x.mant) + } + // len(x.mant) >= n + sz += 4 + n*_S // exp + mant } buf := make([]byte, sz) @@ -32,14 +48,19 @@ func (x *Float) GobEncode() ([]byte, error) { } buf[1] = b binary.BigEndian.PutUint32(buf[2:], x.prec) + if x.form == finite { binary.BigEndian.PutUint32(buf[6:], uint32(x.exp)) - x.mant.bytes(buf[10:]) + x.mant[len(x.mant)-n:].bytes(buf[10:]) // cut off unused trailing words } + return buf, nil } // GobDecode implements the gob.GobDecoder interface. +// The result is rounded per the precision and rounding mode of +// z unless z's precision is 0, in which case z is set exactly +// to the decoded value. func (z *Float) GobDecode(buf []byte) error { if len(buf) == 0 { // Other side sent a nil or default value. @@ -51,13 +72,14 @@ func (z *Float) GobDecode(buf []byte) error { return fmt.Errorf("Float.GobDecode: encoding version %d not supported", buf[0]) } + oldPrec := z.prec + oldMode := z.mode + b := buf[1] z.mode = RoundingMode((b >> 5) & 7) z.acc = Accuracy((b>>3)&3) - 1 z.form = form((b >> 1) & 3) z.neg = b&1 != 0 - - oldPrec := uint(z.prec) z.prec = binary.BigEndian.Uint32(buf[2:]) if z.form == finite { @@ -66,8 +88,10 @@ func (z *Float) GobDecode(buf []byte) error { } if oldPrec != 0 { - z.SetPrec(oldPrec) + z.mode = oldMode + z.SetPrec(uint(oldPrec)) } + return nil } diff --git a/src/math/big/floatmarsh_test.go b/src/math/big/floatmarsh_test.go index f726c35e99..5bd906ddae 100644 --- a/src/math/big/floatmarsh_test.go +++ b/src/math/big/floatmarsh_test.go @@ -28,43 +28,60 @@ var floatVals = []string{ func TestFloatGobEncoding(t *testing.T) { var medium bytes.Buffer + enc := gob.NewEncoder(&medium) + dec := gob.NewDecoder(&medium) for _, test := range floatVals { for _, sign := range []string{"", "+", "-"} { for _, prec := range []uint{0, 1, 2, 10, 53, 64, 100, 1000} { - medium.Reset() // empty buffer for each test case (in case of failures) - enc := gob.NewEncoder(&medium) - dec := gob.NewDecoder(&medium) - x := sign + test - var tx Float - _, _, err := tx.SetPrec(prec).Parse(x, 0) - if err != nil { - t.Errorf("parsing of %s (prec = %d) failed (invalid test case): %v", x, prec, err) - continue - } - tx.SetMode(ToPositiveInf) - if err := enc.Encode(&tx); err != nil { - t.Errorf("encoding of %v (prec = %d) failed: %v", &tx, prec, err) - continue - } + for _, mode := range []RoundingMode{ToNearestEven, ToNearestAway, ToZero, AwayFromZero, ToNegativeInf, ToPositiveInf} { + medium.Reset() // empty buffer for each test case (in case of failures) + x := sign + test - var rx Float - if err := dec.Decode(&rx); err != nil { - t.Errorf("decoding of %v (prec = %d) failed: %v", &tx, prec, err) - continue - } + var tx Float + _, _, err := tx.SetPrec(prec).SetMode(mode).Parse(x, 0) + if err != nil { + t.Errorf("parsing of %s (%dbits, %v) failed (invalid test case): %v", x, prec, mode, err) + continue + } - if rx.Cmp(&tx) != 0 { - t.Errorf("transmission of %s failed: got %s want %s", x, rx.String(), tx.String()) - continue - } + // If tx was set to prec == 0, tx.Parse(x, 0) assumes precision 64. Correct it. + if prec == 0 { + tx.SetPrec(0) + } + + if err := enc.Encode(&tx); err != nil { + t.Errorf("encoding of %v (%dbits, %v) failed: %v", &tx, prec, mode, err) + continue + } + + var rx Float + if err := dec.Decode(&rx); err != nil { + t.Errorf("decoding of %v (%dbits, %v) failed: %v", &tx, prec, mode, err) + continue + } + + if rx.Cmp(&tx) != 0 { + t.Errorf("transmission of %s failed: got %s want %s", x, rx.String(), tx.String()) + continue + } + + if rx.Prec() != prec { + t.Errorf("transmission of %s's prec failed: got %d want %d", x, rx.Prec(), prec) + } + + if rx.Mode() != mode { + t.Errorf("transmission of %s's mode failed: got %s want %s", x, rx.Mode(), mode) + } - if rx.Mode() != ToPositiveInf { - t.Errorf("transmission of %s's mode failed: got %s want %s", x, rx.Mode(), ToPositiveInf) + if rx.Acc() != tx.Acc() { + t.Errorf("transmission of %s's accuracy failed: got %s want %s", x, rx.Acc(), tx.Acc()) + } } } } } } + func TestFloatCorruptGob(t *testing.T) { var buf bytes.Buffer tx := NewFloat(4 / 3).SetPrec(1000).SetMode(ToPositiveInf) @@ -72,20 +89,22 @@ func TestFloatCorruptGob(t *testing.T) { t.Fatal(err) } b := buf.Bytes() + var rx Float if err := gob.NewDecoder(bytes.NewReader(b)).Decode(&rx); err != nil { t.Fatal(err) } - var rx2 Float - if err := gob.NewDecoder(bytes.NewReader(b[:10])).Decode(&rx2); err != io.ErrUnexpectedEOF { - t.Errorf("expected io.ErrUnexpectedEOF, got %v", err) + + if err := gob.NewDecoder(bytes.NewReader(b[:10])).Decode(&rx); err != io.ErrUnexpectedEOF { + t.Errorf("got %v want EOF", err) } + b[1] = 0 if err := gob.NewDecoder(bytes.NewReader(b)).Decode(&rx); err == nil { - t.Fatal("expected a version error, got nil") + t.Fatal("got nil want version error") } - } + func TestFloatJSONEncoding(t *testing.T) { for _, test := range floatVals { for _, sign := range []string{"", "+", "-"} { -- cgit v1.3