Programming thread

  • Want to keep track of this thread?
    Accounts can bookmark posts, watch threads for updates, and jump back to where you stopped reading.
    Create account
C is also at its best when it's the target language for various compilers
it has been partially designed to serve as an ir since a very long time ago, with special features like the #line preprocessor directive
this has been exploited for many classic tools like yacc
writing c may or may not be based, but the language itself is quite neat
(e.g., f2c compiled Fortran 77 into C, p2c compiled Pascal into C, Squeak's VM is written in a subset of Smalltalk and automatically compiled into C, Eiffel compiled into C and maybe still does, and I don't think any of the Modula-3 compilers ever generated anything but C)
don't forget that at least 93 scheme implementations and 2 common lisp implementations compile to c
I think we should go back to this sort of thing, because I really don't like the modern practice of putting every egg on the planet into LLVM's basket.
when are we going to see a soylang that compiles to gcc ir
 
I really don't like the modern practice of putting every egg on the planet into LLVM's basket.
The thing is, Stallman and co shot themselves in the foot deliberately to make it difficult/impossible to target the GCC intermediate representation to dissuade proprietary tools from using it.
 
make it difficult/impossible to target the GCC intermediate representation
why would they do this? it would only just make maintaining their own frontends way harder for no real reason
dissuade proprietary tools from using it
it is copyright infringement to write a proprietary compiler frontend for gcc because gcc is under the gnu gpl, they do not need to make the ir hard to target
you could write an mit cuck licensed compiler and have a special --i-want-to-do-shit-that-violates-the-gpl switch that removes all linking to gcc if you really wanted to, and have another backend that compiles to c or whatever

36% of the reason llvm even exists is because big tech likes to have a permissively licensed industrial c compiler in case the copyleft one is inconvenient
 
while we're on the topic of gcc i recently made a high effort shitpost using its inline assembler
it was kind of fun but the moral of this story is that i should probably stick to using glibc
 
.
while we're on the topic of gcc i recently made a high effort shitpost using its inline assembler
it was kind of fun but the moral of this story is that i should probably stick to using glibc
One interesting compiler quirk regarding ASM is how they seem to prefer lea to add. From what I understand, due to how many CPU instruction pipelines are set up, when lea and add are converted into microcode, the delegation to the MMU from lea is faster than the corresponding ALU delegation for add.
The time difference is on the order of cycles, but it adds up.

I love screwing around with assembly dumps or godbolt, the stuff gcc outputs at higher optimization levels is downright esoteric
 
From what I understand, due to how many CPU instruction pipelines are set up, when lea and add are converted into microcode, the delegation to the MMU from lea is faster than the corresponding ALU delegation for add.
makes sense because you want to be able to offset pointers really fast
iirc lea doesn't work for everything so they could probably make some special shortcuts
The time difference is on the order of cycles, but it adds up.
when it's something like 3 cycles versus 2 cycles, that's a good 33% to shave off
very noticeable in a tight loop

i ought to get into compiler writing one day...
 
One interesting compiler quirk regarding ASM is how they seem to prefer lea to add. From what I understand, due to how many CPU instruction pipelines are set up, when lea and add are converted into microcode, the delegation to the MMU from lea is faster than the corresponding ALU delegation for add.
The time difference is on the order of cycles, but it adds up.
makes sense because you want to be able to offset pointers really fast
iirc lea doesn't work for everything so they could probably make some special shortcuts
i did some cursory reading and i think lea has its own special alu that works independently apparently fake and gay since the average processor has several alus that do whatever including lea
it also can do the work of like 3 instructions at once if you use it right
i think its main use is just how it can do a lot of shit in 1 smallish instruction instead of juggling a few registers
 
i did some cursory reading and i think lea has its own special alu that works independently apparently fake and gay since the average processor has several alus that do whatever including lea
it also can do the work of like 3 instructions at once if you use it right
i think its main use is just how it can do a lot of shit in 1 smallish instruction instead of juggling a few registers
Well, in CISC architectures, many instructions are decoded into microcode. The instruction set you see when you write x86 assembly is what's called an ISA, it's kind of analogous to an ABI/API. The CPU has fairly large internal register banks it uses while executing the pipeline or doing speculative execution, which get 'committed' to the ISA registers after the instruction is completed. It's part of why branch optimization is so useful. When the cache, branch predictor, etc. are warmed up, the cpu is often looking ahead some number of instructions and preforming prefetches, out of order execution, etc.
When the branch is mispredicted, what happens is that once the CPU gets the result, it has to perform a pipeline flush and revert its internal state back to before it took the wrong path. Even in ideal scenarios, this is a dozen or more cycles, but depending on the context, it can be hundreds or more.
 
it also can do the work of like 3 instructions at once if you use it right
i think its main use is just how it can do a lot of shit in 1 smallish instruction instead of juggling a few registers
That's what it's historically been used for. Use of lea means that you can get a move, an arithmetic left shift of a register by 0, 1, 2, or (with AMD64) 3 bits, a register addition, and an addition of an immediate value all rolled up into one instruction as long as you don't need the result to set condition codes and aren't using the stack pointer register as one of the operands.

Code:
lea eax, [4*ebx + ecx + 42]

is significantly shorter than (and historically has been significantly faster than)

Code:
mov eax, ebx
sal eax, 2
add eax, ecx
add eax, 42
 
Just sat through a relatively tame and surface level IT meeting for 2 hours. Thank fuck I never went into that field. All yall "should've coded" bros can have my share of the pie.

I recognize the "tasks > people" professional profile a lot of techies got, but man. To base your workday on that thing rather than the use of whatever program you're putting into the world is grim. Thank you for your service. Now back to the dark part of the basement office.
 
That's what it's historically been used for. Use of lea means that you can get a move, an arithmetic left shift of a register by 0, 1, 2, or (with AMD64) 3 bits, a register addition, and an addition of an immediate value all rolled up into one instruction as long as you don't need the result to set condition codes and aren't using the stack pointer register as one of the operands.

Code:
lea eax, [4*ebx + ecx + 42]

is significantly shorter than (and historically has been significantly faster than)

Code:
mov eax, ebx
sal eax, 2
add eax, ecx
add eax, 42
I’ve seen lea used to implement FMA a lot, linear transforms like that are ridiculously common both in addressing and also in calculations
 
Look at this ketchup

C++:
The Late Show with Stephen Colbert is an American late-night news talk show hosted by Stephen Colbert, which premiered on September 8, 2015. The show is the second and final iteration of CBS' Late Show franchise. It is taped at the Ed Sullivan Theater in New York City in the same studio as its predecessor Late Show with David Letterman. It airs new episodes live to tape in most American markets Mondays to Thursdays at 11:35 p.m. ET/PT/10:35 p.m. CT, as with its competitors Jimmy Kimmel Live! and The Tonight Show Starring Jimmy Fallon.
 
I’ve seen lea used to implement FMA a lot, linear transforms like that are ridiculously common both in addressing and also in calculations
well not technically the real fma because that is a specific floating point thing
multiplying something then adding something is absolutely a common pattern and lea can multiply, add, and add again if i understand it right
it then becomes shorter and also faster as well because 1 instruction is better than 7 when it comes to stuff like pipelines and loops and the icache
definitely a very powerful instruction
 
well not technically the real fma because that is a specific floating point thing
multiplying something then adding something is absolutely a common pattern and lea can multiply, add, and add again if i understand it right
it then becomes shorter and also faster as well because 1 instruction is better than 7 when it comes to stuff like pipelines and loops and the icache
definitely a very powerful instruction
I love learning about how the CPU works, so much of what we do in programming is kind of conceptual with design patterns and abstractions and the like, but at the end of the day, there's a really intensely engineered little chip that you may ignore at your own peril. Finding out how to write code that works at a high level while also functioning appropriately when the rubber hits the road is a never ending process.
 
A couple weeks back I decided it's time I take the plunge and actually learn how to program.
I've written simple scripts in the past, and anything else I've needed I've been able to get chatgpt to piece something together for me, but I've gotten to the point where I don't want to have to use chatgpt.
I don't want to be a vibe coder, I want to actually know how to write professional code that will actually do the things I want it to do.

I had a couple classes in college for web dev, but other than that my experience is primarily networking and cloud stuff.

I decided to start off with learning python and I'm going through the code academy course for it now, but my concern is once I finish the course, what do I do from there?
I'm 3/4 the way through the course now and the main thing I've realized is that once I finish I will still be far from what I'd consider competent at Python.
There are so many coding principles and practices I feel like I'll still need to learn, use of libraries, and just other things that I'm not really sure how to explain as other than computer science knowledge.

I guess I'm asking, how do I continue my learning in a way that will actually help me learn? I feel like there are currently a lot of "unknown" unknowns for me, and I'd like some advice on how what to do about that.
 
Back
Top Bottom