fosstodon.org is one of the many independent Mastodon servers you can use to participate in the fediverse.
Fosstodon is an invite only Mastodon instance that is open to those who are interested in technology; particularly free & open source software. If you wish to join, contact us for an invite.

Administered by:

Server stats:

9.9K
active users

#defines

0 posts0 participants0 posts today

I'm reminded of years ago when I discovered that the Illumos driver for 10G-T Intel Ethernet chipsets had a 'wait' operation that was implemented with a busy-wait, and used it for multi-millisecond waits through a chain of #defines

(The original kernel busy-wait was intended for microsecond waits, then got resused by the driver because hey, it was there, scaling by 1000 is fine, right?)

In re: mastodon.social/@whitequark/11

Mastodon✧✦Catherine✦✧ (@whitequark@mastodon.social)apparently linux will refuse entering the S0ix power state if the PCH is too hot (above 50 degrees), so whenever this happens the kernel sleeps for 300ms to let the PCH cool down this is cursed
Continued thread

A fabulous amount of source notes pop up

{quote

scsi_all.h started out life as a work by Julian Elischer to add SCSI
support to CMU Mach 2.5. It was 373 lines. Julian ported this to 386BSD,
included in the 386BSD patch kit and incorported into FreeBSD at its
creation. Justin used this file when writing CAM, and imported it with
the initial CAM import, but only 30% (100 lines) of the original
remained. Justin moved from bitfields to bytes in structures, dropped
the complex unions, and renamed many structures to have their length
appended. Only about 30 structure names and about 40 #defines remained
from the original. The define names were taken directly from the SCSI
standard with spaces replaced by '_', so had no creativity. Apart from
the license comment, there were no comments retained (all the comments
in the CAM import were written by Justin and Ken). Even at that time,
Justin and Ken could have put their copyrights and names and moved to an
acknowledgement of Julian.

In the almost 30 years since that original import, this file has grown
to 4500 lines. Kenneth Merry, Alexander Motin and Justin Gibbs write
85% of the file's lines, if mechanical commits are omitted. Other
contributors contributed less than %5 each of the file.

Replace the original license (which lacked a copyright even and has been
criticized as ambiguous) with FreeBSD's standard 2-clause license. Add
copyrights for Justin, Ken and Alexander, with the date ranges they
contributed to the file. Add a note about the origin of the file to
acknowledge Julian's original work upon which all this was built, though
it's become a ship of Theseus in the mean time, built and rebuild many
times.

On an absolute scale, there's less than 1% of the current file with
lines from the original, and those are named after the names in the SCSI
standards and likely wouldn't qualify for copyright protection.

Sponsored by: Netflix
Reviewed by: mav, ken
Differential Revision: reviews.freebsd.org/D49016

End Quote}
^Z

How wonderful to have learned this now

#bash #csh #ksh #sh #freeBSD #SCSI #bhyve #jails #ZFS #programming #POSIX

codeberg.org/FreeBSD/freebsd-s

Codeberg.orgcam: Update scsi_all.h to reflect 30 years of evolution · 1016b3c344 scsi_all.h started out life as a work by Julian Elischer to add SCSI support to CMU Mach 2.5. It was 373 lines. Julian ported this to 386BSD, included in the 386BSD patch kit and incorported into FreeBSD at its creation. Justin used this file when writing CAM, and imported it with the initial CA...
Continued thread

Baking does lots of stuff - light maps, visibility queries, SH probes, etc.

This built system runs on top of a very simple distributed processing system - you just tell the system "run this linux command somewhere" and it just does it. No incredibuild here.

They use ubershaders with #defines for each feature.

They wrote their own GUI shader editor for artists. Programmers would "export" feature flags and settings, and an artist could play around with them. They hooked it up to Maya.

4/10

@samloonie I mean, it will flash successfully without even touching the button, and the hash/CRC claims to be correct. But there must be a half-dozen or more partitioning options in the IDE, and various other IDE tools options that appear to duplicate #defines in the code. But I'll look at what's on there now and see if anything is showing up on the serial port finally.

Continued thread

It's fast! And has very few errors. We like to go through each register one by one, add the typedefs and #defines, then the setter/getter functions, and finally the arduino ino 'sketch' to actually test and verify. However, with three files - header, cpp, and ino - canvas can get really confused about which file we're editing and what it's called.

Continued thread

INTERFACE spits out an .H file with the resource IDs and an .RSH file with the OBJECT and OBSPEC data all helpfully in arrays of C structs. the only problem is the output is for Pure C’s TOS lib and not MiNTlib so I need to include a file that converts the #defines first.

But it means I should be able to whip up a loader that places the OBJECTs in my window’s OBJTREE, converts INTERFACE’s character grid coordinates to pixel grid coordinates, and places the container G_BOX where I want it

GLSL-like swizzling in C++20

* without #defines
* using field syntax
* supporting assignment
* without UB (I think)

godbolt.org/z/xY7Pxerez

godbolt.orgCompiler Explorer - C++ template<typename Base, int len> struct Vec { using This = Vec<Base, len>; template <int dst_len, std::array<int, dst_len> mapping> struct Swizzler { operator Vec<Base, dst_len>() { auto src = reinterpret_cast<Vec<Base, len>*>(this); Vec<Base, dst_len> dst; for (int i = 0; i < dst_len; i++) dst.arr[i] = src->arr[mapping[i]]; return dst; } void operator=(const Vec<Base, dst_len>& src) { auto dst = reinterpret_cast<Vec<Base, len>*>(this); for (int i = 0; i < dst_len; i++) dst->arr[mapping[i]] = src.arr[i]; } }; #define COMPONENT_0 x #define COMPONENT_1 y #define COMPONENT_2 z #define COMPONENT_3 w #define CONCAT_4_(a, b, c, d) a##b##c##d #define CONCAT_4(a, b, c, d) CONCAT_4_(a, b, c, d) #define SWIZZLER_4(a, b, c, d) Swizzler<4, { a, b, c, d }> CONCAT_4(COMPONENT_##a, COMPONENT_##b, COMPONENT_##c, COMPONENT_##d); #define GEN_SWIZZLERS_4_D(D, C, B, A) SWIZZLER_4(A, B, C, D) #define GEN_SWIZZLERS_4_C(C, B, A) GEN_SWIZZLERS_4_D(0, C, B, A) GEN_SWIZZLERS_4_D(1, C, B, A) GEN_SWIZZLERS_4_D(2, C, B, A) GEN_SWIZZLERS_4_D(3, C, B, A) #define GEN_SWIZZLERS_4_B(B, A) GEN_SWIZZLERS_4_C(0, B, A) GEN_SWIZZLERS_4_C(1, B, A) GEN_SWIZZLERS_4_C(2, B, A) GEN_SWIZZLERS_4_C(3, B, A) #define GEN_SWIZZLERS_4_A(A) GEN_SWIZZLERS_4_B(0, A) GEN_SWIZZLERS_4_B(1, A) GEN_SWIZZLERS_4_B(2, A) GEN_SWIZZLERS_4_B(3, A) #define GEN_SWIZZLERS_4() GEN_SWIZZLERS_4_A(0) GEN_SWIZZLERS_4_A(1) GEN_SWIZZLERS_4_A(2) GEN_SWIZZLERS_4_A(3) #define CONCAT_3_(a, b, c) a##b##c #define CONCAT_3(a, b, c) CONCAT_3_(a, b, c) #define SWIZZLER_3(a, b, c) Swizzler<3, { a, b, c }> CONCAT_3(COMPONENT_##a, COMPONENT_##b, COMPONENT_##c); #define GEN_SWIZZLERS_3_C(C, B, A) SWIZZLER_3(A, B, C) #define GEN_SWIZZLERS_3_B(B, A) GEN_SWIZZLERS_3_C(0, B, A) GEN_SWIZZLERS_3_C(1, B, A) GEN_SWIZZLERS_3_C(2, B, A) GEN_SWIZZLERS_3_C(3, B, A) #define GEN_SWIZZLERS_3_A(A) GEN_SWIZZLERS_3_B(0, A) GEN_SWIZZLERS_3_B(1, A) GEN_SWIZZLERS_3_B(2, A) GEN_SWIZZLERS_3_B(3, A) #define GEN_SWIZZLERS_3() GEN_SWIZZLERS_3_A(0) GEN_SWIZZLERS_3_A(1) GEN_SWIZZLERS_3_A(2) GEN_SWIZZLERS_3_A(3) #define CONCAT_2_(a, b) a##b #define CONCAT_2(a, b) CONCAT_2_(a, b) #define SWIZZLER_2(a, b) Swizzler<2, { a, b }> CONCAT_2(COMPONENT_##a, COMPONENT_##b); #define GEN_SWIZZLERS_2_B(B, A) SWIZZLER_2(A, B) #define GEN_SWIZZLERS_2_A(A) GEN_SWIZZLERS_2_B(0, A) GEN_SWIZZLERS_2_B(1, A) GEN_SWIZZLERS_2_B(2, A) GEN_SWIZZLERS_2_B(3, A) #define GEN_SWIZZLERS_2() GEN_SWIZZLERS_2_A(0) GEN_SWIZZLERS_2_A(1) GEN_SWIZZLERS_2_A(2) GEN_SWIZZLERS_2_A(3) #define SWIZZLER_1(a) Swizzler<1, { a }> COMPONENT_##a; #define GEN_SWIZZLERS_1_A(A) SWIZZLER_1(A) #define GEN_SWIZZLERS_1() GEN_SWIZZLERS_1_A(0) GEN_SWIZZLERS_1_A(1) GEN_SWIZZLERS_1_A(2) GEN_SWIZZLERS_1_A(3) union { GEN_SWIZZLERS_4() GEN_SWIZZLERS_3() GEN_SWIZZLERS_2() GEN_SWIZZLERS_1() Base arr[len]; }; }; using Vec4 = Vec<float, 4>; using Vec4i = Vec<int, 4>; static_assert(sizeof(Vec4) == sizeof(float) * 4); static_assert(sizeof(Vec4i) == sizeof(int) * 4); Vec4 foo(Vec4 v) { return v.xyxy; } Vec4i fooi(Vec4i v) { return v.xyxy; } void bar(Vec4& v) { v.xy = v.zw; }

Eclipse Сборка с Помощью ARM GCC Плагинов

В программировании микроконтроллеров часто используют Eclipse с плагинами. Главным образом от незнания языков скриптов сборки (Make, Cmake, Ninjia и т п). В этом тексте я напишут почему способ сборки из Eclipse c ARM плагинами - это тупиковый путь в разработке больших промышленных командных проектов. И как можно частично компенсировать недостатки Eclipse с плагинами.

habr.com/ru/articles/794206/

ХабрEclipse Сборка с Помощью ARM GCC ПлагиновПролог В программировании микроконтроллеров часто Eclipse с плагинами используют потому что в нем есть плагины, которые генерируют make файлы для сборки программ на Си согласно разметке проекта в XML...
Continued thread

After a little bit of fiddling around this morning, I've realised that the classes aren't in the order they come in the external files. In fact, I have no idea how they're ordered. I assume it's something to do with dependencies, but I can't see it.

Like I said, it probably makes no difference - it's just a load of #defines. But I'd like to make it character-perfect at some point.

I have other things to do today, but if I get a chance this evening I'll try using #ctran to compile something.

Replied in thread

@stuartmarks amusingly a few posts before this in my feed was complaints about namespace pollution from the Xlib.h header having for things like “Status” and “None” due to decisions made nearly 40 years ago, when X was just a fun experiment, not core system API.

Continued thread

Have I ever mentioned how much I *hate* the C preprocessor? It poisons everything built on top of it, you make modern code with namespaces and such and it gets broken by the pre-namespace #defines in your thirty year old OS header files. You're building skyscrapers on sand. A significant portion of why I want to jump to Rust or Go is just to get away from the C preprocessor by itself

Replied in thread

@madcoder

In the olden daze, a null pointer in C actually was a zero, and it pointed to address zero, and guess what was there? Zeros.

So, a null string pointer pointed to a null string or zero int. And it worked.

And then ANSI C came along, and NULL was no longer a zero pointer to zeroes, and whoa! Stuff broke.

I spent a lot of time reworking the toolchains back then to wrap all of the C library functions via the preprocessor.

Then, I wrote frontends for the libc functions that had the null pointer problem.

Then, I made the build system use my frontend library which trapped the bad code.

So, strcpy() became safe_strcpy() and if a null pointer came in, I would fix it on the fly, and also log the calling code so it could be fixed later.

Oh, I had a common header file that almost all of the code #included so that made it easier. I just changed that common header file to include all of the #defines I needed from another header file, and like magic, all of the source code C calls to strcpy() (example), magically became calls to safe_strcpy(), and then the rest was linker magic because I controlled the build system so I could make it use my frontend wrapper library.

Continued thread

I've also removed a huge number of preprocessor #defines and moved the constants that they created directly into code, which feels really weird in the abstract, but was the right call in this specific case.

I love "this is usually wrong, *but*..." moves.

There were a huge number of "#define FOO_PID 0x1234" defines, each of which were used once, defining the hardware ID burned into specific device models. Maintaining the list in 2 places was a pain, and it made automated tooling harder.