]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OldMdePkg/Library/BaseMemoryLibSse2/Ia32/SetMem.asm
Moved the MdePkg to OldMdePkg so that new code in MdePkg does not break existing...
[mirror_edk2.git] / OldMdePkg / Library / BaseMemoryLibSse2 / Ia32 / SetMem.asm
diff --git a/OldMdePkg/Library/BaseMemoryLibSse2/Ia32/SetMem.asm b/OldMdePkg/Library/BaseMemoryLibSse2/Ia32/SetMem.asm
new file mode 100644 (file)
index 0000000..a4de29c
--- /dev/null
@@ -0,0 +1,75 @@
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 2006, Intel Corporation\r
+; All rights reserved. This program and the accompanying materials\r
+; are licensed and made available under the terms and conditions of the BSD License\r
+; which accompanies this distribution.  The full text of the license may be found at\r
+; http://opensource.org/licenses/bsd-license.php\r
+;\r
+; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+;\r
+; Module Name:\r
+;\r
+;   SetMem.asm\r
+;\r
+; Abstract:\r
+;\r
+;   SetMem function\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+    .686\r
+    .model  flat,C\r
+    .xmm\r
+    .code\r
+\r
+;------------------------------------------------------------------------------\r
+;  VOID *\r
+;  EFIAPI\r
+;  InternalMemSetMem (\r
+;    IN VOID   *Buffer,\r
+;    IN UINTN  Count,\r
+;    IN UINT8  Value\r
+;    );\r
+;------------------------------------------------------------------------------\r
+InternalMemSetMem   PROC    USES    edi\r
+    mov     edx, [esp + 12]             ; edx <- Count\r
+    mov     edi, [esp + 8]              ; edi <- Buffer\r
+    mov     al, [esp + 16]              ; al <- Value\r
+    xor     ecx, ecx\r
+    sub     ecx, edi\r
+    and     ecx, 15                     ; ecx + edi aligns on 16-byte boundary\r
+    jz      @F\r
+    cmp     ecx, edx\r
+    cmova   ecx, edx\r
+    sub     edx, ecx\r
+    rep     stosb\r
+@@:\r
+    mov     ecx, edx\r
+    and     edx, 15\r
+    shr     ecx, 4                      ; ecx <- # of DQwords to set\r
+    jz      @SetBytes\r
+    mov     ah, al                      ; ax <- Value | (Value << 8)\r
+    add     esp, -16\r
+    movdqu  [esp], xmm0                 ; save xmm0\r
+    movd    xmm0, eax\r
+    pshuflw xmm0, xmm0, 0               ; xmm0[0..63] <- Value repeats 8 times\r
+    movlhps xmm0, xmm0                  ; xmm0 <- Value repeats 16 times\r
+@@:\r
+    movntdq [edi], xmm0                 ; edi should be 16-byte aligned\r
+    add     edi, 16\r
+    loop    @B\r
+    mfence\r
+    movdqu  xmm0, [esp]                 ; restore xmm0\r
+    add     esp, 16                     ; stack cleanup\r
+@SetBytes:\r
+    mov     ecx, edx\r
+    rep     stosb\r
+    mov     eax, [esp + 8]              ; eax <- Buffer as return value\r
+    ret\r
+InternalMemSetMem   ENDP\r
+\r
+    END\r