[HN Gopher] Comparing 6502 Multiply Routines
       ___________________________________________________________________
        
       Comparing 6502 Multiply Routines
        
       Author : adunk
       Score  : 35 points
       Date   : 2023-12-11 09:19 UTC (13 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | JonChesterfield wrote:
       | Exactly what the title sounds like. At least one person has gone
       | very far down this rabbit hole, possibly two people. A joy to
       | read through, thank you for posting.
       | 
       | This is the sort of comparison that would be great to do for a
       | compiler runtime implementation. Integer division comes to mind.
       | Hard to justify the time.
        
         | Someone wrote:
         | > Integer division comes to mind.
         | 
         | In case you don't know about it: https://libdivide.com/
         | 
         | Does what you ask for, but for 8-bit CPUs like the 6502, you
         | probably would want to do additional work (I would at least
         | read the output of the C compiler to see whether there's an
         | 'easily' cuttable corner left)
        
           | duskwuff wrote:
           | > In case you don't know about it: https://libdivide.com/
           | 
           | The division routines generated by libdivide assume that fast
           | integer multiplication is available. If it isn't, you may be
           | better off with other approaches.
        
       | saulpw wrote:
       | I don't miss those early days of programming. It's fun to
       | optimize and it's amazing what you can do with minimal resources,
       | but it took an incredible amount of effort to get a 70s-era
       | computer to do elementary school arithmetic fast enough to be
       | useful. People spent their lives working on analyses like this,
       | only to find in a scant few years that the next chip has it
       | built-in as a single instruction.
        
         | jandrese wrote:
         | To be fair, those chips made multiply a single instruction, but
         | they would take tens or hundreds of clock cycles to complete.
         | What it really saved you was precious working memory, no longer
         | needing to consume a significant chunk of memory with a lookup
         | table in order to multiply at a decent speed. If your platform
         | has 16kb of working memory then a 2k lookup table is a huge
         | ask. Even a small 512k lookup table is serious chunk of your
         | memory budget, you have to really consider if wasting hundreds
         | of clock cycles per multiply is a better option.
        
         | wvenable wrote:
         | I love these early days of programming as I do it as hobby.
         | What's pretty amazing is how much you can do without any
         | multiplication or division at all. With add, substract, and
         | shifts you can do a surprising amount on a computer.
        
         | tonyedgecombe wrote:
         | [delayed]
        
       | jandrese wrote:
       | The graphical error plots for the versions that approximate are a
       | joy to behold. You can clearly see the ringing and how the error
       | bars tend to grow larger with bigger inputs.
        
       | sunpazed wrote:
       | I'm writing a pinball game in assembly for the original Gameboy,
       | and recently had to hand-craft multiply, division and cosine
       | routines to trade off accuracy for spare cycles. Something like
       | this would have come in handy!!
        
       ___________________________________________________________________
       (page generated 2023-12-11 23:00 UTC)