Conversation started Dec 19, 2012 at 14:19.
Dec 19, 2012 14:19
If you need to access a series of pointers, you should access an array rather than incrementing a pointer, as I see it
@Neil It's noticeably slower.
Wut.
It's the same thing.
What kind of broken compilers are you using?
@R.MartinhoFernandes Consider Sum[i] = A[i] + B[i] vs *Sum++ = *A++ + *B++;
@Neil You have call that function like glVertexAttribPoint(..., (void const*)4); for example.
@BartekBanachewicz Yeah...?
@R.MartinhoFernandes Well, it might be outdated, but in 2003 the latter was around 2 times faster.
I can link you the paper I've read it in
Dec 19, 2012 14:21
2003 was... ten years ago.
Anyway, if you're using an iterator, you're implicitly incrementing a pointer.
I need gcc-4.7 -S -O2
Or anyone who has access to it. It's better to check than to argue.
That one's interesting. I'd like to see the assembler code from an OC.
@AndreiTita I'm dl-ing mingw right now. I don't have any VM here
or wait, there has to be an option to do it in MSVCC
hi guys
any good reversers here tonight?
no. This is C++ room, not Reverse Engineering lounge
@Dean like people who reverses rivers?
@BartekBanachewicz I don't see any noticeable difference.
...thanks. Now I wish I was much, much better at reading assembly.
Dec 19, 2012 14:31
f1 starts at _Z2f1PcS_S_: and f2 starts at _Z2f2PcS_S_:
ATnT syntax sucks =\
Assembly syntax sucks
16(%rsi) omfg. how sane people can use it?
@Pubby nah, it doesn't
@Abyx That is Intel syntax :/
@R.MartinhoFernandes wut?
Dec 19, 2012 14:34
@R.MartinhoFernandes It's AT&T. Intel would be [rsi + 16].
it's AT&T
I used masm=intel
GCC must be mad.
-masm=intel?
Just a quick question which came into my mind: How does VS 2012 support things like std::tuple w/o variadic templates?
@Griwes Yeah.
Wait, got it.
Dec 19, 2012 14:35
@Nils macros and magic
@Nils macros
@Nils And magic macros.
@Nils Until latest patch, they had some black magic for standard library.
bah make me puke
Dec 19, 2012 14:35
g++ -S -masm=intel => AT&T. g++ -masm=intel -S => Intel. Fuck you GCC.
4
macros
@R.MartinhoFernandes w00t.
@Griwes what patch?
@R.MartinhoFernandes What about leaqs in first function?
Dec 19, 2012 14:36
@AndreiTita Latest. IIRC, they finally added variadics.
@Griwes Not in the standard library.
@Griwes They did add variadic support with the Nov CTP compiler but they specifically mentioned the std library hasn't been updated to use them.
Ough.
@BartekBanachewicz Sorry, I don't know much assembly.
@ abyx lol
Dec 19, 2012 14:40
@R.MartinhoFernandes Intel syntax shows the same. LEA stands for load effective address
lea rcx, [rdx+16] is rcx = rdx + 16, just short form of add
I don't know what difference it makes.
It's the main and only difference. With pointers, you don't have to compute the address
Dec 19, 2012 14:41
All the LEA instructions in f1
which are simpler in f2
L2 and L17 are the only different parts there.
@BartekBanachewicz Sounds like bullshit. Or you are not looking at the same thing as I am.
LEAs aren't that complex...
sub eax, 1
lea rcx, [rdx+r9]
add rdi, r9
lea r8, [rax+1]
add rsi, r9
xor eax, eax
There is only a difference in the labels Griwes mentioned.
Dec 19, 2012 14:42
Indeed.
And that's the overhead caused by the [ ]
    add     rax, 16
    cmp     rax, 992
    jne     .L17
    add     rdi, 992
    add     rsi, 992
    add     rdx, 992
    mov     r8d, 8
Why don't you benchmark?
vs those leas.
@Griwes and it should be faster.
@BartekBanachewicz huh? what overhead?
Dec 19, 2012 14:43
Seriously, lea rcx, [rdx+r9] is just addition.
There isn't even register move in that instruction, in sane CPUs (register renaming ftw).
@BartekBanachewicz I can run a benchmark if you give me one.
@R.MartinhoFernandes Can you just time the two functions you wrote?
@BartekBanachewicz time isn't fair, since it can be preempted at any given time.
Dec 19, 2012 14:45
not sure how that went
I need something that makes the results big enough to be noticeable and that makes external factors irrelevant..
@R.MartinhoFernandes Increase N?
FWIW, isn't this the loop part?
.L17:                                                    |.L3:
    vmovdqu xmm1, XMMWORD PTR [rdx+rax]                  |    vmovdqu xmm1, XMMWORD PTR [rdx+rax]
    vmovdqu xmm0, XMMWORD PTR [rsi+rax]                  |    vmovdqu xmm0, XMMWORD PTR [rsi+rax]
    vpaddb  xmm0, xmm1, xmm0                             |    vpaddb  xmm0, xmm1, xmm0
    vmovdqu XMMWORD PTR [rdi+rax], xmm0                  |    vmovdqu XMMWORD PTR [rdi+rax], xmm0
    add rax, 16                                          |    add rax, 16
Because I see a loop there.
You would have to boot real CPU into long mode and execute just them, reading HPET just before and right after loops, to truly measure it. </troll>
Seriously, the difference between those leas and adds is exactly 0 on any decently optimized CPU.
I will add some asm comments to see where the loops went.
Dec 19, 2012 14:47
guy didn't ask me any Java, really.
Wait, what.
Adding comments made the generated code much much smaller.
It fits on a screen now
lol.
@R.MartinhoFernandes that's why I hate asm.
What.
Dec 19, 2012 14:49
All I did was add asm("# im in ur loop") to the loop bodies.
Seems we have to add asm comments here and there to get ultimate speed-up of code execution.
Anyway, in neither version do I see any fucking difference in the loops.
Yeah.
=> we are not in 2003 o/
But I am a bit baffled by the different that the comments made.
Ask on SO! :D
Dec 19, 2012 14:53
The moral of the story is: don't use // ... nor /* ... */ for comments. Use asm("# ... ");
Hmm, that could make pretty good SO question, actually.
user142019
asm("# foo"); ain't portable.
Anyway, my tests using QueryPerformanceCounter give surprising results
Turns out the first code is around two times faster (opposite to what I said)
Or maybe I'm doing something wrong
I trust more my eyes upon exactly the same generated code than I trust microbenchmarks.
Anyway, show the benchmark code.
(And now you might understand why I did not want to write benchmarking code)
The results are consistent
Around 1.2M for f1, around 2.2M for f2
(on my PC)
with about 1% deviation
...now, -O3 or however you write that in MSVC?
@Griwes -O2 or -Ox
tried both
Oh, actualy "minimize size" slowed down the f1 to nearly the same as f2
0
Q: Why does adding assembly comments cause such radical change in generated code?

R. Martinho FernandesSo, I had this code: constexpr unsigned N = 1000; void f1(char* sum, char* a, char* b) { for(int i = 0; i < N; ++i) { sum[i] = a[i] + b[i]; } } void f2(char* sum, char* a, char* b) { char* end = sum + N; while(sum != end) { *sum++ = *a++ + *b++; } } I wa...

Dec 19, 2012 15:05
MSVC11 Debug(/Od): about the same; Release(/O2): f1 around 3x faster.
That's classic wtf
@Jerry congrats for passing 10k in
If you were a piece of cheese which cheese would you be?
> I think I'd be brie because I'm smooth as fuck.
What should I use instead of QueryPerformanceCounter to test this on Linux?
Dec 19, 2012 15:07
@R.MartinhoFernandes boost::timer
i should use it too, actually
@BartekBanachewicz There was a question on SO which answered exactly that.
@R.MartinhoFernandes std::chrono::high_resolution_clock::now();
Yeah, I think I had seen the first one before.
pastebin.com/eqiJqqv3 - something like that
Dec 19, 2012 15:09
[rmf@persephone ~]$ g++ -O3 a.c++ -lboost_timer -lboost_system
[rmf@persephone ~]$ ./a.out
 0.213092s wall, 0.210000s user + 0.000000s system = 0.210000s CPU (98.5%)
 0.210384s wall, 0.210000s user + 0.000000s system = 0.210000s CPU (99.8%)
[rmf@persephone ~]$
50 mins ago, by R. Martinho Fernandes
What kind of broken compilers are you using?
Answer is: MSVC.
user142019
What must the default ctor of a ForwardIterator do? Initialize the iterator as if it were end?
So f2 is faster by aroung 0.0027s :)
Wall time is always skewed.
Also, there are other factors involved. Look what happens when I test them in the opposite order:
user + 0.000000s?
[rmf@persephone ~]$ g++ -O3 a.c++ -lboost_timer -lboost_system
[rmf@persephone ~]$ ./a.out
 0.213450s wall, 0.200000s user + 0.000000s system = 0.200000s CPU (93.7%)
 0.210470s wall, 0.210000s user + 0.000000s system = 0.210000s CPU (99.8%)
[rmf@persephone ~]$
Dec 19, 2012 15:15
silence
anyway, g++ sucks and VC++ ftw. it may be broken, but it has decent IDE.
Please don't get me started on that.
ok
@R.MartinhoFernandes MSVCC sucks, but MSVS is the best money can buy right now.
That's from 2001!
Seriously.
Ok, so it's 12 years instead of 10
Anyway, it was a fun experiment to check that
Especially because MSVCC seems to produce strange results
Dec 19, 2012 15:21
> I had just gotten off a red-eye flight, and was in the airport bathroom brushing my teeth. When I spit it out, I still had some toothpaste on the side of my mouth. Some snobby lady looked over at me and said, "It looks like you have a little leftover on your mouth from your last client." I calmly wiped my mouth, turned to her and said, "Yeah, your husband doesn't have the best aim, does he?" Then walked out of the bathroom.
dayuuum!!!
@BartekBanachewicz Yeah, that's sad. It is also entirely different from saying it is great or awesome or decent.
@R.MartinhoFernandes I am well aware of it's imperfections.
The main problem is that M$ really wants us to use C# instead of C++.
what are you smoking?
@BartekBanachewicz um... lol?
Dec 19, 2012 15:25
if anything, MS are the ones who are waking up to the coffee that C# isn't good for everything by a very long shot
are you still living in that hallucinatory dreamworld?
> waking up to the coffee
lol
Or did you just go to "it doesn't matter if what I say is correct, as long as it's negative about Microsoft" school of online discussion?
user142019
Sublime Text 2 y u no Vim. I keep hitting cmd+w and as such closing the tab. T_T
@BartekBanachewicz @R.MartinhoFernandes MSVC assembly at its finest (/O2): pastebin.com/VmPVXnTg (I tried to figure it out for a bit but gave up. Maybe it's useful?)
Dec 19, 2012 15:29
It appears it does not vectorize f2.
but which MSVC?
Conclusion: that paper from 2001 is at best outdated, at worst wrong.
welp!
hats are addictive!
Dec 19, 2012 15:30
lol
@AndreiTita 11 beta?
@jalf is it untrue?
Kids, the lesson here is: stop making silly senseless optimizations because some dude told you it was faster; especially if said dude told you that in another decade.
 
Conversation ended Dec 19, 2012 at 15:30.