Start using C89-style for loop initial declarations for

reusable code module parts that we reuse in other projects. It's
a huge maintenance burden having to change this stuff around everytime
when compiling in non-C99 mode
This commit is contained in:
twinaphex 2013-10-19 19:39:38 +02:00
parent c16217d42f
commit 8487cd0204
11 changed files with 126 additions and 79 deletions

View File

@ -137,6 +137,7 @@ static inline double window_function(double index)
// Check Wiki for mathematical definition ...
static inline double besseli0(double x)
{
unsigned i;
double sum = 0.0;
double factorial = 1.0;
@ -147,7 +148,7 @@ static inline double besseli0(double x)
// Approximate. This is an infinite sum.
// Luckily, it converges rather fast.
for (unsigned i = 0; i < 18; i++)
for (i = 0; i < 18; i++)
{
sum += x_pow * two_div_pow / (factorial * factorial);
@ -171,13 +172,14 @@ static inline double window_function(double index)
static void init_sinc_table(rarch_sinc_resampler_t *resamp, double cutoff,
float *phase_table, int phases, int taps, bool calculate_delta)
{
int i, j, p;
double window_mod = window_function(0.0); // Need to normalize w(0) to 1.0.
int stride = calculate_delta ? 2 : 1;
double sidelobes = taps / 2.0;
for (int i = 0; i < phases; i++)
for (i = 0; i < phases; i++)
{
for (int j = 0; j < taps; j++)
for (j = 0; j < taps; j++)
{
int n = j * phases + i;
double window_phase = (double)n / (phases * taps); // [0, 1).
@ -191,9 +193,9 @@ static void init_sinc_table(rarch_sinc_resampler_t *resamp, double cutoff,
if (calculate_delta)
{
for (int p = 0; p < phases - 1; p++)
for (p = 0; p < phases - 1; p++)
{
for (int j = 0; j < taps; j++)
for (j = 0; j < taps; j++)
{
float delta = phase_table[(p + 1) * stride * taps + j] - phase_table[p * stride * taps + j];
phase_table[(p * stride + 1) * taps + j] = delta;
@ -201,7 +203,7 @@ static void init_sinc_table(rarch_sinc_resampler_t *resamp, double cutoff,
}
int phase = phases - 1;
for (int j = 0; j < taps; j++)
for (j = 0; j < taps; j++)
{
int n = j * phases + (phase + 1);
double window_phase = (double)n / (phases * taps); // (0, 1].
@ -237,6 +239,7 @@ static void aligned_free__(void *ptr)
static inline void process_sinc_C(rarch_sinc_resampler_t *resamp, float *out_buffer)
{
unsigned i;
float sum_l = 0.0f;
float sum_r = 0.0f;
const float *buffer_l = resamp->buffer_l + resamp->ptr;
@ -252,7 +255,7 @@ static inline void process_sinc_C(rarch_sinc_resampler_t *resamp, float *out_buf
const float *phase_table = resamp->phase_table + phase * taps;
#endif
for (unsigned i = 0; i < taps; i++)
for (i = 0; i < taps; i++)
{
#if SINC_COEFF_LERP
float sinc_val = phase_table[i] + delta_table[i] * delta;
@ -271,6 +274,7 @@ static inline void process_sinc_C(rarch_sinc_resampler_t *resamp, float *out_buf
#define process_sinc_func process_sinc
static void process_sinc(rarch_sinc_resampler_t *resamp, float *out_buffer)
{
unsigned i;
__m256 sum_l = _mm256_setzero_ps();
__m256 sum_r = _mm256_setzero_ps();
@ -287,7 +291,7 @@ static void process_sinc(rarch_sinc_resampler_t *resamp, float *out_buffer)
const float *phase_table = resamp->phase_table + phase * taps;
#endif
for (unsigned i = 0; i < taps; i += 8)
for (i = 0; i < taps; i += 8)
{
__m256 buf_l = _mm256_loadu_ps(buffer_l + i);
__m256 buf_r = _mm256_loadu_ps(buffer_r + i);
@ -319,6 +323,7 @@ static void process_sinc(rarch_sinc_resampler_t *resamp, float *out_buffer)
#define process_sinc_func process_sinc
static void process_sinc(rarch_sinc_resampler_t *resamp, float *out_buffer)
{
unsigned i;
__m128 sum_l = _mm_setzero_ps();
__m128 sum_r = _mm_setzero_ps();
@ -335,7 +340,7 @@ static void process_sinc(rarch_sinc_resampler_t *resamp, float *out_buffer)
const float *phase_table = resamp->phase_table + phase * taps;
#endif
for (unsigned i = 0; i < taps; i += 4)
for (i = 0; i < taps; i += 4)
{
__m128 buf_l = _mm_loadu_ps(buffer_l + i);
__m128 buf_r = _mm_loadu_ps(buffer_r + i);

View File

@ -28,15 +28,17 @@
void audio_convert_s16_to_float_C(float *out,
const int16_t *in, size_t samples, float gain)
{
size_t i;
gain = gain / 0x8000;
for (size_t i = 0; i < samples; i++)
for (i = 0; i < samples; i++)
out[i] = (float)in[i] * gain;
}
void audio_convert_float_to_s16_C(int16_t *out,
const float *in, size_t samples)
{
for (size_t i = 0; i < samples; i++)
size_t i;
for (i = 0; i < samples; i++)
{
int32_t val = (int32_t)(in[i] * 0x8000);
out[i] = (val > 0x7FFF) ? 0x7FFF : (val < -0x8000 ? -0x8000 : (int16_t)val);

View File

@ -357,6 +357,7 @@ static config_file_t *config_file_new_internal(const char *path, unsigned depth)
config_file_t *config_file_new_from_string(const char *from_string)
{
size_t i;
struct config_file *conf = (struct config_file*)calloc(1, sizeof(*conf));
if (!conf)
return NULL;
@ -371,7 +372,7 @@ config_file_t *config_file_new_from_string(const char *from_string)
if (!lines)
return conf;
for (size_t i = 0; i < lines->size; i++)
for (i = 0; i < lines->size; i++)
{
struct config_entry_list *list = (struct config_entry_list*)calloc(1, sizeof(*list));

19
file.c
View File

@ -233,10 +233,12 @@ bool save_state(const char *path)
bool load_state(const char *path)
{
RARCH_LOG("Loading state: \"%s\".\n", path);
unsigned i;
void *buf = NULL;
ssize_t size = read_file(path, &buf);
RARCH_LOG("Loading state: \"%s\".\n", path);
if (size < 0)
{
RARCH_ERR("Failed to load state from \"%s\".\n", path);
@ -278,16 +280,16 @@ bool load_state(const char *path)
}
}
for (unsigned i = 0; i < 2; i++)
for (i = 0; i < 2; i++)
if (block_type[i] != -1)
block_size[i] = pretro_get_memory_size(block_type[i]);
for (unsigned i = 0; i < 2; i++)
for (i = 0; i < 2; i++)
if (block_size[i])
block_buf[i] = malloc(block_size[i]);
// Backup current SRAM which is overwritten by unserialize.
for (unsigned i = 0; i < 2; i++)
for (i = 0; i < 2; i++)
{
if (block_buf[i])
{
@ -300,7 +302,7 @@ bool load_state(const char *path)
ret = pretro_unserialize(buf, size);
// Flush back :D
for (unsigned i = 0; i < 2 && ret; i++)
for (i = 0; i < 2 && ret; i++)
{
if (block_buf[i])
{
@ -310,7 +312,7 @@ bool load_state(const char *path)
}
}
for (unsigned i = 0; i < 2; i++)
for (i = 0; i < 2; i++)
if (block_buf[i])
free(block_buf[i]);
@ -376,6 +378,7 @@ static char *load_xml_map(const char *path)
static bool load_roms(unsigned rom_type, const char **rom_paths, size_t roms)
{
size_t i;
bool ret = true;
if (roms == 0)
@ -409,7 +412,7 @@ static bool load_roms(unsigned rom_type, const char **rom_paths, size_t roms)
info[0].size = rom_len[0];
info[0].meta = xml_buf;
for (size_t i = 1; i < roms; i++)
for (i = 1; i < roms; i++)
{
if (rom_paths[i] &&
!g_extern.system.info.need_fullpath &&
@ -434,7 +437,7 @@ static bool load_roms(unsigned rom_type, const char **rom_paths, size_t roms)
RARCH_ERR("Failed to load game.\n");
end:
for (unsigned i = 0; i < MAX_ROMS; i++)
for (i = 0; i < MAX_ROMS; i++)
free(rom_buf[i]);
free(xml_buf);

View File

@ -182,9 +182,10 @@ const struct zlib_file_backend *zlib_get_default_file_backend(void)
static uint32_t read_le(const uint8_t *data, unsigned size)
{
unsigned i;
uint32_t val = 0;
size *= 8;
for (unsigned i = 0; i < size; i += 8)
for (i = 0; i < size; i += 8)
val |= *data++ << i;
return val;

View File

@ -19,16 +19,18 @@
void matrix_identity(math_matrix *mat)
{
unsigned i;
memset(mat, 0, sizeof(*mat));
for (unsigned i = 0; i < 4; i++)
for (i = 0; i < 4; i++)
MAT_ELEM(*mat, i, i) = 1.0f;
}
void matrix_transpose(math_matrix *out, const math_matrix *in)
{
unsigned i, j;
math_matrix mat;
for (unsigned i = 0; i < 4; i++)
for (unsigned j = 0; j < 4; j++)
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
MAT_ELEM(mat, j, i) = MAT_ELEM(*in, i, j);
*out = mat;
@ -125,14 +127,15 @@ void matrix_projection(math_matrix *out, float znear,
void matrix_multiply(math_matrix *out,
const math_matrix *a, const math_matrix *b)
{
unsigned r, c, k;
math_matrix mat;
for (unsigned r = 0; r < 4; r++)
for (r = 0; r < 4; r++)
{
for (unsigned c = 0; c < 4; c++)
for (c = 0; c < 4; c++)
{
float dot = 0.0f;
for (unsigned k = 0; k < 4; k++)
for (k = 0; k < 4; k++)
dot += MAT_ELEM(*a, r, k) * MAT_ELEM(*b, k, c);
MAT_ELEM(mat, r, c) = dot;
}

View File

@ -23,8 +23,9 @@
void matrix_3x3_identity(math_matrix_3x3 *mat)
{
unsigned i;
memset(mat, 0, sizeof(*mat));
for (unsigned i = 0; i < 3; i++)
for (i = 0; i < 3; i++)
MAT_ELEM_3X3(*mat, i, i) = 1.0f;
}
@ -46,9 +47,10 @@ void matrix_3x3_inits(math_matrix_3x3 *mat,
void matrix_3x3_transpose(math_matrix_3x3 *out, const math_matrix_3x3 *in)
{
unsigned i, j;
math_matrix_3x3 mat;
for (unsigned i = 0; i < 3; i++)
for (unsigned j = 0; j < 3; j++)
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
MAT_ELEM_3X3(mat, j, i) = MAT_ELEM_3X3(*in, i, j);
*out = mat;
@ -57,13 +59,14 @@ void matrix_3x3_transpose(math_matrix_3x3 *out, const math_matrix_3x3 *in)
void matrix_3x3_multiply(math_matrix_3x3 *out,
const math_matrix_3x3 *a, const math_matrix_3x3 *b)
{
unsigned r, c, k;
math_matrix_3x3 mat;
for (unsigned r = 0; r < 3; r++)
for (r = 0; r < 3; r++)
{
for (unsigned c = 0; c < 3; c++)
for (c = 0; c < 3; c++)
{
float dot = 0.0f;
for (unsigned k = 0; k < 3; k++)
for (k = 0; k < 3; k++)
dot += MAT_ELEM_3X3(*a, r, k) * MAT_ELEM_3X3(*b, k, c);
MAT_ELEM_3X3(mat, r, c) = dot;
}
@ -74,8 +77,9 @@ void matrix_3x3_multiply(math_matrix_3x3 *out,
void matrix_3x3_divide_scalar(math_matrix_3x3 *mat, const float s)
{
for (unsigned i = 0; i < 3; i++)
for (unsigned j = 0; j < 3; j++)
unsigned i, j;
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
MAT_ELEM_3X3(*mat, i, j) /= s;
}

View File

@ -112,7 +112,8 @@ struct idat_buffer
static enum png_chunk_type png_chunk_type(const struct png_chunk *chunk)
{
for (unsigned i = 0; i < ARRAY_SIZE(chunk_map); i++)
unsigned i;
for (i = 0; i < ARRAY_SIZE(chunk_map); i++)
{
if (memcmp(chunk->type, chunk_map[i].id, 4) == 0)
return chunk_map[i].type;
@ -146,6 +147,7 @@ static void png_free_chunk(struct png_chunk *chunk)
static bool png_parse_ihdr(FILE *file, struct png_chunk *chunk, struct png_ihdr *ihdr)
{
unsigned i;
bool ret = true;
if (!png_read_chunk(file, chunk))
return false;
@ -173,7 +175,7 @@ static bool png_parse_ihdr(FILE *file, struct png_chunk *chunk, struct png_ihdr
{
static const unsigned valid_bpp[] = { 1, 2, 4, 8, 16 };
bool correct_bpp = false;
for (unsigned i = 0; i < ARRAY_SIZE(valid_bpp); i++)
for (i = 0; i < ARRAY_SIZE(valid_bpp); i++)
{
if (valid_bpp[i] == ihdr->depth)
{
@ -189,7 +191,7 @@ static bool png_parse_ihdr(FILE *file, struct png_chunk *chunk, struct png_ihdr
{
static const unsigned valid_bpp[] = { 1, 2, 4, 8 };
bool correct_bpp = false;
for (unsigned i = 0; i < ARRAY_SIZE(valid_bpp); i++)
for (i = 0; i < ARRAY_SIZE(valid_bpp); i++)
{
if (valid_bpp[i] == ihdr->depth)
{
@ -242,8 +244,9 @@ static inline int paeth(int a, int b, int c)
static inline void copy_line_rgb(uint32_t *data, const uint8_t *decoded, unsigned width, unsigned bpp)
{
unsigned i;
bpp /= 8;
for (unsigned i = 0; i < width; i++)
for (i = 0; i < width; i++)
{
uint32_t r = *decoded;
decoded += bpp;
@ -257,8 +260,9 @@ static inline void copy_line_rgb(uint32_t *data, const uint8_t *decoded, unsigne
static inline void copy_line_rgba(uint32_t *data, const uint8_t *decoded, unsigned width, unsigned bpp)
{
unsigned i;
bpp /= 8;
for (unsigned i = 0; i < width; i++)
for (i = 0; i < width; i++)
{
uint32_t r = *decoded;
decoded += bpp;
@ -274,9 +278,10 @@ static inline void copy_line_rgba(uint32_t *data, const uint8_t *decoded, unsign
static inline void copy_line_bw(uint32_t *data, const uint8_t *decoded, unsigned width, unsigned depth)
{
unsigned i, bit;
if (depth == 16)
{
for (unsigned i = 0; i < width; i++)
for (i = 0; i < width; i++)
{
uint32_t val = decoded[i << 1];
data[i] = (val * 0x010101) | (0xffu << 24);
@ -287,7 +292,8 @@ static inline void copy_line_bw(uint32_t *data, const uint8_t *decoded, unsigned
static const unsigned mul_table[] = { 0, 0xff, 0x55, 0, 0x11, 0, 0, 0, 0x01 };
unsigned mul = mul_table[depth];
unsigned mask = (1 << depth) - 1;
for (unsigned i = 0, bit = 0; i < width; i++, bit += depth)
bit = 0;
for (i = 0; i < width; i++, bit += depth)
{
unsigned byte = bit >> 3;
unsigned val = decoded[byte] >> (8 - depth - (bit & 7));
@ -302,8 +308,9 @@ static inline void copy_line_bw(uint32_t *data, const uint8_t *decoded, unsigned
static inline void copy_line_gray_alpha(uint32_t *data, const uint8_t *decoded, unsigned width,
unsigned bpp)
{
unsigned i;
bpp /= 8;
for (unsigned i = 0; i < width; i++)
for (i = 0; i < width; i++)
{
uint32_t gray = *decoded;
decoded += bpp;
@ -316,8 +323,10 @@ static inline void copy_line_gray_alpha(uint32_t *data, const uint8_t *decoded,
static inline void copy_line_plt(uint32_t *data, const uint8_t *decoded, unsigned width, unsigned depth, const uint32_t *palette)
{
unsigned i, bit;
unsigned mask = (1 << depth) - 1;
for (unsigned i = 0, bit = 0; i < width; i++, bit += depth)
bit = 0;
for (i = 0; i < width; i++, bit += depth)
{
unsigned byte = bit >> 3;
unsigned val = decoded[byte] >> (8 - depth - (bit & 7));
@ -377,6 +386,7 @@ static void png_pass_geom(const struct png_ihdr *ihdr,
static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr,
const uint8_t *inflate_buf, size_t inflate_buf_size, const uint32_t *palette)
{
unsigned i, h;
bool ret = true;
unsigned bpp;
@ -393,7 +403,7 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr,
if (!prev_scanline || !decoded_scanline)
GOTO_END_ERROR();
for (unsigned h = 0; h < ihdr->height;
for (h = 0; h < ihdr->height;
h++, inflate_buf += pitch, data += ihdr->width)
{
unsigned filter = *inflate_buf++;
@ -404,24 +414,24 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr,
break;
case 1: // Sub
for (unsigned i = 0; i < bpp; i++)
for (i = 0; i < bpp; i++)
decoded_scanline[i] = inflate_buf[i];
for (unsigned i = bpp; i < pitch; i++)
for (i = bpp; i < pitch; i++)
decoded_scanline[i] = decoded_scanline[i - bpp] + inflate_buf[i];
break;
case 2: // Up
for (unsigned i = 0; i < pitch; i++)
for (i = 0; i < pitch; i++)
decoded_scanline[i] = prev_scanline[i] + inflate_buf[i];
break;
case 3: // Average
for (unsigned i = 0; i < bpp; i++)
for (i = 0; i < bpp; i++)
{
uint8_t avg = prev_scanline[i] >> 1;
decoded_scanline[i] = avg + inflate_buf[i];
}
for (unsigned i = bpp; i < pitch; i++)
for (i = bpp; i < pitch; i++)
{
uint8_t avg = (decoded_scanline[i - bpp] + prev_scanline[i]) >> 1;
decoded_scanline[i] = avg + inflate_buf[i];
@ -429,9 +439,9 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr,
break;
case 4: // Paeth
for (unsigned i = 0; i < bpp; i++)
for (i = 0; i < bpp; i++)
decoded_scanline[i] = paeth(0, prev_scanline[i], 0) + inflate_buf[i];
for (unsigned i = bpp; i < pitch; i++)
for (i = bpp; i < pitch; i++)
decoded_scanline[i] = paeth(decoded_scanline[i - bpp], prev_scanline[i], prev_scanline[i - bpp]) + inflate_buf[i];
break;
@ -470,11 +480,12 @@ struct adam7_pass
static void deinterlace_pass(uint32_t *data, const struct png_ihdr *ihdr,
const uint32_t *input, unsigned pass_width, unsigned pass_height, const struct adam7_pass *pass)
{
unsigned x, y;
data += pass->y * ihdr->width + pass->x;
for (unsigned y = 0; y < pass_height; y++, data += ihdr->width * pass->stride_y, input += pass_width)
for (y = 0; y < pass_height; y++, data += ihdr->width * pass->stride_y, input += pass_width)
{
uint32_t *out = data;
for (unsigned x = 0; x < pass_width; x++, out += pass->stride_x)
for (x = 0; x < pass_width; x++, out += pass->stride_x)
*out = input[x];
}
}
@ -482,6 +493,7 @@ static void deinterlace_pass(uint32_t *data, const struct png_ihdr *ihdr,
static bool png_reverse_filter_adam7(uint32_t *data, const struct png_ihdr *ihdr,
const uint8_t *inflate_buf, size_t inflate_buf_size, const uint32_t *palette)
{
unsigned pass;
static const struct adam7_pass passes[] = {
{ 0, 0, 8, 8 },
{ 4, 0, 8, 8 },
@ -492,7 +504,7 @@ static bool png_reverse_filter_adam7(uint32_t *data, const struct png_ihdr *ihdr
{ 0, 1, 1, 2 },
};
for (unsigned pass = 0; pass < ARRAY_SIZE(passes); pass++)
for (pass = 0; pass < ARRAY_SIZE(passes); pass++)
{
if (ihdr->width <= passes[pass].x || ihdr->height <= passes[pass].y) // Empty pass
continue;
@ -550,6 +562,7 @@ static bool png_append_idat(FILE *file, const struct png_chunk *chunk, struct id
static bool png_read_plte(FILE *file, uint32_t *buffer, unsigned entries)
{
unsigned i;
if (entries > 256)
return false;
@ -557,7 +570,7 @@ static bool png_read_plte(FILE *file, uint32_t *buffer, unsigned entries)
if (fread(buf, 3, entries, file) != entries)
return false;
for (unsigned i = 0; i < entries; i++)
for (i = 0; i < entries; i++)
{
uint32_t r = buf[3 * i + 0];
uint32_t g = buf[3 * i + 1];
@ -573,6 +586,7 @@ static bool png_read_plte(FILE *file, uint32_t *buffer, unsigned entries)
bool rpng_load_image_argb(const char *path, uint32_t **data, unsigned *width, unsigned *height)
{
long pos;
*data = NULL;
*width = 0;
*height = 0;
@ -606,7 +620,7 @@ bool rpng_load_image_argb(const char *path, uint32_t **data, unsigned *width, un
GOTO_END_ERROR();
// feof() apparently isn't triggered after a seek (IEND).
for (long pos = ftell(file); pos < file_len && pos >= 0; pos = ftell(file))
for (pos = ftell(file); pos < file_len && pos >= 0; pos = ftell(file))
{
struct png_chunk chunk = {0};
if (!read_chunk_header(file, &chunk))
@ -792,7 +806,8 @@ static bool png_write_iend(FILE *file)
static void copy_argb_line(uint8_t *dst, const uint32_t *src, unsigned width)
{
for (unsigned i = 0; i < width; i++)
unsigned i;
for (i = 0; i < width; i++)
{
uint32_t col = src[i];
*dst++ = (uint8_t)(col >> 16);
@ -804,7 +819,8 @@ static void copy_argb_line(uint8_t *dst, const uint32_t *src, unsigned width)
static void copy_bgr24_line(uint8_t *dst, const uint8_t *src, unsigned width)
{
for (unsigned i = 0; i < width; i++, dst += 3, src += 3)
unsigned i;
for (i = 0; i < width; i++, dst += 3, src += 3)
{
dst[2] = src[0];
dst[1] = src[1];
@ -814,8 +830,9 @@ static void copy_bgr24_line(uint8_t *dst, const uint8_t *src, unsigned width)
static unsigned count_sad(const uint8_t *data, size_t size)
{
size_t i;
unsigned cnt = 0;
for (size_t i = 0; i < size; i++)
for (i = 0; i < size; i++)
cnt += abs((int8_t)data[i]);
return cnt;
}
@ -823,8 +840,9 @@ static unsigned count_sad(const uint8_t *data, size_t size)
static unsigned filter_up(uint8_t *target, const uint8_t *line, const uint8_t *prev,
unsigned width, unsigned bpp)
{
unsigned i;
width *= bpp;
for (unsigned i = 0; i < width; i++)
for (i = 0; i < width; i++)
target[i] = line[i] - prev[i];
return count_sad(target, width);
@ -833,10 +851,11 @@ static unsigned filter_up(uint8_t *target, const uint8_t *line, const uint8_t *p
static unsigned filter_sub(uint8_t *target, const uint8_t *line,
unsigned width, unsigned bpp)
{
unsigned i;
width *= bpp;
for (unsigned i = 0; i < bpp; i++)
for (i = 0; i < bpp; i++)
target[i] = line[i];
for (unsigned i = bpp; i < width; i++)
for (i = bpp; i < width; i++)
target[i] = line[i] - line[i - bpp];
return count_sad(target, width);
@ -845,10 +864,11 @@ static unsigned filter_sub(uint8_t *target, const uint8_t *line,
static unsigned filter_avg(uint8_t *target, const uint8_t *line, const uint8_t *prev,
unsigned width, unsigned bpp)
{
unsigned i;
width *= bpp;
for (unsigned i = 0; i < bpp; i++)
for (i = 0; i < bpp; i++)
target[i] = line[i] - (prev[i] >> 1);
for (unsigned i = bpp; i < width; i++)
for (i = bpp; i < width; i++)
target[i] = line[i] - ((line[i - bpp] + prev[i]) >> 1);
return count_sad(target, width);
@ -857,10 +877,11 @@ static unsigned filter_avg(uint8_t *target, const uint8_t *line, const uint8_t *
static unsigned filter_paeth(uint8_t *target, const uint8_t *line, const uint8_t *prev,
unsigned width, unsigned bpp)
{
unsigned i;
width *= bpp;
for (unsigned i = 0; i < bpp; i++)
for (i = 0; i < bpp; i++)
target[i] = line[i] - paeth(0, prev[i], 0);
for (unsigned i = bpp; i < width; i++)
for (i = bpp; i < width; i++)
target[i] = line[i] - paeth(line[i - bpp], prev[i], prev[i - bpp]);
return count_sad(target, width);
@ -869,6 +890,7 @@ static unsigned filter_paeth(uint8_t *target, const uint8_t *line, const uint8_t
static bool rpng_save_image(const char *path, const uint8_t *data,
unsigned width, unsigned height, unsigned pitch, unsigned bpp)
{
unsigned h;
bool ret = true;
struct png_ihdr ihdr = {0};
@ -917,7 +939,7 @@ static bool rpng_save_image(const char *path, const uint8_t *data,
GOTO_END_ERROR();
encode_target = encode_buf;
for (unsigned h = 0; h < height;
for (h = 0; h < height;
h++, encode_target += width * bpp, data += pitch)
{
if (bpp == sizeof(uint32_t))

9
hash.c
View File

@ -170,12 +170,14 @@ static void sha256_final(struct sha256_ctx *p)
static void sha256_subhash(struct sha256_ctx *p, uint32_t *t)
{
for (unsigned i = 0; i < 8; i++)
unsigned i;
for (i = 0; i < 8; i++)
store32be(t++, p->h[i]);
}
void sha256_hash(char *out, const uint8_t *in, size_t size)
{
unsigned i;
struct sha256_ctx sha;
union
@ -189,7 +191,7 @@ void sha256_hash(char *out, const uint8_t *in, size_t size)
sha256_final(&sha);
sha256_subhash(&sha, shahash.u32);
for (unsigned i = 0; i < 32; i++)
for (i = 0; i < 32; i++)
snprintf(out + 2 * i, 3, "%02x", (unsigned)shahash.u8[i]);
}
@ -248,8 +250,9 @@ uint32_t crc32_adjust(uint32_t crc32, uint8_t input)
uint32_t crc32_calculate(const uint8_t *data, size_t length)
{
size_t i;
uint32_t crc32 = ~0;
for (size_t i = 0; i < length; i++)
for (i = 0; i < length; i++)
crc32 = crc32_adjust(crc32, data[i]);
return ~crc32;
}

16
patch.c
View File

@ -77,6 +77,7 @@ patch_error_t bps_apply_patch(
const uint8_t *source_data, size_t source_length,
uint8_t *target_data, size_t *target_length)
{
size_t i;
if (modify_length < 19)
return PATCH_PATCH_TOO_SMALL;
@ -96,7 +97,7 @@ patch_error_t bps_apply_patch(
size_t modify_source_size = bps_decode(&bps);
size_t modify_target_size = bps_decode(&bps);
size_t modify_markup_size = bps_decode(&bps);
for (size_t i = 0; i < modify_markup_size; i++)
for (i = 0; i < modify_markup_size; i++)
bps_read(&bps);
if (modify_source_size > bps.source_length)
@ -150,13 +151,13 @@ patch_error_t bps_apply_patch(
}
uint32_t modify_source_checksum = 0, modify_target_checksum = 0, modify_modify_checksum = 0;
for (unsigned i = 0; i < 32; i += 8)
for (i = 0; i < 32; i += 8)
modify_source_checksum |= bps_read(&bps) << i;
for (unsigned i = 0; i < 32; i += 8)
for (i = 0; i < 32; i += 8)
modify_target_checksum |= bps_read(&bps) << i;
uint32_t checksum = ~bps.modify_checksum;
for (unsigned i = 0; i < 32; i += 8)
for (i = 0; i < 32; i += 8)
modify_modify_checksum |= bps_read(&bps) << i;
bps.source_checksum = crc32_calculate(bps.source_data, bps.source_length);
@ -236,6 +237,7 @@ patch_error_t ups_apply_patch(
const uint8_t *sourcedata, size_t sourcelength,
uint8_t *targetdata, size_t *targetlength)
{
size_t i;
struct ups_data data = {0};
data.patch_data = patchdata;
data.source_data = sourcedata;
@ -287,16 +289,16 @@ patch_error_t ups_apply_patch(
ups_target_write(&data, ups_source_read(&data));
uint32_t patch_read_checksum = 0, source_read_checksum = 0, target_read_checksum = 0;
for (unsigned i = 0; i < 4; i++)
for (i = 0; i < 4; i++)
source_read_checksum |= ups_patch_read(&data) << (i * 8);
for (unsigned i = 0; i < 4; i++)
for (i = 0; i < 4; i++)
target_read_checksum |= ups_patch_read(&data) << (i * 8);
uint32_t patch_result_checksum = ~data.patch_checksum;
data.source_checksum = ~data.source_checksum;
data.target_checksum = ~data.target_checksum;
for (unsigned i = 0; i < 4; i++)
for (i = 0; i < 4; i++)
patch_read_checksum |= ups_patch_read(&data) << (i * 8);
if (patch_result_checksum != patch_read_checksum)

View File

@ -78,8 +78,9 @@ void rarch_perf_register(struct rarch_perf_counter *perf)
void rarch_perf_log(void)
{
unsigned i;
RARCH_LOG("[PERF]: Performance counters:\n");
for (unsigned i = 0; i < perf_ptr; i++)
for (i = 0; i < perf_ptr; i++)
RARCH_PERFORMANCE_LOG(perf_counters[i]->ident, *perf_counters[i]);
}