This commit is contained in:
2026-06-14 19:09:18 +01:00
parent 14bd1a9271
commit 13fa90a0e9
3958 changed files with 999286 additions and 4 deletions
@@ -0,0 +1,51 @@
# SPDX-License-Identifier: Apache-2.0
# ----------------------------------------------------------------------------
# Copyright 2020-2024 Arm Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy
# of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
set(ASTCENC_ARTIFACTS native none sve_256 sve_128 neon avx2 sse4.1 sse2)
set(ASTCENC_CONFIGS ${ASTCENC_ISA_NATIVE} ${ASTCENC_ISA_NONE} ${ASTCENC_ISA_SVE_256} ${ASTCENC_ISA_SVE_128} ${ASTCENC_ISA_NEON} ${ASTCENC_ISA_AVX2} ${ASTCENC_ISA_SSE41} ${ASTCENC_ISA_SSE2})
list(LENGTH ASTCENC_ARTIFACTS ASTCENC_ARTIFACTS_LEN)
math(EXPR ASTCENC_ARTIFACTS_LEN "${ASTCENC_ARTIFACTS_LEN} - 1")
foreach(INDEX RANGE ${ASTCENC_ARTIFACTS_LEN})
list(GET ASTCENC_ARTIFACTS ${INDEX} ASTCENC_ARTIFACT)
list(GET ASTCENC_CONFIGS ${INDEX} ASTCENC_CONFIG)
if(${ASTCENC_CONFIG})
set(ASTCENC_ISA_SIMD ${ASTCENC_ARTIFACT})
if(${ASTCENC_ISA_SIMD} MATCHES "sve_256")
# Not supported on macOS
elseif(${ASTCENC_ISA_SIMD} MATCHES "sve_128")
# Not supported on macOS
elseif(${ASTCENC_ISA_SIMD} MATCHES "neon")
set(CMAKE_OSX_ARCHITECTURES arm64)
elseif(${ASTCENC_ISA_SIMD} MATCHES "sse2")
set(CMAKE_OSX_ARCHITECTURES x86_64)
elseif(${ASTCENC_ISA_SIMD} MATCHES "sse4.1")
set(CMAKE_OSX_ARCHITECTURES x86_64)
elseif(${ASTCENC_ISA_SIMD} MATCHES "avx2")
set(CMAKE_OSX_ARCHITECTURES x86_64h)
elseif(${ASTCENC_ISA_SIMD} MATCHES "none")
# Using "none" uses implicit architecture
elseif(${ASTCENC_ISA_SIMD} MATCHES "native")
# Using "native" uses implicit architecture
else()
message(FATAL_ERROR "'${ASTCENC_ISA_SIMD}' is unknown ISA")
endif()
include(cmake_core.cmake)
endif()
endforeach()
@@ -0,0 +1,198 @@
# SPDX-License-Identifier: Apache-2.0
# ----------------------------------------------------------------------------
# Copyright 2020-2025 Arm Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy
# of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
include(../cmake_compiler.cmake)
set(ASTCENC_TEST test-unit-${ASTCENC_ISA_SIMD})
add_executable(${ASTCENC_TEST})
set_property(TARGET ${ASTCENC_TEST}
PROPERTY
CXX_STANDARD 17)
# Enable LTO under the conditions where the codec library will use LTO.
# The library link will fail if the settings don't match
if(${ASTCENC_CLI})
set_property(TARGET ${ASTCENC_TEST}
PROPERTY
INTERPROCEDURAL_OPTIMIZATION_RELEASE True)
endif()
# Use a static runtime on MSVC builds (ignored on non-MSVC compilers)
set_property(TARGET ${ASTCENC_TEST}
PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
target_sources(${ASTCENC_TEST}
PRIVATE
test_simd.cpp
test_softfloat.cpp
test_decode.cpp)
target_include_directories(${ASTCENC_TEST}
PRIVATE
${gtest_SOURCE_DIR}/include)
target_link_libraries(${ASTCENC_TEST}
PRIVATE
astcenc-${ASTCENC_ISA_SIMD}-static)
target_compile_options(${ASTCENC_TEST}
PRIVATE
# Use pthreads on Linux/macOS
$<$<PLATFORM_ID:Linux,Darwin>:-pthread>
# MSVC compiler defines
$<${is_msvc_fe}:/EHsc>
$<$<AND:$<BOOL:${ASTCENC_WERROR}>,${is_msvc_fe}>:/WX>
$<${is_msvccl}:/wd4324>
# G++ and Clang++ compiler defines
$<${is_gnu_fe}:-Wall>
$<${is_gnu_fe}:-Wextra>
$<${is_gnu_fe}:-Wpedantic>
$<$<AND:$<BOOL:${ASTCENC_WERROR}>,${is_gnu_fe}>:-Werror>
$<${is_gnu_fe}:-Wshadow>
$<${is_gnu_fe}:-Wdouble-promotion>
$<${is_clang}:-Wdocumentation>
# Hide noise thrown up by Clang 10 and clang-cl
$<${is_gnu_fe}:-Wno-unknown-warning-option>
$<${is_gnu_fe}:-Wno-c++98-compat-pedantic>
$<${is_gnu_fe}:-Wno-c++98-c++11-compat-pedantic>
$<${is_gnu_fe}:-Wno-float-equal>
$<${is_gnu_fe}:-Wno-overriding-option>
$<${is_gnu_fe}:-Wno-unsafe-buffer-usage>
$<${is_clang}:-Wno-switch-default>
# Ignore things that the googletest build triggers
$<${is_gnu_fe}:-Wno-unknown-warning-option>
$<${is_gnu_fe}:-Wno-double-promotion>
$<${is_gnu_fe}:-Wno-undef>
$<${is_gnu_fe}:-Wno-reserved-identifier>
$<${is_gnu_fe}:-Wno-global-constructors>)
# Set up configuration for SIMD ISA builds
if(${ASTCENC_ISA_SIMD} MATCHES "none")
target_compile_definitions(${ASTCENC_TEST}
PRIVATE
ASTCENC_NEON=0
ASTCENC_SVE=0
ASTCENC_SSE=0
ASTCENC_AVX=0
ASTCENC_POPCNT=0
ASTCENC_F16C=0)
if(${ASTCENC_BIG_ENDIAN})
target_compile_definitions(${ASTCENC_TEST}
PRIVATE
ASTCENC_BIG_ENDIAN=1)
endif()
elseif(${ASTCENC_ISA_SIMD} MATCHES "neon")
target_compile_definitions(${ASTCENC_TEST}
PRIVATE
ASTCENC_NEON=1
ASTCENC_SVE=0
ASTCENC_SSE=0
ASTCENC_AVX=0
ASTCENC_POPCNT=0
ASTCENC_F16C=0)
elseif(${ASTCENC_ISA_SIMD} MATCHES "sve_256")
target_compile_definitions(${ASTCENC_TEST}
PRIVATE
ASTCENC_NEON=1
ASTCENC_SVE=8
ASTCENC_SSE=0
ASTCENC_AVX=0
ASTCENC_POPCNT=0
ASTCENC_F16C=0)
# Enable SVE
target_compile_options(${ASTCENC_TEST}
PRIVATE
-march=armv8-a+sve -msve-vector-bits=256)
elseif(${ASTCENC_ISA_SIMD} MATCHES "sve_128")
target_compile_definitions(${ASTCENC_TEST}
PRIVATE
ASTCENC_NEON=1
ASTCENC_SVE=4
ASTCENC_SSE=0
ASTCENC_AVX=0
ASTCENC_POPCNT=0
ASTCENC_F16C=0)
# Enable SVE
target_compile_options(${ASTCENC_TEST}
PRIVATE
-march=armv8-a+sve)
elseif(${ASTCENC_ISA_SIMD} MATCHES "sse2")
target_compile_definitions(${ASTCENC_TEST}
PRIVATE
ASTCENC_NEON=0
ASTCENC_SVE=0
ASTCENC_SSE=20
ASTCENC_AVX=0
ASTCENC_POPCNT=0
ASTCENC_F16C=0)
target_compile_options(${ASTCENC_TEST}
PRIVATE
$<$<CXX_COMPILER_ID:${GNU_LIKE}>:-msse2>)
elseif(${ASTCENC_ISA_SIMD} MATCHES "sse4.1")
target_compile_definitions(${ASTCENC_TEST}
PRIVATE
ASTCENC_NEON=0
ASTCENC_SVE=0
ASTCENC_SSE=41
ASTCENC_AVX=0
ASTCENC_POPCNT=1
ASTCENC_F16C=0)
target_compile_options(${ASTCENC_TEST}
PRIVATE
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-msse4.1 -mpopcnt>)
elseif(${ASTCENC_ISA_SIMD} MATCHES "avx2")
target_compile_definitions(${ASTCENC_TEST}
PRIVATE
ASTCENC_NEON=0
ASTCENC_SVE=0
ASTCENC_SSE=41
ASTCENC_AVX=2
ASTCENC_POPCNT=1
ASTCENC_F16C=1)
target_compile_options(${ASTCENC_TEST}
PRIVATE
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-mavx2 -mpopcnt -mf16c>
$<$<CXX_COMPILER_ID:MSVC>:/arch:AVX2>)
endif()
target_link_libraries(${ASTCENC_TEST}
PRIVATE
gtest_main)
add_test(NAME ${ASTCENC_TEST}
COMMAND ${ASTCENC_TEST})
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: Apache-2.0
// ----------------------------------------------------------------------------
// Copyright 2023 Arm Limited
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
// ----------------------------------------------------------------------------
/**
* @brief Unit tests for the vectorized SIMD functionality.
*/
#include <limits>
#include "gtest/gtest.h"
#include "../astcenc.h"
namespace astcenc
{
/** @brief Test harness for exploring issue #447. */
TEST(decode, decode12x12)
{
astcenc_error status;
astcenc_config config;
astcenc_context* context;
static const astcenc_swizzle swizzle {
ASTCENC_SWZ_R, ASTCENC_SWZ_G, ASTCENC_SWZ_B, ASTCENC_SWZ_A
};
uint8_t data[16] {
#if 0
0x84,0x00,0x38,0xC8,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xB3,0x4D,0x78
#else
0x29,0x00,0x1A,0x97,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xCF,0x97,0x86
#endif
};
uint8_t output[12*12*4];
astcenc_config_init(ASTCENC_PRF_LDR, 12, 12, 1, ASTCENC_PRE_MEDIUM, 0, &config);
status = astcenc_context_alloc(&config, 1, &context);
EXPECT_EQ(status, ASTCENC_SUCCESS);
astcenc_image image;
image.dim_x = 12;
image.dim_y = 12;
image.dim_z = 1;
image.data_type = ASTCENC_TYPE_U8;
uint8_t* slices = output;
image.data = reinterpret_cast<void**>(&slices);
status = astcenc_decompress_image(context, data, 16, &image, &swizzle, 0);
EXPECT_EQ(status, ASTCENC_SUCCESS);
#if 0
for (int y = 0; y < 12; y++)
{
for (int x = 0; x < 12; x++)
{
uint8_t* pixel = output + (12 * 4 * y) + (4 * x);
printf("[%2dx%2d] = %03d, %03d, %03d, %03d\n", x, y, pixel[0], pixel[1], pixel[2], pixel[3]);
}
}
#endif
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: Apache-2.0
// ----------------------------------------------------------------------------
// Copyright 2021 Arm Limited
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
// ----------------------------------------------------------------------------
/**
* @brief Unit tests for the software half-float library.
*/
#include "gtest/gtest.h"
#include "../astcenc_internal.h"
namespace astcenc
{
#if (ASTCENC_F16C == 0) && (ASTCENC_NEON == 0)
/** @brief Test normal numbers. */
TEST(softfloat, FP16NormalNumbers)
{
float result = sf16_to_float((15 << 10) + 1);
EXPECT_NEAR(result, 1.00098f, 0.00005f);
}
/** @brief Test denormal numbers. */
TEST(softfloat, FP16DenormalNumbers)
{
float result = sf16_to_float((0 << 10) + 1);
EXPECT_NEAR(result, 5.96046e-08f, 0.00005f);
}
/** @brief Test zero. */
TEST(softfloat, FP16Zero)
{
float result = sf16_to_float(0x0000);
EXPECT_EQ(result, 0.0f);
}
/** @brief Test infinity. */
TEST(softfloat, FP16Infinity)
{
float result = sf16_to_float((31 << 10) + 0);
EXPECT_TRUE(std::isinf(result));
}
/** @brief Test NaN. */
TEST(softfloat, FP16NaN)
{
float result = sf16_to_float(0xFFFF);
EXPECT_TRUE(std::isnan(result));
}
#endif
}