Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does gcc require gmp?

Tags:

gcc

gmp

As anyone who has ever built gcc from source knows, gmp is a dependency for gcc. Why is this? In other words, what does gcc actually use it for?

like image 610
Brian Bi Avatar asked Apr 05 '13 05:04

Brian Bi


1 Answers

See this answer to a similar (but not same) question.

GMP is needed inside the compiler (at compilation time) notably for constant folding. Some language standards (notably some recent versions of Fortran) requires that e.g. 1234567891234567*1234567891 be computed in arbitrary precision.

Even C is much happier with bigints for constant folding: it is the only way to get the correct result for an expression (perhaps obtained after some macro expansion, even if you don't put it explicitly in your source code) like (123456789087651234*65125412651209128612+187451)%10000000141 or (140000000000041*150000000000061+134500000000139)%250000000000111.

I forgot what the C or C++ standard says about such constant expressions. Computing them correctly is certainly not wrong. But Fortran requires them to be computed correctly, and that need bigints. My second example contains only primes fitting in 64 bits, but you need bignums to compute the result correctly...

Also, GCC when cross-compiling needs more precision the the host integer. Consider obviously cross-compiling from a 32 to a 64 bits machine, you certainly want the constant folding to compute all the 64 bits!

In addition, some clever optimizations (notably polyhedral optimizations like Cloog or PPL which are used by GCC) may require, during one optimization pass and internally, bigint arithmetic to be precise. More generally, optimizations are symbolic processing, and symbolic processing usually needs bignums. During such optimizations, quite big numbers could appear even if the source code has only quite small constants.

like image 83
Basile Starynkevitch Avatar answered Nov 05 '22 09:11

Basile Starynkevitch