<Michcioperz>
anyway zig's docs for its asm stmt seem much more practical than gcc's
<fgenesis>
"Architectures - All of them."
<s-ol>
sorry, was gone for lunch
<s-ol>
i actually found it, porting from C I forgot to change one occurence of %2 to %[name]
<Michcioperz>
i spent some time fighting gcc's asm before learning from a teacher that you can `register int x __asm__("r11");` or something
<pixelherodev>
Michcioperz: the latter is what Zig uses for the CBE now
<Michcioperz>
i'll just uh
<scientes>
no, but I kinda got disgruntled with zig because I thought it was trying to fix things that are not excessively broken, instead of polishing up what are some really cool features: 1. trapping undefined, 2. comp-time, 3. awareness of multiple ways to allocate memory
<pixelherodev>
Being able to bind values to registers like that is much more convenient
<Michcioperz>
never look inside CBE code
<pixelherodev>
Michcioperz: CBE is actually really straightforward
<Michcioperz>
i don't doubt it
<scientes>
so I started feeling that it would be better to try to improve C, and bringing these features to C
<Michcioperz>
i just feel like i've seen enough C last year
<scientes>
because zig and C, and C's SSA dialect LLVM-ir are all very similar languages
<pixelherodev>
Michcioperz: CBE is written in Zig ;)
<pixelherodev>
It generates C code :P
<Michcioperz>
yes and i'm talking about not looking at that C code
<scientes>
I have been thinking about some highly theoretical non-turing complete C-like language (it means you can't have function pointers), and I realized I would need something like this, but the line number would be calculated by a regular expression
<pixelherodev>
andrewrk: lemme know when you're on to discuss the CBE issue
FireFox317 has joined #zig
<s-ol>
how can I cast a []struct{r,g,b, = u8} to a []u8 (with four times the length)?
<FireFox317>
fgenesis, what platform do you want to run zig on? Arm32?
<FireFox317>
fgenesis, there were some bugfixes regarding segfaults after the 0.6 release and unfortunately they didnt end up in the tar file that is on the website
<pixelherodev>
s-ol: with what intent?
<FireFox317>
I will start building it for arm32 and make sure we dont have these issues for the next release cycle (which is not far away)
<s-ol>
to send data out bytewise
<s-ol>
its a bitbanging protocol for driving LEDs from an AVR
<s-ol>
sorry, to []const u8 actually
<pixelherodev>
s-ol: struct needs to be packed for that
<pixelherodev>
otherwise, there's no guarantee that the order will be what you want
<pixelherodev>
if it's packed... `std.mem.toBytes(&struct)` ?
<pixelherodev>
I haven't done that in a while, so I'm not 100% sure
<s-ol>
thanks, i'll take a look
<s-ol>
std.mem.sliceAsBytes sounds like it
<s-ol>
if I'm hitting LLVM ERROR: Cannot select... is that a Zig bug? Or am I doing things the architecture doesn't support?
<pixelherodev>
Probably an LLVM bug :P
<pixelherodev>
It could be that what you're doing is untested with LLVM on the given architecture
<s-ol>
hm, i really can't amke much of the error output
<pixelherodev>
You could try just `@intToPtr(T, @ptrToInt(`
<pixelherodev>
That removes safety, but it might potentially use different primitives which are better tested on LLVM-avr?
<ifreund>
what safety does it remove?
<s-ol>
i'm not even sure what statement this is about bh
<Michcioperz>
it's pretty cool that if you @intToPtr the peripheral registers to packed structs with u1 for each bit, it compiles to instructions that just set and clear bits, no reading
Hairok has quit [Remote host closed the connection]
Hairok has joined #zig
<Michcioperz>
ifreund: is that their repo? i tried to find the repo author on the internet to not much effect haha
<leeward>
Did I read right that Zig managed to link for you without extra hackery?
<s-ol>
...now I just have to get it to work as well ;)
<s-ol>
leeward: no, I'm linking myself with avr-gcc
<leeward>
ah, ok, no changes from the last time I looked at zig on avr then
<s-ol>
someone mentioned that might be possible *soon* though
<leeward>
That would be nice.
Hairok has quit [Quit: Leaving]
<ifreund>
if llvm11 has better avr support I guess
<leeward>
It could hardly be worse.
<leeward>
Last I checked, llvm shelled out to avr-gcc to link.
<cr1901_modern>
Same w/ msp430. At least for Rust, it shells out to msp430-elf-gcc
<cr1901_modern>
So I imagine msp430 zig would do the same
<leeward>
Yeah, I've got an msp430 running Zig code but it's basically the same as the avr testbed.
<leeward>
I think there were extra problems there. I don't remember exactly what the problem was though.
<fgenesis>
one thing i remember is that it still had problems with PROGMEM data
<fgenesis>
because harvard architectures are freaky
<leeward>
and everywhere
<s-ol>
yeah i was struggling with this, my code ended up in .progmem.data
<s-ol>
avr-gcc fixed it in linking, but originally i had -gc-sections on and so it stripped out my code oO
<cr1901_modern>
progmem is an AVR thing, right?
<ikskuh>
yeah
<ikskuh>
zig could address this with addrspace
<fgenesis>
last big thing i coded was on a 24bit extended AVR with the funny RAMPZ pointer... had to hack data into the .fini0 section to make use of the upper memory (pointers are still 16bit)
<ikskuh>
but i have absolutely no idea how that would work in practise
<cr1901_modern>
Meaning zig needs to organically grow __near and __far pointers :P
<fgenesis>
and while we're at it, fuck linker scripts *shudder*
<ikskuh>
fgenesis: i think zig should support proper progmem pointers
* cr1901_modern
unironically wants this
<ikskuh>
and not fuckhack that stuff GCC does
<ikskuh>
cr1901_modern: we don't need those, we can do that with addrspace
<cr1901_modern>
No, _I_ want them so I can write DOS code w/ Zig :)
<cr1901_modern>
Though addrspace is prob fine too
<cr1901_modern>
The AVR backend of LLVM already uses addrspace for Rust automagically
<FireFox317>
does one of you have a small avr program that i can test?
<cr1901_modern>
err, rearrange some of those words*
<ikskuh>
addrspace would be __near and __far ;)
<ikskuh>
*addrspace(FAR) i32
<cr1901_modern>
yay :D
<FireFox317>
I have llvm 11 build and would like to see if we can get a simple program to compile and link
<fgenesis>
it's like 5-digit ICQ numbers back in the day
* leeward
just had a flashback.
<fgenesis>
hrhr
radgeRayden has joined #zig
<FireFox317>
leeward, were you able to build object files from zig files before?
<leeward>
I was.
<Michcioperz>
scary dot
<leeward>
The Makefile in that repo worked with some version between 0.6.0 and now.
<Michcioperz>
the line for building .o works on 0.6.0 too
<leeward>
Yeah, it looks like it worked with 932d096029433b75bed3a6c21eae190ee91d5c20
<s-ol>
fgenesis: bit late, but that's a pretty sick demo
<fgenesis>
s-ol: thx!
<fgenesis>
it was fun making it tho. working on a system where you can't just malloc(1GB) certainly has its charms
<ikskuh>
<s-ol> fgenesis: bit late, but that's a pretty sick demo
<ikskuh>
fgenesis: told you already, but this is just true. sick!
<ikskuh>
i need better art direction on my next demo…
<fgenesis>
well there WAS an "esp32-sick" demo right next after this one
<fgenesis>
but it was kinda crushed and i feel sorry
<ikskuh>
fgenesis: spoiler: i can probably do proper rasterization on my stupid heater control
<ikskuh>
HCNICC incoming :D
<fgenesis>
of course you can, you have all the mhz
<fgenesis>
(and all the ROM)
<ikskuh>
ROM is the problem actually *rofl*
<ikskuh>
fuckin' flash
<pixelherodev>
ikskuh: you saw my comment on z80 speed? ;P
<ikskuh>
yes. this is cheating
<pixelherodev>
Pft
<pixelherodev>
Not the point.
<ikskuh>
but: you discovered that modern CPUs are more or less a magic piece of stone
<pixelherodev>
It hits PHz levels! Who cares if I have to cheat a little [and not even load a program] in order to do that!
<ikskuh>
that does things
<pixelherodev>
ikskuh: Actually, I could probably get a 4MHz physical z80 running the emulator at the lower THz level too :P
<pixelherodev>
Well, no
<pixelherodev>
GHz at least though
<pixelherodev>
It's turned at runtime into an infinite loop of "PC += 0x10000; cycles += 0x40000"
<ikskuh>
^^
<ikskuh>
that's a quite useless microoptimization :D
<pixelherodev>
Not quite
<pixelherodev>
It uncovered a few nice improvements while profiling ;)
<ikskuh>
^^
<pixelherodev>
Reading the opcode is now much much faster than it was before, for instance
<fgenesis>
the best code is code that doesn't exist
<pixelherodev>
fgenesis: effectively, yeah :P
<pixelherodev>
ikskuh: what it does mean is that nops are truly zero-cost now
<pixelherodev>
So if I have a program that's 1000 nops followed by real code, it'll basically jump right to the real code without bothering with the normal processing for the nops
<pixelherodev>
Still relatively useless, but it comes at no cost to other code
<ikskuh>
this might be problematic for system emulation though
<fgenesis>
good luck doing that with self-modifying code
omglasers2 has quit [Read error: Connection reset by peer]
codemessiah has joined #zig
dermetfan has quit [Ping timeout: 244 seconds]
<pixelherodev>
fgenesis: no luck is needed
<pixelherodev>
cache invalidation is trivial
<pixelherodev>
Doing it in the most efficient way possible is not
<pixelherodev>
But the simple method of "invalidate pointer on write" is
<fgenesis>
set memory to trap on write and handle things in a page fault?
<pixelherodev>
That's one way
<ikskuh>
hehe, probably the most efficient one
<pixelherodev>
Hmm, I think I can do better.
<pixelherodev>
Static tracing, maybe?
<pixelherodev>
Basically, statically pre-compile most of it; run it through with randomized inputs [fuzzing, basically]; cache all possible code blocks with the corresponding in-memory values
waleee-cl has quit [Quit: Connection closed for inactivity]
xackus has joined #zig
<pixelherodev>
fgenesis: I'll take a look later probs
<fgenesis>
"all possible values" is attempting to solve the halting problem when it comes to self-modifying code
<ikskuh>
yep
radgeRayden has quit [Remote host closed the connection]
donniewest1 has joined #zig
donniewest has quit [Ping timeout: 260 seconds]
<pixelherodev>
fgenesis: hence using the equivalent of the Zig max backwards block evaluations
dermetfan has joined #zig
<pixelherodev>
Executing up to N cycles, tracing all the while (and potentially profiling for optimizations?), and bundle the recompiler for anything that wasn't caught
xackus has quit [Read error: Connection reset by peer]
xackus has joined #zig
Norbertle has joined #zig
cole-h has joined #zig
<s-ol>
huh, something very curious with the zig asm statement on AVR: "rjmp .+0" assembles to "rjmp .-2" (infinite loop)
<s-ol>
in GCC asm macro, "rjmp .+0" comes out as the seame "rjmp .+0" in objdump diassembly
<leeward>
That is very strange. Are you sure it's true?
<pixelherodev>
probably using a different base if that's true
<s-ol>
i'm going to try to make a small repro thing I guess
<pixelherodev>
One might be based on current instruction while the other is based on next?
<s-ol>
certainly seems to be happening :D
<s-ol>
pixelherodev: yeah thats what I'm thinking, but its kind of a massive bug if true?
<leeward>
definitely sounds like a huge bug
<leeward>
Does it reproduce under llvm?
<pixelherodev>
s-ol: not particularly
waleee-cl has joined #zig
<pixelherodev>
"Behavior differs from GCC" isn't really a bug
<ikskuh>
pixelherodev: it is, if the assembly language is well-defined ;)
<ikskuh>
which it usually is ;)
<leeward>
AVR's certainly is.
<ikskuh>
yeah
<pixelherodev>
Zig's inline assembler is explicitly meant to be target independent, isn't it?
<ikskuh>
nah
<pixelherodev>
Source?
<ikskuh>
can you please read your sentence again ;)
<ikskuh>
how the heck should an inline assembler ever be target independent
<ikskuh>
that doesn't work
<ikskuh>
and: if the assembly language is well defined (like ARM, AVR, MIPS, …) zig should exactly use that syntax
<Michcioperz>
are you saying there's no FJCVTZS instruction on x86? :P
<ikskuh>
WHAT
<s-ol>
ok this is making no sense; first repro came out without bug, now in the real project both "rjmp .+2" and "rjmp .+0" assemble to "rjmp .+0"?
<s-ol>
does zig build-obj use any kind of global cache that I can point a finger at or am I going crazy?
<leeward>
It does use a cache.
<leeward>
in zig-cache
<s-ol>
leeward: there is no zig-cache in my dir
<leeward>
It's not global though.
<s-ol>
i know that, but only from zig build
<s-ol>
but im doing zig build-obj
<leeward>
oh, huh, build-obj doesn't cache?
<leeward>
I guess that makes sense. I never thought about it.
<ikskuh>
there's ~/.cache/zig
<ikskuh>
as a global cache
<ikskuh>
that's where stuff like the libcs are stored
<larme>
Google search leads to https://github.com/ziglang/zig/issues/746#issuecomment-368948211. If my understanding is correct, `pub fn someMethod` defined inside struct can be called without providing self pointer while a fn field assigned later should be called with self pointer passed explicitly.
<larme>
but why are they treated differently?
<pixelherodev>
larme: function pointer != struct member
<pixelherodev>
`pub fn blah` within a struct T, *if* the first parameter is of type T, can be invoked as `t.blah` on an object `t` of type `T`
<pixelherodev>
With `blah: fn()void`, you have a function *pointer*
<pixelherodev>
Function pointers don't support implicit self passing
<larme>
thanks for the clarification. I assumed the underlying implementation of struct member function is also done in function pointer. seems that my assumption is wrong
xackus has quit [Ping timeout: 265 seconds]
<pixelherodev>
I think the distinction is that the member function is part of T whereas the function pointer is part of t
<s-ol>
smallest I could get it, can someone verify?
<s-ol>
its not happening exactly like it originally did to me, but rather right now i'm *always* getting an rjmp .+0 no matter what offset (positive, negative, zero) I put in the asm macro
<leeward>
Too bad I don't really have time to dig.
<s-ol>
no worries, i also gtg. thanks for checking tho
xackus has joined #zig
frett27 has joined #zig
FireFox317_ has joined #zig
FireFox317 has quit [Ping timeout: 240 seconds]
<FireFox317_>
andrewrk, i'm working on zig-bootstrap and i have a question. Is it correct that i can use the zig compiler from the host as a replacement to zig0? So for cross-compiling we can do `zig build-obj` and then the arguments that normally go to the zig0 compiler.
klltkr has quit [Ping timeout: 240 seconds]
marnix has quit [Ping timeout: 272 seconds]
marnix has joined #zig
marnix has quit [Read error: Connection reset by peer]
marnix has joined #zig
<FireFox317_>
andrewrk, can i push to the llvm11 branch somehow?
<ifreund>
FireFox317_: you can push to your fork and open a PR against it
<FireFox317_>
ifreund, ah thanks. I didnt know that also works for other branches than master xd
<ifreund>
no problem
Xip has joined #zig
Xip has quit [Read error: Connection reset by peer]
a_chou has quit [Ping timeout: 272 seconds]
frett27 has quit [Ping timeout: 246 seconds]
a_chou has joined #zig
a_chou has quit [Ping timeout: 240 seconds]
xackus has quit [Ping timeout: 265 seconds]
osa1 has quit [Ping timeout: 256 seconds]
marnix has quit [Ping timeout: 256 seconds]
ur5us has joined #zig
guan_ has joined #zig
lanodan_ has joined #zig
dch has quit [Ping timeout: 244 seconds]
JimRM has quit [Ping timeout: 244 seconds]
guan has quit [Ping timeout: 244 seconds]
lanodan has quit [Ping timeout: 244 seconds]
Sahnvour has quit [Ping timeout: 244 seconds]
yawniek has quit [Ping timeout: 244 seconds]
guan_ is now known as guan
jmiven has quit [Quit: reboot]
jmiven has joined #zig
layneson has quit [Ping timeout: 244 seconds]
a_chou has joined #zig
xackus has joined #zig
Norbertle has quit [Quit: Leaving]
OpenSpace has joined #zig
wootehfoot has quit [Read error: Connection reset by peer]
OpenSpace has quit [Quit: Leaving]
radgeRayden has joined #zig
lanodan_ is now known as lanodan
nvmd has joined #zig
u0jQx9gPyrYg has joined #zig
<u0jQx9gPyrYg>
woohoo, you did it andrewrk \o/ thx!
<andrewrk>
FireFox317_, yes it's in theory possible but probably some enhancements to the build script / cmakelists are needed before it works
<FireFox317_>
andrewrk, yes i was able to get zig-bootstrap to compile a working zig compiler again :)
<andrewrk>
nice!
<andrewrk>
with llvm11 branch?
<andrewrk>
welcome u0jQx9gPyrYg
<FireFox317_>
yup, with the llvm11 branch and llvm11.0.0-rc5
<andrewrk>
brilliant
<u0jQx9gPyrYg>
i found a thing that is not quite right in std.os.waitdpid: https://github.com/ziglang/zig/blob/master/lib/std/os.zig#L3124 - according to the man: https://man.cx/waitpid(2)#heading4 waitpid should return the pid of the process returning. and i kinda depend on that instead this implementation returns the status, which i don't care about shall i open an issue? i can also send a PR if we agree on how
<u0jQx9gPyrYg>
this should be fixed
<u0jQx9gPyrYg>
you can all call me stef or stf i have hilites on both. my nick changes from time to time randomly, never mind that. my whois is static.
<ifreund>
I agree that os.waitpid() isn't a good abstraction as it loses functionality
<ifreund>
I suppose an out parameter for the status wouldn't be the worst thing
<u0jQx9gPyrYg>
i have written my own waitpid, which creates a different problem, but worksforme(tm) https://tpaste.us/Lwv4
<u0jQx9gPyrYg>
i guess a combination of the original and mine would make sense
<andrewrk>
if you open a bug report it will be addressed eventually
<andrewrk>
I'll be streaming a demo of the recent big changes to Zig in 1.5 hours. Tour of the new organization of self-hosted compiler code, how bootstrapping works, how the caching system works, and how the optional LLVM extensions work. https://www.twitch.tv/andrewrok/
<u0jQx9gPyrYg>
i opened an issue for this: https://github.com/ziglang/zig/issues/6581 - if you people agree that there should be a pointer to the status in the fn signature, i can prepare a PR and submit that for review
<andrewrk>
u0jQx9gPyrYg, I think the confusion here was that whoever implemented std.os.waitpid (probably me) thought that the return value was the same as the pid parameter
<ifreund>
it is usually, but you can pass e.g. 0 to wait the next child to exit or -1 to wait the current process
<u0jQx9gPyrYg>
exactly what i do
<u0jQx9gPyrYg>
i have a bunch of childs and wait until one returns, and i wanna know which it was
<andrewrk>
yes then clearly we should not be destroying this information
<u0jQx9gPyrYg>
if you see anything stupid in that code, my excuse is that this is my very first zig project. i've been learning zig for 3 days now...
<andrewrk>
thanks for the report u0jQx9gPyrYg, we'll get this fixed. feel free to submit a patch if that is something you would like to do
<FireFox317_>
andrewrk, so there is a bug in the new libcxx used by llvm11 and i searched a bit, and found a patch from the debian package. Am I allowed to use that or something? I fixed the issue tho
<FireFox317_>
s/I/it
<andrewrk>
FireFox317_, yes we can carry patches in zig-bootstrap. the idea is to put the patch in a separate commit for auditing purposes
<andrewrk>
FireFox317_, we can also carry patches in zig upstream for libcxx. is it something fixed in llvm trunk?
<u0jQx9gPyrYg>
huh, i looked through std/os.zig and std/os/linux.zig but did not find an example of returning a struct.
<FireFox317_>
andrewrk, yeah it has to go in zig upstream, because it fails building anything when doing `zig c++ -target arm-linux`
<FireFox317_>
lets see if they fixed it in trunk
<andrewrk>
u0jQx9gPyrYg, I believe getrlimit is an example
<andrewrk>
ideally we would only carry patches when they are fixed upstream already
<FireFox317_>
andrewrk, looks like it hasn't been fixed upstream
<FireFox317_>
or downstream idunno.
<andrewrk>
downstream is us since we copy from them :)
<pixelherodev>
andrewrk: what's the issue with the CBE patch? I clearly misunderstood how resolvePeerTypes works, mind explaining what I'm missing?
<andrewrk>
yeah, try it with the left peer being comptime_int and the right peer being u32
<andrewrk>
or vice versa. one of those is going to be broken
* pixelherodev
nods
<pixelherodev>
Will do
<pixelherodev>
I should get in the habit of adding tests anyways
<pixelherodev>
For fixes*
<pixelherodev>
I usually add tests when adding features, but I haven't been doing it when doing fixup commits
donniewest1 has quit [Quit: WeeChat 2.9]
dermetfan has quit [Ping timeout: 244 seconds]
<pixelherodev>
Thanks for the pointer :) (sending this ten minutes late because I forgot to hit enter lol)
FireFox317_ has quit [Ping timeout: 244 seconds]
jjsullivan1 has quit [Remote host closed the connection]