about summary refs log tree commit diff
path: root/sysdeps/loongarch/lp64/multiarch/memset-lasx.S
blob: 5be1a5afeb8946cd6728393244f78a11a2504b82 (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
136
137
138
139
140
141
142
/* Optimized memset implementation using LoongArch LASX instructions.
   Copyright (C) 2023-2024 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_lasx

LEAF(MEMSET, 6)
    li.d            t1, 32
    move            a3, a0
    xvreplgr2vr.b   xr0, a1
    add.d           a4, a0, a2

    bgeu            t1, a2, L(less_32bytes)
    li.d            t3, 128
    li.d            t2, 64
    blt             t3, a2, L(long_bytes)

L(less_128bytes):
    bgeu            t2, a2, L(less_64bytes)
    xvst            xr0, a3, 0
    xvst            xr0, a3, 32
    xvst            xr0, a4, -32

    xvst            xr0, a4, -64
    jr              ra
L(less_64bytes):
    xvst            xr0, a3, 0
    xvst            xr0, a4, -32


    jr              ra
L(less_32bytes):
    srli.d          t0, a2, 4
    beqz            t0, L(less_16bytes)
    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)
    st.b            a1, a3, 0
L(less_1bytes):
    jr              ra

L(long_bytes):
    xvst            xr0, a3, 0
    bstrins.d       a3, zero, 4, 0
    addi.d          a3, a3, 32
    sub.d           a2, a4, a3

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


L(loop_256):
    xvst            xr0, a3, 0
    xvst            xr0, a3, 32
    xvst            xr0, a3, 64
    xvst            xr0, a3, 96

    xvst            xr0, a3, 128
    xvst            xr0, a3, 160
    xvst            xr0, a3, 192
    xvst            xr0, a3, 224

    addi.d          a3, a3, 256
    bne             a3, t0, L(loop_256)
L(long_end):
    bltu            a2, t3, L(end_less_128)
    addi.d          a2, a2, -128

    xvst            xr0, a3, 0
    xvst            xr0, a3, 32
    xvst            xr0, a3, 64
    xvst            xr0, a3, 96


    addi.d          a3, a3, 128
L(end_less_128):
    bltu            a2, t2, L(end_less_64)
    addi.d          a2, a2, -64
    xvst            xr0, a3, 0

    xvst            xr0, a3, 32
    addi.d          a3, a3, 64
L(end_less_64):
    bltu            a2, t1, L(end_less_32)
    xvst            xr0, a3, 0

L(end_less_32):
    xvst            xr0, a4, -32
    jr              ra
END(MEMSET)

libc_hidden_builtin_def (MEMSET)
#endif