2.9
[glibc/nacl-glibc.git] / sysdeps / s390 / s390-64 / bcopy.S
blobabcb1fb1b4b5f1f7376d5d07e2370790aa2f6833
1 /* bcopy -- copy a block from source to destination.  64 bit S/390 version.
2    This file is part of the GNU C Library.
3    Copyright (C) 2000, 2001, 2005 Free Software Foundation, Inc.
4    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, write to the Free
18    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19    02111-1307 USA.  */
21 /* INPUT PARAMETERS
22      %r2 = address of source
23      %r3 = address of destination
24      %r4 = number of bytes to copy.  */
26 #include "sysdep.h"
27 #include "asm-syntax.h"
29         .text
30 ENTRY(__bcopy)
31         ltgr    %r1,%r4             # zero bcopy ?
32         jz      .L4
33         clgr    %r2,%r3             # check against destructive overlap
34         jnl     .L0
35         algr    %r1,%r2
36         clgr    %r1,%r3
37         jh      .L7
38 .L0:    aghi    %r4,-1              # length - 1
39         srlg    %r1,%r4,8
40         ltgr    %r1,%r1             # < 256 bytes to move ?
41         jz      .L2
42         cghi    %r1,255             # > 1MB to move ?
43         jh      .L5
44 .L1:    mvc     0(256,%r3),0(%r2)   # move in 256 byte chunks
45         la      %r2,256(%r2)
46         la      %r3,256(%r3)
47         brctg   %r1,.L1
48 .L2:    bras    %r1,.L3             # setup base pointer for execute
49         mvc     0(1,%r3),0(%r2)     # instruction for execute
50 .L3:    ex      %r4,0(%r1)          # execute mvc with length ((%r4)&255)+1
51 .L4:    br      %r14
52         # data copies > 1MB are faster with mvcle.
53 .L5:    aghi    %r4,1               # length + 1
54         lgr     %r5,%r4             # source length
55         lgr     %r4,%r2             # source address
56         lgr     %r2,%r3             # set destination
57         lgr     %r3,%r5             # destination length = source length
58 .L6:    mvcle   %r2,%r4,0           # thats it, MVCLE is your friend
59         jo      .L6
60         br      %r14
61 .L7:                                # destructive overlay, can not use mvcle
62         lgr     %r1,%r2             # bcopy is called with source,dest
63         lgr     %r2,%r3             # memmove with dest,source! Oh, well...
64         lgr     %r3,%r1
65         jg      HIDDEN_BUILTIN_JUMPTARGET(memmove)
67 END(__bcopy)
69 #ifndef NO_WEAK_ALIAS
70 weak_alias (__bcopy, bcopy)
71 #endif