~ubuntu-branches/ubuntu/trusty/luajit/trusty

« back to all changes in this revision

Viewing changes to src/lj_opt_narrow.c

  • Committer: Package Import Robot
  • Author(s): Enrico Tassi
  • Date: 2012-11-03 14:07:56 UTC
  • mfrom: (1.2.1) (15.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20121103140756-z0zcnyrwqlvuc2m5
Tags: 2.0.0+dfsg-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
** NARROW: Narrowing of numbers to integers (double to int32_t).
3
3
** STRIPOV: Stripping of overflow checks.
4
 
** Copyright (C) 2005-2011 Mike Pall. See Copyright Notice in luajit.h
 
4
** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h
5
5
*/
6
6
 
7
7
#define lj_opt_narrow_c
11
11
 
12
12
#if LJ_HASJIT
13
13
 
14
 
#include "lj_str.h"
15
14
#include "lj_bc.h"
16
15
#include "lj_ir.h"
17
16
#include "lj_jit.h"
18
17
#include "lj_iropt.h"
19
18
#include "lj_trace.h"
20
19
#include "lj_vm.h"
 
20
#include "lj_strscan.h"
21
21
 
22
22
/* Rationale for narrowing optimizations:
23
23
**
519
519
{
520
520
  if (tref_isstr(rb)) {
521
521
    rb = emitir(IRTG(IR_STRTO, IRT_NUM), rb, 0);
522
 
    lj_str_tonum(strV(vb), vb);
 
522
    lj_strscan_num(strV(vb), vb);
523
523
  }
524
524
  if (tref_isstr(rc)) {
525
525
    rc = emitir(IRTG(IR_STRTO, IRT_NUM), rc, 0);
526
 
    lj_str_tonum(strV(vc), vc);
 
526
    lj_strscan_num(strV(vc), vc);
527
527
  }
528
528
  /* Must not narrow MUL in non-DUALNUM variant, because it loses -0. */
529
529
  if ((op >= IR_ADD && op <= (LJ_DUALNUM ? IR_MUL : IR_SUB)) &&
541
541
{
542
542
  if (tref_isstr(rc)) {
543
543
    rc = emitir(IRTG(IR_STRTO, IRT_NUM), rc, 0);
544
 
    lj_str_tonum(strV(vc), vc);
 
544
    lj_strscan_num(strV(vc), vc);
545
545
  }
546
546
  if (tref_isinteger(rc)) {
547
547
    if ((uint32_t)numberVint(vc) != 0x80000000u)
555
555
TRef lj_opt_narrow_mod(jit_State *J, TRef rb, TRef rc, TValue *vc)
556
556
{
557
557
  TRef tmp;
558
 
  if (tvisstr(vc) && !lj_str_tonum(strV(vc), vc))
 
558
  if (tvisstr(vc) && !lj_strscan_num(strV(vc), vc))
559
559
    lj_trace_err(J, LJ_TRERR_BADTYPE);
560
560
  if ((LJ_DUALNUM || (J->flags & JIT_F_OPT_NARROW)) &&
561
561
      tref_isinteger(rb) && tref_isinteger(rc) &&
575
575
/* Narrowing of power operator or math.pow. */
576
576
TRef lj_opt_narrow_pow(jit_State *J, TRef rb, TRef rc, TValue *vc)
577
577
{
578
 
  if (tvisstr(vc) && !lj_str_tonum(strV(vc), vc))
 
578
  if (tvisstr(vc) && !lj_strscan_num(strV(vc), vc))
579
579
    lj_trace_err(J, LJ_TRERR_BADTYPE);
580
580
  /* Narrowing must be unconditional to preserve (-x)^i semantics. */
581
581
  if (tvisint(vc) || numisint(numV(vc))) {