Initial Release

This commit is contained in:
graham sanderson
2021-01-20 10:44:27 -06:00
commit 26653ea81e
404 changed files with 135614 additions and 0 deletions

View File

@ -0,0 +1,57 @@
if (NOT TARGET pico_bit_ops)
#shims for ROM functions for -lgcc functions (listed below)
add_library(pico_bit_ops INTERFACE)
# no custom implementation; falls thru to compiler
add_library(pico_bit_ops_compiler INTERFACE)
# PICO_BUILD_DEFINE: PICO_BIT_OPS_COMPILER, whether compiler provided bit_ops bit functions support is being used, type=bool, default=0, but dependent on CMake options, group=pico_bit_ops
target_compile_definitions(pico_bit_ops_compiler INTERFACE
PICO_BIT_OPS_COMPILER=1
)
# add alias "default" which is just pico.
add_library(pico_bit_ops_default INTERFACE)
target_link_libraries(pico_bit_ops_default INTERFACE pico_bit_ops_pico)
set(PICO_DEFAULT_BIT_OPS_IMPL pico_bit_ops_default)
add_library(pico_bit_ops_pico INTERFACE)
target_link_libraries(pico_bit_ops INTERFACE
$<IF:$<BOOL:$<TARGET_PROPERTY:PICO_TARGET_BIT_OPS_IMPL>>,$<TARGET_PROPERTY:PICO_TARGET_BIT_OPS_IMPL>,${PICO_DEFAULT_BIT_OPS_IMPL}>)
# PICO_BUILD_DEFINE: PICO_BIT_OPS_PICO, whether optimized pico/bootrom provided bit_ops bit functions support is being used, type=bool, default=1, but dependent on CMake options, group=pico_bit_ops
target_compile_definitions(pico_bit_ops_pico INTERFACE
PICO_BIT_OPS_PICO=1
)
target_sources(pico_bit_ops_pico INTERFACE
${CMAKE_CURRENT_LIST_DIR}/bit_ops_aeabi.S
)
target_link_libraries(pico_bit_ops_pico INTERFACE pico_bootrom pico_bit_ops_headers)
# gcc
pico_wrap_function(pico_bit_ops_pico __clzsi2)
pico_wrap_function(pico_bit_ops_pico __clzsi2)
pico_wrap_function(pico_bit_ops_pico __clzdi2)
pico_wrap_function(pico_bit_ops_pico __ctzsi2)
pico_wrap_function(pico_bit_ops_pico __ctzdi2)
pico_wrap_function(pico_bit_ops_pico __popcountsi2)
pico_wrap_function(pico_bit_ops_pico __popcountdi2)
# armclang
pico_wrap_function(pico_bit_ops_pico __clz)
pico_wrap_function(pico_bit_ops_pico __clzl)
pico_wrap_function(pico_bit_ops_pico __clzsi2)
pico_wrap_function(pico_bit_ops_pico __clzll)
macro(pico_set_bit_ops_implementation TARGET IMPL)
get_target_property(target_type ${TARGET} TYPE)
if ("EXECUTABLE" STREQUAL "${target_type}")
set_target_properties(${TARGET} PROPERTIES PICO_TARGET_BIT_OPS_IMPL "pico_bit_ops_${IMPL}")
else()
message(FATAL_ERROR "bit_ops implementation must be set on executable not library")
endif()
endmacro()
endif()

View File

@ -0,0 +1,132 @@
/*
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
.syntax unified
.cpu cortex-m0plus
.thumb
#include "pico/asm_helper.S"
__pre_init __aeabi_bits_init, 00010
.macro bits_section name
#if PICO_BITS_IN_RAM
.section RAM_SECTION_NAME(\name), "ax"
#else
.section SECTION_NAME(\name), "ax"
#endif
.endm
.section .data.aeabi_bits_funcs
.global aeabi_bits_funcs, aeabi_bits_funcs_end
.equ BITS_FUNC_COUNT, 4
.align 4
aeabi_bits_funcs:
.word rom_table_code('P','3') // popcount32
.word rom_table_code('L','3') // clz32
.word rom_table_code('T','3') // ctz32
.word rom_table_code('R','3') // reverse32
aeabi_bits_funcs_end:
.section .text
.thumb_func
__aeabi_bits_init:
ldr r0, =aeabi_bits_funcs
movs r1, #BITS_FUNC_COUNT
ldr r3, =rom_funcs_lookup
bx r3
.equ POPCOUNT32, 0
.equ CLZ32, 4
.equ CTZ32, 8
.equ REVERSE32, 12
bits_section clzsi
wrapper_func __clz
wrapper_func __clzl
wrapper_func __clzsi2
ldr r3, =aeabi_bits_funcs
ldr r3, [r3, #CLZ32]
bx r3
bits_section ctzsi
wrapper_func __ctzsi2
ldr r3, =aeabi_bits_funcs
ldr r3, [r3, #CTZ32]
bx r3
bits_section popcountsi
wrapper_func __popcountsi2
ldr r3, =aeabi_bits_funcs
ldr r3, [r3, #POPCOUNT32]
bx r3
bits_section clzdi
wrapper_func __clzll
wrapper_func __clzdi2
ldr r3, =aeabi_bits_funcs
ldr r3, [r3, #CLZ32]
cmp r1, #0
bne 1f
push {lr}
blx r3
adds r0, #32
pop {pc}
1:
mov r0, r1
bx r3
bits_section ctzdi
wrapper_func __ctzdi2
ldr r3, =aeabi_bits_funcs
ldr r3, [r3, #CTZ32]
cmp r0, #0
bne 1f
bx r3
1:
push {lr}
mov r0, r1
blx r3
adds r0, #32
pop {pc}
bits_section popcountdi
wrapper_func __popcountdi2
ldr r3, =aeabi_bits_funcs
ldr r3, [r3, #POPCOUNT32]
push {r1, r3, lr}
blx r3
mov ip, r0
pop {r0, r3}
blx r3
mov r1, ip
add r0, r1
pop {pc}
bits_section reverse32
regular_func reverse32
ldr r3, =aeabi_bits_funcs
ldr r3, [r3, #REVERSE32]
bx r3
bits_section __rev
regular_func __rev
regular_func __revl
ldr r3, =aeabi_bits_funcs
ldr r3, [r3, #REVERSE32]
bx r3
bits_section __revll
regular_func __revll
push {lr}
ldr r3, =aeabi_bits_funcs
ldr r3, [r3, #REVERSE32]
push {r1, r3}
blx r3
mov ip, r0 // reverse32 preserves ip
pop {r0, r3}
blx r3
mov r1, ip
pop {pc}