OpenCores
URL https://opencores.org/ocsvn/forwardcom/forwardcom/trunk

Subversion Repositories forwardcom

[/] [forwardcom/] [libraries/] [memset.as] - Blame information for rev 166

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 94 Agner
/*********************************  memset.as  ********************************
2
* Author:        Agner Fog
3
* date created:  2018-03-25
4
* Last modified: 2021-04-25
5
* Version:       1.11
6
* Project:       ForwardCom library libc.li
7
* Description:   memcpy and memmove functions. Copy memory block
8
* C declaration: void *memset(void *str, int8_t value, uint64_t n)
9
*
10
* Copyright 2018-2021 GNU General Public License http://www.gnu.org/licenses
11
*****************************************************************************/
12
 
13
public _memset: function, reguse = 0xF, 1
14
 
15
code section execute align = 4
16
 
17
// r0 = destination
18
// r1 = int8 value
19
// r2 = n
20
_memset function
21
 
22
// broadcast value into vector
23
int8 v0 = gp2vec(r1)
24
int8 v0 = broad(v0, r2) // broadcast value into vector of desired length or maximum length
25
 
26
if (uint64 r2 <= 8) {
27
   // small size. do it all at once
28
   int8 [r0, length = r2] = v0
29
   return
30
}
31
// point to end of vector
32
int64 r1 = r0 + r2
33
 
34
// align destination by 8 for efficiency
35
int8  r3 = -r0
36
int8+ r3 &= 7
37
if (int8+ r3 != 0) {
38
   int8  [r0, length = r3] = v0
39
   int64 r2 -= r3
40
}
41
// do the rest as vector loop
42
for (int8 v0 in [r1-r2]) {
43
   int8 [r1-r2, length = r2] = v0
44
}
45
// return str1 in r0 unchanged
46
return
47
_memset end
48
 
49
code end

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.