English Amiga Board Amiga Lore


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

 
 
Thread Tools
Old 26 April 2017, 05:26   #1
earok
Moderator

 
Join Date: Dec 2013
Location: Auckland
Posts: 1,481
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  
AdSense AdSense  
Old 26 April 2017, 06:02   #2
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 55
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, 06:10   #3
earok
Moderator

 
Join Date: Dec 2013
Location: Auckland
Posts: 1,481
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)

Quote:
Dim InverseTable.q(32767)
TempQ.q=0
for TempL.l = 1 to 32766
Poke.l &TempQ,TempL LSL 8
InverseTable(TempL)=1/TempQ
next
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  
AdSense AdSense  
 


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 22:14
Hi all quick question Jackoland New to Emulation or Amiga scene 3 15 July 2014 06:49
Quick Lithiumectomy. Melonfish Hardware mods 5 10 April 2010 11:35
quick start narud17 support.WinUAE 2 30 June 2005 20:04
A Quick Question Reps Amiga scene 5 27 October 2003 10: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 19:50.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Page generated in 0.16683 seconds with 14 queries