aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lj_ffrecord.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c
index 3ef92034..24432d84 100644
--- a/src/lj_ffrecord.c
+++ b/src/lj_ffrecord.c
@@ -188,6 +188,14 @@ static TRef recff_bufhdr(jit_State *J)
188 lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET); 188 lj_ir_kptr(J, &J2G(J)->tmpbuf), IRBUFHDR_RESET);
189} 189}
190 190
191/* Emit TMPREF. */
192static TRef recff_tmpref(jit_State *J, TRef tr, int mode)
193{
194 if (!LJ_DUALNUM && tref_isinteger(tr))
195 tr = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT);
196 return emitir(IRT(IR_TMPREF, IRT_PGC), tr, mode);
197}
198
191/* -- Base library fast functions ----------------------------------------- */ 199/* -- Base library fast functions ----------------------------------------- */
192 200
193static void LJ_FASTCALL recff_assert(jit_State *J, RecordFFData *rd) 201static void LJ_FASTCALL recff_assert(jit_State *J, RecordFFData *rd)
@@ -302,7 +310,7 @@ int32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv)
302 } else { 310 } else {
303 TRef trptr = emitir(IRT(IR_STRREF, IRT_PGC), tr, lj_ir_kint(J, 0)); 311 TRef trptr = emitir(IRT(IR_STRREF, IRT_PGC), tr, lj_ir_kint(J, 0));
304 TRef trchar = emitir(IRT(IR_XLOAD, IRT_U8), trptr, IRXLOAD_READONLY); 312 TRef trchar = emitir(IRT(IR_XLOAD, IRT_U8), trptr, IRXLOAD_READONLY);
305 emitir(IRTG(IR_EQ, IRT_INT), trchar, lj_ir_kint(J, '#')); 313 emitir(IRTGI(IR_EQ), trchar, lj_ir_kint(J, '#'));
306 } 314 }
307 return 0; 315 return 0;
308 } else { /* select(n, ...) */ 316 } else { /* select(n, ...) */
@@ -1299,10 +1307,7 @@ static void LJ_FASTCALL recff_buffer_method_encode(jit_State *J, RecordFFData *r
1299{ 1307{
1300 TRef ud = recff_sbufx_check(J, rd, 0); 1308 TRef ud = recff_sbufx_check(J, rd, 0);
1301 TRef trbuf = recff_sbufx_write(J, ud); 1309 TRef trbuf = recff_sbufx_write(J, ud);
1302 TRef tmp, tr = J->base[1]; 1310 TRef tmp = recff_tmpref(J, J->base[1], IRTMPREF_IN1);
1303 if (!LJ_DUALNUM && tref_isinteger(tr))
1304 tr = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT);
1305 tmp = emitir(IRT(IR_TMPREF, IRT_PGC), tr, IRTMPREF_IN1);
1306 lj_ir_call(J, IRCALL_lj_serialize_put, trbuf, tmp); 1311 lj_ir_call(J, IRCALL_lj_serialize_put, trbuf, tmp);
1307 /* No IR_USE needed, since the call is a store. */ 1312 /* No IR_USE needed, since the call is a store. */
1308} 1313}
@@ -1311,12 +1316,10 @@ static void LJ_FASTCALL recff_buffer_method_decode(jit_State *J, RecordFFData *r
1311{ 1316{
1312 TRef ud = recff_sbufx_check(J, rd, 0); 1317 TRef ud = recff_sbufx_check(J, rd, 0);
1313 TRef trbuf = recff_sbufx_write(J, ud); 1318 TRef trbuf = recff_sbufx_write(J, ud);
1314 TRef trr, tmp; 1319 TRef tmp = recff_tmpref(J, TREF_NIL, IRTMPREF_OUT1);
1315 IRType t; 1320 TRef trr = lj_ir_call(J, IRCALL_lj_serialize_get, trbuf, tmp);
1316 tmp = emitir(IRT(IR_TMPREF, IRT_PGC), REF_NIL, IRTMPREF_OUT1); 1321 IRType t = (IRType)lj_serialize_peektype(bufV(&rd->argv[0]));
1317 trr = lj_ir_call(J, IRCALL_lj_serialize_get, trbuf, tmp);
1318 /* No IR_USE needed, since the call is a store. */ 1322 /* No IR_USE needed, since the call is a store. */
1319 t = (IRType)lj_serialize_peektype(bufV(&rd->argv[0]));
1320 J->base[0] = lj_record_vload(J, tmp, 0, t); 1323 J->base[0] = lj_record_vload(J, tmp, 0, t);
1321 /* The sbx->r store must be after the VLOAD type check, in case it fails. */ 1324 /* The sbx->r store must be after the VLOAD type check, in case it fails. */
1322 recff_sbufx_set_ptr(J, ud, IRFL_SBUF_R, trr); 1325 recff_sbufx_set_ptr(J, ud, IRFL_SBUF_R, trr);
@@ -1324,10 +1327,7 @@ static void LJ_FASTCALL recff_buffer_method_decode(jit_State *J, RecordFFData *r
1324 1327
1325static void LJ_FASTCALL recff_buffer_encode(jit_State *J, RecordFFData *rd) 1328static void LJ_FASTCALL recff_buffer_encode(jit_State *J, RecordFFData *rd)
1326{ 1329{
1327 TRef tmp, tr = J->base[0]; 1330 TRef tmp = recff_tmpref(J, J->base[0], IRTMPREF_IN1);
1328 if (!LJ_DUALNUM && tref_isinteger(tr))
1329 tr = emitir(IRTN(IR_CONV), tr, IRCONV_NUM_INT);
1330 tmp = emitir(IRT(IR_TMPREF, IRT_PGC), tr, IRTMPREF_IN1);
1331 J->base[0] = lj_ir_call(J, IRCALL_lj_serialize_encode, tmp); 1331 J->base[0] = lj_ir_call(J, IRCALL_lj_serialize_encode, tmp);
1332 /* IR_USE needed for IR_CALLA, because the encoder may throw non-OOM. */ 1332 /* IR_USE needed for IR_CALLA, because the encoder may throw non-OOM. */
1333 emitir(IRT(IR_USE, IRT_NIL), J->base[0], 0); 1333 emitir(IRT(IR_USE, IRT_NIL), J->base[0], 0);
@@ -1339,10 +1339,9 @@ static void LJ_FASTCALL recff_buffer_decode(jit_State *J, RecordFFData *rd)
1339 if (tvisstr(&rd->argv[0])) { 1339 if (tvisstr(&rd->argv[0])) {
1340 GCstr *str = strV(&rd->argv[0]); 1340 GCstr *str = strV(&rd->argv[0]);
1341 SBufExt sbx; 1341 SBufExt sbx;
1342 TRef tr, tmp;
1343 IRType t; 1342 IRType t;
1344 tmp = emitir(IRT(IR_TMPREF, IRT_PGC), REF_NIL, IRTMPREF_OUT1); 1343 TRef tmp = recff_tmpref(J, TREF_NIL, IRTMPREF_OUT1);
1345 tr = lj_ir_call(J, IRCALL_lj_serialize_decode, tmp, J->base[0]); 1344 TRef tr = lj_ir_call(J, IRCALL_lj_serialize_decode, tmp, J->base[0]);
1346 /* IR_USE needed for IR_CALLA, because the decoder may throw non-OOM. 1345 /* IR_USE needed for IR_CALLA, because the decoder may throw non-OOM.
1347 ** That's why IRCALL_lj_serialize_decode needs a fake INT result. 1346 ** That's why IRCALL_lj_serialize_decode needs a fake INT result.
1348 */ 1347 */