From 07e0df0d6a3e1c18ff666d993bf38ee0a3c72e66 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 9 Dec 2012 16:29:00 -0300 Subject: [PATCH] tornado/fw/sim/alg.c: separate data processing from sample generation --- tornado/fw/sim/alg.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/tornado/fw/sim/alg.c b/tornado/fw/sim/alg.c index dedb519..5a0a700 100755 --- a/tornado/fw/sim/alg.c +++ b/tornado/fw/sim/alg.c @@ -44,28 +44,37 @@ static uint16_t sample(double t) #define E_SHIFT 3 /* ~ 0.1 */ #define M_SHIFT 10 /* ~ 1/S */ -int main(void) + +static void process(unsigned v) { uint16_t e = MID << E_SHIFT; uint32_t m = MID << M_SHIFT; int d; - int i; bool up = 0; + e = v+(e-(e >> E_SHIFT)); + m = v+(m-(m >> M_SHIFT)); + d = (e >> E_SHIFT)-(m >> M_SHIFT); + if (up) { + if (d < -H) + up = 0; + } else { + if (d > H) + up = 1; + } + printf("%d %d %d %d %d\n", + v, e >> E_SHIFT, m >> M_SHIFT, d, up); +} + + +int main(void) +{ + int i; + for (i = 0; i != 10*S; i++) { unsigned v = sample((double) i/S); - e = v+(e-(e >> E_SHIFT)); - m = v+(m-(m >> M_SHIFT)); - d = (e >> E_SHIFT)-(m >> M_SHIFT); - if (up) { - if (d < -H) - up = 0; - } else { - if (d > H) - up = 1; - } - printf("%d %d %d %d %d\n", - v, e >> E_SHIFT, m >> M_SHIFT, d, up); + + process(v); } return 0; }