- Posts: 3410
- Thank you received: 0
LUT5
Why is it a _5_ element lookup? where does that number come from? The answer is that 2 ^ 5 is 32. And HAL uses 32-bit numbers.
The "magic number" you use in the HAL file is just a list of 32 possible output values. Each bit in the 32-bit number corresponds to one of the possible combinations of input pins.
Imagine it was LUT2 and we wanted an AND gate. The truth table is
0 0 = 0
0 1 = 0
1 0 = 0
1 1 = 1
the first line is binary 0. so bit 0 is 0. (ir the desired output for an input of 0 0)
The second line is binary 1, so bit 1 is 0. ditto line 2 (binary 2).
The last line, binary 3, is required to have an output of 1. Listing the outputs in sequence, we have 1000. (just read up the final column) That is 8 (or 8 in hex
The 2-input XOR would be
0 0 = 0
0 1 = 1
1 0 = 1
1 1 = 0
Which is 0110 in binary, or 6.
How about an XOR with an "over-ride" in input 2 (counting from 0, so the third one).
0 0 0 = 0
0 0 1 = 1
0 1 0 = 1
0 1 1 = 0
1 0 0 = 1
1 0 1 = 1
1 1 0 = 1
1 1 1 = 1
That's b11110110 or 246 decimal or 0xF6 hex.
And as a final 3-bit example, if exactly 2 inputs are set... (which isn't any kind of boolean logic at all)
0 0 0 = 0
0 0 1 = 0
0 1 0 = 0
0 1 1 = 1
1 0 0 = 0
1 0 1 = 1
1 1 0 = 1
1 1 1 = 0
The magic number here is b01101000 or 104 decimal or 0x68
The component doesn't use any internal logic at all. It just looks at the input values, interprets those as a number from 0 to 31, and outputs the bit from the LUT value corresponding.
This is rather neat, as it means that we can combine the 5 inputs in any way we like.
I rather think that the existing docs massively complicate and obfuscate the way that it works with all the talk of summing of weights. it is rather simpler to think in terms of writing out the truth table and converting the output column from binary to hex or decimal.
Please Log in to join the conversation.
PCW wrote: Note that LUT5 will generate any of the 4,294,967,296
logical functions of 5 inputs
Actually, there are only 32 possible outputs of 5 inputs
You are describing LUT32 which awaits the creation of the 4,294,967,296-bit CPU
Please Log in to join the conversation.
andypugh wrote: And as a final 3-bit example, if exactly 2 inputs are set... (which isn't any kind of boolean logic at all)
0 0 0 = 0
0 0 1 = 0
0 1 0 = 0
0 1 1 = 1
1 0 0 = 0
1 0 1 = 1
1 1 0 = 1
1 1 1 = 0
The magic number here is b01101000 or 104 decimal or 0x68
The component doesn't use any internal logic at all. It just looks at the input values, interprets those as a number from 0 to 31, and outputs the bit from the LUT value corresponding.
This is rather neat, as it means that we can combine the 5 inputs in any way we like.
I rather think that the existing docs massively complicate and obfuscate the way that it works with all the talk of summing of weights. it is rather simpler to think in terms of writing out the truth table and converting the output column from binary to hex or decimal.
How do you compute the binary value?
John
Please Log in to join the conversation.
BigJohnT wrote: That is the question, unfortunately it is Greek to me as to how to "read" the output column.
The bottom number is a 0, so the first digit is zero. The next digit up is 1, so the next digit in the number is 1 and so on.
(As an aside the Ubuntu calculator, in View -> programmer mode, displays the bit-pattern corresponding to any number, and you can actually twiddle individual bits in the binary panel)
Please Log in to join the conversation.
0 0 0 0 0 =
0 0 0 0 1 =
0 0 0 1 0 =
0 0 0 1 1 =
0 0 1 0 0 =
0 0 1 0 1 =
0 0 1 1 0 =
0 0 1 1 1 =
0 1 0 0 0 =
0 1 0 0 1 =
0 1 0 1 0 =
0 1 0 1 1 =
0 1 1 0 0 =
0 1 1 0 1 =
0 1 1 1 0 =
0 1 1 1 1 =
1 0 0 0 0 =
1 0 0 0 1 =
1 0 0 1 0 =
1 0 0 1 1 =
1 0 1 0 0 =
1 0 1 0 1 =
1 0 1 1 0 =
1 0 1 1 1 =
1 1 0 0 0 =
1 1 0 0 1 =
1 1 0 1 0 =
1 1 0 1 1 =
1 1 1 0 0 =
1 1 1 0 1 =
1 1 1 1 0 =
1 1 1 1 1 =
Please Log in to join the conversation.
