Skip to content

Commit bb7a195

Browse files
authored
Move SVE length check to a veneer (#502)
1 parent d055945 commit bb7a195

File tree

4 files changed

+109
-33
lines changed

4 files changed

+109
-33
lines changed

Source/astcenccli_entry.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,23 @@
1818
/**
1919
* @brief Application entry point.
2020
*
21-
* This module contains the command line entry point which also performs the
22-
* role of validating the host extended ISA support meets the needs of the
23-
* tools.
21+
* This module contains the first command line entry point veneer, used to
22+
* validate that the host extended ISA availability matches the tool build.
23+
* It is compiled without any extended ISA support so it's guaranteed to be
24+
* executable without any invalid instruction errors.
2425
*/
2526

2627
#include <cstdio>
2728

2829
/**
29-
* @brief The main entry point.
30+
* @brief The main veneer entry point.
3031
*
3132
* @param argc The number of arguments.
3233
* @param argv The vector of arguments.
3334
*
3435
* @return 0 on success, non-zero otherwise.
3536
*/
36-
int astcenc_main(
37+
int astcenc_main_veneer(
3738
int argc,
3839
char **argv);
3940

@@ -311,5 +312,5 @@ int main(
311312
return 1;
312313
}
313314

314-
return astcenc_main(argc, argv);
315+
return astcenc_main_veneer(argc, argv);
315316
}

Source/astcenccli_entry2.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// ----------------------------------------------------------------------------
3+
// Copyright 2024 Arm Limited
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
6+
// use this file except in compliance with the License. You may obtain a copy
7+
// of the License at:
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
// License for the specific language governing permissions and limitations
15+
// under the License.
16+
// ----------------------------------------------------------------------------
17+
18+
/**
19+
* @brief Application entry point second veneer.
20+
*
21+
* This module contains the second command line entry point veneer, used to
22+
* validate that Arm SVE vector width matches the tool build. When used, it is
23+
* compiled with SVE ISA support but without any vector legnth override, so it
24+
* will see the native SVE vector length exposed to the application.
25+
*/
26+
27+
#include <cstdio>
28+
29+
#if ASTCENC_SVE != 0
30+
#include <arm_sve.h>
31+
#endif
32+
33+
/**
34+
* @brief The main entry point.
35+
*
36+
* @param argc The number of arguments.
37+
* @param argv The vector of arguments.
38+
*
39+
* @return 0 on success, non-zero otherwise.
40+
*/
41+
int astcenc_main(
42+
int argc,
43+
char **argv);
44+
45+
/**
46+
* @brief Print a formatted string to stderr.
47+
*/
48+
template<typename ... _Args>
49+
static inline void print_error(
50+
const char* format,
51+
_Args...args
52+
) {
53+
fprintf(stderr, format, args...);
54+
}
55+
56+
int astcenc_main_veneer(
57+
int argc,
58+
char **argv
59+
) {
60+
#if ASTCENC_SVE != 0
61+
// svcntw() return compile-time length if used with -msve-vector-bits
62+
if (svcntw() != ASTCENC_SVE)
63+
{
64+
int bits = ASTCENC_SVE * 32;
65+
print_error("ERROR: Host SVE support is not a %u-bit implementation\n", bits);
66+
return 1;
67+
}
68+
#endif
69+
70+
return astcenc_main(argc, argv);
71+
}

Source/astcenccli_toplevel.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,25 +1889,12 @@ static void print_diagnostic_images(
18891889
*
18901890
* @return 0 on success, non-zero otherwise.
18911891
*/
1892-
int
1893-
astcenc_main(
1892+
int astcenc_main(
18941893
int argc,
18951894
char **argv
18961895
) {
18971896
set_thread_name("astc main");
18981897

1899-
#if ASTCENC_SVE != 0
1900-
// Do this check here because is needs SVE instructions so cannot be in
1901-
// the veneer check which is compiled as stock Armv8. We know we have SVE
1902-
// by the time we get this far, but not the vector width.
1903-
if (svcntw() != ASTCENC_SVE)
1904-
{
1905-
uint32_t bits = ASTCENC_SVE * 32;
1906-
print_error("ERROR: Host does not implement %u bit SVE ISA extension\n", bits);
1907-
return false;
1908-
}
1909-
#endif
1910-
19111898
double start_time = get_time();
19121899

19131900
if (argc < 2)

Source/cmake_core.cmake

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# ----------------------------------------------------------------------------
3-
# Copyright 2020-2023 Arm Limited
3+
# Copyright 2020-2024 Arm Limited
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
66
# use this file except in compliance with the License. You may obtain a copy
@@ -105,9 +105,14 @@ endif()
105105
if(${ASTCENC_CLI})
106106
# Veneer is compiled without any extended ISA so we can safely do
107107
# ISA compatability checks without triggering a SIGILL
108-
add_library(${ASTCENC_TARGET}-veneer
108+
add_library(${ASTCENC_TARGET}-veneer1
109109
astcenccli_entry.cpp)
110110

111+
# Veneer is compiled with extended ISA but without vector length overrides
112+
# so we can safely do SVE vector length compatability checks
113+
add_library(${ASTCENC_TARGET}-veneer2
114+
astcenccli_entry2.cpp)
115+
111116
add_executable(${ASTCENC_TARGET}
112117
astcenccli_error_metrics.cpp
113118
astcenccli_image.cpp
@@ -119,11 +124,12 @@ if(${ASTCENC_CLI})
119124

120125
target_link_libraries(${ASTCENC_TARGET}
121126
PRIVATE
122-
${ASTCENC_TARGET}-veneer
127+
${ASTCENC_TARGET}-veneer1
128+
${ASTCENC_TARGET}-veneer2
123129
${ASTCENC_TARGET}-static)
124130
endif()
125131

126-
macro(astcenc_set_properties ASTCENC_TARGET_NAME ASTCENC_IS_VENEER)
132+
macro(astcenc_set_properties ASTCENC_TARGET_NAME ASTCENC_VENEER_TYPE)
127133

128134
target_compile_features(${ASTCENC_TARGET_NAME}
129135
PRIVATE
@@ -306,11 +312,17 @@ macro(astcenc_set_properties ASTCENC_TARGET_NAME ASTCENC_IS_VENEER)
306312
ASTCENC_POPCNT=0
307313
ASTCENC_F16C=0)
308314

309-
# Enable SVE
310-
if (NOT ${ASTCENC_IS_VENEER})
315+
# Enable SVE in the core library
316+
if (NOT ${ASTCENC_VENEER_TYPE})
311317
target_compile_options(${ASTCENC_TARGET_NAME}
312318
PRIVATE
313319
-march=armv8-a+sve -msve-vector-bits=256)
320+
321+
# Enable SVE without fixed vector length in the veneer
322+
elseif (${ASTCENC_VENEER_TYPE} EQUAL 2)
323+
target_compile_options(${ASTCENC_TARGET_NAME}
324+
PRIVATE
325+
-march=armv8-a+sve)
314326
endif()
315327

316328
elseif(${ASTCENC_ISA_SIMD} MATCHES "sse2")
@@ -341,7 +353,7 @@ macro(astcenc_set_properties ASTCENC_TARGET_NAME ASTCENC_IS_VENEER)
341353
ASTCENC_POPCNT=1
342354
ASTCENC_F16C=0)
343355

344-
if (${ASTCENC_IS_VENEER})
356+
if (${ASTCENC_VENEER_TYPE} GREATER 0)
345357
# Force SSE2 on AppleClang (normally SSE4.1 is the default)
346358
target_compile_options(${ASTCENC_TARGET_NAME}
347359
PRIVATE
@@ -366,7 +378,7 @@ macro(astcenc_set_properties ASTCENC_TARGET_NAME ASTCENC_IS_VENEER)
366378
ASTCENC_POPCNT=1
367379
ASTCENC_F16C=1)
368380

369-
if (${ASTCENC_IS_VENEER})
381+
if (${ASTCENC_VENEER_TYPE} GREATER 0)
370382
# Force SSE2 on AppleClang (normally SSE4.1 is the default)
371383
target_compile_options(${ASTCENC_TARGET_NAME}
372384
PRIVATE
@@ -388,7 +400,7 @@ macro(astcenc_set_properties ASTCENC_TARGET_NAME ASTCENC_IS_VENEER)
388400
# which significantly improve performance. Note that this DOES reduce
389401
# image quality by up to 0.2 dB (normally much less), but buys an
390402
# average of 10-15% performance improvement ...
391-
if((NOT ${ASTCENC_INVARIANCE}) AND (NOT ${ASTCENC_IS_VENEER}))
403+
if((NOT ${ASTCENC_INVARIANCE}) AND (NOT ${ASTCENC_VENEER_TYPE}))
392404
target_compile_options(${ASTCENC_TARGET_NAME}
393405
PRIVATE
394406
$<${is_gnu_fe}:-mfma>)
@@ -447,14 +459,19 @@ if(${ASTCENC_SHAREDLIB})
447459
endif()
448460

449461
if(${ASTCENC_CLI})
450-
astcenc_set_properties(${ASTCENC_TARGET}-veneer ON)
451-
astcenc_set_properties(${ASTCENC_TARGET} OFF)
462+
astcenc_set_properties(${ASTCENC_TARGET}-veneer1 1)
463+
astcenc_set_properties(${ASTCENC_TARGET}-veneer2 2)
464+
astcenc_set_properties(${ASTCENC_TARGET} 0)
452465

453-
target_compile_options(${ASTCENC_TARGET}
466+
target_compile_options(${ASTCENC_TARGET}-veneer1
454467
PRIVATE
455468
$<${is_msvc_fe}:/W3>)
456469

457-
target_compile_options(${ASTCENC_TARGET}-veneer
470+
target_compile_options(${ASTCENC_TARGET}-veneer2
471+
PRIVATE
472+
$<${is_msvc_fe}:/W3>)
473+
474+
target_compile_options(${ASTCENC_TARGET}
458475
PRIVATE
459476
$<${is_msvc_fe}:/W3>)
460477

0 commit comments

Comments
 (0)