OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [machine/] [i960/] [strcmp.S] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
/*******************************************************************************
/*******************************************************************************
 *
 *
 * Copyright (c) 1993 Intel Corporation
 * Copyright (c) 1993 Intel Corporation
 *
 *
 * Intel hereby grants you permission to copy, modify, and distribute this
 * Intel hereby grants you permission to copy, modify, and distribute this
 * software and its documentation.  Intel grants this permission provided
 * software and its documentation.  Intel grants this permission provided
 * that the above copyright notice appears in all copies and that both the
 * that the above copyright notice appears in all copies and that both the
 * copyright notice and this permission notice appear in supporting
 * copyright notice and this permission notice appear in supporting
 * documentation.  In addition, Intel grants this permission provided that
 * documentation.  In addition, Intel grants this permission provided that
 * you prominently mark as "not part of the original" any modifications
 * you prominently mark as "not part of the original" any modifications
 * made to this software or documentation, and that the name of Intel
 * made to this software or documentation, and that the name of Intel
 * Corporation not be used in advertising or publicity pertaining to
 * Corporation not be used in advertising or publicity pertaining to
 * distribution of the software or the documentation without specific,
 * distribution of the software or the documentation without specific,
 * written prior permission.
 * written prior permission.
 *
 *
 * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR
 * Intel Corporation provides this AS IS, WITHOUT ANY WARRANTY, EXPRESS OR
 * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY
 * IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY
 * OR FITNESS FOR A PARTICULAR PURPOSE.  Intel makes no guarantee or
 * OR FITNESS FOR A PARTICULAR PURPOSE.  Intel makes no guarantee or
 * representations regarding the use of, or the results of the use of,
 * representations regarding the use of, or the results of the use of,
 * the software and documentation in terms of correctness, accuracy,
 * the software and documentation in terms of correctness, accuracy,
 * reliability, currentness, or otherwise; and you rely on the software,
 * reliability, currentness, or otherwise; and you rely on the software,
 * documentation and results solely at your own risk.
 * documentation and results solely at your own risk.
 *
 *
 * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS,
 * IN NO EVENT SHALL INTEL BE LIABLE FOR ANY LOSS OF USE, LOSS OF BUSINESS,
 * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES
 * LOSS OF PROFITS, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES
 * OF ANY KIND.  IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM
 * OF ANY KIND.  IN NO EVENT SHALL INTEL'S TOTAL LIABILITY EXCEED THE SUM
 * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER.
 * PAID TO INTEL FOR THE PRODUCT LICENSED HEREUNDER.
 *
 *
 ******************************************************************************/
 ******************************************************************************/
        .file "strcmp.s"
        .file "strcmp.s"
#ifdef  __PIC
#ifdef  __PIC
        .pic
        .pic
#endif
#endif
#ifdef  __PID
#ifdef  __PID
        .pid
        .pid
#endif
#endif
/*
/*
 * (c) copyright 1988,1993 Intel Corp., all rights reserved
 * (c) copyright 1988,1993 Intel Corp., all rights reserved
 */
 */
/*
/*
        procedure strcmp  (optimized assembler version for the 80960K Series)
        procedure strcmp  (optimized assembler version for the 80960K Series)
        result = strcmp (src1_addr, src2_addr)
        result = strcmp (src1_addr, src2_addr)
        compare the null terminated string pointed to by src1_addr to
        compare the null terminated string pointed to by src1_addr to
        the string pointed to by src2_addr.  Return 0 iff the strings
        the string pointed to by src2_addr.  Return 0 iff the strings
        are equal, -1 if src1_addr is lexicographically less than src2_addr,
        are equal, -1 if src1_addr is lexicographically less than src2_addr,
        and 1 if it is lexicographically greater.
        and 1 if it is lexicographically greater.
        Undefined behavior will occur if the end of either source string
        Undefined behavior will occur if the end of either source string
        (i.e. the terminating null byte) is in the last two words of the
        (i.e. the terminating null byte) is in the last two words of the
        program's allocated memory space.  This is so because strcmp fetches
        program's allocated memory space.  This is so because strcmp fetches
        ahead.  Disallowing the fetch ahead would impose a severe performance
        ahead.  Disallowing the fetch ahead would impose a severe performance
        penalty.
        penalty.
        Strategy:
        Strategy:
        Fetch the source strings by words and compare the words until either
        Fetch the source strings by words and compare the words until either
        differing words are found or the null byte is encountered.  In either
        differing words are found or the null byte is encountered.  In either
        case, move through the word until either the differing byte if found,
        case, move through the word until either the differing byte if found,
        in which case return -1 or 1 appropriately;  or the null byte is
        in which case return -1 or 1 appropriately;  or the null byte is
        encountered, in which case, return zero (equality).
        encountered, in which case, return zero (equality).
        Tactics:
        Tactics:
        1) Do NOT try to fetch the words in a word aligned manner because,
        1) Do NOT try to fetch the words in a word aligned manner because,
        in my judgement, the performance degradation experienced due to
        in my judgement, the performance degradation experienced due to
        non-aligned accesses does NOT outweigh the time and complexity added
        non-aligned accesses does NOT outweigh the time and complexity added
        by the preamble and convoluted body that would be necessary to assure
        by the preamble and convoluted body that would be necessary to assure
        alignment.  This is supported by the intuition that many source
        alignment.  This is supported by the intuition that many source
        strings will be word aligned to begin with.
        strings will be word aligned to begin with.
*/
*/
        .globl _strcmp
        .globl _strcmp
        .globl __strcmp
        .globl __strcmp
        .leafproc _strcmp,__strcmp
        .leafproc _strcmp,__strcmp
        .align 2
        .align 2
_strcmp:
_strcmp:
#ifndef __PIC
#ifndef __PIC
        lda     .Lrett,g14
        lda     .Lrett,g14
#else
#else
        lda     .Lrett-(.+8)(ip),g14
        lda     .Lrett-(.+8)(ip),g14
#endif
#endif
__strcmp:
__strcmp:
        ld      (g0), g5        # fetch first word of source_1
        ld      (g0), g5        # fetch first word of source_1
        mov     g14,g7          # preserve return address
        mov     g14,g7          # preserve return address
        ldconst 0,g14           # conform to register conventions
        ldconst 0,g14           # conform to register conventions
        ldconst 0xff,g4         # byte extraction mask
        ldconst 0xff,g4         # byte extraction mask
.Lwloop:
.Lwloop:
        addo     4,g0,g0        # post-increment source_1 byte ptr
        addo     4,g0,g0        # post-increment source_1 byte ptr
        ld      (g1), g3        # fetch word of source_2
        ld      (g1), g3        # fetch word of source_2
        scanbyte 0,g5           # does word have a null byte?
        scanbyte 0,g5           # does word have a null byte?
        mov      g5,g2          # save a copy of the source_1 word
        mov      g5,g2          # save a copy of the source_1 word
        be .Lcloop              # branch if null byte encountered
        be .Lcloop              # branch if null byte encountered
        cmpo     g2,g3          # are the source words the same?
        cmpo     g2,g3          # are the source words the same?
        addo     4,g1,g1        # post-increment source_2 byte ptr
        addo     4,g1,g1        # post-increment source_2 byte ptr
        ld      (g0), g5        # fetch ahead next word of source_1
        ld      (g0), g5        # fetch ahead next word of source_1
        be       .Lwloop                # fall thru if words are unequal
        be       .Lwloop                # fall thru if words are unequal
.Lcloop: and    g4,g2,g5        # extract and compare individual bytes
.Lcloop: and    g4,g2,g5        # extract and compare individual bytes
        and     g4,g3,g6
        and     g4,g3,g6
        cmpobne g5,g6,.diff     # if they differ, go return 1 or -1
        cmpobne g5,g6,.diff     # if they differ, go return 1 or -1
        cmpo    0,g6            # they are the same.  Are they null?
        cmpo    0,g6            # they are the same.  Are they null?
        shlo    8,g4,g4         # position mask for next extraction
        shlo    8,g4,g4         # position mask for next extraction
        bne     .Lcloop         # loop if null not encountered
        bne     .Lcloop         # loop if null not encountered
        mov     0,g0            # return equality
        mov     0,g0            # return equality
        bx      (g7)
        bx      (g7)
.Lrett:
.Lrett:
        ret
        ret
.diff:  bl      .neg
.diff:  bl      .neg
        mov     1,g0
        mov     1,g0
        bx      (g7)
        bx      (g7)
.neg:   subi    1,0,g0
.neg:   subi    1,0,g0
.Lexit:
.Lexit:
        bx      (g7)
        bx      (g7)
 
 

powered by: WebSVN 2.1.0

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