1 /*
 2  *  This program is free software; you can redistribute it and/or modify
 3  *  it under the terms of the GNU General Public License as published by
 4  *  the Free Software Foundation; either version 2 of the License, or
 5  *  (at your option) any later version.
 6  *
 7  *  This program is distributed in the hope that it will be useful,
 8  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *  GNU Library General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  * Copyright (C) 2005,2006 Ralf Huesing <ralf@stormbind.net>
17  *
18  */
19 
20 #include "rh_memory.h"
21 
22 void rh_bzero (register void *s, register size_t n)
23 {
24         switch (n) {
25         case 0: return;
26         case 1: rh_memzero1(s); return;
27         case 2: rh_memzero2(s); return;
28         case 3: rh_memzero3(s); return;
29         case 4: rh_memzero4(s); return;
30         case 5: rh_memzero5(s); return;
31         case 6: rh_memzero6(s); return;
32         case 7: rh_memzero7(s); return;
33         case 8: rh_memzero8(s); return;
34         }
35 
36         /* align `s' on a WORD-boundary */
37         if (WORD_OFFSET(s)) {
38                 WORD_AT(s,0) = 0U;
39                 n -= WORD_SIZE - WORD_OFFSET(s);
40                 BYTE_INC(s, WORD_SIZE - WORD_OFFSET(s));
41         }
42         
43         switch ( (n/WORD_SIZE) % 8) {
44         case 7:
45                 n += WORD_SIZE * 1;
46                 WORD_INC(s,-1);
47                 goto do7;
48         case 6:
49                 n += WORD_SIZE * 2;
50                 WORD_INC(s,-2);
51                 goto do6;
52         case 5:
53                 n += WORD_SIZE * 3;
54                 WORD_INC(s,-3);
55                 goto do5;
56         case 4:
57                 n += WORD_SIZE * 4;
58                 WORD_INC(s,-4);
59                 goto do4;
60         case 3:
61                 n += WORD_SIZE * 5;
62                 WORD_INC(s,-5);
63                 goto do3;
64         case 2:
65                 n += WORD_SIZE * 6;
66                 WORD_INC(s,-6);
67                 goto do2;
68         case 1:
69                 n += WORD_SIZE * 7;
70                 WORD_INC(s,-7);
71                 goto do1;
72         }
73         
74         do {
75                 WORD_AT(s,0) = 0U;
76 do7:            WORD_AT(s,1) = 0U;
77 do6:            WORD_AT(s,2) = 0U;
78 do5:            WORD_AT(s,3) = 0U;
79 do4:            WORD_AT(s,4) = 0U;
80 do3:            WORD_AT(s,5) = 0U;
81 do2:            WORD_AT(s,6) = 0U;
82 do1:            WORD_AT(s,7) = 0U;
83         
84                 WORD_INC(s,8);
85         
86         } while ( (n -= WORD_SIZE*8) > (WORD_SIZE*8)-1);
87 
88         if (n)
89                 WORD_AT(&BYTE_AT(s,-(WORD_SIZE-n)),0) = 0U;
90 }


syntax highlighted by Code2HTML, v. 0.9.1