Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Probable compilation bug in Burst 1.8.8 under AVX2

Discussion in 'Burst' started by viruseg, Sep 9, 2023.

  1. viruseg

    viruseg

    Joined:
    Jul 8, 2017
    Posts:
    17
    I assume it is a bug in the compiler. But before sending a report I would like to ask those who know more about the issue than I do.

    This loop looks too cumbersome after compilation in burst 1.8.8 under AVX2.
    upload_2023-9-9_4-20-42.png

    The simplest loop compiled under AVX2 unfolds into some incredibly large number of instructions. All the compiled code does not fit on the screenshot.
    upload_2023-9-9_4-18-38.png

    The same loop compiled under AVX looks like this:
    upload_2023-9-9_4-17-46.png

    I attach the full source code to the message.
     

    Attached Files:

  2. tim_jones

    tim_jones

    Unity Technologies

    Joined:
    May 2, 2019
    Posts:
    280
    Hi @viruseg - please could you attach the full AVX2 assembly? At first glance, it looks like it may just be the optimizer doing its job. Sometimes it adds conditional branches like "if there are more than N elements, use this vectorized path for multiple elements at a time, otherwise fallback to this scalar path", but it's hard to tell without seeing all the assembly code.
     
  3. viruseg

    viruseg

    Joined:
    Jul 8, 2017
    Posts:
    17
    Hi, @tim_jones. Here is the complete assembly. The source code for the job is in the first post.
     

    Attached Files:

  4. tim_jones

    tim_jones

    Unity Technologies

    Joined:
    May 2, 2019
    Posts:
    280
    Hi @viruseg - to me, that looks like the optimizer doing its job correctly. At the top there's a branch based on how many elements are in the array - if less than (I think, from reading the assembly) 32, it uses a scalar path, and if 32 or more, it uses the vectorized path, plus a scalar path for any remainder.
     
  5. viruseg

    viruseg

    Joined:
    Jul 8, 2017
    Posts:
    17
    Thank you so much for the clarification.