PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Fixed Point Math

    I would like to do the fixed point math conversions for PQ so it will run faster since thats what we all want. My problem is that i dont know how i am a beginner level c programmer(i know dos programming, just a bit of windows programming using api, and ive done work with the q2 and q3 dll's for modding). So if someone is willing enough to walk me through how to do this proccess i am willing to do it for quake. We all gain everyone gets faster quake and i get to learn how to do all this conversion stuff.
I don't have time at the moment to go through the details. However, over the last several months I (and others I think) have posted very specific info on fixed point math. Try searching this forum for "fixed point".

Dan East
Robert, if you want to undertake this project, that would be cool. I wish you luck on finding the right info to get you rolling. Perhaps once you do Dan or someone else could tell you which areas need the conversion the most.
To implement this correctly you're probably going to need to write it in assembly language.  This is so that you can handle the conditions when values overflow 32 bits.  

Since the current crop of compilers doesn't support inline assembly language then you'll need to put this code in a separate function.  Unfortunately if you do this the compiler won't inline them so you'll have function call overhead for every math operation (bad).  

There's a way around this, you write the entire routine that relies on floating point math in hand-coded assembly language.  You'd need to do this for each CPU you plan to support.

You obviously don't want to do this all over the entire Quake codebase, rather only in the places that matter.  How do you find this?  By profiling the code.  That's where you should start.  Profile the code and find the one or two slow spots, then start hammering on them.  Post code bits here if you want and I can tell you how to speed them up.  Dan or Jacco is familiar with the codebase so they can point you in the direction of where to start looking, however you really need to understand profiling so that when you make a change you can measure the results in a meaningful way.

Thanks for the info. Im going to start on this as soon as i can. Does eVC have a built in profiler if not where can i get a free one?
To my knowledge, it does not. The easiest way to profile would be to procure the original Quake source code from id Software, build WinQuake with Visual C++, and profile it from there.

Dan East
That will help? Wouldnt the code not be slow on the pc version in the same places its slow in the ppc version. Since pc has math-co.
Moose or Chuck · 14 Sep 2001, 11:54 UTC
Robert, if you don't understand that much just quit now.
erhhh that was the whole point of this, to learn somthing new, im not just going to becuase you think i should, no way. Ill quit when i really dont understand, heh j/k.
yeah, james 'pocketcoder' sonne is a real expert.
Moose or Chuck · 14 Sep 2001, 15:54 UTC
Yup... just do it on the PC. It's faster and easier to do everything. Like Dan said.
Gee, that's a first.  Moose is telling someone not to try.  Ha, sure, give the Fixed point math a shot.  Do you have an arm processor in you device?  I think that that would be the best processor to optimize, because most things will be using it soon, and it makes my job of porting the new source so much easier, if I don't have to learn yet another form of asm.  Lets see, I know 9 different ones now, and it is anoying to learn more.  Good luck, and if you think I can help you in any wy, feel free to ask.
My last post was supposed to go before the one moose just posted.  I really doesn't make much sense where it is now.
Moose or Chuck · 14 Sep 2001, 16:04 UTC
LOL! LMAO... what a moron :-P
ssd
screw stupid developers (who dont even think about mips).anyway, the new processors will be fast enough to handle a floating point quake
Yes i do use an arm but if i do get somthing working i am willing to devote alot of effort into ports for others. :) I really want to do this so if anyone has any advice for me not on these boards im willing to listen.
Moose or Chuck · 14 Sep 2001, 16:41 UTC

Yes i do use my arm but if i do get somthing working up i am willing to devote alot of effort into parts of others. :) I really want to do this so if anyone has any advice for me im willing to listen.
Dude, did you read your own post?
I really don't know whether to laugh at that or what. How old are you moose?
here we go...
No no, Im not tyring to argue with moose, i really dont want to argue with somwonw on the net it's a waist of time. Im just curious how old he is becuase of the comment he made(wich i assume has somthing to do with masterbation, but i really didn't get all to much).
Moose or Chuck · 14 Sep 2001, 20:23 UTC
uhm ... 16, but I was in a funny mood. Now I'm in a brooding mood. So, uhm... ya. People were supposed to laugh.
Robert,

Profiling on the PC can get you started.  The things you want to look for initially are functions that are called frequently per frame, and functions that take the most time per frame.  Once you know these, then you probably should move over to the Pocket PC.  The reason is twofold.

First, the Quake code wasn't written by your average dummy so you won't find opportunities for algorithmic speed ups.  If you were going to be doing algorithmic optimization, then staying on the PC until you nailed this down could help your productivity.

The second reason is that most of what you will be doing to the PocketQuake code is rewriting things in assembly language.  There's not much point of doing that for x86 and then redoing it for StrongARM.

I have the beginnings of a profiler written for StrongARM, but never finished it.  It relies on the /Gh compiler option to add prolog function calls in each of your app's functions.  I then implemented the prolog function that munged the caller's return address so that when the app's function returns, it calls my epilog function.  In the prolog and epilog functions I grab the system counter via QueryPerformanceCounter and stuff those values along with the address of the calling function into a private buffer.  When the buffer is full, or the app exits, I send the buffer back to the PC where I use the DbgHelp library to correlate the function address stored in the buffer with an actual function from the symbols stored in the .pdb file.  Once this info is retrieved you can do all sorts of cool graphs showing function frequencies and timings.  You can also get an idea of what functions are never called and possibly remove them making the game smaller.

Anyway, that's what I was working on a while back. What you'll probably want to do is something much simpler like surround code you want to profile with calls to QueryPerformanceCounter and get the difference to determine how long the code took to execute.  From what I remember, QPC would reliably give you timings to an accuracy of one microsecond on my iPaq.  GetTickCount() and timeGetTime() have one millisecond accuracy.  QPC is more difficult to use because you have to divide the value returned by QueryPerformanceFrequency and these values are usually 64 bit numbers.  Fun stuff, eh?


Thanks digby. thats really cool, nopw i understand a little more of whats going on. Do you know where i can get a white sheet for arm asm. I really dont know asm but im willing to learn what i need to get by. Also does rewritting in asm speed things up, i always here asm is so much faster, but i was reading a c book that said vc++ will convert your code into asm and it will make the asm with as little instructions as possible.

Where do you guys learn all of this stuff? Are you all pro programmers, went to colleage for compputer science? I work at a local computer shop as a vb programmer with sql, and i consider myself to be quite good at what i do but its takin m like 3 years to get there, but then i hear about people like carp learning c++ and starting argentium in 6 months. How the hell do you learn so much so fast?

Also moose, thats cool i wasn't trying to start an argument i was just curious about your age becuase most people wouldn't post that kind of stuff. Im happy im not the youngest here im 17 i thought that i was just about the youngest. :P
I don't think there's a beginner's guide to ARM assembly or anything like that available.  There are plenty of ARM docs on the ARM website here.

Looks like www.techonline.com offers a free Introduction to ARM course.  That might be aimed more at hardware folks than software programmers though.  Heck, it's free.  Give it a look and let us know how it goes.

The MS ARM compiler isn't too shabby.  It always seems to impress me when I look at the disassembled code it generates from my C++ routines.  I tend to write routines in C/C++ first, then profile, look at the disassembly and see if there's some way I can keep values in registers across multiple calculations.  

The main reason that I use assembly language is because with C/C++ there is no way to get to things like the CPU flags.  I need access to flags to detect things like when a fixed-point multiplication overflows a 32 bit value.  

The ARM also has some really cool routines for block copying memory.  Maybe MS took advantage of them with memcpy()? I've never checked.  But things like my blit routines sure do.

I would hope that I know a lot of this stuff.  I'm 25 years older than you are.  When I was your age there was no PC.  There was no Atari.  There was no Commodore.  I had one of the first TI programmable calculators with a magnetic strip for storing programs (TI-59).  Wish I still had that thing.

I think it took me 3 weeks or so to learn C.  I had programmed in assembly language for a few years before that.  Learning a new computer language shouldn't take too long, learning how to write solid, efficient game code is something entirely different.

The next-gen ARM's are to have a vector floating point coprocessor. I'm assuming this will help speed things up in this math area for PocketQuake aside from the increase in clock speed..........(I don't know if that's really true for sure, but I am still jonesin' to get a hold of a PPC with an XScale....still...)
Moose or Chuck · 15 Sep 2001, 12:34 UTC
LOL, Robert you don't have to worry about being the youngest. Village Ideot is twelve. I don't even think he HAS a PocketPC.
Moose or Chuck · 15 Sep 2001, 12:57 UTC
he did until he dropped it, remember.
Thanks alot digby i will check out that online thing, i was planning on reading this tut about x86 asm and then learning the arm form. I will probably sign up for that thing moday or tuesday just dont have time tell then. I was looking through the FixedMath.C file last night and noticed Dan commented alot of functions with could be improved, is this some of the stuff i should rewrite in asm?

Village Ideot is 12 how the heck does a 12 year old afford a ppc, i had to save up for like 2 months to buy my ipaq and i work, theres no way a 12 year old has a real job.
mummy and daddy love their little ideot very very much. aww.
Robert,

Beats me... I've never seen the PocketQuake source code or FixedMath.c.

Dan?

I was looking through the FixedMath.C file last night and noticed Dan commented alot of functions with could be improved, is this some of the stuff i should rewrite in asm?


I thought the same thing, when I was first starting to optimize PQ.  But, I believe that Dan said (and correct me if I'm wrong), that FixedPoint.c is not in used.  It is included, but is not compiled with the source, or used in the game.
Well that sucks i thought it be fun to rigt a sqrt function since the comments said that it would really help out.
That's what I thought too, just go through and fix the unoptimized code.  But, asm would be a good idea.  It's really easy to check flags, and its usually pretty fast, so you can deal with overflows, and div by 0 problems quickly and efficiently.
Those routines would have been used for a global fixed point replacement, if it were feasible. They are not used currently.

All the fixed point conversions that are in use now are hand-coded, and were meticulously written to work exactly with the precision / range encountered in that routine. They are integrated directly in the source in place of the original code.

The current FixedPointMath source is very inefficient. The only criteria during the conversion phase was that the fixed point code be accurate. When I discovered that a fixed point number of a predefined, static precision could not store all the various floating point values Quake encounters, I dropped that part of the project. What is needed is FixedPointMath code that dynamically adjusts the precision based on the value that needs to be stored. Of course then you also need to store what the precision is, in addition to the value. So each fixed point "number" would have to be a handle or pointer to a structure that actually contains the data.

Dan East
I'm not planing on undertaking this anytime soon, myself, but just out of curiosity, for dynamic percision, does that contantly change, or is there an exact percision for each var, and it's just a matter of finding out what that is?