Jump to content

  • Log In with Google      Sign In   
  • Create Account


Programming OpenGL using Assembly ASM


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
20 replies to this topic

#1 WillPash   Members   -  Reputation: 211

Like
0Likes
Like

Posted 11 October 2005 - 04:24 PM

Hi I have been writing OpenGL using C++ for a long while. Now I want to write faster applications, so I have decided to go for a lower level programming language so I have enquired about Assembly. I have the ASM code for various APIs, except OpenGL, so can someone recommend OpenGL programming tutorials using ASM, from beginners to advanced level will suffice. Nehe doesnt seem to have many features on ASM coding. Helping me with finding good links will help me in a big way.Thank you for now and forever Regards

Sponsor:

#2 Thaligar   Members   -  Reputation: 142

Like
0Likes
Like

Posted 11 October 2005 - 09:25 PM

try this
NeHe

tuts for several languages, and from beginner to advanced,

greets
tgar

#3 WillPash   Members   -  Reputation: 211

Like
0Likes
Like

Posted 11 October 2005 - 09:48 PM

As stated by my previous post, i dont need general OpenGL tutorial as I stated clearly Nehe doesnt have the details that I need. Read the message as i clearly need Assembly tutorials or information that strictly which deals with openGL.
Thanks anyway...

#4 FlowingOoze   Members   -  Reputation: 236

Like
0Likes
Like

Posted 11 October 2005 - 10:07 PM

Why on Earth would you want to program OpenGL with assembly? I doubt that you'll be able to make faster applications that way. Dealing with OpenGL mostly just involves a bunch of function calls anyway, coding them manually in assembly won't improve performance at all.
If you're doing some heavy computations on the CPU then you might want to use SSE instructions, but that doesn't really have much to do with OpenGL.

#5 WillPash   Members   -  Reputation: 211

Like
0Likes
Like

Posted 12 October 2005 - 12:09 AM

Well im taking the word of experienced Demo programmers who swear that by programming in assembly, improves performance as the lower the level of language, the faster the execution and the smaller the final executable will be. Assembly is used my most if not all top level graphics and application programmers (especially console game programmers, who always point out the importance of using low-level machine code in their apps). I am far away from that level of experience as im more of an enthusiast. I like to see which ways can improve the performance if possible. I am not saying it will 100% guarantee a faster program, but i want to see if these tutorials exist so I can see for myself...

#6 phantom   Moderators   -  Reputation: 6791

Like
0Likes
Like

Posted 12 October 2005 - 12:27 AM

Hmm it's possible you misunderstood slightly [smile]

Assembler is usefull for optermising certain parts of the code AFTER profiling, however in the majority of cases the code will be done in something like C or C++ first. Ofcourse the exception to this rule are the demo scene coders who are making small apps (64k intros and the like).

Seriously, apart from certain parts of a program where profiling and detailed knowledge of whats going on with the data can help you tune the code, most of the time the C or C++ compiler is going to produce MUCH better code than you can buy hand. CPU's these days are VERY complex beasties, you can infact end up doing things much slower if you dont know what you are doing.

That all said, if you want to go down that road then using OpenGL from Assembler is much like using it from C, C++ or any other language, you are just making function calls, infact i'm pretty certain modern assembler compilers can perform C-style function calls for you, without you having to worry about the ins and outs of it, you'll have to look that up in the docs for your tool of choice.

Nehe does have the tutorial code converted to assembler, at least in the first case and if you are serious about working on such a low level then you need to get into the habbit of solving these things for yourself anyways, so its probably a good time to start.

#7 mikeman   Members   -  Reputation: 2176

Like
0Likes
Like

Posted 12 October 2005 - 12:36 AM

What he said.

Don't go down that road, it's not worth it. At least know that if you do it, what you gain will not be performance, but additional knowledge(knowing ASM never hurt anybody). Do you think the Doom3 engine for example(and any other top-notch game) is coded in assembly? Nope, it's C/C++. I really doubt even if 64K(an artificial boundary) demo coders use assembly*. For the most parts, they could just use a really lightweight C compiler.

Quote:

...improves performance as the lower the level of language, the faster the execution and the smaller the final executable will be.


I would argue that, the better the programmer is, the faster the execution and the better the program mechanics will be. There is absolutely no need to write an entire program in assembly. You can use C/C++ or other higher level languanges and use the inline assembler for the most critical parts of the code.
In any case, the choise of languange has very little to do with the execution speed of OpenGL itself, which resides in the drivers and the GPU, not in your code.

*Proof: Taken directly from the .kkreiger faq(the FPS game in 96KB, made by the same guys who developed .the .product demo):

Quote:

In general, if you have any technical questions concerning .kkrieger, either refer to our
web site or contact us via email. However past experience shows that there are some rumours
and misunderstandings about our work that are very hard to correct, so we'll state the truth
here, in written form, for all the world to see :)

-We do .not. have some kind of magical data compression machine that is able to squeeze
hundreds of megabytes of mesh/texture and sound data into 96k. We merely store the
individual steps employed by the artists to produce their textures and meshes, in a very
compact way. This allows us to get .much. higher data density than is achievable with
normal data compression techniques, at some expense in artistic freedom and loading times.

- .kkrieger is not written in 100% assembler/machine language. Not even nearly. Like the
vast majority of game projects being developed today, .kkrieger was mostly written in
C++, with some tiny bits of assembler where it is actually advantageous (notably, there
are a lot of MMX optimisations in the texture generator).

- A kilobyte is, historically, defined to be 1024 (2^10) bytes, not 1000. Thus .kkrieger is
a game in 96k even though it's actually 98304 bytes.
- The concept of the texture/mesh generators was developed by fiver2. We do .not. want to
claim that the techniques we used to develop .kkrieger are new inventions. It´s rather a
selection of useful operations and their parameters to optimise the results.


[Edited by - mikeman on October 12, 2005 7:36:41 AM]

#8 WillPash   Members   -  Reputation: 211

Like
0Likes
Like

Posted 12 October 2005 - 01:13 AM

Thanks Phantom and Mikeman. Your views are more than appreciated as you are right about the function calls of openGL. It wont hurt learning from here and learning a little assembly. I might just first of all learn how to write inline asembly inside my C++ code. It wont possibly make much difference if any. As i am trying to find alternate ways to push that extra bit of power out of my application. It looks like all you guys who have replied are right. Stick to what i know best - C++, as it is still the best programming language there is available.

#9 vanevery0   Members   -  Reputation: 146

Like
0Likes
Like

Posted 12 October 2005 - 01:32 AM

Quote:
Original post by phantom

Seriously, apart from certain parts of a program where profiling and detailed knowledge of whats going on with the data can help you tune the code, most of the time the C or C++ compiler is going to produce MUCH better code than you can buy hand. CPU's these days are VERY complex beasties,


I get tired of hearing this kind of exaggerated claim of compiler efficacy and quality. It has never been true and it is not going to be true. The reason is that CPU instruction sets keep changing and by the time someone's starting to bother to utilize CPU-specific optimizations, another CPU has come out and the whole thing starts all over again. It is, seemingly, too much work for the industry to keep up with. A lot of markets aren't driven by compiler performance, but rather by IDE GUI builder niceties, so this is another part of why the Any Good Compiler of academic legend never exists in industrial practice.

That said, yes you can waste your time writing ASM code for things that are pointless / no faster than what the compiler will produce. It's important to know what kind of ASM code your compiler will produce and what it won't. And, um, don't fear the 'complexity' of the CPUs. It's just a learning curve same as any other stupid API in industry. Just as funky and just as pedestrian once you finally know all the details.


#10 vNistelrooy   Members   -  Reputation: 140

Like
0Likes
Like

Posted 12 October 2005 - 01:40 AM

Don't forget that good optimizing compilers will usually be able to produce very good assembly code out of your C++ code, many times at least as fast as yours. Use assembly only when your assembly is faster than the compiler generated code, usually where the code can benefit from SSE/MMX instructions.
"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

#11 mikeman   Members   -  Reputation: 2176

Like
0Likes
Like

Posted 12 October 2005 - 02:36 AM

Quote:
Original post by vanevery0
Quote:
Original post by phantom

Seriously, apart from certain parts of a program where profiling and detailed knowledge of whats going on with the data can help you tune the code, most of the time the C or C++ compiler is going to produce MUCH better code than you can buy hand. CPU's these days are VERY complex beasties,


I get tired of hearing this kind of exaggerated claim of compiler efficacy and quality. It has never been true and it is not going to be true. The reason is that CPU instruction sets keep changing and by the time someone's starting to bother to utilize CPU-specific optimizations, another CPU has come out and the whole thing starts all over again. It is, seemingly, too much work for the industry to keep up with. A lot of markets aren't driven by compiler performance, but rather by IDE GUI builder niceties, so this is another part of why the Any Good Compiler of academic legend never exists in industrial practice.

That said, yes you can waste your time writing ASM code for things that are pointless / no faster than what the compiler will produce. It's important to know what kind of ASM code your compiler will produce and what it won't. And, um, don't fear the 'complexity' of the CPUs. It's just a learning curve same as any other stupid API in industry. Just as funky and just as pedestrian once you finally know all the details.


I think when phantom said "much better code than you" meant the OP, as a beginner or even medium-level in assembly, which is the majority of the already limited crowd that even know anything about ASM. Modern compilers are in fact more than able to achieve great optimizations, but there's no doubt that proficient programmers in ASM can produce specialized code even better than that. The point is to know where it will make a difference and where it will not.

As for the complexity of the CPUs, I only partly agree. Learning ASM is not that much difficult, but after a certain point, getting the best performance out of the pipeline(by rearranging the order of instructions that do not affect each other for example) can be very tricky, and you can't always obtain easily the info you need about the hardware.

#12 vanevery0   Members   -  Reputation: 146

Like
0Likes
Like

Posted 12 October 2005 - 02:49 AM

Quote:
Original post by mikeman

I think when phantom said "much better code than you" meant the OP, as a beginner or even medium-level in assembly, which is the majority of the already limited crowd that even know anything about ASM.


Hadn't thought of that. Wouldn't think of that, as it's a defeatist attitude. All we can do is learn, yes? Otherwise, I think we agree on the pitfalls of assembly coding. Drove me to bankruptcy, actually. $82K worth. Thank goodness it's over now, as of this week. Now I get to start fresh on new mistakes!


Cheers, Brandon J. Van Every(cruise (director (of SeaFunc) '(Seattle Functional Programmers)))

#13 phantom   Moderators   -  Reputation: 6791

Like
0Likes
Like

Posted 12 October 2005 - 06:35 AM

@mikeman
I stand corrected on the 64k issue and you're quite right about where I was going on the assembler issue.

Infact, I did mention profiling as to when you would apply assembler language [smile] (directed at vanevery0)

#14 zedzeek   Members   -  Reputation: 528

Like
0Likes
Like

Posted 12 October 2005 - 07:40 AM

real world example
within a couple of months of releasing quake3 a function written with asm was actually slower than the plain c version.
with a higher language to get the benifits of a new compiler or new hardware u just need to recompile it with asm youre buggered u need to rewrite it

#15 Raghar   Members   -  Reputation: 92

Like
0Likes
Like

Posted 12 October 2005 - 08:09 AM

Quote:
Original post by WillPash
Hi I have been writing OpenGL using C++ for a long while. Now I want to write faster applications, so I have decided to go for a lower level programming language so I have enquired about Assembly. I have the ASM code for various APIs, except OpenGL, so can someone recommend OpenGL programming tutorials using ASM, from beginners to advanced level will suffice. Nehe doesnt seem to have many features on ASM coding.

Helping me with finding good links will help me in a big way.Thank you for now and forever
Regards


I think that macro assembly has superior clarity over C++ code. If you'd like to forget about object dealocations and CPU specific code, use Java, if you need to do allocation/dealocation by hand anyway try to find some reasonable macroassemblers. You would at least get rid of majority of {} and ; .
Look at http://www.masmforum.com/simple/index.php



Of course the main problem in assembly is too much typing. Also comments in the source code are neccessity. On the other hand we have copy and paste, and assembly tends to work well with the copy and paste.

I don't know why anyone pretends like Assembly ended, it has not. Tools even without support of a larger companies becomed better, and CPUs rather standardizated itself into a common set of features. 64 bit assembly is actually nice because you could have all that freaking 14 registers (big improvement from 6). If you need just call OpenGL from an assembly it's as easy to write as from C++. Espacially with a macro assembler, and a prepared list of constants. The main slowdown is driver anyway so the main advantage of such dll linked with rest of your program would be small size.

To sum it up. There is nothing wrong with learning assembly and trying to create a small (or kinda large) OpenGL program. Programmers that don't have any experience with pure assembly/macroassembly are missing important experience that could increase theirs understanding about current CPUs. Direct experience is best. (And experience with messing up seemingly unrelated things in rest of the program is even better.)


BTW the biggest problems with creating programs in assembly are windoze internals and lack of documentation (Intel syntax assembly related) on linux. I always tended to write things first in Java, then if there was time add also JNI library done in assembly. There is no doubt that carry flag is accessible anly from assembly, and proper registry utilization, and variable chaching is hard to be done by compiler. There is also some (minor) programming language overhead, and some compilers tends to add a few unnecessary instructions. (If you'd like to know why look at optimalizing compiler design and try to imagine result of theirs work from distance.)



#16 V-man   Members   -  Reputation: 797

Like
0Likes
Like

Posted 12 October 2005 - 12:10 PM

Quote:
Original post by Raghar
then if there was time add also JNI library done in assembly.


What's JNI?



#17 blueshogun96   Crossbones+   -  Reputation: 811

Like
0Likes
Like

Posted 12 October 2005 - 12:25 PM

Maybe he's not writing a game. Maybe he wants wo write a sega saturn emulator or something, where speed counts.

#18 JavaCoolDude   Members   -  Reputation: 670

Like
0Likes
Like

Posted 12 October 2005 - 05:44 PM

Quote:
Original post by V-man
Quote:
Original post by Raghar
then if there was time add also JNI library done in assembly.


What's JNI?


Java Native Interface: a bridge from Java to DLLs

#19 hplus0603   Moderators   -  Reputation: 4966

Like
0Likes
Like

Posted 12 October 2005 - 05:55 PM

If someone wants to learn assembly, let him learn assembly.

If that someone thinks that his assembly program will run faster, let him. If he actually cares, he'll write both versions and profile them, and the profiler will tell him whether it's true or not.

In general, a program's run time is dependent first on the algorithmic complexity (N-squared vs N-log-N vs N vs O(1)); second on its memory behavior (how many cache misses and TLB misses); and only third on its instruction selection. Thus, you can only optimize something in assembly if you already have optimal algorithmic choices and optimal memory behavior.

When it comes to calling OpenGL, calling OpenGL from assembly is exactly the same as calling any other standard API. You push the arguments, and call the function, just like you would call, say, CreateWindowW(). (Note the __stdcall calling convention if you're on Windows). Thus, you don't need an asm-specific OpenGL tutorial.

#20 Promit   Moderators   -  Reputation: 6106

Like
0Likes
Like

Posted 12 October 2005 - 05:56 PM

Quote:
Original post by blueshogun96
Maybe he's not writing a game. Maybe he wants wo write a sega saturn emulator or something, where speed counts.


Assembly does not equate to speed. More often than not, it equates to slower code. Reasons assembly is legitimately used in projects, such as emulators:
1) MMX/SSE optimizations are big in that arena.
2) A lot of the mature emulator projects started a long time ago, well before optimizing compilers reached the level of sophistication that they are at today.
3) Using instructions that the compiler doens't necessarily know about, but the assembler does, or that the compiler simply can't apply very well.
4) Occasionally, the programmer can legitimately exploit something about a particular CPU architecture to gain speed. This is generally restricted to 1 or 2 specific processors, e.g. Pentium 4s based off the Northwood core or something.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS