+\f
+void
+nxm_parse_reg_move(struct ofpact_reg_move *move, const char *s)
+{
+ const char *full_s = s;
+
+ s = mf_parse_subfield(&move->src, s);
+ if (strncmp(s, "->", 2)) {
+ ovs_fatal(0, "%s: missing `->' following source", full_s);
+ }
+ s += 2;
+ s = mf_parse_subfield(&move->dst, s);
+ if (*s != '\0') {
+ ovs_fatal(0, "%s: trailing garbage following destination", full_s);
+ }
+
+ if (move->src.n_bits != move->dst.n_bits) {
+ ovs_fatal(0, "%s: source field is %d bits wide but destination is "
+ "%d bits wide", full_s,
+ move->src.n_bits, move->dst.n_bits);
+ }
+}
+
+void
+nxm_parse_reg_load(struct ofpact_reg_load *load, const char *s)
+{
+ const char *full_s = s;
+
+ load->value = strtoull(s, (char **) &s, 0);
+ if (strncmp(s, "->", 2)) {
+ ovs_fatal(0, "%s: missing `->' following value", full_s);
+ }
+ s += 2;
+ s = mf_parse_subfield(&load->dst, s);
+ if (*s != '\0') {
+ ovs_fatal(0, "%s: trailing garbage following destination", full_s);
+ }
+
+ if (load->dst.n_bits < 64 && (load->value >> load->dst.n_bits) != 0) {
+ ovs_fatal(0, "%s: value %"PRIu64" does not fit into %d bits",
+ full_s, load->value, load->dst.n_bits);
+ }
+}
+\f
+/* nxm_format_reg_move(), nxm_format_reg_load(). */
+
+void
+nxm_format_reg_move(const struct ofpact_reg_move *move, struct ds *s)
+{
+ ds_put_format(s, "move:");
+ mf_format_subfield(&move->src, s);
+ ds_put_cstr(s, "->");
+ mf_format_subfield(&move->dst, s);
+}
+
+void
+nxm_format_reg_load(const struct ofpact_reg_load *load, struct ds *s)
+{
+ ds_put_format(s, "load:%#"PRIx64"->", load->value);
+ mf_format_subfield(&load->dst, s);
+}
+\f
+enum ofperr
+nxm_reg_move_from_openflow(const struct nx_action_reg_move *narm,
+ struct ofpbuf *ofpacts)
+{
+ struct ofpact_reg_move *move;
+
+ move = ofpact_put_REG_MOVE(ofpacts);
+ move->src.field = mf_from_nxm_header(ntohl(narm->src));
+ move->src.ofs = ntohs(narm->src_ofs);
+ move->src.n_bits = ntohs(narm->n_bits);
+ move->dst.field = mf_from_nxm_header(ntohl(narm->dst));
+ move->dst.ofs = ntohs(narm->dst_ofs);
+ move->dst.n_bits = ntohs(narm->n_bits);
+
+ return nxm_reg_move_check(move, NULL);
+}
+
+enum ofperr
+nxm_reg_load_from_openflow(const struct nx_action_reg_load *narl,
+ struct ofpbuf *ofpacts)
+{
+ struct ofpact_reg_load *load;
+
+ load = ofpact_put_REG_LOAD(ofpacts);
+ load->dst.field = mf_from_nxm_header(ntohl(narl->dst));
+ load->dst.ofs = nxm_decode_ofs(narl->ofs_nbits);
+ load->dst.n_bits = nxm_decode_n_bits(narl->ofs_nbits);
+ load->value = ntohll(narl->value);
+
+ /* Reject 'narl' if a bit numbered 'n_bits' or higher is set to 1 in
+ * narl->value. */
+ if (load->dst.n_bits < 64 && load->value >> load->dst.n_bits) {
+ return OFPERR_OFPBAC_BAD_ARGUMENT;
+ }
+
+ return nxm_reg_load_check(load, NULL);
+}
+\f
+enum ofperr
+nxm_reg_move_check(const struct ofpact_reg_move *move, const struct flow *flow)
+{
+ enum ofperr error;
+
+ error = mf_check_src(&move->src, flow);
+ if (error) {
+ return error;
+ }
+
+ return mf_check_dst(&move->dst, NULL);
+}
+
+enum ofperr
+nxm_reg_load_check(const struct ofpact_reg_load *load, const struct flow *flow)
+{
+ return mf_check_dst(&load->dst, flow);
+}
+\f
+void
+nxm_reg_move_to_nxast(const struct ofpact_reg_move *move,
+ struct ofpbuf *openflow)
+{
+ struct nx_action_reg_move *narm;
+
+ narm = ofputil_put_NXAST_REG_MOVE(openflow);
+ narm->n_bits = htons(move->dst.n_bits);
+ narm->src_ofs = htons(move->src.ofs);
+ narm->dst_ofs = htons(move->dst.ofs);
+ narm->src = htonl(move->src.field->nxm_header);
+ narm->dst = htonl(move->dst.field->nxm_header);
+}
+
+void
+nxm_reg_load_to_nxast(const struct ofpact_reg_load *load,
+ struct ofpbuf *openflow)
+{
+ struct nx_action_reg_load *narl;
+
+ narl = ofputil_put_NXAST_REG_LOAD(openflow);
+ narl->ofs_nbits = nxm_encode_ofs_nbits(load->dst.ofs, load->dst.n_bits);
+ narl->dst = htonl(load->dst.field->nxm_header);
+ narl->value = htonll(load->value);
+}
+\f
+/* nxm_execute_reg_move(), nxm_execute_reg_load(). */
+
+void
+nxm_execute_reg_move(const struct ofpact_reg_move *move,
+ struct flow *flow)
+{
+ union mf_value src_value;
+ union mf_value dst_value;
+
+ mf_get_value(move->dst.field, flow, &dst_value);
+ mf_get_value(move->src.field, flow, &src_value);
+ bitwise_copy(&src_value, move->src.field->n_bytes, move->src.ofs,
+ &dst_value, move->dst.field->n_bytes, move->dst.ofs,
+ move->src.n_bits);
+ mf_set_flow_value(move->dst.field, &dst_value, flow);
+}
+
+void
+nxm_execute_reg_load(const struct ofpact_reg_load *load, struct flow *flow)
+{
+ nxm_reg_load(&load->dst, load->value, flow);
+}
+
+void
+nxm_reg_load(const struct mf_subfield *dst, uint64_t src_data,
+ struct flow *flow)
+{
+ union mf_value dst_value;
+ union mf_value src_value;
+
+ mf_get_value(dst->field, flow, &dst_value);
+ src_value.be64 = htonll(src_data);
+ bitwise_copy(&src_value, sizeof src_value.be64, 0,
+ &dst_value, dst->field->n_bytes, dst->ofs,
+ dst->n_bits);
+ mf_set_flow_value(dst->field, &dst_value, flow);
+}