1 /* a-memset.s -- memset, optimised for fido asm
3 * Copyright (c) 2007 mocom software GmbH & Co KG)
5 * The authors hereby grant permission to use, copy, modify, distribute,
6 * and license this software and its documentation for any purpose, provided
7 * that existing copyright notices are retained in all copies and that this
8 * notice is included verbatim in any distributions. No written agreement,
9 * license, or royalty fee is required for any of the authorized uses.
10 * Modifications to this software may be copyrighted by their authors
11 * and need not follow the licensing terms described here, provided that
12 * the new terms are clearly indicated on the first page of each file where
22 .type SYM(memset), @function
27 | - no argument testing (the original memcpy from the GNU lib does
29 | - make sure the destination pointer (the write pointer) is long word
30 | aligned. This is the best you can do, because writing to unaligned
31 | addresses can be the most costfull thing one could do.
32 | - we fill long word wise if possible
37 | - distribution of byte value improved - in cases someone gives
39 | - residue byte transfer was not working
44 move.l 4(sp),a0 | dest ptr
45 move.l 8(sp),d0 | value
46 move.l 12(sp),d1 | len
48 blo .Lbset | below, byte fills
50 move.l d2,-(sp) | need a register
51 move.b d0,d2 | distribute low byte to all byte in word
58 move.l a0,d2 | copy of src
59 neg.l d2 | 1 2 3 ==> 3 2 1
63 sub.l d2,d1 | fix length
64 lsr.l #1,d2 | word align needed?
66 move.b d0,(a0)+ | fill byte
68 lsr.l #1,d2 | long align needed?
70 move.w d0,(a0)+ | fill word
72 move.l d1,d2 | number of long transfers (at least 3)
77 move.l d0,(a0)+ | fill long words
79 #if !defined (__mcoldfire__)
80 dbra d2,1b | loop until done
86 and.l #3,d1 | residue byte transfers, fixed
87 move.l (sp)+,d2 | restore d2
91 move.b d0,(a0)+ | fill residue bytes
93 #if !defined (__mcoldfire__)
94 dbra d1,1b | loop until done
99 move.l 4(sp),d0 | return value