1/* 2 * Copyright (C) 2016-2017 Andes Technology, Inc. 3 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. 4 */ 5 6/* Copyright (C) 1998, 2003 Free Software Foundation, Inc. 7 * Contributed by Philip Blundell <philb@gnu.org> 8 * 9 * The GNU C Library is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Lesser General Public 11 * License as published by the Free Software Foundation; either 12 * version 2.1 of the License, or (at your option) any later version. 13 * 14 * The GNU C Library is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with the GNU C Library; if not, write to the Free 21 * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 22 * 02111-1307 USA. 23 */ 24 25#include <features.h> 26#include <sysdep.h> 27!========================================================== 28! void *memset(void *dst, int val, int len); 29! 30! dst: $r0 31! val: $r1 32! len: $r2 33! ret: $r0 - pointer to the memory area dst. 34!========================================================== 35.weak memset 36ENTRY(memset) 37 move $r5, $r0 ! Return value 38 beqz $r2, .Lend_memset ! Exit when len = 0 39 srli $r3, $r2, 2 ! r3 is how many words to copy 40 andi $r2, $r2, 3 ! How many bytes are less than a word 41 beqz $r3, .Lbyte_set ! When n is less than a word 42 43 ! set r1 from to abababab 44 andi $r1, $r1, 0x00ff ! r1 = 000000ab 45 slli $r4, $r1, 8 ! r4 = 0000ab00 46 or $r1, $r1, $r4 ! r1 = 0000abab 47 slli $r4, $r1, 16 ! r4 = abab0000 48 or $r1, $r1, $r4 ! r1 = abababab 49 50.Lword_set: 51 addi $r3, $r3, -1 ! How many words left to copy 52 smw.bim $r1, [$r5], $r1 ! Copy the word to det 53 bnez $r3, .Lword_set ! Still words to set, continue looping 54 beqz $r2, .Lend_memset ! No left byte to set 55 56.Lbyte_set: 57 ! Less than 4 bytes left to set 58 addi $r2, $r2, -1 ! Decrease len by 1 59 sbi.p $r1, [$r5], 1 ! Set data of the next byte to r1 60 bnez $r2, .Lbyte_set ! Still bytes left to set 61 62.Lend_memset: 63 ret 64 65END(memset) 66libc_hidden_def(memset) 67