Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
ASM in GCC

 
Post new topic   Reply to topic Printable version
 View previous topic  Linux Post :: Post Bumping.  View next topic  
Author Message
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Thu Sep 02, 2004 9:13 pm   Post maybe stupid    Post subject: ASM in GCC Reply to topic Reply with quote

I'm just nearing the end of modding the MERV source for it to compile under MinGW (Dev-C++). I just have one linker error left, and that's with converting the ASM code into AT&T syntax. Here's the code:
Code: Show/Hide
Uint32 IMULHIDWORD(Uint32 A, Uint32 B)
{
   Uint32 HDW;
   
#ifdef __GNUC__ //Cyan~Fire: Added GCC-style asm
    __asm("movl _A, %eax");
    __asm("imull _B");
    __asm("movl %edx, _HDW");
#else
   __asm
   {
      mov      eax, A
      imul   B
      mov      HDW, edx
   }
#endif

   return HDW;
}


The errors I get are:
algorithms.cpp: undefined reference to `A'
algorithms.cpp: undefined reference to `B'
algorithms.cpp: undefined reference to `HDW'

Anybody know why?

Thanks,
Cyan
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Thu Sep 02, 2004 9:50 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

You can do the same operation if the compiler supports 64-bit operators. In VC this would be something like:

Code: Show/Hide
Uint32 IMULHIDWORD(Uint32 A, Uint32 B)
{
unsigned __int64 product;

product = (unsigned __int64)A * (unsigned __int64)B;

return ((Uint32)(product >> 32));
}


Of course it's much less efficient unless the compiler is really good at optimization.[/code]
_________________
4,691 irradiated haggis!
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Fri Sep 03, 2004 10:28 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

Well I'm trying to leave this code as near to the original as possible... thanks, though.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Grelminar
Creator of Asss


Joined: Feb 26 2003
Posts: 378
Offline

PostPosted: Fri Sep 03, 2004 11:27 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

First, that's not a linker error. Second, that's not valid gcc inline asm syntax. This page should help.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Sat Sep 04, 2004 1:14 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

It was a linker error, but I did solve it now with that site. I had seen a similar site before, but it hadn't addressed how to address (lol) local vars. Thanks icon_smile.gif

Just for anyone who's curious:
Code: Show/Hide
Uint32 IMULHIDWORD(Uint32 A, Uint32 B)
{
   Uint32 HDW;
   
#ifdef __GNUC__ //Cyan~Fire: Added GCC-style asm
    asm("imull %0" : "=d"(HDW) : "a"(A), "q"(B));
#else
   __asm
   {
      mov      eax, A
      imul   B
      mov      HDW, edx
   }
#endif

   return HDW;
}

So much simpler in GCC...
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sat Sep 04, 2004 3:15 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

MS conforms to Intel ASM spec. That GCC stuff is like reading hex data. icon_sad.gif
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Sat Sep 04, 2004 11:42 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

Eh, it's easy to read once you understand what it's doing.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Sat Sep 04, 2004 1:22 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

You might want to put "memory" in the clober section.

After reading the page that was linked to I am thinking why does this say numwords when the suffix is 'l'?
Code: Show/Hide
#define rep_stosl(value, dest, numwords) \
__asm__ __volatile__ ( \
  "cld\n\t" \
  "rep\n\t" \
  "stosl" \
  : : "a" (value), "D" (dest), "c" (numwords) \
  : "%ecx", "%edi" )
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Sat Sep 04, 2004 2:38 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

I probably should just to be safe, but I've already tested the build and sent the source to Catid, so I think I'll just leave it alone for now.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sat Sep 04, 2004 6:14 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Cyan~Fire wrote:
Eh, it's easy to read once you understand what it's doing.


The point is, the MS version shows you the actual assembly, instruction for instruction. Making a whole new language that hides the operations and their sequences is like using C++.
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Sat Sep 04, 2004 9:43 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Yeah, just like C and PERL and ASM and all those other stupid high-level languages! Bah! Let's just write in machine code!!
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sat Sep 04, 2004 10:03 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Sigh. When you write in ASM, you are trying to talk directly to the machine you are targetting. In the case of Intel/AMD, the instruction set is a known. Trying to disguise instructions with crazy symbols or pretending it's higher level than it is is not helpful. One line, one instruction, one opcode.
Back to top
View users profile Send private message Add User to Ignore List
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Sat Sep 04, 2004 10:13 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Cyan, why write in machine code when you can use 0's and 1's? $$

Some old guy> What?! You had 0's?! Back in my day, we had to use the letter 'O'
_________________

Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:41
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Sun Sep 05, 2004 12:24 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

I've actually used someone's machine in which it required you to toggle switches to talk to it. They made their own computer, like back in the original computer type days. Much easier to do now.
Back to top
View users profile Send private message Add User to Ignore List Send email
Grelminar
Creator of Asss


Joined: Feb 26 2003
Posts: 378
Offline

PostPosted: Sun Sep 05, 2004 1:54 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

Mr Ekted wrote:
The point is, the MS version shows you the actual assembly, instruction for instruction. Making a whole new language that hides the operations and their sequences is like using C++.


I don't think you get it, Ek. The gcc method is actually more powerful and more transparent than the msvc method.

First, there's nothing hidden: gcc writes your instructions directly into the assembly output, as written. Of course, substitutions are performed where input and output are concerned, but msvc also performs substitutions, so I see no difference there.

Second, consider trying to imul a variable and a constant. In msvc, you'd have to mov at least one into a register, perform the imul, and then move the result into a variable. In gcc, you just tell it where you want the input and output to go, and it takes care of the rest. Specifically, it can perform register allocation so that the desired input and output values are already in the correct registers, and save those extra mov instructions. Also, you tell gcc which registers are clobbered by your operation, so it can optimize better by eliminating spills that msvc would have to include, since it doesn't know what registeres are clobbered.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Trash Talk All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 13 page(s) served in previous 5 minutes.

phpBB Created this page in 0.666989 seconds : 39 queries executed (75.3%): GZIP compression disabled