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#include <inttypes.h>
98
99#define MEXP 19937
100
101#ifndef SFMT_PARAMS_H
102#define SFMT_PARAMS_H
103
104#if !defined(MEXP)
105#ifdef __GNUC__
106#warning "MEXP is not defined. I assume MEXP is 19937."
107#endif
108#define MEXP 19937
109#endif
110/*-----------------
111 BASIC DEFINITIONS
112 -----------------*/
118#define N (MEXP / 128 + 1)
121#define N32 (N * 4)
124#define N64 (N * 2)
125
126/*----------------------
127 the parameters of SFMT
128 following definitions are in paramsXXXX.h file.
129 ----------------------*/
167#if 0
168#if MEXP == 607
169#include "SFMT-params607.h"
170#elif MEXP == 1279
171#include "SFMT-params1279.h"
172#elif MEXP == 2281
173#include "SFMT-params2281.h"
174#elif MEXP == 4253
175#include "SFMT-params4253.h"
176#elif MEXP == 11213
177#include "SFMT-params11213.h"
178#elif MEXP == 19937
179#include "SFMT-params19937.h"
180#elif MEXP == 44497
181#include "SFMT-params44497.h"
182#elif MEXP == 86243
183#include "SFMT-params86243.h"
184#elif MEXP == 132049
185#include "SFMT-params132049.h"
186#elif MEXP == 216091
187#include "SFMT-params216091.h"
188#else
189#ifdef __GNUC__
190#error "MEXP is not valid."
191#undef MEXP
192#else
193#undef MEXP
194#endif
195#endif
196
197#endif
198
199#endif /* SFMT_PARAMS_H */
200
201#ifndef SFMT_PARAMS19937_H
202#define SFMT_PARAMS19937_H
203
204#define POS1 122
205#define SL1 18
206#define SL2 1
207#define SR1 11
208#define SR2 1
209#define MSK1 0xdfffffefU
210#define MSK2 0xddfecb7fU
211#define MSK3 0xbffaffffU
212#define MSK4 0xbffffff6U
213#define PARITY1 0x00000001U
214#define PARITY2 0x00000000U
215#define PARITY3 0x00000000U
216#define PARITY4 0x13c9e684U
217
218
219#define ALTI_SL1 \
220 { \
221 SL1, SL1, SL1, SL1 \
222 }
223#define ALTI_SR1 \
224 { \
225 SR1, SR1, SR1, SR1 \
226 }
227#define ALTI_MSK \
228 { \
229 MSK1, MSK2, MSK3, MSK4 \
230 }
231#define ALTI_MSK64 \
232 { \
233 MSK2, MSK1, MSK4, MSK3 \
234 }
235#define ALTI_SL2_PERM \
236 { \
237 1, 2, 3, 23, 5, 6, 7, 0, 9, 10, 11, 4, 13, 14, 15, 8 \
238 }
239#define ALTI_SL2_PERM64 \
240 { \
241 1, 2, 3, 4, 5, 6, 7, 31, 9, 10, 11, 12, 13, 14, 15, 0 \
242 }
243#define ALTI_SR2_PERM \
244 { \
245 7, 0, 1, 2, 11, 4, 5, 6, 15, 8, 9, 10, 17, 12, 13, 14 \
246 }
247#define ALTI_SR2_PERM64 \
248 { \
249 15, 0, 1, 2, 3, 4, 5, 6, 17, 8, 9, 10, 11, 12, 13, 14 \
250 }
251#define IDSTR "SFMT-19937:122-18-1-11-1:dfffffef-ddfecb7f-bffaffff-bffffff6"
252
253#endif /* SFMT_PARAMS19937_H */
254
256typedef union w128_t
257{
258 __m128i si;
259 uint32_t u[4];
260} w128_t;
261
262typedef struct sfmt_state_t
263{
265 w128_t sfmt[N];
267 uint32_t *psfmt32;
268#if !defined(BIG_ENDIAN64) || defined(ONLY64)
270 uint64_t *psfmt64;
271#endif
273 int idx;
276 int initialized;
278 uint32_t parity[4];
279} sfmt_state_t;
280
311#ifndef SFMT_H
312#define SFMT_H
313
314#include <stdio.h>
315
316#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
317#include <inttypes.h>
318#elif defined(_MSC_VER) || defined(__BORLANDC__)
319typedef unsigned int uint32_t;
320typedef unsigned __int64 uint64_t;
321#define inline __inline
322#else
323#include <inttypes.h>
324#if defined(__GNUC__)
325#define inline __inline__
326#endif
327#endif
328
329#ifndef PRIu64
330#if defined(_MSC_VER) || defined(__BORLANDC__)
331#define PRIu64 "I64u"
332#define PRIx64 "I64x"
333#else
334#define PRIu64 "llu"
335#define PRIx64 "llx"
336#endif
337#endif
338
339#if defined(__GNUC__)
340#define ALWAYSINLINE __attribute__((always_inline))
341#else
342#define ALWAYSINLINE
343#endif
344
345#if defined(_MSC_VER)
346#if _MSC_VER >= 1200
347#define PRE_ALWAYS __forceinline
348#else
349#define PRE_ALWAYS inline
350#endif
351#else
352#define PRE_ALWAYS inline
353#endif
354
355static inline uint32_t gen_rand32(struct sfmt_state_t *s);
356static inline uint64_t gen_rand64(struct sfmt_state_t *s);
357static inline void init_gen_rand(struct sfmt_state_t *s, uint32_t seed) __attribute__((unused));
358static inline void init_by_array(struct sfmt_state_t *s, uint32_t *init_key, int key_length)
359 __attribute__((unused));
360static inline const char *get_idstring(void) __attribute__((unused));
362inline static float to_real2f(uint32_t v)
363{
364 union {
365 float f;
366 uint32_t u;
367 } x;
368 x.u = 0x3f800000 | (v >> 9); // faster than double version.
369 return x.f - 1.0f;
370 /* divided by 2^32 */
371}
372inline static float genrand_real2f(struct sfmt_state_t *s)
373{
374 return to_real2f(gen_rand32(s));
375}
376
377#endif
393#ifndef SFMT_SSE2_H
394#define SFMT_SSE2_H
395
396PRE_ALWAYS static __m128i mm_recursion(__m128i *a, __m128i *b, __m128i c, __m128i d,
397 __m128i mask) ALWAYSINLINE;
398
408PRE_ALWAYS static __m128i mm_recursion(__m128i *a, __m128i *b, __m128i c, __m128i d, __m128i mask)
409{
410 __m128i v, x, y, z;
411
412 x = _mm_load_si128(a);
413 y = _mm_srli_epi32(*b, SR1);
414 z = _mm_srli_si128(c, SR2);
415 v = _mm_slli_epi32(d, SL1);
416 z = _mm_xor_si128(z, x);
417 z = _mm_xor_si128(z, v);
418 x = _mm_slli_si128(x, SL2);
419 y = _mm_and_si128(y, mask);
420 z = _mm_xor_si128(z, x);
421 z = _mm_xor_si128(z, y);
422 return z;
423}
424
429inline static void gen_rand_all(struct sfmt_state_t *s)
430{
431 int i;
432 __m128i r, r1, r2, mask;
433 mask = _mm_set_epi32(MSK4, MSK3, MSK2, MSK1);
434
435 r1 = _mm_load_si128(&(s->sfmt[N - 2].si));
436 r2 = _mm_load_si128(&(s->sfmt[N - 1].si));
437 for(i = 0; i < N - POS1; i++)
438 {
439 r = mm_recursion(&(s->sfmt[i].si), &(s->sfmt[i + POS1].si), r1, r2, mask);
440 _mm_store_si128(&(s->sfmt[i].si), r);
441 r1 = r2;
442 r2 = r;
443 }
444 for(; i < N; i++)
445 {
446 r = mm_recursion(&(s->sfmt[i].si), &(s->sfmt[i + POS1 - N].si), r1, r2, mask);
447 _mm_store_si128(&(s->sfmt[i].si), r);
448 r1 = r2;
449 r2 = r;
450 }
451}
452
460inline static void gen_rand_array(struct sfmt_state_t *s, w128_t *array, int size)
461{
462 int i, j;
463 __m128i r, r1, r2, mask;
464 mask = _mm_set_epi32(MSK4, MSK3, MSK2, MSK1);
465
466 r1 = _mm_load_si128(&(s->sfmt[N - 2].si));
467 r2 = _mm_load_si128(&(s->sfmt[N - 1].si));
468 for(i = 0; i < N - POS1; i++)
469 {
470 r = mm_recursion(&(s->sfmt[i].si), &(s->sfmt[i + POS1].si), r1, r2, mask);
471 _mm_store_si128(&array[i].si, r);
472 r1 = r2;
473 r2 = r;
474 }
475 for(; i < N; i++)
476 {
477 r = mm_recursion(&(s->sfmt[i].si), &array[i + POS1 - N].si, r1, r2, mask);
478 _mm_store_si128(&array[i].si, r);
479 r1 = r2;
480 r2 = r;
481 }
482 /* main loop */
483 for(; i < size - N; i++)
484 {
485 r = mm_recursion(&array[i - N].si, &array[i + POS1 - N].si, r1, r2, mask);
486 _mm_store_si128(&array[i].si, r);
487 r1 = r2;
488 r2 = r;
489 }
490 for(j = 0; j < 2 * N - size; j++)
491 {
492 r = _mm_load_si128(&array[j + size - N].si);
493 _mm_store_si128(&(s->sfmt[j].si), r);
494 }
495 for(; i < size; i++)
496 {
497 r = mm_recursion(&array[i - N].si, &array[i + POS1 - N].si, r1, r2, mask);
498 _mm_store_si128(&array[i].si, r);
499 _mm_store_si128(&(s->sfmt[j++].si), r);
500 r1 = r2;
501 r2 = r;
502 }
503}
504
505#endif
518#include <assert.h>
519#include <string.h>
520//#include "SFMT.h"
521//#include "SFMT-params.h"
522
523#if defined(__BIG_ENDIAN__) && !defined(__amd64) && !defined(BIG_ENDIAN64)
524#define BIG_ENDIAN64 1
525#endif
526#if defined(HAVE_ALTIVEC) && !defined(BIG_ENDIAN64)
527#define BIG_ENDIAN64 1
528#endif
529#if defined(ONLY64) && !defined(BIG_ENDIAN64)
530#if defined(__GNUC__)
531#error "-DONLY64 must be specified with -DBIG_ENDIAN64"
532#endif
533#undef ONLY64
534#endif
535
536
537typedef struct dt_points_t
538{
539 sfmt_state_t **s;
540 unsigned int num;
542
543#if 0
544/*--------------------------------------
545 FILE GLOBAL VARIABLES
546 internal state, index counter and flag
547 --------------------------------------*/
549static w128_t sfmt[N];
551static uint32_t *psfmt32 = &sfmt[0].u[0];
552#if !defined(BIG_ENDIAN64) || defined(ONLY64)
554static uint64_t *psfmt64 = (uint64_t *)&sfmt[0].u[0];
555#endif
557static int idx;
560static int initialized = 0;
562static uint32_t parity[4] = {PARITY1, PARITY2, PARITY3, PARITY4};
563#endif
564
565/*----------------
566 STATIC FUNCTIONS
567 ----------------*/
568inline static int idxof(int i);
569inline static void rshift128(w128_t *out, w128_t const *in, int shift);
570inline static void lshift128(w128_t *out, w128_t const *in, int shift);
571inline static void gen_rand_all(sfmt_state_t *s);
572inline static void gen_rand_array(sfmt_state_t *s, w128_t *array, int size);
573inline static uint32_t func1(uint32_t x);
574inline static uint32_t func2(uint32_t x);
575static void period_certification(sfmt_state_t *s);
576#if defined(BIG_ENDIAN64) && !defined(ONLY64)
577inline static void swap(w128_t *array, int size);
578#endif
579
580/*#if defined(HAVE_ALTIVEC)
581#include "SFMT-alti.h"
582#elif defined(HAVE_SSE2)
583#include "SFMT-sse2.h"
584#endif*/
585
590#ifdef ONLY64
591inline static int idxof(int i)
592{
593 return i ^ 1;
594}
595#else
596inline static int idxof(int i)
597{
598 return i;
599}
600#endif
609#ifdef ONLY64
610inline static void rshift128(w128_t *out, w128_t const *in, int shift)
611{
612 uint64_t th, tl, oh, ol;
613
614 th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
615 tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
616
617 oh = th >> (shift * 8);
618 ol = tl >> (shift * 8);
619 ol |= th << (64 - shift * 8);
620 out->u[0] = (uint32_t)(ol >> 32);
621 out->u[1] = (uint32_t)ol;
622 out->u[2] = (uint32_t)(oh >> 32);
623 out->u[3] = (uint32_t)oh;
624}
625#else
626inline static void rshift128(w128_t *out, w128_t const *in, int shift)
627{
628 uint64_t th, tl, oh, ol;
629
630 th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
631 tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
632
633 oh = th >> (shift * 8);
634 ol = tl >> (shift * 8);
635 ol |= th << (64 - shift * 8);
636 out->u[1] = (uint32_t)(ol >> 32);
637 out->u[0] = (uint32_t)ol;
638 out->u[3] = (uint32_t)(oh >> 32);
639 out->u[2] = (uint32_t)oh;
640}
641#endif
650#ifdef ONLY64
651inline static void lshift128(w128_t *out, w128_t const *in, int shift)
652{
653 uint64_t th, tl, oh, ol;
654
655 th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
656 tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
657
658 oh = th << (shift * 8);
659 ol = tl << (shift * 8);
660 oh |= tl >> (64 - shift * 8);
661 out->u[0] = (uint32_t)(ol >> 32);
662 out->u[1] = (uint32_t)ol;
663 out->u[2] = (uint32_t)(oh >> 32);
664 out->u[3] = (uint32_t)oh;
665}
666#else
667inline static void lshift128(w128_t *out, w128_t const *in, int shift)
668{
669 uint64_t th, tl, oh, ol;
670
671 th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
672 tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
673
674 oh = th << (shift * 8);
675 ol = tl << (shift * 8);
676 oh |= tl >> (64 - shift * 8);
677 out->u[1] = (uint32_t)(ol >> 32);
678 out->u[0] = (uint32_t)ol;
679 out->u[3] = (uint32_t)(oh >> 32);
680 out->u[2] = (uint32_t)oh;
681}
682#endif
683
692#if(!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
693#ifdef ONLY64
694inline static void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c, w128_t *d)
695{
696 w128_t x;
697 w128_t y;
698
699 lshift128(&x, a, SL2);
700 rshift128(&y, c, SR2);
701 r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK2) ^ y.u[0] ^ (d->u[0] << SL1);
702 r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK1) ^ y.u[1] ^ (d->u[1] << SL1);
703 r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK4) ^ y.u[2] ^ (d->u[2] << SL1);
704 r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK3) ^ y.u[3] ^ (d->u[3] << SL1);
705}
706#else
707inline static void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c, w128_t *d)
708{
709 w128_t x;
710 w128_t y;
711
712 lshift128(&x, a, SL2);
713 rshift128(&y, c, SR2);
714 r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK1) ^ y.u[0] ^ (d->u[0] << SL1);
715 r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK2) ^ y.u[1] ^ (d->u[1] << SL1);
716 r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK3) ^ y.u[2] ^ (d->u[2] << SL1);
717 r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK4) ^ y.u[3] ^ (d->u[3] << SL1);
718}
719#endif
720#endif
721
722#if defined(BIG_ENDIAN64) && !defined(ONLY64) && !defined(HAVE_ALTIVEC)
723inline static void swap(w128_t *array, int size)
724{
725 for(int i = 0; i < size; i++)
726 {
727 uint32_t x = array[i].u[0];
728 uint32_t y = array[i].u[2];
729 array[i].u[0] = array[i].u[1];
730 array[i].u[2] = array[i].u[3];
731 array[i].u[1] = x;
732 array[i].u[3] = y;
733 }
734}
735#endif
742static uint32_t func1(uint32_t x)
743{
744 return (x ^ (x >> 27)) * (uint32_t)1664525UL;
745}
746
753static uint32_t func2(uint32_t x)
754{
755 return (x ^ (x >> 27)) * (uint32_t)1566083941UL;
756}
757
761static void period_certification(sfmt_state_t *s)
762{
763 int inner = 0;
764
765 for(int i = 0; i < 4; i++) inner ^= s->psfmt32[idxof(i)] & s->parity[i];
766 for(int i = 16; i > 0; i >>= 1) inner ^= inner >> i;
767 inner &= 1;
768 /* check OK */
769 if(inner == 1)
770 {
771 return;
772 }
773 /* check NG, and modification */
774 for(int i = 0; i < 4; i++)
775 {
776 uint32_t work = 1;
777 for(int j = 0; j < 32; j++)
778 {
779 if((work & s->parity[i]) != 0)
780 {
781 s->psfmt32[idxof(i)] ^= work;
782 return;
783 }
784 work = work << 1;
785 }
786 }
787}
788
789/*----------------
790 PUBLIC FUNCTIONS
791 ----------------*/
797const char *get_idstring(void)
798{
799 return IDSTR;
800}
801
802#ifndef ONLY64
808uint32_t gen_rand32(sfmt_state_t *s)
809{
810 uint32_t r;
811
812 // assert(s->initialized);
813 if(s->idx >= N32)
814 {
815 gen_rand_all(s);
816 s->idx = 0;
817 }
818 r = s->psfmt32[s->idx++];
819 return r;
820}
821#endif
829uint64_t gen_rand64(sfmt_state_t *s)
830{
831#if defined(BIG_ENDIAN64) && !defined(ONLY64)
832 uint32_t r1, r2;
833#else
834 uint64_t r;
835#endif
836
837 // assert(s->initialized);
838 // assert(s->idx % 2 == 0);
839
840 if(s->idx >= N32)
841 {
842 gen_rand_all(s);
843 s->idx = 0;
844 }
845#if defined(BIG_ENDIAN64) && !defined(ONLY64)
846 r1 = s->psfmt32[s->idx];
847 r2 = s->psfmt32[s->idx + 1];
848 s->idx += 2;
849 return ((uint64_t)r2 << 32) | r1;
850#else
851 r = s->psfmt64[s->idx / 2];
852 s->idx += 2;
853 return r;
854#endif
855}
856
857
864void init_gen_rand(sfmt_state_t *s, uint32_t seed)
865{
866 int i;
867
868 s->psfmt32[idxof(0)] = seed;
869 for(i = 1; i < N32; i++)
870 {
871 s->psfmt32[idxof(i)] = 1812433253UL * (s->psfmt32[idxof(i - 1)] ^ (s->psfmt32[idxof(i - 1)] >> 30)) + i;
872 }
873 s->idx = N32;
874 period_certification(s);
875 s->initialized = 1;
876}
877
884void init_by_array(sfmt_state_t *s, uint32_t *init_key, int key_length)
885{
886 int i, j, count;
887 uint32_t r;
888 int lag;
889 int mid;
890 int size = N * 4;
891
892 if(size >= 623)
893 {
894 lag = 11;
895 }
896 else if(size >= 68)
897 {
898 lag = 7;
899 }
900 else if(size >= 39)
901 {
902 lag = 5;
903 }
904 else
905 {
906 lag = 3;
907 }
908 mid = (size - lag) / 2;
909
910 memset(s->sfmt, 0x8b, sizeof(s->sfmt));
911 if(key_length + 1 > N32)
912 {
913 count = key_length + 1;
914 }
915 else
916 {
917 count = N32;
918 }
919 r = func1(s->psfmt32[idxof(0)] ^ s->psfmt32[idxof(mid)] ^ s->psfmt32[idxof(N32 - 1)]);
920 s->psfmt32[idxof(mid)] += r;
921 r += key_length;
922 s->psfmt32[idxof(mid + lag)] += r;
923 s->psfmt32[idxof(0)] = r;
924
925 count--;
926 for(i = 1, j = 0; (j < count) && (j < key_length); 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 += init_key[j] + 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 < count; j++)
937 {
938 r = func1(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 for(j = 0; j < N32; j++)
947 {
948 r = func2(s->psfmt32[idxof(i)] + s->psfmt32[idxof((i + mid) % N32)]
949 + s->psfmt32[idxof((i + N32 - 1) % N32)]);
950 s->psfmt32[idxof((i + mid) % N32)] ^= r;
951 r -= i;
952 s->psfmt32[idxof((i + mid + lag) % N32)] ^= r;
953 s->psfmt32[idxof(i)] = r;
954 i = (i + 1) % N32;
955 }
956
957 s->idx = N32;
958 period_certification(s);
959 s->initialized = 1;
960}
961
962
963static inline void dt_points_init(dt_points_t *p, const unsigned int num_threads)
964{
965 sfmt_state_t *states = (sfmt_state_t *)dt_pixelpipe_cache_alloc_align_cache(
966 sizeof(sfmt_state_t) * num_threads, 0);
967 p->s = (sfmt_state_t **)calloc(num_threads, sizeof(sfmt_state_t *));
968 p->num = num_threads;
969
970 int seed = 0xD71337;
971 for(int i = 0; i < (int)num_threads; i++)
972 {
973 p->s[i] = states + i;
974#if !defined(BIG_ENDIAN64) || defined(ONLY64)
975 p->s[i]->psfmt64 = (uint64_t *)&(p->s[i]->sfmt[0].u[0]);
976#endif
977 p->s[i]->psfmt32 = &(p->s[i]->sfmt[0].u[0]);
978 p->s[i]->initialized = 0;
979 p->s[i]->parity[0] = PARITY1;
980 p->s[i]->parity[1] = PARITY2;
981 p->s[i]->parity[2] = PARITY3;
982 p->s[i]->parity[3] = PARITY4;
983 init_gen_rand(p->s[i], seed);
984 seed ^= seed << 1;
985 }
986}
987
988static inline void dt_points_cleanup(dt_points_t *p)
989{
991 dt_free(p->s);
992}
993
994static inline float dt_points_get_for(dt_points_t *p, const unsigned int thread_num)
995{
996 return genrand_real2f(p->s[thread_num]);
997}
998
999static inline float dt_points_get()
1000{
1002}
1003
1004#endif
1005// clang-format off
1006// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
1007// vim: shiftwidth=2 expandtab tabstop=2 cindent
1008// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
1009// clang-format on
static const dt_aligned_pixel_simd_t const dt_adaptation_t const float p
Definition chromatic_adaptation.h:309
const float i
Definition colorspaces_inline_conversions.h:440
const dt_aligned_pixel_t f
Definition colorspaces_inline_conversions.h:102
const float d
Definition colorspaces_inline_conversions.h:680
const dt_colormatrix_t dt_aligned_pixel_t out
Definition colorspaces_inline_conversions.h:42
darktable_t darktable
Definition darktable.c:173
#define dt_pixelpipe_cache_alloc_align_cache(size, id)
Definition darktable.h:433
float dt_aligned_pixel_simd_t __attribute__((vector_size(16), aligned(16)))
Enable aggressive floating-point arithmetic optimizations, in denormals handling. Set through user pr...
Definition darktable.h:524
static int dt_get_thread_num()
Definition darktable.h:291
#define dt_free(ptr)
Definition darktable.h:456
#define dt_pixelpipe_cache_free_align(mem)
Definition darktable.h:453
static const float x
Definition iop_profile.h:235
const float v
Definition iop_profile.h:221
static void swap(float *x, float *y)
Definition lightroom.c:1022
float *const restrict const size_t k
Definition luminance_mask.h:78
size_t size
Definition mipmap_cache.c:3
mask
Definition dtstyle_to_xmp.py:79
tuple b
Definition extract_wb.py:190
#define N
Definition noiseprofile.c:158
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
const float r
Definition src/develop/noise_generator.h:101
unsigned __int64 uint64_t
Definition strptime.c:75
struct dt_points_t * points
Definition darktable.h:782
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