Skip to content

Commit

Permalink
loongarch: add loongarch support
Browse files Browse the repository at this point in the history
  • Loading branch information
HecaiYuan committed Jan 10, 2025
1 parent ef5d336 commit 3a57223
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,20 @@ if( VVENC_TARGET_ARCH MATCHES "ARM\|AARCH64" )
set_if_compiler_supports_arm_extensions( FLAG_sve FLAG_sve2 )
endif()

if( VVENC_TARGET_ARCH MATCHES "LOONGARCH64" )
set( VVENC_LOONGARCH64_SIMD_DEFAULT TRUE )

if( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
endif()
endif()

# We enable x86 intrinsics for all target architectures, because they are implemented through SIMD-everywhere on non-x86.
set( VVENC_ENABLE_X86_SIMD TRUE CACHE BOOL "Enable x86 intrinsics" )
set( VVENC_ENABLE_ARM_SIMD ${VVENC_ARM_SIMD_DEFAULT} CACHE BOOL "Enable Arm Neon intrinsics" )
set( VVENC_ENABLE_ARM_SIMD_SVE FALSE CACHE BOOL "Enable Arm SVE intrinsics" )
set( VVENC_ENABLE_ARM_SIMD_SVE2 FALSE CACHE BOOL "Enable Arm SVE2 intrinsics" )
set( VVENC_ENABLE_LOONGARCH64_SIMD_LSX ${VVENC_LOONGARCH64_SIMD_DEFAULT} CACHE BOOL "Enable LoongArch64 LSX intrinsics" )

check_problematic_compiler( VVENC_PROBLEMATIC_COMPILER "MSVC" 19.38 19.39 )
if( VVENC_PROBLEMATIC_COMPILER )
Expand Down Expand Up @@ -119,6 +128,17 @@ if( VVENC_TARGET_ARCH STREQUAL "ARM" )
endif()
endif()

if( VVENC_TARGET_ARCH STREQUAL "LOONGARCH64" )
if( VVENC_ENABLE_LOONGARCH64_SIMD_LSX )
set_if_compiler_supports_flag( FLAG_mlsx -mlsx )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG_mlsx}" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG_mlsx}" )
message( STATUS "LoongArch64 LSX intrinsics enabled" )
else()
message( STATUS "LoongArch64 LSX intrinsics disabled" )
endif()
endif()

if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
# set exception handling
if( MSVC )
Expand Down
2 changes: 2 additions & 0 deletions cmake/modules/vvencCompilerSupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ function( _append_cpu_type_guess output_list input_str )
list( APPEND ret "AARCH64" )
elseif( ${input_lower} MATCHES "arm")
list( APPEND ret "ARM" )
elseif( ${input_lower} MATCHES "loongarch64")
list( APPEND ret "LOONGARCH64" )
endif()

set( ${output_list} ${ret} PARENT_SCOPE )
Expand Down
2 changes: 2 additions & 0 deletions source/Lib/CommonLib/CommonDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ POSSIBILITY OF SUCH DAMAGE.
# define REAL_TARGET_ARM 1
#elif defined( __wasm__ ) || defined( __wasm32__ )
# define REAL_TARGET_WASM 1
#elif defined( __loongarch__ )
# define REAL_TARGET_LOONGARCH 1
#endif

#if defined( TARGET_SIMD_X86 )
Expand Down
2 changes: 2 additions & 0 deletions source/Lib/CommonLib/x86/CommonDefX86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ const static std::map<X86_VEXT, std::string> vext_names{ { UNDEFINED, "" }, { SC
const static std::map<X86_VEXT, std::string> vext_names{ { UNDEFINED, "" }, { SCALAR, "SCALAR" }, { SIMD_EVERYWHERE_EXTENSION_LEVEL, "NEON" } };
# elif defined( REAL_TARGET_WASM )
const static std::map<X86_VEXT, std::string> vext_names{ { UNDEFINED, "" }, { SCALAR, "SCALAR" }, { SIMD_EVERYWHERE_EXTENSION_LEVEL, "WASM" } };
# elif defined( REAL_TARGET_LOONGARCH )
const static std::map<X86_VEXT, std::string> vext_names{ { UNDEFINED, "" }, { SCALAR, "SCALAR" }, { SIMD_EVERYWHERE_EXTENSION_LEVEL, "LSX" } };
# else
const static std::map<X86_VEXT, std::string> vext_names{ { UNDEFINED, "" }, { SCALAR, "SCALAR" }, { SIMD_EVERYWHERE_EXTENSION_LEVEL, "SIMDE" } };
# endif
Expand Down
2 changes: 2 additions & 0 deletions source/Lib/apputils/VVEncAppCfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,8 @@ int parse( int argc, char* argv[], vvenc_config* c, std::ostream& rcOstr )
("SIMD", ignoreParams, "SIMD extension to use (SCALAR, NEON), default: the highest supported extension")
#elif defined( __wasm__ ) || defined( __wasm32__ )
("SIMD", ignoreParams, "SIMD extension to use (SCALAR, WASM), default: the highest supported extension")
#elif defined( __loongarch__ )
("SIMD", ignoreParams, "SIMD extension to use (SCALAR, LSX), default: the highest supported extension")
#else
("SIMD", ignoreParams, "SIMD extension to use (SCALAR, SIMDE), default: the highest supported extension")
# endif
Expand Down

0 comments on commit 3a57223

Please sign in to comment.