Skip to content

Instantly share code, notes, and snippets.

@gpnuma gpnuma/patch Secret
Created Nov 8, 2013

Embed
What would you like to do?
Patch for -c2 Piotr suggestion
diff --git a/src/kernel_chameleon_1p.c b/src/kernel_chameleon_1p.c
index 96b1be0..dd19e66 100644
--- a/src/kernel_chameleon_1p.c
+++ b/src/kernel_chameleon_1p.c
@@ -32,6 +32,7 @@
#define SSC_CHAMELEON_CODE_INCLUSION
+#define SSC_CHAMELEON_MODE_1P
#define SSC_CHAMELEON_SUFFIX 1p
#define SSC_CHAMELEON_HASH_OFFSET_BASIS (uint32_t)2885564586
#define SSC_CHAMELEON_DICTIONARY_RESET ssc_dictionary_reset_1p
@@ -42,5 +43,6 @@
#undef SSC_CHAMELEON_DICTIONARY_RESET
#undef SSC_CHAMELEON_HASH_OFFSET_BASIS
#undef SSC_CHAMELEON_SUFFIX
+#undef SSC_CHAMELEON_MODE_1P
#undef SSC_CHAMELEON_CODE_INCLUSION
\ No newline at end of file
diff --git a/src/kernel_chameleon_2p.c b/src/kernel_chameleon_2p.c
index cf159eb..0ec73ef 100644
--- a/src/kernel_chameleon_2p.c
+++ b/src/kernel_chameleon_2p.c
@@ -32,6 +32,7 @@
#define SSC_CHAMELEON_CODE_INCLUSION
+#define SSC_CHAMELEON_MODE_2P
#define SSC_CHAMELEON_SUFFIX 2p
#define SSC_CHAMELEON_HASH_OFFSET_BASIS (uint32_t)2166115717
#define SSC_CHAMELEON_DICTIONARY_RESET ssc_dictionary_reset_2p
@@ -42,5 +43,6 @@
#undef SSC_CHAMELEON_DICTIONARY_RESET
#undef SSC_CHAMELEON_HASH_OFFSET_BASIS
#undef SSC_CHAMELEON_SUFFIX
+#undef SSC_CHAMELEON_MODE_2P
#undef SSC_CHAMELEON_CODE_INCLUSION
diff --git a/src/kernel_chameleon_dictionary.c b/src/kernel_chameleon_dictionary.c
index 1094056..4e7dfb5 100644
--- a/src/kernel_chameleon_dictionary.c
+++ b/src/kernel_chameleon_dictionary.c
@@ -33,7 +33,7 @@
#include "kernel_chameleon_dictionary.h"
const ssc_dictionary ssc_dictionary_1p = {.entries = SSC_DICTIONARY_CHAMELEON_1P};
-const ssc_dictionary ssc_dictionary_2p = {.entries = SSC_DICTIONARY_CHAMELEON_2P};
+const ssc_dictionary ssc_dictionary_2p = {.entries = 0};//SSC_DICTIONARY_CHAMELEON_2P};
SSC_FORCE_INLINE void ssc_dictionary_reset_1p(ssc_dictionary * dictionary) {
memcpy(dictionary, &ssc_dictionary_1p, sizeof(ssc_dictionary));
diff --git a/src/kernel_chameleon_encode.c b/src/kernel_chameleon_encode.c
index a81119e..209c891 100644
--- a/src/kernel_chameleon_encode.c
+++ b/src/kernel_chameleon_encode.c
@@ -101,6 +101,30 @@ SSC_FORCE_INLINE void ssc_hash_encode_kernel(ssc_byte_buffer *restrict out, uint
if (chunk ^ found->as_uint32_t) {
found->as_uint32_t = chunk;
+#ifdef SSC_CHAMELEON_MODE_2P
+ uint32_t chunkB;
+ switch(state->shift & 0x3) {
+ case 0:
+ break;
+ case 1:
+ chunkB = (state->previous << 8) + (chunk >> 24);
+ SSC_CHAMELEON_HASH_ALGORITHM(*hash, SSC_LITTLE_ENDIAN_32(chunkB));
+ (&state->dictionary.entries[*hash])->as_uint32_t = chunkB;
+ break;
+ case 2:
+ chunkB = (state->previous << 16) + (chunk >> 16);
+ SSC_CHAMELEON_HASH_ALGORITHM(*hash, SSC_LITTLE_ENDIAN_32(chunkB));
+ (&state->dictionary.entries[*hash])->as_uint32_t = chunkB;
+ break;
+ case 3:
+ chunkB = (state->previous << 24) + (chunk >> 8);
+ SSC_CHAMELEON_HASH_ALGORITHM(*hash, SSC_LITTLE_ENDIAN_32(chunkB));
+ (&state->dictionary.entries[*hash])->as_uint32_t = chunkB;
+ break;
+ default:
+ break;
+ }
+#endif
*(uint32_t *) (out->pointer + out->position) = chunk;
out->position += sizeof(uint32_t);
} else {
@@ -110,6 +134,7 @@ SSC_FORCE_INLINE void ssc_hash_encode_kernel(ssc_byte_buffer *restrict out, uint
}
state->shift++;
+ state->previous = chunk;
}
SSC_FORCE_INLINE void ssc_hash_encode_process_chunk(uint64_t *chunk, ssc_byte_buffer *restrict in, ssc_byte_buffer *restrict out, uint32_t *restrict hash, ssc_chameleon_encode_state *restrict state) {
diff --git a/src/kernel_chameleon_encode.h b/src/kernel_chameleon_encode.h
index 43cefb7..8763e53 100644
--- a/src/kernel_chameleon_encode.h
+++ b/src/kernel_chameleon_encode.h
@@ -61,6 +61,7 @@ typedef struct {
uint_fast8_t efficiencyChecked;
ssc_dictionary dictionary;
+ uint_fast32_t previous;
} ssc_chameleon_encode_state;
#pragma pack(pop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.