-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RISCV][Clang] Add C API header for bitmanip CORE-V intrinsics.
This commit adds the C API header to serve as an interface for the intrinsic functions provided with the CORE-V xcvbitmanip extension. The commit includes the addition of the header itself, the update of cmake to support this header file and more to follow from RISC-V and a clang CodeGen test that checks the integrity of the call to the wrapper functions designed in the C API CORE-V bitmanip header.
- Loading branch information
Showing
3 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
102
clang/test/CodeGen/RISCV/corev-intrinsics/bitmanip-c-api.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |