Home » SIRTECH CLASSICS » Jagged Alliance: Unfinished Business » Vanilla Modding » Wishlist stuff
Wishlist stuff[message #102353] Fri, 21 October 2005 15:23 Go to next message
ebuck is currently offline ebuck

 
Messages:123
Registered:August 2004
Location: Houston, TX
Defrog, or anyone else interested...

there's a small assembly routine in ja2/Build/Tactical/LOS.c that could be converted to C.

Looks like it's a custom floating point stuff packed into integers. I've converted it to GNU's asm, (and brushed up on my very dusty asm in the process). From first appearances, I can state that the GCC port never worked, as the ASM is a hybrid of AT&T and Intel syntaxes.

Well, it would be nice to see it in C...

Report message to a moderator

Sergeant
Re: Wishlist stuff[message #102354] Tue, 25 October 2005 02:17 Go to previous messageGo to next message
defrog is currently offline defrog

 
Messages:234
Registered:March 2004
Location: Austria
pretty sure this is the solution... I have a program verifying it with a large test case

UINT32 FPMult32_C(UINT32 uiA, UINT32 uiB)
{
	UINT32 uiResult;
	unsigned long long result = (unsigned long long)uiA * (unsigned long long)uiB;
	//   result acts like edx and eax side by side
	//                        eax    
	//                         |     shr eax, 16
	//                         |         |                      edx
	//                         v         v                       v       shl edx, 16
	uiResult = ((UINT32)((result << 32) >> 48)) | ((UINT32)((result >> 32) << 16));
	return(uiResult);
}
ummm.. I'm testing this algorithm, but my test is taking a long time... it will be a few days until its checked every combination


UPDATE: flaw found in the random batch..
UPDATE2: hmmm.. found the problem is I don't have overflow! Sad

Report message to a moderator

Sergeant 1st Class
Re: Wishlist stuff[message #102355] Tue, 25 October 2005 13:24 Go to previous messageGo to next message
ebuck is currently offline ebuck

 
Messages:123
Registered:August 2004
Location: Houston, TX
Defrog,

Since I know you're a bit familiar with ASM, I thought I'd just share this with you, as there are not many that might enjoy it as much:

Intel syntax (that you know so well)

asm {
// Load the 32-bit registers with the two values
mov eax, uiA
mov ebx, uiB

// Multiply them
// Top 32 bits (whole portion) goes into edx
// Bottom 32 bits (fractional portion) goes into eax
imul ebx

// Shift the fractional portion back to (lower) 16 bits
shr eax, 16
// Shift the whole portion to 16 bits, in the upper word
shl edx, 16

// At this point, we have edx xxxx0000 and eax 0000xxxx
// Combine the two words into a dword
or eax, edx

// Put the result into a returnable variable
mov uiResult, eax
}

AT&T syntax:

__asm__ __volatile__ (
// Load the 32-bit registers with the two values
"movl %1, %%eax \t"
"movl %2, %%ebx \t"

// Multiply them
// Top 32 bits (whole portion) goes into edx
// Bottom 32 bits (fractional portion) goes into eax
"imull %%ebx \t"

// Shift the fractional portion back to (lower) 16 bits
"shr $16, %%eax \t"
// Shift the whole portion to 16 bits, in the upper word
"shl $16, %%edx \t"

// At this point, we have edx xxxx0000 and eax 0000xxxx
// Combine the two words into a dword
"or %%edx, %%eax \t"

// Put the result into a returnable variable
"movl %%eax, %0 \t"
: "=r" (uiResult)
: "r" (uiA), "r" (uiB)
);

Note the reveral of register order.

Also the use of % (the %% is reduced to % by the time it reaches the assembler, single %'s resolve to the "out" and "in" paramter modifiers at the end. So %0 resolves to (uiResult) while %2 resolved to uiB.

Constants are preceded by '$'.

And most operators are sized (mov becomes movl, imul becomes imull, etc.) The extra l = 32 bit operations.

Yes, this asm is still Intel specific (imul), but at least AT&T syntax is used by gnu's assmebler, which is available on many platforms.

Report message to a moderator

Sergeant
Re: Wishlist stuff[message #102356] Tue, 25 October 2005 14:38 Go to previous messageGo to next message
defrog is currently offline defrog

 
Messages:234
Registered:March 2004
Location: Austria
were you converting to another version of asm or to C?

problem with the C compiler is its using mul instead of imul upon compile.

I'm so close to getting this to work...
its 5AM, but it just dawned on me that I probably just need to detect the resulting sign of the multiplication...

if its negative then I need to use
(0x100000000-(uiA-(result>>32))) << 16
and with the positive results I should be able to use the code above...

if this works, then we'd be emulating imul behavior using a mul...

I manipulated the VS2005 compiler to generate the code using a imul, through some clever casting. But the result was MS butchered the edx and it became always 0xFFFFFFFF Sad

the asm block above doesn't work?

Report message to a moderator

Sergeant 1st Class
Re: Wishlist stuff[message #102357] Tue, 25 October 2005 15:13 Go to previous messageGo to next message
ebuck is currently offline ebuck

 
Messages:123
Registered:August 2004
Location: Houston, TX
Well, mabye I should clarify...

My port is to a gcc toolchain driven by autotools running under Cygwin. So I'll be using GNU's assembler, which uses AT&T syntax. I have already "ported" the assembler to the AT&T syntax, so it compiles, but we both know that C will be more maintainable / portable in the long term.

Since it's such a short snippet of code, I thought I'd advertise it as a wishlist item. The AT&T syntax was just for your personal enjoyment (which means you can ignore it entirely if you wish).

Yes, the imul is a bit of an odd beast. Seems to be Intel (cpu) specific, which means the C version will become a requirement when we (eventually) try to go multi-platform.

Report message to a moderator

Sergeant
Re: Wishlist stuff[message #102358] Tue, 25 October 2005 15:15 Go to previous messageGo to next message
ebuck is currently offline ebuck

 
Messages:123
Registered:August 2004
Location: Houston, TX
Defrog,

If it's 5AM, you'll need some rest! Talk about a dedicated fan. Even I don't bother to code JA2 much past 1AM Smile hahahaha

Report message to a moderator

Sergeant
Re: Wishlist stuff[message #102359] Wed, 26 October 2005 01:57 Go to previous messageGo to next message
defrog is currently offline defrog

 
Messages:234
Registered:March 2004
Location: Austria
this code appears to provide 100% match to the asm block....
I'm currently testing it with a random number generator...

UINT32 FPMult32_C(UINT32 uiA, UINT32 uiB)
{
	if( !uiA || !uiB )
		return 0;

	unsigned long long result = ((long long)uiA) * ((long long)uiB);
	UINT32 reg_eax = ((result << 32)>>32);
	UINT32 reg_edx;
	if( (uiA & 0x80000000) || (uiB & 0x80000000) 
		&& !( (uiA & 0x80000000) && (uiB & 0x80000000) )
	  )
	  reg_edx = 0x100000000-(uiA-(result>>32));
	else
	  reg_edx = (result>>32);
	return ((reg_eax >> 16) | (reg_edx << 16));
}

Report message to a moderator

Sergeant 1st Class
Re: Wishlist stuff[message #102360] Sun, 11 December 2005 23:01 Go to previous message
TrashMan is currently offline TrashMan

 
Messages:61
Registered:November 2005
Location: Croatia
Whishlist?

Hmm...Anyone tried to change the weapons so that single shot and burst fire are two separate entries?
that why you can have precise control over them (including weapons with burst mode only, and weapons with greater single shot cost than burst mode)

Report message to a moderator

Corporal
Previous Topic: Sun goggles and laser scope bonuses
Next Topic: Autotool conversion project.
Goto Forum:
  


Current Time: Sat Jun 13 06:10:56 GMT+3 2026

Total time taken to generate the page: 0.01555 seconds