Benchmark scalar sincos32 (1 angle per call)
| 22 | |
| 23 | // Benchmark scalar sincos32 (1 angle per call) |
| 24 | __attribute__((noinline)) |
| 25 | void benchmark_sincos32_scalar(int calls) { |
| 26 | // Pre-generate test angles (16 different angles to prevent pattern optimization) |
| 27 | u32 test_angles[16]; |
| 28 | for (int i = 0; i < 16; i++) { |
| 29 | test_angles[i] = i * 1048576; // 0, 22.5, 45, ... degrees |
| 30 | } |
| 31 | |
| 32 | i32 local_accumulator = 0; |
| 33 | |
| 34 | for (int i = 0; i < calls; i++) { |
| 35 | // Vary angles using volatile offset |
| 36 | int angle_idx = (i + g_angle_offset) & 15; |
| 37 | |
| 38 | asm volatile("" : : : "memory"); |
| 39 | u32 angle = test_angles[angle_idx]; |
| 40 | |
| 41 | SinCos32 result = sincos32(angle); |
| 42 | |
| 43 | // Accumulate to prevent dead code elimination |
| 44 | local_accumulator ^= result.sin_val; |
| 45 | local_accumulator ^= result.cos_val; |
| 46 | |
| 47 | asm volatile("" : "+r"(local_accumulator) : : "memory"); |
| 48 | } |
| 49 | |
| 50 | g_accumulator = local_accumulator; |
| 51 | } |
| 52 | |
| 53 | // Benchmark SIMD sincos32_simd (4 angles per call) |
| 54 | __attribute__((noinline)) |