178cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar# Library Utility Functions 278cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar# 378cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar# This should be included following 'lib_info.mk'. 478cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar 548464e0ee1c2de5bcbf0d609348f55d0c301085dDaniel Dunbar# Function: GetCNAVar variable-name platform-key config arch 648464e0ee1c2de5bcbf0d609348f55d0c301085dDaniel Dunbar# 748464e0ee1c2de5bcbf0d609348f55d0c301085dDaniel Dunbar# Get a per-config-and-arch variable value. 848464e0ee1c2de5bcbf0d609348f55d0c301085dDaniel DunbarGetCNAVar = $(strip \ 948464e0ee1c2de5bcbf0d609348f55d0c301085dDaniel Dunbar $(or $($(2).$(1).$(3).$(4)), \ 1048464e0ee1c2de5bcbf0d609348f55d0c301085dDaniel Dunbar $($(2).$(1).$(3)), \ 1148464e0ee1c2de5bcbf0d609348f55d0c301085dDaniel Dunbar $($(2).$(1).$(4)), \ 1248464e0ee1c2de5bcbf0d609348f55d0c301085dDaniel Dunbar $($(2).$(1)))) 1348464e0ee1c2de5bcbf0d609348f55d0c301085dDaniel Dunbar 1478cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar# Function: SelectFunctionDir config arch function-name optimized 1578cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar# 1678cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar# Choose the appropriate implementation directory to use for 'function-name' in 1778cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar# the configuration 'config' and on given arch. 1878cfbc57c62949e16fa7b4a69775aa6450343a00Daniel DunbarSelectFunctionDir = $(strip \ 1978cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(call Set,Tmp.SelectFunctionDir,$(call SelectFunctionDirs,$(1),$(2),$(3),$(4)))\ 2078cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(if $(call streq,1,$(words $(Tmp.SelectFunctionDir))),\ 2178cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(Tmp.SelectFunctionDir),\ 2278cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(error SelectFunctionDir: invalid function name "$(3)" ($(strip\ 2378cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(if $(call streq,0,$(words $(Tmp.SelectFunctionDir))),\ 2478cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar no such function,\ 2578cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar function implemented in multiple directories!!!)))))) 2678cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar 2778cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar# Helper functions that select the entire list of subdirs where a function is 2878cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar# defined with a certain specificity. 2978cfbc57c62949e16fa7b4a69775aa6450343a00Daniel DunbarSelectFunctionDirs_Opt_ConfigAndArch = $(strip \ 3078cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(foreach key,$(AvailableIn.$(3)),\ 316db90e61b58ae72b07faf3272fa9f15d4ad9b3bcDaniel Dunbar $(if $(and $(call streq,Optimized,$($(key).Implementation)),\ 3278cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(call contains,$($(key).OnlyConfigs),$(1)),\ 3378cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(call contains,$($(key).OnlyArchs),$(2))),$(key),))) 3478cfbc57c62949e16fa7b4a69775aa6450343a00Daniel DunbarSelectFunctionDirs_Opt_Config = $(strip \ 3578cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(foreach key,$(AvailableIn.$(3)),\ 366db90e61b58ae72b07faf3272fa9f15d4ad9b3bcDaniel Dunbar $(if $(and $(call streq,Optimized,$($(key).Implementation)),\ 3778cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(call contains,$($(key).OnlyConfigs),$(1))),$(key),))) 3878cfbc57c62949e16fa7b4a69775aa6450343a00Daniel DunbarSelectFunctionDirs_Opt_Arch = $(strip \ 3978cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(foreach key,$(AvailableIn.$(3)),\ 406db90e61b58ae72b07faf3272fa9f15d4ad9b3bcDaniel Dunbar $(if $(and $(call streq,Optimized,$($(key).Implementation)),\ 4178cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(call contains,$($(key).OnlyArchs),$(2))),$(key),))) 4278cfbc57c62949e16fa7b4a69775aa6450343a00Daniel DunbarSelectFunctionDirs_Gen = $(strip \ 4378cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(foreach key,$(AvailableIn.$(3)),\ 446db90e61b58ae72b07faf3272fa9f15d4ad9b3bcDaniel Dunbar $(if $(call streq,Generic,$($(key).Implementation)),$(key)))) 4578cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar 4678cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar# Helper function to select the right set of dirs in generic priority order. 4778cfbc57c62949e16fa7b4a69775aa6450343a00Daniel DunbarSelectFunctions_Gen = \ 4878cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(or $(call SelectFunctionDirs_Gen,$(1),$(2),$(3)),\ 4978cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(call SelectFunctionDirs_Opt_ConfigAndArch,$(1),$(2),$(3)), \ 5078cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(call SelectFunctionDirs_Opt_Config,$(1),$(2),$(3)), \ 5178cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(call SelectFunctionDirs_Opt_Arch,$(1),$(2),$(3))) 5278cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar 5378cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar# Helper function to select the right set of dirs in optimized priority order. 5478cfbc57c62949e16fa7b4a69775aa6450343a00Daniel DunbarSelectFunctions_Opt = \ 5578cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(or $(call SelectFunctionDirs_Opt_ConfigAndArch,$(1),$(2),$(3)), \ 5678cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(call SelectFunctionDirs_Opt_Config,$(1),$(2),$(3)), \ 5778cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(call SelectFunctionDirs_Opt_Arch,$(1),$(2),$(3)), \ 5878cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(call SelectFunctionDirs_Gen,$(1),$(2),$(3))) 5978cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar 6078cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar# Helper function to select the right set of dirs (which should be exactly one) 6178cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar# for a function. 6278cfbc57c62949e16fa7b4a69775aa6450343a00Daniel DunbarSelectFunctionDirs = \ 6378cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(if $(call streq,1,$(4)),\ 6478cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(call SelectFunctions_Opt,$(1),$(2),$(3)),\ 6578cfbc57c62949e16fa7b4a69775aa6450343a00Daniel Dunbar $(call SelectFunctions_Gen,$(1),$(2),$(3))) 66