Cutting any pattern on a square bar would require something like a CNC lathe, As the bar turns, the cutter would have to move in and out to track the surface. A CNC mill with a fourth axis could also cut this type of feature.
In woodworking there are pattern lathes that track a premade pattern to guide the cutter. This is how the curved legs on antique furniture are made.
On round stock the problem is gearing the lead screw such that it is turning faster than the spindle. If you were looking at a 1" pitch on the part and the lead screw has a pitch of 8 tpi, the lead screw will have to rotate 8 times for every spindle revolution. This would subject the lead screw and gearing well outside their design envelope. Modifying the lathe by using a fast pitch ball screw (
https://www.mcmaster.com/products/ball-screws/fast-travel-ball-screws-and-nuts/) would ease the situation but this isn't practical for a one off part.
Tom Lipton, OxTools, made a setup using an indexer (
) to accomplish this task on a manual mill. It uses an encoder driven by the x axis lead screw to send commands to a stepper which rotates the indexer in sync with the x axis travel to create the spiral.
Another option would be to use a spiral gear from an automotive differential or similar transmission to act as a knurling tool. You would have to make a custom setup to mount the gear rigidly on the cross slide. You would be limited to the pitch dictated by the helical gear though.