Skip to content
Snippets Groups Projects
Commit ef867686 authored by Jonathan Lennox's avatar Jonathan Lennox Committed by Timothy B. Terriberry
Browse files

Simplify and generalize implementation of align(). Should be very efficient on...

Simplify and generalize implementation of align(). Should be very efficient on sensible platforms, and correct everywhere.
parent 24539c4d
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include "opus.h" #include "opus.h"
#include "celt.h" #include "celt.h"
#include <stddef.h> /* offsetof */
struct OpusRepacketizer { struct OpusRepacketizer {
unsigned char toc; unsigned char toc;
int nb_frames; int nb_frames;
...@@ -110,15 +112,13 @@ int opus_decode_native(OpusDecoder *st, const unsigned char *data, opus_int32 le ...@@ -110,15 +112,13 @@ int opus_decode_native(OpusDecoder *st, const unsigned char *data, opus_int32 le
/* Make sure everything is properly aligned. */ /* Make sure everything is properly aligned. */
static OPUS_INLINE int align(int i) static OPUS_INLINE int align(int i)
{ {
int size; struct foo {char c; union { void* p; opus_int32 i; opus_val32 v; } u;};
/* Alignment is determined by the max size of void*, opus_int32 and opus_val32,
rounded up to the nearest power of two. */ int alignment = offsetof(struct foo, u);
int tmp = (sizeof(opus_int32)-1)|(sizeof(opus_val32)-1)|(sizeof(void*)-1);
if (tmp == 0) /* Optimizing compilers should optimize div and multiply into and
size = 1; for all sensible alignment values. */
else return ((i + alignment - 1) / alignment) * alignment;
size = 1 << EC_ILOG(tmp);
return (i+size-1)&-size;
} }
int opus_packet_parse_impl(const unsigned char *data, opus_int32 len, int opus_packet_parse_impl(const unsigned char *data, opus_int32 len,
......
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