Compare commits

..

No commits in common. "master" and "2.0.1" have entirely different histories.

8 changed files with 73 additions and 129 deletions

7
.gitignore vendored
View file

@ -1,6 +1,3 @@
# Build files # Build files
build*/ build/
libprof.a
# GiteaPC configuration files
giteapc-config-*.make
giteapc-config.make

View file

@ -1,21 +0,0 @@
# Build system for the libprof library for gint
cmake_minimum_required(VERSION 3.15)
project(libprof VERSION 2.4.0 LANGUAGES C)
find_package(Gint 2.4.0 REQUIRED)
configure_file(libprof.h libprof.h)
set(NAME "prof-${FXSDK_PLATFORM}")
add_library(${NAME} STATIC libprof.c)
target_compile_options(${NAME} PUBLIC -Wall -Wextra -std=c11 -Os)
target_include_directories(${NAME} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(${NAME} Gint::Gint)
install(TARGETS ${NAME}
DESTINATION "${FXSDK_LIB}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libprof.h"
DESTINATION "${FXSDK_INCLUDE}")
install(FILES cmake/FindLibProf.cmake
DESTINATION "${FXSDK_CMAKE_MODULE_PATH}")

46
Makefile Normal file
View file

@ -0,0 +1,46 @@
#! /usr/bin/make -f
# libprof Makefile
cflags := -m3 -mb -ffreestanding -nostdlib -fstrict-volatile-bitfields -Wall \
-Wextra -Os -I .
target ?= sh-elf
lib := libprof.a
header := libprof.h
PREFIX ?= $(shell $(target)-gcc -print-search-dirs | grep install \
| sed 's/install: //')
ifeq "$(PREFIX)" ""
$(error "Cannot determine compiler install path")
endif
src := $(wildcard *.c)
obj := $(src:%=build/%.o)
# Rules
all: $(lib)
$(lib): $(obj)
$(target)-ar rcs $@ $^
build/%.c.o: %.c | build/
$(target)-gcc -c $< -o $@ $(cflags)
# Misc rules
clean:
@ rm -rf build
distclean: clean
@ rm -f $(lib)
%/:
mkdir -p $@
.PRECIOUS: %/
# Install
install: $(lib)
cp $(lib) $(DESTDIR)$(PREFIX)
cp $(header) $(DESTDIR)$(PREFIX)/include

View file

@ -8,46 +8,32 @@ libprof's measurements are accurate down to the microsecond-level thanks to
precise hardware timers, so it can also be used to time even small portions of precise hardware timers, so it can also be used to time even small portions of
code. code.
## Installing and using libprof in a program ## Building
**Installing with GiteaPC** libprof is built and installed only once for both fx-9860G and fx-CG 50. The
dependencies are:
libprof can be built and installed with [GiteaPC](https://gitea.planet-casio.com/Lephenixnoir/GiteaPC), an automation tool for the fxSDK. * A GCC cross-compiler for a SuperH architecture
* The [gint kernel](/Lephenixnoir/gint)
```bash The Makefile will build and install the library without further instructions.
% giteapc install Lephenixnoir/libprof
```sh
% make
% make install
``` ```
**Installing manually** By default `sh-elf` is used to build; you can override this by setting the
`target` variable.
libprof should be built with the [fxSDK](/Lephenixnoir/fxsdk), which provides ```sh
compiler settings and library interfaces to build on the calculator. % make target=sh4eb-elf
% make install target=sh4eb-elf
Simply run `fxsdk build-fx` or `fxsdk build-cg`. The fxSDK will invoke CMake
with a suitable toolchain file while exposing CMake modules for the calculator.
```bash
% fxsdk build-fx install
% fxsdk build-cg install
``` ```
**Using in a CMake-based add-in** If you have the older setup with two toolchains (`sh3eb-elf` and `sh4eb-elf`),
instead of the new one with two targets on the same toolchain (`sh-elf`), you
Find the `LibProf` package, which has a `LibProf` target. Versions are numbered like gint, so aim for your version of gint. will need to make and install twice.
```cmake
find_package(LibProf 2.1 REQUIRED)
target_link_libraries(<target_name> LibProf::LibProf)
```
**Using in a Makefile-based add-in**
Link with `-lprof-fx` on fx-9860G and `-lprof-cg` on fx-CG 50. In `project.cfg`:
```makefile
LIBS_FX := -lprof-fx
LIBS_CG := -lprof-cg
```
## Basic use ## Basic use

View file

@ -1,19 +0,0 @@
include(FindSimpleLibrary)
include(FindPackageHandleStandardArgs)
find_package(Gint 2.2.1 REQUIRED)
find_simple_library("libprof-${FXSDK_PLATFORM}.a" libprof.h
"PROF_VERSION" PATH_VAR PROF_PATH VERSION_VAR PROF_VERSION)
find_package_handle_standard_args(LibProf
REQUIRED_VARS PROF_PATH PROF_VERSION
VERSION_VAR PROF_VERSION)
if(LibProf_FOUND)
add_library(LibProf::LibProf UNKNOWN IMPORTED)
set_target_properties(LibProf::LibProf PROPERTIES
IMPORTED_LOCATION "${PROF_PATH}"
INTERFACE_LINK_OPTIONS -lprof-${FXSDK_PLATFORM}
IMPORTED_LINK_INTERFACE_LIBRARIES Gint::Gint)
endif()

View file

@ -1,25 +0,0 @@
# giteapc: version=1 depends=Lephenixnoir/gint
-include giteapc-config.make
configure:
@ fxsdk build-fx -c
@ fxsdk build-cg -c
build:
@ fxsdk build-fx
@ fxsdk build-cg
install:
@ fxsdk build-fx install
@ fxsdk build-cg install
uninstall:
@ if [ -e build-fx/install_manifest.txt ]; then \
xargs rm -f < build-fx/install_manifest.txt; \
fi
@ if [ -e build-cg/install_manifest.txt ]; then \
xargs rm -f < build-cg/install_manifest.txt; \
fi
.PHONY: configure build install uninstall

View file

@ -22,8 +22,7 @@ int prof_init(void)
int timer = -1; int timer = -1;
for(int t = 2; t >= 0 && timer == -1; t--) for(int t = 2; t >= 0 && timer == -1; t--)
{ {
timer = timer_configure(t | TIMER_Pphi_4, 0xffffffff, timer = timer_setup(t | TIMER_Pphi_4, 0xffffffff, callback);
GINT_CALL(callback));
} }
if(timer == -1) if(timer == -1)
{ {

View file

@ -5,16 +5,9 @@
#ifndef LIBPROF_LIBPROF #ifndef LIBPROF_LIBPROF
#define LIBPROF_LIBPROF #define LIBPROF_LIBPROF
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h> #include <stdint.h>
#include <gint/defs/attributes.h> #include <gint/defs/attributes.h>
/* This is substituted by CMake at compile-time */
#define PROF_VERSION "@libprof_VERSION@"
//--- //---
// Initialization // Initialization
//--- //---
@ -58,7 +51,7 @@ extern uint32_t volatile *prof_tcnt;
function was already executing then the deepest instance in the stack is function was already executing then the deepest instance in the stack is
used instead of creating a new counter. */ used instead of creating a new counter. */
#define prof_enter(prof) { \ #define prof_enter(prof) { \
if(!(prof).rec++) (prof).elapsed += *prof_tcnt; \ if(!prof.rec++) prof.elapsed += *prof_tcnt; \
} }
/* prof_leave(): Stop counting time for a function /* prof_leave(): Stop counting time for a function
@ -67,15 +60,7 @@ extern uint32_t volatile *prof_tcnt;
are not as exactly as many prof_leave()'s as prof_enter()'s then the are not as exactly as many prof_leave()'s as prof_enter()'s then the
resulting time measure will not be relevant at all. */ resulting time measure will not be relevant at all. */
#define prof_leave(prof) { \ #define prof_leave(prof) { \
if(!--(prof).rec) (prof).elapsed -= *prof_tcnt; \ if(!--prof.rec) prof.elapsed -= *prof_tcnt; \
}
/* Variant of prof_enter()/prof_leave() for non-recursive contexts */
#define prof_enter_norec(prof) { \
(prof).elapsed += *prof_tcnt; \
}
#define prof_leave_norec(prof) { \
(prof).elapsed -= *prof_tcnt; \
} }
/* prof_exec(): Measure a single block of code /* prof_exec(): Measure a single block of code
@ -87,11 +72,11 @@ extern uint32_t volatile *prof_tcnt;
exec_code(); exec_code();
}); */ }); */
#define prof_exec(code) ({ \ #define prof_exec(code) ({ \
prof_t _prof = prof_make(); \ prof_t prof = prof_make(); \
prof_enter(_prof); \ prof_enter(prof); \
code; \ code; \
prof_leave(_prof); \ prof_leave(prof); \
prof_time(_prof); \ prof_time(prof); \
}) })
//--- //---
@ -102,8 +87,4 @@ extern uint32_t volatile *prof_tcnt;
Should only be called when the context is not currently executing. */ Should only be called when the context is not currently executing. */
uint32_t prof_time(prof_t prof); uint32_t prof_time(prof_t prof);
#ifdef __cplusplus
}
#endif
#endif /* LIBPROF_LIBPROF */ #endif /* LIBPROF_LIBPROF */