Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: stdlib examples #3

Open
mmcloughlin opened this issue Feb 2, 2020 · 3 comments
Open

testing: stdlib examples #3

mmcloughlin opened this issue Feb 2, 2020 · 3 comments

Comments

@mmcloughlin
Copy link
Owner

The standard library has a lot of examples of this kind of thing. Perhaps use them for test cases?

Related #2

@mmcloughlin
Copy link
Owner Author

$ find . -name '*.go' | xargs grep -El '[0-9]+\^[0-9]+'
./cmd/asm/internal/asm/expr_test.go
./cmd/compile/internal/gc/testdata/arith_test.go
./cmd/compile/internal/gc/universe.go
./cmd/link/internal/ld/data.go
./cmd/link/linkbig_test.go
./crypto/elliptic/p256_asm.go
./crypto/elliptic/p256_s390x.go
./crypto/elliptic/p256.go
./crypto/rsa/pss.go
./crypto/cipher/example_test.go
./crypto/tls/ticket.go
./crypto/rand/rand_linux.go
./crypto/ed25519/internal/edwards25519/edwards25519.go
./strconv/atof_test.go
./strconv/extfloat.go
./strconv/decimal.go
./strconv/atof.go
./strings/strings_test.go
./net/textproto/pipeline.go
./net/http/h2_bundle.go
./regexp/all_test.go
./bytes/bytes_test.go
./hash/adler32/adler32.go
./hash/crc32/gen_const_ppc64le.go
./runtime/error.go
./runtime/profbuf.go
./runtime/sema.go
./runtime/softfloat64.go
./encoding/asn1/asn1_test.go
./math/big/example_test.go
./math/big/nat.go
./math/big/nat_test.go
./math/big/prime_test.go
./math/rand/rand.go
./math/atan.go
./vendor/golang.org/x/crypto/poly1305/sum_generic.go
./vendor/golang.org/x/crypto/curve25519/curve25519.go
./vendor/golang.org/x/crypto/curve25519/mont25519_amd64.go
./vendor/golang.org/x/net/http2/hpack/hpack.go

For example:

$ find . -name '*.go' | xargs grep -E '[0-9]+\^[0-9]+' | head -n 20
./cmd/asm/internal/asm/expr_test.go:	{"3^4", 3 ^ 4, true},
./cmd/compile/internal/gc/testdata/arith_test.go:	v4 := (v1 * v1) ^ v1 | v1 - v1 - v1&v1 ^ uint8(3+2) + v1*1>>0 - v1 | 1 | v1<<(2*3|0-0*0^1)
./cmd/compile/internal/gc/testdata/arith_test.go:	v11 := 2&1 ^ 0 + 3 | int(0^0)<<1>>(1*0*3) ^ 0*0 ^ 3&0*3&3 ^ 3*3 ^ 1 ^ int(2)<<(2*3) + 2 | 2 | 2 ^ 2 + 1 | 3 | 0 ^ int(1)>>1 ^ 2 // int
./cmd/compile/internal/gc/universe.go:	maxfltval[TFLOAT32].SetString("33554431p103") // 2^24-1 p (127-23) + 1/2 ulp
./cmd/compile/internal/gc/universe.go:	maxfltval[TFLOAT64].SetString("18014398509481983p970") // 2^53-1 p (1023-52) + 1/2 ulp
./cmd/link/internal/ld/data.go:const cutoff = 2e9 // 2 GB (or so; looks better in errors than 2^31)
./cmd/link/internal/ld/data.go:	// On ppc64x a text section should not be larger than 2^26 bytes due to the size of
./cmd/link/linkbig_test.go:	// which is 2^26.  When that happens the call requires special trampolines or
./crypto/elliptic/p256_asm.go:	// This code operates in the Montgomery domain where R = 2^256 mod n
./crypto/elliptic/p256_asm.go:// p256Mul operates in a Montgomery domain with R = 2^256 mod p, where p is the
./crypto/elliptic/p256_s390x.go:	// This code operates in the Montgomery domain where R = 2^256 mod n
./crypto/elliptic/p256_s390x.go:// p256MulAsm operates in a Montgomery domain with R = 2^256 mod p, where p is the
./crypto/elliptic/p256_s390x.go:			0x75, 0xba, 0x95, 0xfc, 0x5f, 0xed, 0xb6, 0x01, 0x79, 0xe7, 0x30, 0xd4, 0x18, 0xa9, 0x14, 0x3c}, //(p256.x*2^256)%p
./crypto/elliptic/p256_s390x.go:			0x8b, 0x4a, 0xb8, 0xe4, 0xba, 0x19, 0xe4, 0x5c, 0xdd, 0xf2, 0x53, 0x57, 0xce, 0x95, 0x56, 0x0a}, //(p256.y*2^256)%p
./crypto/elliptic/p256_s390x.go:			0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, //(p256.z*2^256)%p
./crypto/elliptic/p256.go:	p256Square(&ftmp, in)     // 2^1
./crypto/elliptic/p256.go:	p256Mul(&ftmp, in, &ftmp) // 2^2 - 2^0
./crypto/elliptic/p256.go:	p256Square(&ftmp, &ftmp)   // 2^3 - 2^1
./crypto/elliptic/p256.go:	p256Square(&ftmp, &ftmp)   // 2^4 - 2^2
./crypto/elliptic/p256.go:	p256Mul(&ftmp, &ftmp, &e2) // 2^4 - 2^0

@mmcloughlin
Copy link
Owner Author

$ find . -name '*.go' | xargs grep -Ec '\/\/.+[0-9]+\^[0-9]+' | awk -F: '$2 > 0 {print $2, $1}' | sort -nr | head
59 ./vendor/golang.org/x/crypto/curve25519/curve25519.go
50 ./crypto/ed25519/internal/edwards25519/edwards25519.go
45 ./strconv/extfloat.go
31 ./crypto/elliptic/p256.go
9 ./net/http/h2_bundle.go
6 ./strconv/atof.go
5 ./math/big/prime_test.go
5 ./crypto/elliptic/p256_s390x.go
4 ./math/big/nat.go
3 ./runtime/sema.go

mmcloughlin added a commit that referenced this issue Feb 4, 2020
This was referenced Feb 5, 2020
mmcloughlin added a commit that referenced this issue Feb 5, 2020
Running mathfmt over x/crypto revealed a bunch of problematic cases. This PR reimplements formula processing with regular expressions, enabling more complex logic to be easily expressed. Overall this greatly simplified everything -- I wish I'd done it this way at first!

Updates #3 #9
mmcloughlin added a commit that referenced this issue Feb 5, 2020
Makes changes as a result of running over the standard library. Changes
some aliases to less common sequences. Adds test cases.

Updates #3 #9
@mmcloughlin
Copy link
Owner Author

probablyPrimeLucas in math/big/prime.go is another excellent example of where mathfmt could be used.

https://github.com/golang/go/blob/bfaf11c158b5ccd7db3c43727357b8b1071d7fde/src/math/big/prime.go#L126-L320

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant