二进制数比较
如果我有一个 32 位二进制补码数字,并且我想知道知道两个数字相等的最简单方法是什么...知道这个的最快按位运算符是什么?我知道对两个数字进行异或并检查结果是否为零效果很好......还有其他的吗?
如果一个数字大于0怎么办?我可以检查第 31 位,看看它是否大于或等于 0..但是 bgtz 怎么样?
If I have a 32 bit two's complement number and I want to know what is the easiest way to know of two numbers are equal... what would be the fastest bitwise operator to know this? I know xor'ing both numbers and check if the results are zero works well... any other one's?
how about if a number is greater than 0?? I can check the 31'st bit to see if it's greater or equal to 0..but how about bgtz?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
与您的评论相反,“==”是 Verilog 的一部分,除非我今晚的记忆力比平常差很多,否则它应该可以很好地综合。例如,您可以编写如下内容:
Verilog 还支持您通常期望的其他比较运算符(!=、<= 等)。合成器相当“智能”,因此像
x != 0
这样的东西通常会合成到 N 输入 OR 门而不是比较器。Contrary to your comments, '==' is part of Verilog, and unless my memory is a lot worse than usual tonight, it should synthesize just fine. Just for example, you could write something like:
Verilog also supports the other comparison operators you'd normally expect (!=, <=, etc.). Synthesizers are fairly "smart", so something like
x != 0
will normally synthesize to an N-input OR gate instead of a comparator.如果您可以进行异或,然后将结果与零进行比较,那么您可以将结果与某个值进行比较,如果您可以将某个值与某个值进行比较,那么您可以只比较这两个值,而无需使用异或和 32 位零。
if you can xor and then compare the result with zero then you can compare a result with some value and if you can compare something to a value then you can just compare the two values without using an xor and a 32 bit zero.