diff options
author | Mike Pall <mike> | 2013-05-15 13:57:35 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2013-05-15 13:57:35 +0200 |
commit | fd616caf2691d8629aa9096216714ba9defd7748 (patch) | |
tree | a496c4e9b912f9be76defbbbe92b342f3abeaa24 | |
parent | a86017784eb6195bed5bbe1252204eb871f83270 (diff) | |
download | luajit-fd616caf2691d8629aa9096216714ba9defd7748.tar.gz luajit-fd616caf2691d8629aa9096216714ba9defd7748.tar.bz2 luajit-fd616caf2691d8629aa9096216714ba9defd7748.zip |
Compile bit.tohex().
-rw-r--r-- | src/Makefile.dep | 6 | ||||
-rw-r--r-- | src/lib_bit.c | 2 | ||||
-rw-r--r-- | src/lj_crecord.c | 37 | ||||
-rw-r--r-- | src/lj_crecord.h | 1 | ||||
-rw-r--r-- | src/lj_ffrecord.c | 23 |
5 files changed, 59 insertions, 10 deletions
diff --git a/src/Makefile.dep b/src/Makefile.dep index 376e2d2f..0ea0d98e 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep | |||
@@ -88,10 +88,10 @@ lj_cparse.o: lj_cparse.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | |||
88 | lj_frame.h lj_bc.h lj_vm.h lj_char.h lj_strscan.h lj_strfmt.h | 88 | lj_frame.h lj_bc.h lj_vm.h lj_char.h lj_strscan.h lj_strfmt.h |
89 | lj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 89 | lj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
90 | lj_err.h lj_errmsg.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h lj_gc.h \ | 90 | lj_err.h lj_errmsg.h lj_tab.h lj_frame.h lj_bc.h lj_ctype.h lj_gc.h \ |
91 | lj_cdata.h lj_cparse.h lj_cconv.h lj_clib.h lj_ccall.h lj_ff.h \ | 91 | lj_cdata.h lj_cparse.h lj_cconv.h lj_carith.h lj_clib.h lj_ccall.h \ |
92 | lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \ | 92 | lj_ff.h lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \ |
93 | lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_snap.h \ | 93 | lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_snap.h \ |
94 | lj_crecord.h | 94 | lj_crecord.h lj_strfmt.h |
95 | lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ | 95 | lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ |
96 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_strfmt.h lj_ctype.h \ | 96 | lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_strfmt.h lj_ctype.h \ |
97 | lj_ccallback.h | 97 | lj_ccallback.h |
diff --git a/src/lib_bit.c b/src/lib_bit.c index a258484d..a3f7c1ac 100644 --- a/src/lib_bit.c +++ b/src/lib_bit.c | |||
@@ -142,7 +142,7 @@ LJLIB_ASM_(bit_bxor) LJLIB_REC(bit_nary IR_BXOR) | |||
142 | 142 | ||
143 | /* ------------------------------------------------------------------------ */ | 143 | /* ------------------------------------------------------------------------ */ |
144 | 144 | ||
145 | LJLIB_CF(bit_tohex) | 145 | LJLIB_CF(bit_tohex) LJLIB_REC(.) |
146 | { | 146 | { |
147 | #if LJ_HASFFI | 147 | #if LJ_HASFFI |
148 | CTypeID id = 0, id2 = 0; | 148 | CTypeID id = 0, id2 = 0; |
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 | ||
1725 | TRef 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 | ||
1725 | void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd) | 1762 | void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd) |
diff --git a/src/lj_crecord.h b/src/lj_crecord.h index 92d777b8..47c0a69d 100644 --- a/src/lj_crecord.h +++ b/src/lj_crecord.h | |||
@@ -30,6 +30,7 @@ LJ_FUNC void LJ_FASTCALL recff_bit64_tobit(jit_State *J, RecordFFData *rd); | |||
30 | LJ_FUNC int LJ_FASTCALL recff_bit64_unary(jit_State *J, RecordFFData *rd); | 30 | LJ_FUNC int LJ_FASTCALL recff_bit64_unary(jit_State *J, RecordFFData *rd); |
31 | LJ_FUNC int LJ_FASTCALL recff_bit64_nary(jit_State *J, RecordFFData *rd); | 31 | LJ_FUNC int LJ_FASTCALL recff_bit64_nary(jit_State *J, RecordFFData *rd); |
32 | LJ_FUNC int LJ_FASTCALL recff_bit64_shift(jit_State *J, RecordFFData *rd); | 32 | LJ_FUNC int LJ_FASTCALL recff_bit64_shift(jit_State *J, RecordFFData *rd); |
33 | LJ_FUNC TRef recff_bit64_tohex(jit_State *J, RecordFFData *rd, TRef hdr); | ||
33 | 34 | ||
34 | LJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd); | 35 | LJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd); |
35 | #endif | 36 | #endif |
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 31f9b390..fcc46319 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c | |||
@@ -119,6 +119,13 @@ static void LJ_FASTCALL recff_c(jit_State *J, RecordFFData *rd) | |||
119 | UNUSED(rd); | 119 | UNUSED(rd); |
120 | } | 120 | } |
121 | 121 | ||
122 | /* Emit BUFHDR for the global temporary buffer. */ | ||
123 | static TRef recff_bufhdr(jit_State *J) | ||
124 | { | ||
125 | return emitir(IRT(IR_BUFHDR, IRT_P32), | ||
126 | lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET); | ||
127 | } | ||
128 | |||
122 | /* -- Base library fast functions ----------------------------------------- */ | 129 | /* -- Base library fast functions ----------------------------------------- */ |
123 | 130 | ||
124 | static void LJ_FASTCALL recff_assert(jit_State *J, RecordFFData *rd) | 131 | static void LJ_FASTCALL recff_assert(jit_State *J, RecordFFData *rd) |
@@ -645,15 +652,19 @@ static void LJ_FASTCALL recff_bit_shift(jit_State *J, RecordFFData *rd) | |||
645 | } | 652 | } |
646 | } | 653 | } |
647 | 654 | ||
648 | /* -- String library fast functions --------------------------------------- */ | 655 | static void LJ_FASTCALL recff_bit_tohex(jit_State *J, RecordFFData *rd) |
649 | |||
650 | /* Emit BUFHDR for the global temporary buffer. */ | ||
651 | static TRef recff_bufhdr(jit_State *J) | ||
652 | { | 656 | { |
653 | return emitir(IRT(IR_BUFHDR, IRT_P32), | 657 | #if LJ_HASFFI |
654 | lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET); | 658 | TRef hdr = recff_bufhdr(J); |
659 | TRef tr = recff_bit64_tohex(J, rd, hdr); | ||
660 | J->base[0] = emitir(IRT(IR_BUFSTR, IRT_STR), tr, hdr); | ||
661 | #else | ||
662 | recff_nyiu(J); /* Don't bother working around this NYI. */ | ||
663 | #endif | ||
655 | } | 664 | } |
656 | 665 | ||
666 | /* -- String library fast functions --------------------------------------- */ | ||
667 | |||
657 | /* Specialize to relative starting position for string. */ | 668 | /* Specialize to relative starting position for string. */ |
658 | static TRef recff_string_start(jit_State *J, GCstr *s, int32_t *st, TRef tr, | 669 | static TRef recff_string_start(jit_State *J, GCstr *s, int32_t *st, TRef tr, |
659 | TRef trlen, TRef tr0) | 670 | TRef trlen, TRef tr0) |