Jump to content

  • Log In with Google      Sign In   
  • Create Account

NightCreature83

Member Since 21 Feb 2008
Offline Last Active Today, 02:17 AM

#5261872 [c++ | asm x64] I think I call a function in the wrong way

Posted by NightCreature83 on 13 November 2015 - 02:52 AM

Eeh, I must be sounding like a spoiled asshole dry.png I won't argue if you think that of me.
But I'm not that bad a person. Really.

And I appreciate the help.

I'm just bitter because I'm being halted by yet another problem that's only the last in a long streak you haven't seen me deal with. Only, this time it involves assembly, a subject I never delved in.
Could this be solved it'd be the very last brick to complete the wall. Which makes it even more frustrating a problem, 'cause I'm spending several hours on it instead of moving on the other modules in this project.

I'll read the link posted by Nypyren (<-- thanks for it, man), and then, dunno, we'll see...

What are you really trying to achieve, maybe if you described more of your problem in general terms we might actually be able to give you a solution. And that solution might not even need asm to work.




#5261843 [c++ | asm x64] I think I call a function in the wrong way

Posted by NightCreature83 on 12 November 2015 - 05:39 PM

 

The ABI for both the 32-bit and 64-bit code is well documented. There are several large PDFs about it, you need to read them and have a solid understanding of what they are and how they work for all the different calling conventions and parameter types, an understanding of what must be saved and what is invalidated, and know how to convert from one to the other.

So you're saying that I should go read a couple tomes, learn how to do proper assembly, implying that I shouldn't be asking for help in a forum.

Honestly, that wasn't nice. At all.

 

[...] On the other hand, the 32-bit cdecl calling convention will preserve EBX, EBP, EDI, ESI, ESP, CS, and DS. While the 32-bit code shouldn't be touching the Rxx registers you need to know that they might, so you need to preserve them. Since the memory addresses in 64-bit code may not exist in the 32-bit address space you need to ensure proper virtualization. You don't do either.

You talk to me as if I know this stuff already. Don't you realize that this is the same mistake made by every one of those that write the tutorials on assembly? Those very same tutorials that I don't understand -- because they assume I'm familiar with the subject _already_? If that was the case why would I be reading a tutorial?
And the same goes for the notes on the x64 ABI -- And by the way, by mere luck I know what A.B.I. stands for. But you just threw the acronim in the discussion, assuming that I knew it _already_. See? the same mistake
 

 

@ Rattrap:

I understand now. Makes sense.

But still: whatever I write, doesn't work. It crashes invariably. I'm noticing a misalignment with the arguments passed to the function that's crashing. Instead of a pointer to a pointer I'm seeing the address of a local function. And where should be a small integer value I'm seeing what might be a portion of an address. It's as if things were offset to the left or right altogether.

 

You are trying to do something in asm that is a fairly advanced affair, if you dont understand asm well enough I would not even start with DLL loading and stick with getting the hang of asm first. Visual Studio can show you what asm is generated for C/C++ code when you are on a breakpoint and tell it to show you the disassembly. It should look like this: L3ral.png

 

Assembly is not a topic you should jump in lightly and x86 and x64 is not the easiest instruction set to get to know. You should start learning asm with a simple board like an arduino or a Rasberry pi, this chips are simple enough to easily understand what is going on on them. From there moving to x86 and x64 is easier, because you understand the basics of asm by that point.

 

There are some serious tricks going on in some asm code like moving to only the ah or al register and then cmp on the next line with eax or rax, which require that you know things about the architecture of the chips involved. For example: al/ah, ax, eax and rax all refer to the same register for example but with different bit sizes and this is all legacy stuff coming from the shifts from 8 bits -> 16bits -> 32bits -> 64 bits. In x64 you will hardly see any x87 or FPU instructions any more these are almost always replaced by SSE2 instructions. I am surpised that link nypren provided didnt mention the LEA instruction because next to the most common once that lists.




#5260924 char[32] as function parameter

Posted by NightCreature83 on 07 November 2015 - 02:40 PM

The syntax for array passing is crazy in C++ but this will do allow you to do this:

template <size_t charCount>
void stringCopy(char (&output)[charCount], const char* source)
{
}

I highly recommend you use a template on the array parameter here because this function now works with any sized arrays.

 




#5258020 Confusion with smart pointers

Posted by NightCreature83 on 19 October 2015 - 06:03 PM

You would get access violations if you were trying to access member variables in those functions on very low address. Like access violation at 0x00000008 for example, usually when seeing these low address values in access violations it indicates that your object access has been cleared. Because members are usually accessed by adding the field offset to the object memory address.




#5256990 Migrated from VC++ 2008 Express to Visual Studio 2015: Now getting linking er...

Posted by NightCreature83 on 13 October 2015 - 01:32 AM

Or if you have the code for that library rebuild it with VS2015




#5256818 Hash on gpu?

Posted by NightCreature83 on 12 October 2015 - 02:57 AM

The question I am asking myself is why do you want to do this on the GPU. If its just to have a resource name changed in a hash the CPU will do fine for that.




#5255993 Thoughts on the Boost.Build system? (as opposed to CMake?)

Posted by NightCreature83 on 07 October 2015 - 05:57 AM

For C++ on Windows, I've been preferring development in Sublime Text, rather than Visual Studio. It's more lightweight, there's less magic going on and I've got it configured the way I like. And I really hate VC++'s filtered folder project system. I just want to see my source directory and not have to screw around with the project file every time I want to add a child folder. Also, as someone from a non-C++ background, I feel I am learning more by running my own build script (just a custom PowerShell script at the moment) and having it run CL.exe. CMake is all well and good, but my project is built around a large number of plugins which each have to be built separately, and... well I guess the way CMake clutters up my folders with a million files just irks me a bit. That, and I've read a number of stories from other projects where the developers were complaining about CMake problems that made their lives harder rather than easier on Linux. I like things to be simple and clean.

 

Even so, I know that maintaining your own set of build scripts can get complicated and be a pain to maintain, particularly when you want to target the other major OS's as well. CMake's not the only show in town. What do you guys think about Boost's build system? I built Boost for the first time a few weeks ago and found the build process to be very clean and straightforward. Still, CMake seems to be what the majority of dev teams gravitate towards, so I'd like to get the opinions of those more experienced than myself with cross-platform C and C++ development. If you know of something else really solid as well, I'd be interested in that as well.

 

You do know that you can switch Visual Studios solution explorer view to show you the real files underneath right? Once you set this and saved the solution file it will open in this view. The option is called "show all" and is in the top bar of the solution explorer window, this change the option in the add menu from "New Filter" to "New Folder".
 




#5255801 What's the best system on which to learn ASM?

Posted by NightCreature83 on 06 October 2015 - 07:05 AM

I much preferred the 68k style of assembly over x86 just feels cleaner and nicer to work with but as Eric said, you have an x86/x64 machine so easier to play with.

 

That said in the modern world it is far harder to get to the metal than it was when I played with assembly so getting an old machine emulator and using that would be a good in.

 

For a gentile introduction in playing at a low level you could explore the old nerd classic that is http://www.corewars.org/ is is a pseudo assembly language where two programs get loaded into an "address space" and have to locate and destroy the other before they get killed smile.png

 

Its not that hard to kick an asm function even from x64 code, the only thing that has gotten hard is that the C++ compiler no longer allows for inline ASM.

Is a good series on getting started with x64 asm in VS2010, he shows you how to call an asm function and then moves on to explaining what all the instructions do.

 

I learned ASM on a 8088 like board with MASM as the compiler this looked so much like x86 asm that moving to PC was only getting used to the new register names like EAX and stuff.
 

The other thing you can do is write a simple function in C/C++ and see what the compiler transforms that into on PC in a debug build. You will want to do this in a debug build because in that case the compiler will actual transform all of your code in to ASM.




#5255116 WIN32 or WIN64

Posted by NightCreature83 on 02 October 2015 - 05:37 AM

 

Are you running out of memory/resources while you target x86? If not then the question becomes "Is it worth it?" smile.png

 

That was the initial reason, yes

 

The market is now dominated by x64 machines, only 12% of the windows OS installbase in the steam hardware survey is running a 32bit version of windows on mac and linux there is no more 32bit version in the survey. Another reason to add x64 support is so you find those nasty bugs in your code where you are assuming that a pointer is always of size 4, these kinds of constructs in your code are bad.

 

One of the other reasons could also be that all 64bit cpus support SSE2 so that SIMD instructions in release builds are enabled by default, this might give you a performance increase for free.




#5254764 Shaders

Posted by NightCreature83 on 30 September 2015 - 06:32 AM

I am assuming you are doing some more sorting than just the shader states right, because eliminating state changes in my rendering loop gave me a good performance boost even doing this manually with keeping track of the current ids and just checking against what I would be setting next.




#5254759 Why did COD: AW move every file into the same folder where .exe is?

Posted by NightCreature83 on 30 September 2015 - 05:16 AM

This is Steam, do they even have an ability to control that?

Besides, why do you care? It works and that's enough.

Steam is nothing special as a developer you have the control over where files are located in your own directory structure.

 

It looks like COD went with an archive format for their files now which allows for better compression on the archived files. This will in turn have a faster load from the disc with perhaps a trade of in the decompression step of those files in the archive. The massive FF files seem to be the archive files. And it seems like they made a single archive per location which means you dont have to jump through the directory structure to load the files for a level. This is offcourse all speculation on my part :)




#5254419 pass an array? (stock c++)

Posted by NightCreature83 on 28 September 2015 - 11:35 AM

The safest way to do this in stock C++ is to use a template

template<class T, size_t arraySizeX, size_t arraySizeY>
void function1(T(&array)[arraySizeX][arraySizeY])
{
    for (auto counter = 0; counter < arraySizeX; ++counter)
    {
        for (auto counter1 = 0; counter1 < arraySizeY; ++counter1)
        {
            array[counter][counter1] = 111;
            std::cout << array[counter][counter1] << std::endl;
        }
    }
}
 
//Call the function
int anArray[12][3];
function1(anArray);

You can now make use of arraySizeX and arraySizeY inside of the template for the size in both directions. The function syntax looks weird but it will capture the size of the array through the compiler.  You can find more information about this at this link

Caveat though this only works for stuff that is an array, you can't pass a pointer this way, that will actually generate a compile time error.




#5253781 Feedback on this Threading architecture

Posted by NightCreature83 on 24 September 2015 - 02:31 AM

Can your renderer exist on a seperate thread so that that thread only has to deal with rendering transforms and feeding the GPU, whilst you update the game on the other thread?




#5253678 can anyone explain const char*, char, strings, char array

Posted by NightCreature83 on 23 September 2015 - 09:31 AM

 

 

Any advanced string type, std::string as well, will inform you of chracter count especialy, when calling .size()

This is not true if the string is UTF enocded. UTF8 and UTF16 can encode a single character in multiple bytes. If you store UTF8 in a std::string size() doesn't guarantee that it corresponds to the number of characters in the string, it will however guarantee the amounts of bytes needed for the buffer, and the same goes for storing a UTF16 string in a std::wstring.

 

How does it contradict my quote? It is what I said, that size yields amount of characters...

 

That is just what I am saying it does not do that for a UTF8 or UTF16 encoded string, size actually gives you the size of the internal buffer not the number of characters used in the string. UTF8 can encode a single utf character in 3 chars internally in the string buffer, this happens when you start using characters outside the latin A character set, japanese and chinese characters for example need more bytes to express their pattern so it can be displayed.




#5253650 C++ Graphics Library

Posted by NightCreature83 on 23 September 2015 - 07:27 AM

It can do that too, among other things. While I have read a bit about it in the past I have not actually used it so far. The closest analogue in a nutshell is probably "something like Windows GDI" independent of any OS. That includes different output devices (a simple memory bitmap, a PDF, an OpenGL texture which was created by rendering into a framebuffer, ...).

EAWebkit uses cairo interally to render the webpages/uis you load with it out to a bitmap you can use for your rendering pipe.






PARTNERS