"llvm/IR/InstrTypes.h"
中CmpInst::Predicate
类型的定义描述了LLVM中比较指令的类型:
enum Predicate {
// Opcode U L G E Intuitive operation
FCMP_FALSE = 0, ///< 0 0 0 0 Always false (always folded)
FCMP_OEQ = 1, ///< 0 0 0 1 True if ordered and equal
FCMP_OGT = 2, ///< 0 0 1 0 True if ordered and greater than
FCMP_OGE = 3, ///< 0 0 1 1 True if ordered and greater than or equal
FCMP_OLT = 4, ///< 0 1 0 0 True if ordered and less than
FCMP_OLE = 5, ///< 0 1 0 1 True if ordered and less than or equal
FCMP_ONE = 6, ///< 0 1 1 0 True if ordered and operands are unequal
FCMP_ORD = 7, ///< 0 1 1 1 True if ordered (no nans)
FCMP_UNO = 8, ///< 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
FCMP_UEQ = 9, ///< 1 0 0 1 True if unordered or equal
FCMP_UGT = 10, ///< 1 0 1 0 True if unordered or greater than
FCMP_UGE = 11, ///< 1 0 1 1 True if unordered, greater than, or equal
FCMP_ULT = 12, ///< 1 1 0 0 True if unordered or less than
FCMP_ULE = 13, ///< 1 1 0 1 True if unordered, less than, or equal
FCMP_UNE = 14, ///< 1 1 1 0 True if unordered or not equal
FCMP_TRUE = 15, ///< 1 1 1 1 Always true (always folded)
FIRST_FCMP_PREDICATE = FCMP_FALSE,
LAST_FCMP_PREDICATE = FCMP_TRUE,
BAD_FCMP_PREDICATE = FCMP_TRUE + 1,
ICMP_EQ = 32, ///< equal
ICMP_NE = 33, ///< not equal
ICMP_UGT = 34, ///< unsigned greater than
ICMP_UGE = 35, ///< unsigned greater or equal
ICMP_ULT = 36, ///< unsigned less than
ICMP_ULE = 37, ///< unsigned less or equal
ICMP_SGT = 38, ///< signed greater than
ICMP_SGE = 39, ///< signed greater or equal
ICMP_SLT = 40, ///< signed less than
ICMP_SLE = 41, ///< signed less or equal
FIRST_ICMP_PREDICATE = ICMP_EQ,
LAST_ICMP_PREDICATE = ICMP_SLE,
BAD_ICMP_PREDICATE = ICMP_SLE + 1
};
我想知道什么是"有序"one_answers"无序"谓词(如"如果有序且相等"或"如果无序,大于或等于"与正常的"unsigned greater or equal"相比)。
如果你不知道NaN是什么,从最后一段开始:)
如果至少有一个操作数是NaN,则有序浮点数比较和无序浮点数比较的结果是不同的。有关更多细节,请参阅IR lang参考中的fcmp说明。特别是这句话很重要:"有序意味着两个操作数都不是QNAN,而无序意味着两个操作数都可能是QNAN"。注意LLVM (AFAIK)不支持SNaN,这就是为什么lang只谈论QNaN。
命名的原因是NaN不能与浮点数进行比较。你不能说NaN小于或大于0。所以NaN是无序的。因此,如果其中一个操作数是NaN,则无序比较返回true。有序比较要求两个操作数都是数字。
这是关于NaN的维基百科页面,如果你需要背景知识的话。简单地说,当某些浮点计算的结果不是一个数字时,就会生成一个特殊的结果,称为NaN (not a number)。例如,如果您要求负数的平方根,' std::sqrt'将生成NaN。NaN有两种变体。SNaN和QNan。维基百科是这样描述的。对于您的问题,您可以忽略差异,因为只有QNaN重要。LLVM AFAIK不支持SNaN