1 /* QImode 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
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public 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
71 ;; These routines leave DE alone - the signed functions use DE
72 ;; to store sign information that must remain intact
84 ;; (quot,rem) = 4[hl] /% 6[hl]
92 ; mov a, [hl+4] ; already there from above
100 bz $den_is_zero\which
108 ;; initialize bit to 1
111 ; while (den < num && !(den & (1L << BITS_MINUS_1)))
117 bc $enter_main_loop\which
119 bh $enter_main_loop\which
122 ; mov a, den ; already has it from the cmpw above
133 br $shift_den_bit\which
137 ;; if (num >= den) (cmp den > num)
161 enter_main_loop\which:
165 main_loop_done\which:
172 ;----------------------------------------------------------------------
175 .type ___udivqi3,@function
177 ;; r8 = 4[sp] / 6[sp]
180 .size ___udivqi3, . - ___udivqi3
184 .type ___umodqi3,@function
186 ;; r8 = 4[sp] % 6[sp]
189 .size ___umodqi3, . - ___umodqi3
191 ;----------------------------------------------------------------------
201 .type ___divqi3,@function
203 ;; r8 = 4[sp] / 6[sp]
222 bnc $div_unsigned_den
234 bz $div_skip_restore_num
235 ;; We have to restore the numerator [sp+4]
240 div_skip_restore_num:
248 bz $div_skip_restore_den
252 div_skip_restore_den:
254 .size ___divqi3, . - ___divqi3
258 .type ___modqi3,@function
260 ;; r8 = 4[sp] % 6[sp]
279 bnc $mod_unsigned_den
295 ;; Also restore numerator
302 bz $mod_skip_restore_den
306 mod_skip_restore_den:
308 .size ___modqi3, . - ___modqi3