for clarification... machine code is a form of VHDL? Because that's kind of how I see him explaining since that's what I had to do to program a 8086 chip instruction set...
VHDL is an FPGA programming language, while machine codes are instructions that directly use hardware-based instruction hard-coded in to a chip, called the instruction set. You can use VHDL or Verilog (basically same thing) to define the behavior of an FPGA to give it an instruction set, that you could then write machine code to program in.
I think it is way more important to know the compiler you're working with than to know the underlying assembly. You have to write code that the compiler will be able to optimize.
Then, read the assembly for critical part and make sure it was optimized correctly by the compiler.
Buy by analyzing the underlying assembly code can deduce how your compiler is creating the assembly language.
It has been a while since I touched C++ but back then I suddenly realized that only the first 4 parameters are passed on as register memories, the fifth is pushed onto the stack. So if you wanted speed then any method you call should be limited to 4 parameters.
But not the assigning to zero, the assigning to other variable. Lines ...000f57 and ...000f5a. Go to 8:42 in the video to see very clearly, that they're both collectively labeled "x = y", and my point is that that should be able to be done in one line, not two.
Reading and writing to memory at the same time might not be possible on that architecture. The difference with writing 0 and 0xFF is that those are constants/literals and not memory addresses.
What is the reason for putting your code into an infinite while(1) loop? Just to output multiple times? Also, in printf, shouldn't you be using printf(%i\n, x) since you are printing an integer rather than a double?
18 comments
7 u/roznak [OP] 10 Aug 2015 03:00
In order to write very efficient code in C/C++ it is useful to understand how the C gets translated into machine code.
In a lot of cases your C/C++ code can work faster when you reorganize your C/C++ code to a point where it creates the most optimal assembly code.
0 u/spookybm 10 Aug 2015 10:41
for clarification... machine code is a form of VHDL? Because that's kind of how I see him explaining since that's what I had to do to program a 8086 chip instruction set...
2 u/magnora 10 Aug 2015 12:44
VHDL is an FPGA programming language, while machine codes are instructions that directly use hardware-based instruction hard-coded in to a chip, called the instruction set. You can use VHDL or Verilog (basically same thing) to define the behavior of an FPGA to give it an instruction set, that you could then write machine code to program in.
0 u/bvanheu 10 Aug 2015 15:34
I think it is way more important to know the compiler you're working with than to know the underlying assembly. You have to write code that the compiler will be able to optimize.
Then, read the assembly for critical part and make sure it was optimized correctly by the compiler.
0 u/roznak [OP] 10 Aug 2015 21:51
Buy by analyzing the underlying assembly code can deduce how your compiler is creating the assembly language.
It has been a while since I touched C++ but back then I suddenly realized that only the first 4 parameters are passed on as register memories, the fifth is pushed onto the stack. So if you wanted speed then any method you call should be limited to 4 parameters.
0 u/theoldguy 10 Aug 2015 22:06
For the specific compiler, OS and 32 bit vs. 64 bit, that's probably true.
http://www.agner.org/optimize/calling_conventions.pdf
2 u/un_salamandre 10 Aug 2015 07:06
A question: Why does "x = y" need two lines? Would not "movl -0xc(%rbp), -0x8(%rbp)" suffice?
-1 u/JohnQCitizen 10 Aug 2015 08:23
It only uses one line. It justs takes two lines to add a number.
1 u/un_salamandre 10 Aug 2015 09:37
I'm not talking about the adding, but the assigning part.
-1 u/JohnQCitizen 10 Aug 2015 09:38
I'm saying the assigning part is only one line.
1 u/un_salamandre 10 Aug 2015 09:53
But not the assigning to zero, the assigning to other variable. Lines ...000f57 and ...000f5a. Go to 8:42 in the video to see very clearly, that they're both collectively labeled "x = y", and my point is that that should be able to be done in one line, not two.
1 u/Zerot 10 Aug 2015 19:35
Reading and writing to memory at the same time might not be possible on that architecture. The difference with writing 0 and 0xFF is that those are constants/literals and not memory addresses.
7 u/Ronjoe 10 Aug 2015 13:06
x86 doesn't have a MOV that takes two memory addresses. You must use a temporary register to move data between memory addresses.
1 u/un_salamandre 10 Aug 2015 17:39
Ah, ok, thank you.
2 u/DickHertz 10 Aug 2015 12:59
assembly != machine language
2 u/roznak [OP] 10 Aug 2015 21:45
Nope but it directly translates to machine language almost 1 on 1.
0 u/SxToMidnight 16 Aug 2015 19:50
What is the reason for putting your code into an infinite while(1) loop? Just to output multiple times? Also, in printf, shouldn't you be using printf(%i\n, x) since you are printing an integer rather than a double?