Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

It's 2016 and COMPILERS ARE STILL STUPID

Name: Cudder !cXCudderUE 2015-12-31 22:29

Just analysing a device driver for hardware few months old... as usual, it's as bloated as a week-old dead pig overall but then I come across pieces like this:

shl ecx, 4
mov edx, ecx
shr ecx, 2
xor eax, eax
rep stosd
mov ecx, edx
and ecx, 3
rep stosb


:facepalm:

Name: Anonymous 2018-01-21 17:40

Name: Anonymous 2018-01-21 17:42

sext example
derp.

Name: Anonymous 2018-01-21 18:04

sage

Name: Anonymous 2018-01-21 18:11

>>80
Go away.

Name: Anonymous 2018-01-21 23:18

>>84
>things that won't happen

Name: Anonymous 2018-01-22 7:34

>>85
who are you quoting?

Name: Anonymous 2018-01-23 20:04

Check it out: C89 has restrict:
/* also try e.g. int, unsigned, long, double, etc */
#define type float

void add4(type *d, type *s, type *t) {
unsigned i;
for(i = 0; i < 4; ++i)
d[i] = s[i] + t[i];
}

void add4_r(type *d, type *s, type *t) {
type S[4], T[4];
unsigned i;
for(i = 0; i < 4; ++i)
S[i] = s[i], T[i] = t[i];
for(i = 0; i < 4; ++i)
d[i] = S[i] + T[i];
}

Name: Anonymous 2018-01-23 20:05

>>87
Result: 'add4()' produces shit code, 'add4_r()' produces nice SIMD code.

Name: Anonymous 2018-01-24 6:02

>>87
Segmentation fault: Core dumped

Name: Anonymous 2018-01-24 12:38

>>87,88
The two pieces of code aren't equivalent since d, s and t can overlap; the SIMD code would be wrong for add4. This is why languages that require you to break down every operation on arrays into detailed loops are stupid by the way.

Name: Anonymous 2018-01-24 14:41

>>90
This is why languages that require you to break down every operation on arrays into detailed loops are stupid by the way.
I agree, but only because of the qualifier about 'every operation'. most things people use loops for could be expressed with map/filter/reduce without losing readability - and it would be better for the more advanced compiler optimizations. still, most things are not the same as all things - there are things that are just plain easier to understand with loops: writing something like a multimedia codec (or even that ASCII->GSM-7 converter from a /prog/ challenge) with just map would require an anal deformation of your brain far worse than the one required to program in Forth

Name: Anonymous 2018-01-24 16:22

>>91
The qualifier was intentional. There's a time and place for the old for loop, but it's not every time and every place.

Name: Anonymous 2018-01-24 19:21

Check it out: Rust

#[macro_use]
extern crate faster;
use faster::*;

fn testt(s: &[f32], t: &[f32]) {
let a = ((&s[..]).simd_iter(), (&t[..]).simd_iter())
.zip()
.simd_map(tuplify!(2, f32s(0.0)), |(a, b)| a + b)
.scalar_collect();
println!("{:?}", a);
}

Name: Cudder !cXCudderUE 2018-01-25 4:37

add ebp, 2
inc ebp


My face is full of palm.

Name: Anonymous 2018-02-02 5:14

>>94
What in the fuck. Isn't ebp special cased? Why emit inc for anything ever? So many questions.

Name: Anonymous 2018-02-02 22:51

>>94
What? What the fuck?
What was the input for that? What compiler?

Name: Cudder !HBl1hGyY4Y 2018-02-06 4:36

>>96
I'm guessing it was something like

x = *((short*)p)++;
y = *p++;


since the code before that is (there are some other intervening unrelated instructions too, signified by ...):

mov ax, [ebp+0]
...
mov bl, [ebp+2]
...
add ebp, 2
...
inc ebp


Not sure of compiler. Might be MSVC

Name: Anonymous 2018-02-06 8:10

I think you mean x = *((short*)p++); instead

Name: Anonymous 2018-02-06 8:30

>>97
Guess the compiler is configured to use ebp as a GPR then. Still dumb but not totally inexcusable.

Name: Anonymous 2018-02-06 15:17

Chekc my dubs

Name: Anonymous 2018-02-09 3:28

``it's (int) current_year'' doesn't mean much

Name: Anonymous 2018-02-09 8:26

>>101
And yet it does. A program using 40MB of memory is a nonissue. Compare to 1988.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List