source: trunk/libs/newlib/src/newlib/libc/machine/riscv/memset.S @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.8 KB
Line 
1/* Copyright (c) 2017  SiFive Inc. All rights reserved.
2
3   This copyrighted material is made available to anyone wishing to use,
4   modify, copy, or redistribute it subject to the terms and conditions
5   of the FreeBSD License.   This program is distributed in the hope that
6   it will be useful, but WITHOUT ANY WARRANTY expressed or implied,
7   including the implied warranties of MERCHANTABILITY or FITNESS FOR
8   A PARTICULAR PURPOSE.  A copy of this license is available at
9   http://www.opensource.org/licenses.
10*/
11
12.text
13.global memset
14.type   memset, @function
15memset:
16  li t1, 15
17  move a4, a0
18  bleu a2, t1, .Ltiny
19  and a5, a4, 15
20  bnez a5, .Lmisaligned
21
22.Laligned:
23  bnez a1, .Lwordify
24
25.Lwordified:
26  and a3, a2, ~15
27  and a2, a2, 15
28  add a3, a3, a4
29
30#if __riscv_xlen == 64
311:sd a1, 0(a4)
32  sd a1, 8(a4)
33#else
341:sw a1, 0(a4)
35  sw a1, 4(a4)
36  sw a1, 8(a4)
37  sw a1, 12(a4)
38#endif
39  add a4, a4, 16
40  bltu a4, a3, 1b
41
42  bnez a2, .Ltiny
43  ret
44
45.Ltiny:
46  sub a3, t1, a2
47  sll a3, a3, 2
481:auipc t0, %pcrel_hi(.Ltable)
49  add a3, a3, t0
50.option push
51.option norvc
52.Ltable_misaligned:
53  jr a3, %pcrel_lo(1b)
54.Ltable:
55  sb a1,14(a4)
56  sb a1,13(a4)
57  sb a1,12(a4)
58  sb a1,11(a4)
59  sb a1,10(a4)
60  sb a1, 9(a4)
61  sb a1, 8(a4)
62  sb a1, 7(a4)
63  sb a1, 6(a4)
64  sb a1, 5(a4)
65  sb a1, 4(a4)
66  sb a1, 3(a4)
67  sb a1, 2(a4)
68  sb a1, 1(a4)
69  sb a1, 0(a4)
70.option pop
71  ret
72
73.Lwordify:
74  and a1, a1, 0xFF
75  sll a3, a1, 8
76  or  a1, a1, a3
77  sll a3, a1, 16
78  or  a1, a1, a3
79#if __riscv_xlen == 64
80  sll a3, a1, 32
81  or  a1, a1, a3
82#endif
83  j .Lwordified
84
85.Lmisaligned:
86  sll a3, a5, 2
871:auipc t0, %pcrel_hi(.Ltable_misaligned)
88  add a3, a3, t0
89  mv t0, ra
90  jalr a3, %pcrel_lo(1b)
91  mv ra, t0
92
93  add a5, a5, -16
94  sub a4, a4, a5
95  add a2, a2, a5
96  bleu a2, t1, .Ltiny
97  j .Laligned
98  .size memset, .-memset
Note: See TracBrowser for help on using the repository browser.