This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] h8300/lib1funcs.asm: Optimize DenHighNonzero.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Cc: pisa at cmp dot felk dot cvut dot cz
- Date: Thu, 13 Nov 2003 12:10:25 -0500 (EST)
- Subject: [patch] h8300/lib1funcs.asm: Optimize DenHighNonzero.
Hi,
Attached is a patch to DenHighNonZero, which is a subroutine of
divmodsi4.
As in udivsi3 in m68k/lb1sf68.asm, we can compute an approximate
quotient with shifted dividend and divisor, and then correct the
quotient later.
The difference from the m68k implementation is that this version
assumes that the quotient is too large to begin with. If that is not
the case, we restore the original quotient.
Tested on h8300 port. Committed.
Kazu Hirata
2003-11-13 Pavel Pisa <pisa@cmp.felk.cvut.cz>
Kazu Hirata <kazu@cs.umass.edu>
* config/h8300/lib1funcs.asm (DenHighNonZero): Optimize using
the approximate quotient method.
Index: lib1funcs.asm
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/h8300/lib1funcs.asm,v
retrieving revision 1.20
diff -c -r1.20 lib1funcs.asm
*** lib1funcs.asm 13 Nov 2003 04:26:00 -0000 1.20
--- lib1funcs.asm 13 Nov 2003 04:38:05 -0000
***************
*** 603,634 ****
extu.l S0P
rts
DenHighNonZero:
! sub.l S0P,S0P ; zero play area
! mov.w A0E,A2
! mov.b A2H,S0L
! mov.b A2L,A2H
! mov.b A0H,A2L
! mov.w A2,A0E
! mov.b A0L,A0H
! mov.b #0,A0L
! mov.b #24,S2H ; only do 24 iterations
!
! nextbit:
! shll.l A0P ; double the answer guess
! rotxl.l S0P ; double remainder
! sub.l A1P,S0P ; does it all fit?
! bhs setone
!
! add.l A1P,S0P ; no, restore mistake
! dec S2H
! bne nextbit
! rts
!
! setone:
! inc A0L
! dec S2H
! bne nextbit
rts
#endif
--- 603,659 ----
extu.l S0P
rts
+ ; er0 = er0 / er1
+ ; er4 = er0 % er1
+ ; trashes er1 er2
+ ; expects er1 >= 2^16
DenHighNonZero:
! mov.l er0,er4
! mov.l er1,er2
! #ifdef __H8300H__
! divmod_L21:
! shlr.l er0
! shlr.l er2 ; make divisor < 2^16
! mov.w e2,e2
! bne divmod_L21
! #else
! bra divmod_L22
! divmod_L21:
! shlr.l #2,er0
! divmod_L22:
! shlr.l #2,er2 ; make divisor < 2^16
! mov.w e2,e2
! bne divmod_L21
! rotxl.w r2
! bcs divmod_L23
! shlr.l er0
! bra divmod_L24
! divmod_L23:
! rotxr.w r2
! shlr.l #2,er0
! divmod_L24:
! #endif
! ;; At this point,
! ;; er0 contains shifted dividend
! ;; er1 contains divisor
! ;; er2 contains shifted divisor
! ;; er4 contains dividend, later remainder
! divxu.w r2,er0 ; e0 now contains the approximate quotient (AQ)
! extu.l er0
! beq divmod_L25
! subs #1,er0 ; er0 = AQ - 1
! mov.w e1,r2
! mulxu.w r0,er2 ; er2 = upper (AQ - 1) * divisor
! sub.w r2,e4 ; dividend - 65536 * er2
! mov.w r1,r2
! mulxu.w r0,er2 ; compute er4 = remainder (tentative)
! sub.l er2,er4 ; er4 = dividend - (AQ - 1) * divisor
! divmod_L25:
! cmp.l er1,er4 ; is divisor < remainder?
! blo divmod_L26
! adds #1,er0
! sub.l er1,er4 ; correct the remainder
! divmod_L26:
rts
#endif