129 {
130 const uint64_t F2 = 1572067135;
131 const uint64_t G2 = 907633384;
132
133
134 uint32_t s = (((uint64_t)
x + (uint64_t)
y) * F2) >> 32;
135 uint32_t i = ((
x>>1) + (s>>1)) >> 11;
136 uint32_t j = ((
y>>1) + (s>>1)) >> 11;
137
138 uint64_t
t = ((uint64_t)i + (uint64_t)j) * G2;
139 uint64_t X0 = ((uint64_t)i<<32) -
t;
140 uint64_t Y0 = ((uint64_t)j<<32) -
t;
141 int32_t x0 = ((uint64_t)
x<<2) - (X0>>18);
142 int32_t y0 = ((uint64_t)
y<<2) - (Y0>>18);
143
144
145
146 uint32_t i1, j1;
147 if (x0 > y0) {
148 i1 = 1;
149 j1 = 0;
150 } else {
151 i1 = 0;
152 j1 = 1;
153 }
154
155
156
157
158
159 int32_t x1 = x0 - ((int32_t)i1<<14) + (int32_t)(G2>>18);
160 int32_t y1 = y0 - ((int32_t)j1<<14) + (int32_t)(G2>>18);
161 int32_t x2 = x0 - (1 << 14) + ((int32_t)(2*G2)>>18);
162 int32_t y2 = y0 - (1 << 14) + ((int32_t)(2*G2)>>18);
163
164 int32_t n0 = 0, n1 = 0, n2 = 0;
165
166
167 int32_t t0 = (((int32_t)1 << 27) - x0*x0 - y0*y0) >> 12;
168 if (t0 > 0) {
169 t0 = (t0 * t0) >> 16;
170 t0 = (t0 * t0) >> 16;
172 }
173
174 int32_t t1 = (((int32_t)1 << 27) - x1*x1 - y1*y1) >> 12;
175 if (t1 > 0) {
176 t1 = (t1 * t1) >> 16;
177 t1 = (t1 * t1) >> 16;
179 }
180
181 int32_t t2 = (((int32_t)1 << 27) - x2*x2 - y2*y2) >> 12;
182 if (t2 > 0) {
183 t2 = (t2 * t2) >> 16;
184 t2 = (t2 * t2) >> 16;
186 }
187
188
189
190 int32_t n = n0 + n1 + n2;
191 n = ((n >> 8) * 23163) >> 16;
192 return (uint16_t)n + 0x8000;
193}
static int32_t grad(uint8_t hash, int32_t x)