Path: blob/21.2-virgl/src/util/format/u_format_unpack_neon.c
7206 views
/*1* Copyright © 2021 Google LLC2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include <u_format.h>2425#if (defined(PIPE_ARCH_AARCH64) || defined(PIPE_ARCH_ARM)) && !defined NO_FORMAT_ASM2627/* armhf builds default to vfp, not neon, and refuses to compile neon intrinsics28* unless you tell it "no really".29*/30#ifdef PIPE_ARCH_ARM31#pragma GCC target ("fpu=neon")32#endif3334#include <arm_neon.h>35#include "u_format_pack.h"36#include "util/u_cpu_detect.h"3738static void39util_format_b8g8r8a8_unorm_unpack_rgba_8unorm_neon(uint8_t *restrict dst, const uint8_t *restrict src, unsigned width)40{41while (width >= 16) {42uint8x16x4_t load = vld4q_u8(src);43uint8x16x4_t swap = { .val = { load.val[2], load.val[1], load.val[0], load.val[3] } };44vst4q_u8(dst, swap);45width -= 16;46dst += 16 * 4;47src += 16 * 4;48}49if (width)50util_format_b8g8r8a8_unorm_unpack_rgba_8unorm(dst, src, width);51}5253static const struct util_format_unpack_description util_format_unpack_descriptions_neon[] = {54[PIPE_FORMAT_B8G8R8A8_UNORM] = {55.unpack_rgba_8unorm = &util_format_b8g8r8a8_unorm_unpack_rgba_8unorm_neon,56.unpack_rgba = &util_format_b8g8r8a8_unorm_unpack_rgba_float,57},58};5960const struct util_format_unpack_description *61util_format_unpack_description_neon(enum pipe_format format)62{63/* CPU detect for NEON support. On arm64, it's implied. */64#ifdef PIPE_ARCH_ARM65if (!util_get_cpu_caps()->has_neon)66return NULL;67#endif6869if (format >= ARRAY_SIZE(util_format_unpack_descriptions_neon))70return NULL;7172if (!util_format_unpack_descriptions_neon[format].unpack_rgba)73return NULL;7475return &util_format_unpack_descriptions_neon[format];76}7778#endif /* PIPE_ARCH_AARCH64 | PIPE_ARCH_ARM */798081