Skip to content

Commit

Permalink
Change the meaning of 'x' in a transformation
Browse files Browse the repository at this point in the history
The purpose of this series of commits is to improve code generation
for the Clang compiler.

As a first step we want to change the meaning of 'x' in a
transformation such as:

  operation Literal=q => move Literal x | operation x

Currently, a plain 'x' means reg[0] or x(0), which is the first
element in the X register array. That element is distinct from
r(0) which is a variable in process_main(). Therefore, since r(0)
and x(0) are currently distinct it is fine to use x(0) as a
scratch register.

However, in the next commit we will eliminate the separate variable
for storing the contents of X register zero (thus, x(0) and r(0)
will point to the same location in the X register array). Therefore,
we must use another scratch register in transformation. Redefine
a plain 'x' in a transformation to mean x(1023). Also define
SCRATCH_X_REG so that we can refer to the register by name from
C code.
  • Loading branch information
bjorng committed Jul 3, 2015
1 parent 54189af commit 45f469c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion erts/emulator/beam/beam_load.c
Expand Up @@ -4322,7 +4322,7 @@ gen_has_map_fields(LoaderState* stp, GenOpArg Fail, GenOpArg Src,
for (i = 0; i < n; i++) {
op->a[3+2*i] = Rest[i];
op->a[3+2*i+1].type = TAG_x;
op->a[3+2*i+1].val = 0; /* x(0); normally not used */
op->a[3+2*i+1].val = SCRATCH_X_REG; /* Ignore result */
}
return op;
}
Expand Down
9 changes: 4 additions & 5 deletions erts/emulator/utils/beam_makeops
Expand Up @@ -601,6 +601,7 @@ sub emulator_output {
print "#define MAX_GENERIC_OPCODE ", $num_file_opcodes-1, "\n";
print "#define NUM_GENERIC_OPS ", scalar(@gen_opname), "\n";
print "#define NUM_SPECIFIC_OPS ", scalar(@op_to_name), "\n";
print "#define SCRATCH_X_REG 1023\n";
print "\n";
print "#ifdef ARCH_64\n";
print "# define BEAM_WIDE_MASK 0xFFFFUL\n";
Expand Down Expand Up @@ -1341,7 +1342,10 @@ sub tr_parse_op {
}

# Get an optional value. (In destination.)
$type_val = $type eq 'x' ? 1023 : 0;
if (/^=(.*)/) {
error("value not allowed in source: $op")
if $src;
$type_val = $1;
$_ = '';
}
Expand All @@ -1360,11 +1364,6 @@ sub tr_parse_op {
if $var && $type;
}

# Test that source has no values.
if ($src) {
error("value not allowed in source: $op")
if $type_val;
}
($var,$type,$type_val,$cond,$cond_val);
}

Expand Down

0 comments on commit 45f469c

Please sign in to comment.