annotation: add likely/unlikely functions

This commit is contained in:
Danny Robson 2016-08-02 18:49:42 +10:00
parent 7e0875628b
commit 5fee69debb
2 changed files with 34 additions and 0 deletions

View File

@ -32,6 +32,7 @@ UTIL_FILES = \
alloc/null.hpp \ alloc/null.hpp \
alloc/stack.cpp \ alloc/stack.cpp \
alloc/stack.hpp \ alloc/stack.hpp \
annotation.hpp \
ascii.hpp \ ascii.hpp \
backtrace.hpp \ backtrace.hpp \
bezier.cpp \ bezier.cpp \

33
annotation.hpp Normal file
View File

@ -0,0 +1,33 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2011 Danny Robson <danny@nerdcruft.net>
*/
#ifndef __UTIL_ANNOTATION_HPP
#define __UTIL_ANNOTATION_HPP
template <typename T>
constexpr inline
bool
likely (T &&t)
{ return __builtin_expect (!!t, true); }
template <typename T>
constexpr inline
bool
unlikely (T &&t)
{ return __builtin_expect (!!t, false); }
#endif