memcmp.asm revision ff1c2857f14cb60d1463a4979e06c698135878f8
6210N/A; $Id$
6210N/A;; @file
6210N/A; InnoTek Portable Runtime - No-CRT memcmp - AMD64 & X86.
6210N/A;
6210N/A
6210N/A;
6210N/A; Copyright (C) 2006 InnoTek Systemberatung GmbH
6210N/A;
6210N/A; This file is part of VirtualBox Open Source Edition (OSE), as
6210N/A; available from http://www.virtualbox.org. This file is free software;
6210N/A; you can redistribute it and/or modify it under the terms of the GNU
6210N/A; General Public License as published by the Free Software Foundation,
6210N/A; in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
6210N/A; distribution. VirtualBox OSE is distributed in the hope that it will
6210N/A; be useful, but WITHOUT ANY WARRANTY of any kind.
6210N/A;
6210N/A; If you received this file as part of a commercial VirtualBox
6210N/A; distribution, then only the terms of your commercial VirtualBox
6210N/A; license agreement apply instead of the previous paragraph.
6210N/A;
6210N/A
6210N/A%include "iprt/asmdefs.mac"
6210N/A
6210N/ABEGINCODE
6210N/A
6210N/A;;
6210N/A; @param pv1 gcc: rdi msc: rcx x86:[esp+4]
6210N/A; @param pv2 gcc: rsi msc: rdx x86:[esp+8]
6210N/A; @param cb gcc: rdx msc: r8 x86:[esp+0ch]
6210N/ABEGINPROC RT_NOCRT(memcmp)
6210N/A cld
6210N/A
6210N/A ; Do the bulk of the work.
6210N/A%ifdef __AMD64__
6246N/A %ifdef ASM_CALL64_MSC
6210N/A mov r10, rdi ; save
6210N/A mov r11, rsi ; save
6210N/A mov rdi, rcx
6210N/A mov rsi, rdx
6210N/A mov rcx, r8
6210N/A mov rdx, r8
6210N/A %else
6210N/A mov rcx, rdx
6210N/A %endif
6210N/A mov rax, rdi ; save the return value
6210N/A shr rcx, 3
6210N/A repe cmpsq
6210N/A jne .not_equal_qword
6210N/A%else
6210N/A push edi
6210N/A push esi
6210N/A
6210N/A mov ecx, [esp + 0ch + 8]
6210N/A mov edi, [esp + 04h + 8]
6210N/A mov esi, [esp + 08h + 8]
6210N/A mov edx, ecx
6210N/A xor eax, eax
6210N/A jecxz .done
6210N/A shr ecx, 2
6210N/A repe cmpsd
6210N/A jne .not_equal_dword
6210N/A%endif
6210N/A
6210N/A ; The remaining bytes.
6210N/A%ifdef __AMD64__
6210N/A test dl, 4
6210N/A jz .dont_cmp_dword
6210N/A cmpsd
6210N/A jne .not_equal_dword
6210N/A%endif
6210N/A.dont_cmp_dword:
6210N/A test dl, 2
6210N/A jz .dont_cmp_word
6210N/A cmpsw
6210N/A jne .not_equal_word
6210N/A.dont_cmp_word:
6210N/A test dl, 1
6210N/A jz .dont_cmp_byte
6210N/A cmpsb
6210N/A jne .not_equal_byte
6210N/A.dont_cmp_byte:
6210N/A
6210N/A.done:
6210N/A%ifdef __AMD64__
6210N/A %ifdef ASM_CALL64_MSC
6210N/A mov rdi, r10
6210N/A mov rsi, r11
6210N/A %endif
6210N/A%else
6210N/A pop esi
6210N/A pop edi
6210N/A%endif
6210N/A ret
6210N/A
6210N/A;
6210N/A; Mismatches.
6210N/A;
6210N/A%ifdef __AMD64__
6210N/A.not_equal_qword:
6210N/A mov ecx, 8
6210N/A sub rsi, 8
6210N/A sub rdi, 8
6210N/A.not_equal_byte:
6210N/A repe cmpsb
6210N/A mov al, [xDI-1]
6210N/A movzx ecx, byte [xSI-1]
6210N/A sub eax, ecx
6210N/A jmp .done
6210N/A%endif
6210N/A
6210N/A.not_equal_dword:
6210N/A mov ecx, 4
6210N/A sub xSI, 4
6210N/A sub xDI, 4
6210N/A repe cmpsb
6210N/A%ifdef __AMD64__
6246N/A jmp .not_equal_byte
6210N/A%else
6210N/A.not_equal_byte:
6210N/A mov al, [xDI-1]
6210N/A movzx ecx, byte [xSI-1]
6246N/A sub eax, ecx
6210N/A jmp .done
6210N/A%endif
6210N/A
6210N/A.not_equal_word:
6210N/A mov ecx, 2
6246N/A sub xSI, 2
6210N/A sub xDI, 2
6210N/A repe cmpsb
6210N/A jmp .not_equal_byte
6210N/AENDPROC RT_NOCRT(memcmp)
6210N/A
6210N/A