Compile bit.tohex().
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "lj_cdata.h"
|
||||
#include "lj_cparse.h"
|
||||
#include "lj_cconv.h"
|
||||
#include "lj_carith.h"
|
||||
#include "lj_clib.h"
|
||||
#include "lj_ccall.h"
|
||||
#include "lj_ff.h"
|
||||
@@ -30,6 +31,7 @@
|
||||
#include "lj_snap.h"
|
||||
#include "lj_crecord.h"
|
||||
#include "lj_dispatch.h"
|
||||
#include "lj_strfmt.h"
|
||||
|
||||
/* Some local macros to save typing. Undef'd at the end. */
|
||||
#define IR(ref) (&J->cur.ir[(ref)])
|
||||
@@ -1720,6 +1722,41 @@ int LJ_FASTCALL recff_bit64_shift(jit_State *J, RecordFFData *rd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
TRef recff_bit64_tohex(jit_State *J, RecordFFData *rd, TRef hdr)
|
||||
{
|
||||
CTState *cts = ctype_ctsG(J2G(J));
|
||||
CTypeID id = crec_bit64_type(cts, &rd->argv[0]);
|
||||
TRef tr, trsf = J->base[1];
|
||||
SFormat sf = (STRFMT_UINT|STRFMT_T_HEX);
|
||||
int32_t n;
|
||||
if (trsf) {
|
||||
CTypeID id2 = 0;
|
||||
n = (int32_t)lj_carith_check64(J->L, 2, &id2);
|
||||
if (id2)
|
||||
trsf = crec_ct_tv(J, ctype_get(cts, CTID_INT32), 0, trsf, &rd->argv[1]);
|
||||
else
|
||||
trsf = lj_opt_narrow_tobit(J, trsf);
|
||||
emitir(IRTGI(IR_EQ), trsf, lj_ir_kint(J, n)); /* Specialize to n. */
|
||||
} else {
|
||||
n = id ? 16 : 8;
|
||||
}
|
||||
if (n < 0) { n = -n; sf |= STRFMT_F_UPPER; }
|
||||
sf |= ((SFormat)((n+1)&255) << STRFMT_SH_PREC);
|
||||
if (id) {
|
||||
tr = crec_ct_tv(J, ctype_get(cts, id), 0, J->base[0], &rd->argv[0]);
|
||||
if (n < 16)
|
||||
tr = emitir(IRT(IR_BAND, IRT_U64), tr,
|
||||
lj_ir_kint64(J, ((uint64_t)1 << 4*n)-1));
|
||||
} else {
|
||||
tr = lj_opt_narrow_tobit(J, J->base[0]);
|
||||
if (n < 8)
|
||||
tr = emitir(IRTI(IR_BAND), tr, lj_ir_kint(J, (int32_t)((1u << 4*n)-1)));
|
||||
tr = emitconv(tr, IRT_U64, IRT_INT, 0); /* No sign-extension. */
|
||||
lj_needsplit(J);
|
||||
}
|
||||
return lj_ir_call(J, IRCALL_lj_strfmt_putfxint, hdr, lj_ir_kint(J, sf), tr);
|
||||
}
|
||||
|
||||
/* -- Miscellaneous library functions ------------------------------------- */
|
||||
|
||||
void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd)
|
||||
|
||||
Reference in New Issue
Block a user