Binary comparison

If I have a 32-bit number with two additions, and I want to know that the easiest way to learn about two numbers is equal ... what would be the fastest bitwise operator to know about this? I know xor'ing both numbers and check if the result 0 works well ... any other?

how about if the number is greater than 0 ?? I can check the 31st bit to see if it is greater than or equal to 0 ... but what about bgtz?

+3
source share
3 answers

Unlike your comments, '==' is part of Verilog, and if my memory is much worse today than usual, it should be synthesized just fine. For example, you can write something like:

// warning: untested, incomplete and utterly useless in any case.
// It been a while since I wrote much Verilog, so my syntax is probably a bit off
// anyway (might well be more like VHDL than it should be).
//
module add_when_equal(clock, a, b, x, y, z);
input clock;
input [31:0] a, b, x, y;
output [31:0] z;
reg [31:0] a, b, x, y, z;

always begin: main
   @(posedge clock);
   if (a == b)
       z <= x + y;
end
endmodule;

Verilog , (! =, <= ..). "", - x != 0 N- .

+9
// this should work as comparator for Equality
wire [31:0] Cmp1, Cmp2;
wire Equal;
assign Equal  =  &{Cmp1 ~^ Cmp2}; // using XNOR
assign Equal  = ~|{Cmp1  ^ Cmp2}; // using XOR
+1

if you can xor and then compare the result with zero, then you can compare the result with some value, and if you can compare something with the value, you can simply compare two values ​​without using xor and 32-bit zero.

0
source

Source: https://habr.com/ru/post/1744268/


All Articles