GCC optimization steps [closed] - c

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am working or performance evaluation and I encountered a problem: when I add some instruction to the code it executes faster than the initial code, I think due to compilers optimization (without specifying any).
How do compiler optimization works? In particular are they performed while converting C to Assembly or in the step from Assembly to binary code?
I suppose both, however is possible to know which optimizations are performed in each step?
I have looked at assembly but I have found only slightly differences so I suppose that some architecture specific optimization is involved.
Thank you!

Assembly is binary code, to all intents and purposes BTW. Most optimisation occurs when the higher level language is compiled to assembly. It's weird that you add functionality and it gets faster... but compiler optimisation is kinda dark magic.
You may be able to get to the bottom of it, you could compile your C to assembly (gcc -S) and see what it did for your versions... Of course bear in mind not all instructions are created equally, this will help you more if you have some awareness of assembly and how CPUs and buses and memory, etc, work at a low level.

Related

Optimizing Lua for embedded processor? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am embedding Lua in a programm for no-eabi device with 16Mhz 32-bit ARM7TDMI processor and 256Kb RAM (yes, that's GBA). Currently it's working flawlessly (thank you, StackOveflow users, for answering my questions), doing easy tasks, but what optimizations I can do to perform overall efficiency? Here's some of my thoughts:
Currently I am storing my Lua code as constant char array (there's separate ROM up to 32Mb, so it helps to free RAM). When I want to run it I just push this string to Lua stack and "pcall" it. But as I know, Lua builds that code into byte-code in RAM. I thoght that can be some problems with big Lua files too. Any way-to precompile that byte-code and save it to constant container too?
Which asm command set is better for running Lua - THUMB or ARM?
EDIT: Maybe, changing vanilla Lua to LuaJIT? As I know, LuaJIT has many assembly lines of code (which makes it less portable), any chance to perform successful build to old ARM7 processors?

Compiler for custom cpu architecture [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is there a tool that will convert C to assembly that will run on Windows?
The cpu architecture (8 bit and 16 bit) is in-house meaning that it has it own instruction set.
The C compiler should use our in-house assembly language. The language is not based on x86 nor ARM. I can not provide too many further details because it is company's Intellectual Property.
You will have to learn one of the open source Compilers which are using replaceable backend for their code generation. Gcc, and CLang, might be a good starting point.
Yes, Virginia, there are "tools to convert C to assembly" on Windows. GCC comes to mind; likewise MS Visual Studio.
I'm sure this isn't what you want, since the off-the-shelf versions for Windows tend to generate x86 object code. It sounds like you want a compiler for a special not-x86 instruction set.
Given that you have not provided any details, there's no way for anybody to respond if such a compiler already exists.
In the absence of such detail, all one can do is offer you generic advice. It is possible to configure GCC to generate code for relatively arbitrary instruction sets. It isn't a walk in the park to do this, but it has been done for many different instruction sets.

Good output for first language [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have built a compiler for my new programming language. It works perfectly. I am onto the last part. I need to put it into a runnable format (an executable). I was looking at the mach-o format (I am runnning on osx), but it is not well documented and I am not that advanced. So my question is:
What is a good output for my first compiler?
P.S. I would really like to be able to run my program in terminal
I would suggest you to use TAC as an output of your compiler. TAC is a context free language, which means it can easily be converted to assembly by a simple script. It is widely used by compilers to optimize the intermediate code, before it is translated to a processor specific assembly language and being optimized to the corresponding processor architecture.
If I'm not wrong, there are several types of TAC code, and you will need to find which one suits you better. I remember having used it as an output of my compiler in the compiler course of my graduation, because I could then run a python script which would translate it into x86 assembly

arm or mips core to implement in fpga [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am trying to implement a risc processor core in fpga. Is it a good idea to do such a project. I am confused whether to implement an arm core or mips core. Please tell me which would be a better option consider that i am a starter in this field.
Yes such a project would be pretty cool and you would learn a lot. That being said I believe you should build smaller things first. As for ARM vs. MIPS, the complexity is equivalent, but I would pick ARM cause it's actually the most popular processor architecture in the world right now, so the knowledge you would gain would be highly practical.
I recommend starting with a book called "CODE". It will teach you all the basics in a very clear way. Once you read that you should be able to build logic gates, full adders and even a simple generic purpose computer, all using nothing but relays and wires.
Once you've done those smaller projects then try something larger with transistors, protoboards or FGPA. One very interesting computer you could build is the IAS, also called the Von Neumann machine, which is the base for all modern computers (yet is very simple and elegant).

Crenshaw's "Let's Build a Compiler": Transcription to C and x86 Assembler? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to work through Jack Crenshaw's excellent compiler programming tutorial "Let's Build a Compiler" and have bumped into two hurdles. First the code is written in Pascal, a great language for which I have both respect and fondness from a brief exposure to it in the mid 1980s, but which I have not touched since. I currently program mostly in C.
The other hurdle is that the generated assembler is for the Motorola 68000 line of processors. While I may be able to find a translator for it, it would be preferable if I could generate Intel x86 assembler (either Intel or AT&T style).
I can work through the code on Linux, Mac OsX or Windows 7, if it makes anything easier. I have access to all of the named operating systems.
I do not feel fully qualified to do the transcription myself. Has anybody worked this out already, or do you have other suggestions?
Any ideas, feedback or suggestions welcome.
You could run the generated code on a 68K emulator—several of the entries on that page are open-source.
It might be easier to target the JVM instead of a native processor. as for translating Pascal to C... it'shouldn't be that much of a hurdle really.

Resources