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: 5094
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: 2014
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
csabanw
Brataccas/HF
Genius/Xenon
JackAsser/Booze Design
Jammer
Flex/Artline Designs
Guests online: 99
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 Triad  (9.3)
5 Censor Design  (9.3)
Top Swappers
1 Derbyshire Ram  (10)
2 Jerry  (9.8)
3 Violator  (9.7)
4 Acidchild  (9.7)
5 Cash  (9.6)

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