5

This week I could optimize using a reduced C library that allowed a drastic shrinkage in code size - from about 60 K to about 6 K and then we could load the code in the 8 K on-chip memory of an FPGA (Altera DE2) which I suppose is SRAM so there is SRAM both on-chip and off-chip(?)

The program was rather small itself and we noticed that most of the size was from libraries and doing embedded system we reduce the libraries to only what is needed so that the footprint is minimized.

It makes me wonder about something I heard in the media which was a story, maybe fictious, that Microsoft had to deliver a C compiler in only 20 K or so in the 70s or early 80s when there was not much memory available for software, is it true? What is a feasible size of the footprint for a small C compiler?

4
  • 4
    You may wish to investigate an existing project such as bellard.org/tcc Commented Oct 11, 2013 at 4:32
  • I'm not sure about how legit Microsoft's story is, but this should give you an idea on how small the first c compiler is github.com/mortdeus/legacy-cc . its around 50K for the source, might be smaller once compiled.
    – Maru
    Commented Oct 11, 2013 at 4:45
  • 6
    The size of the compiler has nothing to do with the size of the binaries it generates, which seemed to be your problem (unless you're putting the compiler on the fpga)
    – James
    Commented Oct 11, 2013 at 8:19
  • 2
    use the optimization setting for space instead of for speed Commented Oct 11, 2013 at 8:45

2 Answers 2

9

The Software Toolworks C compiler for CP/M came on one 8" SSSD floppy, and compiled most of the language as of about 1982. It required a machine with 56K of memory and one floppy drive. I don't remember how much the resident portion of CP/M required.

Turbo Pascal 1.0 required 64K on a CP/M machine, and included an IDE. It was a single-pass compiler, written in heavily-optimized assembly language, and did EVERYTHING in RAM, making it BLINDINGLY fast. (Bill Gates was reportedly NOT happy about it: it made Microsoft look really bad.)

6
  • 4
    I remember Turbo Pascal 1.0. It compiled in 10 seconds a program I wrote that took 10 minutes to compile on an Apple IIe using the Apple Pascal compiler. Commented Oct 11, 2013 at 5:46
  • 1
    Says a lot, if you think about it: the authors of Turbo Pascal didn't use Pascal inside their compiler. It might be fast, but the code produced clearly wasn't that efficient.
    – MSalters
    Commented Oct 11, 2013 at 9:43
  • @MSalters: Well, Pascal as a language wasn't designed specifically for writing compilers. People could still get the same performance that the compiler got by writing their programs the way Borland wrote their compiler, with the accompanying tradeoffs. I think that there is a general sense in the programming community that all languages should be capable of everything, but that's just not reality. FWIW programs written and compiled in Turbo Pascal did perform pretty well. Microsoft's C# compiler is written in C++; the Mono compiler is self-hosting. Commented Oct 12, 2013 at 2:27
  • @MSalters: The code wasn't terribly efficient, but it was loads better than BASIC. Further, I had a free third-party tool to take a suitably-formatted assembly-language source file and produce an "inline" directive, using >identifier and similar notations to identify variables by name. The difference between what the compiler generated and optimal code was more significant for small routines than big ones, so a dozen or so lines of assembly could in some cases allow a ten-fold overall performance boost.
    – supercat
    Commented Feb 20, 2015 at 19:46
  • @RobertHarvey: FYI, the most recent version of the C# compiler is written in C#.
    – supercat
    Commented Feb 20, 2015 at 19:47
4

Writing a tiny C compiler is easy, if you don't care about the performance of the generated code. TinyCC (originally by F.Bellard, now here) is such a compiler: it compiles quite quickly C programs (perhaps with a compilation time 5 to 10 times faster than GCC ...) but the produced executable is very slow (often more than 3 times slower than what gcc -O2 gives you). And nwcc is small, but probably generates slow code (w.r.t. what gcc -O2 can produce). The tcc compiler (i.e. TinyCC) is quite small (a few dozens of thousand lines of C code) and the executable (on x86-64) is about 190Kbytes.

But on current processors, you need an optimizing compiler to get most of the performance from the compiled executable code. And good optimizations are hard to achieve and need a big lot of compiler code: both GCC and Clang/LLVM have several millions lines of source code (some of which is generated by specific programs producing C or C++ code). See also this reply to a related question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.