about summary refs log tree commit diff
path: root/sysdeps/loongarch/lp64/multiarch/memset-lsx.S
blob: 3d3982aa5aa5eea5c18aa56cb79015f7fa9e5f5a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* Optimized memset implementation using LoongArch LSX instructions.
   Copyright (C) 2023 Free Software Foundation, Inc.

   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library.  If not, see
   <https://www.gnu.org/licenses/>.  */

#include <sysdep.h>
#include <sys/regdef.h>
#include <sys/asm.h>

#if IS_IN (libc) && !defined __loongarch_soft_float

# define MEMSET __memset_lsx

LEAF(MEMSET, 6)
    li.d            t1, 16
    move            a3, a0
    vreplgr2vr.b    vr0, a1
    add.d           a4, a0, a2

    bgeu            t1, a2, L(less_16bytes)
    li.d            t3, 64
    li.d            t2, 32
    bgeu            a2, t3, L(long_bytes)

L(less_64bytes):
    bgeu            t2, a2, L(less_32bytes)
    vst             vr0, a3, 0
    vst             vr0, a3, 16
    vst             vr0, a4, -32

    vst             vr0, a4, -16
    jr              ra
L(less_32bytes):
    vst             vr0, a3, 0
    vst             vr0, a4, -16


    jr              ra
L(less_16bytes):
    srli.d          t0, a2, 3
    beqz            t0, L(less_8bytes)
    vstelm.d        vr0, a3, 0, 0

    vstelm.d        vr0, a4, -8, 0
    jr              ra
L(less_8bytes):
    srli.d          t0, a2, 2
    beqz            t0, L(less_4bytes)

    vstelm.w        vr0, a3, 0, 0
    vstelm.w        vr0, a4, -4, 0
    jr              ra
L(less_4bytes):
    srli.d          t0, a2, 1

    beqz            t0, L(less_2bytes)
    vstelm.h        vr0, a3, 0, 0
    vstelm.h        vr0, a4, -2, 0
    jr              ra


L(less_2bytes):
    beqz            a2, L(less_1bytes)
    vstelm.b        vr0, a3, 0, 0
L(less_1bytes):
    jr              ra
L(long_bytes):
    vst             vr0, a3, 0

    bstrins.d       a3, zero, 3, 0
    addi.d          a3, a3, 16
    sub.d           a2, a4, a3
    andi            t0, a2, 0x7f

    beq             t0, a2, L(long_end)
    move            a2, t0
    sub.d           t0, a4, t0

L(loop_128):
    vst             vr0, a3, 0

    vst             vr0, a3, 16
    vst             vr0, a3, 32
    vst             vr0, a3, 48
    vst             vr0, a3, 64


    vst             vr0, a3, 80
    vst             vr0, a3, 96
    vst             vr0, a3, 112
    addi.d          a3, a3, 128

    bne             a3, t0, L(loop_128)
L(long_end):
    bltu            a2, t3, L(end_less_64)
    addi.d          a2, a2, -64
    vst             vr0, a3, 0

    vst             vr0, a3, 16
    vst             vr0, a3, 32
    vst             vr0, a3, 48
    addi.d          a3, a3, 64

L(end_less_64):
    bltu            a2, t2, L(end_less_32)
    addi.d          a2, a2, -32
    vst             vr0, a3, 0
    vst             vr0, a3, 16

    addi.d          a3, a3, 32
L(end_less_32):
    bltu            a2, t1, L(end_less_16)
    vst             vr0, a3, 0

L(end_less_16):
    vst             vr0, a4, -16
    jr              ra
END(MEMSET)

libc_hidden_builtin_def (MEMSET)
#endif