8#ifndef INCLUDED_BSLS_PERFORMANCEHINT
9#define INCLUDED_BSLS_PERFORMANCEHINT
403#include <bsls_platform.h>
405#if defined(BSLS_PLATFORM_CMP_IBM)
409#if defined(BSLS_PLATFORM_CMP_HP)
410#include <machine/sys/builtins.h>
412#include <machine/sys/inline.h>
415#if defined(BSLS_PLATFORM_CMP_SUN)
416#include <sun_prefetch.h>
421#if defined(BSLS_PLATFORM_CMP_MSVC)
422#if !defined(BSLS_PLATFORM_CPU_ARM)
423#include <xmmintrin.h>
438#if defined(BDE_BUILD_TARGET_OPT) && \
439 (defined(BSLS_PLATFORM_CMP_CLANG) || \
440 defined(BSLS_PLATFORM_CMP_GNU) || \
441 defined(BSLS_PLATFORM_CMP_IBM))
443 #define BSLS_PERFORMANCEHINT_PREDICT_LIKELY(expr) \
444 __builtin_expect(!!(expr), 1)
445 #define BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(expr) \
446 __builtin_expect(!!(expr), 0)
447 #define BSLS_PERFORMANCEHINT_PREDICT_EXPECT(expr, value) \
448 __builtin_expect((expr), (value))
451 #define BSLS_PERFORMANCEHINT_PREDICT_LIKELY(expr) (expr)
452 #define BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(expr) (expr)
453 #define BSLS_PERFORMANCEHINT_PREDICT_EXPECT(expr, value) (expr)
460#if defined(BSLS_PLATFORM_CMP_CLANG)
461 #if __has_attribute(cold)
462 #define BSLS_PERFORMANCEHINT_ATTRIBUTE_COLD __attribute__((cold))
464#elif defined(BSLS_PLATFORM_CMP_GNU)
465 #define BSLS_PERFORMANCEHINT_ATTRIBUTE_COLD __attribute__((cold))
468#if !defined(BSLS_PERFORMANCEHINT_ATTRIBUTE_COLD)
469 #define BSLS_PERFORMANCEHINT_ATTRIBUTE_COLD
471 #define BSLS_PERFORMANCEHINT_HAS_ATTRIBUTE_COLD 1
476#if defined(BDE_BUILD_TARGET_OPT) && defined(BSLS_PLATFORM_CMP_SUN)
477 #define BSLS_PERFORMANCEHINT_UNLIKELY_HINT \
478 BloombergLP::bsls::PerformanceHint::rarelyCalled()
479#elif defined(BDE_BUILD_TARGET_OPT) && \
480 (defined(BSLS_PLATFORM_CMP_IBM) || BSLS_PERFORMANCEHINT_HAS_ATTRIBUTE_COLD)
481 #define BSLS_PERFORMANCEHINT_UNLIKELY_HINT \
482 BloombergLP::bsls::PerformanceHint::lowFrequency()
484 #define BSLS_PERFORMANCEHINT_UNLIKELY_HINT
491#if defined(BSLS_PLATFORM_CMP_IBM)
493 #define BSLS_PERFORMANCEHINT_OPTIMIZATION_FENCE __fence()
495#elif defined(BSLS_PLATFORM_CMP_MSVC)
497 #pragma intrinsic(_ReadWriteBarrier)
498 #define BSLS_PERFORMANCEHINT_OPTIMIZATION_FENCE _ReadWriteBarrier()
500#elif defined(BSLS_PLATFORM_CMP_HP)
502 #define BSLS_PERFORMANCEHINT_OPTIMIZATION_FENCE \
503 _Asm_sched_fence(_UP_MEM_FENCE|_DOWN_MEM_FENCE)
505#elif defined(BSLS_PLATFORM_CMP_SUN)
507 #define BSLS_PERFORMANCEHINT_OPTIMIZATION_FENCE __compiler_barrier()
509#elif defined(BSLS_PLATFORM_CMP_GNU) \
510 || defined(BSLS_PLATFORM_CMP_CLANG)
512 #define BSLS_PERFORMANCEHINT_OPTIMIZATION_FENCE asm volatile("":::"memory")
515 #error "BSLS_PERFORMANCEHINT_OPTIMIZATION_FENCE not implemented"
549#if defined(BDE_BUILD_TARGET_OPT)
550#if defined(BSLS_PLATFORM_CMP_SUN)
553#pragma rarely_called(rarelyCalled)
559#pragma no_side_effect(rarelyCalled)
584#if defined(BSLS_PLATFORM_CMP_GNU) || defined(BSLS_PLATFORM_CMP_CLANG)
586 __builtin_prefetch(address, 0);
588#elif defined(BSLS_PLATFORM_CMP_IBM)
590 __dcbt(
const_cast<void *
>(address));
592#elif defined(BSLS_PLATFORM_CMP_SUN)
594 sparc_prefetch_read_many(
const_cast<void *
>(address));
596#elif defined(BSLS_PLATFORM_CMP_MSVC)
598#if !defined(BSLS_PLATFORM_CPU_ARM)
599 _mm_prefetch(
static_cast<const char*
>(address), _MM_HINT_T0);
605#elif defined(BSLS_PLATFORM_CMP_HP)
607 _Asm_lfetch(_LFTYPE_NONE, _LFHINT_NTA, address);
619#if defined(BSLS_PLATFORM_CMP_GNU) || defined(BSLS_PLATFORM_CMP_CLANG)
621 __builtin_prefetch(address, 1);
623#elif defined(BSLS_PLATFORM_CMP_IBM)
627#elif defined(BSLS_PLATFORM_CMP_SUN)
629 sparc_prefetch_write_many(address);
631#elif defined(BSLS_PLATFORM_CMP_MSVC)
633#if !defined(BSLS_PLATFORM_CPU_ARM)
634 _mm_prefetch(
static_cast<const char*
>(address), _MM_HINT_T0);
640#elif defined(BSLS_PLATFORM_CMP_HP)
642 _Asm_lfetch_excl(_LFTYPE_NONE, _LFHINT_NTA, address);
658#if defined(BDE_BUILD_TARGET_OPT) && defined(BSLS_PLATFORM_CMP_IBM)
660#pragma execution_frequency(very_low)
667#ifndef BDE_OPENSOURCE_PUBLICATION
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlt_iso8601util.h:691