Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > 8 or 16bit muls/divs
2006-10-15 13:01
Luke

Registered: Dec 2004
Posts: 19
8 or 16bit muls/divs

About multiply:

Bad one:

a*b=((a+b)/2)^2-(((a+b)/2-b))^2 with x*x matrix

It's near 30-40 cycles, but unstable with (a+b)bit0 bcoz ror after adc.

Some ppl using "nybble tables" $0n x $xy with $1000 size of tables and swap+add, but more than 50 cycles left.

And last bad is old asl bcc adc ror routine, but very slow
like 80+ cycles.

Now I trying to do any 16x16bit signed multiply, but it's really hard to make "short time" routine. Anyone got any idea?


About Divu/Divs

Classical lsr bcs sbc rol too slow.

But a/b= e^(lna-lnb) looks quite fast with e^x matrix, but
quite inaccurate.

Somebody got other "faster" idea for it? Particular 16/16bit routines.


 
... 29 posts hidden. Click here to view all posts....
 
2006-10-16 18:55
Krill

Registered: Apr 2002
Posts: 2980
Just use drive code and the plain old binary mul/div loops suit perfectly. Works great for me. :)
2006-10-17 00:10
White Flame

Registered: Sep 2002
Posts: 136
ready.: Unfortunately, that's a multiply routine, not a divide. You're multiplying by a percentage or ratio, which is great if you already have the ratio, but doesn't avoid the division if you need to find it.
2006-10-17 04:48
ready.

Registered: Feb 2003
Posts: 441
White Flame: check it out better, it's a division.

Each lsr divides by 2, right? Many by 2 divisions provide 1/2, 1/4, 1/8,.... then sum toghether the terms you need to get the percentage you want of your original number. Don't you agree?

Besides in this way, there's no need for tables.

ciao,
Ready.
2006-10-17 06:47
Luke

Registered: Dec 2004
Posts: 19
ready. - you are wrong :)
1) x = lda #$7f lsr lsr lsr lsr lsr lsr lsr sta $nn (nn)=$00

so for example 3x #$7f/ 128 = 0 ???!!!
Too many lost carry flags. It's inaccurate at all.
2006-10-17 06:48
JackAsser

Registered: Jun 2002
Posts: 2014
@ready: So... if a line is dx=34 and dy=78 and I wanna calculate the line slope dx/dy = 34/78, how do I do that using your algorithm?
2006-10-17 11:04
ready.

Registered: Feb 2003
Posts: 441
Luke:
x = lda #$7f lsr lsr lsr lsr lsr lsr lsr sta $nn (nn)=$00

so for example 3x #$7f/ 128 = 0 ???!!!

is absolutely correct. #$7f=127 and 127/128=0.something. My routine deals only with integer.
2006-10-17 11:07
ready.

Registered: Feb 2003
Posts: 441
Luke:
x = lda #$7f lsr lsr lsr lsr lsr lsr lsr sta $nn (nn)=$00

so for example 3x #$7f/ 128 = 0 ???!!!

is absolutely correct. #$7f=127 and 127/128=0.something. My routine deals only with integer.
2006-10-17 12:03
Luke

Registered: Dec 2004
Posts: 19
No :D 3x ($7f/128) = dec 2.97 not 0 :)
Show me that zoomer :))))))

edit: JackAsser: :DDDDDDD 34/78 = 0 too:D Did you know?:D
2006-10-17 12:16
ready.

Registered: Feb 2003
Posts: 441
Luke: ok, you are right, but working with integers, it also depends on what operation you do first. If you do 3x#$7f=#$17d and then divide by 128 you get a more accurate result. The routine I put in my previous post was meant to be used for 8bit division. I just wanted to give the idea, not the detailed routine.

Doing division first causes you to loose significant digits.

For 16bit number, of course you have to use ror instead of lsr.

JackAsser: the same answer is valid for you too. #$34/#$78 is less then 1, so you should do something like #$134/#$78 to store some significant digits into memory as a result.

But so far I have used this division routine just with 8bit numbers and it works.

Ready.
2006-10-17 12:22
Luke

Registered: Dec 2004
Posts: 19
I understand, sorry :)
Previous - 1 | 2 | 3 | 4 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Aomeba/Artline Desig..
Lazycow
Mike
zscs
TheRyk/MYD!
LKP/CFN
kbs/Pht/Lxt
t0m3000/hf^boom!^ibx
Case/Padua
St0rmfr0nt/Quantum
MWR/Visdom
Chesoner/House Designs
katon/Lepsi De
The Syndrom/TIA/Pret..
Youth
Guests online: 135
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Coders
1 Axis  (9.8)
2 Graham  (9.8)
3 Lft  (9.8)
4 Crossbow  (9.8)
5 HCL  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.054 sec.