Update
This commit is contained in:
74
3rdparty/libyuv/riscv_script/prepare_toolchain_qemu.sh
vendored
Normal file
74
3rdparty/libyuv/riscv_script/prepare_toolchain_qemu.sh
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
#!/bin/bash
|
||||
set -ev
|
||||
|
||||
# Download & build RISC-V Clang toolchain & QEMU emulator.
|
||||
# RISC-V Clang is for cross compile with the RISC-V Vector ISA.
|
||||
# RISC-V QEMU is used to run the test suite.
|
||||
#
|
||||
# Requirements: Linux host w/ working C++ compiler, git, cmake, ninja, wget, tar
|
||||
|
||||
# NOTE: this script must be run from the top-level directory of the LIBYUV_SRC_DIR.
|
||||
|
||||
RISCV_TRIPLE="riscv64-unknown-linux-gnu"
|
||||
RISCV_QEMU="qemu-riscv64"
|
||||
|
||||
LIBYUV_SRC_DIR=$(pwd)
|
||||
BUILD_DIR="$LIBYUV_SRC_DIR"/build-toolchain-qemu
|
||||
INSTALL_QEMU="$BUILD_DIR"/riscv-qemu
|
||||
INSTALL_CLANG="$BUILD_DIR"/riscv-clang
|
||||
|
||||
LLVM_VERSION="16.0.0"
|
||||
LLVM_NAME=llvm-project-"$LLVM_VERSION".src
|
||||
|
||||
RISCV_GNU_TOOLCHAIN="$BUILD_DIR"/riscv-gnu-toolchain
|
||||
RISCV_CLANG_TOOLCHAIN="$BUILD_DIR"/"$LLVM_NAME"
|
||||
|
||||
QEMU_NAME="qemu-7.0.0"
|
||||
|
||||
mkdir -p "$BUILD_DIR"
|
||||
cd "$BUILD_DIR"
|
||||
|
||||
# Download and install RISC-V GNU Toolchain (needed to build Clang)
|
||||
if [ ! -d "$RISCV_GNU_TOOLCHAIN" ]
|
||||
then
|
||||
git clone git@github.com:riscv/riscv-gnu-toolchain.git
|
||||
pushd "$RISCV_GNU_TOOLCHAIN"
|
||||
git submodule update --init --recursive
|
||||
./configure --with-cmodel=medany --prefix="$INSTALL_CLANG"
|
||||
ionice nice make linux -j `nproc` install
|
||||
popd
|
||||
fi
|
||||
|
||||
# Download Clang toolchain & build cross compiler
|
||||
if [ ! -d "$RISCV_CLANG_TOOLCHAIN" ]
|
||||
then
|
||||
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-"$LLVM_VERSION"/"$LLVM_NAME".tar.xz
|
||||
tar xvJf "$LLVM_NAME".tar.xz
|
||||
pushd "$RISCV_CLANG_TOOLCHAIN"
|
||||
cmake -DCMAKE_INSTALL_PREFIX="$INSTALL_CLANG" \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DLLVM_TARGETS_TO_BUILD="RISCV" \
|
||||
-DLLVM_ENABLE_PROJECTS="clang" \
|
||||
-DLLVM_DEFAULT_TARGET_TRIPLE="$RISCV_TRIPLE" \
|
||||
-DLLVM_INSTALL_TOOLCHAIN_ONLY=On \
|
||||
-DDEFAULT_SYSROOT=../sysroot \
|
||||
-G "Ninja" "$RISCV_CLANG_TOOLCHAIN"/llvm
|
||||
ionice nice ninja -j `nproc`
|
||||
ionice nice ninja -j `nproc` install
|
||||
popd
|
||||
pushd "$INSTALL_CLANG"/bin
|
||||
ln -sf clang "$RISCV_TRIPLE"-clang
|
||||
ln -sf clang++ "$RISCV_TRIPLE"-clang++
|
||||
popd
|
||||
fi
|
||||
|
||||
# Download QEMU and build the riscv64 Linux usermode emulator
|
||||
if [ ! -d "$QEMU_NAME" ]
|
||||
then
|
||||
wget https://download.qemu.org/"$QEMU_NAME".tar.xz
|
||||
tar xvJf "$QEMU_NAME".tar.xz
|
||||
pushd "$QEMU_NAME"
|
||||
./configure --target-list=riscv64-linux-user --prefix="$INSTALL_QEMU"
|
||||
ionice nice make -j `nproc` install
|
||||
popd
|
||||
fi
|
||||
56
3rdparty/libyuv/riscv_script/riscv-clang.cmake
vendored
Normal file
56
3rdparty/libyuv/riscv_script/riscv-clang.cmake
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
set(CMAKE_CROSSCOMPILING TRUE)
|
||||
set(CMAKE_SYSTEM_NAME "Linux")
|
||||
set(CMAKE_SYSTEM_PROCESSOR "riscv64")
|
||||
|
||||
option(USE_RVV "Enable riscv vector or not." ON)
|
||||
option(USE_AUTO_VECTORIZER "Enable riscv auto vectorizer or not." OFF)
|
||||
|
||||
# Avoid to use system path for cross-compile
|
||||
set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE)
|
||||
|
||||
set(TOOLCHAIN_PATH "" CACHE STRING "The toolcahin path.")
|
||||
if(NOT TOOLCHAIN_PATH)
|
||||
set(TOOLCHAIN_PATH ${CMAKE_SOURCE_DIR}/build-toolchain-qemu/riscv-clang)
|
||||
endif()
|
||||
|
||||
set(TOOLCHAIN_PREFIX "riscv64-unknown-linux-gnu-" CACHE STRING "The toolcahin prefix.")
|
||||
|
||||
# toolchain setting
|
||||
set(CMAKE_C_COMPILER "${TOOLCHAIN_PATH}/bin/${TOOLCHAIN_PREFIX}clang")
|
||||
set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PATH}/bin/${TOOLCHAIN_PREFIX}clang++")
|
||||
|
||||
# CMake will just use the host-side tools for the following tools, so we setup them here.
|
||||
set(CMAKE_C_COMPILER_AR "${TOOLCHAIN_PATH}/bin/llvm-ar")
|
||||
set(CMAKE_CXX_COMPILER_AR "${TOOLCHAIN_PATH}/bin/llvm-ar")
|
||||
set(CMAKE_C_COMPILER_RANLIB "${TOOLCHAIN_PATH}/bin/llvm-ranlib")
|
||||
set(CMAKE_CXX_COMPILER_RANLIB "${TOOLCHAIN_PATH}/bin/llvm-ranlib")
|
||||
set(CMAKE_OBJDUMP "${TOOLCHAIN_PATH}/bin/llvm-objdump")
|
||||
set(CMAKE_OBJCOPY "${TOOLCHAIN_PATH}/bin/llvm-objcopy")
|
||||
|
||||
# compile options
|
||||
set(RISCV_COMPILER_FLAGS "" CACHE STRING "Compile flags")
|
||||
# if user provides RISCV_COMPILER_FLAGS, appeding compile flags is avoided.
|
||||
if(RISCV_COMPILER_FLAGS STREQUAL "")
|
||||
message(STATUS "USE_RVV: ${USE_RVV}")
|
||||
message(STATUS "USE_AUTO_VECTORIZER: ${USE_AUTO_VECTORIZER}")
|
||||
if(USE_RVV)
|
||||
list(APPEND RISCV_COMPILER_FLAGS "-march=rv64gcv")
|
||||
if(NOT USE_AUTO_VECTORIZER)
|
||||
# Disable auto-vectorizer
|
||||
add_compile_options(-fno-vectorize -fno-slp-vectorize)
|
||||
endif()
|
||||
else()
|
||||
list(APPEND RISCV_COMPILER_FLAGS "-march=rv64gc")
|
||||
endif()
|
||||
endif()
|
||||
add_compile_options("-Wuninitialized")
|
||||
message(STATUS "RISCV_COMPILER_FLAGS: ${RISCV_COMPILER_FLAGS}")
|
||||
|
||||
set(CMAKE_C_FLAGS "${RISCV_COMPILER_FLAGS} ${CMAKE_C_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${RISCV_COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}")
|
||||
|
||||
set(RISCV_LINKER_FLAGS "-lstdc++ -lpthread -lm -ldl")
|
||||
set(RISCV_LINKER_FLAGS_EXE)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${RISCV_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
|
||||
set(CMAKE_MODULE_LINKER_FLAGS "${RISCV_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${RISCV_LINKER_FLAGS} ${RISCV_LINKER_FLAGS_EXE} ${CMAKE_EXE_LINKER_FLAGS}")
|
||||
15
3rdparty/libyuv/riscv_script/run_qemu.sh
vendored
Normal file
15
3rdparty/libyuv/riscv_script/run_qemu.sh
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
set -x
|
||||
set -e
|
||||
|
||||
USE_RVV="${USE_RVV:-OFF}"
|
||||
TOOLCHAIN_PATH="${TOOLCHAIN_PATH:-../../build-toolchain-qemu/riscv-clang}"
|
||||
QEMU_PREFIX_PATH="${QEMU_PREFIX_PATH:-../../build-toolchain-qemu/riscv-qemu/}"
|
||||
|
||||
if [ "${USE_RVV}" = "ON" ];then
|
||||
QEMU_OPTION="-cpu rv64,zba=true,zbb=true,zbc=true,zbs=true,v=true,vlen=512,elen=64,vext_spec=v1.0 -L ${TOOLCHAIN_PATH}/sysroot"
|
||||
else
|
||||
QEMU_OPTION="-cpu rv64,zba=true,zbb=true,zbc=true,zbs=true -L ${TOOLCHAIN_PATH}/sysroot"
|
||||
fi
|
||||
|
||||
$QEMU_PREFIX_PATH/bin/qemu-riscv64 $QEMU_OPTION $@
|
||||
Reference in New Issue
Block a user