https://godbolt.org/z/cT46Tn5TE
|
private static AssemblyNameFlags GetAssemblyNameFlags(AssemblyFlags flags) |
|
{ |
|
AssemblyNameFlags assemblyNameFlags = AssemblyNameFlags.None; |
|
|
|
if ((flags & AssemblyFlags.PublicKey) != 0) |
|
assemblyNameFlags |= AssemblyNameFlags.PublicKey; |
|
|
|
if ((flags & AssemblyFlags.Retargetable) != 0) |
|
assemblyNameFlags |= AssemblyNameFlags.Retargetable; |
|
|
|
if ((flags & AssemblyFlags.EnableJitCompileTracking) != 0) |
|
assemblyNameFlags |= AssemblyNameFlags.EnableJITcompileTracking; |
|
|
|
if ((flags & AssemblyFlags.DisableJitCompileOptimizer) != 0) |
|
assemblyNameFlags |= AssemblyNameFlags.EnableJITcompileOptimizer; |
|
|
|
return assemblyNameFlags; |
For the above method we generate (with #124738):
G_M38219_IG02: ;; offset=0x0000
mov eax, edx
and eax, 1
mov ecx, eax
or ecx, 256
test edx, 256
cmovne eax, ecx
mov ecx, eax
or ecx, 0x8000
test edx, 0x8000
cmovne eax, ecx
mov ecx, eax
or ecx, 0x4000
test edx, 0x4000
cmovne eax, ecx
;; size=56 bbWeight=1 PerfScore 3.50
G_M38219_IG03: ;; offset=0x0038
ret
While clang/gcc generate:
GetAssemblyNameFlags(int):
mov eax, edi
and eax, 49409
ret
We are missing 2 things.
First, we need to transform this if-version:
if ((flags & 256) != 0)
{
assemblyNameFlags |= 256;
}
into the simpler equivalent: assemblyNameFlags |= flags & 256
Second, when we end up with a bunch of these, e.g:
assemblyNameFlags |= flags & 256;
assemblyNameFlags |= flags & 512;
we need to merge them into one: assemblyNameFlags |= flags & (256 | 512);
https://godbolt.org/z/cT46Tn5TE
runtime/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/MetadataReader.netstandard.cs
Lines 114 to 130 in f416dc4
For the above method we generate (with #124738):
While clang/gcc generate:
We are missing 2 things.
First, we need to transform this if-version:
into the simpler equivalent:
assemblyNameFlags |= flags & 256Second, when we end up with a bunch of these, e.g:
we need to merge them into one:
assemblyNameFlags |= flags & (256 | 512);