|
From: Patrick H. <pa...@13...> - 2004-10-12 03:25:41
|
Another problem with this is that it doesn't compile with Visual C++=20
7.0. For example, the following (from gmtl/Util/Meta.h) is not=20
supported by VC++ 7.0:
// ------ LOOP UnRolling ------------ //
template<int ELT, typename T>
struct AssignVecUnrolled
{
static void func(T& lVec, const T& rVec)
{
AssignVecUnrolled<ELT-1,T>::func(lVec, rVec);
lVec[ELT] =3D rVec[ELT];
}
};
template<typename T>
struct AssignVecUnrolled<0,T>
{
static void func(T& lVec, const T& rVec)
{ lVec[0] =3D rVec[0]; }
};
The error is this:
...\include\gmtl\Util\Meta.h(107): error C2687: cannot define a nested=20
UDT of a template class out of line
Searching for this error turns up some confirmation that this is a problem:
http://www.gamedev.net/community/forums/topic.asp?topic_id=3D274966
http://msdn.microsoft.com/library/default.asp?url=3D/library/en-us/dndeepc/=
html/deep07092002.asp
I haven't had a chance to read through the (long) MSDN article, but is=20
there any hope of working around this?
-Patrick
Allen Bierbaum wrote:
> I just merged my work on expression templates from the work branch into=20
> the CVS head of GMTL.
>=20
> This is a *major* feature addition and re-working of the VecBase (Vec &=20
> Point) classes and all operators that work on them.
>=20
> This change uses expression templates to remove temporary objects from=20
> expression evaluation and potentially allow compilers to better optimize=20
> the code.
>=20
> For example, with the previous code:
>=20
> vec1 =3D vec2 + vec3 + (vec4 * 6)
>=20
> that would have created 3 temporary vectors. In the new code the=20
> expression templates output code that directly computes the final value=20
> from the given operands. This has shown at least a 2x performance=20
> increase in my tests.
>=20
> The code is far from perfect though and could definitely be optimized=20
> much further. (especially by someone that knows intel assembly and has=20
> some patience)
>=20
> There is one common compiler error to be aware of. It is not possible=20
> to pass expression templates where VecBase/Vec/Point objects are expected=
.
>=20
> Details:
>=20
> GMTL makes extensive use of expression templates. These templates come=20
> into play when evaluating statement such as:
>=20
> gmtl::Vec3f vec1, vec2, vec3;
> vec1 =3D vec2 + (vec3 * 6.0);
>=20
> When evaluating the expression on the second line, GMTL creates an=20
> expression template tree to fully evaluate this expression when =3D is=20
> called. The details of this process are normally hidden from the user,=20
> but can come to the forefront when a method expects a Vec or Point=20
> argument and is passed an expression. For example:
>=20
> void myMethod(gmtl::Vec3f vec)
> { ... }
>=20
> gmtl::Vec3f vec1, vec2;
>=20
> myMethod(vec1); // Works correctly
> myMethod(vec1 + vec2); // Fails to compile
>=20
> The reason the second line fails to compile is that the type for "vec1 +=20
> vec2" is not a Vec3f. It is an expression template that describes how=20
> to sum two Vec3f's. (You may expect an autoconversion to happen, but it=20
> does not because of template argument deduction rules).
>=20
> There are two solutions to this, either explicitly construct a temporary
> object to pass to the method (which is what an auto conversion would do=20
> anyway) or write the method to handle expression templates. This second=20
> option is not difficult, but does require a further understanding of=20
> GMTL then is documented here.
>=20
> Here is how the first option could be used:
>=20
> myMethod(gmtl::Vec3f(vec1 + vec2)); // Creates a temporary to pass in
>=20
>=20
>=20
> In closing: Give the code and try and let me know what you think. :)
>=20
>=20
> -Allen
--=20
Patrick L. Hartling | Research Assistant, VRAC
http://www.137.org/patrick/ | 2274 Howe Hall Room 2624
PGP: http://tinyurl.com/2oum9 | http://www.vrac.iastate.edu/
|