Variable Simple
This commit is contained in:
92
vsimple.c
92
vsimple.c
@ -26,21 +26,36 @@
|
|||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
#include <emmintrin.h>
|
#include <emmintrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <stdint.h>
|
||||||
#include "vsimple.h"
|
#include "vsimple.h"
|
||||||
|
|
||||||
#define USE_RLE
|
#define USE_RLE
|
||||||
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
||||||
#define SV_LIM unsigned char s_lim[] = { 0, 28, 28, 28, 28, 36, 36, 36, 36, 36, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 0 };
|
#define SV_LIM32 unsigned char s_lim32[] = { 0, 28, 28, 28, 28, 36, 36, 36, 36, 36, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 0 };
|
||||||
#define SV_ITM unsigned s_itm[] = { 0, 28, 14, 9, 7, 7, 6, 5, 4, 4, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, -1 }
|
#define SV_ITM32 unsigned s_itm32[] = { 0, 28, 14, 9, 7, 7, 6, 5, 4, 4, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, -1 }
|
||||||
static SV_ITM;
|
|
||||||
static SV_LIM;
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
#define SV_LIM64 unsigned char s_lim64[] = { 0, 28, 28, 28, 28, 36, 36, 36, 36, 36, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60,\
|
||||||
|
60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 64, 64, 64, 64, 64, 64, 64, 64, 0 };
|
||||||
|
|
||||||
|
#define SV_ITM64 unsigned s_itm64[] = { 0, 28, 14, 9, 7, 7, 6, 5, 4, 4, 6, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1,\
|
||||||
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1 }
|
||||||
|
|
||||||
|
static SV_LIM32;
|
||||||
|
static SV_ITM32;
|
||||||
#define USIZE 32
|
#define USIZE 32
|
||||||
#include __FILE__
|
#include __FILE__
|
||||||
#undef USIZE
|
#undef USIZE
|
||||||
|
|
||||||
#define USIZE 16
|
#define USIZE 16
|
||||||
|
#define s_lim16 s_lim32
|
||||||
|
#define s_itm16 s_itm32
|
||||||
|
#include __FILE__
|
||||||
|
#undef USIZE
|
||||||
|
|
||||||
|
#define USIZE 64
|
||||||
|
static SV_ITM64;
|
||||||
|
static SV_LIM64;
|
||||||
#include __FILE__
|
#include __FILE__
|
||||||
#undef USIZE
|
#undef USIZE
|
||||||
|
|
||||||
@ -65,14 +80,14 @@ unsigned char *TEMPLATE2(vsenc, USIZE)(uint_t *__restrict in, int n, unsigned ch
|
|||||||
while(q+1 < e && *(q+1) == *ip) q++;
|
while(q+1 < e && *(q+1) == *ip) q++;
|
||||||
r = q - ip;
|
r = q - ip;
|
||||||
if(r*TEMPLATE2(bsr, USIZE)(*ip) > 16 || (!*ip && r>4)) {
|
if(r*TEMPLATE2(bsr, USIZE)(*ip) > 16 || (!*ip && r>4)) {
|
||||||
m = (*ip)?33:0;
|
m = (*ip)?(USIZE<=32?33:65):0;
|
||||||
goto a;
|
goto a;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
r = 0;
|
r = 0;
|
||||||
for(m = x = TEMPLATE2(bsr, USIZE)(*ip);(r+1)*(xm = x > m?x:m) <= s_lim[xm] && ip+r<e;) m = xm, x = TEMPLATE2(bsr, USIZE)(*(ip+(++r)));
|
for(m = x = TEMPLATE2(bsr, USIZE)(*ip);(r+1)*(xm = x > m?x:m) <= TEMPLATE2(s_lim, USIZE)[xm] && ip+r<e;) m = xm, x = TEMPLATE2(bsr, USIZE)(ip[++r]);
|
||||||
while(r < s_itm[m]) m++;
|
while(r < TEMPLATE2(s_itm, USIZE)[m]) m++;
|
||||||
|
|
||||||
a:;
|
a:;
|
||||||
switch(m) {
|
switch(m) {
|
||||||
@ -176,11 +191,11 @@ unsigned char *TEMPLATE2(vsenc, USIZE)(uint_t *__restrict in, int n, unsigned ch
|
|||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
*(uint64_t *)op = 7 |
|
*(uint64_t *)op = 7 |
|
||||||
(unsigned)ip[ 0] << 4 |
|
(unsigned)ip[ 0] << 5 |
|
||||||
(unsigned)ip[ 1] << 11 |
|
(unsigned)ip[ 1] << 12 |
|
||||||
(unsigned)ip[ 2] << 18 |
|
(unsigned)ip[ 2] << 19 |
|
||||||
(uint64_t)ip[ 3] << 25 |
|
(uint64_t)ip[ 3] << 26 |
|
||||||
(uint64_t)ip[ 4] << 32; ip += 5; op += 5;
|
(uint64_t)ip[ 4] << 33; ip += 5; op += 5;
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
case 9:
|
case 9:
|
||||||
@ -219,15 +234,18 @@ unsigned char *TEMPLATE2(vsenc, USIZE)(uint_t *__restrict in, int n, unsigned ch
|
|||||||
(uint64_t)ip[ 3] << 49; ip += 4; op += 8;
|
(uint64_t)ip[ 3] << 49; ip += 4; op += 8;
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
|
#if USIZE > 16
|
||||||
case 17:
|
case 17:
|
||||||
case 18:
|
case 18:
|
||||||
case 19:
|
case 19:
|
||||||
case 20:
|
case 20:
|
||||||
|
#endif
|
||||||
*(uint64_t *)op = 11 |
|
*(uint64_t *)op = 11 |
|
||||||
(unsigned)ip[ 0] << 4 |
|
(unsigned)ip[ 0] << 4 |
|
||||||
(uint64_t)ip[ 1] << 24 |
|
(uint64_t)ip[ 1] << 24 |
|
||||||
(uint64_t)ip[ 2] << 44; ip += 3; op += 8;
|
(uint64_t)ip[ 2] << 44; ip += 3; op += 8;
|
||||||
break;
|
break;
|
||||||
|
#if USIZE > 16
|
||||||
case 21:
|
case 21:
|
||||||
case 22:
|
case 22:
|
||||||
case 23:
|
case 23:
|
||||||
@ -244,11 +262,21 @@ unsigned char *TEMPLATE2(vsenc, USIZE)(uint_t *__restrict in, int n, unsigned ch
|
|||||||
break;
|
break;
|
||||||
case 31:
|
case 31:
|
||||||
case 32:
|
case 32:
|
||||||
|
#if USIZE == 64
|
||||||
|
case 33: case 34: case 35: case 36:
|
||||||
|
#endif
|
||||||
*(uint64_t *)op = 14 |
|
*(uint64_t *)op = 14 |
|
||||||
(uint64_t)ip[ 0] << 4; ip++; op += 5;
|
(uint64_t)ip[ 0] << 4; ip++; op += 5;
|
||||||
break;
|
break;
|
||||||
|
#if USIZE == 64
|
||||||
|
case 37 ... 64: xm = (m+7)/8;
|
||||||
|
*op++ = 0x17 | (xm-1) << 5;
|
||||||
|
*(uint64_t *)op = (uint64_t)ip[ 0]; ip++; op += xm;
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
#ifdef USE_RLE
|
#ifdef USE_RLE
|
||||||
case 33: ip += r;
|
case USIZE<=32?33:65: ip += r;
|
||||||
if(--r >= 0xf) {
|
if(--r >= 0xf) {
|
||||||
*op++ = 0xf0|8;
|
*op++ = 0xf0|8;
|
||||||
if(n <= 0x100)
|
if(n <= 0x100)
|
||||||
@ -256,9 +284,10 @@ unsigned char *TEMPLATE2(vsenc, USIZE)(uint_t *__restrict in, int n, unsigned ch
|
|||||||
else
|
else
|
||||||
vbput(op, r);
|
vbput(op, r);
|
||||||
} else *op++ = r<<4|8;
|
} else *op++ = r<<4|8;
|
||||||
vbput(op, ip[0]);
|
TEMPLATE2(vbput, USIZE)(op, ip[0]);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return op;
|
return op;
|
||||||
@ -273,7 +302,7 @@ unsigned char *TEMPLATE2(vsdec, USIZE)(unsigned char *__restrict ip, int n, uint
|
|||||||
uint_t *op_ = op+n;
|
uint_t *op_ = op+n;
|
||||||
while(op < op_) {
|
while(op < op_) {
|
||||||
register uint64_t w = *(uint64_t *)ip;
|
register uint64_t w = *(uint64_t *)ip;
|
||||||
switch(w & 15) {
|
switch(w & 0xf) {
|
||||||
case 0: {
|
case 0: {
|
||||||
unsigned r = (w>>4)&0xf; ip++;
|
unsigned r = (w>>4)&0xf; ip++;
|
||||||
if(unlikely(r == 0xf)) {
|
if(unlikely(r == 0xf)) {
|
||||||
@ -283,11 +312,11 @@ unsigned char *TEMPLATE2(vsdec, USIZE)(unsigned char *__restrict ip, int n, uint
|
|||||||
r = vbget(ip);
|
r = vbget(ip);
|
||||||
}
|
}
|
||||||
uint_t *q = op; op += r+1;
|
uint_t *q = op; op += r+1;
|
||||||
#ifdef __SSE2__
|
#if defined(__SSE2__) && USIZE == 32
|
||||||
__m128i zv = _mm_setzero_si128();
|
__m128i zv = _mm_setzero_si128();
|
||||||
#endif
|
#endif
|
||||||
while(q < op) {
|
while(q < op) {
|
||||||
#ifdef __SSE2__
|
#if defined(__SSE2__) && USIZE == 32
|
||||||
_mm_storeu_si128((__m128i *)q,zv); q = (uint_t *)((unsigned char *)q+16);
|
_mm_storeu_si128((__m128i *)q,zv); q = (uint_t *)((unsigned char *)q+16);
|
||||||
_mm_storeu_si128((__m128i *)q,zv); q = (uint_t *)((unsigned char *)q+16);
|
_mm_storeu_si128((__m128i *)q,zv); q = (uint_t *)((unsigned char *)q+16);
|
||||||
#else
|
#else
|
||||||
@ -380,11 +409,20 @@ unsigned char *TEMPLATE2(vsdec, USIZE)(unsigned char *__restrict ip, int n, uint
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 7:
|
case 7:
|
||||||
OP(0) = (w >> 4) & 0x7f;
|
#if USIZE == 64
|
||||||
OP(1) = (w >> 11) & 0x7f;
|
if(unlikely((w>>4) & 1)) {
|
||||||
OP(2) = (w >> 18) & 0x7f;
|
unsigned b = ((*ip++) >> 5)+1;
|
||||||
OP(3) = (w >> 25) & 0x7f;
|
*op = *(unsigned long long *)ip;
|
||||||
OP(4) = (w >> 32) & 0x7f; OPI( 5); ip+=5;
|
if(unlikely(b!=8))
|
||||||
|
*op &= (1ull<<(b*8))-1; op++; ip += b;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
OP(0) = (w >> 5) & 0x7f;
|
||||||
|
OP(1) = (w >> 12) & 0x7f;
|
||||||
|
OP(2) = (w >> 19) & 0x7f;
|
||||||
|
OP(3) = (w >> 26) & 0x7f;
|
||||||
|
OP(4) = (w >> 33) & 0x7f; OPI( 5); ip+=5;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef USE_RLE
|
#ifdef USE_RLE
|
||||||
@ -396,7 +434,7 @@ unsigned char *TEMPLATE2(vsdec, USIZE)(unsigned char *__restrict ip, int n, uint
|
|||||||
else
|
else
|
||||||
r = vbget(ip);
|
r = vbget(ip);
|
||||||
}
|
}
|
||||||
unsigned u = vbget(ip); uint_t *q=op; op += r+1;
|
uint_t u = TEMPLATE2(vbget, USIZE)(ip), *q=op; op += r+1;
|
||||||
#if defined(__SSE2__) && USIZE == 32
|
#if defined(__SSE2__) && USIZE == 32
|
||||||
__m128i v = _mm_set1_epi32(u);
|
__m128i v = _mm_set1_epi32(u);
|
||||||
while(q < op) {
|
while(q < op) {
|
||||||
@ -448,7 +486,11 @@ unsigned char *TEMPLATE2(vsdec, USIZE)(unsigned char *__restrict ip, int n, uint
|
|||||||
OP(1) = (w >> 34) & 0x3fffffffu; OPI( 2); ip+=8;
|
OP(1) = (w >> 34) & 0x3fffffffu; OPI( 2); ip+=8;
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
OP(0) = (w >> 4) & 0xffffffffu; OPI( 1); ip+=5;
|
#if USIZE <= 32
|
||||||
|
OP(0) = (w >> 4) & 0xfffffffffull; OPI( 1); ip+=5;
|
||||||
|
#else
|
||||||
|
OP(0) = (w >> 4) & 0xfffffffffull; OPI( 1); ip+=5;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user