• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
cr88192

ridiculous compiler output...

10 posts in this topic

I was off compiling something, having some fairly good success...

 

basically, I went and wrote an implementation of the Apple Video codec (partly because, hell, why not?...), and was thinking things were doing pretty good.

after all, the thing is going along, decoding video at a rate of about 430 Mpix/s (megapixels per second), ...

 

side info:

http://en.wikipedia.org/wiki/Apple_Video

http://wiki.multimedia.cx/index.php?title=Apple_RPZA

 

 

then I was like, "maybe I will run it through the profiler, and see what the profiler has to say about it."

 

but, then I saw it...

 

 

the expressions:
tb[6]=0; tb[7]=0;

compile to:
0xfe08c6a mov edx,00000001h BA 01 00 00 00 0.44537419
0xfe08c6f imul eax,edx,06h 6B C2 06
0xfe08c72 mov [ebp-44h],eax 89 45 BC 0.21256495
0xfe08c75 cmp [ebp-44h],10h 83 7D BC 10
0xfe08c79 jnb $+04h (0xfe08c7d) 73 02 1.38335919
0xfe08c7b jmp $+07h (0xfe08c82) EB 05 0.19569471
0xfe08c7d call $+00018ce1h (0xfe2195e) E8 DC 8C 01 00
0xfe08c82 mov ecx,[ebp-44h] 8B 4D BC
0xfe08c85 mov [ebp+ecx-14h],00h C6 44 0D EC 00 0.25305352
0xfe08c8a mov edx,00000001h BA 01 00 00 00 0.50273299
0xfe08c8f imul eax,edx,07h 6B C2 07
0xfe08c92 mov [ebp-3ch],eax 89 45 C4 0.30703825
0xfe08c95 cmp [ebp-3ch],10h 83 7D C4 10
0xfe08c99 jnb $+04h (0xfe08c9d) 73 02 1.26189351
0xfe08c9b jmp $+07h (0xfe08ca2) EB 05 0.2598016
0xfe08c9d call $+00018cc1h (0xfe2195e) E8 BC 8C 01 00
0xfe08ca2 mov ecx,[ebp-3ch] 8B 4D C4
0xfe08ca5 mov [ebp+ecx-14h],00h C6 44 0D EC 00 0.00337405


which is actually, pretty much, just plain ridiculous...

 

(pretty much the most absurd compiler output I have seen recently...).

 

 

like, whatever happened to something like:

xor eax, eax

mov [...], al

or:

mov [...], 0x00

 

?...

 

 

or, maybe it is just my fault for trying to apply logic to compiler output sometimes?...

 

0

Share this post


Link to post
Share on other sites

I like it when people re-implement something written by big corporations like Google, Microsoft or Apple. But were the specifications for this codec available and enough for you to implement it, or was it reverse engineering done(or is the whole thing open source somewhere?)?

 

Also, what compiler are you using? And to me, it looks like you are proficient in assembly, so I am sure you can inline some assembly to handle that part where you say the compiler is doing a nasty job of optimizing.

 

However, if all you are doing is assigning an integer to whatever that index is pointing to, then that is a lot of instructions for something so simple, but hey, the only thing I know about assembly is what it looks like(depends on the architecture) so I could be wrong.

Edited by farmdve
0

Share this post


Link to post
Share on other sites
Considering that the assembly you posted makes two function calls to (0xfe2195e) and is referencing other objects (what is at -44h and -3ch?) it is pretty clear that you left out some important information from your problem description.

The function calls are conditional, the locations of the elements are computed, and it looks like either object existence or size bounds are being tested. My hunch is that it isn't a simple array at all, but is instead a sparse array or other container class, and objects are potentially getting created and added to it if they were not already present at those two locations.
2

Share this post


Link to post
Share on other sites

Are you looking at an optimized release build, or debug? Maybe the compiler injected some bounds-checking. Or maybe it just rearranged your code and all that other stuff is actually from other lines, to optimize pipelining for example.

Edited by patrrr
0

Share this post


Link to post
Share on other sites

Considering that the assembly you posted makes two function calls to (0xfe2195e) and is referencing other objects (what is at -44h and -3ch?) it is pretty clear that you left out some important information from your problem description.

 

 

if you look closely though, it seems that this is actually the code generated for those two array-index assignments.

 

it does actually follow through and assign the array elements, just it does so in a very roundabout way (far more so than normal).

 

 

those locations are (I suspect) temporaries on the stack, and the function-calls are compiler-inserted array bound-check handlers (newer versions of MSVC insert these).

 

 

here is the context of the code fragment where this came from:

    byte tb[16];
    byte *cs, *cse, *csm;
    byte *ct, *cte;
    int xs1, ys1, n, n1;
    int i, j, k, l;

...

        case 0xA0:
            j=(cs[0]<<8)|cs[1];
            cs+=2;
            j=((j&0x7FE0)<<1)|(j&0x1F);

            tb[0]=j&0xFF;
            tb[1]=(j>>8)&0xFF;
            tb[2]=j&0xFF;
            tb[3]=(j>>8)&0xFF;
            tb[4]=0; tb[5]=0;    //
            tb[6]=0; tb[7]=0;    //here

            n1=(i&31)+1;
            for(i=0; i<n1; i++)
                { memcpy(ct, tb, 8); ct+=stride; }
            
//            ct+=(i&31)*8;
            break;

where each of the pairs of assignments generated the same sequences of instructions...

 

IOW:

it appears as if MSVC has gone and generated a few sequences of unusually bad code...

 

compiler: Visual Studio Express 2013 RC

language: C

0

Share this post


Link to post
Share on other sites

Are you looking at an optimized release build, or debug? Maybe the compiler injected some bounds-checking.

 

this is a debug build.

while debug code isn't usually particularly good, it usually isn't quite this bad.

 

the profiler (AMD Code XL) only really works correctly on debug builds (in my experience), so you have to do a debug build to profile things.

 

 

but, yes, it is compiler-inserted bounds checking...

and some particularly bizarre way of calculating the array offset.

...

 

 

ADD:

switching over to using a pointer rather than a local array, and making a few minor changes (using an #ifdef to eliminate the use of "memcpy()"), did somewhat boost the performance of the debug build, but had negligible impact on a release build (this implies that most likely the release build did not use the bounds-checks).

Edited by BGB
0

Share this post


Link to post
Share on other sites

I like it when people re-implement something written by big corporations like Google, Microsoft or Apple. But were the specifications for this codec available and enough for you to implement it, or was it reverse engineering done(or is the whole thing open source somewhere?)?


most of the needed information is given or is linked to by the wiki articles.
I actually implemented it directly using this information, and tested it using videos from a linked-to site.

granted, it depends a lot on a lot of other code I already had laying around (I implemented the codec mostly by fudging it into DXT1, and using my DXT1 decoder to convert it back to RGBA).

 

Also, what compiler are you using? And to me, it looks like you are proficient in assembly, so I am sure you can inline some assembly to handle that part where you say the compiler is doing a nasty job of optimizing.


as noted, MSVC / Visual Studio 2013 RC.

there are ways to work around this issue without resorting to inline ASM though (usually you don't want to do this if it can be avoided, as this does bad things to portability).

 

However, if all you are doing is assigning an integer to whatever that index is pointing to, then that is a lot of instructions for something so simple, but hey, the only thing I know about assembly is what it looks like(depends on the architecture) so I could be wrong.


this is the issue.

even if building for debug, this is still a lot of code to accomplish the task...

though, even as such (funky array assignments and being a debug build aside), the codec still gets moderately good performance overall. Edited by BGB
0

Share this post


Link to post
Share on other sites

this is the issue.

even if building for debug, this is still a lot of code to accomplish the task...

though, even as such (funky array assignments and being a debug build aside), the codec still gets moderately good performance overall.

 

So the issue is the amount of code that is generated, not the performance hike? Just compile with optimizations. I don't see the problem, and profiling non-optimized code sounds a bit meaningless. Debug symbols are good to have though.

If it's just the bounds checking that is annoying you, you can probably disable it somehow.

Btw. Didn't you find this out during your research? http://www.gamedev.net/blog/1645/entry-2258708-bounds-checking-in-c-it-would-appear-so-sort-of/

1

Share this post


Link to post
Share on other sites


profiling non-optimized code sounds a bit meaningless

This is pretty much what I had to do with my game, the profiler was spitting out stuff that didn't seem to make much sense. I took the release build, copied it and enabled the settings to keep the symbols in (so the profiler could be used), and surprise, suddenly the profiler was showing results that made way more sense with what I'd have expected from the code.

0

Share this post


Link to post
Share on other sites

MSVC gives you options for inserting runtime debugging code, such as bounds checking. These are options - the compiler is just doing what you're telling it to. If you don't want the compiler to do this stuff, edit your project properties.

N.B. these validation options are separate from the optimization and debug-database options.

 

yeah.

 

normally bounds-checks aren't a bad thing, but is kind of pointless with a constant index into a fixed size array, since otherwise it is fairly obvious whether the bounds-check will pass or fail.

 

luckily, it was fairly trivial to side-step though, via using a pointer instead in this case.

 

 

ADD:

just discovered I can generate optimized code and have debug symbols via "/O2 /Zi".

well, this is good to know I guess...

 

(I tried doing similar once before with an older version of MSVC, but it didn't work.)

Edited by BGB
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0