SetMem.S 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #------------------------------------------------------------------------------
  2. #
  3. # Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
  4. # This program and the accompanying materials
  5. # are licensed and made available under the terms and conditions of the BSD License
  6. # which accompanies this distribution. The full text of the license may be found at
  7. # http://opensource.org/licenses/bsd-license.php.
  8. #
  9. # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  10. # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  11. #
  12. # Module Name:
  13. #
  14. # SetMem.asm
  15. #
  16. # Abstract:
  17. #
  18. # SetMem function
  19. #
  20. # Notes:
  21. #
  22. #------------------------------------------------------------------------------
  23. #.MODEL flat,C
  24. .xmm:
  25. .code:
  26. #------------------------------------------------------------------------------
  27. # VOID *
  28. # _mem_SetMem (
  29. # IN VOID *Buffer,
  30. # IN UINTN Count,
  31. # IN UINT8 Value
  32. # );
  33. #------------------------------------------------------------------------------
  34. ASM_GLOBAL ASM_PFX(InternalMemSetMem)
  35. ASM_PFX(InternalMemSetMem):
  36. push %edi
  37. movl 12(%esp), %edx # edx <- Count
  38. movl 8(%esp), %edi # edi <- Buffer
  39. movb 16(%esp), %al # al <- Value
  40. xorl %ecx, %ecx
  41. subl %edi, %ecx
  42. andl $15, %ecx # ecx + edi aligns on 16-byte boundary
  43. jz L0
  44. cmpl %edx, %ecx
  45. cmova %edx, %ecx
  46. subl %ecx, %edx
  47. rep
  48. stosb
  49. L0:
  50. movl %edx, %ecx
  51. andl $15, %edx
  52. shrl $4, %ecx # ecx <- # of DQwords to set
  53. jz L_SetBytes
  54. movb %al, %ah # ax <- Value | (Value << 8)
  55. addl $-16, %esp
  56. movdqu %xmm0, (%esp)
  57. movd %eax, %xmm0
  58. pshuflw $0, %xmm0, %xmm0
  59. movlhps %xmm0, %xmm0
  60. L1:
  61. movntdq %xmm0, (%edi)
  62. addl $16, %edi
  63. loop L1
  64. mfence
  65. movdqu (%esp), %xmm0
  66. addl $16, %esp # stack cleanup
  67. L_SetBytes:
  68. movl %edx, %ecx
  69. rep
  70. stosb
  71. movl 8(%esp), %eax # eax <- Buffer as return value
  72. pop %edi
  73. ret