1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2021 Intel Corporation
4 #ifndef __INCLUDE_RTE_SWX_PIPELINE_INTERNAL_H__
5 #define __INCLUDE_RTE_SWX_PIPELINE_INTERNAL_H__
11 #include <rte_byteorder.h>
12 #include <rte_common.h>
13 #include <rte_cycles.h>
14 #include <rte_prefetch.h>
15 #include <rte_meter.h>
17 #include <rte_swx_table_selector.h>
18 #include <rte_swx_table_learner.h>
19 #include <rte_swx_pipeline.h>
20 #include <rte_swx_ctl.h>
27 #define TRACE(...) printf(__VA_ARGS__)
35 #define ntoh64(x) rte_be_to_cpu_64(x)
36 #define hton64(x) rte_cpu_to_be_64(x)
42 char name[RTE_SWX_NAME_SIZE];
49 TAILQ_ENTRY(struct_type) node;
50 char name[RTE_SWX_NAME_SIZE];
58 TAILQ_HEAD(struct_type_tailq, struct_type);
64 TAILQ_ENTRY(port_in_type) node;
65 char name[RTE_SWX_NAME_SIZE];
66 struct rte_swx_port_in_ops ops;
69 TAILQ_HEAD(port_in_type_tailq, port_in_type);
72 TAILQ_ENTRY(port_in) node;
73 struct port_in_type *type;
78 TAILQ_HEAD(port_in_tailq, port_in);
80 struct port_in_runtime {
81 rte_swx_port_in_pkt_rx_t pkt_rx;
88 struct port_out_type {
89 TAILQ_ENTRY(port_out_type) node;
90 char name[RTE_SWX_NAME_SIZE];
91 struct rte_swx_port_out_ops ops;
94 TAILQ_HEAD(port_out_type_tailq, port_out_type);
97 TAILQ_ENTRY(port_out) node;
98 struct port_out_type *type;
103 TAILQ_HEAD(port_out_tailq, port_out);
105 struct port_out_runtime {
106 rte_swx_port_out_pkt_tx_t pkt_tx;
107 rte_swx_port_out_flush_t flush;
114 struct extern_type_member_func {
115 TAILQ_ENTRY(extern_type_member_func) node;
116 char name[RTE_SWX_NAME_SIZE];
117 rte_swx_extern_type_member_func_t func;
121 TAILQ_HEAD(extern_type_member_func_tailq, extern_type_member_func);
124 TAILQ_ENTRY(extern_type) node;
125 char name[RTE_SWX_NAME_SIZE];
126 struct struct_type *mailbox_struct_type;
127 rte_swx_extern_type_constructor_t constructor;
128 rte_swx_extern_type_destructor_t destructor;
129 struct extern_type_member_func_tailq funcs;
133 TAILQ_HEAD(extern_type_tailq, extern_type);
136 TAILQ_ENTRY(extern_obj) node;
137 char name[RTE_SWX_NAME_SIZE];
138 struct extern_type *type;
144 TAILQ_HEAD(extern_obj_tailq, extern_obj);
146 #ifndef RTE_SWX_EXTERN_TYPE_MEMBER_FUNCS_MAX
147 #define RTE_SWX_EXTERN_TYPE_MEMBER_FUNCS_MAX 8
150 struct extern_obj_runtime {
153 rte_swx_extern_type_member_func_t funcs[RTE_SWX_EXTERN_TYPE_MEMBER_FUNCS_MAX];
160 TAILQ_ENTRY(extern_func) node;
161 char name[RTE_SWX_NAME_SIZE];
162 struct struct_type *mailbox_struct_type;
163 rte_swx_extern_func_t func;
168 TAILQ_HEAD(extern_func_tailq, extern_func);
170 struct extern_func_runtime {
172 rte_swx_extern_func_t func;
179 TAILQ_ENTRY(header) node;
180 char name[RTE_SWX_NAME_SIZE];
181 struct struct_type *st;
186 TAILQ_HEAD(header_tailq, header);
188 struct header_runtime {
193 struct header_out_runtime {
203 /* Packet headers are always in Network Byte Order (NBO), i.e. big endian.
204 * Packet meta-data fields are always assumed to be in Host Byte Order (HBO).
205 * Table entry fields can be in either NBO or HBO; they are assumed to be in HBO
206 * when transferred to packet meta-data and in NBO when transferred to packet
210 /* Notation conventions:
211 * -Header field: H = h.header.field (dst/src)
212 * -Meta-data field: M = m.field (dst/src)
213 * -Extern object mailbox field: E = e.field (dst/src)
214 * -Extern function mailbox field: F = f.field (dst/src)
215 * -Table action data field: T = t.field (src only)
216 * -Immediate value: I = 32-bit unsigned value (src only)
219 enum instruction_type {
226 INSTR_TX, /* port_out = M */
227 INSTR_TX_I, /* port_out = I */
229 /* extract h.header */
239 /* extract h.header m.last_field_size */
242 /* lookahead h.header */
256 /* validate h.header */
259 /* invalidate h.header */
260 INSTR_HDR_INVALIDATE,
264 * dst = HMEF, src = HMEFTI
266 INSTR_MOV, /* dst = MEF, src = MEFT */
267 INSTR_MOV_MH, /* dst = MEF, src = H */
268 INSTR_MOV_HM, /* dst = H, src = MEFT */
269 INSTR_MOV_HH, /* dst = H, src = H */
270 INSTR_MOV_I, /* dst = HMEF, src = I */
272 /* dma h.header t.field
273 * memcpy(h.header, t.field, sizeof(h.header))
286 * dst = HMEF, src = HMEFTI
288 INSTR_ALU_ADD, /* dst = MEF, src = MEF */
289 INSTR_ALU_ADD_MH, /* dst = MEF, src = H */
290 INSTR_ALU_ADD_HM, /* dst = H, src = MEF */
291 INSTR_ALU_ADD_HH, /* dst = H, src = H */
292 INSTR_ALU_ADD_MI, /* dst = MEF, src = I */
293 INSTR_ALU_ADD_HI, /* dst = H, src = I */
297 * dst = HMEF, src = HMEFTI
299 INSTR_ALU_SUB, /* dst = MEF, src = MEF */
300 INSTR_ALU_SUB_MH, /* dst = MEF, src = H */
301 INSTR_ALU_SUB_HM, /* dst = H, src = MEF */
302 INSTR_ALU_SUB_HH, /* dst = H, src = H */
303 INSTR_ALU_SUB_MI, /* dst = MEF, src = I */
304 INSTR_ALU_SUB_HI, /* dst = H, src = I */
307 * dst = dst '+ src[0:1] '+ src[2:3] + ...
308 * dst = H, src = {H, h.header}
310 INSTR_ALU_CKADD_FIELD, /* src = H */
311 INSTR_ALU_CKADD_STRUCT20, /* src = h.header, with sizeof(header) = 20 */
312 INSTR_ALU_CKADD_STRUCT, /* src = h.hdeader, with any sizeof(header) */
318 INSTR_ALU_CKSUB_FIELD,
322 * dst = HMEF, src = HMEFTI
324 INSTR_ALU_AND, /* dst = MEF, src = MEFT */
325 INSTR_ALU_AND_MH, /* dst = MEF, src = H */
326 INSTR_ALU_AND_HM, /* dst = H, src = MEFT */
327 INSTR_ALU_AND_HH, /* dst = H, src = H */
328 INSTR_ALU_AND_I, /* dst = HMEF, src = I */
332 * dst = HMEF, src = HMEFTI
334 INSTR_ALU_OR, /* dst = MEF, src = MEFT */
335 INSTR_ALU_OR_MH, /* dst = MEF, src = H */
336 INSTR_ALU_OR_HM, /* dst = H, src = MEFT */
337 INSTR_ALU_OR_HH, /* dst = H, src = H */
338 INSTR_ALU_OR_I, /* dst = HMEF, src = I */
342 * dst = HMEF, src = HMEFTI
344 INSTR_ALU_XOR, /* dst = MEF, src = MEFT */
345 INSTR_ALU_XOR_MH, /* dst = MEF, src = H */
346 INSTR_ALU_XOR_HM, /* dst = H, src = MEFT */
347 INSTR_ALU_XOR_HH, /* dst = H, src = H */
348 INSTR_ALU_XOR_I, /* dst = HMEF, src = I */
352 * dst = HMEF, src = HMEFTI
354 INSTR_ALU_SHL, /* dst = MEF, src = MEF */
355 INSTR_ALU_SHL_MH, /* dst = MEF, src = H */
356 INSTR_ALU_SHL_HM, /* dst = H, src = MEF */
357 INSTR_ALU_SHL_HH, /* dst = H, src = H */
358 INSTR_ALU_SHL_MI, /* dst = MEF, src = I */
359 INSTR_ALU_SHL_HI, /* dst = H, src = I */
363 * dst = HMEF, src = HMEFTI
365 INSTR_ALU_SHR, /* dst = MEF, src = MEF */
366 INSTR_ALU_SHR_MH, /* dst = MEF, src = H */
367 INSTR_ALU_SHR_HM, /* dst = H, src = MEF */
368 INSTR_ALU_SHR_HH, /* dst = H, src = H */
369 INSTR_ALU_SHR_MI, /* dst = MEF, src = I */
370 INSTR_ALU_SHR_HI, /* dst = H, src = I */
372 /* regprefetch REGARRAY index
373 * prefetch REGARRAY[index]
376 INSTR_REGPREFETCH_RH, /* index = H */
377 INSTR_REGPREFETCH_RM, /* index = MEFT */
378 INSTR_REGPREFETCH_RI, /* index = I */
380 /* regrd dst REGARRAY index
381 * dst = REGARRAY[index]
382 * dst = HMEF, index = HMEFTI
384 INSTR_REGRD_HRH, /* dst = H, index = H */
385 INSTR_REGRD_HRM, /* dst = H, index = MEFT */
386 INSTR_REGRD_HRI, /* dst = H, index = I */
387 INSTR_REGRD_MRH, /* dst = MEF, index = H */
388 INSTR_REGRD_MRM, /* dst = MEF, index = MEFT */
389 INSTR_REGRD_MRI, /* dst = MEF, index = I */
391 /* regwr REGARRAY index src
392 * REGARRAY[index] = src
393 * index = HMEFTI, src = HMEFTI
395 INSTR_REGWR_RHH, /* index = H, src = H */
396 INSTR_REGWR_RHM, /* index = H, src = MEFT */
397 INSTR_REGWR_RHI, /* index = H, src = I */
398 INSTR_REGWR_RMH, /* index = MEFT, src = H */
399 INSTR_REGWR_RMM, /* index = MEFT, src = MEFT */
400 INSTR_REGWR_RMI, /* index = MEFT, src = I */
401 INSTR_REGWR_RIH, /* index = I, src = H */
402 INSTR_REGWR_RIM, /* index = I, src = MEFT */
403 INSTR_REGWR_RII, /* index = I, src = I */
405 /* regadd REGARRAY index src
406 * REGARRAY[index] += src
407 * index = HMEFTI, src = HMEFTI
409 INSTR_REGADD_RHH, /* index = H, src = H */
410 INSTR_REGADD_RHM, /* index = H, src = MEFT */
411 INSTR_REGADD_RHI, /* index = H, src = I */
412 INSTR_REGADD_RMH, /* index = MEFT, src = H */
413 INSTR_REGADD_RMM, /* index = MEFT, src = MEFT */
414 INSTR_REGADD_RMI, /* index = MEFT, src = I */
415 INSTR_REGADD_RIH, /* index = I, src = H */
416 INSTR_REGADD_RIM, /* index = I, src = MEFT */
417 INSTR_REGADD_RII, /* index = I, src = I */
419 /* metprefetch METARRAY index
420 * prefetch METARRAY[index]
423 INSTR_METPREFETCH_H, /* index = H */
424 INSTR_METPREFETCH_M, /* index = MEFT */
425 INSTR_METPREFETCH_I, /* index = I */
427 /* meter METARRAY index length color_in color_out
428 * color_out = meter(METARRAY[index], length, color_in)
429 * index = HMEFTI, length = HMEFT, color_in = MEFTI, color_out = MEF
431 INSTR_METER_HHM, /* index = H, length = H, color_in = MEFT */
432 INSTR_METER_HHI, /* index = H, length = H, color_in = I */
433 INSTR_METER_HMM, /* index = H, length = MEFT, color_in = MEFT */
434 INSTR_METER_HMI, /* index = H, length = MEFT, color_in = I */
435 INSTR_METER_MHM, /* index = MEFT, length = H, color_in = MEFT */
436 INSTR_METER_MHI, /* index = MEFT, length = H, color_in = I */
437 INSTR_METER_MMM, /* index = MEFT, length = MEFT, color_in = MEFT */
438 INSTR_METER_MMI, /* index = MEFT, length = MEFT, color_in = I */
439 INSTR_METER_IHM, /* index = I, length = H, color_in = MEFT */
440 INSTR_METER_IHI, /* index = I, length = H, color_in = I */
441 INSTR_METER_IMM, /* index = I, length = MEFT, color_in = MEFT */
442 INSTR_METER_IMI, /* index = I, length = MEFT, color_in = I */
449 /* learn LEARNER ACTION_NAME */
453 INSTR_LEARNER_FORGET,
455 /* extern e.obj.func */
466 /* jmpv LABEL h.header
467 * Jump if header is valid
471 /* jmpnv LABEL h.header
472 * Jump if header is invalid
477 * Jump if table lookup hit
482 * Jump if table lookup miss
489 INSTR_JMP_ACTION_HIT,
491 /* jmpna LABEL ACTION
492 * Jump if action not run
494 INSTR_JMP_ACTION_MISS,
497 * Jump if a is equal to b
498 * a = HMEFT, b = HMEFTI
500 INSTR_JMP_EQ, /* a = MEFT, b = MEFT */
501 INSTR_JMP_EQ_MH, /* a = MEFT, b = H */
502 INSTR_JMP_EQ_HM, /* a = H, b = MEFT */
503 INSTR_JMP_EQ_HH, /* a = H, b = H */
504 INSTR_JMP_EQ_I, /* (a, b) = (MEFT, I) or (a, b) = (H, I) */
507 * Jump if a is not equal to b
508 * a = HMEFT, b = HMEFTI
510 INSTR_JMP_NEQ, /* a = MEFT, b = MEFT */
511 INSTR_JMP_NEQ_MH, /* a = MEFT, b = H */
512 INSTR_JMP_NEQ_HM, /* a = H, b = MEFT */
513 INSTR_JMP_NEQ_HH, /* a = H, b = H */
514 INSTR_JMP_NEQ_I, /* (a, b) = (MEFT, I) or (a, b) = (H, I) */
517 * Jump if a is less than b
518 * a = HMEFT, b = HMEFTI
520 INSTR_JMP_LT, /* a = MEFT, b = MEFT */
521 INSTR_JMP_LT_MH, /* a = MEFT, b = H */
522 INSTR_JMP_LT_HM, /* a = H, b = MEFT */
523 INSTR_JMP_LT_HH, /* a = H, b = H */
524 INSTR_JMP_LT_MI, /* a = MEFT, b = I */
525 INSTR_JMP_LT_HI, /* a = H, b = I */
528 * Jump if a is greater than b
529 * a = HMEFT, b = HMEFTI
531 INSTR_JMP_GT, /* a = MEFT, b = MEFT */
532 INSTR_JMP_GT_MH, /* a = MEFT, b = H */
533 INSTR_JMP_GT_HM, /* a = H, b = MEFT */
534 INSTR_JMP_GT_HH, /* a = H, b = H */
535 INSTR_JMP_GT_MI, /* a = MEFT, b = I */
536 INSTR_JMP_GT_HI, /* a = H, b = I */
544 struct instr_operand {
565 uint8_t header_id[8];
566 uint8_t struct_id[8];
571 struct instr_hdr_validity {
583 struct instr_extern_obj {
588 struct instr_extern_func {
592 struct instr_dst_src {
593 struct instr_operand dst;
595 struct instr_operand src;
600 struct instr_regarray {
605 struct instr_operand idx;
610 struct instr_operand dstsrc;
620 struct instr_operand idx;
624 struct instr_operand length;
627 struct instr_operand color_in;
628 uint32_t color_in_val;
631 struct instr_operand color_out;
636 uint8_t header_id[8];
637 uint8_t struct_id[8];
648 struct instruction *ip;
651 struct instr_operand a;
657 struct instr_operand b;
663 enum instruction_type type;
666 struct instr_hdr_validity valid;
667 struct instr_dst_src mov;
668 struct instr_regarray regarray;
669 struct instr_meter meter;
670 struct instr_dma dma;
671 struct instr_dst_src alu;
672 struct instr_table table;
673 struct instr_learn learn;
674 struct instr_extern_obj ext_obj;
675 struct instr_extern_func ext_func;
676 struct instr_jmp jmp;
680 struct instruction_data {
681 char label[RTE_SWX_NAME_SIZE];
682 char jmp_label[RTE_SWX_NAME_SIZE];
683 uint32_t n_users; /* user = jmp instruction to this instruction. */
691 TAILQ_ENTRY(action) node;
692 char name[RTE_SWX_NAME_SIZE];
693 struct struct_type *st;
694 int *args_endianness; /* 0 = Host Byte Order (HBO); 1 = Network Byte Order (NBO). */
695 struct instruction *instructions;
696 uint32_t n_instructions;
700 TAILQ_HEAD(action_tailq, action);
706 TAILQ_ENTRY(table_type) node;
707 char name[RTE_SWX_NAME_SIZE];
708 enum rte_swx_table_match_type match_type;
709 struct rte_swx_table_ops ops;
712 TAILQ_HEAD(table_type_tailq, table_type);
715 enum rte_swx_table_match_type match_type;
720 TAILQ_ENTRY(table) node;
721 char name[RTE_SWX_NAME_SIZE];
722 char args[RTE_SWX_NAME_SIZE];
723 struct table_type *type; /* NULL when n_fields == 0. */
726 struct match_field *fields;
728 struct header *header; /* Only valid when n_fields > 0. */
731 struct action **actions;
732 struct action *default_action;
733 uint8_t *default_action_data;
735 int default_action_is_const;
736 uint32_t action_data_size_max;
742 TAILQ_HEAD(table_tailq, table);
744 struct table_runtime {
745 rte_swx_table_lookup_t func;
750 struct table_statistics {
751 uint64_t n_pkts_hit[2]; /* 0 = Miss, 1 = Hit. */
752 uint64_t *n_pkts_action;
759 TAILQ_ENTRY(selector) node;
760 char name[RTE_SWX_NAME_SIZE];
762 struct field *group_id_field;
763 struct field **selector_fields;
764 uint32_t n_selector_fields;
765 struct header *selector_header;
766 struct field *member_id_field;
768 uint32_t n_groups_max;
769 uint32_t n_members_per_group_max;
774 TAILQ_HEAD(selector_tailq, selector);
776 struct selector_runtime {
778 uint8_t **group_id_buffer;
779 uint8_t **selector_buffer;
780 uint8_t **member_id_buffer;
783 struct selector_statistics {
791 TAILQ_ENTRY(learner) node;
792 char name[RTE_SWX_NAME_SIZE];
795 struct field **fields;
797 struct header *header;
800 struct action **actions;
801 struct field **action_arg;
802 struct action *default_action;
803 uint8_t *default_action_data;
805 int default_action_is_const;
806 uint32_t action_data_size_max;
813 TAILQ_HEAD(learner_tailq, learner);
815 struct learner_runtime {
818 uint8_t **action_data;
821 struct learner_statistics {
822 uint64_t n_pkts_hit[2]; /* 0 = Miss, 1 = Hit. */
823 uint64_t n_pkts_learn[2]; /* 0 = Learn OK, 1 = Learn error. */
824 uint64_t n_pkts_forget;
825 uint64_t *n_pkts_action;
832 TAILQ_ENTRY(regarray) node;
833 char name[RTE_SWX_NAME_SIZE];
839 TAILQ_HEAD(regarray_tailq, regarray);
841 struct regarray_runtime {
849 struct meter_profile {
850 TAILQ_ENTRY(meter_profile) node;
851 char name[RTE_SWX_NAME_SIZE];
852 struct rte_meter_trtcm_params params;
853 struct rte_meter_trtcm_profile profile;
857 TAILQ_HEAD(meter_profile_tailq, meter_profile);
860 TAILQ_ENTRY(metarray) node;
861 char name[RTE_SWX_NAME_SIZE];
866 TAILQ_HEAD(metarray_tailq, metarray);
869 struct rte_meter_trtcm m;
870 struct meter_profile *profile;
871 enum rte_color color_mask;
874 uint64_t n_pkts[RTE_COLORS];
875 uint64_t n_bytes[RTE_COLORS];
878 struct metarray_runtime {
879 struct meter *metarray;
888 struct rte_swx_pkt pkt;
894 /* Packet headers. */
895 struct header_runtime *headers; /* Extracted or generated headers. */
896 struct header_out_runtime *headers_out; /* Emitted headers. */
897 uint8_t *header_storage;
898 uint8_t *header_out_storage;
899 uint64_t valid_headers;
900 uint32_t n_headers_out;
902 /* Packet meta-data. */
906 struct table_runtime *tables;
907 struct selector_runtime *selectors;
908 struct learner_runtime *learners;
909 struct rte_swx_table_state *table_state;
911 int hit; /* 0 = Miss, 1 = Hit. */
915 /* Extern objects and functions. */
916 struct extern_obj_runtime *extern_objs;
917 struct extern_func_runtime *extern_funcs;
920 struct instruction *ip;
921 struct instruction *ret;
924 #define MASK64_BIT_GET(mask, pos) ((mask) & (1LLU << (pos)))
925 #define MASK64_BIT_SET(mask, pos) ((mask) | (1LLU << (pos)))
926 #define MASK64_BIT_CLR(mask, pos) ((mask) & ~(1LLU << (pos)))
928 #define HEADER_VALID(thread, header_id) \
929 MASK64_BIT_GET((thread)->valid_headers, header_id)
931 static inline uint64_t
932 instr_operand_hbo(struct thread *t, const struct instr_operand *x)
934 uint8_t *x_struct = t->structs[x->struct_id];
935 uint64_t *x64_ptr = (uint64_t *)&x_struct[x->offset];
936 uint64_t x64 = *x64_ptr;
937 uint64_t x64_mask = UINT64_MAX >> (64 - x->n_bits);
939 return x64 & x64_mask;
942 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
944 static inline uint64_t
945 instr_operand_nbo(struct thread *t, const struct instr_operand *x)
947 uint8_t *x_struct = t->structs[x->struct_id];
948 uint64_t *x64_ptr = (uint64_t *)&x_struct[x->offset];
949 uint64_t x64 = *x64_ptr;
951 return ntoh64(x64) >> (64 - x->n_bits);
956 #define instr_operand_nbo instr_operand_hbo
960 #define ALU(thread, ip, operator) \
962 uint8_t *dst_struct = (thread)->structs[(ip)->alu.dst.struct_id]; \
963 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[(ip)->alu.dst.offset]; \
964 uint64_t dst64 = *dst64_ptr; \
965 uint64_t dst64_mask = UINT64_MAX >> (64 - (ip)->alu.dst.n_bits); \
966 uint64_t dst = dst64 & dst64_mask; \
968 uint8_t *src_struct = (thread)->structs[(ip)->alu.src.struct_id]; \
969 uint64_t *src64_ptr = (uint64_t *)&src_struct[(ip)->alu.src.offset]; \
970 uint64_t src64 = *src64_ptr; \
971 uint64_t src64_mask = UINT64_MAX >> (64 - (ip)->alu.src.n_bits); \
972 uint64_t src = src64 & src64_mask; \
974 uint64_t result = dst operator src; \
976 *dst64_ptr = (dst64 & ~dst64_mask) | (result & dst64_mask); \
979 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
981 #define ALU_MH(thread, ip, operator) \
983 uint8_t *dst_struct = (thread)->structs[(ip)->alu.dst.struct_id]; \
984 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[(ip)->alu.dst.offset]; \
985 uint64_t dst64 = *dst64_ptr; \
986 uint64_t dst64_mask = UINT64_MAX >> (64 - (ip)->alu.dst.n_bits); \
987 uint64_t dst = dst64 & dst64_mask; \
989 uint8_t *src_struct = (thread)->structs[(ip)->alu.src.struct_id]; \
990 uint64_t *src64_ptr = (uint64_t *)&src_struct[(ip)->alu.src.offset]; \
991 uint64_t src64 = *src64_ptr; \
992 uint64_t src = ntoh64(src64) >> (64 - (ip)->alu.src.n_bits); \
994 uint64_t result = dst operator src; \
996 *dst64_ptr = (dst64 & ~dst64_mask) | (result & dst64_mask); \
999 #define ALU_HM(thread, ip, operator) \
1001 uint8_t *dst_struct = (thread)->structs[(ip)->alu.dst.struct_id]; \
1002 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[(ip)->alu.dst.offset]; \
1003 uint64_t dst64 = *dst64_ptr; \
1004 uint64_t dst64_mask = UINT64_MAX >> (64 - (ip)->alu.dst.n_bits); \
1005 uint64_t dst = ntoh64(dst64) >> (64 - (ip)->alu.dst.n_bits); \
1007 uint8_t *src_struct = (thread)->structs[(ip)->alu.src.struct_id]; \
1008 uint64_t *src64_ptr = (uint64_t *)&src_struct[(ip)->alu.src.offset]; \
1009 uint64_t src64 = *src64_ptr; \
1010 uint64_t src64_mask = UINT64_MAX >> (64 - (ip)->alu.src.n_bits); \
1011 uint64_t src = src64 & src64_mask; \
1013 uint64_t result = dst operator src; \
1014 result = hton64(result << (64 - (ip)->alu.dst.n_bits)); \
1016 *dst64_ptr = (dst64 & ~dst64_mask) | result; \
1019 #define ALU_HM_FAST(thread, ip, operator) \
1021 uint8_t *dst_struct = (thread)->structs[(ip)->alu.dst.struct_id]; \
1022 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[(ip)->alu.dst.offset]; \
1023 uint64_t dst64 = *dst64_ptr; \
1024 uint64_t dst64_mask = UINT64_MAX >> (64 - (ip)->alu.dst.n_bits); \
1025 uint64_t dst = dst64 & dst64_mask; \
1027 uint8_t *src_struct = (thread)->structs[(ip)->alu.src.struct_id]; \
1028 uint64_t *src64_ptr = (uint64_t *)&src_struct[(ip)->alu.src.offset]; \
1029 uint64_t src64 = *src64_ptr; \
1030 uint64_t src64_mask = UINT64_MAX >> (64 - (ip)->alu.src.n_bits); \
1031 uint64_t src = hton64(src64 & src64_mask) >> (64 - (ip)->alu.dst.n_bits); \
1033 uint64_t result = dst operator src; \
1035 *dst64_ptr = (dst64 & ~dst64_mask) | result; \
1038 #define ALU_HH(thread, ip, operator) \
1040 uint8_t *dst_struct = (thread)->structs[(ip)->alu.dst.struct_id]; \
1041 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[(ip)->alu.dst.offset]; \
1042 uint64_t dst64 = *dst64_ptr; \
1043 uint64_t dst64_mask = UINT64_MAX >> (64 - (ip)->alu.dst.n_bits); \
1044 uint64_t dst = ntoh64(dst64) >> (64 - (ip)->alu.dst.n_bits); \
1046 uint8_t *src_struct = (thread)->structs[(ip)->alu.src.struct_id]; \
1047 uint64_t *src64_ptr = (uint64_t *)&src_struct[(ip)->alu.src.offset]; \
1048 uint64_t src64 = *src64_ptr; \
1049 uint64_t src = ntoh64(src64) >> (64 - (ip)->alu.src.n_bits); \
1051 uint64_t result = dst operator src; \
1052 result = hton64(result << (64 - (ip)->alu.dst.n_bits)); \
1054 *dst64_ptr = (dst64 & ~dst64_mask) | result; \
1057 #define ALU_HH_FAST(thread, ip, operator) \
1059 uint8_t *dst_struct = (thread)->structs[(ip)->alu.dst.struct_id]; \
1060 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[(ip)->alu.dst.offset]; \
1061 uint64_t dst64 = *dst64_ptr; \
1062 uint64_t dst64_mask = UINT64_MAX >> (64 - (ip)->alu.dst.n_bits); \
1063 uint64_t dst = dst64 & dst64_mask; \
1065 uint8_t *src_struct = (thread)->structs[(ip)->alu.src.struct_id]; \
1066 uint64_t *src64_ptr = (uint64_t *)&src_struct[(ip)->alu.src.offset]; \
1067 uint64_t src64 = *src64_ptr; \
1068 uint64_t src = (src64 << (64 - (ip)->alu.src.n_bits)) >> (64 - (ip)->alu.dst.n_bits); \
1070 uint64_t result = dst operator src; \
1072 *dst64_ptr = (dst64 & ~dst64_mask) | result; \
1079 #define ALU_HM_FAST ALU
1081 #define ALU_HH_FAST ALU
1085 #define ALU_I(thread, ip, operator) \
1087 uint8_t *dst_struct = (thread)->structs[(ip)->alu.dst.struct_id]; \
1088 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[(ip)->alu.dst.offset]; \
1089 uint64_t dst64 = *dst64_ptr; \
1090 uint64_t dst64_mask = UINT64_MAX >> (64 - (ip)->alu.dst.n_bits); \
1091 uint64_t dst = dst64 & dst64_mask; \
1093 uint64_t src = (ip)->alu.src_val; \
1095 uint64_t result = dst operator src; \
1097 *dst64_ptr = (dst64 & ~dst64_mask) | (result & dst64_mask); \
1100 #define ALU_MI ALU_I
1102 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
1104 #define ALU_HI(thread, ip, operator) \
1106 uint8_t *dst_struct = (thread)->structs[(ip)->alu.dst.struct_id]; \
1107 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[(ip)->alu.dst.offset]; \
1108 uint64_t dst64 = *dst64_ptr; \
1109 uint64_t dst64_mask = UINT64_MAX >> (64 - (ip)->alu.dst.n_bits); \
1110 uint64_t dst = ntoh64(dst64) >> (64 - (ip)->alu.dst.n_bits); \
1112 uint64_t src = (ip)->alu.src_val; \
1114 uint64_t result = dst operator src; \
1115 result = hton64(result << (64 - (ip)->alu.dst.n_bits)); \
1117 *dst64_ptr = (dst64 & ~dst64_mask) | result; \
1122 #define ALU_HI ALU_I
1126 #define MOV(thread, ip) \
1128 uint8_t *dst_struct = (thread)->structs[(ip)->mov.dst.struct_id]; \
1129 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[(ip)->mov.dst.offset]; \
1130 uint64_t dst64 = *dst64_ptr; \
1131 uint64_t dst64_mask = UINT64_MAX >> (64 - (ip)->mov.dst.n_bits); \
1133 uint8_t *src_struct = (thread)->structs[(ip)->mov.src.struct_id]; \
1134 uint64_t *src64_ptr = (uint64_t *)&src_struct[(ip)->mov.src.offset]; \
1135 uint64_t src64 = *src64_ptr; \
1136 uint64_t src64_mask = UINT64_MAX >> (64 - (ip)->mov.src.n_bits); \
1137 uint64_t src = src64 & src64_mask; \
1139 *dst64_ptr = (dst64 & ~dst64_mask) | (src & dst64_mask); \
1142 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
1144 #define MOV_MH(thread, ip) \
1146 uint8_t *dst_struct = (thread)->structs[(ip)->mov.dst.struct_id]; \
1147 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[(ip)->mov.dst.offset]; \
1148 uint64_t dst64 = *dst64_ptr; \
1149 uint64_t dst64_mask = UINT64_MAX >> (64 - (ip)->mov.dst.n_bits); \
1151 uint8_t *src_struct = (thread)->structs[(ip)->mov.src.struct_id]; \
1152 uint64_t *src64_ptr = (uint64_t *)&src_struct[(ip)->mov.src.offset]; \
1153 uint64_t src64 = *src64_ptr; \
1154 uint64_t src = ntoh64(src64) >> (64 - (ip)->mov.src.n_bits); \
1156 *dst64_ptr = (dst64 & ~dst64_mask) | (src & dst64_mask); \
1159 #define MOV_HM(thread, ip) \
1161 uint8_t *dst_struct = (thread)->structs[(ip)->mov.dst.struct_id]; \
1162 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[(ip)->mov.dst.offset]; \
1163 uint64_t dst64 = *dst64_ptr; \
1164 uint64_t dst64_mask = UINT64_MAX >> (64 - (ip)->mov.dst.n_bits); \
1166 uint8_t *src_struct = (thread)->structs[(ip)->mov.src.struct_id]; \
1167 uint64_t *src64_ptr = (uint64_t *)&src_struct[(ip)->mov.src.offset]; \
1168 uint64_t src64 = *src64_ptr; \
1169 uint64_t src64_mask = UINT64_MAX >> (64 - (ip)->mov.src.n_bits); \
1170 uint64_t src = src64 & src64_mask; \
1172 src = hton64(src) >> (64 - (ip)->mov.dst.n_bits); \
1173 *dst64_ptr = (dst64 & ~dst64_mask) | src; \
1176 #define MOV_HH(thread, ip) \
1178 uint8_t *dst_struct = (thread)->structs[(ip)->mov.dst.struct_id]; \
1179 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[(ip)->mov.dst.offset]; \
1180 uint64_t dst64 = *dst64_ptr; \
1181 uint64_t dst64_mask = UINT64_MAX >> (64 - (ip)->mov.dst.n_bits); \
1183 uint8_t *src_struct = (thread)->structs[(ip)->mov.src.struct_id]; \
1184 uint64_t *src64_ptr = (uint64_t *)&src_struct[(ip)->mov.src.offset]; \
1185 uint64_t src64 = *src64_ptr; \
1187 uint64_t src = src64 << (64 - (ip)->mov.src.n_bits); \
1188 src = src >> (64 - (ip)->mov.dst.n_bits); \
1189 *dst64_ptr = (dst64 & ~dst64_mask) | src; \
1200 #define MOV_I(thread, ip) \
1202 uint8_t *dst_struct = (thread)->structs[(ip)->mov.dst.struct_id]; \
1203 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[(ip)->mov.dst.offset]; \
1204 uint64_t dst64 = *dst64_ptr; \
1205 uint64_t dst64_mask = UINT64_MAX >> (64 - (ip)->mov.dst.n_bits); \
1207 uint64_t src = (ip)->mov.src_val; \
1209 *dst64_ptr = (dst64 & ~dst64_mask) | (src & dst64_mask); \
1212 #define JMP_CMP(thread, ip, operator) \
1214 uint8_t *a_struct = (thread)->structs[(ip)->jmp.a.struct_id]; \
1215 uint64_t *a64_ptr = (uint64_t *)&a_struct[(ip)->jmp.a.offset]; \
1216 uint64_t a64 = *a64_ptr; \
1217 uint64_t a64_mask = UINT64_MAX >> (64 - (ip)->jmp.a.n_bits); \
1218 uint64_t a = a64 & a64_mask; \
1220 uint8_t *b_struct = (thread)->structs[(ip)->jmp.b.struct_id]; \
1221 uint64_t *b64_ptr = (uint64_t *)&b_struct[(ip)->jmp.b.offset]; \
1222 uint64_t b64 = *b64_ptr; \
1223 uint64_t b64_mask = UINT64_MAX >> (64 - (ip)->jmp.b.n_bits); \
1224 uint64_t b = b64 & b64_mask; \
1226 (thread)->ip = (a operator b) ? (ip)->jmp.ip : ((thread)->ip + 1); \
1229 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
1231 #define JMP_CMP_MH(thread, ip, operator) \
1233 uint8_t *a_struct = (thread)->structs[(ip)->jmp.a.struct_id]; \
1234 uint64_t *a64_ptr = (uint64_t *)&a_struct[(ip)->jmp.a.offset]; \
1235 uint64_t a64 = *a64_ptr; \
1236 uint64_t a64_mask = UINT64_MAX >> (64 - (ip)->jmp.a.n_bits); \
1237 uint64_t a = a64 & a64_mask; \
1239 uint8_t *b_struct = (thread)->structs[(ip)->jmp.b.struct_id]; \
1240 uint64_t *b64_ptr = (uint64_t *)&b_struct[(ip)->jmp.b.offset]; \
1241 uint64_t b64 = *b64_ptr; \
1242 uint64_t b = ntoh64(b64) >> (64 - (ip)->jmp.b.n_bits); \
1244 (thread)->ip = (a operator b) ? (ip)->jmp.ip : ((thread)->ip + 1); \
1247 #define JMP_CMP_HM(thread, ip, operator) \
1249 uint8_t *a_struct = (thread)->structs[(ip)->jmp.a.struct_id]; \
1250 uint64_t *a64_ptr = (uint64_t *)&a_struct[(ip)->jmp.a.offset]; \
1251 uint64_t a64 = *a64_ptr; \
1252 uint64_t a = ntoh64(a64) >> (64 - (ip)->jmp.a.n_bits); \
1254 uint8_t *b_struct = (thread)->structs[(ip)->jmp.b.struct_id]; \
1255 uint64_t *b64_ptr = (uint64_t *)&b_struct[(ip)->jmp.b.offset]; \
1256 uint64_t b64 = *b64_ptr; \
1257 uint64_t b64_mask = UINT64_MAX >> (64 - (ip)->jmp.b.n_bits); \
1258 uint64_t b = b64 & b64_mask; \
1260 (thread)->ip = (a operator b) ? (ip)->jmp.ip : ((thread)->ip + 1); \
1263 #define JMP_CMP_HH(thread, ip, operator) \
1265 uint8_t *a_struct = (thread)->structs[(ip)->jmp.a.struct_id]; \
1266 uint64_t *a64_ptr = (uint64_t *)&a_struct[(ip)->jmp.a.offset]; \
1267 uint64_t a64 = *a64_ptr; \
1268 uint64_t a = ntoh64(a64) >> (64 - (ip)->jmp.a.n_bits); \
1270 uint8_t *b_struct = (thread)->structs[(ip)->jmp.b.struct_id]; \
1271 uint64_t *b64_ptr = (uint64_t *)&b_struct[(ip)->jmp.b.offset]; \
1272 uint64_t b64 = *b64_ptr; \
1273 uint64_t b = ntoh64(b64) >> (64 - (ip)->jmp.b.n_bits); \
1275 (thread)->ip = (a operator b) ? (ip)->jmp.ip : ((thread)->ip + 1); \
1278 #define JMP_CMP_HH_FAST(thread, ip, operator) \
1280 uint8_t *a_struct = (thread)->structs[(ip)->jmp.a.struct_id]; \
1281 uint64_t *a64_ptr = (uint64_t *)&a_struct[(ip)->jmp.a.offset]; \
1282 uint64_t a64 = *a64_ptr; \
1283 uint64_t a = a64 << (64 - (ip)->jmp.a.n_bits); \
1285 uint8_t *b_struct = (thread)->structs[(ip)->jmp.b.struct_id]; \
1286 uint64_t *b64_ptr = (uint64_t *)&b_struct[(ip)->jmp.b.offset]; \
1287 uint64_t b64 = *b64_ptr; \
1288 uint64_t b = b64 << (64 - (ip)->jmp.b.n_bits); \
1290 (thread)->ip = (a operator b) ? (ip)->jmp.ip : ((thread)->ip + 1); \
1295 #define JMP_CMP_MH JMP_CMP
1296 #define JMP_CMP_HM JMP_CMP
1297 #define JMP_CMP_HH JMP_CMP
1298 #define JMP_CMP_HH_FAST JMP_CMP
1302 #define JMP_CMP_I(thread, ip, operator) \
1304 uint8_t *a_struct = (thread)->structs[(ip)->jmp.a.struct_id]; \
1305 uint64_t *a64_ptr = (uint64_t *)&a_struct[(ip)->jmp.a.offset]; \
1306 uint64_t a64 = *a64_ptr; \
1307 uint64_t a64_mask = UINT64_MAX >> (64 - (ip)->jmp.a.n_bits); \
1308 uint64_t a = a64 & a64_mask; \
1310 uint64_t b = (ip)->jmp.b_val; \
1312 (thread)->ip = (a operator b) ? (ip)->jmp.ip : ((thread)->ip + 1); \
1315 #define JMP_CMP_MI JMP_CMP_I
1317 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
1319 #define JMP_CMP_HI(thread, ip, operator) \
1321 uint8_t *a_struct = (thread)->structs[(ip)->jmp.a.struct_id]; \
1322 uint64_t *a64_ptr = (uint64_t *)&a_struct[(ip)->jmp.a.offset]; \
1323 uint64_t a64 = *a64_ptr; \
1324 uint64_t a = ntoh64(a64) >> (64 - (ip)->jmp.a.n_bits); \
1326 uint64_t b = (ip)->jmp.b_val; \
1328 (thread)->ip = (a operator b) ? (ip)->jmp.ip : ((thread)->ip + 1); \
1333 #define JMP_CMP_HI JMP_CMP_I
1337 #define METADATA_READ(thread, offset, n_bits) \
1339 uint64_t *m64_ptr = (uint64_t *)&(thread)->metadata[offset]; \
1340 uint64_t m64 = *m64_ptr; \
1341 uint64_t m64_mask = UINT64_MAX >> (64 - (n_bits)); \
1345 #define METADATA_WRITE(thread, offset, n_bits, value) \
1347 uint64_t *m64_ptr = (uint64_t *)&(thread)->metadata[offset]; \
1348 uint64_t m64 = *m64_ptr; \
1349 uint64_t m64_mask = UINT64_MAX >> (64 - (n_bits)); \
1351 uint64_t m_new = value; \
1353 *m64_ptr = (m64 & ~m64_mask) | (m_new & m64_mask); \
1356 #ifndef RTE_SWX_PIPELINE_THREADS_MAX
1357 #define RTE_SWX_PIPELINE_THREADS_MAX 16
1360 struct rte_swx_pipeline {
1361 struct struct_type_tailq struct_types;
1362 struct port_in_type_tailq port_in_types;
1363 struct port_in_tailq ports_in;
1364 struct port_out_type_tailq port_out_types;
1365 struct port_out_tailq ports_out;
1366 struct extern_type_tailq extern_types;
1367 struct extern_obj_tailq extern_objs;
1368 struct extern_func_tailq extern_funcs;
1369 struct header_tailq headers;
1370 struct struct_type *metadata_st;
1371 uint32_t metadata_struct_id;
1372 struct action_tailq actions;
1373 struct table_type_tailq table_types;
1374 struct table_tailq tables;
1375 struct selector_tailq selectors;
1376 struct learner_tailq learners;
1377 struct regarray_tailq regarrays;
1378 struct meter_profile_tailq meter_profiles;
1379 struct metarray_tailq metarrays;
1381 struct port_in_runtime *in;
1382 struct port_out_runtime *out;
1383 struct instruction **action_instructions;
1384 struct rte_swx_table_state *table_state;
1385 struct table_statistics *table_stats;
1386 struct selector_statistics *selector_stats;
1387 struct learner_statistics *learner_stats;
1388 struct regarray_runtime *regarray_runtime;
1389 struct metarray_runtime *metarray_runtime;
1390 struct instruction *instructions;
1391 struct thread threads[RTE_SWX_PIPELINE_THREADS_MAX];
1394 uint32_t n_ports_in;
1395 uint32_t n_ports_out;
1396 uint32_t n_extern_objs;
1397 uint32_t n_extern_funcs;
1400 uint32_t n_selectors;
1401 uint32_t n_learners;
1402 uint32_t n_regarrays;
1403 uint32_t n_metarrays;
1407 uint32_t n_instructions;
1416 pipeline_port_inc(struct rte_swx_pipeline *p)
1418 p->port_id = (p->port_id + 1) & (p->n_ports_in - 1);
1422 thread_ip_reset(struct rte_swx_pipeline *p, struct thread *t)
1424 t->ip = p->instructions;
1428 thread_ip_set(struct thread *t, struct instruction *ip)
1434 thread_ip_action_call(struct rte_swx_pipeline *p,
1439 t->ip = p->action_instructions[action_id];
1443 thread_ip_inc(struct rte_swx_pipeline *p);
1446 thread_ip_inc(struct rte_swx_pipeline *p)
1448 struct thread *t = &p->threads[p->thread_id];
1454 thread_ip_inc_cond(struct thread *t, int cond)
1460 thread_yield(struct rte_swx_pipeline *p)
1462 p->thread_id = (p->thread_id + 1) & (RTE_SWX_PIPELINE_THREADS_MAX - 1);
1466 thread_yield_cond(struct rte_swx_pipeline *p, int cond)
1468 p->thread_id = (p->thread_id + cond) & (RTE_SWX_PIPELINE_THREADS_MAX - 1);
1475 __instr_rx_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
1477 struct port_in_runtime *port = &p->in[p->port_id];
1478 struct rte_swx_pkt *pkt = &t->pkt;
1482 pkt_received = port->pkt_rx(port->obj, pkt);
1483 t->ptr = &pkt->pkt[pkt->offset];
1484 rte_prefetch0(t->ptr);
1486 TRACE("[Thread %2u] rx %s from port %u\n",
1488 pkt_received ? "1 pkt" : "0 pkts",
1492 t->valid_headers = 0;
1493 t->n_headers_out = 0;
1496 METADATA_WRITE(t, ip->io.io.offset, ip->io.io.n_bits, p->port_id);
1499 t->table_state = p->table_state;
1502 pipeline_port_inc(p);
1504 return pkt_received;
1508 instr_rx_exec(struct rte_swx_pipeline *p)
1510 struct thread *t = &p->threads[p->thread_id];
1511 struct instruction *ip = t->ip;
1515 pkt_received = __instr_rx_exec(p, t, ip);
1518 thread_ip_inc_cond(t, pkt_received);
1526 emit_handler(struct thread *t)
1528 struct header_out_runtime *h0 = &t->headers_out[0];
1529 struct header_out_runtime *h1 = &t->headers_out[1];
1530 uint32_t offset = 0, i;
1532 /* No header change or header decapsulation. */
1533 if ((t->n_headers_out == 1) &&
1534 (h0->ptr + h0->n_bytes == t->ptr)) {
1535 TRACE("Emit handler: no header change or header decap.\n");
1537 t->pkt.offset -= h0->n_bytes;
1538 t->pkt.length += h0->n_bytes;
1543 /* Header encapsulation (optionally, with prior header decasulation). */
1544 if ((t->n_headers_out == 2) &&
1545 (h1->ptr + h1->n_bytes == t->ptr) &&
1546 (h0->ptr == h0->ptr0)) {
1549 TRACE("Emit handler: header encapsulation.\n");
1551 offset = h0->n_bytes + h1->n_bytes;
1552 memcpy(t->ptr - offset, h0->ptr, h0->n_bytes);
1553 t->pkt.offset -= offset;
1554 t->pkt.length += offset;
1559 /* For any other case. */
1560 TRACE("Emit handler: complex case.\n");
1562 for (i = 0; i < t->n_headers_out; i++) {
1563 struct header_out_runtime *h = &t->headers_out[i];
1565 memcpy(&t->header_out_storage[offset], h->ptr, h->n_bytes);
1566 offset += h->n_bytes;
1570 memcpy(t->ptr - offset, t->header_out_storage, offset);
1571 t->pkt.offset -= offset;
1572 t->pkt.length += offset;
1577 __instr_tx_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
1579 uint64_t port_id = METADATA_READ(t, ip->io.io.offset, ip->io.io.n_bits);
1580 struct port_out_runtime *port = &p->out[port_id];
1581 struct rte_swx_pkt *pkt = &t->pkt;
1583 TRACE("[Thread %2u]: tx 1 pkt to port %u\n",
1591 port->pkt_tx(port->obj, pkt);
1595 __instr_tx_i_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
1597 uint64_t port_id = ip->io.io.val;
1598 struct port_out_runtime *port = &p->out[port_id];
1599 struct rte_swx_pkt *pkt = &t->pkt;
1601 TRACE("[Thread %2u]: tx (i) 1 pkt to port %u\n",
1609 port->pkt_tx(port->obj, pkt);
1616 __instr_hdr_extract_many_exec(struct rte_swx_pipeline *p __rte_unused,
1618 const struct instruction *ip,
1621 uint64_t valid_headers = t->valid_headers;
1622 uint8_t *ptr = t->ptr;
1623 uint32_t offset = t->pkt.offset;
1624 uint32_t length = t->pkt.length;
1627 for (i = 0; i < n_extract; i++) {
1628 uint32_t header_id = ip->io.hdr.header_id[i];
1629 uint32_t struct_id = ip->io.hdr.struct_id[i];
1630 uint32_t n_bytes = ip->io.hdr.n_bytes[i];
1632 TRACE("[Thread %2u]: extract header %u (%u bytes)\n",
1638 t->structs[struct_id] = ptr;
1639 valid_headers = MASK64_BIT_SET(valid_headers, header_id);
1648 t->valid_headers = valid_headers;
1651 t->pkt.offset = offset;
1652 t->pkt.length = length;
1657 __instr_hdr_extract_exec(struct rte_swx_pipeline *p,
1659 const struct instruction *ip)
1661 __instr_hdr_extract_many_exec(p, t, ip, 1);
1665 __instr_hdr_extract2_exec(struct rte_swx_pipeline *p,
1667 const struct instruction *ip)
1669 TRACE("[Thread %2u] *** The next 2 instructions are fused. ***\n", p->thread_id);
1671 __instr_hdr_extract_many_exec(p, t, ip, 2);
1675 __instr_hdr_extract3_exec(struct rte_swx_pipeline *p,
1677 const struct instruction *ip)
1679 TRACE("[Thread %2u] *** The next 3 instructions are fused. ***\n", p->thread_id);
1681 __instr_hdr_extract_many_exec(p, t, ip, 3);
1685 __instr_hdr_extract4_exec(struct rte_swx_pipeline *p,
1687 const struct instruction *ip)
1689 TRACE("[Thread %2u] *** The next 4 instructions are fused. ***\n", p->thread_id);
1691 __instr_hdr_extract_many_exec(p, t, ip, 4);
1695 __instr_hdr_extract5_exec(struct rte_swx_pipeline *p,
1697 const struct instruction *ip)
1699 TRACE("[Thread %2u] *** The next 5 instructions are fused. ***\n", p->thread_id);
1701 __instr_hdr_extract_many_exec(p, t, ip, 5);
1705 __instr_hdr_extract6_exec(struct rte_swx_pipeline *p,
1707 const struct instruction *ip)
1709 TRACE("[Thread %2u] *** The next 6 instructions are fused. ***\n", p->thread_id);
1711 __instr_hdr_extract_many_exec(p, t, ip, 6);
1715 __instr_hdr_extract7_exec(struct rte_swx_pipeline *p,
1717 const struct instruction *ip)
1719 TRACE("[Thread %2u] *** The next 7 instructions are fused. ***\n", p->thread_id);
1721 __instr_hdr_extract_many_exec(p, t, ip, 7);
1725 __instr_hdr_extract8_exec(struct rte_swx_pipeline *p,
1727 const struct instruction *ip)
1729 TRACE("[Thread %2u] *** The next 8 instructions are fused. ***\n", p->thread_id);
1731 __instr_hdr_extract_many_exec(p, t, ip, 8);
1735 __instr_hdr_extract_m_exec(struct rte_swx_pipeline *p __rte_unused,
1737 const struct instruction *ip)
1739 uint64_t valid_headers = t->valid_headers;
1740 uint8_t *ptr = t->ptr;
1741 uint32_t offset = t->pkt.offset;
1742 uint32_t length = t->pkt.length;
1744 uint32_t n_bytes_last = METADATA_READ(t, ip->io.io.offset, ip->io.io.n_bits);
1745 uint32_t header_id = ip->io.hdr.header_id[0];
1746 uint32_t struct_id = ip->io.hdr.struct_id[0];
1747 uint32_t n_bytes = ip->io.hdr.n_bytes[0];
1749 struct header_runtime *h = &t->headers[header_id];
1751 TRACE("[Thread %2u]: extract header %u (%u + %u bytes)\n",
1757 n_bytes += n_bytes_last;
1760 t->structs[struct_id] = ptr;
1761 t->valid_headers = MASK64_BIT_SET(valid_headers, header_id);
1762 h->n_bytes = n_bytes;
1765 t->pkt.offset = offset + n_bytes;
1766 t->pkt.length = length - n_bytes;
1767 t->ptr = ptr + n_bytes;
1771 __instr_hdr_lookahead_exec(struct rte_swx_pipeline *p __rte_unused,
1773 const struct instruction *ip)
1775 uint64_t valid_headers = t->valid_headers;
1776 uint8_t *ptr = t->ptr;
1778 uint32_t header_id = ip->io.hdr.header_id[0];
1779 uint32_t struct_id = ip->io.hdr.struct_id[0];
1781 TRACE("[Thread %2u]: lookahead header %u\n",
1786 t->structs[struct_id] = ptr;
1787 t->valid_headers = MASK64_BIT_SET(valid_headers, header_id);
1794 __instr_hdr_emit_many_exec(struct rte_swx_pipeline *p __rte_unused,
1796 const struct instruction *ip,
1799 uint64_t valid_headers = t->valid_headers;
1800 uint32_t n_headers_out = t->n_headers_out;
1801 struct header_out_runtime *ho = &t->headers_out[n_headers_out - 1];
1802 uint8_t *ho_ptr = NULL;
1803 uint32_t ho_nbytes = 0, first = 1, i;
1805 for (i = 0; i < n_emit; i++) {
1806 uint32_t header_id = ip->io.hdr.header_id[i];
1807 uint32_t struct_id = ip->io.hdr.struct_id[i];
1809 struct header_runtime *hi = &t->headers[header_id];
1810 uint8_t *hi_ptr0 = hi->ptr0;
1811 uint32_t n_bytes = hi->n_bytes;
1813 uint8_t *hi_ptr = t->structs[struct_id];
1815 if (!MASK64_BIT_GET(valid_headers, header_id))
1818 TRACE("[Thread %2u]: emit header %u\n",
1826 if (!t->n_headers_out) {
1827 ho = &t->headers_out[0];
1833 ho_nbytes = n_bytes;
1840 ho_nbytes = ho->n_bytes;
1844 if (ho_ptr + ho_nbytes == hi_ptr) {
1845 ho_nbytes += n_bytes;
1847 ho->n_bytes = ho_nbytes;
1854 ho_nbytes = n_bytes;
1860 ho->n_bytes = ho_nbytes;
1861 t->n_headers_out = n_headers_out;
1865 __instr_hdr_emit_exec(struct rte_swx_pipeline *p,
1867 const struct instruction *ip)
1869 __instr_hdr_emit_many_exec(p, t, ip, 1);
1873 __instr_hdr_emit_tx_exec(struct rte_swx_pipeline *p,
1875 const struct instruction *ip)
1877 TRACE("[Thread %2u] *** The next 2 instructions are fused. ***\n", p->thread_id);
1879 __instr_hdr_emit_many_exec(p, t, ip, 1);
1880 __instr_tx_exec(p, t, ip);
1884 __instr_hdr_emit2_tx_exec(struct rte_swx_pipeline *p,
1886 const struct instruction *ip)
1888 TRACE("[Thread %2u] *** The next 3 instructions are fused. ***\n", p->thread_id);
1890 __instr_hdr_emit_many_exec(p, t, ip, 2);
1891 __instr_tx_exec(p, t, ip);
1895 __instr_hdr_emit3_tx_exec(struct rte_swx_pipeline *p,
1897 const struct instruction *ip)
1899 TRACE("[Thread %2u] *** The next 4 instructions are fused. ***\n", p->thread_id);
1901 __instr_hdr_emit_many_exec(p, t, ip, 3);
1902 __instr_tx_exec(p, t, ip);
1906 __instr_hdr_emit4_tx_exec(struct rte_swx_pipeline *p,
1908 const struct instruction *ip)
1910 TRACE("[Thread %2u] *** The next 5 instructions are fused. ***\n", p->thread_id);
1912 __instr_hdr_emit_many_exec(p, t, ip, 4);
1913 __instr_tx_exec(p, t, ip);
1917 __instr_hdr_emit5_tx_exec(struct rte_swx_pipeline *p,
1919 const struct instruction *ip)
1921 TRACE("[Thread %2u] *** The next 6 instructions are fused. ***\n", p->thread_id);
1923 __instr_hdr_emit_many_exec(p, t, ip, 5);
1924 __instr_tx_exec(p, t, ip);
1928 __instr_hdr_emit6_tx_exec(struct rte_swx_pipeline *p,
1930 const struct instruction *ip)
1932 TRACE("[Thread %2u] *** The next 7 instructions are fused. ***\n", p->thread_id);
1934 __instr_hdr_emit_many_exec(p, t, ip, 6);
1935 __instr_tx_exec(p, t, ip);
1939 __instr_hdr_emit7_tx_exec(struct rte_swx_pipeline *p,
1941 const struct instruction *ip)
1943 TRACE("[Thread %2u] *** The next 8 instructions are fused. ***\n", p->thread_id);
1945 __instr_hdr_emit_many_exec(p, t, ip, 7);
1946 __instr_tx_exec(p, t, ip);
1950 __instr_hdr_emit8_tx_exec(struct rte_swx_pipeline *p,
1952 const struct instruction *ip)
1954 TRACE("[Thread %2u] *** The next 9 instructions are fused. ***\n", p->thread_id);
1956 __instr_hdr_emit_many_exec(p, t, ip, 8);
1957 __instr_tx_exec(p, t, ip);
1964 __instr_hdr_validate_exec(struct rte_swx_pipeline *p __rte_unused,
1966 const struct instruction *ip)
1968 uint32_t header_id = ip->valid.header_id;
1970 TRACE("[Thread %2u] validate header %u\n", p->thread_id, header_id);
1973 t->valid_headers = MASK64_BIT_SET(t->valid_headers, header_id);
1980 __instr_hdr_invalidate_exec(struct rte_swx_pipeline *p __rte_unused,
1982 const struct instruction *ip)
1984 uint32_t header_id = ip->valid.header_id;
1986 TRACE("[Thread %2u] invalidate header %u\n", p->thread_id, header_id);
1989 t->valid_headers = MASK64_BIT_CLR(t->valid_headers, header_id);
1996 __instr_learn_exec(struct rte_swx_pipeline *p,
1998 const struct instruction *ip)
2000 uint64_t action_id = ip->learn.action_id;
2001 uint32_t learner_id = t->learner_id;
2002 struct rte_swx_table_state *ts = &t->table_state[p->n_tables +
2003 p->n_selectors + learner_id];
2004 struct learner_runtime *l = &t->learners[learner_id];
2005 struct learner_statistics *stats = &p->learner_stats[learner_id];
2009 status = rte_swx_table_learner_add(ts->obj,
2013 l->action_data[action_id]);
2015 TRACE("[Thread %2u] learner %u learn %s\n",
2018 status ? "ok" : "error");
2020 stats->n_pkts_learn[status] += 1;
2027 __instr_forget_exec(struct rte_swx_pipeline *p,
2029 const struct instruction *ip __rte_unused)
2031 uint32_t learner_id = t->learner_id;
2032 struct rte_swx_table_state *ts = &t->table_state[p->n_tables +
2033 p->n_selectors + learner_id];
2034 struct learner_runtime *l = &t->learners[learner_id];
2035 struct learner_statistics *stats = &p->learner_stats[learner_id];
2038 rte_swx_table_learner_delete(ts->obj, l->mailbox);
2040 TRACE("[Thread %2u] learner %u forget\n",
2044 stats->n_pkts_forget += 1;
2050 static inline uint32_t
2051 __instr_extern_obj_exec(struct rte_swx_pipeline *p __rte_unused,
2053 const struct instruction *ip)
2055 uint32_t obj_id = ip->ext_obj.ext_obj_id;
2056 uint32_t func_id = ip->ext_obj.func_id;
2057 struct extern_obj_runtime *obj = &t->extern_objs[obj_id];
2058 rte_swx_extern_type_member_func_t func = obj->funcs[func_id];
2061 TRACE("[Thread %2u] extern obj %u member func %u\n",
2066 done = func(obj->obj, obj->mailbox);
2071 static inline uint32_t
2072 __instr_extern_func_exec(struct rte_swx_pipeline *p __rte_unused,
2074 const struct instruction *ip)
2076 uint32_t ext_func_id = ip->ext_func.ext_func_id;
2077 struct extern_func_runtime *ext_func = &t->extern_funcs[ext_func_id];
2078 rte_swx_extern_func_t func = ext_func->func;
2081 TRACE("[Thread %2u] extern func %u\n",
2085 done = func(ext_func->mailbox);
2094 __instr_mov_exec(struct rte_swx_pipeline *p __rte_unused,
2096 const struct instruction *ip)
2098 TRACE("[Thread %2u] mov\n", p->thread_id);
2104 __instr_mov_mh_exec(struct rte_swx_pipeline *p __rte_unused,
2106 const struct instruction *ip)
2108 TRACE("[Thread %2u] mov (mh)\n", p->thread_id);
2114 __instr_mov_hm_exec(struct rte_swx_pipeline *p __rte_unused,
2116 const struct instruction *ip)
2118 TRACE("[Thread %2u] mov (hm)\n", p->thread_id);
2124 __instr_mov_hh_exec(struct rte_swx_pipeline *p __rte_unused,
2126 const struct instruction *ip)
2128 TRACE("[Thread %2u] mov (hh)\n", p->thread_id);
2134 __instr_mov_i_exec(struct rte_swx_pipeline *p __rte_unused,
2136 const struct instruction *ip)
2138 TRACE("[Thread %2u] mov m.f %" PRIx64 "\n", p->thread_id, ip->mov.src_val);
2147 __instr_dma_ht_many_exec(struct rte_swx_pipeline *p __rte_unused,
2149 const struct instruction *ip,
2152 uint8_t *action_data = t->structs[0];
2153 uint64_t valid_headers = t->valid_headers;
2156 for (i = 0; i < n_dma; i++) {
2157 uint32_t header_id = ip->dma.dst.header_id[i];
2158 uint32_t struct_id = ip->dma.dst.struct_id[i];
2159 uint32_t offset = ip->dma.src.offset[i];
2160 uint32_t n_bytes = ip->dma.n_bytes[i];
2162 struct header_runtime *h = &t->headers[header_id];
2163 uint8_t *h_ptr0 = h->ptr0;
2164 uint8_t *h_ptr = t->structs[struct_id];
2166 void *dst = MASK64_BIT_GET(valid_headers, header_id) ?
2168 void *src = &action_data[offset];
2170 TRACE("[Thread %2u] dma h.s t.f\n", p->thread_id);
2173 memcpy(dst, src, n_bytes);
2174 t->structs[struct_id] = dst;
2175 valid_headers = MASK64_BIT_SET(valid_headers, header_id);
2178 t->valid_headers = valid_headers;
2182 __instr_dma_ht_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
2184 __instr_dma_ht_many_exec(p, t, ip, 1);
2188 __instr_dma_ht2_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
2190 TRACE("[Thread %2u] *** The next 2 instructions are fused. ***\n", p->thread_id);
2192 __instr_dma_ht_many_exec(p, t, ip, 2);
2196 __instr_dma_ht3_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
2198 TRACE("[Thread %2u] *** The next 3 instructions are fused. ***\n", p->thread_id);
2200 __instr_dma_ht_many_exec(p, t, ip, 3);
2204 __instr_dma_ht4_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
2206 TRACE("[Thread %2u] *** The next 4 instructions are fused. ***\n", p->thread_id);
2208 __instr_dma_ht_many_exec(p, t, ip, 4);
2212 __instr_dma_ht5_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
2214 TRACE("[Thread %2u] *** The next 5 instructions are fused. ***\n", p->thread_id);
2216 __instr_dma_ht_many_exec(p, t, ip, 5);
2220 __instr_dma_ht6_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
2222 TRACE("[Thread %2u] *** The next 6 instructions are fused. ***\n", p->thread_id);
2224 __instr_dma_ht_many_exec(p, t, ip, 6);
2228 __instr_dma_ht7_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
2230 TRACE("[Thread %2u] *** The next 7 instructions are fused. ***\n", p->thread_id);
2232 __instr_dma_ht_many_exec(p, t, ip, 7);
2236 __instr_dma_ht8_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
2238 TRACE("[Thread %2u] *** The next 8 instructions are fused. ***\n", p->thread_id);
2240 __instr_dma_ht_many_exec(p, t, ip, 8);
2247 __instr_alu_add_exec(struct rte_swx_pipeline *p __rte_unused,
2249 const struct instruction *ip)
2251 TRACE("[Thread %2u] add\n", p->thread_id);
2257 __instr_alu_add_mh_exec(struct rte_swx_pipeline *p __rte_unused,
2259 const struct instruction *ip)
2261 TRACE("[Thread %2u] add (mh)\n", p->thread_id);
2267 __instr_alu_add_hm_exec(struct rte_swx_pipeline *p __rte_unused,
2269 const struct instruction *ip)
2271 TRACE("[Thread %2u] add (hm)\n", p->thread_id);
2277 __instr_alu_add_hh_exec(struct rte_swx_pipeline *p __rte_unused,
2279 const struct instruction *ip)
2281 TRACE("[Thread %2u] add (hh)\n", p->thread_id);
2287 __instr_alu_add_mi_exec(struct rte_swx_pipeline *p __rte_unused,
2289 const struct instruction *ip)
2291 TRACE("[Thread %2u] add (mi)\n", p->thread_id);
2297 __instr_alu_add_hi_exec(struct rte_swx_pipeline *p __rte_unused,
2299 const struct instruction *ip)
2301 TRACE("[Thread %2u] add (hi)\n", p->thread_id);
2307 __instr_alu_sub_exec(struct rte_swx_pipeline *p __rte_unused,
2309 const struct instruction *ip)
2311 TRACE("[Thread %2u] sub\n", p->thread_id);
2317 __instr_alu_sub_mh_exec(struct rte_swx_pipeline *p __rte_unused,
2319 const struct instruction *ip)
2321 TRACE("[Thread %2u] sub (mh)\n", p->thread_id);
2327 __instr_alu_sub_hm_exec(struct rte_swx_pipeline *p __rte_unused,
2329 const struct instruction *ip)
2331 TRACE("[Thread %2u] sub (hm)\n", p->thread_id);
2337 __instr_alu_sub_hh_exec(struct rte_swx_pipeline *p __rte_unused,
2339 const struct instruction *ip)
2341 TRACE("[Thread %2u] sub (hh)\n", p->thread_id);
2347 __instr_alu_sub_mi_exec(struct rte_swx_pipeline *p __rte_unused,
2349 const struct instruction *ip)
2351 TRACE("[Thread %2u] sub (mi)\n", p->thread_id);
2357 __instr_alu_sub_hi_exec(struct rte_swx_pipeline *p __rte_unused,
2359 const struct instruction *ip)
2361 TRACE("[Thread %2u] sub (hi)\n", p->thread_id);
2367 __instr_alu_shl_exec(struct rte_swx_pipeline *p __rte_unused,
2369 const struct instruction *ip)
2371 TRACE("[Thread %2u] shl\n", p->thread_id);
2377 __instr_alu_shl_mh_exec(struct rte_swx_pipeline *p __rte_unused,
2379 const struct instruction *ip)
2381 TRACE("[Thread %2u] shl (mh)\n", p->thread_id);
2387 __instr_alu_shl_hm_exec(struct rte_swx_pipeline *p __rte_unused,
2389 const struct instruction *ip)
2391 TRACE("[Thread %2u] shl (hm)\n", p->thread_id);
2397 __instr_alu_shl_hh_exec(struct rte_swx_pipeline *p __rte_unused,
2399 const struct instruction *ip)
2401 TRACE("[Thread %2u] shl (hh)\n", p->thread_id);
2407 __instr_alu_shl_mi_exec(struct rte_swx_pipeline *p __rte_unused,
2409 const struct instruction *ip)
2411 TRACE("[Thread %2u] shl (mi)\n", p->thread_id);
2417 __instr_alu_shl_hi_exec(struct rte_swx_pipeline *p __rte_unused,
2419 const struct instruction *ip)
2421 TRACE("[Thread %2u] shl (hi)\n", p->thread_id);
2427 __instr_alu_shr_exec(struct rte_swx_pipeline *p __rte_unused,
2429 const struct instruction *ip)
2431 TRACE("[Thread %2u] shr\n", p->thread_id);
2437 __instr_alu_shr_mh_exec(struct rte_swx_pipeline *p __rte_unused,
2439 const struct instruction *ip)
2441 TRACE("[Thread %2u] shr (mh)\n", p->thread_id);
2447 __instr_alu_shr_hm_exec(struct rte_swx_pipeline *p __rte_unused,
2449 const struct instruction *ip)
2451 TRACE("[Thread %2u] shr (hm)\n", p->thread_id);
2457 __instr_alu_shr_hh_exec(struct rte_swx_pipeline *p __rte_unused,
2459 const struct instruction *ip)
2461 TRACE("[Thread %2u] shr (hh)\n", p->thread_id);
2467 __instr_alu_shr_mi_exec(struct rte_swx_pipeline *p __rte_unused,
2469 const struct instruction *ip)
2471 TRACE("[Thread %2u] shr (mi)\n", p->thread_id);
2478 __instr_alu_shr_hi_exec(struct rte_swx_pipeline *p __rte_unused,
2480 const struct instruction *ip)
2482 TRACE("[Thread %2u] shr (hi)\n", p->thread_id);
2488 __instr_alu_and_exec(struct rte_swx_pipeline *p __rte_unused,
2490 const struct instruction *ip)
2492 TRACE("[Thread %2u] and\n", p->thread_id);
2498 __instr_alu_and_mh_exec(struct rte_swx_pipeline *p __rte_unused,
2500 const struct instruction *ip)
2502 TRACE("[Thread %2u] and (mh)\n", p->thread_id);
2508 __instr_alu_and_hm_exec(struct rte_swx_pipeline *p __rte_unused,
2510 const struct instruction *ip)
2512 TRACE("[Thread %2u] and (hm)\n", p->thread_id);
2514 ALU_HM_FAST(t, ip, &);
2518 __instr_alu_and_hh_exec(struct rte_swx_pipeline *p __rte_unused,
2520 const struct instruction *ip)
2522 TRACE("[Thread %2u] and (hh)\n", p->thread_id);
2524 ALU_HH_FAST(t, ip, &);
2528 __instr_alu_and_i_exec(struct rte_swx_pipeline *p __rte_unused,
2530 const struct instruction *ip)
2532 TRACE("[Thread %2u] and (i)\n", p->thread_id);
2538 __instr_alu_or_exec(struct rte_swx_pipeline *p __rte_unused,
2540 const struct instruction *ip)
2542 TRACE("[Thread %2u] or\n", p->thread_id);
2548 __instr_alu_or_mh_exec(struct rte_swx_pipeline *p __rte_unused,
2550 const struct instruction *ip)
2552 TRACE("[Thread %2u] or (mh)\n", p->thread_id);
2558 __instr_alu_or_hm_exec(struct rte_swx_pipeline *p __rte_unused,
2560 const struct instruction *ip)
2562 TRACE("[Thread %2u] or (hm)\n", p->thread_id);
2564 ALU_HM_FAST(t, ip, |);
2568 __instr_alu_or_hh_exec(struct rte_swx_pipeline *p __rte_unused,
2570 const struct instruction *ip)
2572 TRACE("[Thread %2u] or (hh)\n", p->thread_id);
2574 ALU_HH_FAST(t, ip, |);
2578 __instr_alu_or_i_exec(struct rte_swx_pipeline *p __rte_unused,
2580 const struct instruction *ip)
2582 TRACE("[Thread %2u] or (i)\n", p->thread_id);
2588 __instr_alu_xor_exec(struct rte_swx_pipeline *p __rte_unused,
2590 const struct instruction *ip)
2592 TRACE("[Thread %2u] xor\n", p->thread_id);
2598 __instr_alu_xor_mh_exec(struct rte_swx_pipeline *p __rte_unused,
2600 const struct instruction *ip)
2602 TRACE("[Thread %2u] xor (mh)\n", p->thread_id);
2608 __instr_alu_xor_hm_exec(struct rte_swx_pipeline *p __rte_unused,
2610 const struct instruction *ip)
2612 TRACE("[Thread %2u] xor (hm)\n", p->thread_id);
2614 ALU_HM_FAST(t, ip, ^);
2618 __instr_alu_xor_hh_exec(struct rte_swx_pipeline *p __rte_unused,
2620 const struct instruction *ip)
2622 TRACE("[Thread %2u] xor (hh)\n", p->thread_id);
2624 ALU_HH_FAST(t, ip, ^);
2628 __instr_alu_xor_i_exec(struct rte_swx_pipeline *p __rte_unused,
2630 const struct instruction *ip)
2632 TRACE("[Thread %2u] xor (i)\n", p->thread_id);
2638 __instr_alu_ckadd_field_exec(struct rte_swx_pipeline *p __rte_unused,
2640 const struct instruction *ip)
2642 uint8_t *dst_struct, *src_struct;
2643 uint16_t *dst16_ptr, dst;
2644 uint64_t *src64_ptr, src64, src64_mask, src;
2647 TRACE("[Thread %2u] ckadd (field)\n", p->thread_id);
2650 dst_struct = t->structs[ip->alu.dst.struct_id];
2651 dst16_ptr = (uint16_t *)&dst_struct[ip->alu.dst.offset];
2654 src_struct = t->structs[ip->alu.src.struct_id];
2655 src64_ptr = (uint64_t *)&src_struct[ip->alu.src.offset];
2657 src64_mask = UINT64_MAX >> (64 - ip->alu.src.n_bits);
2658 src = src64 & src64_mask;
2663 /* The first input (r) is a 16-bit number. The second and the third
2664 * inputs are 32-bit numbers. In the worst case scenario, the sum of the
2665 * three numbers (output r) is a 34-bit number.
2667 r += (src >> 32) + (src & 0xFFFFFFFF);
2669 /* The first input is a 16-bit number. The second input is an 18-bit
2670 * number. In the worst case scenario, the sum of the two numbers is a
2673 r = (r & 0xFFFF) + (r >> 16);
2675 /* The first input is a 16-bit number (0 .. 0xFFFF). The second input is
2676 * a 3-bit number (0 .. 7). Their sum is a 17-bit number (0 .. 0x10006).
2678 r = (r & 0xFFFF) + (r >> 16);
2680 /* When the input r is (0 .. 0xFFFF), the output r is equal to the input
2681 * r, so the output is (0 .. 0xFFFF). When the input r is (0x10000 ..
2682 * 0x10006), the output r is (0 .. 7). So no carry bit can be generated,
2683 * therefore the output r is always a 16-bit number.
2685 r = (r & 0xFFFF) + (r >> 16);
2690 *dst16_ptr = (uint16_t)r;
2694 __instr_alu_cksub_field_exec(struct rte_swx_pipeline *p __rte_unused,
2696 const struct instruction *ip)
2698 uint8_t *dst_struct, *src_struct;
2699 uint16_t *dst16_ptr, dst;
2700 uint64_t *src64_ptr, src64, src64_mask, src;
2703 TRACE("[Thread %2u] cksub (field)\n", p->thread_id);
2706 dst_struct = t->structs[ip->alu.dst.struct_id];
2707 dst16_ptr = (uint16_t *)&dst_struct[ip->alu.dst.offset];
2710 src_struct = t->structs[ip->alu.src.struct_id];
2711 src64_ptr = (uint64_t *)&src_struct[ip->alu.src.offset];
2713 src64_mask = UINT64_MAX >> (64 - ip->alu.src.n_bits);
2714 src = src64 & src64_mask;
2719 /* Subtraction in 1's complement arithmetic (i.e. a '- b) is the same as
2720 * the following sequence of operations in 2's complement arithmetic:
2721 * a '- b = (a - b) % 0xFFFF.
2723 * In order to prevent an underflow for the below subtraction, in which
2724 * a 33-bit number (the subtrahend) is taken out of a 16-bit number (the
2725 * minuend), we first add a multiple of the 0xFFFF modulus to the
2726 * minuend. The number we add to the minuend needs to be a 34-bit number
2727 * or higher, so for readability reasons we picked the 36-bit multiple.
2728 * We are effectively turning the 16-bit minuend into a 36-bit number:
2729 * (a - b) % 0xFFFF = (a + 0xFFFF00000 - b) % 0xFFFF.
2731 r += 0xFFFF00000ULL; /* The output r is a 36-bit number. */
2733 /* A 33-bit number is subtracted from a 36-bit number (the input r). The
2734 * result (the output r) is a 36-bit number.
2736 r -= (src >> 32) + (src & 0xFFFFFFFF);
2738 /* The first input is a 16-bit number. The second input is a 20-bit
2739 * number. Their sum is a 21-bit number.
2741 r = (r & 0xFFFF) + (r >> 16);
2743 /* The first input is a 16-bit number (0 .. 0xFFFF). The second input is
2744 * a 5-bit number (0 .. 31). The sum is a 17-bit number (0 .. 0x1001E).
2746 r = (r & 0xFFFF) + (r >> 16);
2748 /* When the input r is (0 .. 0xFFFF), the output r is equal to the input
2749 * r, so the output is (0 .. 0xFFFF). When the input r is (0x10000 ..
2750 * 0x1001E), the output r is (0 .. 31). So no carry bit can be
2751 * generated, therefore the output r is always a 16-bit number.
2753 r = (r & 0xFFFF) + (r >> 16);
2758 *dst16_ptr = (uint16_t)r;
2762 __instr_alu_ckadd_struct20_exec(struct rte_swx_pipeline *p __rte_unused,
2764 const struct instruction *ip)
2766 uint8_t *dst_struct, *src_struct;
2767 uint16_t *dst16_ptr;
2768 uint32_t *src32_ptr;
2771 TRACE("[Thread %2u] ckadd (struct of 20 bytes)\n", p->thread_id);
2774 dst_struct = t->structs[ip->alu.dst.struct_id];
2775 dst16_ptr = (uint16_t *)&dst_struct[ip->alu.dst.offset];
2777 src_struct = t->structs[ip->alu.src.struct_id];
2778 src32_ptr = (uint32_t *)&src_struct[0];
2780 r0 = src32_ptr[0]; /* r0 is a 32-bit number. */
2781 r1 = src32_ptr[1]; /* r1 is a 32-bit number. */
2782 r0 += src32_ptr[2]; /* The output r0 is a 33-bit number. */
2783 r1 += src32_ptr[3]; /* The output r1 is a 33-bit number. */
2784 r0 += r1 + src32_ptr[4]; /* The output r0 is a 35-bit number. */
2786 /* The first input is a 16-bit number. The second input is a 19-bit
2787 * number. Their sum is a 20-bit number.
2789 r0 = (r0 & 0xFFFF) + (r0 >> 16);
2791 /* The first input is a 16-bit number (0 .. 0xFFFF). The second input is
2792 * a 4-bit number (0 .. 15). The sum is a 17-bit number (0 .. 0x1000E).
2794 r0 = (r0 & 0xFFFF) + (r0 >> 16);
2796 /* When the input r is (0 .. 0xFFFF), the output r is equal to the input
2797 * r, so the output is (0 .. 0xFFFF). When the input r is (0x10000 ..
2798 * 0x1000E), the output r is (0 .. 15). So no carry bit can be
2799 * generated, therefore the output r is always a 16-bit number.
2801 r0 = (r0 & 0xFFFF) + (r0 >> 16);
2804 r0 = r0 ? r0 : 0xFFFF;
2806 *dst16_ptr = (uint16_t)r0;
2810 __instr_alu_ckadd_struct_exec(struct rte_swx_pipeline *p __rte_unused,
2812 const struct instruction *ip)
2814 uint8_t *dst_struct, *src_struct;
2815 uint16_t *dst16_ptr;
2816 uint32_t *src32_ptr;
2820 TRACE("[Thread %2u] ckadd (struct)\n", p->thread_id);
2823 dst_struct = t->structs[ip->alu.dst.struct_id];
2824 dst16_ptr = (uint16_t *)&dst_struct[ip->alu.dst.offset];
2826 src_struct = t->structs[ip->alu.src.struct_id];
2827 src32_ptr = (uint32_t *)&src_struct[0];
2829 /* The max number of 32-bit words in a 256-byte header is 8 = 2^3.
2830 * Therefore, in the worst case scenario, a 35-bit number is added to a
2831 * 16-bit number (the input r), so the output r is 36-bit number.
2833 for (i = 0; i < ip->alu.src.n_bits / 32; i++, src32_ptr++)
2836 /* The first input is a 16-bit number. The second input is a 20-bit
2837 * number. Their sum is a 21-bit number.
2839 r = (r & 0xFFFF) + (r >> 16);
2841 /* The first input is a 16-bit number (0 .. 0xFFFF). The second input is
2842 * a 5-bit number (0 .. 31). The sum is a 17-bit number (0 .. 0x1000E).
2844 r = (r & 0xFFFF) + (r >> 16);
2846 /* When the input r is (0 .. 0xFFFF), the output r is equal to the input
2847 * r, so the output is (0 .. 0xFFFF). When the input r is (0x10000 ..
2848 * 0x1001E), the output r is (0 .. 31). So no carry bit can be
2849 * generated, therefore the output r is always a 16-bit number.
2851 r = (r & 0xFFFF) + (r >> 16);
2856 *dst16_ptr = (uint16_t)r;
2862 static inline uint64_t *
2863 instr_regarray_regarray(struct rte_swx_pipeline *p, const struct instruction *ip)
2865 struct regarray_runtime *r = &p->regarray_runtime[ip->regarray.regarray_id];
2869 static inline uint64_t
2870 instr_regarray_idx_hbo(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
2872 struct regarray_runtime *r = &p->regarray_runtime[ip->regarray.regarray_id];
2874 uint8_t *idx_struct = t->structs[ip->regarray.idx.struct_id];
2875 uint64_t *idx64_ptr = (uint64_t *)&idx_struct[ip->regarray.idx.offset];
2876 uint64_t idx64 = *idx64_ptr;
2877 uint64_t idx64_mask = UINT64_MAX >> (64 - ip->regarray.idx.n_bits);
2878 uint64_t idx = idx64 & idx64_mask & r->size_mask;
2883 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2885 static inline uint64_t
2886 instr_regarray_idx_nbo(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
2888 struct regarray_runtime *r = &p->regarray_runtime[ip->regarray.regarray_id];
2890 uint8_t *idx_struct = t->structs[ip->regarray.idx.struct_id];
2891 uint64_t *idx64_ptr = (uint64_t *)&idx_struct[ip->regarray.idx.offset];
2892 uint64_t idx64 = *idx64_ptr;
2893 uint64_t idx = (ntoh64(idx64) >> (64 - ip->regarray.idx.n_bits)) & r->size_mask;
2900 #define instr_regarray_idx_nbo instr_regarray_idx_hbo
2904 static inline uint64_t
2905 instr_regarray_idx_imm(struct rte_swx_pipeline *p, const struct instruction *ip)
2907 struct regarray_runtime *r = &p->regarray_runtime[ip->regarray.regarray_id];
2909 uint64_t idx = ip->regarray.idx_val & r->size_mask;
2914 static inline uint64_t
2915 instr_regarray_src_hbo(struct thread *t, const struct instruction *ip)
2917 uint8_t *src_struct = t->structs[ip->regarray.dstsrc.struct_id];
2918 uint64_t *src64_ptr = (uint64_t *)&src_struct[ip->regarray.dstsrc.offset];
2919 uint64_t src64 = *src64_ptr;
2920 uint64_t src64_mask = UINT64_MAX >> (64 - ip->regarray.dstsrc.n_bits);
2921 uint64_t src = src64 & src64_mask;
2926 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2928 static inline uint64_t
2929 instr_regarray_src_nbo(struct thread *t, const struct instruction *ip)
2931 uint8_t *src_struct = t->structs[ip->regarray.dstsrc.struct_id];
2932 uint64_t *src64_ptr = (uint64_t *)&src_struct[ip->regarray.dstsrc.offset];
2933 uint64_t src64 = *src64_ptr;
2934 uint64_t src = ntoh64(src64) >> (64 - ip->regarray.dstsrc.n_bits);
2941 #define instr_regarray_src_nbo instr_regarray_src_hbo
2946 instr_regarray_dst_hbo_src_hbo_set(struct thread *t, const struct instruction *ip, uint64_t src)
2948 uint8_t *dst_struct = t->structs[ip->regarray.dstsrc.struct_id];
2949 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[ip->regarray.dstsrc.offset];
2950 uint64_t dst64 = *dst64_ptr;
2951 uint64_t dst64_mask = UINT64_MAX >> (64 - ip->regarray.dstsrc.n_bits);
2953 *dst64_ptr = (dst64 & ~dst64_mask) | (src & dst64_mask);
2957 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
2960 instr_regarray_dst_nbo_src_hbo_set(struct thread *t, const struct instruction *ip, uint64_t src)
2962 uint8_t *dst_struct = t->structs[ip->regarray.dstsrc.struct_id];
2963 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[ip->regarray.dstsrc.offset];
2964 uint64_t dst64 = *dst64_ptr;
2965 uint64_t dst64_mask = UINT64_MAX >> (64 - ip->regarray.dstsrc.n_bits);
2967 src = hton64(src) >> (64 - ip->regarray.dstsrc.n_bits);
2968 *dst64_ptr = (dst64 & ~dst64_mask) | (src & dst64_mask);
2973 #define instr_regarray_dst_nbo_src_hbo_set instr_regarray_dst_hbo_src_hbo_set
2978 __instr_regprefetch_rh_exec(struct rte_swx_pipeline *p,
2980 const struct instruction *ip)
2982 uint64_t *regarray, idx;
2984 TRACE("[Thread %2u] regprefetch (r[h])\n", p->thread_id);
2986 regarray = instr_regarray_regarray(p, ip);
2987 idx = instr_regarray_idx_nbo(p, t, ip);
2988 rte_prefetch0(®array[idx]);
2992 __instr_regprefetch_rm_exec(struct rte_swx_pipeline *p,
2994 const struct instruction *ip)
2996 uint64_t *regarray, idx;
2998 TRACE("[Thread %2u] regprefetch (r[m])\n", p->thread_id);
3000 regarray = instr_regarray_regarray(p, ip);
3001 idx = instr_regarray_idx_hbo(p, t, ip);
3002 rte_prefetch0(®array[idx]);
3006 __instr_regprefetch_ri_exec(struct rte_swx_pipeline *p,
3007 struct thread *t __rte_unused,
3008 const struct instruction *ip)
3010 uint64_t *regarray, idx;
3012 TRACE("[Thread %2u] regprefetch (r[i])\n", p->thread_id);
3014 regarray = instr_regarray_regarray(p, ip);
3015 idx = instr_regarray_idx_imm(p, ip);
3016 rte_prefetch0(®array[idx]);
3020 __instr_regrd_hrh_exec(struct rte_swx_pipeline *p,
3022 const struct instruction *ip)
3024 uint64_t *regarray, idx;
3026 TRACE("[Thread %2u] regrd (h = r[h])\n", p->thread_id);
3028 regarray = instr_regarray_regarray(p, ip);
3029 idx = instr_regarray_idx_nbo(p, t, ip);
3030 instr_regarray_dst_nbo_src_hbo_set(t, ip, regarray[idx]);
3034 __instr_regrd_hrm_exec(struct rte_swx_pipeline *p,
3036 const struct instruction *ip)
3038 uint64_t *regarray, idx;
3040 TRACE("[Thread %2u] regrd (h = r[m])\n", p->thread_id);
3043 regarray = instr_regarray_regarray(p, ip);
3044 idx = instr_regarray_idx_hbo(p, t, ip);
3045 instr_regarray_dst_nbo_src_hbo_set(t, ip, regarray[idx]);
3049 __instr_regrd_mrh_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3051 uint64_t *regarray, idx;
3053 TRACE("[Thread %2u] regrd (m = r[h])\n", p->thread_id);
3055 regarray = instr_regarray_regarray(p, ip);
3056 idx = instr_regarray_idx_nbo(p, t, ip);
3057 instr_regarray_dst_hbo_src_hbo_set(t, ip, regarray[idx]);
3061 __instr_regrd_mrm_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3063 uint64_t *regarray, idx;
3065 TRACE("[Thread %2u] regrd (m = r[m])\n", p->thread_id);
3067 regarray = instr_regarray_regarray(p, ip);
3068 idx = instr_regarray_idx_hbo(p, t, ip);
3069 instr_regarray_dst_hbo_src_hbo_set(t, ip, regarray[idx]);
3073 __instr_regrd_hri_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3075 uint64_t *regarray, idx;
3077 TRACE("[Thread %2u] regrd (h = r[i])\n", p->thread_id);
3079 regarray = instr_regarray_regarray(p, ip);
3080 idx = instr_regarray_idx_imm(p, ip);
3081 instr_regarray_dst_nbo_src_hbo_set(t, ip, regarray[idx]);
3085 __instr_regrd_mri_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3087 uint64_t *regarray, idx;
3089 TRACE("[Thread %2u] regrd (m = r[i])\n", p->thread_id);
3091 regarray = instr_regarray_regarray(p, ip);
3092 idx = instr_regarray_idx_imm(p, ip);
3093 instr_regarray_dst_hbo_src_hbo_set(t, ip, regarray[idx]);
3097 __instr_regwr_rhh_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3099 uint64_t *regarray, idx, src;
3101 TRACE("[Thread %2u] regwr (r[h] = h)\n", p->thread_id);
3103 regarray = instr_regarray_regarray(p, ip);
3104 idx = instr_regarray_idx_nbo(p, t, ip);
3105 src = instr_regarray_src_nbo(t, ip);
3106 regarray[idx] = src;
3110 __instr_regwr_rhm_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3112 uint64_t *regarray, idx, src;
3114 TRACE("[Thread %2u] regwr (r[h] = m)\n", p->thread_id);
3116 regarray = instr_regarray_regarray(p, ip);
3117 idx = instr_regarray_idx_nbo(p, t, ip);
3118 src = instr_regarray_src_hbo(t, ip);
3119 regarray[idx] = src;
3123 __instr_regwr_rmh_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3125 uint64_t *regarray, idx, src;
3127 TRACE("[Thread %2u] regwr (r[m] = h)\n", p->thread_id);
3129 regarray = instr_regarray_regarray(p, ip);
3130 idx = instr_regarray_idx_hbo(p, t, ip);
3131 src = instr_regarray_src_nbo(t, ip);
3132 regarray[idx] = src;
3136 __instr_regwr_rmm_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3138 uint64_t *regarray, idx, src;
3140 TRACE("[Thread %2u] regwr (r[m] = m)\n", p->thread_id);
3142 regarray = instr_regarray_regarray(p, ip);
3143 idx = instr_regarray_idx_hbo(p, t, ip);
3144 src = instr_regarray_src_hbo(t, ip);
3145 regarray[idx] = src;
3149 __instr_regwr_rhi_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3151 uint64_t *regarray, idx, src;
3153 TRACE("[Thread %2u] regwr (r[h] = i)\n", p->thread_id);
3155 regarray = instr_regarray_regarray(p, ip);
3156 idx = instr_regarray_idx_nbo(p, t, ip);
3157 src = ip->regarray.dstsrc_val;
3158 regarray[idx] = src;
3162 __instr_regwr_rmi_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3164 uint64_t *regarray, idx, src;
3166 TRACE("[Thread %2u] regwr (r[m] = i)\n", p->thread_id);
3168 regarray = instr_regarray_regarray(p, ip);
3169 idx = instr_regarray_idx_hbo(p, t, ip);
3170 src = ip->regarray.dstsrc_val;
3171 regarray[idx] = src;
3175 __instr_regwr_rih_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3177 uint64_t *regarray, idx, src;
3179 TRACE("[Thread %2u] regwr (r[i] = h)\n", p->thread_id);
3181 regarray = instr_regarray_regarray(p, ip);
3182 idx = instr_regarray_idx_imm(p, ip);
3183 src = instr_regarray_src_nbo(t, ip);
3184 regarray[idx] = src;
3188 __instr_regwr_rim_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3190 uint64_t *regarray, idx, src;
3192 TRACE("[Thread %2u] regwr (r[i] = m)\n", p->thread_id);
3194 regarray = instr_regarray_regarray(p, ip);
3195 idx = instr_regarray_idx_imm(p, ip);
3196 src = instr_regarray_src_hbo(t, ip);
3197 regarray[idx] = src;
3201 __instr_regwr_rii_exec(struct rte_swx_pipeline *p,
3202 struct thread *t __rte_unused,
3203 const struct instruction *ip)
3205 uint64_t *regarray, idx, src;
3207 TRACE("[Thread %2u] regwr (r[i] = i)\n", p->thread_id);
3209 regarray = instr_regarray_regarray(p, ip);
3210 idx = instr_regarray_idx_imm(p, ip);
3211 src = ip->regarray.dstsrc_val;
3212 regarray[idx] = src;
3216 __instr_regadd_rhh_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3218 uint64_t *regarray, idx, src;
3220 TRACE("[Thread %2u] regadd (r[h] += h)\n", p->thread_id);
3222 regarray = instr_regarray_regarray(p, ip);
3223 idx = instr_regarray_idx_nbo(p, t, ip);
3224 src = instr_regarray_src_nbo(t, ip);
3225 regarray[idx] += src;
3229 __instr_regadd_rhm_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3231 uint64_t *regarray, idx, src;
3233 TRACE("[Thread %2u] regadd (r[h] += m)\n", p->thread_id);
3235 regarray = instr_regarray_regarray(p, ip);
3236 idx = instr_regarray_idx_nbo(p, t, ip);
3237 src = instr_regarray_src_hbo(t, ip);
3238 regarray[idx] += src;
3242 __instr_regadd_rmh_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3244 uint64_t *regarray, idx, src;
3246 TRACE("[Thread %2u] regadd (r[m] += h)\n", p->thread_id);
3248 regarray = instr_regarray_regarray(p, ip);
3249 idx = instr_regarray_idx_hbo(p, t, ip);
3250 src = instr_regarray_src_nbo(t, ip);
3251 regarray[idx] += src;
3255 __instr_regadd_rmm_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3257 uint64_t *regarray, idx, src;
3259 TRACE("[Thread %2u] regadd (r[m] += m)\n", p->thread_id);
3261 regarray = instr_regarray_regarray(p, ip);
3262 idx = instr_regarray_idx_hbo(p, t, ip);
3263 src = instr_regarray_src_hbo(t, ip);
3264 regarray[idx] += src;
3268 __instr_regadd_rhi_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3270 uint64_t *regarray, idx, src;
3272 TRACE("[Thread %2u] regadd (r[h] += i)\n", p->thread_id);
3274 regarray = instr_regarray_regarray(p, ip);
3275 idx = instr_regarray_idx_nbo(p, t, ip);
3276 src = ip->regarray.dstsrc_val;
3277 regarray[idx] += src;
3281 __instr_regadd_rmi_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3283 uint64_t *regarray, idx, src;
3285 TRACE("[Thread %2u] regadd (r[m] += i)\n", p->thread_id);
3287 regarray = instr_regarray_regarray(p, ip);
3288 idx = instr_regarray_idx_hbo(p, t, ip);
3289 src = ip->regarray.dstsrc_val;
3290 regarray[idx] += src;
3294 __instr_regadd_rih_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3296 uint64_t *regarray, idx, src;
3298 TRACE("[Thread %2u] regadd (r[i] += h)\n", p->thread_id);
3300 regarray = instr_regarray_regarray(p, ip);
3301 idx = instr_regarray_idx_imm(p, ip);
3302 src = instr_regarray_src_nbo(t, ip);
3303 regarray[idx] += src;
3307 __instr_regadd_rim_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3309 uint64_t *regarray, idx, src;
3311 TRACE("[Thread %2u] regadd (r[i] += m)\n", p->thread_id);
3313 regarray = instr_regarray_regarray(p, ip);
3314 idx = instr_regarray_idx_imm(p, ip);
3315 src = instr_regarray_src_hbo(t, ip);
3316 regarray[idx] += src;
3320 __instr_regadd_rii_exec(struct rte_swx_pipeline *p,
3321 struct thread *t __rte_unused,
3322 const struct instruction *ip)
3324 uint64_t *regarray, idx, src;
3326 TRACE("[Thread %2u] regadd (r[i] += i)\n", p->thread_id);
3328 regarray = instr_regarray_regarray(p, ip);
3329 idx = instr_regarray_idx_imm(p, ip);
3330 src = ip->regarray.dstsrc_val;
3331 regarray[idx] += src;
3337 static inline struct meter *
3338 instr_meter_idx_hbo(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3340 struct metarray_runtime *r = &p->metarray_runtime[ip->meter.metarray_id];
3342 uint8_t *idx_struct = t->structs[ip->meter.idx.struct_id];
3343 uint64_t *idx64_ptr = (uint64_t *)&idx_struct[ip->meter.idx.offset];
3344 uint64_t idx64 = *idx64_ptr;
3345 uint64_t idx64_mask = UINT64_MAX >> (64 - (ip)->meter.idx.n_bits);
3346 uint64_t idx = idx64 & idx64_mask & r->size_mask;
3348 return &r->metarray[idx];
3351 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3353 static inline struct meter *
3354 instr_meter_idx_nbo(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3356 struct metarray_runtime *r = &p->metarray_runtime[ip->meter.metarray_id];
3358 uint8_t *idx_struct = t->structs[ip->meter.idx.struct_id];
3359 uint64_t *idx64_ptr = (uint64_t *)&idx_struct[ip->meter.idx.offset];
3360 uint64_t idx64 = *idx64_ptr;
3361 uint64_t idx = (ntoh64(idx64) >> (64 - ip->meter.idx.n_bits)) & r->size_mask;
3363 return &r->metarray[idx];
3368 #define instr_meter_idx_nbo instr_meter_idx_hbo
3372 static inline struct meter *
3373 instr_meter_idx_imm(struct rte_swx_pipeline *p, const struct instruction *ip)
3375 struct metarray_runtime *r = &p->metarray_runtime[ip->meter.metarray_id];
3377 uint64_t idx = ip->meter.idx_val & r->size_mask;
3379 return &r->metarray[idx];
3382 static inline uint32_t
3383 instr_meter_length_hbo(struct thread *t, const struct instruction *ip)
3385 uint8_t *src_struct = t->structs[ip->meter.length.struct_id];
3386 uint64_t *src64_ptr = (uint64_t *)&src_struct[ip->meter.length.offset];
3387 uint64_t src64 = *src64_ptr;
3388 uint64_t src64_mask = UINT64_MAX >> (64 - (ip)->meter.length.n_bits);
3389 uint64_t src = src64 & src64_mask;
3391 return (uint32_t)src;
3394 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
3396 static inline uint32_t
3397 instr_meter_length_nbo(struct thread *t, const struct instruction *ip)
3399 uint8_t *src_struct = t->structs[ip->meter.length.struct_id];
3400 uint64_t *src64_ptr = (uint64_t *)&src_struct[ip->meter.length.offset];
3401 uint64_t src64 = *src64_ptr;
3402 uint64_t src = ntoh64(src64) >> (64 - ip->meter.length.n_bits);
3404 return (uint32_t)src;
3409 #define instr_meter_length_nbo instr_meter_length_hbo
3413 static inline enum rte_color
3414 instr_meter_color_in_hbo(struct thread *t, const struct instruction *ip)
3416 uint8_t *src_struct = t->structs[ip->meter.color_in.struct_id];
3417 uint64_t *src64_ptr = (uint64_t *)&src_struct[ip->meter.color_in.offset];
3418 uint64_t src64 = *src64_ptr;
3419 uint64_t src64_mask = UINT64_MAX >> (64 - ip->meter.color_in.n_bits);
3420 uint64_t src = src64 & src64_mask;
3422 return (enum rte_color)src;
3426 instr_meter_color_out_hbo_set(struct thread *t,
3427 const struct instruction *ip,
3428 enum rte_color color_out)
3430 uint8_t *dst_struct = t->structs[ip->meter.color_out.struct_id];
3431 uint64_t *dst64_ptr = (uint64_t *)&dst_struct[ip->meter.color_out.offset];
3432 uint64_t dst64 = *dst64_ptr;
3433 uint64_t dst64_mask = UINT64_MAX >> (64 - ip->meter.color_out.n_bits);
3435 uint64_t src = (uint64_t)color_out;
3437 *dst64_ptr = (dst64 & ~dst64_mask) | (src & dst64_mask);
3441 __instr_metprefetch_h_exec(struct rte_swx_pipeline *p,
3443 const struct instruction *ip)
3447 TRACE("[Thread %2u] metprefetch (h)\n", p->thread_id);
3449 m = instr_meter_idx_nbo(p, t, ip);
3454 __instr_metprefetch_m_exec(struct rte_swx_pipeline *p,
3456 const struct instruction *ip)
3460 TRACE("[Thread %2u] metprefetch (m)\n", p->thread_id);
3462 m = instr_meter_idx_hbo(p, t, ip);
3467 __instr_metprefetch_i_exec(struct rte_swx_pipeline *p,
3468 struct thread *t __rte_unused,
3469 const struct instruction *ip)
3473 TRACE("[Thread %2u] metprefetch (i)\n", p->thread_id);
3475 m = instr_meter_idx_imm(p, ip);
3480 __instr_meter_hhm_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3483 uint64_t time, n_pkts, n_bytes;
3485 enum rte_color color_in, color_out;
3487 TRACE("[Thread %2u] meter (hhm)\n", p->thread_id);
3489 m = instr_meter_idx_nbo(p, t, ip);
3490 rte_prefetch0(m->n_pkts);
3491 time = rte_get_tsc_cycles();
3492 length = instr_meter_length_nbo(t, ip);
3493 color_in = instr_meter_color_in_hbo(t, ip);
3495 color_out = rte_meter_trtcm_color_aware_check(&m->m,
3496 &m->profile->profile,
3501 color_out &= m->color_mask;
3503 n_pkts = m->n_pkts[color_out];
3504 n_bytes = m->n_bytes[color_out];
3506 instr_meter_color_out_hbo_set(t, ip, color_out);
3508 m->n_pkts[color_out] = n_pkts + 1;
3509 m->n_bytes[color_out] = n_bytes + length;
3513 __instr_meter_hhi_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3516 uint64_t time, n_pkts, n_bytes;
3518 enum rte_color color_in, color_out;
3520 TRACE("[Thread %2u] meter (hhi)\n", p->thread_id);
3522 m = instr_meter_idx_nbo(p, t, ip);
3523 rte_prefetch0(m->n_pkts);
3524 time = rte_get_tsc_cycles();
3525 length = instr_meter_length_nbo(t, ip);
3526 color_in = (enum rte_color)ip->meter.color_in_val;
3528 color_out = rte_meter_trtcm_color_aware_check(&m->m,
3529 &m->profile->profile,
3534 color_out &= m->color_mask;
3536 n_pkts = m->n_pkts[color_out];
3537 n_bytes = m->n_bytes[color_out];
3539 instr_meter_color_out_hbo_set(t, ip, color_out);
3541 m->n_pkts[color_out] = n_pkts + 1;
3542 m->n_bytes[color_out] = n_bytes + length;
3546 __instr_meter_hmm_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3549 uint64_t time, n_pkts, n_bytes;
3551 enum rte_color color_in, color_out;
3553 TRACE("[Thread %2u] meter (hmm)\n", p->thread_id);
3555 m = instr_meter_idx_nbo(p, t, ip);
3556 rte_prefetch0(m->n_pkts);
3557 time = rte_get_tsc_cycles();
3558 length = instr_meter_length_hbo(t, ip);
3559 color_in = instr_meter_color_in_hbo(t, ip);
3561 color_out = rte_meter_trtcm_color_aware_check(&m->m,
3562 &m->profile->profile,
3567 color_out &= m->color_mask;
3569 n_pkts = m->n_pkts[color_out];
3570 n_bytes = m->n_bytes[color_out];
3572 instr_meter_color_out_hbo_set(t, ip, color_out);
3574 m->n_pkts[color_out] = n_pkts + 1;
3575 m->n_bytes[color_out] = n_bytes + length;
3579 __instr_meter_hmi_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3582 uint64_t time, n_pkts, n_bytes;
3584 enum rte_color color_in, color_out;
3586 TRACE("[Thread %2u] meter (hmi)\n", p->thread_id);
3588 m = instr_meter_idx_nbo(p, t, ip);
3589 rte_prefetch0(m->n_pkts);
3590 time = rte_get_tsc_cycles();
3591 length = instr_meter_length_hbo(t, ip);
3592 color_in = (enum rte_color)ip->meter.color_in_val;
3594 color_out = rte_meter_trtcm_color_aware_check(&m->m,
3595 &m->profile->profile,
3600 color_out &= m->color_mask;
3602 n_pkts = m->n_pkts[color_out];
3603 n_bytes = m->n_bytes[color_out];
3605 instr_meter_color_out_hbo_set(t, ip, color_out);
3607 m->n_pkts[color_out] = n_pkts + 1;
3608 m->n_bytes[color_out] = n_bytes + length;
3612 __instr_meter_mhm_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3615 uint64_t time, n_pkts, n_bytes;
3617 enum rte_color color_in, color_out;
3619 TRACE("[Thread %2u] meter (mhm)\n", p->thread_id);
3621 m = instr_meter_idx_hbo(p, t, ip);
3622 rte_prefetch0(m->n_pkts);
3623 time = rte_get_tsc_cycles();
3624 length = instr_meter_length_nbo(t, ip);
3625 color_in = instr_meter_color_in_hbo(t, ip);
3627 color_out = rte_meter_trtcm_color_aware_check(&m->m,
3628 &m->profile->profile,
3633 color_out &= m->color_mask;
3635 n_pkts = m->n_pkts[color_out];
3636 n_bytes = m->n_bytes[color_out];
3638 instr_meter_color_out_hbo_set(t, ip, color_out);
3640 m->n_pkts[color_out] = n_pkts + 1;
3641 m->n_bytes[color_out] = n_bytes + length;
3645 __instr_meter_mhi_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3648 uint64_t time, n_pkts, n_bytes;
3650 enum rte_color color_in, color_out;
3652 TRACE("[Thread %2u] meter (mhi)\n", p->thread_id);
3654 m = instr_meter_idx_hbo(p, t, ip);
3655 rte_prefetch0(m->n_pkts);
3656 time = rte_get_tsc_cycles();
3657 length = instr_meter_length_nbo(t, ip);
3658 color_in = (enum rte_color)ip->meter.color_in_val;
3660 color_out = rte_meter_trtcm_color_aware_check(&m->m,
3661 &m->profile->profile,
3666 color_out &= m->color_mask;
3668 n_pkts = m->n_pkts[color_out];
3669 n_bytes = m->n_bytes[color_out];
3671 instr_meter_color_out_hbo_set(t, ip, color_out);
3673 m->n_pkts[color_out] = n_pkts + 1;
3674 m->n_bytes[color_out] = n_bytes + length;
3678 __instr_meter_mmm_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3681 uint64_t time, n_pkts, n_bytes;
3683 enum rte_color color_in, color_out;
3685 TRACE("[Thread %2u] meter (mmm)\n", p->thread_id);
3687 m = instr_meter_idx_hbo(p, t, ip);
3688 rte_prefetch0(m->n_pkts);
3689 time = rte_get_tsc_cycles();
3690 length = instr_meter_length_hbo(t, ip);
3691 color_in = instr_meter_color_in_hbo(t, ip);
3693 color_out = rte_meter_trtcm_color_aware_check(&m->m,
3694 &m->profile->profile,
3699 color_out &= m->color_mask;
3701 n_pkts = m->n_pkts[color_out];
3702 n_bytes = m->n_bytes[color_out];
3704 instr_meter_color_out_hbo_set(t, ip, color_out);
3706 m->n_pkts[color_out] = n_pkts + 1;
3707 m->n_bytes[color_out] = n_bytes + length;
3711 __instr_meter_mmi_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3714 uint64_t time, n_pkts, n_bytes;
3716 enum rte_color color_in, color_out;
3718 TRACE("[Thread %2u] meter (mmi)\n", p->thread_id);
3720 m = instr_meter_idx_hbo(p, t, ip);
3721 rte_prefetch0(m->n_pkts);
3722 time = rte_get_tsc_cycles();
3723 length = instr_meter_length_hbo(t, ip);
3724 color_in = (enum rte_color)ip->meter.color_in_val;
3726 color_out = rte_meter_trtcm_color_aware_check(&m->m,
3727 &m->profile->profile,
3732 color_out &= m->color_mask;
3734 n_pkts = m->n_pkts[color_out];
3735 n_bytes = m->n_bytes[color_out];
3737 instr_meter_color_out_hbo_set(t, ip, color_out);
3739 m->n_pkts[color_out] = n_pkts + 1;
3740 m->n_bytes[color_out] = n_bytes + length;
3744 __instr_meter_ihm_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3747 uint64_t time, n_pkts, n_bytes;
3749 enum rte_color color_in, color_out;
3751 TRACE("[Thread %2u] meter (ihm)\n", p->thread_id);
3753 m = instr_meter_idx_imm(p, ip);
3754 rte_prefetch0(m->n_pkts);
3755 time = rte_get_tsc_cycles();
3756 length = instr_meter_length_nbo(t, ip);
3757 color_in = instr_meter_color_in_hbo(t, ip);
3759 color_out = rte_meter_trtcm_color_aware_check(&m->m,
3760 &m->profile->profile,
3765 color_out &= m->color_mask;
3767 n_pkts = m->n_pkts[color_out];
3768 n_bytes = m->n_bytes[color_out];
3770 instr_meter_color_out_hbo_set(t, ip, color_out);
3772 m->n_pkts[color_out] = n_pkts + 1;
3773 m->n_bytes[color_out] = n_bytes + length;
3777 __instr_meter_ihi_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3780 uint64_t time, n_pkts, n_bytes;
3782 enum rte_color color_in, color_out;
3784 TRACE("[Thread %2u] meter (ihi)\n", p->thread_id);
3786 m = instr_meter_idx_imm(p, ip);
3787 rte_prefetch0(m->n_pkts);
3788 time = rte_get_tsc_cycles();
3789 length = instr_meter_length_nbo(t, ip);
3790 color_in = (enum rte_color)ip->meter.color_in_val;
3792 color_out = rte_meter_trtcm_color_aware_check(&m->m,
3793 &m->profile->profile,
3798 color_out &= m->color_mask;
3800 n_pkts = m->n_pkts[color_out];
3801 n_bytes = m->n_bytes[color_out];
3803 instr_meter_color_out_hbo_set(t, ip, color_out);
3805 m->n_pkts[color_out] = n_pkts + 1;
3806 m->n_bytes[color_out] = n_bytes + length;
3810 __instr_meter_imm_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3813 uint64_t time, n_pkts, n_bytes;
3815 enum rte_color color_in, color_out;
3817 TRACE("[Thread %2u] meter (imm)\n", p->thread_id);
3819 m = instr_meter_idx_imm(p, ip);
3820 rte_prefetch0(m->n_pkts);
3821 time = rte_get_tsc_cycles();
3822 length = instr_meter_length_hbo(t, ip);
3823 color_in = instr_meter_color_in_hbo(t, ip);
3825 color_out = rte_meter_trtcm_color_aware_check(&m->m,
3826 &m->profile->profile,
3831 color_out &= m->color_mask;
3833 n_pkts = m->n_pkts[color_out];
3834 n_bytes = m->n_bytes[color_out];
3836 instr_meter_color_out_hbo_set(t, ip, color_out);
3838 m->n_pkts[color_out] = n_pkts + 1;
3839 m->n_bytes[color_out] = n_bytes + length;
3843 __instr_meter_imi_exec(struct rte_swx_pipeline *p, struct thread *t, const struct instruction *ip)
3846 uint64_t time, n_pkts, n_bytes;
3848 enum rte_color color_in, color_out;
3850 TRACE("[Thread %2u] meter (imi)\n", p->thread_id);
3852 m = instr_meter_idx_imm(p, ip);
3853 rte_prefetch0(m->n_pkts);
3854 time = rte_get_tsc_cycles();
3855 length = instr_meter_length_hbo(t, ip);
3856 color_in = (enum rte_color)ip->meter.color_in_val;
3858 color_out = rte_meter_trtcm_color_aware_check(&m->m,
3859 &m->profile->profile,
3864 color_out &= m->color_mask;
3866 n_pkts = m->n_pkts[color_out];
3867 n_bytes = m->n_bytes[color_out];
3869 instr_meter_color_out_hbo_set(t, ip, color_out);
3871 m->n_pkts[color_out] = n_pkts + 1;
3872 m->n_bytes[color_out] = n_bytes + length;