It is currently Fri Apr 10, 2020 10:28 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Combined x86 / x64 source
PostPosted: Fri Mar 02, 2012 7:43 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3606
Location: Netherlands
Sometimes all it takes to make x86 code work on x64 is to change some register names.
A lot of CompilerIf statements can make the code harder to read.
I tried to use Macro's to make things easier.
Code:
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
  Macro _RegB : ebx : EndMacro 
  Macro _RegD : edx : EndMacro 
CompilerElse
  Macro _RegB : rbx : EndMacro 
  Macro _RegD : rdx : EndMacro 
CompilerEndIf

Procedure.l FNV32a(*key, len.l)
  EnableASM
  MOV _RegD, *key
  MOV ecx, len
  PUSH _RegB
  !mov eax, 2166136261
  !fnv32a_loop:
  MOVZX ebx, byte [_RegD]
  !xor eax, ebx
  !imul eax, 0x01000193
  INC _RegD
  !dec ecx
  !jnz fnv32a_loop
  POP _RegB
  DisableASM
  ProcedureReturn
EndProcedure

Does someone know a better way to handle this ?


Top
 Profile  
Reply with quote  
 Post subject: Re: Combined x86 / x64 source
PostPosted: Fri Mar 02, 2012 10:18 am 
Offline
Addict
Addict
User avatar

Joined: Sat Aug 15, 2009 6:59 pm
Posts: 1252
I think this is a nice way to handle it.

In most cases i do 2 versions of the complete ASM code, so i need only one CompilerIf. Makes the source big, but many CompilerIf's make the source confusing. But i think your approach using macros is much better.


Top
 Profile  
Reply with quote  
 Post subject: Re: Combined x86 / x64 source
PostPosted: Fri Mar 02, 2012 10:20 am 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 2484
Looks already fine for me -- maybe enabling asm inline support will allow you to simplify the macros...

Code:
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
   Macro rbx : ebx : EndMacro
   Macro rdx : edx : EndMacro
CompilerEndIf

Procedure.l FNV32a(*key, len.l)
   MOV rdx, *key
   MOV rbx, len
   PUSH rbx
   MOV eax, 2166136261
   !fnv32a_loop:
   MOVZX ebx, byte [rdx]
   XOR eax,rbx
   IMUL eax, 0x01000193
   INC rdx
   DEC ecx
   JNZ fnv32a_loop
   POP rbx
EndProcedure


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye