Remove some std-vector usage

This commit is contained in:
twinaphex 2016-08-06 16:38:45 +02:00
parent c8bec5472d
commit 608e2bac52
4 changed files with 16 additions and 31 deletions

View File

@ -1,7 +1,6 @@
#ifndef __MDFN_SIMPLEFIFO_H
#define __MDFN_SIMPLEFIFO_H
#include <vector>
#include <assert.h>
#include "../math_ops.h"
@ -12,19 +11,23 @@ class SimpleFIFO
public:
// Constructor
SimpleFIFO(uint32 the_size) // Size should be a power of 2!
SimpleFIFO(uint32 the_size)
{
data.resize(round_up_pow2(the_size));
size = the_size;
read_pos = 0;
write_pos = 0;
in_count = 0;
/* Size should be a power of 2! */
assert(the_size && !(the_size & (the_size - 1)));
data = (T*)malloc(the_size * sizeof(T));
size = the_size;
read_pos = 0;
write_pos = 0;
in_count = 0;
}
// Destructor
INLINE ~SimpleFIFO()
{
if (data)
free(data);
}
INLINE uint32 CanRead(void)
@ -47,7 +50,7 @@ class SimpleFIFO
if(!peek)
{
read_pos = (read_pos + 1) & (data.size() - 1);
read_pos = (read_pos + 1) & (size - 1);
in_count--;
}
@ -69,7 +72,7 @@ class SimpleFIFO
{
data[write_pos] = *happy_data;
write_pos = (write_pos + 1) & (data.size() - 1);
write_pos = (write_pos + 1) & (size - 1);
in_count++;
happy_data++;
happy_count--;
@ -95,8 +98,7 @@ class SimpleFIFO
in_count = 0;
}
//private:
std::vector<T> data;
T* data;
uint32 size;
uint32 read_pos; // Read position
uint32 write_pos; // Write position

View File

@ -1,23 +1,6 @@
#ifndef __MDFN_MATH_OPS_H
#define __MDFN_MATH_OPS_H
// Source: http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
// Rounds up to the nearest power of 2.
static INLINE uint32 round_up_pow2(uint32 v)
{
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;
v += (v == 0);
return(v);
}
// Some compilers' optimizers and some platforms might fubar the generated code from these macros,
// so some tests are run in...tests.cpp
#define sign_8_to_s16(_value) ((int16)(int8)(_value))

View File

@ -953,7 +953,7 @@ int PCECD_StateAction(StateMem *sm, int load, int data_only)
SFVAR(Fader.CountValue),
SFVAR(Fader.Clocked),
SFARRAY(&SubChannelFIFO.data[0], SubChannelFIFO.data.size()),
SFARRAY(&SubChannelFIFO.data[0], SubChannelFIFO.size),
SFVAR(SubChannelFIFO.read_pos),
SFVAR(SubChannelFIFO.write_pos),
SFVAR(SubChannelFIFO.in_count),

View File

@ -1300,7 +1300,7 @@ int PCECD_Drive_StateAction(StateMem * sm, int load, int data_only, const char *
SFVARN(cd.command_size_left, "command_size_left"),
// Don't save the FIFO's write position, it will be reconstructed from read_pos and in_count
SFARRAYN(&din.data[0], din.data.size(), "din_fifo"),
SFARRAYN(&din.data[0], din.size, "din_fifo"),
SFVARN(din.read_pos, "din_read_pos"),
SFVARN(din.in_count, "din_in_count"),
SFVARN(cd.data_transfer_done, "data_transfer_done"),