Search found 11 matches

by ilmenit
Mon Feb 07, 2022 5:28 am
Forum: Programming
Topic: Comparing 16 bit Integer Square Root routines (SQRT)
Replies: 18
Views: 3998

Re: Comparing 16 bit Integer Square Root routines (SQRT)

TobyLobster wrote:
This improves the performance, but as it stands my sqrt10.a is still a little bit faster in general and smaller (no tables).
Your procedure is amazing and I'm going to steal it for my project, if you don't mind :-)
by ilmenit
Sat Feb 05, 2022 11:11 pm
Forum: Programming
Topic: Comparing 16 bit Integer Square Root routines (SQRT)
Replies: 18
Views: 3998

Re: Comparing 16 bit Integer Square Root routines (SQRT)

Thanks, very good points about the rounding. I needed it for an Euclidean distance and rounding problem was negligible for me, so I didn't catch it before.
The code is on the MIT license so feel free to use it or add it to your benchmark.
by ilmenit
Thu Feb 03, 2022 9:19 am
Forum: Programming
Topic: Comparing 16 bit Integer Square Root routines (SQRT)
Replies: 18
Views: 3998

Re: Comparing 16 bit Integer Square Root routines (SQRT)

So you need an integer SQRT function, but which to choose?
Here is my implementation that is using 2 tables of 256 bytes and binary search. The code is in MADS assembler syntax for table generation.

; 2 tables with low and high bytes of all x*x values
squared_table_lo:
:256 dta l(#*#)
squared ...
by ilmenit
Mon Jan 03, 2022 7:51 pm
Forum: Programming
Topic: short 8bit x 16bit multiplication by 16
Replies: 12
Views: 1273

Re: short 8bit x 16bit multiplication by 16

that's the shortest one, indeed. Great job, thank you!
Hold on there, buddy! mul: ; result16 = factor8 * 16
lda value
sta result
lda #$10
mul2:
asl result
rol
bcc mul2
sta result+1
rts
Wow, you are a 6502 wizard! :-)
As the others pointed, in such sizecoding everything depends on what ...
by ilmenit
Mon Jan 03, 2022 12:20 am
Forum: Programming
Topic: short 8bit x 16bit multiplication by 16
Replies: 12
Views: 1273

Re: short 8bit x 16bit multiplication by 16

John West wrote:
ilmenit wrote:
Are you sure the code is correct? With either 4 or 5 ROLs it's giving a wrong result.
The code I tested was right, but that was a hurried re-write after my first go, and I didn't edit the post correctly. Swap the AND #15 and AND #240 and it should work better.
Correct, thanks!
by ilmenit
Mon Jan 03, 2022 12:18 am
Forum: Programming
Topic: short 8bit x 16bit multiplication by 16
Replies: 12
Views: 1273

Re: short 8bit x 16bit multiplication by 16

barrym95838 wrote:
If I understand the problem correctly, my proposed solution is 17 bytes if your variables are in ZP, and 21 bytes if not
that's the shortest one, indeed. Great job, thank you!
by ilmenit
Mon Jan 03, 2022 12:12 am
Forum: Programming
Topic: short 8bit x 16bit multiplication by 16
Replies: 12
Views: 1273

Re: short 8bit x 16bit multiplication by 16

John West wrote:
If everything is in zero page, I think that's 18 bytes. You can of course replace the TAY/TYA with PHA/PLA without changing the size.
Are you sure the code is correct? With either 4 or 5 ROLs it's giving a wrong result.
by ilmenit
Sun Jan 02, 2022 11:30 pm
Forum: Programming
Topic: short 8bit x 16bit multiplication by 16
Replies: 12
Views: 1273

short 8bit x 16bit multiplication by 16

Hi,

I'm looking for a way to shorten (by the size, not the cycles) a procedure that is performing multiplication of 8bit value to 16bit result (where the result address is not overlapping the value address). So far I got it down to 21 ($15) bytes. Any ideas how to shorten it more?


org $80

val ...
by ilmenit
Wed Sep 09, 2020 11:08 am
Forum: Programming
Topic: Fast scaling down (or "hex percent") of 8bit value
Replies: 7
Views: 1286

Re: Fast scaling down (or "hex percent") of 8bit value

Thank you all for great answers so far! I'll need some time to process them to find the best approach to my cases. For sure idea of using logarithms is a good one and worth checking from accuracy perspective. Scaling is multiplication and there are some very fast multiplication routines e.g. https ...
by ilmenit
Tue Sep 08, 2020 8:49 am
Forum: Programming
Topic: Fast scaling down (or "hex percent") of 8bit value
Replies: 7
Views: 1286

Fast scaling down (or "hex percent") of 8bit value

Hi,

What is the best (fast) method on 6502 to make a scaling down of specific 8bit value by other 8bit value.
Lets say I have byte value A and I want to scale it by [0,1) in form of byte value B ($0-$FF, so $80 is 0.5).

scaled= A * B (hex%)

A = $C0
B = $80
scaled = $C0 * $80 / $100
scaled ...
by ilmenit
Thu Apr 23, 2020 1:02 pm
Forum: Programming
Topic: Advanced optimizations in C for CC65
Replies: 2
Views: 972

Advanced optimizations in C for CC65

Hi,
I wrote an article about optimizing C code for 6502, aiming CC65 compiler. I think it may be useful also for other programming environments, therefore sharing it here too. Enjoy the reading! All comments are welcome.
https://github.com/ilmenit/CC65-Advanced-Optimizations