From fea5284c31a8409a2e7ac04cdb66f35c4fd099cc Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 25 Mar 2024 20:03:53 +0100 Subject: [PATCH 01/52] JIT: Split ABI classification by ABI --- src/coreclr/jit/abi.cpp | 374 ++++++++++++++++++++++++ src/coreclr/jit/abi.h | 117 +++++++- src/coreclr/jit/compiler.h | 5 + src/coreclr/jit/compmemkind.h | 1 + src/coreclr/jit/lclvars.cpp | 219 +++++++------- src/coreclr/jit/registerargconvention.h | 13 +- 6 files changed, 598 insertions(+), 131 deletions(-) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index d28e11f6129b3f..dc5f2b9e43d10a 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -120,3 +120,377 @@ bool ABIPassingInformation::IsSplitAcrossRegistersAndStack() const } return anyReg && anyStack; } + +ABIPassingInformation ABIPassingInformation::FromSegment(Compiler* comp, const ABIPassingSegment& segment) +{ + ABIPassingInformation info; + info.NumSegments = 1; + info.Segments = new (comp, CMK_ABI) ABIPassingSegment(segment); + return info; +} + +regNumber RegisterQueue::Dequeue() +{ + assert(Count() > 0); + return static_cast(m_regs[m_index++]); +} + +regNumber RegisterQueue::Peek() +{ + assert(Count() > 0); + return static_cast(m_regs[m_index]); +} + +void RegisterQueue::Clear() +{ + m_index = m_numRegs; +} + +static unsigned TypeSize(var_types type, ClassLayout* structLayout) +{ + return type == TYP_STRUCT ? structLayout->GetSize() : genTypeSize(type); +} + +#ifdef TARGET_X86 +ABIPassingInformation X86Classifier::Classify(Compiler* comp, + var_types type, + ClassLayout* structLayout, + WellKnownArg wellKnownParam) +{ + unsigned size = TypeSize(type, structLayout); + unsigned numSlots = (size + TARGET_POINTER_SIZE - 1) / TARGET_POINTER_SIZE; + + bool canEnreg = false; + if (m_regs.Count() >= numSlots) + { + switch (type) + { + case TYP_BYTE: + case TYP_UBYTE: + case TYP_SHORT: + case TYP_USHORT: + case TYP_INT: + case TYP_REF: + case TYP_BYREF: + canEnreg = true; + break; + case TYP_STRUCT: + canEnreg = comp->isTrivialPointerSizedStruct(structLayout->GetClassHandle()); + default: + break; + } + } + + ABIPassingSegment segment; + if (canEnreg) + { + assert(numSlots == 1); + segment = ABIPassingSegment::InRegister(m_regs.Dequeue(), 0, size); + } + else + { + assert((m_stackArgSize % TARGET_POINTER_SIZE) == 0); + segment = ABIPassingSegment::OnStack(m_stackArgSize, 0, size); + m_stackArgSize += roundUp(size, TARGET_POINTER_SIZE); + } + + return ABIPassingInformation::FromSegment(comp, segment); +} +#endif + +#ifdef WINDOWS_AMD64_ABI +static const regNumberSmall WinX64IntArgRegs[] = {REG_RCX, REG_RDX, REG_R8, REG_R9}; +static const regNumberSmall WinX64FloatArgRegs[] = {REG_XMM0, REG_XMM1, REG_XMM2, REG_XMM3}; + +WinX64Classifier::WinX64Classifier() + : m_intRegs(WinX64IntArgRegs, ArrLen(WinX64IntArgRegs)), m_floatRegs(WinX64FloatArgRegs, ArrLen(WinX64FloatArgRegs)) +{ +} + +ABIPassingInformation WinX64Classifier::Classify(Compiler* comp, + var_types type, + ClassLayout* structLayout, + WellKnownArg wellKnownParam) +{ + // On windows-x64 ABI all parameters take exactly 1 stack slot (structs + // that do not fit are passed implicitly by reference). Passing a parameter + // in an int register also consumes the corresponding float register and + // vice versa. + assert(m_intRegs.Count() == m_floatRegs.Count()); + + unsigned typeSize = TypeSize(type, structLayout); + if ((typeSize > TARGET_POINTER_SIZE) || !isPow2(typeSize)) + { + typeSize = TARGET_POINTER_SIZE; // Passed by implicit byref + } + + ABIPassingSegment segment; + if (m_intRegs.Count() > 0) + { + regNumber reg = varTypeUsesFloatArgReg(type) ? m_floatRegs.Peek() : m_intRegs.Peek(); + segment = ABIPassingSegment::InRegister(reg, 0, typeSize); + m_intRegs.Dequeue(); + m_floatRegs.Dequeue(); + } + else + { + segment = ABIPassingSegment::OnStack(m_stackArgSize, 0, typeSize); + m_stackArgSize += TARGET_POINTER_SIZE; + } + + return ABIPassingInformation::FromSegment(comp, segment); +} +#endif + +#ifdef UNIX_AMD64_ABI +static const regNumberSmall SysVX64IntArgRegs[] = {REG_EDI, REG_ESI, REG_EDX, REG_ECX, REG_R8, REG_R9}; +static const regNumberSmall SysVX64FloatArgRegs[] = {REG_XMM0, REG_XMM1, REG_XMM2, REG_XMM3, + REG_XMM4, REG_XMM5, REG_XMM6, REG_XMM7}; + +SysVX64Classifier::SysVX64Classifier() + : m_intRegs(SysVX64IntArgRegs, ArrLen(SysVX64IntArgRegs)) + , m_floatRegs(SysVX64FloatArgRegs, ArrLen(SysVX64FloatArgRegs)) +{ +} + +ABIPassingInformation SysVX64Classifier::Classify(Compiler* comp, + var_types type, + ClassLayout* structLayout, + WellKnownArg wellKnownParam) +{ + bool canEnreg = false; + SYSTEMV_AMD64_CORINFO_STRUCT_REG_PASSING_DESCRIPTOR structDesc; + if (varTypeIsStruct(type)) + { + comp->eeGetSystemVAmd64PassStructInRegisterDescriptor(structLayout->GetClassHandle(), &structDesc); + + if (structDesc.passedInRegisters) + { + unsigned intRegCount = 0; + unsigned floatRegCount = 0; + + for (unsigned int i = 0; i < structDesc.eightByteCount; i++) + { + if (structDesc.IsIntegralSlot(i)) + { + intRegCount++; + } + else if (structDesc.IsSseSlot(i)) + { + floatRegCount++; + } + else + { + assert(!"Invalid eightbyte classification type."); + break; + } + } + + canEnreg = (m_intRegs.Count() <= intRegCount) && (m_floatRegs.Count() <= floatRegCount); + } + } + else + { + unsigned availRegs = varTypeUsesFloatArgReg(type) ? m_floatRegs.Count() : m_intRegs.Count(); + canEnreg = availRegs > 0; + } + + ABIPassingInformation info; + if (canEnreg) + { + if (varTypeIsStruct(type)) + { + info.NumSegments = structDesc.eightByteCount; + info.Segments = new (comp, CMK_ABI) ABIPassingSegment[structDesc.eightByteCount]; + + for (unsigned i = 0; i < structDesc.eightByteCount; i++) + { + regNumber reg = structDesc.IsIntegralSlot(i) ? m_intRegs.Dequeue() : m_floatRegs.Dequeue(); + info.Segments[i] = + ABIPassingSegment::InRegister(reg, structDesc.eightByteOffsets[i], structDesc.eightByteSizes[i]); + } + } + else + { + regNumber reg = varTypeUsesFloatArgReg(type) ? m_floatRegs.Dequeue() : m_intRegs.Dequeue(); + info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::InRegister(reg, 0, genTypeSize(type))); + } + } + else + { + assert((m_stackArgSize % TARGET_POINTER_SIZE) == 0); + unsigned size = TypeSize(type, structLayout); + info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::OnStack(m_stackArgSize, 0, size)); + m_stackArgSize += roundUp(size, TARGET_POINTER_SIZE); + } + + return info; +} +#endif + +#ifdef TARGET_ARM64 +static const regNumberSmall Arm64IntArgRegs[] = {REG_R0, REG_R1, REG_R2, REG_R3, REG_R4, REG_R5, REG_R6, REG_R7}; +static const regNumberSmall Arm64FloatArgRegs[] = {REG_V0, REG_V1, REG_V2, REG_V3, REG_V4, REG_V5, REG_V6, REG_V7}; + +Arm64Classifier::Arm64Classifier() + : m_intRegs(Arm64IntArgRegs, ArrLen(Arm64IntArgRegs)), m_floatRegs(Arm64FloatArgRegs, ArrLen(Arm64FloatArgRegs)) +{ +} + +ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, + var_types type, + ClassLayout* structLayout, + WellKnownArg wellKnownParam) +{ + if (wellKnownParam == WellKnownArg::RetBuffer) + { + return ABIPassingInformation::FromSegment(comp, ABIPassingSegment::InRegister(REG_ARG_RET_BUFF, 0, + TARGET_POINTER_SIZE)); + } + + if (varTypeIsStruct(type) && !comp->info.compIsVarArgs) + { + var_types hfaType = comp->GetHfaType(structLayout->GetClassHandle()); + + if (hfaType != TYP_UNDEF) + { + unsigned elemSize = genTypeSize(hfaType); + unsigned slots = structLayout->GetSize() / elemSize; + ABIPassingInformation info; + if (m_floatRegs.Count() >= slots) + { + info.NumSegments = slots; + info.Segments = new (comp, CMK_ABI) ABIPassingSegment[slots]; + + for (unsigned i = 0; i < slots; i++) + { + info.Segments[i] = ABIPassingSegment::InRegister(m_floatRegs.Dequeue(), i * elemSize, elemSize); + } + } + else + { + unsigned alignment = compAppleArm64Abi() ? elemSize : TARGET_POINTER_SIZE; + m_stackArgSize = roundUp(m_stackArgSize, alignment); + info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::OnStack(m_stackArgSize, 0, + structLayout->GetSize())); + m_stackArgSize += structLayout->GetSize(); + // After passing any float value on the stack, we should not enregister more float values. + m_floatRegs.Clear(); + } + + return info; + } + } + + unsigned slots; + if (varTypeIsStruct(type)) + { + unsigned size = structLayout->GetSize(); + if (size > 16) + { + slots = 1; // Passed by implicit byref + } + else + { + slots = (size + TARGET_POINTER_SIZE - 1) / TARGET_POINTER_SIZE; + } + } + else + { + assert(genTypeSize(type) <= TARGET_POINTER_SIZE); + slots = 1; + } + + assert((slots == 1) || (slots == 2)); + + ABIPassingInformation info; + if (comp->info.compIsVarArgs && (slots == 2) && (m_intRegs.Count() == 1)) + { + // On varargs we split structs between register and stack in this case. + // Normally a struct that does not fit in registers will always be + // passed on stack. + assert(compFeatureArgSplit()); + info.NumSegments = 2; + info.Segments = new (comp, CMK_ABI) ABIPassingSegment[2]; + info.Segments[0] = ABIPassingSegment::InRegister(m_intRegs.Dequeue(), 0, TARGET_POINTER_SIZE); + info.Segments[1] = ABIPassingSegment::OnStack(m_stackArgSize, TARGET_POINTER_SIZE, + structLayout->GetSize() - TARGET_POINTER_SIZE); + m_stackArgSize += TARGET_POINTER_SIZE; + } + else + { + RegisterQueue& regs = varTypeUsesFloatArgReg(type) ? m_floatRegs : m_intRegs; + + if (regs.Count() >= slots) + { + info.NumSegments = slots; + info.Segments = new (comp, CMK_ABI) ABIPassingSegment[slots]; + unsigned slotSize = varTypeIsStruct(type) ? TARGET_POINTER_SIZE : genTypeSize(type); + info.Segments[0] = ABIPassingSegment::InRegister(regs.Dequeue(), 0, slotSize); + if (slots == 2) + { + assert(varTypeIsStruct(type)); + unsigned tailSize = structLayout->GetSize() - slotSize; + info.Segments[1] = ABIPassingSegment::InRegister(regs.Dequeue(), slotSize, tailSize); + } + } + else + { + unsigned alignment; + if (compAppleArm64Abi()) + { + if (varTypeIsStruct(type)) + { + alignment = TARGET_POINTER_SIZE; + } + else + { + alignment = genTypeSize(type); + } + + m_stackArgSize = roundUp(m_stackArgSize, alignment); + } + else + { + alignment = TARGET_POINTER_SIZE; + assert((m_stackArgSize % TARGET_POINTER_SIZE) == 0); + } + + unsigned size = TypeSize(type, structLayout); + info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::OnStack(m_stackArgSize, 0, size)); + + m_stackArgSize += roundUp(size, alignment); + + // As soon as we pass something on stack we cannot go back and + // enregister something else. + regs.Clear(); + } + } + + return info; +} +#endif + +#ifdef SWIFT_SUPPORT +ABIPassingInformation SwiftABIClassifier::Classify(Compiler* comp, + var_types type, + ClassLayout* structLayout, + WellKnownArg wellKnownParam) +{ +#ifdef TARGET_AMD64 + if (wellKnownParam == WellKnownArg::RetBuffer) + { + return ABIPassingInformation::FromSegment(comp, ABIPassingSegment::InRegister(REG_SWIFT_ARG_RET_BUFF, 0, + TARGET_POINTER_SIZE)); + } +#endif + + if (wellKnownParam == WellKnownArg::SwiftSelf) + { + return ABIPassingInformation::FromSegment(comp, ABIPassingSegment::InRegister(REG_SWIFT_SELF, 0, + TARGET_POINTER_SIZE)); + } + + return m_classifier.Classify(comp, type, structLayout, wellKnownParam); +} +#endif diff --git a/src/coreclr/jit/abi.h b/src/coreclr/jit/abi.h index 4d50c46851fa9c..9bfa0b94863116 100644 --- a/src/coreclr/jit/abi.h +++ b/src/coreclr/jit/abi.h @@ -36,18 +36,127 @@ class ABIPassingSegment struct ABIPassingInformation { // The number of segments used to pass the value. Examples: - // - On x86, TYP_LONG can be passed in two registers, resulting in two - // register segments // - On SysV x64, structs can be passed in two registers, resulting in two // register segments // - On arm64/arm32, HFAs can be passed in up to four registers, giving // four register segments // - On arm32, structs can be split out over register and stack, giving // multiple register segments and a struct segment. - // - On Windows x64, all parameters always belong into one stack slot or register, - // and thus always have NumSegments == 1 + // - On Windows x64, all parameters always fit into one stack slot or + // register, and thus always have NumSegments == 1 unsigned NumSegments = 0; ABIPassingSegment* Segments = nullptr; bool IsSplitAcrossRegistersAndStack() const; + + static ABIPassingInformation FromSegment(Compiler* comp, const ABIPassingSegment& segment); +}; + +class RegisterQueue +{ + const regNumberSmall* m_regs; + unsigned int m_numRegs; + unsigned int m_index = 0; + +public: + RegisterQueue(const regNumberSmall* regs, unsigned int numRegs) : m_regs(regs), m_numRegs(numRegs) + { + } + + unsigned Count() + { + return m_numRegs - m_index; + } + + regNumber Dequeue(); + regNumber Peek(); + void Clear(); +}; + +class X86Classifier +{ + RegisterQueue m_regs; + unsigned m_stackArgSize = 0; + +public: + X86Classifier(const regNumberSmall* regs, unsigned int numRegs) : m_regs(regs, numRegs) + { + } + + ABIPassingInformation Classify(Compiler* comp, + var_types type, + ClassLayout* structLayout, + WellKnownArg wellKnownParam); +}; + +class WinX64Classifier +{ + RegisterQueue m_intRegs; + RegisterQueue m_floatRegs; + unsigned m_stackArgSize = 0; + +public: + WinX64Classifier(); + + ABIPassingInformation Classify(Compiler* comp, + var_types type, + ClassLayout* structLayout, + WellKnownArg wellKnownParam); +}; + +class SysVX64Classifier +{ + RegisterQueue m_intRegs; + RegisterQueue m_floatRegs; + unsigned m_stackArgSize = 0; + +public: + SysVX64Classifier(); + + ABIPassingInformation Classify(Compiler* comp, + var_types type, + ClassLayout* structLayout, + WellKnownArg wellKnownParam); +}; + +class Arm64Classifier +{ + RegisterQueue m_intRegs; + RegisterQueue m_floatRegs; + unsigned m_stackArgSize = 0; + +public: + Arm64Classifier(); + + ABIPassingInformation Classify(Compiler* comp, + var_types type, + ClassLayout* structLayout, + WellKnownArg wellKnownParam); +}; + +#if defined(TARGET_X86) +typedef X86Classifier PlatformClassifier; +#elif defined(WINDOWS_AMD64_ABI) +typedef WinX64Classifier PlatformClassifier; +#elif defined(UNIX_AMD64_ABI) +typedef SysVX64Classifier PlatformClassifier; +#elif defined(TARGET_ARM64) +typedef Arm64Classifier PlatformClassifier; +#endif + +#ifdef SWIFT_SUPPORT +class SwiftABIClassifier +{ + PlatformClassifier m_classifier; + +public: + SwiftABIClassifier() + { + } + + ABIPassingInformation Classify(Compiler* comp, + var_types type, + ClassLayout* structLayout, + WellKnownArg wellKnownParam); }; +#endif diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 4e9ec67b31a467..5d85ec124c3f6c 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -3994,6 +3994,11 @@ class Compiler CORINFO_ARG_LIST_HANDLE varList, CORINFO_SIG_INFO* varSig); + template + void lvaClassifyParameterABI(Classifier& classifier); + + void lvaClassifyParameterABI(); + bool lvaInitSpecialSwiftParam(InitVarDscInfo* varDscInfo, CorInfoType type, CORINFO_CLASS_HANDLE typeHnd); var_types lvaGetActualType(unsigned lclNum); diff --git a/src/coreclr/jit/compmemkind.h b/src/coreclr/jit/compmemkind.h index e986682894c3b6..0221eadb067492 100644 --- a/src/coreclr/jit/compmemkind.h +++ b/src/coreclr/jit/compmemkind.h @@ -10,6 +10,7 @@ // and the corresponding array of string names for these enum members. // clang-format off +CompMemKindMacro(ABI) CompMemKindMacro(AssertionProp) CompMemKindMacro(ASTNode) CompMemKindMacro(InstDesc) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 3630020fc12873..2503642a42c44d 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -35,6 +35,8 @@ unsigned Compiler::s_lvaDoubleAlignedProcsCount = 0; void Compiler::lvaInit() { + lvaParameterPassingInfo = nullptr; + /* We haven't allocated stack variables yet */ lvaRefCountState = RCS_INVALID; @@ -258,23 +260,23 @@ void Compiler::lvaInitTypeRef() { case CorInfoCallConvExtension::Thiscall: // In thiscall the this parameter goes into a register. - varDscInfo.Init(lvaTable, lvaParameterPassingInfo, hasRetBuffArg, 1, 0); + varDscInfo.Init(lvaTable, hasRetBuffArg, 1, 0); break; case CorInfoCallConvExtension::C: case CorInfoCallConvExtension::Stdcall: case CorInfoCallConvExtension::CMemberFunction: case CorInfoCallConvExtension::StdcallMemberFunction: - varDscInfo.Init(lvaTable, lvaParameterPassingInfo, hasRetBuffArg, 0, 0); + varDscInfo.Init(lvaTable, hasRetBuffArg, 0, 0); break; case CorInfoCallConvExtension::Managed: case CorInfoCallConvExtension::Fastcall: case CorInfoCallConvExtension::FastcallMemberFunction: default: - varDscInfo.Init(lvaTable, lvaParameterPassingInfo, hasRetBuffArg, MAX_REG_ARG, MAX_FLOAT_REG_ARG); + varDscInfo.Init(lvaTable, hasRetBuffArg, MAX_REG_ARG, MAX_FLOAT_REG_ARG); break; } #else - varDscInfo.Init(lvaTable, lvaParameterPassingInfo, hasRetBuffArg, MAX_REG_ARG, MAX_FLOAT_REG_ARG); + varDscInfo.Init(lvaTable, hasRetBuffArg, MAX_REG_ARG, MAX_FLOAT_REG_ARG); #endif lvaInitArgs(&varDscInfo); @@ -415,7 +417,7 @@ void Compiler::lvaInitArgs(InitVarDscInfo* varDscInfo) //---------------------------------------------------------------------- - /* Is there a "this" pointer ? */ + // Is there a "this" pointer ? lvaInitThisPtr(varDscInfo); unsigned numUserArgsToSkip = 0; @@ -468,6 +470,10 @@ void Compiler::lvaInitArgs(InitVarDscInfo* varDscInfo) // We have set info.compArgsCount in compCompile() noway_assert(varDscInfo->varNum == info.compArgsCount); + + // Now we have parameters created in the right order. Figure out how they're passed. + lvaClassifyParameterABI(); + assert(varDscInfo->intRegArgNum <= MAX_REG_ARG); codeGen->intRegState.rsCalleeRegArgCount = varDscInfo->intRegArgNum; @@ -515,16 +521,6 @@ void Compiler::lvaInitThisPtr(InitVarDscInfo* varDscInfo) lvaSetClass(varDscInfo->varNum, info.compClassHnd); } - varDsc->lvIsRegArg = 1; - noway_assert(varDscInfo->intRegArgNum == 0); - - varDsc->SetArgReg( - genMapRegArgNumToRegNum(varDscInfo->allocRegArg(TYP_INT), varDsc->TypeGet(), info.compCallConv)); -#if FEATURE_MULTIREG_ARGS - varDsc->SetOtherArgReg(REG_NA); -#endif - varDsc->lvOnFrame = true; // The final home for this incoming register might be our local stack frame - #ifdef DEBUG if (verbose) { @@ -581,19 +577,6 @@ void Compiler::lvaInitRetBuffArg(InitVarDscInfo* varDscInfo, bool useFixedRetBuf } #endif - ABIPassingInformation* abiInfo = varDscInfo->abiInfo; - abiInfo->NumSegments = 1; - abiInfo->Segments = new (this, CMK_LvaTable) ABIPassingSegment[1]; - - if (varDsc->lvIsRegArg) - { - abiInfo->Segments[0] = ABIPassingSegment::InRegister(varDsc->GetArgReg(), 0, TARGET_POINTER_SIZE); - } - else - { - abiInfo->Segments[0] = ABIPassingSegment::OnStack(varDsc->GetStackOffset(), 0, TARGET_POINTER_SIZE); - } - compArgSize += TARGET_POINTER_SIZE; varDscInfo->nextParam(); @@ -677,7 +660,6 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo, unsigned skipArgs, un } #endif - ABIPassingInformation* abiInfo = varDscInfo->abiInfo; // For ARM, ARM64, LOONGARCH64, RISCV64 and AMD64 varargs, all arguments go in integer registers var_types argType = mangleVarArgsType(varDsc->TypeGet()); @@ -1053,16 +1035,6 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo, unsigned skipArgs, un genMapRegArgNumToRegNum(firstAllocatedRegArgNum + 1, TYP_I_IMPL, info.compCallConv)); varDsc->lvIsMultiRegArg = true; } - - abiInfo->NumSegments = cSlots; - abiInfo->Segments = new (this, CMK_LvaTable) ABIPassingSegment[cSlots]; - for (unsigned i = 0; i < cSlots; i++) - { - abiInfo->Segments[i] = - ABIPassingSegment::InRegister(genMapRegArgNumToRegNum(firstAllocatedRegArgNum + i, TYP_I_IMPL, - info.compCallConv), - i * TARGET_POINTER_SIZE, TARGET_POINTER_SIZE); - } } #elif defined(UNIX_AMD64_ABI) if (varTypeIsStruct(argType)) @@ -1085,14 +1057,6 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo, unsigned skipArgs, un } assert(structDesc.eightByteCount <= 2); - abiInfo->NumSegments = structDesc.eightByteCount; - abiInfo->Segments = new (this, CMK_LvaTable) ABIPassingSegment[structDesc.eightByteCount]; - for (int i = 0; i < structDesc.eightByteCount; i++) - { - regNumber reg = i == 0 ? varDsc->GetArgReg() : varDsc->GetOtherArgReg(); - abiInfo->Segments[i] = ABIPassingSegment::InRegister(reg, structDesc.eightByteOffsets[i], - structDesc.eightByteSizes[i]); - } } #elif defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64) if (argType == TYP_STRUCT) @@ -1125,14 +1089,6 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo, unsigned skipArgs, un varDsc->lvIsSplit = 1; varDsc->SetOtherArgReg(REG_STK); varDscInfo->setAllRegArgUsed(argRegTypeInStruct1); - - abiInfo->NumSegments = 2; - abiInfo->Segments = new (this, CMK_LvaTable) ABIPassingSegment[2]; - abiInfo->Segments[0] = - ABIPassingSegment::InRegister(varDsc->GetArgReg(), 0, genTypeSize(argRegTypeInStruct1)); - abiInfo->Segments[1] = ABIPassingSegment::OnStack(varDscInfo->stackArgSize, TARGET_POINTER_SIZE, - TARGET_POINTER_SIZE); - varDscInfo->stackArgSize += TARGET_POINTER_SIZE; #ifdef TARGET_RISCV64 varDscInfo->hasSplitParam = true; @@ -1204,44 +1160,8 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo, unsigned skipArgs, un { numEnregistered = cSlots; } - - abiInfo->NumSegments = numEnregistered + (stackSize > 0 ? 1 : 0); - abiInfo->Segments = new (this, CMK_LvaTable) ABIPassingSegment[abiInfo->NumSegments]; - for (unsigned i = 0; i < numEnregistered; i++) - { - abiInfo->Segments[i] = - ABIPassingSegment::InRegister(genMapRegArgNumToRegNum(firstAllocatedRegArgNum + i, argType, - info.compCallConv), - i * TARGET_POINTER_SIZE, TARGET_POINTER_SIZE); - } - - if (stackSize > 0) - { - abiInfo->Segments[numEnregistered] = - ABIPassingSegment::OnStack(0, numEnregistered * TARGET_POINTER_SIZE, stackSize); - } - #endif // TARGET_ARM - if (abiInfo->NumSegments == 0) - { - // Structs at this point are always passed in 1 slot (either - // because it is small enough, or because it is an implicit - // byref). HFA's are also handled here, but they were retyped - // to have argType equal to their element type. - assert((argType != TYP_STRUCT) || (cSlots == 1)); - abiInfo->NumSegments = cSlots; - unsigned size = argType == TYP_STRUCT ? TARGET_POINTER_SIZE : genTypeSize(argType); - abiInfo->Segments = new (this, CMK_LvaTable) ABIPassingSegment[cSlots]; - for (unsigned i = 0; i < cSlots; i++) - { - abiInfo->Segments[i] = - ABIPassingSegment::InRegister(genMapRegArgNumToRegNum(firstAllocatedRegArgNum + i, argType, - info.compCallConv), - i * size, size); - } - } - #ifdef DEBUG if (verbose) { @@ -1391,11 +1311,6 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo, unsigned skipArgs, un JITDUMP("set user arg V%02u offset to %u\n", varDscInfo->varNum, varDscInfo->stackArgSize); varDsc->SetStackOffset(varDscInfo->stackArgSize); - - abiInfo->NumSegments = 1; - abiInfo->Segments = new (this, CMK_LvaTable) - ABIPassingSegment(ABIPassingSegment::OnStack(varDscInfo->stackArgSize, 0, argSize)); - varDscInfo->stackArgSize += argSize; } @@ -1486,15 +1401,11 @@ bool Compiler::lvaInitSpecialSwiftParam(InitVarDscInfo* varDscInfo, CorInfoType const char* className = info.compCompHnd->getClassNameFromMetadata(typeHnd, &namespaceName); if ((strcmp(className, "SwiftSelf") == 0) && (strcmp(namespaceName, "System.Runtime.InteropServices.Swift") == 0)) { - LclVarDsc* varDsc = varDscInfo->varDsc; - ABIPassingInformation* abiInfo = varDscInfo->abiInfo; + LclVarDsc* varDsc = varDscInfo->varDsc; varDsc->SetArgReg(REG_SWIFT_SELF); varDsc->SetOtherArgReg(REG_NA); varDsc->lvIsRegArg = true; - abiInfo->NumSegments = 1; - abiInfo->Segments = new (this, CMK_LvaTable) - ABIPassingSegment(ABIPassingSegment::InRegister(REG_SWIFT_SELF, 0, TARGET_POINTER_SIZE)); compArgSize += TARGET_POINTER_SIZE; lvaSwiftSelfArg = varDscInfo->varNum; @@ -1515,11 +1426,9 @@ void Compiler::lvaInitGenericsCtxt(InitVarDscInfo* varDscInfo) { info.compTypeCtxtArg = varDscInfo->varNum; - LclVarDsc* varDsc = varDscInfo->varDsc; - varDsc->lvIsParam = 1; - varDsc->lvType = TYP_I_IMPL; - ABIPassingInformation* abiInfo = varDscInfo->abiInfo; - abiInfo->NumSegments = 1; + LclVarDsc* varDsc = varDscInfo->varDsc; + varDsc->lvIsParam = 1; + varDsc->lvType = TYP_I_IMPL; if (varDscInfo->canEnreg(TYP_I_IMPL)) { @@ -1531,8 +1440,6 @@ void Compiler::lvaInitGenericsCtxt(InitVarDscInfo* varDscInfo) #if FEATURE_MULTIREG_ARGS varDsc->SetOtherArgReg(REG_NA); #endif - abiInfo->Segments = new (this, CMK_LvaTable) - ABIPassingSegment(ABIPassingSegment::InRegister(varDsc->GetArgReg(), 0, TARGET_POINTER_SIZE)); varDsc->lvOnFrame = true; // The final home for this incoming register might be our local stack frame varDscInfo->intRegArgNum++; @@ -1549,8 +1456,6 @@ void Compiler::lvaInitGenericsCtxt(InitVarDscInfo* varDscInfo) // We need to mark these as being on the stack, as this is not done elsewhere in the case that canEnreg // returns false. varDsc->lvOnFrame = true; - abiInfo->Segments = new (this, CMK_LvaTable) - ABIPassingSegment(ABIPassingSegment::OnStack(varDscInfo->stackArgSize, 0, TARGET_POINTER_SIZE)); varDsc->SetStackOffset(varDscInfo->stackArgSize); varDscInfo->stackArgSize += TARGET_POINTER_SIZE; } @@ -1582,9 +1487,6 @@ void Compiler::lvaInitVarArgsHandle(InitVarDscInfo* varDscInfo) #endif // TARGET_X86 varDsc->lvHasLdAddrOp = 1; - ABIPassingInformation* abiInfo = varDscInfo->abiInfo; - abiInfo->NumSegments = 1; - lvaSetVarDoNotEnregister(lvaVarargsHandleArg DEBUGARG(DoNotEnregisterReason::VMNeedsStackAddr)); assert(mostRecentlyActivePhase == PHASE_PRE_IMPORT); @@ -1597,8 +1499,6 @@ void Compiler::lvaInitVarArgsHandle(InitVarDscInfo* varDscInfo) varDsc->lvIsRegArg = 1; varDsc->SetArgReg(genMapRegArgNumToRegNum(varArgHndArgNum, TYP_I_IMPL, info.compCallConv)); - abiInfo->Segments = new (this, CMK_LvaTable) - ABIPassingSegment(ABIPassingSegment::InRegister(varDsc->GetArgReg(), 0, TARGET_POINTER_SIZE)); #if FEATURE_MULTIREG_ARGS varDsc->SetOtherArgReg(REG_NA); #endif @@ -1625,8 +1525,6 @@ void Compiler::lvaInitVarArgsHandle(InitVarDscInfo* varDscInfo) // We need to mark these as being on the stack, as this is not done elsewhere in the case that canEnreg // returns false. varDsc->lvOnFrame = true; - abiInfo->Segments = new (this, CMK_LvaTable) - ABIPassingSegment(ABIPassingSegment::OnStack(varDscInfo->stackArgSize, 0, TARGET_POINTER_SIZE)); varDsc->SetStackOffset(varDscInfo->stackArgSize); varDscInfo->stackArgSize += TARGET_POINTER_SIZE; } @@ -1724,6 +1622,93 @@ void Compiler::lvaInitVarDsc(LclVarDsc* varDsc, #endif // FEATURE_MULTIREG_ARGS } +template +void Compiler::lvaClassifyParameterABI(Classifier& classifier) +{ + lvaParameterPassingInfo = new (this, CMK_LvaTable) ABIPassingInformation[info.compArgsCount]; + + for (unsigned i = 0; i < info.compArgsCount; i++) + { + LclVarDsc* dsc = lvaGetDesc(i); + ClassLayout* structLayout = varTypeIsStruct(dsc) ? dsc->GetLayout() : nullptr; + + WellKnownArg wellKnownArg = WellKnownArg::None; + if (i == info.compRetBuffArg) + { + wellKnownArg = WellKnownArg::RetBuffer; + } +#ifdef SWIFT_SUPPORT + else if (i == lvaSwiftSelfArg) + { + wellKnownArg = WellKnownArg::SwiftSelf; + } +#endif + + lvaParameterPassingInfo[i] = classifier.Classify(this, dsc->TypeGet(), structLayout, wellKnownArg); + } +} + +void Compiler::lvaClassifyParameterABI() +{ + if (info.compArgsCount == 0) + { + return; + } + +#if defined(TARGET_X86) + switch (info.compCallConv) + { + case CorInfoCallConvExtension::Thiscall: + { + static const regNumberSmall thiscallRegs[] = {REG_ECX}; + X86Classifier classifier(thiscallRegs, ArrLen(thiscallRegs)); + lvaClassifyParameterABI(classifier); + break; + } + case CorInfoCallConvExtension::C: + case CorInfoCallConvExtension::Stdcall: + case CorInfoCallConvExtension::CMemberFunction: + case CorInfoCallConvExtension::StdcallMemberFunction: + { + X86Classifier classifier(nullptr, 0); + lvaClassifyParameterABI(classifier); + break; + } + default: + { + static const regNumberSmall regs[] = {REG_ECX, REG_EDX}; + unsigned numRegs = ArrLen(regs); + if (info.compIsVarArgs) + { + // In varargs methods we only enregister the this pointer (if there is one). + numRegs = info.compThisArg == BAD_VAR_NUM ? 0 : 1; + } + X86Classifier classifier(regs, numRegs); + lvaClassifyParameterABI(classifier); + break; + } + } +#elif !defined(TARGET_ARM) +#ifdef SWIFT_SUPPORT + if (info.compCallConv == CorInfoCallConvExtension::Swift) + { + SwiftABIClassifier classifier; + lvaClassifyParameterABI(classifier); + } + else +#endif + { + PlatformClassifier classifier; + lvaClassifyParameterABI(classifier); + } +#endif + + if (lvaParameterPassingInfo == nullptr) + { + return; + } +} + /***************************************************************************** * Returns our internal varNum for a given IL variable. * Asserts assume it is called after lvaTable[] has been set up. diff --git a/src/coreclr/jit/registerargconvention.h b/src/coreclr/jit/registerargconvention.h index bddb5ae1477df1..840f7adc4fcebd 100644 --- a/src/coreclr/jit/registerargconvention.h +++ b/src/coreclr/jit/registerargconvention.h @@ -8,9 +8,8 @@ class LclVarDsc; struct InitVarDscInfo { - LclVarDsc* varDsc; - unsigned varNum; - ABIPassingInformation* abiInfo; + LclVarDsc* varDsc; + unsigned varNum; unsigned intRegArgNum; unsigned floatRegArgNum; @@ -35,16 +34,11 @@ struct InitVarDscInfo public: // set to initial values - void Init(LclVarDsc* lvaTable, - ABIPassingInformation* abiInfoTable, - bool _hasRetBufArg, - unsigned _maxIntRegArgNum, - unsigned _maxFloatRegArgNum) + void Init(LclVarDsc* lvaTable, bool _hasRetBufArg, unsigned _maxIntRegArgNum, unsigned _maxFloatRegArgNum) { hasRetBufArg = _hasRetBufArg; varDsc = lvaTable; // the first argument LclVar 0 varNum = 0; // the first argument varNum 0 - this->abiInfo = abiInfoTable; intRegArgNum = 0; floatRegArgNum = 0; maxIntRegArgNum = _maxIntRegArgNum; @@ -117,7 +111,6 @@ struct InitVarDscInfo { varDsc++; varNum++; - abiInfo++; } private: From 150cb283854fb06683a93a86f1182b06007f3e01 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 25 Mar 2024 22:21:23 +0100 Subject: [PATCH 02/52] Refactor, fix arm64 --- src/coreclr/jit/abi.cpp | 77 +++++++++++++++++++++------ src/coreclr/jit/abi.h | 21 +++++--- src/coreclr/jit/compiler.hpp | 4 +- src/coreclr/jit/gentree.cpp | 6 +-- src/coreclr/jit/lclvars.cpp | 100 ++++++++++++++++++++++------------- src/coreclr/jit/target.h | 2 +- 6 files changed, 143 insertions(+), 67 deletions(-) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index dc5f2b9e43d10a..c3949071c4ecc5 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -152,6 +152,39 @@ static unsigned TypeSize(var_types type, ClassLayout* structLayout) } #ifdef TARGET_X86 +X86Classifier::X86Classifier(const ClassifierInfo& info) + : m_regs(nullptr, 0) +{ + switch (info.CallConv) + { + case CorInfoCallConvExtension::Thiscall: + { + static const regNumberSmall thiscallRegs[] = {REG_ECX}; + m_regs = RegisterQueue(thiscallRegs, ArrLen(thiscallRegs)); + break; + } + case CorInfoCallConvExtension::C: + case CorInfoCallConvExtension::Stdcall: + case CorInfoCallConvExtension::CMemberFunction: + case CorInfoCallConvExtension::StdcallMemberFunction: + { + break; + } + default: + { + static const regNumberSmall regs[] = {REG_ECX, REG_EDX}; + unsigned numRegs = ArrLen(regs); + if (info.IsVarArgs) + { + // In varargs methods we only enregister the this pointer (if there is one). + numRegs = info.HasThis ? 1 : 0; + } + m_regs = RegisterQueue(regs, numRegs); + break; + } + } +} + ABIPassingInformation X86Classifier::Classify(Compiler* comp, var_types type, ClassLayout* structLayout, @@ -202,7 +235,7 @@ ABIPassingInformation X86Classifier::Classify(Compiler* comp, static const regNumberSmall WinX64IntArgRegs[] = {REG_RCX, REG_RDX, REG_R8, REG_R9}; static const regNumberSmall WinX64FloatArgRegs[] = {REG_XMM0, REG_XMM1, REG_XMM2, REG_XMM3}; -WinX64Classifier::WinX64Classifier() +WinX64Classifier::WinX64Classifier(const ClassifierInfo& info) : m_intRegs(WinX64IntArgRegs, ArrLen(WinX64IntArgRegs)), m_floatRegs(WinX64FloatArgRegs, ArrLen(WinX64FloatArgRegs)) { } @@ -247,7 +280,7 @@ static const regNumberSmall SysVX64IntArgRegs[] = {REG_EDI, REG_ESI, REG_EDX, static const regNumberSmall SysVX64FloatArgRegs[] = {REG_XMM0, REG_XMM1, REG_XMM2, REG_XMM3, REG_XMM4, REG_XMM5, REG_XMM6, REG_XMM7}; -SysVX64Classifier::SysVX64Classifier() +SysVX64Classifier::SysVX64Classifier(const ClassifierInfo& info) : m_intRegs(SysVX64IntArgRegs, ArrLen(SysVX64IntArgRegs)) , m_floatRegs(SysVX64FloatArgRegs, ArrLen(SysVX64FloatArgRegs)) { @@ -332,8 +365,10 @@ ABIPassingInformation SysVX64Classifier::Classify(Compiler* comp, static const regNumberSmall Arm64IntArgRegs[] = {REG_R0, REG_R1, REG_R2, REG_R3, REG_R4, REG_R5, REG_R6, REG_R7}; static const regNumberSmall Arm64FloatArgRegs[] = {REG_V0, REG_V1, REG_V2, REG_V3, REG_V4, REG_V5, REG_V6, REG_V7}; -Arm64Classifier::Arm64Classifier() - : m_intRegs(Arm64IntArgRegs, ArrLen(Arm64IntArgRegs)), m_floatRegs(Arm64FloatArgRegs, ArrLen(Arm64FloatArgRegs)) +Arm64Classifier::Arm64Classifier(const ClassifierInfo& info) + : m_info(info) + , m_intRegs(Arm64IntArgRegs, ArrLen(Arm64IntArgRegs)) + , m_floatRegs(Arm64FloatArgRegs, ArrLen(Arm64FloatArgRegs)) { } @@ -342,13 +377,13 @@ ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, ClassLayout* structLayout, WellKnownArg wellKnownParam) { - if (wellKnownParam == WellKnownArg::RetBuffer) + if ((wellKnownParam == WellKnownArg::RetBuffer) && hasFixedRetBuffReg(m_info.CallConv)) { return ABIPassingInformation::FromSegment(comp, ABIPassingSegment::InRegister(REG_ARG_RET_BUFF, 0, TARGET_POINTER_SIZE)); } - if (varTypeIsStruct(type) && !comp->info.compIsVarArgs) + if (varTypeIsStruct(type) && !m_info.IsVarArgs) { var_types hfaType = comp->GetHfaType(structLayout->GetClassHandle()); @@ -373,7 +408,7 @@ ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, m_stackArgSize = roundUp(m_stackArgSize, alignment); info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::OnStack(m_stackArgSize, 0, structLayout->GetSize())); - m_stackArgSize += structLayout->GetSize(); + m_stackArgSize += roundUp(structLayout->GetSize(), TARGET_POINTER_SIZE); // After passing any float value on the stack, we should not enregister more float values. m_floatRegs.Clear(); } @@ -383,28 +418,32 @@ ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, } unsigned slots; + unsigned passedSize; if (varTypeIsStruct(type)) { unsigned size = structLayout->GetSize(); if (size > 16) { slots = 1; // Passed by implicit byref + passedSize = TARGET_POINTER_SIZE; } else { slots = (size + TARGET_POINTER_SIZE - 1) / TARGET_POINTER_SIZE; + passedSize = size; } } else { assert(genTypeSize(type) <= TARGET_POINTER_SIZE); slots = 1; + passedSize = genTypeSize(type); } assert((slots == 1) || (slots == 2)); ABIPassingInformation info; - if (comp->info.compIsVarArgs && (slots == 2) && (m_intRegs.Count() == 1)) + if (m_info.IsVarArgs && (slots == 2) && (m_intRegs.Count() == 1)) { // On varargs we split structs between register and stack in this case. // Normally a struct that does not fit in registers will always be @@ -419,19 +458,26 @@ ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, } else { - RegisterQueue& regs = varTypeUsesFloatArgReg(type) ? m_floatRegs : m_intRegs; + RegisterQueue* regs = &m_intRegs; + + // In varargs methods (only supported on Windows) all arguments go in + // integer registers. + if (varTypeUsesFloatArgReg(type) && !m_info.IsVarArgs) + { + regs = &m_floatRegs; + } - if (regs.Count() >= slots) + if (regs->Count() >= slots) { info.NumSegments = slots; info.Segments = new (comp, CMK_ABI) ABIPassingSegment[slots]; unsigned slotSize = varTypeIsStruct(type) ? TARGET_POINTER_SIZE : genTypeSize(type); - info.Segments[0] = ABIPassingSegment::InRegister(regs.Dequeue(), 0, slotSize); + info.Segments[0] = ABIPassingSegment::InRegister(regs->Dequeue(), 0, slotSize); if (slots == 2) { assert(varTypeIsStruct(type)); unsigned tailSize = structLayout->GetSize() - slotSize; - info.Segments[1] = ABIPassingSegment::InRegister(regs.Dequeue(), slotSize, tailSize); + info.Segments[1] = ABIPassingSegment::InRegister(regs->Dequeue(), slotSize, tailSize); } } else @@ -456,14 +502,13 @@ ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, assert((m_stackArgSize % TARGET_POINTER_SIZE) == 0); } - unsigned size = TypeSize(type, structLayout); - info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::OnStack(m_stackArgSize, 0, size)); + info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::OnStack(m_stackArgSize, 0, passedSize)); - m_stackArgSize += roundUp(size, alignment); + m_stackArgSize += roundUp(passedSize, alignment); // As soon as we pass something on stack we cannot go back and // enregister something else. - regs.Clear(); + regs->Clear(); } } diff --git a/src/coreclr/jit/abi.h b/src/coreclr/jit/abi.h index 9bfa0b94863116..200eb9c6c1a207 100644 --- a/src/coreclr/jit/abi.h +++ b/src/coreclr/jit/abi.h @@ -73,15 +73,20 @@ class RegisterQueue void Clear(); }; +struct ClassifierInfo +{ + CorInfoCallConvExtension CallConv; + bool IsVarArgs; + bool HasThis; +}; + class X86Classifier { RegisterQueue m_regs; unsigned m_stackArgSize = 0; public: - X86Classifier(const regNumberSmall* regs, unsigned int numRegs) : m_regs(regs, numRegs) - { - } + X86Classifier(const ClassifierInfo& info); ABIPassingInformation Classify(Compiler* comp, var_types type, @@ -96,7 +101,7 @@ class WinX64Classifier unsigned m_stackArgSize = 0; public: - WinX64Classifier(); + WinX64Classifier(const ClassifierInfo& info); ABIPassingInformation Classify(Compiler* comp, var_types type, @@ -111,7 +116,7 @@ class SysVX64Classifier unsigned m_stackArgSize = 0; public: - SysVX64Classifier(); + SysVX64Classifier(const ClassifierInfo& info); ABIPassingInformation Classify(Compiler* comp, var_types type, @@ -121,12 +126,13 @@ class SysVX64Classifier class Arm64Classifier { + const ClassifierInfo& m_info; RegisterQueue m_intRegs; RegisterQueue m_floatRegs; unsigned m_stackArgSize = 0; public: - Arm64Classifier(); + Arm64Classifier(const ClassifierInfo& info); ABIPassingInformation Classify(Compiler* comp, var_types type, @@ -150,7 +156,8 @@ class SwiftABIClassifier PlatformClassifier m_classifier; public: - SwiftABIClassifier() + SwiftABIClassifier(const ClassifierInfo& info) + : m_classifier(info) { } diff --git a/src/coreclr/jit/compiler.hpp b/src/coreclr/jit/compiler.hpp index 432a435c98919d..b6ba06ba7a1986 100644 --- a/src/coreclr/jit/compiler.hpp +++ b/src/coreclr/jit/compiler.hpp @@ -2817,8 +2817,8 @@ inline var_types Compiler::mangleVarArgsType(var_types type) if (varTypeIsSIMD(type)) { - // Vectors also get passed in int registers. Use TYP_INT. - return TYP_INT; + // Vectors should be considered like passing a struct + return TYP_STRUCT; } } #endif // defined(TARGET_ARMARCH) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index a8374adbe0a22c..c6d87d6141a747 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -1810,11 +1810,7 @@ regNumber CallArgs::GetCustomRegister(Compiler* comp, CorInfoCallConvExtension c case WellKnownArg::RetBuffer: if (hasFixedRetBuffReg(cc)) { - // Windows does not use fixed ret buff arg for instance calls, but does otherwise. - if (!TargetOS::IsWindows || !callConvIsInstanceMethodCallConv(cc)) - { - return theFixedRetBuffReg(cc); - } + return theFixedRetBuffReg(cc); } break; diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 2503642a42c44d..41607909e79398 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -521,6 +521,16 @@ void Compiler::lvaInitThisPtr(InitVarDscInfo* varDscInfo) lvaSetClass(varDscInfo->varNum, info.compClassHnd); } + varDsc->lvIsRegArg = 1; + noway_assert(varDscInfo->intRegArgNum == 0); + + varDsc->SetArgReg( + genMapRegArgNumToRegNum(varDscInfo->allocRegArg(TYP_INT), varDsc->TypeGet(), info.compCallConv)); +#if FEATURE_MULTIREG_ARGS + varDsc->SetOtherArgReg(REG_NA); +#endif + varDsc->lvOnFrame = true; // The final home for this incoming register might be our local stack frame + #ifdef DEBUG if (verbose) { @@ -733,6 +743,7 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo, unsigned skipArgs, un !varDscInfo->canEnreg(TYP_INT, cSlots)) // The end of the struct can't fit in a register { cSlotsToEnregister = 1; // Force the split + varDscInfo->stackArgSize += TARGET_POINTER_SIZE; } } } @@ -1655,50 +1666,22 @@ void Compiler::lvaClassifyParameterABI() return; } -#if defined(TARGET_X86) - switch (info.compCallConv) - { - case CorInfoCallConvExtension::Thiscall: - { - static const regNumberSmall thiscallRegs[] = {REG_ECX}; - X86Classifier classifier(thiscallRegs, ArrLen(thiscallRegs)); - lvaClassifyParameterABI(classifier); - break; - } - case CorInfoCallConvExtension::C: - case CorInfoCallConvExtension::Stdcall: - case CorInfoCallConvExtension::CMemberFunction: - case CorInfoCallConvExtension::StdcallMemberFunction: - { - X86Classifier classifier(nullptr, 0); - lvaClassifyParameterABI(classifier); - break; - } - default: - { - static const regNumberSmall regs[] = {REG_ECX, REG_EDX}; - unsigned numRegs = ArrLen(regs); - if (info.compIsVarArgs) - { - // In varargs methods we only enregister the this pointer (if there is one). - numRegs = info.compThisArg == BAD_VAR_NUM ? 0 : 1; - } - X86Classifier classifier(regs, numRegs); - lvaClassifyParameterABI(classifier); - break; - } - } -#elif !defined(TARGET_ARM) + ClassifierInfo cInfo; + cInfo.CallConv = info.compCallConv; + cInfo.IsVarArgs = info.compIsVarArgs; + cInfo.HasThis = info.compThisArg != BAD_VAR_NUM; + #ifdef SWIFT_SUPPORT if (info.compCallConv == CorInfoCallConvExtension::Swift) { - SwiftABIClassifier classifier; + SwiftABIClassifier classifier(cInfo); lvaClassifyParameterABI(classifier); } else #endif +#ifndef TARGET_ARM { - PlatformClassifier classifier; + PlatformClassifier classifier(cInfo); lvaClassifyParameterABI(classifier); } #endif @@ -1707,6 +1690,51 @@ void Compiler::lvaClassifyParameterABI() { return; } + + for (unsigned lclNum = 0; lclNum < info.compArgsCount; lclNum++) + { + LclVarDsc* dsc = lvaGetDesc(lclNum); + const ABIPassingInformation& abiInfo = lvaParameterPassingInfo[lclNum]; + + assert(abiInfo.NumSegments > 0); + + unsigned numSegmentsToCompare = abiInfo.NumSegments; + if (dsc->lvIsHfa()) + { + assert(abiInfo.NumSegments >= 1); + // LclVarDsc only has one register set for HFAs + numSegmentsToCompare = 1; + } + + for (unsigned i = 0; i < numSegmentsToCompare; i++) + { + const ABIPassingSegment& expected = abiInfo.Segments[i]; + regNumber reg = REG_NA; + if (i == 0) + { + reg = dsc->GetArgReg(); + } +#if FEATURE_MULTIREG_ARGS + else if (i == 1) + { + reg = dsc->GetOtherArgReg(); + } +#endif + + if (expected.IsPassedOnStack()) + { + if (i == 0) + { + assert(reg == REG_STK); + assert((unsigned)dsc->GetStackOffset() == expected.GetStackOffset()); + } + } + else + { + assert(reg == expected.GetRegister()); + } + } + } } /***************************************************************************** diff --git a/src/coreclr/jit/target.h b/src/coreclr/jit/target.h index 94a4810c561238..38fa7add49dfae 100644 --- a/src/coreclr/jit/target.h +++ b/src/coreclr/jit/target.h @@ -422,7 +422,7 @@ inline bool genIsValidDoubleReg(regNumber reg) inline bool hasFixedRetBuffReg(CorInfoCallConvExtension callConv) { #if defined(TARGET_ARM64) - return true; + return !TargetOS::IsWindows || !callConvIsInstanceMethodCallConv(callConv); #elif defined(TARGET_AMD64) && defined(SWIFT_SUPPORT) return callConv == CorInfoCallConvExtension::Swift; #else From af2fc728c62613de9287a28766c4b11b7c729d8e Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 25 Mar 2024 22:22:31 +0100 Subject: [PATCH 03/52] Run jit-format --- src/coreclr/jit/abi.cpp | 11 +++++------ src/coreclr/jit/abi.h | 13 ++++++------- src/coreclr/jit/lclvars.cpp | 8 ++++---- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index c3949071c4ecc5..447b0e6f3bc8b1 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -152,15 +152,14 @@ static unsigned TypeSize(var_types type, ClassLayout* structLayout) } #ifdef TARGET_X86 -X86Classifier::X86Classifier(const ClassifierInfo& info) - : m_regs(nullptr, 0) +X86Classifier::X86Classifier(const ClassifierInfo& info) : m_regs(nullptr, 0) { switch (info.CallConv) { case CorInfoCallConvExtension::Thiscall: { static const regNumberSmall thiscallRegs[] = {REG_ECX}; - m_regs = RegisterQueue(thiscallRegs, ArrLen(thiscallRegs)); + m_regs = RegisterQueue(thiscallRegs, ArrLen(thiscallRegs)); break; } case CorInfoCallConvExtension::C: @@ -424,19 +423,19 @@ ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, unsigned size = structLayout->GetSize(); if (size > 16) { - slots = 1; // Passed by implicit byref + slots = 1; // Passed by implicit byref passedSize = TARGET_POINTER_SIZE; } else { - slots = (size + TARGET_POINTER_SIZE - 1) / TARGET_POINTER_SIZE; + slots = (size + TARGET_POINTER_SIZE - 1) / TARGET_POINTER_SIZE; passedSize = size; } } else { assert(genTypeSize(type) <= TARGET_POINTER_SIZE); - slots = 1; + slots = 1; passedSize = genTypeSize(type); } diff --git a/src/coreclr/jit/abi.h b/src/coreclr/jit/abi.h index 200eb9c6c1a207..ef5e966f66fbbc 100644 --- a/src/coreclr/jit/abi.h +++ b/src/coreclr/jit/abi.h @@ -76,8 +76,8 @@ class RegisterQueue struct ClassifierInfo { CorInfoCallConvExtension CallConv; - bool IsVarArgs; - bool HasThis; + bool IsVarArgs; + bool HasThis; }; class X86Classifier @@ -127,9 +127,9 @@ class SysVX64Classifier class Arm64Classifier { const ClassifierInfo& m_info; - RegisterQueue m_intRegs; - RegisterQueue m_floatRegs; - unsigned m_stackArgSize = 0; + RegisterQueue m_intRegs; + RegisterQueue m_floatRegs; + unsigned m_stackArgSize = 0; public: Arm64Classifier(const ClassifierInfo& info); @@ -156,8 +156,7 @@ class SwiftABIClassifier PlatformClassifier m_classifier; public: - SwiftABIClassifier(const ClassifierInfo& info) - : m_classifier(info) + SwiftABIClassifier(const ClassifierInfo& info) : m_classifier(info) { } diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 41607909e79398..8dec5bbcb2b303 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1667,9 +1667,9 @@ void Compiler::lvaClassifyParameterABI() } ClassifierInfo cInfo; - cInfo.CallConv = info.compCallConv; + cInfo.CallConv = info.compCallConv; cInfo.IsVarArgs = info.compIsVarArgs; - cInfo.HasThis = info.compThisArg != BAD_VAR_NUM; + cInfo.HasThis = info.compThisArg != BAD_VAR_NUM; #ifdef SWIFT_SUPPORT if (info.compCallConv == CorInfoCallConvExtension::Swift) @@ -1693,7 +1693,7 @@ void Compiler::lvaClassifyParameterABI() for (unsigned lclNum = 0; lclNum < info.compArgsCount; lclNum++) { - LclVarDsc* dsc = lvaGetDesc(lclNum); + LclVarDsc* dsc = lvaGetDesc(lclNum); const ABIPassingInformation& abiInfo = lvaParameterPassingInfo[lclNum]; assert(abiInfo.NumSegments > 0); @@ -1709,7 +1709,7 @@ void Compiler::lvaClassifyParameterABI() for (unsigned i = 0; i < numSegmentsToCompare; i++) { const ABIPassingSegment& expected = abiInfo.Segments[i]; - regNumber reg = REG_NA; + regNumber reg = REG_NA; if (i == 0) { reg = dsc->GetArgReg(); From 1d09c9f5985050902c0a19fcb1a782fc1df084c3 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 09:53:51 +0100 Subject: [PATCH 04/52] Comments --- src/coreclr/jit/abi.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index 447b0e6f3bc8b1..b54f139853154d 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -382,6 +382,8 @@ ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, TARGET_POINTER_SIZE)); } + // First handle HFA/HVAs. These are allowed to be passed in more registers + // than other structures. if (varTypeIsStruct(type) && !m_info.IsVarArgs) { var_types hfaType = comp->GetHfaType(structLayout->GetClassHandle()); @@ -444,9 +446,9 @@ ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, ABIPassingInformation info; if (m_info.IsVarArgs && (slots == 2) && (m_intRegs.Count() == 1)) { - // On varargs we split structs between register and stack in this case. - // Normally a struct that does not fit in registers will always be - // passed on stack. + // For varargs we split structs between register and stack in this + // case. Normally a struct that does not fit in registers will always + // be passed on stack. assert(compFeatureArgSplit()); info.NumSegments = 2; info.Segments = new (comp, CMK_ABI) ABIPassingSegment[2]; @@ -459,7 +461,7 @@ ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, { RegisterQueue* regs = &m_intRegs; - // In varargs methods (only supported on Windows) all arguments go in + // In varargs methods (only supported on Windows) all parameters go in // integer registers. if (varTypeUsesFloatArgReg(type) && !m_info.IsVarArgs) { From dcccedd293dcf93f889ad597ea7cc1030bf98aa4 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 11:55:38 +0100 Subject: [PATCH 05/52] Fix varargs retbuf case --- src/coreclr/jit/abi.cpp | 4 ++-- src/coreclr/jit/abi.h | 1 + src/coreclr/jit/lclvars.cpp | 14 +++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index b54f139853154d..598dd55c04859a 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -175,8 +175,8 @@ X86Classifier::X86Classifier(const ClassifierInfo& info) : m_regs(nullptr, 0) unsigned numRegs = ArrLen(regs); if (info.IsVarArgs) { - // In varargs methods we only enregister the this pointer (if there is one). - numRegs = info.HasThis ? 1 : 0; + // In varargs methods we only enregister the this pointer or retbuff. + numRegs = info.HasThis || info.HasRetBuff ? 1 : 0; } m_regs = RegisterQueue(regs, numRegs); break; diff --git a/src/coreclr/jit/abi.h b/src/coreclr/jit/abi.h index ef5e966f66fbbc..c7027057ea2444 100644 --- a/src/coreclr/jit/abi.h +++ b/src/coreclr/jit/abi.h @@ -78,6 +78,7 @@ struct ClassifierInfo CorInfoCallConvExtension CallConv; bool IsVarArgs; bool HasThis; + bool HasRetBuff; }; class X86Classifier diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 8dec5bbcb2b303..38d760eb05d886 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1667,9 +1667,10 @@ void Compiler::lvaClassifyParameterABI() } ClassifierInfo cInfo; - cInfo.CallConv = info.compCallConv; - cInfo.IsVarArgs = info.compIsVarArgs; - cInfo.HasThis = info.compThisArg != BAD_VAR_NUM; + cInfo.CallConv = info.compCallConv; + cInfo.IsVarArgs = info.compIsVarArgs; + cInfo.HasThis = info.compThisArg != BAD_VAR_NUM; + cInfo.HasRetBuff = info.compRetBuffArg != BAD_VAR_NUM; #ifdef SWIFT_SUPPORT if (info.compCallConv == CorInfoCallConvExtension::Swift) @@ -1726,7 +1727,14 @@ void Compiler::lvaClassifyParameterABI() if (i == 0) { assert(reg == REG_STK); + +// On x86, varargs methods access stack args off of a base pointer, and the +// first stack arg is not considered to be at offset 0. +// TODO-Cleanup: Unify things so that x86 is consistent with other platforms +// here and change fgMorphExpandStackArgForVarArgs to account for that. +#ifndef TARGET_X86 assert((unsigned)dsc->GetStackOffset() == expected.GetStackOffset()); +#endif } } else From 7fe878bf47d1e100f936de52d8cc50d1bd20df25 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 12:18:57 +0100 Subject: [PATCH 06/52] Fix SysV --- src/coreclr/jit/abi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index 598dd55c04859a..38e6ca70e5d12e 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -318,7 +318,7 @@ ABIPassingInformation SysVX64Classifier::Classify(Compiler* comp, } } - canEnreg = (m_intRegs.Count() <= intRegCount) && (m_floatRegs.Count() <= floatRegCount); + canEnreg = (intRegCount <= m_intRegs.Count()) && (floatRegCount <= m_floatRegs.Count()); } } else From 9297865298c4af7a242c9e3136a8dc442f8b2517 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 12:33:21 +0100 Subject: [PATCH 07/52] Add function headers --- src/coreclr/jit/abi.cpp | 139 +++++++++++++++++++++++++++++++++++- src/coreclr/jit/abi.h | 8 +-- src/coreclr/jit/lclvars.cpp | 16 +++++ 3 files changed, 158 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index 38e6ca70e5d12e..fc552e10d66e0c 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -121,6 +121,17 @@ bool ABIPassingInformation::IsSplitAcrossRegistersAndStack() const return anyReg && anyStack; } +//----------------------------------------------------------------------------- +// FromSegment: +// Create ABIPassingInformation from a single segment. +// +// Parameters: +// comp - Compiler instance +// segment - The single segment that represents the passing information +// +// Return Value: +// An instance of ABIPassingInformation. +// ABIPassingInformation ABIPassingInformation::FromSegment(Compiler* comp, const ABIPassingSegment& segment) { ABIPassingInformation info; @@ -129,29 +140,65 @@ ABIPassingInformation ABIPassingInformation::FromSegment(Compiler* comp, const A return info; } +//----------------------------------------------------------------------------- +// RegisterQueue::Dequeue: +// Dequeue a register from the queue. +// +// Return Value: +// The dequeued register. +// regNumber RegisterQueue::Dequeue() { assert(Count() > 0); return static_cast(m_regs[m_index++]); } +//----------------------------------------------------------------------------- +// RegisterQueue::Peek: +// Peek at the head of the queue. +// +// Return Value: +// The head register in the queue. +// regNumber RegisterQueue::Peek() { assert(Count() > 0); return static_cast(m_regs[m_index]); } +//----------------------------------------------------------------------------- +// RegisterQueue::Clear: +// Clear the register queue. +// void RegisterQueue::Clear() { m_index = m_numRegs; } +//----------------------------------------------------------------------------- +// TypeSize: +// Get the size of a JIT type or struct. +// +// Parameters: +// type - The type +// structLayout - The layout to get the size if type is TYP_STRUCT +// +// Returns: +// The type size. +// static unsigned TypeSize(var_types type, ClassLayout* structLayout) { return type == TYP_STRUCT ? structLayout->GetSize() : genTypeSize(type); } #ifdef TARGET_X86 +//----------------------------------------------------------------------------- +// X86Classifier: +// Construct a new instance of the x86 ABI classifier. +// +// Parameters: +// info - Info about the method being classified. +// X86Classifier::X86Classifier(const ClassifierInfo& info) : m_regs(nullptr, 0) { switch (info.CallConv) @@ -184,6 +231,20 @@ X86Classifier::X86Classifier(const ClassifierInfo& info) : m_regs(nullptr, 0) } } +//----------------------------------------------------------------------------- +// Classify: +// Classify a parameter for the x86 ABI. +// +// Parameters: +// comp - Compiler instance +// type - The type of the parameter +// structLayout - The layout of the struct. Expected to be non-null if +// varTypeIsStruct(type) is true. +// wellKnownParam - Well known type of the parameter (if it may affect its ABI classification) +// +// Returns: +// Classification information for the parameter. +// ABIPassingInformation X86Classifier::Classify(Compiler* comp, var_types type, ClassLayout* structLayout, @@ -234,11 +295,32 @@ ABIPassingInformation X86Classifier::Classify(Compiler* comp, static const regNumberSmall WinX64IntArgRegs[] = {REG_RCX, REG_RDX, REG_R8, REG_R9}; static const regNumberSmall WinX64FloatArgRegs[] = {REG_XMM0, REG_XMM1, REG_XMM2, REG_XMM3}; +//----------------------------------------------------------------------------- +// WinX64Classifier: +// Construct a new instance of the Windows x64 ABI classifier. +// +// Parameters: +// info - Info about the method being classified. +// WinX64Classifier::WinX64Classifier(const ClassifierInfo& info) : m_intRegs(WinX64IntArgRegs, ArrLen(WinX64IntArgRegs)), m_floatRegs(WinX64FloatArgRegs, ArrLen(WinX64FloatArgRegs)) { } +//----------------------------------------------------------------------------- +// Classify: +// Classify a parameter for the Windows x64 ABI. +// +// Parameters: +// comp - Compiler instance +// type - The type of the parameter +// structLayout - The layout of the struct. Expected to be non-null if +// varTypeIsStruct(type) is true. +// wellKnownParam - Well known type of the parameter (if it may affect its ABI classification) +// +// Returns: +// Classification information for the parameter. +// ABIPassingInformation WinX64Classifier::Classify(Compiler* comp, var_types type, ClassLayout* structLayout, @@ -278,13 +360,33 @@ ABIPassingInformation WinX64Classifier::Classify(Compiler* comp, static const regNumberSmall SysVX64IntArgRegs[] = {REG_EDI, REG_ESI, REG_EDX, REG_ECX, REG_R8, REG_R9}; static const regNumberSmall SysVX64FloatArgRegs[] = {REG_XMM0, REG_XMM1, REG_XMM2, REG_XMM3, REG_XMM4, REG_XMM5, REG_XMM6, REG_XMM7}; - +//----------------------------------------------------------------------------- +// SysVX64Classifier: +// Construct a new instance of the SysV x64 ABI classifier. +// +// Parameters: +// info - Info about the method being classified. +// SysVX64Classifier::SysVX64Classifier(const ClassifierInfo& info) : m_intRegs(SysVX64IntArgRegs, ArrLen(SysVX64IntArgRegs)) , m_floatRegs(SysVX64FloatArgRegs, ArrLen(SysVX64FloatArgRegs)) { } +//----------------------------------------------------------------------------- +// Classify: +// Classify a parameter for the SysV x64 ABI. +// +// Parameters: +// comp - Compiler instance +// type - The type of the parameter +// structLayout - The layout of the struct. Expected to be non-null if +// varTypeIsStruct(type) is true. +// wellKnownParam - Well known type of the parameter (if it may affect its ABI classification) +// +// Returns: +// Classification information for the parameter. +// ABIPassingInformation SysVX64Classifier::Classify(Compiler* comp, var_types type, ClassLayout* structLayout, @@ -364,6 +466,13 @@ ABIPassingInformation SysVX64Classifier::Classify(Compiler* comp, static const regNumberSmall Arm64IntArgRegs[] = {REG_R0, REG_R1, REG_R2, REG_R3, REG_R4, REG_R5, REG_R6, REG_R7}; static const regNumberSmall Arm64FloatArgRegs[] = {REG_V0, REG_V1, REG_V2, REG_V3, REG_V4, REG_V5, REG_V6, REG_V7}; +//----------------------------------------------------------------------------- +// Arm64Classifier: +// Construct a new instance of the ARM64 ABI classifier. +// +// Parameters: +// info - Info about the method being classified. +// Arm64Classifier::Arm64Classifier(const ClassifierInfo& info) : m_info(info) , m_intRegs(Arm64IntArgRegs, ArrLen(Arm64IntArgRegs)) @@ -371,6 +480,20 @@ Arm64Classifier::Arm64Classifier(const ClassifierInfo& info) { } +//----------------------------------------------------------------------------- +// Classify: +// Classify a parameter for the ARM64 ABI. +// +// Parameters: +// comp - Compiler instance +// type - The type of the parameter +// structLayout - The layout of the struct. Expected to be non-null if +// varTypeIsStruct(type) is true. +// wellKnownParam - Well known type of the parameter (if it may affect its ABI classification) +// +// Returns: +// Classification information for the parameter. +// ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, var_types type, ClassLayout* structLayout, @@ -518,6 +641,20 @@ ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, #endif #ifdef SWIFT_SUPPORT +//----------------------------------------------------------------------------- +// Classify: +// Classify a parameter for the Swift ABI. +// +// Parameters: +// comp - Compiler instance +// type - The type of the parameter +// structLayout - The layout of the struct. Expected to be non-null if +// varTypeIsStruct(type) is true. +// wellKnownParam - Well known type of the parameter (if it may affect its ABI classification) +// +// Returns: +// Classification information for the parameter. +// ABIPassingInformation SwiftABIClassifier::Classify(Compiler* comp, var_types type, ClassLayout* structLayout, diff --git a/src/coreclr/jit/abi.h b/src/coreclr/jit/abi.h index c7027057ea2444..bfc76236501a9c 100644 --- a/src/coreclr/jit/abi.h +++ b/src/coreclr/jit/abi.h @@ -75,10 +75,10 @@ class RegisterQueue struct ClassifierInfo { - CorInfoCallConvExtension CallConv; - bool IsVarArgs; - bool HasThis; - bool HasRetBuff; + CorInfoCallConvExtension CallConv = CorInfoCallConvExtension::Managed; + bool IsVarArgs = false; + bool HasThis = false; + bool HasRetBuff = false; }; class X86Classifier diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 38d760eb05d886..63e94b11280fcb 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1633,6 +1633,16 @@ void Compiler::lvaInitVarDsc(LclVarDsc* varDsc, #endif // FEATURE_MULTIREG_ARGS } +//----------------------------------------------------------------------------- +// lvaClassifyParameterABI: +// Classify the ABI information for all parameters. +// +// Type parameters: +// Classifier - The type of classifier to use. +// +// Parameters: +// classifier - The classifier to use +// template void Compiler::lvaClassifyParameterABI(Classifier& classifier) { @@ -1659,6 +1669,10 @@ void Compiler::lvaClassifyParameterABI(Classifier& classifier) } } +//----------------------------------------------------------------------------- +// lvaClassifyParameterABI: +// Classify the ABI information for all parameters. +// void Compiler::lvaClassifyParameterABI() { if (info.compArgsCount == 0) @@ -1687,6 +1701,7 @@ void Compiler::lvaClassifyParameterABI() } #endif +#ifdef DEBUG if (lvaParameterPassingInfo == nullptr) { return; @@ -1743,6 +1758,7 @@ void Compiler::lvaClassifyParameterABI() } } } +#endif } /***************************************************************************** From 25e2c49282cbd6bcd26d26aa9d2e74930817b88d Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 12:35:15 +0100 Subject: [PATCH 08/52] Nit --- src/coreclr/jit/abi.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index fc552e10d66e0c..f553968c699fad 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -269,6 +269,7 @@ ABIPassingInformation X86Classifier::Classify(Compiler* comp, break; case TYP_STRUCT: canEnreg = comp->isTrivialPointerSizedStruct(structLayout->GetClassHandle()); + break; default: break; } From 99540622675f177083a0a358740ddb20df1db347 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 12:40:38 +0100 Subject: [PATCH 09/52] Fix macOS arm64 ABI bug --- src/coreclr/jit/abi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index f553968c699fad..fcf01d132bd3ff 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -533,7 +533,7 @@ ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, m_stackArgSize = roundUp(m_stackArgSize, alignment); info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::OnStack(m_stackArgSize, 0, structLayout->GetSize())); - m_stackArgSize += roundUp(structLayout->GetSize(), TARGET_POINTER_SIZE); + m_stackArgSize += roundUp(structLayout->GetSize(), alignment); // After passing any float value on the stack, we should not enregister more float values. m_floatRegs.Clear(); } From 5fab654d85e8e7eac5bf2b22a41da2be9e00117b Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 12:54:00 +0100 Subject: [PATCH 10/52] Preemptively fix build --- src/coreclr/jit/lclvars.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 63e94b11280fcb..9d96d8643ce0cb 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1694,7 +1694,7 @@ void Compiler::lvaClassifyParameterABI() } else #endif -#ifndef TARGET_ARM +#if defined(TARGET_X86) || defined(TARGET_AMD64) || defined(TARGET_ARM64) { PlatformClassifier classifier(cInfo); lvaClassifyParameterABI(classifier); From 3f1c738a8709193e1eb0a19fa047442588097def Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 12:56:42 +0100 Subject: [PATCH 11/52] More build fixes --- src/coreclr/jit/lclvars.cpp | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 9d96d8643ce0cb..8e85840909c95f 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1083,15 +1083,6 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo, unsigned skipArgs, un varDsc->SetOtherArgReg( genMapRegArgNumToRegNum(secondAllocatedRegArgNum, argRegTypeInStruct2, info.compCallConv)); varDsc->lvIs4Field2 = (genTypeSize(argRegTypeInStruct2) == 4) ? 1 : 0; - - abiInfo->NumSegments = 2; - abiInfo->Segments = new (this, CMK_LvaTable) ABIPassingSegment[2]; - abiInfo->Segments[0] = - ABIPassingSegment::InRegister(varDsc->GetArgReg(), 0, genTypeSize(argRegTypeInStruct1)); - abiInfo->Segments[1] = ABIPassingSegment::InRegister(varDsc->GetOtherArgReg(), - roundUp(genTypeSize(argRegTypeInStruct1), - genTypeSize(argRegTypeInStruct2)), - genTypeSize(argRegTypeInStruct2)); } else if (cSlots > 1) { @@ -1116,14 +1107,6 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo, unsigned skipArgs, un } assert(cSlots <= 2); - abiInfo->NumSegments = cSlots; - abiInfo->Segments = new (this, CMK_LvaTable) ABIPassingSegment[cSlots]; - for (unsigned i = 0; i < cSlots; i++) - { - regNumber reg = i == 0 ? varDsc->GetArgReg() : varDsc->GetOtherArgReg(); - abiInfo->Segments[i] = - ABIPassingSegment::InRegister(reg, TARGET_POINTER_SIZE * i, argRegTypeInStruct1); - } } } #else // ARM32 From b8d9334c43eab7355600969f1c66d70846a40ae5 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 13:21:53 +0100 Subject: [PATCH 12/52] Further fix build --- src/coreclr/jit/lclvars.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 8e85840909c95f..978fff461e146a 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -243,8 +243,6 @@ void Compiler::lvaInitTypeRef() new (&lvaTable[i], jitstd::placement_t()) LclVarDsc(); // call the constructor. } - lvaParameterPassingInfo = new (this, CMK_LvaTable) ABIPassingInformation[max(info.compArgsCount, 1)]{}; - //------------------------------------------------------------------------- // Count the arguments and initialize the respective lvaTable[] entries // From f12a9d74e55fbabf39c8ee07fa389cb5bd27f4ca Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 13:27:42 +0100 Subject: [PATCH 13/52] Move classifiers into target specific files --- src/coreclr/jit/abi.cpp | 466 -------------------------------- src/coreclr/jit/abi.h | 8 +- src/coreclr/jit/targetamd64.cpp | 164 +++++++++++ src/coreclr/jit/targetarm64.cpp | 171 ++++++++++++ src/coreclr/jit/targetx86.cpp | 99 +++++++ 5 files changed, 438 insertions(+), 470 deletions(-) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index fcf01d132bd3ff..c52c13273c63cc 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -175,472 +175,6 @@ void RegisterQueue::Clear() m_index = m_numRegs; } -//----------------------------------------------------------------------------- -// TypeSize: -// Get the size of a JIT type or struct. -// -// Parameters: -// type - The type -// structLayout - The layout to get the size if type is TYP_STRUCT -// -// Returns: -// The type size. -// -static unsigned TypeSize(var_types type, ClassLayout* structLayout) -{ - return type == TYP_STRUCT ? structLayout->GetSize() : genTypeSize(type); -} - -#ifdef TARGET_X86 -//----------------------------------------------------------------------------- -// X86Classifier: -// Construct a new instance of the x86 ABI classifier. -// -// Parameters: -// info - Info about the method being classified. -// -X86Classifier::X86Classifier(const ClassifierInfo& info) : m_regs(nullptr, 0) -{ - switch (info.CallConv) - { - case CorInfoCallConvExtension::Thiscall: - { - static const regNumberSmall thiscallRegs[] = {REG_ECX}; - m_regs = RegisterQueue(thiscallRegs, ArrLen(thiscallRegs)); - break; - } - case CorInfoCallConvExtension::C: - case CorInfoCallConvExtension::Stdcall: - case CorInfoCallConvExtension::CMemberFunction: - case CorInfoCallConvExtension::StdcallMemberFunction: - { - break; - } - default: - { - static const regNumberSmall regs[] = {REG_ECX, REG_EDX}; - unsigned numRegs = ArrLen(regs); - if (info.IsVarArgs) - { - // In varargs methods we only enregister the this pointer or retbuff. - numRegs = info.HasThis || info.HasRetBuff ? 1 : 0; - } - m_regs = RegisterQueue(regs, numRegs); - break; - } - } -} - -//----------------------------------------------------------------------------- -// Classify: -// Classify a parameter for the x86 ABI. -// -// Parameters: -// comp - Compiler instance -// type - The type of the parameter -// structLayout - The layout of the struct. Expected to be non-null if -// varTypeIsStruct(type) is true. -// wellKnownParam - Well known type of the parameter (if it may affect its ABI classification) -// -// Returns: -// Classification information for the parameter. -// -ABIPassingInformation X86Classifier::Classify(Compiler* comp, - var_types type, - ClassLayout* structLayout, - WellKnownArg wellKnownParam) -{ - unsigned size = TypeSize(type, structLayout); - unsigned numSlots = (size + TARGET_POINTER_SIZE - 1) / TARGET_POINTER_SIZE; - - bool canEnreg = false; - if (m_regs.Count() >= numSlots) - { - switch (type) - { - case TYP_BYTE: - case TYP_UBYTE: - case TYP_SHORT: - case TYP_USHORT: - case TYP_INT: - case TYP_REF: - case TYP_BYREF: - canEnreg = true; - break; - case TYP_STRUCT: - canEnreg = comp->isTrivialPointerSizedStruct(structLayout->GetClassHandle()); - break; - default: - break; - } - } - - ABIPassingSegment segment; - if (canEnreg) - { - assert(numSlots == 1); - segment = ABIPassingSegment::InRegister(m_regs.Dequeue(), 0, size); - } - else - { - assert((m_stackArgSize % TARGET_POINTER_SIZE) == 0); - segment = ABIPassingSegment::OnStack(m_stackArgSize, 0, size); - m_stackArgSize += roundUp(size, TARGET_POINTER_SIZE); - } - - return ABIPassingInformation::FromSegment(comp, segment); -} -#endif - -#ifdef WINDOWS_AMD64_ABI -static const regNumberSmall WinX64IntArgRegs[] = {REG_RCX, REG_RDX, REG_R8, REG_R9}; -static const regNumberSmall WinX64FloatArgRegs[] = {REG_XMM0, REG_XMM1, REG_XMM2, REG_XMM3}; - -//----------------------------------------------------------------------------- -// WinX64Classifier: -// Construct a new instance of the Windows x64 ABI classifier. -// -// Parameters: -// info - Info about the method being classified. -// -WinX64Classifier::WinX64Classifier(const ClassifierInfo& info) - : m_intRegs(WinX64IntArgRegs, ArrLen(WinX64IntArgRegs)), m_floatRegs(WinX64FloatArgRegs, ArrLen(WinX64FloatArgRegs)) -{ -} - -//----------------------------------------------------------------------------- -// Classify: -// Classify a parameter for the Windows x64 ABI. -// -// Parameters: -// comp - Compiler instance -// type - The type of the parameter -// structLayout - The layout of the struct. Expected to be non-null if -// varTypeIsStruct(type) is true. -// wellKnownParam - Well known type of the parameter (if it may affect its ABI classification) -// -// Returns: -// Classification information for the parameter. -// -ABIPassingInformation WinX64Classifier::Classify(Compiler* comp, - var_types type, - ClassLayout* structLayout, - WellKnownArg wellKnownParam) -{ - // On windows-x64 ABI all parameters take exactly 1 stack slot (structs - // that do not fit are passed implicitly by reference). Passing a parameter - // in an int register also consumes the corresponding float register and - // vice versa. - assert(m_intRegs.Count() == m_floatRegs.Count()); - - unsigned typeSize = TypeSize(type, structLayout); - if ((typeSize > TARGET_POINTER_SIZE) || !isPow2(typeSize)) - { - typeSize = TARGET_POINTER_SIZE; // Passed by implicit byref - } - - ABIPassingSegment segment; - if (m_intRegs.Count() > 0) - { - regNumber reg = varTypeUsesFloatArgReg(type) ? m_floatRegs.Peek() : m_intRegs.Peek(); - segment = ABIPassingSegment::InRegister(reg, 0, typeSize); - m_intRegs.Dequeue(); - m_floatRegs.Dequeue(); - } - else - { - segment = ABIPassingSegment::OnStack(m_stackArgSize, 0, typeSize); - m_stackArgSize += TARGET_POINTER_SIZE; - } - - return ABIPassingInformation::FromSegment(comp, segment); -} -#endif - -#ifdef UNIX_AMD64_ABI -static const regNumberSmall SysVX64IntArgRegs[] = {REG_EDI, REG_ESI, REG_EDX, REG_ECX, REG_R8, REG_R9}; -static const regNumberSmall SysVX64FloatArgRegs[] = {REG_XMM0, REG_XMM1, REG_XMM2, REG_XMM3, - REG_XMM4, REG_XMM5, REG_XMM6, REG_XMM7}; -//----------------------------------------------------------------------------- -// SysVX64Classifier: -// Construct a new instance of the SysV x64 ABI classifier. -// -// Parameters: -// info - Info about the method being classified. -// -SysVX64Classifier::SysVX64Classifier(const ClassifierInfo& info) - : m_intRegs(SysVX64IntArgRegs, ArrLen(SysVX64IntArgRegs)) - , m_floatRegs(SysVX64FloatArgRegs, ArrLen(SysVX64FloatArgRegs)) -{ -} - -//----------------------------------------------------------------------------- -// Classify: -// Classify a parameter for the SysV x64 ABI. -// -// Parameters: -// comp - Compiler instance -// type - The type of the parameter -// structLayout - The layout of the struct. Expected to be non-null if -// varTypeIsStruct(type) is true. -// wellKnownParam - Well known type of the parameter (if it may affect its ABI classification) -// -// Returns: -// Classification information for the parameter. -// -ABIPassingInformation SysVX64Classifier::Classify(Compiler* comp, - var_types type, - ClassLayout* structLayout, - WellKnownArg wellKnownParam) -{ - bool canEnreg = false; - SYSTEMV_AMD64_CORINFO_STRUCT_REG_PASSING_DESCRIPTOR structDesc; - if (varTypeIsStruct(type)) - { - comp->eeGetSystemVAmd64PassStructInRegisterDescriptor(structLayout->GetClassHandle(), &structDesc); - - if (structDesc.passedInRegisters) - { - unsigned intRegCount = 0; - unsigned floatRegCount = 0; - - for (unsigned int i = 0; i < structDesc.eightByteCount; i++) - { - if (structDesc.IsIntegralSlot(i)) - { - intRegCount++; - } - else if (structDesc.IsSseSlot(i)) - { - floatRegCount++; - } - else - { - assert(!"Invalid eightbyte classification type."); - break; - } - } - - canEnreg = (intRegCount <= m_intRegs.Count()) && (floatRegCount <= m_floatRegs.Count()); - } - } - else - { - unsigned availRegs = varTypeUsesFloatArgReg(type) ? m_floatRegs.Count() : m_intRegs.Count(); - canEnreg = availRegs > 0; - } - - ABIPassingInformation info; - if (canEnreg) - { - if (varTypeIsStruct(type)) - { - info.NumSegments = structDesc.eightByteCount; - info.Segments = new (comp, CMK_ABI) ABIPassingSegment[structDesc.eightByteCount]; - - for (unsigned i = 0; i < structDesc.eightByteCount; i++) - { - regNumber reg = structDesc.IsIntegralSlot(i) ? m_intRegs.Dequeue() : m_floatRegs.Dequeue(); - info.Segments[i] = - ABIPassingSegment::InRegister(reg, structDesc.eightByteOffsets[i], structDesc.eightByteSizes[i]); - } - } - else - { - regNumber reg = varTypeUsesFloatArgReg(type) ? m_floatRegs.Dequeue() : m_intRegs.Dequeue(); - info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::InRegister(reg, 0, genTypeSize(type))); - } - } - else - { - assert((m_stackArgSize % TARGET_POINTER_SIZE) == 0); - unsigned size = TypeSize(type, structLayout); - info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::OnStack(m_stackArgSize, 0, size)); - m_stackArgSize += roundUp(size, TARGET_POINTER_SIZE); - } - - return info; -} -#endif - -#ifdef TARGET_ARM64 -static const regNumberSmall Arm64IntArgRegs[] = {REG_R0, REG_R1, REG_R2, REG_R3, REG_R4, REG_R5, REG_R6, REG_R7}; -static const regNumberSmall Arm64FloatArgRegs[] = {REG_V0, REG_V1, REG_V2, REG_V3, REG_V4, REG_V5, REG_V6, REG_V7}; - -//----------------------------------------------------------------------------- -// Arm64Classifier: -// Construct a new instance of the ARM64 ABI classifier. -// -// Parameters: -// info - Info about the method being classified. -// -Arm64Classifier::Arm64Classifier(const ClassifierInfo& info) - : m_info(info) - , m_intRegs(Arm64IntArgRegs, ArrLen(Arm64IntArgRegs)) - , m_floatRegs(Arm64FloatArgRegs, ArrLen(Arm64FloatArgRegs)) -{ -} - -//----------------------------------------------------------------------------- -// Classify: -// Classify a parameter for the ARM64 ABI. -// -// Parameters: -// comp - Compiler instance -// type - The type of the parameter -// structLayout - The layout of the struct. Expected to be non-null if -// varTypeIsStruct(type) is true. -// wellKnownParam - Well known type of the parameter (if it may affect its ABI classification) -// -// Returns: -// Classification information for the parameter. -// -ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, - var_types type, - ClassLayout* structLayout, - WellKnownArg wellKnownParam) -{ - if ((wellKnownParam == WellKnownArg::RetBuffer) && hasFixedRetBuffReg(m_info.CallConv)) - { - return ABIPassingInformation::FromSegment(comp, ABIPassingSegment::InRegister(REG_ARG_RET_BUFF, 0, - TARGET_POINTER_SIZE)); - } - - // First handle HFA/HVAs. These are allowed to be passed in more registers - // than other structures. - if (varTypeIsStruct(type) && !m_info.IsVarArgs) - { - var_types hfaType = comp->GetHfaType(structLayout->GetClassHandle()); - - if (hfaType != TYP_UNDEF) - { - unsigned elemSize = genTypeSize(hfaType); - unsigned slots = structLayout->GetSize() / elemSize; - ABIPassingInformation info; - if (m_floatRegs.Count() >= slots) - { - info.NumSegments = slots; - info.Segments = new (comp, CMK_ABI) ABIPassingSegment[slots]; - - for (unsigned i = 0; i < slots; i++) - { - info.Segments[i] = ABIPassingSegment::InRegister(m_floatRegs.Dequeue(), i * elemSize, elemSize); - } - } - else - { - unsigned alignment = compAppleArm64Abi() ? elemSize : TARGET_POINTER_SIZE; - m_stackArgSize = roundUp(m_stackArgSize, alignment); - info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::OnStack(m_stackArgSize, 0, - structLayout->GetSize())); - m_stackArgSize += roundUp(structLayout->GetSize(), alignment); - // After passing any float value on the stack, we should not enregister more float values. - m_floatRegs.Clear(); - } - - return info; - } - } - - unsigned slots; - unsigned passedSize; - if (varTypeIsStruct(type)) - { - unsigned size = structLayout->GetSize(); - if (size > 16) - { - slots = 1; // Passed by implicit byref - passedSize = TARGET_POINTER_SIZE; - } - else - { - slots = (size + TARGET_POINTER_SIZE - 1) / TARGET_POINTER_SIZE; - passedSize = size; - } - } - else - { - assert(genTypeSize(type) <= TARGET_POINTER_SIZE); - slots = 1; - passedSize = genTypeSize(type); - } - - assert((slots == 1) || (slots == 2)); - - ABIPassingInformation info; - if (m_info.IsVarArgs && (slots == 2) && (m_intRegs.Count() == 1)) - { - // For varargs we split structs between register and stack in this - // case. Normally a struct that does not fit in registers will always - // be passed on stack. - assert(compFeatureArgSplit()); - info.NumSegments = 2; - info.Segments = new (comp, CMK_ABI) ABIPassingSegment[2]; - info.Segments[0] = ABIPassingSegment::InRegister(m_intRegs.Dequeue(), 0, TARGET_POINTER_SIZE); - info.Segments[1] = ABIPassingSegment::OnStack(m_stackArgSize, TARGET_POINTER_SIZE, - structLayout->GetSize() - TARGET_POINTER_SIZE); - m_stackArgSize += TARGET_POINTER_SIZE; - } - else - { - RegisterQueue* regs = &m_intRegs; - - // In varargs methods (only supported on Windows) all parameters go in - // integer registers. - if (varTypeUsesFloatArgReg(type) && !m_info.IsVarArgs) - { - regs = &m_floatRegs; - } - - if (regs->Count() >= slots) - { - info.NumSegments = slots; - info.Segments = new (comp, CMK_ABI) ABIPassingSegment[slots]; - unsigned slotSize = varTypeIsStruct(type) ? TARGET_POINTER_SIZE : genTypeSize(type); - info.Segments[0] = ABIPassingSegment::InRegister(regs->Dequeue(), 0, slotSize); - if (slots == 2) - { - assert(varTypeIsStruct(type)); - unsigned tailSize = structLayout->GetSize() - slotSize; - info.Segments[1] = ABIPassingSegment::InRegister(regs->Dequeue(), slotSize, tailSize); - } - } - else - { - unsigned alignment; - if (compAppleArm64Abi()) - { - if (varTypeIsStruct(type)) - { - alignment = TARGET_POINTER_SIZE; - } - else - { - alignment = genTypeSize(type); - } - - m_stackArgSize = roundUp(m_stackArgSize, alignment); - } - else - { - alignment = TARGET_POINTER_SIZE; - assert((m_stackArgSize % TARGET_POINTER_SIZE) == 0); - } - - info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::OnStack(m_stackArgSize, 0, passedSize)); - - m_stackArgSize += roundUp(passedSize, alignment); - - // As soon as we pass something on stack we cannot go back and - // enregister something else. - regs->Clear(); - } - } - - return info; -} -#endif - #ifdef SWIFT_SUPPORT //----------------------------------------------------------------------------- // Classify: diff --git a/src/coreclr/jit/abi.h b/src/coreclr/jit/abi.h index bfc76236501a9c..f6303899b2509a 100644 --- a/src/coreclr/jit/abi.h +++ b/src/coreclr/jit/abi.h @@ -54,12 +54,12 @@ struct ABIPassingInformation class RegisterQueue { - const regNumberSmall* m_regs; - unsigned int m_numRegs; - unsigned int m_index = 0; + const regNumber* m_regs; + unsigned int m_numRegs; + unsigned int m_index = 0; public: - RegisterQueue(const regNumberSmall* regs, unsigned int numRegs) : m_regs(regs), m_numRegs(numRegs) + RegisterQueue(const regNumber* regs, unsigned int numRegs) : m_regs(regs), m_numRegs(numRegs) { } diff --git a/src/coreclr/jit/targetamd64.cpp b/src/coreclr/jit/targetamd64.cpp index 4ac48cb229fbed..576a152d4b8161 100644 --- a/src/coreclr/jit/targetamd64.cpp +++ b/src/coreclr/jit/targetamd64.cpp @@ -30,4 +30,168 @@ const regMaskTP fltArgMasks[] = { RBM_XMM0, RBM_XMM1, RBM_XMM2, RBM_XMM3 }; #endif // !UNIX_AMD64_ABI // clang-format on +#ifdef UNIX_AMD64_ABI +//----------------------------------------------------------------------------- +// SysVX64Classifier: +// Construct a new instance of the SysV x64 ABI classifier. +// +// Parameters: +// info - Info about the method being classified. +// +SysVX64Classifier::SysVX64Classifier(const ClassifierInfo& info) + : m_intRegs(intArgRegs, ArrLen(intArgRegs)), m_floatRegs(fltArgRegs, ArrLen(fltArgRegs)) +{ +} + +//----------------------------------------------------------------------------- +// Classify: +// Classify a parameter for the SysV x64 ABI. +// +// Parameters: +// comp - Compiler instance +// type - The type of the parameter +// structLayout - The layout of the struct. Expected to be non-null if +// varTypeIsStruct(type) is true. +// wellKnownParam - Well known type of the parameter (if it may affect its ABI classification) +// +// Returns: +// Classification information for the parameter. +// +ABIPassingInformation SysVX64Classifier::Classify(Compiler* comp, + var_types type, + ClassLayout* structLayout, + WellKnownArg wellKnownParam) +{ + bool canEnreg = false; + SYSTEMV_AMD64_CORINFO_STRUCT_REG_PASSING_DESCRIPTOR structDesc; + if (varTypeIsStruct(type)) + { + comp->eeGetSystemVAmd64PassStructInRegisterDescriptor(structLayout->GetClassHandle(), &structDesc); + + if (structDesc.passedInRegisters) + { + unsigned intRegCount = 0; + unsigned floatRegCount = 0; + + for (unsigned int i = 0; i < structDesc.eightByteCount; i++) + { + if (structDesc.IsIntegralSlot(i)) + { + intRegCount++; + } + else if (structDesc.IsSseSlot(i)) + { + floatRegCount++; + } + else + { + assert(!"Invalid eightbyte classification type."); + break; + } + } + + canEnreg = (intRegCount <= m_intRegs.Count()) && (floatRegCount <= m_floatRegs.Count()); + } + } + else + { + unsigned availRegs = varTypeUsesFloatArgReg(type) ? m_floatRegs.Count() : m_intRegs.Count(); + canEnreg = availRegs > 0; + } + + ABIPassingInformation info; + if (canEnreg) + { + if (varTypeIsStruct(type)) + { + info.NumSegments = structDesc.eightByteCount; + info.Segments = new (comp, CMK_ABI) ABIPassingSegment[structDesc.eightByteCount]; + + for (unsigned i = 0; i < structDesc.eightByteCount; i++) + { + regNumber reg = structDesc.IsIntegralSlot(i) ? m_intRegs.Dequeue() : m_floatRegs.Dequeue(); + info.Segments[i] = + ABIPassingSegment::InRegister(reg, structDesc.eightByteOffsets[i], structDesc.eightByteSizes[i]); + } + } + else + { + regNumber reg = varTypeUsesFloatArgReg(type) ? m_floatRegs.Dequeue() : m_intRegs.Dequeue(); + info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::InRegister(reg, 0, genTypeSize(type))); + } + } + else + { + assert((m_stackArgSize % TARGET_POINTER_SIZE) == 0); + unsigned size = type == TYP_STRUCT ? structLayout->GetSize() : genTypeSize(type); + info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::OnStack(m_stackArgSize, 0, size)); + m_stackArgSize += roundUp(size, TARGET_POINTER_SIZE); + } + + return info; +} + +#else // !UNIX_AMD64_ABI + +//----------------------------------------------------------------------------- +// WinX64Classifier: +// Construct a new instance of the Windows x64 ABI classifier. +// +// Parameters: +// info - Info about the method being classified. +// +WinX64Classifier::WinX64Classifier(const ClassifierInfo& info) + : m_intRegs(intArgRegs, ArrLen(intArgRegs)), m_floatRegs(fltArgRegs, ArrLen(fltArgRegs)) +{ +} + +//----------------------------------------------------------------------------- +// Classify: +// Classify a parameter for the Windows x64 ABI. +// +// Parameters: +// comp - Compiler instance +// type - The type of the parameter +// structLayout - The layout of the struct. Expected to be non-null if +// varTypeIsStruct(type) is true. +// wellKnownParam - Well known type of the parameter (if it may affect its ABI classification) +// +// Returns: +// Classification information for the parameter. +// +ABIPassingInformation WinX64Classifier::Classify(Compiler* comp, + var_types type, + ClassLayout* structLayout, + WellKnownArg wellKnownParam) +{ + // On windows-x64 ABI all parameters take exactly 1 stack slot (structs + // that do not fit are passed implicitly by reference). Passing a parameter + // in an int register also consumes the corresponding float register and + // vice versa. + assert(m_intRegs.Count() == m_floatRegs.Count()); + + unsigned typeSize = type == TYP_STRUCT ? structLayout->GetSize() : genTypeSize(type); + if ((typeSize > TARGET_POINTER_SIZE) || !isPow2(typeSize)) + { + typeSize = TARGET_POINTER_SIZE; // Passed by implicit byref + } + + ABIPassingSegment segment; + if (m_intRegs.Count() > 0) + { + regNumber reg = varTypeUsesFloatArgReg(type) ? m_floatRegs.Peek() : m_intRegs.Peek(); + segment = ABIPassingSegment::InRegister(reg, 0, typeSize); + m_intRegs.Dequeue(); + m_floatRegs.Dequeue(); + } + else + { + segment = ABIPassingSegment::OnStack(m_stackArgSize, 0, typeSize); + m_stackArgSize += TARGET_POINTER_SIZE; + } + + return ABIPassingInformation::FromSegment(comp, segment); +} +#endif + #endif // TARGET_AMD64 diff --git a/src/coreclr/jit/targetarm64.cpp b/src/coreclr/jit/targetarm64.cpp index dcec1db6c5229f..befe688247c09f 100644 --- a/src/coreclr/jit/targetarm64.cpp +++ b/src/coreclr/jit/targetarm64.cpp @@ -24,4 +24,175 @@ const regNumber fltArgRegs [] = {REG_V0, REG_V1, REG_V2, REG_V3, REG_V4, REG_V5, const regMaskTP fltArgMasks[] = {RBM_V0, RBM_V1, RBM_V2, RBM_V3, RBM_V4, RBM_V5, RBM_V6, RBM_V7 }; // clang-format on +//----------------------------------------------------------------------------- +// Arm64Classifier: +// Construct a new instance of the ARM64 ABI classifier. +// +// Parameters: +// info - Info about the method being classified. +// +Arm64Classifier::Arm64Classifier(const ClassifierInfo& info) + : m_info(info), m_intRegs(intArgRegs, ArrLen(intArgRegs)), m_floatRegs(fltArgRegs, ArrLen(fltArgRegs)) +{ +} + +//----------------------------------------------------------------------------- +// Classify: +// Classify a parameter for the ARM64 ABI. +// +// Parameters: +// comp - Compiler instance +// type - The type of the parameter +// structLayout - The layout of the struct. Expected to be non-null if +// varTypeIsStruct(type) is true. +// wellKnownParam - Well known type of the parameter (if it may affect its ABI classification) +// +// Returns: +// Classification information for the parameter. +// +ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, + var_types type, + ClassLayout* structLayout, + WellKnownArg wellKnownParam) +{ + if ((wellKnownParam == WellKnownArg::RetBuffer) && hasFixedRetBuffReg(m_info.CallConv)) + { + return ABIPassingInformation::FromSegment(comp, ABIPassingSegment::InRegister(REG_ARG_RET_BUFF, 0, + TARGET_POINTER_SIZE)); + } + + // First handle HFA/HVAs. These are allowed to be passed in more registers + // than other structures. + if (varTypeIsStruct(type) && !m_info.IsVarArgs) + { + var_types hfaType = comp->GetHfaType(structLayout->GetClassHandle()); + + if (hfaType != TYP_UNDEF) + { + unsigned elemSize = genTypeSize(hfaType); + unsigned slots = structLayout->GetSize() / elemSize; + ABIPassingInformation info; + if (m_floatRegs.Count() >= slots) + { + info.NumSegments = slots; + info.Segments = new (comp, CMK_ABI) ABIPassingSegment[slots]; + + for (unsigned i = 0; i < slots; i++) + { + info.Segments[i] = ABIPassingSegment::InRegister(m_floatRegs.Dequeue(), i * elemSize, elemSize); + } + } + else + { + unsigned alignment = compAppleArm64Abi() ? elemSize : TARGET_POINTER_SIZE; + m_stackArgSize = roundUp(m_stackArgSize, alignment); + info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::OnStack(m_stackArgSize, 0, + structLayout->GetSize())); + m_stackArgSize += roundUp(structLayout->GetSize(), alignment); + // After passing any float value on the stack, we should not enregister more float values. + m_floatRegs.Clear(); + } + + return info; + } + } + + unsigned slots; + unsigned passedSize; + if (varTypeIsStruct(type)) + { + unsigned size = structLayout->GetSize(); + if (size > 16) + { + slots = 1; // Passed by implicit byref + passedSize = TARGET_POINTER_SIZE; + } + else + { + slots = (size + TARGET_POINTER_SIZE - 1) / TARGET_POINTER_SIZE; + passedSize = size; + } + } + else + { + assert(genTypeSize(type) <= TARGET_POINTER_SIZE); + slots = 1; + passedSize = genTypeSize(type); + } + + assert((slots == 1) || (slots == 2)); + + ABIPassingInformation info; + if (m_info.IsVarArgs && (slots == 2) && (m_intRegs.Count() == 1)) + { + // For varargs we split structs between register and stack in this + // case. Normally a struct that does not fit in registers will always + // be passed on stack. + assert(compFeatureArgSplit()); + info.NumSegments = 2; + info.Segments = new (comp, CMK_ABI) ABIPassingSegment[2]; + info.Segments[0] = ABIPassingSegment::InRegister(m_intRegs.Dequeue(), 0, TARGET_POINTER_SIZE); + info.Segments[1] = ABIPassingSegment::OnStack(m_stackArgSize, TARGET_POINTER_SIZE, + structLayout->GetSize() - TARGET_POINTER_SIZE); + m_stackArgSize += TARGET_POINTER_SIZE; + } + else + { + RegisterQueue* regs = &m_intRegs; + + // In varargs methods (only supported on Windows) all parameters go in + // integer registers. + if (varTypeUsesFloatArgReg(type) && !m_info.IsVarArgs) + { + regs = &m_floatRegs; + } + + if (regs->Count() >= slots) + { + info.NumSegments = slots; + info.Segments = new (comp, CMK_ABI) ABIPassingSegment[slots]; + unsigned slotSize = varTypeIsStruct(type) ? TARGET_POINTER_SIZE : genTypeSize(type); + info.Segments[0] = ABIPassingSegment::InRegister(regs->Dequeue(), 0, slotSize); + if (slots == 2) + { + assert(varTypeIsStruct(type)); + unsigned tailSize = structLayout->GetSize() - slotSize; + info.Segments[1] = ABIPassingSegment::InRegister(regs->Dequeue(), slotSize, tailSize); + } + } + else + { + unsigned alignment; + if (compAppleArm64Abi()) + { + if (varTypeIsStruct(type)) + { + alignment = TARGET_POINTER_SIZE; + } + else + { + alignment = genTypeSize(type); + } + + m_stackArgSize = roundUp(m_stackArgSize, alignment); + } + else + { + alignment = TARGET_POINTER_SIZE; + assert((m_stackArgSize % TARGET_POINTER_SIZE) == 0); + } + + info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::OnStack(m_stackArgSize, 0, passedSize)); + + m_stackArgSize += roundUp(passedSize, alignment); + + // As soon as we pass something on stack we cannot go back and + // enregister something else. + regs->Clear(); + } + } + + return info; +} + #endif // TARGET_ARM64 diff --git a/src/coreclr/jit/targetx86.cpp b/src/coreclr/jit/targetx86.cpp index d5ed8b0bbf606f..36044df9a981ad 100644 --- a/src/coreclr/jit/targetx86.cpp +++ b/src/coreclr/jit/targetx86.cpp @@ -21,4 +21,103 @@ const regNumber intArgRegs [] = {REG_ECX, REG_EDX}; const regMaskTP intArgMasks[] = {RBM_ECX, RBM_EDX}; // clang-format on +//----------------------------------------------------------------------------- +// X86Classifier: +// Construct a new instance of the x86 ABI classifier. +// +// Parameters: +// info - Info about the method being classified. +// +X86Classifier::X86Classifier(const ClassifierInfo& info) : m_regs(nullptr, 0) +{ + switch (info.CallConv) + { + case CorInfoCallConvExtension::Thiscall: + { + static const regNumberSmall thiscallRegs[] = {REG_ECX}; + m_regs = RegisterQueue(thiscallRegs, ArrLen(thiscallRegs)); + break; + } + case CorInfoCallConvExtension::C: + case CorInfoCallConvExtension::Stdcall: + case CorInfoCallConvExtension::CMemberFunction: + case CorInfoCallConvExtension::StdcallMemberFunction: + { + break; + } + default: + { + static const regNumberSmall regs[] = {REG_ECX, REG_EDX}; + unsigned numRegs = ArrLen(regs); + if (info.IsVarArgs) + { + // In varargs methods we only enregister the this pointer or retbuff. + numRegs = info.HasThis || info.HasRetBuff ? 1 : 0; + } + m_regs = RegisterQueue(regs, numRegs); + break; + } + } +} + +//----------------------------------------------------------------------------- +// Classify: +// Classify a parameter for the x86 ABI. +// +// Parameters: +// comp - Compiler instance +// type - The type of the parameter +// structLayout - The layout of the struct. Expected to be non-null if +// varTypeIsStruct(type) is true. +// wellKnownParam - Well known type of the parameter (if it may affect its ABI classification) +// +// Returns: +// Classification information for the parameter. +// +ABIPassingInformation X86Classifier::Classify(Compiler* comp, + var_types type, + ClassLayout* structLayout, + WellKnownArg wellKnownParam) +{ + unsigned size = type == TYP_STRUCT ? structLayout->GetSize() : genTypeSize(type); + unsigned numSlots = (size + TARGET_POINTER_SIZE - 1) / TARGET_POINTER_SIZE; + + bool canEnreg = false; + if (m_regs.Count() >= numSlots) + { + switch (type) + { + case TYP_BYTE: + case TYP_UBYTE: + case TYP_SHORT: + case TYP_USHORT: + case TYP_INT: + case TYP_REF: + case TYP_BYREF: + canEnreg = true; + break; + case TYP_STRUCT: + canEnreg = comp->isTrivialPointerSizedStruct(structLayout->GetClassHandle()); + break; + default: + break; + } + } + + ABIPassingSegment segment; + if (canEnreg) + { + assert(numSlots == 1); + segment = ABIPassingSegment::InRegister(m_regs.Dequeue(), 0, size); + } + else + { + assert((m_stackArgSize % TARGET_POINTER_SIZE) == 0); + segment = ABIPassingSegment::OnStack(m_stackArgSize, 0, size); + m_stackArgSize += roundUp(size, TARGET_POINTER_SIZE); + } + + return ABIPassingInformation::FromSegment(comp, segment); +} + #endif // TARGET_X86 From 70a0affa1230335ed41de0e92ec9fac423abc6fb Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 13:29:30 +0100 Subject: [PATCH 14/52] Fix x86 --- src/coreclr/jit/targetx86.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/targetx86.cpp b/src/coreclr/jit/targetx86.cpp index 36044df9a981ad..1c3e91be1bd2ff 100644 --- a/src/coreclr/jit/targetx86.cpp +++ b/src/coreclr/jit/targetx86.cpp @@ -34,8 +34,8 @@ X86Classifier::X86Classifier(const ClassifierInfo& info) : m_regs(nullptr, 0) { case CorInfoCallConvExtension::Thiscall: { - static const regNumberSmall thiscallRegs[] = {REG_ECX}; - m_regs = RegisterQueue(thiscallRegs, ArrLen(thiscallRegs)); + static const regNumber thiscallRegs[] = {REG_ECX}; + m_regs = RegisterQueue(thiscallRegs, ArrLen(thiscallRegs)); break; } case CorInfoCallConvExtension::C: @@ -47,14 +47,13 @@ X86Classifier::X86Classifier(const ClassifierInfo& info) : m_regs(nullptr, 0) } default: { - static const regNumberSmall regs[] = {REG_ECX, REG_EDX}; - unsigned numRegs = ArrLen(regs); + unsigned numRegs = ArrLen(intArgRegs); if (info.IsVarArgs) { // In varargs methods we only enregister the this pointer or retbuff. numRegs = info.HasThis || info.HasRetBuff ? 1 : 0; } - m_regs = RegisterQueue(regs, numRegs); + m_regs = RegisterQueue(intArgRegs, numRegs); break; } } From 0e82029fb9609347f33a83d599f18d2624ac4eb2 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 14:18:01 +0100 Subject: [PATCH 15/52] Fix Apple ARM64 ABI for HVAs For HVAs the element size can be > 8, but should at most be 8-byte aligned. --- src/coreclr/jit/targetarm64.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/targetarm64.cpp b/src/coreclr/jit/targetarm64.cpp index befe688247c09f..f48cfae542cd34 100644 --- a/src/coreclr/jit/targetarm64.cpp +++ b/src/coreclr/jit/targetarm64.cpp @@ -84,7 +84,7 @@ ABIPassingInformation Arm64Classifier::Classify(Compiler* comp, } else { - unsigned alignment = compAppleArm64Abi() ? elemSize : TARGET_POINTER_SIZE; + unsigned alignment = compAppleArm64Abi() ? min(elemSize, TARGET_POINTER_SIZE) : TARGET_POINTER_SIZE; m_stackArgSize = roundUp(m_stackArgSize, alignment); info = ABIPassingInformation::FromSegment(comp, ABIPassingSegment::OnStack(m_stackArgSize, 0, structLayout->GetSize())); From 8cf09c791d12ff0677b8a608189f3e3d406878d9 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 16:03:26 +0100 Subject: [PATCH 16/52] Initial work --- src/coreclr/jit/abi.cpp | 113 ++++++++++++++++++++++++++++++ src/coreclr/jit/abi.h | 6 ++ src/coreclr/jit/codegen.h | 3 + src/coreclr/jit/codegencommon.cpp | 89 ++++++++++++++++++++--- src/coreclr/jit/lclvars.cpp | 30 +++++++- 5 files changed, 230 insertions(+), 11 deletions(-) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index c52c13273c63cc..ac1d78932bf3ee 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -54,6 +54,53 @@ unsigned ABIPassingSegment::GetStackOffset() const return m_stackOffset; } +//----------------------------------------------------------------------------- +// GetRegisterStoreType: +// Return a type that can be used to store from the register this segment is +// in, taking the segment's size into account. +// +// Return Value: +// A type that matches ABIPassingSegment::Size and the register type. +// +var_types ABIPassingSegment::GetRegisterStoreType() const +{ + assert(IsPassedInRegister()); + if (genIsValidFloatReg(m_register)) + { + switch (Size) + { + case 4: + return TYP_FLOAT; + case 8: + return TYP_DOUBLE; +#ifdef FEATURE_SIMD + case 16: + return TYP_SIMD16; + default: + return TYP_UNDEF; +#endif + } + } + else + { + switch (Size) + { + case 1: + return TYP_UBYTE; + case 2: + return TYP_USHORT; + case 4: + return TYP_INT; +#ifdef TARGET_64BIT + case 8: + return TYP_LONG; +#endif + default: + return TYP_UNDEF; + } + } +} + //----------------------------------------------------------------------------- // InRegister: // Create an ABIPassingSegment representing that a segment is passed in a @@ -140,6 +187,39 @@ ABIPassingInformation ABIPassingInformation::FromSegment(Compiler* comp, const A return info; } +#ifdef DEBUG +//----------------------------------------------------------------------------- +// Dump: +// Dump the ABIPassingInformation to stdout. +// +void ABIPassingInformation::Dump() const +{ + if (NumSegments != 1) + { + printf("%u segments\n", NumSegments); + } + + for (unsigned i = 0; i < NumSegments; i++) + { + if (NumSegments > 1) + { + printf(" [%u] ", i); + } + + const ABIPassingSegment& seg = Segments[i]; + + if (Segments[i].IsPassedInRegister()) + { + printf("[%02u..%02u) reg %s\n", seg.Offset, seg.Offset + seg.Size, getRegName(seg.GetRegister())); + } + else + { + printf("[%02u..%02u) stack @ +%02u\n", seg.Offset, seg.Offset + seg.Size, seg.GetStackOffset()); + } + } +} +#endif + //----------------------------------------------------------------------------- // RegisterQueue::Dequeue: // Dequeue a register from the queue. @@ -209,6 +289,39 @@ ABIPassingInformation SwiftABIClassifier::Classify(Compiler* comp, TARGET_POINTER_SIZE)); } + if (type == TYP_STRUCT) + { + const CORINFO_SWIFT_LOWERING* lowering = comp->GetSwiftLowering(structLayout->GetClassHandle()); + if (lowering->byReference) + { + return m_classifier.Classify(comp, TYP_I_IMPL, nullptr, WellKnownArg::None); + } + + ArrayStack segments(comp->getAllocator(CMK_ABI)); + for (unsigned i = 0; i < lowering->numLoweredElements; i++) + { + var_types elemType = JITtype2varType(lowering->loweredElements[i]); + ABIPassingInformation elemInfo = m_classifier.Classify(comp, elemType, nullptr, WellKnownArg::None); + + for (unsigned j = 0; j < elemInfo.NumSegments; j++) + { + ABIPassingSegment newSegment = elemInfo.Segments[j]; + newSegment.Offset += lowering->offsets[i]; + segments.Push(newSegment); + } + } + + ABIPassingInformation result; + result.NumSegments = static_cast(segments.Height()); + result.Segments = new (comp, CMK_ABI) ABIPassingSegment[result.NumSegments]; + for (int i = 0; i < segments.Height(); i++) + { + result.Segments[i] = segments.Bottom(i); + } + + return result; + } + return m_classifier.Classify(comp, type, structLayout, wellKnownParam); } #endif diff --git a/src/coreclr/jit/abi.h b/src/coreclr/jit/abi.h index f6303899b2509a..7f358caa4a6d8b 100644 --- a/src/coreclr/jit/abi.h +++ b/src/coreclr/jit/abi.h @@ -29,6 +29,8 @@ class ABIPassingSegment // offset, relative to the first stack argument's offset. unsigned GetStackOffset() const; + var_types GetRegisterStoreType() const; + static ABIPassingSegment InRegister(regNumber reg, unsigned offset, unsigned size); static ABIPassingSegment OnStack(unsigned stackOffset, unsigned offset, unsigned size); }; @@ -50,6 +52,10 @@ struct ABIPassingInformation bool IsSplitAcrossRegistersAndStack() const; static ABIPassingInformation FromSegment(Compiler* comp, const ABIPassingSegment& segment); + +#ifdef DEBUG + void Dump() const; +#endif }; class RegisterQueue diff --git a/src/coreclr/jit/codegen.h b/src/coreclr/jit/codegen.h index 7a2359c9fb5fc9..c155421ae65870 100644 --- a/src/coreclr/jit/codegen.h +++ b/src/coreclr/jit/codegen.h @@ -276,6 +276,9 @@ class CodeGen final : public CodeGenInterface #else void genEnregisterOSRArgsAndLocals(); #endif + + void genHomeSwiftStructParameters(regNumber initReg, bool *initRegZeroed); + void genCheckUseBlockInit(); #if defined(UNIX_AMD64_ABI) && defined(FEATURE_SIMD) void genClearStackVec3ArgUpperBits(); diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 24f5a922f18878..fe373eb0db155e 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -4975,6 +4975,77 @@ void CodeGen::genEnregisterOSRArgsAndLocals() } } +#ifdef SWIFT_SUPPORT +void CodeGen::genHomeSwiftStructParameters(regNumber initReg, bool *initRegZeroed) +{ + for (unsigned lclNum = 0; lclNum < compiler->info.compArgsCount; lclNum++) + { + LclVarDsc* dsc = compiler->lvaGetDesc(lclNum); + if ((dsc->TypeGet() != TYP_STRUCT) || dsc->lvIsImplicitByRef) + { + continue; + } + + JITDUMP("Homing Swift parameter V%02u: ", lclNum); + const ABIPassingInformation& abiInfo = compiler->lvaParameterPassingInfo[lclNum]; + DBEXEC(VERBOSE, abiInfo.Dump()); + + for (unsigned i = 0; i < abiInfo.NumSegments; i++) + { + const ABIPassingSegment& seg = abiInfo.Segments[i]; + if (seg.IsPassedInRegister()) + { + var_types storeType = seg.GetRegisterStoreType(); + assert(storeType != TYP_UNDEF); + GetEmitter()->emitIns_S_R(ins_Store(storeType), emitTypeSize(storeType), seg.GetRegister(), lclNum, seg.Offset); + } + else + { + var_types loadType = TYP_UNDEF; + switch (seg.Size) + { + case 1: + loadType = TYP_UBYTE; + break; + case 2: + loadType = TYP_USHORT; + break; + case 4: + loadType = TYP_INT; + break; + case 8: + loadType = TYP_LONG; + break; + default: + assert(!"Unexpected segment size for struct parameter not passed implicitly by ref"); + continue; + } + + ssize_t offset; + if (isFramePointerUsed()) + { + offset = -genCallerSPtoFPdelta(); + } + else + { + offset = -genCallerSPtoInitialSPdelta(); + } + +#ifdef TARGET_XARCH + offset += TARGET_POINTER_SIZE; // Return address +#endif + + offset += (ssize_t)seg.GetStackOffset(); + genInstrWithConstant(ins_Load(loadType), emitTypeSize(loadType), initReg, genFramePointerReg(), offset, initReg); + *initRegZeroed = false; + + GetEmitter()->emitIns_S_R(ins_Store(loadType), emitTypeSize(loadType), initReg, lclNum, seg.Offset); + } + } + } +} +#endif + /*----------------------------------------------------------------------------- * * Save the generic context argument. @@ -6148,14 +6219,6 @@ void CodeGen::genFnProlog() intRegState.rsCalleeRegArgMaskLiveIn &= ~RBM_SECRET_STUB_PARAM; } -#ifdef SWIFT_SUPPORT - if ((compiler->lvaSwiftSelfArg != BAD_VAR_NUM) && ((intRegState.rsCalleeRegArgMaskLiveIn & RBM_SWIFT_SELF) != 0)) - { - GetEmitter()->emitIns_S_R(ins_Store(TYP_I_IMPL), EA_PTRSIZE, REG_SWIFT_SELF, compiler->lvaSwiftSelfArg, 0); - intRegState.rsCalleeRegArgMaskLiveIn &= ~RBM_SWIFT_SELF; - } -#endif - // // Zero out the frame as needed // @@ -6247,6 +6310,16 @@ void CodeGen::genFnProlog() * Take care of register arguments first */ +#ifdef SWIFT_SUPPORT + if ((compiler->lvaSwiftSelfArg != BAD_VAR_NUM) && ((intRegState.rsCalleeRegArgMaskLiveIn & RBM_SWIFT_SELF) != 0)) + { + GetEmitter()->emitIns_S_R(ins_Store(TYP_I_IMPL), EA_PTRSIZE, REG_SWIFT_SELF, compiler->lvaSwiftSelfArg, 0); + intRegState.rsCalleeRegArgMaskLiveIn &= ~RBM_SWIFT_SELF; + } + + genHomeSwiftStructParameters(initReg, &initRegZeroed); +#endif + // Home incoming arguments and generate any required inits. // OSR handles this by moving the values from the original frame. // diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 978fff461e146a..dbf3bbadeab48d 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -661,10 +661,26 @@ void Compiler::lvaInitUserArgs(InitVarDscInfo* varDscInfo, unsigned skipArgs, un varDsc->lvOnFrame = true; #ifdef SWIFT_SUPPORT - if ((info.compCallConv == CorInfoCallConvExtension::Swift) && - lvaInitSpecialSwiftParam(varDscInfo, strip(corInfoType), typeHnd)) + if (info.compCallConv == CorInfoCallConvExtension::Swift) { - continue; + if (varTypeIsSIMD(varDsc)) + { + IMPL_LIMITATION("SIMD types are currently unsupported in Swift reverse pinvokes"); + } + + if (lvaInitSpecialSwiftParam(varDscInfo, strip(corInfoType), typeHnd)) + { + continue; + } + + if (varDsc->TypeGet() == TYP_STRUCT) + { + // Struct parameters are lowered to separate primitives in the + // Swift calling convention. We cannot handle these patterns + // efficiently, so we always DNER them and home them to stack + // in the prolog. + lvaSetVarDoNotEnregister(varDscInfo->varNum DEBUGARG(DoNotEnregisterReason::IsStructArg)); + } } #endif @@ -1647,6 +1663,14 @@ void Compiler::lvaClassifyParameterABI(Classifier& classifier) #endif lvaParameterPassingInfo[i] = classifier.Classify(this, dsc->TypeGet(), structLayout, wellKnownArg); + +#ifdef DEBUG + if (verbose) + { + printf("Parameter #%u ABI info: ", i); + lvaParameterPassingInfo[i].Dump(); + } +#endif } } From 10bbcceb899b3b7ff47bea4d4d85319e5c0aa84b Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 16:17:51 +0100 Subject: [PATCH 17/52] Fix build --- src/coreclr/jit/abi.cpp | 40 +++++++++++++-------------- src/coreclr/jit/codegen.h | 2 +- src/coreclr/jit/codegencommon.cpp | 46 ++++++++++++++++--------------- 3 files changed, 45 insertions(+), 43 deletions(-) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index ac1d78932bf3ee..597a472d386e1e 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -69,34 +69,34 @@ var_types ABIPassingSegment::GetRegisterStoreType() const { switch (Size) { - case 4: - return TYP_FLOAT; - case 8: - return TYP_DOUBLE; + case 4: + return TYP_FLOAT; + case 8: + return TYP_DOUBLE; #ifdef FEATURE_SIMD - case 16: - return TYP_SIMD16; - default: - return TYP_UNDEF; + case 16: + return TYP_SIMD16; #endif + default: + return TYP_UNDEF; } } else { switch (Size) { - case 1: - return TYP_UBYTE; - case 2: - return TYP_USHORT; - case 4: - return TYP_INT; + case 1: + return TYP_UBYTE; + case 2: + return TYP_USHORT; + case 4: + return TYP_INT; #ifdef TARGET_64BIT - case 8: - return TYP_LONG; + case 8: + return TYP_LONG; #endif - default: - return TYP_UNDEF; + default: + return TYP_UNDEF; } } } @@ -300,7 +300,7 @@ ABIPassingInformation SwiftABIClassifier::Classify(Compiler* comp, ArrayStack segments(comp->getAllocator(CMK_ABI)); for (unsigned i = 0; i < lowering->numLoweredElements; i++) { - var_types elemType = JITtype2varType(lowering->loweredElements[i]); + var_types elemType = JITtype2varType(lowering->loweredElements[i]); ABIPassingInformation elemInfo = m_classifier.Classify(comp, elemType, nullptr, WellKnownArg::None); for (unsigned j = 0; j < elemInfo.NumSegments; j++) @@ -313,7 +313,7 @@ ABIPassingInformation SwiftABIClassifier::Classify(Compiler* comp, ABIPassingInformation result; result.NumSegments = static_cast(segments.Height()); - result.Segments = new (comp, CMK_ABI) ABIPassingSegment[result.NumSegments]; + result.Segments = new (comp, CMK_ABI) ABIPassingSegment[result.NumSegments]; for (int i = 0; i < segments.Height(); i++) { result.Segments[i] = segments.Bottom(i); diff --git a/src/coreclr/jit/codegen.h b/src/coreclr/jit/codegen.h index c155421ae65870..d99e86d2aa28d1 100644 --- a/src/coreclr/jit/codegen.h +++ b/src/coreclr/jit/codegen.h @@ -277,7 +277,7 @@ class CodeGen final : public CodeGenInterface void genEnregisterOSRArgsAndLocals(); #endif - void genHomeSwiftStructParameters(regNumber initReg, bool *initRegZeroed); + void genHomeSwiftStructParameters(regNumber initReg, bool* initRegZeroed); void genCheckUseBlockInit(); #if defined(UNIX_AMD64_ABI) && defined(FEATURE_SIMD) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index fe373eb0db155e..8c3d5026736ce4 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -4976,12 +4976,12 @@ void CodeGen::genEnregisterOSRArgsAndLocals() } #ifdef SWIFT_SUPPORT -void CodeGen::genHomeSwiftStructParameters(regNumber initReg, bool *initRegZeroed) +void CodeGen::genHomeSwiftStructParameters(regNumber initReg, bool* initRegZeroed) { for (unsigned lclNum = 0; lclNum < compiler->info.compArgsCount; lclNum++) { LclVarDsc* dsc = compiler->lvaGetDesc(lclNum); - if ((dsc->TypeGet() != TYP_STRUCT) || dsc->lvIsImplicitByRef) + if ((dsc->TypeGet() != TYP_STRUCT) || compiler->lvaIsImplicitByRefLocal(lclNum)) { continue; } @@ -4997,28 +4997,29 @@ void CodeGen::genHomeSwiftStructParameters(regNumber initReg, bool *initRegZeroe { var_types storeType = seg.GetRegisterStoreType(); assert(storeType != TYP_UNDEF); - GetEmitter()->emitIns_S_R(ins_Store(storeType), emitTypeSize(storeType), seg.GetRegister(), lclNum, seg.Offset); + GetEmitter()->emitIns_S_R(ins_Store(storeType), emitTypeSize(storeType), seg.GetRegister(), lclNum, + seg.Offset); } else { var_types loadType = TYP_UNDEF; switch (seg.Size) { - case 1: - loadType = TYP_UBYTE; - break; - case 2: - loadType = TYP_USHORT; - break; - case 4: - loadType = TYP_INT; - break; - case 8: - loadType = TYP_LONG; - break; - default: - assert(!"Unexpected segment size for struct parameter not passed implicitly by ref"); - continue; + case 1: + loadType = TYP_UBYTE; + break; + case 2: + loadType = TYP_USHORT; + break; + case 4: + loadType = TYP_INT; + break; + case 8: + loadType = TYP_LONG; + break; + default: + assert(!"Unexpected segment size for struct parameter not passed implicitly by ref"); + continue; } ssize_t offset; @@ -5036,7 +5037,8 @@ void CodeGen::genHomeSwiftStructParameters(regNumber initReg, bool *initRegZeroe #endif offset += (ssize_t)seg.GetStackOffset(); - genInstrWithConstant(ins_Load(loadType), emitTypeSize(loadType), initReg, genFramePointerReg(), offset, initReg); + genInstrWithConstant(ins_Load(loadType), emitTypeSize(loadType), initReg, genFramePointerReg(), offset, + initReg); *initRegZeroed = false; GetEmitter()->emitIns_S_R(ins_Store(loadType), emitTypeSize(loadType), initReg, lclNum, seg.Offset); @@ -6306,9 +6308,9 @@ void CodeGen::genFnProlog() genClearStackVec3ArgUpperBits(); #endif // UNIX_AMD64_ABI && FEATURE_SIMD - /*----------------------------------------------------------------------------- - * Take care of register arguments first - */ +/*----------------------------------------------------------------------------- + * Take care of register arguments first + */ #ifdef SWIFT_SUPPORT if ((compiler->lvaSwiftSelfArg != BAD_VAR_NUM) && ((intRegState.rsCalleeRegArgMaskLiveIn & RBM_SWIFT_SELF) != 0)) From 6d2a284b78d4760d0b77db9efe96b8935a1248f2 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 16:22:13 +0100 Subject: [PATCH 18/52] More fixes --- src/coreclr/jit/codegencommon.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 8c3d5026736ce4..e75e0a3609e466 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -5022,7 +5022,7 @@ void CodeGen::genHomeSwiftStructParameters(regNumber initReg, bool* initRegZeroe continue; } - ssize_t offset; + int offset; if (isFramePointerUsed()) { offset = -genCallerSPtoFPdelta(); @@ -5032,13 +5032,16 @@ void CodeGen::genHomeSwiftStructParameters(regNumber initReg, bool* initRegZeroe offset = -genCallerSPtoInitialSPdelta(); } + + offset += (int)seg.GetStackOffset(); + #ifdef TARGET_XARCH offset += TARGET_POINTER_SIZE; // Return address -#endif - - offset += (ssize_t)seg.GetStackOffset(); + GetEmitter()->emitIns_R_AR(ins_Load(loadType), emitTypeSize(loadType), initReg, genFramePointerReg(), offset); +#else genInstrWithConstant(ins_Load(loadType), emitTypeSize(loadType), initReg, genFramePointerReg(), offset, initReg); +#endif *initRegZeroed = false; GetEmitter()->emitIns_S_R(ins_Store(loadType), emitTypeSize(loadType), initReg, lclNum, seg.Offset); From 90bab28aaada4ec9b5271e41e4db8e868d6c23cb Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 16:47:26 +0100 Subject: [PATCH 19/52] Check for swift call conv --- src/coreclr/jit/codegencommon.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index e75e0a3609e466..0c03cb503d0c60 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -6316,13 +6316,16 @@ void CodeGen::genFnProlog() */ #ifdef SWIFT_SUPPORT - if ((compiler->lvaSwiftSelfArg != BAD_VAR_NUM) && ((intRegState.rsCalleeRegArgMaskLiveIn & RBM_SWIFT_SELF) != 0)) + if (compiler->info.compCallConv == CorInfoCallConvExtension::Swift) { - GetEmitter()->emitIns_S_R(ins_Store(TYP_I_IMPL), EA_PTRSIZE, REG_SWIFT_SELF, compiler->lvaSwiftSelfArg, 0); - intRegState.rsCalleeRegArgMaskLiveIn &= ~RBM_SWIFT_SELF; - } + if ((compiler->lvaSwiftSelfArg != BAD_VAR_NUM) && ((intRegState.rsCalleeRegArgMaskLiveIn & RBM_SWIFT_SELF) != 0)) + { + GetEmitter()->emitIns_S_R(ins_Store(TYP_I_IMPL), EA_PTRSIZE, REG_SWIFT_SELF, compiler->lvaSwiftSelfArg, 0); + intRegState.rsCalleeRegArgMaskLiveIn &= ~RBM_SWIFT_SELF; + } - genHomeSwiftStructParameters(initReg, &initRegZeroed); + genHomeSwiftStructParameters(initReg, &initRegZeroed); + } #endif // Home incoming arguments and generate any required inits. From b5586dacbab7031b15c8a76f1d0ee5882cce756b Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 17:29:04 +0100 Subject: [PATCH 20/52] More --- src/coreclr/jit/abi.cpp | 38 ++++++++++++++++++++++++++++ src/coreclr/jit/abi.h | 2 ++ src/coreclr/jit/codegencommon.cpp | 5 ++++ src/coreclr/jit/compiler.cpp | 8 +++--- src/coreclr/jit/compiler.h | 8 +++--- src/coreclr/jit/lclvars.cpp | 41 ++++++++++++++++++++++++++++++- 6 files changed, 93 insertions(+), 9 deletions(-) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index 597a472d386e1e..cf5e0a2588a5e0 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -148,6 +148,44 @@ ABIPassingSegment ABIPassingSegment::OnStack(unsigned stackOffset, unsigned offs return segment; } +//----------------------------------------------------------------------------- +// HasAnyRegisterSegment: +// Check if any part of this value is passed in a register. +// +// Return Value: +// True if so. +// +bool ABIPassingInformation::HasAnyRegisterSegment() const +{ + for (unsigned i = 0; i < NumSegments; i++) + { + if (Segments[i].IsPassedInRegister()) + { + return true; + } + } + return false; +} + +//----------------------------------------------------------------------------- +// HasAnyStackSegment: +// Check if any part of this value is passed on the stack. +// +// Return Value: +// True if so. +// +bool ABIPassingInformation::HasAnyStackSegment() const +{ + for (unsigned i = 0; i < NumSegments; i++) + { + if (Segments[i].IsPassedOnStack()) + { + return true; + } + } + return false; +} + //----------------------------------------------------------------------------- // IsSplitAcrossRegistersAndStack: // Check if this ABIPassingInformation represents passing a value in both diff --git a/src/coreclr/jit/abi.h b/src/coreclr/jit/abi.h index 7f358caa4a6d8b..a5c11b31cc60e6 100644 --- a/src/coreclr/jit/abi.h +++ b/src/coreclr/jit/abi.h @@ -49,6 +49,8 @@ struct ABIPassingInformation unsigned NumSegments = 0; ABIPassingSegment* Segments = nullptr; + bool HasAnyRegisterSegment() const; + bool HasAnyStackSegment() const; bool IsSplitAcrossRegistersAndStack() const; static ABIPassingInformation FromSegment(Compiler* comp, const ABIPassingSegment& segment); diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 0c03cb503d0c60..84fce7379ca83b 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -4980,6 +4980,11 @@ void CodeGen::genHomeSwiftStructParameters(regNumber initReg, bool* initRegZeroe { for (unsigned lclNum = 0; lclNum < compiler->info.compArgsCount; lclNum++) { + if (lclNum == compiler->lvaSwiftSelfArg) + { + continue; + } + LclVarDsc* dsc = compiler->lvaGetDesc(lclNum); if ((dsc->TypeGet() != TYP_STRUCT) || compiler->lvaIsImplicitByRefLocal(lclNum)) { diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index f85029179f966b..dad698830a35c6 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -604,10 +604,10 @@ var_types Compiler::getPrimitiveTypeForStruct(unsigned structSize, CORINFO_CLASS // If there are two or more elements in the HFA type then the this method's // return value is TYP_STRUCT and *wbPassStruct is SPK_ByValueAsHfa // -var_types Compiler::getArgTypeForStruct(CORINFO_CLASS_HANDLE clsHnd, - structPassingKind* wbPassStruct, - bool isVarArg, - unsigned structSize) +var_types Compiler::getArgTypeForStruct(CORINFO_CLASS_HANDLE clsHnd, + structPassingKind* wbPassStruct, + bool isVarArg, + unsigned structSize) { var_types useType = TYP_UNKNOWN; structPassingKind howToPassStruct = SPK_Unknown; // We must change this before we return diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 5d85ec124c3f6c..02cfc4467d4fde 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -5795,10 +5795,10 @@ class Compiler // isVarArg is passed for use on Windows Arm64 to change the decision returned regarding // hfa types. // - var_types getArgTypeForStruct(CORINFO_CLASS_HANDLE clsHnd, - structPassingKind* wbPassStruct, - bool isVarArg, - unsigned structSize); + var_types getArgTypeForStruct(CORINFO_CLASS_HANDLE clsHnd, + structPassingKind* wbPassStruct, + bool isVarArg, + unsigned structSize); // Get the type that is used to return values of the given struct type. // If the size is unknown, pass 0 and it will be determined from 'clsHnd'. diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index dbf3bbadeab48d..00d89e8b93b29a 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1696,6 +1696,40 @@ void Compiler::lvaClassifyParameterABI() { SwiftABIClassifier classifier(cInfo); lvaClassifyParameterABI(classifier); + + // The calling convention details computed by the old ABI classifier + // are wrong due to Swift structs. Grab them from the new ABI + // information. + for (unsigned lclNum = 0; lclNum < info.compArgsCount; lclNum++) + { + LclVarDsc* dsc = lvaGetDesc(lclNum); + const ABIPassingInformation& abiInfo = lvaParameterPassingInfo[lclNum]; + + if (dsc->TypeGet() != TYP_STRUCT) + { + assert(abiInfo.NumSegments == 1); + if (abiInfo.Segments[0].IsPassedInRegister()) + { + dsc->lvIsRegArg = true; + dsc->SetArgReg(abiInfo.Segments[0].GetRegister()); + dsc->SetOtherArgReg(REG_NA); + } + else + { + dsc->lvIsRegArg = false; + dsc->SetArgReg(REG_STK); + dsc->SetOtherArgReg(REG_NA); + dsc->SetStackOffset(abiInfo.Segments[0].GetStackOffset()); + } + } + else + { +#if FEATURE_IMPLICIT_BYREFS + const CORINFO_SWIFT_LOWERING* lowering = GetSwiftLowering(dsc->GetLayout()->GetClassHandle()); + dsc->lvIsImplicitByRef = lowering->byReference; +#endif + } + } } else #endif @@ -1719,6 +1753,11 @@ void Compiler::lvaClassifyParameterABI() assert(abiInfo.NumSegments > 0); + if ((dsc->TypeGet() == TYP_STRUCT) && info.compCallConv == CorInfoCallConvExtension::Swift) + { + continue; + } + unsigned numSegmentsToCompare = abiInfo.NumSegments; if (dsc->lvIsHfa()) { @@ -3132,7 +3171,7 @@ void Compiler::lvaSetStruct(unsigned varNum, ClassLayout* layout, bool unsafeVal if (varDsc->lvIsParam && !varDsc->lvIsStructField) { structPassingKind howToReturnStruct; - getArgTypeForStruct(layout->GetClassHandle(), &howToReturnStruct, this->info.compIsVarArgs, + getArgTypeForStruct(layout->GetClassHandle(), &howToReturnStruct, info.compIsVarArgs, varDsc->lvExactSize()); if (howToReturnStruct == SPK_ByReference) From a17cdeb9c594ea4787f9e8f16c39bf08f306f376 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 17:38:43 +0100 Subject: [PATCH 21/52] More fixing --- src/coreclr/jit/codegencommon.cpp | 9 +++++++++ src/coreclr/jit/lclvars.cpp | 22 ++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 84fce7379ca83b..07063540b376dd 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -5004,6 +5004,15 @@ void CodeGen::genHomeSwiftStructParameters(regNumber initReg, bool* initRegZeroe assert(storeType != TYP_UNDEF); GetEmitter()->emitIns_S_R(ins_Store(storeType), emitTypeSize(storeType), seg.GetRegister(), lclNum, seg.Offset); + + if (genIsValidFloatReg(seg.GetRegister())) + { + floatRegState.rsCalleeRegArgMaskLiveIn &= ~genRegMask(seg.GetRegister()); + } + else + { + intRegState.rsCalleeRegArgMaskLiveIn &= ~genRegMask(seg.GetRegister()); + } } else { diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 00d89e8b93b29a..734ddc1a8406a7 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1705,7 +1705,19 @@ void Compiler::lvaClassifyParameterABI() LclVarDsc* dsc = lvaGetDesc(lclNum); const ABIPassingInformation& abiInfo = lvaParameterPassingInfo[lclNum]; - if (dsc->TypeGet() != TYP_STRUCT) +#if FEATURE_IMPLICIT_BYREFS + if (dsc->TypeGet() == TYP_STRUCT) + { + const CORINFO_SWIFT_LOWERING* lowering = GetSwiftLowering(dsc->GetLayout()->GetClassHandle()); + dsc->lvIsImplicitByRef = lowering->byReference; + } +#endif + + if ((dsc->TypeGet() == TYP_STRUCT) && !lvaIsImplicitByRefLocal(lclNum)) + { + dsc->lvIsRegArg = false; + } + else { assert(abiInfo.NumSegments == 1); if (abiInfo.Segments[0].IsPassedInRegister()) @@ -1721,13 +1733,7 @@ void Compiler::lvaClassifyParameterABI() dsc->SetOtherArgReg(REG_NA); dsc->SetStackOffset(abiInfo.Segments[0].GetStackOffset()); } - } - else - { -#if FEATURE_IMPLICIT_BYREFS - const CORINFO_SWIFT_LOWERING* lowering = GetSwiftLowering(dsc->GetLayout()->GetClassHandle()); - dsc->lvIsImplicitByRef = lowering->byReference; -#endif + } } } From 6214044025dad4acb9ce4bfc974c705e87aea8e4 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 26 Mar 2024 17:48:01 +0100 Subject: [PATCH 22/52] Fix further --- src/coreclr/jit/lclvars.cpp | 1 - src/coreclr/jit/lsrabuild.cpp | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 734ddc1a8406a7..51102b91be69f5 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1733,7 +1733,6 @@ void Compiler::lvaClassifyParameterABI() dsc->SetOtherArgReg(REG_NA); dsc->SetStackOffset(abiInfo.Segments[0].GetStackOffset()); } - } } } diff --git a/src/coreclr/jit/lsrabuild.cpp b/src/coreclr/jit/lsrabuild.cpp index 0eba0d6b19bdc2..ecdf1e02be33fe 100644 --- a/src/coreclr/jit/lsrabuild.cpp +++ b/src/coreclr/jit/lsrabuild.cpp @@ -2290,6 +2290,25 @@ void LinearScan::buildIntervals() regsInUseThisLocation = RBM_NONE; regsInUseNextLocation = RBM_NONE; +#ifdef SWIFT_SUPPORT + if (compiler->info.compCallConv == CorInfoCallConvExtension::Swift) + { + for (unsigned lclNum = 0; lclNum < compiler->info.compArgsCount; lclNum++) + { + const ABIPassingInformation& abiInfo = compiler->lvaParameterPassingInfo[lclNum]; + for (unsigned i = 0; i < abiInfo.NumSegments; i++) + { + const ABIPassingSegment& seg = abiInfo.Segments[i]; + if (seg.IsPassedInRegister()) + { + RegState* regState = genIsValidFloatReg(seg.GetRegister()) ? floatRegState : intRegState; + regState->rsCalleeRegArgMaskLiveIn |= genRegMask(seg.GetRegister()); + } + } + } + } +#endif + for (unsigned int varIndex = 0; varIndex < compiler->lvaTrackedCount; varIndex++) { LclVarDsc* argDsc = compiler->lvaGetDescByTrackedIndex(varIndex); From 60eecf146c0fb2a412d2d2b7c25c495ca812a7ee Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 27 Mar 2024 10:53:40 +0100 Subject: [PATCH 23/52] Fixes --- src/coreclr/jit/compiler.h | 2 + src/coreclr/jit/lclvars.cpp | 117 +++++++++++++++++++++++++----------- 2 files changed, 84 insertions(+), 35 deletions(-) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 02cfc4467d4fde..28c92062aee748 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -3930,12 +3930,14 @@ class Compiler void lvaUpdateArgWithInitialReg(LclVarDsc* varDsc); void lvaUpdateArgsWithInitialReg(); void lvaAssignVirtualFrameOffsetsToArgs(); + void lvaAssignVirtualFrameOffsetsToSwiftFuncArgs(); #ifdef UNIX_AMD64_ABI int lvaAssignVirtualFrameOffsetToArg(unsigned lclNum, unsigned argSize, int argOffs, int* callerArgOffset); #else // !UNIX_AMD64_ABI int lvaAssignVirtualFrameOffsetToArg(unsigned lclNum, unsigned argSize, int argOffs); #endif // !UNIX_AMD64_ABI void lvaAssignVirtualFrameOffsetsToLocals(); + bool lvaParamShouldHaveLocalStackSpace(unsigned lclNum); int lvaAllocLocalAndSetVirtualOffset(unsigned lclNum, unsigned size, int stkOffs); #ifdef TARGET_AMD64 // Returns true if compCalleeRegsPushed (including RBP if used as frame pointer) is even. diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 51102b91be69f5..b5416e95217905 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1698,8 +1698,8 @@ void Compiler::lvaClassifyParameterABI() lvaClassifyParameterABI(classifier); // The calling convention details computed by the old ABI classifier - // are wrong due to Swift structs. Grab them from the new ABI - // information. + // are wrong since it does not handle the Swift ABI for structs + // appropriately. Grab them from the new ABI information. for (unsigned lclNum = 0; lclNum < info.compArgsCount; lclNum++) { LclVarDsc* dsc = lvaGetDesc(lclNum); @@ -5751,6 +5751,17 @@ void Compiler::lvaAssignVirtualFrameOffsetsToArgs() // Update the arg initial register locations. lvaUpdateArgsWithInitialReg(); +#ifdef SWIFT_SUPPORT + if (info.compCallConv == CorInfoCallConvExtension::Swift) + { + // We already assigned argument offsets in lvaClassifyParameterABI. + // TODO-Cleanup: We actually assign the stack offsets in the front + // always, even outside the Swift calling convention, so likely this + // entire function can be deleted. + return; + } +#endif + /* Is there a "this" argument? */ if (!info.compIsStatic) @@ -5928,6 +5939,15 @@ void Compiler::lvaAssignVirtualFrameOffsetsToArgs() #endif // USER_ARGS_COME_LAST } +//------------------------------------------------------------------------ +// lvaAssignVirtualFrameOffsetsToSwiftFuncArgs: +// Assign stack frame offsets for the arguments to a CallConvSwift function. +// +void Compiler::lvaAssignVirtualFrameOffsetsToSwiftFuncArgs() +{ + +} + #ifdef UNIX_AMD64_ABI // // lvaAssignVirtualFrameOffsetToArg() : Assign virtual stack offsets to an @@ -6932,22 +6952,6 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals() if (varDsc->lvIsParam) { -#if defined(TARGET_AMD64) && !defined(UNIX_AMD64_ABI) - - // On Windows AMD64 we can use the caller-reserved stack area that is already setup - assert(varDsc->GetStackOffset() != BAD_STK_OFFS); - continue; - -#else // !TARGET_AMD64 - - // A register argument that is not enregistered ends up as - // a local variable which will need stack frame space. - // - if (!varDsc->lvIsRegArg) - { - continue; - } - #ifdef TARGET_ARM64 if (info.compIsVarArgs && (varDsc->GetArgReg() != theFixedRetBuffReg(info.compCallConv))) { @@ -6956,21 +6960,12 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals() varDsc->SetStackOffset(-initialStkOffs + regArgNum * REGSIZE_BYTES); continue; } - #endif -#ifdef TARGET_ARM - // On ARM we spill the registers in codeGen->regSet.rsMaskPreSpillRegArg - // in the prolog, thus they don't need stack frame space. - // - if ((codeGen->regSet.rsMaskPreSpillRegs(false) & genRegMask(varDsc->GetArgReg())) != 0) + if (!lvaParamShouldHaveLocalStackSpace(lclNum)) { - assert(varDsc->GetStackOffset() != BAD_STK_OFFS); continue; } -#endif - -#endif // !TARGET_AMD64 } /* Make sure the type is appropriate */ @@ -7052,11 +7047,10 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals() // Reserve the stack space for this variable stkOffs = lvaAllocLocalAndSetVirtualOffset(lclNum, lvaLclSize(lclNum), stkOffs); -#if defined(TARGET_ARMARCH) || defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64) - // If we have an incoming register argument that has a promoted field then we - // need to copy the lvStkOff (the stack home) from the reg arg to the field lclvar - // - if (varDsc->lvIsRegArg && varDsc->lvPromoted) + + // Propagate the stack allocation to the fields for a dependently + // promoted struct. + if (lvaGetPromotionType(lclNum) == PROMOTION_TYPE_DEPENDENT) { unsigned firstFieldNum = varDsc->lvFieldLclStart; for (unsigned i = 0; i < varDsc->lvFieldCnt; i++) @@ -7065,7 +7059,6 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals() fieldVarDsc->SetStackOffset(varDsc->GetStackOffset() + fieldVarDsc->lvFldOffset); } } -#endif // defined(TARGET_ARMARCH) || defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64) } } @@ -7224,6 +7217,60 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals() (unsigned)-(stkOffs + (pushedCount * (int)TARGET_POINTER_SIZE))); } +//------------------------------------------------------------------------ +// lvaParamShouldHaveLocalStackSpace: Check if a local that represents a +// parameter should be allocated as part of the locals space. +// +// Arguments: +// lclNum - the variable number +// +// Return Value: +// true if the local does not have reusable stack space passed by the caller +// already. +// +bool Compiler::lvaParamShouldHaveLocalStackSpace(unsigned lclNum) +{ + LclVarDsc* varDsc = lvaGetDesc(lclNum); + +#ifdef SWIFT_SUPPORT + // In Swift functions, struct parameters that are no passed implicitly by + // reference are always reassembled on the local stack frame since their + // passing is decomposed. + if ((info.compCallConv == CorInfoCallConvExtension::Swift) && (varDsc->TypeGet() == TYP_STRUCT) && !lvaIsImplicitByRefLocal(lclNum)) + { + return true; + } +#endif + +#if defined(WINDOWS_AMD64_ABI) + // On Windows AMD64 we can use the caller-reserved stack area that is already setup + return false; +#else // !WINDOWS_AMD64_ABI + + // A register argument that is not enregistered ends up as + // a local variable which will need stack frame space. + // + if (!varDsc->lvIsRegArg) + { + return false; + } + +#ifdef TARGET_ARM + // On ARM we spill the registers in codeGen->regSet.rsMaskPreSpillRegArg + // in the prolog, thus they don't need stack frame space. + // + if ((codeGen->regSet.rsMaskPreSpillRegs(false) & genRegMask(varDsc->GetArgReg())) != 0) + { + assert(varDsc->GetStackOffset() != BAD_STK_OFFS); + return false; + } +#endif + +#endif // !WINDOWS_AMD64_ABI + + return true; +} + int Compiler::lvaAllocLocalAndSetVirtualOffset(unsigned lclNum, unsigned size, int stkOffs) { noway_assert(lclNum != BAD_VAR_NUM); @@ -8118,7 +8165,7 @@ unsigned Compiler::lvaFrameSize(FrameLayoutState curState) // // Return Value: // The offset. - +// int Compiler::lvaGetSPRelativeOffset(unsigned varNum) { assert(!compLocallocUsed); From 10d1f3be89c078fd35adc51bf22aea147f9c1173 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 27 Mar 2024 11:23:22 +0100 Subject: [PATCH 24/52] More fixing --- src/coreclr/jit/lclvars.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index b5416e95217905..9cc6171268769f 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -469,14 +469,14 @@ void Compiler::lvaInitArgs(InitVarDscInfo* varDscInfo) // We have set info.compArgsCount in compCompile() noway_assert(varDscInfo->varNum == info.compArgsCount); - // Now we have parameters created in the right order. Figure out how they're passed. - lvaClassifyParameterABI(); - assert(varDscInfo->intRegArgNum <= MAX_REG_ARG); codeGen->intRegState.rsCalleeRegArgCount = varDscInfo->intRegArgNum; codeGen->floatRegState.rsCalleeRegArgCount = varDscInfo->floatRegArgNum; + // Now we have parameters created in the right order. Figure out how they're passed. + lvaClassifyParameterABI(); + #if FEATURE_FASTTAILCALL // Save the stack usage information // We can get register usage information using codeGen->intRegState and @@ -1697,6 +1697,8 @@ void Compiler::lvaClassifyParameterABI() SwiftABIClassifier classifier(cInfo); lvaClassifyParameterABI(classifier); + regMaskTP argRegs = RBM_NONE; + // The calling convention details computed by the old ABI classifier // are wrong since it does not handle the Swift ABI for structs // appropriately. Grab them from the new ABI information. @@ -1734,7 +1736,20 @@ void Compiler::lvaClassifyParameterABI() dsc->SetStackOffset(abiInfo.Segments[0].GetStackOffset()); } } + + for (unsigned i = 0; i < abiInfo.NumSegments; i++) + { + const ABIPassingSegment& segment = abiInfo.Segments[i]; + if (segment.IsPassedInRegister()) + { + argRegs |= genRegMask(segment.GetRegister()); + } + } } + + // genFnPrologCalleeRegArgs expect these to be the counts of registers it knows how to handle. + codeGen->intRegState.rsCalleeRegArgCount = genCountBits(argRegs & (RBM_ARG_REGS | theFixedRetBuffMask(CorInfoCallConvExtension::Swift))); + codeGen->floatRegState.rsCalleeRegArgCount = genCountBits(argRegs & RBM_FLTARG_REGS); } else #endif @@ -7233,9 +7248,9 @@ bool Compiler::lvaParamShouldHaveLocalStackSpace(unsigned lclNum) LclVarDsc* varDsc = lvaGetDesc(lclNum); #ifdef SWIFT_SUPPORT - // In Swift functions, struct parameters that are no passed implicitly by - // reference are always reassembled on the local stack frame since their - // passing is decomposed. + // In Swift functions, struct parameters that are not passed implicitly by + // reference are always reassembled on the local stack frame since they are + // passed in a way that does not match their full layout. if ((info.compCallConv == CorInfoCallConvExtension::Swift) && (varDsc->TypeGet() == TYP_STRUCT) && !lvaIsImplicitByRefLocal(lclNum)) { return true; From 8db32afbe649789bda2db61d7f7ed712fefb648b Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 27 Mar 2024 11:28:20 +0100 Subject: [PATCH 25/52] Fix --- src/coreclr/jit/lclvars.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 9cc6171268769f..0a404b9890d6ac 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1748,7 +1748,7 @@ void Compiler::lvaClassifyParameterABI() } // genFnPrologCalleeRegArgs expect these to be the counts of registers it knows how to handle. - codeGen->intRegState.rsCalleeRegArgCount = genCountBits(argRegs & (RBM_ARG_REGS | theFixedRetBuffMask(CorInfoCallConvExtension::Swift))); + codeGen->intRegState.rsCalleeRegArgCount = genCountBits(argRegs & RBM_ARG_REGS); codeGen->floatRegState.rsCalleeRegArgCount = genCountBits(argRegs & RBM_FLTARG_REGS); } else From 1eab0d9d723c9952fa5938bb950b4fc561f8b32f Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 27 Mar 2024 13:45:47 +0100 Subject: [PATCH 26/52] Fix --- src/coreclr/jit/abi.cpp | 12 +++++++++++ src/coreclr/jit/abi.h | 1 + src/coreclr/jit/lclvars.cpp | 43 +++++++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index cf5e0a2588a5e0..092bbbde5a09ad 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -186,6 +186,18 @@ bool ABIPassingInformation::HasAnyStackSegment() const return false; } +//----------------------------------------------------------------------------- +// HasExactlyOneStackSegment: +// Check if this value is passed as a single stack segment. +// +// Return Value: +// True if so. +// +bool ABIPassingInformation::HasExactlyOneStackSegment() const +{ + return (NumSegments == 1) && Segments[0].IsPassedOnStack(); +} + //----------------------------------------------------------------------------- // IsSplitAcrossRegistersAndStack: // Check if this ABIPassingInformation represents passing a value in both diff --git a/src/coreclr/jit/abi.h b/src/coreclr/jit/abi.h index a5c11b31cc60e6..af5fd466f01fe1 100644 --- a/src/coreclr/jit/abi.h +++ b/src/coreclr/jit/abi.h @@ -51,6 +51,7 @@ struct ABIPassingInformation bool HasAnyRegisterSegment() const; bool HasAnyStackSegment() const; + bool HasExactlyOneStackSegment() const; bool IsSplitAcrossRegistersAndStack() const; static ABIPassingInformation FromSegment(Compiler* comp, const ABIPassingSegment& segment); diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 0a404b9890d6ac..e9a92341f28086 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1715,7 +1715,7 @@ void Compiler::lvaClassifyParameterABI() } #endif - if ((dsc->TypeGet() == TYP_STRUCT) && !lvaIsImplicitByRefLocal(lclNum)) + if ((dsc->TypeGet() == TYP_STRUCT) && !lvaIsImplicitByRefLocal(lclNum) && !abiInfo.HasExactlyOneStackSegment()) { dsc->lvIsRegArg = false; } @@ -5770,9 +5770,19 @@ void Compiler::lvaAssignVirtualFrameOffsetsToArgs() if (info.compCallConv == CorInfoCallConvExtension::Swift) { // We already assigned argument offsets in lvaClassifyParameterABI. - // TODO-Cleanup: We actually assign the stack offsets in the front - // always, even outside the Swift calling convention, so likely this - // entire function can be deleted. + // Just get them from there. + // TODO-Cleanup: We can use similar logic for all backends once we have + // the new ABI info for all targets. + for (unsigned lclNum = 0; lclNum < info.compArgsCount; lclNum++) + { + LclVarDsc* dsc = lvaGetDesc(lclNum); + const ABIPassingInformation& abiInfo = lvaParameterPassingInfo[lclNum]; + + if (abiInfo.HasExactlyOneStackSegment()) + { + dsc->SetStackOffset(abiInfo.Segments[0].GetStackOffset()); + } + } return; } #endif @@ -7062,10 +7072,11 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals() // Reserve the stack space for this variable stkOffs = lvaAllocLocalAndSetVirtualOffset(lclNum, lvaLclSize(lclNum), stkOffs); - - // Propagate the stack allocation to the fields for a dependently - // promoted struct. - if (lvaGetPromotionType(lclNum) == PROMOTION_TYPE_DEPENDENT) +#if defined(TARGET_ARMARCH) || defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64) + // If we have an incoming register argument that has a promoted field then we + // need to copy the lvStkOff (the stack home) from the reg arg to the field lclvar + // + if (varDsc->lvIsRegArg && varDsc->lvPromoted) { unsigned firstFieldNum = varDsc->lvFieldLclStart; for (unsigned i = 0; i < varDsc->lvFieldCnt; i++) @@ -7074,6 +7085,7 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals() fieldVarDsc->SetStackOffset(varDsc->GetStackOffset() + fieldVarDsc->lvFldOffset); } } +#endif // defined(TARGET_ARMARCH) || defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64) } } @@ -7248,10 +7260,13 @@ bool Compiler::lvaParamShouldHaveLocalStackSpace(unsigned lclNum) LclVarDsc* varDsc = lvaGetDesc(lclNum); #ifdef SWIFT_SUPPORT - // In Swift functions, struct parameters that are not passed implicitly by - // reference are always reassembled on the local stack frame since they are - // passed in a way that does not match their full layout. - if ((info.compCallConv == CorInfoCallConvExtension::Swift) && (varDsc->TypeGet() == TYP_STRUCT) && !lvaIsImplicitByRefLocal(lclNum)) + // In Swift functions, struct parameters that aren't passed in a single + // stack segment are always reassembled on the local stack frame since they + // are passed in a way that does not match their full layout. + if ((info.compCallConv == CorInfoCallConvExtension::Swift) && + (varDsc->TypeGet() == TYP_STRUCT) && + !lvaIsImplicitByRefLocal(lclNum) && + !lvaParameterPassingInfo[lclNum].HasExactlyOneStackSegment()) { return true; } @@ -7568,9 +7583,9 @@ void Compiler::lvaAssignFrameOffsetsToPromotedStructs() // const bool mustProcessParams = true; #else - // OSR must also assign offsets here. + // OSR/Swift must also assign offsets here. // - const bool mustProcessParams = opts.IsOSR(); + const bool mustProcessParams = opts.IsOSR() || (info.compCallConv == CorInfoCallConvExtension::Swift); #endif // defined(UNIX_AMD64_ABI) || defined(TARGET_ARM) || defined(TARGET_X86) if (varDsc->lvIsStructField && (!varDsc->lvIsParam || mustProcessParams)) From be0137ed0b5a01b5344f2b89c999d29e858c05c6 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 27 Mar 2024 14:20:12 +0100 Subject: [PATCH 27/52] Handle stack and registers separately --- src/coreclr/jit/codegen.h | 2 +- src/coreclr/jit/codegencommon.cpp | 35 ++++++++++++++++++++++++------- src/coreclr/jit/codegenlinear.cpp | 6 ++++++ src/coreclr/jit/compiler.h | 1 + src/coreclr/jit/flowgraph.cpp | 2 +- src/coreclr/jit/lclvars.cpp | 29 +++++++++++++++++++++++++ src/coreclr/jit/lsrabuild.cpp | 15 ++++++++++++- 7 files changed, 80 insertions(+), 10 deletions(-) diff --git a/src/coreclr/jit/codegen.h b/src/coreclr/jit/codegen.h index d99e86d2aa28d1..b559c0fdce6867 100644 --- a/src/coreclr/jit/codegen.h +++ b/src/coreclr/jit/codegen.h @@ -277,7 +277,7 @@ class CodeGen final : public CodeGenInterface void genEnregisterOSRArgsAndLocals(); #endif - void genHomeSwiftStructParameters(regNumber initReg, bool* initRegZeroed); + void genHomeSwiftStructParameters(bool handleStack, regNumber scratchReg, bool* scratchRegClobbered); void genCheckUseBlockInit(); #if defined(UNIX_AMD64_ABI) && defined(FEATURE_SIMD) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 07063540b376dd..af097f14dc33aa 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -4976,7 +4976,18 @@ void CodeGen::genEnregisterOSRArgsAndLocals() } #ifdef SWIFT_SUPPORT -void CodeGen::genHomeSwiftStructParameters(regNumber initReg, bool* initRegZeroed) + +//----------------------------------------------------------------------------- +// genHomeSwiftStructParameters: +// Reassemble Swift struct parameters if necessary. +// +// Parameters: +// handleStack - If true, reassemble the segments that were passed on the stack. +// If false, reassemble the segments that were passed in registers. +// scratchReg - A scratch register to use +// scratchRegClobbered - [out] if scratchReg is used, this will be set to true. Otherwise will not be set. +// +void CodeGen::genHomeSwiftStructParameters(bool handleStack, regNumber scratchReg, bool* scratchRegClobbered) { for (unsigned lclNum = 0; lclNum < compiler->info.compArgsCount; lclNum++) { @@ -4998,6 +5009,11 @@ void CodeGen::genHomeSwiftStructParameters(regNumber initReg, bool* initRegZeroe for (unsigned i = 0; i < abiInfo.NumSegments; i++) { const ABIPassingSegment& seg = abiInfo.Segments[i]; + if (seg.IsPassedOnStack() != handleStack) + { + continue; + } + if (seg.IsPassedInRegister()) { var_types storeType = seg.GetRegisterStoreType(); @@ -5051,14 +5067,14 @@ void CodeGen::genHomeSwiftStructParameters(regNumber initReg, bool* initRegZeroe #ifdef TARGET_XARCH offset += TARGET_POINTER_SIZE; // Return address - GetEmitter()->emitIns_R_AR(ins_Load(loadType), emitTypeSize(loadType), initReg, genFramePointerReg(), offset); + GetEmitter()->emitIns_R_AR(ins_Load(loadType), emitTypeSize(loadType), scratchReg, genFramePointerReg(), offset); #else - genInstrWithConstant(ins_Load(loadType), emitTypeSize(loadType), initReg, genFramePointerReg(), offset, - initReg); + genInstrWithConstant(ins_Load(loadType), emitTypeSize(loadType), scratchReg, genFramePointerReg(), offset, + scratchReg); #endif - *initRegZeroed = false; + *scratchRegClobbered = true; - GetEmitter()->emitIns_S_R(ins_Store(loadType), emitTypeSize(loadType), initReg, lclNum, seg.Offset); + GetEmitter()->emitIns_S_R(ins_Store(loadType), emitTypeSize(loadType), scratchReg, lclNum, seg.Offset); } } } @@ -6338,7 +6354,12 @@ void CodeGen::genFnProlog() intRegState.rsCalleeRegArgMaskLiveIn &= ~RBM_SWIFT_SELF; } - genHomeSwiftStructParameters(initReg, &initRegZeroed); + bool clobbered = false; + genHomeSwiftStructParameters(/* handleStack */ false, initReg, &clobbered); + if (clobbered) + { + initRegZeroed = false; + } } #endif diff --git a/src/coreclr/jit/codegenlinear.cpp b/src/coreclr/jit/codegenlinear.cpp index 78df10811a4c24..1f1a87499791e7 100644 --- a/src/coreclr/jit/codegenlinear.cpp +++ b/src/coreclr/jit/codegenlinear.cpp @@ -386,6 +386,12 @@ void CodeGen::genCodeForBBlist() compiler->compCurStmt = nullptr; compiler->compCurLifeTree = nullptr; + if (compiler->lvaHasAnySwiftStackParamToReassemble()) + { + bool clobbered = false; + genHomeSwiftStructParameters(/* handleStack */ true, REG_SCRATCH, &clobbered); + } + // Emit poisoning into scratch BB that comes right after prolog. // We cannot emit this code in the prolog as it might make the prolog too large. if (compiler->compShouldPoisonFrame() && compiler->fgBBisScratch(block)) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 28c92062aee748..8179a3bd9108b1 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -4002,6 +4002,7 @@ class Compiler void lvaClassifyParameterABI(); bool lvaInitSpecialSwiftParam(InitVarDscInfo* varDscInfo, CorInfoType type, CORINFO_CLASS_HANDLE typeHnd); + bool lvaHasAnySwiftStackParamToReassemble(); var_types lvaGetActualType(unsigned lclNum); var_types lvaGetRealType(unsigned lclNum); diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index 9b9f3a3f951418..3c8ba289b90870 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -2294,7 +2294,7 @@ PhaseStatus Compiler::fgAddInternal() // The backend requires a scratch BB into which it can safely insert a P/Invoke method prolog if one is // required. Similarly, we need a scratch BB for poisoning. Create it here. - if (compMethodRequiresPInvokeFrame() || compShouldPoisonFrame()) + if (compMethodRequiresPInvokeFrame() || compShouldPoisonFrame() || lvaHasAnySwiftStackParamToReassemble()) { madeChanges |= fgEnsureFirstBBisScratch(); fgFirstBB->SetFlags(BBF_DONT_REMOVE); diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index e9a92341f28086..90f5ab1092040f 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1825,6 +1825,35 @@ void Compiler::lvaClassifyParameterABI() #endif } +//-------------------------------------------------------------------------------------------- +// lvaHaveSwiftStructStackParamsToReassemble: +// Check if this compilation has any Swift parameters that are passed on the +// stack and that need to be reassembled on the local stack frame. +// +// Return value: +// True if so. +// +bool Compiler::lvaHasAnySwiftStackParamToReassemble() +{ +#ifdef SWIFT_SUPPORT + if (info.compCallConv != CorInfoCallConvExtension::Swift) + { + return false; + } + + for (unsigned lclNum = 0; lclNum < info.compArgsCount; lclNum++) + { + const ABIPassingInformation& abiInfo = lvaParameterPassingInfo[lclNum]; + if (abiInfo.HasAnyStackSegment() && !abiInfo.HasExactlyOneStackSegment()) + { + return true; + } + } +#endif + + return false; +} + /***************************************************************************** * Returns our internal varNum for a given IL variable. * Asserts assume it is called after lvaTable[] has been set up. diff --git a/src/coreclr/jit/lsrabuild.cpp b/src/coreclr/jit/lsrabuild.cpp index ecdf1e02be33fe..a13bea06f3c8e8 100644 --- a/src/coreclr/jit/lsrabuild.cpp +++ b/src/coreclr/jit/lsrabuild.cpp @@ -2527,11 +2527,24 @@ void LinearScan::buildIntervals() // assert(block->isRunRarely()); } + // For Swift calls there can be an arbitrary amount of codegen related + // to homing of decomposed struct parameters passed on stack. We cannot + // do that in the prolog. We handle registers in the prolog but the + // stack args in the scratch BB that we have ensured exists. + // in the scratch BB, but need REG_SCRATCH for it. + if ((block == compiler->fgFirstBB) && compiler->lvaHasAnySwiftStackParamToReassemble()) + { + assert(compiler->fgFirstBBisScratch()); + addRefsForPhysRegMask(genRegMask(REG_SCRATCH), currentLoc + 1, RefTypeKill, true); + currentLoc += 2; + } + // For frame poisoning we generate code into scratch BB right after prolog since // otherwise the prolog might become too large. In this case we will put the poison immediate // into the scratch register, so it will be killed here. - if (compiler->compShouldPoisonFrame() && compiler->fgFirstBBisScratch() && block == compiler->fgFirstBB) + if (compiler->compShouldPoisonFrame() && (block == compiler->fgFirstBB)) { + assert(compiler->fgFirstBBisScratch()); regMaskTP killed; #if defined(TARGET_XARCH) // Poisoning uses EAX for small vars and rep stosd that kills edi, ecx and eax for large vars. From 3faedce8a4d29c95ba3829d619b693bb03759be3 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 27 Mar 2024 14:22:55 +0100 Subject: [PATCH 28/52] More --- src/coreclr/jit/codegenlinear.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/codegenlinear.cpp b/src/coreclr/jit/codegenlinear.cpp index 1f1a87499791e7..c43486a0b30027 100644 --- a/src/coreclr/jit/codegenlinear.cpp +++ b/src/coreclr/jit/codegenlinear.cpp @@ -386,11 +386,16 @@ void CodeGen::genCodeForBBlist() compiler->compCurStmt = nullptr; compiler->compCurLifeTree = nullptr; - if (compiler->lvaHasAnySwiftStackParamToReassemble()) +#ifdef SWIFT_SUPPORT + // Reassemble Swift struct parameters on the local stack frame in the + // scratch BB right after the prolog. There can be arbitrary amounts of + // codegen related to doing this, so it cannot be done in the prolog. + if (compiler->fgBBisScratch(block) && compiler->lvaHasAnySwiftStackParamToReassemble()) { bool clobbered = false; genHomeSwiftStructParameters(/* handleStack */ true, REG_SCRATCH, &clobbered); } +#endif // Emit poisoning into scratch BB that comes right after prolog. // We cannot emit this code in the prolog as it might make the prolog too large. From 5b72eddaff72204fbae0106958beec4525b30f77 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 27 Mar 2024 15:10:57 +0100 Subject: [PATCH 29/52] Enable implicit byrefs on SysV x64 --- src/coreclr/jit/lclvars.cpp | 2 -- src/coreclr/jit/targetamd64.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 90f5ab1092040f..44e99ebeb282df 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1707,13 +1707,11 @@ void Compiler::lvaClassifyParameterABI() LclVarDsc* dsc = lvaGetDesc(lclNum); const ABIPassingInformation& abiInfo = lvaParameterPassingInfo[lclNum]; -#if FEATURE_IMPLICIT_BYREFS if (dsc->TypeGet() == TYP_STRUCT) { const CORINFO_SWIFT_LOWERING* lowering = GetSwiftLowering(dsc->GetLayout()->GetClassHandle()); dsc->lvIsImplicitByRef = lowering->byReference; } -#endif if ((dsc->TypeGet() == TYP_STRUCT) && !lvaIsImplicitByRefLocal(lclNum) && !abiInfo.HasExactlyOneStackSegment()) { diff --git a/src/coreclr/jit/targetamd64.h b/src/coreclr/jit/targetamd64.h index a15029c3c39249..49973f2f3cc53d 100644 --- a/src/coreclr/jit/targetamd64.h +++ b/src/coreclr/jit/targetamd64.h @@ -32,7 +32,7 @@ #define FEATURE_SET_FLAGS 0 // Set to true to force the JIT to mark the trees with GTF_SET_FLAGS when the flags need to be set #define MAX_PASS_SINGLEREG_BYTES 8 // Maximum size of a struct passed in a single register (double). #ifdef UNIX_AMD64_ABI - #define FEATURE_IMPLICIT_BYREFS 0 // Support for struct parameters passed via pointers to shadow copies + #define FEATURE_IMPLICIT_BYREFS 1 // Support for struct parameters passed via pointers to shadow copies #define FEATURE_MULTIREG_ARGS_OR_RET 1 // Support for passing and/or returning single values in more than one register #define FEATURE_MULTIREG_ARGS 1 // Support for passing a single argument in more than one register #define FEATURE_MULTIREG_RET 1 // Support for returning a single value in more than one register From 27cb1b16273e766ca3f75933de09c945abdc55f2 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 27 Mar 2024 15:26:04 +0100 Subject: [PATCH 30/52] Fix SysV x64 arg asserts --- src/coreclr/jit/emitxarch.cpp | 6 +----- src/coreclr/jit/lclvars.cpp | 15 ++++++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/coreclr/jit/emitxarch.cpp b/src/coreclr/jit/emitxarch.cpp index 1bafb6796d8075..379e94739b19b4 100644 --- a/src/coreclr/jit/emitxarch.cpp +++ b/src/coreclr/jit/emitxarch.cpp @@ -3827,11 +3827,7 @@ inline UNATIVE_OFFSET emitter::emitInsSizeSVCalcDisp(instrDesc* id, code_t code, /* Is this a stack parameter reference? */ - if ((emitComp->lvaIsParameter(var) -#if !defined(TARGET_AMD64) || defined(UNIX_AMD64_ABI) - && !emitComp->lvaIsRegArgument(var) -#endif // !TARGET_AMD64 || UNIX_AMD64_ABI - ) || + if ((emitComp->lvaIsParameter(var) && !emitComp->lvaParamShouldHaveLocalStackSpace(var)) || (static_cast(var) == emitComp->lvaRetAddrVar)) { /* If no EBP frame, arguments and ret addr are off of ESP, above temps */ diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 44e99ebeb282df..bd9c0b413cb6b5 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -7290,12 +7290,17 @@ bool Compiler::lvaParamShouldHaveLocalStackSpace(unsigned lclNum) // In Swift functions, struct parameters that aren't passed in a single // stack segment are always reassembled on the local stack frame since they // are passed in a way that does not match their full layout. - if ((info.compCallConv == CorInfoCallConvExtension::Swift) && - (varDsc->TypeGet() == TYP_STRUCT) && - !lvaIsImplicitByRefLocal(lclNum) && - !lvaParameterPassingInfo[lclNum].HasExactlyOneStackSegment()) + if ((info.compCallConv == CorInfoCallConvExtension::Swift)) { - return true; + unsigned baseLclNum = varDsc->lvIsStructField ? varDsc->lvParentLcl : lclNum; + LclVarDsc* baseDsc = lvaGetDesc(baseLclNum); + + if ((baseDsc->TypeGet() == TYP_STRUCT) && + !lvaIsImplicitByRefLocal(baseLclNum) && + !lvaParameterPassingInfo[baseLclNum].HasExactlyOneStackSegment()) + { + return true; + } } #endif From a99d809ac6d573b4c032b44ffb5277b15cc06bfd Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 27 Mar 2024 15:26:59 +0100 Subject: [PATCH 31/52] Fix warning --- src/coreclr/jit/lclvars.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index bd9c0b413cb6b5..9532f8af79eea4 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -7290,7 +7290,7 @@ bool Compiler::lvaParamShouldHaveLocalStackSpace(unsigned lclNum) // In Swift functions, struct parameters that aren't passed in a single // stack segment are always reassembled on the local stack frame since they // are passed in a way that does not match their full layout. - if ((info.compCallConv == CorInfoCallConvExtension::Swift)) + if (info.compCallConv == CorInfoCallConvExtension::Swift) { unsigned baseLclNum = varDsc->lvIsStructField ? varDsc->lvParentLcl : lclNum; LclVarDsc* baseDsc = lvaGetDesc(baseLclNum); From eab21e733f4064fa1a18ec94603ec2d65b8f1d2d Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 27 Mar 2024 15:47:17 +0100 Subject: [PATCH 32/52] Maybe fix? --- src/coreclr/jit/codegencommon.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index af097f14dc33aa..c032283f20dfc6 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -5066,7 +5066,6 @@ void CodeGen::genHomeSwiftStructParameters(bool handleStack, regNumber scratchRe offset += (int)seg.GetStackOffset(); #ifdef TARGET_XARCH - offset += TARGET_POINTER_SIZE; // Return address GetEmitter()->emitIns_R_AR(ins_Load(loadType), emitTypeSize(loadType), scratchReg, genFramePointerReg(), offset); #else genInstrWithConstant(ins_Load(loadType), emitTypeSize(loadType), scratchReg, genFramePointerReg(), offset, From b015690f5f2e75b8d13544a468f253f6eaddaf3d Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 27 Mar 2024 15:49:35 +0100 Subject: [PATCH 33/52] Run jit-format --- src/coreclr/jit/codegencommon.cpp | 11 ++++++----- src/coreclr/jit/compiler.cpp | 8 ++++---- src/coreclr/jit/lclvars.cpp | 21 ++++++++++----------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index c032283f20dfc6..916f1b8b104ac6 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -5062,14 +5062,14 @@ void CodeGen::genHomeSwiftStructParameters(bool handleStack, regNumber scratchRe offset = -genCallerSPtoInitialSPdelta(); } - offset += (int)seg.GetStackOffset(); #ifdef TARGET_XARCH - GetEmitter()->emitIns_R_AR(ins_Load(loadType), emitTypeSize(loadType), scratchReg, genFramePointerReg(), offset); + GetEmitter()->emitIns_R_AR(ins_Load(loadType), emitTypeSize(loadType), scratchReg, genFramePointerReg(), + offset); #else - genInstrWithConstant(ins_Load(loadType), emitTypeSize(loadType), scratchReg, genFramePointerReg(), offset, - scratchReg); + genInstrWithConstant(ins_Load(loadType), emitTypeSize(loadType), scratchReg, genFramePointerReg(), + offset, scratchReg); #endif *scratchRegClobbered = true; @@ -6347,7 +6347,8 @@ void CodeGen::genFnProlog() #ifdef SWIFT_SUPPORT if (compiler->info.compCallConv == CorInfoCallConvExtension::Swift) { - if ((compiler->lvaSwiftSelfArg != BAD_VAR_NUM) && ((intRegState.rsCalleeRegArgMaskLiveIn & RBM_SWIFT_SELF) != 0)) + if ((compiler->lvaSwiftSelfArg != BAD_VAR_NUM) && + ((intRegState.rsCalleeRegArgMaskLiveIn & RBM_SWIFT_SELF) != 0)) { GetEmitter()->emitIns_S_R(ins_Store(TYP_I_IMPL), EA_PTRSIZE, REG_SWIFT_SELF, compiler->lvaSwiftSelfArg, 0); intRegState.rsCalleeRegArgMaskLiveIn &= ~RBM_SWIFT_SELF; diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index dad698830a35c6..f85029179f966b 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -604,10 +604,10 @@ var_types Compiler::getPrimitiveTypeForStruct(unsigned structSize, CORINFO_CLASS // If there are two or more elements in the HFA type then the this method's // return value is TYP_STRUCT and *wbPassStruct is SPK_ByValueAsHfa // -var_types Compiler::getArgTypeForStruct(CORINFO_CLASS_HANDLE clsHnd, - structPassingKind* wbPassStruct, - bool isVarArg, - unsigned structSize) +var_types Compiler::getArgTypeForStruct(CORINFO_CLASS_HANDLE clsHnd, + structPassingKind* wbPassStruct, + bool isVarArg, + unsigned structSize) { var_types useType = TYP_UNKNOWN; structPassingKind howToPassStruct = SPK_Unknown; // We must change this before we return diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 9532f8af79eea4..3c527e8e7ebeae 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1704,16 +1704,17 @@ void Compiler::lvaClassifyParameterABI() // appropriately. Grab them from the new ABI information. for (unsigned lclNum = 0; lclNum < info.compArgsCount; lclNum++) { - LclVarDsc* dsc = lvaGetDesc(lclNum); + LclVarDsc* dsc = lvaGetDesc(lclNum); const ABIPassingInformation& abiInfo = lvaParameterPassingInfo[lclNum]; if (dsc->TypeGet() == TYP_STRUCT) { const CORINFO_SWIFT_LOWERING* lowering = GetSwiftLowering(dsc->GetLayout()->GetClassHandle()); - dsc->lvIsImplicitByRef = lowering->byReference; + dsc->lvIsImplicitByRef = lowering->byReference; } - if ((dsc->TypeGet() == TYP_STRUCT) && !lvaIsImplicitByRefLocal(lclNum) && !abiInfo.HasExactlyOneStackSegment()) + if ((dsc->TypeGet() == TYP_STRUCT) && !lvaIsImplicitByRefLocal(lclNum) && + !abiInfo.HasExactlyOneStackSegment()) { dsc->lvIsRegArg = false; } @@ -1746,7 +1747,7 @@ void Compiler::lvaClassifyParameterABI() } // genFnPrologCalleeRegArgs expect these to be the counts of registers it knows how to handle. - codeGen->intRegState.rsCalleeRegArgCount = genCountBits(argRegs & RBM_ARG_REGS); + codeGen->intRegState.rsCalleeRegArgCount = genCountBits(argRegs & RBM_ARG_REGS); codeGen->floatRegState.rsCalleeRegArgCount = genCountBits(argRegs & RBM_FLTARG_REGS); } else @@ -5802,7 +5803,7 @@ void Compiler::lvaAssignVirtualFrameOffsetsToArgs() // the new ABI info for all targets. for (unsigned lclNum = 0; lclNum < info.compArgsCount; lclNum++) { - LclVarDsc* dsc = lvaGetDesc(lclNum); + LclVarDsc* dsc = lvaGetDesc(lclNum); const ABIPassingInformation& abiInfo = lvaParameterPassingInfo[lclNum]; if (abiInfo.HasExactlyOneStackSegment()) @@ -5992,12 +5993,11 @@ void Compiler::lvaAssignVirtualFrameOffsetsToArgs() } //------------------------------------------------------------------------ -// lvaAssignVirtualFrameOffsetsToSwiftFuncArgs: +// lvaAssignVirtualFrameOffsetsToSwiftFuncArgs: // Assign stack frame offsets for the arguments to a CallConvSwift function. // void Compiler::lvaAssignVirtualFrameOffsetsToSwiftFuncArgs() { - } #ifdef UNIX_AMD64_ABI @@ -7292,11 +7292,10 @@ bool Compiler::lvaParamShouldHaveLocalStackSpace(unsigned lclNum) // are passed in a way that does not match their full layout. if (info.compCallConv == CorInfoCallConvExtension::Swift) { - unsigned baseLclNum = varDsc->lvIsStructField ? varDsc->lvParentLcl : lclNum; - LclVarDsc* baseDsc = lvaGetDesc(baseLclNum); + unsigned baseLclNum = varDsc->lvIsStructField ? varDsc->lvParentLcl : lclNum; + LclVarDsc* baseDsc = lvaGetDesc(baseLclNum); - if ((baseDsc->TypeGet() == TYP_STRUCT) && - !lvaIsImplicitByRefLocal(baseLclNum) && + if ((baseDsc->TypeGet() == TYP_STRUCT) && !lvaIsImplicitByRefLocal(baseLclNum) && !lvaParameterPassingInfo[baseLclNum].HasExactlyOneStackSegment()) { return true; From bae830c476fd84eb510ffddd98b606d39c897cfb Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 27 Mar 2024 15:59:50 +0100 Subject: [PATCH 34/52] Generate final tests --- .../SwiftCallbackAbiStress.cs | 8552 ++++++++++++++++- .../SwiftCallbackAbiStress.swift | 3881 +++++++- 2 files changed, 12079 insertions(+), 354 deletions(-) diff --git a/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.cs b/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.cs index 33e8dac7a184c0..cd00caec4667f4 100644 --- a/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.cs +++ b/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.cs @@ -14,456 +14,8406 @@ public unsafe class SwiftCallbackAbiStress { private const string SwiftLib = "libSwiftCallbackAbiStress.dylib"; + [StructLayout(LayoutKind.Sequential, Size = 14)] + struct F0_S0 + { + public double F0; + public uint F1; + public ushort F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F0_S1 + { + public ulong F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F0_S2 + { + public float F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func01fs5Int32VAEs5Int16V_AEs6UInt64Vs6UInt16VAA5F0_S0VAA0K3_S1Vs5UInt8VAA0K3_S2VtXE_tF")] + private static extern int SwiftCallbackFunc0(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static int SwiftCallbackFunc0Callback(short a0, int a1, ulong a2, ushort a3, F0_S0 a4, F0_S1 a5, byte a6, F0_S2 a7, SwiftSelf self) + { + try + { + Assert.Equal((short)-17813, a0); + Assert.Equal((int)318006528, a1); + Assert.Equal((ulong)1195162122024233590, a2); + Assert.Equal((ushort)60467, a3); + Assert.Equal((double)2239972725713766, a4.F0); + Assert.Equal((uint)1404066621, a4.F1); + Assert.Equal((ushort)29895, a4.F2); + Assert.Equal((ulong)7923486769850554262, a5.F0); + Assert.Equal((byte)217, a6); + Assert.Equal((float)2497655, a7.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 1579768470; + } + + [Fact] + public static void TestSwiftCallbackFunc0() + { + Console.Write("Running SwiftCallbackFunc0: "); + ExceptionDispatchInfo ex = null; + int val = SwiftCallbackFunc0(&SwiftCallbackFunc0Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((int)1579768470, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 3)] + struct F1_S0 + { + public ushort F0; + public byte F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 28)] + struct F1_S1 + { + public byte F0; + public ulong F1; + public short F2; + public float F3; + public float F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F1_S2_S0 + { + public uint F0; + public double F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 40)] + struct F1_S2 + { + public sbyte F0; + public nuint F1; + public F1_S2_S0 F2; + public nint F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F1_S3 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F1_S4 + { + public nint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F1_S5_S0 + { + public uint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F1_S5 + { + public F1_S5_S0 F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func11fs5UInt8VAEs5Int64V_Sds4Int8VAA5F1_S0VAA0J3_S1VAA0J3_S2VAeigA0J3_S3VSuAA0J3_S4VAA0J3_S5VSitXE_tF")] + private static extern byte SwiftCallbackFunc1(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static byte SwiftCallbackFunc1Callback(long a0, double a1, sbyte a2, F1_S0 a3, F1_S1 a4, F1_S2 a5, byte a6, sbyte a7, long a8, F1_S3 a9, nuint a10, F1_S4 a11, F1_S5 a12, nint a13, SwiftSelf self) + { + try + { + Assert.Equal((long)7920511243396412395, a0); + Assert.Equal((double)1396130721334528, a1); + Assert.Equal((sbyte)-55, a2); + Assert.Equal((ushort)33758, a3.F0); + Assert.Equal((byte)103, a3.F1); + Assert.Equal((byte)201, a4.F0); + Assert.Equal((ulong)7390774039746135757, a4.F1); + Assert.Equal((short)14699, a4.F2); + Assert.Equal((float)7235330, a4.F3); + Assert.Equal((float)7189013, a4.F4); + Assert.Equal((sbyte)37, a5.F0); + Assert.Equal((nuint)unchecked((nuint)3310322731568932038), a5.F1); + Assert.Equal((uint)1100328218, a5.F2.F0); + Assert.Equal((double)1060779460203640, a5.F2.F1); + Assert.Equal((nint)unchecked((nint)8325292022909418877), a5.F3); + Assert.Equal((byte)137, a6); + Assert.Equal((sbyte)82, a7); + Assert.Equal((long)1197537325837505041, a8); + Assert.Equal((ushort)46950, a9.F0); + Assert.Equal((nuint)unchecked((nuint)8181828233622947597), a10); + Assert.Equal((nint)unchecked((nint)1851182205030289056), a11.F0); + Assert.Equal((uint)1971014225, a12.F0.F0); + Assert.Equal((nint)unchecked((nint)6437995407675718392), a13); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 248; + } + + [Fact] + public static void TestSwiftCallbackFunc1() + { + Console.Write("Running SwiftCallbackFunc1: "); + ExceptionDispatchInfo ex = null; + byte val = SwiftCallbackFunc1(&SwiftCallbackFunc1Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((byte)248, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 20)] + struct F2_S0 + { + public int F0; + public nuint F1; + public float F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F2_S1_S0 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F2_S1 + { + public long F0; + public ushort F1; + public F2_S1_S0 F2; + public nint F3; + public double F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 11)] + struct F2_S2 + { + public float F0; + public int F1; + public ushort F2; + public sbyte F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F2_S3_S0 + { + public sbyte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F2_S3 + { + public F2_S3_S0 F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func21fs4Int8VAeA5F2_S0V_AA0H3_S1VAA0H3_S2VSfs6UInt64VAA0H3_S3VtXE_tF")] + private static extern sbyte SwiftCallbackFunc2(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static sbyte SwiftCallbackFunc2Callback(F2_S0 a0, F2_S1 a1, F2_S2 a2, float a3, ulong a4, F2_S3 a5, SwiftSelf self) + { + try + { + Assert.Equal((int)1860840185, a0.F0); + Assert.Equal((nuint)unchecked((nuint)5407074783834178811), a0.F1); + Assert.Equal((float)6261766, a0.F2); + Assert.Equal((long)4033972792915237065, a1.F0); + Assert.Equal((ushort)22825, a1.F1); + Assert.Equal((ushort)44574, a1.F2.F0); + Assert.Equal((nint)unchecked((nint)4536911485304731630), a1.F3); + Assert.Equal((double)4282944015147385, a1.F4); + Assert.Equal((float)2579193, a2.F0); + Assert.Equal((int)586252933, a2.F1); + Assert.Equal((ushort)47002, a2.F2); + Assert.Equal((sbyte)71, a2.F3); + Assert.Equal((float)3225929, a3); + Assert.Equal((ulong)3599444831393612282, a4); + Assert.Equal((sbyte)13, a5.F0.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 115; + } + + [Fact] + public static void TestSwiftCallbackFunc2() + { + Console.Write("Running SwiftCallbackFunc2: "); + ExceptionDispatchInfo ex = null; + sbyte val = SwiftCallbackFunc2(&SwiftCallbackFunc2Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((sbyte)115, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F3_S0_S0 + { + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F3_S0 + { + public F3_S0_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F3_S1 + { + public uint F0; + public long F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 3)] + struct F3_S2_S0 + { + public short F0; + public byte F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 5)] + struct F3_S2 + { + public F3_S2_S0 F0; + public sbyte F1; + public byte F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F3_S3 + { + public ulong F0; + public long F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F3_S4 + { + public short F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F3_Ret + { + public ushort F0; + public byte F1; + public ushort F2; + public float F3; + + public F3_Ret(ushort f0, byte f1, ushort f2, float f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func31fAA6F3_RetVAeA0G3_S0V_Sfs6UInt16VAA0G3_S1VAIs5Int32VAA0G3_S2VSiAA0G3_S3VAA0G3_S4VtXE_tF")] + private static extern F3_Ret SwiftCallbackFunc3(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F3_Ret SwiftCallbackFunc3Callback(F3_S0 a0, float a1, ushort a2, F3_S1 a3, ushort a4, int a5, F3_S2 a6, nint a7, F3_S3 a8, F3_S4 a9, SwiftSelf self) + { + try + { + Assert.Equal((nuint)unchecked((nuint)5610153900386943274), a0.F0.F0); + Assert.Equal((float)7736836, a1); + Assert.Equal((ushort)31355, a2); + Assert.Equal((uint)1159208572, a3.F0); + Assert.Equal((long)2707818827451590538, a3.F1); + Assert.Equal((ushort)37580, a4); + Assert.Equal((int)1453603418, a5); + Assert.Equal((short)699, a6.F0.F0); + Assert.Equal((byte)46, a6.F0.F1); + Assert.Equal((sbyte)-125, a6.F1); + Assert.Equal((byte)92, a6.F2); + Assert.Equal((nint)unchecked((nint)94557706586779834), a7); + Assert.Equal((ulong)2368015527878194540, a8.F0); + Assert.Equal((long)5026404532195049271, a8.F1); + Assert.Equal((short)21807, a9.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F3_Ret(51293, 217, 64666, 5667425); + } + + [Fact] + public static void TestSwiftCallbackFunc3() + { + Console.Write("Running SwiftCallbackFunc3: "); + ExceptionDispatchInfo ex = null; + F3_Ret val = SwiftCallbackFunc3(&SwiftCallbackFunc3Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ushort)51293, val.F0); + Assert.Equal((byte)217, val.F1); + Assert.Equal((ushort)64666, val.F2); + Assert.Equal((float)5667425, val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F4_S0_S0 + { + public uint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F4_S0 + { + public F4_S0_S0 F0; + public float F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F4_Ret_S0 + { + public nint F0; + + public F4_Ret_S0(nint f0) + { + F0 = f0; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 44)] + struct F4_Ret + { + public int F0; + public F4_Ret_S0 F1; + public nint F2; + public short F3; + public nint F4; + public uint F5; + + public F4_Ret(int f0, F4_Ret_S0 f1, nint f2, short f3, nint f4, uint f5) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + F4 = f4; + F5 = f5; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func41fAA6F4_RetVAESd_AA0G3_S0Vs5UInt8Vs5Int32Vs6UInt32VtXE_tF")] + private static extern F4_Ret SwiftCallbackFunc4(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F4_Ret SwiftCallbackFunc4Callback(double a0, F4_S0 a1, byte a2, int a3, uint a4, SwiftSelf self) + { + try + { + Assert.Equal((double)4282972206489588, a0); + Assert.Equal((uint)611688063, a1.F0.F0); + Assert.Equal((float)877466, a1.F1); + Assert.Equal((byte)53, a2); + Assert.Equal((int)965123506, a3); + Assert.Equal((uint)1301067653, a4); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F4_Ret(2069454428, new F4_Ret_S0(unchecked((nint)5483154806067048127)), unchecked((nint)2342208892279753870), -21578, unchecked((nint)4641984012938514811), 1691113876); + } + + [Fact] + public static void TestSwiftCallbackFunc4() + { + Console.Write("Running SwiftCallbackFunc4: "); + ExceptionDispatchInfo ex = null; + F4_Ret val = SwiftCallbackFunc4(&SwiftCallbackFunc4Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((int)2069454428, val.F0); + Assert.Equal((nint)unchecked((nint)5483154806067048127), val.F1.F0); + Assert.Equal((nint)unchecked((nint)2342208892279753870), val.F2); + Assert.Equal((short)-21578, val.F3); + Assert.Equal((nint)unchecked((nint)4641984012938514811), val.F4); + Assert.Equal((uint)1691113876, val.F5); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F5_S0 + { + public nuint F0; + public uint F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F5_S1_S0 + { + public nint F0; + public uint F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F5_S1_S1 + { + public float F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F5_S1 + { + public F5_S1_S0 F0; + public F5_S1_S1 F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F5_S2 + { + public double F0; + public sbyte F1; + public nint F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F5_S3 + { + public long F0; + public double F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F5_S4 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 26)] + struct F5_Ret + { + public short F0; + public int F1; + public int F2; + public ulong F3; + public short F4; + + public F5_Ret(short f0, int f1, int f2, ulong f3, short f4) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + F4 = f4; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func51fAA6F5_RetVAEs5UInt8V_s5Int16Vs6UInt64VS2uAkgA0G3_S0Vs4Int8VAoA0G3_S1VAA0G3_S2VAA0G3_S3VSdAA0G3_S4Vs6UInt16VS2fAYtXE_tF")] + private static extern F5_Ret SwiftCallbackFunc5(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F5_Ret SwiftCallbackFunc5Callback(byte a0, short a1, ulong a2, nuint a3, nuint a4, ulong a5, byte a6, F5_S0 a7, sbyte a8, sbyte a9, F5_S1 a10, F5_S2 a11, F5_S3 a12, double a13, F5_S4 a14, ushort a15, float a16, float a17, ushort a18, SwiftSelf self) + { + try + { + Assert.Equal((byte)42, a0); + Assert.Equal((short)18727, a1); + Assert.Equal((ulong)3436765034579128495, a2); + Assert.Equal((nuint)unchecked((nuint)6305137336506323506), a3); + Assert.Equal((nuint)unchecked((nuint)6280137078630028944), a4); + Assert.Equal((ulong)6252650621827449809, a5); + Assert.Equal((byte)129, a6); + Assert.Equal((nuint)unchecked((nuint)6879980973426111678), a7.F0); + Assert.Equal((uint)1952654577, a7.F1); + Assert.Equal((sbyte)-34, a8); + Assert.Equal((sbyte)102, a9); + Assert.Equal((nint)unchecked((nint)8389143657021522019), a10.F0.F0); + Assert.Equal((uint)437030241, a10.F0.F1); + Assert.Equal((float)7522798, a10.F1.F0); + Assert.Equal((double)523364011167530, a11.F0); + Assert.Equal((sbyte)16, a11.F1); + Assert.Equal((nint)unchecked((nint)3823439046574037759), a11.F2); + Assert.Equal((long)3767260839267771462, a12.F0); + Assert.Equal((double)1181031208183008, a12.F1); + Assert.Equal((double)2338830539621828, a13); + Assert.Equal((ushort)36276, a14.F0); + Assert.Equal((ushort)41286, a15); + Assert.Equal((float)6683955, a16); + Assert.Equal((float)6399917, a17); + Assert.Equal((ushort)767, a18); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F5_Ret(-23277, 1015782032, 83490460, 2747931081050267058, -10369); + } + + [Fact] + public static void TestSwiftCallbackFunc5() + { + Console.Write("Running SwiftCallbackFunc5: "); + ExceptionDispatchInfo ex = null; + F5_Ret val = SwiftCallbackFunc5(&SwiftCallbackFunc5Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((short)-23277, val.F0); + Assert.Equal((int)1015782032, val.F1); + Assert.Equal((int)83490460, val.F2); + Assert.Equal((ulong)2747931081050267058, val.F3); + Assert.Equal((short)-10369, val.F4); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F6_S0_S0 + { + public float F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F6_S0 + { + public sbyte F0; + public sbyte F1; + public int F2; + public F6_S0_S0 F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 28)] + struct F6_S1 + { + public int F0; + public ulong F1; + public ulong F2; + public uint F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 11)] + struct F6_S2 + { + public long F0; + public short F1; + public sbyte F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F6_S3 + { + public float F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F6_Ret_S0 + { + public long F0; + public uint F1; + + public F6_Ret_S0(long f0, uint f1) + { + F0 = f0; + F1 = f1; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 29)] + struct F6_Ret + { + public F6_Ret_S0 F0; + public ulong F1; + public float F2; + public sbyte F3; + + public F6_Ret(F6_Ret_S0 f0, ulong f1, float f2, sbyte f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func61fAA6F6_RetVAESf_AA0G3_S0Vs5Int64Vs4Int8Vs6UInt16VSuAMs6UInt64VAA0G3_S1Vs5Int16VAA0G3_S2VAA0G3_S3VAMtXE_tF")] + private static extern F6_Ret SwiftCallbackFunc6(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F6_Ret SwiftCallbackFunc6Callback(float a0, F6_S0 a1, long a2, sbyte a3, ushort a4, nuint a5, ushort a6, ulong a7, F6_S1 a8, short a9, F6_S2 a10, F6_S3 a11, ushort a12, SwiftSelf self) + { + try + { + Assert.Equal((float)2905241, a0); + Assert.Equal((sbyte)-27, a1.F0); + Assert.Equal((sbyte)-77, a1.F1); + Assert.Equal((int)1315779092, a1.F2); + Assert.Equal((float)5373970, a1.F3.F0); + Assert.Equal((long)7022244764256789748, a2); + Assert.Equal((sbyte)-110, a3); + Assert.Equal((ushort)2074, a4); + Assert.Equal((nuint)unchecked((nuint)3560129042279209151), a5); + Assert.Equal((ushort)2200, a6); + Assert.Equal((ulong)5730241035812482149, a7); + Assert.Equal((int)18625011, a8.F0); + Assert.Equal((ulong)242340713355417257, a8.F1); + Assert.Equal((ulong)6962175160124965670, a8.F2); + Assert.Equal((uint)1983617839, a8.F3); + Assert.Equal((short)-28374, a9); + Assert.Equal((long)6355748563312062178, a10.F0); + Assert.Equal((short)-23189, a10.F1); + Assert.Equal((sbyte)81, a10.F2); + Assert.Equal((float)4547677, a11.F0); + Assert.Equal((ushort)6397, a12); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F6_Ret(new F6_Ret_S0(3036123356548380503, 653452587), 4787954187933165977, 5060002, -68); + } + + [Fact] + public static void TestSwiftCallbackFunc6() + { + Console.Write("Running SwiftCallbackFunc6: "); + ExceptionDispatchInfo ex = null; + F6_Ret val = SwiftCallbackFunc6(&SwiftCallbackFunc6Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((long)3036123356548380503, val.F0.F0); + Assert.Equal((uint)653452587, val.F0.F1); + Assert.Equal((ulong)4787954187933165977, val.F1); + Assert.Equal((float)5060002, val.F2); + Assert.Equal((sbyte)-68, val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F7_S0 + { + public float F0; + public long F1; + public nuint F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F7_S1 + { + public short F0; + public uint F1; + public uint F2; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func71fs6UInt16VAEs5Int64V_s5UInt8VSdAeA5F7_S0VAISds6UInt32VAA0J3_S1Vs5Int32VAQSis5Int16VAESis6UInt64VAiStXE_tF")] + private static extern ushort SwiftCallbackFunc7(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static ushort SwiftCallbackFunc7Callback(long a0, byte a1, double a2, ushort a3, F7_S0 a4, byte a5, double a6, uint a7, F7_S1 a8, int a9, int a10, nint a11, short a12, ushort a13, nint a14, ulong a15, byte a16, short a17, SwiftSelf self) + { + try + { + Assert.Equal((long)7625368278886567558, a0); + Assert.Equal((byte)70, a1); + Assert.Equal((double)2146971972122530, a2); + Assert.Equal((ushort)54991, a3); + Assert.Equal((float)1072132, a4.F0); + Assert.Equal((long)3890459003549150599, a4.F1); + Assert.Equal((nuint)unchecked((nuint)56791000421908673), a4.F2); + Assert.Equal((byte)227, a5); + Assert.Equal((double)3248250571953113, a6); + Assert.Equal((uint)1138780108, a7); + Assert.Equal((short)-22670, a8.F0); + Assert.Equal((uint)1796712687, a8.F1); + Assert.Equal((uint)304251857, a8.F2); + Assert.Equal((int)1288765591, a9); + Assert.Equal((int)1382721790, a10); + Assert.Equal((nint)unchecked((nint)6746417265635727373), a11); + Assert.Equal((short)-15600, a12); + Assert.Equal((ushort)47575, a13); + Assert.Equal((nint)unchecked((nint)7200793040165597188), a14); + Assert.Equal((ulong)2304985873826892392, a15); + Assert.Equal((byte)99, a16); + Assert.Equal((short)-9993, a17); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 31412; + } + + [Fact] + public static void TestSwiftCallbackFunc7() + { + Console.Write("Running SwiftCallbackFunc7: "); + ExceptionDispatchInfo ex = null; + ushort val = SwiftCallbackFunc7(&SwiftCallbackFunc7Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ushort)31412, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F8_S0 + { + public short F0; + public short F1; + public nuint F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F8_S1 + { + public long F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F8_Ret_S0 + { + public int F0; + public nuint F1; + public nint F2; + + public F8_Ret_S0(int f0, nuint f1, nint f2) + { + F0 = f0; + F1 = f1; + F2 = f2; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 44)] + struct F8_Ret + { + public long F0; + public F8_Ret_S0 F1; + public nint F2; + public uint F3; + + public F8_Ret(long f0, F8_Ret_S0 f1, nint f2, uint f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func81fAA6F8_RetVAeA0G3_S0V_AA0G3_S1VtXE_tF")] + private static extern F8_Ret SwiftCallbackFunc8(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F8_Ret SwiftCallbackFunc8Callback(F8_S0 a0, F8_S1 a1, SwiftSelf self) + { + try + { + Assert.Equal((short)16278, a0.F0); + Assert.Equal((short)-31563, a0.F1); + Assert.Equal((nuint)unchecked((nuint)2171308312325435543), a0.F2); + Assert.Equal((long)8923668560896309835, a1.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F8_Ret(4170441467272673523, new F8_Ret_S0(1940721160, unchecked((nuint)6524670832376567295), unchecked((nint)4210781401091965722)), unchecked((nint)3245727696885859461), 855061841); + } + + [Fact] + public static void TestSwiftCallbackFunc8() + { + Console.Write("Running SwiftCallbackFunc8: "); + ExceptionDispatchInfo ex = null; + F8_Ret val = SwiftCallbackFunc8(&SwiftCallbackFunc8Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((long)4170441467272673523, val.F0); + Assert.Equal((int)1940721160, val.F1.F0); + Assert.Equal((nuint)unchecked((nuint)6524670832376567295), val.F1.F1); + Assert.Equal((nint)unchecked((nint)4210781401091965722), val.F1.F2); + Assert.Equal((nint)unchecked((nint)3245727696885859461), val.F2); + Assert.Equal((uint)855061841, val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F9_S0_S0 + { + public byte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F9_S0 + { + public F9_S0_S0 F0; + public short F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F9_S1_S0 + { + public long F0; + public long F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 28)] + struct F9_S1 + { + public nint F0; + public F9_S1_S0 F1; + public float F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 19)] + struct F9_S2 + { + public ulong F0; + public double F1; + public short F2; + public sbyte F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F9_S3_S0_S0 + { + public ulong F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F9_S3_S0 + { + public F9_S3_S0_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F9_S3 + { + public sbyte F0; + public F9_S3_S0 F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F9_S4_S0 + { + public ulong F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 9)] + struct F9_S4 + { + public F9_S4_S0 F0; + public sbyte F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F9_S5_S0 + { + public uint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F9_S5 + { + public uint F0; + public F9_S5_S0 F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F9_S6 + { + public double F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func91fs6UInt16VAEs4Int8V_s5UInt8Vs5Int64VAA5F9_S0VAA0K3_S1VAA0K3_S2VSdAA0K3_S3VAA0K3_S4VSdAA0K3_S5VAA0K3_S6VtXE_tF")] + private static extern ushort SwiftCallbackFunc9(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static ushort SwiftCallbackFunc9Callback(sbyte a0, byte a1, long a2, F9_S0 a3, F9_S1 a4, F9_S2 a5, double a6, F9_S3 a7, F9_S4 a8, double a9, F9_S5 a10, F9_S6 a11, SwiftSelf self) + { + try + { + Assert.Equal((sbyte)17, a0); + Assert.Equal((byte)104, a1); + Assert.Equal((long)8922699691031703191, a2); + Assert.Equal((byte)123, a3.F0.F0); + Assert.Equal((short)31706, a3.F1); + Assert.Equal((nint)unchecked((nint)1804058604961822948), a4.F0); + Assert.Equal((long)8772179036715198777, a4.F1.F0); + Assert.Equal((long)3320511540592563328, a4.F1.F1); + Assert.Equal((float)679540, a4.F2); + Assert.Equal((ulong)8642590829466497926, a5.F0); + Assert.Equal((double)4116322155252965, a5.F1); + Assert.Equal((short)17992, a5.F2); + Assert.Equal((sbyte)-48, a5.F3); + Assert.Equal((double)414017537937894, a6); + Assert.Equal((sbyte)47, a7.F0); + Assert.Equal((ulong)7576380984563129085, a7.F1.F0.F0); + Assert.Equal((ulong)1356827400304742803, a8.F0.F0); + Assert.Equal((sbyte)-17, a8.F1); + Assert.Equal((double)4458031413035521, a9); + Assert.Equal((uint)352075098, a10.F0); + Assert.Equal((uint)1840980094, a10.F1.F0); + Assert.Equal((double)396957263013930, a11.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 5567; + } + + [Fact] + public static void TestSwiftCallbackFunc9() + { + Console.Write("Running SwiftCallbackFunc9: "); + ExceptionDispatchInfo ex = null; + ushort val = SwiftCallbackFunc9(&SwiftCallbackFunc9Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ushort)5567, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 20)] + struct F10_Ret + { + public long F0; + public uint F1; + public ushort F2; + public uint F3; + + public F10_Ret(long f0, uint f1, ushort f2, uint f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func101fAA7F10_RetVAEs5Int16VXE_tF")] + private static extern F10_Ret SwiftCallbackFunc10(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F10_Ret SwiftCallbackFunc10Callback(short a0, SwiftSelf self) + { + try + { + Assert.Equal((short)-7168, a0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F10_Ret(7820305774933543349, 1501926289, 39078, 661487951); + } + + [Fact] + public static void TestSwiftCallbackFunc10() + { + Console.Write("Running SwiftCallbackFunc10: "); + ExceptionDispatchInfo ex = null; + F10_Ret val = SwiftCallbackFunc10(&SwiftCallbackFunc10Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((long)7820305774933543349, val.F0); + Assert.Equal((uint)1501926289, val.F1); + Assert.Equal((ushort)39078, val.F2); + Assert.Equal((uint)661487951, val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F11_S0_S0 + { + public sbyte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F11_S0 + { + public uint F0; + public F11_S0_S0 F1; + public nuint F2; + public int F3; + public long F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F11_S1_S0 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 10)] + struct F11_S1 + { + public F11_S1_S0 F0; + public short F1; + public uint F2; + public short F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F11_S2 + { + public byte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F11_Ret + { + public short F0; + public short F1; + public byte F2; + public long F3; + + public F11_Ret(short f0, short f1, byte f2, long f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func111fAA7F11_RetVAEs6UInt32V_Sus6UInt64Vs5Int16VAA0G3_S0VSfs4Int8Vs6UInt16VAA0G3_S1VAGs5Int64VAgA0G3_S2VtXE_tF")] + private static extern F11_Ret SwiftCallbackFunc11(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F11_Ret SwiftCallbackFunc11Callback(uint a0, nuint a1, ulong a2, short a3, F11_S0 a4, float a5, sbyte a6, ushort a7, F11_S1 a8, uint a9, long a10, uint a11, F11_S2 a12, SwiftSelf self) + { + try + { + Assert.Equal((uint)454751144, a0); + Assert.Equal((nuint)unchecked((nuint)1696592254558667577), a1); + Assert.Equal((ulong)5831587230944972245, a2); + Assert.Equal((short)15352, a3); + Assert.Equal((uint)1306601347, a4.F0); + Assert.Equal((sbyte)123, a4.F1.F0); + Assert.Equal((nuint)unchecked((nuint)3064471520018434938), a4.F2); + Assert.Equal((int)272956246, a4.F3); + Assert.Equal((long)3683518307106722029, a4.F4); + Assert.Equal((float)5606122, a5); + Assert.Equal((sbyte)-126, a6); + Assert.Equal((ushort)50801, a7); + Assert.Equal((ushort)63467, a8.F0.F0); + Assert.Equal((short)-31828, a8.F1); + Assert.Equal((uint)2117176776, a8.F2); + Assert.Equal((short)-27265, a8.F3); + Assert.Equal((uint)1879606687, a9); + Assert.Equal((long)4981244336430926707, a10); + Assert.Equal((uint)1159924856, a11); + Assert.Equal((byte)29, a12.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F11_Ret(7934, -24509, 20, 5470383170748296608); + } + + [Fact] + public static void TestSwiftCallbackFunc11() + { + Console.Write("Running SwiftCallbackFunc11: "); + ExceptionDispatchInfo ex = null; + F11_Ret val = SwiftCallbackFunc11(&SwiftCallbackFunc11Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((short)7934, val.F0); + Assert.Equal((short)-24509, val.F1); + Assert.Equal((byte)20, val.F2); + Assert.Equal((long)5470383170748296608, val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 9)] + struct F12_S0 + { + public ulong F0; + public sbyte F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F12_S1_S0_S0 + { + public ulong F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F12_S1_S0 + { + public F12_S1_S0_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F12_S1 + { + public ushort F0; + public uint F1; + public F12_S1_S0 F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F12_Ret + { + public ulong F0; + public nint F1; + + public F12_Ret(ulong f0, nint f1) + { + F0 = f0; + F1 = f1; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func121fAA7F12_RetVAeA0G3_S0V_s5Int16Vs6UInt64VAA0G3_S1Vs4Int8VtXE_tF")] + private static extern F12_Ret SwiftCallbackFunc12(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F12_Ret SwiftCallbackFunc12Callback(F12_S0 a0, short a1, ulong a2, F12_S1 a3, sbyte a4, SwiftSelf self) + { + try + { + Assert.Equal((ulong)3236871137735400659, a0.F0); + Assert.Equal((sbyte)-123, a0.F1); + Assert.Equal((short)-22828, a1); + Assert.Equal((ulong)2132557792366642035, a2); + Assert.Equal((ushort)42520, a3.F0); + Assert.Equal((uint)879349060, a3.F1); + Assert.Equal((ulong)5694370973277919380, a3.F2.F0.F0); + Assert.Equal((sbyte)-75, a4); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F12_Ret(4675419585914412295, unchecked((nint)1931022181202552704)); + } + + [Fact] + public static void TestSwiftCallbackFunc12() + { + Console.Write("Running SwiftCallbackFunc12: "); + ExceptionDispatchInfo ex = null; + F12_Ret val = SwiftCallbackFunc12(&SwiftCallbackFunc12Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ulong)4675419585914412295, val.F0); + Assert.Equal((nint)unchecked((nint)1931022181202552704), val.F1); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F13_S0_S0 + { + public long F0; + public long F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 22)] + struct F13_S0 + { + public F13_S0_S0 F0; + public float F1; + public short F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F13_S1 + { + public nint F0; + public ulong F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F13_S2_S0 + { + public byte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F13_S2 + { + public F13_S2_S0 F0; + public double F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 5)] + struct F13_S3 + { + public float F0; + public sbyte F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F13_S4 + { + public nint F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func131fS2dAA6F13_S0V_s5Int32VSis6UInt16VSuAA0G3_S1VAA0G3_S2VSiSds4Int8VSfSiAA0G3_S3VSuAA0G3_S4VtXE_tF")] + private static extern double SwiftCallbackFunc13(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static double SwiftCallbackFunc13Callback(F13_S0 a0, int a1, nint a2, ushort a3, nuint a4, F13_S1 a5, F13_S2 a6, nint a7, double a8, sbyte a9, float a10, nint a11, F13_S3 a12, nuint a13, F13_S4 a14, SwiftSelf self) + { + try + { + Assert.Equal((long)9003727031576598067, a0.F0.F0); + Assert.Equal((long)8527798284445940986, a0.F0.F1); + Assert.Equal((float)3585628, a0.F1); + Assert.Equal((short)-12520, a0.F2); + Assert.Equal((int)1510815104, a1); + Assert.Equal((nint)unchecked((nint)5883331525294982326), a2); + Assert.Equal((ushort)60738, a3); + Assert.Equal((nuint)unchecked((nuint)5291799143932627546), a4); + Assert.Equal((nint)unchecked((nint)1949276559361384602), a5.F0); + Assert.Equal((ulong)876048527237138968, a5.F1); + Assert.Equal((byte)67, a6.F0.F0); + Assert.Equal((double)2455575228564859, a6.F1); + Assert.Equal((nint)unchecked((nint)2321408806345977320), a7); + Assert.Equal((double)12750323283778, a8); + Assert.Equal((sbyte)46, a9); + Assert.Equal((float)6774339, a10); + Assert.Equal((nint)unchecked((nint)5121910967292140178), a11); + Assert.Equal((float)8254279, a12.F0); + Assert.Equal((sbyte)-7, a12.F1); + Assert.Equal((nuint)unchecked((nuint)7533347207018595125), a13); + Assert.Equal((nint)unchecked((nint)6605448167191082938), a14.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 2798050901932855; + } + + [Fact] + public static void TestSwiftCallbackFunc13() + { + Console.Write("Running SwiftCallbackFunc13: "); + ExceptionDispatchInfo ex = null; + double val = SwiftCallbackFunc13(&SwiftCallbackFunc13Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((double)2798050901932855, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 10)] + struct F14_S0 + { + public sbyte F0; + public float F1; + public ushort F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F14_S1 + { + public ulong F0; + public ulong F1; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func141fs5Int64VA2E_AA6F14_S0Vs4Int8Vs6UInt64VAA0H3_S1VSitXE_tF")] + private static extern long SwiftCallbackFunc14(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static long SwiftCallbackFunc14Callback(long a0, F14_S0 a1, sbyte a2, ulong a3, F14_S1 a4, nint a5, SwiftSelf self) + { + try + { + Assert.Equal((long)5547219684656041875, a0); + Assert.Equal((sbyte)-39, a1.F0); + Assert.Equal((float)5768837, a1.F1); + Assert.Equal((ushort)53063, a1.F2); + Assert.Equal((sbyte)-102, a2); + Assert.Equal((ulong)5745438709817040873, a3); + Assert.Equal((ulong)2178706453119907411, a4.F0); + Assert.Equal((ulong)4424726479787355131, a4.F1); + Assert.Equal((nint)unchecked((nint)5693881223150438553), a5); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 5130561516716417305; + } + + [Fact] + public static void TestSwiftCallbackFunc14() + { + Console.Write("Running SwiftCallbackFunc14: "); + ExceptionDispatchInfo ex = null; + long val = SwiftCallbackFunc14(&SwiftCallbackFunc14Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((long)5130561516716417305, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F15_S0 + { + public uint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F15_S1 + { + public nint F0; + public uint F1; + public byte F2; + public short F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 25)] + struct F15_S2 + { + public sbyte F0; + public ulong F1; + public long F2; + public byte F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F15_S3 + { + public double F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func151fS2is5UInt8V_s6UInt16Vs6UInt64VAIs4Int8VSuSdSfSiAA6F15_S0VAA0K3_S1VAgA0K3_S2VAeA0K3_S3VtXE_tF")] + private static extern nint SwiftCallbackFunc15(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static nint SwiftCallbackFunc15Callback(byte a0, ushort a1, ulong a2, ulong a3, sbyte a4, nuint a5, double a6, float a7, nint a8, F15_S0 a9, F15_S1 a10, ushort a11, F15_S2 a12, byte a13, F15_S3 a14, SwiftSelf self) + { + try + { + Assert.Equal((byte)0, a0); + Assert.Equal((ushort)31081, a1); + Assert.Equal((ulong)8814881608835743979, a2); + Assert.Equal((ulong)4283853687332682681, a3); + Assert.Equal((sbyte)80, a4); + Assert.Equal((nuint)unchecked((nuint)7895994601265649979), a5); + Assert.Equal((double)1855521542692398, a6); + Assert.Equal((float)3235683, a7); + Assert.Equal((nint)unchecked((nint)215122646177738904), a8); + Assert.Equal((uint)2044750195, a9.F0); + Assert.Equal((nint)unchecked((nint)1772412898183620625), a10.F0); + Assert.Equal((uint)131256973, a10.F1); + Assert.Equal((byte)153, a10.F2); + Assert.Equal((short)25281, a10.F3); + Assert.Equal((ushort)50965, a11); + Assert.Equal((sbyte)-83, a12.F0); + Assert.Equal((ulong)7751486385861474282, a12.F1); + Assert.Equal((long)3744400479301818340, a12.F2); + Assert.Equal((byte)150, a12.F3); + Assert.Equal((byte)179, a13); + Assert.Equal((double)3108143600787174, a14.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return unchecked((nint)2326283264176371053); + } + + [Fact] + public static void TestSwiftCallbackFunc15() + { + Console.Write("Running SwiftCallbackFunc15: "); + ExceptionDispatchInfo ex = null; + nint val = SwiftCallbackFunc15(&SwiftCallbackFunc15Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nint)unchecked((nint)2326283264176371053), val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F16_S0 + { + public sbyte F0; + public int F1; + public ushort F2; + public ushort F3; + public uint F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F16_S1 + { + public ushort F0; + public sbyte F1; + public byte F2; + public nint F3; + public nint F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F16_S2_S0 + { + public sbyte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 14)] + struct F16_S2 + { + public int F0; + public int F1; + public uint F2; + public byte F3; + public F16_S2_S0 F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 28)] + struct F16_S3 + { + public short F0; + public double F1; + public double F2; + public int F3; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func161fs4Int8VAeA6F16_S0V_s5Int16VSfAA0H3_S1VAA0H3_S2Vs6UInt64VAA0H3_S3VSutXE_tF")] + private static extern sbyte SwiftCallbackFunc16(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static sbyte SwiftCallbackFunc16Callback(F16_S0 a0, short a1, float a2, F16_S1 a3, F16_S2 a4, ulong a5, F16_S3 a6, nuint a7, SwiftSelf self) + { + try + { + Assert.Equal((sbyte)-59, a0.F0); + Assert.Equal((int)1181591186, a0.F1); + Assert.Equal((ushort)44834, a0.F2); + Assert.Equal((ushort)28664, a0.F3); + Assert.Equal((uint)404461767, a0.F4); + Assert.Equal((short)2482, a1); + Assert.Equal((float)2997348, a2); + Assert.Equal((ushort)22423, a3.F0); + Assert.Equal((sbyte)-106, a3.F1); + Assert.Equal((byte)182, a3.F2); + Assert.Equal((nint)unchecked((nint)3784074551275084420), a3.F3); + Assert.Equal((nint)unchecked((nint)7092934571108982079), a3.F4); + Assert.Equal((int)1835134709, a4.F0); + Assert.Equal((int)246067261, a4.F1); + Assert.Equal((uint)1986526591, a4.F2); + Assert.Equal((byte)24, a4.F3); + Assert.Equal((sbyte)-112, a4.F4.F0); + Assert.Equal((ulong)1465053746911704089, a5); + Assert.Equal((short)-27636, a6.F0); + Assert.Equal((double)1896887612303356, a6.F1); + Assert.Equal((double)4263157082840190, a6.F2); + Assert.Equal((int)774653659, a6.F3); + Assert.Equal((nuint)unchecked((nuint)3755775782607884861), a7); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 103; + } + + [Fact] + public static void TestSwiftCallbackFunc16() + { + Console.Write("Running SwiftCallbackFunc16: "); + ExceptionDispatchInfo ex = null; + sbyte val = SwiftCallbackFunc16(&SwiftCallbackFunc16Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((sbyte)103, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F17_S0 + { + public int F0; + public nuint F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F17_S1_S0 + { + public double F0; + public uint F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 17)] + struct F17_S1 + { + public F17_S1_S0 F0; + public int F1; + public byte F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F17_S2 + { + public uint F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func171fS2ds6UInt32V_AA6F17_S0VAA0H3_S1VSds6UInt64VAA0H3_S2VtXE_tF")] + private static extern double SwiftCallbackFunc17(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static double SwiftCallbackFunc17Callback(uint a0, F17_S0 a1, F17_S1 a2, double a3, ulong a4, F17_S2 a5, SwiftSelf self) + { + try + { + Assert.Equal((uint)201081002, a0); + Assert.Equal((int)2018751226, a1.F0); + Assert.Equal((nuint)unchecked((nuint)8488544433072104028), a1.F1); + Assert.Equal((double)1190765430157980, a2.F0.F0); + Assert.Equal((uint)70252071, a2.F0.F1); + Assert.Equal((int)1297775609, a2.F1); + Assert.Equal((byte)160, a2.F2); + Assert.Equal((double)4290084351352688, a3); + Assert.Equal((ulong)4738339757002694731, a4); + Assert.Equal((uint)1829312773, a5.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 4214404512040467; + } + + [Fact] + public static void TestSwiftCallbackFunc17() + { + Console.Write("Running SwiftCallbackFunc17: "); + ExceptionDispatchInfo ex = null; + double val = SwiftCallbackFunc17(&SwiftCallbackFunc17Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((double)4214404512040467, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F18_S0 + { + public sbyte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F18_S1 + { + public ushort F0; + public short F1; + public double F2; + public nuint F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F18_S2 + { + public nint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F18_Ret_S0 + { + public short F0; + + public F18_Ret_S0(short f0) + { + F0 = f0; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F18_Ret + { + public F18_Ret_S0 F0; + + public F18_Ret(F18_Ret_S0 f0) + { + F0 = f0; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func181fAA7F18_RetVAeA0G3_S0V_AA0G3_S1VAA0G3_S2VSus6UInt32Vs5Int64Vs5Int16VSdtXE_tF")] + private static extern F18_Ret SwiftCallbackFunc18(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F18_Ret SwiftCallbackFunc18Callback(F18_S0 a0, F18_S1 a1, F18_S2 a2, nuint a3, uint a4, long a5, short a6, double a7, SwiftSelf self) + { + try + { + Assert.Equal((sbyte)106, a0.F0); + Assert.Equal((ushort)21619, a1.F0); + Assert.Equal((short)-4350, a1.F1); + Assert.Equal((double)3457288266203248, a1.F2); + Assert.Equal((nuint)unchecked((nuint)9020447812661292883), a1.F3); + Assert.Equal((nint)unchecked((nint)2317132584983719004), a2.F0); + Assert.Equal((nuint)unchecked((nuint)7379425918918939512), a3); + Assert.Equal((uint)2055208746, a4); + Assert.Equal((long)1042861174364145790, a5); + Assert.Equal((short)28457, a6); + Assert.Equal((double)1799004152435515, a7); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F18_Ret(new F18_Ret_S0(-2080)); + } + + [Fact] + public static void TestSwiftCallbackFunc18() + { + Console.Write("Running SwiftCallbackFunc18: "); + ExceptionDispatchInfo ex = null; + F18_Ret val = SwiftCallbackFunc18(&SwiftCallbackFunc18Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((short)-2080, val.F0.F0); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F19_S0 + { + public short F0; + public sbyte F1; + public float F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 10)] + struct F19_S1 + { + public long F0; + public ushort F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F19_S2 + { + public ulong F0; + public long F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F19_S3 + { + public uint F0; + public int F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F19_Ret_S0 + { + public long F0; + + public F19_Ret_S0(long f0) + { + F0 = f0; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 56)] + struct F19_Ret + { + public uint F0; + public long F1; + public ushort F2; + public F19_Ret_S0 F3; + public double F4; + public double F5; + public double F6; + + public F19_Ret(uint f0, long f1, ushort f2, F19_Ret_S0 f3, double f4, double f5, double f6) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + F4 = f4; + F5 = f5; + F6 = f6; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func191fAA7F19_RetVAEs5Int64V_s5UInt8VAA0G3_S0VSiAA0G3_S1Vs5Int32VAOSus6UInt64VAA0G3_S2Vs6UInt16VAA0G3_S3Vs4Int8VAGtXE_tF")] + private static extern F19_Ret SwiftCallbackFunc19(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F19_Ret SwiftCallbackFunc19Callback(long a0, byte a1, F19_S0 a2, nint a3, F19_S1 a4, int a5, int a6, nuint a7, ulong a8, F19_S2 a9, ushort a10, F19_S3 a11, sbyte a12, long a13, SwiftSelf self) + { + try + { + Assert.Equal((long)7456120134117592143, a0); + Assert.Equal((byte)114, a1); + Assert.Equal((short)-7583, a2.F0); + Assert.Equal((sbyte)97, a2.F1); + Assert.Equal((float)2768322, a2.F2); + Assert.Equal((nint)unchecked((nint)3605245176125291560), a3); + Assert.Equal((long)4445885313084714470, a4.F0); + Assert.Equal((ushort)15810, a4.F1); + Assert.Equal((int)1179699879, a5); + Assert.Equal((int)109603412, a6); + Assert.Equal((nuint)unchecked((nuint)6521628547431964799), a7); + Assert.Equal((ulong)7687430644226018854, a8); + Assert.Equal((ulong)8464855230956039883, a9.F0); + Assert.Equal((long)861462819289140037, a9.F1); + Assert.Equal((ushort)26519, a10); + Assert.Equal((uint)1864602741, a11.F0); + Assert.Equal((int)397176384, a11.F1); + Assert.Equal((sbyte)81, a12); + Assert.Equal((long)4909173176891211442, a13); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F19_Ret(301901837, 5183322153843416979, 16744, new F19_Ret_S0(4587948079871666183), 341974742264104, 750011710367955, 681779256292286); + } + + [Fact] + public static void TestSwiftCallbackFunc19() + { + Console.Write("Running SwiftCallbackFunc19: "); + ExceptionDispatchInfo ex = null; + F19_Ret val = SwiftCallbackFunc19(&SwiftCallbackFunc19Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((uint)301901837, val.F0); + Assert.Equal((long)5183322153843416979, val.F1); + Assert.Equal((ushort)16744, val.F2); + Assert.Equal((long)4587948079871666183, val.F3.F0); + Assert.Equal((double)341974742264104, val.F4); + Assert.Equal((double)750011710367955, val.F5); + Assert.Equal((double)681779256292286, val.F6); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F20_S0_S0 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 18)] + struct F20_S0 + { + public short F0; + public nuint F1; + public F20_S0_S0 F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F20_S1_S0 + { + public float F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 36)] + struct F20_S1 + { + public long F0; + public nuint F1; + public F20_S1_S0 F2; + public long F3; + public int F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F20_S2 + { + public uint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F20_Ret + { + public ushort F0; + public ushort F1; + public double F2; + public short F3; + public double F4; + + public F20_Ret(ushort f0, ushort f1, double f2, short f3, double f4) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + F4 = f4; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func201fAA7F20_RetVAeA0G3_S0V_AA0G3_S1VS2fs4Int8VAA0G3_S2VSftXE_tF")] + private static extern F20_Ret SwiftCallbackFunc20(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F20_Ret SwiftCallbackFunc20Callback(F20_S0 a0, F20_S1 a1, float a2, float a3, sbyte a4, F20_S2 a5, float a6, SwiftSelf self) + { + try + { + Assert.Equal((short)28858, a0.F0); + Assert.Equal((nuint)unchecked((nuint)7024100299344418039), a0.F1); + Assert.Equal((ushort)13025, a0.F2.F0); + Assert.Equal((long)7900431324553135989, a1.F0); + Assert.Equal((nuint)unchecked((nuint)8131425055682506706), a1.F1); + Assert.Equal((float)3884322, a1.F2.F0); + Assert.Equal((long)605453501265278638, a1.F3); + Assert.Equal((int)353756684, a1.F4); + Assert.Equal((float)622319, a2); + Assert.Equal((float)1401604, a3); + Assert.Equal((sbyte)-101, a4); + Assert.Equal((uint)1355570413, a5.F0); + Assert.Equal((float)2912776, a6); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F20_Ret(53384, 55736, 105589186779121, -24217, 2181722329638192); + } + + [Fact] + public static void TestSwiftCallbackFunc20() + { + Console.Write("Running SwiftCallbackFunc20: "); + ExceptionDispatchInfo ex = null; + F20_Ret val = SwiftCallbackFunc20(&SwiftCallbackFunc20Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ushort)53384, val.F0); + Assert.Equal((ushort)55736, val.F1); + Assert.Equal((double)105589186779121, val.F2); + Assert.Equal((short)-24217, val.F3); + Assert.Equal((double)2181722329638192, val.F4); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F21_S0 + { + public double F0; + public ulong F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F21_S1 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F21_Ret + { + public ushort F0; + public uint F1; + public long F2; + + public F21_Ret(ushort f0, uint f1, long f2) + { + F0 = f0; + F1 = f1; + F2 = f2; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func211fAA7F21_RetVAEs5Int32V_s5Int16VAA0G3_S0VAgA0G3_S1Vs5Int64Vs6UInt32VAOs5UInt8Vs6UInt16VtXE_tF")] + private static extern F21_Ret SwiftCallbackFunc21(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F21_Ret SwiftCallbackFunc21Callback(int a0, short a1, F21_S0 a2, int a3, F21_S1 a4, long a5, uint a6, long a7, byte a8, ushort a9, SwiftSelf self) + { + try + { + Assert.Equal((int)256017319, a0); + Assert.Equal((short)14555, a1); + Assert.Equal((double)2102091966108033, a2.F0); + Assert.Equal((ulong)8617538752301505079, a2.F1); + Assert.Equal((int)834677431, a3); + Assert.Equal((ushort)7043, a4.F0); + Assert.Equal((long)7166819734655141128, a5); + Assert.Equal((uint)965538086, a6); + Assert.Equal((long)3827752442102685645, a7); + Assert.Equal((byte)110, a8); + Assert.Equal((ushort)33646, a9); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F21_Ret(13904, 1020161192, 7669588951617295307); + } + + [Fact] + public static void TestSwiftCallbackFunc21() + { + Console.Write("Running SwiftCallbackFunc21: "); + ExceptionDispatchInfo ex = null; + F21_Ret val = SwiftCallbackFunc21(&SwiftCallbackFunc21Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ushort)13904, val.F0); + Assert.Equal((uint)1020161192, val.F1); + Assert.Equal((long)7669588951617295307, val.F2); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F22_S0 + { + public nint F0; + public float F1; + public double F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F22_S1 + { + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F22_S2 + { + public int F0; + public double F1; + public float F2; + public short F3; + public ushort F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 10)] + struct F22_S3 + { + public long F0; + public ushort F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 10)] + struct F22_S4 + { + public double F0; + public ushort F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 6)] + struct F22_S5 + { + public uint F0; + public short F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F22_S6 + { + public float F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F22_Ret + { + public ushort F0; + public short F1; + public nuint F2; + + public F22_Ret(ushort f0, short f1, nuint f2) + { + F0 = f0; + F1 = f1; + F2 = f2; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func221fAA7F22_RetVAEs5Int32V_AA0G3_S0VAA0G3_S1VAA0G3_S2VAA0G3_S3Vs4Int8VAA0G3_S4Vs5UInt8Vs6UInt16Vs5Int64VAA0G3_S5VAYSfAA0G3_S6VAWtXE_tF")] + private static extern F22_Ret SwiftCallbackFunc22(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F22_Ret SwiftCallbackFunc22Callback(int a0, F22_S0 a1, F22_S1 a2, F22_S2 a3, F22_S3 a4, sbyte a5, F22_S4 a6, byte a7, ushort a8, long a9, F22_S5 a10, long a11, float a12, F22_S6 a13, ushort a14, SwiftSelf self) + { + try + { + Assert.Equal((int)640156952, a0); + Assert.Equal((nint)unchecked((nint)824774470287401457), a1.F0); + Assert.Equal((float)6163704, a1.F1); + Assert.Equal((double)54328782764685, a1.F2); + Assert.Equal((nuint)unchecked((nuint)1679730195865415747), a2.F0); + Assert.Equal((int)1462995665, a3.F0); + Assert.Equal((double)2554087365600344, a3.F1); + Assert.Equal((float)8193295, a3.F2); + Assert.Equal((short)16765, a3.F3); + Assert.Equal((ushort)45388, a3.F4); + Assert.Equal((long)5560492364570389430, a4.F0); + Assert.Equal((ushort)48308, a4.F1); + Assert.Equal((sbyte)71, a5); + Assert.Equal((double)1639169280741045, a6.F0); + Assert.Equal((ushort)12045, a6.F1); + Assert.Equal((byte)217, a7); + Assert.Equal((ushort)62917, a8); + Assert.Equal((long)1465918945905384332, a9); + Assert.Equal((uint)1364750179, a10.F0); + Assert.Equal((short)3311, a10.F1); + Assert.Equal((long)9003480567517966914, a11); + Assert.Equal((float)2157327, a12); + Assert.Equal((float)6647392, a13.F0); + Assert.Equal((ushort)1760, a14); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F22_Ret(39726, 21753, unchecked((nuint)5706055053768469840)); + } + + [Fact] + public static void TestSwiftCallbackFunc22() + { + Console.Write("Running SwiftCallbackFunc22: "); + ExceptionDispatchInfo ex = null; + F22_Ret val = SwiftCallbackFunc22(&SwiftCallbackFunc22Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ushort)39726, val.F0); + Assert.Equal((short)21753, val.F1); + Assert.Equal((nuint)unchecked((nuint)5706055053768469840), val.F2); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F23_S0 + { + public nint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F23_S1 + { + public nint F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func231fS2dSu_s5UInt8Vs4Int8VA2eA6F23_S0VSuAA0I3_S1VSdtXE_tF")] + private static extern double SwiftCallbackFunc23(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static double SwiftCallbackFunc23Callback(nuint a0, byte a1, sbyte a2, byte a3, byte a4, F23_S0 a5, nuint a6, F23_S1 a7, double a8, SwiftSelf self) + { + try + { + Assert.Equal((nuint)unchecked((nuint)5779410841248940897), a0); + Assert.Equal((byte)192, a1); + Assert.Equal((sbyte)-128, a2); + Assert.Equal((byte)133, a3); + Assert.Equal((byte)20, a4); + Assert.Equal((nint)unchecked((nint)2959916071636885436), a5.F0); + Assert.Equal((nuint)unchecked((nuint)3651155214497129159), a6); + Assert.Equal((nint)unchecked((nint)8141565342203061885), a7.F0); + Assert.Equal((double)1465425469608034, a8); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 893532429511039; + } + + [Fact] + public static void TestSwiftCallbackFunc23() + { + Console.Write("Running SwiftCallbackFunc23: "); + ExceptionDispatchInfo ex = null; + double val = SwiftCallbackFunc23(&SwiftCallbackFunc23Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((double)893532429511039, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 20)] + struct F24_S0 + { + public sbyte F0; + public byte F1; + public ulong F2; + public uint F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F24_S1 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F24_S2_S0 + { + public ushort F0; + public uint F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F24_S2_S1 + { + public long F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F24_S2 + { + public nint F0; + public uint F1; + public F24_S2_S0 F2; + public F24_S2_S1 F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F24_S3 + { + public short F0; + public float F1; + public long F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F24_S4 + { + public byte F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func241fS2fs5Int32V_SuAA6F24_S0Vs6UInt16VAA0H3_S1Vs4Int8VAA0H3_S2Vs6UInt64VAqA0H3_S3VSdAA0H3_S4VtXE_tF")] + private static extern float SwiftCallbackFunc24(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static float SwiftCallbackFunc24Callback(int a0, nuint a1, F24_S0 a2, ushort a3, F24_S1 a4, sbyte a5, F24_S2 a6, ulong a7, ulong a8, F24_S3 a9, double a10, F24_S4 a11, SwiftSelf self) + { + try + { + Assert.Equal((int)1710754874, a0); + Assert.Equal((nuint)unchecked((nuint)6447433131978039331), a1); + Assert.Equal((sbyte)-92, a2.F0); + Assert.Equal((byte)181, a2.F1); + Assert.Equal((ulong)3710374263631495948, a2.F2); + Assert.Equal((uint)257210428, a2.F3); + Assert.Equal((ushort)6631, a3); + Assert.Equal((ushort)2303, a4.F0); + Assert.Equal((sbyte)15, a5); + Assert.Equal((nint)unchecked((nint)2509049432824972381), a6.F0); + Assert.Equal((uint)616918672, a6.F1); + Assert.Equal((ushort)50635, a6.F2.F0); + Assert.Equal((uint)1337844540, a6.F2.F1); + Assert.Equal((long)335964796567786281, a6.F3.F0); + Assert.Equal((ulong)1114365571136806382, a7); + Assert.Equal((ulong)8988425145801188208, a8); + Assert.Equal((short)31969, a9.F0); + Assert.Equal((float)3008861, a9.F1); + Assert.Equal((long)5466306080595269107, a9.F2); + Assert.Equal((double)2027780227887952, a10); + Assert.Equal((byte)234, a11.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 3470219; + } + + [Fact] + public static void TestSwiftCallbackFunc24() + { + Console.Write("Running SwiftCallbackFunc24: "); + ExceptionDispatchInfo ex = null; + float val = SwiftCallbackFunc24(&SwiftCallbackFunc24Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((float)3470219, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F25_S0 + { + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F25_S1 + { + public float F0; + public sbyte F1; + public float F2; + public nint F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 25)] + struct F25_S2 + { + public nuint F0; + public nuint F1; + public long F2; + public byte F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F25_S3 + { + public float F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F25_S4 + { + public sbyte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 20)] + struct F25_Ret + { + public ulong F0; + public long F1; + public byte F2; + public ushort F3; + + public F25_Ret(ulong f0, long f1, byte f2, ushort f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func251fAA7F25_RetVAeA0G3_S0V_s6UInt16VSuAA0G3_S1Vs5Int16VAA0G3_S2Vs6UInt64VA2qA0G3_S3VAA0G3_S4VtXE_tF")] + private static extern F25_Ret SwiftCallbackFunc25(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F25_Ret SwiftCallbackFunc25Callback(F25_S0 a0, ushort a1, nuint a2, F25_S1 a3, short a4, F25_S2 a5, ulong a6, ulong a7, ulong a8, F25_S3 a9, F25_S4 a10, SwiftSelf self) + { + try + { + Assert.Equal((nuint)unchecked((nuint)6077761381429658786), a0.F0); + Assert.Equal((ushort)2300, a1); + Assert.Equal((nuint)unchecked((nuint)3498354181807010234), a2); + Assert.Equal((float)5360721, a3.F0); + Assert.Equal((sbyte)-40, a3.F1); + Assert.Equal((float)109485, a3.F2); + Assert.Equal((nint)unchecked((nint)2311625789899959825), a3.F3); + Assert.Equal((short)-28395, a4); + Assert.Equal((nuint)unchecked((nuint)8729509817732080529), a5.F0); + Assert.Equal((nuint)unchecked((nuint)860365359368130822), a5.F1); + Assert.Equal((long)7498894262834346040, a5.F2); + Assert.Equal((byte)218, a5.F3); + Assert.Equal((ulong)961687210282504701, a6); + Assert.Equal((ulong)7184177441364400868, a7); + Assert.Equal((ulong)8389319500274436977, a8); + Assert.Equal((float)4437173, a9.F0); + Assert.Equal((sbyte)-107, a10.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F25_Ret(8006862079710523876, 7879510716857855733, 114, 3220); + } + + [Fact] + public static void TestSwiftCallbackFunc25() + { + Console.Write("Running SwiftCallbackFunc25: "); + ExceptionDispatchInfo ex = null; + F25_Ret val = SwiftCallbackFunc25(&SwiftCallbackFunc25Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ulong)8006862079710523876, val.F0); + Assert.Equal((long)7879510716857855733, val.F1); + Assert.Equal((byte)114, val.F2); + Assert.Equal((ushort)3220, val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 18)] + struct F26_S0 + { + public sbyte F0; + public nint F1; + public byte F2; + public byte F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F26_S1_S0 + { + public ulong F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F26_S1 + { + public sbyte F0; + public int F1; + public short F2; + public F26_S1_S0 F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F26_S2 + { + public long F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F26_S3 + { + public byte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 9)] + struct F26_Ret + { + public nuint F0; + public byte F1; + + public F26_Ret(nuint f0, byte f1) + { + F0 = f0; + F1 = f1; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func261fAA7F26_RetVAEs4Int8V_s5UInt8Vs6UInt32VAA0G3_S0VAA0G3_S1VAA0G3_S2VAA0G3_S3VtXE_tF")] + private static extern F26_Ret SwiftCallbackFunc26(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F26_Ret SwiftCallbackFunc26Callback(sbyte a0, byte a1, uint a2, F26_S0 a3, F26_S1 a4, F26_S2 a5, F26_S3 a6, SwiftSelf self) + { + try + { + Assert.Equal((sbyte)-16, a0); + Assert.Equal((byte)220, a1); + Assert.Equal((uint)72386567, a2); + Assert.Equal((sbyte)-33, a3.F0); + Assert.Equal((nint)unchecked((nint)6488877286424796715), a3.F1); + Assert.Equal((byte)143, a3.F2); + Assert.Equal((byte)74, a3.F3); + Assert.Equal((sbyte)104, a4.F0); + Assert.Equal((int)1719453315, a4.F1); + Assert.Equal((short)20771, a4.F2); + Assert.Equal((ulong)3636117595999837800, a4.F3.F0); + Assert.Equal((long)2279530426119665839, a5.F0); + Assert.Equal((byte)207, a6.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F26_Ret(unchecked((nuint)1050319650554930471), 89); + } + + [Fact] + public static void TestSwiftCallbackFunc26() + { + Console.Write("Running SwiftCallbackFunc26: "); + ExceptionDispatchInfo ex = null; + F26_Ret val = SwiftCallbackFunc26(&SwiftCallbackFunc26Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nuint)unchecked((nuint)1050319650554930471), val.F0); + Assert.Equal((byte)89, val.F1); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F27_S0 + { + public short F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 3)] + struct F27_S1_S0 + { + public ushort F0; + public sbyte F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F27_S1 + { + public long F0; + public F27_S1_S0 F1; + public float F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F27_S2 + { + public ulong F0; + public sbyte F1; + public uint F2; + public long F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F27_S3_S0 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F27_S3 + { + public F27_S3_S0 F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func271fS2fs6UInt64V_s5UInt8VAA6F27_S0VA2gA0I3_S1Vs5Int32VAA0I3_S2VSis6UInt32VAA0I3_S3VtXE_tF")] + private static extern float SwiftCallbackFunc27(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static float SwiftCallbackFunc27Callback(ulong a0, byte a1, F27_S0 a2, byte a3, byte a4, F27_S1 a5, int a6, F27_S2 a7, nint a8, uint a9, F27_S3 a10, SwiftSelf self) + { + try + { + Assert.Equal((ulong)4847421047018330189, a0); + Assert.Equal((byte)214, a1); + Assert.Equal((short)31313, a2.F0); + Assert.Equal((byte)207, a3); + Assert.Equal((byte)174, a4); + Assert.Equal((long)4476120319602257660, a5.F0); + Assert.Equal((ushort)26662, a5.F1.F0); + Assert.Equal((sbyte)-55, a5.F1.F1); + Assert.Equal((float)70666, a5.F2); + Assert.Equal((int)1340306103, a6); + Assert.Equal((ulong)2772939788297637999, a7.F0); + Assert.Equal((sbyte)-65, a7.F1); + Assert.Equal((uint)7500441, a7.F2); + Assert.Equal((long)4926907273817562134, a7.F3); + Assert.Equal((nint)unchecked((nint)5862689255099071258), a8); + Assert.Equal((uint)1077270996, a9); + Assert.Equal((ushort)35167, a10.F0.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 8117856; + } + + [Fact] + public static void TestSwiftCallbackFunc27() + { + Console.Write("Running SwiftCallbackFunc27: "); + ExceptionDispatchInfo ex = null; + float val = SwiftCallbackFunc27(&SwiftCallbackFunc27Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((float)8117856, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 9)] + struct F28_S0 + { + public ulong F0; + public sbyte F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 28)] + struct F28_S1 + { + public long F0; + public nuint F1; + public nint F2; + public int F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F28_S2 + { + public nint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F28_S3 + { + public long F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F28_Ret_S0 + { + public float F0; + + public F28_Ret_S0(float f0) + { + F0 = f0; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 6)] + struct F28_Ret + { + public F28_Ret_S0 F0; + public ushort F1; + + public F28_Ret(F28_Ret_S0 f0, ushort f1) + { + F0 = f0; + F1 = f1; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func281fAA7F28_RetVAEs6UInt32V_s6UInt16Vs4Int8VAkISfAA0G3_S0VSds6UInt64VAA0G3_S1VAA0G3_S2VAA0G3_S3VtXE_tF")] + private static extern F28_Ret SwiftCallbackFunc28(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F28_Ret SwiftCallbackFunc28Callback(uint a0, ushort a1, sbyte a2, sbyte a3, ushort a4, float a5, F28_S0 a6, double a7, ulong a8, F28_S1 a9, F28_S2 a10, F28_S3 a11, SwiftSelf self) + { + try + { + Assert.Equal((uint)893827094, a0); + Assert.Equal((ushort)38017, a1); + Assert.Equal((sbyte)-90, a2); + Assert.Equal((sbyte)-1, a3); + Assert.Equal((ushort)16109, a4); + Assert.Equal((float)5844449, a5); + Assert.Equal((ulong)176269147098539470, a6.F0); + Assert.Equal((sbyte)23, a6.F1); + Assert.Equal((double)1431426259441210, a7); + Assert.Equal((ulong)6103261251702315645, a8); + Assert.Equal((long)3776818122826483419, a9.F0); + Assert.Equal((nuint)unchecked((nuint)9181420263296840471), a9.F1); + Assert.Equal((nint)unchecked((nint)3281861424961082542), a9.F2); + Assert.Equal((int)1442905253, a9.F3); + Assert.Equal((nint)unchecked((nint)8760009193798370900), a10.F0); + Assert.Equal((long)7119917900929398683, a11.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F28_Ret(new F28_Ret_S0(4515425), 25944); + } + + [Fact] + public static void TestSwiftCallbackFunc28() + { + Console.Write("Running SwiftCallbackFunc28: "); + ExceptionDispatchInfo ex = null; + F28_Ret val = SwiftCallbackFunc28(&SwiftCallbackFunc28Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((float)4515425, val.F0.F0); + Assert.Equal((ushort)25944, val.F1); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 18)] + struct F29_S0 + { + public byte F0; + public double F1; + public ushort F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 28)] + struct F29_S1 + { + public uint F0; + public nint F1; + public ulong F2; + public uint F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F29_S2 + { + public int F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F29_S3 + { + public uint F0; + public uint F1; + public float F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F29_S4 + { + public int F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F29_Ret_S0 + { + public nint F0; + public ulong F1; + + public F29_Ret_S0(nint f0, ulong f1) + { + F0 = f0; + F1 = f1; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 52)] + struct F29_Ret + { + public nuint F0; + public nuint F1; + public nuint F2; + public F29_Ret_S0 F3; + public ulong F4; + public uint F5; + + public F29_Ret(nuint f0, nuint f1, nuint f2, F29_Ret_S0 f3, ulong f4, uint f5) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + F4 = f4; + F5 = f5; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func291fAA7F29_RetVAeA0G3_S0V_Sis6UInt64Vs5UInt8Vs5Int64VAKSiAA0G3_S1Vs5Int32Vs4Int8VAkiA0G3_S2VAA0G3_S3Vs5Int16VAA0G3_S4Vs6UInt32VtXE_tF")] + private static extern F29_Ret SwiftCallbackFunc29(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F29_Ret SwiftCallbackFunc29Callback(F29_S0 a0, nint a1, ulong a2, byte a3, long a4, byte a5, nint a6, F29_S1 a7, int a8, sbyte a9, byte a10, ulong a11, F29_S2 a12, F29_S3 a13, short a14, F29_S4 a15, uint a16, SwiftSelf self) + { + try + { + Assert.Equal((byte)152, a0.F0); + Assert.Equal((double)737900189383874, a0.F1); + Assert.Equal((ushort)33674, a0.F2); + Assert.Equal((nint)unchecked((nint)5162040247631126074), a1); + Assert.Equal((ulong)6524156301721885895, a2); + Assert.Equal((byte)129, a3); + Assert.Equal((long)6661424933974053497, a4); + Assert.Equal((byte)145, a5); + Assert.Equal((nint)unchecked((nint)7521422786615537370), a6); + Assert.Equal((uint)1361601345, a7.F0); + Assert.Equal((nint)unchecked((nint)3366726213840694614), a7.F1); + Assert.Equal((ulong)7767610514138029164, a7.F2); + Assert.Equal((uint)1266864987, a7.F3); + Assert.Equal((int)1115803878, a8); + Assert.Equal((sbyte)5, a9); + Assert.Equal((byte)80, a10); + Assert.Equal((ulong)2041754562738600205, a11); + Assert.Equal((int)1492686870, a12.F0); + Assert.Equal((uint)142491811, a13.F0); + Assert.Equal((uint)1644962309, a13.F1); + Assert.Equal((float)1905811, a13.F2); + Assert.Equal((short)-3985, a14); + Assert.Equal((int)1921386549, a15.F0); + Assert.Equal((uint)1510666400, a16); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F29_Ret(unchecked((nuint)1866868811776234672), unchecked((nuint)8169323498884891375), unchecked((nuint)2528257272266524428), new F29_Ret_S0(unchecked((nint)4705260670026405131), 8299241689326234556), 4459635217352912270, 188636136); + } + + [Fact] + public static void TestSwiftCallbackFunc29() + { + Console.Write("Running SwiftCallbackFunc29: "); + ExceptionDispatchInfo ex = null; + F29_Ret val = SwiftCallbackFunc29(&SwiftCallbackFunc29Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nuint)unchecked((nuint)1866868811776234672), val.F0); + Assert.Equal((nuint)unchecked((nuint)8169323498884891375), val.F1); + Assert.Equal((nuint)unchecked((nuint)2528257272266524428), val.F2); + Assert.Equal((nint)unchecked((nint)4705260670026405131), val.F3.F0); + Assert.Equal((ulong)8299241689326234556, val.F3.F1); + Assert.Equal((ulong)4459635217352912270, val.F4); + Assert.Equal((uint)188636136, val.F5); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 7)] + struct F30_S0 + { + public ushort F0; + public short F1; + public short F2; + public sbyte F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F30_S1 + { + public ushort F0; + public nuint F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F30_S2 + { + public long F0; + public sbyte F1; + public ushort F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F30_S3 + { + public sbyte F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func301fS2fAA6F30_S0V_AA0G3_S1VAA0G3_S2VAA0G3_S3VSitXE_tF")] + private static extern float SwiftCallbackFunc30(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static float SwiftCallbackFunc30Callback(F30_S0 a0, F30_S1 a1, F30_S2 a2, F30_S3 a3, nint a4, SwiftSelf self) + { + try + { + Assert.Equal((ushort)50723, a0.F0); + Assert.Equal((short)19689, a0.F1); + Assert.Equal((short)-6469, a0.F2); + Assert.Equal((sbyte)83, a0.F3); + Assert.Equal((ushort)51238, a1.F0); + Assert.Equal((nuint)unchecked((nuint)5879147675377398012), a1.F1); + Assert.Equal((long)7909999288286190848, a2.F0); + Assert.Equal((sbyte)-99, a2.F1); + Assert.Equal((ushort)61385, a2.F2); + Assert.Equal((sbyte)48, a3.F0); + Assert.Equal((nint)unchecked((nint)2980085298293056148), a4); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 289587; + } + + [Fact] + public static void TestSwiftCallbackFunc30() + { + Console.Write("Running SwiftCallbackFunc30: "); + ExceptionDispatchInfo ex = null; + float val = SwiftCallbackFunc30(&SwiftCallbackFunc30Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((float)289587, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F31_S0 + { + public int F0; + public ulong F1; + public nuint F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F31_Ret_S0 + { + public uint F0; + public float F1; + public ushort F2; + public short F3; + public float F4; + + public F31_Ret_S0(uint f0, float f1, ushort f2, short f3, float f4) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + F4 = f4; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 18)] + struct F31_Ret + { + public F31_Ret_S0 F0; + public ushort F1; + + public F31_Ret(F31_Ret_S0 f0, ushort f1) + { + F0 = f0; + F1 = f1; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func311fAA7F31_RetVAeA0G3_S0V_SdtXE_tF")] + private static extern F31_Ret SwiftCallbackFunc31(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F31_Ret SwiftCallbackFunc31Callback(F31_S0 a0, double a1, SwiftSelf self) + { + try + { + Assert.Equal((int)1072945099, a0.F0); + Assert.Equal((ulong)5760996810500287322, a0.F1); + Assert.Equal((nuint)unchecked((nuint)3952909367135409979), a0.F2); + Assert.Equal((double)2860786541632685, a1); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F31_Ret(new F31_Ret_S0(1236856932, 1761447, 1260, 25704, 6212541), 44632); + } + + [Fact] + public static void TestSwiftCallbackFunc31() + { + Console.Write("Running SwiftCallbackFunc31: "); + ExceptionDispatchInfo ex = null; + F31_Ret val = SwiftCallbackFunc31(&SwiftCallbackFunc31Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((uint)1236856932, val.F0.F0); + Assert.Equal((float)1761447, val.F0.F1); + Assert.Equal((ushort)1260, val.F0.F2); + Assert.Equal((short)25704, val.F0.F3); + Assert.Equal((float)6212541, val.F0.F4); + Assert.Equal((ushort)44632, val.F1); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F32_Ret + { + public nuint F0; + public double F1; + public nint F2; + + public F32_Ret(nuint f0, double f1, nint f2) + { + F0 = f0; + F1 = f1; + F2 = f2; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func321fAA7F32_RetVAEs6UInt16V_s5Int16VtXE_tF")] + private static extern F32_Ret SwiftCallbackFunc32(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F32_Ret SwiftCallbackFunc32Callback(ushort a0, short a1, SwiftSelf self) + { + try + { + Assert.Equal((ushort)21020, a0); + Assert.Equal((short)7462, a1); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F32_Ret(unchecked((nuint)868833742355713000), 411817582525317, unchecked((nint)3926422244180816571)); + } + + [Fact] + public static void TestSwiftCallbackFunc32() + { + Console.Write("Running SwiftCallbackFunc32: "); + ExceptionDispatchInfo ex = null; + F32_Ret val = SwiftCallbackFunc32(&SwiftCallbackFunc32Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nuint)unchecked((nuint)868833742355713000), val.F0); + Assert.Equal((double)411817582525317, val.F1); + Assert.Equal((nint)unchecked((nint)3926422244180816571), val.F2); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F33_S0 + { + public short F0; + public ulong F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F33_S1_S0 + { + public short F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F33_S1 + { + public F33_S1_S0 F0; + public uint F1; + public nuint F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F33_S2 + { + public uint F0; + public ulong F1; + public sbyte F2; + public sbyte F3; + public nuint F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F33_S3_S0_S0 + { + public short F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F33_S3_S0 + { + public F33_S3_S0_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F33_S3 + { + public F33_S3_S0 F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func331fS2uAA6F33_S0V_SfAA0G3_S1Vs6UInt32VSis4Int8VAKSfs5UInt8VSfAkA0G3_S2VSiAA0G3_S3VSiAItXE_tF")] + private static extern nuint SwiftCallbackFunc33(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static nuint SwiftCallbackFunc33Callback(F33_S0 a0, float a1, F33_S1 a2, uint a3, nint a4, sbyte a5, sbyte a6, float a7, byte a8, float a9, sbyte a10, F33_S2 a11, nint a12, F33_S3 a13, nint a14, uint a15, SwiftSelf self) + { + try + { + Assert.Equal((short)-23471, a0.F0); + Assert.Equal((ulong)2736941806609505888, a0.F1); + Assert.Equal((float)6930550, a1); + Assert.Equal((short)32476, a2.F0.F0); + Assert.Equal((uint)165441961, a2.F1); + Assert.Equal((nuint)unchecked((nuint)3890227499323387948), a2.F2); + Assert.Equal((uint)591524870, a3); + Assert.Equal((nint)unchecked((nint)1668420058132495503), a4); + Assert.Equal((sbyte)-67, a5); + Assert.Equal((sbyte)94, a6); + Assert.Equal((float)3180786, a7); + Assert.Equal((byte)42, a8); + Assert.Equal((float)7674952, a9); + Assert.Equal((sbyte)43, a10); + Assert.Equal((uint)771356149, a11.F0); + Assert.Equal((ulong)3611576949210389997, a11.F1); + Assert.Equal((sbyte)-15, a11.F2); + Assert.Equal((sbyte)7, a11.F3); + Assert.Equal((nuint)unchecked((nuint)2577587324978560192), a11.F4); + Assert.Equal((nint)unchecked((nint)8266150294848599489), a12); + Assert.Equal((short)9216, a13.F0.F0.F0); + Assert.Equal((nint)unchecked((nint)710302565025364450), a14); + Assert.Equal((uint)1060812904, a15); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return unchecked((nuint)8322391372382633712); + } + + [Fact] + public static void TestSwiftCallbackFunc33() + { + Console.Write("Running SwiftCallbackFunc33: "); + ExceptionDispatchInfo ex = null; + nuint val = SwiftCallbackFunc33(&SwiftCallbackFunc33Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nuint)unchecked((nuint)8322391372382633712), val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F34_S0_S0 + { + public uint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F34_S0 + { + public F34_S0_S0 F0; + public nuint F1; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func341fs6UInt16VAEs6UInt32V_AA6F34_S0VSus5Int16VtXE_tF")] + private static extern ushort SwiftCallbackFunc34(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static ushort SwiftCallbackFunc34Callback(uint a0, F34_S0 a1, nuint a2, short a3, SwiftSelf self) + { + try + { + Assert.Equal((uint)2068009847, a0); + Assert.Equal((uint)845123292, a1.F0.F0); + Assert.Equal((nuint)unchecked((nuint)5148244462913472487), a1.F1); + Assert.Equal((nuint)unchecked((nuint)8632568386462910655), a2); + Assert.Equal((short)7058, a3); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 20647; + } + + [Fact] + public static void TestSwiftCallbackFunc34() + { + Console.Write("Running SwiftCallbackFunc34: "); + ExceptionDispatchInfo ex = null; + ushort val = SwiftCallbackFunc34(&SwiftCallbackFunc34Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ushort)20647, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F35_S0_S0_S0 + { + public int F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F35_S0_S0 + { + public long F0; + public F35_S0_S0_S0 F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F35_S0_S1 + { + public double F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F35_S0 + { + public F35_S0_S0 F0; + public int F1; + public F35_S0_S1 F2; + public nint F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F35_S1 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F35_S2_S0 + { + public double F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F35_S2 + { + public F35_S2_S0 F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func351fs6UInt64VAEs5UInt8V_s4Int8VSfs5Int64VSiAA6F35_S0VAA0K3_S1VAA0K3_S2VtXE_tF")] + private static extern ulong SwiftCallbackFunc35(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static ulong SwiftCallbackFunc35Callback(byte a0, sbyte a1, float a2, long a3, nint a4, F35_S0 a5, F35_S1 a6, F35_S2 a7, SwiftSelf self) + { + try + { + Assert.Equal((byte)182, a0); + Assert.Equal((sbyte)-16, a1); + Assert.Equal((float)7763558, a2); + Assert.Equal((long)5905028570860904693, a3); + Assert.Equal((nint)unchecked((nint)5991001624972063224), a4); + Assert.Equal((long)6663912001709962059, a5.F0.F0); + Assert.Equal((int)1843939591, a5.F0.F1.F0); + Assert.Equal((int)1095170337, a5.F1); + Assert.Equal((double)3908756332193409, a5.F2.F0); + Assert.Equal((nint)unchecked((nint)8246190362462442203), a5.F3); + Assert.Equal((ushort)52167, a6.F0); + Assert.Equal((double)283499999631068, a7.F0.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 4329482286317894385; + } + + [Fact] + public static void TestSwiftCallbackFunc35() + { + Console.Write("Running SwiftCallbackFunc35: "); + ExceptionDispatchInfo ex = null; + ulong val = SwiftCallbackFunc35(&SwiftCallbackFunc35Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ulong)4329482286317894385, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F36_S0 + { + public uint F0; + public long F1; + public byte F2; + public nuint F3; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func361fS2iSu_SdSus5UInt8Vs5Int64VAA6F36_S0Vs4Int8VtXE_tF")] + private static extern nint SwiftCallbackFunc36(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static nint SwiftCallbackFunc36Callback(nuint a0, double a1, nuint a2, byte a3, long a4, F36_S0 a5, sbyte a6, SwiftSelf self) + { + try + { + Assert.Equal((nuint)unchecked((nuint)5079603407518207003), a0); + Assert.Equal((double)2365862518115571, a1); + Assert.Equal((nuint)unchecked((nuint)6495651757722767835), a2); + Assert.Equal((byte)46, a3); + Assert.Equal((long)1550138390178394449, a4); + Assert.Equal((uint)1858960269, a5.F0); + Assert.Equal((long)1925263848394986294, a5.F1); + Assert.Equal((byte)217, a5.F2); + Assert.Equal((nuint)unchecked((nuint)8520779488644482307), a5.F3); + Assert.Equal((sbyte)-83, a6); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return unchecked((nint)2889858798271230534); + } + + [Fact] + public static void TestSwiftCallbackFunc36() + { + Console.Write("Running SwiftCallbackFunc36: "); + ExceptionDispatchInfo ex = null; + nint val = SwiftCallbackFunc36(&SwiftCallbackFunc36Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nint)unchecked((nint)2889858798271230534), val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F37_S0_S0 + { + public nint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 28)] + struct F37_S0 + { + public nuint F0; + public uint F1; + public F37_S0_S0 F2; + public float F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F37_S1 + { + public nuint F0; + public uint F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F37_S2 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F37_Ret + { + public float F0; + public byte F1; + public short F2; + public ulong F3; + + public F37_Ret(float f0, byte f1, short f2, ulong f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func371fAA7F37_RetVAEs6UInt64V_AA0G3_S0VSds6UInt16VAA0G3_S1VAA0G3_S2VtXE_tF")] + private static extern F37_Ret SwiftCallbackFunc37(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F37_Ret SwiftCallbackFunc37Callback(ulong a0, F37_S0 a1, double a2, ushort a3, F37_S1 a4, F37_S2 a5, SwiftSelf self) + { + try + { + Assert.Equal((ulong)1623104856688575867, a0); + Assert.Equal((nuint)unchecked((nuint)3785544303342575322), a1.F0); + Assert.Equal((uint)717682682, a1.F1); + Assert.Equal((nint)unchecked((nint)2674933748436691896), a1.F2.F0); + Assert.Equal((float)3211458, a1.F3); + Assert.Equal((double)996705046384579, a2); + Assert.Equal((ushort)8394, a3); + Assert.Equal((nuint)unchecked((nuint)1048947722954084863), a4.F0); + Assert.Equal((uint)252415487, a4.F1); + Assert.Equal((ushort)3664, a5.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F37_Ret(433224, 163, -5538, 4525229514824359136); + } + + [Fact] + public static void TestSwiftCallbackFunc37() + { + Console.Write("Running SwiftCallbackFunc37: "); + ExceptionDispatchInfo ex = null; + F37_Ret val = SwiftCallbackFunc37(&SwiftCallbackFunc37Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((float)433224, val.F0); + Assert.Equal((byte)163, val.F1); + Assert.Equal((short)-5538, val.F2); + Assert.Equal((ulong)4525229514824359136, val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F38_S0_S0 + { + public nint F0; + public float F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F38_S0 + { + public F38_S0_S0 F0; + public ushort F1; + public int F2; + public float F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F38_S1 + { + public short F0; + public int F1; + public uint F2; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func381fS2dAA6F38_S0V_AA0G3_S1VSds5Int16Vs4Int8Vs6UInt32VAISfSiSfAMs5UInt8VSdAKtXE_tF")] + private static extern double SwiftCallbackFunc38(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static double SwiftCallbackFunc38Callback(F38_S0 a0, F38_S1 a1, double a2, short a3, sbyte a4, uint a5, short a6, float a7, nint a8, float a9, uint a10, byte a11, double a12, sbyte a13, SwiftSelf self) + { + try + { + Assert.Equal((nint)unchecked((nint)7389960750529773276), a0.F0.F0); + Assert.Equal((float)4749108, a0.F0.F1); + Assert.Equal((ushort)54323, a0.F1); + Assert.Equal((int)634649910, a0.F2); + Assert.Equal((float)83587, a0.F3); + Assert.Equal((short)-15547, a1.F0); + Assert.Equal((int)1747384081, a1.F1); + Assert.Equal((uint)851987981, a1.F2); + Assert.Equal((double)3543874366683681, a2); + Assert.Equal((short)5045, a3); + Assert.Equal((sbyte)-32, a4); + Assert.Equal((uint)2084540698, a5); + Assert.Equal((short)25583, a6); + Assert.Equal((float)3158067, a7); + Assert.Equal((nint)unchecked((nint)1655263182833369283), a8); + Assert.Equal((float)829404, a9); + Assert.Equal((uint)1888859844, a10); + Assert.Equal((byte)153, a11); + Assert.Equal((double)222366180309763, a12); + Assert.Equal((sbyte)61, a13); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 2529010496939244; + } + + [Fact] + public static void TestSwiftCallbackFunc38() + { + Console.Write("Running SwiftCallbackFunc38: "); + ExceptionDispatchInfo ex = null; + double val = SwiftCallbackFunc38(&SwiftCallbackFunc38Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((double)2529010496939244, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F39_S0_S0 + { + public short F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F39_S0_S1 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F39_S0 + { + public F39_S0_S0 F0; + public int F1; + public F39_S0_S1 F2; + public nuint F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F39_S1 + { + public ushort F0; + public byte F1; + public float F2; + public long F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F39_S2 + { + public int F0; + public float F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F39_S3 + { + public uint F0; + public nint F1; + public nint F2; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func391fS2iAA6F39_S0V_Sus6UInt32VSdAA0G3_S1VAA0G3_S2Vs4Int8VAA0G3_S3Vs5Int32Vs6UInt64Vs5UInt8VtXE_tF")] + private static extern nint SwiftCallbackFunc39(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static nint SwiftCallbackFunc39Callback(F39_S0 a0, nuint a1, uint a2, double a3, F39_S1 a4, F39_S2 a5, sbyte a6, F39_S3 a7, int a8, ulong a9, byte a10, SwiftSelf self) + { + try + { + Assert.Equal((short)-31212, a0.F0.F0); + Assert.Equal((int)1623216479, a0.F1); + Assert.Equal((ushort)7181, a0.F2.F0); + Assert.Equal((nuint)unchecked((nuint)8643545152918150186), a0.F3); + Assert.Equal((nuint)unchecked((nuint)799631211988519637), a1); + Assert.Equal((uint)94381581, a2); + Assert.Equal((double)761127371030426, a3); + Assert.Equal((ushort)417, a4.F0); + Assert.Equal((byte)85, a4.F1); + Assert.Equal((float)1543931, a4.F2); + Assert.Equal((long)3918460222899735322, a4.F3); + Assert.Equal((int)883468300, a5.F0); + Assert.Equal((float)2739152, a5.F1); + Assert.Equal((sbyte)-94, a6); + Assert.Equal((uint)1374766954, a7.F0); + Assert.Equal((nint)unchecked((nint)2042223450490396789), a7.F1); + Assert.Equal((nint)unchecked((nint)2672454113535023130), a7.F2); + Assert.Equal((int)946259065, a8); + Assert.Equal((ulong)6805548458517673751, a9); + Assert.Equal((byte)61, a10); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return unchecked((nint)3023907365579871618); + } + + [Fact] + public static void TestSwiftCallbackFunc39() + { + Console.Write("Running SwiftCallbackFunc39: "); + ExceptionDispatchInfo ex = null; + nint val = SwiftCallbackFunc39(&SwiftCallbackFunc39Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nint)unchecked((nint)3023907365579871618), val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F40_S0 + { + public short F0; + public int F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F40_S1 + { + public int F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 25)] + struct F40_S2 + { + public long F0; + public ushort F1; + public nint F2; + public byte F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F40_S3_S0 + { + public float F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F40_S3 + { + public nuint F0; + public double F1; + public F40_S3_S0 F2; + public double F3; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func401fS2uAA6F40_S0V_s6UInt32Vs5UInt8VAA0G3_S1VAA0G3_S2Vs6UInt64VSuAOSis6UInt16VAgA0G3_S3VSutXE_tF")] + private static extern nuint SwiftCallbackFunc40(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static nuint SwiftCallbackFunc40Callback(F40_S0 a0, uint a1, byte a2, F40_S1 a3, F40_S2 a4, ulong a5, nuint a6, ulong a7, nint a8, ushort a9, uint a10, F40_S3 a11, nuint a12, SwiftSelf self) + { + try + { + Assert.Equal((short)22601, a0.F0); + Assert.Equal((int)312892872, a0.F1); + Assert.Equal((uint)1040102825, a1); + Assert.Equal((byte)56, a2); + Assert.Equal((int)101203812, a3.F0); + Assert.Equal((long)4298883321494088257, a4.F0); + Assert.Equal((ushort)2095, a4.F1); + Assert.Equal((nint)unchecked((nint)1536552108568739270), a4.F2); + Assert.Equal((byte)220, a4.F3); + Assert.Equal((ulong)2564624804830565018, a5); + Assert.Equal((nuint)unchecked((nuint)173855559108584219), a6); + Assert.Equal((ulong)6222832940831380264, a7); + Assert.Equal((nint)unchecked((nint)1898370824516510398), a8); + Assert.Equal((ushort)3352, a9); + Assert.Equal((uint)1643571476, a10); + Assert.Equal((nuint)unchecked((nuint)7940054758811932961), a11.F0); + Assert.Equal((double)246670432251533, a11.F1); + Assert.Equal((float)7890596, a11.F2.F0); + Assert.Equal((double)1094140965415232, a11.F3); + Assert.Equal((nuint)unchecked((nuint)2081923113238309816), a12); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return unchecked((nuint)4616766375038360400); + } + + [Fact] + public static void TestSwiftCallbackFunc40() + { + Console.Write("Running SwiftCallbackFunc40: "); + ExceptionDispatchInfo ex = null; + nuint val = SwiftCallbackFunc40(&SwiftCallbackFunc40Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nuint)unchecked((nuint)4616766375038360400), val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F41_S0 + { + public uint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F41_Ret + { + public ulong F0; + public double F1; + public uint F2; + public uint F3; + + public F41_Ret(ulong f0, double f1, uint f2, uint f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func411fAA7F41_RetVAeA0G3_S0VXE_tF")] + private static extern F41_Ret SwiftCallbackFunc41(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F41_Ret SwiftCallbackFunc41Callback(F41_S0 a0, SwiftSelf self) + { + try + { + Assert.Equal((uint)1430200072, a0.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F41_Ret(5150172797708870426, 3489330932479773, 833949606, 2098665090); + } + + [Fact] + public static void TestSwiftCallbackFunc41() + { + Console.Write("Running SwiftCallbackFunc41: "); + ExceptionDispatchInfo ex = null; + F41_Ret val = SwiftCallbackFunc41(&SwiftCallbackFunc41Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ulong)5150172797708870426, val.F0); + Assert.Equal((double)3489330932479773, val.F1); + Assert.Equal((uint)833949606, val.F2); + Assert.Equal((uint)2098665090, val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F42_S0_S0 + { + public nint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F42_S0 + { + public F42_S0_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F42_S1 + { + public uint F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func421fS2is5Int32V_s6UInt32VAA6F42_S0VSfs5UInt8VAA0I3_S1VtXE_tF")] + private static extern nint SwiftCallbackFunc42(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static nint SwiftCallbackFunc42Callback(int a0, uint a1, F42_S0 a2, float a3, byte a4, F42_S1 a5, SwiftSelf self) + { + try + { + Assert.Equal((int)1046060439, a0); + Assert.Equal((uint)1987212952, a1); + Assert.Equal((nint)unchecked((nint)4714080408858753964), a2.F0.F0); + Assert.Equal((float)2364146, a3); + Assert.Equal((byte)25, a4); + Assert.Equal((uint)666986488, a5.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return unchecked((nint)4147856807670154637); + } + + [Fact] + public static void TestSwiftCallbackFunc42() + { + Console.Write("Running SwiftCallbackFunc42: "); + ExceptionDispatchInfo ex = null; + nint val = SwiftCallbackFunc42(&SwiftCallbackFunc42Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nint)unchecked((nint)4147856807670154637), val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F43_S0 + { + public int F0; + public int F1; + public nint F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F43_S1 + { + public sbyte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F43_Ret + { + public ushort F0; + + public F43_Ret(ushort f0) + { + F0 = f0; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func431fAA7F43_RetVAeA0G3_S0V_AA0G3_S1VtXE_tF")] + private static extern F43_Ret SwiftCallbackFunc43(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F43_Ret SwiftCallbackFunc43Callback(F43_S0 a0, F43_S1 a1, SwiftSelf self) + { + try + { + Assert.Equal((int)406102630, a0.F0); + Assert.Equal((int)1946236062, a0.F1); + Assert.Equal((nint)unchecked((nint)663606396354980308), a0.F2); + Assert.Equal((sbyte)-8, a1.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F43_Ret(18672); + } + + [Fact] + public static void TestSwiftCallbackFunc43() + { + Console.Write("Running SwiftCallbackFunc43: "); + ExceptionDispatchInfo ex = null; + F43_Ret val = SwiftCallbackFunc43(&SwiftCallbackFunc43Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ushort)18672, val.F0); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F44_S0 + { + public uint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F44_S1_S0 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F44_S1_S1 + { + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F44_S1 + { + public short F0; + public short F1; + public F44_S1_S0 F2; + public F44_S1_S1 F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F44_S2 + { + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F44_S3 + { + public sbyte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F44_Ret_S0 + { + public nuint F0; + + public F44_Ret_S0(nuint f0) + { + F0 = f0; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F44_Ret + { + public nint F0; + public F44_Ret_S0 F1; + public double F2; + + public F44_Ret(nint f0, F44_Ret_S0 f1, double f2) + { + F0 = f0; + F1 = f1; + F2 = f2; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func441fAA7F44_RetVAESd_AA0G3_S0VAA0G3_S1VAA0G3_S2VAA0G3_S3VtXE_tF")] + private static extern F44_Ret SwiftCallbackFunc44(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F44_Ret SwiftCallbackFunc44Callback(double a0, F44_S0 a1, F44_S1 a2, F44_S2 a3, F44_S3 a4, SwiftSelf self) + { + try + { + Assert.Equal((double)4281406007431544, a0); + Assert.Equal((uint)2097291497, a1.F0); + Assert.Equal((short)-10489, a2.F0); + Assert.Equal((short)-9573, a2.F1); + Assert.Equal((ushort)62959, a2.F2.F0); + Assert.Equal((nuint)unchecked((nuint)7144119809173057975), a2.F3.F0); + Assert.Equal((nuint)unchecked((nuint)168733393207234277), a3.F0); + Assert.Equal((sbyte)64, a4.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F44_Ret(unchecked((nint)7157474620613398513), new F44_Ret_S0(unchecked((nuint)8272092288451488897)), 8724612718809); + } + + [Fact] + public static void TestSwiftCallbackFunc44() + { + Console.Write("Running SwiftCallbackFunc44: "); + ExceptionDispatchInfo ex = null; + F44_Ret val = SwiftCallbackFunc44(&SwiftCallbackFunc44Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nint)unchecked((nint)7157474620613398513), val.F0); + Assert.Equal((nuint)unchecked((nuint)8272092288451488897), val.F1.F0); + Assert.Equal((double)8724612718809, val.F2); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F45_S0 + { + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 10)] + struct F45_S1 + { + public nuint F0; + public short F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F45_Ret_S0 + { + public float F0; + + public F45_Ret_S0(float f0) + { + F0 = f0; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 48)] + struct F45_Ret + { + public double F0; + public F45_Ret_S0 F1; + public long F2; + public double F3; + public ulong F4; + public sbyte F5; + public int F6; + + public F45_Ret(double f0, F45_Ret_S0 f1, long f2, double f3, ulong f4, sbyte f5, int f6) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + F4 = f4; + F5 = f5; + F6 = f6; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func451fAA7F45_RetVAeA0G3_S0V_AA0G3_S1Vs5UInt8VtXE_tF")] + private static extern F45_Ret SwiftCallbackFunc45(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F45_Ret SwiftCallbackFunc45Callback(F45_S0 a0, F45_S1 a1, byte a2, SwiftSelf self) + { + try + { + Assert.Equal((nuint)unchecked((nuint)5311803360204128233), a0.F0); + Assert.Equal((nuint)unchecked((nuint)2204790044275015546), a1.F0); + Assert.Equal((short)8942, a1.F1); + Assert.Equal((byte)207, a2); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F45_Ret(262658215125446, new F45_Ret_S0(3145713), 4924669542959578265, 2052183120467519, 3135406744871464298, 81, 1000720476); + } + + [Fact] + public static void TestSwiftCallbackFunc45() + { + Console.Write("Running SwiftCallbackFunc45: "); + ExceptionDispatchInfo ex = null; + F45_Ret val = SwiftCallbackFunc45(&SwiftCallbackFunc45Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((double)262658215125446, val.F0); + Assert.Equal((float)3145713, val.F1.F0); + Assert.Equal((long)4924669542959578265, val.F2); + Assert.Equal((double)2052183120467519, val.F3); + Assert.Equal((ulong)3135406744871464298, val.F4); + Assert.Equal((sbyte)81, val.F5); + Assert.Equal((int)1000720476, val.F6); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 26)] + struct F46_Ret + { + public nuint F0; + public double F1; + public long F2; + public ushort F3; + + public F46_Ret(nuint f0, double f1, long f2, ushort f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func461fAA7F46_RetVAESi_Sus6UInt16VAGs5Int64VtXE_tF")] + private static extern F46_Ret SwiftCallbackFunc46(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F46_Ret SwiftCallbackFunc46Callback(nint a0, nuint a1, ushort a2, ushort a3, long a4, SwiftSelf self) + { + try + { + Assert.Equal((nint)unchecked((nint)1855296013283572041), a0); + Assert.Equal((nuint)unchecked((nuint)1145047910516899437), a1); + Assert.Equal((ushort)20461, a2); + Assert.Equal((ushort)58204, a3); + Assert.Equal((long)1923767011143317115, a4); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F46_Ret(unchecked((nuint)4268855101008870857), 2061088094528291, 541679466428431692, 30655); + } + + [Fact] + public static void TestSwiftCallbackFunc46() + { + Console.Write("Running SwiftCallbackFunc46: "); + ExceptionDispatchInfo ex = null; + F46_Ret val = SwiftCallbackFunc46(&SwiftCallbackFunc46Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nuint)unchecked((nuint)4268855101008870857), val.F0); + Assert.Equal((double)2061088094528291, val.F1); + Assert.Equal((long)541679466428431692, val.F2); + Assert.Equal((ushort)30655, val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F47_S0 + { + public byte F0; + public int F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 13)] + struct F47_S1 + { + public nint F0; + public uint F1; + public sbyte F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F47_S2_S0 + { + public byte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 17)] + struct F47_S2 + { + public sbyte F0; + public float F1; + public int F2; + public float F3; + public F47_S2_S0 F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F47_S3 + { + public ulong F0; + public long F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F47_S4 + { + public ulong F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F47_Ret + { + public short F0; + public short F1; + public long F2; + + public F47_Ret(short f0, short f1, long f2) + { + F0 = f0; + F1 = f1; + F2 = f2; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func471fAA7F47_RetVAESi_Sfs6UInt32VAA0G3_S0VAA0G3_S1Vs6UInt16VSfS2iS2us5Int16VAA0G3_S2VAA0G3_S3VAA0G3_S4VtXE_tF")] + private static extern F47_Ret SwiftCallbackFunc47(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F47_Ret SwiftCallbackFunc47Callback(nint a0, float a1, uint a2, F47_S0 a3, F47_S1 a4, ushort a5, float a6, nint a7, nint a8, nuint a9, nuint a10, short a11, F47_S2 a12, F47_S3 a13, F47_S4 a14, SwiftSelf self) + { + try + { + Assert.Equal((nint)unchecked((nint)6545360066379352091), a0); + Assert.Equal((float)1240616, a1); + Assert.Equal((uint)575670382, a2); + Assert.Equal((byte)27, a3.F0); + Assert.Equal((int)1769677101, a3.F1); + Assert.Equal((nint)unchecked((nint)4175209822525678639), a4.F0); + Assert.Equal((uint)483151627, a4.F1); + Assert.Equal((sbyte)-41, a4.F2); + Assert.Equal((ushort)20891, a5); + Assert.Equal((float)1011044, a6); + Assert.Equal((nint)unchecked((nint)8543308148327168378), a7); + Assert.Equal((nint)unchecked((nint)9126721646663585297), a8); + Assert.Equal((nuint)unchecked((nuint)5438914191614359864), a9); + Assert.Equal((nuint)unchecked((nuint)5284613245897089025), a10); + Assert.Equal((short)-9227, a11); + Assert.Equal((sbyte)-23, a12.F0); + Assert.Equal((float)1294109, a12.F1); + Assert.Equal((int)411726757, a12.F2); + Assert.Equal((float)6621598, a12.F3); + Assert.Equal((byte)249, a12.F4.F0); + Assert.Equal((ulong)5281612261430853979, a13.F0); + Assert.Equal((long)7161295082465816089, a13.F1); + Assert.Equal((ulong)1995556861952451598, a14.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F47_Ret(32110, 21949, 479980404077668674); + } + + [Fact] + public static void TestSwiftCallbackFunc47() + { + Console.Write("Running SwiftCallbackFunc47: "); + ExceptionDispatchInfo ex = null; + F47_Ret val = SwiftCallbackFunc47(&SwiftCallbackFunc47Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((short)32110, val.F0); + Assert.Equal((short)21949, val.F1); + Assert.Equal((long)479980404077668674, val.F2); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F48_S0 + { + public ulong F0; + public short F1; + public ulong F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F48_S1_S0 + { + public float F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F48_S1 + { + public double F0; + public int F1; + public int F2; + public F48_S1_S0 F3; + public nuint F4; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func481fs5Int64VAEs4Int8V_s5Int16VAIs6UInt32VAA6F48_S0VAkA0K3_S1Vs5Int32VAQs6UInt16VAeKtXE_tF")] + private static extern long SwiftCallbackFunc48(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static long SwiftCallbackFunc48Callback(sbyte a0, short a1, short a2, uint a3, F48_S0 a4, uint a5, F48_S1 a6, int a7, int a8, ushort a9, long a10, uint a11, SwiftSelf self) + { + try + { + Assert.Equal((sbyte)-34, a0); + Assert.Equal((short)11634, a1); + Assert.Equal((short)-27237, a2); + Assert.Equal((uint)1039294154, a3); + Assert.Equal((ulong)1367847206719062131, a4.F0); + Assert.Equal((short)22330, a4.F1); + Assert.Equal((ulong)689282484471011648, a4.F2); + Assert.Equal((uint)1572626904, a5); + Assert.Equal((double)3054128759424009, a6.F0); + Assert.Equal((int)1677338134, a6.F1); + Assert.Equal((int)1257237843, a6.F2); + Assert.Equal((float)6264494, a6.F3.F0); + Assert.Equal((nuint)unchecked((nuint)8397097040610783205), a6.F4); + Assert.Equal((int)1060447208, a7); + Assert.Equal((int)269785114, a8); + Assert.Equal((ushort)20635, a9); + Assert.Equal((long)7679010342730986048, a10); + Assert.Equal((uint)1362633148, a11); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 1864372483209206459; + } + + [Fact] + public static void TestSwiftCallbackFunc48() + { + Console.Write("Running SwiftCallbackFunc48: "); + ExceptionDispatchInfo ex = null; + long val = SwiftCallbackFunc48(&SwiftCallbackFunc48Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((long)1864372483209206459, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F49_S0_S0 + { + public byte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F49_S0 + { + public F49_S0_S0 F0; + public ulong F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F49_Ret + { + public int F0; + public short F1; + public byte F2; + public byte F3; + public sbyte F4; + public long F5; + + public F49_Ret(int f0, short f1, byte f2, byte f3, sbyte f4, long f5) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + F4 = f4; + F5 = f5; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func491fAA7F49_RetVAeA0G3_S0V_s5Int64VtXE_tF")] + private static extern F49_Ret SwiftCallbackFunc49(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F49_Ret SwiftCallbackFunc49Callback(F49_S0 a0, long a1, SwiftSelf self) + { + try + { + Assert.Equal((byte)48, a0.F0.F0); + Assert.Equal((ulong)7563394992711018452, a0.F1); + Assert.Equal((long)4358370311341042916, a1); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F49_Ret(1638493854, -13624, 61, 236, -97, 3942201385605817844); + } + + [Fact] + public static void TestSwiftCallbackFunc49() + { + Console.Write("Running SwiftCallbackFunc49: "); + ExceptionDispatchInfo ex = null; + F49_Ret val = SwiftCallbackFunc49(&SwiftCallbackFunc49Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((int)1638493854, val.F0); + Assert.Equal((short)-13624, val.F1); + Assert.Equal((byte)61, val.F2); + Assert.Equal((byte)236, val.F3); + Assert.Equal((sbyte)-97, val.F4); + Assert.Equal((long)3942201385605817844, val.F5); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F50_S0_S0 + { + public double F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F50_S0 + { + public ushort F0; + public F50_S0_S0 F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F50_S1 + { + public double F0; + public ushort F1; + public int F2; + public nint F3; + public double F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F50_S2 + { + public int F0; + public float F1; + public uint F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 17)] + struct F50_S3 + { + public long F0; + public int F1; + public float F2; + public sbyte F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F50_S4 + { + public long F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F50_S5_S0 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F50_S5 + { + public F50_S5_S0 F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func501fs5UInt8VAeA6F50_S0V_AA0H3_S1VAeA0H3_S2Vs5Int32Vs6UInt64Vs4Int8VAQSfAA0H3_S3VAA0H3_S4VAA0H3_S5VSftXE_tF")] + private static extern byte SwiftCallbackFunc50(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static byte SwiftCallbackFunc50Callback(F50_S0 a0, F50_S1 a1, byte a2, F50_S2 a3, int a4, ulong a5, sbyte a6, sbyte a7, float a8, F50_S3 a9, F50_S4 a10, F50_S5 a11, float a12, SwiftSelf self) + { + try + { + Assert.Equal((ushort)31857, a0.F0); + Assert.Equal((double)1743417849706254, a0.F1.F0); + Assert.Equal((double)4104577461772135, a1.F0); + Assert.Equal((ushort)13270, a1.F1); + Assert.Equal((int)2072598986, a1.F2); + Assert.Equal((nint)unchecked((nint)9056978834867675248), a1.F3); + Assert.Equal((double)844742439929087, a1.F4); + Assert.Equal((byte)87, a2); + Assert.Equal((int)1420884537, a3.F0); + Assert.Equal((float)78807, a3.F1); + Assert.Equal((uint)1081688273, a3.F2); + Assert.Equal((int)336878110, a4); + Assert.Equal((ulong)1146514566942283069, a5); + Assert.Equal((sbyte)-93, a6); + Assert.Equal((sbyte)73, a7); + Assert.Equal((float)2321639, a8); + Assert.Equal((long)1940888991336881606, a9.F0); + Assert.Equal((int)688345394, a9.F1); + Assert.Equal((float)712275, a9.F2); + Assert.Equal((sbyte)-128, a9.F3); + Assert.Equal((long)2638503583829414770, a10.F0); + Assert.Equal((ushort)23681, a11.F0.F0); + Assert.Equal((float)8223218, a12); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 252; + } + + [Fact] + public static void TestSwiftCallbackFunc50() + { + Console.Write("Running SwiftCallbackFunc50: "); + ExceptionDispatchInfo ex = null; + byte val = SwiftCallbackFunc50(&SwiftCallbackFunc50Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((byte)252, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F51_S0 + { + public long F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F51_Ret + { + public ushort F0; + public sbyte F1; + public nint F2; + public ushort F3; + public ulong F4; + + public F51_Ret(ushort f0, sbyte f1, nint f2, ushort f3, ulong f4) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + F4 = f4; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func511fAA7F51_RetVAEs5Int16V_SuAA0G3_S0Vs6UInt64VtXE_tF")] + private static extern F51_Ret SwiftCallbackFunc51(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F51_Ret SwiftCallbackFunc51Callback(short a0, nuint a1, F51_S0 a2, ulong a3, SwiftSelf self) + { + try + { + Assert.Equal((short)10812, a0); + Assert.Equal((nuint)unchecked((nuint)470861239714315155), a1); + Assert.Equal((long)5415660333180374788, a2.F0); + Assert.Equal((ulong)2389942629143476149, a3); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F51_Ret(28396, 23, unchecked((nint)4042678034578400305), 16166, 8390419605778076733); + } + + [Fact] + public static void TestSwiftCallbackFunc51() + { + Console.Write("Running SwiftCallbackFunc51: "); + ExceptionDispatchInfo ex = null; + F51_Ret val = SwiftCallbackFunc51(&SwiftCallbackFunc51Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ushort)28396, val.F0); + Assert.Equal((sbyte)23, val.F1); + Assert.Equal((nint)unchecked((nint)4042678034578400305), val.F2); + Assert.Equal((ushort)16166, val.F3); + Assert.Equal((ulong)8390419605778076733, val.F4); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F52_S0 + { + public float F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F52_S1 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 33)] + struct F52_Ret + { + public float F0; + public ushort F1; + public long F2; + public short F3; + public ulong F4; + public sbyte F5; + + public F52_Ret(float f0, ushort f1, long f2, short f3, ulong f4, sbyte f5) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + F4 = f4; + F5 = f5; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func521fAA7F52_RetVAESi_AA0G3_S0Vs5Int16VAiA0G3_S1VtXE_tF")] + private static extern F52_Ret SwiftCallbackFunc52(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F52_Ret SwiftCallbackFunc52Callback(nint a0, F52_S0 a1, short a2, short a3, F52_S1 a4, SwiftSelf self) + { + try + { + Assert.Equal((nint)unchecked((nint)3233654765973602550), a0); + Assert.Equal((float)5997729, a1.F0); + Assert.Equal((short)-7404, a2); + Assert.Equal((short)-20804, a3); + Assert.Equal((ushort)17231, a4.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F52_Ret(3003005, 4886, 1846269873983567093, 24151, 1408198981123859746, -41); + } + + [Fact] + public static void TestSwiftCallbackFunc52() + { + Console.Write("Running SwiftCallbackFunc52: "); + ExceptionDispatchInfo ex = null; + F52_Ret val = SwiftCallbackFunc52(&SwiftCallbackFunc52Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((float)3003005, val.F0); + Assert.Equal((ushort)4886, val.F1); + Assert.Equal((long)1846269873983567093, val.F2); + Assert.Equal((short)24151, val.F3); + Assert.Equal((ulong)1408198981123859746, val.F4); + Assert.Equal((sbyte)-41, val.F5); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F53_S0_S0_S0 + { + public long F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F53_S0_S0 + { + public F53_S0_S0_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 40)] + struct F53_S0 + { + public sbyte F0; + public F53_S0_S0 F1; + public byte F2; + public nuint F3; + public long F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 5)] + struct F53_S1 + { + public float F0; + public byte F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F53_S2 + { + public sbyte F0; + public long F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F53_S3_S0 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 10)] + struct F53_S3 + { + public int F0; + public uint F1; + public F53_S3_S0 F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F53_S4 + { + public short F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F53_S5_S0 + { + public uint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F53_S5_S1_S0 + { + public byte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F53_S5_S1 + { + public F53_S5_S1_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 20)] + struct F53_S5 + { + public F53_S5_S0 F0; + public nuint F1; + public ushort F2; + public F53_S5_S1 F3; + public sbyte F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F53_S6 + { + public nint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F53_Ret + { + public nint F0; + + public F53_Ret(nint f0) + { + F0 = f0; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func531fAA7F53_RetVAeA0G3_S0V_s5UInt8Vs5Int64VAA0G3_S1VAA0G3_S2VAA0G3_S3VAkA0G3_S4VAA0G3_S5VAA0G3_S6VtXE_tF")] + private static extern F53_Ret SwiftCallbackFunc53(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F53_Ret SwiftCallbackFunc53Callback(F53_S0 a0, byte a1, long a2, F53_S1 a3, F53_S2 a4, F53_S3 a5, long a6, F53_S4 a7, F53_S5 a8, F53_S6 a9, SwiftSelf self) + { + try + { + Assert.Equal((sbyte)-123, a0.F0); + Assert.Equal((long)3494916243607193741, a0.F1.F0.F0); + Assert.Equal((byte)167, a0.F2); + Assert.Equal((nuint)unchecked((nuint)4018943158751734338), a0.F3); + Assert.Equal((long)6768175524813742847, a0.F4); + Assert.Equal((byte)207, a1); + Assert.Equal((long)8667995458064724392, a2); + Assert.Equal((float)492157, a3.F0); + Assert.Equal((byte)175, a3.F1); + Assert.Equal((sbyte)76, a4.F0); + Assert.Equal((long)5794486968525461488, a4.F1); + Assert.Equal((int)2146070335, a5.F0); + Assert.Equal((uint)1109141712, a5.F1); + Assert.Equal((ushort)44270, a5.F2.F0); + Assert.Equal((long)3581380181786253859, a6); + Assert.Equal((short)23565, a7.F0); + Assert.Equal((uint)1995174927, a8.F0.F0); + Assert.Equal((nuint)unchecked((nuint)5025417700244056666), a8.F1); + Assert.Equal((ushort)1847, a8.F2); + Assert.Equal((byte)6, a8.F3.F0.F0); + Assert.Equal((sbyte)-87, a8.F4); + Assert.Equal((nint)unchecked((nint)5737280129078653969), a9.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F53_Ret(unchecked((nint)3955567540648861371)); + } + + [Fact] + public static void TestSwiftCallbackFunc53() + { + Console.Write("Running SwiftCallbackFunc53: "); + ExceptionDispatchInfo ex = null; + F53_Ret val = SwiftCallbackFunc53(&SwiftCallbackFunc53Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nint)unchecked((nint)3955567540648861371), val.F0); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 17)] + struct F54_S0 + { + public int F0; + public float F1; + public nuint F2; + public byte F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F54_S1 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F54_S2_S0_S0 + { + public double F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F54_S2_S0 + { + public short F0; + public F54_S2_S0_S0 F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 40)] + struct F54_S2 + { + public double F0; + public F54_S2_S0 F1; + public long F2; + public ulong F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F54_S3 + { + public float F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 3)] + struct F54_S4 + { + public ushort F0; + public sbyte F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F54_S5 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F54_Ret + { + public short F0; + public nint F1; + + public F54_Ret(short f0, nint f1) + { + F0 = f0; + F1 = f1; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func541fAA7F54_RetVAEs6UInt16V_AA0G3_S0VSfAA0G3_S1Vs5Int64Vs5Int32VAA0G3_S2VAA0G3_S3VAA0G3_S4VSfAA0G3_S5VtXE_tF")] + private static extern F54_Ret SwiftCallbackFunc54(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F54_Ret SwiftCallbackFunc54Callback(ushort a0, F54_S0 a1, float a2, F54_S1 a3, long a4, int a5, F54_S2 a6, F54_S3 a7, F54_S4 a8, float a9, F54_S5 a10, SwiftSelf self) + { + try + { + Assert.Equal((ushort)16440, a0); + Assert.Equal((int)922752112, a1.F0); + Assert.Equal((float)7843043, a1.F1); + Assert.Equal((nuint)unchecked((nuint)1521939500434086364), a1.F2); + Assert.Equal((byte)50, a1.F3); + Assert.Equal((float)3111108, a2); + Assert.Equal((ushort)50535, a3.F0); + Assert.Equal((long)4761507229870258916, a4); + Assert.Equal((int)1670668155, a5); + Assert.Equal((double)432665443852892, a6.F0); + Assert.Equal((short)13094, a6.F1.F0); + Assert.Equal((double)669143993481144, a6.F1.F1.F0); + Assert.Equal((long)30067117315069590, a6.F2); + Assert.Equal((ulong)874012622621600805, a6.F3); + Assert.Equal((float)7995066, a7.F0); + Assert.Equal((ushort)48478, a8.F0); + Assert.Equal((sbyte)23, a8.F1); + Assert.Equal((float)4383787, a9); + Assert.Equal((ushort)61633, a10.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F54_Ret(924, unchecked((nint)7680560643733996038)); + } + + [Fact] + public static void TestSwiftCallbackFunc54() + { + Console.Write("Running SwiftCallbackFunc54: "); + ExceptionDispatchInfo ex = null; + F54_Ret val = SwiftCallbackFunc54(&SwiftCallbackFunc54Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((short)924, val.F0); + Assert.Equal((nint)unchecked((nint)7680560643733996038), val.F1); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F55_S0_S0 + { + public double F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 17)] + struct F55_S0 + { + public nuint F0; + public F55_S0_S0 F1; + public sbyte F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F55_S1 + { + public nint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F55_S2 + { + public ulong F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F55_Ret_S0 + { + public short F0; + public int F1; + + public F55_Ret_S0(short f0, int f1) + { + F0 = f0; + F1 = f1; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 40)] + struct F55_Ret + { + public nuint F0; + public nint F1; + public double F2; + public F55_Ret_S0 F3; + public ulong F4; + + public F55_Ret(nuint f0, nint f1, double f2, F55_Ret_S0 f3, ulong f4) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + F4 = f4; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func551fAA7F55_RetVAeA0G3_S0V_s5Int64VAA0G3_S1Vs4Int8VAA0G3_S2VSftXE_tF")] + private static extern F55_Ret SwiftCallbackFunc55(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F55_Ret SwiftCallbackFunc55Callback(F55_S0 a0, long a1, F55_S1 a2, sbyte a3, F55_S2 a4, float a5, SwiftSelf self) + { + try + { + Assert.Equal((nuint)unchecked((nuint)2856661562863799725), a0.F0); + Assert.Equal((double)1260582440479139, a0.F1.F0); + Assert.Equal((sbyte)5, a0.F2); + Assert.Equal((long)7945068527720423751, a1); + Assert.Equal((nint)unchecked((nint)4321616441998677375), a2.F0); + Assert.Equal((sbyte)-68, a3); + Assert.Equal((ulong)3311106172201778367, a4.F0); + Assert.Equal((float)5600069, a5); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F55_Ret(unchecked((nuint)6916953478574785342), unchecked((nint)6448649235859031640), 1920468532326411, new F55_Ret_S0(30394, 40356024), 6146457824330132360); + } + + [Fact] + public static void TestSwiftCallbackFunc55() + { + Console.Write("Running SwiftCallbackFunc55: "); + ExceptionDispatchInfo ex = null; + F55_Ret val = SwiftCallbackFunc55(&SwiftCallbackFunc55Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nuint)unchecked((nuint)6916953478574785342), val.F0); + Assert.Equal((nint)unchecked((nint)6448649235859031640), val.F1); + Assert.Equal((double)1920468532326411, val.F2); + Assert.Equal((short)30394, val.F3.F0); + Assert.Equal((int)40356024, val.F3.F1); + Assert.Equal((ulong)6146457824330132360, val.F4); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F56_S0 + { + public double F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func561fs6UInt32VAeA6F56_S0VXE_tF")] + private static extern uint SwiftCallbackFunc56(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static uint SwiftCallbackFunc56Callback(F56_S0 a0, SwiftSelf self) + { + try + { + Assert.Equal((double)3082602006731666, a0.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 1601166926; + } + + [Fact] + public static void TestSwiftCallbackFunc56() + { + Console.Write("Running SwiftCallbackFunc56: "); + ExceptionDispatchInfo ex = null; + uint val = SwiftCallbackFunc56(&SwiftCallbackFunc56Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((uint)1601166926, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F57_S0 + { + public long F0; + public int F1; + public ulong F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F57_S1 + { + public byte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F57_S2 + { + public float F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F57_Ret_S0 + { + public long F0; + public byte F1; + public short F2; + + public F57_Ret_S0(long f0, byte f1, short f2) + { + F0 = f0; + F1 = f1; + F2 = f2; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 13)] + struct F57_Ret + { + public F57_Ret_S0 F0; + public byte F1; + + public F57_Ret(F57_Ret_S0 f0, byte f1) + { + F0 = f0; + F1 = f1; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func571fAA7F57_RetVAEs4Int8V_Sus6UInt32Vs5Int64Vs6UInt64Vs5Int16VAkA0G3_S0VAA0G3_S1VAA0G3_S2VtXE_tF")] + private static extern F57_Ret SwiftCallbackFunc57(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F57_Ret SwiftCallbackFunc57Callback(sbyte a0, nuint a1, uint a2, long a3, ulong a4, short a5, long a6, F57_S0 a7, F57_S1 a8, F57_S2 a9, SwiftSelf self) + { + try + { + Assert.Equal((sbyte)54, a0); + Assert.Equal((nuint)unchecked((nuint)753245150862584974), a1); + Assert.Equal((uint)1470962934, a2); + Assert.Equal((long)1269392070140776313, a3); + Assert.Equal((ulong)2296560034524654667, a4); + Assert.Equal((short)12381, a5); + Assert.Equal((long)198893062684618980, a6); + Assert.Equal((long)1310571041794038100, a7.F0); + Assert.Equal((int)18741662, a7.F1); + Assert.Equal((ulong)7855196891704523814, a7.F2); + Assert.Equal((byte)156, a8.F0); + Assert.Equal((float)72045, a9.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F57_Ret(new F57_Ret_S0(3441370978522907304, 105, 24446), 200); + } + + [Fact] + public static void TestSwiftCallbackFunc57() + { + Console.Write("Running SwiftCallbackFunc57: "); + ExceptionDispatchInfo ex = null; + F57_Ret val = SwiftCallbackFunc57(&SwiftCallbackFunc57Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((long)3441370978522907304, val.F0.F0); + Assert.Equal((byte)105, val.F0.F1); + Assert.Equal((short)24446, val.F0.F2); + Assert.Equal((byte)200, val.F1); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F58_S0 + { + public byte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 6)] + struct F58_S1 + { + public float F0; + public ushort F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F58_S2_S0_S0 + { + public nint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F58_S2_S0 + { + public F58_S2_S0_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F58_S2 + { + public F58_S2_S0 F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func581fS2is6UInt64V_s4Int8VSiAA6F58_S0VAA0I3_S1Vs5Int64VAA0I3_S2Vs5Int32VtXE_tF")] + private static extern nint SwiftCallbackFunc58(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static nint SwiftCallbackFunc58Callback(ulong a0, sbyte a1, nint a2, F58_S0 a3, F58_S1 a4, long a5, F58_S2 a6, int a7, SwiftSelf self) + { + try + { + Assert.Equal((ulong)4612004722568513699, a0); + Assert.Equal((sbyte)-96, a1); + Assert.Equal((nint)unchecked((nint)1970590839325113617), a2); + Assert.Equal((byte)211, a3.F0); + Assert.Equal((float)5454927, a4.F0); + Assert.Equal((ushort)48737, a4.F1); + Assert.Equal((long)921570327236881486, a5); + Assert.Equal((nint)unchecked((nint)7726203059421444802), a6.F0.F0.F0); + Assert.Equal((int)491616915, a7); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return unchecked((nint)5337995302960578101); + } + + [Fact] + public static void TestSwiftCallbackFunc58() + { + Console.Write("Running SwiftCallbackFunc58: "); + ExceptionDispatchInfo ex = null; + nint val = SwiftCallbackFunc58(&SwiftCallbackFunc58Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nint)unchecked((nint)5337995302960578101), val); + Console.WriteLine("OK"); + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func591fs6UInt64VAEs6UInt16V_s5Int64VSitXE_tF")] + private static extern ulong SwiftCallbackFunc59(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static ulong SwiftCallbackFunc59Callback(ushort a0, long a1, nint a2, SwiftSelf self) + { + try + { + Assert.Equal((ushort)9232, a0); + Assert.Equal((long)7281011081566942937, a1); + Assert.Equal((nint)unchecked((nint)8203439771560005792), a2); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 7843473552989551261; + } + + [Fact] + public static void TestSwiftCallbackFunc59() + { + Console.Write("Running SwiftCallbackFunc59: "); + ExceptionDispatchInfo ex = null; + ulong val = SwiftCallbackFunc59(&SwiftCallbackFunc59Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ulong)7843473552989551261, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F60_S0 + { + public nint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F60_S1 + { + public ulong F0; + public int F1; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func601fs6UInt64VAESf_Sds5Int64Vs6UInt16VS2fAA6F60_S0Vs5Int16VAA0J3_S1VAmGtXE_tF")] + private static extern ulong SwiftCallbackFunc60(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static ulong SwiftCallbackFunc60Callback(float a0, double a1, long a2, ushort a3, float a4, float a5, F60_S0 a6, short a7, F60_S1 a8, short a9, long a10, SwiftSelf self) + { + try + { + Assert.Equal((float)2682255, a0); + Assert.Equal((double)2041676057169359, a1); + Assert.Equal((long)5212916666940122160, a2); + Assert.Equal((ushort)64444, a3); + Assert.Equal((float)6372882, a4); + Assert.Equal((float)8028835, a5); + Assert.Equal((nint)unchecked((nint)6629286640024570381), a6.F0); + Assert.Equal((short)1520, a7); + Assert.Equal((ulong)8398497739914283366, a8.F0); + Assert.Equal((int)1882981891, a8.F1); + Assert.Equal((short)7716, a9); + Assert.Equal((long)6631047215535600409, a10); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 1713850918199577358; + } + + [Fact] + public static void TestSwiftCallbackFunc60() + { + Console.Write("Running SwiftCallbackFunc60: "); + ExceptionDispatchInfo ex = null; + ulong val = SwiftCallbackFunc60(&SwiftCallbackFunc60Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ulong)1713850918199577358, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F61_S0_S0 + { + public long F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 20)] + struct F61_S0 + { + public F61_S0_S0 F0; + public long F1; + public uint F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F61_S1 + { + public sbyte F0; + public float F1; + public nint F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F61_S2_S0_S0 + { + public ulong F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F61_S2_S0 + { + public F61_S2_S0_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F61_S2_S1 + { + public sbyte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 9)] + struct F61_S2 + { + public F61_S2_S0 F0; + public F61_S2_S1 F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F61_S3 + { + public ulong F0; + public nint F1; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func611fs6UInt32VA2E_AeA6F61_S0VAA0H3_S1VAA0H3_S2Vs4Int8Vs5Int16VAA0H3_S3Vs5Int32VAEtXE_tF")] + private static extern uint SwiftCallbackFunc61(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static uint SwiftCallbackFunc61Callback(uint a0, uint a1, F61_S0 a2, F61_S1 a3, F61_S2 a4, sbyte a5, short a6, F61_S3 a7, int a8, uint a9, SwiftSelf self) + { + try + { + Assert.Equal((uint)1070797065, a0); + Assert.Equal((uint)135220309, a1); + Assert.Equal((long)6475887024664217162, a2.F0.F0); + Assert.Equal((long)563444654083452485, a2.F1); + Assert.Equal((uint)1748956360, a2.F2); + Assert.Equal((sbyte)-112, a3.F0); + Assert.Equal((float)3433396, a3.F1); + Assert.Equal((nint)unchecked((nint)8106074956722850624), a3.F2); + Assert.Equal((ulong)2318628619979263858, a4.F0.F0.F0); + Assert.Equal((sbyte)-93, a4.F1.F0); + Assert.Equal((sbyte)-122, a5); + Assert.Equal((short)-11696, a6); + Assert.Equal((ulong)5229393236090246212, a7.F0); + Assert.Equal((nint)unchecked((nint)4021449757638811198), a7.F1); + Assert.Equal((int)689517945, a8); + Assert.Equal((uint)657677740, a9); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 138627237; + } + + [Fact] + public static void TestSwiftCallbackFunc61() + { + Console.Write("Running SwiftCallbackFunc61: "); + ExceptionDispatchInfo ex = null; + uint val = SwiftCallbackFunc61(&SwiftCallbackFunc61Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((uint)138627237, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F62_S0 + { + public float F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F62_Ret + { + public ushort F0; + public long F1; + public nint F2; + public long F3; + + public F62_Ret(ushort f0, long f1, nint f2, long f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func621fAA7F62_RetVAeA0G3_S0VXE_tF")] + private static extern F62_Ret SwiftCallbackFunc62(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F62_Ret SwiftCallbackFunc62Callback(F62_S0 a0, SwiftSelf self) + { + try + { + Assert.Equal((float)6500993, a0.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F62_Ret(63013, 4076138842444340990, unchecked((nint)6876195265868121021), 223819901796794423); + } + + [Fact] + public static void TestSwiftCallbackFunc62() + { + Console.Write("Running SwiftCallbackFunc62: "); + ExceptionDispatchInfo ex = null; + F62_Ret val = SwiftCallbackFunc62(&SwiftCallbackFunc62Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ushort)63013, val.F0); + Assert.Equal((long)4076138842444340990, val.F1); + Assert.Equal((nint)unchecked((nint)6876195265868121021), val.F2); + Assert.Equal((long)223819901796794423, val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F63_S0 + { + public nint F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func631fS2fAA6F63_S0V_s5Int16VtXE_tF")] + private static extern float SwiftCallbackFunc63(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static float SwiftCallbackFunc63Callback(F63_S0 a0, short a1, SwiftSelf self) + { + try + { + Assert.Equal((nint)unchecked((nint)8391317504019075904), a0.F0); + Assert.Equal((short)11218, a1); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 1458978; + } + + [Fact] + public static void TestSwiftCallbackFunc63() + { + Console.Write("Running SwiftCallbackFunc63: "); + ExceptionDispatchInfo ex = null; + float val = SwiftCallbackFunc63(&SwiftCallbackFunc63Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((float)1458978, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F64_S0 + { + public int F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F64_S1 + { + public ulong F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F64_S2 + { + public uint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F64_Ret_S0 + { + public ushort F0; + public nuint F1; + public ulong F2; + + public F64_Ret_S0(ushort f0, nuint f1, ulong f2) + { + F0 = f0; + F1 = f1; + F2 = f2; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 40)] + struct F64_Ret + { + public nuint F0; + public F64_Ret_S0 F1; + public double F2; + + public F64_Ret(nuint f0, F64_Ret_S0 f1, double f2) + { + F0 = f0; + F1 = f1; + F2 = f2; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func641fAA7F64_RetVAEs4Int8V_AA0G3_S0VAA0G3_S1VSuAA0G3_S2VtXE_tF")] + private static extern F64_Ret SwiftCallbackFunc64(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F64_Ret SwiftCallbackFunc64Callback(sbyte a0, F64_S0 a1, F64_S1 a2, nuint a3, F64_S2 a4, SwiftSelf self) + { + try + { + Assert.Equal((sbyte)-22, a0); + Assert.Equal((int)1591678205, a1.F0); + Assert.Equal((ulong)8355549563000003325, a2.F0); + Assert.Equal((nuint)unchecked((nuint)5441989206466502201), a3); + Assert.Equal((uint)2097092811, a4.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F64_Ret(unchecked((nuint)7966680593035770540), new F64_Ret_S0(20244, unchecked((nuint)7259704667595065333), 1039021449222712763), 594768504899138); + } + + [Fact] + public static void TestSwiftCallbackFunc64() + { + Console.Write("Running SwiftCallbackFunc64: "); + ExceptionDispatchInfo ex = null; + F64_Ret val = SwiftCallbackFunc64(&SwiftCallbackFunc64Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nuint)unchecked((nuint)7966680593035770540), val.F0); + Assert.Equal((ushort)20244, val.F1.F0); + Assert.Equal((nuint)unchecked((nuint)7259704667595065333), val.F1.F1); + Assert.Equal((ulong)1039021449222712763, val.F1.F2); + Assert.Equal((double)594768504899138, val.F2); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F65_S0 + { + public double F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F65_S1 + { + public ushort F0; + public nint F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F65_S2 + { + public short F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F65_S3 + { + public int F0; + public uint F1; + public sbyte F2; + public nuint F3; + public double F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 28)] + struct F65_Ret + { + public nint F0; + public nint F1; + public nint F2; + public float F3; + + public F65_Ret(nint f0, nint f1, nint f2, float f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func651fAA7F65_RetVAeA0G3_S0V_s5Int16VSdSuAA0G3_S1Vs6UInt64VAA0G3_S2VSiAA0G3_S3Vs5Int32Vs5Int64Vs6UInt32VSdtXE_tF")] + private static extern F65_Ret SwiftCallbackFunc65(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F65_Ret SwiftCallbackFunc65Callback(F65_S0 a0, short a1, double a2, nuint a3, F65_S1 a4, ulong a5, F65_S2 a6, nint a7, F65_S3 a8, int a9, long a10, uint a11, double a12, SwiftSelf self) + { + try + { + Assert.Equal((double)2969223123583220, a0.F0); + Assert.Equal((short)-10269, a1); + Assert.Equal((double)3909264978196109, a2); + Assert.Equal((nuint)unchecked((nuint)522883062031213707), a3); + Assert.Equal((ushort)37585, a4.F0); + Assert.Equal((nint)unchecked((nint)5879827541057349126), a4.F1); + Assert.Equal((ulong)1015270399093748716, a5); + Assert.Equal((short)19670, a6.F0); + Assert.Equal((nint)unchecked((nint)1900026319968050423), a7); + Assert.Equal((int)1440511399, a8.F0); + Assert.Equal((uint)1203865685, a8.F1); + Assert.Equal((sbyte)12, a8.F2); + Assert.Equal((nuint)unchecked((nuint)4061296318630567634), a8.F3); + Assert.Equal((double)2406524883317724, a8.F4); + Assert.Equal((int)1594888000, a9); + Assert.Equal((long)2860599972459787263, a10); + Assert.Equal((uint)1989052358, a11); + Assert.Equal((double)1036075606072593, a12); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F65_Ret(unchecked((nint)7810903219784151958), unchecked((nint)8310527878848492866), unchecked((nint)1357258266300958550), 5970506); + } + + [Fact] + public static void TestSwiftCallbackFunc65() + { + Console.Write("Running SwiftCallbackFunc65: "); + ExceptionDispatchInfo ex = null; + F65_Ret val = SwiftCallbackFunc65(&SwiftCallbackFunc65Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nint)unchecked((nint)7810903219784151958), val.F0); + Assert.Equal((nint)unchecked((nint)8310527878848492866), val.F1); + Assert.Equal((nint)unchecked((nint)1357258266300958550), val.F2); + Assert.Equal((float)5970506, val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 5)] + struct F66_Ret_S0 + { + public float F0; + public byte F1; + + public F66_Ret_S0(float f0, byte f1) + { + F0 = f0; + F1 = f1; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F66_Ret + { + public uint F0; + public int F1; + public uint F2; + public F66_Ret_S0 F3; + public nint F4; + + public F66_Ret(uint f0, int f1, uint f2, F66_Ret_S0 f3, nint f4) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + F4 = f4; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func661fAA7F66_RetVAEs5Int64VXE_tF")] + private static extern F66_Ret SwiftCallbackFunc66(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F66_Ret SwiftCallbackFunc66Callback(long a0, SwiftSelf self) + { + try + { + Assert.Equal((long)8300712022174991120, a0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F66_Ret(1855065799, 2029697750, 149423164, new F66_Ret_S0(4327716, 116), unchecked((nint)5847795120921557969)); + } + + [Fact] + public static void TestSwiftCallbackFunc66() + { + Console.Write("Running SwiftCallbackFunc66: "); + ExceptionDispatchInfo ex = null; + F66_Ret val = SwiftCallbackFunc66(&SwiftCallbackFunc66Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((uint)1855065799, val.F0); + Assert.Equal((int)2029697750, val.F1); + Assert.Equal((uint)149423164, val.F2); + Assert.Equal((float)4327716, val.F3.F0); + Assert.Equal((byte)116, val.F3.F1); + Assert.Equal((nint)unchecked((nint)5847795120921557969), val.F4); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F67_S0 + { + public uint F0; + public byte F1; + public byte F2; + public int F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F67_S1 + { + public uint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F67_S2_S0 + { + public nint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 40)] + struct F67_S2 + { + public ulong F0; + public uint F1; + public nint F2; + public uint F3; + public F67_S2_S0 F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 28)] + struct F67_S3 + { + public short F0; + public ulong F1; + public ulong F2; + public float F3; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func671fs5Int32VAESd_AA6F67_S0VSfAA0H3_S1Vs5Int16VSuAA0H3_S2Vs6UInt16VS2uAA0H3_S3Vs6UInt64VtXE_tF")] + private static extern int SwiftCallbackFunc67(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static int SwiftCallbackFunc67Callback(double a0, F67_S0 a1, float a2, F67_S1 a3, short a4, nuint a5, F67_S2 a6, ushort a7, nuint a8, nuint a9, F67_S3 a10, ulong a11, SwiftSelf self) + { + try + { + Assert.Equal((double)2365334314089079, a0); + Assert.Equal((uint)1133369490, a1.F0); + Assert.Equal((byte)54, a1.F1); + Assert.Equal((byte)244, a1.F2); + Assert.Equal((int)411611102, a1.F3); + Assert.Equal((float)4453912, a2); + Assert.Equal((uint)837821989, a3.F0); + Assert.Equal((short)-3824, a4); + Assert.Equal((nuint)unchecked((nuint)2394019088612006082), a5); + Assert.Equal((ulong)2219661088889353540, a6.F0); + Assert.Equal((uint)294254132, a6.F1); + Assert.Equal((nint)unchecked((nint)5363897228951721947), a6.F2); + Assert.Equal((uint)2038380379, a6.F3); + Assert.Equal((nint)unchecked((nint)8364879421385869437), a6.F4.F0); + Assert.Equal((ushort)27730, a7); + Assert.Equal((nuint)unchecked((nuint)1854446871602777695), a8); + Assert.Equal((nuint)unchecked((nuint)5020910156102352016), a9); + Assert.Equal((short)-2211, a10.F0); + Assert.Equal((ulong)5910581461792482729, a10.F1); + Assert.Equal((ulong)9095210648679611609, a10.F2); + Assert.Equal((float)6138428, a10.F3); + Assert.Equal((ulong)4274242076331880276, a11); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 391983354; + } + + [Fact] + public static void TestSwiftCallbackFunc67() + { + Console.Write("Running SwiftCallbackFunc67: "); + ExceptionDispatchInfo ex = null; + int val = SwiftCallbackFunc67(&SwiftCallbackFunc67Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((int)391983354, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F68_S0_S0 + { + public sbyte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 9)] + struct F68_S0 + { + public long F0; + public F68_S0_S0 F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F68_S1 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F68_S2_S0 + { + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F68_S2_S1_S0 + { + public ulong F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F68_S2_S1 + { + public F68_S2_S1_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F68_S2 + { + public F68_S2_S0 F0; + public F68_S2_S1 F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F68_S3 + { + public short F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F68_Ret + { + public ushort F0; + public long F1; + + public F68_Ret(ushort f0, long f1) + { + F0 = f0; + F1 = f1; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func681fAA7F68_RetVAEs5UInt8V_Sfs5Int32VSiAA0G3_S0Vs5Int16VSiAISiAA0G3_S1VSdAA0G3_S2VAA0G3_S3VtXE_tF")] + private static extern F68_Ret SwiftCallbackFunc68(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F68_Ret SwiftCallbackFunc68Callback(byte a0, float a1, int a2, nint a3, F68_S0 a4, short a5, nint a6, int a7, nint a8, F68_S1 a9, double a10, F68_S2 a11, F68_S3 a12, SwiftSelf self) + { + try + { + Assert.Equal((byte)203, a0); + Assert.Equal((float)7725681, a1); + Assert.Equal((int)323096997, a2); + Assert.Equal((nint)unchecked((nint)7745650233784541800), a3); + Assert.Equal((long)4103074885750473230, a4.F0); + Assert.Equal((sbyte)12, a4.F1.F0); + Assert.Equal((short)28477, a5); + Assert.Equal((nint)unchecked((nint)3772772447290536725), a6); + Assert.Equal((int)1075348149, a7); + Assert.Equal((nint)unchecked((nint)2017898311184593242), a8); + Assert.Equal((ushort)60280, a9.F0); + Assert.Equal((double)4052387873895590, a10); + Assert.Equal((nuint)unchecked((nuint)1321857087602747558), a11.F0.F0); + Assert.Equal((ulong)9011155097138053416, a11.F1.F0.F0); + Assert.Equal((short)8332, a12.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F68_Ret(64088, 8144208533922264568); + } + + [Fact] + public static void TestSwiftCallbackFunc68() + { + Console.Write("Running SwiftCallbackFunc68: "); + ExceptionDispatchInfo ex = null; + F68_Ret val = SwiftCallbackFunc68(&SwiftCallbackFunc68Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ushort)64088, val.F0); + Assert.Equal((long)8144208533922264568, val.F1); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F69_S0_S0 + { + public ulong F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F69_S0 + { + public F69_S0_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F69_S1 + { + public long F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F69_S2 + { + public int F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F69_S3 + { + public byte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F69_S4_S0 + { + public long F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F69_S4 + { + public F69_S4_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 20)] + struct F69_Ret + { + public byte F0; + public long F1; + public uint F2; + + public F69_Ret(byte f0, long f1, uint f2) + { + F0 = f0; + F1 = f1; + F2 = f2; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func691fAA7F69_RetVAeA0G3_S0V_Sis5Int32VAA0G3_S1Vs6UInt32Vs4Int8VAA0G3_S2VSiAA0G3_S3VAA0G3_S4VtXE_tF")] + private static extern F69_Ret SwiftCallbackFunc69(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F69_Ret SwiftCallbackFunc69Callback(F69_S0 a0, nint a1, int a2, F69_S1 a3, uint a4, sbyte a5, F69_S2 a6, nint a7, F69_S3 a8, F69_S4 a9, SwiftSelf self) + { + try + { + Assert.Equal((ulong)7154553222175076145, a0.F0.F0); + Assert.Equal((nint)unchecked((nint)6685908100026425691), a1); + Assert.Equal((int)1166526155, a2); + Assert.Equal((long)6042278185730963289, a3.F0); + Assert.Equal((uint)182060391, a4); + Assert.Equal((sbyte)45, a5); + Assert.Equal((int)1886331345, a6.F0); + Assert.Equal((nint)unchecked((nint)485542148877875333), a7); + Assert.Equal((byte)209, a8.F0); + Assert.Equal((long)6856847647688321191, a9.F0.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F69_Ret(52, 5510942427596951043, 1854355776); + } + + [Fact] + public static void TestSwiftCallbackFunc69() + { + Console.Write("Running SwiftCallbackFunc69: "); + ExceptionDispatchInfo ex = null; + F69_Ret val = SwiftCallbackFunc69(&SwiftCallbackFunc69Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((byte)52, val.F0); + Assert.Equal((long)5510942427596951043, val.F1); + Assert.Equal((uint)1854355776, val.F2); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F70_S0 + { + public long F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 18)] + struct F70_S1 + { + public nint F0; + public double F1; + public short F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F70_S2 + { + public uint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 36)] + struct F70_S3 + { + public ushort F0; + public double F1; + public byte F2; + public ulong F3; + public int F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F70_S4_S0 + { + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F70_S4 + { + public F70_S4_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 20)] + struct F70_Ret + { + public sbyte F0; + public uint F1; + public ulong F2; + public short F3; + public short F4; + + public F70_Ret(sbyte f0, uint f1, ulong f2, short f3, short f4) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + F4 = f4; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func701fAA7F70_RetVAEs5Int16V_s5UInt8VSis6UInt32VAA0G3_S0Vs5Int32VAA0G3_S1VAA0G3_S2VAA0G3_S3Vs5Int64VAOs6UInt16VS2iSuAA0G3_S4VtXE_tF")] + private static extern F70_Ret SwiftCallbackFunc70(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F70_Ret SwiftCallbackFunc70Callback(short a0, byte a1, nint a2, uint a3, F70_S0 a4, int a5, F70_S1 a6, F70_S2 a7, F70_S3 a8, long a9, int a10, ushort a11, nint a12, nint a13, nuint a14, F70_S4 a15, SwiftSelf self) + { + try + { + Assert.Equal((short)-13167, a0); + Assert.Equal((byte)126, a1); + Assert.Equal((nint)unchecked((nint)3641983584484741827), a2); + Assert.Equal((uint)1090448265, a3); + Assert.Equal((long)3696858216713616004, a4.F0); + Assert.Equal((int)1687025402, a5); + Assert.Equal((nint)unchecked((nint)714916953527626038), a6.F0); + Assert.Equal((double)459810445900614, a6.F1); + Assert.Equal((short)4276, a6.F2); + Assert.Equal((uint)529194028, a7.F0); + Assert.Equal((ushort)40800, a8.F0); + Assert.Equal((double)3934985905568056, a8.F1); + Assert.Equal((byte)230, a8.F2); + Assert.Equal((ulong)7358783417346157372, a8.F3); + Assert.Equal((int)187926922, a8.F4); + Assert.Equal((long)228428560763393434, a9); + Assert.Equal((int)146501405, a10); + Assert.Equal((ushort)58804, a11); + Assert.Equal((nint)unchecked((nint)7098488973446286248), a12); + Assert.Equal((nint)unchecked((nint)1283658442251334575), a13); + Assert.Equal((nuint)unchecked((nuint)3644681944588099582), a14); + Assert.Equal((nuint)unchecked((nuint)8197135412164695911), a15.F0.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F70_Ret(45, 460004173, 7766748067698372018, 27369, 16509); + } + + [Fact] + public static void TestSwiftCallbackFunc70() + { + Console.Write("Running SwiftCallbackFunc70: "); + ExceptionDispatchInfo ex = null; + F70_Ret val = SwiftCallbackFunc70(&SwiftCallbackFunc70Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((sbyte)45, val.F0); + Assert.Equal((uint)460004173, val.F1); + Assert.Equal((ulong)7766748067698372018, val.F2); + Assert.Equal((short)27369, val.F3); + Assert.Equal((short)16509, val.F4); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F71_S0_S0 + { + public int F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F71_S0 + { + public F71_S0_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F71_S1 + { + public long F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func711fs6UInt64VAeA6F71_S0V_AA0H3_S1VtXE_tF")] + private static extern ulong SwiftCallbackFunc71(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static ulong SwiftCallbackFunc71Callback(F71_S0 a0, F71_S1 a1, SwiftSelf self) + { + try + { + Assert.Equal((int)258165353, a0.F0.F0); + Assert.Equal((long)8603744544763953916, a1.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 8460721064583106347; + } + + [Fact] + public static void TestSwiftCallbackFunc71() + { + Console.Write("Running SwiftCallbackFunc71: "); + ExceptionDispatchInfo ex = null; + ulong val = SwiftCallbackFunc71(&SwiftCallbackFunc71Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ulong)8460721064583106347, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F72_S0 + { + public int F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F72_Ret + { + public uint F0; + public float F1; + public float F2; + public long F3; + + public F72_Ret(uint f0, float f1, float f2, long f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func721fAA7F72_RetVAeA0G3_S0V_s5Int64Vs4Int8VtXE_tF")] + private static extern F72_Ret SwiftCallbackFunc72(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F72_Ret SwiftCallbackFunc72Callback(F72_S0 a0, long a1, sbyte a2, SwiftSelf self) + { + try + { + Assert.Equal((int)2021509367, a0.F0); + Assert.Equal((long)2480039820482100351, a1); + Assert.Equal((sbyte)91, a2); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F72_Ret(1583929847, 2026234, 8092211, 445254465286132488); + } + + [Fact] + public static void TestSwiftCallbackFunc72() + { + Console.Write("Running SwiftCallbackFunc72: "); + ExceptionDispatchInfo ex = null; + F72_Ret val = SwiftCallbackFunc72(&SwiftCallbackFunc72Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((uint)1583929847, val.F0); + Assert.Equal((float)2026234, val.F1); + Assert.Equal((float)8092211, val.F2); + Assert.Equal((long)445254465286132488, val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F73_S0 + { + public int F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F73_S1_S0 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F73_S1 + { + public F73_S1_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F73_S2 + { + public int F0; + public float F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 11)] + struct F73_S3 + { + public nuint F0; + public short F1; + public sbyte F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F73_S4 + { + public short F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F73_S5 + { + public uint F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func731fs4Int8VAESd_SfAA6F73_S0Vs5Int64VAA0H3_S1VAA0H3_S2Vs5Int16VSdAEs5Int32VAiA0H3_S3VSus6UInt64VAqA0H3_S4Vs5UInt8VAA0H3_S5VtXE_tF")] + private static extern sbyte SwiftCallbackFunc73(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static sbyte SwiftCallbackFunc73Callback(double a0, float a1, F73_S0 a2, long a3, F73_S1 a4, F73_S2 a5, short a6, double a7, sbyte a8, int a9, long a10, F73_S3 a11, nuint a12, ulong a13, int a14, F73_S4 a15, byte a16, F73_S5 a17, SwiftSelf self) + { + try + { + Assert.Equal((double)3038361048801008, a0); + Assert.Equal((float)7870661, a1); + Assert.Equal((int)1555231180, a2.F0); + Assert.Equal((long)7433951069104961, a3); + Assert.Equal((ushort)63298, a4.F0.F0); + Assert.Equal((int)1759846580, a5.F0); + Assert.Equal((float)1335901, a5.F1); + Assert.Equal((short)11514, a6); + Assert.Equal((double)695278874601974, a7); + Assert.Equal((sbyte)108, a8); + Assert.Equal((int)48660527, a9); + Assert.Equal((long)7762050749172332624, a10); + Assert.Equal((nuint)unchecked((nuint)7486686356276472663), a11.F0); + Assert.Equal((short)11622, a11.F1); + Assert.Equal((sbyte)112, a11.F2); + Assert.Equal((nuint)unchecked((nuint)884183974530885885), a12); + Assert.Equal((ulong)7434462110419085390, a13); + Assert.Equal((int)170242607, a14); + Assert.Equal((short)-26039, a15.F0); + Assert.Equal((byte)41, a16); + Assert.Equal((uint)191302504, a17.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 76; + } + + [Fact] + public static void TestSwiftCallbackFunc73() + { + Console.Write("Running SwiftCallbackFunc73: "); + ExceptionDispatchInfo ex = null; + sbyte val = SwiftCallbackFunc73(&SwiftCallbackFunc73Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((sbyte)76, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 17)] + struct F74_S0_S0 + { + public ushort F0; + public nuint F1; + public sbyte F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F74_S0 + { + public F74_S0_S0 F0; + public nint F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F74_S1 + { + public float F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func741fs5Int64VAeA6F74_S0V_AA0H3_S1Vs5Int16VtXE_tF")] + private static extern long SwiftCallbackFunc74(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static long SwiftCallbackFunc74Callback(F74_S0 a0, F74_S1 a1, short a2, SwiftSelf self) + { + try + { + Assert.Equal((ushort)59883, a0.F0.F0); + Assert.Equal((nuint)unchecked((nuint)5554216411943233256), a0.F0.F1); + Assert.Equal((sbyte)126, a0.F0.F2); + Assert.Equal((nint)unchecked((nint)724541378819571203), a0.F1); + Assert.Equal((float)172601, a1.F0); + Assert.Equal((short)27932, a2); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 7382123574052120438; + } + + [Fact] + public static void TestSwiftCallbackFunc74() + { + Console.Write("Running SwiftCallbackFunc74: "); + ExceptionDispatchInfo ex = null; + long val = SwiftCallbackFunc74(&SwiftCallbackFunc74Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((long)7382123574052120438, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F75_S0 + { + public long F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F75_S1_S0 + { + public byte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F75_S1 + { + public F75_S1_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F75_S2 + { + public sbyte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F75_S3_S0 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F75_S3 + { + public F75_S3_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 36)] + struct F75_Ret + { + public byte F0; + public double F1; + public double F2; + public long F3; + public uint F4; + + public F75_Ret(byte f0, double f1, double f2, long f3, uint f4) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + F4 = f4; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func751fAA7F75_RetVAEs4Int8V_A2gA0G3_S0VAA0G3_S1VAA0G3_S2VAA0G3_S3VtXE_tF")] + private static extern F75_Ret SwiftCallbackFunc75(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F75_Ret SwiftCallbackFunc75Callback(sbyte a0, sbyte a1, sbyte a2, F75_S0 a3, F75_S1 a4, F75_S2 a5, F75_S3 a6, SwiftSelf self) + { + try + { + Assert.Equal((sbyte)-105, a0); + Assert.Equal((sbyte)71, a1); + Assert.Equal((sbyte)108, a2); + Assert.Equal((long)7224638108479292438, a3.F0); + Assert.Equal((byte)126, a4.F0.F0); + Assert.Equal((sbyte)-88, a5.F0); + Assert.Equal((ushort)4934, a6.F0.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F75_Ret(8, 494440474432982, 3322048351205313, 7525253715666045341, 7365589); + } + + [Fact] + public static void TestSwiftCallbackFunc75() + { + Console.Write("Running SwiftCallbackFunc75: "); + ExceptionDispatchInfo ex = null; + F75_Ret val = SwiftCallbackFunc75(&SwiftCallbackFunc75Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((byte)8, val.F0); + Assert.Equal((double)494440474432982, val.F1); + Assert.Equal((double)3322048351205313, val.F2); + Assert.Equal((long)7525253715666045341, val.F3); + Assert.Equal((uint)7365589, val.F4); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F76_S0 + { + public ushort F0; + public nint F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F76_S1_S0 + { + public nint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F76_S1 + { + public F76_S1_S0 F0; + public nuint F1; + public double F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 18)] + struct F76_S2 + { + public ulong F0; + public nint F1; + public ushort F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F76_S3_S0 + { + public long F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F76_S3 + { + public F76_S3_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F76_S4 + { + public long F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F76_S5 + { + public nuint F0; + public double F1; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func761fs6UInt64VAEs5UInt8V_AA6F76_S0Vs4Int8VAA0I3_S1VAA0I3_S2VAA0I3_S3Vs6UInt32VAA0I3_S4VAgA0I3_S5VSds5Int16VtXE_tF")] + private static extern ulong SwiftCallbackFunc76(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static ulong SwiftCallbackFunc76Callback(byte a0, F76_S0 a1, sbyte a2, F76_S1 a3, F76_S2 a4, F76_S3 a5, uint a6, F76_S4 a7, byte a8, F76_S5 a9, double a10, short a11, SwiftSelf self) + { + try + { + Assert.Equal((byte)69, a0); + Assert.Equal((ushort)25503, a1.F0); + Assert.Equal((nint)unchecked((nint)4872234474620951743), a1.F1); + Assert.Equal((sbyte)43, a2); + Assert.Equal((nint)unchecked((nint)1199076663426903579), a3.F0.F0); + Assert.Equal((nuint)unchecked((nuint)4639522222462236688), a3.F1); + Assert.Equal((double)4082956091930029, a3.F2); + Assert.Equal((ulong)5171821618947987626, a4.F0); + Assert.Equal((nint)unchecked((nint)3369410144919558564), a4.F1); + Assert.Equal((ushort)5287, a4.F2); + Assert.Equal((long)929854460912895550, a5.F0.F0); + Assert.Equal((uint)1208311201, a6); + Assert.Equal((long)7033993025788649145, a7.F0); + Assert.Equal((byte)58, a8); + Assert.Equal((nuint)unchecked((nuint)1401399014740601512), a9.F0); + Assert.Equal((double)2523645319232571, a9.F1); + Assert.Equal((double)230232835550369, a10); + Assert.Equal((short)-22975, a11); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 2608582352406315143; + } + + [Fact] + public static void TestSwiftCallbackFunc76() + { + Console.Write("Running SwiftCallbackFunc76: "); + ExceptionDispatchInfo ex = null; + ulong val = SwiftCallbackFunc76(&SwiftCallbackFunc76Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ulong)2608582352406315143, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F77_S0 + { + public long F0; + public double F1; + public nuint F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F77_S1 + { + public short F0; + public float F1; + public float F2; + public long F3; + public long F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F77_S2 + { + public ushort F0; + public sbyte F1; + public int F2; + public float F3; + public float F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F77_Ret + { + public double F0; + public ushort F1; + public sbyte F2; + public nuint F3; + + public F77_Ret(double f0, ushort f1, sbyte f2, nuint f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func771fAA7F77_RetVAESd_AA0G3_S0VAA0G3_S1VAA0G3_S2Vs6UInt32VtXE_tF")] + private static extern F77_Ret SwiftCallbackFunc77(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F77_Ret SwiftCallbackFunc77Callback(double a0, F77_S0 a1, F77_S1 a2, F77_S2 a3, uint a4, SwiftSelf self) + { + try + { + Assert.Equal((double)1623173949127682, a0); + Assert.Equal((long)5204451347781433070, a1.F0); + Assert.Equal((double)3469485630755805, a1.F1); + Assert.Equal((nuint)unchecked((nuint)7586276835848725004), a1.F2); + Assert.Equal((short)2405, a2.F0); + Assert.Equal((float)2419792, a2.F1); + Assert.Equal((float)6769317, a2.F2); + Assert.Equal((long)1542327522833750776, a2.F3); + Assert.Equal((long)1297586130846695275, a2.F4); + Assert.Equal((ushort)10102, a3.F0); + Assert.Equal((sbyte)-48, a3.F1); + Assert.Equal((int)14517107, a3.F2); + Assert.Equal((float)4856023, a3.F3); + Assert.Equal((float)2681358, a3.F4); + Assert.Equal((uint)1463251524, a4); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F77_Ret(1601613740657843, 14373, -17, unchecked((nuint)274065318894652498)); + } + + [Fact] + public static void TestSwiftCallbackFunc77() + { + Console.Write("Running SwiftCallbackFunc77: "); + ExceptionDispatchInfo ex = null; + F77_Ret val = SwiftCallbackFunc77(&SwiftCallbackFunc77Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((double)1601613740657843, val.F0); + Assert.Equal((ushort)14373, val.F1); + Assert.Equal((sbyte)-17, val.F2); + Assert.Equal((nuint)unchecked((nuint)274065318894652498), val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F78_S0 + { + public nuint F0; + public nint F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F78_S1_S0 + { + public sbyte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F78_S1 + { + public short F0; + public ulong F1; + public F78_S1_S0 F2; + public int F3; + public nint F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F78_S2 + { + public nuint F0; + public ulong F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F78_S3 + { + public ulong F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F78_S4 + { + public ulong F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func781fS2ds6UInt64V_AA6F78_S0VAeA0H3_S1VAA0H3_S2Vs5Int32VAEs5Int64VAA0H3_S3VS2fs6UInt16VAA0H3_S4VSdtXE_tF")] + private static extern double SwiftCallbackFunc78(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static double SwiftCallbackFunc78Callback(ulong a0, F78_S0 a1, ulong a2, F78_S1 a3, F78_S2 a4, int a5, ulong a6, long a7, F78_S3 a8, float a9, float a10, ushort a11, F78_S4 a12, double a13, SwiftSelf self) + { + try + { + Assert.Equal((ulong)6780767594736146373, a0); + Assert.Equal((nuint)unchecked((nuint)6264193481541646332), a1.F0); + Assert.Equal((nint)unchecked((nint)6600856439035088503), a1.F1); + Assert.Equal((ulong)1968254881389492170, a2); + Assert.Equal((short)-17873, a3.F0); + Assert.Equal((ulong)5581169895682201971, a3.F1); + Assert.Equal((sbyte)127, a3.F2.F0); + Assert.Equal((int)1942346704, a3.F3); + Assert.Equal((nint)unchecked((nint)118658265323815307), a3.F4); + Assert.Equal((nuint)unchecked((nuint)1489326778640378879), a4.F0); + Assert.Equal((ulong)1427061853707270770, a4.F1); + Assert.Equal((int)858391966, a5); + Assert.Equal((ulong)5830110056171302270, a6); + Assert.Equal((long)2953614358173898788, a7); + Assert.Equal((ulong)6761452244699684409, a8.F0); + Assert.Equal((float)3452451, a9); + Assert.Equal((float)3507119, a10); + Assert.Equal((ushort)40036, a11); + Assert.Equal((ulong)4800085294404376817, a12.F0); + Assert.Equal((double)780368756754436, a13); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 1088544646657969; + } + + [Fact] + public static void TestSwiftCallbackFunc78() + { + Console.Write("Running SwiftCallbackFunc78: "); + ExceptionDispatchInfo ex = null; + double val = SwiftCallbackFunc78(&SwiftCallbackFunc78Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((double)1088544646657969, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F79_S0_S0 + { + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F79_S0 + { + public F79_S0_S0 F0; + public nint F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F79_Ret + { + public uint F0; + public ulong F1; + public double F2; + + public F79_Ret(uint f0, ulong f1, double f2) + { + F0 = f0; + F1 = f1; + F2 = f2; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func791fAA7F79_RetVAeA0G3_S0V_SftXE_tF")] + private static extern F79_Ret SwiftCallbackFunc79(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F79_Ret SwiftCallbackFunc79Callback(F79_S0 a0, float a1, SwiftSelf self) + { + try + { + Assert.Equal((nuint)unchecked((nuint)1013911700897046117), a0.F0.F0); + Assert.Equal((nint)unchecked((nint)7323935615297665289), a0.F1); + Assert.Equal((float)5159506, a1); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F79_Ret(895629788, 4824209192377460356, 2599150646028906); + } + + [Fact] + public static void TestSwiftCallbackFunc79() + { + Console.Write("Running SwiftCallbackFunc79: "); + ExceptionDispatchInfo ex = null; + F79_Ret val = SwiftCallbackFunc79(&SwiftCallbackFunc79Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((uint)895629788, val.F0); + Assert.Equal((ulong)4824209192377460356, val.F1); + Assert.Equal((double)2599150646028906, val.F2); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F80_S0 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F80_S1_S0_S0 + { + public byte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F80_S1_S0 + { + public F80_S1_S0_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 9)] + struct F80_S1 + { + public nint F0; + public F80_S1_S0 F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F80_S2 + { + public ulong F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func801fS2fs6UInt64V_Sis5Int32Vs5Int16VSuAA6F80_S0VAISis4Int8VAGs6UInt32VAA0J3_S1VAA0J3_S2VAEtXE_tF")] + private static extern float SwiftCallbackFunc80(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static float SwiftCallbackFunc80Callback(ulong a0, nint a1, int a2, short a3, nuint a4, F80_S0 a5, short a6, nint a7, sbyte a8, int a9, uint a10, F80_S1 a11, F80_S2 a12, ulong a13, SwiftSelf self) + { + try + { + Assert.Equal((ulong)4470427843910624516, a0); + Assert.Equal((nint)unchecked((nint)8383677749057878551), a1); + Assert.Equal((int)2017117925, a2); + Assert.Equal((short)-10531, a3); + Assert.Equal((nuint)unchecked((nuint)3438375001906177611), a4); + Assert.Equal((ushort)65220, a5.F0); + Assert.Equal((short)7107, a6); + Assert.Equal((nint)unchecked((nint)7315288835693680178), a7); + Assert.Equal((sbyte)-48, a8); + Assert.Equal((int)813870434, a9); + Assert.Equal((uint)1092037477, a10); + Assert.Equal((nint)unchecked((nint)7104962838387954470), a11.F0); + Assert.Equal((byte)236, a11.F1.F0.F0); + Assert.Equal((ulong)7460392384225808790, a12.F0); + Assert.Equal((ulong)364121728483540667, a13); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 5169959; + } + + [Fact] + public static void TestSwiftCallbackFunc80() + { + Console.Write("Running SwiftCallbackFunc80: "); + ExceptionDispatchInfo ex = null; + float val = SwiftCallbackFunc80(&SwiftCallbackFunc80Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((float)5169959, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F81_S0 + { + public float F0; + public float F1; + public nint F2; + public nint F3; + public nint F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F81_Ret + { + public nint F0; + + public F81_Ret(nint f0) + { + F0 = f0; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func811fAA7F81_RetVAEs5UInt8V_s6UInt32VAgA0G3_S0Vs4Int8VtXE_tF")] + private static extern F81_Ret SwiftCallbackFunc81(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F81_Ret SwiftCallbackFunc81Callback(byte a0, uint a1, byte a2, F81_S0 a3, sbyte a4, SwiftSelf self) + { + try + { + Assert.Equal((byte)53, a0); + Assert.Equal((uint)57591489, a1); + Assert.Equal((byte)19, a2); + Assert.Equal((float)5675845, a3.F0); + Assert.Equal((float)6469988, a3.F1); + Assert.Equal((nint)unchecked((nint)5775316279348621124), a3.F2); + Assert.Equal((nint)unchecked((nint)7699091894067057939), a3.F3); + Assert.Equal((nint)unchecked((nint)1049086627558950131), a3.F4); + Assert.Equal((sbyte)15, a4); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F81_Ret(unchecked((nint)1055606720535823947)); + } + + [Fact] + public static void TestSwiftCallbackFunc81() + { + Console.Write("Running SwiftCallbackFunc81: "); + ExceptionDispatchInfo ex = null; + F81_Ret val = SwiftCallbackFunc81(&SwiftCallbackFunc81Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nint)unchecked((nint)1055606720535823947), val.F0); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 18)] + struct F82_S0_S0 + { + public float F0; + public nuint F1; + public ushort F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 28)] + struct F82_S0 + { + public nuint F0; + public F82_S0_S0 F1; + public ushort F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F82_S1 + { + public int F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F82_S2 + { + public nint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F82_S3_S0 + { + public int F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 20)] + struct F82_S3 + { + public double F0; + public nuint F1; + public F82_S3_S0 F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F82_S4 + { + public ulong F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func821fS2fs5Int64V_AA6F82_S0Vs5Int16Vs4Int8Vs6UInt32VAA0H3_S1Vs5Int32VAeKSdAA0H3_S2VAA0H3_S3VAA0H3_S4VtXE_tF")] + private static extern float SwiftCallbackFunc82(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static float SwiftCallbackFunc82Callback(long a0, F82_S0 a1, short a2, sbyte a3, uint a4, F82_S1 a5, int a6, long a7, sbyte a8, double a9, F82_S2 a10, F82_S3 a11, F82_S4 a12, SwiftSelf self) + { + try + { + Assert.Equal((long)6454754584537364459, a0); + Assert.Equal((nuint)unchecked((nuint)6703634779264968131), a1.F0); + Assert.Equal((float)1010059, a1.F1.F0); + Assert.Equal((nuint)unchecked((nuint)4772968591609202284), a1.F1.F1); + Assert.Equal((ushort)64552, a1.F1.F2); + Assert.Equal((ushort)47126, a1.F2); + Assert.Equal((short)9869, a2); + Assert.Equal((sbyte)-8, a3); + Assert.Equal((uint)1741550381, a4); + Assert.Equal((int)705741282, a5.F0); + Assert.Equal((int)1998781399, a6); + Assert.Equal((long)7787961471254401526, a7); + Assert.Equal((sbyte)-27, a8); + Assert.Equal((double)4429830670351707, a9); + Assert.Equal((nint)unchecked((nint)4975772762589349422), a10.F0); + Assert.Equal((double)1423948098664774, a11.F0); + Assert.Equal((nuint)unchecked((nuint)504607538824251986), a11.F1); + Assert.Equal((int)1940911018, a11.F2.F0); + Assert.Equal((ulong)2988623645681463667, a12.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 7514083; + } + + [Fact] + public static void TestSwiftCallbackFunc82() + { + Console.Write("Running SwiftCallbackFunc82: "); + ExceptionDispatchInfo ex = null; + float val = SwiftCallbackFunc82(&SwiftCallbackFunc82Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((float)7514083, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F83_S0 + { + public int F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F83_Ret + { + public short F0; + + public F83_Ret(short f0) + { + F0 = f0; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func831fAA7F83_RetVAEs4Int8V_AA0G3_S0Vs5Int16VtXE_tF")] + private static extern F83_Ret SwiftCallbackFunc83(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F83_Ret SwiftCallbackFunc83Callback(sbyte a0, F83_S0 a1, short a2, SwiftSelf self) + { + try + { + Assert.Equal((sbyte)17, a0); + Assert.Equal((int)530755056, a1.F0); + Assert.Equal((short)-11465, a2); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F83_Ret(-32475); + } + + [Fact] + public static void TestSwiftCallbackFunc83() + { + Console.Write("Running SwiftCallbackFunc83: "); + ExceptionDispatchInfo ex = null; + F83_Ret val = SwiftCallbackFunc83(&SwiftCallbackFunc83Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((short)-32475, val.F0); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 36)] + struct F84_S0 + { + public nuint F0; + public uint F1; + public nuint F2; + public ulong F3; + public int F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F84_S1 + { + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F84_S2 + { + public float F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F84_S3 + { + public byte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F84_S4 + { + public short F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 10)] + struct F84_S5 + { + public nint F0; + public short F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F84_S6 + { + public short F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F84_S7 + { + public int F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func841fS2is5Int32V_AA6F84_S0VAA0H3_S1VSdAEs5Int16VSdAA0H3_S2VAA0H3_S3VSdAA0H3_S4VAA0H3_S5VAA0H3_S6VAA0H3_S7VSutXE_tF")] + private static extern nint SwiftCallbackFunc84(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static nint SwiftCallbackFunc84Callback(int a0, F84_S0 a1, F84_S1 a2, double a3, int a4, short a5, double a6, F84_S2 a7, F84_S3 a8, double a9, F84_S4 a10, F84_S5 a11, F84_S6 a12, F84_S7 a13, nuint a14, SwiftSelf self) + { + try + { + Assert.Equal((int)1605022009, a0); + Assert.Equal((nuint)unchecked((nuint)6165049220831866664), a1.F0); + Assert.Equal((uint)1235491183, a1.F1); + Assert.Equal((nuint)unchecked((nuint)7926620970405586826), a1.F2); + Assert.Equal((ulong)2633248816907294140, a1.F3); + Assert.Equal((int)2012834055, a1.F4); + Assert.Equal((nuint)unchecked((nuint)2881830362339122988), a2.F0); + Assert.Equal((double)4065309434963087, a3); + Assert.Equal((int)1125165825, a4); + Assert.Equal((short)-32360, a5); + Assert.Equal((double)1145602045200029, a6); + Assert.Equal((float)5655563, a7.F0); + Assert.Equal((byte)14, a8.F0); + Assert.Equal((double)3919593995303128, a9); + Assert.Equal((short)26090, a10.F0); + Assert.Equal((nint)unchecked((nint)8584898862398781737), a11.F0); + Assert.Equal((short)-5185, a11.F1); + Assert.Equal((short)144, a12.F0); + Assert.Equal((int)2138004352, a13.F0); + Assert.Equal((nuint)unchecked((nuint)9102562043027810686), a14); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return unchecked((nint)2320162198211027422); + } + + [Fact] + public static void TestSwiftCallbackFunc84() + { + Console.Write("Running SwiftCallbackFunc84: "); + ExceptionDispatchInfo ex = null; + nint val = SwiftCallbackFunc84(&SwiftCallbackFunc84Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((nint)unchecked((nint)2320162198211027422), val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F85_S0 + { + public double F0; + public double F1; + public sbyte F2; + public int F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F85_S1 + { + public long F0; + public ushort F1; + public ulong F2; + public nuint F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F85_S2 + { + public float F0; + public float F1; + public uint F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F85_S3 + { + public byte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F85_S4 + { + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F85_S5 + { + public double F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 48)] + struct F85_Ret + { + public uint F0; + public ushort F1; + public int F2; + public double F3; + public nint F4; + public ulong F5; + public long F6; + + public F85_Ret(uint f0, ushort f1, int f2, double f3, nint f4, ulong f5, long f6) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + F4 = f4; + F5 = f5; + F6 = f6; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func851fAA7F85_RetVAeA0G3_S0V_AA0G3_S1Vs6UInt32VAA0G3_S2Vs5Int64VAA0G3_S3VAoA0G3_S4Vs6UInt16Vs5UInt8Vs5Int32VAkYSfAA0G3_S5VAOtXE_tF")] + private static extern F85_Ret SwiftCallbackFunc85(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F85_Ret SwiftCallbackFunc85Callback(F85_S0 a0, F85_S1 a1, uint a2, F85_S2 a3, long a4, F85_S3 a5, long a6, F85_S4 a7, ushort a8, byte a9, int a10, uint a11, int a12, float a13, F85_S5 a14, long a15, SwiftSelf self) + { + try + { + Assert.Equal((double)4325646965362202, a0.F0); + Assert.Equal((double)3313084380250914, a0.F1); + Assert.Equal((sbyte)42, a0.F2); + Assert.Equal((int)2034100272, a0.F3); + Assert.Equal((long)1365643665271339575, a1.F0); + Assert.Equal((ushort)25442, a1.F1); + Assert.Equal((ulong)3699631470459352980, a1.F2); + Assert.Equal((nuint)unchecked((nuint)7611776251925132200), a1.F3); + Assert.Equal((uint)911446742, a2); + Assert.Equal((float)352423, a3.F0); + Assert.Equal((float)7150341, a3.F1); + Assert.Equal((uint)2090089360, a3.F2); + Assert.Equal((long)5731257538910387688, a4); + Assert.Equal((byte)171, a5.F0); + Assert.Equal((long)5742887585483060342, a6); + Assert.Equal((nuint)unchecked((nuint)1182236975680416316), a7.F0); + Assert.Equal((ushort)32137, a8); + Assert.Equal((byte)44, a9); + Assert.Equal((int)2143531010, a10); + Assert.Equal((uint)1271996557, a11); + Assert.Equal((int)1035188446, a12); + Assert.Equal((float)1925443, a13); + Assert.Equal((double)2591574394337603, a14.F0); + Assert.Equal((long)721102428782331317, a15); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F85_Ret(1768798158, 27348, 1836190158, 2058478254572549, unchecked((nint)7881716796049851507), 5099946246805224241, 1499623158991084417); + } + + [Fact] + public static void TestSwiftCallbackFunc85() + { + Console.Write("Running SwiftCallbackFunc85: "); + ExceptionDispatchInfo ex = null; + F85_Ret val = SwiftCallbackFunc85(&SwiftCallbackFunc85Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((uint)1768798158, val.F0); + Assert.Equal((ushort)27348, val.F1); + Assert.Equal((int)1836190158, val.F2); + Assert.Equal((double)2058478254572549, val.F3); + Assert.Equal((nint)unchecked((nint)7881716796049851507), val.F4); + Assert.Equal((ulong)5099946246805224241, val.F5); + Assert.Equal((long)1499623158991084417, val.F6); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 15)] + struct F86_S0 + { + public nint F0; + public float F1; + public short F2; + public sbyte F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F86_S1 + { + public double F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F86_S2 + { + public nint F0; + public float F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F86_S3 + { + public ushort F0; + public float F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 17)] + struct F86_Ret + { + public short F0; + public uint F1; + public double F2; + public byte F3; + + public F86_Ret(short f0, uint f1, double f2, byte f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func861fAA7F86_RetVAESf_s5Int16VSiAGSfAA0G3_S0VAA0G3_S1VAA0G3_S2VSis6UInt32VS2uSfs5Int64VAA0G3_S3VSutXE_tF")] + private static extern F86_Ret SwiftCallbackFunc86(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F86_Ret SwiftCallbackFunc86Callback(float a0, short a1, nint a2, short a3, float a4, F86_S0 a5, F86_S1 a6, F86_S2 a7, nint a8, uint a9, nuint a10, nuint a11, float a12, long a13, F86_S3 a14, nuint a15, SwiftSelf self) + { + try + { + Assert.Equal((float)2913632, a0); + Assert.Equal((short)3735, a1); + Assert.Equal((nint)unchecked((nint)2773655476379499086), a2); + Assert.Equal((short)22973, a3); + Assert.Equal((float)8292778, a4); + Assert.Equal((nint)unchecked((nint)5562042565258891920), a5.F0); + Assert.Equal((float)8370233, a5.F1); + Assert.Equal((short)18292, a5.F2); + Assert.Equal((sbyte)-32, a5.F3); + Assert.Equal((double)486951152980016, a6.F0); + Assert.Equal((nint)unchecked((nint)170033426151098456), a7.F0); + Assert.Equal((float)3867810, a7.F1); + Assert.Equal((nint)unchecked((nint)7390780928011218856), a8); + Assert.Equal((uint)1504267943, a9); + Assert.Equal((nuint)unchecked((nuint)2046987193814931100), a10); + Assert.Equal((nuint)unchecked((nuint)4860202472307588968), a11); + Assert.Equal((float)1644019, a12); + Assert.Equal((long)8084012412562897328, a13); + Assert.Equal((ushort)46301, a14.F0); + Assert.Equal((float)5633701, a14.F1); + Assert.Equal((nuint)unchecked((nuint)1911608136082175332), a15); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F86_Ret(23398, 842205070, 544883763911905, 215); + } + + [Fact] + public static void TestSwiftCallbackFunc86() + { + Console.Write("Running SwiftCallbackFunc86: "); + ExceptionDispatchInfo ex = null; + F86_Ret val = SwiftCallbackFunc86(&SwiftCallbackFunc86Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((short)23398, val.F0); + Assert.Equal((uint)842205070, val.F1); + Assert.Equal((double)544883763911905, val.F2); + Assert.Equal((byte)215, val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F87_S0 + { + public int F0; + public short F1; + public int F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F87_S1 + { + public float F0; + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func871fs6UInt64VAESf_SiAA6F87_S0VAA0H3_S1VtXE_tF")] + private static extern ulong SwiftCallbackFunc87(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static ulong SwiftCallbackFunc87Callback(float a0, nint a1, F87_S0 a2, F87_S1 a3, SwiftSelf self) + { + try + { + Assert.Equal((float)1413086, a0); + Assert.Equal((nint)unchecked((nint)4206825694012787823), a1); + Assert.Equal((int)70240457, a2.F0); + Assert.Equal((short)30503, a2.F1); + Assert.Equal((int)671751848, a2.F2); + Assert.Equal((float)6641304, a3.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return 7817329728997505478; + } + + [Fact] + public static void TestSwiftCallbackFunc87() + { + Console.Write("Running SwiftCallbackFunc87: "); + ExceptionDispatchInfo ex = null; + ulong val = SwiftCallbackFunc87(&SwiftCallbackFunc87Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((ulong)7817329728997505478, val); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 18)] + struct F88_S0 + { + public sbyte F0; + public short F1; + public byte F2; + public double F3; + public ushort F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 9)] + struct F88_S1 + { + public double F0; + public byte F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F88_S2 + { + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F88_S3 + { + public sbyte F0; + public uint F1; + } + [StructLayout(LayoutKind.Sequential, Size = 24)] - struct F0_Ret + struct F88_Ret + { + public int F0; + public uint F1; + public nint F2; + public ulong F3; + + public F88_Ret(int f0, uint f1, nint f2, ulong f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func881fAA7F88_RetVAeA0G3_S0V_AA0G3_S1VSfSuSfSiAA0G3_S2Vs6UInt64VAA0G3_S3VAMtXE_tF")] + private static extern F88_Ret SwiftCallbackFunc88(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F88_Ret SwiftCallbackFunc88Callback(F88_S0 a0, F88_S1 a1, float a2, nuint a3, float a4, nint a5, F88_S2 a6, ulong a7, F88_S3 a8, ulong a9, SwiftSelf self) + { + try + { + Assert.Equal((sbyte)125, a0.F0); + Assert.Equal((short)-10705, a0.F1); + Assert.Equal((byte)21, a0.F2); + Assert.Equal((double)361845689097003, a0.F3); + Assert.Equal((ushort)41749, a0.F4); + Assert.Equal((double)1754583995806427, a1.F0); + Assert.Equal((byte)178, a1.F1); + Assert.Equal((float)4705205, a2); + Assert.Equal((nuint)unchecked((nuint)5985040566226273121), a3); + Assert.Equal((float)2484194, a4); + Assert.Equal((nint)unchecked((nint)1904196135427766362), a5); + Assert.Equal((nuint)unchecked((nuint)5436710892090266406), a6.F0); + Assert.Equal((ulong)4250368992471675181, a7); + Assert.Equal((sbyte)-87, a8.F0); + Assert.Equal((uint)362108395, a8.F1); + Assert.Equal((ulong)3388632419732870796, a9); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F88_Ret(46260161, 1256453227, unchecked((nint)1136413683894590872), 5467618237876965483); + } + + [Fact] + public static void TestSwiftCallbackFunc88() + { + Console.Write("Running SwiftCallbackFunc88: "); + ExceptionDispatchInfo ex = null; + F88_Ret val = SwiftCallbackFunc88(&SwiftCallbackFunc88Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((int)46260161, val.F0); + Assert.Equal((uint)1256453227, val.F1); + Assert.Equal((nint)unchecked((nint)1136413683894590872), val.F2); + Assert.Equal((ulong)5467618237876965483, val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F89_S0 + { + public double F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F89_Ret_S0 + { + public double F0; + + public F89_Ret_S0(double f0) + { + F0 = f0; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F89_Ret + { + public int F0; + public F89_Ret_S0 F1; + public nuint F2; + public long F3; + + public F89_Ret(int f0, F89_Ret_S0 f1, nuint f2, long f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func891fAA7F89_RetVAeA0G3_S0VXE_tF")] + private static extern F89_Ret SwiftCallbackFunc89(delegate* unmanaged[Swift] func, void* funcContext); + + [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] + private static F89_Ret SwiftCallbackFunc89Callback(F89_S0 a0, SwiftSelf self) + { + try + { + Assert.Equal((double)2137010348736191, a0.F0); + } + catch (Exception ex) + { + *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); + } + + return new F89_Ret(891143792, new F89_Ret_S0(3363709596088133), unchecked((nuint)18782615486598250), 1765451025668395967); + } + + [Fact] + public static void TestSwiftCallbackFunc89() + { + Console.Write("Running SwiftCallbackFunc89: "); + ExceptionDispatchInfo ex = null; + F89_Ret val = SwiftCallbackFunc89(&SwiftCallbackFunc89Callback, &ex); + if (ex != null) + ex.Throw(); + + Assert.Equal((int)891143792, val.F0); + Assert.Equal((double)3363709596088133, val.F1.F0); + Assert.Equal((nuint)unchecked((nuint)18782615486598250), val.F2); + Assert.Equal((long)1765451025668395967, val.F3); + Console.WriteLine("OK"); + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F90_S0_S0_S0 + { + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F90_S0_S0 + { + public F90_S0_S0_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 34)] + struct F90_S0 + { + public F90_S0_S0 F0; + public nuint F1; + public uint F2; + public long F3; + public short F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F90_S1 + { + public ushort F0; + public short F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F90_S2 + { + public nint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F90_S3 + { + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F90_S4 { - public ushort F0; - public float F1; - public int F2; - public ulong F3; + public ulong F0; + } - public F0_Ret(ushort f0, float f1, int f2, ulong f3) + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F90_Ret + { + public short F0; + public nint F1; + + public F90_Ret(short f0, nint f1) { F0 = f0; F1 = f1; - F2 = f2; - F3 = f3; } } [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] - [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func01fAA6F0_RetVAEs5Int16V_s5Int32Vs6UInt64Vs6UInt16Vs5Int64VSds6UInt32VAMSiAKtXE_tF")] - private static extern F0_Ret SwiftCallbackFunc0(delegate* unmanaged[Swift] func, void* funcContext); + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func901fAA7F90_RetVAEs5Int64V_SfAA0G3_S0Vs6UInt32Vs6UInt16VAA0G3_S1VAA0G3_S2VAA0G3_S3VAA0G3_S4VtXE_tF")] + private static extern F90_Ret SwiftCallbackFunc90(delegate* unmanaged[Swift] func, void* funcContext); [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] - private static F0_Ret SwiftCallbackFunc0Callback(short a0, int a1, ulong a2, ushort a3, long a4, double a5, uint a6, ushort a7, nint a8, ulong a9, SwiftSelf self) + private static F90_Ret SwiftCallbackFunc90Callback(long a0, float a1, F90_S0 a2, uint a3, ushort a4, F90_S1 a5, F90_S2 a6, F90_S3 a7, F90_S4 a8, SwiftSelf self) { try { - Assert.Equal((short)-17813, a0); - Assert.Equal((int)318006528, a1); - Assert.Equal((ulong)1195162122024233590, a2); - Assert.Equal((ushort)60467, a3); - Assert.Equal((long)4587464142261794085, a4); - Assert.Equal((double)2686980744237725, a5); - Assert.Equal((uint)331986645, a6); - Assert.Equal((ushort)56299, a7); - Assert.Equal((nint)unchecked((nint)6785053689615432643), a8); - Assert.Equal((ulong)6358078381523084952, a9); + Assert.Equal((long)920081051198141017, a0); + Assert.Equal((float)661904, a1); + Assert.Equal((nuint)unchecked((nuint)3898354148166517637), a2.F0.F0.F0); + Assert.Equal((nuint)unchecked((nuint)1003118682503285076), a2.F1); + Assert.Equal((uint)1418362079, a2.F2); + Assert.Equal((long)3276689793574299746, a2.F3); + Assert.Equal((short)-18559, a2.F4); + Assert.Equal((uint)1773011602, a3); + Assert.Equal((ushort)32638, a4); + Assert.Equal((ushort)47129, a5.F0); + Assert.Equal((short)-31849, a5.F1); + Assert.Equal((nint)unchecked((nint)4795020225668482328), a6.F0); + Assert.Equal((nuint)unchecked((nuint)5307513663902191175), a7.F0); + Assert.Equal((ulong)7057074401404034083, a8.F0); } catch (Exception ex) { *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); } - return new F0_Ret(65117, 981990, 1192391225, 7001579272668151908); + return new F90_Ret(25416, unchecked((nint)5015525780568020281)); } [Fact] - public static void TestSwiftCallbackFunc0() + public static void TestSwiftCallbackFunc90() { - Console.Write("Running SwiftCallbackFunc0: "); + Console.Write("Running SwiftCallbackFunc90: "); ExceptionDispatchInfo ex = null; - F0_Ret val = SwiftCallbackFunc0(&SwiftCallbackFunc0Callback, &ex); + F90_Ret val = SwiftCallbackFunc90(&SwiftCallbackFunc90Callback, &ex); if (ex != null) ex.Throw(); - Assert.Equal((ushort)65117, val.F0); - Assert.Equal((float)981990, val.F1); - Assert.Equal((int)1192391225, val.F2); - Assert.Equal((ulong)7001579272668151908, val.F3); + Assert.Equal((short)25416, val.F0); + Assert.Equal((nint)unchecked((nint)5015525780568020281), val.F1); Console.WriteLine("OK"); } + [StructLayout(LayoutKind.Sequential, Size = 20)] + struct F91_S0 + { + public sbyte F0; + public nint F1; + public ushort F2; + public ushort F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 36)] + struct F91_S1 + { + public double F0; + public ulong F1; + public sbyte F2; + public long F3; + public float F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F91_S2_S0_S0 + { + public long F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F91_S2_S0 + { + public F91_S2_S0_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 18)] + struct F91_S2 + { + public double F0; + public F91_S2_S0 F1; + public short F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F91_S3_S0 + { + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F91_S3 + { + public F91_S3_S0 F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 24)] + struct F91_Ret + { + public long F0; + public ulong F1; + public short F2; + public uint F3; + + public F91_Ret(long f0, ulong f1, short f2, uint f3) + { + F0 = f0; + F1 = f1; + F2 = f2; + F3 = f3; + } + } + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] - [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func11fS2uSd_s4Int8Vs5Int32Vs6UInt16Vs5UInt8VSdAKs6UInt64Vs5Int16VS2fAmEtXE_tF")] - private static extern nuint SwiftCallbackFunc1(delegate* unmanaged[Swift] func, void* funcContext); + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func911fAA7F91_RetVAeA0G3_S0V_s5Int16Vs6UInt32VSdAA0G3_S1Vs5Int64Vs6UInt64VSfAA0G3_S2VSiAA0G3_S3VtXE_tF")] + private static extern F91_Ret SwiftCallbackFunc91(delegate* unmanaged[Swift] func, void* funcContext); [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] - private static nuint SwiftCallbackFunc1Callback(double a0, sbyte a1, int a2, ushort a3, byte a4, double a5, byte a6, ulong a7, short a8, float a9, float a10, ulong a11, sbyte a12, SwiftSelf self) + private static F91_Ret SwiftCallbackFunc91Callback(F91_S0 a0, short a1, uint a2, double a3, F91_S1 a4, long a5, ulong a6, float a7, F91_S2 a8, nint a9, F91_S3 a10, SwiftSelf self) { try { - Assert.Equal((double)3867437130564654, a0); - Assert.Equal((sbyte)-64, a1); - Assert.Equal((int)31081182, a2); - Assert.Equal((ushort)20316, a3); - Assert.Equal((byte)73, a4); - Assert.Equal((double)3543740592144911, a5); - Assert.Equal((byte)250, a6); - Assert.Equal((ulong)6680393408153342744, a7); - Assert.Equal((short)23758, a8); - Assert.Equal((float)7189013, a9); - Assert.Equal((float)5438196, a10); - Assert.Equal((ulong)3310322731568932038, a11); - Assert.Equal((sbyte)3, a12); + Assert.Equal((sbyte)-117, a0.F0); + Assert.Equal((nint)unchecked((nint)6851485542307521521), a0.F1); + Assert.Equal((ushort)23224, a0.F2); + Assert.Equal((ushort)28870, a0.F3); + Assert.Equal((short)-26318, a1); + Assert.Equal((uint)874052395, a2); + Assert.Equal((double)3651199868446152, a3); + Assert.Equal((double)3201729800438540, a4.F0); + Assert.Equal((ulong)7737032265509566019, a4.F1); + Assert.Equal((sbyte)123, a4.F2); + Assert.Equal((long)7508633930609553617, a4.F3); + Assert.Equal((float)8230501, a4.F4); + Assert.Equal((long)2726677037673277403, a5); + Assert.Equal((ulong)4990410590084533996, a6); + Assert.Equal((float)3864639, a7); + Assert.Equal((double)1763083442463892, a8.F0); + Assert.Equal((long)6783710957456602933, a8.F1.F0.F0); + Assert.Equal((short)2927, a8.F2); + Assert.Equal((nint)unchecked((nint)3359440517385934325), a9); + Assert.Equal((nuint)unchecked((nuint)3281136825102667421), a10.F0.F0); } catch (Exception ex) { *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); } - return unchecked((nuint)2172476334497055933); + return new F91_Ret(8703949006228331232, 4839530995689756024, 14798, 1337111683); } [Fact] - public static void TestSwiftCallbackFunc1() + public static void TestSwiftCallbackFunc91() { - Console.Write("Running SwiftCallbackFunc1: "); + Console.Write("Running SwiftCallbackFunc91: "); ExceptionDispatchInfo ex = null; - nuint val = SwiftCallbackFunc1(&SwiftCallbackFunc1Callback, &ex); + F91_Ret val = SwiftCallbackFunc91(&SwiftCallbackFunc91Callback, &ex); if (ex != null) ex.Throw(); - Assert.Equal((nuint)unchecked((nuint)2172476334497055933), val); + Assert.Equal((long)8703949006228331232, val.F0); + Assert.Equal((ulong)4839530995689756024, val.F1); + Assert.Equal((short)14798, val.F2); + Assert.Equal((uint)1337111683, val.F3); Console.WriteLine("OK"); } - [StructLayout(LayoutKind.Sequential, Size = 12)] - struct F2_Ret_S0 + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F92_S0 { - public long F0; - public int F1; + public double F0; + public double F1; + } - public F2_Ret_S0(long f0, int f1) - { - F0 = f0; - F1 = f1; - } + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F92_S1 + { + public uint F0; + public long F1; + public uint F2; + public short F3; + public ulong F4; } - [StructLayout(LayoutKind.Sequential, Size = 14)] - struct F2_Ret + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F92_S2_S0 { - public F2_Ret_S0 F0; - public short F1; + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 18)] + struct F92_S2 + { + public uint F0; + public long F1; + public F92_S2_S0 F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F92_Ret + { + public int F0; - public F2_Ret(F2_Ret_S0 f0, short f1) + public F92_Ret(int f0) { F0 = f0; - F1 = f1; } } [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] - [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func21fAA6F2_RetVAESu_s5UInt8VtXE_tF")] - private static extern F2_Ret SwiftCallbackFunc2(delegate* unmanaged[Swift] func, void* funcContext); + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func921fAA7F92_RetVAEs6UInt32V_s5Int64VAA0G3_S0VSis5UInt8VAA0G3_S1VAA0G3_S2VAMSis5Int32VtXE_tF")] + private static extern F92_Ret SwiftCallbackFunc92(delegate* unmanaged[Swift] func, void* funcContext); [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] - private static F2_Ret SwiftCallbackFunc2Callback(nuint a0, byte a1, SwiftSelf self) + private static F92_Ret SwiftCallbackFunc92Callback(uint a0, long a1, F92_S0 a2, nint a3, byte a4, F92_S1 a5, F92_S2 a6, byte a7, nint a8, int a9, SwiftSelf self) { try { - Assert.Equal((nuint)unchecked((nuint)2153637757371267722), a0); - Assert.Equal((byte)150, a1); + Assert.Equal((uint)479487770, a0); + Assert.Equal((long)3751818229732502126, a1); + Assert.Equal((double)3486664439392893, a2.F0); + Assert.Equal((double)1451061144702448, a2.F1); + Assert.Equal((nint)unchecked((nint)1103649059951788126), a3); + Assert.Equal((byte)17, a4); + Assert.Equal((uint)1542537473, a5.F0); + Assert.Equal((long)2256304993713022795, a5.F1); + Assert.Equal((uint)1773847876, a5.F2); + Assert.Equal((short)-4712, a5.F3); + Assert.Equal((ulong)2811859744132572185, a5.F4); + Assert.Equal((uint)290315682, a6.F0); + Assert.Equal((long)4847587202070249866, a6.F1); + Assert.Equal((ushort)20774, a6.F2.F0); + Assert.Equal((byte)8, a7); + Assert.Equal((nint)unchecked((nint)2206063999764082749), a8); + Assert.Equal((int)1481391120, a9); } catch (Exception ex) { *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); } - return new F2_Ret(new F2_Ret_S0(5628852360797741825, 939232542), -9943); + return new F92_Ret(2031462105); } [Fact] - public static void TestSwiftCallbackFunc2() + public static void TestSwiftCallbackFunc92() { - Console.Write("Running SwiftCallbackFunc2: "); + Console.Write("Running SwiftCallbackFunc92: "); ExceptionDispatchInfo ex = null; - F2_Ret val = SwiftCallbackFunc2(&SwiftCallbackFunc2Callback, &ex); + F92_Ret val = SwiftCallbackFunc92(&SwiftCallbackFunc92Callback, &ex); if (ex != null) ex.Throw(); - Assert.Equal((long)5628852360797741825, val.F0.F0); - Assert.Equal((int)939232542, val.F0.F1); - Assert.Equal((short)-9943, val.F1); + Assert.Equal((int)2031462105, val.F0); Console.WriteLine("OK"); } - [StructLayout(LayoutKind.Sequential, Size = 10)] - struct F3_Ret_S0 + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F93_S0 { - public short F0; - public int F1; - public ushort F2; + public sbyte F0; + public uint F1; + } - public F3_Ret_S0(short f0, int f1, ushort f2) - { - F0 = f0; - F1 = f1; - F2 = f2; - } + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F93_S1 + { + public uint F0; } - [StructLayout(LayoutKind.Sequential, Size = 33)] - struct F3_Ret + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F93_Ret { public nint F0; - public F3_Ret_S0 F1; - public nuint F2; - public sbyte F3; + public ulong F1; - public F3_Ret(nint f0, F3_Ret_S0 f1, nuint f2, sbyte f3) + public F93_Ret(nint f0, ulong f1) { F0 = f0; F1 = f1; - F2 = f2; - F3 = f3; } } [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] - [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func31fAA6F3_RetVAEs6UInt16V_S2uSiSfAGtXE_tF")] - private static extern F3_Ret SwiftCallbackFunc3(delegate* unmanaged[Swift] func, void* funcContext); + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func931fAA7F93_RetVAESu_s6UInt16VSdAA0G3_S0VAA0G3_S1VtXE_tF")] + private static extern F93_Ret SwiftCallbackFunc93(delegate* unmanaged[Swift] func, void* funcContext); [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] - private static F3_Ret SwiftCallbackFunc3Callback(ushort a0, nuint a1, nuint a2, nint a3, float a4, ushort a5, SwiftSelf self) + private static F93_Ret SwiftCallbackFunc93Callback(nuint a0, ushort a1, double a2, F93_S0 a3, F93_S1 a4, SwiftSelf self) { try { - Assert.Equal((ushort)45065, a0); - Assert.Equal((nuint)unchecked((nuint)8506742096411295359), a1); - Assert.Equal((nuint)unchecked((nuint)8619375465417625458), a2); - Assert.Equal((nint)unchecked((nint)5288917394772427257), a3); - Assert.Equal((float)5678138, a4); - Assert.Equal((ushort)33467, a5); + Assert.Equal((nuint)unchecked((nuint)5170226481546239050), a0); + Assert.Equal((ushort)2989, a1); + Assert.Equal((double)1630717078645270, a2); + Assert.Equal((sbyte)-46, a3.F0); + Assert.Equal((uint)859171256, a3.F1); + Assert.Equal((uint)254449240, a4.F0); } catch (Exception ex) { *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); } - return new F3_Ret(unchecked((nint)3330016214205716187), new F3_Ret_S0(-29819, 2075852318, 671), unchecked((nuint)2368015527878194540), -79); + return new F93_Ret(unchecked((nint)7713003294977630041), 4769707787914611024); } [Fact] - public static void TestSwiftCallbackFunc3() + public static void TestSwiftCallbackFunc93() { - Console.Write("Running SwiftCallbackFunc3: "); + Console.Write("Running SwiftCallbackFunc93: "); ExceptionDispatchInfo ex = null; - F3_Ret val = SwiftCallbackFunc3(&SwiftCallbackFunc3Callback, &ex); + F93_Ret val = SwiftCallbackFunc93(&SwiftCallbackFunc93Callback, &ex); if (ex != null) ex.Throw(); - Assert.Equal((nint)unchecked((nint)3330016214205716187), val.F0); - Assert.Equal((short)-29819, val.F1.F0); - Assert.Equal((int)2075852318, val.F1.F1); - Assert.Equal((ushort)671, val.F1.F2); - Assert.Equal((nuint)unchecked((nuint)2368015527878194540), val.F2); - Assert.Equal((sbyte)-79, val.F3); + Assert.Equal((nint)unchecked((nint)7713003294977630041), val.F0); + Assert.Equal((ulong)4769707787914611024, val.F1); Console.WriteLine("OK"); } - [StructLayout(LayoutKind.Sequential, Size = 24)] - struct F4_Ret + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F94_S0 { - public ulong F0; + public nuint F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F94_S1 + { + public int F0; + public nuint F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 14)] + struct F94_S2 + { + public nint F0; public uint F1; - public ulong F2; + public ushort F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 12)] + struct F94_S3 + { + public byte F0; + public int F1; + public float F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 20)] + struct F94_S4 + { + public int F0; + public long F1; + public float F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 19)] + struct F94_S5 + { + public short F0; + public nuint F1; + public short F2; + public sbyte F3; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F94_Ret + { + public long F0; - public F4_Ret(ulong f0, uint f1, ulong f2) + public F94_Ret(long f0) { F0 = f0; - F1 = f1; - F2 = f2; } } [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] - [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func41fAA6F4_RetVAEs5Int64V_s6UInt16Vs5Int32VAISiSdAISfAkIs4Int8VSfs6UInt64Vs5Int16VSdA2mKSiAk2GtXE_tF")] - private static extern F4_Ret SwiftCallbackFunc4(delegate* unmanaged[Swift] func, void* funcContext); + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func941fAA7F94_RetVAeA0G3_S0V_s5Int16VAA0G3_S1VAA0G3_S2VAA0G3_S3VSfAA0G3_S4Vs6UInt32VAA0G3_S5VAItXE_tF")] + private static extern F94_Ret SwiftCallbackFunc94(delegate* unmanaged[Swift] func, void* funcContext); [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] - private static F4_Ret SwiftCallbackFunc4Callback(long a0, ushort a1, int a2, ushort a3, nint a4, double a5, ushort a6, float a7, int a8, ushort a9, sbyte a10, float a11, ulong a12, short a13, double a14, sbyte a15, sbyte a16, int a17, nint a18, int a19, long a20, long a21, SwiftSelf self) + private static F94_Ret SwiftCallbackFunc94Callback(F94_S0 a0, short a1, F94_S1 a2, F94_S2 a3, F94_S3 a4, float a5, F94_S4 a6, uint a7, F94_S5 a8, short a9, SwiftSelf self) { try { - Assert.Equal((long)8771527078890676837, a0); - Assert.Equal((ushort)18667, a1); - Assert.Equal((int)224631333, a2); - Assert.Equal((ushort)13819, a3); - Assert.Equal((nint)unchecked((nint)8888237425788084647), a4); - Assert.Equal((double)2677321682649925, a5); - Assert.Equal((ushort)50276, a6); - Assert.Equal((float)2703201, a7); - Assert.Equal((int)545337834, a8); - Assert.Equal((ushort)11190, a9); - Assert.Equal((sbyte)112, a10); - Assert.Equal((float)4053251, a11); - Assert.Equal((ulong)7107857019164433129, a12); - Assert.Equal((short)-3092, a13); - Assert.Equal((double)2176685406663423, a14); - Assert.Equal((sbyte)57, a15); - Assert.Equal((sbyte)-61, a16); - Assert.Equal((int)866840318, a17); - Assert.Equal((nint)unchecked((nint)5927291145767969522), a18); - Assert.Equal((int)1818333546, a19); - Assert.Equal((long)6272248211765159948, a20); - Assert.Equal((long)6555966806846053216, a21); + Assert.Equal((nuint)unchecked((nuint)8626725032375870186), a0.F0); + Assert.Equal((short)-7755, a1); + Assert.Equal((int)544707027, a2.F0); + Assert.Equal((nuint)unchecked((nuint)2251410026467996594), a2.F1); + Assert.Equal((nint)unchecked((nint)2972912419231960385), a3.F0); + Assert.Equal((uint)740529487, a3.F1); + Assert.Equal((ushort)34526, a3.F2); + Assert.Equal((byte)41, a4.F0); + Assert.Equal((int)1598856955, a4.F1); + Assert.Equal((float)5126603, a4.F2); + Assert.Equal((float)7242977, a5); + Assert.Equal((int)473684762, a6.F0); + Assert.Equal((long)4023878650965716094, a6.F1); + Assert.Equal((float)2777693, a6.F2); + Assert.Equal((uint)1612378906, a7); + Assert.Equal((short)-17074, a8.F0); + Assert.Equal((nuint)unchecked((nuint)2666903737827472071), a8.F1); + Assert.Equal((short)418, a8.F2); + Assert.Equal((sbyte)106, a8.F3); + Assert.Equal((short)-14547, a9); } catch (Exception ex) { *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); } - return new F4_Ret(2182947204061522719, 1721424472, 7504841280611598884); + return new F94_Ret(4965341488842559693); } [Fact] - public static void TestSwiftCallbackFunc4() + public static void TestSwiftCallbackFunc94() { - Console.Write("Running SwiftCallbackFunc4: "); + Console.Write("Running SwiftCallbackFunc94: "); ExceptionDispatchInfo ex = null; - F4_Ret val = SwiftCallbackFunc4(&SwiftCallbackFunc4Callback, &ex); + F94_Ret val = SwiftCallbackFunc94(&SwiftCallbackFunc94Callback, &ex); if (ex != null) ex.Throw(); - Assert.Equal((ulong)2182947204061522719, val.F0); - Assert.Equal((uint)1721424472, val.F1); - Assert.Equal((ulong)7504841280611598884, val.F2); + Assert.Equal((long)4965341488842559693, val.F0); Console.WriteLine("OK"); } - [StructLayout(LayoutKind.Sequential, Size = 40)] - struct F5_Ret + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F95_S0 { - public ulong F0; - public int F1; - public nint F2; - public float F3; - public short F4; - public ulong F5; + public ushort F0; + public long F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F95_S1 + { + public uint F0; + public short F1; + public double F2; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F95_S2 + { + public ushort F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F95_Ret_S0 + { + public short F0; + + public F95_Ret_S0(short f0) + { + F0 = f0; + } + } + + [StructLayout(LayoutKind.Sequential, Size = 14)] + struct F95_Ret + { + public nint F0; + public short F1; + public sbyte F2; + public byte F3; + public F95_Ret_S0 F4; - public F5_Ret(ulong f0, int f1, nint f2, float f3, short f4, ulong f5) + public F95_Ret(nint f0, short f1, sbyte f2, byte f3, F95_Ret_S0 f4) { F0 = f0; F1 = f1; F2 = f2; F3 = f3; F4 = f4; - F5 = f5; } } [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] - [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func51fAA6F5_RetVAEs5Int32V_s6UInt16VAIs5Int16Vs5UInt8Vs4Int8VAMSis6UInt64VAQs5Int64VA2ksimItXE_tF")] - private static extern F5_Ret SwiftCallbackFunc5(delegate* unmanaged[Swift] func, void* funcContext); + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func951fAA7F95_RetVAeA0G3_S0V_SuAA0G3_S1VAA0G3_S2VtXE_tF")] + private static extern F95_Ret SwiftCallbackFunc95(delegate* unmanaged[Swift] func, void* funcContext); [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] - private static F5_Ret SwiftCallbackFunc5Callback(int a0, ushort a1, ushort a2, short a3, byte a4, sbyte a5, byte a6, nint a7, ulong a8, ulong a9, long a10, short a11, short a12, long a13, ushort a14, byte a15, ushort a16, SwiftSelf self) + private static F95_Ret SwiftCallbackFunc95Callback(F95_S0 a0, nuint a1, F95_S1 a2, F95_S2 a3, SwiftSelf self) { try { - Assert.Equal((int)359602150, a0); - Assert.Equal((ushort)51495, a1); - Assert.Equal((ushort)37765, a2); - Assert.Equal((short)29410, a3); - Assert.Equal((byte)95, a4); - Assert.Equal((sbyte)-104, a5); - Assert.Equal((byte)32, a6); - Assert.Equal((nint)unchecked((nint)8530952551906271255), a7); - Assert.Equal((ulong)706266487837805024, a8); - Assert.Equal((ulong)707905209555595641, a9); - Assert.Equal((long)8386588676727568762, a10); - Assert.Equal((short)-8624, a11); - Assert.Equal((short)26113, a12); - Assert.Equal((long)8389143657021522019, a13); - Assert.Equal((ushort)13337, a14); - Assert.Equal((byte)229, a15); - Assert.Equal((ushort)51876, a16); + Assert.Equal((ushort)45388, a0.F0); + Assert.Equal((long)6620047889014935849, a0.F1); + Assert.Equal((nuint)unchecked((nuint)97365157264460373), a1); + Assert.Equal((uint)357234637, a2.F0); + Assert.Equal((short)-13720, a2.F1); + Assert.Equal((double)3313430568949662, a2.F2); + Assert.Equal((ushort)14248, a3.F0); } catch (Exception ex) { *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); } - return new F5_Ret(5224035852455624489, 493616651, unchecked((nint)3355493231962241213), 8151117, -6001, 2418751914358801711); + return new F95_Ret(unchecked((nint)6503817931835164175), 1481, 117, 79, new F95_Ret_S0(-2735)); } [Fact] - public static void TestSwiftCallbackFunc5() + public static void TestSwiftCallbackFunc95() { - Console.Write("Running SwiftCallbackFunc5: "); + Console.Write("Running SwiftCallbackFunc95: "); ExceptionDispatchInfo ex = null; - F5_Ret val = SwiftCallbackFunc5(&SwiftCallbackFunc5Callback, &ex); + F95_Ret val = SwiftCallbackFunc95(&SwiftCallbackFunc95Callback, &ex); if (ex != null) ex.Throw(); - Assert.Equal((ulong)5224035852455624489, val.F0); - Assert.Equal((int)493616651, val.F1); - Assert.Equal((nint)unchecked((nint)3355493231962241213), val.F2); - Assert.Equal((float)8151117, val.F3); - Assert.Equal((short)-6001, val.F4); - Assert.Equal((ulong)2418751914358801711, val.F5); + Assert.Equal((nint)unchecked((nint)6503817931835164175), val.F0); + Assert.Equal((short)1481, val.F1); + Assert.Equal((sbyte)117, val.F2); + Assert.Equal((byte)79, val.F3); + Assert.Equal((short)-2735, val.F4.F0); Console.WriteLine("OK"); } + [StructLayout(LayoutKind.Sequential, Size = 32)] + struct F96_S0 + { + public long F0; + public uint F1; + public short F2; + public double F3; + public double F4; + } + + [StructLayout(LayoutKind.Sequential, Size = 8)] + struct F96_S1 + { + public ulong F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F96_S2 + { + public float F0; + } + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] - [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func61fs6UInt16VAEs5Int32V_s6UInt32Vs6UInt64VAGs4Int8VS2is5Int16VSiAi2Ks5Int64VAItXE_tF")] - private static extern ushort SwiftCallbackFunc6(delegate* unmanaged[Swift] func, void* funcContext); + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func961fs6UInt64VAEs6UInt32V_AA6F96_S0VSfAe2gA0I3_S1VAA0I3_S2Vs5Int64VtXE_tF")] + private static extern ulong SwiftCallbackFunc96(delegate* unmanaged[Swift] func, void* funcContext); [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] - private static ushort SwiftCallbackFunc6Callback(int a0, uint a1, ulong a2, int a3, sbyte a4, nint a5, nint a6, short a7, nint a8, uint a9, ulong a10, ulong a11, long a12, uint a13, SwiftSelf self) + private static ulong SwiftCallbackFunc96Callback(uint a0, F96_S0 a1, float a2, ulong a3, uint a4, uint a5, F96_S1 a6, F96_S2 a7, long a8, SwiftSelf self) { try { - Assert.Equal((int)743741783, a0); - Assert.Equal((uint)850236948, a1); - Assert.Equal((ulong)5908745692727636656, a2); - Assert.Equal((int)2106839818, a3); - Assert.Equal((sbyte)77, a4); - Assert.Equal((nint)unchecked((nint)291907785975160065), a5); - Assert.Equal((nint)unchecked((nint)3560129042279209151), a6); - Assert.Equal((short)-30568, a7); - Assert.Equal((nint)unchecked((nint)5730241035812482149), a8); - Assert.Equal((uint)18625011, a9); - Assert.Equal((ulong)242340713355417257, a10); - Assert.Equal((ulong)6962175160124965670, a11); - Assert.Equal((long)2935089705514798822, a12); - Assert.Equal((uint)2051956645, a13); + Assert.Equal((uint)1103144790, a0); + Assert.Equal((long)496343164737276588, a1.F0); + Assert.Equal((uint)1541085564, a1.F1); + Assert.Equal((short)-16271, a1.F2); + Assert.Equal((double)1062575289573718, a1.F3); + Assert.Equal((double)570255786498865, a1.F4); + Assert.Equal((float)7616839, a2); + Assert.Equal((ulong)7370881799887414383, a3); + Assert.Equal((uint)390392554, a4); + Assert.Equal((uint)1492692139, a5); + Assert.Equal((ulong)1666031716012978365, a6.F0); + Assert.Equal((float)3427394, a7.F0); + Assert.Equal((long)4642371619161527189, a8); } catch (Exception ex) { *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); } - return 45160; + return 8803914823303717324; } [Fact] - public static void TestSwiftCallbackFunc6() + public static void TestSwiftCallbackFunc96() { - Console.Write("Running SwiftCallbackFunc6: "); + Console.Write("Running SwiftCallbackFunc96: "); ExceptionDispatchInfo ex = null; - ushort val = SwiftCallbackFunc6(&SwiftCallbackFunc6Callback, &ex); + ulong val = SwiftCallbackFunc96(&SwiftCallbackFunc96Callback, &ex); if (ex != null) ex.Throw(); - Assert.Equal((ushort)45160, val); + Assert.Equal((ulong)8803914823303717324, val); Console.WriteLine("OK"); } + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F97_S0 + { + public sbyte F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F97_S1 + { + public long F0; + public ulong F1; + } + + [StructLayout(LayoutKind.Sequential, Size = 16)] + struct F97_S2 + { + public byte F0; + public long F1; + } + [StructLayout(LayoutKind.Sequential, Size = 8)] - struct F7_Ret_S0 + struct F97_S3 { - public nint F0; + public double F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F97_Ret_S0 + { + public int F0; - public F7_Ret_S0(nint f0) + public F97_Ret_S0(int f0) { F0 = f0; } } - [StructLayout(LayoutKind.Sequential, Size = 20)] - struct F7_Ret + [StructLayout(LayoutKind.Sequential, Size = 28)] + struct F97_Ret { - public sbyte F0; - public sbyte F1; - public byte F2; - public F7_Ret_S0 F3; + public double F0; + public nuint F1; + public F97_Ret_S0 F2; + public ushort F3; public uint F4; - public F7_Ret(sbyte f0, sbyte f1, byte f2, F7_Ret_S0 f3, uint f4) + public F97_Ret(double f0, nuint f1, F97_Ret_S0 f2, ushort f3, uint f4) { F0 = f0; F1 = f1; @@ -474,150 +8424,150 @@ public F7_Ret(sbyte f0, sbyte f1, byte f2, F7_Ret_S0 f3, uint f4) } [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] - [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func71fAA6F7_RetVAEs6UInt64V_s5UInt8Vs5Int16VSutXE_tF")] - private static extern F7_Ret SwiftCallbackFunc7(delegate* unmanaged[Swift] func, void* funcContext); + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func971fAA7F97_RetVAeA0G3_S0V_AA0G3_S1VAA0G3_S2VAA0G3_S3VtXE_tF")] + private static extern F97_Ret SwiftCallbackFunc97(delegate* unmanaged[Swift] func, void* funcContext); [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] - private static F7_Ret SwiftCallbackFunc7Callback(ulong a0, byte a1, short a2, nuint a3, SwiftSelf self) + private static F97_Ret SwiftCallbackFunc97Callback(F97_S0 a0, F97_S1 a1, F97_S2 a2, F97_S3 a3, SwiftSelf self) { try { - Assert.Equal((ulong)7625368278886567558, a0); - Assert.Equal((byte)70, a1); - Assert.Equal((short)26780, a2); - Assert.Equal((nuint)unchecked((nuint)7739343395912136630), a3); + Assert.Equal((sbyte)-87, a0.F0); + Assert.Equal((long)1414208343412494909, a1.F0); + Assert.Equal((ulong)453284654311256466, a1.F1); + Assert.Equal((byte)224, a2.F0); + Assert.Equal((long)1712859616922087053, a2.F1); + Assert.Equal((double)3987671154739178, a3.F0); } catch (Exception ex) { *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); } - return new F7_Ret(-96, -93, 251, new F7_Ret_S0(unchecked((nint)3590193056511262571)), 13223810); + return new F97_Ret(3262802544778620, unchecked((nuint)988644880611380240), new F97_Ret_S0(1818371708), 15694, 2068394006); } [Fact] - public static void TestSwiftCallbackFunc7() + public static void TestSwiftCallbackFunc97() { - Console.Write("Running SwiftCallbackFunc7: "); + Console.Write("Running SwiftCallbackFunc97: "); ExceptionDispatchInfo ex = null; - F7_Ret val = SwiftCallbackFunc7(&SwiftCallbackFunc7Callback, &ex); + F97_Ret val = SwiftCallbackFunc97(&SwiftCallbackFunc97Callback, &ex); if (ex != null) ex.Throw(); - Assert.Equal((sbyte)-96, val.F0); - Assert.Equal((sbyte)-93, val.F1); - Assert.Equal((byte)251, val.F2); - Assert.Equal((nint)unchecked((nint)3590193056511262571), val.F3.F0); - Assert.Equal((uint)13223810, val.F4); + Assert.Equal((double)3262802544778620, val.F0); + Assert.Equal((nuint)unchecked((nuint)988644880611380240), val.F1); + Assert.Equal((int)1818371708, val.F2.F0); + Assert.Equal((ushort)15694, val.F3); + Assert.Equal((uint)2068394006, val.F4); Console.WriteLine("OK"); } + [StructLayout(LayoutKind.Sequential, Size = 4)] + struct F98_S0 + { + public int F0; + } + [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] - [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func81fs5UInt8VAESf_SutXE_tF")] - private static extern byte SwiftCallbackFunc8(delegate* unmanaged[Swift] func, void* funcContext); + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func981fS2iSf_s6UInt16VAA6F98_S0VAEtXE_tF")] + private static extern nint SwiftCallbackFunc98(delegate* unmanaged[Swift] func, void* funcContext); [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] - private static byte SwiftCallbackFunc8Callback(float a0, nuint a1, SwiftSelf self) + private static nint SwiftCallbackFunc98Callback(float a0, ushort a1, F98_S0 a2, ushort a3, SwiftSelf self) { try { - Assert.Equal((float)6278007, a0); - Assert.Equal((nuint)unchecked((nuint)1620979945874429615), a1); + Assert.Equal((float)2863898, a0); + Assert.Equal((ushort)37573, a1); + Assert.Equal((int)1073068257, a2.F0); + Assert.Equal((ushort)53560, a3); } catch (Exception ex) { *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); } - return 60; + return unchecked((nint)6686142382639170849); } [Fact] - public static void TestSwiftCallbackFunc8() + public static void TestSwiftCallbackFunc98() { - Console.Write("Running SwiftCallbackFunc8: "); + Console.Write("Running SwiftCallbackFunc98: "); ExceptionDispatchInfo ex = null; - byte val = SwiftCallbackFunc8(&SwiftCallbackFunc8Callback, &ex); + nint val = SwiftCallbackFunc98(&SwiftCallbackFunc98Callback, &ex); if (ex != null) ex.Throw(); - Assert.Equal((byte)60, val); + Assert.Equal((nint)unchecked((nint)6686142382639170849), val); Console.WriteLine("OK"); } - [StructLayout(LayoutKind.Sequential, Size = 26)] - struct F9_Ret + [StructLayout(LayoutKind.Sequential, Size = 20)] + struct F99_S0 { - public uint F0; - public long F1; - public ulong F2; - public ushort F3; + public nint F0; + public uint F1; + public int F2; + public uint F3; + } - public F9_Ret(uint f0, long f1, ulong f2, ushort f3) - { - F0 = f0; - F1 = f1; - F2 = f2; - F3 = f3; - } + [StructLayout(LayoutKind.Sequential, Size = 2)] + struct F99_S1 + { + public short F0; + } + + [StructLayout(LayoutKind.Sequential, Size = 1)] + struct F99_S2 + { + public byte F0; } [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })] - [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB5Func91fAA6F9_RetVAEs4Int8V_Sis5Int16Vs5Int64VS2dSis6UInt16VAMS2fAMs6UInt32VAIs5Int32VAQs6UInt64VAiKSis5UInt8VAmISiAItXE_tF")] - private static extern F9_Ret SwiftCallbackFunc9(delegate* unmanaged[Swift] func, void* funcContext); + [DllImport(SwiftLib, EntryPoint = "$s22SwiftCallbackAbiStress05swiftB6Func991fs6UInt64VAEs5Int64V_SuSfs6UInt16VAA6F99_S0Vs5UInt8VSfAMs4Int8VAA0J3_S1VAA0J3_S2VtXE_tF")] + private static extern ulong SwiftCallbackFunc99(delegate* unmanaged[Swift] func, void* funcContext); [UnmanagedCallersOnly(CallConvs = new Type[] { typeof(CallConvSwift) })] - private static F9_Ret SwiftCallbackFunc9Callback(sbyte a0, nint a1, short a2, long a3, double a4, double a5, nint a6, ushort a7, ushort a8, float a9, float a10, ushort a11, uint a12, short a13, int a14, int a15, ulong a16, short a17, long a18, nint a19, byte a20, ushort a21, short a22, nint a23, short a24, SwiftSelf self) + private static ulong SwiftCallbackFunc99Callback(long a0, nuint a1, float a2, ushort a3, F99_S0 a4, byte a5, float a6, byte a7, sbyte a8, F99_S1 a9, F99_S2 a10, SwiftSelf self) { try { - Assert.Equal((sbyte)17, a0); - Assert.Equal((nint)unchecked((nint)4720638462358523954), a1); - Assert.Equal((short)30631, a2); - Assert.Equal((long)8206569929240962953, a3); - Assert.Equal((double)1359667226908383, a4); - Assert.Equal((double)3776001892555053, a5); - Assert.Equal((nint)unchecked((nint)747160900180286726), a6); - Assert.Equal((ushort)12700, a7); - Assert.Equal((ushort)53813, a8); - Assert.Equal((float)7860389, a9); - Assert.Equal((float)1879743, a10); - Assert.Equal((ushort)61400, a11); - Assert.Equal((uint)1962814337, a12); - Assert.Equal((short)17992, a13); - Assert.Equal((int)677814589, a14); - Assert.Equal((int)1019483263, a15); - Assert.Equal((ulong)6326265259403184370, a16); - Assert.Equal((short)-14633, a17); - Assert.Equal((long)4127072498763789519, a18); - Assert.Equal((nint)unchecked((nint)4008108205305320386), a19); - Assert.Equal((byte)128, a20); - Assert.Equal((ushort)21189, a21); - Assert.Equal((short)32104, a22); - Assert.Equal((nint)unchecked((nint)384827814282870543), a23); - Assert.Equal((short)20647, a24); + Assert.Equal((long)1152281003884062246, a0); + Assert.Equal((nuint)unchecked((nuint)2482384127373829622), a1); + Assert.Equal((float)3361150, a2); + Assert.Equal((ushort)2121, a3); + Assert.Equal((nint)unchecked((nint)4484545590050696958), a4.F0); + Assert.Equal((uint)422528630, a4.F1); + Assert.Equal((int)1418346646, a4.F2); + Assert.Equal((uint)1281567856, a4.F3); + Assert.Equal((byte)223, a5); + Assert.Equal((float)1917656, a6); + Assert.Equal((byte)103, a7); + Assert.Equal((sbyte)-46, a8); + Assert.Equal((short)14554, a9.F0); + Assert.Equal((byte)68, a10.F0); } catch (Exception ex) { *(ExceptionDispatchInfo*)self.Value = ExceptionDispatchInfo.Capture(ex); } - return new F9_Ret(189282789, 114803850982111219, 4506415416389763390, 23584); + return 8220698022338840251; } [Fact] - public static void TestSwiftCallbackFunc9() + public static void TestSwiftCallbackFunc99() { - Console.Write("Running SwiftCallbackFunc9: "); + Console.Write("Running SwiftCallbackFunc99: "); ExceptionDispatchInfo ex = null; - F9_Ret val = SwiftCallbackFunc9(&SwiftCallbackFunc9Callback, &ex); + ulong val = SwiftCallbackFunc99(&SwiftCallbackFunc99Callback, &ex); if (ex != null) ex.Throw(); - Assert.Equal((uint)189282789, val.F0); - Assert.Equal((long)114803850982111219, val.F1); - Assert.Equal((ulong)4506415416389763390, val.F2); - Assert.Equal((ushort)23584, val.F3); + Assert.Equal((ulong)8220698022338840251, val); Console.WriteLine("OK"); } diff --git a/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.swift b/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.swift index 344fd65a5ed2a3..3089ae2e5e0978 100644 --- a/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.swift +++ b/src/tests/Interop/Swift/SwiftCallbackAbiStress/SwiftCallbackAbiStress.swift @@ -4,126 +4,3901 @@ import Foundation @frozen -public struct F0_Ret +public struct F0_S0 +{ + public let f0 : Double; + public let f1 : UInt32; + public let f2 : UInt16; +} + +@frozen +public struct F0_S1 +{ + public let f0 : UInt64; +} + +@frozen +public struct F0_S2 +{ + public let f0 : Float; +} + +public func swiftCallbackFunc0(f: (Int16, Int32, UInt64, UInt16, F0_S0, F0_S1, UInt8, F0_S2) -> Int32) -> Int32 { + return f(-17813, 318006528, 1195162122024233590, 60467, F0_S0(f0: 2239972725713766, f1: 1404066621, f2: 29895), F0_S1(f0: 7923486769850554262), 217, F0_S2(f0: 2497655)) +} + +@frozen +public struct F1_S0 { public let f0 : UInt16; - public let f1 : Float; - public let f2 : Int32; - public let f3 : UInt64; + public let f1 : UInt8; +} + +@frozen +public struct F1_S1 +{ + public let f0 : UInt8; + public let f1 : UInt64; + public let f2 : Int16; + public let f3 : Float; + public let f4 : Float; +} + +@frozen +public struct F1_S2_S0 +{ + public let f0 : UInt32; + public let f1 : Double; +} + +@frozen +public struct F1_S2 +{ + public let f0 : Int8; + public let f1 : UInt; + public let f2 : F1_S2_S0; + public let f3 : Int; +} + +@frozen +public struct F1_S3 +{ + public let f0 : UInt16; +} + +@frozen +public struct F1_S4 +{ + public let f0 : Int; +} + +@frozen +public struct F1_S5_S0 +{ + public let f0 : UInt32; +} + +@frozen +public struct F1_S5 +{ + public let f0 : F1_S5_S0; +} + +public func swiftCallbackFunc1(f: (Int64, Double, Int8, F1_S0, F1_S1, F1_S2, UInt8, Int8, Int64, F1_S3, UInt, F1_S4, F1_S5, Int) -> UInt8) -> UInt8 { + return f(7920511243396412395, 1396130721334528, -55, F1_S0(f0: 33758, f1: 103), F1_S1(f0: 201, f1: 7390774039746135757, f2: 14699, f3: 7235330, f4: 7189013), F1_S2(f0: 37, f1: 3310322731568932038, f2: F1_S2_S0(f0: 1100328218, f1: 1060779460203640), f3: 8325292022909418877), 137, 82, 1197537325837505041, F1_S3(f0: 46950), 8181828233622947597, F1_S4(f0: 1851182205030289056), F1_S5(f0: F1_S5_S0(f0: 1971014225)), 6437995407675718392) } -public func swiftCallbackFunc0(f: (Int16, Int32, UInt64, UInt16, Int64, Double, UInt32, UInt16, Int, UInt64) -> F0_Ret) -> F0_Ret { - return f(-17813, 318006528, 1195162122024233590, 60467, 4587464142261794085, 2686980744237725, 331986645, 56299, 6785053689615432643, 6358078381523084952) +@frozen +public struct F2_S0 +{ + public let f0 : Int32; + public let f1 : UInt; + public let f2 : Float; } -public func swiftCallbackFunc1(f: (Double, Int8, Int32, UInt16, UInt8, Double, UInt8, UInt64, Int16, Float, Float, UInt64, Int8) -> UInt) -> UInt { - return f(3867437130564654, -64, 31081182, 20316, 73, 3543740592144911, 250, 6680393408153342744, 23758, 7189013, 5438196, 3310322731568932038, 3) +@frozen +public struct F2_S1_S0 +{ + public let f0 : UInt16; } @frozen -public struct F2_Ret_S0 +public struct F2_S1 { public let f0 : Int64; + public let f1 : UInt16; + public let f2 : F2_S1_S0; + public let f3 : Int; + public let f4 : Double; +} + +@frozen +public struct F2_S2 +{ + public let f0 : Float; public let f1 : Int32; + public let f2 : UInt16; + public let f3 : Int8; } @frozen -public struct F2_Ret +public struct F2_S3_S0 { - public let f0 : F2_Ret_S0; - public let f1 : Int16; + public let f0 : Int8; +} + +@frozen +public struct F2_S3 +{ + public let f0 : F2_S3_S0; +} + +public func swiftCallbackFunc2(f: (F2_S0, F2_S1, F2_S2, Float, UInt64, F2_S3) -> Int8) -> Int8 { + return f(F2_S0(f0: 1860840185, f1: 5407074783834178811, f2: 6261766), F2_S1(f0: 4033972792915237065, f1: 22825, f2: F2_S1_S0(f0: 44574), f3: 4536911485304731630, f4: 4282944015147385), F2_S2(f0: 2579193, f1: 586252933, f2: 47002, f3: 71), 3225929, 3599444831393612282, F2_S3(f0: F2_S3_S0(f0: 13))) +} + +@frozen +public struct F3_S0_S0 +{ + public let f0 : UInt; +} + +@frozen +public struct F3_S0 +{ + public let f0 : F3_S0_S0; } -public func swiftCallbackFunc2(f: (UInt, UInt8) -> F2_Ret) -> F2_Ret { - return f(2153637757371267722, 150) +@frozen +public struct F3_S1 +{ + public let f0 : UInt32; + public let f1 : Int64; } @frozen -public struct F3_Ret_S0 +public struct F3_S2_S0 +{ + public let f0 : Int16; + public let f1 : UInt8; +} + +@frozen +public struct F3_S2 +{ + public let f0 : F3_S2_S0; + public let f1 : Int8; + public let f2 : UInt8; +} + +@frozen +public struct F3_S3 +{ + public let f0 : UInt64; + public let f1 : Int64; +} + +@frozen +public struct F3_S4 { public let f0 : Int16; - public let f1 : Int32; - public let f2 : UInt16; } @frozen public struct F3_Ret { - public let f0 : Int; - public let f1 : F3_Ret_S0; - public let f2 : UInt; - public let f3 : Int8; + public let f0 : UInt16; + public let f1 : UInt8; + public let f2 : UInt16; + public let f3 : Float; } -public func swiftCallbackFunc3(f: (UInt16, UInt, UInt, Int, Float, UInt16) -> F3_Ret) -> F3_Ret { - return f(45065, 8506742096411295359, 8619375465417625458, 5288917394772427257, 5678138, 33467) +public func swiftCallbackFunc3(f: (F3_S0, Float, UInt16, F3_S1, UInt16, Int32, F3_S2, Int, F3_S3, F3_S4) -> F3_Ret) -> F3_Ret { + return f(F3_S0(f0: F3_S0_S0(f0: 5610153900386943274)), 7736836, 31355, F3_S1(f0: 1159208572, f1: 2707818827451590538), 37580, 1453603418, F3_S2(f0: F3_S2_S0(f0: 699, f1: 46), f1: -125, f2: 92), 94557706586779834, F3_S3(f0: 2368015527878194540, f1: 5026404532195049271), F3_S4(f0: 21807)) +} + +@frozen +public struct F4_S0_S0 +{ + public let f0 : UInt32; +} + +@frozen +public struct F4_S0 +{ + public let f0 : F4_S0_S0; + public let f1 : Float; +} + +@frozen +public struct F4_Ret_S0 +{ + public let f0 : Int; } @frozen public struct F4_Ret { - public let f0 : UInt64; + public let f0 : Int32; + public let f1 : F4_Ret_S0; + public let f2 : Int; + public let f3 : Int16; + public let f4 : Int; + public let f5 : UInt32; +} + +public func swiftCallbackFunc4(f: (Double, F4_S0, UInt8, Int32, UInt32) -> F4_Ret) -> F4_Ret { + return f(4282972206489588, F4_S0(f0: F4_S0_S0(f0: 611688063), f1: 877466), 53, 965123506, 1301067653) +} + +@frozen +public struct F5_S0 +{ + public let f0 : UInt; public let f1 : UInt32; - public let f2 : UInt64; } -public func swiftCallbackFunc4(f: (Int64, UInt16, Int32, UInt16, Int, Double, UInt16, Float, Int32, UInt16, Int8, Float, UInt64, Int16, Double, Int8, Int8, Int32, Int, Int32, Int64, Int64) -> F4_Ret) -> F4_Ret { - return f(8771527078890676837, 18667, 224631333, 13819, 8888237425788084647, 2677321682649925, 50276, 2703201, 545337834, 11190, 112, 4053251, 7107857019164433129, -3092, 2176685406663423, 57, -61, 866840318, 5927291145767969522, 1818333546, 6272248211765159948, 6555966806846053216) +@frozen +public struct F5_S1_S0 +{ + public let f0 : Int; + public let f1 : UInt32; } @frozen -public struct F5_Ret +public struct F5_S1_S1 { - public let f0 : UInt64; - public let f1 : Int32; + public let f0 : Float; +} + +@frozen +public struct F5_S1 +{ + public let f0 : F5_S1_S0; + public let f1 : F5_S1_S1; +} + +@frozen +public struct F5_S2 +{ + public let f0 : Double; + public let f1 : Int8; public let f2 : Int; - public let f3 : Float; - public let f4 : Int16; - public let f5 : UInt64; } -public func swiftCallbackFunc5(f: (Int32, UInt16, UInt16, Int16, UInt8, Int8, UInt8, Int, UInt64, UInt64, Int64, Int16, Int16, Int64, UInt16, UInt8, UInt16) -> F5_Ret) -> F5_Ret { - return f(359602150, 51495, 37765, 29410, 95, -104, 32, 8530952551906271255, 706266487837805024, 707905209555595641, 8386588676727568762, -8624, 26113, 8389143657021522019, 13337, 229, 51876) +@frozen +public struct F5_S3 +{ + public let f0 : Int64; + public let f1 : Double; +} + +@frozen +public struct F5_S4 +{ + public let f0 : UInt16; +} + +@frozen +public struct F5_Ret +{ + public let f0 : Int16; + public let f1 : Int32; + public let f2 : Int32; + public let f3 : UInt64; + public let f4 : Int16; } -public func swiftCallbackFunc6(f: (Int32, UInt32, UInt64, Int32, Int8, Int, Int, Int16, Int, UInt32, UInt64, UInt64, Int64, UInt32) -> UInt16) -> UInt16 { - return f(743741783, 850236948, 5908745692727636656, 2106839818, 77, 291907785975160065, 3560129042279209151, -30568, 5730241035812482149, 18625011, 242340713355417257, 6962175160124965670, 2935089705514798822, 2051956645) +public func swiftCallbackFunc5(f: (UInt8, Int16, UInt64, UInt, UInt, UInt64, UInt8, F5_S0, Int8, Int8, F5_S1, F5_S2, F5_S3, Double, F5_S4, UInt16, Float, Float, UInt16) -> F5_Ret) -> F5_Ret { + return f(42, 18727, 3436765034579128495, 6305137336506323506, 6280137078630028944, 6252650621827449809, 129, F5_S0(f0: 6879980973426111678, f1: 1952654577), -34, 102, F5_S1(f0: F5_S1_S0(f0: 8389143657021522019, f1: 437030241), f1: F5_S1_S1(f0: 7522798)), F5_S2(f0: 523364011167530, f1: 16, f2: 3823439046574037759), F5_S3(f0: 3767260839267771462, f1: 1181031208183008), 2338830539621828, F5_S4(f0: 36276), 41286, 6683955, 6399917, 767) } @frozen -public struct F7_Ret_S0 +public struct F6_S0_S0 { - public let f0 : Int; + public let f0 : Float; } @frozen -public struct F7_Ret +public struct F6_S0 { public let f0 : Int8; public let f1 : Int8; - public let f2 : UInt8; - public let f3 : F7_Ret_S0; - public let f4 : UInt32; + public let f2 : Int32; + public let f3 : F6_S0_S0; +} + +@frozen +public struct F6_S1 +{ + public let f0 : Int32; + public let f1 : UInt64; + public let f2 : UInt64; + public let f3 : UInt32; } -public func swiftCallbackFunc7(f: (UInt64, UInt8, Int16, UInt) -> F7_Ret) -> F7_Ret { - return f(7625368278886567558, 70, 26780, 7739343395912136630) +@frozen +public struct F6_S2 +{ + public let f0 : Int64; + public let f1 : Int16; + public let f2 : Int8; } -public func swiftCallbackFunc8(f: (Float, UInt) -> UInt8) -> UInt8 { - return f(6278007, 1620979945874429615) +@frozen +public struct F6_S3 +{ + public let f0 : Float; } @frozen -public struct F9_Ret +public struct F6_Ret_S0 { - public let f0 : UInt32; + public let f0 : Int64; + public let f1 : UInt32; +} + +@frozen +public struct F6_Ret +{ + public let f0 : F6_Ret_S0; + public let f1 : UInt64; + public let f2 : Float; + public let f3 : Int8; +} + +public func swiftCallbackFunc6(f: (Float, F6_S0, Int64, Int8, UInt16, UInt, UInt16, UInt64, F6_S1, Int16, F6_S2, F6_S3, UInt16) -> F6_Ret) -> F6_Ret { + return f(2905241, F6_S0(f0: -27, f1: -77, f2: 1315779092, f3: F6_S0_S0(f0: 5373970)), 7022244764256789748, -110, 2074, 3560129042279209151, 2200, 5730241035812482149, F6_S1(f0: 18625011, f1: 242340713355417257, f2: 6962175160124965670, f3: 1983617839), -28374, F6_S2(f0: 6355748563312062178, f1: -23189, f2: 81), F6_S3(f0: 4547677), 6397) +} + +@frozen +public struct F7_S0 +{ + public let f0 : Float; public let f1 : Int64; - public let f2 : UInt64; - public let f3 : UInt16; + public let f2 : UInt; +} + +@frozen +public struct F7_S1 +{ + public let f0 : Int16; + public let f1 : UInt32; + public let f2 : UInt32; +} + +public func swiftCallbackFunc7(f: (Int64, UInt8, Double, UInt16, F7_S0, UInt8, Double, UInt32, F7_S1, Int32, Int32, Int, Int16, UInt16, Int, UInt64, UInt8, Int16) -> UInt16) -> UInt16 { + return f(7625368278886567558, 70, 2146971972122530, 54991, F7_S0(f0: 1072132, f1: 3890459003549150599, f2: 56791000421908673), 227, 3248250571953113, 1138780108, F7_S1(f0: -22670, f1: 1796712687, f2: 304251857), 1288765591, 1382721790, 6746417265635727373, -15600, 47575, 7200793040165597188, 2304985873826892392, 99, -9993) +} + +@frozen +public struct F8_S0 +{ + public let f0 : Int16; + public let f1 : Int16; + public let f2 : UInt; +} + +@frozen +public struct F8_S1 +{ + public let f0 : Int64; +} + +@frozen +public struct F8_Ret_S0 +{ + public let f0 : Int32; + public let f1 : UInt; + public let f2 : Int; +} + +@frozen +public struct F8_Ret +{ + public let f0 : Int64; + public let f1 : F8_Ret_S0; + public let f2 : Int; + public let f3 : UInt32; +} + +public func swiftCallbackFunc8(f: (F8_S0, F8_S1) -> F8_Ret) -> F8_Ret { + return f(F8_S0(f0: 16278, f1: -31563, f2: 2171308312325435543), F8_S1(f0: 8923668560896309835)) +} + +@frozen +public struct F9_S0_S0 +{ + public let f0 : UInt8; +} + +@frozen +public struct F9_S0 +{ + public let f0 : F9_S0_S0; + public let f1 : Int16; +} + +@frozen +public struct F9_S1_S0 +{ + public let f0 : Int64; + public let f1 : Int64; +} + +@frozen +public struct F9_S1 +{ + public let f0 : Int; + public let f1 : F9_S1_S0; + public let f2 : Float; +} + +@frozen +public struct F9_S2 +{ + public let f0 : UInt64; + public let f1 : Double; + public let f2 : Int16; + public let f3 : Int8; +} + +@frozen +public struct F9_S3_S0_S0 +{ + public let f0 : UInt64; +} + +@frozen +public struct F9_S3_S0 +{ + public let f0 : F9_S3_S0_S0; +} + +@frozen +public struct F9_S3 +{ + public let f0 : Int8; + public let f1 : F9_S3_S0; +} + +@frozen +public struct F9_S4_S0 +{ + public let f0 : UInt64; +} + +@frozen +public struct F9_S4 +{ + public let f0 : F9_S4_S0; + public let f1 : Int8; +} + +@frozen +public struct F9_S5_S0 +{ + public let f0 : UInt32; +} + +@frozen +public struct F9_S5 +{ + public let f0 : UInt32; + public let f1 : F9_S5_S0; +} + +@frozen +public struct F9_S6 +{ + public let f0 : Double; +} + +public func swiftCallbackFunc9(f: (Int8, UInt8, Int64, F9_S0, F9_S1, F9_S2, Double, F9_S3, F9_S4, Double, F9_S5, F9_S6) -> UInt16) -> UInt16 { + return f(17, 104, 8922699691031703191, F9_S0(f0: F9_S0_S0(f0: 123), f1: 31706), F9_S1(f0: 1804058604961822948, f1: F9_S1_S0(f0: 8772179036715198777, f1: 3320511540592563328), f2: 679540), F9_S2(f0: 8642590829466497926, f1: 4116322155252965, f2: 17992, f3: -48), 414017537937894, F9_S3(f0: 47, f1: F9_S3_S0(f0: F9_S3_S0_S0(f0: 7576380984563129085))), F9_S4(f0: F9_S4_S0(f0: 1356827400304742803), f1: -17), 4458031413035521, F9_S5(f0: 352075098, f1: F9_S5_S0(f0: 1840980094)), F9_S6(f0: 396957263013930)) +} + +@frozen +public struct F10_Ret +{ + public let f0 : Int64; + public let f1 : UInt32; + public let f2 : UInt16; + public let f3 : UInt32; +} + +public func swiftCallbackFunc10(f: (Int16) -> F10_Ret) -> F10_Ret { + return f(-7168) +} + +@frozen +public struct F11_S0_S0 +{ + public let f0 : Int8; +} + +@frozen +public struct F11_S0 +{ + public let f0 : UInt32; + public let f1 : F11_S0_S0; + public let f2 : UInt; + public let f3 : Int32; + public let f4 : Int64; +} + +@frozen +public struct F11_S1_S0 +{ + public let f0 : UInt16; +} + +@frozen +public struct F11_S1 +{ + public let f0 : F11_S1_S0; + public let f1 : Int16; + public let f2 : UInt32; + public let f3 : Int16; +} + +@frozen +public struct F11_S2 +{ + public let f0 : UInt8; +} + +@frozen +public struct F11_Ret +{ + public let f0 : Int16; + public let f1 : Int16; + public let f2 : UInt8; + public let f3 : Int64; +} + +public func swiftCallbackFunc11(f: (UInt32, UInt, UInt64, Int16, F11_S0, Float, Int8, UInt16, F11_S1, UInt32, Int64, UInt32, F11_S2) -> F11_Ret) -> F11_Ret { + return f(454751144, 1696592254558667577, 5831587230944972245, 15352, F11_S0(f0: 1306601347, f1: F11_S0_S0(f0: 123), f2: 3064471520018434938, f3: 272956246, f4: 3683518307106722029), 5606122, -126, 50801, F11_S1(f0: F11_S1_S0(f0: 63467), f1: -31828, f2: 2117176776, f3: -27265), 1879606687, 4981244336430926707, 1159924856, F11_S2(f0: 29)) +} + +@frozen +public struct F12_S0 +{ + public let f0 : UInt64; + public let f1 : Int8; +} + +@frozen +public struct F12_S1_S0_S0 +{ + public let f0 : UInt64; +} + +@frozen +public struct F12_S1_S0 +{ + public let f0 : F12_S1_S0_S0; +} + +@frozen +public struct F12_S1 +{ + public let f0 : UInt16; + public let f1 : UInt32; + public let f2 : F12_S1_S0; +} + +@frozen +public struct F12_Ret +{ + public let f0 : UInt64; + public let f1 : Int; +} + +public func swiftCallbackFunc12(f: (F12_S0, Int16, UInt64, F12_S1, Int8) -> F12_Ret) -> F12_Ret { + return f(F12_S0(f0: 3236871137735400659, f1: -123), -22828, 2132557792366642035, F12_S1(f0: 42520, f1: 879349060, f2: F12_S1_S0(f0: F12_S1_S0_S0(f0: 5694370973277919380))), -75) +} + +@frozen +public struct F13_S0_S0 +{ + public let f0 : Int64; + public let f1 : Int64; +} + +@frozen +public struct F13_S0 +{ + public let f0 : F13_S0_S0; + public let f1 : Float; + public let f2 : Int16; +} + +@frozen +public struct F13_S1 +{ + public let f0 : Int; + public let f1 : UInt64; +} + +@frozen +public struct F13_S2_S0 +{ + public let f0 : UInt8; +} + +@frozen +public struct F13_S2 +{ + public let f0 : F13_S2_S0; + public let f1 : Double; +} + +@frozen +public struct F13_S3 +{ + public let f0 : Float; + public let f1 : Int8; +} + +@frozen +public struct F13_S4 +{ + public let f0 : Int; +} + +public func swiftCallbackFunc13(f: (F13_S0, Int32, Int, UInt16, UInt, F13_S1, F13_S2, Int, Double, Int8, Float, Int, F13_S3, UInt, F13_S4) -> Double) -> Double { + return f(F13_S0(f0: F13_S0_S0(f0: 9003727031576598067, f1: 8527798284445940986), f1: 3585628, f2: -12520), 1510815104, 5883331525294982326, 60738, 5291799143932627546, F13_S1(f0: 1949276559361384602, f1: 876048527237138968), F13_S2(f0: F13_S2_S0(f0: 67), f1: 2455575228564859), 2321408806345977320, 12750323283778, 46, 6774339, 5121910967292140178, F13_S3(f0: 8254279, f1: -7), 7533347207018595125, F13_S4(f0: 6605448167191082938)) +} + +@frozen +public struct F14_S0 +{ + public let f0 : Int8; + public let f1 : Float; + public let f2 : UInt16; +} + +@frozen +public struct F14_S1 +{ + public let f0 : UInt64; + public let f1 : UInt64; +} + +public func swiftCallbackFunc14(f: (Int64, F14_S0, Int8, UInt64, F14_S1, Int) -> Int64) -> Int64 { + return f(5547219684656041875, F14_S0(f0: -39, f1: 5768837, f2: 53063), -102, 5745438709817040873, F14_S1(f0: 2178706453119907411, f1: 4424726479787355131), 5693881223150438553) +} + +@frozen +public struct F15_S0 +{ + public let f0 : UInt32; +} + +@frozen +public struct F15_S1 +{ + public let f0 : Int; + public let f1 : UInt32; + public let f2 : UInt8; + public let f3 : Int16; +} + +@frozen +public struct F15_S2 +{ + public let f0 : Int8; + public let f1 : UInt64; + public let f2 : Int64; + public let f3 : UInt8; +} + +@frozen +public struct F15_S3 +{ + public let f0 : Double; +} + +public func swiftCallbackFunc15(f: (UInt8, UInt16, UInt64, UInt64, Int8, UInt, Double, Float, Int, F15_S0, F15_S1, UInt16, F15_S2, UInt8, F15_S3) -> Int) -> Int { + return f(0, 31081, 8814881608835743979, 4283853687332682681, 80, 7895994601265649979, 1855521542692398, 3235683, 215122646177738904, F15_S0(f0: 2044750195), F15_S1(f0: 1772412898183620625, f1: 131256973, f2: 153, f3: 25281), 50965, F15_S2(f0: -83, f1: 7751486385861474282, f2: 3744400479301818340, f3: 150), 179, F15_S3(f0: 3108143600787174)) +} + +@frozen +public struct F16_S0 +{ + public let f0 : Int8; + public let f1 : Int32; + public let f2 : UInt16; + public let f3 : UInt16; + public let f4 : UInt32; +} + +@frozen +public struct F16_S1 +{ + public let f0 : UInt16; + public let f1 : Int8; + public let f2 : UInt8; + public let f3 : Int; + public let f4 : Int; +} + +@frozen +public struct F16_S2_S0 +{ + public let f0 : Int8; +} + +@frozen +public struct F16_S2 +{ + public let f0 : Int32; + public let f1 : Int32; + public let f2 : UInt32; + public let f3 : UInt8; + public let f4 : F16_S2_S0; +} + +@frozen +public struct F16_S3 +{ + public let f0 : Int16; + public let f1 : Double; + public let f2 : Double; + public let f3 : Int32; +} + +public func swiftCallbackFunc16(f: (F16_S0, Int16, Float, F16_S1, F16_S2, UInt64, F16_S3, UInt) -> Int8) -> Int8 { + return f(F16_S0(f0: -59, f1: 1181591186, f2: 44834, f3: 28664, f4: 404461767), 2482, 2997348, F16_S1(f0: 22423, f1: -106, f2: 182, f3: 3784074551275084420, f4: 7092934571108982079), F16_S2(f0: 1835134709, f1: 246067261, f2: 1986526591, f3: 24, f4: F16_S2_S0(f0: -112)), 1465053746911704089, F16_S3(f0: -27636, f1: 1896887612303356, f2: 4263157082840190, f3: 774653659), 3755775782607884861) +} + +@frozen +public struct F17_S0 +{ + public let f0 : Int32; + public let f1 : UInt; +} + +@frozen +public struct F17_S1_S0 +{ + public let f0 : Double; + public let f1 : UInt32; +} + +@frozen +public struct F17_S1 +{ + public let f0 : F17_S1_S0; + public let f1 : Int32; + public let f2 : UInt8; +} + +@frozen +public struct F17_S2 +{ + public let f0 : UInt32; +} + +public func swiftCallbackFunc17(f: (UInt32, F17_S0, F17_S1, Double, UInt64, F17_S2) -> Double) -> Double { + return f(201081002, F17_S0(f0: 2018751226, f1: 8488544433072104028), F17_S1(f0: F17_S1_S0(f0: 1190765430157980, f1: 70252071), f1: 1297775609, f2: 160), 4290084351352688, 4738339757002694731, F17_S2(f0: 1829312773)) +} + +@frozen +public struct F18_S0 +{ + public let f0 : Int8; +} + +@frozen +public struct F18_S1 +{ + public let f0 : UInt16; + public let f1 : Int16; + public let f2 : Double; + public let f3 : UInt; +} + +@frozen +public struct F18_S2 +{ + public let f0 : Int; +} + +@frozen +public struct F18_Ret_S0 +{ + public let f0 : Int16; +} + +@frozen +public struct F18_Ret +{ + public let f0 : F18_Ret_S0; +} + +public func swiftCallbackFunc18(f: (F18_S0, F18_S1, F18_S2, UInt, UInt32, Int64, Int16, Double) -> F18_Ret) -> F18_Ret { + return f(F18_S0(f0: 106), F18_S1(f0: 21619, f1: -4350, f2: 3457288266203248, f3: 9020447812661292883), F18_S2(f0: 2317132584983719004), 7379425918918939512, 2055208746, 1042861174364145790, 28457, 1799004152435515) +} + +@frozen +public struct F19_S0 +{ + public let f0 : Int16; + public let f1 : Int8; + public let f2 : Float; +} + +@frozen +public struct F19_S1 +{ + public let f0 : Int64; + public let f1 : UInt16; +} + +@frozen +public struct F19_S2 +{ + public let f0 : UInt64; + public let f1 : Int64; +} + +@frozen +public struct F19_S3 +{ + public let f0 : UInt32; + public let f1 : Int32; +} + +@frozen +public struct F19_Ret_S0 +{ + public let f0 : Int64; +} + +@frozen +public struct F19_Ret +{ + public let f0 : UInt32; + public let f1 : Int64; + public let f2 : UInt16; + public let f3 : F19_Ret_S0; + public let f4 : Double; + public let f5 : Double; + public let f6 : Double; +} + +public func swiftCallbackFunc19(f: (Int64, UInt8, F19_S0, Int, F19_S1, Int32, Int32, UInt, UInt64, F19_S2, UInt16, F19_S3, Int8, Int64) -> F19_Ret) -> F19_Ret { + return f(7456120134117592143, 114, F19_S0(f0: -7583, f1: 97, f2: 2768322), 3605245176125291560, F19_S1(f0: 4445885313084714470, f1: 15810), 1179699879, 109603412, 6521628547431964799, 7687430644226018854, F19_S2(f0: 8464855230956039883, f1: 861462819289140037), 26519, F19_S3(f0: 1864602741, f1: 397176384), 81, 4909173176891211442) +} + +@frozen +public struct F20_S0_S0 +{ + public let f0 : UInt16; +} + +@frozen +public struct F20_S0 +{ + public let f0 : Int16; + public let f1 : UInt; + public let f2 : F20_S0_S0; +} + +@frozen +public struct F20_S1_S0 +{ + public let f0 : Float; +} + +@frozen +public struct F20_S1 +{ + public let f0 : Int64; + public let f1 : UInt; + public let f2 : F20_S1_S0; + public let f3 : Int64; + public let f4 : Int32; +} + +@frozen +public struct F20_S2 +{ + public let f0 : UInt32; +} + +@frozen +public struct F20_Ret +{ + public let f0 : UInt16; + public let f1 : UInt16; + public let f2 : Double; + public let f3 : Int16; + public let f4 : Double; +} + +public func swiftCallbackFunc20(f: (F20_S0, F20_S1, Float, Float, Int8, F20_S2, Float) -> F20_Ret) -> F20_Ret { + return f(F20_S0(f0: 28858, f1: 7024100299344418039, f2: F20_S0_S0(f0: 13025)), F20_S1(f0: 7900431324553135989, f1: 8131425055682506706, f2: F20_S1_S0(f0: 3884322), f3: 605453501265278638, f4: 353756684), 622319, 1401604, -101, F20_S2(f0: 1355570413), 2912776) +} + +@frozen +public struct F21_S0 +{ + public let f0 : Double; + public let f1 : UInt64; +} + +@frozen +public struct F21_S1 +{ + public let f0 : UInt16; +} + +@frozen +public struct F21_Ret +{ + public let f0 : UInt16; + public let f1 : UInt32; + public let f2 : Int64; +} + +public func swiftCallbackFunc21(f: (Int32, Int16, F21_S0, Int32, F21_S1, Int64, UInt32, Int64, UInt8, UInt16) -> F21_Ret) -> F21_Ret { + return f(256017319, 14555, F21_S0(f0: 2102091966108033, f1: 8617538752301505079), 834677431, F21_S1(f0: 7043), 7166819734655141128, 965538086, 3827752442102685645, 110, 33646) +} + +@frozen +public struct F22_S0 +{ + public let f0 : Int; + public let f1 : Float; + public let f2 : Double; +} + +@frozen +public struct F22_S1 +{ + public let f0 : UInt; +} + +@frozen +public struct F22_S2 +{ + public let f0 : Int32; + public let f1 : Double; + public let f2 : Float; + public let f3 : Int16; + public let f4 : UInt16; +} + +@frozen +public struct F22_S3 +{ + public let f0 : Int64; + public let f1 : UInt16; +} + +@frozen +public struct F22_S4 +{ + public let f0 : Double; + public let f1 : UInt16; +} + +@frozen +public struct F22_S5 +{ + public let f0 : UInt32; + public let f1 : Int16; +} + +@frozen +public struct F22_S6 +{ + public let f0 : Float; +} + +@frozen +public struct F22_Ret +{ + public let f0 : UInt16; + public let f1 : Int16; + public let f2 : UInt; +} + +public func swiftCallbackFunc22(f: (Int32, F22_S0, F22_S1, F22_S2, F22_S3, Int8, F22_S4, UInt8, UInt16, Int64, F22_S5, Int64, Float, F22_S6, UInt16) -> F22_Ret) -> F22_Ret { + return f(640156952, F22_S0(f0: 824774470287401457, f1: 6163704, f2: 54328782764685), F22_S1(f0: 1679730195865415747), F22_S2(f0: 1462995665, f1: 2554087365600344, f2: 8193295, f3: 16765, f4: 45388), F22_S3(f0: 5560492364570389430, f1: 48308), 71, F22_S4(f0: 1639169280741045, f1: 12045), 217, 62917, 1465918945905384332, F22_S5(f0: 1364750179, f1: 3311), 9003480567517966914, 2157327, F22_S6(f0: 6647392), 1760) +} + +@frozen +public struct F23_S0 +{ + public let f0 : Int; +} + +@frozen +public struct F23_S1 +{ + public let f0 : Int; +} + +public func swiftCallbackFunc23(f: (UInt, UInt8, Int8, UInt8, UInt8, F23_S0, UInt, F23_S1, Double) -> Double) -> Double { + return f(5779410841248940897, 192, -128, 133, 20, F23_S0(f0: 2959916071636885436), 3651155214497129159, F23_S1(f0: 8141565342203061885), 1465425469608034) +} + +@frozen +public struct F24_S0 +{ + public let f0 : Int8; + public let f1 : UInt8; + public let f2 : UInt64; + public let f3 : UInt32; +} + +@frozen +public struct F24_S1 +{ + public let f0 : UInt16; +} + +@frozen +public struct F24_S2_S0 +{ + public let f0 : UInt16; + public let f1 : UInt32; +} + +@frozen +public struct F24_S2_S1 +{ + public let f0 : Int64; +} + +@frozen +public struct F24_S2 +{ + public let f0 : Int; + public let f1 : UInt32; + public let f2 : F24_S2_S0; + public let f3 : F24_S2_S1; +} + +@frozen +public struct F24_S3 +{ + public let f0 : Int16; + public let f1 : Float; + public let f2 : Int64; +} + +@frozen +public struct F24_S4 +{ + public let f0 : UInt8; +} + +public func swiftCallbackFunc24(f: (Int32, UInt, F24_S0, UInt16, F24_S1, Int8, F24_S2, UInt64, UInt64, F24_S3, Double, F24_S4) -> Float) -> Float { + return f(1710754874, 6447433131978039331, F24_S0(f0: -92, f1: 181, f2: 3710374263631495948, f3: 257210428), 6631, F24_S1(f0: 2303), 15, F24_S2(f0: 2509049432824972381, f1: 616918672, f2: F24_S2_S0(f0: 50635, f1: 1337844540), f3: F24_S2_S1(f0: 335964796567786281)), 1114365571136806382, 8988425145801188208, F24_S3(f0: 31969, f1: 3008861, f2: 5466306080595269107), 2027780227887952, F24_S4(f0: 234)) +} + +@frozen +public struct F25_S0 +{ + public let f0 : UInt; +} + +@frozen +public struct F25_S1 +{ + public let f0 : Float; + public let f1 : Int8; + public let f2 : Float; + public let f3 : Int; +} + +@frozen +public struct F25_S2 +{ + public let f0 : UInt; + public let f1 : UInt; + public let f2 : Int64; + public let f3 : UInt8; +} + +@frozen +public struct F25_S3 +{ + public let f0 : Float; +} + +@frozen +public struct F25_S4 +{ + public let f0 : Int8; +} + +@frozen +public struct F25_Ret +{ + public let f0 : UInt64; + public let f1 : Int64; + public let f2 : UInt8; + public let f3 : UInt16; +} + +public func swiftCallbackFunc25(f: (F25_S0, UInt16, UInt, F25_S1, Int16, F25_S2, UInt64, UInt64, UInt64, F25_S3, F25_S4) -> F25_Ret) -> F25_Ret { + return f(F25_S0(f0: 6077761381429658786), 2300, 3498354181807010234, F25_S1(f0: 5360721, f1: -40, f2: 109485, f3: 2311625789899959825), -28395, F25_S2(f0: 8729509817732080529, f1: 860365359368130822, f2: 7498894262834346040, f3: 218), 961687210282504701, 7184177441364400868, 8389319500274436977, F25_S3(f0: 4437173), F25_S4(f0: -107)) +} + +@frozen +public struct F26_S0 +{ + public let f0 : Int8; + public let f1 : Int; + public let f2 : UInt8; + public let f3 : UInt8; +} + +@frozen +public struct F26_S1_S0 +{ + public let f0 : UInt64; +} + +@frozen +public struct F26_S1 +{ + public let f0 : Int8; + public let f1 : Int32; + public let f2 : Int16; + public let f3 : F26_S1_S0; +} + +@frozen +public struct F26_S2 +{ + public let f0 : Int64; +} + +@frozen +public struct F26_S3 +{ + public let f0 : UInt8; +} + +@frozen +public struct F26_Ret +{ + public let f0 : UInt; + public let f1 : UInt8; +} + +public func swiftCallbackFunc26(f: (Int8, UInt8, UInt32, F26_S0, F26_S1, F26_S2, F26_S3) -> F26_Ret) -> F26_Ret { + return f(-16, 220, 72386567, F26_S0(f0: -33, f1: 6488877286424796715, f2: 143, f3: 74), F26_S1(f0: 104, f1: 1719453315, f2: 20771, f3: F26_S1_S0(f0: 3636117595999837800)), F26_S2(f0: 2279530426119665839), F26_S3(f0: 207)) +} + +@frozen +public struct F27_S0 +{ + public let f0 : Int16; +} + +@frozen +public struct F27_S1_S0 +{ + public let f0 : UInt16; + public let f1 : Int8; +} + +@frozen +public struct F27_S1 +{ + public let f0 : Int64; + public let f1 : F27_S1_S0; + public let f2 : Float; +} + +@frozen +public struct F27_S2 +{ + public let f0 : UInt64; + public let f1 : Int8; + public let f2 : UInt32; + public let f3 : Int64; +} + +@frozen +public struct F27_S3_S0 +{ + public let f0 : UInt16; +} + +@frozen +public struct F27_S3 +{ + public let f0 : F27_S3_S0; +} + +public func swiftCallbackFunc27(f: (UInt64, UInt8, F27_S0, UInt8, UInt8, F27_S1, Int32, F27_S2, Int, UInt32, F27_S3) -> Float) -> Float { + return f(4847421047018330189, 214, F27_S0(f0: 31313), 207, 174, F27_S1(f0: 4476120319602257660, f1: F27_S1_S0(f0: 26662, f1: -55), f2: 70666), 1340306103, F27_S2(f0: 2772939788297637999, f1: -65, f2: 7500441, f3: 4926907273817562134), 5862689255099071258, 1077270996, F27_S3(f0: F27_S3_S0(f0: 35167))) +} + +@frozen +public struct F28_S0 +{ + public let f0 : UInt64; + public let f1 : Int8; +} + +@frozen +public struct F28_S1 +{ + public let f0 : Int64; + public let f1 : UInt; + public let f2 : Int; + public let f3 : Int32; +} + +@frozen +public struct F28_S2 +{ + public let f0 : Int; +} + +@frozen +public struct F28_S3 +{ + public let f0 : Int64; +} + +@frozen +public struct F28_Ret_S0 +{ + public let f0 : Float; +} + +@frozen +public struct F28_Ret +{ + public let f0 : F28_Ret_S0; + public let f1 : UInt16; +} + +public func swiftCallbackFunc28(f: (UInt32, UInt16, Int8, Int8, UInt16, Float, F28_S0, Double, UInt64, F28_S1, F28_S2, F28_S3) -> F28_Ret) -> F28_Ret { + return f(893827094, 38017, -90, -1, 16109, 5844449, F28_S0(f0: 176269147098539470, f1: 23), 1431426259441210, 6103261251702315645, F28_S1(f0: 3776818122826483419, f1: 9181420263296840471, f2: 3281861424961082542, f3: 1442905253), F28_S2(f0: 8760009193798370900), F28_S3(f0: 7119917900929398683)) +} + +@frozen +public struct F29_S0 +{ + public let f0 : UInt8; + public let f1 : Double; + public let f2 : UInt16; +} + +@frozen +public struct F29_S1 +{ + public let f0 : UInt32; + public let f1 : Int; + public let f2 : UInt64; + public let f3 : UInt32; +} + +@frozen +public struct F29_S2 +{ + public let f0 : Int32; +} + +@frozen +public struct F29_S3 +{ + public let f0 : UInt32; + public let f1 : UInt32; + public let f2 : Float; +} + +@frozen +public struct F29_S4 +{ + public let f0 : Int32; +} + +@frozen +public struct F29_Ret_S0 +{ + public let f0 : Int; + public let f1 : UInt64; +} + +@frozen +public struct F29_Ret +{ + public let f0 : UInt; + public let f1 : UInt; + public let f2 : UInt; + public let f3 : F29_Ret_S0; + public let f4 : UInt64; + public let f5 : UInt32; +} + +public func swiftCallbackFunc29(f: (F29_S0, Int, UInt64, UInt8, Int64, UInt8, Int, F29_S1, Int32, Int8, UInt8, UInt64, F29_S2, F29_S3, Int16, F29_S4, UInt32) -> F29_Ret) -> F29_Ret { + return f(F29_S0(f0: 152, f1: 737900189383874, f2: 33674), 5162040247631126074, 6524156301721885895, 129, 6661424933974053497, 145, 7521422786615537370, F29_S1(f0: 1361601345, f1: 3366726213840694614, f2: 7767610514138029164, f3: 1266864987), 1115803878, 5, 80, 2041754562738600205, F29_S2(f0: 1492686870), F29_S3(f0: 142491811, f1: 1644962309, f2: 1905811), -3985, F29_S4(f0: 1921386549), 1510666400) +} + +@frozen +public struct F30_S0 +{ + public let f0 : UInt16; + public let f1 : Int16; + public let f2 : Int16; + public let f3 : Int8; +} + +@frozen +public struct F30_S1 +{ + public let f0 : UInt16; + public let f1 : UInt; +} + +@frozen +public struct F30_S2 +{ + public let f0 : Int64; + public let f1 : Int8; + public let f2 : UInt16; +} + +@frozen +public struct F30_S3 +{ + public let f0 : Int8; +} + +public func swiftCallbackFunc30(f: (F30_S0, F30_S1, F30_S2, F30_S3, Int) -> Float) -> Float { + return f(F30_S0(f0: 50723, f1: 19689, f2: -6469, f3: 83), F30_S1(f0: 51238, f1: 5879147675377398012), F30_S2(f0: 7909999288286190848, f1: -99, f2: 61385), F30_S3(f0: 48), 2980085298293056148) +} + +@frozen +public struct F31_S0 +{ + public let f0 : Int32; + public let f1 : UInt64; + public let f2 : UInt; +} + +@frozen +public struct F31_Ret_S0 +{ + public let f0 : UInt32; + public let f1 : Float; + public let f2 : UInt16; + public let f3 : Int16; + public let f4 : Float; +} + +@frozen +public struct F31_Ret +{ + public let f0 : F31_Ret_S0; + public let f1 : UInt16; +} + +public func swiftCallbackFunc31(f: (F31_S0, Double) -> F31_Ret) -> F31_Ret { + return f(F31_S0(f0: 1072945099, f1: 5760996810500287322, f2: 3952909367135409979), 2860786541632685) +} + +@frozen +public struct F32_Ret +{ + public let f0 : UInt; + public let f1 : Double; + public let f2 : Int; +} + +public func swiftCallbackFunc32(f: (UInt16, Int16) -> F32_Ret) -> F32_Ret { + return f(21020, 7462) +} + +@frozen +public struct F33_S0 +{ + public let f0 : Int16; + public let f1 : UInt64; +} + +@frozen +public struct F33_S1_S0 +{ + public let f0 : Int16; +} + +@frozen +public struct F33_S1 +{ + public let f0 : F33_S1_S0; + public let f1 : UInt32; + public let f2 : UInt; +} + +@frozen +public struct F33_S2 +{ + public let f0 : UInt32; + public let f1 : UInt64; + public let f2 : Int8; + public let f3 : Int8; + public let f4 : UInt; +} + +@frozen +public struct F33_S3_S0_S0 +{ + public let f0 : Int16; +} + +@frozen +public struct F33_S3_S0 +{ + public let f0 : F33_S3_S0_S0; +} + +@frozen +public struct F33_S3 +{ + public let f0 : F33_S3_S0; +} + +public func swiftCallbackFunc33(f: (F33_S0, Float, F33_S1, UInt32, Int, Int8, Int8, Float, UInt8, Float, Int8, F33_S2, Int, F33_S3, Int, UInt32) -> UInt) -> UInt { + return f(F33_S0(f0: -23471, f1: 2736941806609505888), 6930550, F33_S1(f0: F33_S1_S0(f0: 32476), f1: 165441961, f2: 3890227499323387948), 591524870, 1668420058132495503, -67, 94, 3180786, 42, 7674952, 43, F33_S2(f0: 771356149, f1: 3611576949210389997, f2: -15, f3: 7, f4: 2577587324978560192), 8266150294848599489, F33_S3(f0: F33_S3_S0(f0: F33_S3_S0_S0(f0: 9216))), 710302565025364450, 1060812904) +} + +@frozen +public struct F34_S0_S0 +{ + public let f0 : UInt32; +} + +@frozen +public struct F34_S0 +{ + public let f0 : F34_S0_S0; + public let f1 : UInt; +} + +public func swiftCallbackFunc34(f: (UInt32, F34_S0, UInt, Int16) -> UInt16) -> UInt16 { + return f(2068009847, F34_S0(f0: F34_S0_S0(f0: 845123292), f1: 5148244462913472487), 8632568386462910655, 7058) +} + +@frozen +public struct F35_S0_S0_S0 +{ + public let f0 : Int32; +} + +@frozen +public struct F35_S0_S0 +{ + public let f0 : Int64; + public let f1 : F35_S0_S0_S0; +} + +@frozen +public struct F35_S0_S1 +{ + public let f0 : Double; +} + +@frozen +public struct F35_S0 +{ + public let f0 : F35_S0_S0; + public let f1 : Int32; + public let f2 : F35_S0_S1; + public let f3 : Int; +} + +@frozen +public struct F35_S1 +{ + public let f0 : UInt16; +} + +@frozen +public struct F35_S2_S0 +{ + public let f0 : Double; +} + +@frozen +public struct F35_S2 +{ + public let f0 : F35_S2_S0; +} + +public func swiftCallbackFunc35(f: (UInt8, Int8, Float, Int64, Int, F35_S0, F35_S1, F35_S2) -> UInt64) -> UInt64 { + return f(182, -16, 7763558, 5905028570860904693, 5991001624972063224, F35_S0(f0: F35_S0_S0(f0: 6663912001709962059, f1: F35_S0_S0_S0(f0: 1843939591)), f1: 1095170337, f2: F35_S0_S1(f0: 3908756332193409), f3: 8246190362462442203), F35_S1(f0: 52167), F35_S2(f0: F35_S2_S0(f0: 283499999631068))) +} + +@frozen +public struct F36_S0 +{ + public let f0 : UInt32; + public let f1 : Int64; + public let f2 : UInt8; + public let f3 : UInt; +} + +public func swiftCallbackFunc36(f: (UInt, Double, UInt, UInt8, Int64, F36_S0, Int8) -> Int) -> Int { + return f(5079603407518207003, 2365862518115571, 6495651757722767835, 46, 1550138390178394449, F36_S0(f0: 1858960269, f1: 1925263848394986294, f2: 217, f3: 8520779488644482307), -83) +} + +@frozen +public struct F37_S0_S0 +{ + public let f0 : Int; +} + +@frozen +public struct F37_S0 +{ + public let f0 : UInt; + public let f1 : UInt32; + public let f2 : F37_S0_S0; + public let f3 : Float; +} + +@frozen +public struct F37_S1 +{ + public let f0 : UInt; + public let f1 : UInt32; +} + +@frozen +public struct F37_S2 +{ + public let f0 : UInt16; +} + +@frozen +public struct F37_Ret +{ + public let f0 : Float; + public let f1 : UInt8; + public let f2 : Int16; + public let f3 : UInt64; +} + +public func swiftCallbackFunc37(f: (UInt64, F37_S0, Double, UInt16, F37_S1, F37_S2) -> F37_Ret) -> F37_Ret { + return f(1623104856688575867, F37_S0(f0: 3785544303342575322, f1: 717682682, f2: F37_S0_S0(f0: 2674933748436691896), f3: 3211458), 996705046384579, 8394, F37_S1(f0: 1048947722954084863, f1: 252415487), F37_S2(f0: 3664)) +} + +@frozen +public struct F38_S0_S0 +{ + public let f0 : Int; + public let f1 : Float; +} + +@frozen +public struct F38_S0 +{ + public let f0 : F38_S0_S0; + public let f1 : UInt16; + public let f2 : Int32; + public let f3 : Float; +} + +@frozen +public struct F38_S1 +{ + public let f0 : Int16; + public let f1 : Int32; + public let f2 : UInt32; +} + +public func swiftCallbackFunc38(f: (F38_S0, F38_S1, Double, Int16, Int8, UInt32, Int16, Float, Int, Float, UInt32, UInt8, Double, Int8) -> Double) -> Double { + return f(F38_S0(f0: F38_S0_S0(f0: 7389960750529773276, f1: 4749108), f1: 54323, f2: 634649910, f3: 83587), F38_S1(f0: -15547, f1: 1747384081, f2: 851987981), 3543874366683681, 5045, -32, 2084540698, 25583, 3158067, 1655263182833369283, 829404, 1888859844, 153, 222366180309763, 61) +} + +@frozen +public struct F39_S0_S0 +{ + public let f0 : Int16; +} + +@frozen +public struct F39_S0_S1 +{ + public let f0 : UInt16; +} + +@frozen +public struct F39_S0 +{ + public let f0 : F39_S0_S0; + public let f1 : Int32; + public let f2 : F39_S0_S1; + public let f3 : UInt; +} + +@frozen +public struct F39_S1 +{ + public let f0 : UInt16; + public let f1 : UInt8; + public let f2 : Float; + public let f3 : Int64; +} + +@frozen +public struct F39_S2 +{ + public let f0 : Int32; + public let f1 : Float; +} + +@frozen +public struct F39_S3 +{ + public let f0 : UInt32; + public let f1 : Int; + public let f2 : Int; +} + +public func swiftCallbackFunc39(f: (F39_S0, UInt, UInt32, Double, F39_S1, F39_S2, Int8, F39_S3, Int32, UInt64, UInt8) -> Int) -> Int { + return f(F39_S0(f0: F39_S0_S0(f0: -31212), f1: 1623216479, f2: F39_S0_S1(f0: 7181), f3: 8643545152918150186), 799631211988519637, 94381581, 761127371030426, F39_S1(f0: 417, f1: 85, f2: 1543931, f3: 3918460222899735322), F39_S2(f0: 883468300, f1: 2739152), -94, F39_S3(f0: 1374766954, f1: 2042223450490396789, f2: 2672454113535023130), 946259065, 6805548458517673751, 61) +} + +@frozen +public struct F40_S0 +{ + public let f0 : Int16; + public let f1 : Int32; +} + +@frozen +public struct F40_S1 +{ + public let f0 : Int32; +} + +@frozen +public struct F40_S2 +{ + public let f0 : Int64; + public let f1 : UInt16; + public let f2 : Int; + public let f3 : UInt8; +} + +@frozen +public struct F40_S3_S0 +{ + public let f0 : Float; +} + +@frozen +public struct F40_S3 +{ + public let f0 : UInt; + public let f1 : Double; + public let f2 : F40_S3_S0; + public let f3 : Double; +} + +public func swiftCallbackFunc40(f: (F40_S0, UInt32, UInt8, F40_S1, F40_S2, UInt64, UInt, UInt64, Int, UInt16, UInt32, F40_S3, UInt) -> UInt) -> UInt { + return f(F40_S0(f0: 22601, f1: 312892872), 1040102825, 56, F40_S1(f0: 101203812), F40_S2(f0: 4298883321494088257, f1: 2095, f2: 1536552108568739270, f3: 220), 2564624804830565018, 173855559108584219, 6222832940831380264, 1898370824516510398, 3352, 1643571476, F40_S3(f0: 7940054758811932961, f1: 246670432251533, f2: F40_S3_S0(f0: 7890596), f3: 1094140965415232), 2081923113238309816) +} + +@frozen +public struct F41_S0 +{ + public let f0 : UInt32; +} + +@frozen +public struct F41_Ret +{ + public let f0 : UInt64; + public let f1 : Double; + public let f2 : UInt32; + public let f3 : UInt32; +} + +public func swiftCallbackFunc41(f: (F41_S0) -> F41_Ret) -> F41_Ret { + return f(F41_S0(f0: 1430200072)) +} + +@frozen +public struct F42_S0_S0 +{ + public let f0 : Int; +} + +@frozen +public struct F42_S0 +{ + public let f0 : F42_S0_S0; +} + +@frozen +public struct F42_S1 +{ + public let f0 : UInt32; +} + +public func swiftCallbackFunc42(f: (Int32, UInt32, F42_S0, Float, UInt8, F42_S1) -> Int) -> Int { + return f(1046060439, 1987212952, F42_S0(f0: F42_S0_S0(f0: 4714080408858753964)), 2364146, 25, F42_S1(f0: 666986488)) +} + +@frozen +public struct F43_S0 +{ + public let f0 : Int32; + public let f1 : Int32; + public let f2 : Int; +} + +@frozen +public struct F43_S1 +{ + public let f0 : Int8; +} + +@frozen +public struct F43_Ret +{ + public let f0 : UInt16; +} + +public func swiftCallbackFunc43(f: (F43_S0, F43_S1) -> F43_Ret) -> F43_Ret { + return f(F43_S0(f0: 406102630, f1: 1946236062, f2: 663606396354980308), F43_S1(f0: -8)) +} + +@frozen +public struct F44_S0 +{ + public let f0 : UInt32; +} + +@frozen +public struct F44_S1_S0 +{ + public let f0 : UInt16; +} + +@frozen +public struct F44_S1_S1 +{ + public let f0 : UInt; +} + +@frozen +public struct F44_S1 +{ + public let f0 : Int16; + public let f1 : Int16; + public let f2 : F44_S1_S0; + public let f3 : F44_S1_S1; +} + +@frozen +public struct F44_S2 +{ + public let f0 : UInt; +} + +@frozen +public struct F44_S3 +{ + public let f0 : Int8; +} + +@frozen +public struct F44_Ret_S0 +{ + public let f0 : UInt; +} + +@frozen +public struct F44_Ret +{ + public let f0 : Int; + public let f1 : F44_Ret_S0; + public let f2 : Double; +} + +public func swiftCallbackFunc44(f: (Double, F44_S0, F44_S1, F44_S2, F44_S3) -> F44_Ret) -> F44_Ret { + return f(4281406007431544, F44_S0(f0: 2097291497), F44_S1(f0: -10489, f1: -9573, f2: F44_S1_S0(f0: 62959), f3: F44_S1_S1(f0: 7144119809173057975)), F44_S2(f0: 168733393207234277), F44_S3(f0: 64)) +} + +@frozen +public struct F45_S0 +{ + public let f0 : UInt; +} + +@frozen +public struct F45_S1 +{ + public let f0 : UInt; + public let f1 : Int16; +} + +@frozen +public struct F45_Ret_S0 +{ + public let f0 : Float; +} + +@frozen +public struct F45_Ret +{ + public let f0 : Double; + public let f1 : F45_Ret_S0; + public let f2 : Int64; + public let f3 : Double; + public let f4 : UInt64; + public let f5 : Int8; + public let f6 : Int32; +} + +public func swiftCallbackFunc45(f: (F45_S0, F45_S1, UInt8) -> F45_Ret) -> F45_Ret { + return f(F45_S0(f0: 5311803360204128233), F45_S1(f0: 2204790044275015546, f1: 8942), 207) +} + +@frozen +public struct F46_Ret +{ + public let f0 : UInt; + public let f1 : Double; + public let f2 : Int64; + public let f3 : UInt16; +} + +public func swiftCallbackFunc46(f: (Int, UInt, UInt16, UInt16, Int64) -> F46_Ret) -> F46_Ret { + return f(1855296013283572041, 1145047910516899437, 20461, 58204, 1923767011143317115) +} + +@frozen +public struct F47_S0 +{ + public let f0 : UInt8; + public let f1 : Int32; +} + +@frozen +public struct F47_S1 +{ + public let f0 : Int; + public let f1 : UInt32; + public let f2 : Int8; +} + +@frozen +public struct F47_S2_S0 +{ + public let f0 : UInt8; +} + +@frozen +public struct F47_S2 +{ + public let f0 : Int8; + public let f1 : Float; + public let f2 : Int32; + public let f3 : Float; + public let f4 : F47_S2_S0; +} + +@frozen +public struct F47_S3 +{ + public let f0 : UInt64; + public let f1 : Int64; +} + +@frozen +public struct F47_S4 +{ + public let f0 : UInt64; +} + +@frozen +public struct F47_Ret +{ + public let f0 : Int16; + public let f1 : Int16; + public let f2 : Int64; +} + +public func swiftCallbackFunc47(f: (Int, Float, UInt32, F47_S0, F47_S1, UInt16, Float, Int, Int, UInt, UInt, Int16, F47_S2, F47_S3, F47_S4) -> F47_Ret) -> F47_Ret { + return f(6545360066379352091, 1240616, 575670382, F47_S0(f0: 27, f1: 1769677101), F47_S1(f0: 4175209822525678639, f1: 483151627, f2: -41), 20891, 1011044, 8543308148327168378, 9126721646663585297, 5438914191614359864, 5284613245897089025, -9227, F47_S2(f0: -23, f1: 1294109, f2: 411726757, f3: 6621598, f4: F47_S2_S0(f0: 249)), F47_S3(f0: 5281612261430853979, f1: 7161295082465816089), F47_S4(f0: 1995556861952451598)) +} + +@frozen +public struct F48_S0 +{ + public let f0 : UInt64; + public let f1 : Int16; + public let f2 : UInt64; +} + +@frozen +public struct F48_S1_S0 +{ + public let f0 : Float; +} + +@frozen +public struct F48_S1 +{ + public let f0 : Double; + public let f1 : Int32; + public let f2 : Int32; + public let f3 : F48_S1_S0; + public let f4 : UInt; +} + +public func swiftCallbackFunc48(f: (Int8, Int16, Int16, UInt32, F48_S0, UInt32, F48_S1, Int32, Int32, UInt16, Int64, UInt32) -> Int64) -> Int64 { + return f(-34, 11634, -27237, 1039294154, F48_S0(f0: 1367847206719062131, f1: 22330, f2: 689282484471011648), 1572626904, F48_S1(f0: 3054128759424009, f1: 1677338134, f2: 1257237843, f3: F48_S1_S0(f0: 6264494), f4: 8397097040610783205), 1060447208, 269785114, 20635, 7679010342730986048, 1362633148) +} + +@frozen +public struct F49_S0_S0 +{ + public let f0 : UInt8; +} + +@frozen +public struct F49_S0 +{ + public let f0 : F49_S0_S0; + public let f1 : UInt64; +} + +@frozen +public struct F49_Ret +{ + public let f0 : Int32; + public let f1 : Int16; + public let f2 : UInt8; + public let f3 : UInt8; + public let f4 : Int8; + public let f5 : Int64; +} + +public func swiftCallbackFunc49(f: (F49_S0, Int64) -> F49_Ret) -> F49_Ret { + return f(F49_S0(f0: F49_S0_S0(f0: 48), f1: 7563394992711018452), 4358370311341042916) +} + +@frozen +public struct F50_S0_S0 +{ + public let f0 : Double; +} + +@frozen +public struct F50_S0 +{ + public let f0 : UInt16; + public let f1 : F50_S0_S0; +} + +@frozen +public struct F50_S1 +{ + public let f0 : Double; + public let f1 : UInt16; + public let f2 : Int32; + public let f3 : Int; + public let f4 : Double; +} + +@frozen +public struct F50_S2 +{ + public let f0 : Int32; + public let f1 : Float; + public let f2 : UInt32; +} + +@frozen +public struct F50_S3 +{ + public let f0 : Int64; + public let f1 : Int32; + public let f2 : Float; + public let f3 : Int8; +} + +@frozen +public struct F50_S4 +{ + public let f0 : Int64; +} + +@frozen +public struct F50_S5_S0 +{ + public let f0 : UInt16; +} + +@frozen +public struct F50_S5 +{ + public let f0 : F50_S5_S0; +} + +public func swiftCallbackFunc50(f: (F50_S0, F50_S1, UInt8, F50_S2, Int32, UInt64, Int8, Int8, Float, F50_S3, F50_S4, F50_S5, Float) -> UInt8) -> UInt8 { + return f(F50_S0(f0: 31857, f1: F50_S0_S0(f0: 1743417849706254)), F50_S1(f0: 4104577461772135, f1: 13270, f2: 2072598986, f3: 9056978834867675248, f4: 844742439929087), 87, F50_S2(f0: 1420884537, f1: 78807, f2: 1081688273), 336878110, 1146514566942283069, -93, 73, 2321639, F50_S3(f0: 1940888991336881606, f1: 688345394, f2: 712275, f3: -128), F50_S4(f0: 2638503583829414770), F50_S5(f0: F50_S5_S0(f0: 23681)), 8223218) +} + +@frozen +public struct F51_S0 +{ + public let f0 : Int64; +} + +@frozen +public struct F51_Ret +{ + public let f0 : UInt16; + public let f1 : Int8; + public let f2 : Int; + public let f3 : UInt16; + public let f4 : UInt64; +} + +public func swiftCallbackFunc51(f: (Int16, UInt, F51_S0, UInt64) -> F51_Ret) -> F51_Ret { + return f(10812, 470861239714315155, F51_S0(f0: 5415660333180374788), 2389942629143476149) +} + +@frozen +public struct F52_S0 +{ + public let f0 : Float; +} + +@frozen +public struct F52_S1 +{ + public let f0 : UInt16; +} + +@frozen +public struct F52_Ret +{ + public let f0 : Float; + public let f1 : UInt16; + public let f2 : Int64; + public let f3 : Int16; + public let f4 : UInt64; + public let f5 : Int8; +} + +public func swiftCallbackFunc52(f: (Int, F52_S0, Int16, Int16, F52_S1) -> F52_Ret) -> F52_Ret { + return f(3233654765973602550, F52_S0(f0: 5997729), -7404, -20804, F52_S1(f0: 17231)) +} + +@frozen +public struct F53_S0_S0_S0 +{ + public let f0 : Int64; +} + +@frozen +public struct F53_S0_S0 +{ + public let f0 : F53_S0_S0_S0; +} + +@frozen +public struct F53_S0 +{ + public let f0 : Int8; + public let f1 : F53_S0_S0; + public let f2 : UInt8; + public let f3 : UInt; + public let f4 : Int64; +} + +@frozen +public struct F53_S1 +{ + public let f0 : Float; + public let f1 : UInt8; +} + +@frozen +public struct F53_S2 +{ + public let f0 : Int8; + public let f1 : Int64; +} + +@frozen +public struct F53_S3_S0 +{ + public let f0 : UInt16; +} + +@frozen +public struct F53_S3 +{ + public let f0 : Int32; + public let f1 : UInt32; + public let f2 : F53_S3_S0; +} + +@frozen +public struct F53_S4 +{ + public let f0 : Int16; +} + +@frozen +public struct F53_S5_S0 +{ + public let f0 : UInt32; +} + +@frozen +public struct F53_S5_S1_S0 +{ + public let f0 : UInt8; +} + +@frozen +public struct F53_S5_S1 +{ + public let f0 : F53_S5_S1_S0; +} + +@frozen +public struct F53_S5 +{ + public let f0 : F53_S5_S0; + public let f1 : UInt; + public let f2 : UInt16; + public let f3 : F53_S5_S1; + public let f4 : Int8; +} + +@frozen +public struct F53_S6 +{ + public let f0 : Int; +} + +@frozen +public struct F53_Ret +{ + public let f0 : Int; +} + +public func swiftCallbackFunc53(f: (F53_S0, UInt8, Int64, F53_S1, F53_S2, F53_S3, Int64, F53_S4, F53_S5, F53_S6) -> F53_Ret) -> F53_Ret { + return f(F53_S0(f0: -123, f1: F53_S0_S0(f0: F53_S0_S0_S0(f0: 3494916243607193741)), f2: 167, f3: 4018943158751734338, f4: 6768175524813742847), 207, 8667995458064724392, F53_S1(f0: 492157, f1: 175), F53_S2(f0: 76, f1: 5794486968525461488), F53_S3(f0: 2146070335, f1: 1109141712, f2: F53_S3_S0(f0: 44270)), 3581380181786253859, F53_S4(f0: 23565), F53_S5(f0: F53_S5_S0(f0: 1995174927), f1: 5025417700244056666, f2: 1847, f3: F53_S5_S1(f0: F53_S5_S1_S0(f0: 6)), f4: -87), F53_S6(f0: 5737280129078653969)) +} + +@frozen +public struct F54_S0 +{ + public let f0 : Int32; + public let f1 : Float; + public let f2 : UInt; + public let f3 : UInt8; +} + +@frozen +public struct F54_S1 +{ + public let f0 : UInt16; +} + +@frozen +public struct F54_S2_S0_S0 +{ + public let f0 : Double; +} + +@frozen +public struct F54_S2_S0 +{ + public let f0 : Int16; + public let f1 : F54_S2_S0_S0; +} + +@frozen +public struct F54_S2 +{ + public let f0 : Double; + public let f1 : F54_S2_S0; + public let f2 : Int64; + public let f3 : UInt64; +} + +@frozen +public struct F54_S3 +{ + public let f0 : Float; +} + +@frozen +public struct F54_S4 +{ + public let f0 : UInt16; + public let f1 : Int8; +} + +@frozen +public struct F54_S5 +{ + public let f0 : UInt16; +} + +@frozen +public struct F54_Ret +{ + public let f0 : Int16; + public let f1 : Int; +} + +public func swiftCallbackFunc54(f: (UInt16, F54_S0, Float, F54_S1, Int64, Int32, F54_S2, F54_S3, F54_S4, Float, F54_S5) -> F54_Ret) -> F54_Ret { + return f(16440, F54_S0(f0: 922752112, f1: 7843043, f2: 1521939500434086364, f3: 50), 3111108, F54_S1(f0: 50535), 4761507229870258916, 1670668155, F54_S2(f0: 432665443852892, f1: F54_S2_S0(f0: 13094, f1: F54_S2_S0_S0(f0: 669143993481144)), f2: 30067117315069590, f3: 874012622621600805), F54_S3(f0: 7995066), F54_S4(f0: 48478, f1: 23), 4383787, F54_S5(f0: 61633)) +} + +@frozen +public struct F55_S0_S0 +{ + public let f0 : Double; +} + +@frozen +public struct F55_S0 +{ + public let f0 : UInt; + public let f1 : F55_S0_S0; + public let f2 : Int8; +} + +@frozen +public struct F55_S1 +{ + public let f0 : Int; +} + +@frozen +public struct F55_S2 +{ + public let f0 : UInt64; +} + +@frozen +public struct F55_Ret_S0 +{ + public let f0 : Int16; + public let f1 : Int32; +} + +@frozen +public struct F55_Ret +{ + public let f0 : UInt; + public let f1 : Int; + public let f2 : Double; + public let f3 : F55_Ret_S0; + public let f4 : UInt64; +} + +public func swiftCallbackFunc55(f: (F55_S0, Int64, F55_S1, Int8, F55_S2, Float) -> F55_Ret) -> F55_Ret { + return f(F55_S0(f0: 2856661562863799725, f1: F55_S0_S0(f0: 1260582440479139), f2: 5), 7945068527720423751, F55_S1(f0: 4321616441998677375), -68, F55_S2(f0: 3311106172201778367), 5600069) +} + +@frozen +public struct F56_S0 +{ + public let f0 : Double; +} + +public func swiftCallbackFunc56(f: (F56_S0) -> UInt32) -> UInt32 { + return f(F56_S0(f0: 3082602006731666)) +} + +@frozen +public struct F57_S0 +{ + public let f0 : Int64; + public let f1 : Int32; + public let f2 : UInt64; +} + +@frozen +public struct F57_S1 +{ + public let f0 : UInt8; +} + +@frozen +public struct F57_S2 +{ + public let f0 : Float; +} + +@frozen +public struct F57_Ret_S0 +{ + public let f0 : Int64; + public let f1 : UInt8; + public let f2 : Int16; +} + +@frozen +public struct F57_Ret +{ + public let f0 : F57_Ret_S0; + public let f1 : UInt8; +} + +public func swiftCallbackFunc57(f: (Int8, UInt, UInt32, Int64, UInt64, Int16, Int64, F57_S0, F57_S1, F57_S2) -> F57_Ret) -> F57_Ret { + return f(54, 753245150862584974, 1470962934, 1269392070140776313, 2296560034524654667, 12381, 198893062684618980, F57_S0(f0: 1310571041794038100, f1: 18741662, f2: 7855196891704523814), F57_S1(f0: 156), F57_S2(f0: 72045)) +} + +@frozen +public struct F58_S0 +{ + public let f0 : UInt8; +} + +@frozen +public struct F58_S1 +{ + public let f0 : Float; + public let f1 : UInt16; +} + +@frozen +public struct F58_S2_S0_S0 +{ + public let f0 : Int; +} + +@frozen +public struct F58_S2_S0 +{ + public let f0 : F58_S2_S0_S0; +} + +@frozen +public struct F58_S2 +{ + public let f0 : F58_S2_S0; +} + +public func swiftCallbackFunc58(f: (UInt64, Int8, Int, F58_S0, F58_S1, Int64, F58_S2, Int32) -> Int) -> Int { + return f(4612004722568513699, -96, 1970590839325113617, F58_S0(f0: 211), F58_S1(f0: 5454927, f1: 48737), 921570327236881486, F58_S2(f0: F58_S2_S0(f0: F58_S2_S0_S0(f0: 7726203059421444802))), 491616915) +} + +public func swiftCallbackFunc59(f: (UInt16, Int64, Int) -> UInt64) -> UInt64 { + return f(9232, 7281011081566942937, 8203439771560005792) +} + +@frozen +public struct F60_S0 +{ + public let f0 : Int; +} + +@frozen +public struct F60_S1 +{ + public let f0 : UInt64; + public let f1 : Int32; +} + +public func swiftCallbackFunc60(f: (Float, Double, Int64, UInt16, Float, Float, F60_S0, Int16, F60_S1, Int16, Int64) -> UInt64) -> UInt64 { + return f(2682255, 2041676057169359, 5212916666940122160, 64444, 6372882, 8028835, F60_S0(f0: 6629286640024570381), 1520, F60_S1(f0: 8398497739914283366, f1: 1882981891), 7716, 6631047215535600409) +} + +@frozen +public struct F61_S0_S0 +{ + public let f0 : Int64; +} + +@frozen +public struct F61_S0 +{ + public let f0 : F61_S0_S0; + public let f1 : Int64; + public let f2 : UInt32; +} + +@frozen +public struct F61_S1 +{ + public let f0 : Int8; + public let f1 : Float; + public let f2 : Int; +} + +@frozen +public struct F61_S2_S0_S0 +{ + public let f0 : UInt64; +} + +@frozen +public struct F61_S2_S0 +{ + public let f0 : F61_S2_S0_S0; +} + +@frozen +public struct F61_S2_S1 +{ + public let f0 : Int8; +} + +@frozen +public struct F61_S2 +{ + public let f0 : F61_S2_S0; + public let f1 : F61_S2_S1; +} + +@frozen +public struct F61_S3 +{ + public let f0 : UInt64; + public let f1 : Int; +} + +public func swiftCallbackFunc61(f: (UInt32, UInt32, F61_S0, F61_S1, F61_S2, Int8, Int16, F61_S3, Int32, UInt32) -> UInt32) -> UInt32 { + return f(1070797065, 135220309, F61_S0(f0: F61_S0_S0(f0: 6475887024664217162), f1: 563444654083452485, f2: 1748956360), F61_S1(f0: -112, f1: 3433396, f2: 8106074956722850624), F61_S2(f0: F61_S2_S0(f0: F61_S2_S0_S0(f0: 2318628619979263858)), f1: F61_S2_S1(f0: -93)), -122, -11696, F61_S3(f0: 5229393236090246212, f1: 4021449757638811198), 689517945, 657677740) +} + +@frozen +public struct F62_S0 +{ + public let f0 : Float; +} + +@frozen +public struct F62_Ret +{ + public let f0 : UInt16; + public let f1 : Int64; + public let f2 : Int; + public let f3 : Int64; +} + +public func swiftCallbackFunc62(f: (F62_S0) -> F62_Ret) -> F62_Ret { + return f(F62_S0(f0: 6500993)) +} + +@frozen +public struct F63_S0 +{ + public let f0 : Int; +} + +public func swiftCallbackFunc63(f: (F63_S0, Int16) -> Float) -> Float { + return f(F63_S0(f0: 8391317504019075904), 11218) +} + +@frozen +public struct F64_S0 +{ + public let f0 : Int32; +} + +@frozen +public struct F64_S1 +{ + public let f0 : UInt64; +} + +@frozen +public struct F64_S2 +{ + public let f0 : UInt32; +} + +@frozen +public struct F64_Ret_S0 +{ + public let f0 : UInt16; + public let f1 : UInt; + public let f2 : UInt64; +} + +@frozen +public struct F64_Ret +{ + public let f0 : UInt; + public let f1 : F64_Ret_S0; + public let f2 : Double; +} + +public func swiftCallbackFunc64(f: (Int8, F64_S0, F64_S1, UInt, F64_S2) -> F64_Ret) -> F64_Ret { + return f(-22, F64_S0(f0: 1591678205), F64_S1(f0: 8355549563000003325), 5441989206466502201, F64_S2(f0: 2097092811)) +} + +@frozen +public struct F65_S0 +{ + public let f0 : Double; +} + +@frozen +public struct F65_S1 +{ + public let f0 : UInt16; + public let f1 : Int; +} + +@frozen +public struct F65_S2 +{ + public let f0 : Int16; +} + +@frozen +public struct F65_S3 +{ + public let f0 : Int32; + public let f1 : UInt32; + public let f2 : Int8; + public let f3 : UInt; + public let f4 : Double; +} + +@frozen +public struct F65_Ret +{ + public let f0 : Int; + public let f1 : Int; + public let f2 : Int; + public let f3 : Float; +} + +public func swiftCallbackFunc65(f: (F65_S0, Int16, Double, UInt, F65_S1, UInt64, F65_S2, Int, F65_S3, Int32, Int64, UInt32, Double) -> F65_Ret) -> F65_Ret { + return f(F65_S0(f0: 2969223123583220), -10269, 3909264978196109, 522883062031213707, F65_S1(f0: 37585, f1: 5879827541057349126), 1015270399093748716, F65_S2(f0: 19670), 1900026319968050423, F65_S3(f0: 1440511399, f1: 1203865685, f2: 12, f3: 4061296318630567634, f4: 2406524883317724), 1594888000, 2860599972459787263, 1989052358, 1036075606072593) +} + +@frozen +public struct F66_Ret_S0 +{ + public let f0 : Float; + public let f1 : UInt8; +} + +@frozen +public struct F66_Ret +{ + public let f0 : UInt32; + public let f1 : Int32; + public let f2 : UInt32; + public let f3 : F66_Ret_S0; + public let f4 : Int; +} + +public func swiftCallbackFunc66(f: (Int64) -> F66_Ret) -> F66_Ret { + return f(8300712022174991120) +} + +@frozen +public struct F67_S0 +{ + public let f0 : UInt32; + public let f1 : UInt8; + public let f2 : UInt8; + public let f3 : Int32; +} + +@frozen +public struct F67_S1 +{ + public let f0 : UInt32; +} + +@frozen +public struct F67_S2_S0 +{ + public let f0 : Int; +} + +@frozen +public struct F67_S2 +{ + public let f0 : UInt64; + public let f1 : UInt32; + public let f2 : Int; + public let f3 : UInt32; + public let f4 : F67_S2_S0; +} + +@frozen +public struct F67_S3 +{ + public let f0 : Int16; + public let f1 : UInt64; + public let f2 : UInt64; + public let f3 : Float; +} + +public func swiftCallbackFunc67(f: (Double, F67_S0, Float, F67_S1, Int16, UInt, F67_S2, UInt16, UInt, UInt, F67_S3, UInt64) -> Int32) -> Int32 { + return f(2365334314089079, F67_S0(f0: 1133369490, f1: 54, f2: 244, f3: 411611102), 4453912, F67_S1(f0: 837821989), -3824, 2394019088612006082, F67_S2(f0: 2219661088889353540, f1: 294254132, f2: 5363897228951721947, f3: 2038380379, f4: F67_S2_S0(f0: 8364879421385869437)), 27730, 1854446871602777695, 5020910156102352016, F67_S3(f0: -2211, f1: 5910581461792482729, f2: 9095210648679611609, f3: 6138428), 4274242076331880276) +} + +@frozen +public struct F68_S0_S0 +{ + public let f0 : Int8; +} + +@frozen +public struct F68_S0 +{ + public let f0 : Int64; + public let f1 : F68_S0_S0; +} + +@frozen +public struct F68_S1 +{ + public let f0 : UInt16; +} + +@frozen +public struct F68_S2_S0 +{ + public let f0 : UInt; +} + +@frozen +public struct F68_S2_S1_S0 +{ + public let f0 : UInt64; +} + +@frozen +public struct F68_S2_S1 +{ + public let f0 : F68_S2_S1_S0; +} + +@frozen +public struct F68_S2 +{ + public let f0 : F68_S2_S0; + public let f1 : F68_S2_S1; +} + +@frozen +public struct F68_S3 +{ + public let f0 : Int16; +} + +@frozen +public struct F68_Ret +{ + public let f0 : UInt16; + public let f1 : Int64; +} + +public func swiftCallbackFunc68(f: (UInt8, Float, Int32, Int, F68_S0, Int16, Int, Int32, Int, F68_S1, Double, F68_S2, F68_S3) -> F68_Ret) -> F68_Ret { + return f(203, 7725681, 323096997, 7745650233784541800, F68_S0(f0: 4103074885750473230, f1: F68_S0_S0(f0: 12)), 28477, 3772772447290536725, 1075348149, 2017898311184593242, F68_S1(f0: 60280), 4052387873895590, F68_S2(f0: F68_S2_S0(f0: 1321857087602747558), f1: F68_S2_S1(f0: F68_S2_S1_S0(f0: 9011155097138053416))), F68_S3(f0: 8332)) +} + +@frozen +public struct F69_S0_S0 +{ + public let f0 : UInt64; +} + +@frozen +public struct F69_S0 +{ + public let f0 : F69_S0_S0; +} + +@frozen +public struct F69_S1 +{ + public let f0 : Int64; +} + +@frozen +public struct F69_S2 +{ + public let f0 : Int32; +} + +@frozen +public struct F69_S3 +{ + public let f0 : UInt8; +} + +@frozen +public struct F69_S4_S0 +{ + public let f0 : Int64; +} + +@frozen +public struct F69_S4 +{ + public let f0 : F69_S4_S0; +} + +@frozen +public struct F69_Ret +{ + public let f0 : UInt8; + public let f1 : Int64; + public let f2 : UInt32; +} + +public func swiftCallbackFunc69(f: (F69_S0, Int, Int32, F69_S1, UInt32, Int8, F69_S2, Int, F69_S3, F69_S4) -> F69_Ret) -> F69_Ret { + return f(F69_S0(f0: F69_S0_S0(f0: 7154553222175076145)), 6685908100026425691, 1166526155, F69_S1(f0: 6042278185730963289), 182060391, 45, F69_S2(f0: 1886331345), 485542148877875333, F69_S3(f0: 209), F69_S4(f0: F69_S4_S0(f0: 6856847647688321191))) +} + +@frozen +public struct F70_S0 +{ + public let f0 : Int64; +} + +@frozen +public struct F70_S1 +{ + public let f0 : Int; + public let f1 : Double; + public let f2 : Int16; +} + +@frozen +public struct F70_S2 +{ + public let f0 : UInt32; +} + +@frozen +public struct F70_S3 +{ + public let f0 : UInt16; + public let f1 : Double; + public let f2 : UInt8; + public let f3 : UInt64; + public let f4 : Int32; +} + +@frozen +public struct F70_S4_S0 +{ + public let f0 : UInt; +} + +@frozen +public struct F70_S4 +{ + public let f0 : F70_S4_S0; +} + +@frozen +public struct F70_Ret +{ + public let f0 : Int8; + public let f1 : UInt32; + public let f2 : UInt64; + public let f3 : Int16; + public let f4 : Int16; +} + +public func swiftCallbackFunc70(f: (Int16, UInt8, Int, UInt32, F70_S0, Int32, F70_S1, F70_S2, F70_S3, Int64, Int32, UInt16, Int, Int, UInt, F70_S4) -> F70_Ret) -> F70_Ret { + return f(-13167, 126, 3641983584484741827, 1090448265, F70_S0(f0: 3696858216713616004), 1687025402, F70_S1(f0: 714916953527626038, f1: 459810445900614, f2: 4276), F70_S2(f0: 529194028), F70_S3(f0: 40800, f1: 3934985905568056, f2: 230, f3: 7358783417346157372, f4: 187926922), 228428560763393434, 146501405, 58804, 7098488973446286248, 1283658442251334575, 3644681944588099582, F70_S4(f0: F70_S4_S0(f0: 8197135412164695911))) +} + +@frozen +public struct F71_S0_S0 +{ + public let f0 : Int32; +} + +@frozen +public struct F71_S0 +{ + public let f0 : F71_S0_S0; +} + +@frozen +public struct F71_S1 +{ + public let f0 : Int64; +} + +public func swiftCallbackFunc71(f: (F71_S0, F71_S1) -> UInt64) -> UInt64 { + return f(F71_S0(f0: F71_S0_S0(f0: 258165353)), F71_S1(f0: 8603744544763953916)) +} + +@frozen +public struct F72_S0 +{ + public let f0 : Int32; +} + +@frozen +public struct F72_Ret +{ + public let f0 : UInt32; + public let f1 : Float; + public let f2 : Float; + public let f3 : Int64; +} + +public func swiftCallbackFunc72(f: (F72_S0, Int64, Int8) -> F72_Ret) -> F72_Ret { + return f(F72_S0(f0: 2021509367), 2480039820482100351, 91) +} + +@frozen +public struct F73_S0 +{ + public let f0 : Int32; +} + +@frozen +public struct F73_S1_S0 +{ + public let f0 : UInt16; +} + +@frozen +public struct F73_S1 +{ + public let f0 : F73_S1_S0; +} + +@frozen +public struct F73_S2 +{ + public let f0 : Int32; + public let f1 : Float; +} + +@frozen +public struct F73_S3 +{ + public let f0 : UInt; + public let f1 : Int16; + public let f2 : Int8; +} + +@frozen +public struct F73_S4 +{ + public let f0 : Int16; +} + +@frozen +public struct F73_S5 +{ + public let f0 : UInt32; +} + +public func swiftCallbackFunc73(f: (Double, Float, F73_S0, Int64, F73_S1, F73_S2, Int16, Double, Int8, Int32, Int64, F73_S3, UInt, UInt64, Int32, F73_S4, UInt8, F73_S5) -> Int8) -> Int8 { + return f(3038361048801008, 7870661, F73_S0(f0: 1555231180), 7433951069104961, F73_S1(f0: F73_S1_S0(f0: 63298)), F73_S2(f0: 1759846580, f1: 1335901), 11514, 695278874601974, 108, 48660527, 7762050749172332624, F73_S3(f0: 7486686356276472663, f1: 11622, f2: 112), 884183974530885885, 7434462110419085390, 170242607, F73_S4(f0: -26039), 41, F73_S5(f0: 191302504)) +} + +@frozen +public struct F74_S0_S0 +{ + public let f0 : UInt16; + public let f1 : UInt; + public let f2 : Int8; +} + +@frozen +public struct F74_S0 +{ + public let f0 : F74_S0_S0; + public let f1 : Int; +} + +@frozen +public struct F74_S1 +{ + public let f0 : Float; +} + +public func swiftCallbackFunc74(f: (F74_S0, F74_S1, Int16) -> Int64) -> Int64 { + return f(F74_S0(f0: F74_S0_S0(f0: 59883, f1: 5554216411943233256, f2: 126), f1: 724541378819571203), F74_S1(f0: 172601), 27932) +} + +@frozen +public struct F75_S0 +{ + public let f0 : Int64; +} + +@frozen +public struct F75_S1_S0 +{ + public let f0 : UInt8; +} + +@frozen +public struct F75_S1 +{ + public let f0 : F75_S1_S0; +} + +@frozen +public struct F75_S2 +{ + public let f0 : Int8; +} + +@frozen +public struct F75_S3_S0 +{ + public let f0 : UInt16; +} + +@frozen +public struct F75_S3 +{ + public let f0 : F75_S3_S0; +} + +@frozen +public struct F75_Ret +{ + public let f0 : UInt8; + public let f1 : Double; + public let f2 : Double; + public let f3 : Int64; + public let f4 : UInt32; +} + +public func swiftCallbackFunc75(f: (Int8, Int8, Int8, F75_S0, F75_S1, F75_S2, F75_S3) -> F75_Ret) -> F75_Ret { + return f(-105, 71, 108, F75_S0(f0: 7224638108479292438), F75_S1(f0: F75_S1_S0(f0: 126)), F75_S2(f0: -88), F75_S3(f0: F75_S3_S0(f0: 4934))) +} + +@frozen +public struct F76_S0 +{ + public let f0 : UInt16; + public let f1 : Int; +} + +@frozen +public struct F76_S1_S0 +{ + public let f0 : Int; +} + +@frozen +public struct F76_S1 +{ + public let f0 : F76_S1_S0; + public let f1 : UInt; + public let f2 : Double; +} + +@frozen +public struct F76_S2 +{ + public let f0 : UInt64; + public let f1 : Int; + public let f2 : UInt16; +} + +@frozen +public struct F76_S3_S0 +{ + public let f0 : Int64; +} + +@frozen +public struct F76_S3 +{ + public let f0 : F76_S3_S0; +} + +@frozen +public struct F76_S4 +{ + public let f0 : Int64; +} + +@frozen +public struct F76_S5 +{ + public let f0 : UInt; + public let f1 : Double; +} + +public func swiftCallbackFunc76(f: (UInt8, F76_S0, Int8, F76_S1, F76_S2, F76_S3, UInt32, F76_S4, UInt8, F76_S5, Double, Int16) -> UInt64) -> UInt64 { + return f(69, F76_S0(f0: 25503, f1: 4872234474620951743), 43, F76_S1(f0: F76_S1_S0(f0: 1199076663426903579), f1: 4639522222462236688, f2: 4082956091930029), F76_S2(f0: 5171821618947987626, f1: 3369410144919558564, f2: 5287), F76_S3(f0: F76_S3_S0(f0: 929854460912895550)), 1208311201, F76_S4(f0: 7033993025788649145), 58, F76_S5(f0: 1401399014740601512, f1: 2523645319232571), 230232835550369, -22975) +} + +@frozen +public struct F77_S0 +{ + public let f0 : Int64; + public let f1 : Double; + public let f2 : UInt; +} + +@frozen +public struct F77_S1 +{ + public let f0 : Int16; + public let f1 : Float; + public let f2 : Float; + public let f3 : Int64; + public let f4 : Int64; +} + +@frozen +public struct F77_S2 +{ + public let f0 : UInt16; + public let f1 : Int8; + public let f2 : Int32; + public let f3 : Float; + public let f4 : Float; +} + +@frozen +public struct F77_Ret +{ + public let f0 : Double; + public let f1 : UInt16; + public let f2 : Int8; + public let f3 : UInt; +} + +public func swiftCallbackFunc77(f: (Double, F77_S0, F77_S1, F77_S2, UInt32) -> F77_Ret) -> F77_Ret { + return f(1623173949127682, F77_S0(f0: 5204451347781433070, f1: 3469485630755805, f2: 7586276835848725004), F77_S1(f0: 2405, f1: 2419792, f2: 6769317, f3: 1542327522833750776, f4: 1297586130846695275), F77_S2(f0: 10102, f1: -48, f2: 14517107, f3: 4856023, f4: 2681358), 1463251524) +} + +@frozen +public struct F78_S0 +{ + public let f0 : UInt; + public let f1 : Int; +} + +@frozen +public struct F78_S1_S0 +{ + public let f0 : Int8; +} + +@frozen +public struct F78_S1 +{ + public let f0 : Int16; + public let f1 : UInt64; + public let f2 : F78_S1_S0; + public let f3 : Int32; + public let f4 : Int; +} + +@frozen +public struct F78_S2 +{ + public let f0 : UInt; + public let f1 : UInt64; +} + +@frozen +public struct F78_S3 +{ + public let f0 : UInt64; +} + +@frozen +public struct F78_S4 +{ + public let f0 : UInt64; +} + +public func swiftCallbackFunc78(f: (UInt64, F78_S0, UInt64, F78_S1, F78_S2, Int32, UInt64, Int64, F78_S3, Float, Float, UInt16, F78_S4, Double) -> Double) -> Double { + return f(6780767594736146373, F78_S0(f0: 6264193481541646332, f1: 6600856439035088503), 1968254881389492170, F78_S1(f0: -17873, f1: 5581169895682201971, f2: F78_S1_S0(f0: 127), f3: 1942346704, f4: 118658265323815307), F78_S2(f0: 1489326778640378879, f1: 1427061853707270770), 858391966, 5830110056171302270, 2953614358173898788, F78_S3(f0: 6761452244699684409), 3452451, 3507119, 40036, F78_S4(f0: 4800085294404376817), 780368756754436) +} + +@frozen +public struct F79_S0_S0 +{ + public let f0 : UInt; +} + +@frozen +public struct F79_S0 +{ + public let f0 : F79_S0_S0; + public let f1 : Int; +} + +@frozen +public struct F79_Ret +{ + public let f0 : UInt32; + public let f1 : UInt64; + public let f2 : Double; +} + +public func swiftCallbackFunc79(f: (F79_S0, Float) -> F79_Ret) -> F79_Ret { + return f(F79_S0(f0: F79_S0_S0(f0: 1013911700897046117), f1: 7323935615297665289), 5159506) +} + +@frozen +public struct F80_S0 +{ + public let f0 : UInt16; +} + +@frozen +public struct F80_S1_S0_S0 +{ + public let f0 : UInt8; +} + +@frozen +public struct F80_S1_S0 +{ + public let f0 : F80_S1_S0_S0; +} + +@frozen +public struct F80_S1 +{ + public let f0 : Int; + public let f1 : F80_S1_S0; +} + +@frozen +public struct F80_S2 +{ + public let f0 : UInt64; +} + +public func swiftCallbackFunc80(f: (UInt64, Int, Int32, Int16, UInt, F80_S0, Int16, Int, Int8, Int32, UInt32, F80_S1, F80_S2, UInt64) -> Float) -> Float { + return f(4470427843910624516, 8383677749057878551, 2017117925, -10531, 3438375001906177611, F80_S0(f0: 65220), 7107, 7315288835693680178, -48, 813870434, 1092037477, F80_S1(f0: 7104962838387954470, f1: F80_S1_S0(f0: F80_S1_S0_S0(f0: 236))), F80_S2(f0: 7460392384225808790), 364121728483540667) +} + +@frozen +public struct F81_S0 +{ + public let f0 : Float; + public let f1 : Float; + public let f2 : Int; + public let f3 : Int; + public let f4 : Int; +} + +@frozen +public struct F81_Ret +{ + public let f0 : Int; +} + +public func swiftCallbackFunc81(f: (UInt8, UInt32, UInt8, F81_S0, Int8) -> F81_Ret) -> F81_Ret { + return f(53, 57591489, 19, F81_S0(f0: 5675845, f1: 6469988, f2: 5775316279348621124, f3: 7699091894067057939, f4: 1049086627558950131), 15) +} + +@frozen +public struct F82_S0_S0 +{ + public let f0 : Float; + public let f1 : UInt; + public let f2 : UInt16; +} + +@frozen +public struct F82_S0 +{ + public let f0 : UInt; + public let f1 : F82_S0_S0; + public let f2 : UInt16; +} + +@frozen +public struct F82_S1 +{ + public let f0 : Int32; +} + +@frozen +public struct F82_S2 +{ + public let f0 : Int; +} + +@frozen +public struct F82_S3_S0 +{ + public let f0 : Int32; +} + +@frozen +public struct F82_S3 +{ + public let f0 : Double; + public let f1 : UInt; + public let f2 : F82_S3_S0; +} + +@frozen +public struct F82_S4 +{ + public let f0 : UInt64; +} + +public func swiftCallbackFunc82(f: (Int64, F82_S0, Int16, Int8, UInt32, F82_S1, Int32, Int64, Int8, Double, F82_S2, F82_S3, F82_S4) -> Float) -> Float { + return f(6454754584537364459, F82_S0(f0: 6703634779264968131, f1: F82_S0_S0(f0: 1010059, f1: 4772968591609202284, f2: 64552), f2: 47126), 9869, -8, 1741550381, F82_S1(f0: 705741282), 1998781399, 7787961471254401526, -27, 4429830670351707, F82_S2(f0: 4975772762589349422), F82_S3(f0: 1423948098664774, f1: 504607538824251986, f2: F82_S3_S0(f0: 1940911018)), F82_S4(f0: 2988623645681463667)) +} + +@frozen +public struct F83_S0 +{ + public let f0 : Int32; +} + +@frozen +public struct F83_Ret +{ + public let f0 : Int16; +} + +public func swiftCallbackFunc83(f: (Int8, F83_S0, Int16) -> F83_Ret) -> F83_Ret { + return f(17, F83_S0(f0: 530755056), -11465) +} + +@frozen +public struct F84_S0 +{ + public let f0 : UInt; + public let f1 : UInt32; + public let f2 : UInt; + public let f3 : UInt64; + public let f4 : Int32; +} + +@frozen +public struct F84_S1 +{ + public let f0 : UInt; +} + +@frozen +public struct F84_S2 +{ + public let f0 : Float; +} + +@frozen +public struct F84_S3 +{ + public let f0 : UInt8; +} + +@frozen +public struct F84_S4 +{ + public let f0 : Int16; +} + +@frozen +public struct F84_S5 +{ + public let f0 : Int; + public let f1 : Int16; +} + +@frozen +public struct F84_S6 +{ + public let f0 : Int16; +} + +@frozen +public struct F84_S7 +{ + public let f0 : Int32; +} + +public func swiftCallbackFunc84(f: (Int32, F84_S0, F84_S1, Double, Int32, Int16, Double, F84_S2, F84_S3, Double, F84_S4, F84_S5, F84_S6, F84_S7, UInt) -> Int) -> Int { + return f(1605022009, F84_S0(f0: 6165049220831866664, f1: 1235491183, f2: 7926620970405586826, f3: 2633248816907294140, f4: 2012834055), F84_S1(f0: 2881830362339122988), 4065309434963087, 1125165825, -32360, 1145602045200029, F84_S2(f0: 5655563), F84_S3(f0: 14), 3919593995303128, F84_S4(f0: 26090), F84_S5(f0: 8584898862398781737, f1: -5185), F84_S6(f0: 144), F84_S7(f0: 2138004352), 9102562043027810686) +} + +@frozen +public struct F85_S0 +{ + public let f0 : Double; + public let f1 : Double; + public let f2 : Int8; + public let f3 : Int32; +} + +@frozen +public struct F85_S1 +{ + public let f0 : Int64; + public let f1 : UInt16; + public let f2 : UInt64; + public let f3 : UInt; +} + +@frozen +public struct F85_S2 +{ + public let f0 : Float; + public let f1 : Float; + public let f2 : UInt32; +} + +@frozen +public struct F85_S3 +{ + public let f0 : UInt8; +} + +@frozen +public struct F85_S4 +{ + public let f0 : UInt; +} + +@frozen +public struct F85_S5 +{ + public let f0 : Double; +} + +@frozen +public struct F85_Ret +{ + public let f0 : UInt32; + public let f1 : UInt16; + public let f2 : Int32; + public let f3 : Double; + public let f4 : Int; + public let f5 : UInt64; + public let f6 : Int64; +} + +public func swiftCallbackFunc85(f: (F85_S0, F85_S1, UInt32, F85_S2, Int64, F85_S3, Int64, F85_S4, UInt16, UInt8, Int32, UInt32, Int32, Float, F85_S5, Int64) -> F85_Ret) -> F85_Ret { + return f(F85_S0(f0: 4325646965362202, f1: 3313084380250914, f2: 42, f3: 2034100272), F85_S1(f0: 1365643665271339575, f1: 25442, f2: 3699631470459352980, f3: 7611776251925132200), 911446742, F85_S2(f0: 352423, f1: 7150341, f2: 2090089360), 5731257538910387688, F85_S3(f0: 171), 5742887585483060342, F85_S4(f0: 1182236975680416316), 32137, 44, 2143531010, 1271996557, 1035188446, 1925443, F85_S5(f0: 2591574394337603), 721102428782331317) +} + +@frozen +public struct F86_S0 +{ + public let f0 : Int; + public let f1 : Float; + public let f2 : Int16; + public let f3 : Int8; +} + +@frozen +public struct F86_S1 +{ + public let f0 : Double; +} + +@frozen +public struct F86_S2 +{ + public let f0 : Int; + public let f1 : Float; +} + +@frozen +public struct F86_S3 +{ + public let f0 : UInt16; + public let f1 : Float; +} + +@frozen +public struct F86_Ret +{ + public let f0 : Int16; + public let f1 : UInt32; + public let f2 : Double; + public let f3 : UInt8; +} + +public func swiftCallbackFunc86(f: (Float, Int16, Int, Int16, Float, F86_S0, F86_S1, F86_S2, Int, UInt32, UInt, UInt, Float, Int64, F86_S3, UInt) -> F86_Ret) -> F86_Ret { + return f(2913632, 3735, 2773655476379499086, 22973, 8292778, F86_S0(f0: 5562042565258891920, f1: 8370233, f2: 18292, f3: -32), F86_S1(f0: 486951152980016), F86_S2(f0: 170033426151098456, f1: 3867810), 7390780928011218856, 1504267943, 2046987193814931100, 4860202472307588968, 1644019, 8084012412562897328, F86_S3(f0: 46301, f1: 5633701), 1911608136082175332) +} + +@frozen +public struct F87_S0 +{ + public let f0 : Int32; + public let f1 : Int16; + public let f2 : Int32; +} + +@frozen +public struct F87_S1 +{ + public let f0 : Float; +} + +public func swiftCallbackFunc87(f: (Float, Int, F87_S0, F87_S1) -> UInt64) -> UInt64 { + return f(1413086, 4206825694012787823, F87_S0(f0: 70240457, f1: 30503, f2: 671751848), F87_S1(f0: 6641304)) +} + +@frozen +public struct F88_S0 +{ + public let f0 : Int8; + public let f1 : Int16; + public let f2 : UInt8; + public let f3 : Double; + public let f4 : UInt16; +} + +@frozen +public struct F88_S1 +{ + public let f0 : Double; + public let f1 : UInt8; +} + +@frozen +public struct F88_S2 +{ + public let f0 : UInt; +} + +@frozen +public struct F88_S3 +{ + public let f0 : Int8; + public let f1 : UInt32; +} + +@frozen +public struct F88_Ret +{ + public let f0 : Int32; + public let f1 : UInt32; + public let f2 : Int; + public let f3 : UInt64; +} + +public func swiftCallbackFunc88(f: (F88_S0, F88_S1, Float, UInt, Float, Int, F88_S2, UInt64, F88_S3, UInt64) -> F88_Ret) -> F88_Ret { + return f(F88_S0(f0: 125, f1: -10705, f2: 21, f3: 361845689097003, f4: 41749), F88_S1(f0: 1754583995806427, f1: 178), 4705205, 5985040566226273121, 2484194, 1904196135427766362, F88_S2(f0: 5436710892090266406), 4250368992471675181, F88_S3(f0: -87, f1: 362108395), 3388632419732870796) +} + +@frozen +public struct F89_S0 +{ + public let f0 : Double; +} + +@frozen +public struct F89_Ret_S0 +{ + public let f0 : Double; +} + +@frozen +public struct F89_Ret +{ + public let f0 : Int32; + public let f1 : F89_Ret_S0; + public let f2 : UInt; + public let f3 : Int64; +} + +public func swiftCallbackFunc89(f: (F89_S0) -> F89_Ret) -> F89_Ret { + return f(F89_S0(f0: 2137010348736191)) +} + +@frozen +public struct F90_S0_S0_S0 +{ + public let f0 : UInt; +} + +@frozen +public struct F90_S0_S0 +{ + public let f0 : F90_S0_S0_S0; +} + +@frozen +public struct F90_S0 +{ + public let f0 : F90_S0_S0; + public let f1 : UInt; + public let f2 : UInt32; + public let f3 : Int64; + public let f4 : Int16; +} + +@frozen +public struct F90_S1 +{ + public let f0 : UInt16; + public let f1 : Int16; +} + +@frozen +public struct F90_S2 +{ + public let f0 : Int; +} + +@frozen +public struct F90_S3 +{ + public let f0 : UInt; +} + +@frozen +public struct F90_S4 +{ + public let f0 : UInt64; +} + +@frozen +public struct F90_Ret +{ + public let f0 : Int16; + public let f1 : Int; +} + +public func swiftCallbackFunc90(f: (Int64, Float, F90_S0, UInt32, UInt16, F90_S1, F90_S2, F90_S3, F90_S4) -> F90_Ret) -> F90_Ret { + return f(920081051198141017, 661904, F90_S0(f0: F90_S0_S0(f0: F90_S0_S0_S0(f0: 3898354148166517637)), f1: 1003118682503285076, f2: 1418362079, f3: 3276689793574299746, f4: -18559), 1773011602, 32638, F90_S1(f0: 47129, f1: -31849), F90_S2(f0: 4795020225668482328), F90_S3(f0: 5307513663902191175), F90_S4(f0: 7057074401404034083)) +} + +@frozen +public struct F91_S0 +{ + public let f0 : Int8; + public let f1 : Int; + public let f2 : UInt16; + public let f3 : UInt16; +} + +@frozen +public struct F91_S1 +{ + public let f0 : Double; + public let f1 : UInt64; + public let f2 : Int8; + public let f3 : Int64; + public let f4 : Float; +} + +@frozen +public struct F91_S2_S0_S0 +{ + public let f0 : Int64; +} + +@frozen +public struct F91_S2_S0 +{ + public let f0 : F91_S2_S0_S0; +} + +@frozen +public struct F91_S2 +{ + public let f0 : Double; + public let f1 : F91_S2_S0; + public let f2 : Int16; +} + +@frozen +public struct F91_S3_S0 +{ + public let f0 : UInt; +} + +@frozen +public struct F91_S3 +{ + public let f0 : F91_S3_S0; +} + +@frozen +public struct F91_Ret +{ + public let f0 : Int64; + public let f1 : UInt64; + public let f2 : Int16; + public let f3 : UInt32; +} + +public func swiftCallbackFunc91(f: (F91_S0, Int16, UInt32, Double, F91_S1, Int64, UInt64, Float, F91_S2, Int, F91_S3) -> F91_Ret) -> F91_Ret { + return f(F91_S0(f0: -117, f1: 6851485542307521521, f2: 23224, f3: 28870), -26318, 874052395, 3651199868446152, F91_S1(f0: 3201729800438540, f1: 7737032265509566019, f2: 123, f3: 7508633930609553617, f4: 8230501), 2726677037673277403, 4990410590084533996, 3864639, F91_S2(f0: 1763083442463892, f1: F91_S2_S0(f0: F91_S2_S0_S0(f0: 6783710957456602933)), f2: 2927), 3359440517385934325, F91_S3(f0: F91_S3_S0(f0: 3281136825102667421))) +} + +@frozen +public struct F92_S0 +{ + public let f0 : Double; + public let f1 : Double; +} + +@frozen +public struct F92_S1 +{ + public let f0 : UInt32; + public let f1 : Int64; + public let f2 : UInt32; + public let f3 : Int16; + public let f4 : UInt64; +} + +@frozen +public struct F92_S2_S0 +{ + public let f0 : UInt16; +} + +@frozen +public struct F92_S2 +{ + public let f0 : UInt32; + public let f1 : Int64; + public let f2 : F92_S2_S0; +} + +@frozen +public struct F92_Ret +{ + public let f0 : Int32; +} + +public func swiftCallbackFunc92(f: (UInt32, Int64, F92_S0, Int, UInt8, F92_S1, F92_S2, UInt8, Int, Int32) -> F92_Ret) -> F92_Ret { + return f(479487770, 3751818229732502126, F92_S0(f0: 3486664439392893, f1: 1451061144702448), 1103649059951788126, 17, F92_S1(f0: 1542537473, f1: 2256304993713022795, f2: 1773847876, f3: -4712, f4: 2811859744132572185), F92_S2(f0: 290315682, f1: 4847587202070249866, f2: F92_S2_S0(f0: 20774)), 8, 2206063999764082749, 1481391120) +} + +@frozen +public struct F93_S0 +{ + public let f0 : Int8; + public let f1 : UInt32; +} + +@frozen +public struct F93_S1 +{ + public let f0 : UInt32; +} + +@frozen +public struct F93_Ret +{ + public let f0 : Int; + public let f1 : UInt64; +} + +public func swiftCallbackFunc93(f: (UInt, UInt16, Double, F93_S0, F93_S1) -> F93_Ret) -> F93_Ret { + return f(5170226481546239050, 2989, 1630717078645270, F93_S0(f0: -46, f1: 859171256), F93_S1(f0: 254449240)) +} + +@frozen +public struct F94_S0 +{ + public let f0 : UInt; +} + +@frozen +public struct F94_S1 +{ + public let f0 : Int32; + public let f1 : UInt; +} + +@frozen +public struct F94_S2 +{ + public let f0 : Int; + public let f1 : UInt32; + public let f2 : UInt16; +} + +@frozen +public struct F94_S3 +{ + public let f0 : UInt8; + public let f1 : Int32; + public let f2 : Float; +} + +@frozen +public struct F94_S4 +{ + public let f0 : Int32; + public let f1 : Int64; + public let f2 : Float; +} + +@frozen +public struct F94_S5 +{ + public let f0 : Int16; + public let f1 : UInt; + public let f2 : Int16; + public let f3 : Int8; +} + +@frozen +public struct F94_Ret +{ + public let f0 : Int64; +} + +public func swiftCallbackFunc94(f: (F94_S0, Int16, F94_S1, F94_S2, F94_S3, Float, F94_S4, UInt32, F94_S5, Int16) -> F94_Ret) -> F94_Ret { + return f(F94_S0(f0: 8626725032375870186), -7755, F94_S1(f0: 544707027, f1: 2251410026467996594), F94_S2(f0: 2972912419231960385, f1: 740529487, f2: 34526), F94_S3(f0: 41, f1: 1598856955, f2: 5126603), 7242977, F94_S4(f0: 473684762, f1: 4023878650965716094, f2: 2777693), 1612378906, F94_S5(f0: -17074, f1: 2666903737827472071, f2: 418, f3: 106), -14547) +} + +@frozen +public struct F95_S0 +{ + public let f0 : UInt16; + public let f1 : Int64; +} + +@frozen +public struct F95_S1 +{ + public let f0 : UInt32; + public let f1 : Int16; + public let f2 : Double; +} + +@frozen +public struct F95_S2 +{ + public let f0 : UInt16; +} + +@frozen +public struct F95_Ret_S0 +{ + public let f0 : Int16; +} + +@frozen +public struct F95_Ret +{ + public let f0 : Int; + public let f1 : Int16; + public let f2 : Int8; + public let f3 : UInt8; + public let f4 : F95_Ret_S0; +} + +public func swiftCallbackFunc95(f: (F95_S0, UInt, F95_S1, F95_S2) -> F95_Ret) -> F95_Ret { + return f(F95_S0(f0: 45388, f1: 6620047889014935849), 97365157264460373, F95_S1(f0: 357234637, f1: -13720, f2: 3313430568949662), F95_S2(f0: 14248)) +} + +@frozen +public struct F96_S0 +{ + public let f0 : Int64; + public let f1 : UInt32; + public let f2 : Int16; + public let f3 : Double; + public let f4 : Double; +} + +@frozen +public struct F96_S1 +{ + public let f0 : UInt64; +} + +@frozen +public struct F96_S2 +{ + public let f0 : Float; +} + +public func swiftCallbackFunc96(f: (UInt32, F96_S0, Float, UInt64, UInt32, UInt32, F96_S1, F96_S2, Int64) -> UInt64) -> UInt64 { + return f(1103144790, F96_S0(f0: 496343164737276588, f1: 1541085564, f2: -16271, f3: 1062575289573718, f4: 570255786498865), 7616839, 7370881799887414383, 390392554, 1492692139, F96_S1(f0: 1666031716012978365), F96_S2(f0: 3427394), 4642371619161527189) +} + +@frozen +public struct F97_S0 +{ + public let f0 : Int8; +} + +@frozen +public struct F97_S1 +{ + public let f0 : Int64; + public let f1 : UInt64; +} + +@frozen +public struct F97_S2 +{ + public let f0 : UInt8; + public let f1 : Int64; +} + +@frozen +public struct F97_S3 +{ + public let f0 : Double; +} + +@frozen +public struct F97_Ret_S0 +{ + public let f0 : Int32; +} + +@frozen +public struct F97_Ret +{ + public let f0 : Double; + public let f1 : UInt; + public let f2 : F97_Ret_S0; + public let f3 : UInt16; + public let f4 : UInt32; +} + +public func swiftCallbackFunc97(f: (F97_S0, F97_S1, F97_S2, F97_S3) -> F97_Ret) -> F97_Ret { + return f(F97_S0(f0: -87), F97_S1(f0: 1414208343412494909, f1: 453284654311256466), F97_S2(f0: 224, f1: 1712859616922087053), F97_S3(f0: 3987671154739178)) +} + +@frozen +public struct F98_S0 +{ + public let f0 : Int32; +} + +public func swiftCallbackFunc98(f: (Float, UInt16, F98_S0, UInt16) -> Int) -> Int { + return f(2863898, 37573, F98_S0(f0: 1073068257), 53560) +} + +@frozen +public struct F99_S0 +{ + public let f0 : Int; + public let f1 : UInt32; + public let f2 : Int32; + public let f3 : UInt32; +} + +@frozen +public struct F99_S1 +{ + public let f0 : Int16; +} + +@frozen +public struct F99_S2 +{ + public let f0 : UInt8; } -public func swiftCallbackFunc9(f: (Int8, Int, Int16, Int64, Double, Double, Int, UInt16, UInt16, Float, Float, UInt16, UInt32, Int16, Int32, Int32, UInt64, Int16, Int64, Int, UInt8, UInt16, Int16, Int, Int16) -> F9_Ret) -> F9_Ret { - return f(17, 4720638462358523954, 30631, 8206569929240962953, 1359667226908383, 3776001892555053, 747160900180286726, 12700, 53813, 7860389, 1879743, 61400, 1962814337, 17992, 677814589, 1019483263, 6326265259403184370, -14633, 4127072498763789519, 4008108205305320386, 128, 21189, 32104, 384827814282870543, 20647) +public func swiftCallbackFunc99(f: (Int64, UInt, Float, UInt16, F99_S0, UInt8, Float, UInt8, Int8, F99_S1, F99_S2) -> UInt64) -> UInt64 { + return f(1152281003884062246, 2482384127373829622, 3361150, 2121, F99_S0(f0: 4484545590050696958, f1: 422528630, f2: 1418346646, f3: 1281567856), 223, 1917656, 103, -46, F99_S1(f0: 14554), F99_S2(f0: 68)) } From 925ad52fafea4bee0a4eec96e503dd73b5f4bb0a Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 27 Mar 2024 16:14:31 +0100 Subject: [PATCH 35/52] Nits --- src/coreclr/jit/compiler.h | 1 - src/coreclr/jit/lclvars.cpp | 8 -------- src/coreclr/jit/lsrabuild.cpp | 6 +++--- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 8179a3bd9108b1..a9dfa2cb60605a 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -3930,7 +3930,6 @@ class Compiler void lvaUpdateArgWithInitialReg(LclVarDsc* varDsc); void lvaUpdateArgsWithInitialReg(); void lvaAssignVirtualFrameOffsetsToArgs(); - void lvaAssignVirtualFrameOffsetsToSwiftFuncArgs(); #ifdef UNIX_AMD64_ABI int lvaAssignVirtualFrameOffsetToArg(unsigned lclNum, unsigned argSize, int argOffs, int* callerArgOffset); #else // !UNIX_AMD64_ABI diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 3c527e8e7ebeae..7ab2db3343f8ca 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -5992,14 +5992,6 @@ void Compiler::lvaAssignVirtualFrameOffsetsToArgs() #endif // USER_ARGS_COME_LAST } -//------------------------------------------------------------------------ -// lvaAssignVirtualFrameOffsetsToSwiftFuncArgs: -// Assign stack frame offsets for the arguments to a CallConvSwift function. -// -void Compiler::lvaAssignVirtualFrameOffsetsToSwiftFuncArgs() -{ -} - #ifdef UNIX_AMD64_ABI // // lvaAssignVirtualFrameOffsetToArg() : Assign virtual stack offsets to an diff --git a/src/coreclr/jit/lsrabuild.cpp b/src/coreclr/jit/lsrabuild.cpp index a13bea06f3c8e8..1d928f112655db 100644 --- a/src/coreclr/jit/lsrabuild.cpp +++ b/src/coreclr/jit/lsrabuild.cpp @@ -2529,9 +2529,9 @@ void LinearScan::buildIntervals() // For Swift calls there can be an arbitrary amount of codegen related // to homing of decomposed struct parameters passed on stack. We cannot - // do that in the prolog. We handle registers in the prolog but the - // stack args in the scratch BB that we have ensured exists. - // in the scratch BB, but need REG_SCRATCH for it. + // do that in the prolog. We handle registers in the prolog and the + // stack args in the scratch BB that we have ensured exists. The + // handling clobbers REG_SCRATCH, so kill it here. if ((block == compiler->fgFirstBB) && compiler->lvaHasAnySwiftStackParamToReassemble()) { assert(compiler->fgFirstBBisScratch()); From 12058f502046640404b2af5339df619dd3bf2c7f Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 2 Apr 2024 18:14:32 +0200 Subject: [PATCH 36/52] Return some dumping code --- src/coreclr/jit/abi.cpp | 33 +++++++++++++++++++++++++++++++++ src/coreclr/jit/abi.h | 4 ++++ src/coreclr/jit/lclvars.cpp | 8 ++++++++ 3 files changed, 45 insertions(+) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index 7d841a4373a3e7..c8cac2b0b6b54c 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -237,6 +237,39 @@ ABIPassingInformation ABIPassingInformation::FromSegment(Compiler* comp, const A return info; } +#ifdef DEBUG +//----------------------------------------------------------------------------- +// Dump: +// Dump the ABIPassingInformation to stdout. +// +void ABIPassingInformation::Dump() const +{ + if (NumSegments != 1) + { + printf("%u segments\n", NumSegments); + } + + for (unsigned i = 0; i < NumSegments; i++) + { + if (NumSegments > 1) + { + printf(" [%u] ", i); + } + + const ABIPassingSegment& seg = Segments[i]; + + if (Segments[i].IsPassedInRegister()) + { + printf("[%02u..%02u) reg %s\n", seg.Offset, seg.Offset + seg.Size, getRegName(seg.GetRegister())); + } + else + { + printf("[%02u..%02u) stack @ +%02u\n", seg.Offset, seg.Offset + seg.Size, seg.GetStackOffset()); + } + } +} +#endif + //----------------------------------------------------------------------------- // RegisterQueue::Dequeue: // Dequeue a register from the queue. diff --git a/src/coreclr/jit/abi.h b/src/coreclr/jit/abi.h index 21de667d9d9ede..af5fd466f01fe1 100644 --- a/src/coreclr/jit/abi.h +++ b/src/coreclr/jit/abi.h @@ -55,6 +55,10 @@ struct ABIPassingInformation bool IsSplitAcrossRegistersAndStack() const; static ABIPassingInformation FromSegment(Compiler* comp, const ABIPassingSegment& segment); + +#ifdef DEBUG + void Dump() const; +#endif }; class RegisterQueue diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index f79c5b845d8b50..7ab2db3343f8ca 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1663,6 +1663,14 @@ void Compiler::lvaClassifyParameterABI(Classifier& classifier) #endif lvaParameterPassingInfo[i] = classifier.Classify(this, dsc->TypeGet(), structLayout, wellKnownArg); + +#ifdef DEBUG + if (verbose) + { + printf("Parameter #%u ABI info: ", i); + lvaParameterPassingInfo[i].Dump(); + } +#endif } } From a901d9012bd5518e03571c42df4cf4607dd646b3 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 3 Apr 2024 12:13:17 +0200 Subject: [PATCH 37/52] Return code removed by mistake --- src/coreclr/jit/abi.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index c8cac2b0b6b54c..092bbbde5a09ad 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -339,6 +339,39 @@ ABIPassingInformation SwiftABIClassifier::Classify(Compiler* comp, TARGET_POINTER_SIZE)); } + if (type == TYP_STRUCT) + { + const CORINFO_SWIFT_LOWERING* lowering = comp->GetSwiftLowering(structLayout->GetClassHandle()); + if (lowering->byReference) + { + return m_classifier.Classify(comp, TYP_I_IMPL, nullptr, WellKnownArg::None); + } + + ArrayStack segments(comp->getAllocator(CMK_ABI)); + for (unsigned i = 0; i < lowering->numLoweredElements; i++) + { + var_types elemType = JITtype2varType(lowering->loweredElements[i]); + ABIPassingInformation elemInfo = m_classifier.Classify(comp, elemType, nullptr, WellKnownArg::None); + + for (unsigned j = 0; j < elemInfo.NumSegments; j++) + { + ABIPassingSegment newSegment = elemInfo.Segments[j]; + newSegment.Offset += lowering->offsets[i]; + segments.Push(newSegment); + } + } + + ABIPassingInformation result; + result.NumSegments = static_cast(segments.Height()); + result.Segments = new (comp, CMK_ABI) ABIPassingSegment[result.NumSegments]; + for (int i = 0; i < segments.Height(); i++) + { + result.Segments[i] = segments.Bottom(i); + } + + return result; + } + return m_classifier.Classify(comp, type, structLayout, wellKnownParam); } #endif From 06c4e1b33736ce5c42a3d207c382048b177ee3f6 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 2 Apr 2024 21:16:02 +0200 Subject: [PATCH 38/52] Fix arm64 varargs bug, small formatting nit --- src/coreclr/jit/compiler.h | 8 ++++---- src/coreclr/jit/lclvars.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 3f60e88c80078f..0366895ad75e5f 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -5807,10 +5807,10 @@ class Compiler // isVarArg is passed for use on Windows Arm64 to change the decision returned regarding // hfa types. // - var_types getArgTypeForStruct(CORINFO_CLASS_HANDLE clsHnd, - structPassingKind* wbPassStruct, - bool isVarArg, - unsigned structSize); + var_types getArgTypeForStruct(CORINFO_CLASS_HANDLE clsHnd, + structPassingKind* wbPassStruct, + bool isVarArg, + unsigned structSize); // Get the type that is used to return values of the given struct type. // If the size is unknown, pass 0 and it will be determined from 'clsHnd'. diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 7ab2db3343f8ca..b591a258dd0b79 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -6997,7 +6997,7 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals() if (varDsc->lvIsParam) { #ifdef TARGET_ARM64 - if (info.compIsVarArgs && (varDsc->GetArgReg() != theFixedRetBuffReg(info.compCallConv))) + if (info.compIsVarArgs && varDsc->lvIsRegArg && (varDsc->GetArgReg() != theFixedRetBuffReg(info.compCallConv))) { // Stack offset to varargs (parameters) should point to home area which will be preallocated. const unsigned regArgNum = genMapIntRegNumToRegArgNum(varDsc->GetArgReg(), info.compCallConv); From c8dd128c710327b152e29e6783264647ad23b1aa Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 3 Apr 2024 12:17:16 +0200 Subject: [PATCH 39/52] Run jit-format --- src/coreclr/jit/lclvars.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index b591a258dd0b79..701cb8bbe2629c 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -6997,7 +6997,8 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals() if (varDsc->lvIsParam) { #ifdef TARGET_ARM64 - if (info.compIsVarArgs && varDsc->lvIsRegArg && (varDsc->GetArgReg() != theFixedRetBuffReg(info.compCallConv))) + if (info.compIsVarArgs && varDsc->lvIsRegArg && + (varDsc->GetArgReg() != theFixedRetBuffReg(info.compCallConv))) { // Stack offset to varargs (parameters) should point to home area which will be preallocated. const unsigned regArgNum = genMapIntRegNumToRegArgNum(varDsc->GetArgReg(), info.compCallConv); From 3f5070833d5c412bd0fe64207bc4bfab54c0e9b6 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 3 Apr 2024 14:01:10 +0200 Subject: [PATCH 40/52] Refactor to fix TP --- src/coreclr/jit/morph.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index d342a85a324486..35cd21fdd1a9c1 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -4019,7 +4019,7 @@ void Compiler::fgMakeOutgoingStructArgCopy(GenTreeCall* call, CallArg* arg) GenTree* argNode = call->gtArgs.MakeTmpArgNode(this, arg); // Change the expression to "(tmp=val),tmp" - argNode = gtNewOperNode(GT_COMMA, argNode->TypeGet(), copyBlk, argNode); + argNode = gtNewOperNode(GT_COMMA, argNode->TypeGet(), copyBlk, argNode); #endif // !FEATURE_FIXED_OUT_ARGS @@ -4622,17 +4622,15 @@ GenTree* Compiler::fgMorphExpandStackArgForVarArgs(GenTreeLclVarCommon* lclNode) // GenTree* Compiler::fgMorphExpandImplicitByRefArg(GenTreeLclVarCommon* lclNode) { - if (!fgGlobalMorph) - { - return nullptr; - } - unsigned lclNum = lclNode->GetLclNum(); LclVarDsc* varDsc = lvaGetDesc(lclNum); unsigned fieldOffset = 0; unsigned newLclNum = BAD_VAR_NUM; bool isStillLastUse = false; + assert(lvaIsImplicitByRefLocal(lclNum) || + (varDsc->lvIsStructField && lvaIsImplicitByRefLocal(varDsc->lvParentLcl))); + if (lvaIsImplicitByRefLocal(lclNum)) { // The SIMD transformation to coalesce contiguous references to SIMD vector fields will re-invoke @@ -4682,16 +4680,12 @@ GenTree* Compiler::fgMorphExpandImplicitByRefArg(GenTreeLclVarCommon* lclNode) } } } - else if (varDsc->lvIsStructField && lvaIsImplicitByRefLocal(varDsc->lvParentLcl)) + else { // This was a field reference to an implicit-by-reference struct parameter that was dependently promoted. newLclNum = varDsc->lvParentLcl; fieldOffset = varDsc->lvFldOffset; } - else - { - return nullptr; - } // Add a level of indirection to this node. The "base" will be a local node referring to "newLclNum". // We will also add an offset, and, if the original "lclNode" represents a location, a dereference. @@ -4753,7 +4747,16 @@ GenTree* Compiler::fgMorphExpandLocal(GenTreeLclVarCommon* lclNode) #ifdef TARGET_X86 expandedTree = fgMorphExpandStackArgForVarArgs(lclNode); #else - expandedTree = fgMorphExpandImplicitByRefArg(lclNode); +#if FEATURE_IMPLICIT_BYREFS + if (fgGlobalMorph) + { + LclVarDsc* dsc = lvaGetDesc(lclNode); + if (dsc->lvIsImplicitByRef || (dsc->lvIsStructField && lvaIsImplicitByRefLocal(dsc->lvParentLcl))) + { + expandedTree = fgMorphExpandImplicitByRefArg(lclNode); + } + } +#endif #endif if (expandedTree != nullptr) @@ -14961,7 +14964,7 @@ PhaseStatus Compiler::fgPromoteStructs() // PhaseStatus Compiler::fgMarkImplicitByRefCopyOmissionCandidates() { -#if FEATURE_IMPLICIT_BYREFS +#if FEATURE_IMPLICIT_BYREFS && !defined(UNIX_AMD64_ABI) if (!fgDidEarlyLiveness) { return PhaseStatus::MODIFIED_NOTHING; From 09c0c1f59c757147e15801257422c3831b344e57 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 3 Apr 2024 14:57:59 +0200 Subject: [PATCH 41/52] Fixes for no refs case --- src/coreclr/jit/abi.cpp | 22 ++++++++++++++++++++++ src/coreclr/jit/abi.h | 2 ++ src/coreclr/jit/codegencommon.cpp | 20 ++++++++++---------- src/coreclr/jit/lclvars.cpp | 2 +- src/coreclr/jit/lsrabuild.cpp | 2 +- 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index 092bbbde5a09ad..aa6ebea00f2653 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -41,6 +41,28 @@ regNumber ABIPassingSegment::GetRegister() const return m_register; } +//----------------------------------------------------------------------------- +// GetRegisterMask: +// Get the mask of registers that this segment is passed in. +// +// Return Value: +// The register mask. +// +regMaskTP ABIPassingSegment::GetRegisterMask() const +{ + assert(IsPassedInRegister()); + regMaskTP reg = genRegMask(m_register); + +#ifdef TARGET_ARM + if (varTypeIsFloating(m_register) && (Size == 8)) + { + reg |= genRegMask(REG_NEXT(m_register)); + } +#endif + + return reg; +} + //----------------------------------------------------------------------------- // GetStackOffset: // Get the stack offset where this segment is passed. diff --git a/src/coreclr/jit/abi.h b/src/coreclr/jit/abi.h index af5fd466f01fe1..7ec819f6ddce31 100644 --- a/src/coreclr/jit/abi.h +++ b/src/coreclr/jit/abi.h @@ -25,6 +25,8 @@ class ABIPassingSegment // If this segment is passed in a register, return the particular register. regNumber GetRegister() const; + regMaskTP GetRegisterMask() const; + // If this segment is passed on the stack then return the particular stack // offset, relative to the first stack argument's offset. unsigned GetStackOffset() const; diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 916f1b8b104ac6..f44b9f171d98c6 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -5016,18 +5016,17 @@ void CodeGen::genHomeSwiftStructParameters(bool handleStack, regNumber scratchRe if (seg.IsPassedInRegister()) { - var_types storeType = seg.GetRegisterStoreType(); - assert(storeType != TYP_UNDEF); - GetEmitter()->emitIns_S_R(ins_Store(storeType), emitTypeSize(storeType), seg.GetRegister(), lclNum, - seg.Offset); + RegState* regState = genIsValidFloatReg(seg.GetRegister()) ? &floatRegState : &intRegState; + regMaskTP regs = seg.GetRegisterMask(); - if (genIsValidFloatReg(seg.GetRegister())) + if ((regState->rsCalleeRegArgMaskLiveIn & regs) != RBM_NONE) { - floatRegState.rsCalleeRegArgMaskLiveIn &= ~genRegMask(seg.GetRegister()); - } - else - { - intRegState.rsCalleeRegArgMaskLiveIn &= ~genRegMask(seg.GetRegister()); + var_types storeType = seg.GetRegisterStoreType(); + assert(storeType != TYP_UNDEF); + GetEmitter()->emitIns_S_R(ins_Store(storeType), emitTypeSize(storeType), seg.GetRegister(), lclNum, + seg.Offset); + + regState->rsCalleeRegArgMaskLiveIn &= ~regs; } } else @@ -5064,6 +5063,7 @@ void CodeGen::genHomeSwiftStructParameters(bool handleStack, regNumber scratchRe offset += (int)seg.GetStackOffset(); + assert(dsc->lvOnFrame); #ifdef TARGET_XARCH GetEmitter()->emitIns_R_AR(ins_Load(loadType), emitTypeSize(loadType), scratchReg, genFramePointerReg(), offset); diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 701cb8bbe2629c..b5c83a024abdaf 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1741,7 +1741,7 @@ void Compiler::lvaClassifyParameterABI() const ABIPassingSegment& segment = abiInfo.Segments[i]; if (segment.IsPassedInRegister()) { - argRegs |= genRegMask(segment.GetRegister()); + argRegs |= segment.GetRegisterMask(); } } } diff --git a/src/coreclr/jit/lsrabuild.cpp b/src/coreclr/jit/lsrabuild.cpp index 1d928f112655db..d75e4704859c2c 100644 --- a/src/coreclr/jit/lsrabuild.cpp +++ b/src/coreclr/jit/lsrabuild.cpp @@ -2302,7 +2302,7 @@ void LinearScan::buildIntervals() if (seg.IsPassedInRegister()) { RegState* regState = genIsValidFloatReg(seg.GetRegister()) ? floatRegState : intRegState; - regState->rsCalleeRegArgMaskLiveIn |= genRegMask(seg.GetRegister()); + regState->rsCalleeRegArgMaskLiveIn |= seg.GetRegisterMask(); } } } From 80343cd09342d86bc0e35f1f20a0b05e669fcbb8 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 3 Apr 2024 15:01:41 +0200 Subject: [PATCH 42/52] Fix build --- src/coreclr/jit/abi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/abi.cpp b/src/coreclr/jit/abi.cpp index aa6ebea00f2653..066373415986fc 100644 --- a/src/coreclr/jit/abi.cpp +++ b/src/coreclr/jit/abi.cpp @@ -54,7 +54,7 @@ regMaskTP ABIPassingSegment::GetRegisterMask() const regMaskTP reg = genRegMask(m_register); #ifdef TARGET_ARM - if (varTypeIsFloating(m_register) && (Size == 8)) + if (genIsValidFloatReg(m_register) && (Size == 8)) { reg |= genRegMask(REG_NEXT(m_register)); } From ba7da24d0ee97f1d376aef121ee8d520a02962a6 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 3 Apr 2024 15:04:04 +0200 Subject: [PATCH 43/52] Another assert --- src/coreclr/jit/codegencommon.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index f44b9f171d98c6..31fd095d297807 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -5019,6 +5019,7 @@ void CodeGen::genHomeSwiftStructParameters(bool handleStack, regNumber scratchRe RegState* regState = genIsValidFloatReg(seg.GetRegister()) ? &floatRegState : &intRegState; regMaskTP regs = seg.GetRegisterMask(); + assert(dsc->lvOnFrame); if ((regState->rsCalleeRegArgMaskLiveIn & regs) != RBM_NONE) { var_types storeType = seg.GetRegisterStoreType(); From 59294258417c1ee61db57f4ac9d62bd62186fd2a Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 3 Apr 2024 15:35:36 +0200 Subject: [PATCH 44/52] Maybe that does it --- src/coreclr/jit/codegencommon.cpp | 3 +-- src/coreclr/jit/lclvars.cpp | 25 +++++++++++++------------ src/coreclr/jit/lsrabuild.cpp | 7 +++++++ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 31fd095d297807..bb4e0d2dc16639 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -4997,7 +4997,7 @@ void CodeGen::genHomeSwiftStructParameters(bool handleStack, regNumber scratchRe } LclVarDsc* dsc = compiler->lvaGetDesc(lclNum); - if ((dsc->TypeGet() != TYP_STRUCT) || compiler->lvaIsImplicitByRefLocal(lclNum)) + if ((dsc->TypeGet() != TYP_STRUCT) || compiler->lvaIsImplicitByRefLocal(lclNum) || !dsc->lvOnFrame) { continue; } @@ -5019,7 +5019,6 @@ void CodeGen::genHomeSwiftStructParameters(bool handleStack, regNumber scratchRe RegState* regState = genIsValidFloatReg(seg.GetRegister()) ? &floatRegState : &intRegState; regMaskTP regs = seg.GetRegisterMask(); - assert(dsc->lvOnFrame); if ((regState->rsCalleeRegArgMaskLiveIn & regs) != RBM_NONE) { var_types storeType = seg.GetRegisterStoreType(); diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index b5c83a024abdaf..2889ba7439195a 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -2418,6 +2418,17 @@ bool Compiler::StructPromotionHelper::CanPromoteStructVar(unsigned lclNum) return false; } +#ifdef SWIFT_SUPPORT + // Swift structs are not passed in a way that match their layout and + // require reassembling on the local stack frame. Skip promotion for these + // (which would result in dependent promotion anyway). + if ((compiler->info.compCallConv == CorInfoCallConvExtension::Swift) && varDsc->lvIsParam) + { + JITDUMP(" struct promotion of V%02u is disabled because it is a parameter to a Swift function"); + return false; + } +#endif + CORINFO_CLASS_HANDLE typeHnd = varDsc->GetLayout()->GetClassHandle(); assert(typeHnd != NO_CLASS_HANDLE); @@ -7280,19 +7291,9 @@ bool Compiler::lvaParamShouldHaveLocalStackSpace(unsigned lclNum) LclVarDsc* varDsc = lvaGetDesc(lclNum); #ifdef SWIFT_SUPPORT - // In Swift functions, struct parameters that aren't passed in a single - // stack segment are always reassembled on the local stack frame since they - // are passed in a way that does not match their full layout. - if (info.compCallConv == CorInfoCallConvExtension::Swift) + if ((info.compCallConv == CorInfoCallConvExtension::Swift) && !lvaIsImplicitByRefLocal(lclNum) && !lvaParameterPassingInfo[lclNum].HasExactlyOneStackSegment()) { - unsigned baseLclNum = varDsc->lvIsStructField ? varDsc->lvParentLcl : lclNum; - LclVarDsc* baseDsc = lvaGetDesc(baseLclNum); - - if ((baseDsc->TypeGet() == TYP_STRUCT) && !lvaIsImplicitByRefLocal(baseLclNum) && - !lvaParameterPassingInfo[baseLclNum].HasExactlyOneStackSegment()) - { - return true; - } + return true; } #endif diff --git a/src/coreclr/jit/lsrabuild.cpp b/src/coreclr/jit/lsrabuild.cpp index d75e4704859c2c..cad871c79d26df 100644 --- a/src/coreclr/jit/lsrabuild.cpp +++ b/src/coreclr/jit/lsrabuild.cpp @@ -2295,6 +2295,13 @@ void LinearScan::buildIntervals() { for (unsigned lclNum = 0; lclNum < compiler->info.compArgsCount; lclNum++) { + LclVarDsc* argDsc = compiler->lvaGetDesc(lclNum); + + if ((argDsc->lvRefCnt() == 0) && !compiler->opts.compDbgCode) + { + continue; + } + const ABIPassingInformation& abiInfo = compiler->lvaParameterPassingInfo[lclNum]; for (unsigned i = 0; i < abiInfo.NumSegments; i++) { From 0bf62c0c152d988cf35e8b7b2e40644c9a276c0b Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 3 Apr 2024 15:42:25 +0200 Subject: [PATCH 45/52] Run jit-format --- src/coreclr/jit/lclvars.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 2889ba7439195a..c0fa5d133f49ab 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -7291,7 +7291,8 @@ bool Compiler::lvaParamShouldHaveLocalStackSpace(unsigned lclNum) LclVarDsc* varDsc = lvaGetDesc(lclNum); #ifdef SWIFT_SUPPORT - if ((info.compCallConv == CorInfoCallConvExtension::Swift) && !lvaIsImplicitByRefLocal(lclNum) && !lvaParameterPassingInfo[lclNum].HasExactlyOneStackSegment()) + if ((info.compCallConv == CorInfoCallConvExtension::Swift) && !lvaIsImplicitByRefLocal(lclNum) && + !lvaParameterPassingInfo[lclNum].HasExactlyOneStackSegment()) { return true; } From 955e5bffc2c9d1253b8de1dd8d2f437c3c9724f0 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 3 Apr 2024 16:01:09 +0200 Subject: [PATCH 46/52] Clean up --- src/coreclr/jit/codegen.h | 2 +- src/coreclr/jit/codegencommon.cpp | 25 ++++++++++--------------- src/coreclr/jit/codegenlinear.cpp | 2 +- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/coreclr/jit/codegen.h b/src/coreclr/jit/codegen.h index b559c0fdce6867..5cb4950db3537f 100644 --- a/src/coreclr/jit/codegen.h +++ b/src/coreclr/jit/codegen.h @@ -277,7 +277,7 @@ class CodeGen final : public CodeGenInterface void genEnregisterOSRArgsAndLocals(); #endif - void genHomeSwiftStructParameters(bool handleStack, regNumber scratchReg, bool* scratchRegClobbered); + void genHomeSwiftStructParameters(bool handleStack); void genCheckUseBlockInit(); #if defined(UNIX_AMD64_ABI) && defined(FEATURE_SIMD) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index bb4e0d2dc16639..03aec0b100c194 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -4984,10 +4984,8 @@ void CodeGen::genEnregisterOSRArgsAndLocals() // Parameters: // handleStack - If true, reassemble the segments that were passed on the stack. // If false, reassemble the segments that were passed in registers. -// scratchReg - A scratch register to use -// scratchRegClobbered - [out] if scratchReg is used, this will be set to true. Otherwise will not be set. // -void CodeGen::genHomeSwiftStructParameters(bool handleStack, regNumber scratchReg, bool* scratchRegClobbered) +void CodeGen::genHomeSwiftStructParameters(bool handleStack) { for (unsigned lclNum = 0; lclNum < compiler->info.compArgsCount; lclNum++) { @@ -5063,17 +5061,19 @@ void CodeGen::genHomeSwiftStructParameters(bool handleStack, regNumber scratchRe offset += (int)seg.GetStackOffset(); + // Move the incoming segment to the local stack frame. We can + // use REG_SCRATCH as a temporary register here as we ensured + // that during LSRA build. assert(dsc->lvOnFrame); #ifdef TARGET_XARCH - GetEmitter()->emitIns_R_AR(ins_Load(loadType), emitTypeSize(loadType), scratchReg, genFramePointerReg(), - offset); + GetEmitter()->emitIns_R_AR(ins_Load(loadType), emitTypeSize(loadType), REG_SCRATCH, + genFramePointerReg(), offset); #else - genInstrWithConstant(ins_Load(loadType), emitTypeSize(loadType), scratchReg, genFramePointerReg(), - offset, scratchReg); + genInstrWithConstant(ins_Load(loadType), emitTypeSize(loadType), REG_SCRATCH, genFramePointerReg(), + offset, REG_SCRATCH); #endif - *scratchRegClobbered = true; - GetEmitter()->emitIns_S_R(ins_Store(loadType), emitTypeSize(loadType), scratchReg, lclNum, seg.Offset); + GetEmitter()->emitIns_S_R(ins_Store(loadType), emitTypeSize(loadType), REG_SCRATCH, lclNum, seg.Offset); } } } @@ -6354,12 +6354,7 @@ void CodeGen::genFnProlog() intRegState.rsCalleeRegArgMaskLiveIn &= ~RBM_SWIFT_SELF; } - bool clobbered = false; - genHomeSwiftStructParameters(/* handleStack */ false, initReg, &clobbered); - if (clobbered) - { - initRegZeroed = false; - } + genHomeSwiftStructParameters(/* handleStack */ false); } #endif diff --git a/src/coreclr/jit/codegenlinear.cpp b/src/coreclr/jit/codegenlinear.cpp index 18fdf0b202ac36..1739ef6f676ae4 100644 --- a/src/coreclr/jit/codegenlinear.cpp +++ b/src/coreclr/jit/codegenlinear.cpp @@ -393,7 +393,7 @@ void CodeGen::genCodeForBBlist() if (compiler->fgBBisScratch(block) && compiler->lvaHasAnySwiftStackParamToReassemble()) { bool clobbered = false; - genHomeSwiftStructParameters(/* handleStack */ true, REG_SCRATCH, &clobbered); + genHomeSwiftStructParameters(/* handleStack */ true); } #endif From efc56374832e33e48daeeebec4219b39300a8386 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 3 Apr 2024 16:42:38 +0200 Subject: [PATCH 47/52] Fix an x64 assert --- src/coreclr/jit/compiler.h | 2 +- src/coreclr/jit/emitxarch.cpp | 2 +- src/coreclr/jit/lclvars.cpp | 22 ++++++---------------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 0366895ad75e5f..2ca525efcd5c4f 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -3944,7 +3944,7 @@ class Compiler int lvaAssignVirtualFrameOffsetToArg(unsigned lclNum, unsigned argSize, int argOffs); #endif // !UNIX_AMD64_ABI void lvaAssignVirtualFrameOffsetsToLocals(); - bool lvaParamShouldHaveLocalStackSpace(unsigned lclNum); + bool lvaParamHasLocalStackSpace(unsigned lclNum); int lvaAllocLocalAndSetVirtualOffset(unsigned lclNum, unsigned size, int stkOffs); #ifdef TARGET_AMD64 // Returns true if compCalleeRegsPushed (including RBP if used as frame pointer) is even. diff --git a/src/coreclr/jit/emitxarch.cpp b/src/coreclr/jit/emitxarch.cpp index 379e94739b19b4..6a6c9b8dd2fe7f 100644 --- a/src/coreclr/jit/emitxarch.cpp +++ b/src/coreclr/jit/emitxarch.cpp @@ -3827,7 +3827,7 @@ inline UNATIVE_OFFSET emitter::emitInsSizeSVCalcDisp(instrDesc* id, code_t code, /* Is this a stack parameter reference? */ - if ((emitComp->lvaIsParameter(var) && !emitComp->lvaParamShouldHaveLocalStackSpace(var)) || + if ((emitComp->lvaIsParameter(var) && !emitComp->lvaParamHasLocalStackSpace(var)) || (static_cast(var) == emitComp->lvaRetAddrVar)) { /* If no EBP frame, arguments and ret addr are off of ESP, above temps */ diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index c0fa5d133f49ab..101b08b0251676 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -5621,17 +5621,7 @@ void Compiler::lvaFixVirtualFrameOffsets() if (!varDsc->lvOnFrame) { - if (!varDsc->lvIsParam -#if !defined(TARGET_AMD64) - || (varDsc->lvIsRegArg -#if defined(TARGET_ARM) && defined(PROFILING_SUPPORTED) - && compIsProfilerHookNeeded() && - !lvaIsPreSpilled(lclNum, codeGen->regSet.rsMaskPreSpillRegs(false)) // We need assign stack offsets - // for prespilled arguments -#endif - ) -#endif // !defined(TARGET_AMD64) - ) + if (!varDsc->lvIsParam || lvaParamHasLocalStackSpace(lclNum)) { doAssignStkOffs = false; // Not on frame or an incoming stack arg } @@ -7018,7 +7008,7 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals() } #endif - if (!lvaParamShouldHaveLocalStackSpace(lclNum)) + if (!lvaParamHasLocalStackSpace(lclNum)) { continue; } @@ -7276,17 +7266,17 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals() } //------------------------------------------------------------------------ -// lvaParamShouldHaveLocalStackSpace: Check if a local that represents a -// parameter should be allocated as part of the locals space. +// lvaParamHasLocalStackSpace: Check if a local that represents a parameter has +// space allocated for it in the local stack frame. // // Arguments: // lclNum - the variable number // // Return Value: -// true if the local does not have reusable stack space passed by the caller +// true if the local does not have reusable stack space created by the caller // already. // -bool Compiler::lvaParamShouldHaveLocalStackSpace(unsigned lclNum) +bool Compiler::lvaParamHasLocalStackSpace(unsigned lclNum) { LclVarDsc* varDsc = lvaGetDesc(lclNum); From c4874e09b8a676aa17567195d19aad8831517ab4 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 3 Apr 2024 16:56:10 +0200 Subject: [PATCH 48/52] Clean up --- src/coreclr/jit/codegencommon.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 03aec0b100c194..7bce45d68533dd 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -4982,8 +4982,8 @@ void CodeGen::genEnregisterOSRArgsAndLocals() // Reassemble Swift struct parameters if necessary. // // Parameters: -// handleStack - If true, reassemble the segments that were passed on the stack. -// If false, reassemble the segments that were passed in registers. +// handleStack - If true, reassemble the segments that were passed on the stack. +// If false, reassemble the segments that were passed in registers. // void CodeGen::genHomeSwiftStructParameters(bool handleStack) { @@ -5064,7 +5064,6 @@ void CodeGen::genHomeSwiftStructParameters(bool handleStack) // Move the incoming segment to the local stack frame. We can // use REG_SCRATCH as a temporary register here as we ensured // that during LSRA build. - assert(dsc->lvOnFrame); #ifdef TARGET_XARCH GetEmitter()->emitIns_R_AR(ins_Load(loadType), emitTypeSize(loadType), REG_SCRATCH, genFramePointerReg(), offset); From ee436f660c4d7ee9aac9e8373a449dba5d9da169 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 3 Apr 2024 17:01:01 +0200 Subject: [PATCH 49/52] Straggler --- src/coreclr/jit/codegenlinear.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/jit/codegenlinear.cpp b/src/coreclr/jit/codegenlinear.cpp index 1739ef6f676ae4..015d11bb5cf344 100644 --- a/src/coreclr/jit/codegenlinear.cpp +++ b/src/coreclr/jit/codegenlinear.cpp @@ -392,7 +392,6 @@ void CodeGen::genCodeForBBlist() // codegen related to doing this, so it cannot be done in the prolog. if (compiler->fgBBisScratch(block) && compiler->lvaHasAnySwiftStackParamToReassemble()) { - bool clobbered = false; genHomeSwiftStructParameters(/* handleStack */ true); } #endif From ef478a0bbc9366a2dbe992f211f2de723ee72891 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 4 Apr 2024 11:04:04 +0200 Subject: [PATCH 50/52] Run jit-format --- src/coreclr/jit/codegencommon.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 2507613390203d..834b26093d294c 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -6322,9 +6322,9 @@ void CodeGen::genFnProlog() genClearStackVec3ArgUpperBits(); #endif // UNIX_AMD64_ABI && FEATURE_SIMD -/*----------------------------------------------------------------------------- - * Take care of register arguments first - */ + /*----------------------------------------------------------------------------- + * Take care of register arguments first + */ #ifdef SWIFT_SUPPORT if (compiler->info.compCallConv == CorInfoCallConvExtension::Swift) From 010552a4e6df1d43b334e0099eba0295f82f699e Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 4 Apr 2024 21:23:49 +0200 Subject: [PATCH 51/52] Fix bad merge --- src/coreclr/jit/codegencommon.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 32133773285eae..0d11780ddee203 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -6246,19 +6246,6 @@ void CodeGen::genFnProlog() intRegState.rsCalleeRegArgMaskLiveIn &= ~RBM_SECRET_STUB_PARAM; } -#ifdef SWIFT_SUPPORT - if ((compiler->lvaSwiftSelfArg != BAD_VAR_NUM) && ((intRegState.rsCalleeRegArgMaskLiveIn & RBM_SWIFT_SELF) != 0)) - { - GetEmitter()->emitIns_S_R(ins_Store(TYP_I_IMPL), EA_PTRSIZE, REG_SWIFT_SELF, compiler->lvaSwiftSelfArg, 0); - intRegState.rsCalleeRegArgMaskLiveIn &= ~RBM_SWIFT_SELF; - } - - if (compiler->lvaSwiftErrorArg != BAD_VAR_NUM) - { - intRegState.rsCalleeRegArgMaskLiveIn &= ~RBM_SWIFT_ERROR; - } -#endif - // // Zero out the frame as needed // @@ -6360,6 +6347,11 @@ void CodeGen::genFnProlog() intRegState.rsCalleeRegArgMaskLiveIn &= ~RBM_SWIFT_SELF; } + if (compiler->lvaSwiftErrorArg != BAD_VAR_NUM) + { + intRegState.rsCalleeRegArgMaskLiveIn &= ~RBM_SWIFT_ERROR; + } + genHomeSwiftStructParameters(/* handleStack */ false); } #endif From 4f272f7eae8110692ffd49517bcff6a387c8c93b Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 4 Apr 2024 23:04:03 +0200 Subject: [PATCH 52/52] Address feedback --- src/coreclr/jit/flowgraph.cpp | 3 ++- src/coreclr/jit/lclvars.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index 272e474105c44d..863cd1daaf6ba9 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -2294,7 +2294,8 @@ PhaseStatus Compiler::fgAddInternal() madeChanges |= fgCreateFiltersForGenericExceptions(); // The backend requires a scratch BB into which it can safely insert a P/Invoke method prolog if one is - // required. Similarly, we need a scratch BB for poisoning. Create it here. + // required. Similarly, we need a scratch BB for poisoning and when we have Swift parameters to reassemble. + // Create it here. if (compMethodRequiresPInvokeFrame() || compShouldPoisonFrame() || lvaHasAnySwiftStackParamToReassemble()) { madeChanges |= fgEnsureFirstBBisScratch(); diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index fdd7202bfcbb9e..31b16e51329282 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -1828,7 +1828,7 @@ void Compiler::lvaClassifyParameterABI() assert(abiInfo.NumSegments > 0); - if ((dsc->TypeGet() == TYP_STRUCT) && info.compCallConv == CorInfoCallConvExtension::Swift) + if ((dsc->TypeGet() == TYP_STRUCT) && (info.compCallConv == CorInfoCallConvExtension::Swift)) { continue; }