Merged revisions 143552,143554,143557,143560,143562,143564-143567,143570-143573,14357...
[official-gcc.git] / gcc / config / picochip / libgccExtras / divmod15.asm
blobdd5d63240a9ba3b438a4190d50c6a258b8052095
1 // picoChip ASM file
2 //
3 // Support for 16-bit unsigned division/modulus.
4 //
5 // Copyright (C) 2003, 2004, 2005, 2008 Free Software Foundation, Inc.
6 // Contributed by picoChip Designs Ltd.
7 // Maintained by Daniel Towner (daniel.towner@picochip.com)
8 //
9 // This file is free software; you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 2, or (at your option) any
12 // later version.
14 // In addition to the permissions in the GNU General Public License, the
15 // Free Software Foundation gives you unlimited permission to link the
16 // compiled version of this file into combinations with other programs,
17 // and to distribute those combinations without any restriction coming
18 // from the use of this file. (The General Public License restrictions
19 // do apply in other respects; for example, they cover modification of
20 // the file, and distribution when not linked into a combine
21 // executable.)
23 // This file is distributed in the hope that it will be useful, but
24 // WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 // General Public License for more details.
28 // You should have received a copy of the GNU General Public License
29 // along with this program; see the file COPYING. If not, write to
30 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
31 // Boston, MA 02110-1301, USA.
33 .section .text
35 .global __divmod15
36 __divmod15:
37 _picoMark_FUNCTION_BEGIN=
39 // picoChip Function Prologue : &__divmod15 = 0 bytes
41 __divmod15:
43 // The picoChip instruction set has a divstep instruction which
44 // is used to perform one iteration of a binary division algorithm.
45 // The instruction allows 16-bit signed division to be implemented.
46 // It does not directly allow 16-bit unsigned division to be
47 // implemented. Thus, this function pulls out the common division
48 // iteration for 15-bits unsigned, and then special wrappers
49 // provide the logic to change this into a 16-bit signed or
50 // unsigned division, as appropriate. This allows the two
51 // versions of division to share a common implementation, reducing
52 // code size when the two are used together. It also reduces
53 // the maintenance overhead.
55 // Input:
56 // r0 - dividend
57 // r1 - divisor
58 // Output:
59 // r0 - quotient
60 // r1 - remainder
61 // R5 is unused
63 // Check for special cases. The emphasis is on detecting these as
64 // quickly as possible, so that the main division can be started. If
65 // the user requests division by one, division by self, and so on
66 // then they will just have to accept that this won't be particularly
67 // quick (relatively), whereas a real division (e.g., dividing a
68 // large value by a small value) will run as fast as possible
69 // (i.e., special case detection should not slow down the common case)
71 // Special cases to consider:
73 // Division by zero.
74 // Division of zero.
75 // Inputs are equal
76 // Divisor is bigger than dividend
77 // Division by power of two (can be shifted instead).
78 // Division by 1 (special case of power of two division)
80 // Division/modulus by zero is undefined (ISO C:6.5.5), so
81 // don't bother handling this special case.
83 // The special cases of division by a power of 2 are ignored, since
84 // they cause the general case to slow down. Omitting these
85 // special cases also reduces code size considerably.
87 // Handle divisor >= dividend separately. Note that this also handles
88 // the case where the dividend is zero. Note that the flags must be
89 // preserved, since they are also used at the branch destination.
90 sub.0 r1,r0,r15
91 sbc r0,r2 \ bge divisorGeDividend
92 =-> sbc r1,r4
94 // Compute the shift count. The amount by which the divisor
95 // must be shifted left to be aligned with the dividend.
96 sub.0 r4,r2,r3
98 // Align the divisor to the dividend. Execute a divstep (since at
99 // least one will always be executed). Skip the remaining loop
100 // if the shift count is zero.
101 lsl.0 r1,r3,r1 \ beq skipLoop
102 =-> divstep r0,r1 \ add.1 r3,1,r2
104 // Execute the divstep loop until temp is 0. This assumes that the
105 // loop count is at least one.
106 sub.0 r3,1,r4
107 divLoop:
108 divstep r0,r1 \ bne divLoop
109 =-> sub.0 r4,1,r4
111 skipLoop:
113 // The top bits of the result are the remainder. The bottom
114 // bits are the quotient.
115 lsr.0 r0,r2,r1 \ sub.1 16,r2,r4
116 jr (lr ) \ lsl.0 r0,r4,r0
117 =-> lsr.0 r0,r4,r0
119 // Special case.
121 divisorGeDividend:
122 // The divisor is greater than or equal to the dividend. The flags
123 // indicate which of these alternatives it is. The COPYNE can be used
124 // to set the result appropriately, without introducing any more
125 // branches.
126 copy.0 r0,r1 \ copy.1 0,r0
127 jr (lr) \ copyeq r0,r1
128 =-> copyeq 1,r0
130 _picoMark_FUNCTION_END=
131 // picoChip Function Epilogue : __divmod15
134 //============================================================================
135 // All DWARF information between this marker, and the END OF DWARF
136 // marker should be included in the source file. Search for
137 // FUNCTION_STACK_SIZE_GOES_HERE and FUNCTION NAME GOES HERE, and
138 // provide the relevent information. Add markers called
139 // _picoMark_FUNCTION_BEGIN and _picoMark_FUNCTION_END around the
140 // function in question.
141 //============================================================================
143 //============================================================================
144 // Frame information.
145 //============================================================================
147 .section .debug_frame
148 _picoMark_DebugFrame=
150 // Common CIE header.
151 .unalignedInitLong _picoMark_CieEnd-_picoMark_CieBegin
152 _picoMark_CieBegin=
153 .unalignedInitLong 0xffffffff
154 .initByte 0x1 // CIE Version
155 .ascii 16#0# // CIE Augmentation
156 .uleb128 0x1 // CIE Code Alignment Factor
157 .sleb128 2 // CIE Data Alignment Factor
158 .initByte 0xc // CIE RA Column
159 .initByte 0xc // DW_CFA_def_cfa
160 .uleb128 0xd
161 .uleb128 0x0
162 .align 2
163 _picoMark_CieEnd=
165 // FDE
166 _picoMark_LSFDE0I900821033007563=
167 .unalignedInitLong _picoMark_FdeEnd-_picoMark_FdeBegin
168 _picoMark_FdeBegin=
169 .unalignedInitLong _picoMark_DebugFrame // FDE CIE offset
170 .unalignedInitWord _picoMark_FUNCTION_BEGIN // FDE initial location
171 .unalignedInitWord _picoMark_FUNCTION_END-_picoMark_FUNCTION_BEGIN
172 .initByte 0xe // DW_CFA_def_cfa_offset
173 .uleb128 0x0 // <-- FUNCTION_STACK_SIZE_GOES_HERE
174 .initByte 0x4 // DW_CFA_advance_loc4
175 .unalignedInitLong _picoMark_FUNCTION_END-_picoMark_FUNCTION_BEGIN
176 .initByte 0xe // DW_CFA_def_cfa_offset
177 .uleb128 0x0
178 .align 2
179 _picoMark_FdeEnd=
181 //============================================================================
182 // Abbrevation information.
183 //============================================================================
185 .section .debug_abbrev
186 _picoMark_ABBREVIATIONS=
188 .section .debug_abbrev
189 .uleb128 0x1 // (abbrev code)
190 .uleb128 0x11 // (TAG: DW_TAG_compile_unit)
191 .initByte 0x1 // DW_children_yes
192 .uleb128 0x10 // (DW_AT_stmt_list)
193 .uleb128 0x6 // (DW_FORM_data4)
194 .uleb128 0x12 // (DW_AT_high_pc)
195 .uleb128 0x1 // (DW_FORM_addr)
196 .uleb128 0x11 // (DW_AT_low_pc)
197 .uleb128 0x1 // (DW_FORM_addr)
198 .uleb128 0x25 // (DW_AT_producer)
199 .uleb128 0x8 // (DW_FORM_string)
200 .uleb128 0x13 // (DW_AT_language)
201 .uleb128 0x5 // (DW_FORM_data2)
202 .uleb128 0x3 // (DW_AT_name)
203 .uleb128 0x8 // (DW_FORM_string)
204 .initByte 0x0
205 .initByte 0x0
207 .uleb128 0x2 ;# (abbrev code)
208 .uleb128 0x2e ;# (TAG: DW_TAG_subprogram)
209 .initByte 0x0 ;# DW_children_no
210 .uleb128 0x3 ;# (DW_AT_name)
211 .uleb128 0x8 ;# (DW_FORM_string)
212 .uleb128 0x11 ;# (DW_AT_low_pc)
213 .uleb128 0x1 ;# (DW_FORM_addr)
214 .uleb128 0x12 ;# (DW_AT_high_pc)
215 .uleb128 0x1 ;# (DW_FORM_addr)
216 .initByte 0x0
217 .initByte 0x0
219 .initByte 0x0
221 //============================================================================
222 // Line information. DwarfLib requires this to be present, but it can
223 // be empty.
224 //============================================================================
226 .section .debug_line
227 _picoMark_LINES=
229 //============================================================================
230 // Debug Information
231 //============================================================================
232 .section .debug_info
234 //Fixed header.
235 .unalignedInitLong _picoMark_DEBUG_INFO_END-_picoMark_DEBUG_INFO_BEGIN
236 _picoMark_DEBUG_INFO_BEGIN=
237 .unalignedInitWord 0x2
238 .unalignedInitLong _picoMark_ABBREVIATIONS
239 .initByte 0x2
241 // Compile unit information.
242 .uleb128 0x1 // (DIE 0xb) DW_TAG_compile_unit)
243 .unalignedInitLong _picoMark_LINES
244 .unalignedInitWord _picoMark_FUNCTION_END
245 .unalignedInitWord _picoMark_FUNCTION_BEGIN
246 // Producer is `picoChip'
247 .ascii 16#70# 16#69# 16#63# 16#6f# 16#43# 16#68# 16#69# 16#70# 16#00#
248 .unalignedInitWord 0xcafe // ASM language
249 .ascii 16#0# // Name. DwarfLib expects this to be present.
251 .uleb128 0x2 ;# (DIE DW_TAG_subprogram)
253 // FUNCTION NAME GOES HERE. Use `echo name | od -t x1' to get the hex. Each hex
254 // digit is specified using the format 16#XX#
255 .ascii 16#5f# 16#64# 16#69# 16#76# 16#6d# 16#6f# 16#64# 16#31# 16#35# 16#0# // Function name `_divmod15'
256 .unalignedInitWord _picoMark_FUNCTION_BEGIN // DW_AT_low_pc
257 .unalignedInitWord _picoMark_FUNCTION_END // DW_AT_high_pc
259 .initByte 0x0 // end of compile unit children.
261 _picoMark_DEBUG_INFO_END=
263 //============================================================================
264 // END OF DWARF
265 //============================================================================
267 .section .endFile
268 // End of picoChip ASM file