Apply auto-vectorization to the inner loop of div_var_fast().
authorDean Rasheed <dean.a.rasheed@gmail.com>
Sun, 27 Feb 2022 10:15:46 +0000 (10:15 +0000)
committerDean Rasheed <dean.a.rasheed@gmail.com>
Sun, 27 Feb 2022 10:15:46 +0000 (10:15 +0000)
commite3d41d08a17549fdc60a8b9450c0511c11d666d7
tree502d340d44984e6fc6d9ddc279e716593b818c6f
parent6b04abdfc5e0653542ac5d586e639185a8c61a39
Apply auto-vectorization to the inner loop of div_var_fast().

This loop is basically the same as the inner loop of mul_var(), which
was auto-vectorized in commit 8870917623, but the compiler will only
consider auto-vectorizing the div_var_fast() loop if the assignment
target div[qi + i] is replaced by div_qi[i], where div_qi = &div[qi].

Additionally, since the compiler doesn't know that qdigit is
guaranteed to fit in a 16-bit NumericDigit, cast it to NumericDigit
before multiplying to make the resulting auto-vectorized code more
efficient (avoiding unnecessary multiplication of the high 16 bits).

While at it, per suggestion from Tom Lane, change var1digit in
mul_var() to be a NumericDigit rather than an int for the same
reason. This actually makes no difference with modern gcc, but it
might help other compilers generate more efficient assembly.

Dean Rasheed, reviewed by Tom Lane.

Discussion: https://postgr.es/m/CAEZATCVwsBi-ND-t82Cuuh1=8ee6jdOpzsmGN+CUZB6yjLg9jw@mail.gmail.com
src/backend/utils/adt/numeric.c