![]() |
![]() |
![]() |
#1 |
Registered User
![]() Join Date: Dec 2013
Location: Auckland
Posts: 1,625
|
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. |
![]() |
![]() |
|
|
![]() |
#2 |
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... |
![]() |
![]() |
#3 | |
Registered User
![]() Join Date: Dec 2013
Location: Auckland
Posts: 1,625
|
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:
![]() |
|
![]() |
![]() |
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
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 |
|
|