~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP2M68000 Hi-Performance Microprocessor Division3M68060 Software Package4Production Release P1.00 -- October 10, 199456M68060 Software Package Copyright © 1993, 1994 Motorola Inc. All rights reserved.78THE SOFTWARE is provided on an "AS IS" basis and without warranty.9To the maximum extent permitted by applicable law,10MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,11INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE12and any warranty against infringement with regard to the SOFTWARE13(INCLUDING ANY MODIFIED VERSIONS THEREOF) and any accompanying written materials.1415To the maximum extent permitted by applicable law,16IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER17(INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,18BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS)19ARISING OF THE USE OR INABILITY TO USE THE SOFTWARE.20Motorola assumes no responsibility for the maintenance and support of the SOFTWARE.2122You are hereby granted a copyright license to use, modify, and distribute the SOFTWARE23so long as this entire notice is retained without alteration in any modified and/or24redistributed versions, and that such modified versions are clearly identified as such.25No licenses are granted by implication, estoppel or otherwise under any patents26or trademarks of Motorola, Inc.27~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~28# litop.s:29# This file is appended to the top of the 060FPLSP package30# and contains the entry points into the package. The user, in31# effect, branches to one of the branch table entries located here.32#3334bra.l _060LSP__idivs64_35short 0x000036bra.l _060LSP__idivu64_37short 0x00003839bra.l _060LSP__imuls64_40short 0x000041bra.l _060LSP__imulu64_42short 0x00004344bra.l _060LSP__cmp2_Ab_45short 0x000046bra.l _060LSP__cmp2_Aw_47short 0x000048bra.l _060LSP__cmp2_Al_49short 0x000050bra.l _060LSP__cmp2_Db_51short 0x000052bra.l _060LSP__cmp2_Dw_53short 0x000054bra.l _060LSP__cmp2_Dl_55short 0x00005657# leave room for future possible aditions.58align 0x2005960#########################################################################61# XDEF **************************************************************** #62# _060LSP__idivu64_(): Emulate 64-bit unsigned div instruction. #63# _060LSP__idivs64_(): Emulate 64-bit signed div instruction. #64# #65# This is the library version which is accessed as a subroutine #66# and therefore does not work exactly like the 680X0 div{s,u}.l #67# 64-bit divide instruction. #68# #69# XREF **************************************************************** #70# None. #71# #72# INPUT *************************************************************** #73# 0x4(sp) = divisor #74# 0x8(sp) = hi(dividend) #75# 0xc(sp) = lo(dividend) #76# 0x10(sp) = pointer to location to place quotient/remainder #77# #78# OUTPUT ************************************************************** #79# 0x10(sp) = points to location of remainder/quotient. #80# remainder is in first longword, quotient is in 2nd. #81# #82# ALGORITHM *********************************************************** #83# If the operands are signed, make them unsigned and save the #84# sign info for later. Separate out special cases like divide-by-zero #85# or 32-bit divides if possible. Else, use a special math algorithm #86# to calculate the result. #87# Restore sign info if signed instruction. Set the condition #88# codes before performing the final "rts". If the divisor was equal to #89# zero, then perform a divide-by-zero using a 16-bit implemented #90# divide instruction. This way, the operating system can record that #91# the event occurred even though it may not point to the correct place. #92# #93#########################################################################9495set POSNEG, -196set NDIVISOR, -297set NDIVIDEND, -398set DDSECOND, -499set DDNORMAL, -8100set DDQUOTIENT, -12101set DIV64_CC, -16102103##########104# divs.l #105##########106global _060LSP__idivs64_107_060LSP__idivs64_:108# PROLOGUE BEGIN ########################################################109link.w %a6,&-16110movm.l &0x3f00,-(%sp) # save d2-d7111# fmovm.l &0x0,-(%sp) # save no fpregs112# PROLOGUE END ##########################################################113114mov.w %cc,DIV64_CC(%a6)115st POSNEG(%a6) # signed operation116bra.b ldiv64_cont117118##########119# divu.l #120##########121global _060LSP__idivu64_122_060LSP__idivu64_:123# PROLOGUE BEGIN ########################################################124link.w %a6,&-16125movm.l &0x3f00,-(%sp) # save d2-d7126# fmovm.l &0x0,-(%sp) # save no fpregs127# PROLOGUE END ##########################################################128129mov.w %cc,DIV64_CC(%a6)130sf POSNEG(%a6) # unsigned operation131132ldiv64_cont:133mov.l 0x8(%a6),%d7 # fetch divisor134135beq.w ldiv64eq0 # divisor is = 0!!!136137mov.l 0xc(%a6), %d5 # get dividend hi138mov.l 0x10(%a6), %d6 # get dividend lo139140# separate signed and unsigned divide141tst.b POSNEG(%a6) # signed or unsigned?142beq.b ldspecialcases # use positive divide143144# save the sign of the divisor145# make divisor unsigned if it's negative146tst.l %d7 # chk sign of divisor147slt NDIVISOR(%a6) # save sign of divisor148bpl.b ldsgndividend149neg.l %d7 # complement negative divisor150151# save the sign of the dividend152# make dividend unsigned if it's negative153ldsgndividend:154tst.l %d5 # chk sign of hi(dividend)155slt NDIVIDEND(%a6) # save sign of dividend156bpl.b ldspecialcases157158mov.w &0x0, %cc # clear 'X' cc bit159negx.l %d6 # complement signed dividend160negx.l %d5161162# extract some special cases:163# - is (dividend == 0) ?164# - is (hi(dividend) == 0 && (divisor <= lo(dividend))) ? (32-bit div)165ldspecialcases:166tst.l %d5 # is (hi(dividend) == 0)167bne.b ldnormaldivide # no, so try it the long way168169tst.l %d6 # is (lo(dividend) == 0), too170beq.w lddone # yes, so (dividend == 0)171172cmp.l %d7,%d6 # is (divisor <= lo(dividend))173bls.b ld32bitdivide # yes, so use 32 bit divide174175exg %d5,%d6 # q = 0, r = dividend176bra.w ldivfinish # can't divide, we're done.177178ld32bitdivide:179tdivu.l %d7, %d5:%d6 # it's only a 32/32 bit div!180181bra.b ldivfinish182183ldnormaldivide:184# last special case:185# - is hi(dividend) >= divisor ? if yes, then overflow186cmp.l %d7,%d5187bls.b lddovf # answer won't fit in 32 bits188189# perform the divide algorithm:190bsr.l ldclassical # do int divide191192# separate into signed and unsigned finishes.193ldivfinish:194tst.b POSNEG(%a6) # do divs, divu separately195beq.b lddone # divu has no processing!!!196197# it was a divs.l, so ccode setting is a little more complicated...198tst.b NDIVIDEND(%a6) # remainder has same sign199beq.b ldcc # as dividend.200neg.l %d5 # sgn(rem) = sgn(dividend)201ldcc:202mov.b NDIVISOR(%a6), %d0203eor.b %d0, NDIVIDEND(%a6) # chk if quotient is negative204beq.b ldqpos # branch to quot positive205206# 0x80000000 is the largest number representable as a 32-bit negative207# number. the negative of 0x80000000 is 0x80000000.208cmpi.l %d6, &0x80000000 # will (-quot) fit in 32 bits?209bhi.b lddovf210211neg.l %d6 # make (-quot) 2's comp212213bra.b lddone214215ldqpos:216btst &0x1f, %d6 # will (+quot) fit in 32 bits?217bne.b lddovf218219lddone:220# if the register numbers are the same, only the quotient gets saved.221# so, if we always save the quotient second, we save ourselves a cmp&beq222andi.w &0x10,DIV64_CC(%a6)223mov.w DIV64_CC(%a6),%cc224tst.l %d6 # may set 'N' ccode bit225226# here, the result is in d1 and d0. the current strategy is to save227# the values at the location pointed to by a0.228# use movm here to not disturb the condition codes.229ldexit:230movm.l &0x0060,([0x14,%a6]) # save result231232# EPILOGUE BEGIN ########################################################233# fmovm.l (%sp)+,&0x0 # restore no fpregs234movm.l (%sp)+,&0x00fc # restore d2-d7235unlk %a6236# EPILOGUE END ##########################################################237238rts239240# the result should be the unchanged dividend241lddovf:242mov.l 0xc(%a6), %d5 # get dividend hi243mov.l 0x10(%a6), %d6 # get dividend lo244245andi.w &0x1c,DIV64_CC(%a6)246ori.w &0x02,DIV64_CC(%a6) # set 'V' ccode bit247mov.w DIV64_CC(%a6),%cc248249bra.b ldexit250251ldiv64eq0:252mov.l 0xc(%a6),([0x14,%a6])253mov.l 0x10(%a6),([0x14,%a6],0x4)254255mov.w DIV64_CC(%a6),%cc256257# EPILOGUE BEGIN ########################################################258# fmovm.l (%sp)+,&0x0 # restore no fpregs259movm.l (%sp)+,&0x00fc # restore d2-d7260unlk %a6261# EPILOGUE END ##########################################################262263divu.w &0x0,%d0 # force a divbyzero exception264rts265266###########################################################################267#########################################################################268# This routine uses the 'classical' Algorithm D from Donald Knuth's #269# Art of Computer Programming, vol II, Seminumerical Algorithms. #270# For this implementation b=2**16, and the target is U1U2U3U4/V1V2, #271# where U,V are words of the quadword dividend and longword divisor, #272# and U1, V1 are the most significant words. #273# #274# The most sig. longword of the 64 bit dividend must be in %d5, least #275# in %d6. The divisor must be in the variable ddivisor, and the #276# signed/unsigned flag ddusign must be set (0=unsigned,1=signed). #277# The quotient is returned in %d6, remainder in %d5, unless the #278# v (overflow) bit is set in the saved %ccr. If overflow, the dividend #279# is unchanged. #280#########################################################################281ldclassical:282# if the divisor msw is 0, use simpler algorithm then the full blown283# one at ddknuth:284285cmpi.l %d7, &0xffff286bhi.b lddknuth # go use D. Knuth algorithm287288# Since the divisor is only a word (and larger than the mslw of the dividend),289# a simpler algorithm may be used :290# In the general case, four quotient words would be created by291# dividing the divisor word into each dividend word. In this case,292# the first two quotient words must be zero, or overflow would occur.293# Since we already checked this case above, we can treat the most significant294# longword of the dividend as (0) remainder (see Knuth) and merely complete295# the last two divisions to get a quotient longword and word remainder:296297clr.l %d1298swap %d5 # same as r*b if previous step rqd299swap %d6 # get u3 to lsw position300mov.w %d6, %d5 # rb + u3301302divu.w %d7, %d5303304mov.w %d5, %d1 # first quotient word305swap %d6 # get u4306mov.w %d6, %d5 # rb + u4307308divu.w %d7, %d5309310swap %d1311mov.w %d5, %d1 # 2nd quotient 'digit'312clr.w %d5313swap %d5 # now remainder314mov.l %d1, %d6 # and quotient315316rts317318lddknuth:319# In this algorithm, the divisor is treated as a 2 digit (word) number320# which is divided into a 3 digit (word) dividend to get one quotient321# digit (word). After subtraction, the dividend is shifted and the322# process repeated. Before beginning, the divisor and quotient are323# 'normalized' so that the process of estimating the quotient digit324# will yield verifiably correct results..325326clr.l DDNORMAL(%a6) # count of shifts for normalization327clr.b DDSECOND(%a6) # clear flag for quotient digits328clr.l %d1 # %d1 will hold trial quotient329lddnchk:330btst &31, %d7 # must we normalize? first word of331bne.b lddnormalized # divisor (V1) must be >= 65536/2332addq.l &0x1, DDNORMAL(%a6) # count normalization shifts333lsl.l &0x1, %d7 # shift the divisor334lsl.l &0x1, %d6 # shift u4,u3 with overflow to u2335roxl.l &0x1, %d5 # shift u1,u2336bra.w lddnchk337lddnormalized:338339# Now calculate an estimate of the quotient words (msw first, then lsw).340# The comments use subscripts for the first quotient digit determination.341mov.l %d7, %d3 # divisor342mov.l %d5, %d2 # dividend mslw343swap %d2344swap %d3345cmp.w %d2, %d3 # V1 = U1 ?346bne.b lddqcalc1347mov.w &0xffff, %d1 # use max trial quotient word348bra.b lddadj0349lddqcalc1:350mov.l %d5, %d1351352divu.w %d3, %d1 # use quotient of mslw/msw353354andi.l &0x0000ffff, %d1 # zero any remainder355lddadj0:356357# now test the trial quotient and adjust. This step plus the358# normalization assures (according to Knuth) that the trial359# quotient will be at worst 1 too large.360mov.l %d6, -(%sp)361clr.w %d6 # word u3 left362swap %d6 # in lsw position363lddadj1: mov.l %d7, %d3364mov.l %d1, %d2365mulu.w %d7, %d2 # V2q366swap %d3367mulu.w %d1, %d3 # V1q368mov.l %d5, %d4 # U1U2369sub.l %d3, %d4 # U1U2 - V1q370371swap %d4372373mov.w %d4,%d0374mov.w %d6,%d4 # insert lower word (U3)375376tst.w %d0 # is upper word set?377bne.w lddadjd1378379# add.l %d6, %d4 # (U1U2 - V1q) + U3380381cmp.l %d2, %d4382bls.b lddadjd1 # is V2q > (U1U2-V1q) + U3 ?383subq.l &0x1, %d1 # yes, decrement and recheck384bra.b lddadj1385lddadjd1:386# now test the word by multiplying it by the divisor (V1V2) and comparing387# the 3 digit (word) result with the current dividend words388mov.l %d5, -(%sp) # save %d5 (%d6 already saved)389mov.l %d1, %d6390swap %d6 # shift answer to ms 3 words391mov.l %d7, %d5392bsr.l ldmm2393mov.l %d5, %d2 # now %d2,%d3 are trial*divisor394mov.l %d6, %d3395mov.l (%sp)+, %d5 # restore dividend396mov.l (%sp)+, %d6397sub.l %d3, %d6398subx.l %d2, %d5 # subtract double precision399bcc ldd2nd # no carry, do next quotient digit400subq.l &0x1, %d1 # q is one too large401# need to add back divisor longword to current ms 3 digits of dividend402# - according to Knuth, this is done only 2 out of 65536 times for random403# divisor, dividend selection.404clr.l %d2405mov.l %d7, %d3406swap %d3407clr.w %d3 # %d3 now ls word of divisor408add.l %d3, %d6 # aligned with 3rd word of dividend409addx.l %d2, %d5410mov.l %d7, %d3411clr.w %d3 # %d3 now ms word of divisor412swap %d3 # aligned with 2nd word of dividend413add.l %d3, %d5414ldd2nd:415tst.b DDSECOND(%a6) # both q words done?416bne.b lddremain417# first quotient digit now correct. store digit and shift the418# (subtracted) dividend419mov.w %d1, DDQUOTIENT(%a6)420clr.l %d1421swap %d5422swap %d6423mov.w %d6, %d5424clr.w %d6425st DDSECOND(%a6) # second digit426bra.w lddnormalized427lddremain:428# add 2nd word to quotient, get the remainder.429mov.w %d1, DDQUOTIENT+2(%a6)430# shift down one word/digit to renormalize remainder.431mov.w %d5, %d6432swap %d6433swap %d5434mov.l DDNORMAL(%a6), %d7 # get norm shift count435beq.b lddrn436subq.l &0x1, %d7 # set for loop count437lddnlp:438lsr.l &0x1, %d5 # shift into %d6439roxr.l &0x1, %d6440dbf %d7, lddnlp441lddrn:442mov.l %d6, %d5 # remainder443mov.l DDQUOTIENT(%a6), %d6 # quotient444445rts446ldmm2:447# factors for the 32X32->64 multiplication are in %d5 and %d6.448# returns 64 bit result in %d5 (hi) %d6(lo).449# destroys %d2,%d3,%d4.450451# multiply hi,lo words of each factor to get 4 intermediate products452mov.l %d6, %d2453mov.l %d6, %d3454mov.l %d5, %d4455swap %d3456swap %d4457mulu.w %d5, %d6 # %d6 <- lsw*lsw458mulu.w %d3, %d5 # %d5 <- msw-dest*lsw-source459mulu.w %d4, %d2 # %d2 <- msw-source*lsw-dest460mulu.w %d4, %d3 # %d3 <- msw*msw461# now use swap and addx to consolidate to two longwords462clr.l %d4463swap %d6464add.w %d5, %d6 # add msw of l*l to lsw of m*l product465addx.w %d4, %d3 # add any carry to m*m product466add.w %d2, %d6 # add in lsw of other m*l product467addx.w %d4, %d3 # add any carry to m*m product468swap %d6 # %d6 is low 32 bits of final product469clr.w %d5470clr.w %d2 # lsw of two mixed products used,471swap %d5 # now use msws of longwords472swap %d2473add.l %d2, %d5474add.l %d3, %d5 # %d5 now ms 32 bits of final product475rts476477#########################################################################478# XDEF **************************************************************** #479# _060LSP__imulu64_(): Emulate 64-bit unsigned mul instruction #480# _060LSP__imuls64_(): Emulate 64-bit signed mul instruction. #481# #482# This is the library version which is accessed as a subroutine #483# and therefore does not work exactly like the 680X0 mul{s,u}.l #484# 64-bit multiply instruction. #485# #486# XREF **************************************************************** #487# None #488# #489# INPUT *************************************************************** #490# 0x4(sp) = multiplier #491# 0x8(sp) = multiplicand #492# 0xc(sp) = pointer to location to place 64-bit result #493# #494# OUTPUT ************************************************************** #495# 0xc(sp) = points to location of 64-bit result #496# #497# ALGORITHM *********************************************************** #498# Perform the multiply in pieces using 16x16->32 unsigned #499# multiplies and "add" instructions. #500# Set the condition codes as appropriate before performing an #501# "rts". #502# #503#########################################################################504505set MUL64_CC, -4506507global _060LSP__imulu64_508_060LSP__imulu64_:509510# PROLOGUE BEGIN ########################################################511link.w %a6,&-4512movm.l &0x3800,-(%sp) # save d2-d4513# fmovm.l &0x0,-(%sp) # save no fpregs514# PROLOGUE END ##########################################################515516mov.w %cc,MUL64_CC(%a6) # save incoming ccodes517518mov.l 0x8(%a6),%d0 # store multiplier in d0519beq.w mulu64_zero # handle zero separately520521mov.l 0xc(%a6),%d1 # get multiplicand in d1522beq.w mulu64_zero # handle zero separately523524#########################################################################525# 63 32 0 #526# ---------------------------- #527# | hi(mplier) * hi(mplicand)| #528# ---------------------------- #529# ----------------------------- #530# | hi(mplier) * lo(mplicand) | #531# ----------------------------- #532# ----------------------------- #533# | lo(mplier) * hi(mplicand) | #534# ----------------------------- #535# | ----------------------------- #536# --|-- | lo(mplier) * lo(mplicand) | #537# | ----------------------------- #538# ======================================================== #539# -------------------------------------------------------- #540# | hi(result) | lo(result) | #541# -------------------------------------------------------- #542#########################################################################543mulu64_alg:544# load temp registers with operands545mov.l %d0,%d2 # mr in d2546mov.l %d0,%d3 # mr in d3547mov.l %d1,%d4 # md in d4548swap %d3 # hi(mr) in lo d3549swap %d4 # hi(md) in lo d4550551# complete necessary multiplies:552mulu.w %d1,%d0 # [1] lo(mr) * lo(md)553mulu.w %d3,%d1 # [2] hi(mr) * lo(md)554mulu.w %d4,%d2 # [3] lo(mr) * hi(md)555mulu.w %d4,%d3 # [4] hi(mr) * hi(md)556557# add lo portions of [2],[3] to hi portion of [1].558# add carries produced from these adds to [4].559# lo([1]) is the final lo 16 bits of the result.560clr.l %d4 # load d4 w/ zero value561swap %d0 # hi([1]) <==> lo([1])562add.w %d1,%d0 # hi([1]) + lo([2])563addx.l %d4,%d3 # [4] + carry564add.w %d2,%d0 # hi([1]) + lo([3])565addx.l %d4,%d3 # [4] + carry566swap %d0 # lo([1]) <==> hi([1])567568# lo portions of [2],[3] have been added in to final result.569# now, clear lo, put hi in lo reg, and add to [4]570clr.w %d1 # clear lo([2])571clr.w %d2 # clear hi([3])572swap %d1 # hi([2]) in lo d1573swap %d2 # hi([3]) in lo d2574add.l %d2,%d1 # [4] + hi([2])575add.l %d3,%d1 # [4] + hi([3])576577# now, grab the condition codes. only one that can be set is 'N'.578# 'N' CAN be set if the operation is unsigned if bit 63 is set.579mov.w MUL64_CC(%a6),%d4580andi.b &0x10,%d4 # keep old 'X' bit581tst.l %d1 # may set 'N' bit582bpl.b mulu64_ddone583ori.b &0x8,%d4 # set 'N' bit584mulu64_ddone:585mov.w %d4,%cc586587# here, the result is in d1 and d0. the current strategy is to save588# the values at the location pointed to by a0.589# use movm here to not disturb the condition codes.590mulu64_end:591exg %d1,%d0592movm.l &0x0003,([0x10,%a6]) # save result593594# EPILOGUE BEGIN ########################################################595# fmovm.l (%sp)+,&0x0 # restore no fpregs596movm.l (%sp)+,&0x001c # restore d2-d4597unlk %a6598# EPILOGUE END ##########################################################599600rts601602# one or both of the operands is zero so the result is also zero.603# save the zero result to the register file and set the 'Z' ccode bit.604mulu64_zero:605clr.l %d0606clr.l %d1607608mov.w MUL64_CC(%a6),%d4609andi.b &0x10,%d4610ori.b &0x4,%d4611mov.w %d4,%cc # set 'Z' ccode bit612613bra.b mulu64_end614615##########616# muls.l #617##########618global _060LSP__imuls64_619_060LSP__imuls64_:620621# PROLOGUE BEGIN ########################################################622link.w %a6,&-4623movm.l &0x3c00,-(%sp) # save d2-d5624# fmovm.l &0x0,-(%sp) # save no fpregs625# PROLOGUE END ##########################################################626627mov.w %cc,MUL64_CC(%a6) # save incoming ccodes628629mov.l 0x8(%a6),%d0 # store multiplier in d0630beq.b mulu64_zero # handle zero separately631632mov.l 0xc(%a6),%d1 # get multiplicand in d1633beq.b mulu64_zero # handle zero separately634635clr.b %d5 # clear sign tag636tst.l %d0 # is multiplier negative?637bge.b muls64_chk_md_sgn # no638neg.l %d0 # make multiplier positive639640ori.b &0x1,%d5 # save multiplier sgn641642# the result sign is the exclusive or of the operand sign bits.643muls64_chk_md_sgn:644tst.l %d1 # is multiplicand negative?645bge.b muls64_alg # no646neg.l %d1 # make multiplicand positive647648eori.b &0x1,%d5 # calculate correct sign649650#########################################################################651# 63 32 0 #652# ---------------------------- #653# | hi(mplier) * hi(mplicand)| #654# ---------------------------- #655# ----------------------------- #656# | hi(mplier) * lo(mplicand) | #657# ----------------------------- #658# ----------------------------- #659# | lo(mplier) * hi(mplicand) | #660# ----------------------------- #661# | ----------------------------- #662# --|-- | lo(mplier) * lo(mplicand) | #663# | ----------------------------- #664# ======================================================== #665# -------------------------------------------------------- #666# | hi(result) | lo(result) | #667# -------------------------------------------------------- #668#########################################################################669muls64_alg:670# load temp registers with operands671mov.l %d0,%d2 # mr in d2672mov.l %d0,%d3 # mr in d3673mov.l %d1,%d4 # md in d4674swap %d3 # hi(mr) in lo d3675swap %d4 # hi(md) in lo d4676677# complete necessary multiplies:678mulu.w %d1,%d0 # [1] lo(mr) * lo(md)679mulu.w %d3,%d1 # [2] hi(mr) * lo(md)680mulu.w %d4,%d2 # [3] lo(mr) * hi(md)681mulu.w %d4,%d3 # [4] hi(mr) * hi(md)682683# add lo portions of [2],[3] to hi portion of [1].684# add carries produced from these adds to [4].685# lo([1]) is the final lo 16 bits of the result.686clr.l %d4 # load d4 w/ zero value687swap %d0 # hi([1]) <==> lo([1])688add.w %d1,%d0 # hi([1]) + lo([2])689addx.l %d4,%d3 # [4] + carry690add.w %d2,%d0 # hi([1]) + lo([3])691addx.l %d4,%d3 # [4] + carry692swap %d0 # lo([1]) <==> hi([1])693694# lo portions of [2],[3] have been added in to final result.695# now, clear lo, put hi in lo reg, and add to [4]696clr.w %d1 # clear lo([2])697clr.w %d2 # clear hi([3])698swap %d1 # hi([2]) in lo d1699swap %d2 # hi([3]) in lo d2700add.l %d2,%d1 # [4] + hi([2])701add.l %d3,%d1 # [4] + hi([3])702703tst.b %d5 # should result be signed?704beq.b muls64_done # no705706# result should be a signed negative number.707# compute 2's complement of the unsigned number:708# -negate all bits and add 1709muls64_neg:710not.l %d0 # negate lo(result) bits711not.l %d1 # negate hi(result) bits712addq.l &1,%d0 # add 1 to lo(result)713addx.l %d4,%d1 # add carry to hi(result)714715muls64_done:716mov.w MUL64_CC(%a6),%d4717andi.b &0x10,%d4 # keep old 'X' bit718tst.l %d1 # may set 'N' bit719bpl.b muls64_ddone720ori.b &0x8,%d4 # set 'N' bit721muls64_ddone:722mov.w %d4,%cc723724# here, the result is in d1 and d0. the current strategy is to save725# the values at the location pointed to by a0.726# use movm here to not disturb the condition codes.727muls64_end:728exg %d1,%d0729movm.l &0x0003,([0x10,%a6]) # save result at (a0)730731# EPILOGUE BEGIN ########################################################732# fmovm.l (%sp)+,&0x0 # restore no fpregs733movm.l (%sp)+,&0x003c # restore d2-d5734unlk %a6735# EPILOGUE END ##########################################################736737rts738739# one or both of the operands is zero so the result is also zero.740# save the zero result to the register file and set the 'Z' ccode bit.741muls64_zero:742clr.l %d0743clr.l %d1744745mov.w MUL64_CC(%a6),%d4746andi.b &0x10,%d4747ori.b &0x4,%d4748mov.w %d4,%cc # set 'Z' ccode bit749750bra.b muls64_end751752#########################################################################753# XDEF **************************************************************** #754# _060LSP__cmp2_Ab_(): Emulate "cmp2.b An,<ea>". #755# _060LSP__cmp2_Aw_(): Emulate "cmp2.w An,<ea>". #756# _060LSP__cmp2_Al_(): Emulate "cmp2.l An,<ea>". #757# _060LSP__cmp2_Db_(): Emulate "cmp2.b Dn,<ea>". #758# _060LSP__cmp2_Dw_(): Emulate "cmp2.w Dn,<ea>". #759# _060LSP__cmp2_Dl_(): Emulate "cmp2.l Dn,<ea>". #760# #761# This is the library version which is accessed as a subroutine #762# and therefore does not work exactly like the 680X0 "cmp2" #763# instruction. #764# #765# XREF **************************************************************** #766# None #767# #768# INPUT *************************************************************** #769# 0x4(sp) = Rn #770# 0x8(sp) = pointer to boundary pair #771# #772# OUTPUT ************************************************************** #773# cc = condition codes are set correctly #774# #775# ALGORITHM *********************************************************** #776# In the interest of simplicity, all operands are converted to #777# longword size whether the operation is byte, word, or long. The #778# bounds are sign extended accordingly. If Rn is a data regsiter, Rn is #779# also sign extended. If Rn is an address register, it need not be sign #780# extended since the full register is always used. #781# The condition codes are set correctly before the final "rts". #782# #783#########################################################################784785set CMP2_CC, -4786787global _060LSP__cmp2_Ab_788_060LSP__cmp2_Ab_:789790# PROLOGUE BEGIN ########################################################791link.w %a6,&-4792movm.l &0x3800,-(%sp) # save d2-d4793# fmovm.l &0x0,-(%sp) # save no fpregs794# PROLOGUE END ##########################################################795796mov.w %cc,CMP2_CC(%a6)797mov.l 0x8(%a6), %d2 # get regval798799mov.b ([0xc,%a6],0x0),%d0800mov.b ([0xc,%a6],0x1),%d1801802extb.l %d0 # sign extend lo bnd803extb.l %d1 # sign extend hi bnd804bra.w l_cmp2_cmp # go do the compare emulation805806global _060LSP__cmp2_Aw_807_060LSP__cmp2_Aw_:808809# PROLOGUE BEGIN ########################################################810link.w %a6,&-4811movm.l &0x3800,-(%sp) # save d2-d4812# fmovm.l &0x0,-(%sp) # save no fpregs813# PROLOGUE END ##########################################################814815mov.w %cc,CMP2_CC(%a6)816mov.l 0x8(%a6), %d2 # get regval817818mov.w ([0xc,%a6],0x0),%d0819mov.w ([0xc,%a6],0x2),%d1820821ext.l %d0 # sign extend lo bnd822ext.l %d1 # sign extend hi bnd823bra.w l_cmp2_cmp # go do the compare emulation824825global _060LSP__cmp2_Al_826_060LSP__cmp2_Al_:827828# PROLOGUE BEGIN ########################################################829link.w %a6,&-4830movm.l &0x3800,-(%sp) # save d2-d4831# fmovm.l &0x0,-(%sp) # save no fpregs832# PROLOGUE END ##########################################################833834mov.w %cc,CMP2_CC(%a6)835mov.l 0x8(%a6), %d2 # get regval836837mov.l ([0xc,%a6],0x0),%d0838mov.l ([0xc,%a6],0x4),%d1839bra.w l_cmp2_cmp # go do the compare emulation840841global _060LSP__cmp2_Db_842_060LSP__cmp2_Db_:843844# PROLOGUE BEGIN ########################################################845link.w %a6,&-4846movm.l &0x3800,-(%sp) # save d2-d4847# fmovm.l &0x0,-(%sp) # save no fpregs848# PROLOGUE END ##########################################################849850mov.w %cc,CMP2_CC(%a6)851mov.l 0x8(%a6), %d2 # get regval852853mov.b ([0xc,%a6],0x0),%d0854mov.b ([0xc,%a6],0x1),%d1855856extb.l %d0 # sign extend lo bnd857extb.l %d1 # sign extend hi bnd858859# operation is a data register compare.860# sign extend byte to long so we can do simple longword compares.861extb.l %d2 # sign extend data byte862bra.w l_cmp2_cmp # go do the compare emulation863864global _060LSP__cmp2_Dw_865_060LSP__cmp2_Dw_:866867# PROLOGUE BEGIN ########################################################868link.w %a6,&-4869movm.l &0x3800,-(%sp) # save d2-d4870# fmovm.l &0x0,-(%sp) # save no fpregs871# PROLOGUE END ##########################################################872873mov.w %cc,CMP2_CC(%a6)874mov.l 0x8(%a6), %d2 # get regval875876mov.w ([0xc,%a6],0x0),%d0877mov.w ([0xc,%a6],0x2),%d1878879ext.l %d0 # sign extend lo bnd880ext.l %d1 # sign extend hi bnd881882# operation is a data register compare.883# sign extend word to long so we can do simple longword compares.884ext.l %d2 # sign extend data word885bra.w l_cmp2_cmp # go emulate compare886887global _060LSP__cmp2_Dl_888_060LSP__cmp2_Dl_:889890# PROLOGUE BEGIN ########################################################891link.w %a6,&-4892movm.l &0x3800,-(%sp) # save d2-d4893# fmovm.l &0x0,-(%sp) # save no fpregs894# PROLOGUE END ##########################################################895896mov.w %cc,CMP2_CC(%a6)897mov.l 0x8(%a6), %d2 # get regval898899mov.l ([0xc,%a6],0x0),%d0900mov.l ([0xc,%a6],0x4),%d1901902#903# To set the ccodes correctly:904# (1) save 'Z' bit from (Rn - lo)905# (2) save 'Z' and 'N' bits from ((hi - lo) - (Rn - hi))906# (3) keep 'X', 'N', and 'V' from before instruction907# (4) combine ccodes908#909l_cmp2_cmp:910sub.l %d0, %d2 # (Rn - lo)911mov.w %cc, %d3 # fetch resulting ccodes912andi.b &0x4, %d3 # keep 'Z' bit913sub.l %d0, %d1 # (hi - lo)914cmp.l %d1,%d2 # ((hi - lo) - (Rn - hi))915916mov.w %cc, %d4 # fetch resulting ccodes917or.b %d4, %d3 # combine w/ earlier ccodes918andi.b &0x5, %d3 # keep 'Z' and 'N'919920mov.w CMP2_CC(%a6), %d4 # fetch old ccodes921andi.b &0x1a, %d4 # keep 'X','N','V' bits922or.b %d3, %d4 # insert new ccodes923mov.w %d4,%cc # save new ccodes924925# EPILOGUE BEGIN ########################################################926# fmovm.l (%sp)+,&0x0 # restore no fpregs927movm.l (%sp)+,&0x001c # restore d2-d4928unlk %a6929# EPILOGUE END ##########################################################930931rts932933934