Merged revisions 143552,143554,143557,143560,143562,143564-143567,143570-143573,14357...
[official-gcc.git] / gcc / config / picochip / libgccExtras / popcounthi2.asm
blobbfafd0cb00e42a17b7d661b0838fcc3a26009a1d
1 // picoChip ASM file
2 //.file "popcounthi2.S"
3 //
4 // Support for 16-bit population count.
5 //
6 // Copyright (C) 2003, 2004, 2005, 2008 Free Software Foundation, Inc.
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
12 // Free Software Foundation; either version 2, or (at your option) any
13 // later version.
15 // In addition to the permissions in the GNU General Public License, the
16 // Free Software Foundation gives you unlimited permission to link the
17 // compiled version of this file into combinations with other programs,
18 // and to distribute those combinations without any restriction coming
19 // from the use of this file. (The General Public License restrictions
20 // do apply in other respects; for example, they cover modification of
21 // the file, and distribution when not linked into a combine
22 // executable.)
24 // This file is distributed in the hope that it will be useful, but
25 // WITHOUT ANY WARRANTY; without even the implied warranty of
26 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 // General Public License for more details.
29 // You should have received a copy of the GNU General Public License
30 // along with this program; see the file COPYING. If not, write to
31 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
32 // Boston, MA 02110-1301, USA.
34 .section .text
36 // The following code (taken from a newsgroup posting) was compiled, and then
37 // hand assembled (a similar version is given in the Hacker's Delight
38 // book, chapter 5).
40 // int
41 // popcount (int value)
42 // {
43 // value = ((value & 0xAAAA) >> 1) + (value & 0x5555);
44 // value = ((value & 0xCCCC) >> 2) + (value & 0x3333);
45 // value = ((value & 0xF0F0) >> 4) + (value & 0x0F0F);
46 // return ((value & 0xFF00) >> 8) + (value & 0x00FF);
47 // }
49 // This assembly function is approx. 20x faster than a naive loop
50 // implementation of the population count, but about 30% bigger
51 // (45 bytes v. 34 bytes).
53 .align 8
54 .global ___popcounthi2
55 ___popcounthi2:
57 _picoMark_FUNCTION_BEGIN=
59 // picoChip Function Prologue : &___popcounthi2 = 0 bytes
61 AND.0 [LSR R0,1],21845,R0 \ AND.1 R0,21845,R5
62 ADD.0 R0,R5,R0
63 AND.0 [LSR R0,2],13107,R0 \ AND.1 R0,13107,R5
64 ADD.0 R0,R5,R0 \ COPY.1 1807,R2
65 AND.0 [LSR R0,4],R2,R0 \ AND.1 R0,3855,R5
66 ADD.0 R0,R5,R0
67 JR (R12) \ AND.0 R0, 255, R5
68 =-> ADD.0 [LSR R0,8],R5,R0
70 _picoMark_FUNCTION_END=
71 // picoChip Function Epilogue : ___popcounthi2
72 //============================================================================
73 // All DWARF information between this marker, and the END OF DWARF
74 // marker should be included in the source file. Search for
75 // FUNCTION_STACK_SIZE_GOES_HERE and FUNCTION NAME GOES HERE, and
76 // provide the relevent information. Add markers called
77 // _picoMark_FUNCTION_BEGIN and _picoMark_FUNCTION_END around the
78 // function in question.
79 //============================================================================
81 //============================================================================
82 // Frame information.
83 //============================================================================
85 .section .debug_frame
86 _picoMark_DebugFrame=
88 // Common CIE header.
89 .unalignedInitLong _picoMark_CieEnd-_picoMark_CieBegin
90 _picoMark_CieBegin=
91 .unalignedInitLong 0xffffffff
92 .initByte 0x1 // CIE Version
93 .ascii 16#0# // CIE Augmentation
94 .uleb128 0x1 // CIE Code Alignment Factor
95 .sleb128 2 // CIE Data Alignment Factor
96 .initByte 0xc // CIE RA Column
97 .initByte 0xc // DW_CFA_def_cfa
98 .uleb128 0xd
99 .uleb128 0x0
100 .align 2
101 _picoMark_CieEnd=
103 // FDE
104 _picoMark_LSFDE0I900821033007563=
105 .unalignedInitLong _picoMark_FdeEnd-_picoMark_FdeBegin
106 _picoMark_FdeBegin=
107 .unalignedInitLong _picoMark_DebugFrame // FDE CIE offset
108 .unalignedInitWord _picoMark_FUNCTION_BEGIN // FDE initial location
109 .unalignedInitWord _picoMark_FUNCTION_END-_picoMark_FUNCTION_BEGIN
110 .initByte 0xe // DW_CFA_def_cfa_offset
111 .uleb128 0x0 // <-- FUNCTION_STACK_SIZE_GOES_HERE
112 .initByte 0x4 // DW_CFA_advance_loc4
113 .unalignedInitLong _picoMark_FUNCTION_END-_picoMark_FUNCTION_BEGIN
114 .initByte 0xe // DW_CFA_def_cfa_offset
115 .uleb128 0x0
116 .align 2
117 _picoMark_FdeEnd=
119 //============================================================================
120 // Abbrevation information.
121 //============================================================================
123 .section .debug_abbrev
124 _picoMark_ABBREVIATIONS=
126 .section .debug_abbrev
127 .uleb128 0x1 // (abbrev code)
128 .uleb128 0x11 // (TAG: DW_TAG_compile_unit)
129 .initByte 0x1 // DW_children_yes
130 .uleb128 0x10 // (DW_AT_stmt_list)
131 .uleb128 0x6 // (DW_FORM_data4)
132 .uleb128 0x12 // (DW_AT_high_pc)
133 .uleb128 0x1 // (DW_FORM_addr)
134 .uleb128 0x11 // (DW_AT_low_pc)
135 .uleb128 0x1 // (DW_FORM_addr)
136 .uleb128 0x25 // (DW_AT_producer)
137 .uleb128 0x8 // (DW_FORM_string)
138 .uleb128 0x13 // (DW_AT_language)
139 .uleb128 0x5 // (DW_FORM_data2)
140 .uleb128 0x3 // (DW_AT_name)
141 .uleb128 0x8 // (DW_FORM_string)
142 .initByte 0x0
143 .initByte 0x0
145 .uleb128 0x2 ;# (abbrev code)
146 .uleb128 0x2e ;# (TAG: DW_TAG_subprogram)
147 .initByte 0x0 ;# DW_children_no
148 .uleb128 0x3 ;# (DW_AT_name)
149 .uleb128 0x8 ;# (DW_FORM_string)
150 .uleb128 0x11 ;# (DW_AT_low_pc)
151 .uleb128 0x1 ;# (DW_FORM_addr)
152 .uleb128 0x12 ;# (DW_AT_high_pc)
153 .uleb128 0x1 ;# (DW_FORM_addr)
154 .initByte 0x0
155 .initByte 0x0
157 .initByte 0x0
159 //============================================================================
160 // Line information. DwarfLib requires this to be present, but it can
161 // be empty.
162 //============================================================================
164 .section .debug_line
165 _picoMark_LINES=
167 //============================================================================
168 // Debug Information
169 //============================================================================
170 .section .debug_info
172 //Fixed header.
173 .unalignedInitLong _picoMark_DEBUG_INFO_END-_picoMark_DEBUG_INFO_BEGIN
174 _picoMark_DEBUG_INFO_BEGIN=
175 .unalignedInitWord 0x2
176 .unalignedInitLong _picoMark_ABBREVIATIONS
177 .initByte 0x2
179 // Compile unit information.
180 .uleb128 0x1 // (DIE 0xb) DW_TAG_compile_unit)
181 .unalignedInitLong _picoMark_LINES
182 .unalignedInitWord _picoMark_FUNCTION_END
183 .unalignedInitWord _picoMark_FUNCTION_BEGIN
184 // Producer is `picoChip'
185 .ascii 16#70# 16#69# 16#63# 16#6f# 16#43# 16#68# 16#69# 16#70# 16#00#
186 .unalignedInitWord 0xcafe // ASM language
187 .ascii 16#0# // Name. DwarfLib expects this to be present.
189 .uleb128 0x2 ;# (DIE DW_TAG_subprogram)
191 // FUNCTION NAME GOES HERE. Use `echo name | od -t x1' to get the hex. Each hex
192 // digit is specified using the format 16#XX#
193 .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'
194 .unalignedInitWord _picoMark_FUNCTION_BEGIN // DW_AT_low_pc
195 .unalignedInitWord _picoMark_FUNCTION_END // DW_AT_high_pc
197 .initByte 0x0 // end of compile unit children.
199 _picoMark_DEBUG_INFO_END=
201 //============================================================================
202 // END OF DWARF
203 //============================================================================
205 .section .endFile
206 // End of picoChip ASM file