Improved encoder acceleration.
Convert accelerator code to a generic template.