English Amiga Board Quick reciprocal?
 Register Amiga FAQ Rules & Help Members List  /  Moderators List Today's Posts Mark Forums Read

 26 April 2017, 05:26 #1 earok Registered User   Join Date: Dec 2013 Location: Auckland Posts: 1,672 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.
 26 April 2017, 06:02 #2 a/b Registered User   Join Date: Jun 2016 Location: europe Posts: 62 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...
26 April 2017, 06:10   #3
earok
Registered User

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

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

 Similar Threads Thread Thread Starter Forum Replies Last Post zerohour1974 project.WHDLoad 2 18 March 2015 22:14 Jackoland New to Emulation or Amiga scene 3 15 July 2014 06:49 Melonfish Hardware mods 5 10 April 2010 11:35 narud17 support.WinUAE 2 30 June 2005 20:04 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home News Main     Amiga scene     Retrogaming General Discussion     Nostalgia & memories Support     New to Emulation or Amiga scene         Member Introductions     support.WinUAE     support.WinFellow     support.OtherUAE     support.FS-UAE     support.Hardware         Hardware mods         Hardware pics     support.Games     support.Demos     support.Apps     support.Amiga Forever     support.Amix     support.Other Requests     request.UAE Wishlist     request.Old Rare Games     request.Demos     request.Apps     request.Modules     request.Music     request.Other     Looking for a game name ?     Games images which need to be WHDified abime.net - Hall Of Light     HOL news     HOL suggestions and feedback     HOL data problems     HOL contributions abime.net - Amiga Magazine Rack     AMR news     AMR suggestions and feedback     AMR data problems     AMR contributions abime.net - Home Projects     project.Amiga Lore     project.EAB     project.IRC     project.Mods Jukebox     project.Wiki abime.net - Hosted Projects     project.aGTW     project.APoV     project.ClassicWB     project.Jambo!     project.Green Amiga Alien GUIDES     project.Maptapper     project.Sprites     project.WinUAE - Kaillera Other Projects     project.Amiga Demo DVD     project.Amiga Game Factory     project.CARE     project.EAB File Server     project.CD32 Conversion     project.Game Cover Art         GCA.Feedback and Suggestions         GCA.Work in Progress         GCA.Cover Requests         GCA.Usefull Programs         GCA.Helpdesk     project.KGLoad     project.MAGE     project.Missing Full Shareware Games     project.SPS (was CAPS)     project.TOSEC (amiga only)     project.WHDLoad         project.Killergorilla's WHD packs Misc     Amiga websites reviews     MarketPlace         Swapshop     Collections     EAB's competition Coders     Coders. General         Coders. Releases         Coders. Tutorials     Coders. Asm / Hardware     Coders. System         Coders. Scripting         Coders. Nextgen     Coders. Language         Coders. C/C++         Coders. AMOS         Coders. Blitz Basic     Coders. Contest Off Topic     OT - General     OT - Technical     OT - Entertainment     OT - Sports     OT - Gaming

All times are GMT +2. The time now is 19:13.

 -- EAB3 skin ---- EAB2 skin ---- Mobile skin Archive - Top