17
17
#if PICO_ON_DEVICE
18
18
19
19
#include "hardware/clocks.h"
20
- #include "hardware/structs/vreg_and_chip_reset .h"
20
+ #include "hardware/vreg .h"
21
21
22
22
#endif
23
23
@@ -44,10 +44,38 @@ static inline fixed float_to_fixed(float x) {
44
44
return (fixed ) (x * (float ) (1u << FRAC_BITS ));
45
45
}
46
46
47
+ #if !PICO_ON_DEVICE || (FRAC_BITS != 25 )
47
48
static inline fixed fixed_mult (fixed a , fixed b ) {
48
49
int64_t r = ((int64_t ) a ) * b ;
49
50
return (int32_t ) (r >> FRAC_BITS );
50
51
}
52
+ #else
53
+ // Since we're trying to go fast, do a better multiply of 32x32 preserving the bits we want
54
+ static inline fixed fixed_mult (fixed a , fixed b ) {
55
+ uint32_t tmp1 , tmp2 , tmp3 ;
56
+ __asm__ volatile (
57
+ ".syntax unified\n"
58
+ "asrs %[r_tmp1], %[r_b], #16 \n" // r_tmp1 = BH
59
+ "uxth %[r_tmp2], %[r_a] \n" // r_tmp2 = AL
60
+ "muls %[r_tmp2], %[r_tmp1] \n" // r_tmp2 = BH * AL
61
+ "asrs %[r_tmp3], %[r_a], #16 \n" // r_tmp3 = AH
62
+ "muls %[r_tmp1], %[r_tmp3] \n" // r_tmp1 = BH * AH
63
+ "uxth %[r_b], %[r_b] \n" // r_b = BL
64
+ "uxth %[r_a], %[r_a] \n" // r_a = AL
65
+ "muls %[r_a], %[r_b] \n" // r_a = AL * BL
66
+ "muls %[r_b], %[r_tmp3] \n" // r_b = BL * AH
67
+ "add %[r_b], %[r_tmp2] \n" // r_b = BL * AH + BH * AL
68
+ "lsls %[r_tmp1], #32 - 25 \n" // r_tmp1 = (BH * AH) >> (32 - FRAC_BITS)
69
+ "lsrs %[r_a], #16 \n" // r_a = (AL & BL) H
70
+ "add %[r_a], %[r_b] \n"
71
+ "asrs %[r_a], #25- 16 \n" // r_a = (BL * AH + BH * AL) H | (AL & BL) H >> (32 - FRAC_BITS)
72
+ "add %[r_a], %[r_tmp1] \n"
73
+ : [r_a ] "+l" (a ), [r_b ] "+l" (b ), [r_tmp1 ] "=&l" (tmp1 ), [r_tmp2 ] "=&l" (tmp2 ), [r_tmp3 ] "=&l" (tmp3 )
74
+ :
75
+ );
76
+ return a ;
77
+ }
78
+ #endif
51
79
52
80
#endif
53
81
@@ -247,7 +275,7 @@ int main(void) {
247
275
#endif
248
276
#if PICO_ON_DEVICE
249
277
#ifdef TURBO_BOOST
250
- hw_set_bits ( & mm_vreg_and_chip_reset -> vreg , VREG_AND_CHIP_RESET_VREG_VSEL_BITS );
278
+ vreg_set_voltage ( VREG_VOLTAGE_1_30 );
251
279
sleep_ms (10 );
252
280
set_sys_clock_khz (base_freq * 6 , true);
253
281
#else
0 commit comments