-
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 alu CORE-V intrinsics.
This commit adds the C API header to serve as an interface for the intrinsic functions provided with the CORE-V xcvalu extension. The commit includes the addition of the header itself and a clang CodeGen test that checks the integrity of the call to the wrapper functions designed in the C API CORE-V alu header.
- Loading branch information
Showing
3 changed files
with
238 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,7 @@ set(ppc_htm_files | |
) | ||
|
||
set(riscv_files | ||
riscv_corev_alu.h | ||
riscv_corev_bitmanip.h | ||
) | ||
|
||
|
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,111 @@ | ||
/*===---- riscv_corev_alu.h - CORE-V ALU 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_ALU_H | ||
#define __RISCV_COREV_ALU_H | ||
|
||
#include <stdint.h> | ||
|
||
#if defined(__cplusplus) | ||
extern "C" { | ||
#endif | ||
|
||
#if defined(__riscv_xcvalu) | ||
|
||
#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__)) | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_cv_abs(long a) { return __builtin_abs(a); } | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_cv_alu_slet(long a, long b) { | ||
return __builtin_riscv_cv_alu_slet(a, b); | ||
} | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_cv_alu_sletu(unsigned long a, unsigned long b) { | ||
return __builtin_riscv_cv_alu_sletu(a, b); | ||
} | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_cv_alu_min(long a, long b) { | ||
return __builtin_riscv_cv_alu_min(a, b); | ||
} | ||
|
||
static __inline__ unsigned long __DEFAULT_FN_ATTRS __riscv_cv_alu_minu(unsigned long a, unsigned long b) { | ||
return __builtin_riscv_cv_alu_minu(a, b); | ||
} | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_cv_alu_max(long a, long b) { | ||
return __builtin_riscv_cv_alu_max(a, b); | ||
} | ||
|
||
static __inline__ unsigned long __DEFAULT_FN_ATTRS __riscv_cv_alu_maxu(unsigned long a, unsigned long b) { | ||
return __builtin_riscv_cv_alu_maxu(a, b); | ||
} | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_cv_alu_exths(int16_t a) { return __builtin_riscv_cv_alu_exths(a); } | ||
|
||
static __inline__ unsigned long __DEFAULT_FN_ATTRS __riscv_cv_alu_exthz(uint16_t a) { | ||
return __builtin_riscv_cv_alu_exthz(a); | ||
} | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_cv_alu_extbs(int8_t a) { return __builtin_riscv_cv_alu_extbs(a); } | ||
|
||
static __inline__ unsigned long __DEFAULT_FN_ATTRS __riscv_cv_alu_extbz(uint8_t a) { | ||
return __builtin_riscv_cv_alu_extbz(a); | ||
} | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_cv_alu_clip(long a, unsigned long b) { | ||
return __builtin_riscv_cv_alu_clip(a, b); | ||
} | ||
|
||
static __inline__ unsigned long __DEFAULT_FN_ATTRS __riscv_cv_alu_clipu(unsigned long a, unsigned long b) { | ||
return __builtin_riscv_cv_alu_clipu(a, b); | ||
} | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_cv_alu_addN(long a, long b, uint8_t shft) { | ||
return __builtin_riscv_cv_alu_addN(a, b, shft); | ||
} | ||
|
||
static __inline__ unsigned long __DEFAULT_FN_ATTRS __riscv_cv_alu_adduN(unsigned long a, unsigned long b, | ||
uint8_t shft) { | ||
return __builtin_riscv_cv_alu_adduN(a, b, shft); | ||
} | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_cv_alu_addRN(long a, long b, uint8_t shft) { | ||
return __builtin_riscv_cv_alu_addRN(a, b, shft); | ||
} | ||
|
||
static __inline__ unsigned long __DEFAULT_FN_ATTRS __riscv_cv_alu_adduRN(unsigned long a, unsigned long b, | ||
uint8_t shft) { | ||
return __builtin_riscv_cv_alu_adduRN(a, b, shft); | ||
} | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_cv_alu_subN(long a, long b, uint8_t shft) { | ||
return __builtin_riscv_cv_alu_subN(a, b, shft); | ||
} | ||
|
||
static __inline__ unsigned long __DEFAULT_FN_ATTRS __riscv_cv_alu_subuN(unsigned long a, unsigned long b, | ||
uint8_t shft) { | ||
return __builtin_riscv_cv_alu_subuN(a, b, shft); | ||
} | ||
|
||
static __inline__ long __DEFAULT_FN_ATTRS __riscv_cv_alu_subRN(long a, long b, uint8_t shft) { | ||
return __builtin_riscv_cv_alu_subRN(a, b, shft); | ||
} | ||
|
||
static __inline__ unsigned long __DEFAULT_FN_ATTRS __riscv_cv_alu_subuRN(unsigned long a, unsigned long b, | ||
uint8_t shft) { | ||
return __builtin_riscv_cv_alu_subuRN(a, b, shft); | ||
} | ||
|
||
#endif // defined(__riscv_xcvalu) | ||
|
||
#if defined(__cplusplus) | ||
} | ||
#endif | ||
|
||
#endif // define __RISCV_COREV_ALU_H |
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,126 @@ | ||
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py | ||
// RUN: %clang_cc1 -triple riscv32 -target-feature +xcvalu -emit-llvm %s -o - \ | ||
// RUN: | FileCheck %s | ||
|
||
#include <stdint.h> | ||
#include <riscv_corev_alu.h> | ||
|
||
// CHECK-LABEL: @test_alu_slet | ||
// CHECK: @llvm.riscv.cv.alu.slet | ||
int test_alu_slet(int32_t a, int32_t b) { | ||
return __riscv_cv_alu_slet(a, b); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_sletu | ||
// CHECK: @llvm.riscv.cv.alu.sletu | ||
int test_alu_sletu(uint32_t a, uint32_t b) { | ||
return __riscv_cv_alu_sletu(a, b); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_min | ||
// CHECK: @llvm.riscv.cv.alu.min | ||
int test_alu_min(int32_t a, int32_t b) { | ||
return __riscv_cv_alu_min(a, b); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_minu | ||
// CHECK: @llvm.riscv.cv.alu.minu | ||
int test_alu_minu(uint32_t a, uint32_t b) { | ||
return __riscv_cv_alu_minu(a, b); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_max | ||
// CHECK: @llvm.riscv.cv.alu.max | ||
int test_alu_max(int32_t a, int32_t b) { | ||
return __riscv_cv_alu_max(a, b); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_maxu | ||
// CHECK: @llvm.riscv.cv.alu.maxu | ||
int test_alu_maxu(uint32_t a, uint32_t b) { | ||
return __riscv_cv_alu_maxu(a, b); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_exths | ||
// CHECK: @llvm.riscv.cv.alu.exths | ||
int test_alu_exths(int16_t a) { | ||
return __riscv_cv_alu_exths(a); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_exthz | ||
// CHECK: @llvm.riscv.cv.alu.exthz | ||
int test_alu_exthz(uint16_t a) { | ||
return __riscv_cv_alu_exthz(a); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_extbs | ||
// CHECK: @llvm.riscv.cv.alu.extbs | ||
int test_alu_extbs(int8_t a) { | ||
return __riscv_cv_alu_extbs(a); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_extbz | ||
// CHECK: @llvm.riscv.cv.alu.extbz | ||
int test_alu_extbz(uint8_t a) { | ||
return __riscv_cv_alu_extbz(a); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_clip | ||
// CHECK: @llvm.riscv.cv.alu.clip | ||
int test_alu_clip(int32_t a) { | ||
return __riscv_cv_alu_clip(a, 0); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_clipu | ||
// CHECK: @llvm.riscv.cv.alu.clipu | ||
int test_alu_clipu(uint32_t a) { | ||
return __riscv_cv_alu_clipu(a, 0); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_addN | ||
// CHECK: @llvm.riscv.cv.alu.addN | ||
int test_alu_addN(int32_t a, int32_t b) { | ||
return __riscv_cv_alu_addN(a, b, 0); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_adduN | ||
// CHECK: @llvm.riscv.cv.alu.adduN | ||
int test_alu_adduN(uint32_t a, uint32_t b) { | ||
return __riscv_cv_alu_adduN(a, b, 0); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_addRN | ||
// CHECK: @llvm.riscv.cv.alu.addRN | ||
int test_alu_addRN(int32_t a, int32_t b) { | ||
return __riscv_cv_alu_addRN(a, b, 0); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_adduRN | ||
// CHECK: @llvm.riscv.cv.alu.adduRN | ||
int test_alu_adduRN(uint32_t a, uint32_t b) { | ||
return __riscv_cv_alu_adduRN(a, b, 0); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_subN | ||
// CHECK: @llvm.riscv.cv.alu.subN | ||
int test_alu_subN(int32_t a, int32_t b) { | ||
return __riscv_cv_alu_subN(a, b, 0); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_subuN | ||
// CHECK: @llvm.riscv.cv.alu.subuN | ||
int test_alu_subuN(uint32_t a, uint32_t b) { | ||
return __riscv_cv_alu_subuN(a, b, 0); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_subRN | ||
// CHECK: @llvm.riscv.cv.alu.subRN | ||
int test_alu_subRN(int32_t a, int32_t b) { | ||
return __riscv_cv_alu_subRN(a, b, 0); | ||
} | ||
|
||
// CHECK-LABEL: @test_alu_subuRN | ||
// CHECK: @llvm.riscv.cv.alu.subuRN | ||
int test_alu_subuRN(uint32_t a, uint32_t b) { | ||
return __riscv_cv_alu_subuRN(a, b, 0); | ||
} |