A log2 function is normally used to determine the number of bits needed to represent a number, and it is often not suitable for synthesis.
The OP asks for synthesizable code. "Priority encoder" circuits are normally synthesizable.
log2 is synthesizable as well, and not just for computing constants. Maybe you should take another look at the code for log2 and re-evaluate your statement that log2 is 'often not suitable for synthesis'. In fact, look at it to say in what way log2 even differs from a priority encoder.
For a single clock cycle input to output delay, Quartus 14.0, targeting a Cyclone IV GX, registering the inputs and outputs surrounding the call to the log2 function (in order to produce a meaningful Fmax for comparison) produces the following results:
31 bits => 252 LE 32.86 MHz
30 bits => 247 LE 35.12 MHz
29 bits => 231 LE 365.65 MHz
16 bits => 38 LE 225.78 MHz
12 bits => 18 LE 550.36 MHz
8 bits => 11 LE 728.86 MHz
I suspect that 'priority encoder' should produce similar results but will leave that for you to produce.
Kevin Jennings