Generate mask for non zero (or inverse) nibbles in integer
Intrinsics from bmi and similar are okay, but I haven't found anything that seems useful.

They're not very useful for this. pdep and pext let you do this in a different way, but it's not better (especially not on AMD Zen1), you shouldn't use this (but maybe it's interesting to think about):
uint64_t m = 0x1111111111111111;
uint64_t stacked = _pext_u64(b, m) | _pext_u64(b, m &lt;&lt; 1) |
                   _pext_u64(b, m &lt;&lt; 2) | _pext_u64(b, m &lt;&lt; 3);
return _pdep_u64(stacked, m) * 15;

There is a slightly different way to write the original logic in a way that may be easier to read, of course that's subjective but it will be as a straight-line composition of common bitwise idioms, it shouldn't make any difference for a compiler. It's the same thing really, but instead of being a single expression it's linearized into discrete steps, which also creates the opportunity for in-line comments to explain the steps:
uint64_t getNonZeroMask( uint64_t b )
{
    // horizontal OR of nibbles in log(bits) steps
    b |= b &gt;&gt; 2;
    b |= b &gt;&gt; 1;
    // remove polluted bits, leaving the results in the lsb of every nibble
    b &amp;= 0x1111111111111111;
    // spread single bit flags into full nibbles
    return b * 15;
}