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 xcvalu #95

Merged
merged 2 commits into from
Jan 1, 2024
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
1 change: 1 addition & 0 deletions clang/lib/Headers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ set(ppc_htm_files
)

set(riscv_files
riscv_corev_alu.h
riscv_corev_bitmanip.h
)

Expand Down
111 changes: 111 additions & 0 deletions clang/lib/Headers/riscv_corev_alu.h
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
126 changes: 126 additions & 0 deletions clang/test/CodeGen/RISCV/corev-intrinsics/alu-c-api.c
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);
}
2 changes: 1 addition & 1 deletion llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ bool RISCVExpandPseudo::expandCoreVAddSub(llvm::MachineBasicBlock &MBB,
Register Y = MBBI->getOperand(2).getReg();
uint8_t Shift = MBBI->getOperand(3).getImm();

bool IsImm = 0 <= Shift && Shift <= 31;
bool IsImm = Shift <= 31;
unsigned Opcode;
switch (MBBI->getOpcode()) {
case RISCV::CV_ADDN_PSEUDO:
Expand Down
Loading