Rate This Document
Findability
Accuracy
Completeness
Readability

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.

  1. In IntelliJ IDEA, 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
  2. A progress bar is displayed in the lower right corner during scanning. Click the progress bar to view details.
    Figure 2 Progress bar
  3. 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
  4. 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.

  5. 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
  6. When you move the cursor to an annotation, a vectorization tip is displayed.
    Figure 7 Vectorization tip
  7. Click More to preview the vectorized code.
    Figure 8 Code preview
  8. 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.

  9. If the project is modular, that is, it has the module-info.java folder, add required content to the module-info.java file.
    1. Find the module-info.java file in the src directory.
    2. Open the file and add the following content:
      module your.module.name {
          requires jdk.incubator.vector;
      }
  10. (Optional) Use the preview function during compilation and running. For details, see Setting the Preview Function.