Last active
July 21, 2022 04:28
-
-
Save Korsar13/f993beaa52947a0ce42a632602e2aecf to your computer and use it in GitHub Desktop.
nested enum_switch: msvc error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m2.cpp -- nested magic_enum::enum_switch() in do_process3 | |
clang output (m2.s) -- 16 calls to templated process_convert() | |
msvc output (m2.asm) -- only 4 calls to templated process_convert(), first type always ChannelType_Invalid (remove all lines except do_process3 body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Function compile flags: /Ogtpy | |
; COMDAT ?do_process3@@YAXW4ChannelType@@0PEBXPEAX_K@Z | |
_TEXT SEGMENT | |
ct1$ = 8 | |
ct2$ = 16 | |
d1$ = 24 | |
d2$ = 32 | |
count$ = 40 | |
?do_process3@@YAXW4ChannelType@@0PEBXPEAX_K@Z PROC ; do_process3, COMDAT | |
; File C:\K13\Work\ChkME\m2.cpp | |
; Line 37 | |
mov rax, r8 | |
; File C:\K13\Work\Akvis\Kernel\magic_enum.hpp | |
; Line 879 | |
cmp ecx, -4 | |
je SHORT $LN1557@do_process | |
cmp ecx, -3 | |
je SHORT $LN1557@do_process | |
cmp ecx, -2 | |
je SHORT $LN1557@do_process | |
cmp ecx, -1 | |
jne SHORT $LN300@do_process | |
$LN1557@do_process: | |
; File C:\K13\Work\ChkME\m2.cpp | |
; Line 56 | |
cmp edx, -4 | |
je SHORT $LN1577@do_process | |
cmp edx, -3 | |
je SHORT $LN1578@do_process | |
cmp edx, -2 | |
je SHORT $LN1579@do_process | |
cmp edx, -1 | |
jne SHORT $LN300@do_process | |
mov r8, QWORD PTR count$[rsp] | |
mov rdx, r9 | |
mov rcx, rax | |
jmp ??$process_convert@$$BY0A@EE@@YAXPEAY0A@$$CBEPEAE_K@Z ; process_convert<unsigned char [0],unsigned char> | |
$LN1579@do_process: | |
mov r8, QWORD PTR count$[rsp] | |
mov rdx, r9 | |
mov rcx, rax | |
jmp ??$process_convert@$$BY0A@EG@@YAXPEAY0A@$$CBEPEAG_K@Z ; process_convert<unsigned char [0],unsigned short> | |
$LN1578@do_process: | |
mov r8, QWORD PTR count$[rsp] | |
mov rdx, r9 | |
mov rcx, rax | |
jmp ??$process_convert@$$BY0A@EM@@YAXPEAY0A@$$CBEPEAM_K@Z ; process_convert<unsigned char [0],float> | |
$LN1577@do_process: | |
mov r8, QWORD PTR count$[rsp] | |
mov rdx, r9 | |
mov rcx, rax | |
jmp ??$process_convert@$$BY0A@EN@@YAXPEAY0A@$$CBEPEAN_K@Z ; process_convert<unsigned char [0],double> | |
$LN300@do_process: | |
ret 0 | |
?do_process3@@YAXW4ChannelType@@0PEBXPEAX_K@Z ENDP ; do_process3 | |
_TEXT ENDS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "magic_enum.hpp" | |
enum ChannelType { | |
ChannelType_Invalid = 0, | |
ChannelType_8bit = -1, | |
ChannelType_16bit = -2, | |
ChannelType_Float = -3, | |
ChannelType_Double = -4 | |
}; | |
template <> | |
struct magic_enum::customize::enum_range<ChannelType> { | |
static constexpr int min = -4; | |
static constexpr int max = 128; | |
}; | |
using Type_8bit = std::uint8_t; | |
using Type_16bit = std::uint16_t; | |
using Type_Float = float; | |
using Type_Double = double; | |
template< int channelType > struct TypeOfChannel { using Type = unsigned char[channelType]; }; | |
template<> struct TypeOfChannel< ChannelType_8bit > { using Type = Type_8bit; }; | |
template<> struct TypeOfChannel< ChannelType_16bit > { using Type = Type_16bit; }; | |
template<> struct TypeOfChannel< ChannelType_Float > { using Type = Type_Float; }; | |
template<> struct TypeOfChannel< ChannelType_Double > { using Type = Type_Double; }; | |
template< int channelType > | |
using TypeOfChannel_t = typename TypeOfChannel<channelType>::Type; | |
template< typename TSrc, typename TDst > | |
void process_convert( const TSrc *d1, TDst *d2, size_t count ); | |
void do_process3( ChannelType ct1, ChannelType ct2, const void *d1, void *d2, size_t count ) | |
{ | |
magic_enum::enum_switch([ct2,d1,d2,count](auto val1){ | |
constexpr ChannelType cht_1 = val1; | |
if ( cht_1 != ChannelType_Invalid ) | |
{ | |
using Type1 = typename TypeOfChannel<(int)cht_1>::Type; | |
magic_enum::enum_switch([d1,d2,count](auto val2){ | |
constexpr ChannelType cht_2 = val2; | |
if ( cht_2 != ChannelType_Invalid ) | |
{ | |
using Type2 = typename TypeOfChannel<(int)cht_2>::Type; | |
process_convert<Type1,Type2>( static_cast<const Type1*>(d1), static_cast<Type2*>(d2), count ); | |
} | |
}, ct2 ); | |
} | |
else | |
{ | |
} | |
}, ct1 ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.text | |
.def @feat.00; | |
.scl 3; | |
.type 0; | |
.endef | |
.globl @feat.00 | |
.set @feat.00, 0 | |
.file "m2.cpp" | |
.def "?do_process3@@YAXW4ChannelType@@0PEBXPEAX_K@Z"; | |
.scl 2; | |
.type 32; | |
.endef | |
.globl "?do_process3@@YAXW4ChannelType@@0PEBXPEAX_K@Z" # -- Begin function ?do_process3@@YAXW4ChannelType@@0PEBXPEAX_K@Z | |
.p2align 4, 0x90 | |
"?do_process3@@YAXW4ChannelType@@0PEBXPEAX_K@Z": # @"?do_process3@@YAXW4ChannelType@@0PEBXPEAX_K@Z" | |
# %bb.0: | |
# kill: def $edx killed $edx def $rdx | |
# kill: def $ecx killed $ecx def $rcx | |
addl $4, %ecx | |
cmpl $3, %ecx | |
ja .LBB0_26 | |
# %bb.1: | |
movq %r8, %r10 | |
movq 40(%rsp), %r8 | |
leaq .LJTI0_0(%rip), %rax | |
movslq (%rax,%rcx,4), %rcx | |
addq %rax, %rcx | |
jmpq *%rcx | |
.LBB0_2: | |
addl $4, %edx | |
cmpl $3, %edx | |
ja .LBB0_26 | |
# %bb.3: | |
leaq .LJTI0_4(%rip), %rax | |
movslq (%rax,%rdx,4), %rcx | |
addq %rax, %rcx | |
jmpq *%rcx | |
.LBB0_4: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@NN@@YAXPEBNPEAN_K@Z" # TAILCALL | |
.LBB0_8: | |
addl $4, %edx | |
cmpl $3, %edx | |
ja .LBB0_26 | |
# %bb.9: | |
leaq .LJTI0_3(%rip), %rax | |
movslq (%rax,%rdx,4), %rcx | |
addq %rax, %rcx | |
jmpq *%rcx | |
.LBB0_10: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@MN@@YAXPEBMPEAN_K@Z" # TAILCALL | |
.LBB0_14: | |
addl $4, %edx | |
cmpl $3, %edx | |
ja .LBB0_26 | |
# %bb.15: | |
leaq .LJTI0_2(%rip), %rax | |
movslq (%rax,%rdx,4), %rcx | |
addq %rax, %rcx | |
jmpq *%rcx | |
.LBB0_16: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@GN@@YAXPEBGPEAN_K@Z" # TAILCALL | |
.LBB0_20: | |
addl $4, %edx | |
cmpl $3, %edx | |
ja .LBB0_26 | |
# %bb.21: | |
leaq .LJTI0_1(%rip), %rax | |
movslq (%rax,%rdx,4), %rcx | |
addq %rax, %rcx | |
jmpq *%rcx | |
.LBB0_22: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@EN@@YAXPEBEPEAN_K@Z" # TAILCALL | |
.LBB0_26: | |
retq | |
.LBB0_5: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@NM@@YAXPEBNPEAM_K@Z" # TAILCALL | |
.LBB0_6: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@NG@@YAXPEBNPEAG_K@Z" # TAILCALL | |
.LBB0_7: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@NE@@YAXPEBNPEAE_K@Z" # TAILCALL | |
.LBB0_11: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@MM@@YAXPEBMPEAM_K@Z" # TAILCALL | |
.LBB0_12: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@MG@@YAXPEBMPEAG_K@Z" # TAILCALL | |
.LBB0_13: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@ME@@YAXPEBMPEAE_K@Z" # TAILCALL | |
.LBB0_17: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@GM@@YAXPEBGPEAM_K@Z" # TAILCALL | |
.LBB0_18: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@GG@@YAXPEBGPEAG_K@Z" # TAILCALL | |
.LBB0_19: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@GE@@YAXPEBGPEAE_K@Z" # TAILCALL | |
.LBB0_23: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@EM@@YAXPEBEPEAM_K@Z" # TAILCALL | |
.LBB0_24: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@EG@@YAXPEBEPEAG_K@Z" # TAILCALL | |
.LBB0_25: | |
movq %r10, %rcx | |
movq %r9, %rdx | |
jmp "??$process_convert@EE@@YAXPEBEPEAE_K@Z" # TAILCALL | |
.p2align 2, 0x90 | |
.LJTI0_0: | |
.long .LBB0_2-.LJTI0_0 | |
.long .LBB0_8-.LJTI0_0 | |
.long .LBB0_14-.LJTI0_0 | |
.long .LBB0_20-.LJTI0_0 | |
.LJTI0_1: | |
.long .LBB0_22-.LJTI0_1 | |
.long .LBB0_23-.LJTI0_1 | |
.long .LBB0_24-.LJTI0_1 | |
.long .LBB0_25-.LJTI0_1 | |
.LJTI0_2: | |
.long .LBB0_16-.LJTI0_2 | |
.long .LBB0_17-.LJTI0_2 | |
.long .LBB0_18-.LJTI0_2 | |
.long .LBB0_19-.LJTI0_2 | |
.LJTI0_3: | |
.long .LBB0_10-.LJTI0_3 | |
.long .LBB0_11-.LJTI0_3 | |
.long .LBB0_12-.LJTI0_3 | |
.long .LBB0_13-.LJTI0_3 | |
.LJTI0_4: | |
.long .LBB0_4-.LJTI0_4 | |
.long .LBB0_5-.LJTI0_4 | |
.long .LBB0_6-.LJTI0_4 | |
.long .LBB0_7-.LJTI0_4 | |
# -- End function | |
.section .drectve,"yn" | |
.ascii " /FAILIFMISMATCH:\"_MSC_VER=1900\"" | |
.ascii " /FAILIFMISMATCH:\"_ITERATOR_DEBUG_LEVEL=0\"" | |
.ascii " /FAILIFMISMATCH:\"RuntimeLibrary=MT_StaticRelease\"" | |
.ascii " /DEFAULTLIB:libcpmt.lib" | |
.ascii " /FAILIFMISMATCH:\"_CRT_STDIO_ISO_WIDE_SPECIFIERS=0\"" | |
.addrsig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment