3 // Copyright 2012 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Various tests for expressions with high complexity.
11 // Concatenate 16 4-bit integers into a 64-bit number.
12 func concat(s *[16]byte) uint64 {
13 r := (((((((((((((((uint64(s[0])<<4|
32 // Compute the determinant of a 4x4-matrix by the sum
33 // over all index permutations.
34 func determinant(m [4][4]float64) float64 {
35 return m[0][0]*m[1][1]*m[2][2]*m[3][3] -
36 m[0][0]*m[1][1]*m[2][3]*m[3][2] -
37 m[0][0]*m[1][2]*m[2][1]*m[3][3] +
38 m[0][0]*m[1][2]*m[2][3]*m[3][1] +
39 m[0][0]*m[1][3]*m[2][1]*m[3][2] -
40 m[0][0]*m[1][3]*m[2][2]*m[3][1] -
41 m[0][1]*m[1][0]*m[2][2]*m[3][3] +
42 m[0][1]*m[1][0]*m[2][3]*m[3][2] +
43 m[0][1]*m[1][2]*m[2][0]*m[3][3] -
44 m[0][1]*m[1][2]*m[2][3]*m[3][0] -
45 m[0][1]*m[1][3]*m[2][0]*m[3][2] +
46 m[0][1]*m[1][3]*m[2][2]*m[3][0] +
47 m[0][2]*m[1][0]*m[2][1]*m[3][3] -
48 m[0][2]*m[1][0]*m[2][3]*m[3][1] -
49 m[0][2]*m[1][1]*m[2][0]*m[3][3] +
50 m[0][2]*m[1][1]*m[2][3]*m[3][0] +
51 m[0][2]*m[1][3]*m[2][0]*m[3][1] -
52 m[0][2]*m[1][3]*m[2][1]*m[3][0] -
53 m[0][3]*m[1][0]*m[2][1]*m[3][2] +
54 m[0][3]*m[1][0]*m[2][2]*m[3][1] +
55 m[0][3]*m[1][1]*m[2][0]*m[3][2] -
56 m[0][3]*m[1][1]*m[2][2]*m[3][0] -
57 m[0][3]*m[1][2]*m[2][0]*m[3][1] +
58 m[0][3]*m[1][2]*m[2][1]*m[3][0]
61 // Compute the determinant of a 4x4-matrix by the sum
62 // over all index permutations.
63 func determinantInt(m [4][4]int) int {
64 return m[0][0]*m[1][1]*m[2][2]*m[3][3] -
65 m[0][0]*m[1][1]*m[2][3]*m[3][2] -
66 m[0][0]*m[1][2]*m[2][1]*m[3][3] +
67 m[0][0]*m[1][2]*m[2][3]*m[3][1] +
68 m[0][0]*m[1][3]*m[2][1]*m[3][2] -
69 m[0][0]*m[1][3]*m[2][2]*m[3][1] -
70 m[0][1]*m[1][0]*m[2][2]*m[3][3] +
71 m[0][1]*m[1][0]*m[2][3]*m[3][2] +
72 m[0][1]*m[1][2]*m[2][0]*m[3][3] -
73 m[0][1]*m[1][2]*m[2][3]*m[3][0] -
74 m[0][1]*m[1][3]*m[2][0]*m[3][2] +
75 m[0][1]*m[1][3]*m[2][2]*m[3][0] +
76 m[0][2]*m[1][0]*m[2][1]*m[3][3] -
77 m[0][2]*m[1][0]*m[2][3]*m[3][1] -
78 m[0][2]*m[1][1]*m[2][0]*m[3][3] +
79 m[0][2]*m[1][1]*m[2][3]*m[3][0] +
80 m[0][2]*m[1][3]*m[2][0]*m[3][1] -
81 m[0][2]*m[1][3]*m[2][1]*m[3][0] -
82 m[0][3]*m[1][0]*m[2][1]*m[3][2] +
83 m[0][3]*m[1][0]*m[2][2]*m[3][1] +
84 m[0][3]*m[1][1]*m[2][0]*m[3][2] -
85 m[0][3]*m[1][1]*m[2][2]*m[3][0] -
86 m[0][3]*m[1][2]*m[2][0]*m[3][1] +
87 m[0][3]*m[1][2]*m[2][1]*m[3][0]
90 // Compute the determinant of a 4x4-matrix by the sum
91 // over all index permutations.
92 func determinantByte(m [4][4]byte) byte {
93 return m[0][0]*m[1][1]*m[2][2]*m[3][3] -
94 m[0][0]*m[1][1]*m[2][3]*m[3][2] -
95 m[0][0]*m[1][2]*m[2][1]*m[3][3] +
96 m[0][0]*m[1][2]*m[2][3]*m[3][1] +
97 m[0][0]*m[1][3]*m[2][1]*m[3][2] -
98 m[0][0]*m[1][3]*m[2][2]*m[3][1] -
99 m[0][1]*m[1][0]*m[2][2]*m[3][3] +
100 m[0][1]*m[1][0]*m[2][3]*m[3][2] +
101 m[0][1]*m[1][2]*m[2][0]*m[3][3] -
102 m[0][1]*m[1][2]*m[2][3]*m[3][0] -
103 m[0][1]*m[1][3]*m[2][0]*m[3][2] +
104 m[0][1]*m[1][3]*m[2][2]*m[3][0] +
105 m[0][2]*m[1][0]*m[2][1]*m[3][3] -
106 m[0][2]*m[1][0]*m[2][3]*m[3][1] -
107 m[0][2]*m[1][1]*m[2][0]*m[3][3] +
108 m[0][2]*m[1][1]*m[2][3]*m[3][0] +
109 m[0][2]*m[1][3]*m[2][0]*m[3][1] -
110 m[0][2]*m[1][3]*m[2][1]*m[3][0] -
111 m[0][3]*m[1][0]*m[2][1]*m[3][2] +
112 m[0][3]*m[1][0]*m[2][2]*m[3][1] +
113 m[0][3]*m[1][1]*m[2][0]*m[3][2] -
114 m[0][3]*m[1][1]*m[2][2]*m[3][0] -
115 m[0][3]*m[1][2]*m[2][0]*m[3][1] +
116 m[0][3]*m[1][2]*m[2][1]*m[3][0]
121 // A sequence of constant indexings.
122 func IndexChain1(s A) A {
123 return s[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0]
126 // A sequence of non-constant indexings.
127 func IndexChain2(s A, i int) A {
128 return s[i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i]
131 // Another sequence of indexings.
132 func IndexChain3(s []int) int {
133 return s[s[s[s[s[s[s[s[s[s[s[s[s[s[s[s[s[s[s[s[s[0]]]]]]]]]]]]]]]]]]]]]
136 // A right-leaning tree of byte multiplications.
137 func righttree(a, b, c, d uint8) uint8 {
138 return a * (b * (c * (d *
143 a * (b * (c * d)))))))))))))))))))))
147 // A left-leaning tree of byte multiplications.
148 func lefttree(a, b, c, d uint8) uint8 {
149 return ((((((((((((((((((a * b) * c) * d *
163 // A chains of type assertions.
164 func ChainT(t *T) *T {
192 func (u *U) Child(n int) J { return u.Children[n] }
198 func ChainUAssert(u *U) *U {
199 return u.Child(0).(*U).
223 func ChainUNoAssert(u *U) *U {
248 // Type assertions and slice indexing. See issue 4207.
249 func ChainAssertIndex(u *U) J {
271 func (u *UArr) Child(n int) J { return u.Children[n] }
273 func ChainAssertArrayIndex(u *UArr) J {
291 type UArrPtr struct {
295 func (u *UArrPtr) Child(n int) J { return u.Children[n] }
297 func ChainAssertArrayptrIndex(u *UArrPtr) J {
299 Children[0].(*UArrPtr).
300 Children[0].(*UArrPtr).
301 Children[0].(*UArrPtr).
302 Children[0].(*UArrPtr).
303 Children[0].(*UArrPtr).
304 Children[0].(*UArrPtr).
305 Children[0].(*UArrPtr).
306 Children[0].(*UArrPtr).
307 Children[0].(*UArrPtr).
308 Children[0].(*UArrPtr).
309 Children[0].(*UArrPtr).
310 Children[0].(*UArrPtr).
311 Children[0].(*UArrPtr).
315 // Chains of divisions. See issue 4201.
317 func ChainDiv(a, b int) int {
318 return a / b / a / b / a / b / a / b /
319 a / b / a / b / a / b / a / b /
320 a / b / a / b / a / b / a / b
323 func ChainDivRight(a, b int) int {
324 return a / (b / (a / (b /
328 (a / (b / (a / b))))))))))))))))))
331 func ChainDivConst(a int) int {
332 return a / 17 / 17 / 17 /
337 func ChainMulBytes(a, b, c byte) byte {
338 return a*(a*(a*(a*(a*(a*(a*(a*(a*b+c)+c)+c)+c)+c)+c)+c)+c) + c
343 case <-make(chan int, cap(make(chan int, cap(make(chan int, cap(make(chan int, cap(make(chan int))))))))):