News for hackers. Stuff that matters.
Re:Hobby x86 kernel written with Zig by wildmusings on Monday January 06, 2020 @07:14AM (#21968544)
>I'm asking out of curiosity because I want to learn a "system" programming language

If you mean that you don't know any right now, just learn C. This isn't web programming, where everyone is always hopping to the latest fads. C is the lingua franca, the sine qua non of systems programming. It will be a long time before that changes. The C machine model is what everyone is working with anyway. C is small, despite some devious and fun corners of it, and mostly just exposes you to that model and way of interacting with the machine.

You can’t even appreciate the new systems languages unless you have a firm grasp of C and systems programming. They are all a response to C, addendum and proposed evolutions to it.

Re:Hobby x86 kernel written with Zig by guggle on Monday January 06, 2020 @07:29AM (#21968609)
Thank you. I sure tried C too (also C++ for gui programming), though I wouldn't say I "know" it (which to me would imply at the very least one significant real-world experience with it), I do understand why some projects try to modernize "system" programming. I just want to evaluate alternatives, but I may very well go for C in the end...
Re:Hobby x86 kernel written with Zig by baq on Monday January 06, 2020 @09:53AM (#21969520)
C is portable assembly, I’d recommend learning it together with the assembly for the platform you’re learning on, so you can actually understand the stack, heap, calling conventions, etc.
Re:Hobby x86 kernel written with Zig by mratsim on Monday January 06, 2020 @10:58AM (#21970087)
C is portable assembly until it isn't:

- no access to carry/overflow flag in registers making it a chore to write bigint libraries

- no way to guarantee emitting add with carry or sub with borrow even though those are simple instructions and some architecture (6502) don't even provide a normal add/sub

- need to drop down to assembly to implement resumable function/fibers to avoid the syscall costs of ucontext/setjmp/longjmp

- no access to hardware counters like RDTSC

- no way to get the CPU frequency in a portable and reliable way

- no portable threadID function and then, those that are available (pthread_self, and Windows') rely on expensive syscalls.

- no way to do CPU feature detection (SSE, AVX, ARM Neon, ...)

- no way to control emission of common intrinsics like popcount, bit-scan-reverse, lowest bit isolation in a portable way.

The portable assembly narrative breaks down rapidly when you actually need specific code to be emitted.

Re:Hobby x86 kernel written with Zig by renox on Monday January 13, 2020 @04:19AM (#22032997)
> C is portable assembly until it isn't:

> - no access to carry/overflow flag in registers making it a chore to write bigint libraries

C is portable assembly: so it provides access to a minimum common set of features which allow the code to be portable:

good luck trying to use the carry flag on the RISC-V..

Re:Hobby x86 kernel written with Zig by throwaway17_17 on Tuesday January 07, 2020 @12:53AM (#21977307)
The following is a genuine question (not a flippant remark):

Is there any way to have those concepts be portable across ISAs/architectures. I don’t think those types of ops are exposed in LLVM-IR or GCC’s various intermediate levels (but could be wrong). I’d love to be able to investigate a language that enables a level of hardware access possible in a portable manner.

Re:Hobby x86 kernel written with Zig by sigjuice on Monday January 06, 2020 @02:59PM (#21972611)
need to drop down to assembly to implement resumable function/fibers to avoid the syscall costs of ucontext/setjmp/longjmp

Which syscalls would be involved in setjmp/longjmp?

Re:Hobby x86 kernel written with Zig by mratsim on Monday January 06, 2020 @03:18PM (#21972800)
Re:Hobby x86 kernel written with Zig by loeg on Monday January 06, 2020 @06:23PM (#21974687)
For inexplicable reasons, ucontext/setjmp/longjmp include signal masks, which, for lack of VDSO implementation, must be obtained by invoking syscalls.

(FreeBSD provides the non-portable _setjmp/_longjmp, which do not preserve signal mask state and avoid the syscall. There are also the POSIX sigsetjmp/siglongjmp, which with savesigs=0 may bypass the syscalls as well. Both FreeBSD and Linux provide the POSIX routines.)

Re:Hobby x86 kernel written with Zig by baq on Monday January 06, 2020 @02:39PM (#21972375)
Precisely my point - learning both together as they compliment each other instead of C abstracting the underlying computer away.