/* Copyright (C) 2006 Free Software Foundation, Inc.12This file is free software; you can redistribute it and/or modify it3under the terms of the GNU General Public License as published by the4Free Software Foundation; either version 2, or (at your option) any5later version.67In addition to the permissions in the GNU General Public License, the8Free Software Foundation gives you unlimited permission to link the9compiled version of this file into combinations with other programs,10and to distribute those combinations without any restriction coming11from the use of this file. (The General Public License restrictions12do apply in other respects; for example, they cover modification of13the file, and distribution when not linked into a combine14executable.)1516This file is distributed in the hope that it will be useful, but17WITHOUT ANY WARRANTY; without even the implied warranty of18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU19General Public License for more details.2021You should have received a copy of the GNU General Public License22along with this program; see the file COPYING. If not, write to23the Free Software Foundation, 51 Franklin Street, Fifth Floor,24Boston, MA 02110-1301, USA. */2526/* Moderately Space-optimized libgcc routines for the Renesas SH /27STMicroelectronics ST40 CPUs.28Contributed by J"orn Rennecke [email protected]. */2930/* Size: 186 bytes jointly for udivsi3_i4i and sdivsi3_i4i31sh4-200 run times:32udiv small divisor: 55 cycles33udiv large divisor: 52 cycles34sdiv small divisor, positive result: 59 cycles35sdiv large divisor, positive result: 56 cycles36sdiv small divisor, negative result: 65 cycles (*)37sdiv large divisor, negative result: 62 cycles (*)38(*): r2 is restored in the rts delay slot and has a lingering latency39of two more cycles. */40.balign 441.global __udivsi3_i4i42.global __udivsi3_i443.set __udivsi3_i4, __udivsi3_i4i44.type __udivsi3_i4i, @function45.type __sdivsi3_i4i, @function46__udivsi3_i4i:47sts pr,r148mov.l r4,@-r1549extu.w r5,r050cmp/eq r5,r051swap.w r4,r052shlr16 r453bf/s large_divisor54div0u55mov.l r5,@-r1556shll16 r557sdiv_small_divisor:58div1 r5,r459bsr div660div1 r5,r461div1 r5,r462bsr div663div1 r5,r464xtrct r4,r065xtrct r0,r466bsr div767swap.w r4,r468div1 r5,r469bsr div770div1 r5,r471xtrct r4,r072mov.l @r15+,r573swap.w r0,r074mov.l @r15+,r475jmp @r176rotcl r077div7:78div1 r5,r479div6:80div1 r5,r4; div1 r5,r4; div1 r5,r481div1 r5,r4; div1 r5,r4; rts; div1 r5,r48283divx3:84rotcl r085div1 r5,r486rotcl r087div1 r5,r488rotcl r089rts90div1 r5,r49192large_divisor:93mov.l r5,@-r1594sdiv_large_divisor:95xor r4,r096.rept 497rotcl r098bsr divx399div1 r5,r4100.endr101mov.l @r15+,r5102mov.l @r15+,r4103jmp @r1104rotcl r0105106.global __sdivsi3_i4i107.global __sdivsi3_i4108.global __sdivsi3109.set __sdivsi3_i4, __sdivsi3_i4i110.set __sdivsi3, __sdivsi3_i4i111__sdivsi3_i4i:112mov.l r4,@-r15113cmp/pz r5114mov.l r5,@-r15115bt/s pos_divisor116cmp/pz r4117neg r5,r5118extu.w r5,r0119bt/s neg_result120cmp/eq r5,r0121neg r4,r4122pos_result:123swap.w r4,r0124bra sdiv_check_divisor125sts pr,r1126pos_divisor:127extu.w r5,r0128bt/s pos_result129cmp/eq r5,r0130neg r4,r4131neg_result:132mova negate_result,r0133;134mov r0,r1135swap.w r4,r0136lds r2,macl137sts pr,r2138sdiv_check_divisor:139shlr16 r4140bf/s sdiv_large_divisor141div0u142bra sdiv_small_divisor143shll16 r5144.balign 4145negate_result:146neg r0,r0147jmp @r2148sts macl,r2149150151