| 
									
										
										
										
											2012-04-20 23:45:43 +08:00
										 |  |  | // runoutput | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Copyright 2009 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. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Generate test of 64-bit arithmetic. | 
					
						
							|  |  |  | // Most synthesized routines have different cases for | 
					
						
							|  |  |  | // constants vs variables and even the generated code has | 
					
						
							|  |  |  | // different cases for large and small constants, | 
					
						
							|  |  |  | // so try a good range of inputs. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	"bufio" | 
					
						
							|  |  |  | 	"fmt" | 
					
						
							|  |  |  | 	"os" | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | var bout *bufio.Writer | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | // 64-bit math without using 64-bit numbers, | 
					
						
							|  |  |  | // so that we can generate the test program even | 
					
						
							|  |  |  | // if the compiler has buggy or missing 64-bit support. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type Uint64 struct { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	hi	uint32 | 
					
						
							|  |  |  | 	lo	uint32 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type Int64 struct { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	hi	int32 | 
					
						
							|  |  |  | 	lo	uint32 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) Int64() (c Int64) { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	c.hi = int32(a.hi) | 
					
						
							|  |  |  | 	c.lo = a.lo | 
					
						
							|  |  |  | 	return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) Cmp(b Uint64) int { | 
					
						
							|  |  |  | 	switch { | 
					
						
							|  |  |  | 	case a.hi < b.hi: | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		return -1 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	case a.hi > b.hi: | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		return 1 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	case a.lo < b.lo: | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		return -1 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	case a.lo > b.lo: | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		return 1 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	return 0 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) LeftShift(b uint) (c Uint64) { | 
					
						
							|  |  |  | 	switch { | 
					
						
							|  |  |  | 	case b >= 64: | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		c.hi = 0 | 
					
						
							|  |  |  | 		c.lo = 0 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	case b >= 32: | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		c.hi = a.lo << (b - 32) | 
					
						
							|  |  |  | 		c.lo = 0 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		c.hi = a.hi<<b | a.lo>>(32-b) | 
					
						
							|  |  |  | 		c.lo = a.lo << b | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) RightShift(b uint) (c Uint64) { | 
					
						
							|  |  |  | 	switch { | 
					
						
							|  |  |  | 	case b >= 64: | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		c.hi = 0 | 
					
						
							|  |  |  | 		c.lo = a.hi | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	case b >= 32: | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		c.hi = 0 | 
					
						
							|  |  |  | 		c.lo = a.hi >> (b - 32) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		c.hi = a.hi >> b | 
					
						
							|  |  |  | 		c.lo = a.hi<<(32-b) | a.lo>>b | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) LeftShift64(b Uint64) (c Uint64) { | 
					
						
							|  |  |  | 	if b.hi != 0 || b.lo >= 64 { | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	return a.LeftShift(uint(b.lo)) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) RightShift64(b Uint64) (c Uint64) { | 
					
						
							|  |  |  | 	if b.hi != 0 || b.lo >= 64 { | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	return a.RightShift(uint(b.lo)) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) Plus(b Uint64) (c Uint64) { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	var carry uint32 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	if c.lo = a.lo + b.lo; c.lo < a.lo { | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		carry = 1 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	c.hi = a.hi + b.hi + carry | 
					
						
							|  |  |  | 	return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) Minus(b Uint64) (c Uint64) { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	var borrow uint32 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	if c.lo = a.lo - b.lo; c.lo > a.lo { | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		borrow = 1 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	c.hi = a.hi - b.hi - borrow | 
					
						
							|  |  |  | 	return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) Neg() (c Uint64) { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	var zero Uint64 | 
					
						
							|  |  |  | 	return zero.Minus(a) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) Com() (c Uint64) { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	c.hi = ^a.hi | 
					
						
							|  |  |  | 	c.lo = ^a.lo | 
					
						
							|  |  |  | 	return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) Len() int { | 
					
						
							|  |  |  | 	switch { | 
					
						
							|  |  |  | 	case a.hi != 0: | 
					
						
							|  |  |  | 		for i := 31; i >= 0; i-- { | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 			if a.hi&(1<<uint(i)) != 0 { | 
					
						
							|  |  |  | 				return i + 1 + 32 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	case a.lo != 0: | 
					
						
							|  |  |  | 		for i := 31; i >= 0; i-- { | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 			if a.lo&(1<<uint(i)) != 0 { | 
					
						
							|  |  |  | 				return i + 1 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	return 0 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) HasBit(b uint) bool { | 
					
						
							|  |  |  | 	switch { | 
					
						
							|  |  |  | 	case b >= 64: | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		return false | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	case b >= 32: | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		return a.hi&(1<<(b-32)) != 0 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	return a.lo&(1<<b) != 0 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) Times(b Uint64) (c Uint64) { | 
					
						
							|  |  |  | 	for i := uint(0); i < 64; i++ { | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		if b.HasBit(i) { | 
					
						
							|  |  |  | 			c = c.Plus(a.LeftShift(i)) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) DivMod(b Uint64) (quo, rem Uint64) { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	n := a.Len() - b.Len() | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	if n >= 0 { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		b = b.LeftShift(uint(n)) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 		for i := 0; i <= n; i++ { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 			quo = quo.LeftShift(1) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 			if b.Cmp(a) <= 0 {	// b <= a | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 				quo.lo |= 1 | 
					
						
							|  |  |  | 				a = a.Minus(b) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 			b = b.RightShift(1) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	rem = a | 
					
						
							|  |  |  | 	return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) And(b Uint64) (c Uint64) { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	c.hi = a.hi & b.hi | 
					
						
							|  |  |  | 	c.lo = a.lo & b.lo | 
					
						
							|  |  |  | 	return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) AndNot(b Uint64) (c Uint64) { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	c.hi = a.hi &^ b.hi | 
					
						
							|  |  |  | 	c.lo = a.lo &^ b.lo | 
					
						
							|  |  |  | 	return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) Or(b Uint64) (c Uint64) { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	c.hi = a.hi | b.hi | 
					
						
							|  |  |  | 	c.lo = a.lo | b.lo | 
					
						
							|  |  |  | 	return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Uint64) Xor(b Uint64) (c Uint64) { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	c.hi = a.hi ^ b.hi | 
					
						
							|  |  |  | 	c.lo = a.lo ^ b.lo | 
					
						
							|  |  |  | 	return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | func (a Uint64) String() string	{ return fmt.Sprintf("%#x%08x", a.hi, a.lo) } | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (a Int64) Uint64() (c Uint64) { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	c.hi = uint32(a.hi) | 
					
						
							|  |  |  | 	c.lo = a.lo | 
					
						
							|  |  |  | 	return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Int64) Cmp(b Int64) int { | 
					
						
							|  |  |  | 	// Same body as Uint64.Cmp, | 
					
						
							|  |  |  | 	// but behaves differently | 
					
						
							|  |  |  | 	// because hi is uint32 not int32. | 
					
						
							|  |  |  | 	switch { | 
					
						
							|  |  |  | 	case a.hi < b.hi: | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		return -1 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	case a.hi > b.hi: | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		return 1 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	case a.lo < b.lo: | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		return -1 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	case a.lo > b.lo: | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		return 1 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	return 0 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | func (a Int64) LeftShift(b uint) (c Int64)	{ return a.Uint64().LeftShift(b).Int64() } | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (a Int64) RightShift(b uint) (c Int64) { | 
					
						
							|  |  |  | 	switch { | 
					
						
							|  |  |  | 	case b >= 64: | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		c.hi = a.hi >> 31	// sign extend | 
					
						
							|  |  |  | 		c.lo = uint32(c.hi) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	case b >= 32: | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		c.hi = a.hi >> 31	// sign extend | 
					
						
							|  |  |  | 		c.lo = uint32(a.hi >> (b - 32)) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		c.hi = a.hi >> b | 
					
						
							|  |  |  | 		c.lo = uint32(a.hi<<(32-b)) | a.lo>>b | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Int64) LeftShift64(b Uint64) (c Int64) { | 
					
						
							|  |  |  | 	if b.hi != 0 || b.lo >= 64 { | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	return a.LeftShift(uint(b.lo)) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (a Int64) RightShift64(b Uint64) (c Int64) { | 
					
						
							|  |  |  | 	if b.hi != 0 || b.lo >= 64 { | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		return a.RightShift(64) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	return a.RightShift(uint(b.lo)) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | func (a Int64) Plus(b Int64) (c Int64)	{ return a.Uint64().Plus(b.Uint64()).Int64() } | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | func (a Int64) Minus(b Int64) (c Int64)	{ return a.Uint64().Minus(b.Uint64()).Int64() } | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | func (a Int64) Neg() (c Int64)	{ return a.Uint64().Neg().Int64() } | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | func (a Int64) Com() (c Int64)	{ return a.Uint64().Com().Int64() } | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | func (a Int64) Times(b Int64) (c Int64)	{ return a.Uint64().Times(b.Uint64()).Int64() } | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (a Int64) DivMod(b Int64) (quo Int64, rem Int64) { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	var zero Int64 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	quoSign := +1 | 
					
						
							|  |  |  | 	remSign := +1 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	if a.Cmp(zero) < 0 { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		quoSign = -1 | 
					
						
							|  |  |  | 		remSign = -1 | 
					
						
							|  |  |  | 		a = a.Neg() | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if b.Cmp(zero) < 0 { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		quoSign = -quoSign | 
					
						
							|  |  |  | 		b = b.Neg() | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	q, r := a.Uint64().DivMod(b.Uint64()) | 
					
						
							|  |  |  | 	quo = q.Int64() | 
					
						
							|  |  |  | 	rem = r.Int64() | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if quoSign < 0 { | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		quo = quo.Neg() | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if remSign < 0 { | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		rem = rem.Neg() | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	return | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | func (a Int64) And(b Int64) (c Int64)	{ return a.Uint64().And(b.Uint64()).Int64() } | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | func (a Int64) AndNot(b Int64) (c Int64)	{ return a.Uint64().AndNot(b.Uint64()).Int64() } | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | func (a Int64) Or(b Int64) (c Int64)	{ return a.Uint64().Or(b.Uint64()).Int64() } | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | func (a Int64) Xor(b Int64) (c Int64)	{ return a.Uint64().Xor(b.Uint64()).Int64() } | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (a Int64) String() string { | 
					
						
							|  |  |  | 	if a.hi < 0 { | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		return fmt.Sprintf("-%s", a.Neg().Uint64()) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	return a.Uint64().String() | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | var int64Values = []Int64{ | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	Int64{0, 0}, | 
					
						
							|  |  |  | 	Int64{0, 1}, | 
					
						
							|  |  |  | 	Int64{0, 2}, | 
					
						
							|  |  |  | 	Int64{0, 3}, | 
					
						
							|  |  |  | 	Int64{0, 100}, | 
					
						
							|  |  |  | 	Int64{0, 10001}, | 
					
						
							|  |  |  | 	Int64{0, 1<<31 - 1}, | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 	Int64{0, 1 << 31}, | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	Int64{0, 1<<31 + 1}, | 
					
						
							|  |  |  | 	Int64{0, 1<<32 - 1<<30}, | 
					
						
							|  |  |  | 	Int64{0, 1<<32 - 1}, | 
					
						
							|  |  |  | 	Int64{1, 0}, | 
					
						
							|  |  |  | 	Int64{1, 1}, | 
					
						
							|  |  |  | 	Int64{2, 0}, | 
					
						
							|  |  |  | 	Int64{1<<31 - 1, 1<<32 - 10000}, | 
					
						
							|  |  |  | 	Int64{1<<31 - 1, 1<<32 - 1}, | 
					
						
							|  |  |  | 	Int64{0x789abcde, 0xf0123456}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Int64{-1, 1<<32 - 1}, | 
					
						
							|  |  |  | 	Int64{-1, 1<<32 - 2}, | 
					
						
							|  |  |  | 	Int64{-1, 1<<32 - 3}, | 
					
						
							|  |  |  | 	Int64{-1, 1<<32 - 100}, | 
					
						
							|  |  |  | 	Int64{-1, 1<<32 - 10001}, | 
					
						
							|  |  |  | 	Int64{-1, 1<<32 - (1<<31 - 1)}, | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 	Int64{-1, 1<<32 - 1<<31}, | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	Int64{-1, 1<<32 - (1<<31 + 1)}, | 
					
						
							|  |  |  | 	Int64{-1, 1<<32 - (1<<32 - 1<<30)}, | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 	Int64{-1, 0}, | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	Int64{-1, 1}, | 
					
						
							|  |  |  | 	Int64{-2, 0}, | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 	Int64{-(1 << 31), 10000}, | 
					
						
							|  |  |  | 	Int64{-(1 << 31), 1}, | 
					
						
							|  |  |  | 	Int64{-(1 << 31), 0}, | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	Int64{-0x789abcde, 0xf0123456}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | var uint64Values = []Uint64{ | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	Uint64{0, 0}, | 
					
						
							|  |  |  | 	Uint64{0, 1}, | 
					
						
							|  |  |  | 	Uint64{0, 2}, | 
					
						
							|  |  |  | 	Uint64{0, 3}, | 
					
						
							|  |  |  | 	Uint64{0, 100}, | 
					
						
							|  |  |  | 	Uint64{0, 10001}, | 
					
						
							|  |  |  | 	Uint64{0, 1<<31 - 1}, | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 	Uint64{0, 1 << 31}, | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	Uint64{0, 1<<31 + 1}, | 
					
						
							|  |  |  | 	Uint64{0, 1<<32 - 1<<30}, | 
					
						
							|  |  |  | 	Uint64{0, 1<<32 - 1}, | 
					
						
							|  |  |  | 	Uint64{1, 0}, | 
					
						
							|  |  |  | 	Uint64{1, 1}, | 
					
						
							|  |  |  | 	Uint64{2, 0}, | 
					
						
							|  |  |  | 	Uint64{1<<31 - 1, 1<<32 - 10000}, | 
					
						
							|  |  |  | 	Uint64{1<<31 - 1, 1<<32 - 1}, | 
					
						
							|  |  |  | 	Uint64{1<<32 - 1<<30, 0}, | 
					
						
							|  |  |  | 	Uint64{1<<32 - 1, 0}, | 
					
						
							|  |  |  | 	Uint64{1<<32 - 1, 1<<32 - 100}, | 
					
						
							|  |  |  | 	Uint64{1<<32 - 1, 1<<32 - 1}, | 
					
						
							|  |  |  | 	Uint64{0x789abcde, 0xf0123456}, | 
					
						
							|  |  |  | 	Uint64{0xfedcba98, 0x76543210}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | var shiftValues = []Uint64{ | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	Uint64{0, 0}, | 
					
						
							|  |  |  | 	Uint64{0, 1}, | 
					
						
							|  |  |  | 	Uint64{0, 2}, | 
					
						
							|  |  |  | 	Uint64{0, 3}, | 
					
						
							|  |  |  | 	Uint64{0, 15}, | 
					
						
							|  |  |  | 	Uint64{0, 16}, | 
					
						
							|  |  |  | 	Uint64{0, 17}, | 
					
						
							|  |  |  | 	Uint64{0, 31}, | 
					
						
							|  |  |  | 	Uint64{0, 32}, | 
					
						
							|  |  |  | 	Uint64{0, 33}, | 
					
						
							|  |  |  | 	Uint64{0, 61}, | 
					
						
							|  |  |  | 	Uint64{0, 62}, | 
					
						
							|  |  |  | 	Uint64{0, 63}, | 
					
						
							|  |  |  | 	Uint64{0, 64}, | 
					
						
							|  |  |  | 	Uint64{0, 65}, | 
					
						
							|  |  |  | 	Uint64{0, 1<<32 - 1}, | 
					
						
							|  |  |  | 	Uint64{1, 0}, | 
					
						
							|  |  |  | 	Uint64{1, 1}, | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 	Uint64{1 << 28, 0}, | 
					
						
							|  |  |  | 	Uint64{1 << 31, 0}, | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	Uint64{1<<32 - 1, 0}, | 
					
						
							|  |  |  | 	Uint64{1<<32 - 1, 1<<32 - 1}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | var ntest = 0 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Part 1 is tests of variable operations; generic functions | 
					
						
							|  |  |  | // called by repetitive code.  Could make a table but not worth it. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | const prolog = "\n" + | 
					
						
							|  |  |  | 	"package main\n" + | 
					
						
							|  |  |  | 	"\n" + | 
					
						
							|  |  |  | 	"import \"os\"\n" + | 
					
						
							|  |  |  | 	"\n" + | 
					
						
							|  |  |  | 	"var ok = true\n" + | 
					
						
							|  |  |  | 	"\n" + | 
					
						
							|  |  |  | 	"func testInt64Unary(a, plus, xor, minus int64) {\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := +a, `+`, plus; n != want { ok=false; println(`int64`, op, a, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := ^a, `^`, xor; n != want { ok=false; println(`int64`, op, a, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := -a, `-`, minus; n != want { ok=false; println(`int64`, op, a, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"}\n" + | 
					
						
							|  |  |  | 	"\n" + | 
					
						
							|  |  |  | 	"func testInt64Binary(a, b, add, sub, mul, div, mod, and, or, xor, andnot int64, dodiv bool) {\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a + b, `+`, add; n != want { ok=false; println(`int64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a - b, `-`, sub; n != want { ok=false; println(`int64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a * b, `*`, mul; n != want { ok=false; println(`int64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if dodiv {\n" + | 
					
						
							|  |  |  | 	"		if n, op, want := a / b, `/`, div; n != want { ok=false; println(`int64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"		if n, op, want := a % b, `%`, mod; n != want { ok=false; println(`int64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	}\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a & b, `&`, and; n != want { ok=false; println(`int64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a | b, `|`, or; n != want { ok=false; println(`int64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a ^ b, `^`, xor; n != want { ok=false; println(`int64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a &^ b, `&^`, andnot; n != want { ok=false; println(`int64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"}\n" + | 
					
						
							|  |  |  | 	"\n" + | 
					
						
							|  |  |  | 	"func testInt64Shift(a int64, b uint64, left, right int64) {\n" + | 
					
						
							|  |  |  | 	"	if n, op, s, want := a << b, `<<`, b, left; n != want { ok=false; println(`int64`, a, op, `uint64`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, s, want := a >> b, `>>`, b, right; n != want { ok=false; println(`int64`, a, op, `uint64`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if uint64(uint(b)) == b {\n" + | 
					
						
							|  |  |  | 	"		b := uint(b);\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a << b, `<<`, b, left; n != want { ok=false; println(`int64`, a, op, `uint`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a >> b, `>>`, b, right; n != want { ok=false; println(`int64`, a, op, `uint`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	}\n" + | 
					
						
							|  |  |  | 	"	if uint64(uint32(b)) == b {\n" + | 
					
						
							|  |  |  | 	"		b := uint32(b);\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a << b, `<<`, b, left; n != want { ok=false; println(`int64`, a, op, `uint32`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a >> b, `>>`, b, right; n != want { ok=false; println(`int64`, a, op, `uint32`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	}\n" + | 
					
						
							|  |  |  | 	"	if uint64(uint16(b)) == b {\n" + | 
					
						
							|  |  |  | 	"		b := uint16(b);\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a << b, `<<`, b, left; n != want { ok=false; println(`int64`, a, op, `uint16`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a >> b, `>>`, b, right; n != want { ok=false; println(`int64`, a, op, `uint16`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	}\n" + | 
					
						
							|  |  |  | 	"	if uint64(uint8(b)) == b {\n" + | 
					
						
							|  |  |  | 	"		b := uint8(b);\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a << b, `<<`, b, left; n != want { ok=false; println(`int64`, a, op, `uint8`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a >> b, `>>`, b, right; n != want { ok=false; println(`int64`, a, op, `uint8`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	}\n" + | 
					
						
							|  |  |  | 	"}\n" + | 
					
						
							|  |  |  | 	"\n" + | 
					
						
							|  |  |  | 	"func testUint64Unary(a, plus, xor, minus uint64) {\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := +a, `+`, plus; n != want { ok=false; println(`uint64`, op, a, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := ^a, `^`, xor; n != want { ok=false; println(`uint64`, op, a, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := -a, `-`, minus; n != want { ok=false; println(`uint64`, op, a, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"}\n" + | 
					
						
							|  |  |  | 	"\n" + | 
					
						
							|  |  |  | 	"func testUint64Binary(a, b, add, sub, mul, div, mod, and, or, xor, andnot uint64, dodiv bool) {\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a + b, `+`, add; n != want { ok=false; println(`uint64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a - b, `-`, sub; n != want { ok=false; println(`uint64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a * b, `*`, mul; n != want { ok=false; println(`uint64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if dodiv {\n" + | 
					
						
							|  |  |  | 	"		if n, op, want := a / b, `/`, div; n != want { ok=false; println(`uint64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"		if n, op, want := a % b, `%`, mod; n != want { ok=false; println(`uint64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	}\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a & b, `&`, and; n != want { ok=false; println(`uint64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a | b, `|`, or; n != want { ok=false; println(`uint64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a ^ b, `^`, xor; n != want { ok=false; println(`uint64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a &^ b, `&^`, andnot; n != want { ok=false; println(`uint64`, a, op, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"}\n" + | 
					
						
							|  |  |  | 	"\n" + | 
					
						
							|  |  |  | 	"func testUint64Shift(a, b, left, right uint64) {\n" + | 
					
						
							|  |  |  | 	"	if n, op, s, want := a << b, `<<`, b, left; n != want { ok=false; println(`uint64`, a, op, `uint64`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, s, want := a >> b, `>>`, b, right; n != want { ok=false; println(`uint64`, a, op, `uint64`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if uint64(uint(b)) == b {\n" + | 
					
						
							|  |  |  | 	"		b := uint(b);\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a << b, `<<`, b, left; n != want { ok=false; println(`uint64`, a, op, `uint`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a >> b, `>>`, b, right; n != want { ok=false; println(`uint64`, a, op, `uint`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	}\n" + | 
					
						
							|  |  |  | 	"	if uint64(uint32(b)) == b {\n" + | 
					
						
							|  |  |  | 	"		b := uint32(b);\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a << b, `<<`, b, left; n != want { ok=false; println(`uint64`, a, op, `uint32`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a >> b, `>>`, b, right; n != want { ok=false; println(`uint64`, a, op, `uint32`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	}\n" + | 
					
						
							|  |  |  | 	"	if uint64(uint16(b)) == b {\n" + | 
					
						
							|  |  |  | 	"		b := uint16(b);\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a << b, `<<`, b, left; n != want { ok=false; println(`uint64`, a, op, `uint16`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a >> b, `>>`, b, right; n != want { ok=false; println(`uint64`, a, op, `uint16`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	}\n" + | 
					
						
							|  |  |  | 	"	if uint64(uint8(b)) == b {\n" + | 
					
						
							|  |  |  | 	"		b := uint8(b);\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a << b, `<<`, b, left; n != want { ok=false; println(`uint64`, a, op, `uint8`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a >> b, `>>`, b, right; n != want { ok=false; println(`uint64`, a, op, `uint8`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	}\n" + | 
					
						
							|  |  |  | 	"}\n" + | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	"\n" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func varTests() { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	fmt.Fprint(bout, prolog) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	for _, a := range int64Values { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		fmt.Fprintf(bout, "func test%v() {\n", ntest) | 
					
						
							|  |  |  | 		ntest++ | 
					
						
							|  |  |  | 		fmt.Fprintf(bout, "\ttestInt64Unary(%v, %v, %v, %v);\n", a, a, a.Com(), a.Neg()) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 		for _, b := range int64Values { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 			var div, mod Int64 | 
					
						
							|  |  |  | 			dodiv := false | 
					
						
							|  |  |  | 			var zero Int64 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 			if b.Cmp(zero) != 0 {	// b != 0 | 
					
						
							|  |  |  | 				// Can't divide by zero but also can't divide -0x8000...000 by -1. | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 				var bigneg = Int64{-0x80000000, 0} | 
					
						
							|  |  |  | 				var minus1 = Int64{-1, ^uint32(0)} | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 				if a.Cmp(bigneg) != 0 || b.Cmp(minus1) != 0 {	// a != -1<<63 || b != -1 | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 					div, mod = a.DivMod(b) | 
					
						
							|  |  |  | 					dodiv = true | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			fmt.Fprintf(bout, "\ttestInt64Binary(%v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v);\n", | 
					
						
							|  |  |  | 				a, b, a.Plus(b), a.Minus(b), a.Times(b), div, mod, | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 				a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		for _, b := range shiftValues { | 
					
						
							|  |  |  | 			fmt.Fprintf(bout, "\ttestInt64Shift(%v, %v, %v, %v);\n", | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 				a, b, a.LeftShift64(b), a.RightShift64(b)) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		fmt.Fprintf(bout, "}\n") | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for _, a := range uint64Values { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		fmt.Fprintf(bout, "func test%v() {\n", ntest) | 
					
						
							|  |  |  | 		ntest++ | 
					
						
							|  |  |  | 		fmt.Fprintf(bout, "\ttestUint64Unary(%v, %v, %v, %v);\n", a, a, a.Com(), a.Neg()) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 		for _, b := range uint64Values { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 			var div, mod Uint64 | 
					
						
							|  |  |  | 			dodiv := false | 
					
						
							|  |  |  | 			var zero Uint64 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 			if b.Cmp(zero) != 0 {	// b != 0 | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 				div, mod = a.DivMod(b) | 
					
						
							|  |  |  | 				dodiv = true | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			fmt.Fprintf(bout, "\ttestUint64Binary(%v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v);\n", | 
					
						
							|  |  |  | 				a, b, a.Plus(b), a.Minus(b), a.Times(b), div, mod, | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 				a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		for _, b := range shiftValues { | 
					
						
							|  |  |  | 			fmt.Fprintf(bout, "\ttestUint64Shift(%v, %v, %v, %v);\n", | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 				a, b, a.LeftShift64(b), a.RightShift64(b)) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		fmt.Fprintf(bout, "}\n") | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Part 2 is tests of operations involving one variable and one constant. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | const binaryConstL = "func test%vBinaryL%v(b, add, sub, mul, div, mod, and, or, xor, andnot %v, dodiv bool) {\n" + | 
					
						
							|  |  |  | 	"	const a %v = %v;\n" + | 
					
						
							|  |  |  | 	"	const typ = `%s`;\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a + b, `+`, add; n != want { ok=false; println(typ, `const`, a, op, `var`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a - b, `-`, sub; n != want { ok=false; println(typ, `const`, a, op, `var`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a * b, `*`, mul; n != want { ok=false; println(typ, `const`, a, op, `var`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if dodiv {\n" + | 
					
						
							|  |  |  | 	"		if n, op, want := a / b, `/`, div; n != want { ok=false; println(typ, `const`, a, op, `var`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"		if n, op, want := a %% b, `%%`, mod; n != want { ok=false; println(typ, `const`, a, op, `var`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	}\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a & b, `&`, and; n != want { ok=false; println(typ, `const`, a, op, `var`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a | b, `|`, or; n != want { ok=false; println(typ, `const`, a, op, `var`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a ^ b, `^`, xor; n != want { ok=false; println(typ, `const`, a, op, `var`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a &^ b, `&^`, andnot; n != want { ok=false; println(typ, `const`, a, op, `var`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"}\n" + | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	"\n" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | const binaryConstR = "func test%vBinaryR%v(a, add, sub, mul, div, mod, and, or, xor, andnot %v, dodiv bool) {\n" + | 
					
						
							|  |  |  | 	"	const b %v = %v;\n" + | 
					
						
							|  |  |  | 	"	const typ = `%s`;\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a + b, `+`, add; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a - b, `-`, sub; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a * b, `*`, mul; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if dodiv {\n" + | 
					
						
							|  |  |  | 	"		if n, op, want := a / b, `/`, div; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"		if n, op, want := a %% b, `%%`, mod; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	}\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a & b, `&`, and; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a | b, `|`, or; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a ^ b, `^`, xor; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a &^ b, `&^`, andnot; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"}\n" + | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	"\n" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-30 20:21:08 +01:00
										 |  |  | const binaryConstR0 = "func test%vBinaryR%v(a, add, sub, mul, div, mod, and, or, xor, andnot %v, dodiv bool) {\n" + | 
					
						
							|  |  |  | 	"	const b %v = %v;\n" + | 
					
						
							|  |  |  | 	"	const typ = `%s`;\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a + b, `+`, add; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a - b, `-`, sub; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a * b, `*`, mul; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a & b, `&`, and; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a | b, `|`, or; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a ^ b, `^`, xor; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, want := a &^ b, `&^`, andnot; n != want { ok=false; println(typ, `var`, a, op, `const`, b, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"}\n" + | 
					
						
							|  |  |  | 	"\n" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | const shiftConstL = "func test%vShiftL%v(b uint64, left, right %v) {\n" + | 
					
						
							|  |  |  | 	"	const a %v = %v;\n" + | 
					
						
							|  |  |  | 	"	const typ = `%s`;\n" + | 
					
						
							|  |  |  | 	"	if n, op, s, want := a << b, `<<`, b, left; n != want { ok=false; println(typ, `const`, a, op, `var`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, s, want := a >> b, `>>`, b, right; n != want { ok=false; println(typ, `const`, a, op, `var`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if uint64(uint32(b)) == b {\n" + | 
					
						
							|  |  |  | 	"		b := uint32(b);\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a << b, `<<`, b, left; n != want { ok=false; println(typ, `const`, a, op, `var`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a >> b, `>>`, b, right; n != want { ok=false; println(typ, `const`, a, op, `var`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	}\n" + | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	"}\n" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | const shiftConstR = "func test%vShiftR%v(a, left, right %v) {\n" + | 
					
						
							|  |  |  | 	"	const b uint64 = %v;\n" + | 
					
						
							|  |  |  | 	"	const typ = `%s`;\n" + | 
					
						
							|  |  |  | 	"	if n, op, s, want := a << b, `<<`, b, left; n != want { ok=false; println(typ, `var`, a, op, `const`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if n, op, s, want := a >> b, `>>`, b, right; n != want { ok=false; println(typ, `var`, a, op, `const`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	if b & 0xffffffff == b {\n" + | 
					
						
							|  |  |  | 	"		const b = uint32(b & 0xffffffff);\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a << b, `<<`, b, left; n != want { ok=false; println(typ, `var`, a, op, `const`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"		if n, op, s, want := a >> b, `>>`, b, right; n != want { ok=false; println(typ, `var`, a, op, `const`, s, `=`, n, `should be`, want); }\n" + | 
					
						
							|  |  |  | 	"	}\n" + | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	"}\n" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func constTests() { | 
					
						
							|  |  |  | 	for i, a := range int64Values { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		fmt.Fprintf(bout, binaryConstL, "Int64", i, "int64", "int64", a, "int64") | 
					
						
							| 
									
										
										
										
											2013-01-30 20:21:08 +01:00
										 |  |  | 		if a.hi == 0 && a.lo == 0 { | 
					
						
							|  |  |  | 			fmt.Fprintf(bout, binaryConstR0, "Int64", i, "int64", "int64", a, "int64") | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			fmt.Fprintf(bout, binaryConstR, "Int64", i, "int64", "int64", a, "int64") | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		fmt.Fprintf(bout, shiftConstL, "Int64", i, "int64", "int64", a, "int64") | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	for i, a := range uint64Values { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		fmt.Fprintf(bout, binaryConstL, "Uint64", i, "uint64", "uint64", a, "uint64") | 
					
						
							| 
									
										
										
										
											2013-01-30 20:21:08 +01:00
										 |  |  | 		if a.hi == 0 && a.lo == 0 { | 
					
						
							|  |  |  | 			fmt.Fprintf(bout, binaryConstR0, "Uint64", i, "uint64", "uint64", a, "uint64") | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			fmt.Fprintf(bout, binaryConstR, "Uint64", i, "uint64", "uint64", a, "uint64") | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		fmt.Fprintf(bout, shiftConstL, "Uint64", i, "uint64", "uint64", a, "uint64") | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	for i, a := range shiftValues { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		fmt.Fprintf(bout, shiftConstR, "Int64", i, "int64", a, "int64") | 
					
						
							|  |  |  | 		fmt.Fprintf(bout, shiftConstR, "Uint64", i, "uint64", a, "uint64") | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	for i, a := range int64Values { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		fmt.Fprintf(bout, "func test%v() {\n", ntest) | 
					
						
							|  |  |  | 		ntest++ | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 		for j, b := range int64Values { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 			var div, mod Int64 | 
					
						
							|  |  |  | 			dodiv := false | 
					
						
							|  |  |  | 			var zero Int64 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 			if b.Cmp(zero) != 0 {	// b != 0 | 
					
						
							|  |  |  | 				// Can't divide by zero but also can't divide -0x8000...000 by -1. | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 				var bigneg = Int64{-0x80000000, 0} | 
					
						
							|  |  |  | 				var minus1 = Int64{-1, ^uint32(0)} | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 				if a.Cmp(bigneg) != 0 || b.Cmp(minus1) != 0 {	// a != -1<<63 || b != -1 | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 					div, mod = a.DivMod(b) | 
					
						
							|  |  |  | 					dodiv = true | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			fmt.Fprintf(bout, "\ttestInt64BinaryL%v(%v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v);\n", | 
					
						
							|  |  |  | 				i, b, a.Plus(b), a.Minus(b), a.Times(b), div, mod, | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 				a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 			fmt.Fprintf(bout, "\ttestInt64BinaryR%v(%v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v);\n", | 
					
						
							|  |  |  | 				j, a, a.Plus(b), a.Minus(b), a.Times(b), div, mod, | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 				a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		for j, b := range shiftValues { | 
					
						
							|  |  |  | 			fmt.Fprintf(bout, "\ttestInt64ShiftL%v(%v, %v, %v);\n", | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 				i, b, a.LeftShift64(b), a.RightShift64(b)) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 			fmt.Fprintf(bout, "\ttestInt64ShiftR%v(%v, %v, %v);\n", | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 				j, a, a.LeftShift64(b), a.RightShift64(b)) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		fmt.Fprintf(bout, "}\n") | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	for i, a := range uint64Values { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		fmt.Fprintf(bout, "func test%v() {\n", ntest) | 
					
						
							|  |  |  | 		ntest++ | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 		for j, b := range uint64Values { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 			var div, mod Uint64 | 
					
						
							|  |  |  | 			dodiv := false | 
					
						
							|  |  |  | 			var zero Uint64 | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 			if b.Cmp(zero) != 0 {	// b != 0 | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 				div, mod = a.DivMod(b) | 
					
						
							|  |  |  | 				dodiv = true | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			fmt.Fprintf(bout, "\ttestUint64BinaryL%v(%v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v);\n", | 
					
						
							|  |  |  | 				i, b, a.Plus(b), a.Minus(b), a.Times(b), div, mod, | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 				a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 			fmt.Fprintf(bout, "\ttestUint64BinaryR%v(%v, %v, %v, %v, %v, %v, %v, %v, %v, %v, %v);\n", | 
					
						
							|  |  |  | 				j, a, a.Plus(b), a.Minus(b), a.Times(b), div, mod, | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 				a.And(b), a.Or(b), a.Xor(b), a.AndNot(b), dodiv) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		for j, b := range shiftValues { | 
					
						
							|  |  |  | 			fmt.Fprintf(bout, "\ttestUint64ShiftL%v(%v, %v, %v);\n", | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 				i, b, a.LeftShift64(b), a.RightShift64(b)) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 			fmt.Fprintf(bout, "\ttestUint64ShiftR%v(%v, %v, %v);\n", | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 				j, a, a.LeftShift64(b), a.RightShift64(b)) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 		fmt.Fprintf(bout, "}\n") | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func main() { | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	bout = bufio.NewWriter(os.Stdout) | 
					
						
							|  |  |  | 	varTests() | 
					
						
							|  |  |  | 	constTests() | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	fmt.Fprintf(bout, "func main() {\n") | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	for i := 0; i < ntest; i++ { | 
					
						
							| 
									
										
										
										
											2009-12-09 16:55:03 -08:00
										 |  |  | 		fmt.Fprintf(bout, "\ttest%v();\n", i) | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-09-04 10:36:13 +10:00
										 |  |  | 	fmt.Fprintf(bout, "\tif !ok { os.Exit(1) }\n") | 
					
						
							|  |  |  | 	fmt.Fprintf(bout, "}\n") | 
					
						
							|  |  |  | 	bout.Flush() | 
					
						
							| 
									
										
										
										
											2009-05-31 12:35:11 -07:00
										 |  |  | } |