IRC channel logs

2025-02-15.log

back to list of logs

<matrix_bridge><Andrius Štikonas> gtker: I've now merged pointer arithmetic fix for riscv32 and riscv64 (and also x86/amd64 was working before)
<matrix_bridge><Andrius Štikonas> unfortunately aarch64 is also broken
<matrix_bridge><Andrius Štikonas> and I wouldn't be surprised if arm7a and knight also need some fixes...
<stikonas>ok, M2-Planet for aarch64 is now fixed too...
<stikonas>hmm, arm and knight might be fine from what I can see without testing
<stikonas>oriansj: I know why unxz crashes on RISC-V...
<stikonas>(write-up is here https://github.com/oriansj/M2-Planet/issues/56)
<stikonas>unxz on riscv32 fixed, there is unforunately another crash on riscv64 (https://github.com/oriansj/M2-Planet/commit/ba2bb4843ee36a2e173fb3231cb0d376c27587e9)
<oriansj>stikonas: hmmm, M1 and hex2 should both throw an error if !number or !label exceeds the limits of the prefix size type
<oriansj>oh most architectures use express_number and risc-v uses express_word which doesn't bounds check
<stikonas>yeah, it should have bounds check
<stikonas>that's one of the things we forgot...
<oriansj>which is probably the root cause for most of the RISC-V bugs in M2-Planet
<stikonas>we could have founds this crash (and possibly other crashes ) much earlier
<stikonas>yeah, though we don't have that many of them
<stikonas>since we can bootstrap mes...
<stikonas>well, there is another riscv64 crash
<stikonas>not sure what causes it yet
<stikonas>and it's getting late today, so I won't look further
<oriansj>and I guess I need to look up the RISC-V integer ranges for the different encoding types
<stikonas>well, ! (I instruction) is 12 bits
<oriansj>(this may break a great many RISC-V programs in the the short term)
<stikonas>but only 11 bits are good for unsigned
<stikonas>that's the main limitation that is worth checking
<oriansj>I was going to use bound_values(displacement, number_of_bytes, -129, 256); sort of thing
<stikonas>so I instructions (! token) is from -2048 to 2047
<oriansj>added to M1
<stikonas>thanks
<stikonas>hmm, just noticed somebody is complaining about powerpc test https://github.com/oriansj/mescc-tools/issues/47
<oriansj>that is fine, I was planning to redo powerpc using word instead of byte
<stikonas>oh yeah, that would be nice
<stikonas>anyway, I'll be going to sleep now. Did quite a bit this evening. Plus gtker is also doing even more work recently
<oriansj>hmm U-format seems to drop the bottom 12bits of the immediate
<stikonas>I think that's because you are supposed to load high bits with U instruction
<stikonas>and low bits with I
<stikonas>see this constant_load function https://github.com/oriansj/M2-Planet/blob/ba2bb4843ee36a2e173fb3231cb0d376c27587e9/cc_core.c#L407
<oriansj>we may have to change that to not conflict with bounds checking
<matrix_bridge><Andrius Štikonas> Hmm, this is used a lot I think
<oriansj>yeah and probably why we skipped bounds checking previously
<matrix_bridge><Andrius Štikonas> Can we check just high bits then?
<matrix_bridge><Andrius Štikonas> A bit incomplete...
<matrix_bridge><Andrius Štikonas> But otherwise all codegen code in M2-planet and cc_* would be much longer
<matrix_bridge><Andrius Štikonas> Oh and sometimes it is a label
<matrix_bridge><Andrius Štikonas> So displacement will contain low bits
<oriansj>yeah but M1 doesn't touch the labels
<oriansj>only the ~1234 looking things
<oriansj>we also could be slightly less optimal and leverage the same trick we used with armv7l and aarch64 and knight
<oriansj>then it'll be %01234567
<oriansj>and will fix the 31bit arithmetic bugs in RISC-V as well
<matrix_bridge><Andrius Štikonas> Yeah, that could work too...
<matrix_bridge><Andrius Štikonas> We have similar bug everywhere where we load constants...
<matrix_bridge><Andrius Štikonas> New riscv pointer arithmetic also breaks with 12 bit sized types
<matrix_bridge><Andrius Štikonas> Though that is probably less of a problem in practice
<oriansj>hmmm, we don't have J format support
<oriansj>so we may need a single hard-coded instruction for the jump-over; also RISC-V doesn't support efficient PC relative loading. So we might need to save the link register in a register, do a jump and link, use the link register to do the relative load, then restore the old link register value.
<matrix_bridge><Andrius Štikonas> J is obsolete isn't it?
<matrix_bridge><Andrius Štikonas> Oh actually no
<matrix_bridge><Andrius Štikonas> J are jumps
<matrix_bridge><Andrius Štikonas> That is mostly needed for labels
<matrix_bridge><Andrius Štikonas> I think I used @ as a workaround for short numeric jumps
<oriansj>yeah B format (formorly SB)
<oriansj>we have UJ format with $ (which might just be the old name for J)
<oriansj>but that is hex2 only and not in M1
<matrix_bridge><Andrius Štikonas> But is that useful in M1?
<oriansj>well, we would be trying to encode approximately jal 4
<matrix_bridge><Andrius Štikonas> Oh for storing 32 bit constants
<matrix_bridge><Andrius Štikonas> Hmm
<matrix_bridge><Andrius Štikonas> rs1_x0 @4 bnez?
<matrix_bridge><Andrius Štikonas> Well, register is zero...so maybe just
<matrix_bridge><Andrius Štikonas> @4 bnez
<matrix_bridge><Andrius Štikonas> Probably slower in cpu
<oriansj>I'd rather slow and correct over fast and buggy
<matrix_bridge><Andrius Štikonas> (Without branch prediction)
<matrix_bridge><Andrius Štikonas> Yeah, I don't worry too much about speed
<oriansj>we can also do something more complex where we look at the immediate and if it fits in 12 bits we just do a direct load of the immediate and otherwise do the slower route
<oriansj>looks like erc eventually runs out of RAM and crashes
<stikonas>oriansj: erc?
<oriansj>irc client that runs in emacs that I use to talk here
<stikonas>oh I see
<stikonas>anyway, I don't think there was much said here while you were away
<stikonas>I've merged a couple of PRs from gtker...
<stikonas>as for those addi bounds, I've checked which functions could cause problems https://github.com/oriansj/M2-Planet/issues/77 with large objects
<stikonas>perhaps one of them is causing the remaining unxz crash
<oriansj>hopefully
<stikonas>well, it doesn't crash on riscv32
<stikonas>and those two assemblies are really similar
<stikonas>(but rv32 has smaller pointers, so probably still fit in the bound)
<oriansj>or the sign extension behavior of riscv64 is causing the problem
<oriansj>as 32bit wouldn't hit any sign extension behaviors on 4byte values
<stikonas>yeah, addi vs addiw I guess