Multiplying an array by a number in C and how can achive vectorize the principal loop in this function?
Review of your Godbolt-fu: https://godbolt.org/z/doD3Ld


You can change the language from "C++" to "C" via the dropdown in the upper right corner of the source-code-editor pane.
You wanted to be using "gcc (trunk)", not "gcc (modules)", anyway.




The biggest contributor to running time must be that uint8_t digit is being provided as a runtime parameter instead of a compile-time parameter. But your benchmark only ever calls LongNumConstMult with 9, 8, 7, and 3. You should benchmark what happens if you write four different versions of the code: one with static const int digit = 9; at the top, one with static const int digit = 8;, and so on. Maybe that won't meet your design requirements, but it will give you a nice bound on what kind of improvement might be possible.

I infer that maybe you only need to handle 10 different digits. In that case, you could implement the runtime-parameterized LongNumConstMult as

void LongNumConstMult(uint8_t *V, size_t N, uint8_t digit)
{
    switch (digit) {
        case 0: return LongNumSetTo0(V, N);
        case 1: return;  // no-op
        case 2: return LongNumConstMult2(V, N);
        case 3: return LongNumConstMult3(V, N);
        [...]
        case 8: return LongNumConstMult8(V, N);
        case 9: return LongNumConstMult9(V, N);
    }
}


I predict that "one branch at the beginning, followed by many constant multiplications in a loop" might well beat "many non-constant multiplications in a loop."




  It's fine for the solution to use intrinsics or other specialized techniques


What about making V an array of uint16_t, uint32_t, uint64_t, or even __uint128_t? Even if V remains uint8_t, could you type-pun it to load 8 or 16 bytes at a time and do the multiplication at that width? (What is the native width of your machine?)



Here's some code that's in C++, so not directly applicable to your case, but you might find it useful: https://quuxplusone.github.io/blog/2020/02/13/wide-integer-proof-of-concept/
The code itself uses some x86 compiler intrinsics that may be relevant to your interests.