1if (NOT TARGET pico_bit_ops)
2    #shims for ROM functions for -lgcc functions  (listed below)
3    pico_add_impl_library(pico_bit_ops)
4
5    # no custom implementation; falls thru to compiler
6    pico_add_library(pico_bit_ops_compiler)
7
8    # add alias "default" which is just pico.
9    add_library(pico_bit_ops_default INTERFACE)
10    target_link_libraries(pico_bit_ops_default INTERFACE pico_bit_ops_pico)
11
12    set(PICO_DEFAULT_BIT_OPS_IMPL pico_bit_ops_default)
13
14    pico_add_library(pico_bit_ops_pico)
15    target_link_libraries(pico_bit_ops INTERFACE
16            $<IF:$<BOOL:$<TARGET_PROPERTY:PICO_TARGET_BIT_OPS_IMPL>>,$<TARGET_PROPERTY:PICO_TARGET_BIT_OPS_IMPL>,${PICO_DEFAULT_BIT_OPS_IMPL}>)
17
18    target_sources(pico_bit_ops_pico INTERFACE
19            ${CMAKE_CURRENT_LIST_DIR}/bit_ops_aeabi.S
20            )
21
22    target_link_libraries(pico_bit_ops_pico INTERFACE pico_bootrom pico_bit_ops_headers)
23
24    if (NOT PICO_RP2350)
25        # gcc
26        pico_wrap_function(pico_bit_ops_pico __clzsi2)
27        pico_wrap_function(pico_bit_ops_pico __clzsi2)
28        pico_wrap_function(pico_bit_ops_pico __clzdi2)
29        pico_wrap_function(pico_bit_ops_pico __ctzsi2)
30        pico_wrap_function(pico_bit_ops_pico __popcountsi2)
31        pico_wrap_function(pico_bit_ops_pico __popcountdi2)
32
33        # armclang
34        pico_wrap_function(pico_bit_ops_pico __clz)
35        pico_wrap_function(pico_bit_ops_pico __clzl)
36        pico_wrap_function(pico_bit_ops_pico __clzsi2)
37        pico_wrap_function(pico_bit_ops_pico __clzll)
38    endif()
39    # this is overridden for RP2350 since GCCs impl is bad for both ARM and RISC-V
40    pico_wrap_function(pico_bit_ops_pico __ctzdi2)
41
42    macro(pico_set_bit_ops_implementation TARGET IMPL)
43        get_target_property(target_type ${TARGET} TYPE)
44        if ("EXECUTABLE" STREQUAL "${target_type}")
45            set_target_properties(${TARGET} PROPERTIES PICO_TARGET_BIT_OPS_IMPL "pico_bit_ops_${IMPL}")
46        else()
47            message(FATAL_ERROR "bit_ops implementation must be set on executable not library")
48        endif()
49    endmacro()
50
51endif()
52