logoalt Hacker News

mxfactorial • today at 6:48 PM • 2 replies • view on HN

> For a signed multiply, I got down to 32 instructions.

gist pls


Replies

jdiff • today at 10:34 PM

https://gist.github.com/different55/08aff15e0f3b67b1feb1fd16...

It's for the Uxn VM, it's a multiply between a signed sample and an unsigned Q13 coefficient. My coefficients are almost always positive, or known negative in advance. If negative, I rewrite an ADD2 in the filter into a SUB2.

Ground rules for Astra were that JMP2r's (returns) aren't counted, no use of the zero page, and it must return the correct result within 9LSBs, which is the error from skipping the smallest partial product.

bena • today at 6:59 PM

Signed multiply means doing multiplication on signed numbers. So you have to care about and implement rules about positive and negative numbers. Fixed point means numbers where the decimal point in a real number is at a fixed point. You can have 4 numbers before the decimal and 5 after; 1 before, 12 after; etc.

This essentially lets you treat the number as an integer.

Code golf is the practice of writing code with the fewest possible number of lines or instructions.

If he was doing this on a particular processor, he could be talking about assembler instructions.

But basically, what he's saying is that he wrote an algorithm that correctly multiplies two arbitrary positive or negative numbers using only 32 instructions.

➕ show 2 replies