Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into even-moar-jit
Browse files Browse the repository at this point in the history
  • Loading branch information
bdw committed May 11, 2017
2 parents 5d556ad + 6d5ea04 commit 536dc18
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 138 deletions.
12 changes: 10 additions & 2 deletions Configure.pl
Expand Up @@ -39,10 +39,11 @@ ($$)
static has-libtommath has-libatomic_ops
has-dyncall has-libffi pkgconfig=s
build=s host=s big-endian jit! enable-jit
prefix=s bindir=s libdir=s mastdir=s make-install asan ubsan valgrind),
prefix=s bindir=s libdir=s mastdir=s make-install asan ubsan valgrind telemeh),

'no-optimize|nooptimize' => sub { $args{optimize} = 0 },
'no-debug|nodebug' => sub { $args{debug} = 0 }
'no-debug|nodebug' => sub { $args{debug} = 0 },
'no-telemeh|notelemeh' => sub { $args{telemeh} = 0 }
) or die "See --help for further information\n";


Expand Down Expand Up @@ -335,6 +336,7 @@ ($$)
push @cflags, '-fsanitize=address' if $args{asan};
push @cflags, '-fsanitize=undefined' if $args{ubsan};
push @cflags, '-DMVM_VALGRIND_SUPPORT' if $args{valgrind};
push @cflags, '-DHAVE_TELEMEH' if $args{telemeh};
push @cflags, '-DWORDS_BIGENDIAN' if $config{be}; # 3rdparty/sha1 needs it and it isnt set on mips;
push @cflags, $ENV{CFLAGS} if $ENV{CFLAGS};
push @cflags, $ENV{CPPFLAGS} if $ENV{CPPFLAGS};
Expand Down Expand Up @@ -425,6 +427,7 @@ ($$)
build::probe::C_type_bool(\%config, \%defaults);
build::probe::computed_goto(\%config, \%defaults);
build::probe::pthread_yield(\%config, \%defaults);
build::probe::rdtscp(\%config, \%defaults);

my $order = $config{be} ? 'big endian' : 'little endian';

Expand Down Expand Up @@ -798,6 +801,7 @@ =head1 SYNOPSIS
[--static] [--prefix]
[--has-libtommath] [--has-sha] [--has-libuv]
[--has-libatomic_ops] [--asan] [--ubsan] [--no-jit]
[--telemeh]
./Configure.pl --build <build-triple> --host <host-triple>
[--ar <ar>] [--cc <cc>] [--ld <ld>] [--make <make>]
Expand Down Expand Up @@ -956,4 +960,8 @@ =head1 OPTIONS
Disable JIT compiler, which is enabled by default to JIT-compile hot frames.
=item --telemeh
Build support for the fine-grained internal event logger.
=back
3 changes: 2 additions & 1 deletion build/Makefile.in
Expand Up @@ -19,6 +19,7 @@ ADDCONFIG =

TRACING = 0
CGOTO = @cancgoto@
RDTSCP = @canrdtscp@
NOISY = 0

MSG = @:
Expand All @@ -35,7 +36,7 @@ MASTDIR = @mastdir@

PKGCONFIGDIR = @prefix@/share/pkgconfig

CFLAGS = @cflags@ @ccdef@MVM_TRACING=$(TRACING) @ccdef@MVM_CGOTO=$(CGOTO)
CFLAGS = @cflags@ @ccdef@MVM_TRACING=$(TRACING) @ccdef@MVM_CGOTO=$(CGOTO) @ccdef@MVM_RDTSCP=$(RDTSCP)
CINCLUDES = @cincludes@ \
@ccinc@@shaincludedir@ \
@ccinc@3rdparty/tinymt \
Expand Down
33 changes: 33 additions & 0 deletions build/probe.pm
Expand Up @@ -450,4 +450,37 @@ sub win32_compiler_toolchain {
$config->{win32_compiler_toolchain}
}

sub rdtscp {
my ($config) = @_;
my $restore = _to_probe_dir();
_spew('try.c', <<'EOT');
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <intrin.h>
#else
#include <x86intrin.h>
#endif
int main(int argc, char **argv) {
unsigned int _tsc_aux;
unsigned int tscValue;
tscValue = __rdtscp(&_tsc_aux);
if (tscValue > 1)
return EXIT_SUCCESS;
return EXIT_FAILURE;
}
EOT

print ::dots(' probing support of rdtscp intrinsic');
my $can_rdtscp = compile($config, 'try');
unless ($config->{crossconf}) {
$can_rdtscp &&= !system './try';
}
print $can_rdtscp ? "YES\n": "NO\n";
$config->{canrdtscp} = $can_rdtscp || 0
}

'00';
26 changes: 14 additions & 12 deletions src/6model/reprs/VMArray.c
Expand Up @@ -528,6 +528,7 @@ static void push(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *dat
static void pop(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data, MVMRegister *value, MVMuint16 kind) {
MVMArrayREPRData *repr_data = (MVMArrayREPRData *)st->REPR_data;
MVMArrayBody *body = (MVMArrayBody *)data;
const MVMuint64 slot = body->start + body->elems - 1;

if (body->elems < 1)
MVM_exception_throw_adhoc(tc,
Expand All @@ -539,66 +540,67 @@ static void pop(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, void *data
case MVM_ARRAY_OBJ:
if (kind != MVM_reg_obj)
MVM_exception_throw_adhoc(tc, "MVMArray: pop expected object register");
value->o = body->slots.o[body->start + body->elems];
value->o = body->slots.o[slot];
break;
case MVM_ARRAY_STR:
if (kind != MVM_reg_str)
MVM_exception_throw_adhoc(tc, "MVMArray: pop expected string register");
value->s = body->slots.s[body->start + body->elems];
value->s = body->slots.s[slot];
break;
case MVM_ARRAY_I64:
if (kind != MVM_reg_int64)
MVM_exception_throw_adhoc(tc, "MVMArray: pop expected int register");
value->i64 = (MVMint64)body->slots.i64[body->start + body->elems];
value->i64 = (MVMint64)body->slots.i64[slot];
break;
case MVM_ARRAY_I32:
if (kind != MVM_reg_int64)
MVM_exception_throw_adhoc(tc, "MVMArray: pop expected int register");
value->i64 = (MVMint64)body->slots.i32[body->start + body->elems];
value->i64 = (MVMint64)body->slots.i32[slot];
break;
case MVM_ARRAY_I16:
if (kind != MVM_reg_int64)
MVM_exception_throw_adhoc(tc, "MVMArray: pop expected int register");
value->i64 = (MVMint64)body->slots.i16[body->start + body->elems];
value->i64 = (MVMint64)body->slots.i16[slot];
break;
case MVM_ARRAY_I8:
if (kind != MVM_reg_int64)
MVM_exception_throw_adhoc(tc, "MVMArray: pop expected int register");
value->i64 = (MVMint64)body->slots.i8[body->start + body->elems];
value->i64 = (MVMint64)body->slots.i8[slot];
break;
case MVM_ARRAY_N64:
if (kind != MVM_reg_num64)
MVM_exception_throw_adhoc(tc, "MVMArray: pop expected num register");
value->n64 = (MVMnum64)body->slots.n64[body->start + body->elems];
value->n64 = (MVMnum64)body->slots.n64[slot];
break;
case MVM_ARRAY_N32:
if (kind != MVM_reg_num64)
MVM_exception_throw_adhoc(tc, "MVMArray: pop expected num register");
value->n64 = (MVMnum64)body->slots.n32[body->start + body->elems];
value->n64 = (MVMnum64)body->slots.n32[slot];
break;
case MVM_ARRAY_U64:
if (kind != MVM_reg_int64)
MVM_exception_throw_adhoc(tc, "MVMArray: pop expected int register");
value->i64 = (MVMint64)body->slots.u64[body->start + body->elems];
value->i64 = (MVMint64)body->slots.u64[slot];
break;
case MVM_ARRAY_U32:
if (kind != MVM_reg_int64)
MVM_exception_throw_adhoc(tc, "MVMArray: pop expected int register");
value->i64 = (MVMint64)body->slots.u32[body->start + body->elems];
value->i64 = (MVMint64)body->slots.u32[slot];
break;
case MVM_ARRAY_U16:
if (kind != MVM_reg_int64)
MVM_exception_throw_adhoc(tc, "MVMArray: pop expected int register");
value->i64 = (MVMint64)body->slots.u16[body->start + body->elems];
value->i64 = (MVMint64)body->slots.u16[slot];
break;
case MVM_ARRAY_U8:
if (kind != MVM_reg_int64)
MVM_exception_throw_adhoc(tc, "MVMArray: pop expected int register");
value->i64 = (MVMint64)body->slots.u8[body->start + body->elems];
value->i64 = (MVMint64)body->slots.u8[slot];
break;
default:
MVM_exception_throw_adhoc(tc, "MVMArray: Unhandled slot type");
}
zero_slots(tc, body, slot, slot + 1, repr_data->slot_type);
exit_single_user(tc, body);
}

Expand Down
13 changes: 10 additions & 3 deletions src/main.c
Expand Up @@ -11,6 +11,12 @@
# define TRACING_USAGE ""
#endif

#ifdef HAVE_TELEMEH
# define TELEMEH_USAGE "MVM_TELEMETRY_LOG Log internal events at high precision to this file\n"
#else
# define TELEMEH_USAGE ""
#endif

#ifndef _WIN32
# include "signal.h"
#endif
Expand Down Expand Up @@ -78,9 +84,8 @@ The following environment variables are respected:\n\
MVM_JIT_LOG Specifies a JIT-compiler log file\n\
MVM_JIT_BYTECODE_DIR Specifies a directory for JIT bytecode dumps\n\
MVM_CROSS_THREAD_WRITE_LOG Log unprotected cross-thread object writes to stderr\n\
MVM_COVERAGE_LOG Append line-by-line coverage messages to this file\n\
MVM_TELEMETRY_LOG Write high-resolution timing for several internal events\n\
";
MVM_COVERAGE_LOG Append line-by-line coverage messages to this file\n"
TELEMEH_USAGE;

static int cmp_flag(const void *key, const void *value)
{
Expand Down Expand Up @@ -200,6 +205,7 @@ int wmain(int argc, wchar_t *wargv[])
}
}

#ifdef HAVE_TELEMEH
if (getenv("MVM_TELEMETRY_LOG")) {
char path[256];
snprintf(path, 255, "%s.%d", getenv("MVM_TELEMETRY_LOG"),
Expand All @@ -212,6 +218,7 @@ int wmain(int argc, wchar_t *wargv[])
MVM_telemetry_init(fopen(path, "w"));
interval_id = MVM_telemetry_interval_start(0, "moarvm startup");
}
#endif

lib_path[lib_path_i] = NULL;

Expand Down
23 changes: 12 additions & 11 deletions src/math/bigintops.c
Expand Up @@ -719,7 +719,17 @@ MVMObject *MVM_bigint_shl(MVMThreadContext *tc, MVMObject *result_type, MVMObjec

return result;
}

/* Checks if a MVMP6bigintBody is negative. Handles cases where it is stored as
* a small int as well as cases when it is stored as a bigint */
int BIGINT_IS_NEGATIVE (MVMP6bigintBody *ba) {
mp_int *mp_a = ba->u.bigint;
if MVM_BIGINT_IS_BIG(ba) {
return SIGN(mp_a) == MP_NEG;
}
else {
return ba->u.smallint.value < 0;
}
}
MVMObject *MVM_bigint_shr(MVMThreadContext *tc, MVMObject *result_type, MVMObject *a, MVMint64 n) {
MVMP6bigintBody *ba = get_bigint_body(tc, a);
MVMP6bigintBody *bb;
Expand All @@ -741,7 +751,7 @@ MVMObject *MVM_bigint_shr(MVMThreadContext *tc, MVMObject *result_type, MVMObjec
clear_temp_bigints(tmp, 1);
adjust_nursery(tc, bb);
} else if (n >= 32) {
store_int64_result(bb, 0);
store_int64_result(bb, BIGINT_IS_NEGATIVE(ba) ? -1 : 0);
} else {
MVMint32 value = ba->u.smallint.value;
value = value >> n;
Expand Down Expand Up @@ -924,18 +934,9 @@ void MVM_bigint_rand(MVMThreadContext *tc, MVMObject *a, MVMObject *b) {
mp_int *rnd = MVM_malloc(sizeof(mp_int));
mp_int *max = force_bigint(bb, tmp);

/* Workaround tommath issue #56 */
mp_int workaround;
mp_init (&workaround);
mp_rand(&workaround, USED(max) + 1);
mp_mul_2d(&workaround, 29, &workaround);

mp_init(rnd);
mp_rand(rnd, USED(max) + 1);

mp_xor(rnd, &workaround, rnd);
mp_clear(&workaround);

mp_mod(rnd, max, rnd);
store_bigint_result(ba, rnd);
clear_temp_bigints(tmp, 1);
Expand Down
40 changes: 33 additions & 7 deletions src/profiler/telemeh.c
@@ -1,17 +1,29 @@
#include <moar.h>

#ifdef HAVE_TELEMEH

#include <stdio.h>
#include <time.h>
#include <string.h>

#ifdef _WIN32
#include <intrin.h>
#else
#if defined(__x86_64__) || defined(__i386__)
#include <x86intrin.h>
#if MVM_RDTSCP
# ifdef _WIN32
# include <intrin.h>
# else
# if defined(__x86_64__) || defined(__i386__)
# include <x86intrin.h>
# else
unsigned int __rdtscp(unsigned int *inval) {
*inval = 0;
return 0;
}
# endif
# endif
#else
#define __rdtscp(V) { V = 0; }
#endif
unsigned int __rdtscp(unsigned int *inval) {
*inval = 0;
return 0;
}
#endif

double ticksPerSecond;
Expand Down Expand Up @@ -317,3 +329,17 @@ MVM_PUBLIC void MVM_telemetry_finish()
continueBackgroundSerialization = 0;
uv_thread_join(&backgroundSerializationThread);
}

#else

MVM_PUBLIC void MVM_telemetry_timestamp(MVMThreadContext *threadID, const char *description) { }

MVM_PUBLIC unsigned int MVM_telemetry_interval_start(MVMThreadContext *threadID, const char *description) { return 0; }
MVM_PUBLIC void MVM_telemetry_interval_stop(MVMThreadContext *threadID, int intervalID, const char *description) { }
MVM_PUBLIC void MVM_telemetry_interval_annotate(uintptr_t subject, int intervalID, const char *description) { }
MVM_PUBLIC void MVM_telemetry_interval_annotate_dynamic(uintptr_t subject, int intervalID, char *description) { }

MVM_PUBLIC void MVM_telemetry_init(FILE *outfile) { }
MVM_PUBLIC void MVM_telemetry_finish() { }

#endif
4 changes: 2 additions & 2 deletions src/spesh/dump.c
Expand Up @@ -141,8 +141,8 @@ static void dump_bb(MVMThreadContext *tc, DumpStr *ds, MVMSpeshGraph *g, MVMSpes
case MVM_SPESH_ANN_LINENO: {
char *cstr = MVM_string_utf8_encode_C_string(tc,
MVM_cu_string(tc, g->sf->body.cu, ann->data.lineno.filename_string_index));
appendf(ds, " [Annotation: Line Number (idx %d -> pc %d); %s:%d]\n",
ann->data.deopt_idx, g->deopt_addrs[2 * ann->data.deopt_idx], cstr, ann->data.lineno.line_number);
appendf(ds, " [Annotation: Line Number: %s:%d]\n",
cstr, ann->data.lineno.line_number);
MVM_free(cstr);
break;
}
Expand Down

0 comments on commit 536dc18

Please sign in to comment.