Grok
12.0.1
src
lib
core
util
simd.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2016-2024 Grok Image Compression Inc.
3
*
4
* This source code is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Affero General Public License, version 3,
6
* as published by the Free Software Foundation.
7
*
8
* This source code is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Affero General Public License for more details.
12
*
13
* You should have received a copy of the GNU Affero General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15
*
16
*
17
*/
18
#pragma once
19
20
#include <cmath>
21
#include <cstdint>
22
23
#if defined(__arm64__) || defined(__arm__)
24
#include <arm_acle.h>
25
#if defined(__ARM_NEON__)
26
#include <arm_neon.h>
27
#endif
28
#elif defined(_WIN32)
29
#include <intrin.h>
30
#elif defined(__x86_64__) || defined(__i386__)
31
#include <x86intrin.h>
32
#ifdef __SSE__
33
#include <xmmintrin.h>
34
#endif
35
#ifdef __SSE2__
36
#include <emmintrin.h>
37
#endif
38
#endif
39
40
static
inline
long
grk_lrintf
(
float
f)
41
{
42
#if defined(_MSC_VER)
43
#ifdef _M_X64
44
return
_mm_cvt_ss2si(_mm_load_ss(&f));
45
#elif defined(_M_IX86)
46
int
i;
47
_asm {
48
fld f
49
fistp i
50
}
51
;
52
return
i;
53
#else
54
return
(
long
)((f > 0.0f) ? (f + 0.5f) : (f - 0.5f));
55
#endif
56
#else
57
return
lrintf(f);
58
#endif
59
}
60
61
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
62
#pragma intrinsic(__emul)
63
#endif
64
65
static
inline
uint32_t
grk_population_count
(uint32_t val)
66
{
67
#ifdef _MSC_VER
68
return
(uint32_t)__popcnt(val);
69
#else
70
return
(uint32_t)__builtin_popcount(val);
71
#endif
72
}
grk_population_count
static uint32_t grk_population_count(uint32_t val)
Definition
simd.h:65
grk_lrintf
static long grk_lrintf(float f)
Definition
simd.h:40
Generated by
1.10.0