]>
Commit | Line | Data |
---|---|---|
358da97e HS |
1 | // picoChip ASM file |
2 | //.file "popcounthi2.S" | |
3 | // | |
4 | // Support for 16-bit population count. | |
5 | // | |
748086b7 | 6 | // Copyright (C) 2003, 2004, 2005, 2008, 2009 Free Software Foundation, Inc. |
358da97e HS |
7 | // Contributed by picoChip Designs Ltd. |
8 | // Maintained by Daniel Towner (daniel.towner@picochip.com) | |
9 | // | |
10 | // This file is free software; you can redistribute it and/or modify it | |
11 | // under the terms of the GNU General Public License as published by the | |
748086b7 | 12 | // Free Software Foundation; either version 3, or (at your option) any |
358da97e HS |
13 | // later version. |
14 | // | |
358da97e HS |
15 | // This file is distributed in the hope that it will be useful, but |
16 | // WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 | // General Public License for more details. | |
19 | // | |
748086b7 JJ |
20 | // Under Section 7 of GPL version 3, you are granted additional |
21 | // permissions described in the GCC Runtime Library Exception, version | |
22 | // 3.1, as published by the Free Software Foundation. | |
23 | // | |
24 | // You should have received a copy of the GNU General Public License and | |
25 | // a copy of the GCC Runtime Library Exception along with this program; | |
26 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
27 | // <http://www.gnu.org/licenses/>. | |
358da97e HS |
28 | |
29 | .section .text | |
30 | ||
31 | // The following code (taken from a newsgroup posting) was compiled, and then | |
32 | // hand assembled (a similar version is given in the Hacker's Delight | |
33 | // book, chapter 5). | |
34 | // | |
35 | // int | |
36 | // popcount (int value) | |
37 | // { | |
38 | // value = ((value & 0xAAAA) >> 1) + (value & 0x5555); | |
39 | // value = ((value & 0xCCCC) >> 2) + (value & 0x3333); | |
40 | // value = ((value & 0xF0F0) >> 4) + (value & 0x0F0F); | |
41 | // return ((value & 0xFF00) >> 8) + (value & 0x00FF); | |
42 | // } | |
43 | // | |
44 | // This assembly function is approx. 20x faster than a naive loop | |
45 | // implementation of the population count, but about 30% bigger | |
46 | // (45 bytes v. 34 bytes). | |
47 | ||
48 | .align 8 | |
49 | .global ___popcounthi2 | |
50 | ___popcounthi2: | |
51 | ||
52 | _picoMark_FUNCTION_BEGIN= | |
53 | ||
54 | // picoChip Function Prologue : &___popcounthi2 = 0 bytes | |
55 | ||
56 | AND.0 [LSR R0,1],21845,R0 \ AND.1 R0,21845,R5 | |
57 | ADD.0 R0,R5,R0 | |
58 | AND.0 [LSR R0,2],13107,R0 \ AND.1 R0,13107,R5 | |
59 | ADD.0 R0,R5,R0 \ COPY.1 1807,R2 | |
60 | AND.0 [LSR R0,4],R2,R0 \ AND.1 R0,3855,R5 | |
61 | ADD.0 R0,R5,R0 | |
62 | JR (R12) \ AND.0 R0, 255, R5 | |
63 | =-> ADD.0 [LSR R0,8],R5,R0 | |
64 | ||
65 | _picoMark_FUNCTION_END= | |
66 | // picoChip Function Epilogue : ___popcounthi2 | |
67 | //============================================================================ | |
68 | // All DWARF information between this marker, and the END OF DWARF | |
69 | // marker should be included in the source file. Search for | |
70 | // FUNCTION_STACK_SIZE_GOES_HERE and FUNCTION NAME GOES HERE, and | |
71 | // provide the relevent information. Add markers called | |
72 | // _picoMark_FUNCTION_BEGIN and _picoMark_FUNCTION_END around the | |
73 | // function in question. | |
74 | //============================================================================ | |
75 | ||
76 | //============================================================================ | |
77 | // Frame information. | |
78 | //============================================================================ | |
79 | ||
80 | .section .debug_frame | |
81 | _picoMark_DebugFrame= | |
82 | ||
83 | // Common CIE header. | |
84 | .unalignedInitLong _picoMark_CieEnd-_picoMark_CieBegin | |
85 | _picoMark_CieBegin= | |
86 | .unalignedInitLong 0xffffffff | |
87 | .initByte 0x1 // CIE Version | |
88 | .ascii 16#0# // CIE Augmentation | |
89 | .uleb128 0x1 // CIE Code Alignment Factor | |
90 | .sleb128 2 // CIE Data Alignment Factor | |
91 | .initByte 0xc // CIE RA Column | |
92 | .initByte 0xc // DW_CFA_def_cfa | |
93 | .uleb128 0xd | |
94 | .uleb128 0x0 | |
95 | .align 2 | |
96 | _picoMark_CieEnd= | |
97 | ||
98 | // FDE | |
99 | _picoMark_LSFDE0I900821033007563= | |
100 | .unalignedInitLong _picoMark_FdeEnd-_picoMark_FdeBegin | |
101 | _picoMark_FdeBegin= | |
102 | .unalignedInitLong _picoMark_DebugFrame // FDE CIE offset | |
103 | .unalignedInitWord _picoMark_FUNCTION_BEGIN // FDE initial location | |
104 | .unalignedInitWord _picoMark_FUNCTION_END-_picoMark_FUNCTION_BEGIN | |
105 | .initByte 0xe // DW_CFA_def_cfa_offset | |
106 | .uleb128 0x0 // <-- FUNCTION_STACK_SIZE_GOES_HERE | |
107 | .initByte 0x4 // DW_CFA_advance_loc4 | |
108 | .unalignedInitLong _picoMark_FUNCTION_END-_picoMark_FUNCTION_BEGIN | |
109 | .initByte 0xe // DW_CFA_def_cfa_offset | |
110 | .uleb128 0x0 | |
111 | .align 2 | |
112 | _picoMark_FdeEnd= | |
113 | ||
114 | //============================================================================ | |
115 | // Abbrevation information. | |
116 | //============================================================================ | |
117 | ||
118 | .section .debug_abbrev | |
119 | _picoMark_ABBREVIATIONS= | |
120 | ||
121 | .section .debug_abbrev | |
122 | .uleb128 0x1 // (abbrev code) | |
123 | .uleb128 0x11 // (TAG: DW_TAG_compile_unit) | |
124 | .initByte 0x1 // DW_children_yes | |
125 | .uleb128 0x10 // (DW_AT_stmt_list) | |
126 | .uleb128 0x6 // (DW_FORM_data4) | |
127 | .uleb128 0x12 // (DW_AT_high_pc) | |
128 | .uleb128 0x1 // (DW_FORM_addr) | |
129 | .uleb128 0x11 // (DW_AT_low_pc) | |
130 | .uleb128 0x1 // (DW_FORM_addr) | |
131 | .uleb128 0x25 // (DW_AT_producer) | |
132 | .uleb128 0x8 // (DW_FORM_string) | |
133 | .uleb128 0x13 // (DW_AT_language) | |
134 | .uleb128 0x5 // (DW_FORM_data2) | |
135 | .uleb128 0x3 // (DW_AT_name) | |
136 | .uleb128 0x8 // (DW_FORM_string) | |
137 | .initByte 0x0 | |
138 | .initByte 0x0 | |
139 | ||
140 | .uleb128 0x2 ;# (abbrev code) | |
141 | .uleb128 0x2e ;# (TAG: DW_TAG_subprogram) | |
142 | .initByte 0x0 ;# DW_children_no | |
143 | .uleb128 0x3 ;# (DW_AT_name) | |
144 | .uleb128 0x8 ;# (DW_FORM_string) | |
145 | .uleb128 0x11 ;# (DW_AT_low_pc) | |
146 | .uleb128 0x1 ;# (DW_FORM_addr) | |
147 | .uleb128 0x12 ;# (DW_AT_high_pc) | |
148 | .uleb128 0x1 ;# (DW_FORM_addr) | |
149 | .initByte 0x0 | |
150 | .initByte 0x0 | |
151 | ||
152 | .initByte 0x0 | |
153 | ||
154 | //============================================================================ | |
155 | // Line information. DwarfLib requires this to be present, but it can | |
156 | // be empty. | |
157 | //============================================================================ | |
158 | ||
159 | .section .debug_line | |
160 | _picoMark_LINES= | |
161 | ||
162 | //============================================================================ | |
163 | // Debug Information | |
164 | //============================================================================ | |
165 | .section .debug_info | |
166 | ||
167 | //Fixed header. | |
168 | .unalignedInitLong _picoMark_DEBUG_INFO_END-_picoMark_DEBUG_INFO_BEGIN | |
169 | _picoMark_DEBUG_INFO_BEGIN= | |
170 | .unalignedInitWord 0x2 | |
171 | .unalignedInitLong _picoMark_ABBREVIATIONS | |
172 | .initByte 0x2 | |
173 | ||
174 | // Compile unit information. | |
175 | .uleb128 0x1 // (DIE 0xb) DW_TAG_compile_unit) | |
176 | .unalignedInitLong _picoMark_LINES | |
177 | .unalignedInitWord _picoMark_FUNCTION_END | |
178 | .unalignedInitWord _picoMark_FUNCTION_BEGIN | |
179 | // Producer is `picoChip' | |
180 | .ascii 16#70# 16#69# 16#63# 16#6f# 16#43# 16#68# 16#69# 16#70# 16#00# | |
181 | .unalignedInitWord 0xcafe // ASM language | |
182 | .ascii 16#0# // Name. DwarfLib expects this to be present. | |
183 | ||
184 | .uleb128 0x2 ;# (DIE DW_TAG_subprogram) | |
185 | ||
186 | // FUNCTION NAME GOES HERE. Use `echo name | od -t x1' to get the hex. Each hex | |
187 | // digit is specified using the format 16#XX# | |
188 | .ascii 16#5f# 16#5f# 16#70# 16#6f# 16#70# 16#63# 16#6f# 16#75# 16#6e# 16#74# 16#68# 16#69# 16#32# 16#0# // Function name `__popcounthi2' | |
189 | .unalignedInitWord _picoMark_FUNCTION_BEGIN // DW_AT_low_pc | |
190 | .unalignedInitWord _picoMark_FUNCTION_END // DW_AT_high_pc | |
191 | ||
192 | .initByte 0x0 // end of compile unit children. | |
193 | ||
194 | _picoMark_DEBUG_INFO_END= | |
195 | ||
196 | //============================================================================ | |
197 | // END OF DWARF | |
198 | //============================================================================ | |
199 | ||
200 | .section .endFile | |
201 | // End of picoChip ASM file |