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 > Seriously Fast Multiply - Codebase
2014-06-25 00:09
Voltage
Account closed

Registered: Jul 2008
Posts: 14
Seriously Fast Multiply - Codebase

So I've used the Seriously Fast Multiplier routine from codebase ... http://codebase64.org/doku.php?id=base:seriously_fast_multiplic..

Works great and I mostly understand it. The unsigned multiplies I get, but the sign conversion process I don't understand.

                ; Apply sign (See C=Hacking16 for details).
                lda T1                                     
                bpl :+                                     
                    sec                                    
                    lda PRODUCT+1                          
                    sbc T2                                 
                    sta PRODUCT+1                          
                :                                          
                lda T2                                     
                bpl :+                                     
                    sec                                    
                    lda PRODUCT+1                          
                    sbc T1                                 
                    sta PRODUCT+1                          
                :                                          


I'm trying to do a 24bit (signed) x 8bit (signed) multiply.

I have the unsigned part working and would like to use the same method as about to sort out the signs (after the multiplication).

I can work around it by getting the ABS values before multiplying and then apply the sign after, but this seems wasteful when the above method doesn't apply ABS before the mult.

I read and re-read issue 16 of C=Hacking but can't find an explanation of how this works.

I also tried it out "on paper" and can see that it works for 8bit x 8bit and also for 16bit x 16bit, but I don't understand why it works.
2014-06-25 05:50
Oswald

Registered: Apr 2002
Posts: 5017
maybe the reference is incorrect, I remember this method is by stephen judd, and is explained in one of the C= hackings, try to look into issues around 16 looking for judd's articles.
2014-06-25 06:37
j0x

Registered: Mar 2004
Posts: 215
A negative number, say -30, will be represented in two's complement as a=256-30

Multiply that by b (assumed to be positive):

(256-30)*b = 256*b - 30*b

What we want is "-30*b", so we need to subtract 256*b, which is exactly what the code does.

If b is also negative, we need to subtract 256*a from the result to correct for this.
2014-06-25 11:08
Voltage
Account closed

Registered: Jul 2008
Posts: 14
ok that makes sense. Thanks j0x, much appreciated.
2014-06-25 13:26
JackAsser

Registered: Jun 2002
Posts: 1989
Quote: ok that makes sense. Thanks j0x, much appreciated.

Sorry for not elaborating the details of sign reconstruction in the article. :P I used that method extensively in the 3D-part of Andropolis. Great that j0x could fill in the details. I did the same experiments on paper to convince myself it actually works. :D
2014-06-30 07:21
Voltage
Account closed

Registered: Jul 2008
Posts: 14
Hey JackAsser, big fan of the 3d in Andropolis, very nice.

Thx for sharing the details on codebase.

I hope to have something nice to show you all by Syntax 2014...
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
Krill/Plush
Menace/Spaceballs
Fungus/Nostalgia
Bieno/Commodore Plus
mutetus/Ald ^ Ons
Marco/DDM
Didi/Laxity
Guests online: 65
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Bromance  (9.6)
10 Memento Mori  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top NTSC-Fixers
1 Pudwerx  (10)
2 Booze  (9.7)
3 Stormbringer  (9.7)
4 Fungus  (9.6)
5 Grim Reaper  (9.3)

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