Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C API header xcvbitmanip and type fixes #97

Merged
merged 2 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions clang/include/clang/Basic/BuiltinsRISCVCOREV.def
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
13 changes: 12 additions & 1 deletion clang/lib/Headers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ set(ppc_htm_files
htmxlintrin.h
)

set(riscv_files
riscv_corev_bitmanip.h
)

set(systemz_files
s390intrin.h
vecintrin.h
Expand Down Expand Up @@ -232,6 +236,7 @@ set(files
${opencl_files}
${ppc_files}
${ppc_htm_files}
${riscv_files}
${systemz_files}
${ve_files}
${x86_files}
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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}
Expand Down
74 changes: 74 additions & 0 deletions clang/lib/Headers/riscv_corev_bitmanip.h
Original file line number Diff line number Diff line change
@@ -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 <stdint.h>

#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
102 changes: 102 additions & 0 deletions clang/test/CodeGen/RISCV/corev-intrinsics/bitmanip-c-api.c
Original file line number Diff line number Diff line change
@@ -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 <stdint.h>
#include <riscv_corev_bitmanip.h>

// 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);
}