1 /* QImode div/mod functions for the GCC support library for the Renesas RL78 processors.
2 Copyright (C) 2012-2016 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/>. */
28 .macro MAKE_GENERIC which,need_result
46 START_FUNC __generic_qidivmod\which
69 ;; These routines leave DE alone - the signed functions use DE
70 ;; to store sign information that must remain intact
73 .global __generic_qidiv
78 .global __generic_qimod
83 ;; (quot,rem) = 4[hl] /% 6[hl]
91 ; mov a, [hl+4] ; already there from above
107 ;; initialize bit to 1
110 ; 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:
167 END_FUNC __generic_qidivmod\which
170 ;----------------------------------------------------------------------
175 ;----------------------------------------------------------------------
177 START_FUNC ___udivqi3
178 ;; r8 = 4[sp] / 6[sp]
184 START_FUNC ___umodqi3
185 ;; r8 = 4[sp] % 6[sp]
190 ;----------------------------------------------------------------------
199 ;----------------------------------------------------------------------
202 ;; r8 = 4[sp] / 6[sp]
221 bnc $div_unsigned_den
229 call $!__generic_qidiv
233 bz $div_skip_restore_num
234 ;; We have to restore the numerator [sp+4]
239 div_skip_restore_num:
247 bz $div_skip_restore_den
251 div_skip_restore_den:
257 ;; r8 = 4[sp] % 6[sp]
276 bnc $mod_unsigned_den
284 call $!__generic_qimod
292 ;; Also restore numerator
299 bz $mod_skip_restore_den
303 mod_skip_restore_den: