Skip to content

Commit 9c4a044

Browse files
committed
remove __builtin_choose_expr usage as it is actually unnecessary it seems, and breaks c++
1 parent 44375f3 commit 9c4a044

3 files changed

Lines changed: 33 additions & 9 deletions

File tree

src/rp2040/pico_platform/include/pico/platform.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,7 @@ return a;
183183
* \param b the second operand
184184
* \return a * b
185185
*/
186-
#define __fast_mul(a, b) __builtin_choose_expr(__builtin_constant_p(b) && !__builtin_constant_p(a), \
187-
(__builtin_popcount(b) >= 2 ? __mul_instruction(a,b) : (a)*(b)), \
188-
(a)*(b))
186+
#define __fast_mul(a, b) (__builtin_constant_p(b) && !__builtin_constant_p(a) && __builtin_popcount(b) >= 2 ? __mul_instruction(a,b) : (a)*(b))
189187

190188
#ifdef __cplusplus
191189
}

src/rp2_common/pico_float/include/pico/float.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ uint64_t float2ufix64(float f, int e);
357357
// or call the original function
358358
#if PICO_FLOAT_HAS_FIX32_TO_FLOAT_CONVERSIONS
359359
// a bit of a hack to inline VFP fixed-point conversion when exponent is constant and in range 1-32
360-
#define fix2float(m, e) __builtin_choose_expr(__builtin_constant_p(e), (e) >= 1 && (e) <= 32 ? _fix2float_inline(m, e) : fix2 ## float(m, e), fix2 ## float(m, e))
361-
#define ufix2float(m, e) __builtin_choose_expr(__builtin_constant_p(e), (e) >= 1 && (e) <= 32 ? _ufix2float_inline(m, e) : ufix2 ## float(m, e), ufix2 ## float(m, e))
360+
#define fix2float(m, e) (__builtin_constant_p(e) && (e) >= 1 && (e) <= 32 ? _fix2float_inline(m, e) : fix2 ## float(m, e))
361+
#define ufix2float(m, e) (__builtin_constant_p(e) && (e) >= 1 && (e) <= 32 ? _ufix2float_inline(m, e) : ufix2 ## float(m, e))
362362

363363
#define _fix2float_inline(m, e) ({ \
364364
int32_t _m = m; \
@@ -385,8 +385,8 @@ uint64_t float2ufix64(float f, int e);
385385

386386
#endif
387387
#if PICO_FLOAT_HAS_FLOAT_TO_FIX32_Z_CONVERSIONS
388-
#define float2fix_z(f, e) __builtin_choose_expr(__builtin_constant_p(e), (e) >= 1 && (e) <= 32 ? _float2fix_z_inline(f, e) : float2 ## fix_z(f, e), float2 ## fix_z(f, e))
389-
#define float2ufix_z(f, e) __builtin_choose_expr(__builtin_constant_p(e), (e) >= 1 && (e) <= 32 ? _float2ufix_z_inline(f, e) : float2 ## ufix_z(f, e), float2 ## ufix_z(f, e))
388+
#define float2fix_z(f, e) (__builtin_constant_p(e) && (e) >= 1 && (e) <= 32 ? _float2fix_z_inline(f, e) : float2 ## fix_z(f, e))
389+
#define float2ufix_z(f, e) (__builtin_constant_p(e) && (e) >= 1 && (e) <= 32 ? _float2ufix_z_inline(f, e) : float2 ## ufix_z(f, e))
390390

391391
#define _float2fix_z_inline(f, e) ({ \
392392
int32_t _m; \
@@ -413,8 +413,8 @@ uint64_t float2ufix64(float f, int e);
413413

414414
#endif
415415
#if PICO_FLOAT_HAS_FLOAT_TO_FIX32_M_CONVERSIONS
416-
#define float2fix(f, e) __builtin_choose_expr(__builtin_constant_p(e), (e) >= 1 && (e) <= 32 ? _float2fix_inline(f, e) : float2 ## fix(f, e), float2 ## fix(f, e))
417-
#define float2ufix(f, e) __builtin_choose_expr(__builtin_constant_p(e), (e) >= 1 && (e) <= 32 ? _float2ufix_inline(f, e) : float2 ## ufix(f, e), float2 ## ufix(f, e))
416+
#define float2fix(f, e) (__builtin_constant_p(e) && (e) >= 1 && (e) <= 32 ? _float2fix_inline(f, e) : float2 ## fix(f, e))
417+
#define float2ufix(f, e) (__builtin_constant_p(e) && (e) >= 1 && (e) <= 32 ? _float2ufix_inline(f, e) : float2 ## ufix(f, e))
418418

419419
#define _float2fix_inline(f, e) ({ \
420420
union { float _f; int32_t _i; } _u; \

test/kitchen_sink/kitchen_sink.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ float __attribute__((noinline)) foox(float x, float b) {
6363
return x * b;
6464
}
6565

66+
uint __noinline const_funcs_returning_int(float x, int n) {
67+
return float2fix_z(x, 7) +
68+
float2fix(x, 7) +
69+
float2ufix_z(x, 7) +
70+
float2ufix(x, 7) +
71+
__fast_mul(n, 7);
72+
}
73+
74+
uint __noinline non_const_funcs_returning_int(float x, int n) {
75+
return float2fix_z(x, n) +
76+
float2fix(x, n) +
77+
float2ufix_z(x, n) +
78+
float2ufix(x, n) +
79+
__fast_mul(n, n);
80+
}
81+
82+
float __noinline const_funcs_returning_float(int n) {
83+
return fix2float(n, 7) + ufix2float(n, 7);
84+
}
85+
86+
float __noinline non_const_funcs_returning_float(int n) {
87+
return fix2float(n, n) + ufix2float(n, n);
88+
}
89+
6690
void svc_call(void) {
6791
puts("PASSED");
6892
exit(0);
@@ -93,6 +117,8 @@ int main(void) {
93117
hard_assert(recursive_mutex_try_enter(&recursive_mutex, NULL));
94118
hard_assert(recursive_mutex_try_enter(&recursive_mutex, NULL));
95119
printf("%f\n", foox(1.3f, 2.6f));
120+
printf("%u %u\n", const_funcs_returning_int(3.7f, 7), non_const_funcs_returning_int(3.7f, 7));
121+
printf("%f %f\n", const_funcs_returning_float(7), non_const_funcs_returning_float(7));
96122
#ifdef EXTRA_DATA_SECTION
97123
extern uint32_t __extra_end_variable__;
98124
printf("__extra_end_variable__ = %p\n", (void *)&__extra_end_variable__);

0 commit comments

Comments
 (0)