Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
points.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2010-2020 darktable developers.
4
5 darktable is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 darktable is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with darktable. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#pragma once
20
21#ifndef __SSE2__
22
23#if !defined _XOPEN_SOURCE && !defined(__DragonFly__) && !defined(__FreeBSD__) && !defined(__NetBSD__) \
24 && !defined(__OpenBSD__) && !defined(_WIN32)
25#define _XOPEN_SOURCE
26#endif
27
28#include <stdlib.h>
29
30// xorshift128+, period 2^128-1, apparently passes all TestU01 suite tests.
36
41
42static inline void dt_points_init(dt_points_t *p, const unsigned int num_threads)
43{
44 p->s = (dt_points_state_t *)malloc(sizeof(dt_points_state_t) * num_threads);
45 for(int k = 0; k < num_threads; k++)
46 {
47 p->s[k].state0 = 1 + k;
48 p->s[k].state1 = 2 + k;
49 }
50}
51
52static inline void dt_points_cleanup(dt_points_t *p)
53{
54 free(p->s);
55}
56
57static inline float dt_points_get_for(dt_points_t *p, const unsigned int thread_num)
58{
59 uint64_t s1 = p->s[thread_num].state0;
60 uint64_t s0 = p->s[thread_num].state1;
61 p->s[thread_num].state0 = s0;
62 s1 ^= s1 << 23;
63 s1 ^= s1 >> 17;
64 s1 ^= s0;
65 s1 ^= s0 >> 26;
66 p->s[thread_num].state1 = s1;
67 // return (state0 + state1) / ((double)((uint64_t)-1) + 1.0);
68 union {
69 float f;
70 uint32_t u;
71 } v;
72 v.u = 0x3f800000 |
73 ((p->s[thread_num].state0 + p->s[thread_num].state1) >> 41); // faster than double version.
74 return v.f - 1.0f;
75}
76
77static inline float dt_points_get()
78{
80}
81
82#else
83
84#if defined(__SSE__)
85#include <xmmintrin.h>
86#endif
87#include <inttypes.h>
88
89#define MEXP 19937
90
91#ifndef SFMT_PARAMS_H
92#define SFMT_PARAMS_H
93
94#if !defined(MEXP)
95#ifdef __GNUC__
96#warning "MEXP is not defined. I assume MEXP is 19937."
97#endif
98#define MEXP 19937
99#endif
100/*-----------------
101 BASIC DEFINITIONS
102 -----------------*/
108#define N (MEXP / 128 + 1)
111#define N32 (N * 4)
114#define N64 (N * 2)
115
116/*----------------------
117 the parameters of SFMT
118 following definitions are in paramsXXXX.h file.
119 ----------------------*/
157#if 0
158#if MEXP == 607
159#include "SFMT-params607.h"
160#elif MEXP == 1279
161#include "SFMT-params1279.h"
162#elif MEXP == 2281
163#include "SFMT-params2281.h"
164#elif MEXP == 4253
165#include "SFMT-params4253.h"
166#elif MEXP == 11213
167#include "SFMT-params11213.h"
168#elif MEXP == 19937
169#include "SFMT-params19937.h"
170#elif MEXP == 44497
171#include "SFMT-params44497.h"
172#elif MEXP == 86243
173#include "SFMT-params86243.h"
174#elif MEXP == 132049
175#include "SFMT-params132049.h"
176#elif MEXP == 216091
177#include "SFMT-params216091.h"
178#else
179#ifdef __GNUC__
180#error "MEXP is not valid."
181#undef MEXP
182#else
183#undef MEXP
184#endif
185#endif
186
187#endif
188
189#endif /* SFMT_PARAMS_H */
190
191#ifndef SFMT_PARAMS19937_H
192#define SFMT_PARAMS19937_H
193
194#define POS1 122
195#define SL1 18
196#define SL2 1
197#define SR1 11
198#define SR2 1
199#define MSK1 0xdfffffefU
200#define MSK2 0xddfecb7fU
201#define MSK3 0xbffaffffU
202#define MSK4 0xbffffff6U
203#define PARITY1 0x00000001U
204#define PARITY2 0x00000000U
205#define PARITY3 0x00000000U
206#define PARITY4 0x13c9e684U
207
208
209#define ALTI_SL1 \
210 { \
211 SL1, SL1, SL1, SL1 \
212 }
213#define ALTI_SR1 \
214 { \
215 SR1, SR1, SR1, SR1 \
216 }
217#define ALTI_MSK \
218 { \
219 MSK1, MSK2, MSK3, MSK4 \
220 }
221#define ALTI_MSK64 \
222 { \
223 MSK2, MSK1, MSK4, MSK3 \
224 }
225#define ALTI_SL2_PERM \
226 { \
227 1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, 8 \
228 }
229#define ALTI_SL2_PERM64 \
230 { \
231 1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, 13, 14, 15, 0 \
232 }
233#define ALTI_SR2_PERM \
234 { \
235 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, 17, 12, 13, 14 \
236 }
237#define ALTI_SR2_PERM64 \
238 { \
239 15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, 11, 12, 13, 14 \
240 }
241#define IDSTR "SFMT-19937:122-18-1-11-1:dfffffef-ddfecb7f-bffaffff-bffffff6"
242
243#endif /* SFMT_PARAMS19937_H */
244
246typedef union w128_t
247{
248 __m128i si;
249 uint32_t u[4];
250} w128_t;
251
252typedef struct sfmt_state_t
253{
255 w128_t sfmt[N];
257 uint32_t *psfmt32;
258#if !defined(BIG_ENDIAN64) || defined(ONLY64)
260 uint64_t *psfmt64;
261#endif
263 int idx;
266 int initialized;
268 uint32_t parity[4];
269} sfmt_state_t;
270
301#ifndef SFMT_H
302#define SFMT_H
303
304#include <stdio.h>
305
306#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
307#include <inttypes.h>
308#elif defined(_MSC_VER) || defined(__BORLANDC__)
309typedef unsigned int uint32_t;
310typedef unsigned __int64 uint64_t;
311#define inline __inline
312#else
313#include <inttypes.h>
314#if defined(__GNUC__)
315#define inline __inline__
316#endif
317#endif
318
319#ifndef PRIu64
320#if defined(_MSC_VER) || defined(__BORLANDC__)
321#define PRIu64 "I64u"
322#define PRIx64 "I64x"
323#else
324#define PRIu64 "llu"
325#define PRIx64 "llx"
326#endif
327#endif
328
329#if defined(__GNUC__)
330#define ALWAYSINLINE __attribute__((always_inline))
331#else
332#define ALWAYSINLINE
333#endif
334
335#if defined(_MSC_VER)
336#if _MSC_VER >= 1200
337#define PRE_ALWAYS __forceinline
338#else
339#define PRE_ALWAYS inline
340#endif
341#else
342#define PRE_ALWAYS inline
343#endif
344
345static inline uint32_t gen_rand32(struct sfmt_state_t *s);
346static inline uint64_t gen_rand64(struct sfmt_state_t *s);
347static inline void init_gen_rand(struct sfmt_state_t *s, uint32_t seed) __attribute__((unused));
348static inline void init_by_array(struct sfmt_state_t *s, uint32_t *init_key, int key_length)
349 __attribute__((unused));
350static inline const char *get_idstring(void) __attribute__((unused));
352inline static float to_real2f(uint32_t v)
353{
354 union {
355 float f;
356 uint32_t u;
357 } x;
358 x.u = 0x3f800000 | (v >> 9); // faster than double version.
359 return x.f - 1.0f;
360 /* divided by 2^32 */
361}
362inline static float genrand_real2f(struct sfmt_state_t *s)
363{
364 return to_real2f(gen_rand32(s));
365}
366
367#endif
383#ifndef SFMT_SSE2_H
384#define SFMT_SSE2_H
385
386PRE_ALWAYS static __m128i mm_recursion(__m128i *a, __m128i *b, __m128i c, __m128i d,
387 __m128i mask) ALWAYSINLINE;
388
398PRE_ALWAYS static __m128i mm_recursion(__m128i *a, __m128i *b, __m128i c, __m128i d, __m128i mask)
399{
400 __m128i v, x, y, z;
401
402 x = _mm_load_si128(a);
403 y = _mm_srli_epi32(*b, SR1);
404 z = _mm_srli_si128(c, SR2);
405 v = _mm_slli_epi32(d, SL1);
406 z = _mm_xor_si128(z, x);
407 z = _mm_xor_si128(z, v);
408 x = _mm_slli_si128(x, SL2);
409 y = _mm_and_si128(y, mask);
410 z = _mm_xor_si128(z, x);
411 z = _mm_xor_si128(z, y);
412 return z;
413}
414
419inline static void gen_rand_all(struct sfmt_state_t *s)
420{
421 int i;
422 __m128i r, r1, r2, mask;
423 mask = _mm_set_epi32(MSK4, MSK3, MSK2, MSK1);
424
425 r1 = _mm_load_si128(&(s->sfmt[N - 2].si));
426 r2 = _mm_load_si128(&(s->sfmt[N - 1].si));
427 for(i = 0; i < N - POS1; i++)
428 {
429 r = mm_recursion(&(s->sfmt[i].si), &(s->sfmt[i + POS1].si), r1, r2, mask);
430 _mm_store_si128(&(s->sfmt[i].si), r);
431 r1 = r2;
432 r2 = r;
433 }
434 for(; i < N; i++)
435 {
436 r = mm_recursion(&(s->sfmt[i].si), &(s->sfmt[i + POS1 - N].si), r1, r2, mask);
437 _mm_store_si128(&(s->sfmt[i].si), r);
438 r1 = r2;
439 r2 = r;
440 }
441}
442
450inline static void gen_rand_array(struct sfmt_state_t *s, w128_t *array, int size)
451{
452 int i, j;
453 __m128i r, r1, r2, mask;
454 mask = _mm_set_epi32(MSK4, MSK3, MSK2, MSK1);
455
456 r1 = _mm_load_si128(&(s->sfmt[N - 2].si));
457 r2 = _mm_load_si128(&(s->sfmt[N - 1].si));
458 for(i = 0; i < N - POS1; i++)
459 {
460 r = mm_recursion(&(s->sfmt[i].si), &(s->sfmt[i + POS1].si), r1, r2, mask);
461 _mm_store_si128(&array[i].si, r);
462 r1 = r2;
463 r2 = r;
464 }
465 for(; i < N; i++)
466 {
467 r = mm_recursion(&(s->sfmt[i].si), &array[i + POS1 - N].si, r1, r2, mask);
468 _mm_store_si128(&array[i].si, r);
469 r1 = r2;
470 r2 = r;
471 }
472 /* main loop */
473 for(; i < size - N; i++)
474 {
475 r = mm_recursion(&array[i - N].si, &array[i + POS1 - N].si, r1, r2, mask);
476 _mm_store_si128(&array[i].si, r);
477 r1 = r2;
478 r2 = r;
479 }
480 for(j = 0; j < 2 * N - size; j++)
481 {
482 r = _mm_load_si128(&array[j + size - N].si);
483 _mm_store_si128(&(s->sfmt[j].si), r);
484 }
485 for(; i < size; i++)
486 {
487 r = mm_recursion(&array[i - N].si, &array[i + POS1 - N].si, r1, r2, mask);
488 _mm_store_si128(&array[i].si, r);
489 _mm_store_si128(&(s->sfmt[j++].si), r);
490 r1 = r2;
491 r2 = r;
492 }
493}
494
495#endif
508#include <assert.h>
509#include <string.h>
510//#include "SFMT.h"
511//#include "SFMT-params.h"
512
513#if defined(__BIG_ENDIAN__) && !defined(__amd64) && !defined(BIG_ENDIAN64)
514#define BIG_ENDIAN64 1
515#endif
516#if defined(HAVE_ALTIVEC) && !defined(BIG_ENDIAN64)
517#define BIG_ENDIAN64 1
518#endif
519#if defined(ONLY64) && !defined(BIG_ENDIAN64)
520#if defined(__GNUC__)
521#error "-DONLY64 must be specified with -DBIG_ENDIAN64"
522#endif
523#undef ONLY64
524#endif
525
526
527typedef struct dt_points_t
528{
529 sfmt_state_t **s;
530 unsigned int num;
532
533#if 0
534/*--------------------------------------
535 FILE GLOBAL VARIABLES
536 internal state, index counter and flag
537 --------------------------------------*/
539static w128_t sfmt[N];
541static uint32_t *psfmt32 = &sfmt[0].u[0];
542#if !defined(BIG_ENDIAN64) || defined(ONLY64)
544static uint64_t *psfmt64 = (uint64_t *)&sfmt[0].u[0];
545#endif
547static int idx;
550static int initialized = 0;
552static uint32_t parity[4] = {PARITY1, PARITY2, PARITY3, PARITY4};
553#endif
554
555/*----------------
556 STATIC FUNCTIONS
557 ----------------*/
558inline static int idxof(int i);
559inline static void rshift128(w128_t *out, w128_t const *in, int shift);
560inline static void lshift128(w128_t *out, w128_t const *in, int shift);
561inline static void gen_rand_all(sfmt_state_t *s);
562inline static void gen_rand_array(sfmt_state_t *s, w128_t *array, int size);
563inline static uint32_t func1(uint32_t x);
564inline static uint32_t func2(uint32_t x);
565static void period_certification(sfmt_state_t *s);
566#if defined(BIG_ENDIAN64) && !defined(ONLY64)
567inline static void swap(w128_t *array, int size);
568#endif
569
570/*#if defined(HAVE_ALTIVEC)
571#include "SFMT-alti.h"
572#elif defined(HAVE_SSE2)
573#include "SFMT-sse2.h"
574#endif*/
575
580#ifdef ONLY64
581inline static int idxof(int i)
582{
583 return i ^ 1;
584}
585#else
586inline static int idxof(int i)
587{
588 return i;
589}
590#endif
599#ifdef ONLY64
600inline static void rshift128(w128_t *out, w128_t const *in, int shift)
601{
602 uint64_t th, tl, oh, ol;
603
604 th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
605 tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
606
607 oh = th >> (shift * 8);
608 ol = tl >> (shift * 8);
609 ol |= th << (64 - shift * 8);
610 out->u[0] = (uint32_t)(ol >> 32);
611 out->u[1] = (uint32_t)ol;
612 out->u[2] = (uint32_t)(oh >> 32);
613 out->u[3] = (uint32_t)oh;
614}
615#else
616inline static void rshift128(w128_t *out, w128_t const *in, int shift)
617{
618 uint64_t th, tl, oh, ol;
619
620 th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
621 tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
622
623 oh = th >> (shift * 8);
624 ol = tl >> (shift * 8);
625 ol |= th << (64 - shift * 8);
626 out->u[1] = (uint32_t)(ol >> 32);
627 out->u[0] = (uint32_t)ol;
628 out->u[3] = (uint32_t)(oh >> 32);
629 out->u[2] = (uint32_t)oh;
630}
631#endif
640#ifdef ONLY64
641inline static void lshift128(w128_t *out, w128_t const *in, int shift)
642{
643 uint64_t th, tl, oh, ol;
644
645 th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
646 tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
647
648 oh = th << (shift * 8);
649 ol = tl << (shift * 8);
650 oh |= tl >> (64 - shift * 8);
651 out->u[0] = (uint32_t)(ol >> 32);
652 out->u[1] = (uint32_t)ol;
653 out->u[2] = (uint32_t)(oh >> 32);
654 out->u[3] = (uint32_t)oh;
655}
656#else
657inline static void lshift128(w128_t *out, w128_t const *in, int shift)
658{
659 uint64_t th, tl, oh, ol;
660
661 th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
662 tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
663
664 oh = th << (shift * 8);
665 ol = tl << (shift * 8);
666 oh |= tl >> (64 - shift * 8);
667 out->u[1] = (uint32_t)(ol >> 32);
668 out->u[0] = (uint32_t)ol;
669 out->u[3] = (uint32_t)(oh >> 32);
670 out->u[2] = (uint32_t)oh;
671}
672#endif
673
682#if(!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
683#ifdef ONLY64
684inline static void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c, w128_t *d)
685{
686 w128_t x;
687 w128_t y;
688
689 lshift128(&x, a, SL2);
690 rshift128(&y, c, SR2);
691 r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK2) ^ y.u[0] ^ (d->u[0] << SL1);
692 r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK1) ^ y.u[1] ^ (d->u[1] << SL1);
693 r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK4) ^ y.u[2] ^ (d->u[2] << SL1);
694 r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK3) ^ y.u[3] ^ (d->u[3] << SL1);
695}
696#else
697inline static void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c, w128_t *d)
698{
699 w128_t x;
700 w128_t y;
701
702 lshift128(&x, a, SL2);
703 rshift128(&y, c, SR2);
704 r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK1) ^ y.u[0] ^ (d->u[0] << SL1);
705 r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK2) ^ y.u[1] ^ (d->u[1] << SL1);
706 r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK3) ^ y.u[2] ^ (d->u[2] << SL1);
707 r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK4) ^ y.u[3] ^ (d->u[3] << SL1);
708}
709#endif
710#endif
711
712#if defined(BIG_ENDIAN64) && !defined(ONLY64) && !defined(HAVE_ALTIVEC)
713inline static void swap(w128_t *array, int size)
714{
715 for(int i = 0; i < size; i++)
716 {
717 uint32_t x = array[i].u[0];
718 uint32_t y = array[i].u[2];
719 array[i].u[0] = array[i].u[1];
720 array[i].u[2] = array[i].u[3];
721 array[i].u[1] = x;
722 array[i].u[3] = y;
723 }
724}
725#endif
732static uint32_t func1(uint32_t x)
733{
734 return (x ^ (x >> 27)) * (uint32_t)1664525UL;
735}
736
743static uint32_t func2(uint32_t x)
744{
745 return (x ^ (x >> 27)) * (uint32_t)1566083941UL;
746}
747
751static void period_certification(sfmt_state_t *s)
752{
753 int inner = 0;
754
755 for(int i = 0; i < 4; i++) inner ^= s->psfmt32[idxof(i)] & s->parity[i];
756 for(int i = 16; i > 0; i >>= 1) inner ^= inner >> i;
757 inner &= 1;
758 /* check OK */
759 if(inner == 1)
760 {
761 return;
762 }
763 /* check NG, and modification */
764 for(int i = 0; i < 4; i++)
765 {
766 uint32_t work = 1;
767 for(int j = 0; j < 32; j++)
768 {
769 if((work & s->parity[i]) != 0)
770 {
771 s->psfmt32[idxof(i)] ^= work;
772 return;
773 }
774 work = work << 1;
775 }
776 }
777}
778
779/*----------------
780 PUBLIC FUNCTIONS
781 ----------------*/
787const char *get_idstring(void)
788{
789 return IDSTR;
790}
791
792#ifndef ONLY64
798uint32_t gen_rand32(sfmt_state_t *s)
799{
800 uint32_t r;
801
802 // assert(s->initialized);
803 if(s->idx >= N32)
804 {
805 gen_rand_all(s);
806 s->idx = 0;
807 }
808 r = s->psfmt32[s->idx++];
809 return r;
810}
811#endif
819uint64_t gen_rand64(sfmt_state_t *s)
820{
821#if defined(BIG_ENDIAN64) && !defined(ONLY64)
822 uint32_t r1, r2;
823#else
824 uint64_t r;
825#endif
826
827 // assert(s->initialized);
828 // assert(s->idx % 2 == 0);
829
830 if(s->idx >= N32)
831 {
832 gen_rand_all(s);
833 s->idx = 0;
834 }
835#if defined(BIG_ENDIAN64) && !defined(ONLY64)
836 r1 = s->psfmt32[s->idx];
837 r2 = s->psfmt32[s->idx + 1];
838 s->idx += 2;
839 return ((uint64_t)r2 << 32) | r1;
840#else
841 r = s->psfmt64[s->idx / 2];
842 s->idx += 2;
843 return r;
844#endif
845}
846
847
854void init_gen_rand(sfmt_state_t *s, uint32_t seed)
855{
856 int i;
857
858 s->psfmt32[idxof(0)] = seed;
859 for(i = 1; i < N32; i++)
860 {
861 s->psfmt32[idxof(i)] = 1812433253UL * (s->psfmt32[idxof(i - 1)] ^ (s->psfmt32[idxof(i - 1)] >> 30)) + i;
862 }
863 s->idx = N32;
864 period_certification(s);
865 s->initialized = 1;
866}
867
874void init_by_array(sfmt_state_t *s, uint32_t *init_key, int key_length)
875{
876 int i, j, count;
877 uint32_t r;
878 int lag;
879 int mid;
880 int size = N * 4;
881
882 if(size >= 623)
883 {
884 lag = 11;
885 }
886 else if(size >= 68)
887 {
888 lag = 7;
889 }
890 else if(size >= 39)
891 {
892 lag = 5;
893 }
894 else
895 {
896 lag = 3;
897 }
898 mid = (size - lag) / 2;
899
900 memset(s->sfmt, 0x8b, sizeof(s->sfmt));
901 if(key_length + 1 > N32)
902 {
903 count = key_length + 1;
904 }
905 else
906 {
907 count = N32;
908 }
909 r = func1(s->psfmt32[idxof(0)] ^ s->psfmt32[idxof(mid)] ^ s->psfmt32[idxof(N32 - 1)]);
910 s->psfmt32[idxof(mid)] += r;
911 r += key_length;
912 s->psfmt32[idxof(mid + lag)] += r;
913 s->psfmt32[idxof(0)] = r;
914
915 count--;
916 for(i = 1, j = 0; (j < count) && (j < key_length); j++)
917 {
918 r = func1(s->psfmt32[idxof(i)] ^ s->psfmt32[idxof((i + mid) % N32)]
919 ^ s->psfmt32[idxof((i + N32 - 1) % N32)]);
920 s->psfmt32[idxof((i + mid) % N32)] += r;
921 r += init_key[j] + i;
922 s->psfmt32[idxof((i + mid + lag) % N32)] += r;
923 s->psfmt32[idxof(i)] = r;
924 i = (i + 1) % N32;
925 }
926 for(; j < count; j++)
927 {
928 r = func1(s->psfmt32[idxof(i)] ^ s->psfmt32[idxof((i + mid) % N32)]
929 ^ s->psfmt32[idxof((i + N32 - 1) % N32)]);
930 s->psfmt32[idxof((i + mid) % N32)] += r;
931 r += i;
932 s->psfmt32[idxof((i + mid + lag) % N32)] += r;
933 s->psfmt32[idxof(i)] = r;
934 i = (i + 1) % N32;
935 }
936 for(j = 0; j < N32; j++)
937 {
938 r = func2(s->psfmt32[idxof(i)] + s->psfmt32[idxof((i + mid) % N32)]
939 + s->psfmt32[idxof((i + N32 - 1) % N32)]);
940 s->psfmt32[idxof((i + mid) % N32)] ^= r;
941 r -= i;
942 s->psfmt32[idxof((i + mid + lag) % N32)] ^= r;
943 s->psfmt32[idxof(i)] = r;
944 i = (i + 1) % N32;
945 }
946
947 s->idx = N32;
948 period_certification(s);
949 s->initialized = 1;
950}
951
952
953static inline void dt_points_init(dt_points_t *p, const unsigned int num_threads)
954{
955 sfmt_state_t *states = (sfmt_state_t *)dt_alloc_align(sizeof(sfmt_state_t) * num_threads);
956 p->s = (sfmt_state_t **)calloc(num_threads, sizeof(sfmt_state_t *));
957 p->num = num_threads;
958
959 int seed = 0xD71337;
960 for(int i = 0; i < (int)num_threads; i++)
961 {
962 p->s[i] = states + i;
963#if !defined(BIG_ENDIAN64) || defined(ONLY64)
964 p->s[i]->psfmt64 = (uint64_t *)&(p->s[i]->sfmt[0].u[0]);
965#endif
966 p->s[i]->psfmt32 = &(p->s[i]->sfmt[0].u[0]);
967 p->s[i]->initialized = 0;
968 p->s[i]->parity[0] = PARITY1;
969 p->s[i]->parity[1] = PARITY2;
970 p->s[i]->parity[2] = PARITY3;
971 p->s[i]->parity[3] = PARITY4;
972 init_gen_rand(p->s[i], seed);
973 seed ^= seed << 1;
974 }
975}
976
977static inline void dt_points_cleanup(dt_points_t *p)
978{
979 dt_free_align(p->s[0]);
980 free(p->s);
981}
982
983static inline float dt_points_get_for(dt_points_t *p, const unsigned int thread_num)
984{
985 return genrand_real2f(p->s[thread_num]);
986}
987
988static inline float dt_points_get()
989{
991}
992
993#endif
994// clang-format off
995// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
996// vim: shiftwidth=2 expandtab tabstop=2 cindent
997// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
998// clang-format on
darktable_t darktable
Definition darktable.c:111
static int dt_get_thread_num()
Definition darktable.h:227
#define dt_free_align(A)
Definition darktable.h:334
static float f(const float t, const float c, const float x)
Definition graduatednd.c:173
static void swap(float *x, float *y)
Definition lightroom.c:1042
size_t size
Definition mipmap_cache.c:3
r
Definition derive_filmic_v6_gamut_mapping.py:17
mask
Definition dtstyle_to_xmp.py:54
tuple b
Definition extract_wb.py:166
str p
Definition extract_wb.py:157
#define N
Definition noiseprofile.c:139
static float dt_points_get()
Definition points.h:77
static void dt_points_cleanup(dt_points_t *p)
Definition points.h:52
static void dt_points_init(dt_points_t *p, const unsigned int num_threads)
Definition points.h:42
static float dt_points_get_for(dt_points_t *p, const unsigned int thread_num)
Definition points.h:57
unsigned __int64 uint64_t
Definition strptime.c:71
struct dt_points_t * points
Definition darktable.h:549
Definition points.h:32
uint64_t state1
Definition points.h:34
uint64_t state0
Definition points.h:33
Definition points.h:38
dt_points_state_t * s
Definition points.h:39
#define dt_alloc_align(B)
Definition tests/cache.c:22
static float __attribute__((__unused__))
Definition thinplate.c:39