/* Optimised simple memory fill1*2* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.3* Written by David Howells ([email protected])4*5* This program is free software; you can redistribute it and/or6* modify it under the terms of the GNU General Public Licence7* as published by the Free Software Foundation; either version8* 2 of the Licence, or (at your option) any later version.9*/10#include <asm/cache.h>1112.section .text13.balign L1_CACHE_BYTES1415###############################################################################16#17# void *memset(void *dst, int c, size_t n)18#19###############################################################################20.globl memset21.type memset,@function22memset:23movm [d2,d3],(sp)24mov d0,(12,sp)25mov d1,(16,sp)26mov (20,sp),d2 # count27mov d0,a0 # dst28mov d0,e3 # the return value2930cmp +0,d231beq memset_done # return if zero-length fill3233# see if the region parameters are four-byte aligned34or d0,d2,d335and +3,d336bne memset_1 # jump if not3738extbu d139mov_asl d1,d3,8,d140or_asl d1,d3,8,d141or_asl d1,d3,8,d142or d3,d14344# we want to transfer as much as we can in chunks of 32 bytes45cmp +31,d246bls memset_4_remainder # 4-byte aligned remainder4748add -32,d249mov +32,d35051memset_4_loop:52mov d1,(a0+)53mov d1,(a0+)54mov d1,(a0+)55mov d1,(a0+)56mov d1,(a0+)57mov d1,(a0+)58mov d1,(a0+)59mov d1,(a0+)6061sub d3,d262bcc memset_4_loop6364add d3,d265beq memset_4_no_remainder6667memset_4_remainder:68# cut 4-7 words down to 0-369cmp +16,d270bcs memset_4_three_or_fewer_words71mov d1,(a0+)72mov d1,(a0+)73mov d1,(a0+)74mov d1,(a0+)75add -16,d276beq memset_4_no_remainder7778# copy the remaining 1, 2 or 3 words79memset_4_three_or_fewer_words:80cmp +8,d281bcs memset_4_one_word82beq memset_4_two_words83mov d1,(a0+)84memset_4_two_words:85mov d1,(a0+)86memset_4_one_word:87mov d1,(a0+)8889memset_4_no_remainder:90# check we set the correct amount91# TODO: REMOVE CHECK92sub e3,a0,d293mov (20,sp),d194cmp d2,d195beq memset_done96break97break98break99100memset_done:101mov e3,a0102ret [d2,d3],8103104# handle misaligned copying105memset_1:106add -1,d2107mov +1,d3108setlb # setlb requires the next insns109# to occupy exactly 4 bytes110111sub d3,d2112movbu d1,(a0)113inc a0114lcc115116mov e3,a0117ret [d2,d3],8118119memset_end:120.size memset, memset_end-memset121122123