Jump to content
Sign in to follow this  
RDP1974

chatgpt can convert 32bit asm into 64bit

Recommended Posts

question

do you remember the good old https://fastcode.sourceforge.net/ ? (2007 project)

I asked chatgpt to convert asm32 to asm64 delphi, look at this example:

 

procedure MoveJOH_SSE2_10(const Source; var Dest; Count : Integer);
asm
  cmp     ecx, TINYSIZE
  ja      @@Large {Count > TINYSIZE or Count < 0}
  cmp     eax, edx
  jbe     @@SmallCheck
  add     eax, ecx
  add     edx, ecx
  jmp     SmallForwardMove_10
@@SmallCheck:
  jne     SmallBackwardMove_10
  ret {For Compatibility with Delphi's move for Source = Dest}
@@Large:
  jng     @@Done {For Compatibility with Delphi's move for Count < 0}
  cmp     eax, edx
  ja      Forwards_SSE2_10
  je      @@Done {For Compatibility with Delphi's move for Source = Dest}
  sub     edx, ecx
  cmp     eax, edx
  lea     edx, [edx+ecx]
  jna     Forwards_SSE2_10
  jmp     Backwards_SSE2_10 {Source/Dest Overlap}
@@Done:
end; {MoveJOH_SSE2}

 

chat gpt rewrite this in 64bit:

procedure MoveJOH_SSE2_10(const Source; var Dest; Count: Integer);
asm
  cmp     r8d, TINYSIZE        // Compare Count (R8D) with TINYSIZE
  ja      @@Large              // If Count > TINYSIZE or Count < 0, jump to @@Large
  cmp     rcx, rdx             // Compare Source (RCX) with Dest (RDX)
  jbe     @@SmallCheck
  add     rcx, r8              // Adjust Source address: Source + Count
  add     rdx, r8              // Adjust Dest address: Dest + Count
  jmp     SmallForwardMove_10  // Jump to small forward move
@@SmallCheck:
  jne     SmallBackwardMove_10 // If Source ≠ Dest, use backward move
  ret                           // If Source = Dest, exit (compatible with Delphi’s Move)
@@Large:
  jng     @@Done                // If Count < 0, exit (compatible with Delphi’s Move)
  cmp     rcx, rdx
  ja      Forwards_SSE2_10      // If Source > Dest, use forward move
  je      @@Done                // If Source = Dest, exit
  sub     rdx, r8               // Adjust Dest address: Dest - Count
  cmp     rcx, rdx
  lea     rdx, [rdx + r8]       // Restore original Dest address
  jna     Forwards_SSE2_10      // If no overlap, use forward move
  jmp     Backwards_SSE2_10     // If overlap, use backward move
@@Done:
end;
 

opinions? does this make sense to you? can we take the winners of fastcode 32bit and convert them in 64bit so easily?
chatgpt then owns the copyright?

Share this post


Link to post

For something to be patentable it must have a creative and innovative character.
I don't think that a few lines of assembler can be considered as such.

Share this post


Link to post

Note it is a 64-bit version of a 32-bit move function not a 64-bit move function. 

 

A 64-bit move function would have Count as: NativeInt and other changes to allow moves over the limits of a 32-bit integer.

Edited by Brian Evans

Share this post


Link to post

Converting source code that won any challenge over 15 years ago is questionable regardless of correctness.

 

Anyway, for this particular example, implementing a faster System.Move for Windows (other platforms use their libc memory) has been solved since Delphi 11.3.

 

I sincerely challenge everyone to come up with a faster/better implementation.

Edited by Stefan Glienke
  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×