Ansel
0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
fp_mode.h
Go to the documentation of this file.
1
/*
2
This file is part of Ansel,
3
Copyright (C) 2026 Aurélien PIERRE.
4
5
Ansel 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
Ansel 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
#include <
math.h
>
22
23
#if defined(__x86_64__) || defined(__i386__)
24
#include <xmmintrin.h>
25
#endif
26
27
#if defined(__aarch64__)
28
#include <fenv.h>
29
#endif
30
31
#include <stdio.h>
32
33
#ifdef __cplusplus
34
extern
"C"
{
35
#endif
36
37
typedef
enum
{
38
DT_FP_MODE_DEFAULT
= 0,
39
DT_FP_MODE_FAST
,
// fast
40
DT_FP_MODE_STRICT
// debug/scientific
41
}
dt_cpu_fp_mode_t
;
42
43
44
static
inline
__attribute__
((always_inline))
void
set_fast_mode(
void
)
45
{
46
#if defined(__x86_64__) || defined(__i386__)
47
unsigned
int
mxcsr = _mm_getcsr();
48
49
// Flush denormals to zero
50
mxcsr |= _MM_FLUSH_ZERO_ON;
51
52
// (optional if available)
53
#ifdef _MM_DENORMALS_ZERO_ON
54
mxcsr |= _MM_DENORMALS_ZERO_ON;
55
#endif
56
57
_mm_setcsr(mxcsr);
58
#endif
59
60
#if defined(__aarch64__)
61
// Best-effort: ARM usually already fast for denormals in SIMD paths
62
fesetenv(FE_DFL_ENV);
63
#endif
64
}
65
66
static
inline
__attribute__
((always_inline))
void
set_strict_mode(
void
)
67
{
68
#if defined(__x86_64__) || defined(__i386__)
69
unsigned
int
mxcsr = _mm_getcsr();
70
71
// Disable FTZ
72
mxcsr &= ~_MM_FLUSH_ZERO_ON;
73
74
_mm_setcsr(mxcsr);
75
#endif
76
77
#if defined(__aarch64__)
78
fesetenv(FE_DFL_ENV);
79
#endif
80
}
81
88
static
inline
void
__attribute__
((always_inline)) dt_fp_init(
const
dt_cpu_fp_mode_t
mode)
89
{
90
switch
(mode)
91
{
92
case
DT_FP_MODE_FAST
:
93
set_fast_mode();
94
break
;
95
96
case
DT_FP_MODE_STRICT
:
97
set_strict_mode();
98
break
;
99
100
default
:
101
// leave defaults unchanged
102
break
;
103
}
104
}
105
106
static
inline
void
dt_fp_print
(
const
char
*tag)
107
{
108
#if defined(__x86_64__) || defined(__i386__)
109
unsigned
int
mxcsr = _mm_getcsr();
110
111
fprintf(stdout,
"[%s] MXCSR = 0x%08x\n"
, tag, mxcsr);
112
113
fprintf(stdout,
" FTZ : %s\n"
, (mxcsr & _MM_FLUSH_ZERO_ON) ?
"ON"
:
"OFF"
);
114
115
#ifdef _MM_DENORMALS_ZERO_ON
116
fprintf(stdout,
" DAZ : %s\n"
, (mxcsr & _MM_DENORMALS_ZERO_ON) ?
"ON"
:
"OFF"
);
117
#endif
118
119
fprintf(stdout,
" exceptions mask: 0x%04x\n"
, (mxcsr >> 7) & 0x3f);
120
#endif
121
}
122
123
#ifdef __cplusplus
124
}
125
#endif
__attribute__
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
dt_cpu_fp_mode_t
dt_cpu_fp_mode_t
Definition
fp_mode.h:37
DT_FP_MODE_FAST
@ DT_FP_MODE_FAST
Definition
fp_mode.h:39
DT_FP_MODE_DEFAULT
@ DT_FP_MODE_DEFAULT
Definition
fp_mode.h:38
DT_FP_MODE_STRICT
@ DT_FP_MODE_STRICT
Definition
fp_mode.h:40
dt_fp_print
static void dt_fp_print(const char *tag)
Definition
fp_mode.h:106
math.h
src
common
fp_mode.h
Generated by
1.9.8