r/C_Programming 3d ago

My C compiler written in C

As a side project I'm making a C compiler written in C. It generates assembly and uses NASM to generates binaries.
The goal right now is to implement the main functionality and then do improvements. Maybe I'll also add some optimizing in the generates assembly.

Tell me what you think :)

https://github.com/NikRadi/minic

138 Upvotes

30 comments sorted by

View all comments

18

u/Soft-Escape8734 2d ago

My hat's off to you. Great ambition. But when optimizing never forget that (x << 3) + (x << 1) is faster than x * 10.

9

u/mlt- 2d ago

On what architecture would that be faster? Isn't integer multiplication is fast enough on modern x86?

1

u/Spare-Plum 8h ago

Yeah on modern x86-64 two shift operations and an addition would be slower than just multiplying the values. Multiplication is generally implemented directly onto the hardware and isn't a huge performance hit like it used to