From 5fee69debbd8fe5ba0cda7db583c2de7af64f0e0 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 2 Aug 2016 18:49:42 +1000 Subject: [PATCH] annotation: add likely/unlikely functions --- Makefile.am | 1 + annotation.hpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 annotation.hpp diff --git a/Makefile.am b/Makefile.am index 7886b2fd..5690cd00 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,6 +32,7 @@ UTIL_FILES = \ alloc/null.hpp \ alloc/stack.cpp \ alloc/stack.hpp \ + annotation.hpp \ ascii.hpp \ backtrace.hpp \ bezier.cpp \ diff --git a/annotation.hpp b/annotation.hpp new file mode 100644 index 00000000..7f74fe11 --- /dev/null +++ b/annotation.hpp @@ -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 + */ + +#ifndef __UTIL_ANNOTATION_HPP +#define __UTIL_ANNOTATION_HPP + +template +constexpr inline +bool +likely (T &&t) +{ return __builtin_expect (!!t, true); } + + +template +constexpr inline +bool +unlikely (T &&t) +{ return __builtin_expect (!!t, false); } + +#endif