328 {
329
330 const uint64_t F4 = 331804471;
331 const uint64_t G4 = 593549882;
332
333
334
335 uint32_t s = (((uint64_t)
x + (uint64_t)
y + (uint64_t)
z + (uint64_t)w) * F4) >> 32;
336 uint32_t i = ((
x>>2) + s) >> 10;
337 uint32_t j = ((
y>>2) + s) >> 10;
338 uint32_t k = ((
z>>2) + s) >> 10;
339 uint32_t l = ((w>>2) + s) >> 10;
340
341 uint64_t
t = (((uint64_t)i + (uint64_t)j + (uint64_t)k + (uint64_t)l) * G4) >> 18;
342 uint64_t X0 = ((uint64_t)i<<14) -
t;
343 uint64_t Y0 = ((uint64_t)j<<14) -
t;
344 uint64_t Z0 = ((uint64_t)k<<14) -
t;
345 uint64_t
W0 = ((uint64_t)l<<14) -
t;
346 int32_t x0 = ((uint64_t)
x<<2) - X0;
347 int32_t y0 = ((uint64_t)
y<<2) - Y0;
348 int32_t z0 = ((uint64_t)
z<<2) - Z0;
349 int32_t w0 = ((uint64_t)w<<2) -
W0;
350
351
352
353
354
355
356
357
358
359 int c = 0;
360 if (x0 > y0) {
361 c += 32;
362 }
363 if (x0 > z0) {
364 c += 16;
365 }
366 if (y0 > z0) {
367 c += 8;
368 }
369 if (x0 > w0) {
370 c += 4;
371 }
372 if (y0 > w0) {
373 c += 2;
374 }
375 if (z0 > w0) {
376 c += 1;
377 }
378
379
380
381
382
383
384
389
390
395
396
401
402
403 int32_t x1 = x0 - ((int32_t)i1<<14) + (int32_t)(G4>>18);
404 int32_t y1 = y0 - ((int32_t)j1<<14) + (int32_t)(G4>>18);
405 int32_t z1 = z0 - ((int32_t)k1<<14) + (int32_t)(G4>>18);
406 int32_t w1 = w0 - ((int32_t)l1<<14) + (int32_t)(G4>>18);
407 int32_t x2 = x0 - ((int32_t)i2<<14) + (int32_t)(2*G4>>18);
408 int32_t y2 = y0 - ((int32_t)j2<<14) + (int32_t)(2*G4>>18);
409 int32_t z2 = z0 - ((int32_t)k2<<14) + (int32_t)(2*G4>>18);
410 int32_t w2 = w0 - ((int32_t)l2<<14) + (int32_t)(2*G4>>18);
411 int32_t x3 = x0 - ((int32_t)i3<<14) + (int32_t)(3*G4>>18);
412 int32_t y3 = y0 - ((int32_t)j3<<14) + (int32_t)(3*G4>>18);
413 int32_t z3 = z0 - ((int32_t)k3<<14) + (int32_t)(3*G4>>18);
414 int32_t w3 = w0 - ((int32_t)l3<<14) + (int32_t)(3*G4>>18);
415 int32_t x4 = x0 - (1 << 14) + (int32_t)(4*G4>>18);
416 int32_t y4 = y0 - (1 << 14) + (int32_t)(4*G4>>18);
417 int32_t z4 = z0 - (1 << 14) + (int32_t)(4*G4>>18);
418 int32_t w4 = w0 - (1 << 14) + (int32_t)(4*G4>>18);
419
420 int32_t n0 = 0, n1 = 0, n2 = 0, n3 = 0, n4 = 0;
421 const int32_t fix0_6 = 161061274;
422
423
424 int32_t t0 = (fix0_6 - x0*x0 - y0*y0 - z0*z0 - w0*w0) >> 12;
425 if (t0 > 0) {
426 t0 = (t0 * t0) >> 16;
427 t0 = (t0 * t0) >> 16;
428
430 }
431
432 int32_t t1 = (fix0_6 - x1*x1 - y1*y1 - z1*z1 - w1*w1) >> 12;
433 if (t1 > 0) {
434 t1 = (t1 * t1) >> 16;
435 t1 = (t1 * t1) >> 16;
436
438 }
439
440 int32_t t2 = (fix0_6 - x2*x2 - y2*y2 - z2*z2 - w2*w2) >> 12;
441 if (t2 > 0) {
442 t2 = (t2 * t2) >> 16;
443 t2 = (t2 * t2) >> 16;
444
446 }
447
448 int32_t t3 = (fix0_6 - x3*x3 - y3*y3 - z3*z3 - w3*w3) >> 12;
449 if (t3 > 0) {
450 t3 = (t3 * t3) >> 16;
451 t3 = (t3 * t3) >> 16;
452
454 }
455
456 int32_t t4 = (fix0_6 - x4*x4 - y4*y4 - z4*z4 - w4*w4) >> 12;
457 if (t4 > 0) {
458 t4 = (t4 * t4) >> 16;
459 t4 = (t4 * t4) >> 16;
460
462 }
463
464 int32_t n = n0 + n1 + n2 + n3 + n4;
465 n = ((n >> 8) * 13832) >> 16;
466 return uint16_t(n) + 0x8000;
467}
static uint8_t const simplex[64][4]
static int32_t grad(uint8_t hash, int32_t x)