You are right, what an idiot I am ('specially considering that I did
that very thing two years ago when emulating bios for cowbite). I
need to get more sleep. Kids, make sure you finish school *before*
going to work full time, rather than concurrently.
Anyway, the 2.30 square root is around 50% faster (according to my
ghetto colored-scanlines measuring method). I did not test this
rigoruosly, however.
Also, I actually contacted the original author of that code, and he
wrote back saying that rather than shifting right by 10 at the end, I
can simply replace the "count = 30;" with "count = 20;" and I'll get
the same results for less iterations. Looking at Demian's
explanation below, I'd guess the '20' comes by doing 30 - (30-n)/2,
where n is my 10 binary places.
Tom
--- In gbadev@yahoogroups.com, "Graham Wall" <graham@t...> wrote:
> Do bear in mind that if you test the speed of the BIOS functions on
an
> emulator the result will not necessarily be indicative of what
happens on
> real hardware. The emulators generally just do a sqrt in native
80x86 code
> and return the result.
>
> Graham
>
> -----Original Message-----
> From: Thomas [mailto:sorcererxiii@y...]
> Sent: 09 December 2003 16:23
> To: gbadev@yahoogroups.com
> Subject: [gbadev] Re: Fixed Point Square Root
>
>
> Ok, testing has revealed that the bios function is a good 10 times
> faster than the 2.30 function (I didn't measure it precisely - all I
> need to know is that it's faster). To get more precision, I
multiply
> the input by 4096 then divide the result by sqrt(4096).
>
> (Sqrt(fixedval << 12) << 5) >> 6
>
> Of course, this limits us to a max input of 512.0, which is
> sufficient for what it's being used.
>
> Tom
>
>
> --- In gbadev@yahoogroups.com, "Thomas" <sorcererxiii@y...> wrote:
> > Thanks, I'll try that out . . . for some reason my brain is not
> > working on this issue (years of only having to press the square
> root
> > key on a calculator?). I also figured out that I can use the bios
> > square root (I think) by realizing that
> >
> > sqrt(n * 1024) = sqrt(n)*sqrt(1024) = sqrt(n) << 5.
> >
> > I'll need to compare to see which method is faster/more accurate.
> >
> > Tom
> >
> >
> > --- In gbadev@yahoogroups.com, "Damian Yerrick" <d_yerrick@h...>
> > wrote:
> > > --- In gbadev@yahoogroups.com, "Thomas" <sorcererxiii@y...>
wrote:
> > > > I'd like a general algorithm in C or psuedocode that could be
> > > > used for different fraction sizes just be changing a #define
> > > > value. I've searched and found some that worked for specific
> > > > cases (like one that was 2.30)
> > >
> > > For reference, here's an example of a 2.30 square root function:
> > > http://www.worldserver.com/turk/opensource/FractSqrt.c.txt
> > >
> > > > but I could figure out how to adapt it for 22.10.
> > >
> > > The given code gives sqrt(1<<30) == 1<<30. You want
> > > sqrt(1<<10) == 1<<10 and sqrt(1<<30) == 1<<20. So use the
> > > 2.30 code and just shift the result right by 10 binary places.
> > > In general, if you have n fractional places (in your case 10),
> > > where n is odd and 0 <= n <= 30, then shift right by (30-n)/2
> > > after calling the 2.30 routine.
> > >
> > > Division is rather slow on ARM; don't use the division based
> > > Newton's method code that somebody else just posted.
> > >
> > > --
> > > Damian
>
>
>
> Yahoo! Groups Sponsor
> ADVERTISEMENT
>
>
>
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.