~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/alpha/lib/memchr.S

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/alpha/lib/memchr.S (Architecture i386) and /arch/alpha/lib/memchr.S (Architecture alpha)


  1 /* Copyright (C) 1996 Free Software Foundation      1 /* Copyright (C) 1996 Free Software Foundation, Inc.
  2    This file is part of the GNU C Library.          2    This file is part of the GNU C Library.
  3    Contributed by David Mosberger (davidm@cs.a      3    Contributed by David Mosberger (davidm@cs.arizona.edu).
  4                                                     4 
  5    The GNU C Library is free software; you can      5    The GNU C Library is free software; you can redistribute it and/or
  6    modify it under the terms of the GNU Librar      6    modify it under the terms of the GNU Library General Public License as
  7    published by the Free Software Foundation;       7    published by the Free Software Foundation; either version 2 of the
  8    License, or (at your option) any later vers      8    License, or (at your option) any later version.
  9                                                     9 
 10    The GNU C Library is distributed in the hop     10    The GNU C Library is distributed in the hope that it will be useful,
 11    but WITHOUT ANY WARRANTY; without even the      11    but WITHOUT ANY WARRANTY; without even the implied warranty of
 12    MERCHANTABILITY or FITNESS FOR A PARTICULAR     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13    Library General Public License for more det     13    Library General Public License for more details.
 14                                                    14 
 15    You should have received a copy of the GNU      15    You should have received a copy of the GNU Library General Public
 16    License along with the GNU C Library; see t     16    License along with the GNU C Library; see the file COPYING.LIB.  If not,
 17    write to the Free Software Foundation, Inc.     17    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 18    Boston, MA 02111-1307, USA.  */                 18    Boston, MA 02111-1307, USA.  */
 19                                                    19 
 20 /* Finds characters in a memory area.  Optimiz     20 /* Finds characters in a memory area.  Optimized for the Alpha:
 21                                                    21 
 22       - memory accessed as aligned quadwords o     22       - memory accessed as aligned quadwords only
 23       - uses cmpbge to compare 8 bytes in para     23       - uses cmpbge to compare 8 bytes in parallel
 24       - does binary search to find 0 byte in l     24       - does binary search to find 0 byte in last
 25         quadword (HAKMEM needed 12 instruction     25         quadword (HAKMEM needed 12 instructions to
 26         do this instead of the 9 instructions      26         do this instead of the 9 instructions that
 27         binary search needs).                      27         binary search needs).
 28                                                    28 
 29 For correctness consider that:                     29 For correctness consider that:
 30                                                    30 
 31       - only minimum number of quadwords may b     31       - only minimum number of quadwords may be accessed
 32       - the third argument is an unsigned long     32       - the third argument is an unsigned long
 33 */                                                 33 */
 34 #include <linux/export.h>                          34 #include <linux/export.h>
 35         .set noreorder                             35         .set noreorder
 36         .set noat                                  36         .set noat
 37                                                    37 
 38         .globl memchr                              38         .globl memchr
 39         .ent memchr                                39         .ent memchr
 40 memchr:                                            40 memchr:
 41         .frame $30,0,$26,0                         41         .frame $30,0,$26,0
 42         .prologue 0                                42         .prologue 0
 43                                                    43 
 44         # Hack -- if someone passes in (size_t     44         # Hack -- if someone passes in (size_t)-1, hoping to just
 45         # search til the end of the address sp     45         # search til the end of the address space, we will overflow
 46         # below when we find the address of th     46         # below when we find the address of the last byte.  Given
 47         # that we will never have a 56-bit add     47         # that we will never have a 56-bit address space, cropping
 48         # the length is the easiest way to avo     48         # the length is the easiest way to avoid trouble.
 49         zap     $18, 0x80, $5   #-e0    :          49         zap     $18, 0x80, $5   #-e0    :
 50                                                    50 
 51         beq     $18, $not_found # .. e1 :          51         beq     $18, $not_found # .. e1 :
 52         ldq_u   $1, 0($16)      # e1    : load     52         ldq_u   $1, 0($16)      # e1    : load first quadword
 53         insbl   $17, 1, $2      # .. e0 : $2 =     53         insbl   $17, 1, $2      # .. e0 : $2 = 000000000000ch00
 54         and     $17, 0xff, $17  #-e0    : $17      54         and     $17, 0xff, $17  #-e0    : $17 = 00000000000000ch
 55         cmpult  $18, 9, $4      # .. e1 :          55         cmpult  $18, 9, $4      # .. e1 :
 56         or      $2, $17, $17    # e0    : $17      56         or      $2, $17, $17    # e0    : $17 = 000000000000chch
 57         lda     $3, -1($31)     # .. e1 :          57         lda     $3, -1($31)     # .. e1 :
 58         sll     $17, 16, $2     #-e0    : $2 =     58         sll     $17, 16, $2     #-e0    : $2 = 00000000chch0000
 59         addq    $16, $5, $5     # .. e1 :          59         addq    $16, $5, $5     # .. e1 :
 60         or      $2, $17, $17    # e1    : $17      60         or      $2, $17, $17    # e1    : $17 = 00000000chchchch
 61         unop                    #       :          61         unop                    #       :
 62         sll     $17, 32, $2     #-e0    : $2 =     62         sll     $17, 32, $2     #-e0    : $2 = chchchch00000000
 63         or      $2, $17, $17    # e1    : $17      63         or      $2, $17, $17    # e1    : $17 = chchchchchchchch
 64         extql   $1, $16, $7     # e0    :          64         extql   $1, $16, $7     # e0    : 
 65         beq     $4, $first_quad # .. e1 :          65         beq     $4, $first_quad # .. e1 :
 66                                                    66 
 67         ldq_u   $6, -1($5)      #-e1    : eigh     67         ldq_u   $6, -1($5)      #-e1    : eight or less bytes to search
 68         extqh   $6, $16, $6     # .. e0 :          68         extqh   $6, $16, $6     # .. e0 :
 69         mov     $16, $0         # e0    :          69         mov     $16, $0         # e0    :
 70         or      $7, $6, $1      # .. e1 : $1 =     70         or      $7, $6, $1      # .. e1 : $1 = quadword starting at $16
 71                                                    71 
 72         # Deal with the case where at most 8 b     72         # Deal with the case where at most 8 bytes remain to be searched
 73         # in $1.  E.g.:                            73         # in $1.  E.g.:
 74         #       $18 = 6                            74         #       $18 = 6
 75         #       $1 = ????c6c5c4c3c2c1              75         #       $1 = ????c6c5c4c3c2c1
 76 $last_quad:                                        76 $last_quad:
 77         negq    $18, $6         #-e0    :          77         negq    $18, $6         #-e0    :
 78         xor     $17, $1, $1     # .. e1 :          78         xor     $17, $1, $1     # .. e1 :
 79         srl     $3, $6, $6      # e0    : $6 =     79         srl     $3, $6, $6      # e0    : $6 = mask of $18 bits set
 80         cmpbge  $31, $1, $2     # .. e1 :          80         cmpbge  $31, $1, $2     # .. e1 :
 81         and     $2, $6, $2      #-e0    :          81         and     $2, $6, $2      #-e0    :
 82         beq     $2, $not_found  # .. e1 :          82         beq     $2, $not_found  # .. e1 :
 83                                                    83 
 84 $found_it:                                         84 $found_it:
 85         # Now, determine which byte matched:       85         # Now, determine which byte matched:
 86         negq    $2, $3          # e0    :          86         negq    $2, $3          # e0    :
 87         and     $2, $3, $2      # e1    :          87         and     $2, $3, $2      # e1    :
 88                                                    88 
 89         and     $2, 0x0f, $1    #-e0    :          89         and     $2, 0x0f, $1    #-e0    :
 90         addq    $0, 4, $3       # .. e1 :          90         addq    $0, 4, $3       # .. e1 :
 91         cmoveq  $1, $3, $0      # e0    :          91         cmoveq  $1, $3, $0      # e0    :
 92                                                    92 
 93         addq    $0, 2, $3       # .. e1 :          93         addq    $0, 2, $3       # .. e1 :
 94         and     $2, 0x33, $1    #-e0    :          94         and     $2, 0x33, $1    #-e0    :
 95         cmoveq  $1, $3, $0      # .. e1 :          95         cmoveq  $1, $3, $0      # .. e1 :
 96                                                    96 
 97         and     $2, 0x55, $1    # e0    :          97         and     $2, 0x55, $1    # e0    :
 98         addq    $0, 1, $3       # .. e1 :          98         addq    $0, 1, $3       # .. e1 :
 99         cmoveq  $1, $3, $0      #-e0    :          99         cmoveq  $1, $3, $0      #-e0    :
100                                                   100 
101 $done:  ret                     # .. e1 :         101 $done:  ret                     # .. e1 :
102                                                   102 
103         # Deal with the case where $18 > 8 byt    103         # Deal with the case where $18 > 8 bytes remain to be
104         # searched.  $16 may not be aligned.      104         # searched.  $16 may not be aligned.
105         .align 4                                  105         .align 4
106 $first_quad:                                      106 $first_quad:
107         andnot  $16, 0x7, $0    #-e1    :         107         andnot  $16, 0x7, $0    #-e1    :
108         insqh   $3, $16, $2     # .. e0 : $2 =    108         insqh   $3, $16, $2     # .. e0 : $2 = 0000ffffffffffff ($16<0:2> ff)
109         xor     $1, $17, $1     # e0    :         109         xor     $1, $17, $1     # e0    :
110         or      $1, $2, $1      # e1    : $1 =    110         or      $1, $2, $1      # e1    : $1 = ====ffffffffffff
111         cmpbge  $31, $1, $2     #-e0    :         111         cmpbge  $31, $1, $2     #-e0    :
112         bne     $2, $found_it   # .. e1 :         112         bne     $2, $found_it   # .. e1 :
113                                                   113 
114         # At least one byte left to process.      114         # At least one byte left to process.
115                                                   115 
116         ldq     $1, 8($0)       # e0    :         116         ldq     $1, 8($0)       # e0    :
117         subq    $5, 1, $18      # .. e1 :         117         subq    $5, 1, $18      # .. e1 :
118         addq    $0, 8, $0       #-e0    :         118         addq    $0, 8, $0       #-e0    :
119                                                   119 
120         # Make $18 point to last quad to be ac    120         # Make $18 point to last quad to be accessed (the
121         # last quad may or may not be partial)    121         # last quad may or may not be partial).
122                                                   122 
123         andnot  $18, 0x7, $18   # .. e1 :         123         andnot  $18, 0x7, $18   # .. e1 :
124         cmpult  $0, $18, $2     # e0    :         124         cmpult  $0, $18, $2     # e0    :
125         beq     $2, $final      # .. e1 :         125         beq     $2, $final      # .. e1 :
126                                                   126 
127         # At least two quads remain to be acce    127         # At least two quads remain to be accessed.
128                                                   128 
129         subq    $18, $0, $4     #-e0    : $4 <    129         subq    $18, $0, $4     #-e0    : $4 <- nr quads to be processed
130         and     $4, 8, $4       # e1    : odd     130         and     $4, 8, $4       # e1    : odd number of quads?
131         bne     $4, $odd_quad_count # e1 :        131         bne     $4, $odd_quad_count # e1 :
132                                                   132 
133         # At least three quads remain to be ac    133         # At least three quads remain to be accessed
134                                                   134 
135         mov     $1, $4          # e0    : move    135         mov     $1, $4          # e0    : move prefetched value to correct reg
136                                                   136 
137         .align  4                                 137         .align  4
138 $unrolled_loop:                                   138 $unrolled_loop:
139         ldq     $1, 8($0)       #-e0    : pref    139         ldq     $1, 8($0)       #-e0    : prefetch $1
140         xor     $17, $4, $2     # .. e1 :         140         xor     $17, $4, $2     # .. e1 :
141         cmpbge  $31, $2, $2     # e0    :         141         cmpbge  $31, $2, $2     # e0    :
142         bne     $2, $found_it   # .. e1 :         142         bne     $2, $found_it   # .. e1 :
143                                                   143 
144         addq    $0, 8, $0       #-e0    :         144         addq    $0, 8, $0       #-e0    :
145 $odd_quad_count:                                  145 $odd_quad_count:
146         xor     $17, $1, $2     # .. e1 :         146         xor     $17, $1, $2     # .. e1 :
147         ldq     $4, 8($0)       # e0    : pref    147         ldq     $4, 8($0)       # e0    : prefetch $4
148         cmpbge  $31, $2, $2     # .. e1 :         148         cmpbge  $31, $2, $2     # .. e1 :
149         addq    $0, 8, $6       #-e0    :         149         addq    $0, 8, $6       #-e0    :
150         bne     $2, $found_it   # .. e1 :         150         bne     $2, $found_it   # .. e1 :
151                                                   151 
152         cmpult  $6, $18, $6     # e0    :         152         cmpult  $6, $18, $6     # e0    :
153         addq    $0, 8, $0       # .. e1 :         153         addq    $0, 8, $0       # .. e1 :
154         bne     $6, $unrolled_loop #-e1 :         154         bne     $6, $unrolled_loop #-e1 :
155                                                   155 
156         mov     $4, $1          # e0    : move    156         mov     $4, $1          # e0    : move prefetched value into $1
157 $final: subq    $5, $0, $18     # .. e1 : $18     157 $final: subq    $5, $0, $18     # .. e1 : $18 <- number of bytes left to do
158         bne     $18, $last_quad # e1    :         158         bne     $18, $last_quad # e1    :
159                                                   159 
160 $not_found:                                       160 $not_found:
161         mov     $31, $0         #-e0    :         161         mov     $31, $0         #-e0    :
162         ret                     # .. e1 :         162         ret                     # .. e1 :
163                                                   163 
164         .end memchr                               164         .end memchr
165         EXPORT_SYMBOL(memchr)                     165         EXPORT_SYMBOL(memchr)
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php