Skip to content

qiujiandong/rvv-intrinsic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RISC-V Vector Extension Intrinsics for Clangd

Related Issues

The RISC-V vector intrinsic functions are defined in <riscv_vector.h> as follows:

#pragma clang riscv intrinsic vector

While the compiler can recognize these, clangd currently does not. It may support them in the future, but for now, you'll need to manually generate these header files as a workaround.

Demo

Let's write some RVV code!

demo

Quick Start

Download the release package from the Releases Page.

wget https://github.com/qiujiandong/rvv-intrinsic/releases/latest/download/rvv-intrinsic.tar.gz
tar -xzvf rvv-intrinsic.tar.gz
cd rvv-intrinsic_v[tab]
./configure

Then, the clangd configuration should work properly.

How to Generate the Header Files

0. By Single Script

To generate the header files by a single script, run the following command:

./scripts/release.sh

If you want to known the details, please follow the following steps:

1. Generate Header Files

Start by generating the intrinsic files from rvv-intrinsic-doc. Clone the submodule:

git submodule update --init --recursive

The intrinsic version is v1.0-ratified. Prepare your Python environment, navigate to the rvv-intrinsic-doc directory, and then run the following commands:

cd rvv-intrinsic-generator
pip install -r requirements.txt
git apply ../../scripts/clang-format.patch
make

The intrinsic files will be generated in rvv-intrinsic-doc/auto-generated/ in .adoc format. We need to convert these to .h format.

Run the following command in the root of this repo:

./scripts/run.py

This will generate the header files in the rvv_intrinsic directory.

2. Configure Clangd

The rvv_intrinsic.h file organizes the header files with corresponding extensions. You do not need to include this file directly in your application, as the compiler already knows about these intrinsics.

However, clangd does not automatically recognize them. To configure clangd, please refer to the Configurations documentation. Add the following configuration to your .clangd file:

CompileFlags:
  Add:
    [
      -include /path/to/repo/rvv_intrinsic/rvv_intrinsic.h,
      -I /path/to/repo/rvv-intrinsic/rvv_intrinsic,
    ]

This will force the inclusion of rvv_intrinsic.h and allow clangd to locate the generated header files.

Testing

Before running tests, make sure you have prepared the RISC-V toolchain and bear. bear is used to generate the compile_commands.json compilation database, which is required by clangd.

The tests directory contains various RISC-V vector extension subset test cases, including:

  • _zve32x
  • _zve32f
  • _zfh_zvfh_zve32f
  • _zve64x
  • _zve64f
  • _zve64d

For more details on the different vector extensions, refer to the RISC-V V-Spec v1.0.

To generate the compilation database (compile_commands.json), run the following command in the directory where the Makefile exists:

bear -- make

If you have the clangd plugin installed in VSCode or Neovim, it should work seamlessly.


Let me know if you'd like to adjust anything further!

License

This project is licensed under the Apache License 2.0 - see the LICENSE.txt file for details.

About

RVV intrinsic header files used for clangd LSP

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors