Live data from Hacker News

Original Age of Empires 2 dev talks about its usage of assembly code

old.reddit.com

31–40 of 113 posts

Re: Original Age of Empires 2 dev talks about its usage of assembly code

#31
post #29

You probably need to ignore the first comment thread to see the comment of interest.

Not any more; in any case, here's a link to the comment in question:

https://old.reddit.com/r/aoe2/comments/18ysttu/_/kgltqrg/

Re: Original Age of Empires 2 dev talks about its usage of assembly code

#32
post #7

> A key speedup technique AoE used was realized during discussions I had with iD software programmer and optimization guru Michael Abrash over lunch at Tia's Mexican Restaurant in Mesquite, TX. How many freeform interactions like this did we lose because of the Internet's illusion of being connected?

Don't people still have lunch?

They do. Over their desks, while working or in a video call.

Re: Original Age of Empires 2 dev talks about its usage of assembly code

#33
post #12
post #6

Earlier quoted context omitted.

Are there any good resources on using mipmapping and swizzling effectively?

I was actually trying to find it - there were lots of .txt files published back then - and there was one about texture mapping from 1992... 1994? - and it explained swizzling and why it was efficient with caches.

You might be thinking of the article written by Pascal of Cubic Team. I think the archive is called pasroto.zip and it explained why rotozoomer performance would tank when the texture was rotated by 90 degrees (since you're stepping in the Y direction and blowing out your cache for every pixel). Really interesting at the time.

Re: Original Age of Empires 2 dev talks about its usage of assembly code

#34
post #7

> A key speedup technique AoE used was realized during discussions I had with iD software programmer and optimization guru Michael Abrash over lunch at Tia's Mexican Restaurant in Mesquite, TX. How many freeform interactions like this did we lose because of the Internet's illusion of being connected?

I think we've lost some and gained other.

People may say that Discord and similar will compensate, greatly, as the number of interactions can grow a lot. On the other hand, I don't think the experience is comparable to fully focusing on the person you're eating in person with.

Re: Original Age of Empires 2 dev talks about its usage of assembly code

#35
post #20

Earlier quoted context omitted.

It was always so disappointing, spending hours coding up a tightly wound assembly language version of some inner loop that uses half the instructions generated by the C++ compiler, only to find that your slaved-over version is actually 5% slower . But OTOH... the thrill when it actually was faster! This was back in the Pentium 4 era, where there were deep pipelines and oddities like some simple ALU instructions (ADD,…

> uses half the instructions generated by the C++ compiler is there a tool that could profile/predict ahead of time, so that one does not attempt to hand write assembly before knowing for sure it will beat the compiled version?

There was Intel VTune, which I heard was good, though I haven't used it myself. One difficulty is that there are many non-obvious and hard-to-predict factors that interact to produce pipeline stalls. Instructions had specified throughputs and latencies (throughout being the number of cycles before another independent instruction of that type could be initiated; latency being the number of cycles before its output could be used by another instruction), but that was only part of the story. Was that memory read from L1 cache? L2? Main memory? Is this conditional branch predictable? Which of the several applicable execution units will this micro-op get sent to? There were also occasional performance cliffs (alternating memory reads that were exactly some particular power of 2 apart would alias in the cache, leading to worst-case cache behaviour; tight loops that did not begin on a 16-byte boundary would confuse the instruction prefetcher on some CPUs...)

I may be getting x86 CPU generations mixed up. But having wrestled with all this, I can certainly see the appeal of hand-optimising for older, simpler CPUs like the 6510 used in the C64, where things were a lot more deterministic.

Re: Original Age of Empires 2 dev talks about its usage of assembly code

#36
post #5
post #2

>The use of assembly in the drawing core resulting in a ~10x sprite drawing speed improvement over the C++ Wow that's a chunky improvement over an already fast lang

This was in 1999. C++ compilers have come a long ways since then. While there are still opportunities for hand-written asm to go and order of magnitude faster than C++, they're mostly around manual vectorization where the auto-vectorizer fails.

Even intrinsics didn't even necessarily work well. MSVC, in particular, was really, really bad back then with SIMD intrinsics -- any use of MMX or SSE intrinsics in VC6 would result in more than two-thirds of the generated code being move instructions, with a single value sometimes moved two or three times between ALU instructions. It was trivial to beat the compiler with hand-written assembly. MMX intrinsics were never fixed and SSE intrinsics weren't fixed until VS2010.

For scalar code, it was more that the CPUs got better, as out-of-order execution starting with the Pentium Pro made instruction scheduling less important. The original Pentium CPU was an in-order design with two pipes where the second V pipe had significant restrictions, which was harder for compilers to deal with than the PPro/PII and its decoding pattern.

Re: Original Age of Empires 2 dev talks about its usage of assembly code

#37
post #28
post #5

Earlier quoted context omitted.

This was in 1999. C++ compilers have come a long ways since then. While there are still opportunities for hand-written asm to go and order of magnitude faster than C++, they're mostly around manual vectorization where the auto-vectorizer fails.

Yes, younger devs grown up on the myth of C and C++ being always fast, have missed the days when inline Assembly was a higher count than pure C and C++ code. I have seen applications for MS-DOS, effectively using C as a Macro Assembler, only the data structures and high level logic was C as if Macro Assembler macros.

> Yes, younger devs grown up on the myth of C and C++ being always fast, have missed the days when inline Assembly was a higher count than pure C and C++ code.

And still is in VLC. (Okay, maybe not higher, but they do use a crapton of assembly in their decoders, and it does speed them up by a factor of 10 or so today.)

Re: Original Age of Empires 2 dev talks about its usage of assembly code

#38
post #28

Earlier quoted context omitted.

Yes, younger devs grown up on the myth of C and C++ being always fast, have missed the days when inline Assembly was a higher count than pure C and C++ code. I have seen applications for MS-DOS, effectively using C as a Macro Assembler, only the data structures and high level logic was C as if Macro Assembler macros.

> Yes, younger devs grown up on the myth of C and C++ being always fast, have missed the days when inline Assembly was a higher count than pure C and C++ code. And still is in VLC. (Okay, maybe not higher , but they do use a crapton of assembly in their decoders, and it does speed them up by a factor of 10 or so today.)

Video decoding has always been a prime example for SIMD stuff, however I wonder how much of that code VLC devs could wipeout, assuming hardware vídeo decoding being available everywhere.

Re: Original Age of Empires 2 dev talks about its usage of assembly code

#39
post #28

Earlier quoted context omitted.

Yes, younger devs grown up on the myth of C and C++ being always fast, have missed the days when inline Assembly was a higher count than pure C and C++ code. I have seen applications for MS-DOS, effectively using C as a Macro Assembler, only the data structures and high level logic was C as if Macro Assembler macros.

> Yes, younger devs grown up on the myth of C and C++ being always fast, have missed the days when inline Assembly was a higher count than pure C and C++ code. And still is in VLC. (Okay, maybe not higher , but they do use a crapton of assembly in their decoders, and it does speed them up by a factor of 10 or so today.)

Do you mean the VLC media player? Just curious is there any reason modern compilers don't beat assemblies or is that simply a legacy issue?

Re: Original Age of Empires 2 dev talks about its usage of assembly code

#40
post #22
post #20

Earlier quoted context omitted.

> uses half the instructions generated by the C++ compiler is there a tool that could profile/predict ahead of time, so that one does not attempt to hand write assembly before knowing for sure it will beat the compiled version?

For small pieces of code I would try to use a superoptimizer like souper.

https://github.com/google/souper

It looks like it only supports Linux and macOS - no Windows, but no other things too like mobile.

It seems it exists for ten years, I wonder what optimizations aren't still picked by the recent compilers.

Post reply on HN