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/] [strlen.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 "strlen.s"
        .file "strlen.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 strlen  (optimized assembler version for the 80960K series)
        procedure strlen  (optimized assembler version for the 80960K series)
        src_addr = strlen (src_addr)
        src_addr = strlen (src_addr)
        return the number of bytes that precede the null byte in the
        return the number of bytes that precede the null byte in the
        string pointed to by src_addr.
        string pointed to by src_addr.
        Undefined behavior will occur if the end of the source string (i.e.
        Undefined behavior will occur if the end of the source string (i.e.
        the terminating null byte) is in the last four words of the program's
        the terminating null byte) is in the last four words of the program's
        allocated memory space.  This is so because strlen fetches ahead
        allocated memory space.  This is so because strlen fetches ahead
        several words.  Disallowing the fetch ahead would impose a severe
        several words.  Disallowing the fetch ahead would impose a severe
        performance penalty.
        performance penalty.
        Strategy:
        Strategy:
        Fetch the source array by long-words and scanbyte the words for the
        Fetch the source array by long-words and scanbyte the words for the
        null byte until found.  Examine the word in which the null byte is
        null byte until found.  Examine the word in which the null byte is
        found, to determine its actual position, and return the length.
        found, to determine its actual position, and return the length.
        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 that would be necessary to assure alignment.  This
        by the preamble that would be necessary to assure alignment.  This
        is supported by the intuition that many source strings will be word
        is supported by the intuition that many source strings will be word
        aligned to begin with.
        aligned to begin with.
*/
*/
        .globl  _strlen
        .globl  _strlen
        .globl  __strlen
        .globl  __strlen
        .leafproc       _strlen, __strlen
        .leafproc       _strlen, __strlen
        .align  2
        .align  2
_strlen:
_strlen:
#ifndef __PIC
#ifndef __PIC
        lda     Lrett,g14
        lda     Lrett,g14
#else
#else
        lda     Lrett-(.+8)(ip),g14
        lda     Lrett-(.+8)(ip),g14
#endif
#endif
__strlen:
__strlen:
        mov     g14,g13         # preserve return address
        mov     g14,g13         # preserve return address
        ldl     (g0),g4         # fetch first two words
        ldl     (g0),g4         # fetch first two words
        addo    8,g0,g2         # post-increment src word pointer
        addo    8,g0,g2         # post-increment src word pointer
        lda     0xff,g3         # byte extraction mask
        lda     0xff,g3         # byte extraction mask
Lsearch_for_word_with_null_byte:
Lsearch_for_word_with_null_byte:
        scanbyte 0,g4           # check for null byte
        scanbyte 0,g4           # check for null byte
        mov     g5,g7           # copy second word
        mov     g5,g7           # copy second word
        bo.f    Lsearch_for_null        # branch if null found
        bo.f    Lsearch_for_null        # branch if null found
        scanbyte 0,g7           # check for null byte
        scanbyte 0,g7           # check for null byte
        ldl     (g2),g4         # fetch next pair of word of src
        ldl     (g2),g4         # fetch next pair of word of src
        addo    8,g2,g2         # post-increment src word pointer
        addo    8,g2,g2         # post-increment src word pointer
        bno     Lsearch_for_word_with_null_byte # branch if null not found yet
        bno     Lsearch_for_word_with_null_byte # branch if null not found yet
        subo    4,g2,g2         # back up the byte pointer
        subo    4,g2,g2         # back up the byte pointer
        mov     g7,g4           # move word with null to search word
        mov     g7,g4           # move word with null to search word
Lsearch_for_null:
Lsearch_for_null:
        subo    9,g2,g2         # back up the byte pointer
        subo    9,g2,g2         # back up the byte pointer
Lsearch_for_null.a:
Lsearch_for_null.a:
        and     g4,g3,g14       # extract byte
        and     g4,g3,g14       # extract byte
        cmpo    0,g14           # is it null?
        cmpo    0,g14           # is it null?
        addo    1,g2,g2         # bump src byte ptr
        addo    1,g2,g2         # bump src byte ptr
        shro    8,g4,g4         # shift word to position next byte
        shro    8,g4,g4         # shift word to position next byte
        bne     Lsearch_for_null.a
        bne     Lsearch_for_null.a
Lexit_code:
Lexit_code:
        subo    g0,g2,g0        # calculate string length
        subo    g0,g2,g0        # calculate string length
        bx      (g13)           # g0 = addr of src;  g14 = 0
        bx      (g13)           # g0 = addr of src;  g14 = 0
Lrett:
Lrett:
        ret
        ret
/* end of strlen */
/* end of strlen */
 
 

powered by: WebSVN 2.1.0

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