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

View File

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

View File

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

View File

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

View File

@ -32,6 +32,7 @@
using namespace std;
#define INLINE inline
#define ALWAYS_INLINE inline
#define TYPENAME typename
#define CONSTEXPR
#define NOEXCEPT noexcept
@ -115,11 +116,19 @@ typedef ios::iostate ios_iostate;
typedef ios::seekdir ios_seekdir;
#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,
// which tells MS VC++ to override its internal benefit heuristic
// and inline the fn if it is technically possible to do so.
#define INLINE __forceinline
#define INLINE ALWAYS_INLINE
#else
#define INLINE inline
#endif

View File

@ -263,24 +263,3 @@ INLINE TypeHandle::
operator bool () const {
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
////////////////////////////////////////////////////////////////////
// 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 &
operator << (ostream &out, TypeHandle::MemoryClass mem_class) {
switch (mem_class) {

View File

@ -123,7 +123,7 @@ PUBLISHED:
INLINE TypeHandle get_parent_towards(TypeHandle ancestor,
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
int get_memory_usage(MemoryClass memory_class) const;

View File

@ -20,7 +20,7 @@
// valid (based on a comparison of the supplied
// local_modified value with the global_modified value).
////////////////////////////////////////////////////////////////////
INLINE bool ConfigFlags::
ALWAYS_INLINE bool ConfigFlags::
is_cache_valid(AtomicAdjust::Integer local_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
// calls invalidate_cache().
////////////////////////////////////////////////////////////////////
INLINE void ConfigFlags::
ALWAYS_INLINE void ConfigFlags::
mark_cache_valid(AtomicAdjust::Integer &local_modified) {
local_modified = _global_modified;
}

View File

@ -62,8 +62,8 @@ PUBLISHED:
};
protected:
INLINE static bool is_cache_valid(AtomicAdjust::Integer local_modified);
INLINE static void mark_cache_valid(AtomicAdjust::Integer &local_modified);
ALWAYS_INLINE static bool is_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 void invalidate_cache();

View File

@ -517,23 +517,6 @@ reverse_ls() const {
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
// 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
// Access: Published

View File

@ -278,8 +278,7 @@ PUBLISHED:
INLINE void ls() const;
INLINE void ls(ostream &out, int indent_level = 0) 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.
const RenderState *get_state(Thread *current_thread = Thread::get_current_thread()) const;