OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [machine/] [i960/] [strcmp.S] - Blame information for rev 862

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/*******************************************************************************
2
 *
3
 * Copyright (c) 1993 Intel Corporation
4
 *
5
 * Intel hereby grants you permission to copy, modify, and distribute this
6
 * software and its documentation.  Intel grants this permission provided
7
 * that the above copyright notice appears in all copies and that both the
8
 * copyright notice and this permission notice appear in supporting
9
 * documentation.  In addition, Intel grants this permission provided that
10
 * you prominently mark as "not part of the original" any modifications
11
 * made to this software or documentation, and that the name of Intel
12
 * Corporation not be used in advertising or publicity pertaining to
13
 * distribution of the software or the documentation without specific,
14
 * written prior permission.
15
 *
16
 * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR
17
 * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY
18
 * OR FITNESS FOR A PARTICULAR PURPOSE.  Intel makes no guarantee or
19
 * representations regarding the use of, or the results of the use of,
20
 * the software and documentation in terms of correctness, accuracy,
21
 * reliability, currentness, or otherwise; and you rely on the software,
22
 * documentation and results solely at your own risk.
23
 *
24
 * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS,
25
 * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES
26
 * OF ANY KIND.  IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM
27
 * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER.
28
 *
29
 ******************************************************************************/
30
 
31
        .file "strcmp.s"
32
#ifdef  __PIC
33
        .pic
34
#endif
35
#ifdef  __PID
36
        .pid
37
#endif
38
/*
39
 * (c) copyright 1988,1993 Intel Corp., all rights reserved
40
 */
41
/*
42
        procedure strcmp  (optimized assembler version for the 80960K Series)
43
 
44
        result = strcmp (src1_addr, src2_addr)
45
 
46
        compare the null terminated string pointed to by src1_addr to
47
        the string pointed to by src2_addr.  Return 0 iff the strings
48
        are equal, -1 if src1_addr is lexicographically less than src2_addr,
49
        and 1 if it is lexicographically greater.
50
 
51
        Undefined behavior will occur if the end of either source string
52
        (i.e. the terminating null byte) is in the last two words of the
53
        program's allocated memory space.  This is so because strcmp fetches
54
        ahead.  Disallowing the fetch ahead would impose a severe performance
55
        penalty.
56
 
57
        Strategy:
58
 
59
        Fetch the source strings by words and compare the words until either
60
        differing words are found or the null byte is encountered.  In either
61
        case, move through the word until either the differing byte if found,
62
        in which case return -1 or 1 appropriately;  or the null byte is
63
        encountered, in which case, return zero (equality).
64
 
65
        Tactics:
66
 
67
        1) Do NOT try to fetch the words in a word aligned manner because,
68
        in my judgement, the performance degradation experienced due to
69
        non-aligned accesses does NOT outweigh the time and complexity added
70
        by the preamble and convoluted body that would be necessary to assure
71
        alignment.  This is supported by the intuition that many source
72
        strings will be word aligned to begin with.
73
*/
74
 
75
        .globl _strcmp
76
        .globl __strcmp
77
        .leafproc _strcmp,__strcmp
78
        .align 2
79
 
80
_strcmp:
81
#ifndef __PIC
82
        lda     .Lrett,g14
83
#else
84
        lda     .Lrett-(.+8)(ip),g14
85
#endif
86
__strcmp:
87
        ld      (g0), g5        # fetch first word of source_1
88
        mov     g14,g7          # preserve return address
89
        ldconst 0,g14           # conform to register conventions
90
        ldconst 0xff,g4         # byte extraction mask
91
.Lwloop:
92
        addo     4,g0,g0        # post-increment source_1 byte ptr
93
        ld      (g1), g3        # fetch word of source_2
94
        scanbyte 0,g5           # does word have a null byte?
95
        mov      g5,g2          # save a copy of the source_1 word
96
        be .Lcloop              # branch if null byte encountered
97
        cmpo     g2,g3          # are the source words the same?
98
        addo     4,g1,g1        # post-increment source_2 byte ptr
99
        ld      (g0), g5        # fetch ahead next word of source_1
100
        be       .Lwloop                # fall thru if words are unequal
101
 
102
.Lcloop: and    g4,g2,g5        # extract and compare individual bytes
103
        and     g4,g3,g6
104
        cmpobne g5,g6,.diff     # if they differ, go return 1 or -1
105
        cmpo    0,g6            # they are the same.  Are they null?
106
        shlo    8,g4,g4         # position mask for next extraction
107
        bne     .Lcloop         # loop if null not encountered
108
 
109
        mov     0,g0            # return equality
110
        bx      (g7)
111
.Lrett:
112
        ret
113
.diff:  bl      .neg
114
        mov     1,g0
115
        bx      (g7)
116
.neg:   subi    1,0,g0
117
.Lexit:
118
        bx      (g7)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.