1 Multi-Architecture Arbitrary Function Cookbook
2 ==============================================
4 Optimizing arbitrary functions for multiple architectures is simple
5 enough, and very similar to process used to produce multi-architecture
6 graph node dispatch functions.
8 As with multi-architecture graph nodes, we compile source files
9 multiple times, generating multiple implementations of the original
10 function, and a public selector function.
15 Decorate function definitions with CLIB_MARCH_FN macros. For example:
17 Change the original function prototype...
21 u32 vlib_frame_alloc_to_node (vlib_main_t * vm, u32 to_node_index,
24 ...by recasting the function name and return type as the first two
25 arguments to the CLIB_MARCH_FN macro:
29 CLIB_MARCH_FN (vlib_frame_alloc_to_node, u32, vlib_main_t * vm,
30 u32 to_node_index, u32 frame_flags)
32 In the actual vpp image, several versions of vlib_frame_alloc_to_node
33 will appear: vlib_frame_alloc_to_node_avx2,
34 vlib_frame_alloc_to_node_avx512, and so forth.
37 For each multi-architecture function, use the CLIB_MARCH_FN_SELECT
38 macro to help generate the one-and-only multi-architecture selector
43 #ifndef CLIB_MARCH_VARIANT
45 vlib_frame_alloc_to_node (vlib_main_t * vm, u32 to_node_index,
48 return CLIB_MARCH_FN_SELECT (vlib_frame_alloc_to_node)
49 (vm, to_node_index, frame_flags);
51 #endif /* CLIB_MARCH_VARIANT */
53 Once bound, the multi-architecture selector function is about as
54 expensive as an indirect function call; which is to say: not very
60 If the component in question already lists "MULTIARCH_SOURCES", simply
61 add the indicated .c file to the list. Otherwise, add as shown
62 below. Note that the added file "new_multiarch_node.c" should appear in
63 *both* SOURCES and MULTIARCH_SOURCES:
67 add_vpp_plugin(myplugin
80 A file which liberally mixes functions worth compiling for multiple
81 architectures and functions which are not will end up full of
82 #ifndef CLIB_MARCH_VARIANT conditionals. This won't do a thing to make
83 the code look any better.
85 Depending on requirements, it may make sense to move functions to
86 (new) files to reduce complexity and/or improve legibility of the