From 0269c1bdf17d1e6044b5b0ec7de7561ac4d73cf1 Mon Sep 17 00:00:00 2001 From: Michael Steil Date: Mon, 1 Dec 2014 14:00:28 +0100 Subject: [PATCH] cleanups --- netlist_sim.c | 82 +++++++++++++++++++++++++-------------------------- perfect6502.c | 12 ++++---- 2 files changed, 48 insertions(+), 46 deletions(-) diff --git a/netlist_sim.c b/netlist_sim.c index 5457ef9..5a73b6e 100644 --- a/netlist_sim.c +++ b/netlist_sim.c @@ -31,12 +31,6 @@ #include #include "types.h" -/************************************************************ - * - * Global Data Types - * - ************************************************************/ - /* the smallest types to fit the numbers */ typedef uint16_t transnum_t; typedef uint16_t count_t; @@ -44,11 +38,11 @@ typedef uint16_t count_t; /************************************************************ * - * Bitmap Data Structures and Algorithms + * Main State Data Structure * ************************************************************/ -#if 0 /* on 64 bit CPUs */ +#if 0 /* faster on 64 bit CPUs */ typedef unsigned long long bitmap_t; #define BITMAP_SHIFT 6 #define BITMAP_MASK 63 @@ -60,35 +54,6 @@ typedef unsigned int bitmap_t; #define ONE 1 #endif -#define WORDS_FOR_BITS(a) (a/(sizeof(bitmap_t) * 8)+1) - -static inline void -bitmap_clear(bitmap_t *bitmap, count_t count) -{ - bzero(bitmap, WORDS_FOR_BITS(count)*sizeof(bitmap_t)); -} - -static inline void -set_bitmap(bitmap_t *bitmap, int index, BOOL state) -{ - if (state) - bitmap[index>>BITMAP_SHIFT] |= ONE << (index & BITMAP_MASK); - else - bitmap[index>>BITMAP_SHIFT] &= ~(ONE << (index & BITMAP_MASK)); -} - -static inline BOOL -get_bitmap(bitmap_t *bitmap, int index) -{ - return (bitmap[index>>BITMAP_SHIFT] >> (index & BITMAP_MASK)) & 1; -} - -/************************************************************ - * - * Main State Data Structure - * - ************************************************************/ - /* list of nodes that need to be recalculated */ typedef struct { nodenum_t *list; @@ -144,13 +109,48 @@ typedef struct { } group_contains_value; } state_t; +/************************************************************ + * + * Main Header Include + * + ************************************************************/ + #define INCLUDED_FROM_NETLIST_SIM_C #include "netlist_sim.h" #undef INCLUDED_FROM_NETLIST_SIM_C /************************************************************ * - * Data Structures for Nodes + * Algorithms for Bitmaps + * + ************************************************************/ + +#define WORDS_FOR_BITS(a) (a / (sizeof(bitmap_t) * 8) + 1) + +static inline void +bitmap_clear(bitmap_t *bitmap, count_t count) +{ + bzero(bitmap, WORDS_FOR_BITS(count)*sizeof(bitmap_t)); +} + +static inline void +set_bitmap(bitmap_t *bitmap, int index, BOOL state) +{ + if (state) + bitmap[index>>BITMAP_SHIFT] |= ONE << (index & BITMAP_MASK); + else + bitmap[index>>BITMAP_SHIFT] &= ~(ONE << (index & BITMAP_MASK)); +} + +static inline BOOL +get_bitmap(bitmap_t *bitmap, int index) +{ + return (bitmap[index>>BITMAP_SHIFT] >> (index & BITMAP_MASK)) & 1; +} + +/************************************************************ + * + * Algorithms for Nodes * ************************************************************/ @@ -197,7 +197,7 @@ get_nodes_value(state_t *state, transnum_t t) /************************************************************ * - * Data Structures and Algorithms for Transistors + * Algorithms for Transistors * ************************************************************/ @@ -215,7 +215,7 @@ get_transistors_on(state_t *state, transnum_t t) /************************************************************ * - * Data Structures and Algorithms for Lists + * Algorithms for Lists * ************************************************************/ @@ -257,7 +257,7 @@ listout_add(state_t *state, nodenum_t i) /************************************************************ * - * Data Structures and Algorithms for Groups of Nodes + * Algorithms for Groups of Nodes * ************************************************************/ diff --git a/perfect6502.c b/perfect6502.c index 8e9cbd9..dc7d60f 100644 --- a/perfect6502.c +++ b/perfect6502.c @@ -135,9 +135,9 @@ static inline void handleMemory(void *state) { if (isNodeHigh(state, rw)) - writeDataBus(state, mRead(readAddressBus(state))); + writeDataBus(state, mRead(readAddressBus(state))); else - mWrite(readAddressBus(state), readDataBus(state)); + mWrite(readAddressBus(state), readDataBus(state)); } /************************************************************ @@ -171,9 +171,11 @@ initAndResetChip() nodenum_t nodes = sizeof(netlist_6502_node_is_pullup)/sizeof(*netlist_6502_node_is_pullup); nodenum_t transistors = sizeof(netlist_6502_transdefs)/sizeof(*netlist_6502_transdefs); void *state = setupNodesAndTransistors(netlist_6502_transdefs, - netlist_6502_node_is_pullup, - nodes, - transistors, vss, vcc); + netlist_6502_node_is_pullup, + nodes, + transistors, + vss, + vcc); setNode(state, res, 0); setNode(state, clk0, 1);