Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include<libc/asm.h>
  3.         .file "memset.s"
  4.         .text
  5.         .align  4
  6. MK_C_SYM(memset)
  7.         pushl   %ebp
  8.         movl    %esp,%ebp
  9.         pushl   %edi
  10.         movl    8(%ebp),%edi
  11.         movl    12(%ebp),%eax
  12.         movl    16(%ebp),%ecx
  13.         cld
  14.  
  15.         # We will handle memsets of <= 15 bytes one byte at a time.
  16.         # This avoids some extra overhead for small memsets, and
  17.         # knowing we are setting > 15 bytes eliminates some annoying
  18.         # checks in the "long move" case.
  19.         cmpl    $15,%ecx
  20.         jle     L3
  21.  
  22.         # Otherwise, tile the byte value out into %eax.
  23.         # 0x41 -> 0x41414141, etc.
  24.         movb    %al,%ah
  25.         movl    %eax,%edx
  26.         sall    $16,%eax
  27.         movw    %dx,%ax
  28.         jmp     L2
  29.  
  30.         # Handle any cruft necessary to get %edi long-aligned.
  31. L1:     stosb
  32.         decl    %ecx
  33. L2:     testl   $3,%edi
  34.         jnz     L1
  35.  
  36.         # Now slam out all of the longs.
  37.         movl    %ecx,%edx
  38.         shrl    $2,%ecx
  39.         rep
  40.         stosl
  41.  
  42.         # Finally, handle any trailing cruft.  We know the high three bytes
  43.         # of %ecx must be zero, so just put the "slop count" in the low byte.
  44.         movb    %dl,%cl
  45.         andb    $3,%cl
  46. L3:     rep
  47.         stosb
  48.         popl    %edi
  49.         movl    8(%ebp),%eax
  50.         leave
  51.         ret
  52.