-
Notifications
You must be signed in to change notification settings - Fork 43
/
Bitmask_Isolate_Rightmost_1_Bit.html
52 lines (43 loc) · 1.71 KB
/
Bitmask_Isolate_Rightmost_1_Bit.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<html>
<head>
<link rel="shortcut icon" href="./favicon.ico">
<link rel="stylesheet" type="text/css" href="./style.css">
<link rel="canonical" href="./Bitmask_Isolate_Rightmost_1_Bit.html">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Credit: [Hacker's Delight](./reading.html#Warren2013), Section 2-1: Manipulating Rightmost Bits">
<title>Bitmask Isolate Rightmost 1 Bit</title>
</head>
<body>
<p class="inline bordered"><b><a href="./Bitmask_Isolate_Rightmost_1_Bit.v">Source</a></b></p>
<p class="inline bordered"><b><a href="./legal.html">License</a></b></p>
<p class="inline bordered"><b><a href="./index.html">Index</a></b></p>
<h1>Bitmask: Isolate Rightmost 1 Bit</h1>
<p>Credit: <a href="./reading.html#Warren2013">Hacker's Delight</a>, Section 2-1: Manipulating Rightmost Bits</p>
<p>Use the following formula to isolate the rightmost 1-bit, producing 0 if
none (e.g., 01011000 -> 00001000)</p>
<p>This function can trivially implement a <a href="./Arbiter_Priority.html">Priority
Arbiter</a>, with the highest priority given to the
least-significant bit, and is the building block of more complex arbiters.</p>
<pre>
`default_nettype none
module <a href="./Bitmask_Isolate_Rightmost_1_Bit.html">Bitmask_Isolate_Rightmost_1_Bit</a>
#(
parameter WORD_WIDTH = 0
)
(
input wire [WORD_WIDTH-1:0] word_in,
output reg [WORD_WIDTH-1:0] word_out
);
initial begin
word_out = {WORD_WIDTH{1'b0}};
end
always @(*) begin
word_out = word_in & (-word_in);
end
endmodule
</pre>
<hr>
<p><a href="./index.html">Back to FPGA Design Elements</a>
<center><a href="https://fpgacpu.ca/">fpgacpu.ca</a></center>
</body>
</html>