1

I have the following very simple code that I would like to have vectorized by the compiler:

#include <cstdlib>
#include <cstdint>


static uint64_t HASH_MOD_PRIME = 8796093022151ull;
static uint64_t HASHED_POWERS_OF_BASE[32] =
{
    5944711979223, 4888226268587, 1088871378212, 6368046812720,
    5682482463725, 6980463874713, 4474597161960, 3050433740522,
    4419504424015, 7686991881063, 4860352712696, 3954861113044,
    100913750218, 7617674651447, 870392028436, 8144819954612,
    5607682262899, 4298315880084, 8346575821400, 7352355788314,
    2809282536675, 6913369912370, 5451192126612, 4805208003318,
    5185419420497, 3389323909658, 3790747989636, 2405024174203,
    7269509666190, 595217685378, 6309768715074, 3873446749003
};

static size_t Hash(const uint16_t* __restrict const data)
{
    uint64_t result = 0;
    for (int i = 0; i < 32; ++i)
    {
        result += data[i] * HASHED_POWERS_OF_BASE[i];
    }
    return result % HASH_MOD_PRIME;
}

int main()
{
    uint16_t data[32];
    return Hash(data);
}

yet it fails with loop not vectorized due to reason '1102'. According to MS docs reason 1102 is Loop contains non-arithmetic or other non-vectorizable operations.

Am I missing something or is this a compiler bug ?

See here: https://godbolt.org/z/TaovaxvxG

drescherjm
  • 10,365
  • 5
  • 44
  • 64
jcxz
  • 1,226
  • 2
  • 12
  • 25
  • 3
    Do you see the integer conversion `uint16_t` to `uint64_t` that must occur in the loop? – j6t Mar 20 '23 at 17:59
  • related/dupe: https://stackoverflow.com/questions/43651706/info-c5012-loop-not-parallelized-due-to-reason-1008 – NathanOliver Mar 20 '23 at 18:20
  • Thanks for your suggestion, I tried changing `uint16_t` to `uint64_t`, but it seems that no matter what I do, I am stuck with reason '1102'. What worked for me was simple loops of type `c[i] = a[i] * b[i]` with **doubles**. I was unable to get other types of loops that to vectorize :/ – jcxz Mar 21 '23 at 14:02

0 Answers0