Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/util/format/u_format_unpack_neon.c
7206 views
1
/*
2
* Copyright © 2021 Google LLC
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
13
* Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
* IN THE SOFTWARE.
22
*/
23
24
#include <u_format.h>
25
26
#if (defined(PIPE_ARCH_AARCH64) || defined(PIPE_ARCH_ARM)) && !defined NO_FORMAT_ASM
27
28
/* armhf builds default to vfp, not neon, and refuses to compile neon intrinsics
29
* unless you tell it "no really".
30
*/
31
#ifdef PIPE_ARCH_ARM
32
#pragma GCC target ("fpu=neon")
33
#endif
34
35
#include <arm_neon.h>
36
#include "u_format_pack.h"
37
#include "util/u_cpu_detect.h"
38
39
static void
40
util_format_b8g8r8a8_unorm_unpack_rgba_8unorm_neon(uint8_t *restrict dst, const uint8_t *restrict src, unsigned width)
41
{
42
while (width >= 16) {
43
uint8x16x4_t load = vld4q_u8(src);
44
uint8x16x4_t swap = { .val = { load.val[2], load.val[1], load.val[0], load.val[3] } };
45
vst4q_u8(dst, swap);
46
width -= 16;
47
dst += 16 * 4;
48
src += 16 * 4;
49
}
50
if (width)
51
util_format_b8g8r8a8_unorm_unpack_rgba_8unorm(dst, src, width);
52
}
53
54
static const struct util_format_unpack_description util_format_unpack_descriptions_neon[] = {
55
[PIPE_FORMAT_B8G8R8A8_UNORM] = {
56
.unpack_rgba_8unorm = &util_format_b8g8r8a8_unorm_unpack_rgba_8unorm_neon,
57
.unpack_rgba = &util_format_b8g8r8a8_unorm_unpack_rgba_float,
58
},
59
};
60
61
const struct util_format_unpack_description *
62
util_format_unpack_description_neon(enum pipe_format format)
63
{
64
/* CPU detect for NEON support. On arm64, it's implied. */
65
#ifdef PIPE_ARCH_ARM
66
if (!util_get_cpu_caps()->has_neon)
67
return NULL;
68
#endif
69
70
if (format >= ARRAY_SIZE(util_format_unpack_descriptions_neon))
71
return NULL;
72
73
if (!util_format_unpack_descriptions_neon[format].unpack_rgba)
74
return NULL;
75
76
return &util_format_unpack_descriptions_neon[format];
77
}
78
79
#endif /* PIPE_ARCH_AARCH64 | PIPE_ARCH_ARM */
80
81