Changes to inlining so we can use FORCE_INLINING in gcc as well

This commit is contained in:
rdb 2015-07-27 15:39:15 +02:00
parent 4206e349c9
commit 75019784f4
13 changed files with 97 additions and 89 deletions

View File

@ -18,7 +18,7 @@
// Access: Public, Static // Access: Public, Static
// Description: Atomically increments the indicated variable. // Description: Atomically increments the indicated variable.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void AtomicAdjustDummyImpl:: ALWAYS_INLINE void AtomicAdjustDummyImpl::
inc(TVOLATILE AtomicAdjustDummyImpl::Integer &var) { inc(TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
++var; ++var;
} }
@ -30,7 +30,7 @@ inc(TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
// returns true if the new value is nonzero, false if it // returns true if the new value is nonzero, false if it
// is zero. // is zero.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE bool AtomicAdjustDummyImpl:: ALWAYS_INLINE bool AtomicAdjustDummyImpl::
dec(TVOLATILE AtomicAdjustDummyImpl::Integer &var) { dec(TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
return (--var) != 0; return (--var) != 0;
} }
@ -41,7 +41,7 @@ dec(TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
// Description: Atomically computes var += delta. It is legal for // Description: Atomically computes var += delta. It is legal for
// delta to be negative. // delta to be negative.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void AtomicAdjustDummyImpl:: ALWAYS_INLINE void AtomicAdjustDummyImpl::
add(TVOLATILE AtomicAdjustDummyImpl::Integer &var, AtomicAdjustDummyImpl::Integer delta) { add(TVOLATILE AtomicAdjustDummyImpl::Integer &var, AtomicAdjustDummyImpl::Integer delta) {
var += delta; var += delta;
} }
@ -52,7 +52,7 @@ add(TVOLATILE AtomicAdjustDummyImpl::Integer &var, AtomicAdjustDummyImpl::Intege
// Description: Atomically changes the indicated variable and // Description: Atomically changes the indicated variable and
// returns the original value. // returns the original value.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl:: ALWAYS_INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
set(TVOLATILE AtomicAdjustDummyImpl::Integer &var, AtomicAdjustDummyImpl::Integer new_value) { set(TVOLATILE AtomicAdjustDummyImpl::Integer &var, AtomicAdjustDummyImpl::Integer new_value) {
Integer orig_value = var; Integer orig_value = var;
var = new_value; var = new_value;
@ -68,7 +68,7 @@ set(TVOLATILE AtomicAdjustDummyImpl::Integer &var, AtomicAdjustDummyImpl::Intege
// asynchronously setting, incrementing, or decrementing // asynchronously setting, incrementing, or decrementing
// (via other AtomicAjust methods). // (via other AtomicAjust methods).
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl:: ALWAYS_INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
get(const TVOLATILE AtomicAdjustDummyImpl::Integer &var) { get(const TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
return var; return var;
} }
@ -79,7 +79,7 @@ get(const TVOLATILE AtomicAdjustDummyImpl::Integer &var) {
// Description: Atomically changes the indicated variable and // Description: Atomically changes the indicated variable and
// returns the original value. // returns the original value.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE AtomicAdjustDummyImpl::Pointer AtomicAdjustDummyImpl:: ALWAYS_INLINE AtomicAdjustDummyImpl::Pointer AtomicAdjustDummyImpl::
set_ptr(TVOLATILE AtomicAdjustDummyImpl::Pointer &var, set_ptr(TVOLATILE AtomicAdjustDummyImpl::Pointer &var,
AtomicAdjustDummyImpl::Pointer new_value) { AtomicAdjustDummyImpl::Pointer new_value) {
Pointer orig_value = var; Pointer orig_value = var;
@ -96,7 +96,7 @@ set_ptr(TVOLATILE AtomicAdjustDummyImpl::Pointer &var,
// asynchronously setting, incrementing, or decrementing // asynchronously setting, incrementing, or decrementing
// (via other AtomicAjust methods). // (via other AtomicAjust methods).
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE AtomicAdjustDummyImpl::Pointer AtomicAdjustDummyImpl:: ALWAYS_INLINE AtomicAdjustDummyImpl::Pointer AtomicAdjustDummyImpl::
get_ptr(const TVOLATILE AtomicAdjustDummyImpl::Pointer &var) { get_ptr(const TVOLATILE AtomicAdjustDummyImpl::Pointer &var) {
return var; return var;
} }
@ -111,7 +111,7 @@ get_ptr(const TVOLATILE AtomicAdjustDummyImpl::Pointer &var) {
// The caller can test for success by comparing // The caller can test for success by comparing
// return_value == old_value. // return_value == old_value.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl:: ALWAYS_INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl::
compare_and_exchange(TVOLATILE AtomicAdjustDummyImpl::Integer &mem, compare_and_exchange(TVOLATILE AtomicAdjustDummyImpl::Integer &mem,
AtomicAdjustDummyImpl::Integer old_value, AtomicAdjustDummyImpl::Integer old_value,
AtomicAdjustDummyImpl::Integer new_value) { AtomicAdjustDummyImpl::Integer new_value) {
@ -129,7 +129,7 @@ compare_and_exchange(TVOLATILE AtomicAdjustDummyImpl::Integer &mem,
// //
// As above, but works on pointers instead of integers. // As above, but works on pointers instead of integers.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE AtomicAdjustDummyImpl::Pointer AtomicAdjustDummyImpl:: ALWAYS_INLINE AtomicAdjustDummyImpl::Pointer AtomicAdjustDummyImpl::
compare_and_exchange_ptr(TVOLATILE AtomicAdjustDummyImpl::Pointer &mem, compare_and_exchange_ptr(TVOLATILE AtomicAdjustDummyImpl::Pointer &mem,
AtomicAdjustDummyImpl::Pointer old_value, AtomicAdjustDummyImpl::Pointer old_value,
AtomicAdjustDummyImpl::Pointer new_value) { AtomicAdjustDummyImpl::Pointer new_value) {

View File

@ -31,20 +31,20 @@ public:
typedef long Integer; typedef long Integer;
typedef void *Pointer; typedef void *Pointer;
INLINE static void inc(TVOLATILE Integer &var); ALWAYS_INLINE static void inc(TVOLATILE Integer &var);
INLINE static bool dec(TVOLATILE Integer &var); ALWAYS_INLINE static bool dec(TVOLATILE Integer &var);
INLINE static void add(TVOLATILE Integer &var, Integer delta); ALWAYS_INLINE static void add(TVOLATILE Integer &var, Integer delta);
INLINE static Integer set(TVOLATILE Integer &var, Integer new_value); ALWAYS_INLINE static Integer set(TVOLATILE Integer &var, Integer new_value);
INLINE static Integer get(const TVOLATILE Integer &var); ALWAYS_INLINE static Integer get(const TVOLATILE Integer &var);
INLINE static Pointer set_ptr(TVOLATILE Pointer &var, Pointer new_value); ALWAYS_INLINE static Pointer set_ptr(TVOLATILE Pointer &var, Pointer new_value);
INLINE static Pointer get_ptr(const TVOLATILE Pointer &var); ALWAYS_INLINE static Pointer get_ptr(const TVOLATILE Pointer &var);
INLINE static Integer compare_and_exchange(TVOLATILE Integer &mem, ALWAYS_INLINE static Integer compare_and_exchange(TVOLATILE Integer &mem,
Integer old_value, Integer old_value,
Integer new_value); Integer new_value);
INLINE static Pointer compare_and_exchange_ptr(TVOLATILE Pointer &mem, ALWAYS_INLINE static Pointer compare_and_exchange_ptr(TVOLATILE Pointer &mem,
Pointer old_value, Pointer old_value,
Pointer new_value); Pointer new_value);
}; };

View File

@ -18,7 +18,7 @@
// Access: Public, Static // Access: Public, Static
// Description: Atomically increments the indicated variable. // Description: Atomically increments the indicated variable.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void AtomicAdjustWin32Impl:: ALWAYS_INLINE void AtomicAdjustWin32Impl::
inc(TVOLATILE AtomicAdjustWin32Impl::Integer &var) { inc(TVOLATILE AtomicAdjustWin32Impl::Integer &var) {
assert((((size_t)&var) & (sizeof(Integer) - 1)) == 0); assert((((size_t)&var) & (sizeof(Integer) - 1)) == 0);
#ifdef _WIN64 #ifdef _WIN64
@ -35,7 +35,7 @@ inc(TVOLATILE AtomicAdjustWin32Impl::Integer &var) {
// returns true if the new value is nonzero, false if it // returns true if the new value is nonzero, false if it
// is zero. // is zero.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE bool AtomicAdjustWin32Impl:: ALWAYS_INLINE bool AtomicAdjustWin32Impl::
dec(TVOLATILE AtomicAdjustWin32Impl::Integer &var) { dec(TVOLATILE AtomicAdjustWin32Impl::Integer &var) {
assert((((size_t)&var) & (sizeof(Integer) - 1)) == 0); assert((((size_t)&var) & (sizeof(Integer) - 1)) == 0);
#ifdef _WIN64 #ifdef _WIN64
@ -70,7 +70,7 @@ add(TVOLATILE AtomicAdjustWin32Impl::Integer &var, AtomicAdjustWin32Impl::Intege
// Description: Atomically changes the indicated variable and // Description: Atomically changes the indicated variable and
// returns the original value. // returns the original value.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE AtomicAdjustWin32Impl::Integer AtomicAdjustWin32Impl:: ALWAYS_INLINE AtomicAdjustWin32Impl::Integer AtomicAdjustWin32Impl::
set(TVOLATILE AtomicAdjustWin32Impl::Integer &var, set(TVOLATILE AtomicAdjustWin32Impl::Integer &var,
AtomicAdjustWin32Impl::Integer new_value) { AtomicAdjustWin32Impl::Integer new_value) {
assert((((size_t)&var) & (sizeof(Integer) - 1)) == 0); assert((((size_t)&var) & (sizeof(Integer) - 1)) == 0);
@ -90,7 +90,7 @@ set(TVOLATILE AtomicAdjustWin32Impl::Integer &var,
// asynchronously setting, incrementing, or decrementing // asynchronously setting, incrementing, or decrementing
// (via other AtomicAjust methods). // (via other AtomicAjust methods).
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE AtomicAdjustWin32Impl::Integer AtomicAdjustWin32Impl:: ALWAYS_INLINE AtomicAdjustWin32Impl::Integer AtomicAdjustWin32Impl::
get(const TVOLATILE AtomicAdjustWin32Impl::Integer &var) { get(const TVOLATILE AtomicAdjustWin32Impl::Integer &var) {
// On Intel platforms, word-aligned loads are atomic (if performed // On Intel platforms, word-aligned loads are atomic (if performed
// in a single instruction). We can't guarantee the compiler will // in a single instruction). We can't guarantee the compiler will
@ -107,7 +107,7 @@ get(const TVOLATILE AtomicAdjustWin32Impl::Integer &var) {
// Description: Atomically changes the indicated variable and // Description: Atomically changes the indicated variable and
// returns the original value. // returns the original value.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE AtomicAdjustWin32Impl::Pointer AtomicAdjustWin32Impl:: ALWAYS_INLINE AtomicAdjustWin32Impl::Pointer AtomicAdjustWin32Impl::
set_ptr(TVOLATILE AtomicAdjustWin32Impl::Pointer &var, set_ptr(TVOLATILE AtomicAdjustWin32Impl::Pointer &var,
AtomicAdjustWin32Impl::Pointer new_value) { AtomicAdjustWin32Impl::Pointer new_value) {
assert((((size_t)&var) & (sizeof(Pointer) - 1)) == 0); assert((((size_t)&var) & (sizeof(Pointer) - 1)) == 0);
@ -123,7 +123,7 @@ set_ptr(TVOLATILE AtomicAdjustWin32Impl::Pointer &var,
// asynchronously setting, incrementing, or decrementing // asynchronously setting, incrementing, or decrementing
// (via other AtomicAjust methods). // (via other AtomicAjust methods).
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE AtomicAdjustWin32Impl::Pointer AtomicAdjustWin32Impl:: ALWAYS_INLINE AtomicAdjustWin32Impl::Pointer AtomicAdjustWin32Impl::
get_ptr(const TVOLATILE AtomicAdjustWin32Impl::Pointer &var) { get_ptr(const TVOLATILE AtomicAdjustWin32Impl::Pointer &var) {
// As in get(), make sure the address is word-aligned. // As in get(), make sure the address is word-aligned.
assert((((size_t)&var) & (sizeof(Pointer) - 1)) == 0); assert((((size_t)&var) & (sizeof(Pointer) - 1)) == 0);

View File

@ -45,14 +45,14 @@ public:
typedef ALIGN_4BYTE UnalignedPointer Pointer; typedef ALIGN_4BYTE UnalignedPointer Pointer;
#endif // _WIN64 #endif // _WIN64
INLINE static void inc(TVOLATILE Integer &var); ALWAYS_INLINE static void inc(TVOLATILE Integer &var);
INLINE static bool dec(TVOLATILE Integer &var); ALWAYS_INLINE static bool dec(TVOLATILE Integer &var);
INLINE static void add(TVOLATILE Integer &var, Integer delta); INLINE static void add(TVOLATILE Integer &var, Integer delta);
INLINE static Integer set(TVOLATILE Integer &var, Integer new_value); ALWAYS_INLINE static Integer set(TVOLATILE Integer &var, Integer new_value);
INLINE static Integer get(const TVOLATILE Integer &var); ALWAYS_INLINE static Integer get(const TVOLATILE Integer &var);
INLINE static Pointer set_ptr(TVOLATILE Pointer &var, Pointer new_value); ALWAYS_INLINE static Pointer set_ptr(TVOLATILE Pointer &var, Pointer new_value);
INLINE static Pointer get_ptr(const TVOLATILE Pointer &var); ALWAYS_INLINE static Pointer get_ptr(const TVOLATILE Pointer &var);
INLINE static Integer compare_and_exchange(TVOLATILE Integer &mem, INLINE static Integer compare_and_exchange(TVOLATILE Integer &mem,
Integer old_value, Integer old_value,

View File

@ -32,6 +32,7 @@
using namespace std; using namespace std;
#define INLINE inline #define INLINE inline
#define ALWAYS_INLINE inline
#define TYPENAME typename #define TYPENAME typename
#define CONSTEXPR #define CONSTEXPR
#define NOEXCEPT noexcept #define NOEXCEPT noexcept
@ -115,11 +116,19 @@ typedef ios::iostate ios_iostate;
typedef ios::seekdir ios_seekdir; typedef ios::seekdir ios_seekdir;
#endif #endif
#if defined(WIN32_VC) && defined(FORCE_INLINING) #ifdef _MSC_VER
#define ALWAYS_INLINE __forceinline
#elif defined(__GNUC__)
#define ALWAYS_INLINE __attribute__((always_inline)) inline
#else
#define ALWAYS_INLINE inline
#endif
#ifdef FORCE_INLINING
// If FORCE_INLINING is defined, we use the keyword __forceinline, // If FORCE_INLINING is defined, we use the keyword __forceinline,
// which tells MS VC++ to override its internal benefit heuristic // which tells MS VC++ to override its internal benefit heuristic
// and inline the fn if it is technically possible to do so. // and inline the fn if it is technically possible to do so.
#define INLINE __forceinline #define INLINE ALWAYS_INLINE
#else #else
#define INLINE inline #define INLINE inline
#endif #endif

View File

@ -263,24 +263,3 @@ INLINE TypeHandle::
operator bool () const { operator bool () const {
return (_index != 0); return (_index != 0);
} }
////////////////////////////////////////////////////////////////////
// Function: get_best_parent_from_Set
// Access: Published
// Description: Return the Index of the BEst fit Classs from a set
////////////////////////////////////////////////////////////////////
INLINE int TypeHandle::get_best_parent_from_Set(const std::set< int > &legal_vals) const
{
if(legal_vals.find(_index) != legal_vals.end())
return _index;
for(int pi = 0; pi < get_num_parent_classes() ; pi++)
{
TypeHandle ph = get_parent_class(pi);
int val = ph.get_best_parent_from_Set(legal_vals);
if(val > 0)
return val;
}
return -1;
}

View File

@ -84,6 +84,27 @@ dec_memory_usage(MemoryClass memory_class, size_t size) {
} }
#endif // DO_MEMORY_USAGE #endif // DO_MEMORY_USAGE
////////////////////////////////////////////////////////////////////
// Function: get_best_parent_from_Set
// Access: Published
// Description: Return the Index of the BEst fit Classs from a set
////////////////////////////////////////////////////////////////////
int TypeHandle::
get_best_parent_from_Set(const std::set< int > &legal_vals) const {
if (legal_vals.find(_index) != legal_vals.end()) {
return _index;
}
for (int pi = 0; pi < get_num_parent_classes(); ++pi) {
TypeHandle ph = get_parent_class(pi);
int val = ph.get_best_parent_from_Set(legal_vals);
if (val > 0) {
return val;
}
}
return -1;
}
ostream & ostream &
operator << (ostream &out, TypeHandle::MemoryClass mem_class) { operator << (ostream &out, TypeHandle::MemoryClass mem_class) {
switch (mem_class) { switch (mem_class) {

View File

@ -123,7 +123,7 @@ PUBLISHED:
INLINE TypeHandle get_parent_towards(TypeHandle ancestor, INLINE TypeHandle get_parent_towards(TypeHandle ancestor,
TypedObject *object = (TypedObject *)NULL) const; TypedObject *object = (TypedObject *)NULL) const;
INLINE int get_best_parent_from_Set(const std::set< int > &legal_vals) const; int get_best_parent_from_Set(const std::set< int > &legal_vals) const;
#ifdef DO_MEMORY_USAGE #ifdef DO_MEMORY_USAGE
int get_memory_usage(MemoryClass memory_class) const; int get_memory_usage(MemoryClass memory_class) const;

View File

@ -20,7 +20,7 @@
// valid (based on a comparison of the supplied // valid (based on a comparison of the supplied
// local_modified value with the global_modified value). // local_modified value with the global_modified value).
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE bool ConfigFlags:: ALWAYS_INLINE bool ConfigFlags::
is_cache_valid(AtomicAdjust::Integer local_modified) { is_cache_valid(AtomicAdjust::Integer local_modified) {
return local_modified == _global_modified; return local_modified == _global_modified;
} }
@ -32,7 +32,7 @@ is_cache_valid(AtomicAdjust::Integer local_modified) {
// the cache will appear to be valid, until someone next // the cache will appear to be valid, until someone next
// calls invalidate_cache(). // calls invalidate_cache().
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
INLINE void ConfigFlags:: ALWAYS_INLINE void ConfigFlags::
mark_cache_valid(AtomicAdjust::Integer &local_modified) { mark_cache_valid(AtomicAdjust::Integer &local_modified) {
local_modified = _global_modified; local_modified = _global_modified;
} }

View File

@ -62,8 +62,8 @@ PUBLISHED:
}; };
protected: protected:
INLINE static bool is_cache_valid(AtomicAdjust::Integer local_modified); ALWAYS_INLINE static bool is_cache_valid(AtomicAdjust::Integer local_modified);
INLINE static void mark_cache_valid(AtomicAdjust::Integer &local_modified); ALWAYS_INLINE static void mark_cache_valid(AtomicAdjust::Integer &local_modified);
INLINE static AtomicAdjust::Integer initial_invalid_cache(); INLINE static AtomicAdjust::Integer initial_invalid_cache();
INLINE static void invalidate_cache(); INLINE static void invalidate_cache();

View File

@ -517,23 +517,6 @@ reverse_ls() const {
reverse_ls(nout); reverse_ls(nout);
} }
////////////////////////////////////////////////////////////////////
// Function: NodePath::reverse_ls
// Access: Published
// Description: Lists the hierarchy at and above the referenced node.
////////////////////////////////////////////////////////////////////
INLINE int NodePath::
reverse_ls(ostream &out, int indent_level) const {
if (is_empty()) {
out << "(empty)\n";
return 0;
} else if (has_parent()) {
indent_level = get_parent().reverse_ls(out, indent_level);
}
node()->write(out, indent_level);
return indent_level + 2;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: NodePath::set_state // Function: NodePath::set_state
// Access: Published // Access: Published

View File

@ -810,6 +810,23 @@ detach_node(Thread *current_thread) {
} }
} }
////////////////////////////////////////////////////////////////////
// Function: NodePath::reverse_ls
// Access: Published
// Description: Lists the hierarchy at and above the referenced node.
////////////////////////////////////////////////////////////////////
int NodePath::
reverse_ls(ostream &out, int indent_level) const {
if (is_empty()) {
out << "(empty)\n";
return 0;
} else if (has_parent()) {
indent_level = get_parent().reverse_ls(out, indent_level);
}
node()->write(out, indent_level);
return indent_level + 2;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: NodePath::output // Function: NodePath::output
// Access: Published // Access: Published

View File

@ -278,8 +278,7 @@ PUBLISHED:
INLINE void ls() const; INLINE void ls() const;
INLINE void ls(ostream &out, int indent_level = 0) const; INLINE void ls(ostream &out, int indent_level = 0) const;
INLINE void reverse_ls() const; INLINE void reverse_ls() const;
INLINE int reverse_ls(ostream &out, int indent_level = 0) const; int reverse_ls(ostream &out, int indent_level = 0) const;
// Aggregate transform and state information. // Aggregate transform and state information.
const RenderState *get_state(Thread *current_thread = Thread::get_current_thread()) const; const RenderState *get_state(Thread *current_thread = Thread::get_current_thread()) const;