4 * Hand-optimized assembler version of memset for OpenRISC.
5 * Algorithm inspired by several other arch-specific memset routines
8 * Copyright (C) 2015 Olof Kindgren <olof.kindgren@gmail.com>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
17 .type memset, @function
23 * r13, r15, r17, r19 used as temp regs
30 /* Truncate c to char */
33 /* Skip word extension if c is 0 */
36 /* Check for at least two whole words (8 bytes) */
39 /* Extend char c to 32-bit word cccc in r13 */
40 l.slli r15, r13, 16 // r13 = 000c, r15 = 0c00
41 l.or r13, r13, r15 // r13 = 0c0c, r15 = 0c00
42 l.slli r15, r13, 8 // r13 = 0c0c, r15 = c0c0
43 l.or r13, r13, r15 // r13 = cccc, r15 = c0c0
45 1: l.addi r19, r3, 0 // Set r19 = src
46 /* Jump to byte copy loop if less than two words */
48 l.or r17, r5, r0 // Set r17 = n
50 /* Mask out two LSBs to check alignment */
53 /* lsb == 00, jump to word copy loop */
56 l.addi r19, r3, 0 // Set r19 = src
58 /* lsb == 01,10 or 11 */
59 l.sb 0(r3), r13 // *src = c
60 l.addi r17, r17, -1 // Decrease n
64 l.addi r19, r3, 1 // src += 1
67 l.sb 1(r3), r13 // *(src+1) = c
68 l.addi r17, r17, -1 // Decrease n
72 l.addi r19, r3, 2 // src += 2
75 l.sb 2(r3), r13 // *(src+2) = c
76 l.addi r17, r17, -1 // Decrease n
77 l.addi r19, r3, 3 // src += 3
80 2: l.sw 0(r19), r13 // *src = cccc
81 l.addi r17, r17, -4 // Decrease n
84 l.addi r19, r19, 4 // Increase src
86 /* When n > 0, copy the remaining bytes, otherwise jump to exit */
91 3: l.addi r17, r17, -1 // Decrease n
92 l.sb 0(r19), r13 // *src = cccc
95 l.addi r19, r19, 1 // Increase src