Browse Source

libs/openlibm: Add a test for OpenLibm floating-point functions

master
Lephe 4 months ago
parent
commit
0ef5b0705a
Signed by: Lephenixnoir GPG Key ID: 1BBA026E13FC0495
5 changed files with 86 additions and 8 deletions
  1. +10
    -4
      Makefile
  2. +3
    -0
      include/gintctl/libs.h
  3. +7
    -4
      project.cfg
  4. +2
    -0
      src/gintctl.c
  5. +64
    -0
      src/libs/openlibm.c

+ 10
- 4
Makefile View File

@ -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/%


+ 3
- 0
include/gintctl/libs.h View File

@ -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);


+ 7
- 4
project.cfg View File

@ -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


+ 2
- 0
src/gintctl.c View File

@ -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 },


+ 64
- 0
src/libs/openlibm.c View File

@ -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…
Cancel
Save