A89: Floating-point "imitation"


[Prev][Next][Index][Thread]

A89: Floating-point "imitation"




This is mainly addressed to Zoltan based on some information he gave in
response to Turbosoft's question about using floating-point values in C/ASM,
but I'll take answers from anyone =)

If I'm not too concerned about accuracy, which of these sections of code is
better (they'll both be off the EXACT number I want a bit through truncating
and not rounding)?  What if I've got to do it 800 times in a row and I'm
concerned about speed?

--------------------------------------------------------------------------
Code_Section_One:
    mulu.w    #60,d0
    divu.w    #100,d0
;-- With d0 being any arbitrary integer x, this
; is the TI-BASIC equivalent of
; iPart((60*y)/100))
;-- I'm concerned about actually getting division
; to WORK and the speed of it - last time I tried
; divu I found that divu.l #7,d7 crashes the calc =(

Code_Section_Two:
    mulu.w    #77,d0
    clr.w     d3
    lsr.w     #7,d0    ;almost the same as divu.w #128,d0
    addx.w    d3,d0    ;but lets me use this line to round
;-- This is equivalent to round((77*y)/128,0)
;-- 77/128 is ROUGHLY equal to 60/100, and it
; SHOULD be faster because of shifting rather
; than dividing.  Plus, this one rounds properly

--------------------------------------------------------------------------

I'm mostly concerned about this speed-wise - which is more efficient?  Using
division is shorter and smaller, but is it actually faster?  And FYI, I want
it to be as close to 3y/5 as possible (60y/100, 77y/128, etc).

FYI, this section of code could be used to generate a table of coordinates
useful in programming Plain Jump (I _was_ considering it before these CCSW
guys announced it, and if they fail I will do it) - but generating these
tables in the program, you save an 800 byte table that would be needed to
store them before hand.  For example, try running this TI-BASIC program and
then look at the screen from the "north" end to the "south" end (yes, I'm
aware this program isn't optomized =)

pj()
Prgm
For y,0,76
PxlOn y,iPart(y/100*60)
PxlOn y,iPart(y/100*45+20)
PxlOn y,iPart(y/100*30+40)
PxlOn y,iPart(y/100*15+60)
PxlOn y,79
PxlOn y,160-iPart(y/100*60)
PxlOn y,160-iPart(y/100*45+20)
PxlOn y,160-iPart(y/100*30+40)
PxlOn y,160-iPart(y/100*15+60)
EndFor
EndPrgm

    -Scott





Follow-Ups: