0

I have a small __msfastcall function with nothing but inline __asm { } code. How do I tell c++builder to not generated a stack frame for the function when generating it for both x86 and x64 architectures?

WARNING: When using the modern c++ compiler the __msfastcall is unknown and ignored. To make it extra confusing that compiler uses the __msfastcall ABI by default and not the one documented by Embaracardo. See CLang Attributes for __fastcall

Here's the weird (WRONG) code it generates with the stack frame (it's debug mode):

crc32chw.cpp.75: uint64_t __fastcall _mm_crc32_u64(unsigned __int64 crc, unsigned __int64 v)
000000000164ECC0 55               push rbp
crc32chw.cpp.75: uint64_t __fastcall _mm_crc32_u64(unsigned __int64 crc, unsigned __int64 v)
000000000164ECC1 4883EC18         sub rsp, 0x18
000000000164ECC5 488D6C2410       lea rbp, [rsp + 0x10]
000000000164ECCA 48894DF8         mov qword ptr [rbp - 0x8], rcx
000000000164ECCE 488955F0         mov qword ptr [rbp - 0x10], rdx
crc32chw.cpp.77: __asm {
000000000164ECD2 F2480F38F1CA     crc32 rcx, rdx
000000000164ECD8 4889C8           mov rax, rcx
crc32chw.cpp.81: }
000000000164ECDB 488B4500         mov rax, qword ptr [rbp]
000000000164ECDF 4883C418         add rsp, 0x18
000000000164ECE3 5D               pop rbp
000000000164ECE4 C3               ret 
user3161924
  • 1,849
  • 18
  • 33
  • Does it generate a stack frame for that function? If it does, are you using the stack within that function in some way you're not aware of? I would expect the optimizer to remove all of that if you aren't actually using the stack. – Ouroborus Jul 03 '23 at 01:44
  • 1
    Not sure if this works in the Clang compiler, but in the old compiler [`__declspec(naked)`](https://docwiki.embarcadero.com/RADStudio/en/Declspec(naked)) removes the stack frame. FYI, Clang's `__fastcall` is Borland/EMB's `__msfastcall`, and Borland/EMB's `__fastcall` is Delphi's `register`. – Remy Lebeau Jul 04 '23 at 18:07

0 Answers0