Changeset 1323


Ignore:
Timestamp:
Apr 30, 2012, 11:30:57 PM (11 years ago)
Author:
sam
Message:

core: reduce compilation time by about 30% by playing with namespaces
and avoid cluttering the compiler's symbol table.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lol/math/vector.h

    r1320 r1323  
    12371237
    12381238#define DECLARE_ALL_VECTOR_OPS(type) \
    1239     DECLARE_ALL_VECTOR_OPS_INNER(Vec2, type) \
    1240     DECLARE_ALL_VECTOR_OPS_INNER(Vec3, type) \
    1241     DECLARE_ALL_VECTOR_OPS_INNER(Vec4, type) \
    1242     \
    1243     DECLARE_VEC_3_COERCE_OPS(Vec3, static, type, type, type)
     1239    namespace x##type \
     1240    { \
     1241        DECLARE_ALL_VECTOR_OPS_INNER(Vec2, type) \
     1242        DECLARE_ALL_VECTOR_OPS_INNER(Vec3, type) \
     1243        DECLARE_ALL_VECTOR_OPS_INNER(Vec4, type) \
     1244        \
     1245        DECLARE_VEC_3_COERCE_OPS(Vec3, static, type, type, type) \
     1246    }
    12441247
    12451248#define DECLARE_VEC_ANY_COERCE_OPS(tname, tlow, thigh) \
     
    12511254
    12521255#define DECLARE_ALL_VECTOR_COERCE_OPS(tlow, thigh) \
    1253     DECLARE_VEC_ANY_COERCE_OPS(Vec2, tlow, thigh) \
    1254     DECLARE_VEC_ANY_COERCE_OPS(Vec3, tlow, thigh) \
    1255     DECLARE_VEC_ANY_COERCE_OPS(Vec4, tlow, thigh) \
    1256     \
    1257     DECLARE_VEC_3_COERCE_OPS(Vec3, static, tlow, thigh, thigh) \
    1258     DECLARE_VEC_3_COERCE_OPS(Vec3, static, thigh, tlow, thigh)
     1256    namespace x##tlow##thigh \
     1257    { \
     1258        DECLARE_VEC_ANY_COERCE_OPS(Vec2, tlow, thigh) \
     1259        DECLARE_VEC_ANY_COERCE_OPS(Vec3, tlow, thigh) \
     1260        DECLARE_VEC_ANY_COERCE_OPS(Vec4, tlow, thigh) \
     1261    } \
     1262    namespace y##tlow##thigh \
     1263    { \
     1264        DECLARE_VEC_3_COERCE_OPS(Vec3, static, tlow, thigh, thigh) \
     1265        DECLARE_VEC_3_COERCE_OPS(Vec3, static, thigh, tlow, thigh) \
     1266    } \
    12591267
    12601268DECLARE_ALL_NONVECTOR_OPS(Cmplx)
     
    12981306#endif
    12991307
     1308/* Hack for compilation speedups: we can hide some of our global methods in
     1309 * namespaces. We therefore want "long_double" to be a one-symbol type */
     1310typedef long double long_double;
     1311
    13001312/* Apply the same coercion rules as in the C++ standard. However, instead
    13011313 * of always promoting smaller types to int, we allow int8_t op int16_t to
     
    13101322DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, float)
    13111323DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, double)
    1312 DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, long double)
     1324DECLARE_ALL_VECTOR_COERCE_OPS(int8_t, long_double)
    13131325
    13141326DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, int16_t)
     
    13201332DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, float)
    13211333DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, double)
    1322 DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, long double)
     1334DECLARE_ALL_VECTOR_COERCE_OPS(uint8_t, long_double)
    13231335
    13241336DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, uint16_t)
     
    13291341DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, float)
    13301342DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, double)
    1331 DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, long double)
     1343DECLARE_ALL_VECTOR_COERCE_OPS(int16_t, long_double)
    13321344
    13331345DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, int32_t)
     
    13371349DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, float)
    13381350DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, double)
    1339 DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, long double)
     1351DECLARE_ALL_VECTOR_COERCE_OPS(uint16_t, long_double)
    13401352
    13411353DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, uint32_t)
     
    13441356DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, float)
    13451357DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, double)
    1346 DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, long double)
     1358DECLARE_ALL_VECTOR_COERCE_OPS(int32_t, long_double)
    13471359
    13481360DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, int64_t)
     
    13501362DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, float)
    13511363DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, double)
    1352 DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, long double)
     1364DECLARE_ALL_VECTOR_COERCE_OPS(uint32_t, long_double)
    13531365
    13541366DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, uint64_t)
    13551367DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, float)
    13561368DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, double)
    1357 DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, long double)
     1369DECLARE_ALL_VECTOR_COERCE_OPS(int64_t, long_double)
    13581370
    13591371DECLARE_ALL_VECTOR_COERCE_OPS(uint64_t, float)
    13601372DECLARE_ALL_VECTOR_COERCE_OPS(uint64_t, double)
    1361 DECLARE_ALL_VECTOR_COERCE_OPS(uint64_t, long double)
     1373DECLARE_ALL_VECTOR_COERCE_OPS(uint64_t, long_double)
    13621374
    13631375DECLARE_ALL_VECTOR_COERCE_OPS(float, double)
    1364 DECLARE_ALL_VECTOR_COERCE_OPS(float, long double)
    1365 
    1366 DECLARE_ALL_VECTOR_COERCE_OPS(double, long double)
     1376DECLARE_ALL_VECTOR_COERCE_OPS(float, long_double)
     1377
     1378DECLARE_ALL_VECTOR_COERCE_OPS(double, long_double)
    13671379
    13681380/* FIXME: vectors of "half" are deactivated for now, because they
     
    13831395DECLARE_ALL_VECTOR_COERCE_OPS(half, float)
    13841396DECLARE_ALL_VECTOR_COERCE_OPS(half, double)
    1385 DECLARE_ALL_VECTOR_COERCE_OPS(half, long double)
     1397DECLARE_ALL_VECTOR_COERCE_OPS(half, long_double)
    13861398#endif
    13871399
     
    14021414DECLARE_ALL_VECTOR_COERCE_OPS(float, real)
    14031415DECLARE_ALL_VECTOR_COERCE_OPS(double, real)
    1404 DECLARE_ALL_VECTOR_COERCE_OPS(long double, real)
    1405 #endif
     1416DECLARE_ALL_VECTOR_COERCE_OPS(long_double, real)
     1417#endif
     1418
     1419/* Activate all the namespaces that we created. Delaying this activation
     1420 * reduces compilation times significantly. */
     1421#define ACTIVATE_COERCE_NAMESPACES_INNER(tlow, thigh) \
     1422    namespace x##tlow##thigh {} \
     1423    namespace y##tlow##thigh {} \
     1424    using namespace x##tlow##thigh; \
     1425    using namespace y##tlow##thigh;
     1426
     1427#define ACTIVATE_COERCE_NAMESPACES(tlow) \
     1428    namespace x##tlow {} \
     1429    using namespace x##tlow; \
     1430    ACTIVATE_COERCE_NAMESPACES_INNER(tlow, int8_t) \
     1431    ACTIVATE_COERCE_NAMESPACES_INNER(tlow, uint8_t) \
     1432    ACTIVATE_COERCE_NAMESPACES_INNER(tlow, int16_t) \
     1433    ACTIVATE_COERCE_NAMESPACES_INNER(tlow, uint16_t) \
     1434    ACTIVATE_COERCE_NAMESPACES_INNER(tlow, int32_t) \
     1435    ACTIVATE_COERCE_NAMESPACES_INNER(tlow, uint32_t) \
     1436    ACTIVATE_COERCE_NAMESPACES_INNER(tlow, int64_t) \
     1437    ACTIVATE_COERCE_NAMESPACES_INNER(tlow, uint64_t) \
     1438    ACTIVATE_COERCE_NAMESPACES_INNER(tlow, half) \
     1439    ACTIVATE_COERCE_NAMESPACES_INNER(tlow, float) \
     1440    ACTIVATE_COERCE_NAMESPACES_INNER(tlow, double) \
     1441    ACTIVATE_COERCE_NAMESPACES_INNER(tlow, long_double) \
     1442    ACTIVATE_COERCE_NAMESPACES_INNER(tlow, real)
     1443
     1444ACTIVATE_COERCE_NAMESPACES(int8_t)
     1445ACTIVATE_COERCE_NAMESPACES(uint8_t)
     1446ACTIVATE_COERCE_NAMESPACES(int16_t)
     1447ACTIVATE_COERCE_NAMESPACES(uint16_t)
     1448ACTIVATE_COERCE_NAMESPACES(int32_t)
     1449ACTIVATE_COERCE_NAMESPACES(uint32_t)
     1450ACTIVATE_COERCE_NAMESPACES(int64_t)
     1451ACTIVATE_COERCE_NAMESPACES(uint64_t)
     1452ACTIVATE_COERCE_NAMESPACES(half)
     1453ACTIVATE_COERCE_NAMESPACES(float)
     1454ACTIVATE_COERCE_NAMESPACES(double)
     1455ACTIVATE_COERCE_NAMESPACES(long_double)
     1456ACTIVATE_COERCE_NAMESPACES(real)
    14061457
    14071458#if defined __GNUC__ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
Note: See TracChangeset for help on using the changeset viewer.