1 | ; $Id: memrchr.asm 62477 2016-07-22 18:27:37Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; IPRT - No-CRT memrchr - AMD64 & X86.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2016 Oracle Corporation
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
11 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | ; General Public License (GPL) as published by the Free Software
|
---|
13 | ; Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | ;
|
---|
17 | ; The contents of this file may alternatively be used under the terms
|
---|
18 | ; of the Common Development and Distribution License Version 1.0
|
---|
19 | ; (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | ; VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | ; CDDL are applicable instead of those of the GPL.
|
---|
22 | ;
|
---|
23 | ; You may elect to license modified versions of this file under the
|
---|
24 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | ;
|
---|
26 |
|
---|
27 | %include "iprt/asmdefs.mac"
|
---|
28 |
|
---|
29 | BEGINCODE
|
---|
30 |
|
---|
31 | ;;
|
---|
32 | ; @param pv gcc: rdi msc: ecx x86:[esp+4]
|
---|
33 | ; @param ch gcc: esi msc: edx x86:[esp+8]
|
---|
34 | ; @param cb gcc: rdx msc: r8 x86:[esp+0ch]
|
---|
35 | RT_NOCRT_BEGINPROC memrchr
|
---|
36 | std
|
---|
37 | %ifdef RT_ARCH_AMD64
|
---|
38 | %ifdef ASM_CALL64_MSC
|
---|
39 | or r8, r8
|
---|
40 | jz .not_found_early
|
---|
41 |
|
---|
42 | mov r9, rdi ; save rdi
|
---|
43 | mov eax, edx
|
---|
44 | lea rdi, [rcx + r8 - 1]
|
---|
45 | mov rcx, r8
|
---|
46 | %else
|
---|
47 | mov rcx, rdx
|
---|
48 | jrcxz .not_found_early
|
---|
49 |
|
---|
50 | mov eax, esi
|
---|
51 | lea rdi, [rdi + rcx - 1]
|
---|
52 | %endif
|
---|
53 |
|
---|
54 | %else
|
---|
55 | mov ecx, [esp + 0ch]
|
---|
56 | jecxz .not_found_early
|
---|
57 | mov edx, edi ; save edi
|
---|
58 | mov eax, [esp + 8]
|
---|
59 | mov edi, [esp + 4]
|
---|
60 | lea edi, [edi + ecx - 1]
|
---|
61 | %endif
|
---|
62 |
|
---|
63 | ; do the search
|
---|
64 | repne scasb
|
---|
65 | jne .not_found
|
---|
66 |
|
---|
67 | ; found it
|
---|
68 | lea xAX, [xDI + 1]
|
---|
69 | %ifdef ASM_CALL64_MSC
|
---|
70 | mov rdi, r9
|
---|
71 | %endif
|
---|
72 | %ifdef RT_ARCH_X86
|
---|
73 | mov edi, edx
|
---|
74 | %endif
|
---|
75 | cld
|
---|
76 | ret
|
---|
77 |
|
---|
78 | .not_found:
|
---|
79 | %ifdef ASM_CALL64_MSC
|
---|
80 | mov rdi, r9
|
---|
81 | %endif
|
---|
82 | %ifdef RT_ARCH_X86
|
---|
83 | mov edi, edx
|
---|
84 | %endif
|
---|
85 | .not_found_early:
|
---|
86 | xor eax, eax
|
---|
87 | cld
|
---|
88 | ret
|
---|
89 | ENDPROC RT_NOCRT(memrchr)
|
---|
90 |
|
---|