3 // Support for 16-bit unsigned division/modulus.
5 // Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
6 // Contributed by picoChip Designs Ltd.
7 // Maintained by Daniel Towner (daniel.towner@picochip.com)
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
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
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.
37 _picoMark_FUNCTION_BEGIN=
39 // picoChip Function Prologue : &__udivmodhi4 = 6 bytes
41 // 16-bit unsigned division. The divstep function is only capable of
42 // handling 15-bit division (plus a sign to give 16-bits). It is not
43 // capable of handling unsigned division directly. Instead, take
44 // advantage of the special property that
45 // ((divisor / 2) / dividend) * 2 will be almost good enough. The
46 // error in the result is only 0 or 1, and this can be easily
47 // tested and corrected. A full description of the algorithm can
48 // be found in `Hacker's Delight', by Henry Warren, page 146.
57 // Note that the lr, and original inputs are speculatively saved. They
58 // will only be restored if the 15-bit division function is called.
60 sub.0 r1,0,r15 \ stl r[0:1],(fp)-1
62 =-> sub.0 r0,r1,r2 \ stw lr,(fp)-3
64 // The divisor is >= 2^15.
67 // The dividend < divisor. The quotient is thus 0, and the
68 // remainder is the dividend.
69 copy.0 r0,r1 \ jr (lr)
73 // The dividend >= divisor. The quotient is thus 1, and the
74 // remainder can be computed directly by subtraction (i.e., the
75 // result of the comparison already performed to branch here).
76 jr (lr) \ copy.0 r2,r1
80 // The divisor is < 2^15.
82 // Divide the original dividend by 2, and call the 15-bit division.
83 // Note that the original dividend is stored in r5, which is
84 // known to be unused by the called function, so that
85 // a memory stall isn't introduced immediately after the
86 // function returns, to reload this value from memory.
88 jl (&__divmod15) \ copy.0 r0,r5 // fn_call &__divmod15
91 // Compute the new quotient and remainder by multiplying them by 2.
92 // The remainder will be 1 out, if the original dividend was odd.
93 and.0 r5,1,r5 \ ldl (fp)-1,r[2:3]
94 add.0 [lsl r1,1],r5,r1 \ lsl.1 r0,1,r0
96 // The error in the quotient is 0 or 1. The error can be determined
97 // by comparing the remainder to the original divisor. If the
98 // remainder is bigger, then an error of 1 has been introduced.
99 sub.0 r1,r3,r15 \ ldw (fp)-3,lr
102 add.0 r0,1,r0 \ sub.1 r1,r3,r1
106 _picoMark_FUNCTION_END=
107 // picoChip Function Epilogue : udivmodhi4
110 //============================================================================
111 // All DWARF information between this marker, and the END OF DWARF
112 // marker should be included in the source file. Search for
113 // FUNCTION_STACK_SIZE_GOES_HERE and FUNCTION NAME GOES HERE, and
114 // provide the relevent information. Add markers called
115 // _picoMark_FUNCTION_BEGIN and _picoMark_FUNCTION_END around the
116 // function in question.
117 //============================================================================
119 //============================================================================
120 // Frame information.
121 //============================================================================
123 .section .debug_frame
124 _picoMark_DebugFrame=
126 // Common CIE header.
127 .unalignedInitLong _picoMark_CieEnd-_picoMark_CieBegin
129 .unalignedInitLong 0xffffffff
130 .initByte 0x1 // CIE Version
131 .ascii 16#0# // CIE Augmentation
132 .uleb128 0x1 // CIE Code Alignment Factor
133 .sleb128 2 // CIE Data Alignment Factor
134 .initByte 0xc // CIE RA Column
135 .initByte 0xc // DW_CFA_def_cfa
142 _picoMark_LSFDE0I900821033007563=
143 .unalignedInitLong _picoMark_FdeEnd-_picoMark_FdeBegin
145 .unalignedInitLong _picoMark_DebugFrame // FDE CIE offset
146 .unalignedInitWord _picoMark_FUNCTION_BEGIN // FDE initial location
147 .unalignedInitWord _picoMark_FUNCTION_END-_picoMark_FUNCTION_BEGIN
148 .initByte 0xe // DW_CFA_def_cfa_offset
149 .uleb128 0x6 // <-- FUNCTION_STACK_SIZE_GOES_HERE
150 .initByte 0x4 // DW_CFA_advance_loc4
151 .unalignedInitLong _picoMark_FUNCTION_END-_picoMark_FUNCTION_BEGIN
152 .initByte 0xe // DW_CFA_def_cfa_offset
157 //============================================================================
158 // Abbrevation information.
159 //============================================================================
161 .section .debug_abbrev
162 _picoMark_ABBREVIATIONS=
164 .section .debug_abbrev
165 .uleb128 0x1 // (abbrev code)
166 .uleb128 0x11 // (TAG: DW_TAG_compile_unit)
167 .initByte 0x1 // DW_children_yes
168 .uleb128 0x10 // (DW_AT_stmt_list)
169 .uleb128 0x6 // (DW_FORM_data4)
170 .uleb128 0x12 // (DW_AT_high_pc)
171 .uleb128 0x1 // (DW_FORM_addr)
172 .uleb128 0x11 // (DW_AT_low_pc)
173 .uleb128 0x1 // (DW_FORM_addr)
174 .uleb128 0x25 // (DW_AT_producer)
175 .uleb128 0x8 // (DW_FORM_string)
176 .uleb128 0x13 // (DW_AT_language)
177 .uleb128 0x5 // (DW_FORM_data2)
178 .uleb128 0x3 // (DW_AT_name)
179 .uleb128 0x8 // (DW_FORM_string)
183 .uleb128 0x2 ;# (abbrev code)
184 .uleb128 0x2e ;# (TAG: DW_TAG_subprogram)
185 .initByte 0x0 ;# DW_children_no
186 .uleb128 0x3 ;# (DW_AT_name)
187 .uleb128 0x8 ;# (DW_FORM_string)
188 .uleb128 0x11 ;# (DW_AT_low_pc)
189 .uleb128 0x1 ;# (DW_FORM_addr)
190 .uleb128 0x12 ;# (DW_AT_high_pc)
191 .uleb128 0x1 ;# (DW_FORM_addr)
197 //============================================================================
198 // Line information. DwarfLib requires this to be present, but it can
200 //============================================================================
205 //============================================================================
207 //============================================================================
211 .unalignedInitLong _picoMark_DEBUG_INFO_END-_picoMark_DEBUG_INFO_BEGIN
212 _picoMark_DEBUG_INFO_BEGIN=
213 .unalignedInitWord 0x2
214 .unalignedInitLong _picoMark_ABBREVIATIONS
217 // Compile unit information.
218 .uleb128 0x1 // (DIE 0xb) DW_TAG_compile_unit)
219 .unalignedInitLong _picoMark_LINES
220 .unalignedInitWord _picoMark_FUNCTION_END
221 .unalignedInitWord _picoMark_FUNCTION_BEGIN
222 // Producer is `picoChip'
223 .ascii 16#70# 16#69# 16#63# 16#6f# 16#43# 16#68# 16#69# 16#70# 16#00#
224 .unalignedInitWord 0xcafe // ASM language
225 .ascii 16#0# // Name. DwarfLib expects this to be present.
227 .uleb128 0x2 ;# (DIE DW_TAG_subprogram)
229 // FUNCTION NAME GOES HERE. Use `echo name | od -t x1' to get the hex. Each hex
230 // digit is specified using the format 16#XX#
231 .ascii 16#5f# 16#75# 16#64# 16#69# 16#76# 16#6d# 16#6f# 16#64# 16#68# 16#69# 16#34# 16#0# // Function name `_udivmodhi4'
232 .unalignedInitWord _picoMark_FUNCTION_BEGIN // DW_AT_low_pc
233 .unalignedInitWord _picoMark_FUNCTION_END // DW_AT_high_pc
235 .initByte 0x0 // end of compile unit children.
237 _picoMark_DEBUG_INFO_END=
239 //============================================================================
241 //============================================================================
243 // End of picoChip ASM file