Author |
Topic: FWAIT (Read 228 times) |
|
David Williams
Developer
member is offline

meh

Gender: 
Posts: 452
|
 |
Re: FWAIT
« Reply #3 on: Oct 11th, 2011, 12:58pm » |
|
Okay, thanks Richard for the reply. The information you gave is good to know.
I have actually used some of the code given in that article (Simply FPU Chap. 7), but I'll proceed with caution re. the author's opinions.
---
While I'm here, here's a recent discovery I made (or borrowed, rather) for getting integer ABS( EAX ):
Code:cdq
xor eax, edx
sub eax, edx
You're most likely familiar with it already?
I've used it in translating this very interesting-looking piece of C code (implementation of Bresenham's line drawing algo):
Code:void line(int x0, int y0, int x1, int y1) {
int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
int err = (dx>dy ? dx : -dy)/2, e2;
for(;;){
setPixel(x0,y0);
if (x0==x1 && y0==y1) break;
e2 = err;
if (e2 >-dx) { err -= dy; x0 += sx; }
if (e2 < dy) { err += dx; y0 += sy; }
}
}
I'm not a C programmer, of course, but even to my eyes that looks like a very efficient bit of C.
I successfully translated it to Asm (at about 4 o'clock this morning!).
Incidentally, I wanted the code not for drawing lines -- but for fast collision detection purposes.
Rgs, David.
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: FWAIT
« Reply #4 on: Oct 11th, 2011, 1:58pm » |
|
on Oct 11th, 2011, 12:58pm, David Williams wrote: Code:cdq
xor eax, edx
sub eax, edx You're most likely familiar with it already? |
|
Indeed. It's not actually what's used for ABS internally to BB4W because of its inflexibility as regards register allocation (cdq forces the use of eax for input and edx for temporary storage, which isn't convenient).
Quote:| I'm not a C programmer, of course, but even to my eyes that looks like a very efficient bit of C. |
|
I'm not too sure how one measures 'efficiency' in C. If one is very familiar with the compiler and its code generator, one might be able to 'tune' the C source code to help the code generator do a good job, but that's quite likely to mean that what's 'efficient' with one compiler is 'inefficient' with another.
Tricks like using for(;;) to implement an 'infinite' loop are unlikely to make much difference with a modern optimising compiler, I would have thought.
Quote:| Incidentally, I wanted the code not for drawing lines -- but for fast collision detection purposes. |
|
In LBLIB I use the CombineRgn API for collision-detection (of course this won't be 'fast' in your terms). To some extent my hand was forced because LB allows you to specify whether collision-detection operates as if the objects are rectangular or elliptical (in the latter case they need to be diagonally closer together before they are deemed to have 'collided', of course) so I needed a method that could easily work for both. CombineRgn, in combination with CreateRectRgn or CreateEllipticRgn, seemed to fit the bill.
Richard.
|
|
Logged
|
|
|
|
Michael Hutton
Developer
member is offline


Gender: 
Posts: 248
|
 |
Re: FWAIT
« Reply #5 on: Oct 11th, 2011, 8:22pm » |
|
on Oct 11th, 2011, 12:58pm, David Williams wrote:While I'm here, here's a recent discovery I made (or borrowed, rather) for getting integer ABS( EAX ):
Code:cdq
xor eax, edx
sub eax, edx
You're most likely familiar with it already? |
|
I would think Richard is :- it's in the wiki!
http://bb4w.wikispaces.com/Simulating+assembler+macros
Michael
|
|
Logged
|
|
|
|
David Williams
Developer
member is offline

meh

Gender: 
Posts: 452
|
 |
Re: FWAIT
« Reply #6 on: Oct 11th, 2011, 8:45pm » |
|
on Oct 11th, 2011, 8:22pm, Michael Hutton wrote:
Ah.
So it is!
|
|
Logged
|
|
|
|
|