Click here to Skip to main content
15,888,031 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: VC6.0 compiler error C2664 while using GUID Pin
PecuniousPete10-Dec-12 8:00
PecuniousPete10-Dec-12 8:00 
AnswerRe: VC6.0 compiler error C2664 while using GUID Pin
Arild Fiskum19-Dec-12 10:18
Arild Fiskum19-Dec-12 10:18 
QuestionFork Implementation using the native API RtlCloneUserProcess Pin
akhilmv889-Dec-12 4:00
akhilmv889-Dec-12 4:00 
QuestionDeclaring a TBYTE in C. Pin
Member 41945938-Dec-12 15:04
Member 41945938-Dec-12 15:04 
AnswerRe: Declaring a TBYTE in C. Pin
manoranjan8-Dec-12 20:56
manoranjan8-Dec-12 20:56 
GeneralRe: Declaring a TBYTE in C. Pin
Member 41945939-Dec-12 3:29
Member 41945939-Dec-12 3:29 
GeneralRe: Declaring a TBYTE in C. Pin
manoranjan9-Dec-12 23:47
manoranjan9-Dec-12 23:47 
GeneralRe: Declaring a TBYTE in C. Pin
Member 419459310-Dec-12 12:11
Member 419459310-Dec-12 12:11 
manoranjan,

I have already implemented the DQWORD arrays for my MASM version, and am adding printf statements of intermediate calculations. The change to use TBYTES did fix the differences I had seen in the calculated ENT value between the C version and my MASM version. This was not as simple as it looked to be at first. The only FPU instructions than can use TBYTES are FLD and FST. You cannot use FADD TBYTE PTR [i], but I can see where the xxxP FPU instructions come from:

fld    val1    /* st0 = val1               */
fadd   val2    /* st0 = (val1+val2)        */
fdiv   val3    /* st0 = ((val1+val2)/val3) */


This had to be changed to:

fld    val1    /* st0 = val1               */
fld    val2    /* st0 = val2, st1 = val2   */
faddp          /* st0 = (val1+val2)        */
fld    val3    /* st0 = val2, st1 = val2   */
fdivp          /* st0 = ((val1+val2)/val3) */


It turns out that this is exactly what the FPU needs to do for an faddd val - it must push the stack, load the double/float/integer into st0 and convert it to temporary real, then add/sub/mul/div ST(1) by ST(0) and put the result into ST(1), then pop the stack leaving the result in ST(0). With TBYTES you just have to do it manually, - BUT - The FPU doesn't have to do any conversions - the TBYTE is already in temporary real format and can contain a signed QWORD (63 bits, + sign). Unfortunately, the FPU cannot handle unsigned 64 bit values (they end up as negative values).


See here for ENT: [^]

The biggest improvement I got was changing from fgetc for each character to reading 65536 bytes into a buffer (with no system buffering) and indexing through the BYTES, then reading more from the file into the buffer and processing. Another interesting change was to fill the buffer, initialize one time for the FIRST character, then skip to process the characters, skipping around the subsequent re-fill buffer entry point. So little extra code, BUT, avoided checking if this was the first character 16 billion times as was done in ENT. Another speedup was to fragment the character occurrence buffer - I had to grow the collection bins to a QWORD for supporting a max file (2^63 BYTES), but in the BIT mode this increased the count to 2^66. I had to accumulate the counts in three DWORDS in a DQWORD, using "add value, adc 0, adc 0," but this occurred (in my 16 GB test) 16 billion times. With a smaller buffer that could contain the counts in a DWORD, it was just an "add value" for the buffer count, then 256 iterations of "add value, adc 0, adc 0," to accumulate the 256 occurrence values in the DQWORD array and clear the DWORD counts between buffer fills. Also for checking whether a bin had any count at all (several places in ENT checked this), I accumulated (at the end of the file processing) the 3 DWORDS for each entry into the fourth DWORD that could be tested with a single instruction.

But I digress from a simple C question into something more appropriate for Algorithms.

Dave
GeneralRe: Declaring a TBYTE in C. Pin
manoranjan11-Dec-12 1:35
manoranjan11-Dec-12 1:35 
QuestionMethods bank account Pin
Magda63477-Dec-12 10:17
Magda63477-Dec-12 10:17 
AnswerRe: Methods bank account Pin
Richard MacCutchan7-Dec-12 21:56
mveRichard MacCutchan7-Dec-12 21:56 
AnswerRe: Methods bank account Pin
Alan Balkany10-Dec-12 5:43
Alan Balkany10-Dec-12 5:43 
AnswerRe: Methods bank account Pin
PecuniousPete10-Dec-12 8:05
PecuniousPete10-Dec-12 8:05 
GeneralRe: Methods bank account Pin
Magda634713-Mar-13 11:36
Magda634713-Mar-13 11:36 
Questionread text file Pin
peoria1237-Dec-12 9:59
peoria1237-Dec-12 9:59 
AnswerRe: read text file Pin
André Kraak7-Dec-12 20:56
André Kraak7-Dec-12 20:56 
AnswerRe: read text file Pin
Sajeesh Payolam9-Dec-12 21:05
Sajeesh Payolam9-Dec-12 21:05 
QuestionWM_DEVICECHANGE sets wParam to unexpected value of 7 - how to troubleshoot this? Pin
Vaclav_7-Dec-12 4:10
Vaclav_7-Dec-12 4:10 
AnswerRe: WM_DEVICECHANGE sets wParam to unexpected value of 7 - how to troubleshoot this? Pin
Jochen Arndt7-Dec-12 5:56
professionalJochen Arndt7-Dec-12 5:56 
AnswerRe: WM_DEVICECHANGE sets wParam to unexpected value of 7 - how to troubleshoot this? Pin
jeron17-Dec-12 5:59
jeron17-Dec-12 5:59 
GeneralRe: WM_DEVICECHANGE sets wParam to unexpected value of 7 - how to troubleshoot this? Pin
Vaclav_7-Dec-12 6:58
Vaclav_7-Dec-12 6:58 
AnswerRe: WM_DEVICECHANGE sets wParam to unexpected value of 7 - how to troubleshoot this? Pin
Richard MacCutchan7-Dec-12 21:51
mveRichard MacCutchan7-Dec-12 21:51 
GeneralRe: WM_DEVICECHANGE sets wParam to unexpected value of 7 - how to troubleshoot this? Pin
Vaclav_9-Dec-12 5:47
Vaclav_9-Dec-12 5:47 
AnswerRe: WM_DEVICECHANGE sets wParam to unexpected value of 7 - how to troubleshoot this? Pin
PecuniousPete9-Dec-12 20:23
PecuniousPete9-Dec-12 20:23 
Questionhow to find out the codes who eat up my memory? Pin
Falconapollo7-Dec-12 2:32
Falconapollo7-Dec-12 2:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.