Skip to content

Commit 0882550

Browse files
Test and improve GCC support for riscv
Fix #1111
1 parent c188d54 commit 0882550

File tree

2 files changed

+54
-45
lines changed

2 files changed

+54
-45
lines changed

.github/workflows/cross-rvv.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
name: RISC-V RVV cross-compilation build
22
on: [push, pull_request]
33
concurrency:
4-
group: ${{ github.workflow }}-${{ github.job }}-${{ github.ref }}
4+
group: ${{ github.workflow }}-${{ matrix.sys.compiler }}-${{ github.ref }}
55
cancel-in-progress: true
6-
env:
7-
GCC_VERSION: "12"
86
jobs:
97
build:
108
runs-on: ubuntu-latest
119
name: 'RISC-V RVV${{ matrix.vector_bits }}'
1210
strategy:
1311
matrix:
12+
sys:
13+
- { compiler: 'gcc', gcc_runtime: '14'}
14+
- { compiler: 'clang', version: '17', gcc_runtime: '14'}
15+
- { compiler: 'clang', version: '18', gcc_runtime: '14'}
1416
vector_bits:
1517
- 128
1618
- 256
1719
- 512
18-
LLVM_VERSION:
19-
- 17
20-
- 18
2120
steps:
2221
- name: Setup GCC
2322
run: |
2423
sudo apt-get -y -qq update
25-
sudo apt-get -y -qq --no-install-suggests --no-install-recommends install gcc-${GCC_VERSION}-riscv64-linux-gnu g++-${GCC_VERSION}-riscv64-linux-gnu
26-
sudo update-alternatives --install /usr/bin/riscv64-linux-gnu-gcc riscv64-linux-gnu-gcc /usr/bin/riscv64-linux-gnu-gcc-${GCC_VERSION} 20
27-
sudo update-alternatives --install /usr/bin/riscv64-linux-gnu-g++ riscv64-linux-gnu-g++ /usr/bin/riscv64-linux-gnu-g++-${GCC_VERSION} 20
24+
sudo apt-get -y -qq --no-install-suggests --no-install-recommends install gcc-${{ matrix.sys.gcc_runtime }}-riscv64-linux-gnu g++-${{ matrix.sys.gcc_runtime }}-riscv64-linux-gnu
25+
sudo update-alternatives --install /usr/bin/riscv64-linux-gnu-gcc riscv64-linux-gnu-gcc /usr/bin/riscv64-linux-gnu-gcc-${{ matrix.sys.gcc_runtime }} 20
26+
sudo update-alternatives --install /usr/bin/riscv64-linux-gnu-g++ riscv64-linux-gnu-g++ /usr/bin/riscv64-linux-gnu-g++-${{ matrix.sys.gcc_runtime }} 20
2827
- name: Setup LLVM
28+
if: ${{ matrix.sys.compiler == 'clang' }}
2929
run: |
30-
# Install latest LLVM stable
30+
# Install given LLVM version
3131
curl -o llvm.sh https://apt.llvm.org/llvm.sh
3232
chmod u+x llvm.sh
33-
sudo ./llvm.sh ${{ matrix.LLVM_VERSION }}
34-
sudo ln -srf $(which clang-${{ matrix.LLVM_VERSION }}) /usr/bin/clang
35-
sudo ln -srf $(which clang++-${{ matrix.LLVM_VERSION }}) /usr/bin/clang++
33+
sudo ./llvm.sh ${{ matrix.sys.version }}
34+
sudo ln -srf $(which clang-${{ matrix.sys.version }}) /usr/bin/clang
35+
sudo ln -srf $(which clang++-${{ matrix.sys.version }}) /usr/bin/clang++
3636
rm llvm.sh
3737
- name: Setup QEMU
3838
uses: docker/setup-qemu-action@v3.0.0
@@ -53,7 +53,7 @@ jobs:
5353
-DTARGET_ARCH=generic
5454
-DCMAKE_C_FLAGS="-march=rv64gcv_zvl${{ matrix.vector_bits }}b_zba_zbb_zbs -mrvv-vector-bits=zvl"
5555
-DCMAKE_CXX_FLAGS="-march=rv64gcv_zvl${{ matrix.vector_bits }}b_zba_zbb_zbs -mrvv-vector-bits=zvl"
56-
-DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/.github/toolchains/clang-riscv64-linux-gnu.cmake
56+
-DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/.github/toolchains/${{ matrix.sys.compiler }}-riscv64-linux-gnu.cmake
5757
- name: Build
5858
run: cmake --build _build
5959
- name: Testing xsimd

include/xsimd/types/xsimd_rvv_register.hpp

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ namespace xsimd
6262
static constexpr size_t rvv_width_mf4 = XSIMD_RVV_BITS / 4;
6363
static constexpr size_t rvv_width_mf2 = XSIMD_RVV_BITS / 2;
6464
static constexpr size_t rvv_width_m1 = XSIMD_RVV_BITS;
65-
static constexpr size_t rvv_width_m2 = XSIMD_RVV_BITS * 2;
66-
static constexpr size_t rvv_width_m4 = XSIMD_RVV_BITS * 4;
67-
static constexpr size_t rvv_width_m8 = XSIMD_RVV_BITS * 8;
65+
66+
// Cope with gcc limitation, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116484
67+
#define XSIMD_RVV_WIDTH_MF8 (XSIMD_RVV_BITS / 8)
68+
#define XSIMD_RVV_WIDTH_MF4 (XSIMD_RVV_BITS / 4)
69+
#define XSIMD_RVV_WIDTH_MF2 (XSIMD_RVV_BITS / 2)
70+
#define XSIMD_RVV_WIDTH_M1 XSIMD_RVV_BITS
6871

6972
// rvv_type_info is a utility class to convert scalar type and
7073
// bitwidth into rvv register types.
@@ -79,30 +82,30 @@ namespace xsimd
7982
//
8083
template <class T, size_t Width>
8184
struct rvv_type_info;
82-
#define XSIMD_RVV_MAKE_TYPE(scalar, t, s, vmul) \
83-
template <> \
84-
struct rvv_type_info<scalar, rvv_width_m1 * vmul> \
85-
{ \
86-
static constexpr size_t width = rvv_width_m1 * vmul; \
87-
using type = XSIMD_RVV_TYPE(t, s, vmul); \
88-
using byte_type = XSIMD_RVV_TYPE(u, 8, vmul); \
89-
using fixed_type = type __attribute__((riscv_rvv_vector_bits(width))); \
90-
template <class U> \
91-
static XSIMD_INLINE type bitcast(U x) noexcept \
92-
{ \
93-
const auto words = XSIMD_RVV_JOINT5(__riscv_vreinterpret_, u, s, m, vmul)(x); \
94-
return XSIMD_RVV_JOINT5(__riscv_vreinterpret_, t, s, m, vmul)(words); \
95-
} \
96-
template <> \
97-
XSIMD_INLINE type bitcast<type>(type x) noexcept { return x; } \
98-
template <class U> \
99-
static XSIMD_INLINE byte_type as_bytes(U x) noexcept \
100-
{ \
101-
static_assert(std::is_same<U, type>::value, "inconsistent conversion types"); \
102-
const auto words = XSIMD_RVV_JOINT5(__riscv_vreinterpret_, u, s, m, vmul)(x); \
103-
return XSIMD_RVV_JOINT5(__riscv_vreinterpret_, u, 8, m, vmul)(words); \
104-
} \
105-
};
85+
#define XSIMD_RVV_MAKE_TYPE(scalar, t, s, vmul) \
86+
template <> \
87+
struct rvv_type_info<scalar, rvv_width_m1 * vmul> \
88+
{ \
89+
static constexpr size_t width = rvv_width_m1 * vmul; \
90+
using type = XSIMD_RVV_TYPE(t, s, vmul); \
91+
using byte_type = XSIMD_RVV_TYPE(u, 8, vmul); \
92+
using fixed_type = type __attribute__((riscv_rvv_vector_bits(/*width=*/XSIMD_RVV_WIDTH_M1 * vmul))); \
93+
template <class U> \
94+
static XSIMD_INLINE type bitcast(U x) noexcept \
95+
{ \
96+
const auto words = XSIMD_RVV_JOINT5(__riscv_vreinterpret_, u, s, m, vmul)(x); \
97+
return XSIMD_RVV_JOINT5(__riscv_vreinterpret_, t, s, m, vmul)(words); \
98+
} \
99+
template <class U> \
100+
static XSIMD_INLINE byte_type as_bytes(U x) noexcept \
101+
{ \
102+
static_assert(std::is_same<U, type>::value, "inconsistent conversion types"); \
103+
const auto words = XSIMD_RVV_JOINT5(__riscv_vreinterpret_, u, s, m, vmul)(x); \
104+
return XSIMD_RVV_JOINT5(__riscv_vreinterpret_, u, 8, m, vmul)(words); \
105+
} \
106+
}; \
107+
template <> \
108+
XSIMD_INLINE XSIMD_RVV_TYPE(t, s, vmul) rvv_type_info<scalar, rvv_width_m1 * vmul>::bitcast<XSIMD_RVV_TYPE(t, s, vmul)>(XSIMD_RVV_TYPE(t, s, vmul) x) noexcept { return x; }
106109

107110
#define XSIMD_RVV_MAKE_TYPES(vmul) \
108111
XSIMD_RVV_MAKE_TYPE(int8_t, i, 8, vmul) \
@@ -235,17 +238,17 @@ namespace xsimd
235238
template <>
236239
struct semitype<2>
237240
{
238-
using type = vuint8mf2_t __attribute__((riscv_rvv_vector_bits(rvv_width_mf2)));
241+
using type = vuint8mf2_t __attribute__((riscv_rvv_vector_bits(XSIMD_RVV_WIDTH_MF2)));
239242
};
240243
template <>
241244
struct semitype<4>
242245
{
243-
using type = vuint8mf4_t __attribute__((riscv_rvv_vector_bits(rvv_width_mf4)));
246+
using type = vuint8mf4_t __attribute__((riscv_rvv_vector_bits(XSIMD_RVV_WIDTH_MF4)));
244247
};
245248
template <>
246249
struct semitype<8>
247250
{
248-
using type = vuint8mf8_t __attribute__((riscv_rvv_vector_bits(rvv_width_mf8)));
251+
using type = vuint8mf8_t __attribute__((riscv_rvv_vector_bits(XSIMD_RVV_WIDTH_MF8)));
249252
};
250253
using fixed_type = typename semitype<divisor>::type;
251254
using super::as_bytes;
@@ -374,7 +377,7 @@ namespace xsimd
374377
struct rvv_bool
375378
{
376379
using bool_info = rvv_bool_info<rvv_width_m1 * sizeof(T) * 8 / Width>;
377-
using storage_type = vuint8m1_t __attribute__((riscv_rvv_vector_bits(rvv_width_m1)));
380+
using storage_type = vuint8m1_t __attribute__((riscv_rvv_vector_bits(XSIMD_RVV_WIDTH_M1)));
378381
using type = typename bool_info::type;
379382
storage_type value;
380383
rvv_bool() = default;
@@ -489,6 +492,12 @@ namespace xsimd
489492
using type = detail::rvv_bool_simd_register<T>;
490493
};
491494
} // namespace types
495+
496+
#undef XSIMD_RVV_WIDTH_MF8
497+
#undef XSIMD_RVV_WIDTH_MF4
498+
#undef XSIMD_RVV_WIDTH_MF2
499+
#undef XSIMD_RVV_WIDTH_M1
500+
492501
#else
493502
using rvv = detail::rvv<0xFFFFFFFF>;
494503
#endif

0 commit comments

Comments
 (0)