Browse Source

Revert "Use alloca() instead of VLAs for dynamic stack allocation."

This reverts commit bb34db46c9.
tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
1ea9afcb97
1 changed files with 9 additions and 10 deletions
  1. +9
    -10
      include/dsp/ode.hpp

+ 9
- 10
include/dsp/ode.hpp View File

@@ -1,6 +1,5 @@
#pragma once #pragma once
#include <dsp/common.hpp> #include <dsp/common.hpp>
#include <alloca.h>




namespace rack { namespace rack {
@@ -29,7 +28,7 @@ For example, the following solves the system x''(t) = -x(t) using a fixed timest
/** Solves an ODE system using the 1st order Euler method */ /** Solves an ODE system using the 1st order Euler method */
template <typename T, typename F> template <typename T, typename F>
void stepEuler(T t, T dt, T x[], int len, F f) { void stepEuler(T t, T dt, T x[], int len, F f) {
T *k = (T*) alloca(len);
T k[len];


f(t, x, k); f(t, x, k);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
@@ -40,9 +39,9 @@ void stepEuler(T t, T dt, T x[], int len, F f) {
/** Solves an ODE system using the 2nd order Runge-Kutta method */ /** Solves an ODE system using the 2nd order Runge-Kutta method */
template <typename T, typename F> template <typename T, typename F>
void stepRK2(T t, T dt, T x[], int len, F f) { void stepRK2(T t, T dt, T x[], int len, F f) {
T *k1 = (T*) alloca(len);
T *k2 = (T*) alloca(len);
T *yi = (T*) alloca(len);
T k1[len];
T k2[len];
T yi[len];


f(t, x, k1); f(t, x, k1);


@@ -59,11 +58,11 @@ void stepRK2(T t, T dt, T x[], int len, F f) {
/** Solves an ODE system using the 4th order Runge-Kutta method */ /** Solves an ODE system using the 4th order Runge-Kutta method */
template <typename T, typename F> template <typename T, typename F>
void stepRK4(T t, T dt, T x[], int len, F f) { void stepRK4(T t, T dt, T x[], int len, F f) {
T *k1 = (T*) alloca(len);
T *k2 = (T*) alloca(len);
T *k3 = (T*) alloca(len);
T *k4 = (T*) alloca(len);
T *yi = (T*) alloca(len);
T k1[len];
T k2[len];
T k3[len];
T k4[len];
T yi[len];


f(t, x, k1); f(t, x, k1);




Loading…
Cancel
Save