• R/O
  • SSH

libctools: Commit

This library contains code that extends and simplifies different operations
for C language based programs.


Commit MetaInfo

Revisiónf9db305d50cc612d0d567bd824a0f0bf57192665 (tree)
Tiempo2022-10-07 10:42:15
AutorSergey Gusarov <laborer2008@gmai...>
CommiterSergey Gusarov

Log Message

Added config option CT_NO_64. Enabled for sdcc port

Cambiar Resumen

Diferencia incremental

diff -r 8540277b0a49 -r f9db305d50cc .hgsubstate
--- a/.hgsubstate Wed Oct 05 07:17:44 2022 +0300
+++ b/.hgsubstate Fri Oct 07 04:42:15 2022 +0300
@@ -1,4 +1,4 @@
1-e17570dd4d5b2716ad6fe1f3b65c4052d5adfd82 cmake/cmake_tools
1+a799a417ac6770fd96892416bc7148144ea600f6 cmake/cmake_tools
22 5013d507802becd2c434d4dbdafad45c3da5ef23 include/ctools/std/msinttypes
33 0556a9e3eb8cef3262acbd7be988447b41b14215 pyrepo
44 0b899aec14d3a9abb2bf260ac355f0f28630a6a3 tests/unity
diff -r 8540277b0a49 -r f9db305d50cc CMakeLists.txt
--- a/CMakeLists.txt Wed Oct 05 07:17:44 2022 +0300
+++ b/CMakeLists.txt Fri Oct 07 04:42:15 2022 +0300
@@ -57,6 +57,10 @@
5757 if (CT_RETARGET_PUTCHAR)
5858 add_definitions(-DCT_RETARGET_PUTCHAR=1)
5959 endif()
60+
61+ if (CT_NO_64)
62+ add_definitions(-DCT_NO_64=1)
63+ endif()
6064 else()
6165 # Definitions from above-mentioned files should provide top level script
6266 endif()
diff -r 8540277b0a49 -r f9db305d50cc README.rst
--- a/README.rst Wed Oct 05 07:17:44 2022 +0300
+++ b/README.rst Fri Oct 07 04:42:15 2022 +0300
@@ -129,7 +129,8 @@
129129 * CT_NO_DYNAMIC_MEMORY - library will lack of dynamic memory support
130130 and some other inherent things;
131131 * CT_RETARGET_PUTCHAR - provide to the linker code of standard putchar() function. It fixes linking errors
132- for standalone builds. Any project-user have to implement this function if necessary.
132+ for standalone builds. Any project-user have to implement this function if necessary;
133+* CT_NO_64 - disable 64 bit data type support
133134
134135 Library initialization
135136 ----------------------
diff -r 8540277b0a49 -r f9db305d50cc README_RU.rst
--- a/README_RU.rst Wed Oct 05 07:17:44 2022 +0300
+++ b/README_RU.rst Fri Oct 07 04:42:15 2022 +0300
@@ -122,7 +122,8 @@
122122 динамической памяти и некоторых возможностей неотрывно зависящих от неё;
123123 * CT_RETARGET_PUTCHAR - включить код стандартной функции putchar(), чтобы исправить ошибки линковки
124124 библиотеки при автономной сборке. Там где это необходимо, проекты-пользователи должны предоставлять
125- линковщику свои реализации этой функции.
125+ линковщику свои реализации этой функции;
126+* CT_NO_64 - выключить поддержку 64 битных типов данных.
126127
127128 Инициализация библиотеки
128129 ------------------------
diff -r 8540277b0a49 -r f9db305d50cc include/ctools/binary_const.h
--- a/include/ctools/binary_const.h Wed Oct 05 07:17:44 2022 +0300
+++ b/include/ctools/binary_const.h Fri Oct 07 04:42:15 2022 +0300
@@ -51,14 +51,16 @@
5151 #define CT_B32(b3, b2, b1, b0) (((uint32_t)CT_B8(b3) << 24) | ((uint32_t)CT_B8(b2) << 16) |\
5252 ((uint32_t)CT_B8(b1) << 8) | CT_B8(b0))
5353
54+#ifndef CT_NO_64
5455 /*
5556 * For up to 64-bit binary constants, MSB first
5657 */
57-#define CT_B64(b7, b6, b5, b4, b3, b2, b1, b0)\
58- ( ((uint64_t)CT_B8(b7) << 56) | ((uint64_t)CT_B8(b6) << 48)\
59- | ((uint64_t)CT_B8(b5) << 40) | ((uint64_t)CT_B8(b4) << 32)\
60- | ((uint64_t)CT_B8(b3) << 24) | ((uint64_t)CT_B8(b2) << 16)\
61- | ((uint64_t)CT_B8(b1) << 8) | CT_B8(b0))
58+# define CT_B64(b7, b6, b5, b4, b3, b2, b1, b0)\
59+ ( ((uint64_t)CT_B8(b7) << 56) | ((uint64_t)CT_B8(b6) << 48)\
60+ | ((uint64_t)CT_B8(b5) << 40) | ((uint64_t)CT_B8(b4) << 32)\
61+ | ((uint64_t)CT_B8(b3) << 24) | ((uint64_t)CT_B8(b2) << 16)\
62+ | ((uint64_t)CT_B8(b1) << 8) | CT_B8(b0))
63+#endif
6264
6365 #ifdef CT_HEX__
6466 # error CT_HEX__ must be undefined
diff -r 8540277b0a49 -r f9db305d50cc include/ctools/simple_round.h
--- a/include/ctools/simple_round.h Wed Oct 05 07:17:44 2022 +0300
+++ b/include/ctools/simple_round.h Fri Oct 07 04:42:15 2022 +0300
@@ -149,8 +149,10 @@
149149 #define CT_SIMPLE_ROUNDF32(x) CT_SIMPLE_ROUND__(float, int32_t, x)
150150 #define CT_SIMPLE_UROUNDF32(x) CT_SIMPLE_ROUND__(float, uint32_t, x)
151151
152-#define CT_SIMPLE_ROUNDF64(x) CT_SIMPLE_ROUND__(float, int64_t, x)
153-#define CT_SIMPLE_UROUNDF64(x) CT_SIMPLE_ROUND__(float, uint64_t, x)
152+#ifndef CT_NO_64
153+# define CT_SIMPLE_ROUNDF64(x) CT_SIMPLE_ROUND__(float, int64_t, x)
154+# define CT_SIMPLE_UROUNDF64(x) CT_SIMPLE_ROUND__(float, uint64_t, x)
155+#endif
154156
155157 #if defined (CT_COMPL_SDCC)
156158 # define CT_SIMPLE_ROUND8(x) CT_SIMPLE_ROUND__(float, int8_t, x)
@@ -162,8 +164,10 @@
162164 # define CT_SIMPLE_ROUND32(x) CT_SIMPLE_ROUND__(float, int32_t, x)
163165 # define CT_SIMPLE_UROUND32(x) CT_SIMPLE_ROUND__(float, uint32_t, x)
164166
165-# define CT_SIMPLE_ROUND64(x) CT_SIMPLE_ROUND__(float, int64_t, x)
166-# define CT_SIMPLE_UROUND64(x) CT_SIMPLE_ROUND__(float, uint64_t, x)
167+# ifndef CT_NO_64
168+# define CT_SIMPLE_ROUND64(x) CT_SIMPLE_ROUND__(float, int64_t, x)
169+# define CT_SIMPLE_UROUND64(x) CT_SIMPLE_ROUND__(float, uint64_t, x)
170+# endif
167171 #else
168172 # define CT_SIMPLE_ROUND8(x) CT_SIMPLE_ROUND__(double, int8_t, x)
169173 # define CT_SIMPLE_UROUND8(x) CT_SIMPLE_ROUND__(double, uint8_t, x)
@@ -174,6 +178,8 @@
174178 # define CT_SIMPLE_ROUND32(x) CT_SIMPLE_ROUND__(double, int32_t, x)
175179 # define CT_SIMPLE_UROUND32(x) CT_SIMPLE_ROUND__(double, uint32_t, x)
176180
177-# define CT_SIMPLE_ROUND64(x) CT_SIMPLE_ROUND__(double, int64_t, x)
178-# define CT_SIMPLE_UROUND64(x) CT_SIMPLE_ROUND__(double, uint64_t, x)
181+# ifndef CT_NO_64
182+# define CT_SIMPLE_ROUND64(x) CT_SIMPLE_ROUND__(double, int64_t, x)
183+# define CT_SIMPLE_UROUND64(x) CT_SIMPLE_ROUND__(double, uint64_t, x)
184+# endif
179185 #endif
diff -r 8540277b0a49 -r f9db305d50cc include/ctools/std/math.h
--- a/include/ctools/std/math.h Wed Oct 05 07:17:44 2022 +0300
+++ b/include/ctools/std/math.h Fri Oct 07 04:42:15 2022 +0300
@@ -127,6 +127,7 @@
127127 return CT_SIMPLE_UROUNDF32(x);
128128 }
129129
130+#ifndef CT_NO_64
130131 static CT_FORCEINLINE int64_t roundf64(const float x) CT_NOEXCEPT
131132 {
132133 return CT_SIMPLE_ROUNDF64(x);
@@ -136,6 +137,7 @@
136137 {
137138 return CT_SIMPLE_UROUNDF64(x);
138139 }
140+#endif
139141
140142 #ifdef CT_COMPL_SDCC
141143
@@ -169,6 +171,7 @@
169171 return uroundf32(x);
170172 }
171173
174+# ifndef CT_NO_64
172175 static inline int64_t round64(const float x) CT_NOEXCEPT
173176 {
174177 return roundf64(x);
@@ -178,6 +181,7 @@
178181 {
179182 return uroundf64(x);
180183 }
184+# endif
181185
182186 #else
183187
@@ -211,6 +215,7 @@
211215 return CT_SIMPLE_UROUND32(x);
212216 }
213217
218+# ifndef CT_NO_64
214219 static CT_FORCEINLINE int64_t round64(const double x) CT_NOEXCEPT
215220 {
216221 return CT_SIMPLE_ROUND64(x);
@@ -220,6 +225,7 @@
220225 {
221226 return CT_SIMPLE_UROUND64(x);
222227 }
228+# endif
223229
224230 #endif
225231
diff -r 8540277b0a49 -r f9db305d50cc include/ctools/string.h
--- a/include/ctools/string.h Wed Oct 05 07:17:44 2022 +0300
+++ b/include/ctools/string.h Fri Oct 07 04:42:15 2022 +0300
@@ -59,8 +59,29 @@
5959 #if defined (CT_PACK_STRING_TO_UINT_AVAILABLE)
6060
6161 # define CT_PACK_STRING_TO_UINT_EMPTY_STRING 0
62-# define CT_PACK_STRING_TO_UINT_TOO_LONG_STRING UINT64_MAX
6362
63+# ifdef CT_NO_64
64+# define CT_PACK_STRING_TO_UINT_TOO_LONG_STRING UINT32_MAX
65+
66+/**
67+ * @brief Store up to 4 characters in the one unsigned integer value
68+ * CT_STRLEN(str) == 2U is strange because of gcc warning "signed and unsigned type in conditional expression".
69+ * Assert couldn't be used here - it will bring nested macro.
70+ *
71+ * @result 4 bytes long(Reason is unknown) for C compilers and 1/2/4 bytes long for C++
72+ */
73+# define CT_PACK_STRING_TO_UINT(str)\
74+ (\
75+ CT_STRLEN(str) == 0 ? ((uint8_t)CT_PACK_STRING_TO_UINT_EMPTY_STRING) :\
76+ CT_STRLEN(str) == 1 ? ((uint8_t)str[0]) :\
77+ CT_STRLEN(str) == 2 ? ((uint16_t)(((uint16_t)str[1] << 8) | ((uint16_t)str[0]))) :\
78+ CT_STRLEN(str) == 3 ? (((uint32_t)str[2] << 16) | ((uint32_t)str[1] << 8) | ((uint32_t)str[0])) :\
79+ CT_STRLEN(str) == 4 ? (((uint32_t)str[3] << 24) | ((uint32_t)str[2] << 16) | ((uint32_t)str[1] << 8)\
80+ | ((uint32_t)str[0])) :\
81+ ((uint32_t)CT_PACK_STRING_TO_UINT_TOO_LONG_STRING)\
82+ )
83+# else
84+# define CT_PACK_STRING_TO_UINT_TOO_LONG_STRING UINT64_MAX
6485 /**
6586 * @brief Store up to 8 characters in the one unsigned integer value
6687 * CT_STRLEN(str) == 2U is strange because of gcc warning "signed and unsigned type in conditional expression".
@@ -68,7 +89,7 @@
6889 *
6990 * @result 8 bytes long(Reason is unknown) for C compilers and 1/2/4/8 bytes long for C++
7091 */
71-# define CT_PACK_STRING_TO_UINT(str)\
92+# define CT_PACK_STRING_TO_UINT(str)\
7293 (\
7394 CT_STRLEN(str) == 0 ? ((uint8_t)CT_PACK_STRING_TO_UINT_EMPTY_STRING) :\
7495 CT_STRLEN(str) == 1 ? ((uint8_t)str[0]) :\
@@ -88,5 +109,6 @@
88109 | ((uint64_t)str[1] << 8) | ((uint64_t)str[0])) :\
89110 ((uint64_t)CT_PACK_STRING_TO_UINT_TOO_LONG_STRING)\
90111 )
112+# endif
91113
92114 #endif // CT_PACK_STRING_TO_UINT_AVAILABLE
diff -r 8540277b0a49 -r f9db305d50cc tests/src/std/test_math.c
--- a/tests/src/std/test_math.c Wed Oct 05 07:17:44 2022 +0300
+++ b/tests/src/std/test_math.c Fri Oct 07 04:42:15 2022 +0300
@@ -65,9 +65,11 @@
6565 TEST_ASSERT_EQUAL_INT32(roundf32(1.5f), 2);
6666 TEST_ASSERT_EQUAL_UINT32(uroundf32(1.5f), 2U);
6767
68-#if defined (UNITY_INCLUDE_64) || (UNITY_LONG_WIDTH == 64)
68+#ifndef CT_NO_64
69+# if defined (UNITY_INCLUDE_64) || (UNITY_LONG_WIDTH == 64)
6970 TEST_ASSERT_EQUAL_INT64(roundf64(1.5f), 2);
7071 TEST_ASSERT_EQUAL_UINT64(uroundf64(1.5f), 2U);
72+# endif
7173 #endif
7274
7375
@@ -80,8 +82,10 @@
8082 TEST_ASSERT_EQUAL_INT32(round32(1.5), 2);
8183 TEST_ASSERT_EQUAL_UINT32(uround32(1.5), 2U);
8284
83-#if defined (UNITY_INCLUDE_64) || (UNITY_LONG_WIDTH == 64)
85+#ifndef CT_NO_64
86+# if defined (UNITY_INCLUDE_64) || (UNITY_LONG_WIDTH == 64)
8487 TEST_ASSERT_EQUAL_INT64(round64(1.5), 2);
8588 TEST_ASSERT_EQUAL_UINT64(uround64(1.5), 2U);
89+# endif
8690 #endif
8791 }
diff -r 8540277b0a49 -r f9db305d50cc tests/src/test_binary_const.c
--- a/tests/src/test_binary_const.c Wed Oct 05 07:17:44 2022 +0300
+++ b/tests/src/test_binary_const.c Fri Oct 07 04:42:15 2022 +0300
@@ -28,10 +28,15 @@
2828 const uint8_t k8 = CT_B8(01010101);
2929 const uint16_t k16 = CT_B16(10101010, 01010101);
3030 const uint32_t k32 = CT_B32(10000000, 11111111, 10101010, 01010101);
31+#ifndef CT_NO_64
3132 const uint64_t k64 = CT_B64(10001000, 10000000, 00000000, 10000000, 10000000, 11111111, 10101010, 01010101);
33+#endif
3234
3335 TEST_ASSERT_TRUE(k8 == 85);
3436 TEST_ASSERT_TRUE(k16 == 43605);
3537 TEST_ASSERT_TRUE(k32 == 2164238933);
38+
39+#ifndef CT_NO_64
3640 TEST_ASSERT_TRUE(k64 == 0x8880008080FFAA55);
41+#endif
3742 }
diff -r 8540277b0a49 -r f9db305d50cc tests/src/test_string.c
--- a/tests/src/test_string.c Wed Oct 05 07:17:44 2022 +0300
+++ b/tests/src/test_string.c Fri Oct 07 04:42:15 2022 +0300
@@ -42,8 +42,10 @@
4242 uint32_t a32;
4343 uint32_t b32;
4444
45+#ifndef CT_NO_64
4546 uint64_t a64;
4647 uint64_t b64;
48+#endif
4749
4850 /*
4951 * CT_PACK_STRING_TO_UINT for C returns 8 byte long value.
@@ -70,6 +72,7 @@
7072 b32 = 0x34333231;
7173 TEST_ASSERT_EQUAL_UINT(a32, b32);
7274
75+#ifndef CT_NO_64
7376 a64 = CT_PACK_STRING_TO_UINT("12345");
7477 b64 = 0x3534333231;
7578 TEST_ASSERT_EQUAL_UINT(a64, b64);
@@ -89,6 +92,7 @@
8992 a64 = CT_PACK_STRING_TO_UINT("1234567890");
9093 b64 = CT_PACK_STRING_TO_UINT_TOO_LONG_STRING;
9194 TEST_ASSERT_EQUAL_UINT(a64, b64);
95+#endif
9296 }
9397
9498 #endif // CT_PACK_STRING_TO_UINT_AVAILABLE
Show on old repository browser