Skip to content
Snippets Groups Projects
Commit 647a83fc authored by Mathis Rosenhauer's avatar Mathis Rosenhauer
Browse files

Obvious performance enhancements for encoding

parent 79136519
No related branches found
No related tags found
No related merge requests found
CC = gcc
#CFLAGS = -g -pg -lc -O2 -Wall -fprofile-arcs -ftest-coverage -DPROFILE
#CFLAGS = -g -pg -lc -O2 -Wall -fprofile-arcs -ftest-coverage -DUNROLL_BLOCK_8
CFLAGS = -g -O3 -Wall
#CFLAGS = -g -pg -lc -O0 -Wall -fprofile-arcs -ftest-coverage
CFLAGS = -g -O3 -Wall -std=c99
OBJS = aee.o aed.o sz_compat.o
OBJS = aee.o aee_mutators.o aed.o sz_compat.o
.PHONY : all clean check
......@@ -23,7 +22,9 @@ libae.a: $(OBJS)
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
aed.o: libae.h
aee.o: libae.h
aee.o: aee_mutators.h aee.h libae.h
aee_mutators.o: aee.h libae.h
sz_compat.o: libae.h
install: libae.a
mkdir -p ../lib ../include
......
This diff is collapsed.
#ifndef AAE_H
#define AAE_H
#include <inttypes.h>
#include "libae.h"
#define M_CONTINUE 1
#define M_EXIT 0
typedef struct internal_state {
int (*mode)(ae_streamp);
void (*get_block)(ae_streamp);
int64_t (*get_sample)(ae_streamp);
int id_len; /* bit length of code option identification key */
int64_t last_in; /* previous input for preprocessing */
int64_t xmin; /* minimum integer for preprocessing */
int64_t xmax; /* maximum integer for preprocessing */
int i; /* counter for samples */
int64_t *in_block; /* input block buffer */
int in_blklen; /* input block length in byte */
int64_t in_total_blocks;/* total blocks in */
uint8_t *out_block; /* output block buffer */
int out_blklen; /* output block length in byte */
uint8_t *out_bp; /* pointer to current output */
int out_direct; /* output to strm->next_out (1)
or out_block (0) */
int bitp; /* bit pointer to the next unused bit in accumulator */
int block_deferred; /* there is a block in the input buffer
but we first have to emit a zero block */
int ref; /* length of reference sample in current block
i.e. 0 or 1 depending on whether the block has
a reference sample or not */
int zero_ref; /* current zero block has a reference sample */
int64_t zero_ref_sample;/* reference sample of zero block */
int zero_blocks; /* number of contiguous zero blocks */
int k; /* splitting position */
int flush;
#ifdef PROFILE
int *prof;
#endif
} encode_state;
#endif
#include <inttypes.h>
#include "libae.h"
#include "aee.h"
#include "aee_mutators.h"
int64_t get_lsb_32(ae_streamp strm)
{
int64_t data;
data = (strm->next_in[3] << 24)
| (strm->next_in[2] << 16)
| (strm->next_in[1] << 8)
| strm->next_in[0];
strm->next_in += 4;
strm->total_in += 4;
strm->avail_in -= 4;
return data;
}
int64_t get_lsb_16(ae_streamp strm)
{
int64_t data;
data = (strm->next_in[1] << 8) | strm->next_in[0];
strm->next_in += 2;
strm->total_in += 2;
strm->avail_in -= 2;
return data;
}
int64_t get_msb_32(ae_streamp strm)
{
int64_t data;
data = (strm->next_in[0] << 24)
| (strm->next_in[1] << 16)
| (strm->next_in[2] << 8)
| strm->next_in[3];
strm->next_in += 4;
strm->total_in += 4;
strm->avail_in -= 4;
return data;
}
int64_t get_msb_16(ae_streamp strm)
{
int64_t data;
data = (strm->next_in[0] << 8) | strm->next_in[1];
strm->next_in += 2;
strm->total_in += 2;
strm->avail_in -= 2;
return data;
}
int64_t get_8(ae_streamp strm)
{
strm->avail_in--;
strm->total_in++;
return *strm->next_in++;
}
void get_block_msb_16_bs_8(ae_streamp strm)
{
int64_t *block = strm->state->in_block;
block[0] = (strm->next_in[0] << 8) | strm->next_in[1];
block[1] = (strm->next_in[2] << 8) | strm->next_in[3];
block[2] = (strm->next_in[4] << 8) | strm->next_in[5];
block[3] = (strm->next_in[6] << 8) | strm->next_in[7];
block[4] = (strm->next_in[8] << 8) | strm->next_in[9];
block[5] = (strm->next_in[10] << 8) | strm->next_in[11];
block[6] = (strm->next_in[12] << 8) | strm->next_in[13];
block[7] = (strm->next_in[14] << 8) | strm->next_in[15];
strm->next_in += 16;
strm->total_in += 16;
strm->avail_in -= 16;
}
void get_block_msb_16_bs_16(ae_streamp strm)
{
int i;
int64_t *block = strm->state->in_block;
for (i = 0; i < strm->block_size; i++)
{
block[i] = (strm->next_in[2 * i] << 8)
| strm->next_in[2 * i + 1];
}
strm->next_in += 32;
strm->total_in += 32;
strm->avail_in -= 32;
}
void get_block_8_bs_8(ae_streamp strm)
{
int64_t *block = strm->state->in_block;
block[0] = strm->next_in[0];
block[1] = strm->next_in[1];
block[2] = strm->next_in[2];
block[3] = strm->next_in[3];
block[4] = strm->next_in[4];
block[5] = strm->next_in[5];
block[6] = strm->next_in[6];
block[7] = strm->next_in[7];
strm->next_in += 8;
strm->total_in += 8;
strm->avail_in -= 8;
}
void get_block_8_bs_16(ae_streamp strm)
{
int64_t *block = strm->state->in_block;
block[0] = strm->next_in[0];
block[1] = strm->next_in[1];
block[2] = strm->next_in[2];
block[3] = strm->next_in[3];
block[4] = strm->next_in[4];
block[5] = strm->next_in[5];
block[6] = strm->next_in[6];
block[7] = strm->next_in[7];
block[8] = strm->next_in[8];
block[9] = strm->next_in[9];
block[10] = strm->next_in[10];
block[11] = strm->next_in[11];
block[12] = strm->next_in[12];
block[13] = strm->next_in[13];
block[14] = strm->next_in[14];
block[15] = strm->next_in[15];
strm->next_in += 16;
strm->total_in += 16;
strm->avail_in -= 16;
}
#ifndef AEE_MUTATORS_H
#define AEE_MUTATORS_H
#include <inttypes.h>
#include "libae.h"
int64_t get_lsb_32(ae_streamp);
int64_t get_lsb_16(ae_streamp);
int64_t get_msb_32(ae_streamp);
int64_t get_msb_16(ae_streamp);
int64_t get_8(ae_streamp);
void get_block_msb_16_bs_8(ae_streamp);
void get_block_msb_16_bs_16(ae_streamp);
void get_block_8_bs_8(ae_streamp);
void get_block_8_bs_16(ae_streamp);
#endif
......@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <getopt.h>
#include "libae.h"
#define CHUNK 1024
......
......@@ -4,6 +4,7 @@
#include <unistd.h>
#include <inttypes.h>
#include <string.h>
#include <getopt.h>
#include "libae.h"
#define CHUNK 1024
......
......@@ -2,6 +2,7 @@
#define LIBAE_H
#include <inttypes.h>
#include <stddef.h>
struct internal_state;
......@@ -21,7 +22,7 @@ typedef struct _ae_stream
uint32_t rsi; /* Reference sample interval, the number of
blocks between consecutive reference
samples. */
uint32_t flags;
uint32_t flags;
struct internal_state *state;
} ae_stream;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment