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-2011 johannes hanika.
4 Copyright (C) 2012 Jean-Sébastien Pédron.
5 Copyright (C) 2012 Richard Wonka.
6 Copyright (C) 2013-2014, 2016 Tobias Ellinghaus.
7 Copyright (C) 2014-2016 Roman Lebedev.
8 Copyright (C) 2017 luzpaz.
9 Copyright (C) 2018 Peter Budai.
10 Copyright (C) 2018 Robert Bridge.
11 Copyright (C) 2019 Andreas Schneider.
12 Copyright (C) 2019, 2025-2026 Aurélien PIERRE.
13 Copyright (C) 2020 Heiko Bauke.
14 Copyright (C) 2020 Pascal Obry.
15 Copyright (C) 2022 Martin Bařinka.
16 Copyright (C) 2024 Alynx Zhou.
17
18 darktable is free software: you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation, either version 3 of the License, or
21 (at your option) any later version.
22
23 darktable is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
27
28 You should have received a copy of the GNU General Public License
29 along with darktable. If not, see <http://www.gnu.org/licenses/>.
30*/
31
32#pragma once
33
34#ifndef __SSE2__
35
36#if !defined _XOPEN_SOURCE && !defined(__DragonFly__) && !defined(__FreeBSD__) && !defined(__NetBSD__) \
37 && !defined(__OpenBSD__) && !defined(_WIN32)
38#define _XOPEN_SOURCE
39#endif
40
41#include <stdlib.h>
42
43// xorshift128+, period 2^128-1, apparently passes all TestU01 suite tests.
49
54
55static inline void dt_points_init(dt_points_t *p, const unsigned int num_threads)
56{
57 p->s = (dt_points_state_t *)malloc(sizeof(dt_points_state_t) * num_threads);
58 for(int k = 0; k < num_threads; k++)
59 {
60 p->s[k].state0 = 1 + k;
61 p->s[k].state1 = 2 + k;
62 }
63}
64
65static inline void dt_points_cleanup(dt_points_t *p)
66{
67 dt_free(p->s);
68}
69
70static inline float dt_points_get_for(dt_points_t *p, const unsigned int thread_num)
71{
72 uint64_t s1 = p->s[thread_num].state0;
73 uint64_t s0 = p->s[thread_num].state1;
74 p->s[thread_num].state0 = s0;
75 s1 ^= s1 << 23;
76 s1 ^= s1 >> 17;
77 s1 ^= s0;
78 s1 ^= s0 >> 26;
79 p->s[thread_num].state1 = s1;
80 // return (state0 + state1) / ((double)((uint64_t)-1) + 1.0);
81 union {
82 float f;
83 uint32_t u;
84 } v;
85 v.u = 0x3f800000 |
86 ((p->s[thread_num].state0 + p->s[thread_num].state1) >> 41); // faster than double version.
87 return v.f - 1.0f;
88}
89
90static inline float dt_points_get()
91{
93}
94
95#else
96
97#if defined(__SSE__)
98#include <xmmintrin.h>
99#endif
100#include <inttypes.h>
101
102#define MEXP 19937
103
104#ifndef SFMT_PARAMS_H
105#define SFMT_PARAMS_H
106
107#if !defined(MEXP)
108#ifdef __GNUC__
109#warning "MEXP is not defined. I assume MEXP is 19937."
110#endif
111#define MEXP 19937
112#endif
113/*-----------------
114 BASIC DEFINITIONS
115 -----------------*/
121#define N (MEXP / 128 + 1)
124#define N32 (N * 4)
127#define N64 (N * 2)
128
129/*----------------------
130 the parameters of SFMT
131 following definitions are in paramsXXXX.h file.
132 ----------------------*/
170#if 0
171#if MEXP == 607
172#include "SFMT-params607.h"
173#elif MEXP == 1279
174#include "SFMT-params1279.h"
175#elif MEXP == 2281
176#include "SFMT-params2281.h"
177#elif MEXP == 4253
178#include "SFMT-params4253.h"
179#elif MEXP == 11213
180#include "SFMT-params11213.h"
181#elif MEXP == 19937
182#include "SFMT-params19937.h"
183#elif MEXP == 44497
184#include "SFMT-params44497.h"
185#elif MEXP == 86243
186#include "SFMT-params86243.h"
187#elif MEXP == 132049
188#include "SFMT-params132049.h"
189#elif MEXP == 216091
190#include "SFMT-params216091.h"
191#else
192#ifdef __GNUC__
193#error "MEXP is not valid."
194#undef MEXP
195#else
196#undef MEXP
197#endif
198#endif
199
200#endif
201
202#endif /* SFMT_PARAMS_H */
203
204#ifndef SFMT_PARAMS19937_H
205#define SFMT_PARAMS19937_H
206
207#define POS1 122
208#define SL1 18
209#define SL2 1
210#define SR1 11
211#define SR2 1
212#define MSK1 0xdfffffefU
213#define MSK2 0xddfecb7fU
214#define MSK3 0xbffaffffU
215#define MSK4 0xbffffff6U
216#define PARITY1 0x00000001U
217#define PARITY2 0x00000000U
218#define PARITY3 0x00000000U
219#define PARITY4 0x13c9e684U
220
221
222#define ALTI_SL1 \
223 { \
224 SL1, SL1, SL1, SL1 \
225 }
226#define ALTI_SR1 \
227 { \
228 SR1, SR1, SR1, SR1 \
229 }
230#define ALTI_MSK \
231 { \
232 MSK1, MSK2, MSK3, MSK4 \
233 }
234#define ALTI_MSK64 \
235 { \
236 MSK2, MSK1, MSK4, MSK3 \
237 }
238#define ALTI_SL2_PERM \
239 { \
240 1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, 8 \
241 }
242#define ALTI_SL2_PERM64 \
243 { \
244 1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, 13, 14, 15, 0 \
245 }
246#define ALTI_SR2_PERM \
247 { \
248 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, 17, 12, 13, 14 \
249 }
250#define ALTI_SR2_PERM64 \
251 { \
252 15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, 11, 12, 13, 14 \
253 }
254#define IDSTR "SFMT-19937:122-18-1-11-1:dfffffef-ddfecb7f-bffaffff-bffffff6"
255
256#endif /* SFMT_PARAMS19937_H */
257
259typedef union w128_t
260{
261 __m128i si;
262 uint32_t u[4];
263} w128_t;
264
265typedef struct sfmt_state_t
266{
268 w128_t sfmt[N];
270 uint32_t *psfmt32;
271#if !defined(BIG_ENDIAN64) || defined(ONLY64)
273 uint64_t *psfmt64;
274#endif
276 int idx;
279 int initialized;
281 uint32_t parity[4];
282} sfmt_state_t;
283
314#ifndef SFMT_H
315#define SFMT_H
316
317#include <stdio.h>
318
319#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
320#include <inttypes.h>
321#elif defined(_MSC_VER) || defined(__BORLANDC__)
322typedef unsigned int uint32_t;
323typedef unsigned __int64 uint64_t;
324#define inline __inline
325#else
326#include <inttypes.h>
327#if defined(__GNUC__)
328#define inline __inline__
329#endif
330#endif
331
332#ifndef PRIu64
333#if defined(_MSC_VER) || defined(__BORLANDC__)
334#define PRIu64 "I64u"
335#define PRIx64 "I64x"
336#else
337#define PRIu64 "llu"
338#define PRIx64 "llx"
339#endif
340#endif
341
342#if defined(__GNUC__)
343#define ALWAYSINLINE __attribute__((always_inline))
344#else
345#define ALWAYSINLINE
346#endif
347
348#if defined(_MSC_VER)
349#if _MSC_VER >= 1200
350#define PRE_ALWAYS __forceinline
351#else
352#define PRE_ALWAYS inline
353#endif
354#else
355#define PRE_ALWAYS inline
356#endif
357
358static inline uint32_t gen_rand32(struct sfmt_state_t *s);
359static inline uint64_t gen_rand64(struct sfmt_state_t *s);
360static inline void init_gen_rand(struct sfmt_state_t *s, uint32_t seed) __attribute__((unused));
361static inline void init_by_array(struct sfmt_state_t *s, uint32_t *init_key, int key_length)
362 __attribute__((unused));
363static inline const char *get_idstring(void) __attribute__((unused));
365inline static float to_real2f(uint32_t v)
366{
367 union {
368 float f;
369 uint32_t u;
370 } x;
371 x.u = 0x3f800000 | (v >> 9); // faster than double version.
372 return x.f - 1.0f;
373 /* divided by 2^32 */
374}
375inline static float genrand_real2f(struct sfmt_state_t *s)
376{
377 return to_real2f(gen_rand32(s));
378}
379
380#endif
396#ifndef SFMT_SSE2_H
397#define SFMT_SSE2_H
398
399PRE_ALWAYS static __m128i mm_recursion(__m128i *a, __m128i *b, __m128i c, __m128i d,
400 __m128i mask) ALWAYSINLINE;
401
411PRE_ALWAYS static __m128i mm_recursion(__m128i *a, __m128i *b, __m128i c, __m128i d, __m128i mask)
412{
413 __m128i v, x, y, z;
414
415 x = _mm_load_si128(a);
416 y = _mm_srli_epi32(*b, SR1);
417 z = _mm_srli_si128(c, SR2);
418 v = _mm_slli_epi32(d, SL1);
419 z = _mm_xor_si128(z, x);
420 z = _mm_xor_si128(z, v);
421 x = _mm_slli_si128(x, SL2);
422 y = _mm_and_si128(y, mask);
423 z = _mm_xor_si128(z, x);
424 z = _mm_xor_si128(z, y);
425 return z;
426}
427
432inline static void gen_rand_all(struct sfmt_state_t *s)
433{
434 int i;
435 __m128i r, r1, r2, mask;
436 mask = _mm_set_epi32(MSK4, MSK3, MSK2, MSK1);
437
438 r1 = _mm_load_si128(&(s->sfmt[N - 2].si));
439 r2 = _mm_load_si128(&(s->sfmt[N - 1].si));
440 for(i = 0; i < N - POS1; i++)
441 {
442 r = mm_recursion(&(s->sfmt[i].si), &(s->sfmt[i + POS1].si), r1, r2, mask);
443 _mm_store_si128(&(s->sfmt[i].si), r);
444 r1 = r2;
445 r2 = r;
446 }
447 for(; i < N; i++)
448 {
449 r = mm_recursion(&(s->sfmt[i].si), &(s->sfmt[i + POS1 - N].si), r1, r2, mask);
450 _mm_store_si128(&(s->sfmt[i].si), r);
451 r1 = r2;
452 r2 = r;
453 }
454}
455
463inline static void gen_rand_array(struct sfmt_state_t *s, w128_t *array, int size)
464{
465 int i, j;
466 __m128i r, r1, r2, mask;
467 mask = _mm_set_epi32(MSK4, MSK3, MSK2, MSK1);
468
469 r1 = _mm_load_si128(&(s->sfmt[N - 2].si));
470 r2 = _mm_load_si128(&(s->sfmt[N - 1].si));
471 for(i = 0; i < N - POS1; i++)
472 {
473 r = mm_recursion(&(s->sfmt[i].si), &(s->sfmt[i + POS1].si), r1, r2, mask);
474 _mm_store_si128(&array[i].si, r);
475 r1 = r2;
476 r2 = r;
477 }
478 for(; i < N; i++)
479 {
480 r = mm_recursion(&(s->sfmt[i].si), &array[i + POS1 - N].si, r1, r2, mask);
481 _mm_store_si128(&array[i].si, r);
482 r1 = r2;
483 r2 = r;
484 }
485 /* main loop */
486 for(; i < size - N; i++)
487 {
488 r = mm_recursion(&array[i - N].si, &array[i + POS1 - N].si, r1, r2, mask);
489 _mm_store_si128(&array[i].si, r);
490 r1 = r2;
491 r2 = r;
492 }
493 for(j = 0; j < 2 * N - size; j++)
494 {
495 r = _mm_load_si128(&array[j + size - N].si);
496 _mm_store_si128(&(s->sfmt[j].si), r);
497 }
498 for(; i < size; i++)
499 {
500 r = mm_recursion(&array[i - N].si, &array[i + POS1 - N].si, r1, r2, mask);
501 _mm_store_si128(&array[i].si, r);
502 _mm_store_si128(&(s->sfmt[j++].si), r);
503 r1 = r2;
504 r2 = r;
505 }
506}
507
508#endif
521#include <assert.h>
522#include <string.h>
523//#include "SFMT.h"
524//#include "SFMT-params.h"
525
526#if defined(__BIG_ENDIAN__) && !defined(__amd64) && !defined(BIG_ENDIAN64)
527#define BIG_ENDIAN64 1
528#endif
529#if defined(HAVE_ALTIVEC) && !defined(BIG_ENDIAN64)
530#define BIG_ENDIAN64 1
531#endif
532#if defined(ONLY64) && !defined(BIG_ENDIAN64)
533#if defined(__GNUC__)
534#error "-DONLY64 must be specified with -DBIG_ENDIAN64"
535#endif
536#undef ONLY64
537#endif
538
539
540typedef struct dt_points_t
541{
542 sfmt_state_t **s;
543 unsigned int num;
545
546#if 0
547/*--------------------------------------
548 FILE GLOBAL VARIABLES
549 internal state, index counter and flag
550 --------------------------------------*/
552static w128_t sfmt[N];
554static uint32_t *psfmt32 = &sfmt[0].u[0];
555#if !defined(BIG_ENDIAN64) || defined(ONLY64)
557static uint64_t *psfmt64 = (uint64_t *)&sfmt[0].u[0];
558#endif
560static int idx;
563static int initialized = 0;
565static uint32_t parity[4] = {PARITY1, PARITY2, PARITY3, PARITY4};
566#endif
567
568/*----------------
569 STATIC FUNCTIONS
570 ----------------*/
571inline static int idxof(int i);
572inline static void rshift128(w128_t *out, w128_t const *in, int shift);
573inline static void lshift128(w128_t *out, w128_t const *in, int shift);
574inline static void gen_rand_all(sfmt_state_t *s);
575inline static void gen_rand_array(sfmt_state_t *s, w128_t *array, int size);
576inline static uint32_t func1(uint32_t x);
577inline static uint32_t func2(uint32_t x);
578static void period_certification(sfmt_state_t *s);
579#if defined(BIG_ENDIAN64) && !defined(ONLY64)
580inline static void swap(w128_t *array, int size);
581#endif
582
583/*#if defined(HAVE_ALTIVEC)
584#include "SFMT-alti.h"
585#elif defined(HAVE_SSE2)
586#include "SFMT-sse2.h"
587#endif*/
588
593#ifdef ONLY64
594inline static int idxof(int i)
595{
596 return i ^ 1;
597}
598#else
599inline static int idxof(int i)
600{
601 return i;
602}
603#endif
612#ifdef ONLY64
613inline static void rshift128(w128_t *out, w128_t const *in, int shift)
614{
615 uint64_t th, tl, oh, ol;
616
617 th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
618 tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
619
620 oh = th >> (shift * 8);
621 ol = tl >> (shift * 8);
622 ol |= th << (64 - shift * 8);
623 out->u[0] = (uint32_t)(ol >> 32);
624 out->u[1] = (uint32_t)ol;
625 out->u[2] = (uint32_t)(oh >> 32);
626 out->u[3] = (uint32_t)oh;
627}
628#else
629inline static void rshift128(w128_t *out, w128_t const *in, int shift)
630{
631 uint64_t th, tl, oh, ol;
632
633 th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
634 tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
635
636 oh = th >> (shift * 8);
637 ol = tl >> (shift * 8);
638 ol |= th << (64 - shift * 8);
639 out->u[1] = (uint32_t)(ol >> 32);
640 out->u[0] = (uint32_t)ol;
641 out->u[3] = (uint32_t)(oh >> 32);
642 out->u[2] = (uint32_t)oh;
643}
644#endif
653#ifdef ONLY64
654inline static void lshift128(w128_t *out, w128_t const *in, int shift)
655{
656 uint64_t th, tl, oh, ol;
657
658 th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
659 tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
660
661 oh = th << (shift * 8);
662 ol = tl << (shift * 8);
663 oh |= tl >> (64 - shift * 8);
664 out->u[0] = (uint32_t)(ol >> 32);
665 out->u[1] = (uint32_t)ol;
666 out->u[2] = (uint32_t)(oh >> 32);
667 out->u[3] = (uint32_t)oh;
668}
669#else
670inline static void lshift128(w128_t *out, w128_t const *in, int shift)
671{
672 uint64_t th, tl, oh, ol;
673
674 th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
675 tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
676
677 oh = th << (shift * 8);
678 ol = tl << (shift * 8);
679 oh |= tl >> (64 - shift * 8);
680 out->u[1] = (uint32_t)(ol >> 32);
681 out->u[0] = (uint32_t)ol;
682 out->u[3] = (uint32_t)(oh >> 32);
683 out->u[2] = (uint32_t)oh;
684}
685#endif
686
695#if(!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
696#ifdef ONLY64
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) & MSK2) ^ y.u[0] ^ (d->u[0] << SL1);
705 r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK1) ^ y.u[1] ^ (d->u[1] << SL1);
706 r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK4) ^ y.u[2] ^ (d->u[2] << SL1);
707 r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK3) ^ y.u[3] ^ (d->u[3] << SL1);
708}
709#else
710inline static void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c, w128_t *d)
711{
712 w128_t x;
713 w128_t y;
714
715 lshift128(&x, a, SL2);
716 rshift128(&y, c, SR2);
717 r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK1) ^ y.u[0] ^ (d->u[0] << SL1);
718 r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK2) ^ y.u[1] ^ (d->u[1] << SL1);
719 r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK3) ^ y.u[2] ^ (d->u[2] << SL1);
720 r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK4) ^ y.u[3] ^ (d->u[3] << SL1);
721}
722#endif
723#endif
724
725#if defined(BIG_ENDIAN64) && !defined(ONLY64) && !defined(HAVE_ALTIVEC)
726inline static void swap(w128_t *array, int size)
727{
728 for(int i = 0; i < size; i++)
729 {
730 uint32_t x = array[i].u[0];
731 uint32_t y = array[i].u[2];
732 array[i].u[0] = array[i].u[1];
733 array[i].u[2] = array[i].u[3];
734 array[i].u[1] = x;
735 array[i].u[3] = y;
736 }
737}
738#endif
745static uint32_t func1(uint32_t x)
746{
747 return (x ^ (x >> 27)) * (uint32_t)1664525UL;
748}
749
756static uint32_t func2(uint32_t x)
757{
758 return (x ^ (x >> 27)) * (uint32_t)1566083941UL;
759}
760
764static void period_certification(sfmt_state_t *s)
765{
766 int inner = 0;
767
768 for(int i = 0; i < 4; i++) inner ^= s->psfmt32[idxof(i)] & s->parity[i];
769 for(int i = 16; i > 0; i >>= 1) inner ^= inner >> i;
770 inner &= 1;
771 /* check OK */
772 if(inner == 1)
773 {
774 return;
775 }
776 /* check NG, and modification */
777 for(int i = 0; i < 4; i++)
778 {
779 uint32_t work = 1;
780 for(int j = 0; j < 32; j++)
781 {
782 if((work & s->parity[i]) != 0)
783 {
784 s->psfmt32[idxof(i)] ^= work;
785 return;
786 }
787 work = work << 1;
788 }
789 }
790}
791
792/*----------------
793 PUBLIC FUNCTIONS
794 ----------------*/
800const char *get_idstring(void)
801{
802 return IDSTR;
803}
804
805#ifndef ONLY64
811uint32_t gen_rand32(sfmt_state_t *s)
812{
813 uint32_t r;
814
815 // assert(s->initialized);
816 if(s->idx >= N32)
817 {
818 gen_rand_all(s);
819 s->idx = 0;
820 }
821 r = s->psfmt32[s->idx++];
822 return r;
823}
824#endif
832uint64_t gen_rand64(sfmt_state_t *s)
833{
834#if defined(BIG_ENDIAN64) && !defined(ONLY64)
835 uint32_t r1, r2;
836#else
837 uint64_t r;
838#endif
839
840 // assert(s->initialized);
841 // assert(s->idx % 2 == 0);
842
843 if(s->idx >= N32)
844 {
845 gen_rand_all(s);
846 s->idx = 0;
847 }
848#if defined(BIG_ENDIAN64) && !defined(ONLY64)
849 r1 = s->psfmt32[s->idx];
850 r2 = s->psfmt32[s->idx + 1];
851 s->idx += 2;
852 return ((uint64_t)r2 << 32) | r1;
853#else
854 r = s->psfmt64[s->idx / 2];
855 s->idx += 2;
856 return r;
857#endif
858}
859
860
867void init_gen_rand(sfmt_state_t *s, uint32_t seed)
868{
869 int i;
870
871 s->psfmt32[idxof(0)] = seed;
872 for(i = 1; i < N32; i++)
873 {
874 s->psfmt32[idxof(i)] = 1812433253UL * (s->psfmt32[idxof(i - 1)] ^ (s->psfmt32[idxof(i - 1)] >> 30)) + i;
875 }
876 s->idx = N32;
877 period_certification(s);
878 s->initialized = 1;
879}
880
887void init_by_array(sfmt_state_t *s, uint32_t *init_key, int key_length)
888{
889 int i, j, count;
890 uint32_t r;
891 int lag;
892 int mid;
893 int size = N * 4;
894
895 if(size >= 623)
896 {
897 lag = 11;
898 }
899 else if(size >= 68)
900 {
901 lag = 7;
902 }
903 else if(size >= 39)
904 {
905 lag = 5;
906 }
907 else
908 {
909 lag = 3;
910 }
911 mid = (size - lag) / 2;
912
913 memset(s->sfmt, 0x8b, sizeof(s->sfmt));
914 if(key_length + 1 > N32)
915 {
916 count = key_length + 1;
917 }
918 else
919 {
920 count = N32;
921 }
922 r = func1(s->psfmt32[idxof(0)] ^ s->psfmt32[idxof(mid)] ^ s->psfmt32[idxof(N32 - 1)]);
923 s->psfmt32[idxof(mid)] += r;
924 r += key_length;
925 s->psfmt32[idxof(mid + lag)] += r;
926 s->psfmt32[idxof(0)] = r;
927
928 count--;
929 for(i = 1, j = 0; (j < count) && (j < key_length); j++)
930 {
931 r = func1(s->psfmt32[idxof(i)] ^ s->psfmt32[idxof((i + mid) % N32)]
932 ^ s->psfmt32[idxof((i + N32 - 1) % N32)]);
933 s->psfmt32[idxof((i + mid) % N32)] += r;
934 r += init_key[j] + i;
935 s->psfmt32[idxof((i + mid + lag) % N32)] += r;
936 s->psfmt32[idxof(i)] = r;
937 i = (i + 1) % N32;
938 }
939 for(; j < count; j++)
940 {
941 r = func1(s->psfmt32[idxof(i)] ^ s->psfmt32[idxof((i + mid) % N32)]
942 ^ s->psfmt32[idxof((i + N32 - 1) % N32)]);
943 s->psfmt32[idxof((i + mid) % N32)] += r;
944 r += i;
945 s->psfmt32[idxof((i + mid + lag) % N32)] += r;
946 s->psfmt32[idxof(i)] = r;
947 i = (i + 1) % N32;
948 }
949 for(j = 0; j < N32; j++)
950 {
951 r = func2(s->psfmt32[idxof(i)] + s->psfmt32[idxof((i + mid) % N32)]
952 + s->psfmt32[idxof((i + N32 - 1) % N32)]);
953 s->psfmt32[idxof((i + mid) % N32)] ^= r;
954 r -= i;
955 s->psfmt32[idxof((i + mid + lag) % N32)] ^= r;
956 s->psfmt32[idxof(i)] = r;
957 i = (i + 1) % N32;
958 }
959
960 s->idx = N32;
961 period_certification(s);
962 s->initialized = 1;
963}
964
965
966static inline void dt_points_init(dt_points_t *p, const unsigned int num_threads)
967{
968 sfmt_state_t *states = (sfmt_state_t *)dt_pixelpipe_cache_alloc_align_cache(
969 sizeof(sfmt_state_t) * num_threads, 0);
970 p->s = (sfmt_state_t **)calloc(num_threads, sizeof(sfmt_state_t *));
971 p->num = num_threads;
972
973 int seed = 0xD71337;
974 for(int i = 0; i < (int)num_threads; i++)
975 {
976 p->s[i] = states + i;
977#if !defined(BIG_ENDIAN64) || defined(ONLY64)
978 p->s[i]->psfmt64 = (uint64_t *)&(p->s[i]->sfmt[0].u[0]);
979#endif
980 p->s[i]->psfmt32 = &(p->s[i]->sfmt[0].u[0]);
981 p->s[i]->initialized = 0;
982 p->s[i]->parity[0] = PARITY1;
983 p->s[i]->parity[1] = PARITY2;
984 p->s[i]->parity[2] = PARITY3;
985 p->s[i]->parity[3] = PARITY4;
986 init_gen_rand(p->s[i], seed);
987 seed ^= seed << 1;
988 }
989}
990
991static inline void dt_points_cleanup(dt_points_t *p)
992{
994 dt_free(p->s);
995}
996
997static inline float dt_points_get_for(dt_points_t *p, const unsigned int thread_num)
998{
999 return genrand_real2f(p->s[thread_num]);
1000}
1001
1002static inline float dt_points_get()
1003{
1005}
1006
1007#endif
1008// clang-format off
1009// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
1010// vim: shiftwidth=2 expandtab tabstop=2 cindent
1011// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
1012// clang-format on
static const dt_aligned_pixel_simd_t const dt_adaptation_t const float p
Definition chromatic_adaptation.h:315
const float i
Definition colorspaces_inline_conversions.h:669
const float c
Definition colorspaces_inline_conversions.h:1365
const dt_aligned_pixel_t f
Definition colorspaces_inline_conversions.h:256
const float d
Definition colorspaces_inline_conversions.h:931
const float r
Definition colorspaces_inline_conversions.h:1324
const float b
Definition colorspaces_inline_conversions.h:1326
const float a
Definition colorspaces_inline_conversions.h:1292
static const dt_colormatrix_t dt_aligned_pixel_t out
Definition colorspaces_inline_conversions.h:184
darktable_t darktable
Definition darktable.c:178
#define dt_pixelpipe_cache_alloc_align_cache(size, id)
Definition darktable.h:357
float dt_aligned_pixel_simd_t __attribute__((vector_size(16), aligned(16)))
Multi-tap smudge source sample with directional jitter.
Definition darktable.h:448
static int dt_get_thread_num()
Definition darktable.h:269
#define dt_free(ptr)
Definition darktable.h:380
#define dt_pixelpipe_cache_free_align(mem)
Definition darktable.h:377
static const float x
Definition iop_profile.h:239
static const float v
Definition iop_profile.h:223
static void swap(float *x, float *y)
Definition lightroom.c:1022
size_t size
Definition mipmap_cache.c:3
mask
Definition dtstyle_to_xmp.py:79
#define N
Definition noiseprofile.c:159
static float dt_points_get()
Definition points.h:90
static void dt_points_cleanup(dt_points_t *p)
Definition points.h:65
static void dt_points_init(dt_points_t *p, const unsigned int num_threads)
Definition points.h:55
static float dt_points_get_for(dt_points_t *p, const unsigned int thread_num)
Definition points.h:70
unsigned __int64 uint64_t
Definition strptime.c:74
struct dt_points_t * points
Definition darktable.h:711
Definition points.h:45
uint64_t state1
Definition points.h:47
uint64_t state0
Definition points.h:46
Definition points.h:51
dt_points_state_t * s
Definition points.h:52