Skip to content

Commit

Permalink
Merge pull request #295 from VisorFolks/feature/akashkollipara/294-li…
Browse files Browse the repository at this point in the history
…bmath

<TC> Add support for libmath
  • Loading branch information
akashkollipara authored Jul 3, 2024
2 parents 8202743 + d2ba34a commit d1f6cec
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 62 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ For more information, please visit [**Github Wiki**](https://github.com/VisorFol

### Supported Platforms

| Atmel | SiFive | STMicro | TI | Raspberry Pi |
| ---------- | ------------- | ----------- | ----------- | -------------|
| ATMega328P | FE310-G002 | Coming soon | Coming soon | Coming soon |
| ATMega2560 | QEMU SiFive-E | | | |
| Atmel | SiFive | STMicro | TI | Raspberry Pi | ibex |
| ---------- | ------------- | ----------- | ----------- | ------------- | ------------- |
| ATMega328P | FE310-G002 | Coming soon | Coming soon | Coming soon | simple-system |
| ATMega2560 | QEMU SiFive-E | | | | |

7 changes: 4 additions & 3 deletions mk/lib.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# CYANCORE LICENSE
# Copyrights (C) 2019, Cyancore Team
# Copyrights (C) 2024, Cyancore Team
#
# File Name : lib.mk
# Description : This file accumulates all the object files
Expand All @@ -18,10 +18,11 @@ include mk/lobj.mk
LIB := $(addprefix $(OUT)/$(DIR)/,$(LIB))
DEP_LIB_PATH += -L $(OUT)/$(DIR)
DEP_LIBS += $(LIB)
AR_FLAGS ?= rcs

$(LIB): $(LIB_OBJS)
$(LIB): $(LIB_OBJS) | $$(@D)/
@echo "Lib: Generating $(@F) ..."
$(AR) rc $@ $^
$(AR) $(AR_FLAGS) $@ $^

LIB_INCLUDE_PATH:=
LIB_OBJS :=
Expand Down
5 changes: 4 additions & 1 deletion mk/tc.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# CYANCORE LICENSE
# Copyrights (C) 2019, Cyancore Team
# Copyrights (C) 2024, Cyancore Team
#
# File Name : tc.mk
# Description : This file defines toolchain specific variables
Expand All @@ -16,6 +16,7 @@ $(eval $(call get_tc_version,$(TC))) # Sets TC_VER
TI := $(TOOLS_ROOT)/arm-toolchain/lib/gcc/arm-none-eabi/$(TC_VER)/include-fixed/
TI += $(TOOLS_ROOT)/arm-toolchain/arm-none-eabi/include/
TL := $(TOOLS_ROOT)/arm-toolchain/lib/gcc/arm-none-eabi/$(TC_VER)/$(TL_TYPE)/
TCL := $(TOOLS_ROOT)/arm-toolchain/arm-none-eabi/lib/
endif

ifeq ($(findstring riscv,$(ARCH)),riscv)
Expand All @@ -24,13 +25,15 @@ $(eval $(call get_tc_version,$(TC))) # Sets TC_VER
TI := $(TOOLS_ROOT)/risc-v-toolchain/lib/gcc/riscv64-unknown-elf/$(TC_VER)/include-fixed/
TI += $(TOOLS_ROOT)/risc-v-toolchain/riscv64-unknown-elf/include/
TL := $(TOOLS_ROOT)/risc-v-toolchain/lib/gcc/riscv64-unknown-elf/$(TC_VER)/rv$(BIT)$(ARCH_VARIANT)/$(ARCH_ABI)/
TCL := $(TOOLS_ROOT)/risc-v-toolchain/riscv64-unknown-elf/lib/rv$(BIT)$(ARCH_VARIANT)/$(ARCH_ABI)
endif

ifeq ($(findstring avr,$(ARCH)),avr)
TC ?= $(TOOLS_ROOT)/avr-toolchain/bin/avr
$(eval $(call get_tc_version,$(TC))) # Sets TC_VER
TI := $(TOOLS_ROOT)/avr-toolchain/lib/gcc/avr/$(TC_VER)/include-fixed
TL := $(TOOLS_ROOT)/avr-toolchain/lib/gcc/avr/$(TC_VER)/$(ARCH)$(ARCH_VARIANT)/
TCL := $(TOOLS_ROOT)/avr-toolchain/avr/lib/$(ARCH)$(ARCH_VARIANT)
endif

ifneq ($(ARCH),)
Expand Down
39 changes: 20 additions & 19 deletions src/include/compiler_macros.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2019, Cyancore Team
* Copyrights (C) 2024, Cyancore Team
*
* File Name : compiler_macro.h
* Description : This file defines the compiler macro utilities
Expand All @@ -10,22 +10,23 @@

#pragma once

#define _PRAGMA(x) _Pragma (#x)
#define INFO(x) _PRAGMA(message (#x))
#define WARN(x) _PRAGMA(GCC warning #x)
#define ERROR(x) _PRAGMA(GCC error #x)
#define TODO(x) INFO(TODO: x)
#define _PRAGMA(x) _Pragma (#x)
#define INFO(x) _PRAGMA(message (#x))
#define WARN(x) _PRAGMA(GCC warning #x)
#define ERROR(x) _PRAGMA(GCC error #x)
#define TODO(x) INFO(TODO: x)

#define _ATTRIBUTE(x) __attribute__((x))
#define _WEAK _ATTRIBUTE(weak)
#define _UNUSED _ATTRIBUTE(unused)
#define _INLINE _ATTRIBUTE(always_inline)
#define _NOINLINE _ATTRIBUTE(noinline)
#define _ALIGN(x) _ATTRIBUTE(aligned(x))
#define _SECTION(x) _ATTRIBUTE(section(x))
#define _DEPRICATE _ATTRIBUTE(depricated)
#define _ALIAS(x) _ATTRIBUTE(alias(x))
#define _FALLTHROUGH _ATTRIBUTE(fallthrough)
#define _NORETURN _ATTRIBUTE(noreturn)
#define _NAKED _ATTRIBUTE(naked)
#define EXPORT_C(x) extern "C" x; x
#define _ATTRIBUTE(x) __attribute__((x))
#define _WEAK _ATTRIBUTE(weak)
#define _UNUSED _ATTRIBUTE(unused)
#define _INLINE _ATTRIBUTE(always_inline)
#define _NOINLINE _ATTRIBUTE(noinline)
#define _ALIGN(x) _ATTRIBUTE(aligned(x))
#define _SECTION(x) _ATTRIBUTE(section(x))
#define _DEPRICATE _ATTRIBUTE(depricated)
#define _ALIAS(x) _ATTRIBUTE(alias(x))
#define _FALLTHROUGH _ATTRIBUTE(fallthrough)
#define _NORETURN _ATTRIBUTE(noreturn)
#define _NAKED _ATTRIBUTE(naked)
#define EXPORT_C(x) extern "C" x; x
#define EXPORT_C_PROTO(x) extern "C" { x }
32 changes: 1 addition & 31 deletions src/lib/libnmath/arithmetic/arithmetic.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2019, Cyancore Team
* Copyrights (C) 2024, Cyancore Team
*
* File Name : arithmetic.c
* Description : This file contains sources of neo-math function
Expand All @@ -25,36 +25,6 @@ unsigned int clog2(unsigned long num)
return (num > 1) ? (1 + clog2((num & 0x01) ? ((num + 1) >> 1) : (num >> 1))) : 0;
}

/**
* ceiling
*
* @brief Determines the ceiling of the input number
*
* @param[in] num: Input number
*
* @return ceiling
*/
double ceiling(double num)
{
long inum = (long) num;
return (double)(num - inum) ? (inum + 1) : num;
}

/**
* floor
*
* @brief Determing the floor of the input number
*
* @param[in] num: Input number
*
* @return floor
*/
double floor(double num)
{
long inum = (long) num;
return (double)inum;
}

/**
* gcd - Greatest Common Divisor
*
Expand Down
4 changes: 3 additions & 1 deletion src/lib/libnmath/build.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# CYANCORE LICENSE
# Copyrights (C) 2019, Cyancore Team
# Copyrights (C) 2024, Cyancore Team
#
# File Name : build.mk
# Descrption : This script accumulates sources and build
Expand All @@ -21,3 +21,5 @@ include $(NMATH_PATH)/dsp/build.mk

DIR := $(NMATH_PATH)
include mk/lib.mk

include $(NMATH_PATH)/libm/build.mk
4 changes: 1 addition & 3 deletions src/lib/libnmath/include/nmath.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2019, Cyancore Team
* Copyrights (C) 2024, Cyancore Team
*
* File Name : nmath.h
* Description : This file contains prototypes of neo-math function
Expand All @@ -11,8 +11,6 @@
#pragma once
#include <stdbool.h>
unsigned int clog2(unsigned long num);
double ceiling(double num);
double floor(double num);
unsigned long gcd(unsigned long a, unsigned long b);
unsigned long lcd(unsigned int *a, unsigned int n);
long mod(long a, long b);
Expand Down
24 changes: 24 additions & 0 deletions src/lib/libnmath/libm/build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# CYANCORE LICENSE
# Copyrights (C) 2024, Cyancore Team
#
# File Name : build.mk
# Descrption : This script generates tcmath library
# it uses toolchain's libm.a
# Primary Author : Akash Kollipara [[email protected]]
# Organisation : Cyancore Core-Team
#

TCMATH_PATH := $(GET_PATH)

LIB_OBJS := $$(TCL)/libm.a

LIB := libtcmath.a
LIB_INCLUDE += $(TCMATH_PATH)/include/
DEP_LIBS_ARG += -ltcmath

AR_FLAGS := rcsT

DIR := $(TCMATH_PATH)

include mk/lib.mk
148 changes: 148 additions & 0 deletions src/lib/libnmath/libm/include/math.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* CYANCORE LICENSE
* Copyrights (C) 2024, Cyancore Team
*
* File Name : math.h
* Description : This file contains prototypes of math function
* It is same as the one in toolchain but tailored
* for cyancore
* Primary Author : Akash Kollipara [[email protected]]
* Organisation : Cyancore Core-Team
*/

#pragma once
#include <status.h>

#define M_E 2.7182818284590452354
#define M_LOG2E 1.4426950408889634074 /* log_2 e */
#define M_LOG10E 0.43429448190325182765 /* log_10 e */
#define M_LN2 0.69314718055994530942 /* log_e 2 */
#define M_LN10 2.30258509299404568402 /* log_e 10 */
#define M_PI 3.14159265358979323846 /* pi */
#define M_PI_2 1.57079632679489661923 /* pi/2 */
#define M_PI_4 0.78539816339744830962 /* pi/4 */
#define M_1_PI 0.31830988618379067154 /* 1/pi */
#define M_2_PI 0.63661977236758134308 /* 2/pi */
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
#define NAN __builtin_nan("")
#define INFINITY __builtin_inf()

#ifdef __cplusplus
EXPORT_C_PROTO(
#endif

extern double cos(double);
#define cosf cos

extern double sin(double);
#define sinf sin

extern double tan(double);
#define tanf tan

extern double fabs(double);
#define fabsf fabs

extern double fmod(double, double);
#define fmodf fmod

extern double modf(double, double *);

extern float modff (float, float *);

extern double sqrt(double);

extern float sqrtf (float);

extern double cbrt(double);
#define cbrtf cbrt

extern double hypot (double, double);
#define hypotf hypot

extern double square(double);
#define squaref square

extern double floor(double);
#define floorf floor

extern double ceil(double);
#define ceilf ceil

extern double frexp(double, int *);
#define frexpf frexp

extern double ldexp(double, int);
#define ldexpf ldexp

extern double exp(double);
#define expf exp

extern double cosh(double);
#define coshf cosh

extern double sinh(double);
#define sinhf sinh

extern double tanh(double);
#define tanhf tanh

extern double acos(double);
#define acosf acos

extern double asin(double);
#define asinf asin

extern double atan(double);
#define atanf atan

extern double atan2(double, double);
#define atan2f atan2

extern double log(double);
#define logf log

extern double log10(double);
#define log10f log10

extern double pow(double, double);
#define powf pow

extern int isnan(double);
#define isnanf isnan

extern int isinf(double);
#define isinff isinf

extern int signbit (double);
#define signbitf signbit

extern double fdim (double, double);
#define fdimf fdim

extern double fma (double, double, double);
#define fmaf fma

extern double fmax (double, double);
#define fmaxf fmax

extern double fmin (double, double);
#define fminf fmin

extern double trunc (double);
#define truncf trunc

extern double round (double);
#define roundf round

extern long lround (double);
#define lroundf lround

extern long lrint (double);
#define lrintf lrint

#ifdef __cplusplus
)
#endif

0 comments on commit d1f6cec

Please sign in to comment.