1 // double-precision codec
2 template <>
3 struct codec<double> {
4   // encode contiguous 1D block
5   static void encode_block_1(zfp_stream* zfp, const double* block, uint shape)
6   {
7     if (shape) {
8       uint nx = 4 - (shape & 3u); shape >>= 2;
9       zfp_encode_partial_block_strided_double_1(zfp, block, nx, 1);
10     }
11     else
12       zfp_encode_block_double_1(zfp, block);
13   }
14 
15   // encode 1D block from strided storage
16   static void encode_block_strided_1(zfp_stream* zfp, const double* p, uint shape, int sx)
17   {
18     if (shape) {
19       uint nx = 4 - (shape & 3u); shape >>= 2;
20       zfp_encode_partial_block_strided_double_1(zfp, p, nx, sx);
21     }
22     else
23       zfp_encode_block_strided_double_1(zfp, p, sx);
24   }
25 
26   // encode contiguous 2D block
27   static void encode_block_2(zfp_stream* zfp, const double* block, uint shape)
28   {
29     if (shape) {
30       uint nx = 4 - (shape & 3u); shape >>= 2;
31       uint ny = 4 - (shape & 3u); shape >>= 2;
32       zfp_encode_partial_block_strided_double_2(zfp, block, nx, ny, 1, 4);
33     }
34     else
35       zfp_encode_block_double_2(zfp, block);
36   }
37 
38   // encode 2D block from strided storage
39   static void encode_block_strided_2(zfp_stream* zfp, const double* p, uint shape, int sx, int sy)
40   {
41     if (shape) {
42       uint nx = 4 - (shape & 3u); shape >>= 2;
43       uint ny = 4 - (shape & 3u); shape >>= 2;
44       zfp_encode_partial_block_strided_double_2(zfp, p, nx, ny, sx, sy);
45     }
46     else
47       zfp_encode_block_strided_double_2(zfp, p, sx, sy);
48   }
49 
50   // encode contiguous 3D block
51   static void encode_block_3(zfp_stream* zfp, const double* block, uint shape)
52   {
53     if (shape) {
54       uint nx = 4 - (shape & 3u); shape >>= 2;
55       uint ny = 4 - (shape & 3u); shape >>= 2;
56       uint nz = 4 - (shape & 3u); shape >>= 2;
57       zfp_encode_partial_block_strided_double_3(zfp, block, nx, ny, nz, 1, 4, 16);
58     }
59     else
60       zfp_encode_block_double_3(zfp, block);
61   }
62 
63   // encode 3D block from strided storage
64   static void encode_block_strided_3(zfp_stream* zfp, const double* p, uint shape, int sx, int sy, int sz)
65   {
66     if (shape) {
67       uint nx = 4 - (shape & 3u); shape >>= 2;
68       uint ny = 4 - (shape & 3u); shape >>= 2;
69       uint nz = 4 - (shape & 3u); shape >>= 2;
70       zfp_encode_partial_block_strided_double_3(zfp, p, nx, ny, nz, sx, sy, sz);
71     }
72     else
73       zfp_encode_block_strided_double_3(zfp, p, sx, sy, sz);
74   }
75 
76   // decode contiguous 1D block
77   static void decode_block_1(zfp_stream* zfp, double* block, uint shape)
78   {
79     if (shape) {
80       uint nx = 4 - (shape & 3u); shape >>= 2;
81       zfp_decode_partial_block_strided_double_1(zfp, block, nx, 1);
82     }
83     else
84       zfp_decode_block_double_1(zfp, block);
85   }
86 
87   // decode 1D block to strided storage
88   static void decode_block_strided_1(zfp_stream* zfp, double* p, uint shape, int sx)
89   {
90     if (shape) {
91       uint nx = 4 - (shape & 3u); shape >>= 2;
92       zfp_decode_partial_block_strided_double_1(zfp, p, nx, sx);
93     }
94     else
95       zfp_decode_block_strided_double_1(zfp, p, sx);
96   }
97 
98   // decode contiguous 2D block
99   static void decode_block_2(zfp_stream* zfp, double* block, uint shape)
100   {
101     if (shape) {
102       uint nx = 4 - (shape & 3u); shape >>= 2;
103       uint ny = 4 - (shape & 3u); shape >>= 2;
104       zfp_decode_partial_block_strided_double_2(zfp, block, nx, ny, 1, 4);
105     }
106     else
107       zfp_decode_block_double_2(zfp, block);
108   }
109 
110   // decode 2D block to strided storage
111   static void decode_block_strided_2(zfp_stream* zfp, double* p, uint shape, int sx, int sy)
112   {
113     if (shape) {
114       uint nx = 4 - (shape & 3u); shape >>= 2;
115       uint ny = 4 - (shape & 3u); shape >>= 2;
116       zfp_decode_partial_block_strided_double_2(zfp, p, nx, ny, sx, sy);
117     }
118     else
119       zfp_decode_block_strided_double_2(zfp, p, sx, sy);
120   }
121 
122   // decode contiguous 3D block
123   static void decode_block_3(zfp_stream* zfp, double* block, uint shape)
124   {
125     if (shape) {
126       uint nx = 4 - (shape & 3u); shape >>= 2;
127       uint ny = 4 - (shape & 3u); shape >>= 2;
128       uint nz = 4 - (shape & 3u); shape >>= 2;
129       zfp_decode_partial_block_strided_double_3(zfp, block, nx, ny, nz, 1, 4, 16);
130     }
131     else
132       zfp_decode_block_double_3(zfp, block);
133   }
134 
135   // decode 3D block to strided storage
136   static void decode_block_strided_3(zfp_stream* zfp, double* p, uint shape, int sx, int sy, int sz)
137   {
138     if (shape) {
139       uint nx = 4 - (shape & 3u); shape >>= 2;
140       uint ny = 4 - (shape & 3u); shape >>= 2;
141       uint nz = 4 - (shape & 3u); shape >>= 2;
142       zfp_decode_partial_block_strided_double_3(zfp, p, nx, ny, nz, sx, sy, sz);
143     }
144     else
145       zfp_decode_block_strided_double_3(zfp, p, sx, sy, sz);
146   }
147 
148   static const zfp_type type = zfp_type_double;
149 };
150