Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Date | 2012-04-26 01:38 +0200 |
|---|---|
| From | Terje Mathisen <"terje.mathisen at tmsw.no"> |
| Newsgroups | comp.arch, comp.lang.c |
| Subject | Re: ffs16 |
| References | <jn1tku$pga$1@reader1.panix.com> <v65g69-41e2.ln1@ntp6.tmsw.no> <jn6tjv$a39$1@reader1.panix.com> <9kmj69-hhi2.ln1@ntp6.tmsw.no> <jn9q4m$4dk$1@reader1.panix.com> |
| Message-ID | <qgem69-75r2.ln1@ntp6.tmsw.no> (permalink) |
Cross-posted to 2 groups.
Joe keane wrote:
> In article<9kmj69-hhi2.ln1@ntp6.tmsw.no>,
> Terje Mathisen<"terje.mathisen at tmsw.no"> wrote:
>> When did you last time the uint16->float->exponent trick?
>
> just now
>
> time in us
>
> 'server'
> 239 testfx
> 270 testfy
>
> 'PC'
> 211 testfx
> 186 testfy
OK, so the 'x' version is 64K tests of the table lookup, while 'y' is
the same number of fp conversions.
Problem one: The table lookups will have 100% cache hits since you are
doing nothing else, so you don't measure the misses you'll get in a real
program.
Problem two: The tests have a really funky way to randomize the tests
(multiply by 31), which means that the table lookup version will have
very close to 100% branch prediction hits for the pattern of switching
between the top and low byte.
Problem three: How common will zero be?
This affects the branch hit ratio for the fp version.
All that said, you are getting effectively the same speed for both
versions, and the fp code has zero table space so better cache behavior.
Terje
>
> -- fhsx.c
> static const char fhstab[256] =
> {
> 99, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
> 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
> 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
> [...]
> };
>
>
> extern int kk_fhsx(int mask)
> {
> int ret;
>
> ret = (mask& 0xFF00) != 0 ? fhstab[mask>> 8& 0xFF] + 8 :
> fhstab[mask& 0xFF];
> return ret;
> }
>
> -- fhsy.c
> union u
> {
> float f;
> unsigned int u;
> };
>
>
> extern int kk_fhsy(int mask)
> {
> union u t;
> int bex;
> int ret;
>
> t.f = (float) mask;
> bex = t.u>> 23;
> ret = bex - 127;
> return ret;
> }
>
> -- testfx.c
> #include<stdio.h>
>
> static void testfx(int *sump);
> extern int kk_fhsx(int mask);
>
>
> [main]
>
>
> static void testfx(int *sump)
> {
> int m;
>
> for (m = 0x1; m<= 0xFFFF; m++)
> {
> int mask;
> int ret;
>
> mask = 31 * m& 0xFFFF;
> ret = kk_fhsx(mask);
> /* *sump += ret; */
> }
> }
>
> -- testfy.c
> #include<stdio.h>
>
> static void testfy(int *sump);
> extern int kk_fhsy(int mask);
>
>
> [main]
>
>
> static void testfy(int *sump)
> {
> int m;
>
> for (m = 0x1; m<= 0xFFFF; m++)
> {
> int mask;
> int ret;
>
> mask = 31 * m& 0xFFFF;
> ret = kk_fhsy(mask);
> /* *sump += ret; */
> }
> }
--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
Back to comp.arch | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
ffs16 jgk@panix.com (Joe keane) - 2012-04-22 21:36 +0000
Re: ffs16 Keith Thompson <kst-u@mib.org> - 2012-04-22 15:23 -0700
Re: ffs16 Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-04-22 20:37 -0400
Re: ffs16 Philip Lantz <prl@canterey.us> - 2012-04-24 06:36 -0700
Re: ffs16 Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-04-24 20:32 -0400
Re: ffs16 Philip Lantz <prl@canterey.us> - 2012-04-25 00:30 -0700
Re: ffs16 Terje Mathisen <"terje.mathisen at tmsw.no"> - 2012-04-23 16:22 +0200
Re: ffs16 Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-04-23 21:46 -0400
Re: ffs16 Terje Mathisen <"terje.mathisen at tmsw.no"> - 2012-04-24 14:16 +0200
Re: ffs16 Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-04-24 20:40 -0400
Re: ffs16 jgk@panix.com (Joe keane) - 2012-04-24 19:06 +0000
Re: ffs16 Terje Mathisen <"terje.mathisen at tmsw.no"> - 2012-04-25 00:38 +0200
Re: ffs16 jgk@panix.com (Joe keane) - 2012-04-25 20:08 +0000
Re: ffs16 "James Van Buskirk" <not_valid@comcast.net> - 2012-04-25 15:06 -0600
Re: ffs16 "James Van Buskirk" <not_valid@comcast.net> - 2012-04-25 16:30 -0600
Re: ffs16 jgk@panix.com (Joe keane) - 2012-04-25 21:25 +0000
Re: ffs16 Terje Mathisen <"terje.mathisen at tmsw.no"> - 2012-04-26 01:38 +0200
Re: ffs16 jgk@panix.com (Joe keane) - 2012-04-26 19:34 +0000
Re: ffs16 jgk@panix.com (Joe keane) - 2012-04-26 20:41 +0000
Re: ffs16 Terje Mathisen <"terje.mathisen at tmsw.no"> - 2012-04-27 02:47 +0200
Re: ffs16 MitchAlsup <MitchAlsup@aol.com> - 2012-04-23 13:01 -0700
Re: ffs16 Terje Mathisen <"terje.mathisen at tmsw.no"> - 2012-04-24 03:28 +0200
Re: ffs16 nmm1@cam.ac.uk - 2012-04-24 09:15 +0100
Re: ffs16 Chris Gray <cg@GraySage.com> - 2012-04-24 13:37 -0600
csiph-web