aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2017-04-28 23:45:45 +0200
committerThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2017-04-28 23:45:45 +0200
commit1b8299753be42dac5d1946b6eb8bb46263142e1d (patch)
tree4c26831f1de84a5eddccd06f061644a598aeb4bf
parentfdf1796bccb64654e65caddb1851a520982e127e (diff)
Moar things.
-rw-r--r--build/gcc.mk40
-rw-r--r--build/hitachi.mk16
-rw-r--r--include/asm.h7
-rw-r--r--include/builtin.h13
-rw-r--r--include/cdefs.h7
-rw-r--r--include/cdefs/attrs.h3
-rw-r--r--include/cdefs/compiler.h65
-rw-r--r--include/cdefs/features.h32
-rw-r--r--include/cdefs/superh.h13
-rw-r--r--include/cdefs/utils.h17
-rw-r--r--include/malloc.h3
-rw-r--r--include/math.h109
-rw-r--r--include/mathf.h86
-rw-r--r--include/smachine.h14
-rw-r--r--include/stdlib.h2
-rw-r--r--include/umachine.h54
-rw-r--r--src/stdlib/div.c2
17 files changed, 343 insertions, 140 deletions
diff --git a/build/gcc.mk b/build/gcc.mk
index b827c06..6588040 100644
--- a/build/gcc.mk
+++ b/build/gcc.mk
@@ -69,27 +69,57 @@ endef
# (prefix, destination directory, source directory, element)
# e.g. ('/home/user/carrot', './obj', './src', 'subdirectory/element')
- SOURCE_EXT = c cpp S s
+ SOURCE_EXT = c C cpp CPP cc CC cp CP cxx CXX c++ S sx s
define make-obj-rules
# Make a C object file.
$1/$2/$4.c.o: $1/$3/$4.c $$(INC) | $(dir $1/$2/$4)
$(call bcmd,cc,$2/$4.c.o,cd "$1" && \
- $(CC) -c -o $2/$4.c.o $3/$4.c $(CFLAGS))
+ $(CC) -x c -c -o $2/$4.c.o $3/$4.c $(CFLAGS))
+ $1/$2/$4.C.o: $1/$3/$4.C $$(INC) | $(dir $1/$2/$4)
+ $(call bcmd,cc,$2/$4.C.o,cd "$1" && \
+ $(CC) -x c -c -o $2/$4.C.o $3/$4.C $(CFLAGS))
# Make a C++ object file.
$1/$2/$4.cpp.o: $1/$3/$4.cpp $$(INC) $$(INCXX) | $(dir $1/$2/$4)
$(call bcmd,cxx,$2/$4.cpp.o,cd "$1" && \
- $(CXX) -c -o $2/$4.cpp.o $3/$4.cpp $(CXXFLAGS))
+ $(CXX) -x c++ -c -o $2/$4.cpp.o $3/$4.cpp $(CXXFLAGS))
+ $1/$2/$4.CPP.o: $1/$3/$4.CPP $$(INC) $$(INCXX) | $(dir $1/$2/$4)
+ $(call bcmd,cxx,$2/$4.CPP.o,cd "$1" && \
+ $(CXX) -x c++ -c -o $2/$4.CPP.o $3/$4.CPP $(CXXFLAGS))
+ $1/$2/$4.cc.o: $1/$3/$4.cc $$(INC) $$(INCXX) | $(dir $1/$2/$4)
+ $(call bcmd,cxx,$2/$4.cc.o,cd "$1" && \
+ $(CXX) -x c++ -c -o $2/$4.cc.o $3/$4.cc $(CXXFLAGS))
+ $1/$2/$4.CC.o: $1/$3/$4.CC $$(INC) $$(INCXX) | $(dir $1/$2/$4)
+ $(call bcmd,cxx,$2/$4.CC.o,cd "$1" && \
+ $(CXX) -x c++ -c -o $2/$4.CC.o $3/$4.CC $(CXXFLAGS))
+ $1/$2/$4.cp.o: $1/$3/$4.cp $$(INC) $$(INCXX) | $(dir $1/$2/$4)
+ $(call bcmd,cxx,$2/$4.cp.o,cd "$1" && \
+ $(CXX) -x c++ -c -o $2/$4.cp.o $3/$4.cp $(CXXFLAGS))
+ $1/$2/$4.CP.o: $1/$3/$4.CP $$(INC) $$(INCXX) | $(dir $1/$2/$4)
+ $(call bcmd,cxx,$2/$4.CP.o,cd "$1" && \
+ $(CXX) -x c++ -c -o $2/$4.CP.o $3/$4.CP $(CXXFLAGS))
+ $1/$2/$4.cxx.o: $1/$3/$4.cxx $$(INC) $$(INCXX) | $(dir $1/$2/$4)
+ $(call bcmd,cxx,$2/$4.cxx.o,cd "$1" && \
+ $(CXX) -x c++ -c -o $2/$4.cxx.o $3/$4.cxx $(CXXFLAGS))
+ $1/$2/$4.CXX.o: $1/$3/$4.CXX $$(INC) $$(INCXX) | $(dir $1/$2/$4)
+ $(call bcmd,cxx,$2/$4.CXX.o,cd "$1" && \
+ $(CXX) -x c++ -c -o $2/$4.CXX.o $3/$4.CXX $(CXXFLAGS))
+ $1/$2/$4.c++.o: $1/$3/$4.c++ $$(INC) $$(INCXX) | $(dir $1/$2/$4)
+ $(call bcmd,c++,$2/$4.c++.o,cd "$1" && \
+ $(CXX) -x c++ -c -o $2/$4.c++.o $3/$4.c++ $(CXXFLAGS))
# Make a C-like assembly object file.
$1/$2/$4.S.o: $1/$3/$4.S $$(INC) | $(dir $1/$2/$4)
$(call bcmd,asc,$2/$4.S.o,cd "$1" && \
- $(ASC) -c -o $2/$4.S.o $3/$4.S $(ASCFLAGS))
+ $(ASC) -x assembler-with-cpp -c -o $2/$4.S.o $3/$4.S $(ASCFLAGS))
+ $1/$2/$4.sx.o: $1/$3/$4.sx $$(INC) | $(dir $1/$2/$4)
+ $(call bcmd,asc,$2/$4.sx.o,cd "$1" && \
+ $(ASC) -x assembler-with-cpp -c -o $2/$4.sx.o $3/$4.sx $(ASCFLAGS))
# Make an assembly object file.
$1/$2/$4.s.o: $1/$3/$4.s | $(dir $1/$2/$4)
$(call bcmd,as,$2/$4.s.o,cd "$1" && \
- $(AS) -c -o $2/$4.s.o $3/$4.s $(ASFLAGS))
+ $(AS) -x assembler -c -o $2/$4.s.o $3/$4.s $(ASFLAGS))
endef
# Make an archive. Takes the following arguments:
diff --git a/build/hitachi.mk b/build/hitachi.mk
index e4ce212..abc0f18 100644
--- a/build/hitachi.mk
+++ b/build/hitachi.mk
@@ -128,7 +128,7 @@ endef
# e.g.
# ('/home/user/carrot', './obj', './src', 'subdirectory/element')
- SOURCE_EXT = c cpp src
+ SOURCE_EXT = c cpp cc cp src
define make-obj-rules
# Make a C object file.
$1/$2/$4.c.o: $1/$3/$4.c $$(INC) | $(dir $1/$2/$4)
@@ -137,13 +137,19 @@ define make-obj-rules
# Make a C++ object file.
$1/$2/$4.cpp.o: $1/$3/$4.cpp $$(INC) | $(dir $1/$2/$4)
- $(call bcmd,cxx,$2/$4.cpp.o,cd "$1" && \
- $(CXX) -objectfile=$2/$4.cpp.o $3/$4.c $(CXXFLAGS))
+ $(call bcmd,cxx,$2/$4.cpp.o,cd "$1" && $(CXX) \
+ -subcommand=$(call make-cxxflags,$2/$4.cpp.o,$3/$4.cpp))
+ $1/$2/$4.cc.o: $1/$3/$4.cc $$(INC) | $(dir $1/$2/$4)
+ $(call bcmd,cxx,$2/$4.cc.o,cd "$1" && $(CXX) \
+ -subcommand=$(call make-cxxflags,$2/$4.cc.o,$3/$4.cc))
+ $1/$2/$4.cp.o: $1/$3/$4.cp $$(INC) | $(dir $1/$2/$4)
+ $(call bcmd,cxx,$2/$4.cp.o,cd "$1" && $(CXX) \
+ -subcommand=$(call make-cxxflags,$2/$4.cp.o,$3/$4.cp))
# Make an assembly object file.
$1/$2/$4.src.o: $1/$3/$4.src | $(dir $1/$2/$4)
- $(call bcmd,as,$2/$4.src.o,cd "$1" && \
- $(AS) -objectfile $2/$4.src.o $3/$4.src $(ASFLAGS))
+ $(call bcmd,as,$2/$4.src.o,cd "$1" && $(AS) \
+ -subcommand=$(call make-asflags,$2/$4.src.o,$3/$4.src))
endef
# Make an archive. Takes the following arguments:
diff --git a/include/asm.h b/include/asm.h
index 2cc7f9a..4ef24a4 100644
--- a/include/asm.h
+++ b/include/asm.h
@@ -26,13 +26,10 @@
# define _ASM_H_ 1
/* Make the syscall entry */
-/*# define ENTRY(_NAME) \
- .text; .align 2; \
- .global _NAME; \
- _NAME: */
# define ENTRY(_NAME) \
-.global _NAME; \
+.section .text; .global _NAME; \
.type _NAME, @function; \
+.align 2; \
_NAME:
/* Define a syscall. */
diff --git a/include/builtin.h b/include/builtin.h
index 5c5e6d6..0b3aa9c 100644
--- a/include/builtin.h
+++ b/include/builtin.h
@@ -26,7 +26,7 @@ __BEGIN_DECLS
/* ************************************************************************** */
/* Hitachi/Renesas C/C++ compiler built-ins */
/* ************************************************************************** */
-# ifdef __HITACHI__
+# if __HITACHI_PREREQ(1, 0)
/* follow math.h & mathf.h */
extern float _builtin_fabsf(float __x);
extern double _builtin_fabs(double __x);
@@ -80,8 +80,8 @@ extern int _builtin_macll(int *__x, int *__y, unsigned int __count,
extern int _builtin_trapa_svc(int __code, int __r0, ...);
extern void _builtin_prefetch(void *__x);
-extern void _builtin_set_fpscr(int __x);
-extern int _builtin_get_fpscr(void);
+# endif
+# if __HITACHI_PREREQ(6, 0)
extern float _builtin_fipr(float __a1[], float __b1[]);
extern void _builtin_ftrv(float __a1[], float __b1[]);
@@ -100,9 +100,13 @@ extern void _builtin_st_ext(float __a[][4]);
extern void _builtin_add4(float __a1[], float __b1[], float __c1[]);
extern void _builtin_sub4(float __a1[], float __b1[], float __c1[]);
+extern void _builtin_set_fpscr(int __x);
+extern int _builtin_get_fpscr(void);
+
extern void _builtin_trace(long __x);
-# if __HITACHI_VERSION__ >= 0x0904 /* 09.04, used by modified SDK by Mike */
+# endif
+# if __HITACHI_PREREQ(9, 4)
extern void _builtin_nop(void);
extern unsigned short _builtin_swapb(unsigned short __x);
@@ -187,7 +191,6 @@ extern void _builtin_set_circ_x(__X __circ __fixed __array[], size_t __size);
extern void _builtin_set_circ_y(__Y __circ __fixed __array[], size_t __size);
extern void _builtin_clr_circ(void);
-# endif
# endif
__END_DECLS
diff --git a/include/cdefs.h b/include/cdefs.h
index 4a8886d..a89b0c5 100644
--- a/include/cdefs.h
+++ b/include/cdefs.h
@@ -21,15 +21,12 @@
# define _CDEFS_H 1
# define _COMPILER_H 1
-/* check the compiler is good enough */
-# if !defined(__STDC__)
-# error "You need an ISO C conforming compiler to use the libcarrot headers."
-# endif
-
/* include subheaders */
+# include <cdefs/compiler.h>
# include <cdefs/superh.h>
# include <cdefs/attrs.h>
# include <cdefs/utils.h>
+# include <cdefs/features.h>
#endif /* _SYS_CDEFS_H, _CDEFS_H, _COMPILER_H */
#ifndef _SYS_CDEFS_H
diff --git a/include/cdefs/attrs.h b/include/cdefs/attrs.h
index 1cf49d9..4a8fc2c 100644
--- a/include/cdefs/attrs.h
+++ b/include/cdefs/attrs.h
@@ -20,7 +20,8 @@
* on the output. These are based on GCC's attributes.
* ************************************************************************** */
#if !defined(_CDEFS_ATTRS_H)
-# define _CDEFS_ATTRS_H
+# define _CDEFS_ATTRS_H 1
+# include <cdefs/features.h>
/* ************************************************************************** */
/* __THROW: optimize function calls for C++ */
diff --git a/include/cdefs/compiler.h b/include/cdefs/compiler.h
new file mode 100644
index 0000000..b283cd2
--- /dev/null
+++ b/include/cdefs/compiler.h
@@ -0,0 +1,65 @@
+/* *****************************************************************************
+ * cdefs/compiler.h -- Compiler-specific macros.
+ * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
+ *
+ * This file is part of libcarrot.
+ * libcarrot is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3.0 of the License,
+ * or (at your option) any later version.
+ *
+ * libcarrot is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>.
+ * ************************************************************************** */
+#if !defined(_CDEFS_COMPILER_H)
+# define _CDEFS_COMPILER_H 1
+
+/* Check if the compiler is ISO C compliant. */
+# if !defined(__STDC__)
+# error "You need an ISO C conforming compiler to use the libcarrot headers."
+# endif
+/* ************************************************************************** */
+/* Renesas/Hitachi C/C++ compiler */
+/* ************************************************************************** */
+/* In case you didn't know, Renesas bought Hitachi in 2003 (?).
+ * That's why they changed the __HITACHI__ compiler defined macro to
+ * __RENESAS__, although they're also defining __HITACHI__ (and the
+ * associated version macro).
+ * This is just in case. */
+
+# if defined(__RENESAS__) && !defined(__HITACHI__)
+# define __HITACHI__ __RENESAS__
+# define __HITACHI_VERSION__ __RENESAS_VERSION__
+# endif
+# if defined(__HITACHI__) && !defined(__RENESAS__)
+# define __RENESAS__ __HITACHI__
+# define __RENESAS_VERSION__ __HITACHI_VERSION__
+# endif
+# if defined(__HITACHI__) && __HITACHI_VERSION__ >= 0xFFFF
+# define __HITACHI_PREREQ(_MAJ, _MIN) \
+ (__HITACHI_VERSION__ >= ((_MAJ) << 24) + ((_MIN) << 16))
+# elif defined(__HITACHI__)
+# define __HITACHI_PREREQ(_MAJ, _MIN) \
+ (__HITACHI_VERSION__ >= ((_MAJ) << 8) + (_MIN))
+# else
+# define __HITACHI_PREREQ(_MAJ, _MIN) 0
+# endif
+/* ************************************************************************** */
+/* Check GCC's version */
+/* ************************************************************************** */
+/* This macro is taken from the GNU C library.
+ * It is an easy check of GCC's version. */
+
+# if defined(__GNUC__) && defined(__GNUC_MINOR__)
+# define __GNUC_PREREQ(_MAJ, _MIN) \
+ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((_MAJ) << 16) + (_MIN))
+# else
+# define __GNUC_PREREQ(_MAJ, _MIN) 0
+# endif
+
+#endif /* _CDEFS_COMPILER_H */
diff --git a/include/cdefs/features.h b/include/cdefs/features.h
new file mode 100644
index 0000000..08c940a
--- /dev/null
+++ b/include/cdefs/features.h
@@ -0,0 +1,32 @@
+/* *****************************************************************************
+ * cdefs/features.h -- Set of features we should provide.
+ * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
+ *
+ * This file is part of libcarrot.
+ * libcarrot is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3.0 of the License,
+ * or (at your option) any later version.
+ *
+ * libcarrot is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the libcarrot; if not, see <http://www.gnu.org/licenses/>.
+ * ************************************************************************** */
+#if !defined(_CDEFS_FEATURES_H)
+# define _CDEFS_FEATURES_H 1
+
+/* ************************************************************************** */
+/* C99 features */
+/* ************************************************************************** */
+/* This macro is for features we should only provide if the used C
+ * standard includes C99. */
+
+# if __STDC_VERSION__ >= 199901L
+# define __USE_C99
+# endif
+
+#endif /* _CDEFS_FEATURES_H */
diff --git a/include/cdefs/superh.h b/include/cdefs/superh.h
index 5466820..3e0ff16 100644
--- a/include/cdefs/superh.h
+++ b/include/cdefs/superh.h
@@ -24,19 +24,6 @@
# define _CDEFS_SUPERH_H 1
/* ************************************************************************** */
-/* Check the Renesas/Hitachi compiler-specific macros */
-/* ************************************************************************** */
-/* In case you didn't know, Renesas bought Hitachi in 2003 (?).
- * That's why they changed the __HITACHI__ compiler defined macro to
- * __RENESAS__, although they're also defining __HITACHI__ (and the
- * associated version macro).
- * This is just in case. */
-
-# if defined(__RENESAS__) && !defined(__HITACHI__)
-# define __HITACHI__ __RENESAS__
-# define __HITACHI_VERSION__ __RENESAS_VERSION__
-# endif
-/* ************************************************************************** */
/* DSP-C Interface and options */
/* ************************************************************************** */
/* This corresponds to Hitachi's fixed-point extension.
diff --git a/include/cdefs/utils.h b/include/cdefs/utils.h
index 36d1c22..b568dc8 100644
--- a/include/cdefs/utils.h
+++ b/include/cdefs/utils.h
@@ -18,6 +18,7 @@
* ************************************************************************** */
#if !defined(_CDEFS_UTILS_H)
# define _CDEFS_UTILS_H 1
+# include <cdefs/compiler.h>
/* ************************************************************************** */
/* Declaration arguments */
@@ -69,6 +70,18 @@
# define __USING_NAMESPACE_C99
# endif
/* ************************************************************************** */
+/* Optimize conditions */
+/* ************************************************************************** */
+/* Use these macros to optimize a little the produced assembly. */
+
+# if __GNUC_PREREQ(2, 96)
+# define __expect(_EXPR, _VAL) __builtin_expect(_EXPR, _VAL)
+# else
+# define __expect(_EXPR, _VAL)
+# endif
+# define likely(_COND) __expect(!!(_COND), 1)
+# define unlikely(_COND) __expect(!!(_COND), 0)
+/* ************************************************************************** */
/* __concat: Catenate things in macros */
/* ************************************************************************** */
# ifdef __concat
@@ -85,8 +98,8 @@
# ifdef __count_va_args
# undef __count_va_args
# endif
-# if defined(__GNUC__) && \
- (__STDC_VERSION__ >= 199901L && !defined(__STRICT_ANSI__))
+# if defined(__GNUC__) && !defined(__STRICT_ANSI__) && \
+ __STDC_VERSION__ >= 199901L
/* This is something that should work, although I don't really understand the
* trick yet. Source: http://stackoverflow.com/a/2124385/6541022 */
diff --git a/include/malloc.h b/include/malloc.h
index 9b843bd..a7cbd61 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -22,11 +22,14 @@
# include <alloca.h>
__BEGIN_DECLS
__BEGIN_NAMESPACE_STD
+
/* Allocate memory */
extern void *malloc OF((size_t __size))
__THROW __malloc __wur;
extern void *calloc OF((size_t __nmemb, size_t __size))
__THROW __malloc __wur;
+
+/* Re-allocate memory */
extern void *realloc OF((void *__ptr, size_t __size))
__THROW __wur;
diff --git a/include/math.h b/include/math.h
index f9638c2..150672b 100644
--- a/include/math.h
+++ b/include/math.h
@@ -23,96 +23,123 @@
# include <errno.h>
__BEGIN_DECLS
-/* ************************************************************************** */
-/* Useful things */
-/* ************************************************************************** */
-/* typedefs */
-typedef float float_t;
+/* the type */
typedef double double_t;
/* useful constants */
-# define M_E 2.7182818284590452354 /* e */
-# 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 M_El 2.718281828459045235360287471352662498L /* e */
+# define M_LOG2El 1.442695040888963407359924681001892137L /* log_2 e */
+# define M_LOG10El 0.434294481903251827651128918916605082L /* log_10 e */
+# define M_LN2l 0.693147180559945309417232121458176568L /* log_e 2 */
+# define M_LN10l 2.302585092994045684017991454684364208L /* log_e 10 */
+# define M_PIl 3.141592653589793238462643383279502884L /* pi */
+# define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
+# define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
+# define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
+# define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
+# define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
+# define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
+# define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
+
+__BEGIN_NAMESPACE_STD
/* ************************************************************************** */
/* Utilities */
/* ************************************************************************** */
-__BEGIN_NAMESPACE_STD
/* Convert floating-point number to fractional and integral components */
-extern double frexp OF((double __x, int *__exp)) __THROW;
+extern double_t frexp OF((double_t __x, int *__exp)) __THROW;
/* Multiply floating-point number by integral power of 2 */
-extern double ldexp OF((double __x, int __exp)) __THROW;
+extern double_t ldexp OF((double_t __x, int __exp)) __THROW;
/* Extract signed integral and fractional values from floating-point number */
-extern double modf OF((double __x, double *__iptr)) __THROW;
+extern double_t modf OF((double_t __x, double_t *__iptr)) __THROW;
/* Find smallest integral value not less than argument */
-extern double ceil OF((double __x)) __THROW;
+extern double_t ceil OF((double_t __x)) __THROW;
/* Absolute value of floating-point number */
-extern double fabs OF((double __x)) __THROW;
+extern double_t fabs OF((double_t __x)) __THROW;
/* Largest integral value not greater than argument */
-extern double floor OF((double __x)) __THROW;
+extern double_t floor OF((double_t __x)) __THROW;
/* Floating-point remainder function */
-extern double fmod OF((double __x, double __y)) __THROW;
+extern double_t fmod OF((double_t __x, double_t __y)) __THROW;
/* Arc cosine function */
-extern double acos OF((double __x)) __THROW;
+extern double_t acos OF((double_t __x)) __THROW;
/* Arc sine function */
-extern double asin OF((double __x)) __THROW;
+extern double_t asin OF((double_t __x)) __THROW;
/* Arc tangent function */
-extern double atan OF((double __x)) __THROW;
+extern double_t atan OF((double_t __x)) __THROW;
/* Arc tangent function of two variables */
-extern double atan2 OF((double __y, double __x)) __THROW;
+extern double_t atan2 OF((double_t __y, double_t __x)) __THROW;
+
+# ifdef __USE_C99
+__END_NAMESPACE_STD
+__BEGIN_NAMESPACE_C99
+/* Inverse hyperbolic cosine function */
+extern double_t acosh OF((double_t __x)) __THROW;
+
+/* Inverse hyperbolic sine function */
+extern double_t asinh OF((double_t __x)) __THROW;
+
+/* Inverse hyperbolic tangeant function */
+extern double_t atanh OF((double_t __x)) __THROW;
+
+__END_NAMESPACE_C99
+__BEGIN_NAMESPACE_STD
+# endif
/* Cosine function */
-extern double cos OF((double __x)) __THROW;
+extern double_t cos OF((double_t __x)) __THROW;
/* Sine function */
-extern double sin OF((double __x)) __THROW;
+extern double_t sin OF((double_t __x)) __THROW;
/* Tangent function */
-extern double tan OF((double __x)) __THROW;
+extern double_t tan OF((double_t __x)) __THROW;
/* Hyperbolic cosine function */
-extern double cosh OF((double __x)) __THROW;
+extern double_t cosh OF((double_t __x)) __THROW;
/* Hyperbolic tangent function */
-extern double tanh OF((double __x)) __THROW;
+extern double_t tanh OF((double_t __x)) __THROW;
/* Hyperbolic sine function */
-extern double sinh OF((double __x)) __THROW;
+extern double_t sinh OF((double_t __x)) __THROW;
/* Base-e exponential function */
-extern double exp OF((double __x)) __THROW;
+extern double_t exp OF((double_t __x)) __THROW;
/* Natural logarithmic function */
-extern double log OF((double __x)) __THROW;
+extern double_t log OF((double_t __x)) __THROW;
/* Base-10 logarithmic function */
-extern double log10 OF((double __x)) __THROW;
+extern double_t log10 OF((double_t __x)) __THROW;
/* Power function */
-extern double pow OF((double __x, double __y)) __THROW;
+extern double_t pow OF((double_t __x, double_t __y)) __THROW;
/* Square root function */
-extern double sqrt OF((double __x)) __THROW;
+extern double_t sqrt OF((double_t __x)) __THROW;
+
+# ifdef __USE_C99
+__END_NAMESPACE_STD
+__BEGIN_NAMESPACE_C99
+
+/* Euclidean distance function */
+extern double_t hypot OF((double_t __x, double_t __y)) __THROW;
+
+/* Cube root function */
+extern double_t cbrt OF((double_t __x)) __THROW;
+
+__END_NAMESPACE_C99
+__BEGIN_NAMESPACE_STD
+# endif
__END_NAMESPACE_STD
__END_DECLS
diff --git a/include/mathf.h b/include/mathf.h
index 4db9266..7a391d6 100644
--- a/include/mathf.h
+++ b/include/mathf.h
@@ -22,73 +22,113 @@
# include <cdefs.h>
# include <errno.h>
__BEGIN_DECLS
-__BEGIN_NAMESPACE_C99
+/* the type */
+typedef float float_t;
+
+/* useful constants */
+# define M_E 2.7182818284590452354 /* e */
+# 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) */
+
+__BEGIN_NAMESPACE_C99
+/* ************************************************************************** */
+/* Utilities */
+/* ************************************************************************** */
/* Convert floating-point number to fractional and integral components */
-extern float frexpf OF((float __x, int *__exp)) __THROW;
+extern float_t frexpf OF((float_t __x, int *__exp)) __THROW;
/* Multiply floating-point number by integral power of 2 */
-extern float ldexpf OF((float __x, int *__exp)) __THROW;
+extern float_t ldexpf OF((float_t __x, int *__exp)) __THROW;
/* Extract signed integral and fractional values from floating-point number */
-extern float modff OF((float __x, float *__iptr)) __THROW;
+extern float_t modff OF((float_t __x, float_t *__iptr)) __THROW;
/* Find smallest integral value not less than argument */
-extern float ceilf OF((float __x)) __THROW;
+extern float_t ceilf OF((float_t __x)) __THROW;
/* Absolute value of floating-point number */
-extern float fabsf OF((float __x)) __THROW;
+extern float_t fabsf OF((float_t __x)) __THROW;
/* Find largest integral value not greater than argument */
-extern float floorf OF((float __x)) __THROW;
+extern float_t floorf OF((float_t __x)) __THROW;
/* Find floating-point remainder */
-extern float fmodf OF((float __x, float __y)) __THROW;
+extern float_t fmodf OF((float_t __x, float_t __y)) __THROW;
/* Arc cosine function */
-extern float acosf OF((float __x)) __THROW;
+extern float_t acosf OF((float_t __x)) __THROW;
/* Arc sine function */
-extern float asinf OF((float __x)) __THROW;
+extern float_t asinf OF((float_t __x)) __THROW;
/* Arc tangent function */
-extern float atanf OF((float __x)) __THROW;
+extern float_t atanf OF((float_t __x)) __THROW;
/* Arc tangent function of two variables */
-extern float atan2f OF((float __y, float __x)) __THROW;
+extern float_t atan2f OF((float_t __y, float_t __x)) __THROW;
+
+# ifdef __USE_C99
+/* Inverse hyperbolic cosine function */
+extern float_t acoshf OF((float_t __x)) __THROW;
+
+/* Inverse hyperbolic sine function */
+extern float_t asinhf OF((float_t __x)) __THROW;
+
+/* Inverse hyperbolic tangeant function */
+extern float_t atanhf OF((float_t __x)) __THROW;
+# endif
/* Cosine function */
-extern float cosf OF((float __x)) __THROW;
+extern float_t cosf OF((float_t __x)) __THROW;
/* Sine function */
-extern float sinf OF((float __x)) __THROW;
+extern float_t sinf OF((float_t __x)) __THROW;
/* Tangent function */
-extern float tanf OF((float __x)) __THROW;
+extern float_t tanf OF((float_t __x)) __THROW;
/* Hyperbolic cosine function */
-extern float coshf OF((float __x)) __THROW;
+extern float_t coshf OF((float_t __x)) __THROW;
/* Hyperbolic tangent function */
-extern float tanhf OF((float __x)) __THROW;
+extern float_t tanhf OF((float_t __x)) __THROW;
/* Hyperbolic sine function */
-extern float sinhf OF((float __x)) __THROW;
+extern float_t sinhf OF((float_t __x)) __THROW;
/* Base-e exponential function */
-extern float expf OF((float __x)) __THROW;
+extern float_t expf OF((float_t __x)) __THROW;
/* Natural logarithmic function */
-extern float logf OF((float __x)) __THROW;
+extern float_t logf OF((float_t __x)) __THROW;
/* Base-10 exponential function */
-extern float log10f OF((float __x)) __THROW;
+extern float_t log10f OF((float_t __x)) __THROW;
/* Power function */
-extern float powf OF((float __x)) __THROW;
+extern float_t powf OF((float_t __x, float_t __y)) __THROW;
/* Square root function */
-extern float sqrtf OF((float __x)) __THROW;
+extern float_t sqrtf OF((float_t __x)) __THROW;
+
+# ifdef __USE_C99
+/* Euclidean distance function */
+extern float_t hypotf OF((float_t __x, float_t __y)) __THROW;
+
+/* Cube root function */
+extern float_t cbrtf OF((float_t __x)) __THROW;
+# endif
__END_NAMESPACE_C99
__END_DECLS
diff --git a/include/smachine.h b/include/smachine.h
index aa78bf9..aa6ca93 100644
--- a/include/smachine.h
+++ b/include/smachine.h
@@ -36,7 +36,7 @@ __BEGIN_DECLS
/* The status register is basically the main control register of the SuperH
* architecture. */
-# if defined(__HITACHI__)
+# if __HITACHI_PREREQ(1, 0)
# define set_cr(_CR) _builtin_set_cr(_CR)
# define get_cr() _builtin_get_cr()
@@ -55,7 +55,7 @@ static __inline void __set_sr(uint32_t __sr) {
/* An interrupt whose priority is equal to or less than the IMASK is masked.
* Here are the macros to set and get this value: */
-# if defined(__HITACHI__)
+# if __HITACHI_PREREQ(1, 0)
# define set_imask(_IMASK) _builtin_set_imask(_IMASK)
# define get_imask() _builtin_get_imask()
@@ -71,7 +71,7 @@ static __inline void __set_sr(uint32_t __sr) {
/* The vector base is the address from which is calculated the addresses of the
* interrupt, exception and MMU exception handlers. */
-# if defined(__HITACHI__)
+# if __HITACHI_PREREQ(1, 0)
# define set_vbr(_VBR) _builtin_set_vbr(_VBR)
# define get_vbr() _builtin_get_vbr()
@@ -89,7 +89,7 @@ static __inline void __set_vbr(uint32_t __vbr) {
/* ************************************************************************** */
/* Sleep: wait for an interruption. */
-# if defined(__HITACHI__)
+# if __HITACHI_PREREQ(1, 0)
# define sleep() _builtin_sleep()
# elif defined(__GNUC__)
# define sleep() __asm__("sleep")
@@ -99,7 +99,7 @@ static __inline void __set_vbr(uint32_t __vbr) {
# if !defined(_SH3) && !defined(_SH3DSP) && !defined(_SH4) && !defined(_SH4A) \
&& !defined(_SH4ALDSP)
-# elif defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0904
+# elif __HITACHI_PREREQ(9, 4)
# define ldtlb() _builtin_ldtlb()
# elif defined(__GNUC__)
# define ldtlb() __asm__("ldtlb")
@@ -111,7 +111,7 @@ static __inline void __set_vbr(uint32_t __vbr) {
# if (!defined(_SH2DSP) && !defined(_SH3DSP) && !defined(_SH4ALDSP)) \
|| !defined(_DSPC)
-# elif defined(__HITACHI__)
+# elif __HITACHI_PREREQ(1, 0)
# define set_circ_x(_ARRAY, _SIZE) _builtin_set_circ_x(_ARRAY, _SIZE)
# define set_circ_y(_ARRAY, _SIZE) _builtin_set_circ_y(_ARRAY, _SIZE)
# define clr_circ() _builtin_clr_circ()
@@ -132,7 +132,7 @@ static __asm_inline void __clr_circ(void) {
* register' to be in the delayed branch of the 'jump to subroutine', which
* may not be enforced by default by Hitachi's compiler...? */
-# if defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0904
+# if __HITACHI_PREREQ(9, 4)
# define sr_jsr(_FUNC, _IMASK) _builtin_sr_jsr(_FUNC, _IMASK)
# elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
# define sr_jsr(_FUNC, _IMASK) asm("jsr %1\r\n" "stc.l %0" \
diff --git a/include/stdlib.h b/include/stdlib.h
index c40f8f1..581f352 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -63,7 +63,7 @@ typedef struct _LDIV_T_TAG ldiv_t;
ldiv_t ldiv OF((long __numerator, long __denominator))
__THROW __wur;
-# if __STDC_VERSION__ >= 199901L
+# ifdef __USE_C99
/* Long long division */
struct _LLDIV_T_TAG {
long long quot; /* quotient */
diff --git a/include/umachine.h b/include/umachine.h
index d246200..b8e956e 100644
--- a/include/umachine.h
+++ b/include/umachine.h
@@ -35,7 +35,7 @@ __BEGIN_DECLS
/* ************************************************************************** */
/* The global base register is a register. TODO */
-# if defined(__HITACHI__)
+# if __HITACHI_PREREQ(1, 0)
# define set_gbr(_BASE) _builtin_set_gbr(_BASE)
# define get_gbr() _builtin_get_gbr()
@@ -53,7 +53,7 @@ static __asm_inline void __set_gbr(uint32_t __gbr) {
/* ************************************************************************** */
/* Here are inline functions to read using the GBR. */
-# if defined(__HITACHI__)
+# if __HITACHI_PREREQ(1, 0)
# define gbr_read_byte(_OFF) _builtin_gbr_read_byte(_OFF)
# define gbr_read_word(_OFF) _builtin_gbr_read_word(_OFF)
# define gbr_read_long(_OFF) _builtin_gbr_read_long(_OFF)
@@ -101,7 +101,7 @@ static __asm_inline void __set_gbr(uint32_t __gbr) {
/* This instruction purges the cache block corresponding to a memory area.
* Here is the macro: */
-# if defined(__HITACHI__)
+# if __HITACHI_PREREQ(1, 0)
# define tas(_ADDR) _builtin_tas(_ADDR)
# elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
# define tas(_ADDR) asm("tas.b @%0"::"r"(_ADDR))
@@ -112,7 +112,7 @@ static __asm_inline void __set_gbr(uint32_t __gbr) {
/* This instruction goes to the exception handler with privileged mode.
* It can be useful for syscalls: */
-# if defined(__HITACHI__)
+# if __HITACHI_PREREQ(1, 0)
# define trapa(_NO) _builtin_trapa(_NO)
# elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
# define trapa(_NO) asm("trapa #%0"::"r"(_NO))
@@ -123,7 +123,7 @@ static __asm_inline void __set_gbr(uint32_t __gbr) {
/* This instruction performs signed multiplication of two operands. */
# if defined(_SH1)
-# elif defined(__HITACHI__)
+# elif __HITACHI_PREREQ(1, 0)
# define macw(_PTR1, _PTR2, _COUNT) \
_builtin_macw(_PTR1, _PTR2, _COUNT)
# define macwl(_PTR1, _PTR2, _COUNT, _MASK) \
@@ -188,7 +188,7 @@ static __asm_inline void __set_gbr(uint32_t __gbr) {
/* Notice that CASIOWIN (CASIO's system) doesn't use this interface, so this
* will not work with it. */
-# if defined(__HITACHI__)
+# if __HITACHI_PREREQ(1, 0)
# define trapa_svc _builtin_trapa_svc
# elif defined(__GNUC__) && defined(__STRICT_ANSI__) \
@@ -271,7 +271,7 @@ static __asm_inline void __set_gbr(uint32_t __gbr) {
# if !defined(_SH2A) && !defined(_SH2AFPU) && !defined(_SH3) \
&& !defined(_SH3DSP) && !defined(_SH4) && !defined(_SH4A) \
&& !defined(_SH4ALDSP)
-# elif defined(__HITACHI__)
+# elif __HITACHI_PREREQ(1, 0)
# define prefetch(_X) _builtin_prefetch(_X)
# elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
@@ -287,7 +287,7 @@ static __asm_inline void __prefetch(void *addr) {
# if !defined(_SH2E) && !defined(_SH2AFPU) && !defined(_SH4) \
&& !defined(_SH4A)
-# elif defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0600
+# elif __HITACHI_PREREQ(6, 0)
# define set_fpscr(_CR) _builtin_set_fpscr(_CR)
# define get_fpscr() _builtin_get_fpscr()
@@ -309,7 +309,7 @@ static __asm_inline uint32_t __get_fpscr(void) {
* MTRX is matrix. */
# if !defined(_SH2AFPU) && !defined(_SH4) && !defined(_SH4A)
-# elif defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0600
+# elif __HITACHI_PREREQ(6, 0)
# define add4(_VEC1, _VEC2, _VEC3) _builtin_add4(_VEC1, _VEC2, _VEC3)
# define sub4(_VEC1, _VEC2, _VEC3) _builtin_sub4(_VEC1, _VEC2, _VEC3)
@@ -511,7 +511,7 @@ static __asm_inline void __mtrx4mulsub(float __mat1[4][4], float __mat2[4][4],
* Why not after all? */
# if defined(_SH1)
-# elif defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0600
+# elif __HITACHI_PREREQ(6, 0)
# define trace(_VAR) _builtin_trace(_VAR)
# elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
# define trace(_VAR) asm("trace %0"::"r"(_VAR))
@@ -522,7 +522,7 @@ static __asm_inline void __mtrx4mulsub(float __mat1[4][4], float __mat2[4][4],
/* 'nop' stands for 'no operation'.
* Here is the macro: */
-# if defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0904
+# if __HITACHI_PREREQ(9, 4)
# define nop() _builtin_nop()
# elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
# define nop() __asm__("nop")
@@ -533,7 +533,7 @@ static __asm_inline void __mtrx4mulsub(float __mat1[4][4], float __mat2[4][4],
/* Swap bytes within words, and words within long words.
* Here are the inline functions: */
-# if defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0904
+# if __HITACHI_PREREQ(9, 4)
# define swapb(_WORD) _builtin_swapb(_WORD)
# define swapw(_LONG) _builtin_swapw(_LONG)
@@ -551,8 +551,10 @@ static __asm_inline uint32_t __swapw(uint32_t __data) {
/* Here are some other macros that seem to use the last ones...? */
-# define end_cnvw(_RM) swapb(_RM)
-# define end_cnvl(_DATA) swapw(_DATA) /* _builtin_end_cnvl(data)? */
+# if defined(swapb) && defined(swapw)
+# define end_cnvw(_RM) swapb(_RM)
+# define end_cnvl(_DATA) swapw(_DATA) /* _builtin_end_cnvl(data)? */
+# endif
/* ************************************************************************** */
/* Double-length Multiply as Signed */
/* ************************************************************************** */
@@ -561,7 +563,7 @@ static __asm_inline uint32_t __swapw(uint32_t __data) {
* Here are the inline functions: */
# if defined(_SH1)
-# elif defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0904
+# elif __HITACHI_PREREQ(9, 4)
# define dmulu_h(_DATA1, _DATA2) _builtin_dmulu_h(_DATA1, _DATA2)
# define dmulu_l(_DATA1, _DATA2) _builtin_dmulu_l(_DATA1, _DATA2)
# define dmuls_h(_DATA1, _DATA2) _builtin_dmuls_h(_DATA1, _DATA2)
@@ -597,7 +599,7 @@ static __asm_inline int32_t __dmuls_l(int32_t __data1, int32_t __data2) {
* Here are the macros: */
# if !defined(_SH4A)
-# elif defined(__HITACHI__)
+# elif __HITACHI_PREREQ(1, 0)
# define fsca(_ANGLE, _SINV, _COSV) _builtin_fsca(_ANGLE, _SINV, _COSV)
# define fsrra(_DATA) _builtin_fsrra(_DATA)
@@ -626,7 +628,7 @@ static __asm_inline float __fsrra(float __data) {
# if (!defined(_SH2DSP) && !defined(_SH3DSP) && !defined(_SH4ALDSP)) \
|| !defined(_DSPC)
-# elif defined(__HITACHI__)
+# elif __HITACHI_PREREQ(1, 0)
# define pabs_lf(_DATA) _builtin_pabs_lf(_DATA)
# define pabs_la(_DATA) _builtin_pabs_la(_DATA)
# define pdmsb_lf(_DATA) _builtin_pdmsb_lf(_DATA)
@@ -756,7 +758,7 @@ static __asm_inline void __set_dsr(uint32_t __dsr) {
* Here are the macros: */
# if !defined(_SH4A) && !defined(_SH4ALDSP)
-# elif defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0904
+# elif __HITACHI_PREREQ(9, 4)
# define icbi(_PTR) _builtin_icbi(_PTR)
# define ocbi(_PTR) _builtin_ocbi(_PTR)
# define ocbp(_PTR) _builtin_ocbp(_PTR)
@@ -779,7 +781,7 @@ static __asm_inline void __set_dsr(uint32_t __dsr) {
/* ************************************************************************** */
/* `movt` gets the T bit, `clrt` sets it to zero, and `sett` sets it to one. */
-# if defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0904
+# if __HITACHI_PREREQ(9, 4)
# define movt() _builtin_movt()
# define clrt() _builtin_clrt()
# define sett() _builtin_sett()
@@ -798,7 +800,7 @@ static __asm_inline int __movt(void) {
/* ************************************************************************** */
/* TODO: explain, because I'm too lazy to do it */
-# if defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0904
+# if __HITACHI_PREREQ(9, 4)
# define xtrct(_DATA1, _DATA2) _builtin_xtrct(_DATA1, _DATA2)
# define addc(_DATA1, _DATA2) _builtin_addc(_DATA1, _DATA2)
# define addv(_DATA1, _DATA2) _builtin_addv(_DATA1, _DATA2)
@@ -866,7 +868,7 @@ static __asm_inline int __unf_subv(int32_t __data1, int32_t __data2) {
/* ************************************************************************** */
/* TODO: check the usage of this */
-# if defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0904
+# if __HITACHI_PREREQ(9, 4)
# define div1(_DATA1, _DATA2) _builtin_div1(_DATA1, _DATA2)
# define div0s(_DATA1, _DATA2) _builtin_div0s(_DATA1, _DATA2)
# define div0u() _builtin_div0u()
@@ -890,7 +892,7 @@ static __asm_inline int32_t __div0s(int32_t __data1, int32_t __data2) {
/* ************************************************************************** */
/* TODO: check the usage of this */
-# if defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0904
+# if __HITACHI_PREREQ(9, 4)
# define rotl(_DATA) _builtin_rotl(_DATA)
# define rotr(_DATA) _builtin_rotr(_DATA)
# define rotcl(_DATA) _builtin_rotcl(_DATA)
@@ -920,7 +922,7 @@ static __asm_inline uint32_t __rotcr(uint32_t __data) {
/* ************************************************************************** */
/* TODO: check the usage of this */
-# if defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0904
+# if __HITACHI_PREREQ(9, 4)
# define shll(_DATA) _builtin_shll(_DATA)
# define shlr(_DATA) _builtin_shlr(_DATA)
# define shar(_DATA) _builtin_shar(_DATA)
@@ -948,7 +950,7 @@ static __asm_inline uint32_t __shar(uint32_t __data) {
* is above it. */
# if !defined(_SH2A) && !defined(_SH2AFPU)
-# elif defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0904
+# elif __HITACHI_PREREQ(9, 4)
# define clipsb(_DATA) _builtin_clipsb(_DATA)
# define clipsw(_DATA) _builtin_clipsw(_DATA)
# define clipub(_DATA) _builtin_clipub(_DATA)
@@ -979,7 +981,7 @@ static __asm_inline int32_t __clipuw(int32_t __data) {
/* TODO: what's TBR? */
# if !defined(_SH2A) && !defined(_SH2AFPU)
-# elif defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0904
+# elif __HITACHI_PREREQ(9, 4)
# define set_tbr(_DATA) _builtin_set_tbr(_DATA)
# define get_tbr() _builtin_get_tbr()
@@ -992,7 +994,7 @@ static __asm_inline int32_t __clipuw(int32_t __data) {
/* ************************************************************************** */
/* TODO: what is this? */
-# if defined(__HITACHI__) && __HITACHI_VERSION__ >= 0x0904
+# if __HITACHI_PREREQ(9, 4)
# define bset(_DATA, _OFF) _builtin_bset(_DATA, _OFF)
# define bclr(_DATA, _OFF) _builtin_bclr(_DATA, _OFF)
diff --git a/src/stdlib/div.c b/src/stdlib/div.c
index 015ea36..a772ca6 100644
--- a/src/stdlib/div.c
+++ b/src/stdlib/div.c
@@ -54,7 +54,7 @@ ldiv_t ldiv(long num, long den)
return (dv);
}
-#if __STDC_VERSION__ >= 199901L
+#if __USE_C99
/**
* lldiv:
* Divide and get remainder, long long version.