diff --git a/clang/include/clang/Basic/BuiltinsRISCVCOREV.def b/clang/include/clang/Basic/BuiltinsRISCVCOREV.def index 60aee2683a84..cefdb48110d6 100644 --- a/clang/include/clang/Basic/BuiltinsRISCVCOREV.def +++ b/clang/include/clang/Basic/BuiltinsRISCVCOREV.def @@ -165,15 +165,15 @@ TARGET_BUILTIN(simd_cplxmul_i, "UZiUZiUZiUZiIUc", "nc", "xcvsimd") TARGET_BUILTIN(simd_cplxconj, "UZiUZi", "nc", "xcvsimd") TARGET_BUILTIN(simd_subrotmj, "UZiUZiUZiIUc", "nc", "xcvsimd") -TARGET_BUILTIN(bitmanip_extract, "UZiUZiUs", "nc", "xcvbitmanip") +TARGET_BUILTIN(bitmanip_extract, "ZiZiUs", "nc", "xcvbitmanip") TARGET_BUILTIN(bitmanip_extractu, "UZiUZiUs", "nc", "xcvbitmanip") TARGET_BUILTIN(bitmanip_insert, "UZiUZiUsUZi", "nc", "xcvbitmanip") TARGET_BUILTIN(bitmanip_bclr, "UZiUZiUs", "nc", "xcvbitmanip") TARGET_BUILTIN(bitmanip_bset, "UZiUZiUs", "nc", "xcvbitmanip") -TARGET_BUILTIN(bitmanip_ff1, "UZiUZi", "nc", "xcvbitmanip") -TARGET_BUILTIN(bitmanip_fl1, "UZiUZi", "nc", "xcvbitmanip") -TARGET_BUILTIN(bitmanip_clb, "UZiUZi", "nc", "xcvbitmanip") -TARGET_BUILTIN(bitmanip_cnt, "UZiUZi", "nc", "xcvbitmanip") +TARGET_BUILTIN(bitmanip_ff1, "UZcUZi", "nc", "xcvbitmanip") +TARGET_BUILTIN(bitmanip_fl1, "UZcUZi", "nc", "xcvbitmanip") +TARGET_BUILTIN(bitmanip_clb, "UZcUZi", "nc", "xcvbitmanip") +TARGET_BUILTIN(bitmanip_cnt, "UZcUZi", "nc", "xcvbitmanip") TARGET_BUILTIN(bitmanip_ror, "UZiUZiUZi", "nc", "xcvbitmanip") TARGET_BUILTIN(bitmanip_bitrev, "UZiUZiIUcIUc", "nc", "xcvbitmanip") diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt index a81f9c126f8b..08d74270b7a0 100644 --- a/clang/lib/Headers/CMakeLists.txt +++ b/clang/lib/Headers/CMakeLists.txt @@ -92,6 +92,10 @@ set(ppc_htm_files htmxlintrin.h ) +set(riscv_files + riscv_corev_bitmanip.h + ) + set(systemz_files s390intrin.h vecintrin.h @@ -232,6 +236,7 @@ set(files ${opencl_files} ${ppc_files} ${ppc_htm_files} + ${riscv_files} ${systemz_files} ${ve_files} ${x86_files} @@ -415,7 +420,7 @@ add_header_target("hip-resource-headers" "${hip_files}") add_header_target("mips-resource-headers" "${mips_msa_files}") add_header_target("ppc-resource-headers" "${ppc_files};${ppc_wrapper_files}") add_header_target("ppc-htm-resource-headers" "${ppc_htm_files}") -add_header_target("riscv-resource-headers" "${riscv_generated_files}") +add_header_target("riscv-resource-headers" "${riscv_generated_files};${riscv_files}") add_header_target("systemz-resource-headers" "${systemz_files}") add_header_target("ve-resource-headers" "${ve_files}") add_header_target("webassembly-resource-headers" "${webassembly_files}") @@ -532,6 +537,12 @@ install( EXCLUDE_FROM_ALL COMPONENT riscv-resource-headers) +install( + FILES ${riscv_files} + DESTINATION ${header_install_dir} + EXCLUDE_FROM_ALL + COMPONENT riscv-resource-headers) + install( FILES ${systemz_files} DESTINATION ${header_install_dir} diff --git a/clang/lib/Headers/riscv_corev_bitmanip.h b/clang/lib/Headers/riscv_corev_bitmanip.h new file mode 100644 index 000000000000..b14c460fadf9 --- /dev/null +++ b/clang/lib/Headers/riscv_corev_bitmanip.h @@ -0,0 +1,74 @@ +/*===---- riscv_corev_bitmanip.h - CORE-V bit manipulation intrinsics ------=== + * + * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. + * See https://llvm.org/LICENSE.txt for license information. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + * + *===-----------------------------------------------------------------------=== + */ + +#ifndef __RISCV_COREV_BITMANIP_H +#define __RISCV_COREV_BITMANIP_H + +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +#if defined(__riscv_xcvbitmanip) + +#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) + +static __inline__ long __DEFAULT_FN_ATTRS __riscv_cv_bitmanip_extract(long a, uint16_t range) { + return __builtin_riscv_cv_bitmanip_extract(a, range); +} + +static __inline__ unsigned long __DEFAULT_FN_ATTRS __riscv_cv_bitmanip_extractu(unsigned long a, uint16_t range) { + return __builtin_riscv_cv_bitmanip_extractu(a, range); +} + +static __inline__ unsigned long __DEFAULT_FN_ATTRS __riscv_cv_bitmanip_insert(unsigned long a, uint16_t range, + unsigned long k) { + return __builtin_riscv_cv_bitmanip_insert(a, range, k); +} + +static __inline__ unsigned long __DEFAULT_FN_ATTRS __riscv_cv_bitmanip_bclr(unsigned long a, uint16_t range) { + return __builtin_riscv_cv_bitmanip_bclr(a, range); +} + +static __inline__ unsigned long __DEFAULT_FN_ATTRS __riscv_cv_bitmanip_bset(unsigned long a, uint16_t range) { + return __builtin_riscv_cv_bitmanip_bset(a, range); +} + +static __inline__ uint8_t __DEFAULT_FN_ATTRS __riscv_cv_bitmanip_ff1(unsigned long a) { + return __builtin_riscv_cv_bitmanip_ff1(a); +} + +static __inline__ uint8_t __DEFAULT_FN_ATTRS __riscv_cv_bitmanip_fl1(unsigned long a) { + return __builtin_riscv_cv_bitmanip_fl1(a); +} + +static __inline__ uint8_t __DEFAULT_FN_ATTRS __riscv_cv_bitmanip_clb(unsigned long a) { + return __builtin_riscv_cv_bitmanip_clb(a); +} + +static __inline__ uint8_t __DEFAULT_FN_ATTRS __riscv_cv_bitmanip_cnt(unsigned long a) { + return __builtin_riscv_cv_bitmanip_cnt(a); +} + +static __inline__ unsigned long __DEFAULT_FN_ATTRS __riscv_cv_bitmanip_ror(unsigned long a, unsigned long b) { + return __builtin_riscv_cv_bitmanip_ror(a, b); +} + +#define __riscv_cv_bitmanip_bitrev(rs1, PTS, RADIX) \ + (unsigned long) __builtin_riscv_cv_bitmanip_bitrev((unsigned long) (rs1), \ + (const uint8_t) (PTS), (const uint8_t) (RADIX)) + +#endif // defined(__riscv_xcvbitmanip) + +#if defined(__cplusplus) +} +#endif + +#endif // define __RISCV_COREV_BITMANIP_H diff --git a/clang/test/CodeGen/RISCV/corev-intrinsics/bitmanip-c-api.c b/clang/test/CodeGen/RISCV/corev-intrinsics/bitmanip-c-api.c new file mode 100644 index 000000000000..96b1c335ef0f --- /dev/null +++ b/clang/test/CodeGen/RISCV/corev-intrinsics/bitmanip-c-api.c @@ -0,0 +1,102 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +// RUN: %clang_cc1 -triple riscv32 -target-feature +xcvbitmanip -emit-llvm %s -o - \ +// RUN: | FileCheck %s + +#include +#include + +// CHECK-LABEL: @test_extract +// CHECK: @llvm.riscv.cv.bitmanip.extract +uint32_t test_extract(uint32_t a) { + return __riscv_cv_bitmanip_extract(a, 0); +} + +// CHECK-LABEL: @test_extractr +// CHECK: @llvm.riscv.cv.bitmanip.extract +uint32_t test_extractr(uint32_t a, uint16_t b) { + return __riscv_cv_bitmanip_extract(a, b); +} + +// CHECK-LABEL: @test_extractu +// CHECK: @llvm.riscv.cv.bitmanip.extractu +uint32_t test_extractu(uint32_t a) { + return __riscv_cv_bitmanip_extractu(a, 0); +} + +// CHECK-LABEL: @test_extractur +// CHECK: @llvm.riscv.cv.bitmanip.extractu +uint32_t test_extractur(uint32_t a, uint16_t b) { + return __riscv_cv_bitmanip_extractu(a, b); +} + +// CHECK-LABEL: @test_insert +// CHECK: @llvm.riscv.cv.bitmanip.insert +uint32_t test_insert(uint32_t a, uint32_t c) { + return __riscv_cv_bitmanip_insert(a, 0, c); +} + +// CHECK-LABEL: @test_insertr +// CHECK: @llvm.riscv.cv.bitmanip.insert +uint32_t test_insertr(uint32_t a, uint16_t b, uint32_t c) { + return __riscv_cv_bitmanip_insert(a, b, c); +} + +// CHECK-LABEL: @test_bclr +// CHECK: @llvm.riscv.cv.bitmanip.bclr +uint32_t test_bclr(uint32_t a) { + return __riscv_cv_bitmanip_bclr(a, 0); +} + +// CHECK-LABEL: @test_bclrr +// CHECK: @llvm.riscv.cv.bitmanip.bclr +uint32_t test_bclrr(uint32_t a, uint16_t b) { + return __riscv_cv_bitmanip_bclr(a, b); +} + +// CHECK-LABEL: @test_bset +// CHECK: @llvm.riscv.cv.bitmanip.bset +uint32_t test_bset(uint32_t a) { + return __riscv_cv_bitmanip_bset(a, 0); +} + +// CHECK-LABEL: @test_bsetr +// CHECK: @llvm.riscv.cv.bitmanip.bclr +uint32_t test_bsetr(uint32_t a, uint16_t b) { + return __riscv_cv_bitmanip_bclr(a, b); +} + +// CHECK-LABEL: @test_ff1 +// CHECK: @llvm.riscv.cv.bitmanip.ff1 +uint32_t test_ff1(uint32_t a) { + return __riscv_cv_bitmanip_ff1(a); +} + +// CHECK-LABEL: @test_fl1 +// CHECK: @llvm.riscv.cv.bitmanip.fl1 +uint32_t test_fl1(uint32_t a) { + return __riscv_cv_bitmanip_fl1(a); +} + +// CHECK-LABEL: @test_clb +// CHECK: @llvm.riscv.cv.bitmanip.clb +uint32_t test_clb(uint32_t a) { + return __riscv_cv_bitmanip_clb(a); +} + +// CHECK-LABEL: @test_cnt +// CHECK: @llvm.riscv.cv.bitmanip.cnt +uint32_t test_cnt(uint32_t a) { + return __riscv_cv_bitmanip_cnt(a); +} + +// CHECK-LABEL: @test_ror +// CHECK: @llvm.riscv.cv.bitmanip.ror +uint32_t test_ror(uint32_t a, uint32_t b) { + return __riscv_cv_bitmanip_ror(a, b); +} + +// CHECK-LABEL: @test_bitrev +// CHECK: @llvm.riscv.cv.bitmanip.bitrev +uint32_t test_bitrev(uint32_t a) { + return __riscv_cv_bitmanip_bitrev(a, 1, 2); +}