Using JavaVectorHelper
Prerequisites
The project file has been built successfully.
If a Java project fails to be built using Maven or Gradle, certain Quick Fix functions may become unavailable after scanning. There is no wavy-line annotation and you have to copy the content in the suggestion box to modify the content. Besides, you need to add the import statement and the constant declaration manually.
Procedure
You can use JavaVectorHelper to scan a single file or the entire project, identify vectorizable loop bodies in the Java source code, and obtain reconstruction suggestions.
- In IntelliJ, expand the project folder, open the Java file, right-click the file, and select Perform Vectorization Analysis on the Current File or Perform Vectorization Analysis on the Entire Project from the shortcut menu to perform vectorization analysis on the current file or the entire project.Figure 1 Scanning the source code
- A progress bar is displayed in the lower right corner during scanning. Click the progress bar to view details.Figure 2 Progress bar
- After the scanning is complete, the tool window displays the number of issues in the current file and entire project.Figure 3 Current file
Figure 4 Entire project
- Click an issue to check the associated code on the right. The code snippets whose loop bodies can be vectorized are displayed.Figure 5 Vectorizable code
You can re-locate the tool window when needed. Click
on the right of the window to change the view mode, move the window, and resize the window. - Double-click an issue or right-click an issue and select Jump to Source from the shortcut menu to open the source file. In the source file, wavy-line annotations are added to the vectorizable for statements.Figure 6 Wavy-line annotations
- When you move the cursor to an annotation, a vectorization tip is displayed.Figure 7 Vectorization tip
- Click More to preview the vectorized code.Figure 8 Code preview
- Click DevKit vectorization to quickly modify the code. The vectorizable code is replaced with the vectorized code.Figure 9 Quick fix
After code replacement, the necessary import statement and constant declaration are added.
- If the project is modular, that is, it has the module-info.java folder, add required content to the module-info.java file.
- Find the module-info.java file in the src directory.
- Open the file and add the following content:
module your.module.name { requires jdk.incubator.vector; }
- (Optional) Use the preview function during compilation and running. For details, see Setting the Preview Function.