Home > Archive > VC Language > January 2006 > vc 2005 intrinsics
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
vc 2005 intrinsics
|
|
|
| The new VC compiler does not inline memcpy when buffer size is not known at
compile time. Is it possible to somehow force it to do so?
I have a project that does not use CRT, only basic intrinsics (strlen,
memcmp, memcpy), and with new VC generating reference to CRT lib executable
grows up by few KB rubbish - I see some extra functions imported like
RtlUnwind, TerminateProcess, GetCurrentProcess, UnhandledExceptionFilter,
SetUnhandledExceptionFilter, IsDebuggerPresent. They seem unused though, as
I set my own entry point, and memcpy does not use them either.. Shall I
rewrite memcpy myself, or is it possible to discard this unwanted code that
gets linked into executable?
| |
| Carl Daniel [VC++ MVP] 2006-01-28, 7:07 pm |
| qfel wrote:
> The new VC compiler does not inline memcpy when buffer size is not
> known at compile time. Is it possible to somehow force it to do so?
No.
> I have a project that does not use CRT, only basic intrinsics (strlen,
> memcmp, memcpy), and with new VC generating reference to CRT lib
> executable grows up by few KB rubbish - I see some extra functions
> imported like RtlUnwind, TerminateProcess, GetCurrentProcess,
> UnhandledExceptionFilter, SetUnhandledExceptionFilter,
> IsDebuggerPresent. They seem unused though, as I set my own entry
> point, and memcpy does not use them either.. Shall I rewrite memcpy
> myself, or is it possible to discard this unwanted code that gets
> linked into executable?
The functions you named above are all in Kernel32.dll - they're not taking
up any space in your EXE other than import descriptors.
Have you tried supplying your own memcpy? Are the references to those other
functions removed?
I'm guessing that another CRT module (aside from memcpy that is) is being
pulled in which in turn causes those other references. It's likely some
startup code that determines if the processor supports SSE, as memcpy will
use SSE for large transfers if it's available.
-cd
| |
|
| > Have you tried supplying your own memcpy? Are the references to those
> other functions removed?
Yes. But instead of using my own, it would be nicer to use
compiler-supplied, as it can be optimized for known at compile-time
arguments.
> I'm guessing that another CRT module (aside from memcpy that is) is being
> pulled in which in turn causes those other references. It's likely some
> startup code that determines if the processor supports SSE, as memcpy will
> use SSE for large transfers if it's available.
Sounds right, but no startup code can be run because I supply my own
entry-point, so shouldn't it be eliminated by linker?
| |
| Carl Daniel [VC++ MVP] 2006-01-28, 7:07 pm |
| qfel wrote:
> Yes. But instead of using my own, it would be nicer to use
> compiler-supplied, as it can be optimized for known at compile-time
> arguments.
>
> Sounds right, but no startup code can be run because I supply my own
> entry-point, so shouldn't it be eliminated by linker?
Only if the entry point was the only public symbol in the module. It sounds
like it's not. It also seems likely that the CRT version of memcpy relies
on the CRT startup code having run.
-cd
| |
| Jochen Kalmbach [MVP] 2006-01-29, 3:57 am |
| Hi qfel!
> The new VC compiler does not inline memcpy when buffer size is not known
> at compile time. Is it possible to somehow force it to do so?
For me the following code works perfectly without CRT:
<code>
#include <windows.h>
#pragma intrinsic(memcpy)
#pragma comment(linker, "/ENTRY:myEntry")
void DoSomeTest(void *v1, void *v2)
{
memcpy(v1, v2, 10);
}
int myEntry()
{
void *v1 = HeapAlloc(GetProcessHeap(), 0, 100);
void *v2 = HeapAlloc(GetProcessHeap(), 0, 100);
DoSomeTest(v1, v2);
return 0;
}
</code>
Or what do you mean?
dumpbin /ALL reports the following:
Microsoft (R) COFF/PE Dumper Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file CPP_OwnEntry.exe
PE signature found
File Type: EXECUTABLE IMAGE
FILE HEADER VALUES
14C machine (x86)
3 number of sections
43DC8F62 time date stamp Sun Jan 29 10:48:18 2006
0 file pointer to symbol table
0 number of symbols
E0 size of optional header
103 characteristics
Relocations stripped
Executable
32 bit word machine
OPTIONAL HEADER VALUES
10B magic # (PE32)
8.00 linker version
200 size of code
600 size of initialized data
0 size of uninitialized data
1000 entry point (00401000) ?myEntry@@YAHXZ (int __cdecl
myEntry(void))
1000 base of code
2000 base of data
400000 image base (00400000 to 00403FFF)
1000 section alignment
200 file alignment
4.00 operating system version
0.00 image version
4.00 subsystem version
0 Win32 version
4000 size of image
400 size of headers
0 checksum
3 subsystem (Windows CUI)
400 DLL characteristics
No structured exception handler
100000 size of stack reserve
1000 size of stack commit
100000 size of heap reserve
1000 size of heap commit
0 loader flags
10 number of directories
0 [ 0] RVA [size] of Export Directory
2034 [ 28] RVA [size] of Import Directory
0 [ 0] RVA [size] of Resource Directory
0 [ 0] RVA [size] of Exception Directory
0 [ 0] RVA [size] of Certificates Directory
0 [ 0] RVA [size] of Base Relocation Directory
2010 [ 1C] RVA [size] of Debug Directory
0 [ 0] RVA [size] of Architecture Directory
0 [ 0] RVA [size] of Global Pointer Directory
0 [ 0] RVA [size] of Thread Storage Directory
0 [ 0] RVA [size] of Load Configuration Directory
0 [ 0] RVA [size] of Bound Import Directory
2000 [ C] RVA [size] of Import Address Table Directory
0 [ 0] RVA [size] of Delay Import Directory
0 [ 0] RVA [size] of COM Descriptor Directory
0 [ 0] RVA [size] of Reserved Directory
SECTION HEADER #1
.text name
3B virtual size
1000 virtual address (00401000 to 0040103A)
200 size of raw data
400 file pointer to raw data (00000400 to 000005FF)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
60000020 flags
Code
Execute Read
RAW DATA #1
00401000: 53 56 57 8B 3D 00 20 40 00 6A 64 6A 00 FF D7 8B SVW.=.
@.jdj.ÿ×.
00401010: 1D 04 20 40 00 50 FF D3 6A 64 6A 00 8B F0 FF D7 ..
@.PÿÓjdj..ðÿ×
00401020: 50 FF D3 8B 08 89 0E 8B 50 04 89 56 04 66 8B 40
PÿÓ.....P..V.f.@
00401030: 08 5F 66 89 46 08 5E 33 C0 5B C3 ._f.F.^3À[Ã
SECTION HEADER #2
.rdata name
DA virtual size
2000 virtual address (00402000 to 004020D9)
200 size of raw data
600 file pointer to raw data (00000600 to 000007FF)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
40000040 flags
Initialized Data
Read Only
RAW DATA #2
00402000: 74 20 00 00 68 20 00 00 00 00 00 00 00 00 00 00 t ..h
...........
00402010: 00 00 00 00 62 8F DC 43 00 00 00 00 02 00 00 00
.....b.ÜC........
00402020: 46 00 00 00 94 20 00 00 94 06 00 00 00 30 40 00 F....
........0@.
00402030: 58 30 40 00 5C 20 00 00 00 00 00 00 00 00 00 00 X0@.\
...........
00402040: 86 20 00 00 00 20 00 00 00 00 00 00 00 00 00 00 . ...
...........
00402050: 00 00 00 00 00 00 00 00 00 00 00 00 74 20 00 00
.............t ..
00402060: 68 20 00 00 00 00 00 00 10 02 48 65 61 70 41 6C h
.........HeapAl
00402070: 6C 6F 63 00 A3 01 47 65 74 50 72 6F 63 65 73 73
loc.£.GetProcess
00402080: 48 65 61 70 00 00 4B 45 52 4E 45 4C 33 32 2E 64
Heap..KERNEL32.d
00402090: 6C 6C 00 00 52 53 44 53 11 FA B2 77 15 75 69 48
ll..RSDS.ú²w.uiH
004020A0: A8 06 13 6C 1B 94 EF A5 01 00 00 00 65 3A 5C 74
¨..l..ï¥....e:\t
004020B0: 65 73 74 5C 63 70 70 5F 6F 77 6E 65 6E 74 72 79
est\cpp_ownentry
004020C0: 5C 72 65 6C 65 61 73 65 5C 43 50 50 5F 4F 77 6E
\release\CPP_Own
004020D0: 45 6E 74 72 79 2E 70 64 62 00 Entry.pdb.
Debug Directories
Time Type Size RVA Pointer
-------- ------ -------- -------- --------
43DC8F62 cv 46 00002094 694 Format: RSDS,
{77B2FA11-7515-4869-A806-136C1B94EFA5}, 1,
e:\test\cpp_ownentry\release\CPP_OwnEntr
y.pdb
Section contains the following imports:
KERNEL32.dll
402000 Import Address Table
40205C Import Name Table
0 time date stamp
0 Index of first forwarder reference
1A3 GetProcessHeap
210 HeapAlloc
SECTION HEADER #3
.data name
324 virtual size
3000 virtual address (00403000 to 00403323)
0 size of raw data
0 file pointer to raw data
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
C0000040 flags
Initialized Data
Read Write
Summary
1000 .data
1000 .rdata
1000 .text
--
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/
| |
|
|
|
|
|
| >> The new VC compiler does not inline memcpy when buffer size is not known
> For me the following code works perfectly without CRT:
> memcpy(v1, v2, 10);
Here size is known at compile-time.
Try
int myEntry()
{
size_t size=10+rand()%10;
void *v1 = HeapAlloc(GetProcessHeap(), 0, size);
void *v2 = HeapAlloc(GetProcessHeap(), 0, size);
memcpy(v1,v2,size);
return 0;
}
It will compile and work fine, but you'll get warning that .CRT section
exists and there may be unhandled static initializers - executable will grow
much more then expected from memcpy.
|
|
|
|
|