home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / ansi / string / memset.s < prev    next >
Encoding:
Text File  |  1995-03-28  |  1.0 KB  |  52 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2.     .file "memset.s"
  3.     .text
  4.     .align    4
  5.     .globl    _memset
  6. _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.