_whitelogger has joined #m-labs
<lekernel> thx
lekernel changed the topic of #m-labs to: Mixxeo, Migen, MiSoC & other M-Labs projects :: fka #milkymist :: Logs http://irclog.whitequark.org/m-labs
whitequark has left #m-labs [#m-labs]
jaeckel has joined #m-labs
jaeckel has quit [Changing host]
jaeckel has joined #m-labs
Mistah_Darcy has joined #m-labs
mrueg has joined #m-labs
kristianpaul has joined #m-labs
kristianpaul has joined #m-labs
kristianpaul has quit [Ping timeout: 264 seconds]
kristianpaul has joined #m-labs
kristianpaul has joined #m-labs
antgreen has joined #m-labs
xiangfu has quit [Remote host closed the connection]
antgreen has quit [Ping timeout: 245 seconds]
Mistah_Darcy_ has joined #m-labs
davidc__ has joined #m-labs
Mistah_Darcy has quit [Ping timeout: 246 seconds]
Mistah_Darcy_ has quit [Ping timeout: 265 seconds]
sh4rm4 has joined #m-labs
Mistah_Darcy has joined #m-labs
rjo has joined #m-labs
jevin has joined #m-labs
jevin has quit [Quit: Textual IRC Client: www.textualapp.com]
Mistah_Darcy has quit [Ping timeout: 246 seconds]
<lekernel> 3'sd1 - 3'sd4 = 5
<lekernel> ...what actually happens is that 4 is the sign bit in "3'sd4", which gets extended to -4 when the target is more than 3 bits. and it becomes 1 - (-4) = 5
<lekernel> thus the rule: in verilog, when you want to represent the most negative integer, you should write its absolute (positive) value instead :)
Mistah_Darcy has joined #m-labs
Mistah_Darcy has quit [Read error: Connection reset by peer]
Mistah_Darcy has joined #m-labs
<GitHub36> [migen] sbourdeauducq pushed 1 new commit to master: http://git.io/d2s6Dg
<GitHub36> migen/master 135a4fe Sebastien Bourdeauducq: fhdl/verilog: fix representation of negative integers...
<lekernel> rjo, your test passes now. -1'sd1 was 1 in Verilog :)
<rjo> lekernel: that's horrible ;)
<rjo> lekernel: thanks for looking into this. i didn't have the guts to dive that deep into verilog.
mumptai has joined #m-labs
<rjo> lekernel: that means verilog does sign extend literal constants even when they do not have a "-" that would indicate their negativity?
<lekernel> it sign-extends operands when the context is signed
<lekernel> the signedness of the context is defined by the signedness of all operands
<lekernel> and you can mark literal constants as signed by using 's
<lekernel> in which case the MSB is the sign bit, and you have to set it manually - using the unary minus before the literal fails for the most negative integer, as we have seen :)
<lekernel> you can also mark any part of an expression as signed by using $signed (Migen inserts those to provide better sign extension rules)
<rjo> lekernel: would writing -4'sd4 not work in a 3-bit signed context?
<lekernel> it would work
<rjo> lekernel: would it not be more readable?
<lekernel> but because that literal would make it a 4-bit context
<lekernel> it would make it more readable, but then, it breaks the rule that literals use their minimum number of bits
<lekernel> which can cause problems e.g. when putting them in Cat() or Replicate()
<mumptai> hey, it contains pixelated men and pretty colors ;)
<rjo> lekernel: ok. understood. but i dont see why verilog is unable to represent the most negative integer using a unary minus. i do understand why 3'sd4 is "wrong" in the sense that it either invalid or -4. But why is -3'sd4 not -4? Just because --3'sd4 != 3'sd4 then?
<lekernel> because 3'sd4 is -4
<rjo> that presentation seriously lacks some WordArt and yellow text.
<lekernel> as the 3rd bit (MSB) is the sign bit, which would have weight 4 if the value wasn't signed
<rjo> lekernel: wouldn't you want 3'sd4 to be invalid in a better world?
<lekernel> yes, but then you can't represent -4, as the unary minus won't let you
<lekernel> (you need an extra bit to represent the absolute value of the most negative integer)
<rjo> lekernel: hmm
<lekernel> right now, migen spits out the explicit two's complement representation of the value, and tells Verilog to treat the MSB as sign bit
<lekernel> it's a straightforward solution, which has the inconvenience of making negative values less readable in the generated code
<lekernel> and you get things like 1'sd1 for -1, which is horrible, but works ...
<rjo> lekernel: so this is the only way to represent the most negative signed integer without wrongly increasing the bit-width of the context?
sh4rm4 has quit [Ping timeout: 264 seconds]
Mistah_Darcy_ has joined #m-labs
mumptai has quit [Quit: Verlassend]
<lekernel> I think so
Mistah_Darcy has quit [Read error: Connection reset by peer]
<lekernel> ah, no
<lekernel> -1'd1 works
<lekernel> :)
sh4rm4 has joined #m-labs
<lekernel> hmm, actually, I could have simply dropped the "s", since the unary minus also makes the context signed
<lekernel> ah, no, it does not
<lekernel> -1'd1*5'sd5 is 155
<lekernel> 1'sd1*5'sd5 is -5 as one would expect
<lekernel> $signed(-1'd1)*5'sd5 also works
<lekernel> but is quite heavy
<lekernel> Verilog is such a terrible language o__O
<lekernel> rjo, so, which is less bad?
<lekernel> 1) $signed(-'d<human readable value>)
<lekernel> 2) 'sd<explicit two's complement value>
<lekernel> 3) 'sd<explicit two's complement value> /* <human readable value> */
lekernel has quit [Quit: Leaving]