Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Agner o C++ kompajlerima

[es] :: C/C++ programiranje :: Agner o C++ kompajlerima

[ Pregleda: 475 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Branimir Maksimovic
Senior Software Engineer

Član broj: 64947
Poruke: 5176
109.72.51.*



+1026 Profil

icon Agner o C++ kompajlerima12.02.2020. u 05:43 - pre 12 meseci
https://www.agner.org/optimize/blog/read.php?i=1015

Citat:

Microsoft Visual Studio is very popular because of the user friendly IDE and excellent debugging and cross-reference features.
But Visual Studio is lagging behind on support for the latest instruction sets, and it is not the best compiler when it comes to code optimization.


The Intel compiler used to be on the cutting edge of code optimization, but now it has been overtaken by Gcc and Clang.
Intel's compiler has also lost in popularity since its hidden "Cripple AMD" function was revealed.


The open source compilers Gcc and Clang have now taken the lead.
These two compilers are very similar. Both are supporting all platforms and the newest instruction set extensions.


I have tested the different C++ compilers and listed the results in my C++ manual. The Gcc and Clang compilers are clearly the best when it comes to code optimization.
Clang is better than Gcc in several respects, but it has a tendency for excessive loop unrolling, which is a waste of code cache. I must admit that I was quite skeptical
of the LLVM/Clang project when it started, but people have put an impressive amount of work into it, and now the Clang compiler can outperform all other compilers on several measures.


Linux and Mac programmers will have no problems finding a Clang compiler. It is a little more complicated on Windows.
There are at least two ready-to-use Clang compiler versions for Windows. A Cygwin version and a Visual Studio plugin version.


Evo recimo scimarka najnoviji gcc/clang vs java
Code:

~/.../forth/sci >>> gcc-trunk -Ofast -march=native *.c -o scimarkgcc -lm                                                                                                                                                        
~/.../forth/sci >>> /home/bmaxa/clang/bin/clang -Ofast -march=native *.c -o scimarkclang -lm                                                                                                                                    
~/.../forth/sci >>> time ./scimarkclang                                                                                                                                                                                         
**                                                              **
** SciMark2 Numeric Benchmark, see http://math.nist.gov/scimark **
** for details. (Results can be submitted to [email protected])     **
**                                                              **
Using       2.00 seconds min time per kenel.
Composite Score:         2796.07
FFT             Mflops:  2367.53    (N=1024)
SOR             Mflops:  2083.18    (100 x 100)
MonteCarlo:     Mflops:   633.00
Sparse matmult  Mflops:  3855.46    (N=1000, nz=5000)
LU              Mflops:  5041.20    (M=100, N=100)
./scimarkclang  29.86s user 0.01s system 99% cpu 29.947 total
~/.../forth/sci >>> time ./scimarkgcc                                                                                                                                                                                           
**                                                              **
** SciMark2 Numeric Benchmark, see http://math.nist.gov/scimark **
** for details. (Results can be submitted to [email protected])     **
**                                                              **
Using       2.00 seconds min time per kenel.
Composite Score:         2705.82
FFT             Mflops:  2207.41    (N=1024)
SOR             Mflops:  2128.87    (100 x 100)
MonteCarlo:     Mflops:   629.74
Sparse matmult  Mflops:  2962.38    (N=1000, nz=5000)
LU              Mflops:  5600.70    (M=100, N=100)
./scimarkgcc  35.26s user 0.00s system 99% cpu 35.325 total
~/.../forth/sci >>> java jnt.scimark2.commandline                                                                                                                                                                               

SciMark 2.0a

Composite Score: 2491.3384059536847
FFT (1024): 1562.9395627763586
SOR (100x100):   1357.0106100257588
Monte Carlo : 1374.38953472
Sparse matmult (N=1000, nz=5000): 2338.4833894485423
LU (100x100): 5823.8689327977645

java.vendor: Oracle Corporation
java.version: 1.8.0_242
os.arch: amd64
os.name: Linux
os.version: 5.6.0-2-CUSTOM




[Ovu poruku je menjao Branimir Maksimovic dana 12.02.2020. u 06:55 GMT+1]
press any key to continue or any other to quit....
 
Odgovor na temu

Nedeljko
Nedeljko Stefanović

Član broj: 314
Poruke: 8410
*.dynamic.isp.telekom.rs.



+2728 Profil

icon Re: Agner o C++ kompajlerima11.07.2020. u 13:48 - pre 7 meseci
GCC i clang imaju uzajamne prednosti i mane.

Osim što GCC podržava veći broj programskih jezika, isporučena biblioteka je bogatija za GCC. Nisam sigiran da možeš generatore koda, kao što su bison i Flex da koristiš sa clang-om, pa ni VC-om, jer generišu pozive koje oni nemaju.

Sa druge strane, clang za Windows je bolji od MinGW-a, kada je isti jezik u pitanju i kada se koristi standardna biblioteka+neke koje se zasebno nabave (a ne ugrađena proširenja, koja GCC ima). Recimo, sledeći kod
Code (cpp):

class A {
public:
    int *x;

    A() { x = new int; }

    ~A() { delete x; }
};

int main() {
    thread_local static A a;

    return 0;
}
 

puca na kraju rada kada se kompajlira MinGW kompajlerom, jer pre vremena otkači dll sa funkcijom free(), koja mu treba za delete.

Kada se kompajlira GNU kompajlerom na Linux-u ili clang kompajlerom na Windows/macOS/Linux sistemu, ili VC kompajlerom (pretpostavljam i intelovim kompajlerom), sve je u redu.

Dakle, clang jednako dobro radi na Windows/Linux/macOS sistemima, dok GCC dobro radi na Linux sistemima, dok Windows port GCC-a MinGW nije na nivou GCC-a za Linux. Ne znam da li GCC ima port na macOS i kakav je ako ga ima.

Takođe, clang omogućava kompajliranje u .ll bajtkod za LLVM, pa da se na ciljnoj mašini dokompajlira u kod za tu arhitekturu, tako da je moguća distribucija binarnog koda, koji se kompajlira optimizovano za onu arhitekturu na kojoj se izvršava.
Nije bitno koji su zaključci izvučeni, već kako se do njih došlo.
 
Odgovor na temu

[es] :: C/C++ programiranje :: Agner o C++ kompajlerima

[ Pregleda: 475 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.