← Home ← Back to /g/

Thread 106215192

60 posts 24 images /g/
Anonymous No.106215192 >>106215378 >>106215381 >>106216284 >>106216474 >>106216484 >>106218243 >>106218800 >>106218972
Why not just write assembly at this point? You'd probably get better portability writing your own transpiler too.
Anonymous No.106215256
how can you get so obsessed about so little?
Anonymous No.106215292 >>106215359
it's kinda amazing compiler is able to optimize out that absolute abomination of source code.
Anonymous No.106215299 >>106215378
How ?
Anonymous No.106215359 >>106216371
>>106215292
Right? This thread makes me want to use systems programming languages with advanced compilers more than it makes me want to use assembly
Anonymous No.106215378 >>106215461 >>106216401 >>106218816
>>106215192 (OP)
>>106215299
tail call optimization, it wouldn't work with O0
Anonymous No.106215381
>>106215192 (OP)
Guess
Anonymous No.106215452
I guess we finally have a sufficiently smart compiler.
Anonymous No.106215461 >>106215796
>>106215378
This isn't just tail call optimization though?
Anonymous No.106215739
Wtf it's real
Anonymous No.106215796 >>106216341
>>106215461
it is though
Anonymous No.106216284 >>106216334 >>106216402 >>106216474
>>106215192 (OP)
I don't know, feels hacky, i.e. ( i -1) to false, then everything is false, unlike the normal %2 expression.
bool iseven(unsigned int i) {
if( i % 2 == 0) return true;
return !iseven(false);
}


Maybe i'm just a creature of habit..
Anonymous No.106216323
are you ever going to do anything? is this your only hobby?
Anonymous No.106216334 >>106216720
>>106216284
Surely you must be trolling, right?
Anonymous No.106216341
>>106215796
He is right. There is more than one optimization at play. Tail call optimization would turn this into a loop without using a call instruction. Further optimizations made this no longer a loop. There was an anon yesterday who showed the exact method used by the compiler to eliminate loop invariants. I don't think we need to keep posting the same shit over and over again though.
Anonymous No.106216371
>>106215359
So you can masturbate to recursion while the compiler just writes the obvious code for you?
Anonymous No.106216401
>>106215378
Pretty sure the negation ruins tail call since you need to evaluate the function return to negate it.
Anonymous No.106216402 >>106216431
>>106216284
isEven(2) -> !isEven(1) -> !!isEven(0) -> !! true -> ! false -> true
Anonymous No.106216431
>>106216402
isEven(n) -> ! isEven(n-1) ->...-> !^n isEven(0) -> !^n true
Anonymous No.106216474
>>106215192 (OP)
>>106216284
LMAO @ that code
this board is clown world
Any first world country No.106216484 >>106216496 >>106216501 >>106216540 >>106216789
>>106215192 (OP)
>Why not just write assembly at this point?
i want to write less
Anonymous No.106216496
>>106216484
Makes sense but brevity comes with understanding
Anonymous No.106216501 >>106216524
>>106216484
Now don't call the function
Any first world country No.106216524 >>106216541
>>106216501
No code is generated. Why would you compile something that will never be used?
Anonymous No.106216540 >>106216824
>>106216484
.globl iseven
iseven:
test dil,1
sete al
ret
Anonymous No.106216541 >>106216767
>>106216524
That's exactly equivalent to calling a pure function and not using the return value
Anonymous No.106216718 >>106216814 >>106216814
should pass the faux "depth" thing as a parameter so your function is in tail position.

fn is_even_real(num: u32, state: bool) -> bool {
if num == 0 {
state
} else {
is_even_real(num - 1, !state)
}
}

fn is_even(num: u32) -> bool {
is_even_real(num - 1, true)
}
Anonymous No.106216720 >>106217793
>>106216334
Any first world country No.106216767 >>106216785 >>106216824
>>106216541
weirdo
Anonymous No.106216785 >>106216824
>>106216767
bizarre ASM output.
Anonymous No.106216789 >>106216921
>>106216484
>using a 32-bit not and and when only the last bit is required
what a shit compiler
Anonymous No.106216814
>>106216718
>>106216718
> is_even_real(num - 1, true)
hmm, oops.
should just be num.
Any first world country No.106216824 >>106216843
>>106216540
>>106216785
>>106216767
--opt:none
Anonymous No.106216843
>>106216824
that's 12 more characters than my asm solution
Anonymous No.106216921 >>106216941 >>106217049
>>106216789
There is no benefit in using 16 or 8 bit operation
Anonymous No.106216941 >>106216986
>>106216921
i am pretty sure you could find several CPUs where it matters
Anonymous No.106216957
auto isEven = [](int i){ return (i % 2) == 0; }


Here's your optimal C++ code.
Anonymous No.106216986 >>106217022
>>106216941
That's not the case here, though
You can target said CPUs and the output is going to differ
Anonymous No.106217005
e(){(($1%2))&&echo Odd||echo Even;}; e 10
Anonymous No.106217022 >>106217118
>>106216986
actually, it would matter in every CPU, because "and al,1" is encoded as two bytes, but "and eax, 1" is encoded as 3 bytes
Anonymous No.106217049 >>106217118
>>106216921
.exe would be smaller.
Anonymous No.106217069
bool is_even(unsigned int i) { return !(i & 1); }
Anonymous No.106217087 >>106217339
Brainlets ITT shitting out their fizzbuzz solutions while missing the point of why the OP picrel is interesting
Anonymous No.106217118 >>106217161
>>106217022
>>106217049
And slower with x86-64
Anonymous No.106217161
>>106217118
I've heard all the bitwise operations require 1 cycle.
Anonymous No.106217190
>inb4 I haven't been writing asm since before your dad was wanking into a sock in his bedroom in his parents house when he was in middle school.
Anonymous No.106217339
>>106217087
Ya, how the fuck does LLVM do it? I know it can detect summation series done with loops too.
Anonymous No.106217352
What we need is an AI system that can look at billions of lines of high level code across projects and pull out patterns that humans could easily see, but can't because of the scale involved. Then add those to language. Not replace langauges with talking to a chatbot.
Anonymous No.106217793
>>106216720
Are you actually serious?
Anonymous No.106218135
Anonymous No.106218158
Clever girl.
Anonymous No.106218243
>>106215192 (OP)
There a no decent Assembly IDEs
Anonymous No.106218266 >>106218781
Assembly code should look something like this.
add:
mov eax, [edi]
xor eax, 0
jz recursion
mov eax 0
ret

recursion:
mov eax, [edi]
add eax. 1
mov [edi], eax
mov eax, [edi+4]
sub eax. 1
mov eax, [edi+4]
jmp add


I guess the intermediate representation is where they do all the optimizations.
Anonymous No.106218733
I spend time more on Godbolt than actually programming.
Anonymous No.106218781
>>106218266
Yeah.
Anonymous No.106218800
>>106215192 (OP)
because you'd have to write a ton of stuff from scratch, not only for different architectures but for different versions of the same architecture with different sets of instructions (or just not support all instruction sets, or code to the lowest common denominator, missing out on specialized instructions), and any OS interaction (e.g. syscalls) would be different for different OSes
a transpiler would be full of nitpicky details and bugs and would probably end up reimplementing a ton of stuff that's already been implemented in various compiler backends, but not as well as it has already been done
Anonymous No.106218816
>>106215378
That's not a tail call though, but thanks for playing.
Anonymous No.106218949 >>106218993
Anonymous No.106218972
>>106215192 (OP)
why write anything?
just ask AI to write the program for you.

prompting is the future
Any first world country No.106218993
>>106218949
wtf is fucking wrong with you fucking aberration?