English Amiga Board

Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

Thread Tools
Old 26 April 2017, 06:26   #1
Registered User

Join Date: Dec 2013
Location: Auckland
Posts: 1,894
Quick reciprocal?

I'm doing a rudimentary 3D engine and I'm finding reciprocal operations on the quick type to be the biggest bottleneck right now, ie 1 / X

Has anyone come up with a solution for this? I was thinking of doing a lookup table of all (or at least a subset) possible reciprocal values - I'm OK with it being a little memory hungry.
earok is offline  
Old 26 April 2017, 07:02   #2
Registered User

Join Date: Jun 2016
Location: europe
Posts: 81
I generally always use a lookup table in such a situation; 1/x=table[x], x/y=x*table[y], ...

If you have to support a larger input range: 1/x = a / (a*x) = (a/x) / a = (1 / (x/a)) / a = table[x/a]/a, where a = log2(table_size)
E.g. in c/c++ for simplicity:
if (x < 1024) return table[x];
if (x < 4096) return table[x>>2]>>2;
return table[x>>N]>>N;
Add extra compares if you have to support negative numbers...
a/b is offline  
Old 26 April 2017, 07:10   #3
Registered User

Join Date: Dec 2013
Location: Auckland
Posts: 1,894
Came up with a workable solution.

The limitations are:
- 131,068 bytes of memory are burned up
- 8 bits of fractional precision are lost (precision to 1/256 is fine for me, I can probably reduce this further to save memory)
- Maximum whole number value that can be fed into it is 128 (I don't need that big a draw distance, likewise I could probably this further to save memory)

Dim InverseTable.q(32767)
for TempL.l = 1 to 32766
Poke.l &TempQ,TempL LSL 8
Then it's just a case of Shifting the Quick type's longword by 8 bits right, and feeding it into the table. Much quicker
earok is offline  

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Quick question zerohour1974 project.WHDLoad 2 18 March 2015 23:14
Hi all quick question Jackoland New to Emulation or Amiga scene 3 15 July 2014 07:49
Quick Lithiumectomy. Melonfish Hardware mods 5 10 April 2010 12:35
quick start narud17 support.WinUAE 2 30 June 2005 21:04
A Quick Question Reps Amiga scene 5 27 October 2003 11:42

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 09:31.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Page generated in 0.06273 seconds with 15 queries