Vous êtes sur la page 1sur 5

 

COMPILERS 

HW-2 
Sawar Sagwal, 20171013 
 

Ques 3 
There are two ways to compile a compiler: 

1. The simplest way is to write the entire compiler in some other existing language and 
then compiling it. 
2. By bootstrapping: The process of compiling a compiler is analogous to the chicken 
and egg problem because we can ask the question, how did the first compiler was 
compiled. This can be done using assembly, or write basic features as machine 
instructions and use it to work on an advanced language which can be the first 
assembler. The technique of using the compiler written for the source programming 
language to compile the compiler is called bootstrapping and such compilers are 
called self-compiling. This technique requires some basic/core set of features for the 
source language to be built using some other language (can be machine language). 
The process can then be used progressively to get higher levels of abstractions. 
Bootstrapping requires the following steps: (from wikipedia) 
a. Prepare an environment for the bootstrap compiler to work with. 
b. Write the bootstrap compiler 
c. Compile an advanced compiler using both the bootstrap compiler. 
d. Compile an advanced compiler using the compiler from the previous step. 

Another example of the chicken or egg problem is booting a computer, wherein we can ask 
how was the first software loaded. Here also bootstrapping is used. Basic machine 
instruction loads the BIOS which loads the bootloader and so on.  

Compiling GCC​: GCC is also compiled using bootstrapping. GCC is itself written in C and 
C++. Bootstrapping GCC involves first building the tools which are necessary to build the 

 
 
 
compiler and creating basic/core features to build the rest of the features (bootstrapping). 
The runtime libraries are then built using the compiler built after bootstrapping. 

So the whole process is: (GCC Source code) => (Intermediate Representation) => (Assembly 
code) => (Machine code) => (linking and generating the executable)  

Compiling LLVM​: LLVM is written in a subset of C++ and requires relatively modern 
features of C++. It is compiled using GCC but can also be compiled through clang or icc. The 
process of generating assembly is omitted (as the assembly code is not generated).  

The process is: (C++ source code) => (Intermediate representation) => (machine code) => 
(linking to generate an executable)  

Ques 4 

JDK version: 

openjdk 11.0.8 2020-07-14 


OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu120.04) 
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu120.04, mixed mode, 
sharing)   

The following program was used (instead of integer, biginteger was used to avoid overflow) 

import​ java.math.BigInteger;

public​ ​class​ ​sqrsum​ {

​public​ ​static​ ​void​ ​main​(​String​ ​args​[]) ​throws​ ​NumberFormatException​ {

​Long​ ​a​ = ​Long​.​parseLong​(args[​0​]);

​BigInteger​ ​result​ = ​BigInteger​.​valueOf​(​0​);

​for​ (​long​ ​i​ = ​1​; i <= a; ++i) result = ​result​.​add​(​sqr​(i));

 

 
 

​System​.​out​.​println​(​"sqrsum of the numbers is: "​ + ​result​.​toString​());

​static​ ​BigInteger​ ​sqr​(​long​ ​b​) {

​return​ ​BigInteger​.​valueOf​(b * b);

k  With Hotspot  Without Hotspot 

5  0.172 s  0.125 s 

6  0.125 s  1.016 s 

7  0.406 s  9.844 s 

8  2.109 s  1m 47.438 s 

9  19.750 s  16m 44.734 s 

10  3m 46.844 s  > 1hour 

Ques 5 
 

  Cholesky  Mvt  Syrk 


(size(bytes)/time(sec))  (size(bytes)/time(sec))  (size(bytes)/time(sec)) 

gcc -O0  18296 bytes   18240 bytes   18248 bytes  


6.903944 sec  0.045671 sec  4.729856 sec 

 

 
 

gcc -O1  18080 bytes   18032 bytes   18032 bytes  


3.783711 sec  0.027870 sec  1.009461 sec 

gcc -O2  18096 bytes   18000 bytes   18000 bytes  


1.915609 sec  0.022602 sec  1.008024 sec 

gcc -O3  18144 bytes   18056 bytes   18056 bytes  


1.886421 sec  0.022866 sec  0.992832 sec 

gcc -Os  18080 bytes   18032 bytes   18032 bytes  


3.902872 sec  0.027920 sec  1.125171 sec 

clang -O0  17904 bytes   17840 bytes   17848 bytes  


6.791107 sec  0.040707 sec  3.931860 sec 

clang -O1  17952 bytes   17840 bytes   17840 bytes  


3.984871 sec  0.028080 sec  1.068725 sec 

clang -O2  17776 bytes   17664 bytes   17672 bytes  


1.915076 sec  0.022614 sec  0.910440 sec 

clang -O3  17776 bytes   17664 bytes   17672 bytes  


1.863934 sec  0.022352 sec  0.980137 sec 

clang -Os  17808 bytes   17696 bytes   17704 bytes  


1.955552  0.022576  1.088513 sec 

icc -w0 -O0  28688 bytes   18160 bytes   18168 bytes  


8.167316 sec  0.046338 sec  5.280596 sec 

 

 
 

icc -w0 -O1  46432 bytes   36528 bytes   36528 bytes  


1.750578 sec  0.022385 sec  1.133925 sec 

icc -w0 -O2  60920 bytes   40640 bytes   41872 bytes  


1.738848 sec  0.021192 sec  0.268237 sec 

icc -w0 -O3  60920 bytes   40640 bytes   41872 bytes  


1.722453 sec  0.020409 sec  0.266132 sec 

icc -w0 -Os  36632 bytes   36632 bytes   36632 bytes  


1.717781 sec  0.022594 sec  0.457877 sec 

 

Vous aimerez peut-être aussi