Open mratsim opened 10 months ago
!nim c
import strutils
const
nim_v2 = (NimMajor, NimMinor) > (1, 6)
noExplicitVarDeref = defined(cpp) or nim_v2
func ccopy_x86_asm(ctl: uint64, x: var uint64, y: uint64) =
when noExplicitVarDeref:
asm """
testq %[ctl], %[ctl]
cmovnzq %[y], %[x]
: [x] "+r" (`x`)
: [ctl] "r" (`ctl`), [y] "r" (`y`)
: "cc"
"""
else:
asm """
testq %[ctl], %[ctl]
cmovnzq %[y], %[x]
: [x] "+r" (*`x`)
: [ctl] "r" (`ctl`), [y] "r" (`y`)
: "cc"
"""
func ccopy_x86_emit(ctl: uint64, x: var uint64, y: uint64) =
when noExplicitVarDeref:
{.emit:[
"""
asm volatile(
"testq %[ctl], %[ctl]\n"
"cmovnzq %[y], %[x]\n"
: [x] "+r" (""", x, """)
: [ctl] "r" (""", ctl, """), [y] "r" (""", y, """)
: "cc"
);"""].}
else:
{.emit:[
"""
asm volatile(
"testq %[ctl], %[ctl]\n"
"cmovnzq %[y], %[x]\n"
: [x] "+r" (*""", x, """)
: [ctl] "r" (""", ctl, """), [y] "r" (""", y, """)
: "cc"
);"""].}
let x = 0x1111111'u64
let y = 0xFFFFFFF'u64
block:
let ctl = 1'u64
var a0 = x
ctl.ccopy_x86_asm(a0, y)
var a1 = x
ctl.ccopy_x86_emit(a1, y)
echo "a0: ", a0.toHex()
echo "a1: ", a1.toHex()
doAssert a0 == a1
block:
let ctl = 0'u64
var a0 = x
ctl.ccopy_x86_asm(a0, y)
var a1 = x
ctl.ccopy_x86_emit(a1, y)
echo "a0: ", a0.toHex()
echo "a1: ", a1.toHex()
doAssert a0 == a1
100.42 Kb (102,832 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#define nimfr_(proc, file) \
TFrame FR_; \
FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; nimFrame(&FR_);
#define nimfrs_(proc, file, slots, length) \
struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename;NI len;VarSlot s[slots];} FR_; \
FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; nimFrame((TFrame*)&FR_);
#define nimln_(n) \
FR_.line = n;
#define nimlf_(n, file) \
FR_.line = n; FR_.filename = file;
typedef struct NimStrPayload NimStrPayload;
typedef struct NimStringV2 NimStringV2;
struct NimStrPayload {
NI cap;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 {
NI len;
NimStrPayload* p;
};
typedef NimStringV2 tyArray__Re75IspeoxXy2oCZHwcRrA[2];
N_LIB_PRIVATE N_NIMCALL(void, ccopy_x86_asm__temp_u24)(NU64 ctl_p0, NU64* x_p1, NU64 y_p2);
static N_INLINE(void, nimFrame)(TFrame* s_p0);
N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__system_u4666)(void);
static N_INLINE(void, popFrame)(void);
N_LIB_PRIVATE N_NIMCALL(void, ccopy_x86_emit__temp_u28)(NU64 ctl_p0, NU64* x_p1, NU64 y_p2);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, toHex__temp_u37)(NU64 x_p0);
N_LIB_PRIVATE N_NIMCALL(void, echoBinSafe)(NimStringV2* args_p0, NI args_p0Len_0);
N_LIB_PRIVATE N_NIMCALL(void, failedAssertImpl__stdZassertions_u254)(NimStringV2 msg_p0);
N_LIB_PRIVATE N_NOCONV(void, deallocShared)(void* p_p0);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatssystemdotnim_Init000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
static const struct {
NI cap; NIM_CHAR data[4+1];
} TM__SRd76hP9cMfCzdUO857UhQQ_2 = { 4 | NIM_STRLIT_FLAG, "a0: " };
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_3 = {4, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_2};
static const struct {
NI cap; NIM_CHAR data[4+1];
} TM__SRd76hP9cMfCzdUO857UhQQ_4 = { 4 | NIM_STRLIT_FLAG, "a1: " };
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_5 = {4, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_4};
static const struct {
NI cap; NIM_CHAR data[53+1];
} TM__SRd76hP9cMfCzdUO857UhQQ_6 = { 53 | NIM_STRLIT_FLAG, "/home/runner/work/Nim/Nim/temp.nim(53, 3) `a0 == a1` " };
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_7 = {53, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_6};
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_8 = {4, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_2};
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_9 = {4, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_4};
static const struct {
NI cap; NIM_CHAR data[53+1];
} TM__SRd76hP9cMfCzdUO857UhQQ_10 = { 53 | NIM_STRLIT_FLAG, "/home/runner/work/Nim/Nim/temp.nim(62, 3) `a0 == a1` " };
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_11 = {53, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_10};
N_LIB_PRIVATE NIM_CONST NU64 x__temp_u32 = 17895697ULL;
N_LIB_PRIVATE NIM_CONST NU64 y__temp_u33 = 268435455ULL;
N_LIB_PRIVATE NIM_CONST NU64 ctl__temp_u34 = 1ULL;
N_LIB_PRIVATE NU64 a0__temp_u35;
extern NIM_THREADVAR TFrame* framePtr__system_u4053;
N_LIB_PRIVATE NU64 a1__temp_u36;
N_LIB_PRIVATE NIM_CONST NU64 ctl__temp_u52 = 0ULL;
N_LIB_PRIVATE NU64 a0__temp_u53;
N_LIB_PRIVATE NU64 a1__temp_u54;
extern NIM_THREADVAR NIM_BOOL nimInErrorMode__system_u4450;
static N_INLINE(void, nimFrame)(TFrame* s_p0) {
{
if (!(framePtr__system_u4053 == ((TFrame*) NIM_NIL))) goto LA3_;
(*s_p0).calldepth = ((NI16)0);
}
goto LA1_;
LA3_: ;
{
(*s_p0).calldepth = (NI16)((*framePtr__system_u4053).calldepth + ((NI16)1));
}
LA1_: ;
(*s_p0).prev = framePtr__system_u4053;
framePtr__system_u4053 = s_p0;
{
if (!((*s_p0).calldepth == ((NI16)2000))) goto LA8_;
callDepthLimitReached__system_u4666();
}
LA8_: ;
}
static N_INLINE(void, popFrame)(void) {
framePtr__system_u4053 = (*framePtr__system_u4053).prev;
}
N_LIB_PRIVATE N_NIMCALL(void, ccopy_x86_asm__temp_u24)(NU64 ctl_p0, NU64* x_p1, NU64 y_p2) {
nimfr_("ccopy_x86_asm", "/home/runner/work/Nim/Nim/temp.nim");
__asm__(" testq %[ctl], %[ctl]\n"
" cmovnzq %[y], %[x]\n"
: [x] "+r" (x_p1)
: [ctl] "r" (ctl_p0), [y] "r" (y_p2)
: "cc"
);
popFrame();
}
N_LIB_PRIVATE N_NIMCALL(void, ccopy_x86_emit__temp_u28)(NU64 ctl_p0, NU64* x_p1, NU64 y_p2) {
nimfr_("ccopy_x86_emit", "/home/runner/work/Nim/Nim/temp.nim");
asm volatile(
"testq %[ctl], %[ctl]\n"
"cmovnzq %[y], %[x]\n"
: [x] "+r" ((*x_p1))
: [ctl] "r" (ctl_p0), [y] "r" (y_p2)
: "cc"
);
popFrame();
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
NIM_BOOL* result;
result = (&nimInErrorMode__system_u4450);
return result;
}
N_LIB_PRIVATE void PreMainInner(void) {
}
N_LIB_PRIVATE int cmdCount;
N_LIB_PRIVATE char** cmdLine;
N_LIB_PRIVATE char** gEnv;
N_LIB_PRIVATE void PreMain(void) {
#if 0
void (*volatile inner)(void);
inner = PreMainInner;
atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatssystemdotnim_Init000();
(*inner)();
#else
atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatssystemdotnim_Init000();
PreMainInner();
#endif
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
NimMainModule();
}
N_CDECL(void, NimMain)(void) {
#if 0
void (*volatile inner)(void);
PreMain();
inner = NimMainInner;
(*inner)();
#else
PreMain();
NimMainInner();
#endif
}
int main(int argc, char** args, char** env) {
cmdLine = args;
cmdCount = argc;
gEnv = env;
NimMain();
return nim_program_result;
}
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
NIM_BOOL* nimErr_;
nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim");
nimErr_ = nimErrorFlag();
{
NimStringV2 colontmpD_;
NimStringV2 colontmpD__2;
tyArray__Re75IspeoxXy2oCZHwcRrA T3_;
tyArray__Re75IspeoxXy2oCZHwcRrA T4_;
colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
colontmpD__2.len = 0; colontmpD__2.p = NIM_NIL;
a0__temp_u35 = x__temp_u32;
ccopy_x86_asm__temp_u24(ctl__temp_u34, (&a0__temp_u35), y__temp_u33);
if (NIM_UNLIKELY(*nimErr_)) goto LA2_;
a1__temp_u36 = x__temp_u32;
ccopy_x86_emit__temp_u28(ctl__temp_u34, (&a1__temp_u36), y__temp_u33);
if (NIM_UNLIKELY(*nimErr_)) goto LA2_;
T3_[0] = TM__SRd76hP9cMfCzdUO857UhQQ_3;
colontmpD_ = toHex__temp_u37(a0__temp_u35);
if (NIM_UNLIKELY(*nimErr_)) goto LA2_;
T3_[1] = colontmpD_;
echoBinSafe(T3_, 2);
T4_[0] = TM__SRd76hP9cMfCzdUO857UhQQ_5;
colontmpD__2 = toHex__temp_u37(a1__temp_u36);
if (NIM_UNLIKELY(*nimErr_)) goto LA2_;
T4_[1] = colontmpD__2;
echoBinSafe(T4_, 2);
{
if (!!((a0__temp_u35 == a1__temp_u36))) goto LA7_;
failedAssertImpl__stdZassertions_u254(TM__SRd76hP9cMfCzdUO857UhQQ_7);
if (NIM_UNLIKELY(*nimErr_)) goto LA2_;
}
LA7_: ;
{
LA2_:;
}
{
if (colontmpD__2.p && !(colontmpD__2.p->cap & NIM_STRLIT_FLAG)) {
deallocShared(colontmpD__2.p);
}
if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) {
deallocShared(colontmpD_.p);
}
}
if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
}
{
NimStringV2 colontmpD__3;
NimStringV2 colontmpD__4;
tyArray__Re75IspeoxXy2oCZHwcRrA T13_;
tyArray__Re75IspeoxXy2oCZHwcRrA T14_;
colontmpD__3.len = 0; colontmpD__3.p = NIM_NIL;
colontmpD__4.len = 0; colontmpD__4.p = NIM_NIL;
a0__temp_u53 = x__temp_u32;
ccopy_x86_asm__temp_u24(ctl__temp_u52, (&a0__temp_u53), y__temp_u33);
if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
a1__temp_u54 = x__temp_u32;
ccopy_x86_emit__temp_u28(ctl__temp_u52, (&a1__temp_u54), y__temp_u33);
if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
T13_[0] = TM__SRd76hP9cMfCzdUO857UhQQ_8;
colontmpD__3 = toHex__temp_u37(a0__temp_u53);
if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
T13_[1] = colontmpD__3;
echoBinSafe(T13_, 2);
T14_[0] = TM__SRd76hP9cMfCzdUO857UhQQ_9;
colontmpD__4 = toHex__temp_u37(a1__temp_u54);
if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
T14_[1] = colontmpD__4;
echoBinSafe(T14_, 2);
{
if (!!((a0__temp_u53 == a1__temp_u54))) goto LA17_;
failedAssertImpl__stdZassertions_u254(TM__SRd76hP9cMfCzdUO857UhQQ_11);
if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
}
LA17_: ;
{
LA12_:;
}
{
if (colontmpD__4.p && !(colontmpD__4.p->cap & NIM_STRLIT_FLAG)) {
deallocShared(colontmpD__4.p);
}
if (colontmpD__3.p && !(colontmpD__3.p->cap & NIM_STRLIT_FLAG)) {
deallocShared(colontmpD__3.p);
}
}
if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
}
BeforeRet_: ;
nimTestErrorFlag();
popFrame();
}
}
```
2023-12-22T01:59:38
2023-12-22T01:59:39
97.06 Kb (99,392 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#define nimfr_(proc, file) \
TFrame FR_; \
FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; nimFrame(&FR_);
#define nimfrs_(proc, file, slots, length) \
struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename;NI len;VarSlot s[slots];} FR_; \
FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; nimFrame((TFrame*)&FR_);
#define nimln_(n) \
FR_.line = n;
#define nimlf_(n, file) \
FR_.line = n; FR_.filename = file;
typedef struct NimStrPayload NimStrPayload;
typedef struct NimStringV2 NimStringV2;
struct NimStrPayload {
NI cap;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 {
NI len;
NimStrPayload* p;
};
typedef NimStringV2 tyArray__Re75IspeoxXy2oCZHwcRrA[2];
N_LIB_PRIVATE N_NIMCALL(void, ccopy_x86_asm__temp_u24)(NU64 ctl_p0, NU64* x_p1, NU64 y_p2);
static N_INLINE(void, nimFrame)(TFrame* s_p0);
N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__system_u4621)(void);
static N_INLINE(void, popFrame)(void);
N_LIB_PRIVATE N_NIMCALL(void, ccopy_x86_emit__temp_u28)(NU64 ctl_p0, NU64* x_p1, NU64 y_p2);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, toHex__temp_u37)(NU64 x_p0);
N_LIB_PRIVATE N_NIMCALL(void, echoBinSafe)(NimStringV2* args_p0, NI args_p0Len_0);
N_LIB_PRIVATE N_NIMCALL(void, failedAssertImpl__stdZassertions_u310)(NimStringV2 msg_p0);
N_LIB_PRIVATE N_NOCONV(void, deallocShared)(void* p_p0);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot2atslibatssystemdotnim_Init000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
static const struct {
NI cap; NIM_CHAR data[4+1];
} TM__SRd76hP9cMfCzdUO857UhQQ_2 = { 4 | NIM_STRLIT_FLAG, "a0: " };
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_3 = {4, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_2};
static const struct {
NI cap; NIM_CHAR data[4+1];
} TM__SRd76hP9cMfCzdUO857UhQQ_4 = { 4 | NIM_STRLIT_FLAG, "a1: " };
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_5 = {4, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_4};
static const struct {
NI cap; NIM_CHAR data[53+1];
} TM__SRd76hP9cMfCzdUO857UhQQ_6 = { 53 | NIM_STRLIT_FLAG, "/home/runner/work/Nim/Nim/temp.nim(53, 3) `a0 == a1` " };
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_7 = {53, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_6};
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_8 = {4, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_2};
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_9 = {4, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_4};
static const struct {
NI cap; NIM_CHAR data[53+1];
} TM__SRd76hP9cMfCzdUO857UhQQ_10 = { 53 | NIM_STRLIT_FLAG, "/home/runner/work/Nim/Nim/temp.nim(62, 3) `a0 == a1` " };
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_11 = {53, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_10};
N_LIB_PRIVATE NIM_CONST NU64 x__temp_u32 = 17895697ULL;
N_LIB_PRIVATE NIM_CONST NU64 y__temp_u33 = 268435455ULL;
N_LIB_PRIVATE NIM_CONST NU64 ctl__temp_u34 = 1ULL;
N_LIB_PRIVATE NU64 a0__temp_u35;
extern NIM_THREADVAR TFrame* framePtr__system_u4020;
N_LIB_PRIVATE NU64 a1__temp_u36;
N_LIB_PRIVATE NIM_CONST NU64 ctl__temp_u52 = 0ULL;
N_LIB_PRIVATE NU64 a0__temp_u53;
N_LIB_PRIVATE NU64 a1__temp_u54;
extern NIM_THREADVAR NIM_BOOL nimInErrorMode__system_u4403;
static N_INLINE(void, nimFrame)(TFrame* s_p0) {
{
if (!(framePtr__system_u4020 == ((TFrame*) NIM_NIL))) goto LA3_;
(*s_p0).calldepth = ((NI16)0);
}
goto LA1_;
LA3_: ;
{
(*s_p0).calldepth = (NI16)((*framePtr__system_u4020).calldepth + ((NI16)1));
}
LA1_: ;
(*s_p0).prev = framePtr__system_u4020;
framePtr__system_u4020 = s_p0;
{
if (!((*s_p0).calldepth == ((NI16)2000))) goto LA8_;
callDepthLimitReached__system_u4621();
}
LA8_: ;
}
static N_INLINE(void, popFrame)(void) {
framePtr__system_u4020 = (*framePtr__system_u4020).prev;
}
N_LIB_PRIVATE N_NIMCALL(void, ccopy_x86_asm__temp_u24)(NU64 ctl_p0, NU64* x_p1, NU64 y_p2) {
nimfr_("ccopy_x86_asm", "/home/runner/work/Nim/Nim/temp.nim");
__asm__(" testq %[ctl], %[ctl]\n"
" cmovnzq %[y], %[x]\n"
: [x] "+r" (x_p1)
: [ctl] "r" (ctl_p0), [y] "r" (y_p2)
: "cc"
);
popFrame();
}
N_LIB_PRIVATE N_NIMCALL(void, ccopy_x86_emit__temp_u28)(NU64 ctl_p0, NU64* x_p1, NU64 y_p2) {
nimfr_("ccopy_x86_emit", "/home/runner/work/Nim/Nim/temp.nim");
asm volatile(
"testq %[ctl], %[ctl]\n"
"cmovnzq %[y], %[x]\n"
: [x] "+r" ((*x_p1))
: [ctl] "r" (ctl_p0), [y] "r" (y_p2)
: "cc"
);
popFrame();
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
NIM_BOOL* result;
result = (&nimInErrorMode__system_u4403);
return result;
}
N_LIB_PRIVATE void PreMainInner(void) {
}
N_LIB_PRIVATE int cmdCount;
N_LIB_PRIVATE char** cmdLine;
N_LIB_PRIVATE char** gEnv;
N_LIB_PRIVATE void PreMain(void) {
#if 0
void (*volatile inner)(void);
inner = PreMainInner;
atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot2atslibatssystemdotnim_Init000();
(*inner)();
#else
atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot2atslibatssystemdotnim_Init000();
PreMainInner();
#endif
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
NimMainModule();
}
N_CDECL(void, NimMain)(void) {
#if 0
void (*volatile inner)(void);
PreMain();
inner = NimMainInner;
(*inner)();
#else
PreMain();
NimMainInner();
#endif
}
int main(int argc, char** args, char** env) {
cmdLine = args;
cmdCount = argc;
gEnv = env;
NimMain();
return nim_program_result;
}
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
NIM_BOOL* nimErr_;
nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim");
nimErr_ = nimErrorFlag();
{
NimStringV2 colontmpD_;
NimStringV2 colontmpD__2;
tyArray__Re75IspeoxXy2oCZHwcRrA T3_;
tyArray__Re75IspeoxXy2oCZHwcRrA T4_;
colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
colontmpD__2.len = 0; colontmpD__2.p = NIM_NIL;
a0__temp_u35 = x__temp_u32;
ccopy_x86_asm__temp_u24(ctl__temp_u34, (&a0__temp_u35), y__temp_u33);
if (NIM_UNLIKELY(*nimErr_)) goto LA2_;
a1__temp_u36 = x__temp_u32;
ccopy_x86_emit__temp_u28(ctl__temp_u34, (&a1__temp_u36), y__temp_u33);
if (NIM_UNLIKELY(*nimErr_)) goto LA2_;
T3_[0] = TM__SRd76hP9cMfCzdUO857UhQQ_3;
colontmpD_ = toHex__temp_u37(a0__temp_u35);
if (NIM_UNLIKELY(*nimErr_)) goto LA2_;
T3_[1] = colontmpD_;
echoBinSafe(T3_, 2);
T4_[0] = TM__SRd76hP9cMfCzdUO857UhQQ_5;
colontmpD__2 = toHex__temp_u37(a1__temp_u36);
if (NIM_UNLIKELY(*nimErr_)) goto LA2_;
T4_[1] = colontmpD__2;
echoBinSafe(T4_, 2);
{
if (!!((a0__temp_u35 == a1__temp_u36))) goto LA7_;
failedAssertImpl__stdZassertions_u310(TM__SRd76hP9cMfCzdUO857UhQQ_7);
if (NIM_UNLIKELY(*nimErr_)) goto LA2_;
}
LA7_: ;
{
LA2_:;
}
{
if (colontmpD__2.p && !(colontmpD__2.p->cap & NIM_STRLIT_FLAG)) {
deallocShared(colontmpD__2.p);
}
if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) {
deallocShared(colontmpD_.p);
}
}
if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
}
{
NimStringV2 colontmpD__3;
NimStringV2 colontmpD__4;
tyArray__Re75IspeoxXy2oCZHwcRrA T13_;
tyArray__Re75IspeoxXy2oCZHwcRrA T14_;
colontmpD__3.len = 0; colontmpD__3.p = NIM_NIL;
colontmpD__4.len = 0; colontmpD__4.p = NIM_NIL;
a0__temp_u53 = x__temp_u32;
ccopy_x86_asm__temp_u24(ctl__temp_u52, (&a0__temp_u53), y__temp_u33);
if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
a1__temp_u54 = x__temp_u32;
ccopy_x86_emit__temp_u28(ctl__temp_u52, (&a1__temp_u54), y__temp_u33);
if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
T13_[0] = TM__SRd76hP9cMfCzdUO857UhQQ_8;
colontmpD__3 = toHex__temp_u37(a0__temp_u53);
if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
T13_[1] = colontmpD__3;
echoBinSafe(T13_, 2);
T14_[0] = TM__SRd76hP9cMfCzdUO857UhQQ_9;
colontmpD__4 = toHex__temp_u37(a1__temp_u54);
if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
T14_[1] = colontmpD__4;
echoBinSafe(T14_, 2);
{
if (!!((a0__temp_u53 == a1__temp_u54))) goto LA17_;
failedAssertImpl__stdZassertions_u310(TM__SRd76hP9cMfCzdUO857UhQQ_11);
if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
}
LA17_: ;
{
LA12_:;
}
{
if (colontmpD__4.p && !(colontmpD__4.p->cap & NIM_STRLIT_FLAG)) {
deallocShared(colontmpD__4.p);
}
if (colontmpD__3.p && !(colontmpD__3.p->cap & NIM_STRLIT_FLAG)) {
deallocShared(colontmpD__3.p);
}
}
if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
}
BeforeRet_: ;
nimTestErrorFlag();
popFrame();
}
}
```
2023-12-22T01:59:39
2023-12-22T01:59:40
97.06 Kb (99,392 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#define nimfr_(proc, file) \
TFrame FR_; \
FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; nimFrame(&FR_);
#define nimfrs_(proc, file, slots, length) \
struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename;NI len;VarSlot s[slots];} FR_; \
FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; nimFrame((TFrame*)&FR_);
#define nimln_(n) \
FR_.line = n;
#define nimlf_(n, file) \
FR_.line = n; FR_.filename = file;
typedef struct NimStrPayload NimStrPayload;
typedef struct NimStringV2 NimStringV2;
struct NimStrPayload {
NI cap;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 {
NI len;
NimStrPayload* p;
};
typedef NimStringV2 tyArray__Re75IspeoxXy2oCZHwcRrA[2];
N_LIB_PRIVATE N_NIMCALL(void, ccopy_x86_asm__temp_u24)(NU64 ctl_p0, NU64* x_p1, NU64 y_p2);
static N_INLINE(void, nimFrame)(TFrame* s_p0);
N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__system_u4607)(void);
static N_INLINE(void, popFrame)(void);
N_LIB_PRIVATE N_NIMCALL(void, ccopy_x86_emit__temp_u28)(NU64 ctl_p0, NU64* x_p1, NU64 y_p2);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, toHex__temp_u37)(NU64 x_p0);
N_LIB_PRIVATE N_NIMCALL(void, echoBinSafe)(NimStringV2* args_p0, NI args_p0Len_0);
N_LIB_PRIVATE N_NIMCALL(void, failedAssertImpl__stdZassertions_u310)(NimStringV2 msg_p0);
N_LIB_PRIVATE N_NOCONV(void, deallocShared)(void* p_p0);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot0atslibatssystemdotnim_Init000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
static const struct {
NI cap; NIM_CHAR data[4+1];
} TM__SRd76hP9cMfCzdUO857UhQQ_2 = { 4 | NIM_STRLIT_FLAG, "a0: " };
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_3 = {4, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_2};
static const struct {
NI cap; NIM_CHAR data[4+1];
} TM__SRd76hP9cMfCzdUO857UhQQ_4 = { 4 | NIM_STRLIT_FLAG, "a1: " };
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_5 = {4, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_4};
static const struct {
NI cap; NIM_CHAR data[53+1];
} TM__SRd76hP9cMfCzdUO857UhQQ_6 = { 53 | NIM_STRLIT_FLAG, "/home/runner/work/Nim/Nim/temp.nim(53, 3) `a0 == a1` " };
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_7 = {53, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_6};
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_8 = {4, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_2};
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_9 = {4, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_4};
static const struct {
NI cap; NIM_CHAR data[53+1];
} TM__SRd76hP9cMfCzdUO857UhQQ_10 = { 53 | NIM_STRLIT_FLAG, "/home/runner/work/Nim/Nim/temp.nim(62, 3) `a0 == a1` " };
static const NimStringV2 TM__SRd76hP9cMfCzdUO857UhQQ_11 = {53, (NimStrPayload*)&TM__SRd76hP9cMfCzdUO857UhQQ_10};
N_LIB_PRIVATE NIM_CONST NU64 x__temp_u32 = 17895697ULL;
N_LIB_PRIVATE NIM_CONST NU64 y__temp_u33 = 268435455ULL;
N_LIB_PRIVATE NIM_CONST NU64 ctl__temp_u34 = 1ULL;
N_LIB_PRIVATE NU64 a0__temp_u35;
extern NIM_THREADVAR TFrame* framePtr__system_u4006;
N_LIB_PRIVATE NU64 a1__temp_u36;
N_LIB_PRIVATE NIM_CONST NU64 ctl__temp_u52 = 0ULL;
N_LIB_PRIVATE NU64 a0__temp_u53;
N_LIB_PRIVATE NU64 a1__temp_u54;
extern NIM_THREADVAR NIM_BOOL nimInErrorMode__system_u4389;
static N_INLINE(void, nimFrame)(TFrame* s_p0) {
{
if (!(framePtr__system_u4006 == ((TFrame*) NIM_NIL))) goto LA3_;
(*s_p0).calldepth = ((NI16)0);
}
goto LA1_;
LA3_: ;
{
(*s_p0).calldepth = (NI16)((*framePtr__system_u4006).calldepth + ((NI16)1));
}
LA1_: ;
(*s_p0).prev = framePtr__system_u4006;
framePtr__system_u4006 = s_p0;
{
if (!((*s_p0).calldepth == ((NI16)2000))) goto LA8_;
callDepthLimitReached__system_u4607();
}
LA8_: ;
}
static N_INLINE(void, popFrame)(void) {
framePtr__system_u4006 = (*framePtr__system_u4006).prev;
}
N_LIB_PRIVATE N_NIMCALL(void, ccopy_x86_asm__temp_u24)(NU64 ctl_p0, NU64* x_p1, NU64 y_p2) {
nimfr_("ccopy_x86_asm", "/home/runner/work/Nim/Nim/temp.nim");
__asm__(" testq %[ctl], %[ctl]\n"
" cmovnzq %[y], %[x]\n"
: [x] "+r" (x_p1)
: [ctl] "r" (ctl_p0), [y] "r" (y_p2)
: "cc"
);
popFrame();
}
N_LIB_PRIVATE N_NIMCALL(void, ccopy_x86_emit__temp_u28)(NU64 ctl_p0, NU64* x_p1, NU64 y_p2) {
nimfr_("ccopy_x86_emit", "/home/runner/work/Nim/Nim/temp.nim");
asm volatile(
"testq %[ctl], %[ctl]\n"
"cmovnzq %[y], %[x]\n"
: [x] "+r" ((*x_p1))
: [ctl] "r" (ctl_p0), [y] "r" (y_p2)
: "cc"
);
popFrame();
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
NIM_BOOL* result;
result = (NIM_BOOL*)0;
result = (&nimInErrorMode__system_u4389);
return result;
}
N_LIB_PRIVATE void PreMainInner(void) {
}
N_LIB_PRIVATE int cmdCount;
N_LIB_PRIVATE char** cmdLine;
N_LIB_PRIVATE char** gEnv;
N_LIB_PRIVATE void PreMain(void) {
#if 0
void (*volatile inner)(void);
inner = PreMainInner;
atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot0atslibatssystemdotnim_Init000();
(*inner)();
#else
atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot0atslibatssystemdotnim_Init000();
PreMainInner();
#endif
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
NimMainModule();
}
N_CDECL(void, NimMain)(void) {
#if 0
void (*volatile inner)(void);
PreMain();
inner = NimMainInner;
(*inner)();
#else
PreMain();
NimMainInner();
#endif
}
int main(int argc, char** args, char** env) {
cmdLine = args;
cmdCount = argc;
gEnv = env;
NimMain();
return nim_program_result;
}
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
NIM_BOOL* nimErr_;
nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim");
nimErr_ = nimErrorFlag();
{
NimStringV2 colontmpD_;
NimStringV2 colontmpD__2;
tyArray__Re75IspeoxXy2oCZHwcRrA T3_;
tyArray__Re75IspeoxXy2oCZHwcRrA T4_;
colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
colontmpD__2.len = 0; colontmpD__2.p = NIM_NIL;
a0__temp_u35 = x__temp_u32;
ccopy_x86_asm__temp_u24(ctl__temp_u34, (&a0__temp_u35), y__temp_u33);
if (NIM_UNLIKELY(*nimErr_)) goto LA2_;
a1__temp_u36 = x__temp_u32;
ccopy_x86_emit__temp_u28(ctl__temp_u34, (&a1__temp_u36), y__temp_u33);
if (NIM_UNLIKELY(*nimErr_)) goto LA2_;
T3_[0] = TM__SRd76hP9cMfCzdUO857UhQQ_3;
colontmpD_ = toHex__temp_u37(a0__temp_u35);
if (NIM_UNLIKELY(*nimErr_)) goto LA2_;
T3_[1] = colontmpD_;
echoBinSafe(T3_, 2);
T4_[0] = TM__SRd76hP9cMfCzdUO857UhQQ_5;
colontmpD__2 = toHex__temp_u37(a1__temp_u36);
if (NIM_UNLIKELY(*nimErr_)) goto LA2_;
T4_[1] = colontmpD__2;
echoBinSafe(T4_, 2);
{
if (!!((a0__temp_u35 == a1__temp_u36))) goto LA7_;
failedAssertImpl__stdZassertions_u310(TM__SRd76hP9cMfCzdUO857UhQQ_7);
if (NIM_UNLIKELY(*nimErr_)) goto LA2_;
}
LA7_: ;
{
LA2_:;
}
{
if (colontmpD__2.p && !(colontmpD__2.p->cap & NIM_STRLIT_FLAG)) {
deallocShared(colontmpD__2.p);
}
if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) {
deallocShared(colontmpD_.p);
}
}
if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
}
{
NimStringV2 colontmpD__3;
NimStringV2 colontmpD__4;
tyArray__Re75IspeoxXy2oCZHwcRrA T13_;
tyArray__Re75IspeoxXy2oCZHwcRrA T14_;
colontmpD__3.len = 0; colontmpD__3.p = NIM_NIL;
colontmpD__4.len = 0; colontmpD__4.p = NIM_NIL;
a0__temp_u53 = x__temp_u32;
ccopy_x86_asm__temp_u24(ctl__temp_u52, (&a0__temp_u53), y__temp_u33);
if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
a1__temp_u54 = x__temp_u32;
ccopy_x86_emit__temp_u28(ctl__temp_u52, (&a1__temp_u54), y__temp_u33);
if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
T13_[0] = TM__SRd76hP9cMfCzdUO857UhQQ_8;
colontmpD__3 = toHex__temp_u37(a0__temp_u53);
if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
T13_[1] = colontmpD__3;
echoBinSafe(T13_, 2);
T14_[0] = TM__SRd76hP9cMfCzdUO857UhQQ_9;
colontmpD__4 = toHex__temp_u37(a1__temp_u54);
if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
T14_[1] = colontmpD__4;
echoBinSafe(T14_, 2);
{
if (!!((a0__temp_u53 == a1__temp_u54))) goto LA17_;
failedAssertImpl__stdZassertions_u310(TM__SRd76hP9cMfCzdUO857UhQQ_11);
if (NIM_UNLIKELY(*nimErr_)) goto LA12_;
}
LA17_: ;
{
LA12_:;
}
{
if (colontmpD__4.p && !(colontmpD__4.p->cap & NIM_STRLIT_FLAG)) {
deallocShared(colontmpD__4.p);
}
if (colontmpD__3.p && !(colontmpD__3.p->cap & NIM_STRLIT_FLAG)) {
deallocShared(colontmpD__3.p);
}
}
if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
}
BeforeRet_: ;
nimTestErrorFlag();
popFrame();
}
}
```
2023-12-22T01:59:43
2023-12-22T01:59:43
105.05 Kb (107,576 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2023-12-22T01:59:46
2023-12-22T01:59:46
97.41 Kb (99,752 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2023-12-22T01:59:48
2023-12-22T01:59:49
97.14 Kb (99,472 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2023-12-22T01:59:50
2023-12-22T01:59:51
92.63 Kb (94,848 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2023-12-22T01:59:53
2023-12-22T01:59:54
2022-12-19 17:56:49 +0800
on commit #70c575095 with message:
```
add changelog for the new strict function checking algorithm (#21129)
add changelog for the new strict function checking
```
The bug is in the files:
```
changelogs/changelog_2_0_0.md
```
The bug can be in the commits:
(Diagnostics sometimes off-by-one).11.4.0
14.0.0
19.0
2023-12-22T01:59:13Z
1
nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
:robot: Bug found in 48 minutes
bisecting 2005
commits at 41
commits per second
The only commit the bisect mentions that touches the compiler is https://github.com/nim-lang/Nim/commit/d83f66a24?
It's not. I have checked the commit and the commit before it. There are no differences between them.
!nim c
import strutils
const
nim_v2 = (NimMajor, NimMinor) > (1, 6)
noExplicitVarDeref = defined(cpp) or nim_v2
func ccopy_x86_asm(ctl: uint64, x: var uint64, y: uint64) =
when noExplicitVarDeref:
asm """
testq %[ctl], %[ctl]
cmovnzq %[y], %[x]
: [x] "+r" (`x`)
: [ctl] "r" (`ctl`), [y] "r" (`y`)
: "cc"
"""
else:
asm """
testq %[ctl], %[ctl]
cmovnzq %[y], %[x]
: [x] "+r" (*`x`)
: [ctl] "r" (`ctl`), [y] "r" (`y`)
: "cc"
"""
func ccopy_x86_emit(ctl: uint64, x: var uint64, y: uint64) =
when noExplicitVarDeref:
{.emit:[
"""
asm volatile(
"testq %[ctl], %[ctl]\n"
"cmovnzq %[y], %[x]\n"
: [x] "+r" (""", x, """)
: [ctl] "r" (""", ctl, """), [y] "r" (""", y, """)
: "cc"
);"""].}
else:
{.emit:[
"""
asm volatile(
"testq %[ctl], %[ctl]\n"
"cmovnzq %[y], %[x]\n"
: [x] "+r" (*""", x, """)
: [ctl] "r" (""", ctl, """), [y] "r" (""", y, """)
: "cc"
);"""].}
let x = 0x1111111'u64
let y = 0xFFFFFFF'u64
block:
let ctl = 1'u64
var a0 = x
ctl.ccopy_x86_asm(a0, y)
var a1 = x
ctl.ccopy_x86_emit(a1, y)
doAssert a0.toHex() == "000000000FFFFFFF"
99.98 Kb (102,376 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2023-12-22T03:48:04
2023-12-22T03:48:05
1 minutes
96.62 Kb (98,936 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2023-12-22T03:48:06
2023-12-22T03:48:06
96.62 Kb (98,936 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2023-12-22T03:48:10
2023-12-22T03:48:10
100.62 Kb (103,032 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2023-12-22T03:48:14
2023-12-22T03:48:15
97.00 Kb (99,328 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2023-12-22T03:48:17
2023-12-22T03:48:18
92.73 Kb (94,952 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2023-12-22T03:48:21
2023-12-22T03:48:22
92.19 Kb (94,400 bytes)
```cpp
#define NIM_INTBITS 64
#include "nimbase.h"
#include 2023-12-22T03:48:24
2023-12-22T03:48:24
11.4.0
14.0.0
19.0
2023-12-22T03:47:30Z
5
nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
:robot: Bug found in 22 minutes
bisecting 2008
commits at 89
commits per second
Before Nim v2, interpolating a
var
parameter:This was the case for both
asm
andemit
statements.Following Nim v2:
Test case:
Output matrix
Expected output:
Incorrect:
and that's not taking into account overriding the
var
pointer, which might lead to writing to random location.Suggested solution ASM should also auto-deref var pointers.
Note The fix can probably address https://github.com/nim-lang/Nim/issues/18133 in one fell swoop.