Just a correction here - today's high level languages will beat a programmers optimization in assembly.
Really? That's pretty crazy. What are the benefits for doing hand-written assembly then? I know there still have to be some.
Just a correction here - today's high level languages will beat a programmers optimization in assembly.
Not that I know of. And I've interviewed with many game company developers. I don't hear it anymore. They may do some low-level assembly for the CPU though. Things like fast sqrt and stuff like that inlined within C++ code.Really? That's pretty crazy. What are the benefits for doing hand-written assembly then? I know there still have to be some.
I believe Embedded Systems still rely a lot in Assembly.Not that I know of. And I've interviewed with many game company developers. I don't hear it anymore. They may do some low-level assembly for the CPU though. Things like fast sqrt and stuff like that inlined within C++ code.
Some graphics devs can compile the shaders and then make sure they are good but shaders are so monolithic right now that it would be a disaster trying to interpret every single line of Assembly code. Compilers are just that good now.
@ethomaz - C++ gets compiled out to assembly language. What I'm saying is that the compiled assembly code is as fast and efficient as someone trying to write it themselves.I believe Embedded Systems still rely a lot in Assembly.
Actually in 2017 it has a interview because the grow in Assembly job opportunities and it was said:
“The only reasonable explanation for this is that the number of very small devices that are only able to run assembly code is increasing. Even your tooth brush or coffee machine are running assembly code nowadays.”
Ohhhh driver writing uses a lot of Assembly… I’m sure AMD and nVidia use it in their drivers too.
OS like Windows, Linux, MacOS, etc uses assembly at core.
Compilers (yes GCC for example) uses assembly too.
This is a year ago video that says why assembly is still used in niche high performance tasks.
No high level language compiler can beat direct assembly code in performance terms because there is overhead for the function and variable for all high level language.
Are you talking to compile to assembly... you mean using the -s option in the compiler flags to generate an asm file?@ethomaz - C++ gets compiled out to assembly language. What I'm saying is that the compiled assembly code is as fast and efficient as someone trying to write it themselves.
I admire your enthusiasm and knowledge here but my point still stands.Are you talking to compile to assembly... you mean using the -s option in the compiler flags to generate an asm file?
Because compilers doesn't compile out to assembly language... most don't even have the option.
GCC has the -s flag so it can generate an asm file is you want.
Some compilers should use assembly as intermediate language but these are so few and most use AST to machine code (the executable) or it other intermediate languages.
GCC for example uses GENERIC, GIMPLE, and RTL as intermediate language but that depends of the frontend (the frontend can use others intermediate languages).
And a well coded assembly code will always be faster than C++ compiled code because there is no overhead of the fuction calls, variables, classes (if you are using), etc... the only language that will as fast as assembly will be the ones are the same level.
There is a reason in key (and very niche) high performance path it is used assembly instead anything else.
And of course machines that no OS and just code execution that we call Embedded Systems, enter in these most common machines in daily use, are coded in Assembly because there are simple instruction, that needs instantaneous response and the machines doesn't have a environment/hardware to run machine code from high level languages... most don't even have space to hold a compiled machine code form a high level language.
Of coruse Smart Machines that uses Android or others custom OS are different and use more high level language compiled machine code but these are still the very small part of the machines sold for daily use.... most coffee machines are coded via assembly... yeap these Nesspress you guys have at home.
You can make the test.
Create an assembly code to do the math 1 + 1
Create an C++ code to do the math 1 + 1
Assemble the assembly code to run in the CPU and use some tool to count the CPU cycles used.
Compile the C++ to machine code (executable) and run it and use the same tool to count the CPU Cycles used.
You will see the C++ complied executable to use more cycles (overhead) than the assembled code.
You don't compile Assembly code... you assemble it... it is not a compiled language.I admire your enthusiasm and knowledge here but my point still stands.
A compiled piece of code where it was C++ is going to be as fast as an assembly language compiled code.
And again, I state that no developer is making large codebases like shaders in assembly language. That's just not happening.
That is fine and I never disputed that.And again, I state that no developer is making large codebases like shaders in assembly language. That's just not happening.
; Exemplo de um Hello World em Assembly
; ld -m elf_i386 -s -o hello hello.o
section .text align=0
global _start
mensagem db 'Hello world', 0x0a
len equ $ - mensagem
_start:
mov eax, 4 ;SYS_write
mov ebx, 1 ;Número do file descriptor (1=stdout)
mov ecx, mensagem ;Ponteiro para a string.
mov edx, len ; tamanho da mensagem
int 0x80
mov eax, 1
int 0x8
// Your First C++ Program
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}
You are being a nitpick at this point. I've programmed in ASM before. You still have to have an assembler to break down that code.You don't compile Assembly code... you assemble it... it is not a compiled language.
No it will not in every case. Prove it.And not... an assembled ASM code into machine code will run faster than a compiled C++ code into machine code.
Run the two codes I got by exemple and use some tool that give you the CPU cycles used.You are being a nitpick at this point. I've programmed in ASM before. You still have to have an assembler to break down that code.
No it will not in every case. Prove it.
If the performance is negligible, it's not enough to be talked about. Assembly programming isn't the language of choice these days - and I mean ANYWHERE. So not sure why you are pushing that agenda.Run the two codes I got by exemple and use some tool that give you the CPU cycles used.
That is your proof.
It never was.If the performance is negligible, it's not enough to be talked about. Assembly programming isn't the language of choice these days - and I mean ANYWHERE. So not sure why you are pushing that agenda.
Then why are you talking about it as if it's some untapped power that developers need to harness?It never was.
Pushing agenda?
I don’t like Assembly at all.
You are the one that makes a definite statement.No it will not in every case. Prove it.
Yes, because I've programmed in both before. Assembly not for production code but training. I also know the industry for the most part (where they are with regards to programming languages, etc.).You are the one that makes a definite statement.
Sure, but it's nowhere near as an important "need to have" as @ethomaz is making it out to be. I have talked to some game developers at MS and some of the workflow may include looking at shader compiled code and seeing if they can make "some" optimizations to it but for the most part, they are better off doing simple things like baking the shaders down from using if-statements, using smaller sized data structures, and things like that.Is doesn't seem hard to conceptualize, the extra generalization of higher languages could in some situations, especially as the project becomes more complex and the compiler has to work harder.
And I'm not saying they are but based on my dealings with many software developers from all walks of life in realtime industry - making a function or block of code in assembly is not something that is going to save several ms of frametime. So from my view, it's not important and certainly less used otherwise I would be doing it myself.I don't work with five at that level, but at every other levels when push comes to shove a good human programmer will improve upon machine generated code from a higher level of abstraction... I don't think compilers have become magic simply because the machine doesn't know the exact context and intent behind each line of code, si any higher level language needs to add something to cover different possible cases.
Now C is not that high
Again you make a false claim.Yes, because I've programmed in both before. Assembly not for production code but training. I also know the industry for the most part (where they are with regards to programming languages, etc.).
Sure, but it's nowhere near as an important "need to have" as @ethomaz is making it out to be. I have talked to some game developers at MS and some of the workflow may include looking at shader compiled code and seeing if they can make "some" optimizations to it but for the most part, they are better off doing simple things like baking the shaders down from using if-statements, using smaller sized data structures, and things like that.
And I'm not saying they are but based on my dealings with many software developers from all walks of life in realtime industry - making a function or block of code in assembly is not something that is going to save several ms of frametime. So from my view, it's not important and certainly less used otherwise I would be doing it myself.
Because you made a false claim.Then why are you talking about it as if it's some untapped power that developers need to harness?
What claim am I making that's false?Again you make a false claim.
You never listed a case at all. You tried to show an example of a very basic hello world to prove what?The industry does use Assembly yet and I listed several cases… either because it is only option or because they need in some very specific case better performance.
Both have to be compiled to machine code. Assembly is closer to machine code than C++ but it's NOT machine code. There is no OOP in Assembly which is absolutely the norm for game code. Again, you are talking about one-offs for specific functions like a fast sqrt or computing a dot product with less adds/mults and even then it's CPU related and not GPU related. I gave you an example on how it can be used for a GPU by pre-compiling the shader and then examining the byte-code to see if there is anything that can be optimized. BUT I told you then that it wasn't going to be like someone would extract out 50% gains in frametime by "correcting" the compiled code.It does perform better than high level language.
You really have a hard time admitting you were wrong.What claim am I making that's false?
You never listed a case at all. You tried to show an example of a very basic hello world to prove what?
Both have to be compiled to machine code. Assembly is closer to machine code than C++ but it's NOT machine code. There is no OOP in Assembly which is absolutely the norm for game code. Again, you are talking about one-offs for specific functions like a fast sqrt or computing a dot product with less adds/mults and even then it's CPU related and not GPU related. I gave you an example on how it can be used for a GPU by pre-compiling the shader and then examining the byte-code to see if there is anything that can be optimized. BUT I told you then that it wasn't going to be like someone would extract out 50% gains in frametime by "correcting" the compiled code.
If you add up all the C++ code and assembly code in a game, I can bet it wouldn't even be 1% assembly code vs. C++/Python/Java code.
I have no problem admitting when I'm wrong dude. I disagree with your claim that Assembly is needed to make a game perform well. Period.You really have a hard time admitting you were wrong.
Yes, at Lockheed we deal with embedded systems all the time for our rockets and we use C for it. Some assembly for the rockets but mostly C. We aren't talking about general practice. We are talking about games and using it to optimize framerates. There is nothing you have provided for that case.Man… majority of embedded system cant be coded without Assembly…
Wut?I have no problem admitting when I'm wrong dude. I disagree with your claim that Assembly is needed to make a game perform well. Period.
Yes, at Lockheed we deal with embedded systems all the time for our rockets and we use C for it. Some assembly for the rockets but mostly C. We aren't talking about general practice. We are talking about games and using it to optimize framerates. There is nothing you have provided for that case.
Let's just drop it. It's not going anywhere.