Recent

Author Topic: [ solved :) ] memmove declaration  (Read 3705 times)

Gilles

  • New Member
  • *
  • Posts: 37
[ solved :) ] memmove declaration
« on: May 05, 2018, 08:52:51 am »
Bonjour à tous

I was using "BlockMove" but I found it would not work in 64 Bits
And so, "memmove" seems to be the solution

but

where can I find the declaration, the "external name ..." of it ?

( I used to declare :

   procedure BlockMove (srcPtr: UnivPtr; destPtr: UnivPtr; byteCount: Size);
      
   {$IFC TARGET_68K} inline $201F, $225F, $205F, $A02E; {$ENDC}
   {$IFC TARGET_CARBON} external name '_BlockMove'; {$ENDC}
)

(I found it in a way in "string.h" but don't see the equivalency in pascal)
(extern void   *memmove(void *, const void *, size_t); )

( Tried "System.Move" but it doesn't work )

The question could be : how include C-code in Pascal-code

merci d'avance
« Last Edit: May 05, 2018, 06:55:41 pm by Gilles »
TurboPascal -> ThinkPascal -> CodeWarrior -> XCode with FPC -> (Well-deserved) Retirement (but not yet, not yet…)

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9082
  • FPC developer.
Re: memmove declaration
« Reply #1 on: May 05, 2018, 04:28:43 pm »
Note that Pascal has its own move(src,dest,count). Which is afaik a builtin function that can be more optimized and inlined for small, constant moves (like you specify for target_68k).

All build in, and reasonably, though not extremely, optimized.


PascalDragon

  • Hero Member
  • *****
  • Posts: 2747
  • Compiler Developer
Re: memmove declaration
« Reply #2 on: May 05, 2018, 04:45:25 pm »
( Tried "System.Move" but it doesn't work )

Would you please explain why you think that System.Move() doesn't work? As it does have a different interface from the mem*-functions provided by the C-library, maybe you simply used it incorrectly.

Gilles

  • New Member
  • *
  • Posts: 37
Re: memmove declaration
« Reply #3 on: May 05, 2018, 04:46:51 pm »
The problem is : when I replace BlockMove by System.MOVE it doesn't work…

I had :

Code: Pascal  [Select][+][-]
  1. procedure MyTest (h_src, h_dst: univ Ptr; L_cnt: SInt32);
  2. begin
  3.         BlockMove(h_src, h_dst, L_cnt)
  4. end;

where h_src and h_dst could be :
   
Code: Pascal  [Select][+][-]
  1. Ptr(ord4(H^) + L_adi)   { H: Handle }
or
   
Code: Pascal  [Select][+][-]
  1. @S[1]                   { S: string }

L_cnt and the ranges are correct


When I try :

Code: Pascal  [Select][+][-]
  1. procedure MyTest (h_src, h_dst: univ Ptr; L_cnt: SInt32);
  2. begin
  3.         System.Move(h_src, h_dst, L_cnt)
  4. end;

everything freeze
« Last Edit: May 05, 2018, 05:00:51 pm by Gilles »
TurboPascal -> ThinkPascal -> CodeWarrior -> XCode with FPC -> (Well-deserved) Retirement (but not yet, not yet…)

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9082
  • FPC developer.
Re: memmove declaration
« Reply #4 on: May 05, 2018, 05:05:13 pm »
Try

Code: Pascal  [Select][+][-]
  1.         System.Move(h_src^, h_dst^, L_cnt)

or if that doesn't work (depending on dialect and univ ptr semantics)

Code: Pascal  [Select][+][-]
  1.         System.Move(pbyte(h_src)^, pbyte(h_dst)^, L_cnt)


Note that an own wrapper will invalidate the inline properties, unless (maybe) you also declare the wrapper inline.

PascalDragon

  • Hero Member
  • *****
  • Posts: 2747
  • Compiler Developer
Re: memmove declaration
« Reply #5 on: May 05, 2018, 06:15:44 pm »
Note that an own wrapper will invalidate the inline properties, unless (maybe) you also declare the wrapper inline.
Yes, the wrapper will need to be declared inline as well. Though as Move is an assembler routine on most platforms it won't be inlined anyway... But with an inline there will be at least one less call.  ;)

Gilles

  • New Member
  • *
  • Posts: 37
Re: memmove declaration
« Reply #6 on: May 05, 2018, 06:50:35 pm »
Tank"s a lot

 
Code: Pascal  [Select][+][-]
  1.  System.Move(pbyte(h_src)^, pbyte(h_dst)^, L_cnt)

work perfectly, even if I don't yet understand why… (in fact, I poorly uses Pascal language… until now, I didn't need to worry about subtilities of it… I'll go back to school ;) )
TurboPascal -> ThinkPascal -> CodeWarrior -> XCode with FPC -> (Well-deserved) Retirement (but not yet, not yet…)

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9082
  • FPC developer.
Re: memmove declaration
« Reply #7 on: May 05, 2018, 08:26:07 pm »
Note that an own wrapper will invalidate the inline properties, unless (maybe) you also declare the wrapper inline.
Yes, the wrapper will need to be declared inline as well. Though as Move is an assembler routine on most platforms it won't be inlined anyway... But with an inline there will be at least one less call.  ;)

Hmm, seems I'm wrong. move() is not inline optimized for small sizes. Bummer.

Gilles

  • New Member
  • *
  • Posts: 37
Re: [ solved :) ] memmove declaration
« Reply #8 on: November 13, 2018, 12:49:58 pm »
the real solution : CFDataGetBytes, CFDataReplaceBytes, … and so on…
« Last Edit: November 13, 2018, 12:51:30 pm by Gilles »
TurboPascal -> ThinkPascal -> CodeWarrior -> XCode with FPC -> (Well-deserved) Retirement (but not yet, not yet…)

 

TinyPortal © 2005-2018