www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/03/24/05:49:57

From: "A.Appleyard" <A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk>
To: DJGPP AT SUN DOT SOE DOT CLARKSON DOT EDU
Date: Fri, 24 Mar 1995 09:09:29 GMT
Subject: copying n bytes

  Re this function that I wrote:-
> void str_cpy(void*s,void*t,int n){
> asm("pushl %esi"); asm("pushl %edi"); asm("cld");
> asm("movl 8(%ebp),%edi"); asm("movl 12(%ebp),%esi");
> asm("movl 16(%ebp),%ecx"); asm("rep"); asm("movsb"); asm("popl %edi");
> asm("popl %esi");}

  challier AT irit3-eth DOT irit DOT fr (Jean-Marc CHALLIER), wrote:-
> You don't have to push %esi and %edi, you can specify to the compiler that
> you are trashing them, and it'll decide all by himself if it needs to
> push/pop them or not.

  How do I tell the compiler that, please?

  mat AT ardi DOT com (Mat Hostetter) wrote:-
> ... You never tell gcc what registers you are clobbering,

  That is why I preserved and restored ESI and EDI, and in other asm()
programming I try to use registers AX and BX only.

> and you split it up into separate asm statements so gcc is free to clobber
> any and all registers between asm statements if it wants to do so.

  When is djgpp likely to shuffle asm() statements which are consecutive in
the *.c or *.cc original, or to interpolate other instructions between them?,
if I stick to plain machine codes as seen in *.s files and I don't put C
variables etc in brackets inside asm() statements. (Once I put some asm()
statements next after an unconditional jump, and djgpp dropped them out and
didn't compile them. They would have been reachable, as the first of them had
a *.s-language label inside the `asm(" ");'.)

  > If you really wanted to write this function, you would write ONE asm
statement like:
void my_memory_copy (void *dst, void *src, int count) {
  asm volatile ("cld\n\t"
		"rep\n\t"
		"movsb"
		: : "S" (src), "D" (dst), "c" (count)
		: "si", "di", "cx", "memory");}

  Are we likely to see an inline memcpy() or memcmp() etc in a djgpp release?

  Roland Exler <R DOT Exler AT jk DOT uni-linz DOT ac DOT at> wrote:-
> According to the documentation of the 80x86-series, if an rep-prefixed
> instruction is interrupted, the rep will be lost after coming back from the
> interrupt, and the movsb-instruction will be done just one more, so not all
> of the block will be transferred. Checking whether ECX is zero and jumping
> back to the rep movsb could help, but as ECX won't be decremented at the
> last move, this should also be checked! So be careful using your code.

  Which makes of PC are likely to have this bug in the interrupt mechanism?
Do djgpp's memcpy() memcmp() etc allow for this?

  Re various criticism of my n-bytes-copier: Sorry. I have now called djgpp's
memcpy() instead. Thankyou for the information.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019