K
KJ
Guest
On Sep 10, 9:56 am, Andy <jonesa...@comcast.net> wrote:
has some mutual exclusiveness property to it in some fashion OTHER
than coding it in that manner....and what I've been saying all along
(somewhat casually at first, a bit more forcefully in my Sept 7 post)
is that if you have some mutual exclusiveness than the functional code
(not the asserts) will directly support that by how it is coded...and
that means coding in a sum of products form or using an enumerated
type...period.
simple sum of products formation (an example way of 8->3 encoding is
below)
Encoded_OneHotInps(0) <= OneHotInps(1) xor OneHotInps(3) xor
OneHotInps(5) xor OneHotInps(7);
Encoded_OneHotInps(1) <= OneHotInps(2) xor OneHotInps(3) xor
OneHotInps(6) xor OneHotInps(7);
Encoded_OneHotInps(2) <= OneHotInps(4) xor OneHotInps(5) xor
OneHotInps(6) xor OneHotInps(7);
Using the above encoding followed by a 3->8 decoder function results
(using Quartus) exactly one logic element per output for a total of
8.
where 'OneHotInps' is an 8 input supposedly one hot input vector,
'Encoded_OneHotInps' is a 3 bit vector that encodes the information.
Just for grins I used 'xor', 'or' could also have been used. I can't
prove that it is 'minimal' but I'll bet you can play all kinds of
games with 'xor', 'or' or changing the function around a bit and get
the exact same result in terms of logic resource usage.
The mechanism for telling the compiler about the 'one hot' nature of
the input is not through an assertion (as you claim) or through a new
language keyword (as Weng claims is required) but through the actual
functional logic that is written. Any other formulation in VHDL using
a case statement or an if statement(s) (without Weng's proposed
'orif') is doomed because it will inherently encode either a priority
encoding (i.e. if/elsif/elsif/endif) or dependency on inputs that, in
fact, declares that maybe, just maybe, the inputs are not one hot
(i.e. using a case statement where the cases are something like "0001"
when REALLY you would like to say "---1")
The sum of products formation (or the product of sums for the DeMorgan
fans) is likely the best one that truly encodes the one hot nature of
the input because it logically depends on those inputs being one hot
and will produce an incorrect coding if somehow two or more of those
puppies ever got set. It does this by including multiples of those
supposedly one hot inputs into single equations taking full advantage
of the higher knowledge that only one term should ever fire for all of
the terms that are being 'or' or 'xor' -ed together.
There was great debate on just what Weng's 'orif' would do in certain
circumstances, even to the extent that proper indenting and color
coding would be needed but the bottom line is that 'orif' would have
to synthesize down to a sum of products implementation. My point back
to Weng, that he never responded to either time, was that he was
claiming superior performance or resource utilization. I seriously
doubt that, and he was unable to demonstrate anything that was an
improvement over what I believe to be best practice (enumerated types
or vector coding for the 'unconstrained number of enumerations'
situation). At best, 'orif' is a clearer and more productive way of
coding...not convinced that it is, but that's what it amounts to.
By the way, another interesting way to encode the one hots could be
the following....
Encoded_OneHotInps_var := (others => '0');
for i in OneHotInps'range loop
Encoded_OneHotInps_var := Encoded_OneHotInps_var + to_unsigned(i *
to_integer(unsigned'("0" & OneHotInps(i))),
Encoded_OneHotInps_var'length);
end loop;
Functionally this produces the exact same result given one hot inputs
as the previous example using 'xor' or 'or'. But the synthesized
result is larger (14 logic cells in Quartus). While the above code
snippet treats each of the inputs as an independent thing and depends
on the inputs really being one hot in order to produce a correct
result (just like the 'xor' implementation). At the moment I don't
quite understand why it is sub-optimal to a simpler sum of products
(maybe it's just a Quartus thing)...but it is.
have liked to say. But sim and synth both are treating them
appropriately per the language standard and the rules of boolean
logic.
type in this case would be an 'n bit' vector which represents the
coding of the various possibilities.
Starting from unencoded form and trying to claim 'one hot-ness'
without realizing that there really is a coded form that underlies the
'one hot-ness' is the fallacy. Not explicitly defining this coded
type as the basis for the claims of 'one hot-ness' results in sub-
optimal (larger logic resource usage) implementations. Once coded in
that manner, synthesis needs no additional help telling it about the
'one hot-ness'....such help is about as useful as getting coding tips
from the boss.
Asserting such knowledge is fruitless because synthesis' job is to
implement the functional logic (not the asserts) correctly. At best
the assertion is true, and therefore redundant since the functional
logic defines the same thing that is being described by the
assertion. At worst, the assertion is not always true and you don't
have a formal logic checker to find that out
KJ
of signals, impart some supreme insight that this arbitrary collectionOn Sep 8, 9:51 am, "KJ" <kkjenni...@sbcglobal.net> wrote:
snip
By "what we wanted", I meant that the subject of the thread, taken as
a whole, has to do with methods for optimally dealing with encodings
or conditions that are not by definition mutually exclusive, but are
functionally guaranteed to be so. A binary encoding is by definition
mutually exclusive, so starting with that would not demonstrate what
the thread, as a whole, seeks.
What 'the thread as a whole seeks' is to take an arbitrary collection
has some mutual exclusiveness property to it in some fashion OTHER
than coding it in that manner....and what I've been saying all along
(somewhat casually at first, a bit more forcefully in my Sept 7 post)
is that if you have some mutual exclusiveness than the functional code
(not the asserts) will directly support that by how it is coded...and
that means coding in a sum of products form or using an enumerated
type...period.
one's definition. The minimal way to do this is some form of theIn light of the thread subject, a more useful demonstration (which you
were not asked for) would be to demonstrate a conversion from a one-
hot vector to a binary or enumeration encoding, and back, with minimal
(preferably zero) logic. As you have pointed out, that is likely not
possible.
I claimed that zero logic is not possible, 'minimal' would depend on
simple sum of products formation (an example way of 8->3 encoding is
below)
Encoded_OneHotInps(0) <= OneHotInps(1) xor OneHotInps(3) xor
OneHotInps(5) xor OneHotInps(7);
Encoded_OneHotInps(1) <= OneHotInps(2) xor OneHotInps(3) xor
OneHotInps(6) xor OneHotInps(7);
Encoded_OneHotInps(2) <= OneHotInps(4) xor OneHotInps(5) xor
OneHotInps(6) xor OneHotInps(7);
Using the above encoding followed by a 3->8 decoder function results
(using Quartus) exactly one logic element per output for a total of
8.
where 'OneHotInps' is an 8 input supposedly one hot input vector,
'Encoded_OneHotInps' is a 3 bit vector that encodes the information.
Just for grins I used 'xor', 'or' could also have been used. I can't
prove that it is 'minimal' but I'll bet you can play all kinds of
games with 'xor', 'or' or changing the function around a bit and get
the exact same result in terms of logic resource usage.
The mechanism for telling the compiler about the 'one hot' nature of
the input is not through an assertion (as you claim) or through a new
language keyword (as Weng claims is required) but through the actual
functional logic that is written. Any other formulation in VHDL using
a case statement or an if statement(s) (without Weng's proposed
'orif') is doomed because it will inherently encode either a priority
encoding (i.e. if/elsif/elsif/endif) or dependency on inputs that, in
fact, declares that maybe, just maybe, the inputs are not one hot
(i.e. using a case statement where the cases are something like "0001"
when REALLY you would like to say "---1")
The sum of products formation (or the product of sums for the DeMorgan
fans) is likely the best one that truly encodes the one hot nature of
the input because it logically depends on those inputs being one hot
and will produce an incorrect coding if somehow two or more of those
puppies ever got set. It does this by including multiples of those
supposedly one hot inputs into single equations taking full advantage
of the higher knowledge that only one term should ever fire for all of
the terms that are being 'or' or 'xor' -ed together.
There was great debate on just what Weng's 'orif' would do in certain
circumstances, even to the extent that proper indenting and color
coding would be needed but the bottom line is that 'orif' would have
to synthesize down to a sum of products implementation. My point back
to Weng, that he never responded to either time, was that he was
claiming superior performance or resource utilization. I seriously
doubt that, and he was unable to demonstrate anything that was an
improvement over what I believe to be best practice (enumerated types
or vector coding for the 'unconstrained number of enumerations'
situation). At best, 'orif' is a clearer and more productive way of
coding...not convinced that it is, but that's what it amounts to.
By the way, another interesting way to encode the one hots could be
the following....
Encoded_OneHotInps_var := (others => '0');
for i in OneHotInps'range loop
Encoded_OneHotInps_var := Encoded_OneHotInps_var + to_unsigned(i *
to_integer(unsigned'("0" & OneHotInps(i))),
Encoded_OneHotInps_var'length);
end loop;
Functionally this produces the exact same result given one hot inputs
as the previous example using 'xor' or 'or'. But the synthesized
result is larger (14 logic cells in Quartus). While the above code
snippet treats each of the inputs as an independent thing and depends
on the inputs really being one hot in order to produce a correct
result (just like the 'xor' implementation). At the moment I don't
quite understand why it is sub-optimal to a simpler sum of products
(maybe it's just a Quartus thing)...but it is.
use of "0001" as a case value instead of "---1" that you would reallySeveral options have been proposed within the existing language and
tool capabilities, but they are all limited to either data types that
include a "don't care" value understood by synthesis,
Simulation doesn't really like the "don't care" either...witness your
have liked to say. But sim and synth both are treating them
appropriately per the language standard and the rules of boolean
logic.
or that support
an OR operation between values.
And what's wrong with that?
coded vector. The number of 'enumerations' would be 2**n. Your rootIt is possible that an enum value
could be treated as a don't care if nothing is done in response to it,
but I have not tried that. Methods capable of dealing with
unconstrained dimensions of input and output would be required as
well.
The unconstrained (i.e. parameterizable) enumerated type is simply a
type in this case would be an 'n bit' vector which represents the
coding of the various possibilities.
Starting from unencoded form and trying to claim 'one hot-ness'
without realizing that there really is a coded form that underlies the
'one hot-ness' is the fallacy. Not explicitly defining this coded
type as the basis for the claims of 'one hot-ness' results in sub-
optimal (larger logic resource usage) implementations. Once coded in
that manner, synthesis needs no additional help telling it about the
'one hot-ness'....such help is about as useful as getting coding tips
from the boss.
Asserting such knowledge is fruitless because synthesis' job is to
implement the functional logic (not the asserts) correctly. At best
the assertion is true, and therefore redundant since the functional
logic defines the same thing that is being described by the
assertion. At worst, the assertion is not always true and you don't
have a formal logic checker to find that out
KJ