[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-dev] patch for fixed-point calculations
From: |
Yann Dirson |
Subject: |
[Wesnoth-dev] patch for fixed-point calculations |
Date: |
Sun, 6 Feb 2005 16:04:57 +0100 |
User-agent: |
Mutt/1.5.6+20040907i |
The patch I've made to replace floating-point operations by
fixed-point ones for image transformations is available at
http://ydirson.free.fr/soft/wesnoth/patches/fxp3.diff
Since there was no concensus on irc about whether to limit this change
to sdl_utils.cpp or to propagate the change to other files, I submit
my patch here, before committing anything.
I've taken the "change everything" approach, rather than "just change
sdl_utls", mostly because I don't see the point in keeping an API
using floating-point numbers, just to have them converted to
fixed-point within each func call.
I've restricted the changes to those directly induced by the API
changes necessary to convert those functions listed as top
cycle-eaters by the flat profile below. It may be good for
consistency to convert the remaining similar functions to using
fixed_t, and possibly change all remaining double usages to floats.
I've also tried to write compatibility macros to have the previous
behaviour, although I've not tested them yet (see util.hpp).
For comparison, I've done gprof flat profiles of playing the 1st
tutorial on the ipaq. With floating-point operations, the top eaters
are:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls s/call s/call name
12.76 57.08 57.08 679 0.08 0.20 brighten_image(surface
const&, double)
10.80 105.43 48.35 9626882 0.00 0.00 double const&
minimum<double>(double const&, double const&)
10.74 153.50 48.07 9607693 0.00 0.00 double const&
maximum<double>(double const&, double const&)
6.73 183.61 30.11 1922 0.02 0.02 scale_surface(surface
const&, int, int)
3.42 198.92 15.31 623 0.02 0.06
adjust_surface_alpha(surface const&, double)
1.73 206.65 7.73 941423 0.00 0.00 surface::surface(surface
const&)
1.38 212.84 6.19 39860267 0.00 0.00
util::scoped_resource<SDL_Surface*, surface::free_sdl_surface>::get() const
1.08 217.69 4.86 36555500 0.00 0.00 surface::operator->()
const
1.00 222.18 4.49 3699254 0.00 0.00
std::less<char>::operator()(char const&, char const&) const
0.72 225.40 3.22 57983 0.00 0.00 display::draw_tile(int,
int, surface, double, unsigned int)
[...]
0.24 278.13 1.08 34251 0.00 0.00
display::draw_unit_on_tile(int, int, surface, double, unsigned int)
others are all below 1%. I've mentionned the last 2 ones because of the number
of invocations.
With the current patch, we have, for a run where the cache does not have to be
built:
% cumulative self self total
time seconds seconds calls s/call s/call name
3.18 6.75 6.75 672061 0.00 0.00 surface::surface(surface
const&)
2.53 12.13 5.38 33598079 0.00 0.00
util::scoped_resource<SDL_Surface*, surface::free_sdl_surface>::get() const
2.27 16.94 4.81 31132347 0.00 0.00 surface::operator->()
const
2.13 21.47 4.53 23151467 0.00 0.00 int const&
minimum<int>(int const&, int const&)
1.85 25.39 3.92 20924069 0.00 0.00 int const&
maximum<int>(int const&, int const&)
1.56 28.71 3.32 2300684 0.00 0.00
std::less<char>::operator()(char const&, char const&) const
1.46 31.80 3.09 255489 0.00 0.00
gamestatus::get_time_of_day_turn(int) const
1.24 34.44 2.64 896 0.00 0.01
adjust_surface_colour(surface const&, int, int, int)
1.15 36.89 2.45 1029 0.00 0.01 brighten_image(surface
const&, int)
1.04 39.10 2.21 75543 0.00 0.00
display::get_terrain_images(int, int, image::TYPE,
display::ADJACENT_TERRAIN_TYPE)
0.99 41.20 2.10 41046 0.00 0.00 display::draw_tile(int,
int, surface, int, unsigned int)
[...]
0.47 61.05 1.00 25181 0.00 0.00
display::draw_unit_on_tile(int, int, surface, int, unsigned int)
Although there are surely other improvements to do, we see that:
- the profile is much more flat, which is a good point
- the calls to minimum/maximum are internal to sdl_utils, so would have been
converted anyway
- doing sdl_utils-internal conversion would probably not have been such of a
gain, because it's not so much called
- doing it on draw_tile and draw_unit_on_tile would probably have made them
raise quite much, although I'm not sure by how much
--
Yann Dirson <address@hidden> |
Debian-related: <address@hidden> | Support Debian GNU/Linux:
| Freedom, Power, Stability, Gratis
http://ydirson.free.fr/ | Check <http://www.debian.org/>
- [Wesnoth-dev] patch for fixed-point calculations,
Yann Dirson <=