1 /* SImode div/mod functions for the GCC support library for the Renesas RL78 processors.
2 Copyright (C) 2012,2013 Free Software Foundation, Inc.
3 Contributed by Red Hat.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published
9 by the Free Software Foundation; either version 3, or (at your
10 option) any later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
30 .macro make_generic which,need_result
84 shift_den_bit16\which:
97 br $shift_den_bit\which
99 ;; These routines leave DE alone - the signed functions use DE
100 ;; to store sign information that must remain intact
112 ;; (quot,rem) = 8[sp] /% 12[sp]
115 movw ax, [hl+14] ; denH
116 cmpw ax, [hl+10] ; numH
117 movw ax, [hl+12] ; denL
119 cmpw ax, [hl+8] ; numL
126 push hl ; bitH - stored in BC
129 ;; (quot,rem) = 16[sp] /% 20[sp]
147 bnz $den_not_zero\which
159 ;; initialize bit to 1
163 ; while (den < num && !(den & (1L << BITS_MINUS_1)))
166 ;; see if we can short-circuit a bunch of shifts
169 bnz $shift_den_bit\which
172 bnh $shift_den_bit16\which
178 bc $enter_main_loop\which
180 movw ax, denL ; we re-use this below
183 bh $enter_main_loop\which
186 ; movw ax, denL ; already has it from the cmpw above
202 ;; if we don't need to compute the quotent, we don't need an
203 ;; actual bit *mask*, we just need to keep track of which bit
207 br $shift_den_bit\which
212 ;; if (num >= den) (cmp den > num)
222 ; movw ax, numL ; already has it from the cmpw above
275 enter_main_loop\which:
284 ;; bit is HImode now; check others
285 movw ax, numH ; numerator
287 bnz $bit_high_set\which
288 movw ax, denH ; denominator
290 bz $switch_to_himode\which
300 switch_to_himode\which:
307 bz $main_loop_done_himode\which
309 ;; From here on in, r22, r14, and r18 are all zero
311 main_loop_himode\which:
313 ;; if (num >= den) (cmp den > num)
316 bh $next_loop_himode\which
338 next_loop_himode\which:
360 bnz $main_loop_himode\which
362 main_loop_done_himode\which:
364 pop hl ; bitH - stored in BC
376 ;----------------------------------------------------------------------
379 .type ___udivsi3,@function
381 ;; r8 = 4[sp] / 8[sp]
384 .size ___udivsi3, . - ___udivsi3
388 .type ___umodsi3,@function
390 ;; r8 = 4[sp] % 8[sp]
393 .size ___umodsi3, . - ___umodsi3
395 ;----------------------------------------------------------------------
410 .type ___divsi3,@function
412 ;; r8 = 4[sp] / 8[sp]
431 bnc $div_unsigned_den
443 bz $div_skip_restore_num
444 ;; We have to restore the numerator [sp+4]
449 div_skip_restore_num:
457 bz $div_skip_restore_den
458 ;; We have to restore the denominator [sp+8]
462 div_skip_restore_den:
464 .size ___divsi3, . - ___divsi3
468 .type ___modsi3,@function
470 ;; r8 = 4[sp] % 8[sp]
489 bnc $mod_unsigned_den
504 ;; We have to restore [sp+4] as well.
512 bz $mod_skip_restore_den
516 mod_skip_restore_den:
519 .size ___modsi3, . - ___modsi3