libfoedus-core
FOEDUS Core Library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Compiler Specific Optimizations

A few macros and functions to exploit compiler specific optimizations. More...

Detailed Description

A few macros and functions to exploit compiler specific optimizations.

This file contains a few macros and functions analogous to linux/compiler.h

Example: likely/unlikely macros
For example, Linux kernel wraps GCC's __builtin_expect as follows.
// from linux/compiler.h.
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
...
if (likely(var == 42)) {
...
}
We provide macros/functions to do equivalent optimizations here. However, we should minimize the use of such detailed and custom optimizations. In general, compiler is good enough to predict branches/inlining, and, even if it isn't, we should rather use -fprofile-arcs. So far, we use it only for a few places that are VERY important and VERY easy to predict by human.
See also
http://blog.man7.org/2012/10/how-much-do-builtinexpect-likely-and.html
Collaboration diagram for Compiler Specific Optimizations:

Modules

 Memorandum on ARMv8 (AArch64) Support
 We keep notes on FOEDUS's ARMv8 (AArch64) Support here.
 

Macros

#define LIKELY(x)    __builtin_expect(!!(x), 1)
 Hints that x is highly likely true. More...
 
#define UNLIKELY(x)    __builtin_expect(!!(x), 0)
 Hints that x is highly likely false. More...
 
#define NO_INLINE   __attribute__((noinline))
 A function suffix to hint that the function should never be inlined. More...
 
#define ALWAYS_INLINE   __attribute__((always_inline))
 A function suffix to hint that the function should always be inlined. More...
 
#define ASSUME_ALIGNED(x, y)   __builtin_assume_aligned(x, y)
 Wraps GCC's __builtin_assume_aligned. More...
 
#define MAY_ALIAS   __attribute__((__may_alias__))
 Wraps GCC's attribute((may_alias)). More...
 
#define RESTRICT_ALIAS   __restrict
 Wraps GCC's __restrict. More...
 

Macro Definition Documentation

#define ALWAYS_INLINE   __attribute__((always_inline))

A function suffix to hint that the function should always be inlined.

GCC's always_inline.

Definition at line 106 of file compiler.hpp.

#define MAY_ALIAS   __attribute__((__may_alias__))

Wraps GCC's attribute((may_alias)).

This is QUITE important for us. This keyword is not for performance but for correctness. I'm seeing weird behaviors even with -fno-strict-aliasing. This keyword might help. Otherwise, we have to memcpy to type-pun everything. uggggrrr.

Definition at line 107 of file compiler.hpp.

#define NO_INLINE   __attribute__((noinline))

A function suffix to hint that the function should never be inlined.

GCC's noinline.

Definition at line 105 of file compiler.hpp.

#define RESTRICT_ALIAS   __restrict

Wraps GCC's __restrict.

OTOH, this explicitly helps compiler auto-vectorize and do other stuffs, saying that the variable is never aliased in the function. Seems like older gcc ignored __restrict when fno-strict-aliasing is specified, but recent gcc doesn't.

Attention
DO NOT USE THIS if you don't know what __restrict means.

Definition at line 108 of file compiler.hpp.

#define UNLIKELY (   x)    __builtin_expect(!!(x), 0)

Hints that x is highly likely false.

GCC's __builtin_expect.

Definition at line 104 of file compiler.hpp.

Referenced by foedus::xct::Xct::acquire_local_work_memory(), foedus::xct::McsWwImpl< ADAPTOR >::acquire_unconditional(), foedus::xct::Xct::add_to_lock_free_read_set(), foedus::xct::Xct::add_to_lock_free_write_set(), foedus::xct::Xct::add_to_page_version_set(), foedus::xct::Xct::add_to_pointer_set(), foedus::xct::Xct::add_to_read_set(), foedus::xct::Xct::add_to_write_set(), foedus::storage::sequential::SequentialStoragePimpl::append_record(), foedus::storage::hash::ComposedBinsMergedStream::assure_writer_buffer(), foedus::xct::SysxctLockList::batch_get_or_add_entries(), foedus::xct::XctManagerPimpl::begin_xct(), foedus::storage::masstree::MasstreeStoragePimpl::check_next_layer_bit(), foedus::ErrorStack::clear_custom_message(), foedus::storage::array::compact_logs(), foedus::storage::hash::ReserveRecords::create_new_tail_page(), foedus::storage::hash::HashTmpBin::delete_record(), foedus::storage::array::ArrayComposeContext::execute(), foedus::storage::hash::HashComposeContext::execute(), foedus::cache::CacheHashtable::find_batch(), foedus::storage::masstree::MasstreeStoragePimpl::find_border_physical(), foedus::storage::masstree::MasstreeBorderPage::find_key_normalized(), foedus::thread::ThreadPimpl::find_or_read_snapshot_pages_batch(), foedus::storage::masstree::MasstreeStoragePimpl::follow_layer(), foedus::storage::hash::HashStoragePimpl::follow_page_bin_head(), foedus::thread::ThreadPimpl::follow_page_pointer(), foedus::thread::ThreadPimpl::follow_page_pointers_for_read_batch(), foedus::thread::ThreadPimpl::follow_page_pointers_for_write_batch(), foedus::storage::masstree::MasstreeStoragePimpl::get_first_root(), foedus::xct::SysxctLockList::get_or_add_entry(), foedus::memory::PagePoolPimpl::grab(), foedus::memory::NumaCoreMemory::grab_free_snapshot_page(), foedus::memory::NumaCoreMemory::grab_free_volatile_page(), foedus::memory::PagePoolPimpl::grab_one(), foedus::snapshot::MergeSort::groupify(), foedus::storage::hash::HashTmpBin::insert_record(), foedus::storage::masstree::MasstreeStorage::insert_record(), foedus::storage::masstree::MasstreeStorage::insert_record_normalized(), foedus::thread::ThreadPimpl::install_a_volatile_page(), foedus::xct::Xct::issue_next_id(), foedus::storage::hash::HashStoragePimpl::locate_record(), foedus::storage::sequential::StreamStatus::next(), foedus::storage::sequential::SequentialRecordIterator::next(), foedus::storage::sequential::SequentialStorageControlBlock::optimistic_read_truncate_epoch(), foedus::storage::hash::HashTmpBin::overwrite_record(), foedus::storage::masstree::MasstreeStoragePimpl::peek_volatile_page_boundaries_next_layer(), foedus::storage::masstree::MasstreeStoragePimpl::peek_volatile_page_boundaries_this_layer_recurse(), foedus::xct::XctManagerPimpl::precommit_xct_lock(), foedus::xct::XctManagerPimpl::precommit_xct_lock_batch_track_moved(), foedus::xct::XctManagerPimpl::precommit_xct_verify_readonly(), foedus::xct::XctManagerPimpl::precommit_xct_verify_readwrite(), foedus::log::ThreadLogBuffer::publish_committed_log(), foedus::xct::McsWwImpl< ADAPTOR >::release(), foedus::memory::NumaCoreMemory::release_free_snapshot_page(), foedus::memory::NumaCoreMemory::release_free_volatile_page(), foedus::xct::McsImpl< ADAPTOR, McsRwSimpleBlock >::release_rw_writer(), foedus::log::ThreadLogBuffer::reserve_new_log(), foedus::xct::run_nested_sysxct_impl(), foedus::xct::XctId::spin_while_being_written(), foedus::storage::masstree::MasstreeBorderPage::track_moved_record_next_layer(), foedus::storage::hash::HashStoragePimpl::track_moved_record_search(), foedus::thread::ThreadRef::try_impersonate(), foedus::storage::hash::HashTmpBin::update_record(), foedus::storage::masstree::MasstreeStorage::upsert_record(), and foedus::storage::masstree::MasstreeStorage::upsert_record_normalized().