The main thing is, Volumetric Efficiency. An engine is nothing more than a pump. The more fuel air mixture you pump in, the more horsepower comes out. A Volumetric Efficiency of one, means that you pump in the same amount of fuel air that the engine displaces.
dakota mentioned many, if not all, of the variables that will ultimately determine the Volumetric Efficiency of a particular engine. Also dakota made a good point about compression ratio, the overall power as well as fuel efficiency is generally improved with an increased compression ratio as long as adequate octane fuel is available for the higher compression ratio.
Another factor that enters into this, is that the horsepower figure quoted is the horsepower peak. As you move the torque peak of a given engine to a higher RPM the horsepower increases dramatically. So, you could have a relatively detuned large displacement engine making good torque at low RPM, but make less horsepower than a smaller displacement engine with a lower torque value at a higher RPM.
As dakota said, there are beaucoup variables involved.
Have a great day,
'84 Euro 240D, 523K miles
'88 300E 5 Speed
'81 300D Daughter's Car
Over 800,000 miles in