Last active
September 8, 2022 15:30
-
-
Save tmyt/77b837d142b6c8ef7963f0005ace6268 to your computer and use it in GitHub Desktop.
tweet_char_weight
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<cstdio> | |
#include<iostream> | |
#include<vector> | |
struct WeightRange{ | |
int start; | |
int end; | |
int weight; | |
WeightRange(int start_, int end_, int weight_) { | |
start = start_; | |
end = end_; | |
weight = weight_; | |
} | |
}; | |
std::vector<WeightRange> ranges{ | |
WeightRange(0, 4351, 100), | |
WeightRange(8192, 8205, 100), | |
WeightRange(8208, 8223, 100), | |
WeightRange(8242, 8247, 100) | |
}; | |
int main(){ | |
int code, w = 200; | |
std::cin >> code; | |
for(const auto &r : ranges){ | |
if(r.start <= code && code <= r.end){ w = 100; break; } | |
} | |
printf("%d\n", w); | |
} | |
/* | |
_main: | |
0040E670: 51 push ecx | |
0040E671: 56 push esi | |
0040E672: 8D 44 24 04 lea eax,[esp+4] | |
0040E676: B9 10 92 4B 00 mov ecx,offset ?cin@std@@3V?$basic_istream@DU?$char_traits@D@std@@@1@A | |
0040E67B: 50 push eax | |
0040E67C: BE C8 00 00 00 mov esi,0C8h | |
0040E681: E8 57 6F FF FF call @ILT+17880(??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAH@Z) | |
0040E686: A1 24 90 4B 00 mov eax,dword ptr [?ranges@@3V?$vector@UWeightRange@@V?$allocator@UWeightRange@@@std@@@std@@A] | |
0040E68B: 8B 15 28 90 4B 00 mov edx,dword ptr ds:[4B9028h] | |
0040E691: 3B C2 cmp eax,edx | |
0040E693: 74 33 je 0040E6C8 | |
0040E695: 8B 4C 24 04 mov ecx,dword ptr [esp+4] | |
0040E699: 0F 1F 80 00 00 00 nop dword ptr [eax] | |
00 | |
0040E6A0: 39 08 cmp dword ptr [eax],ecx | |
0040E6A2: 7F 05 jg 0040E6A9 | |
0040E6A4: 3B 48 04 cmp ecx,dword ptr [eax+4] | |
0040E6A7: 7E 1A jle 0040E6C3 | |
0040E6A9: 83 C0 0C add eax,0Ch | |
0040E6AC: 3B C2 cmp eax,edx | |
0040E6AE: 75 F0 jne 0040E6A0 | |
0040E6B0: 56 push esi | |
0040E6B1: 68 A0 E1 49 00 push 49E1A0h | |
0040E6B6: E8 6E 73 FF FF call @ILT+18980(_printf) | |
0040E6BB: 83 C4 08 add esp,8 | |
0040E6BE: 33 C0 xor eax,eax | |
0040E6C0: 5E pop esi | |
0040E6C1: 59 pop ecx | |
0040E6C2: C3 ret | |
0040E6C3: BE 64 00 00 00 mov esi,64h | |
0040E6C8: 56 push esi | |
0040E6C9: 68 A0 E1 49 00 push 49E1A0h | |
0040E6CE: E8 56 73 FF FF call @ILT+18980(_printf) | |
0040E6D3: 83 C4 08 add esp,8 | |
0040E6D6: 33 C0 xor eax,eax | |
0040E6D8: 5E pop esi | |
0040E6D9: 59 pop ecx | |
0040E6DA: C3 ret | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<cstdio> | |
#include<iostream> | |
int main(){ | |
int code, w = 200; | |
std::cin >> code; | |
if(0 <= code && code <= 4351){ w = 100; } | |
else if (8192<= code && code <= 8205){ w = 100; } | |
else if (8208<= code && code <= 8223){ w = 100; } | |
else if (8242<= code && code <= 8247){ w = 100; } | |
printf("%d\n", w); | |
} | |
/* | |
_main: | |
0040E370: 51 push ecx | |
0040E371: 56 push esi | |
0040E372: 8D 44 24 04 lea eax,[esp+4] | |
0040E376: B9 00 92 4B 00 mov ecx,offset ?cin@std@@3V?$basic_istream@DU?$char_traits@D@std@@@1@A | |
0040E37B: 50 push eax | |
0040E37C: BE C8 00 00 00 mov esi,0C8h | |
0040E381: E8 85 71 FF FF call @ILT+17670(??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAH@Z) | |
0040E386: 8B 4C 24 04 mov ecx,dword ptr [esp+4] | |
0040E38A: 81 F9 FF 10 00 00 cmp ecx,10FFh | |
0040E390: 76 16 jbe 0040E3A8 | |
0040E392: 8D 81 00 E0 FF FF lea eax,[ecx-2000h] | |
0040E398: 83 F8 0D cmp eax,0Dh | |
0040E39B: 76 0B jbe 0040E3A8 | |
0040E39D: 8D 81 F0 DF FF FF lea eax,[ecx-2010h] | |
0040E3A3: 83 F8 0F cmp eax,0Fh | |
0040E3A6: 77 18 ja 0040E3C0 | |
0040E3A8: BE 64 00 00 00 mov esi,64h | |
0040E3AD: 56 push esi | |
0040E3AE: 68 90 E0 49 00 push 49E090h | |
0040E3B3: E8 8B 75 FF FF call @ILT+18750(_printf) | |
0040E3B8: 83 C4 08 add esp,8 | |
0040E3BB: 33 C0 xor eax,eax | |
0040E3BD: 5E pop esi | |
0040E3BE: 59 pop ecx | |
0040E3BF: C3 ret | |
0040E3C0: 8D 81 CE DF FF FF lea eax,[ecx-2032h] | |
0040E3C6: B9 64 00 00 00 mov ecx,64h | |
0040E3CB: 83 F8 05 cmp eax,5 | |
0040E3CE: 0F 46 F1 cmovbe esi,ecx | |
0040E3D1: 56 push esi | |
0040E3D2: 68 90 E0 49 00 push 49E090h | |
0040E3D7: E8 67 75 FF FF call @ILT+18750(_printf) | |
0040E3DC: 83 C4 08 add esp,8 | |
0040E3DF: 33 C0 xor eax,eax | |
0040E3E1: 5E pop esi | |
0040E3E2: 59 pop ecx | |
0040E3E3: C3 ret | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<cstdio> | |
#include<iostream> | |
int main(){ | |
int code, w = 200; | |
std::cin >> code; | |
if((0 <= code && code <= 4351) | |
||(8192<= code && code <= 8205) | |
||(8208<= code && code <= 8223) | |
||(8242<= code && code <= 8247)){ w = 100; } | |
printf("%d\n", w); | |
printf("%d\n", w); | |
} | |
/* | |
_main: | |
0040E370: 51 push ecx | |
0040E371: 56 push esi | |
0040E372: 8D 44 24 04 lea eax,[esp+4] | |
0040E376: B9 00 92 4B 00 mov ecx,offset ?cin@std@@3V?$basic_istream@DU?$char_traits@D@std@@@1@A | |
0040E37B: 50 push eax | |
0040E37C: BE C8 00 00 00 mov esi,0C8h | |
0040E381: E8 85 71 FF FF call @ILT+17670(??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAH@Z) | |
0040E386: 8B 44 24 04 mov eax,dword ptr [esp+4] | |
0040E38A: 85 C0 test eax,eax | |
0040E38C: 78 07 js 0040E395 | |
0040E38E: 3D FF 10 00 00 cmp eax,10FFh | |
0040E393: 7E 26 jle 0040E3BB | |
0040E395: 3D 00 20 00 00 cmp eax,2000h | |
0040E39A: 7C 07 jl 0040E3A3 | |
0040E39C: 3D 0D 20 00 00 cmp eax,200Dh | |
0040E3A1: 7E 18 jle 0040E3BB | |
0040E3A3: 3D 10 20 00 00 cmp eax,2010h | |
0040E3A8: 7C 07 jl 0040E3B1 | |
0040E3AA: 3D 1F 20 00 00 cmp eax,201Fh | |
0040E3AF: 7E 0A jle 0040E3BB | |
0040E3B1: 05 CE DF FF FF add eax,0FFFFDFCEh | |
0040E3B6: 83 F8 05 cmp eax,5 | |
0040E3B9: 77 05 ja 0040E3C0 | |
0040E3BB: BE 64 00 00 00 mov esi,64h | |
0040E3C0: 56 push esi | |
0040E3C1: 68 90 E0 49 00 push 49E090h | |
0040E3C6: E8 78 75 FF FF call @ILT+18750(_printf) | |
0040E3CB: 56 push esi | |
0040E3CC: 68 94 E0 49 00 push 49E094h | |
0040E3D1: E8 6D 75 FF FF call @ILT+18750(_printf) | |
0040E3D6: 83 C4 10 add esp,10h | |
0040E3D9: 33 C0 xor eax,eax | |
0040E3DB: 5E pop esi | |
0040E3DC: 59 pop ecx | |
0040E3DD: C3 ret | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<cstdio> | |
#include<iostream> | |
int main(){ | |
int code, w = 200; | |
std::cin >> code; | |
code = | |
(code ^ (code - 4352) ^ (code - 8192) ^ (code - 8206) ^ (code - 8208) ^ (code - 8224) ^ (code - 8242) ^ (code - 8248)); | |
w = code < 0 ? 100 : 200; | |
printf("%d\n", w); | |
} | |
/* | |
_main: | |
0040E370: 51 push ecx | |
0040E371: 8D 04 24 lea eax,[esp] | |
0040E374: B9 00 92 4B 00 mov ecx,offset ?cin@std@@3V?$basic_istream@DU?$char_traits@D@std@@@1@A | |
0040E379: 50 push eax | |
0040E37A: E8 8C 71 FF FF call @ILT+17670(??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAH@Z) | |
0040E37F: 8B 14 24 mov edx,dword ptr [esp] | |
0040E382: 8D 82 CE DF FF FF lea eax,[edx-2032h] | |
0040E388: 8D 8A C8 DF FF FF lea ecx,[edx-2038h] | |
0040E38E: 33 C8 xor ecx,eax | |
0040E390: 8D 82 E0 DF FF FF lea eax,[edx-2020h] | |
0040E396: 33 C8 xor ecx,eax | |
0040E398: 8D 82 F0 DF FF FF lea eax,[edx-2010h] | |
0040E39E: 33 C8 xor ecx,eax | |
0040E3A0: 8D 82 F2 DF FF FF lea eax,[edx-200Eh] | |
0040E3A6: 33 C8 xor ecx,eax | |
0040E3A8: 8D 82 00 E0 FF FF lea eax,[edx-2000h] | |
0040E3AE: 33 C8 xor ecx,eax | |
0040E3B0: 8D 82 00 EF FF FF lea eax,[edx-1100h] | |
0040E3B6: 33 C8 xor ecx,eax | |
0040E3B8: B8 C8 00 00 00 mov eax,0C8h | |
0040E3BD: 33 D1 xor edx,ecx | |
0040E3BF: B9 64 00 00 00 mov ecx,64h | |
0040E3C4: 0F 4C C1 cmovl eax,ecx | |
0040E3C7: 50 push eax | |
0040E3C8: 68 90 E0 49 00 push 49E090h | |
0040E3CD: E8 71 75 FF FF call @ILT+18750(_printf) | |
0040E3D2: 33 C0 xor eax,eax | |
0040E3D4: 83 C4 0C add esp,0Ch | |
0040E3D7: C3 ret | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<cstdio> | |
#include<iostream> | |
#include<Intrin.h> | |
__declspec(align(32)) | |
int TableBase[]{ 0, 4352, 8192, 8206, 8208, 8224, 8242, 8248 }; | |
__m256i table = *(__m256i*)TableBase; | |
inline int check(int code){ | |
int cnt; | |
__asm { | |
vpbroadcastd ymm1, code | |
vpcmpgtd ymm1, ymm1, table | |
vpmovmskb eax, ymm1 | |
vpslld ymm1, ymm1, 31 | |
popcnt eax, eax | |
lea eax, [eax + eax * 4] | |
mov cnt, ax | |
} | |
std::cout << cnt << std::endl; | |
return cnt ? 100 : 200; | |
} | |
int main() | |
{ | |
int code, w = 200; | |
std::cin >> code; | |
/* | |
auto codes = _mm256_set_epi32(code, code, code, code, code, code, code, code); | |
auto cmp = _mm256_cmpgt_epi32(table, codes); | |
auto bits = _mm256_movemask_epi8(cmp); | |
auto cnt = __popcnt(bits) >> 2; | |
w = cnt & 1 ? 100 : 200; | |
*/ | |
w = check(code); | |
printf("%d\n", w); | |
return 0; | |
} | |
/* | |
_main: | |
0040E390: 51 push ecx | |
0040E391: 8D 04 24 lea eax,[esp] | |
0040E394: B9 60 92 4B 00 mov ecx,offset ?cin@std@@3V?$basic_istream@DU?$char_traits@D@std@@@1@A | |
0040E399: 50 push eax | |
0040E39A: E8 6C 71 FF FF call @ILT+17670(??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAH@Z) | |
0040E39F: C4 E2 7D 58 04 24 vpbroadcastd ymm0,dword ptr [esp] | |
0040E3A5: C5 FD 66 05 60 90 vpcmpgtd ymm0,ymm0,ymmword ptr [?table@@3T__m256i@@A] | |
4B 00 | |
0040E3AD: C5 FD D7 C0 vpmovmskb eax,ymm0 | |
0040E3B1: F3 0F B8 C0 popcnt eax,eax | |
0040E3B5: A8 04 test al,4 | |
0040E3B7: B9 64 00 00 00 mov ecx,64h | |
0040E3BC: B8 C8 00 00 00 mov eax,0C8h | |
0040E3C1: 0F 45 C1 cmovne eax,ecx | |
0040E3C4: 50 push eax | |
0040E3C5: 68 A0 E1 49 00 push 49E1A0h | |
0040E3CA: C5 F8 77 vzeroupper | |
0040E3CD: E8 71 75 FF FF call @ILT+18750(_printf) | |
0040E3D2: 33 C0 xor eax,eax | |
0040E3D4: 83 C4 0C add esp,0Ch | |
0040E3D7: C3 ret | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cl /Ox /Z7 /arch:AVX2 1.cpp | |
cl /Ox /Z7 /arch:AVX2 2.cpp | |
cl /Ox /Z7 /arch:AVX2 3.cpp | |
cl /Ox /Z7 /arch:AVX2 4.cpp | |
cl /Ox /Z7 /arch:AVX2 5.cpp | |
dumpbin /disasm 1.exe > 1.asm | |
dumpbin /disasm 2.exe > 2.asm | |
dumpbin /disasm 3.exe > 3.asm | |
dumpbin /disasm 4.exe > 4.asm | |
dumpbin /disasm 5.exe > 5.asm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment