Diesel-cylinders have a maximum cylinder-compression before detonation of appx 19 bar, petrols 10 bar.
In a diesel, fuel is introduced into the burn-chamber at high presssure at the detonation-time(s) desired, into air already compressed by the piston (and turbo, usually). Fuel ingnites on introduction, by intended self ignition. The high-pressure fuel-valves decide the detonation time in a diesel-engine. Normally several fuel-injections are made through one detonation, to soften operation, and to lower NOx-emissions.
A petrol-engine usually introduces fuel to air before the compression-stroke, and the mix is not ignited by self iginition, because of the lower gas pressure/temperature on the time it is ignited by the spark plug. The spark-plug decides the start of detonation on a petrol.
If a petrol-engine was intended to self ignite, it would vary in performance , as the fuel-air-mix would reach detonation-point at different degrees of crankdue to engine temperature.
Self detonation in a petrol-engine may be due to low octane fuel (ignites on lower temperature) or high compression engine (higher temperature in burn-chamber), both allowing fuel-air to ignite before spark ignition. Typically, high performance petrol cars require high octane fuel. Some alchohols allows higher pre-spark comp/temp than petrol, and are well thought of for certain otto-motorsport purposes.