News for hackers. Stuff that matters.
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.