MSVC可能/不太可能的等价物 [英] likely/unlikely equivalent for MSVC

查看:284
本文介绍了MSVC可能/不太可能的等价物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GCC编译器支持用于定义可能和不可能的宏的__builtin_expect语句。



例如

  #define likely(expr)__builtin_expect(!(expr),0)
#define likely(expr)__builtin_expect((expr),0)



是否有Microsoft Visual C编译器的等效语句或等价语句?

解决方案

我说只是punt



没有什么喜欢。有 __assume(),但不要 t使用它,它是一种不同的优化器指令。



真的,gnu内置的包装在宏中的原因是,你可以自动摆脱它 __ GNUC __ 未定义。



摘要



只要在非GNU上除去(null out) *可能。你不会错过它。


GCC compiler supports __builtin_expect statement that is used to define likely and unlikely macros.

eg.

#define likely(expr)    __builtin_expect(!(expr), 0)
#define unlikely(expr)  __builtin_expect((expr),  0)

Is there an equivalent statement for the Microsoft Visual C compiler, or something equivalent ?

解决方案

I say just punt

There is nothing like it. There is __assume(), but don't use it, it's a different kind of optimizer directive.

Really, the reason the gnu builtin is wrapped in a macro is so you can just get rid of it automatically if __GNUC__ is not defined. There isn't anything the least bit necessary about those macros and I bet you will not notice the run time difference.

Summary

Just get rid of (null out) *likely on non-GNU. You won't miss it.

这篇关于MSVC可能/不太可能的等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆