solidcorp Posted January 11, 2013 Share Posted January 11, 2013 This is an awesome paper on computational math http://www.jjj.de/fxt/fxtbook.pdf Matters Computational Ideas, Algorithms, Source Code In depth explanations of various computational and math techniques, tricks, and gotchas. The first section deals with integers and binary and is totally relevant to 6502 programming. It's a great reference, getting into details of various math operations with an eye on pitfalls and optimization. ( Thinking of you [and DiMath] when I posted this Selgus! ) 4 Quote Link to comment Share on other sites More sharing options...
RevEng Posted January 12, 2013 Share Posted January 12, 2013 Just starting it, and it looks really promising... wrapping my brain around "average without overflow", as I have AVR code that would benefit from that. Cool stuff. Thanks for sharing! Quote Link to comment Share on other sites More sharing options...
GroovyBee Posted January 12, 2013 Share Posted January 12, 2013 Jack Crenshaw's book entitled "Math Toolkit for Real-Time Programming" is a good one to have on the shelf. There are some interesting articles here too. 2 Quote Link to comment Share on other sites More sharing options...
solidcorp Posted January 12, 2013 Author Share Posted January 12, 2013 Right off the bat (section 1.1.4) I found this 2's compliment signed integer gotcha - it's an oldie but a goodie! if ( x<0 ) x = -x; // assume x positive here (WRONG!) This is because there are two numbers in the set of base two integers of a given size that are their own negative: 0 and 2^(bitSizeOfType). i.e. To negate a signed two's compliment integer, you toggle or flip all the bits and increment the number, considering the byte -128 (0x80): 10000000 toggled 01111111 incremented 10000000 => thus, it's its own negative. The paper looks like it has all the bit and math tricks I know and much much more. 1 Quote Link to comment Share on other sites More sharing options...
djmips Posted January 30, 2013 Share Posted January 30, 2013 (edited) I'm not sure where my copy of this book is right now. I think in a box but Hacker's Delight by Henry S. Warren was indeed a delight! http://www.amazon.co...n/dp/0201914654 Looking at the Matters Computational book there is some overlap but the scope of Matters Computational is huge! nice. Also saw that there was his home page http://www.jjj.de/ and a page on the book with more good stuff. This is really a gold mine and yes, I knew much of this already but it's pretty neat to see it collated and presented. http://www.jjj.de/fx...ge.html#fxtbook I have to admit I started to get overwhelmed because you referred to it as a paper. This BOOK is free but it's also available in print: http://www.amazon.co...e/dp/3642147631 Edited January 30, 2013 by djmips Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted January 30, 2013 Share Posted January 30, 2013 Seems like a good book (the author is a German ). I liked the bit manipulation tricks he described, some are even new to me and could be very helpful eventually. But I couldn't find the "double XOR trick" as I call it. It is useful when you only want to exchange some bits of a byte with the bits of another byte. Instead of: ; replace the lower 4 bits of var1 with the lower 4 bits of var2 (without changing the upper 4 bits of var1) lda var2 and #%1111 sta temp lda var1 and #~%1111 ora temp sta var1 you can do: lda var1 eor var2 and #~%1111 eor var2 sta var1 Quote Link to comment Share on other sites More sharing options...
djmips Posted January 31, 2013 Share Posted January 31, 2013 Seems like a good book (the author is a German ). I liked the bit manipulation tricks he described, some are even new to me and could be very helpful eventually. But I couldn't find the "double XOR trick" as I call it. It is useful when you only want to exchange some bits of a byte with the bits of another byte. The following is equivalent to your code ; replace the lower 4 bits of var1 with the lower 4 bits of var2 (without changing the upper 4 bits of var1) lda var1 eor var2 and #%1111 eor var1 sta var1 and doing it that way means you could also ; swap the lower 4 bits of var1 with the lower 4 bits of var2 (without changing the upper 4 bits of var1 or var2) lda var1 eor var2 and #%1111 tax eor var1 sta var1 txa eor var2 sta var2 And that technique is covered in Hacker's Delight with three variations. The variation I used was © The nomenclature is the + in a circle is XOR ; three vertical bars is ! XOR; a bar over the mask is a NOT 1 Quote Link to comment Share on other sites More sharing options...
djmips Posted January 31, 2013 Share Posted January 31, 2013 Right off the bat (section 1.1.4) I found this 2's compliment signed integer gotcha - it's an oldie but a goodie! if ( x<0 ) x = -x; // assume x positive here (WRONG!) This is because there are two numbers in the set of base two integers of a given size that are their own negative: 0 and 2^(bitSizeOfType). i.e. To negate a signed two's compliment integer, you toggle or flip all the bits and increment the number, considering the byte -128 (0x80): 10000000 toggled 01111111 incremented 10000000 => thus, it's its own negative. The paper looks like it has all the bit and math tricks I know and much much more. I've had this as a bug in the past. A good reminder. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.