The S54 cylinder head flows *much* better than the M54 head. The valvetrain is solid and the valves have stiffer springs. This allows it to rev to 8000 reliably. The M3 also has longer duration cams.
It's mostly the better flowing head and the high redline that allows it to make so much more power than the non-M motors.