Commit f41acfe5 authored by Jonathan Jenkins's avatar Jonathan Jenkins

add reverse modulo mapping context

parent eb9826bd
......@@ -29,6 +29,8 @@ enum codes_mctx_type {
// the number of callees in the group, to provide simple wraparound
// behaviour
CODES_MCTX_GROUP_MODULO,
// similar to GROUP_MODULO, but maps to offsets in reverse order
CODES_MCTX_GROUP_MODULO_REVERSE,
// instructs those using the context to map into the same group/repetition
// and directly to a callee offset
CODES_MCTX_GROUP_DIRECT,
......@@ -52,6 +54,7 @@ struct codes_mctx_global_direct {
struct codes_mctx_group_modulo {
struct codes_mctx_annotation anno;
};
// NOTE: group_modulo_reverse shares the group_modulo representation
struct codes_mctx_group_direct {
struct codes_mctx_annotation anno;
......@@ -74,6 +77,10 @@ struct codes_mctx codes_mctx_set_group_modulo(
char const * annotation,
bool ignore_annotations);
struct codes_mctx codes_mctx_set_group_modulo_reverse(
char const * annotation,
bool ignore_annotations);
struct codes_mctx codes_mctx_set_group_direct(
int offset,
char const * annotation,
......
......@@ -27,12 +27,14 @@ struct codes_mctx codes_mctx_set_global_direct(tw_lpid lpid)
rtn.u.global_direct.lpid = lpid;
return rtn;
}
struct codes_mctx codes_mctx_set_group_modulo(
static struct codes_mctx set_group_modulo_common(
enum codes_mctx_type type,
char const * annotation,
bool ignore_annotations)
{
struct codes_mctx rtn;
rtn.type = CODES_MCTX_GROUP_MODULO;
rtn.type = type;
if (ignore_annotations)
rtn.u.group_modulo.anno.cid = -1;
else
......@@ -40,6 +42,22 @@ struct codes_mctx codes_mctx_set_group_modulo(
codes_mapping_get_anno_cid_by_name(annotation);
return rtn;
}
struct codes_mctx codes_mctx_set_group_modulo(
char const * annotation,
bool ignore_annotations)
{
return set_group_modulo_common(CODES_MCTX_GROUP_MODULO, annotation,
ignore_annotations);
}
struct codes_mctx codes_mctx_set_group_modulo_reverse(
char const * annotation,
bool ignore_annotations)
{
return set_group_modulo_common(CODES_MCTX_GROUP_MODULO_REVERSE, annotation,
ignore_annotations);
}
struct codes_mctx codes_mctx_set_group_direct(
int offset,
char const * annotation,
......@@ -69,6 +87,7 @@ tw_lpid codes_mctx_to_lpid(
case CODES_MCTX_GLOBAL_DIRECT:
return ctx->u.global_direct.lpid;
case CODES_MCTX_GROUP_MODULO:
case CODES_MCTX_GROUP_MODULO_REVERSE:
anno = &ctx->u.group_modulo.anno;
break;
case CODES_MCTX_GROUP_DIRECT:
......@@ -92,7 +111,8 @@ tw_lpid codes_mctx_to_lpid(
anno_str = codes_mapping_get_anno_name_by_cid(anno->cid);
int dest_offset;
if (ctx->type == CODES_MCTX_GROUP_MODULO) {
if (ctx->type == CODES_MCTX_GROUP_MODULO ||
ctx->type == CODES_MCTX_GROUP_MODULO_REVERSE) {
int num_dest_lps = codes_mapping_get_lp_count(sender_group, 1,
dest_lp_name, anno_str, anno->cid == -1);
if (num_dest_lps == 0)
......@@ -104,6 +124,8 @@ tw_lpid codes_mctx_to_lpid(
codes_mapping_get_anno_name_by_cid(anno->cid));
dest_offset = offset % num_dest_lps;
if (ctx->type == CODES_MCTX_GROUP_MODULO_REVERSE)
dest_offset = num_dest_lps - 1 - dest_offset;
}
else if (ctx->type == CODES_MCTX_GROUP_DIRECT) {
dest_offset = ctx->u.group_direct.offset;
......@@ -126,6 +148,7 @@ char const * codes_mctx_get_annotation(
case CODES_MCTX_GLOBAL_DIRECT:
return codes_mapping_get_annotation_by_lpid(sender_id);
case CODES_MCTX_GROUP_MODULO:
case CODES_MCTX_GROUP_MODULO_REVERSE:
// if not ignoring the annotation, just return what's in the
// context
if (ctx->u.group_modulo.anno.cid >= 0)
......
......@@ -24,14 +24,16 @@ int main(int argc, char *argv[])
if (rc != 0)
ERR("unable to load configuration file %s", argv[1]);
struct codes_mctx direct, group_modulo, group_direct,
group_modulo_anno, group_direct_anno;
struct codes_mctx direct, group_modulo, group_rmodulo, group_direct,
group_modulo_anno, group_rmodulo_anno, group_direct_anno;
direct = codes_mctx_set_global_direct(12ul);
group_modulo = codes_mctx_set_group_modulo(NULL, true);
group_direct = codes_mctx_set_group_direct(1, NULL, true);
group_modulo_anno = codes_mctx_set_group_modulo("baz", false);
group_direct_anno = codes_mctx_set_group_direct(1, "baz", false);
direct = codes_mctx_set_global_direct(12ul);
group_modulo = codes_mctx_set_group_modulo(NULL, true);
group_rmodulo = codes_mctx_set_group_modulo_reverse(NULL, true);
group_direct = codes_mctx_set_group_direct(1, NULL, true);
group_modulo_anno = codes_mctx_set_group_modulo("baz", false);
group_rmodulo_anno = codes_mctx_set_group_modulo_reverse("baz", false);
group_direct_anno = codes_mctx_set_group_direct(1, "baz", false);
tw_lpid in;
tw_lpid rtn_id;
......@@ -54,6 +56,14 @@ int main(int argc, char *argv[])
if (rtn_anno)
ERR("group_modulo mapping: expected NULL anno, got %s", rtn_anno);
rtn_id = codes_mctx_to_lpid(&group_rmodulo, "bar", in);
if (rtn_id != 9ul)
ERR("group_rmodulo mapping: expected %lu, got %lu",
9ul, rtn_id);
rtn_anno = codes_mctx_get_annotation(&group_rmodulo, "bar", in);
if (rtn_anno)
ERR("group_rmodulo mapping: expected NULL anno, got %s", rtn_anno);
in = 12ul;
rtn_id = codes_mctx_to_lpid(&group_modulo, "bar", in);
if (rtn_id != 13ul)
......@@ -63,6 +73,14 @@ int main(int argc, char *argv[])
if (rtn_anno)
ERR("group_modulo mapping: expected NULL anno, got %s", rtn_anno);
rtn_id = codes_mctx_to_lpid(&group_rmodulo, "bar", in);
if (rtn_id != 14ul)
ERR("group_rmodulo mapping: expected %lu, got %lu",
14ul, rtn_id);
rtn_anno = codes_mctx_get_annotation(&group_rmodulo, "bar", in);
if (rtn_anno)
ERR("group_rmodulo mapping: expected NULL anno, got %s", rtn_anno);
rtn_id = codes_mctx_to_lpid(CODES_MCTX_DEFAULT, "bar", in);
if (rtn_id != 13ul)
ERR("group_modulo mapping (default): expected %lu, got %lu",
......@@ -79,6 +97,14 @@ int main(int argc, char *argv[])
if (strcmp(rtn_anno,"baz") != 0)
ERR("group_modulo mapping: expected anno \"baz\", got %s", rtn_anno);
rtn_id = codes_mctx_to_lpid(&group_rmodulo_anno, "bar", in);
if (rtn_id != 16ul)
ERR("group_rmodulo annotated mapping: expected %lu, got %lu",
16ul, rtn_id);
rtn_anno = codes_mctx_get_annotation(&group_rmodulo_anno, "bar", in);
if (strcmp(rtn_anno,"baz") != 0)
ERR("group_rmodulo mapping: expected anno \"baz\", got %s", rtn_anno);
in = 10ul;
rtn_id = codes_mctx_to_lpid(&group_direct, "bar", in);
if (rtn_id != 14ul)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment