Skip to content

Commit

Permalink
Merge pull request #19 from lukego/dce-fastcall
Browse files Browse the repository at this point in the history
DCE: LJ_FASTCALL
  • Loading branch information
lukego authored Mar 14, 2017
2 parents ad950cc + ac6311d commit 5af7ae7
Show file tree
Hide file tree
Showing 50 changed files with 283 additions and 286 deletions.
4 changes: 2 additions & 2 deletions src/lib_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,11 @@ LJLIB_NOREG LJLIB_ASM(coroutine_wrap_aux)

/* Inline declarations. */
LJ_ASMF void lj_ff_coroutine_wrap_aux(void);
LJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L,
LJ_FUNCA_NORET void lj_ffh_coroutine_wrap_err(lua_State *L,
lua_State *co);

/* Error handler, called from assembler VM. */
void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L, lua_State *co)
void lj_ffh_coroutine_wrap_err(lua_State *L, lua_State *co)
{
co->top--; copyTV(L, L->top, co->top); L->top++;
if (tvisstr(L->top-1))
Expand Down
2 changes: 1 addition & 1 deletion src/lib_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ typedef union { uint64_t u64; double d; } U64double;
r ^= z; rs->gen[i] = z;

/* PRNG step function. Returns a double in the range 1.0 <= d < 2.0. */
LJ_NOINLINE uint64_t LJ_FASTCALL lj_math_random_step(RandomState *rs)
LJ_NOINLINE uint64_t lj_math_random_step(RandomState *rs)
{
uint64_t z, r = 0;
TW223_GEN(0, 63, 31, 18)
Expand Down
22 changes: 11 additions & 11 deletions src/lj_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void buf_grow(SBuf *sb, MSize sz)
setmref(sb->e, b + nsz);
}

LJ_NOINLINE char *LJ_FASTCALL lj_buf_need2(SBuf *sb, MSize sz)
LJ_NOINLINE char *lj_buf_need2(SBuf *sb, MSize sz)
{
lua_assert(sz > sbufsz(sb));
if (LJ_UNLIKELY(sz > LJ_MAX_BUF))
Expand All @@ -37,7 +37,7 @@ LJ_NOINLINE char *LJ_FASTCALL lj_buf_need2(SBuf *sb, MSize sz)
return sbufB(sb);
}

LJ_NOINLINE char *LJ_FASTCALL lj_buf_more2(SBuf *sb, MSize sz)
LJ_NOINLINE char *lj_buf_more2(SBuf *sb, MSize sz)
{
MSize len = sbuflen(sb);
lua_assert(sz > sbufleft(sb));
Expand All @@ -47,7 +47,7 @@ LJ_NOINLINE char *LJ_FASTCALL lj_buf_more2(SBuf *sb, MSize sz)
return sbufP(sb);
}

void LJ_FASTCALL lj_buf_shrink(lua_State *L, SBuf *sb)
void lj_buf_shrink(lua_State *L, SBuf *sb)
{
char *b = sbufB(sb);
MSize osz = (MSize)(sbufE(sb) - b);
Expand All @@ -60,7 +60,7 @@ void LJ_FASTCALL lj_buf_shrink(lua_State *L, SBuf *sb)
}
}

char * LJ_FASTCALL lj_buf_tmp(lua_State *L, MSize sz)
char * lj_buf_tmp(lua_State *L, MSize sz)
{
SBuf *sb = &G(L)->tmpbuf;
setsbufL(sb, L);
Expand All @@ -77,15 +77,15 @@ SBuf *lj_buf_putmem(SBuf *sb, const void *q, MSize len)
return sb;
}

SBuf * LJ_FASTCALL lj_buf_putchar(SBuf *sb, int c)
SBuf * lj_buf_putchar(SBuf *sb, int c)
{
char *p = lj_buf_more(sb, 1);
*p++ = (char)c;
setsbufP(sb, p);
return sb;
}

SBuf * LJ_FASTCALL lj_buf_putstr(SBuf *sb, GCstr *s)
SBuf * lj_buf_putstr(SBuf *sb, GCstr *s)
{
MSize len = s->len;
char *p = lj_buf_more(sb, len);
Expand All @@ -96,7 +96,7 @@ SBuf * LJ_FASTCALL lj_buf_putstr(SBuf *sb, GCstr *s)

/* -- High-level buffer put operations ------------------------------------ */

SBuf * LJ_FASTCALL lj_buf_putstr_reverse(SBuf *sb, GCstr *s)
SBuf * lj_buf_putstr_reverse(SBuf *sb, GCstr *s)
{
MSize len = s->len;
char *p = lj_buf_more(sb, len), *e = p+len;
Expand All @@ -107,7 +107,7 @@ SBuf * LJ_FASTCALL lj_buf_putstr_reverse(SBuf *sb, GCstr *s)
return sb;
}

SBuf * LJ_FASTCALL lj_buf_putstr_lower(SBuf *sb, GCstr *s)
SBuf * lj_buf_putstr_lower(SBuf *sb, GCstr *s)
{
MSize len = s->len;
char *p = lj_buf_more(sb, len), *e = p+len;
Expand All @@ -121,7 +121,7 @@ SBuf * LJ_FASTCALL lj_buf_putstr_lower(SBuf *sb, GCstr *s)
return sb;
}

SBuf * LJ_FASTCALL lj_buf_putstr_upper(SBuf *sb, GCstr *s)
SBuf * lj_buf_putstr_upper(SBuf *sb, GCstr *s)
{
MSize len = s->len;
char *p = lj_buf_more(sb, len), *e = p+len;
Expand Down Expand Up @@ -193,7 +193,7 @@ SBuf *lj_buf_puttab(SBuf *sb, GCtab *t, GCstr *sep, int32_t i, int32_t e)

/* -- Miscellaneous buffer operations ------------------------------------- */

GCstr * LJ_FASTCALL lj_buf_tostr(SBuf *sb)
GCstr * lj_buf_tostr(SBuf *sb)
{
return lj_str_new(sbufL(sb), sbufB(sb), sbuflen(sb));
}
Expand All @@ -209,7 +209,7 @@ GCstr *lj_buf_cat2str(lua_State *L, GCstr *s1, GCstr *s2)
}

/* Read ULEB128 from buffer. */
uint32_t LJ_FASTCALL lj_buf_ruleb128(const char **pp)
uint32_t lj_buf_ruleb128(const char **pp)
{
const uint8_t *p = (const uint8_t *)*pp;
uint32_t v = *p++;
Expand Down
22 changes: 11 additions & 11 deletions src/lj_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
#define setsbufL(sb, l) (setmref((sb)->L, (l)))

/* Buffer management */
LJ_FUNC char *LJ_FASTCALL lj_buf_need2(SBuf *sb, MSize sz);
LJ_FUNC char *LJ_FASTCALL lj_buf_more2(SBuf *sb, MSize sz);
LJ_FUNC void LJ_FASTCALL lj_buf_shrink(lua_State *L, SBuf *sb);
LJ_FUNC char * LJ_FASTCALL lj_buf_tmp(lua_State *L, MSize sz);
LJ_FUNC char *lj_buf_need2(SBuf *sb, MSize sz);
LJ_FUNC char *lj_buf_more2(SBuf *sb, MSize sz);
LJ_FUNC void lj_buf_shrink(lua_State *L, SBuf *sb);
LJ_FUNC char * lj_buf_tmp(lua_State *L, MSize sz);

static LJ_AINLINE void lj_buf_init(lua_State *L, SBuf *sb)
{
Expand Down Expand Up @@ -67,8 +67,8 @@ static LJ_AINLINE char *lj_buf_more(SBuf *sb, MSize sz)

/* Low-level buffer put operations */
LJ_FUNC SBuf *lj_buf_putmem(SBuf *sb, const void *q, MSize len);
LJ_FUNC SBuf * LJ_FASTCALL lj_buf_putchar(SBuf *sb, int c);
LJ_FUNC SBuf * LJ_FASTCALL lj_buf_putstr(SBuf *sb, GCstr *s);
LJ_FUNC SBuf * lj_buf_putchar(SBuf *sb, int c);
LJ_FUNC SBuf * lj_buf_putstr(SBuf *sb, GCstr *s);

static LJ_AINLINE char *lj_buf_wmem(char *p, const void *q, MSize len)
{
Expand All @@ -83,17 +83,17 @@ static LJ_AINLINE void lj_buf_putb(SBuf *sb, int c)
}

/* High-level buffer put operations */
LJ_FUNCA SBuf * LJ_FASTCALL lj_buf_putstr_reverse(SBuf *sb, GCstr *s);
LJ_FUNCA SBuf * LJ_FASTCALL lj_buf_putstr_lower(SBuf *sb, GCstr *s);
LJ_FUNCA SBuf * LJ_FASTCALL lj_buf_putstr_upper(SBuf *sb, GCstr *s);
LJ_FUNCA SBuf * lj_buf_putstr_reverse(SBuf *sb, GCstr *s);
LJ_FUNCA SBuf * lj_buf_putstr_lower(SBuf *sb, GCstr *s);
LJ_FUNCA SBuf * lj_buf_putstr_upper(SBuf *sb, GCstr *s);
LJ_FUNC SBuf *lj_buf_putstr_rep(SBuf *sb, GCstr *s, int32_t rep);
LJ_FUNC SBuf *lj_buf_puttab(SBuf *sb, GCtab *t, GCstr *sep,
int32_t i, int32_t e);

/* Miscellaneous buffer operations */
LJ_FUNCA GCstr * LJ_FASTCALL lj_buf_tostr(SBuf *sb);
LJ_FUNCA GCstr * lj_buf_tostr(SBuf *sb);
LJ_FUNC GCstr *lj_buf_cat2str(lua_State *L, GCstr *s1, GCstr *s2);
LJ_FUNC uint32_t LJ_FASTCALL lj_buf_ruleb128(const char **pp);
LJ_FUNC uint32_t lj_buf_ruleb128(const char **pp);

static LJ_AINLINE GCstr *lj_buf_str(lua_State *L, SBuf *sb)
{
Expand Down
2 changes: 1 addition & 1 deletion src/lj_ccall.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ typedef LJ_ALIGN(CCALL_ALIGN_CALLSTATE) struct CCallState {
/* -- C call handling ----------------------------------------------------- */

/* Really belongs to lj_vm.h. */
LJ_ASMF void LJ_FASTCALL lj_vm_ffi_call(CCallState *cc);
LJ_ASMF void lj_vm_ffi_call(CCallState *cc);

LJ_FUNC CTypeID lj_ccall_ctid_vararg(CTState *cts, cTValue *o);
LJ_FUNC int lj_ccall_func(lua_State *L, GCcdata *cd);
Expand Down
4 changes: 2 additions & 2 deletions src/lj_ccallback.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ static void callback_conv_result(CTState *cts, lua_State *L, TValue *o)
}

/* Enter callback. */
lua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf)
lua_State * lj_ccallback_enter(CTState *cts, void *cf)
{
lua_State *L = cts->L;
global_State *g = cts->g;
Expand All @@ -281,7 +281,7 @@ lua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf)
}

/* Leave callback. */
void LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o)
void lj_ccallback_leave(CTState *cts, TValue *o)
{
lua_State *L = cts->L;
GCfunc *fn;
Expand Down
4 changes: 2 additions & 2 deletions src/lj_ccallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
LJ_ASMF void lj_vm_ffi_callback(void);

LJ_FUNC MSize lj_ccallback_ptr2slot(CTState *cts, void *p);
LJ_FUNCA lua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf);
LJ_FUNCA void LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o);
LJ_FUNCA lua_State * lj_ccallback_enter(CTState *cts, void *cf);
LJ_FUNCA void lj_ccallback_leave(CTState *cts, TValue *o);
LJ_FUNC void *lj_ccallback_new(CTState *cts, CType *ct, GCfunc *fn);
LJ_FUNC void lj_ccallback_mcode_free(CTState *cts);

Expand Down
2 changes: 1 addition & 1 deletion src/lj_cdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ GCcdata *lj_cdata_newx(CTState *cts, CTypeID id, CTSize sz, CTInfo info)
}

/* Free a C data object. */
void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd)
void lj_cdata_free(global_State *g, GCcdata *cd)
{
if (LJ_UNLIKELY(cd->marked & LJ_GC_CDATA_FIN)) {
GCobj *root;
Expand Down
2 changes: 1 addition & 1 deletion src/lj_cdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ LJ_FUNC GCcdata *lj_cdata_newv(lua_State *L, CTypeID id, CTSize sz,
LJ_FUNC GCcdata *lj_cdata_newx(CTState *cts, CTypeID id, CTSize sz,
CTInfo info);

LJ_FUNC void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd);
LJ_FUNC void lj_cdata_free(global_State *g, GCcdata *cd);
LJ_FUNC void lj_cdata_setfin(lua_State *L, GCcdata *cd, GCobj *obj,
uint32_t it);

Expand Down
38 changes: 19 additions & 19 deletions src/lj_crecord.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ static void crec_index_meta(jit_State *J, CTState *cts, CType *ct,
}
}

void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd)
void recff_cdata_index(jit_State *J, RecordFFData *rd)
{
TRef idx, ptr = J->base[0];
ptrdiff_t ofs = sizeof(GCcdata);
Expand Down Expand Up @@ -1147,7 +1147,7 @@ static int crec_call(jit_State *J, RecordFFData *rd, GCcdata *cd)
return 0;
}

void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd)
void recff_cdata_call(jit_State *J, RecordFFData *rd)
{
CTState *cts = ctype_ctsG(J2G(J));
GCcdata *cd = argv2cdata(J, J->base[0], &rd->argv[0]);
Expand Down Expand Up @@ -1323,7 +1323,7 @@ static TRef crec_arith_meta(jit_State *J, TRef *sp, CType **s, CTState *cts,
return 0;
}

void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd)
void recff_cdata_arith(jit_State *J, RecordFFData *rd)
{
CTState *cts = ctype_ctsG(J2G(J));
TRef sp[2];
Expand Down Expand Up @@ -1425,7 +1425,7 @@ void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd)

/* -- C library namespace metamethods ------------------------------------- */

void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd)
void recff_clib_index(jit_State *J, RecordFFData *rd)
{
CTState *cts = ctype_ctsG(J2G(J));
if (tref_isudata(J->base[0]) && tref_isstr(J->base[1]) &&
Expand Down Expand Up @@ -1476,20 +1476,20 @@ static TRef crec_toint(jit_State *J, CTState *cts, TRef sp, TValue *sval)
return crec_ct_tv(J, ctype_get(cts, CTID_INT32), 0, sp, sval);
}

void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd)
void recff_ffi_new(jit_State *J, RecordFFData *rd)
{
crec_alloc(J, rd, argv2ctype(J, J->base[0], &rd->argv[0]));
}

void LJ_FASTCALL recff_ffi_errno(jit_State *J, RecordFFData *rd)
void recff_ffi_errno(jit_State *J, RecordFFData *rd)
{
UNUSED(rd);
if (J->base[0])
lj_trace_err(J, LJ_TRERR_NYICALL);
J->base[0] = lj_ir_call(J, IRCALL_lj_vm_errno);
}

void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd)
void recff_ffi_string(jit_State *J, RecordFFData *rd)
{
CTState *cts = ctype_ctsG(J2G(J));
TRef tr = J->base[0];
Expand All @@ -1506,7 +1506,7 @@ void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd)
} /* else: interpreter will throw. */
}

void LJ_FASTCALL recff_ffi_copy(jit_State *J, RecordFFData *rd)
void recff_ffi_copy(jit_State *J, RecordFFData *rd)
{
CTState *cts = ctype_ctsG(J2G(J));
TRef trdst = J->base[0], trsrc = J->base[1], trlen = J->base[2];
Expand All @@ -1524,7 +1524,7 @@ void LJ_FASTCALL recff_ffi_copy(jit_State *J, RecordFFData *rd)
} /* else: interpreter will throw. */
}

void LJ_FASTCALL recff_ffi_fill(jit_State *J, RecordFFData *rd)
void recff_ffi_fill(jit_State *J, RecordFFData *rd)
{
CTState *cts = ctype_ctsG(J2G(J));
TRef trdst = J->base[0], trlen = J->base[1], trfill = J->base[2];
Expand All @@ -1548,7 +1548,7 @@ void LJ_FASTCALL recff_ffi_fill(jit_State *J, RecordFFData *rd)
} /* else: interpreter will throw. */
}

void LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd)
void recff_ffi_typeof(jit_State *J, RecordFFData *rd)
{
if (tref_iscdata(J->base[0])) {
TRef trid = lj_ir_kint(J, argv2ctype(J, J->base[0], &rd->argv[0]));
Expand All @@ -1560,7 +1560,7 @@ void LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd)
}
}

void LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd)
void recff_ffi_istype(jit_State *J, RecordFFData *rd)
{
argv2ctype(J, J->base[0], &rd->argv[0]);
if (tref_iscdata(J->base[1])) {
Expand All @@ -1572,7 +1572,7 @@ void LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd)
}
}

void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd)
void recff_ffi_abi(jit_State *J, RecordFFData *rd)
{
if (tref_isstr(J->base[0])) {
/* Specialize to the ABI string to make the boolean result a constant. */
Expand All @@ -1585,7 +1585,7 @@ void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd)
}

/* Record ffi.sizeof(), ffi.alignof(), ffi.offsetof(). */
void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd)
void recff_ffi_xof(jit_State *J, RecordFFData *rd)
{
CTypeID id = argv2ctype(J, J->base[0], &rd->argv[0]);
if (rd->data == FF_ffi_sizeof) {
Expand All @@ -1602,7 +1602,7 @@ void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd)
J->base[0] = J->base[1] = J->base[2] = TREF_NIL;
}

void LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd)
void recff_ffi_gc(jit_State *J, RecordFFData *rd)
{
argv2cdata(J, J->base[0], &rd->argv[0]);
if (!J->base[1])
Expand All @@ -1626,7 +1626,7 @@ static CTypeID crec_bit64_type(CTState *cts, cTValue *tv)
return 0; /* Use regular 32 bit ops. */
}

void LJ_FASTCALL recff_bit64_tobit(jit_State *J, RecordFFData *rd)
void recff_bit64_tobit(jit_State *J, RecordFFData *rd)
{
CTState *cts = ctype_ctsG(J2G(J));
TRef tr = crec_ct_tv(J, ctype_get(cts, CTID_INT64), 0,
Expand All @@ -1636,7 +1636,7 @@ void LJ_FASTCALL recff_bit64_tobit(jit_State *J, RecordFFData *rd)
J->base[0] = tr;
}

int LJ_FASTCALL recff_bit64_unary(jit_State *J, RecordFFData *rd)
int recff_bit64_unary(jit_State *J, RecordFFData *rd)
{
CTState *cts = ctype_ctsG(J2G(J));
CTypeID id = crec_bit64_type(cts, &rd->argv[0]);
Expand All @@ -1649,7 +1649,7 @@ int LJ_FASTCALL recff_bit64_unary(jit_State *J, RecordFFData *rd)
return 0;
}

int LJ_FASTCALL recff_bit64_nary(jit_State *J, RecordFFData *rd)
int recff_bit64_nary(jit_State *J, RecordFFData *rd)
{
CTState *cts = ctype_ctsG(J2G(J));
CTypeID id = 0;
Expand All @@ -1672,7 +1672,7 @@ int LJ_FASTCALL recff_bit64_nary(jit_State *J, RecordFFData *rd)
return 0;
}

int LJ_FASTCALL recff_bit64_shift(jit_State *J, RecordFFData *rd)
int recff_bit64_shift(jit_State *J, RecordFFData *rd)
{
CTState *cts = ctype_ctsG(J2G(J));
CTypeID id;
Expand Down Expand Up @@ -1742,7 +1742,7 @@ TRef recff_bit64_tohex(jit_State *J, RecordFFData *rd, TRef hdr)

/* -- Miscellaneous library functions ------------------------------------- */

void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd)
void lj_crecord_tonumber(jit_State *J, RecordFFData *rd)
{
CTState *cts = ctype_ctsG(J2G(J));
CType *d, *ct = lj_ctype_rawref(cts, cdataV(&rd->argv[0])->ctypeid);
Expand Down
Loading

0 comments on commit 5af7ae7

Please sign in to comment.