summaryrefslogtreecommitdiff
path: root/src/lj_crecord.c
diff options
context:
space:
mode:
authorMike Pall <mike>2013-05-15 13:57:35 +0200
committerMike Pall <mike>2013-05-15 13:57:35 +0200
commitfd616caf2691d8629aa9096216714ba9defd7748 (patch)
treea496c4e9b912f9be76defbbbe92b342f3abeaa24 /src/lj_crecord.c
parenta86017784eb6195bed5bbe1252204eb871f83270 (diff)
downloadluajit-fd616caf2691d8629aa9096216714ba9defd7748.tar.gz
luajit-fd616caf2691d8629aa9096216714ba9defd7748.tar.bz2
luajit-fd616caf2691d8629aa9096216714ba9defd7748.zip
Compile bit.tohex().
Diffstat (limited to 'src/lj_crecord.c')
-rw-r--r--src/lj_crecord.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/lj_crecord.c b/src/lj_crecord.c
index 398ca2a7..b98bdbc6 100644
--- a/src/lj_crecord.c
+++ b/src/lj_crecord.c
@@ -17,6 +17,7 @@
17#include "lj_cdata.h" 17#include "lj_cdata.h"
18#include "lj_cparse.h" 18#include "lj_cparse.h"
19#include "lj_cconv.h" 19#include "lj_cconv.h"
20#include "lj_carith.h"
20#include "lj_clib.h" 21#include "lj_clib.h"
21#include "lj_ccall.h" 22#include "lj_ccall.h"
22#include "lj_ff.h" 23#include "lj_ff.h"
@@ -30,6 +31,7 @@
30#include "lj_snap.h" 31#include "lj_snap.h"
31#include "lj_crecord.h" 32#include "lj_crecord.h"
32#include "lj_dispatch.h" 33#include "lj_dispatch.h"
34#include "lj_strfmt.h"
33 35
34/* Some local macros to save typing. Undef'd at the end. */ 36/* Some local macros to save typing. Undef'd at the end. */
35#define IR(ref) (&J->cur.ir[(ref)]) 37#define IR(ref) (&J->cur.ir[(ref)])
@@ -1720,6 +1722,41 @@ int LJ_FASTCALL recff_bit64_shift(jit_State *J, RecordFFData *rd)
1720 return 0; 1722 return 0;
1721} 1723}
1722 1724
1725TRef recff_bit64_tohex(jit_State *J, RecordFFData *rd, TRef hdr)
1726{
1727 CTState *cts = ctype_ctsG(J2G(J));
1728 CTypeID id = crec_bit64_type(cts, &rd->argv[0]);
1729 TRef tr, trsf = J->base[1];
1730 SFormat sf = (STRFMT_UINT|STRFMT_T_HEX);
1731 int32_t n;
1732 if (trsf) {
1733 CTypeID id2 = 0;
1734 n = (int32_t)lj_carith_check64(J->L, 2, &id2);
1735 if (id2)
1736 trsf = crec_ct_tv(J, ctype_get(cts, CTID_INT32), 0, trsf, &rd->argv[1]);
1737 else
1738 trsf = lj_opt_narrow_tobit(J, trsf);
1739 emitir(IRTGI(IR_EQ), trsf, lj_ir_kint(J, n)); /* Specialize to n. */
1740 } else {
1741 n = id ? 16 : 8;
1742 }
1743 if (n < 0) { n = -n; sf |= STRFMT_F_UPPER; }
1744 sf |= ((SFormat)((n+1)&255) << STRFMT_SH_PREC);
1745 if (id) {
1746 tr = crec_ct_tv(J, ctype_get(cts, id), 0, J->base[0], &rd->argv[0]);
1747 if (n < 16)
1748 tr = emitir(IRT(IR_BAND, IRT_U64), tr,
1749 lj_ir_kint64(J, ((uint64_t)1 << 4*n)-1));
1750 } else {
1751 tr = lj_opt_narrow_tobit(J, J->base[0]);
1752 if (n < 8)
1753 tr = emitir(IRTI(IR_BAND), tr, lj_ir_kint(J, (int32_t)((1u << 4*n)-1)));
1754 tr = emitconv(tr, IRT_U64, IRT_INT, 0); /* No sign-extension. */
1755 lj_needsplit(J);
1756 }
1757 return lj_ir_call(J, IRCALL_lj_strfmt_putfxint, hdr, lj_ir_kint(J, sf), tr);
1758}
1759
1723/* -- Miscellaneous library functions ------------------------------------- */ 1760/* -- Miscellaneous library functions ------------------------------------- */
1724 1761
1725void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd) 1762void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd)