Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
openmp_maths.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2020-2021 Aurélien PIERRE.
4 Copyright (C) 2021 Ralf Brown.
5 Copyright (C) 2022 Martin Bařinka.
6
7 darktable is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 darktable is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with darktable. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21
22#include <glib.h> // for inline
23#include <math.h> // for log, logf, powf
24
25#pragma once
26
27
28#if defined(_OPENMP) && !defined(_WIN32) && !defined(__GNUC__)
29
30#pragma omp declare simd
31extern float fmaxf(const float x, const float y);
32
33#pragma omp declare simd
34extern float fminf(const float x, const float y);
35
36#pragma omp declare simd
37extern float fabsf(const float x);
38
39#pragma omp declare simd
40extern float powf(const float x, const float y);
41
42#pragma omp declare simd
43extern float sqrtf(const float x);
44
45#pragma omp declare simd
46extern float cbrtf(const float x);
47
48#pragma omp declare simd
49extern float log2f(const float x);
50
51#pragma omp declare simd
52extern float exp2f(const float x);
53
54#pragma omp declare simd
55extern float log10f(const float x);
56
57#pragma omp declare simd
58extern float expf(const float x);
59
60#pragma omp declare simd
61extern float logf(const float x);
62
63#endif
64
65
66/* Bring our own optimized maths functions because Clang makes dumb shit */
67
68#ifdef _OPENMP
69#pragma omp declare simd
70#endif
71static inline float fast_exp10f(const float x)
72{
73 // we use the property : 10^x = exp(log(10) * x) = 2^(log(10) * x / log(2))
74 // max relative error over x = [0; 4] is 1.5617955706227326e-15
75 return exp2f(3.3219280948873626f * x);
76}
77
78// Since we are at it, write an optimized expf
79#ifdef _OPENMP
80#pragma omp declare simd
81#endif
82static inline float fast_expf(const float x)
83{
84 // we use the property : exp(x) = 2^(x / log(2))
85 // max relative error over x = [0; 4] is 5.246203046472202e-16
86 return exp2f(1.4426950408889634f * x);
87}
88
89
90#ifdef _OPENMP
91#pragma omp declare simd aligned(vector:16)
92#endif
93static inline float v_maxf(const float vector[3])
94{
95 // Find the max over an RGB vector
96 return fmaxf(fmaxf(vector[0], vector[1]), vector[2]);
97}
98
99
100#ifdef _OPENMP
101#pragma omp declare simd aligned(vector:16)
102#endif
103static inline float v_minf(const float vector[3])
104{
105 // Find the min over an RGB vector
106 return fminf(fminf(vector[0], vector[1]), vector[2]);
107}
108
109#ifdef _OPENMP
110#pragma omp declare simd aligned(vector:16)
111#endif
112static inline float v_sumf(const float vector[3])
113{
114 return vector[0] + vector[1] + vector[2];
115}
116
117
118#ifdef _OPENMP
119#pragma omp declare simd
120#endif
121static inline float fmaxabsf(const float a, const float b)
122{
123 // Find the max in absolute value and return it with its sign
124 return (fabsf(a) > fabsf(b) && !isnan(a)) ? a :
125 (isnan(b)) ? 0.f : b;
126}
127
128
129#ifdef _OPENMP
130#pragma omp declare simd
131#endif
132static inline float fminabsf(const float a, const float b)
133{
134 // Find the min in absolute value and return it with its sign
135 return (fabsf(a) < fabsf(b) && !isnan(a)) ? a :
136 (isnan(b)) ? 0.f : b;
137}
138
139
140#ifdef _OPENMP
141#pragma omp declare simd
142#endif
143static inline float clamp_simd(const float x)
144{
145 return fminf(fmaxf(x, 0.0f), 1.0f);
146}
147// clang-format off
148// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
149// vim: shiftwidth=2 expandtab tabstop=2 cindent
150// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
151// clang-format on
152
const float b
Definition colorspaces_inline_conversions.h:1326
const float a
Definition colorspaces_inline_conversions.h:1292
static const float x
Definition iop_profile.h:239
static float fminabsf(const float a, const float b)
Definition openmp_maths.h:132
static float fmaxabsf(const float a, const float b)
Definition openmp_maths.h:121
static float v_maxf(const float vector[3])
Definition openmp_maths.h:93
static float v_sumf(const float vector[3])
Definition openmp_maths.h:112
static float fast_exp10f(const float x)
Definition openmp_maths.h:71
static float clamp_simd(const float x)
Definition openmp_maths.h:143
static float fast_expf(const float x)
Definition openmp_maths.h:82
static float v_minf(const float vector[3])
Definition openmp_maths.h:103