|
but wouldn't be even nicer to have the bulk of the process operating on dword-aligned dwords, instead of just running down an array of non-aligned dwords ?
-c
I'm not the droid you're looking for.
|
|
|
|
|
Yeah, the alignment can be a big problem. Routines such as memcmp check first to make sure the data is aligned.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I'm sure it could be written better, and it doesn't handle DWORD alignment, but it will do the trick. For more information on the Intel instruction set:
http://www.intel.com/design/pentium4/manuals/245471.htm[^]
void Invert( unsigned char * p_pucData, unsigned long p_ulLen )
{
__asm
{
pusha
mov ecx, p_ulLen
mov ebx, p_pucData
head:
cmp ecx, 4
jle tailbytes
not dword ptr [ebx]
sub ecx, 4
cmp ecx, 0
je end
add ebx, 4
jmp head
tailbytes:
cmp ecx, 0
je end
not byte ptr [ebx]
add ebx, 1
sub ecx, 1
jmp tailbytes
end:
popa
}
}
Chris Richardson
Programmers find all sorts of ingenious ways to screw ourselves over. - Tim Smith
|
|
|
|
|
just FYI, this takes less than 15% of the time of the first invert loop i posted:
int z;
BYTE *pb = pBuf;
UINT32 uLeadUp = (DWORD)pBuf & 0x03;
for (z=0;z < uLeadUp;z++)
{
*pb = ~(*pb);pb++;
}
uLen-=uLeadUp;
UINT32 dwords = uLen / 4;
UINT32 leftovers = uLen % 4;
DWORD *p = (DWORD*)pb;
for (z=0;z < dwords;z++)
{
*p = ~(*p);
p++;
}
pb+=4;
for (z=0;z < leftovers;z++)
{
pb[z] = ~pb[z];
}
-c
I'm not the droid you're looking for.
|
|
|
|
|
I just ran some tests, here are the results:
My Machine:
2GHz Pentium 4
512 MB Ram
Data: 180MB char array.
Test: Bitwise NOT the contents of the array 100 times, alternating between the assembly version and the C++ version.
Debug build:
C++ Version:
445 ms average.
Assembler Version:
285 ms average.
Release Build:
C++ Version:
268 ms average.
Assembler Version:
284 ms average.
I think the most significant optimization (from your original sample) is copying 32 bits at a time, rather than 8 bits at a time, but surely the alignment helps.
It also appears that the optimizer is definately your friend!
Chris Richardson
Programmers find all sorts of ingenious ways to screw ourselves over. - Tim Smith
|
|
|
|
|
It also appears that the optimizer is definately your friend!
About a month ago, someone posted a speed fix for a strxxx routine. I thought the enhancement was cool, but really didn't think it would be better than the MASM strxxx routine in CRTL.
I was wrong.
My bet is that many of those old strxxx MASM routines haven't been reviewed for performance on newer machines. A lot has changed.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Tim Smith wrote:
My bet is that many of those old strxxx MASM routines haven't been reviewed for performance on newer machines. A lot has changed.
Imagine how much has changed even in just the last 4.5 years since VC6 was first released. I would not be surprised at all to find that those old asm routines need a bit of review.
Chris Richardson
Programmers find all sorts of ingenious ways to screw ourselves over. - Tim Smith
|
|
|
|
|
I'm not an assembly geek, but did you consider
just assembly stepping into memcpy, copying their
code and modifying to to do whatever particular
operation you need? It should just involve replacing
a MOV instruction with an XOR or OR instruction.
Oh, on other thing, if you are going for fast
performance, I believe the special MMX instructions
of the Pentium processor can do this sort of stuff
really fast (obviously you'll have to check processor
version and provide an alternative for processors
without those instructions.)
|
|
|
|
|
I'm currently working on an MDI application that has dockable toolbars and a child window (view). I want to make a menu item that allows me to return the windows & toolbars to their initial position. I am able to place the toolbars successfully via docktoolbar(), but i cannot recall how to handle the child window. I would like to capture the window's position during/just after it's creation, and upon the appropriate menu call, restore that position. I've looked into Get/Set-WindowPlacement() but i'm very unclear on it's usage. Any advice would be appreciated, code is especially helpful.
I was also wondering how i can call the built in functionality from the window->tile menu command that tiles your child windows (from within my code at runtime).
Thanks
Jeff Rothenberg
Project Engineer
Vector CANtech, Inc.
|
|
|
|
|
Good Formating everyone !
I need to set the string length of a float number :
for example, I have this number :
345.22123123 , and the length is 4 , so the output will be 345.2 , no leader zero, or trunc/round at the end, it's only outputing the number; if the lenght is smaller than the representation of the number, I manage this already.
What's the magic formula for this ?
MSDN says :
%[flags] [width] [.precision] [{h | l | I64 | L}]type
But I'm not sure what width or precision to set, since the width is the minimum length, and the precision is what's after the decimal.
Thanks.
Clueless Max.
|
|
|
|
|
there's a g format token that helps ...
Max.
|
|
|
|
|
I would like to alter the caption displayed on the buttons in a MSVC++ Message box. I've currently got MB_YESNO buttons and would like to have them display Bi lingual text (ie. YES/OUI and NO/NON). Any ideas on how to do this.
Thanks in advance.
|
|
|
|
|
I believe you'll have to make your own dialog to do that. If you're using MFC, you can just create something in the resource editor with some generic buttons, and derive from CDialog and add a few functions to set the text.
As a note - the system Message Boxes will display their text in the language installed/selected on the machine. That is, on an English system, they show English, and on a French system, they show French, etc. So maybe you don't even need to change them...?
Even a broken clock is right twice a day.
|
|
|
|
|
It's not simple. You actually can't change the captions n a true message box; they are fixed.
However, you can use a class called TcxMessageBox to do this, along with a lot of other message box customizations. It's on CP, somewhere.
|
|
|
|
|
|
Hi all, hope someone can help.
Using GetCurrentHWProfile() to obtain GUID string in simple app. #defining _WIN32_WINNT (0x0400)(and #include "windows.h")which ensures that the program works fine with NT and Win2k, but f() fails on a Win98 machine even though the f() is supposed to work with Win95 OSR2 and upwards.
Can't find any documentation in the MSDN - anybody know of further #defines that are necessary for this to work on a Win9x machine?
Sonork ID: 100.13715 - 3bananas4
I have detailed files
|
|
|
|
|
Hi,
I want to spawn a process and wait for it to finish. I'm doing this in a seperate thread, so the user can continue working. The problem is that the new process comes popping up in front of the application each time! Now I could spawn the process with _P_DETACH, so the process is invisible, but that way I can't wait for the process to finish. That is important, because when the process finishes, I build a texture of it's output image. Is this possible and if so how?
Thanks in advance,
Wybren van Keulen,
Funny Farm
|
|
|
|
|
Go to MSDN and check out CreateProcess and WaitForSingleObject .
Even a broken clock is right twice a day.
|
|
|
|
|
Hi All,
I've got a CDialogBar derived class which contains a rich edit control, I am using this as a message window for an MDI app. How can I modify the right click menu that is shown? Currently, my options are "Hide" and "Undock" or something like that. I would llike to add a CLear option to the message window.
Thanks,
Aaron
|
|
|
|
|
Hi All,
I've got a workspace style app (MDI), with a CDialogBar derived window containing a tree control on the left (for navigation, opening views, etc), and a CDialogBar derived window containing an edit control on the bottom (for messages), which sort of looks like the Visual Studio workspace. On exiting the application, I need to save the window position and state of the docking windows. How do I do this?
I guess can get a window rect with GetWindow?? soething or other, but how do I get the docked/undocked state of the window?
Thanks in advance,
Aaron
|
|
|
|
|
Have a look at
SetWindowPlacement/GetWindowPlacement for normal windows.
SaveBarState/LoadBarState for CControlbar windows.
Max.
|
|
|
|
|
Hey Thanks!
That worked pretty good, so far. I found the DOCKTOOL sample searching for that as well, which has helped.
So far, I am able to save the placement of the main frame, and restore the stae of the control bars.
But, what should I use to save/restore the size of the control bars? Ie, when I close the app, the message bar comes up with the correct state, but is not the correct size.
Can I use GetWindowPlacement for the control bars? Or do I need something like GetWindowRect/MoveWindow?
Thanks Again,
Aaron
|
|
|
|
|
AfxInitRichEdit();
I put this in the app class in an MFC MDI.
Now I have just a CDialog based app, and if I dont put it in, i dont get anything.....
Where should it go?
Appreciate your help,
ns
|
|
|
|
|
The dialog based application still should have a class derived from CWinApp...put the AfxInitRichEdit call in the app's InitInstance function
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
I found the function...many thanks
Appreciate your help,
ns
|
|
|
|