Home About Projects PIC code SX code

Most of this code has originated from requests and challenges on the PICList mailing list.

I tried to debug the routines as much as possible (for a hobby), but no guarantees. In case you find a bug, please let me know.

Please send any questions or comments to golovchenko@mail.ru, or the PICList, as many nice folks hang around there and most probably will be glad to help you.

Routine Name Size, instructions Max timing, cycles Temporary registers Notes
Multiplication
24 by 24 bits 29 513 1
Division
8 by 8 bits to 24 bit floating point 41 413 1
16 by 8 bits with Q16.16 fixed point result 39 460 1
24 by 16 bits (and 24 by 15) 27/28 584/581 3
32 by 16 bits using 16 by 16 bits with a 16 bit result 36 345 2/4
48 by 24 bits (and 48 by 23) 58/51 1458/1266 5/4 my versions at the bottom
Scaled 8 bit: x 256*x/y 28 281 3
Approximate 8 bit reciprocal: 32768/x 19 47 0
Divide 14 bit integer using a fixed point divisor and result (7Q8 format) 27 264 0
Square
10 bits 68 70 0 this is a debugged John Payson's version
Routine Name Size, instructions Max timing, cycles Temporary registers Notes
Square Root
24 bit floating point 85 406 6 IEEE<>Microchip format conversion
12 bit integer 32 118 3
8 bit 20 66 2
8 bit fast 53 19 0
8 bit small 9 87 0 Idea from Scott Dattalo, tweak by Dmitry Kiryashov
Powers and logarithms
Fixed point Q0.16 log2x 105 323 3 also notes on xy
Fixed point Q6.10 2x 121 291 4
CORDIC
Vector magnitude, 16 bits 147 ~1600/800 4
Routine Name Size, instructions Max timing, cycles Temporary registers Notes
Radix Conversion
16 bit binary to 5 digit decimal 68 226 0 strips a digit at a time
16 bit binary to 3 digit decimal 34 108 0 based on John Payson's 5 digit version
16 bit binary to 3 digit decimal 56 57 0 based on Scott Dattalo's 8 bit BIN2BCD
5 digit decimal to 16 bit binary 35 36 0
5 digit decimal (BCD) to 16 bit binary 23 341 1
Miscellaneous
8 bit random number generator 10 10 0 my version at the bottom
Delay exactly N cycles - - 0 scalable for any N size
Routine Name Size, instructions Max timing, cycles Temporary registers Notes

Questions:

Comments:

Says: Vittorio Capini replies: hi Mr. Nikolai. In the code "Fixed Point Q(0.16) log2(x) I do not understand how to build the table, starting from the relationship [log2(0.5)-log2(0.5:0.5/16:1)]. what is it log2(0.5:0.5/16:1) ? can you take an example.

See also:

Vittorio Capini Says: