i don't know if this question is valid or not.tried on google but i didnt get a solution.

does a compiler generate different machine codes for different cpus?
like does it generate different binary codes for intel and amd for the same program?

if so how does the compiler know what cpu the computer has?

then does a compiler generate different codes for different operating systems?