libs/openlibm: Add a test for OpenLibm floating-point functions
This commit is contained in:
parent
2836e2648f
commit
0ef5b0705a
14
Makefile
14
Makefile
|
@ -10,8 +10,8 @@
|
|||
include project.cfg
|
||||
|
||||
# Compiler flags
|
||||
CFLAGSFX := $(CFLAGS) $(CFLAGS_FX) $(INCLUDE)
|
||||
CFLAGSCG := $(CFLAGS) $(CFLAGS_CG) $(INCLUDE)
|
||||
CFLAGSFX = $(CFLAGS) $(CFLAGS_FX) $(INCLUDE_FX)
|
||||
CFLAGSCG = $(CFLAGS) $(CFLAGS_CG) $(INCLUDE_CG)
|
||||
|
||||
# Linker flags
|
||||
LDFLAGSFX := $(LDFLAGS) $(LDFLAGS_FX)
|
||||
|
@ -40,6 +40,12 @@ endif
|
|||
FXCONVFX := --fx --toolchain=$(TOOLCHAIN_FX)
|
||||
FXCONVCG := --cg --toolchain=$(TOOLCHAIN_CG)
|
||||
|
||||
# Determine the compiler install and include path
|
||||
GCC_BASE_FX := $(shell $(TOOLCHAIN_FX)-gcc --print-search-dirs | grep install | sed 's/install: //')
|
||||
GCC_BASE_CG := $(shell $(TOOLCHAIN_CG)-gcc --print-search-dirs | grep install | sed 's/install: //')
|
||||
GCC_INCLUDE_FX := $(GCC_BASE_FX)/include
|
||||
GCC_INCLUDE_CG := $(GCC_BASE_CG)/include
|
||||
|
||||
#
|
||||
# File listings
|
||||
#
|
||||
|
@ -128,10 +134,10 @@ build-cg/%.s.o: %.s
|
|||
# Preprocessed assembler sources
|
||||
build-fx/%.S.o: %.S
|
||||
@ mkdir -p $(dir $@)
|
||||
$(TOOLCHAIN_FX)-gcc -c $< -o $@ $(INCLUDE) -Wa,--dsp
|
||||
$(TOOLCHAIN_FX)-gcc -c $< -o $@ $(INCLUDE_FX) -Wa,--dsp
|
||||
build-cg/%.S.o: %.S
|
||||
@ mkdir -p $(dir $@)
|
||||
$(TOOLCHAIN_CG)-gcc -c $< -o $@ $(INCLUDE) -Wa,--dsp
|
||||
$(TOOLCHAIN_CG)-gcc -c $< -o $@ $(INCLUDE_CG) -Wa,--dsp
|
||||
|
||||
# Images
|
||||
build-fx/assets/img/%.o: assets-fx/img/%
|
||||
|
|
|
@ -14,6 +14,9 @@ void gintctl_libs_printf(void);
|
|||
/* gintctl_libs_memory(): Core memory functions */
|
||||
void gintctl_libs_memory(void);
|
||||
|
||||
/* gintctl_libs_openlibm(): OpenLibm floating-point functions */
|
||||
void gintctl_libs_openlibm(void);
|
||||
|
||||
/* gintctl_libs_libimg(): libimg-based rendering and image transform */
|
||||
void gintctl_libs_libimg(void);
|
||||
|
||||
|
|
11
project.cfg
11
project.cfg
|
@ -55,14 +55,17 @@ CFLAGS_CG := -D FXCG50 -m4-nofpu
|
|||
CFLAGS += -Wall -Wextra -Os
|
||||
|
||||
# Include paths. Add one -I option for each folder from which you want to
|
||||
# be able to include files with #include<>.
|
||||
INCLUDE := -I include
|
||||
# be able to include files with #include<>. The Makefile provides a variable
|
||||
# GCC_INCLUDE_FX/GCC_INCLUDE_CG that represents the default include folder,
|
||||
# which is useful for some libraries such as OpenLibm.
|
||||
INCLUDE_FX = -I include -I $(GCC_INCLUDE_FX)/openlibm
|
||||
INCLUDE_CG = -I include -I $(GCC_INCLUDE_CG)/openlibm
|
||||
|
||||
# Libraries. Add one -l option for each library you are using, and also
|
||||
# suitable -L options if you have library files in custom folders. To use
|
||||
# fxlib, add libfx.a to the project directory and use "-L . -lfx".
|
||||
LIBS_FX := -lprof -limg-fx
|
||||
LIBS_CG := -lprof -limg-cg
|
||||
LIBS_FX := -lprof -limg-fx -lopenlibm
|
||||
LIBS_CG := -lprof -limg-cg -lopenlibm
|
||||
|
||||
# Base linker flags for the fxSDK, you usually want to keep these.
|
||||
LDFLAGS_FX := -T fx9860g.ld -lgint-fx $(LIBS_FX) -lgint-fx -lgcc
|
||||
|
|
|
@ -85,6 +85,8 @@ struct menu menu_libs = {
|
|||
gintctl_libs_printf },
|
||||
{ "libc: " _("mem functions", "Core memory functions"),
|
||||
gintctl_libs_memory },
|
||||
{ "libm: " _("OpenLibm", "OpenLibm floating-point functions"),
|
||||
gintctl_libs_openlibm },
|
||||
{ "libimg" _("",": Image transforms"),
|
||||
gintctl_libs_libimg },
|
||||
{ NULL, NULL },
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
#include <gint/display.h>
|
||||
#include <gint/keyboard.h>
|
||||
|
||||
#include <gintctl/libs.h>
|
||||
#include <gintctl/plot.h>
|
||||
|
||||
#define __BSD_VISIBLE 1
|
||||
#include <openlibm/openlibm.h>
|
||||
|
||||
/* gintctl_libs_openlibm(): OpenLibm floating-point functions */
|
||||
void gintctl_libs_openlibm(void)
|
||||
{
|
||||
/* Sine curve magnified 1000 times because plot() only uses ints */
|
||||
int32_t x[128], y[128];
|
||||
|
||||
for(int i = 0; i < 128; i++)
|
||||
{
|
||||
x[i] = 1000 * i * M_PI / 20;
|
||||
y[i] = 1000 * sin(i * M_PI / 20);
|
||||
}
|
||||
|
||||
dclear(C_WHITE);
|
||||
|
||||
#ifdef FXCG50
|
||||
row_title("OpenLibm floating-point functions");
|
||||
row_print(1, 1, "Basic sine curve:");
|
||||
|
||||
struct plot plotspec = {
|
||||
.area = {
|
||||
.x = 20, .w = 354,
|
||||
.y = 40, .h = 80,
|
||||
},
|
||||
.data_x = x,
|
||||
.data_y = y,
|
||||
.data_len = 128,
|
||||
.color = C_RED,
|
||||
|
||||
.ticks_x = {
|
||||
.multiples = 785, /* pi/4 */
|
||||
.subtick_divisions = 4,
|
||||
.format = "",
|
||||
},
|
||||
.ticks_y = {
|
||||
.multiples = 250, /* 0.25 */
|
||||
.subtick_divisions = 2,
|
||||
.format = "",
|
||||
},
|
||||
|
||||
.grid = {
|
||||
.level = PLOT_FULLGRID,
|
||||
.primary_color = C_RGB(20, 20, 20),
|
||||
.secondary_color = C_RGB(28, 28, 28),
|
||||
.dotted = 1,
|
||||
},
|
||||
};
|
||||
plot(&plotspec);
|
||||
|
||||
row_print(8, 1, "exp(1.0) = %.8j", (int)(1e8*exp(1.0)));
|
||||
row_print(9, 1, "atan(1.0)*4 = %.8j", (int)(1e8*4*atan(1.0)));
|
||||
#endif
|
||||
|
||||
dupdate();
|
||||
while(getkey().key != KEY_EXIT) {}
|
||||
}
|
Loading…
Reference in New Issue