Live data from Hacker News

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

old.reddit.com

41–50 of 113 posts

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

#41

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. 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?

Compilers beat hand written Assembly for the general use cases.

Now beating special use cases, like using vector instructions to parallel process video decoding streams is another matter.

It is no accident that after all the efforts improving Java and .NET JITs for auto-vectorization across various vendors, both platforms now expose SIMD intrinsics as well.

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

#42
I'm reading a history of Borland and the author claims that the Turbo Pascal compiler was mostly written in assembly and was also used in Delphi 1.0. No one in Borland could make significant changes in the code so eventually they rewrote it for Delphi 2.0.

Not sure if all was true but very fascinating. I think there is a certain character in programmers who went through the fire and storm by writing softwares in assembly language for non trivial CPUs (like Pentium and up) that is unique.

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

#43
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

Functionality should have been provided by directx though

I think AOE was using DirectX, so I assume that was one level up the stack, ie figuring out which sprites are visible to which extent by walking different data structures and then just throwing stuff at directdraw.

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

#44
post #41

Earlier quoted context omitted.

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?

Compilers beat hand written Assembly for the general use cases. Now beating special use cases, like using vector instructions to parallel process video decoding streams is another matter. It is no accident that after all the efforts improving Java and .NET JITs for auto-vectorization across various vendors, both platforms now expose SIMD intrinsics as well.

Thanks for the explanation. Aside from vectorization is there anything else that handwritten assembly could be better? Assuming on modern CPUs and modern compilers.

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

#45
post #40
post #22

Earlier quoted context omitted.

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.

Compilers need to balance compilation speed with optimization. SMT solvers are right out for speed reasons.

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

#47

Those were also the days when, according to a famous interview with the same devs: > The general argument is that if you know you are going to need to release a patch, then you shouldn't be shipping the game in the first place.

This quote shall be summoned every time I open Steam and note there is yet another 22GB 'rebalancing patch' for a certain game.

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

#48
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?

This varies from trivial to very hard to mostly data dependent with different architectures. llvm-mca might be of interest.

One should be able to do a best-case calculation, mostly assuming caches hit and branch prediction gets the answer right. Register renaming manages to stay out of the way.

Getting more dubious, there is a statistical representation of program performance on unknown (or partially known) data. One might be able to estimate that usefully, though I haven't seen it done.

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

#49
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?

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 cou…

VTune still exists and is free since a few years. Neat thing with VTune is that it has support for a few runtimes, so it understands for example CPython internals to the point that stack-traces can be a mixture of languages. That's something only becoming available just now outside of VTune, like Python 3.12 has some hooks for Linux perf.

A purely pen-and-paper tool was IACA; you simply inserted some macros around a bit of code in the binary and IACA simulated how these would/could be scheduled on a given core: https://stackoverflow.com/questions/26021337/what-is-iaca-an...

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

#50
post #11

Earlier quoted context omitted.

NEVER FORGET WHAT THEY HAVE TAKEN FROM US. WE WERE ONCE A CULTURE. NOW WE ARE LOST, FOREVER. WHITHER OUR SENSE OF BEAUTY. (etc., etc., insert architecture pics to taste) C'mon dude. The opportunity for people to talk to one another about this stuff is unimaginably better than it was back then. Like, here we are, right now, me telling you you're full of shit. What are the chances of us being able to do that in 1999? (…

Do you want to have lunch at Tia's in Mesquite, Texas?

I do. There isn't a Tia's there anymore but there's one an hour north, still in the DFW area.
Post reply on HN