summaryrefslogtreecommitdiff
path: root/src/compression/vals16.c
diff options
context:
space:
mode:
authorMagnus Lundborg <lundborg.magnus@gmail.com>2013-05-15 14:19:08 (GMT)
committerMagnus Lundborg <lundborg.magnus@gmail.com>2013-05-15 14:19:08 (GMT)
commit08150c67d755afab6665207b0a06ae892a0ad7fa (patch)
tree6b062a61759ad14c52cf0c4fcd930995188c3ea5 /src/compression/vals16.c
parent94d926101a73f0b6d210da53e017d17e45fbdbd4 (diff)
parent718d755c5877bc3005ade2827e7c9cec1c6d064a (diff)
Merge branch 'master' of git.gromacs.org:tng
Diffstat (limited to 'src/compression/vals16.c')
-rw-r--r--src/compression/vals16.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/compression/vals16.c b/src/compression/vals16.c
new file mode 100644
index 0000000..6a8e7e7
--- /dev/null
+++ b/src/compression/vals16.c
@@ -0,0 +1,73 @@
+/* This code is part of the tng compression routines.
+ *
+ * Written by Daniel Spangberg
+ * Copyright (c) 2010, 2013, The GROMACS development team.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
+ */
+
+
+#include "vals16.h"
+
+/* Coding 32 bit ints in sequences of 16 bit ints. Worst case
+ the output is 3*nvals long. */
+void Ptngc_comp_conv_to_vals16(unsigned int *vals,int nvals,
+ unsigned int *vals16, int *nvals16)
+{
+ int i;
+ int j=0;
+ for (i=0; i<nvals; i++)
+ {
+ if (vals[i]<=0x7FFFU)
+ vals16[j++]=vals[i];
+ else
+ {
+ unsigned int lo=(vals[i]&0x7FFFU)|0x8000U;
+ unsigned int hi=vals[i]>>15;
+ vals16[j++]=lo;
+ if (hi<=0x7FFFU)
+ vals16[j++]=hi;
+ else
+ {
+ unsigned int lohi=(hi&0x7FFFU)|0x8000U;
+ unsigned int hihi=hi>>15;
+ vals16[j++]=lohi;
+ vals16[j++]=hihi;
+ }
+ }
+ }
+#if 0
+ /* Test that things that detect that this is bad really works. */
+ vals16[0]=0;
+#endif
+ *nvals16=j;
+}
+
+void Ptngc_comp_conv_from_vals16(unsigned int *vals16,int nvals16,
+ unsigned int *vals, int *nvals)
+{
+ int i=0;
+ int j=0;
+ while (i<nvals16)
+ {
+ if (vals16[i]<=0x7FFFU)
+ vals[j++]=vals16[i++];
+ else
+ {
+ unsigned int lo=vals16[i++];
+ unsigned int hi=vals16[i++];
+ if (hi<=0x7FFFU)
+ vals[j++]=(lo&0x7FFFU)|(hi<<15);
+ else
+ {
+ unsigned int hihi=vals16[i++];
+ vals[j++]=(lo&0x7FFFU)|((hi&0x7FFFU)<<15)|(hihi<<30);
+ }
+ }
+ }
+ *nvals=j;
+}
contact: Jan Huwald // Impressum