"Verilog: Thermometer Code"

Efficiently create a [thermometer code][wiki] in verilog:

localparam M = 32;

function [M-1:0] therm_code;
  input    [$clog2(M):0] val;
  begin
    for (int i = 0; i

social