2012-08-14 19:20:20 +08:00
|
|
|
/*
|
|
|
|
* String handling functions.
|
|
|
|
*
|
|
|
|
* Copyright IBM Corp. 2012
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/linkage.h>
|
2016-01-13 02:30:03 +08:00
|
|
|
#include <asm/export.h>
|
2012-08-14 19:20:20 +08:00
|
|
|
|
2016-12-07 20:45:38 +08:00
|
|
|
/*
|
|
|
|
* void *memmove(void *dest, const void *src, size_t n)
|
|
|
|
*/
|
|
|
|
ENTRY(memmove)
|
|
|
|
ltgr %r4,%r4
|
|
|
|
lgr %r1,%r2
|
|
|
|
bzr %r14
|
2016-12-15 15:35:10 +08:00
|
|
|
aghi %r4,-1
|
2016-12-07 20:45:38 +08:00
|
|
|
clgr %r2,%r3
|
|
|
|
jnh .Lmemmove_forward
|
2016-12-15 15:35:10 +08:00
|
|
|
la %r5,1(%r4,%r3)
|
2016-12-07 20:45:38 +08:00
|
|
|
clgr %r2,%r5
|
|
|
|
jl .Lmemmove_reverse
|
|
|
|
.Lmemmove_forward:
|
|
|
|
srlg %r0,%r4,8
|
|
|
|
ltgr %r0,%r0
|
2016-12-15 15:35:10 +08:00
|
|
|
jz .Lmemmove_forward_remainder
|
|
|
|
.Lmemmove_forward_loop:
|
2016-12-07 20:45:38 +08:00
|
|
|
mvc 0(256,%r1),0(%r3)
|
|
|
|
la %r1,256(%r1)
|
|
|
|
la %r3,256(%r3)
|
2016-12-15 15:35:10 +08:00
|
|
|
brctg %r0,.Lmemmove_forward_loop
|
|
|
|
.Lmemmove_forward_remainder:
|
2016-12-07 20:45:38 +08:00
|
|
|
larl %r5,.Lmemmove_mvc
|
|
|
|
ex %r4,0(%r5)
|
|
|
|
br %r14
|
|
|
|
.Lmemmove_reverse:
|
|
|
|
ic %r0,0(%r4,%r3)
|
|
|
|
stc %r0,0(%r4,%r1)
|
2016-12-15 15:35:10 +08:00
|
|
|
brctg %r4,.Lmemmove_reverse
|
2016-12-07 20:45:38 +08:00
|
|
|
ic %r0,0(%r4,%r3)
|
|
|
|
stc %r0,0(%r4,%r1)
|
|
|
|
br %r14
|
|
|
|
.Lmemmove_mvc:
|
|
|
|
mvc 0(1,%r1),0(%r3)
|
|
|
|
EXPORT_SYMBOL(memmove)
|
|
|
|
|
2012-08-14 19:20:20 +08:00
|
|
|
/*
|
|
|
|
* memset implementation
|
|
|
|
*
|
|
|
|
* This code corresponds to the C construct below. We do distinguish
|
|
|
|
* between clearing (c == 0) and setting a memory array (c != 0) simply
|
|
|
|
* because nearly all memset invocations in the kernel clear memory and
|
|
|
|
* the xc instruction is preferred in such cases.
|
|
|
|
*
|
|
|
|
* void *memset(void *s, int c, size_t n)
|
|
|
|
* {
|
|
|
|
* if (likely(c == 0))
|
|
|
|
* return __builtin_memset(s, 0, n);
|
|
|
|
* return __builtin_memset(s, c, n);
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
ENTRY(memset)
|
|
|
|
ltgr %r4,%r4
|
|
|
|
bzr %r14
|
|
|
|
ltgr %r3,%r3
|
|
|
|
jnz .Lmemset_fill
|
|
|
|
aghi %r4,-1
|
|
|
|
srlg %r3,%r4,8
|
|
|
|
ltgr %r3,%r3
|
|
|
|
lgr %r1,%r2
|
2016-12-15 15:35:10 +08:00
|
|
|
jz .Lmemset_clear_remainder
|
2012-08-14 19:20:20 +08:00
|
|
|
.Lmemset_clear_loop:
|
|
|
|
xc 0(256,%r1),0(%r1)
|
|
|
|
la %r1,256(%r1)
|
|
|
|
brctg %r3,.Lmemset_clear_loop
|
2016-12-15 15:35:10 +08:00
|
|
|
.Lmemset_clear_remainder:
|
2012-08-14 19:20:20 +08:00
|
|
|
larl %r3,.Lmemset_xc
|
|
|
|
ex %r4,0(%r3)
|
|
|
|
br %r14
|
|
|
|
.Lmemset_fill:
|
|
|
|
stc %r3,0(%r2)
|
|
|
|
cghi %r4,1
|
|
|
|
lgr %r1,%r2
|
|
|
|
ber %r14
|
|
|
|
aghi %r4,-2
|
|
|
|
srlg %r3,%r4,8
|
|
|
|
ltgr %r3,%r3
|
2016-12-15 15:35:10 +08:00
|
|
|
jz .Lmemset_fill_remainder
|
2012-08-14 19:20:20 +08:00
|
|
|
.Lmemset_fill_loop:
|
|
|
|
mvc 1(256,%r1),0(%r1)
|
|
|
|
la %r1,256(%r1)
|
|
|
|
brctg %r3,.Lmemset_fill_loop
|
2016-12-15 15:35:10 +08:00
|
|
|
.Lmemset_fill_remainder:
|
2012-08-14 19:20:20 +08:00
|
|
|
larl %r3,.Lmemset_mvc
|
|
|
|
ex %r4,0(%r3)
|
|
|
|
br %r14
|
|
|
|
.Lmemset_xc:
|
|
|
|
xc 0(1,%r1),0(%r1)
|
|
|
|
.Lmemset_mvc:
|
|
|
|
mvc 1(1,%r1),0(%r1)
|
2016-01-13 02:30:03 +08:00
|
|
|
EXPORT_SYMBOL(memset)
|
2012-08-14 19:20:20 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* memcpy implementation
|
|
|
|
*
|
|
|
|
* void *memcpy(void *dest, const void *src, size_t n)
|
|
|
|
*/
|
|
|
|
ENTRY(memcpy)
|
|
|
|
ltgr %r4,%r4
|
|
|
|
bzr %r14
|
|
|
|
aghi %r4,-1
|
|
|
|
srlg %r5,%r4,8
|
|
|
|
ltgr %r5,%r5
|
|
|
|
lgr %r1,%r2
|
|
|
|
jnz .Lmemcpy_loop
|
2016-12-15 15:35:10 +08:00
|
|
|
.Lmemcpy_remainder:
|
2012-08-14 19:20:20 +08:00
|
|
|
larl %r5,.Lmemcpy_mvc
|
|
|
|
ex %r4,0(%r5)
|
|
|
|
br %r14
|
|
|
|
.Lmemcpy_loop:
|
|
|
|
mvc 0(256,%r1),0(%r3)
|
|
|
|
la %r1,256(%r1)
|
|
|
|
la %r3,256(%r3)
|
|
|
|
brctg %r5,.Lmemcpy_loop
|
2016-12-15 15:35:10 +08:00
|
|
|
j .Lmemcpy_remainder
|
2012-08-14 19:20:20 +08:00
|
|
|
.Lmemcpy_mvc:
|
|
|
|
mvc 0(1,%r1),0(%r3)
|
2016-01-13 02:30:03 +08:00
|
|
|
EXPORT_SYMBOL(memcpy)
|