Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 3 [4] 5 6 ... 10

Author Topic: What language is Dwarf Fortress made in?  (Read 48017 times)

devek

  • Bay Watcher
  • [KILL_EVERYTHING]
    • View Profile
Re: What language is Dwarf Fortress made in?
« Reply #45 on: September 11, 2010, 07:43:33 am »

Lol...

Compilers are not as smart as you guys think they are. DF itself, looking at the linux version, loves to pad loops with LEA EBX,[EBX+00000000H] because the compiler is so smart lol(I'm not stupid, I know why it does that. But I also understand out of order execution and dependency chains when this compiler clearly does not). Hell, even assemblers are not that bright sometimes. On the topic of cache alignment you can align your innerloop that gets ran a lot by doing a costly alignment of the outer loop, but the assembler won't know to do that!

But whatever, think whatever you guys want. You're just making excuses the fact that you find assembly hard.

The future is exciting though. llvm/clang isn't an ant, it sees the big picture and may someday make my low level knowledge obsolete.
« Last Edit: September 11, 2010, 07:46:14 am by devek »
Logged
"Why do people rebuild things that they know are going to be destroyed? Why do people cling to life when they know they can't live forever?"

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: What language is Dwarf Fortress made in?
« Reply #46 on: September 11, 2010, 07:47:19 am »

Isn't that just a pointer dereference? Makes sense if you're looping an array of pointers...
Ah no, it's LEA. My bad.
« Last Edit: September 11, 2010, 07:49:05 am by Thief^ »
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

devek

  • Bay Watcher
  • [KILL_EVERYTHING]
    • View Profile
Re: What language is Dwarf Fortress made in?
« Reply #47 on: September 11, 2010, 08:04:42 am »

LEA EBX,[EBX] is a nop, it doesn't do anything.

The problem is that NOP only takes 1 byte, while LEA EBX,[EBX] can take anywhere from 2 to 8 bytes depending on how you defined it and it still does nothing. If you have to pad 15 bytes, 15 NOPs is 15 instructions. If you are going to pad, you should still do it with nop over LEA EBX,[EBX] because doing so builds a false dependency on EBX.

The best thing to do is never pad or pad earlier on.. if you have a loop that runs 10,000 times in a function it is better to just misalign the function so that the start of your loop ends up where you want it. Not saying that is the best, it is just better.  An assembler can't do that for you automatically because an assembler doesn't know your loop is going to get ran 10,000 times, so you have to use the ALIGN in the proper places or straight out EMIT the code you want in places to shift your code around.

« Last Edit: September 11, 2010, 08:07:10 am by devek »
Logged
"Why do people rebuild things that they know are going to be destroyed? Why do people cling to life when they know they can't live forever?"

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: What language is Dwarf Fortress made in?
« Reply #48 on: September 11, 2010, 08:36:28 am »

I understand it being a large NOP. And about register dependencies, and cache, and instruction pipelining, and all that lot.

However, I think you'd only get a minor gain (if anything) by writing that loop in assembly yourself. Minor improvements generally aren't worth it, especially if they are platform specific like assembly is.
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

devek

  • Bay Watcher
  • [KILL_EVERYTHING]
    • View Profile
Re: What language is Dwarf Fortress made in?
« Reply #49 on: September 11, 2010, 09:37:55 am »

Look, 99% of the code I write these days is Java.

The whole reason this argument started is because someone had to say that you shouldn't use Java because it is slow.

If your program is actually cpu bound, why not use the right tool for the job? Cache alignment may be a small gain, but it just one thing you can do and it takes a few seconds to accomplish. In the process of an hour you have applied hundreds of changes.

The fact of the matter is that very few programs are cpu bound, so who even cares? I could sit down and optimize every single function in dwarf fortress(I have modified a few of them, not for speed but to aid me in my understanding of it) and it wouldn't change a thing because it would still be doing massive amounts of reads and writes on 500 megs of memory.

Java wouldn't read and write to all that memory any slower than C++ would, so who cares? The language has nothing to do with DF's speed.
Logged
"Why do people rebuild things that they know are going to be destroyed? Why do people cling to life when they know they can't live forever?"

devek

  • Bay Watcher
  • [KILL_EVERYTHING]
    • View Profile
Re: What language is Dwarf Fortress made in?
« Reply #50 on: September 11, 2010, 09:55:53 am »

Actually, I have to take that last part back...

There is some debate about that regarding memory usage... The java and c++ argue about which language fragments the heap worse :P Both problems that can be avoided with proper programing of both languages, so its moot in my boot.
Logged
"Why do people rebuild things that they know are going to be destroyed? Why do people cling to life when they know they can't live forever?"

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: What language is Dwarf Fortress made in?
« Reply #51 on: September 11, 2010, 10:46:55 am »

I was just correcting you where you were saying that assembly was massively faster, and that the internals of game engines are all assembly. The truth is that it's minor at best, and that real licensed game engines use very very very little assembly, if they don't use compiler intrinsics and so have no assembly at all.

And cache alignment of code is really minor. Cache alignment of data is far more important, and you don't need assembly for that.
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

devek

  • Bay Watcher
  • [KILL_EVERYTHING]
    • View Profile
Re: What language is Dwarf Fortress made in?
« Reply #52 on: September 11, 2010, 11:11:42 am »

To be fair, intrinsics are not part of the c standard :P

They are not functions, they are literately assembly instructions inside of your code. The advantage of intrinsics is that you can use high level if statements and such with them, so if anything you're really using high level assembly. If you are not using if statements or whatever, your code is identical to the assembly code.
 
And, the only reason I brought up cache alignment was because the compiler DF used tried to do it and failed in a way that was slower than not doing it at all.
« Last Edit: September 11, 2010, 11:14:35 am by devek »
Logged
"Why do people rebuild things that they know are going to be destroyed? Why do people cling to life when they know they can't live forever?"

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: What language is Dwarf Fortress made in?
« Reply #53 on: September 11, 2010, 11:21:44 am »

Well, except that with intrinsics you don't need to worry about register allocation, and many other things along those lines. Pity C++'10 doesn't seem to be adding vector types to the language, either...
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

devek

  • Bay Watcher
  • [KILL_EVERYTHING]
    • View Profile
Re: What language is Dwarf Fortress made in?
« Reply #54 on: September 11, 2010, 11:31:29 am »

That and I just read that MSVC doesn't support inline assembly at all for 64 bit applications..  I use a paid for copy of icc aa work, gcc at home(but i'm slowly migrating over to clang).

Since we're arguing, and you're fun(which is a compliment, trust me), what do you think about....

Code: [Select]
bool = false;

while(true)
{
    if (this) { that; break;}
    if (this) { that; break;}
    if (this) { that; break;}
    bool = true;
    break;
}

if (bool) panic;

You know what I am talking about.
Logged
"Why do people rebuild things that they know are going to be destroyed? Why do people cling to life when they know they can't live forever?"

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: What language is Dwarf Fortress made in?
« Reply #55 on: September 11, 2010, 11:37:12 am »

It's stupid and much better written as:
if (this) { that; }
else if (this) { that; }
else if (this) { that; }
else panic;

If you mean using goto instead, then my stance is that you should if it makes the code cleaner. The "no goto" crowd overdoes it a bit sometimes.
EDIT: e.g. to exit from multiple nested loops. C++ badly needs a break(2); or break(label); statement...
« Last Edit: September 11, 2010, 11:42:04 am by Thief^ »
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

devek

  • Bay Watcher
  • [KILL_EVERYTHING]
    • View Profile
Re: What language is Dwarf Fortress made in?
« Reply #56 on: September 11, 2010, 12:00:02 pm »

Ha, you saw right through me and knew exactly where I was going with that.

I peer review a guy at work that must have been abused by a complicated if statement as a child, so he uses while(true) a lot. I switch it to use goto and it makes him so mad. I love ribbing people that hate goto. I pretty much use it out of spite, instead of just reorganizing his code to an if statement or a switch.

Ya, break(2) would be awesome, and there is no reason it couldn't exist.
Logged
"Why do people rebuild things that they know are going to be destroyed? Why do people cling to life when they know they can't live forever?"

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: What language is Dwarf Fortress made in?
« Reply #57 on: September 11, 2010, 12:10:27 pm »

If you want a real argument, ask someone how many spaces/newlines should be in this code:
if(test()&&(a+b)/d>c){code;}

(the answer is between 0 and 17 (I think, and discounting indenting), but no two people will agree...)
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

devek

  • Bay Watcher
  • [KILL_EVERYTHING]
    • View Profile
Re: What language is Dwarf Fortress made in?
« Reply #58 on: September 11, 2010, 12:34:18 pm »

I don't even agree with myself on that one and I am pretty much indifferent to anything that is cosmetic. At the end of the day, eclipse auto formats my code anyway so I have no choice but to go with the eclipse default.

Code: [Select]
if (test() && (a + b) / d > c) {
code;
}

Order of operations is a weakness of mine for some reason, so I would totally add more parenthesis to that and just about everything. I'll even put that on new lines.. just so I don't screw up.

NO!!!

I must have wrote that drunk.. I was looking for an example of my crazy parenthesis usage and I found this... oh kill me.

Code: [Select]
        // Make sure none of the dwarfs are about to cut this down
        int abort = 0;
        for (uint32_t i = 0; i < busy.size(); i++)
        {
            if ((busy[i]->x == tree.x) && (busy[i]->y == tree.y) && (busy[i]->z == tree.z))
            {
                abort = 1;
                break;
            }
        } if (abort == 1) continue;

Oh well, can't win them all. I talk shit and end up making a fool of myself. Guess I have to spite myself too or something.

Anyway, off to hang with my daughter. We need to chat more. :)

EDIT: Oh wait, I remember... I was up late tired trying to track down a bug... Dwarf Foreman was causing my game to throw "Urist cancels dig: invalid designation" or  "Urist cancels cut tree" or something like that and I couldn't figure it out.

It turns out that when a dwarf goes to cut down a tree, the designation to be cut is removed. So Foreman saw the tree as not being cut down so it redesigned it to be cut. A dwarf would go there to cut it down when it was already being cut and it already be gone or in the process of being cut down. The tile designation for cutting a tree, gathing a plant, or digging a tile is the same so that explained the different errors. So you have to iterate through all the dwarfs, see who is cutting a tree, and store it than when you iterate through the trees ignore any that are already being cut. I was tired and wanted to go to bed badly :P That is my excuse and I am sticking with it :)
« Last Edit: September 11, 2010, 12:42:23 pm by devek »
Logged
"Why do people rebuild things that they know are going to be destroyed? Why do people cling to life when they know they can't live forever?"

Puzzlemaker

  • Bay Watcher
    • View Profile
Re: What language is Dwarf Fortress made in?
« Reply #59 on: September 11, 2010, 01:24:08 pm »

I really need to learn more about how computer work on the lower end of the spectrum. 
Logged
The mark of the immature man is that he wants to die nobly for a cause, while the mark of the mature man is that he wants to live humbly for one.
Pages: 1 2 3 [4] 5 6 ... 10