source: proto/u16u8/src/u16u8.c @ 510

Last change on this file since 510 was 510, checked in by cameron, 9 years ago

Makefiles for u16u8

File size: 20.7 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <errno.h>
4#include <stdint.h>
5#include <string.h>
6#include <sys/types.h>
7#include <sys/stat.h>
8
9#include "../lib/lib_simd.h"
10#include "../lib/block_carry.h"
11
12typedef SIMD_type BytePack;
13typedef SIMD_type BitBlock;
14
15
16// Profiling
17#include "../lib/perflib/perfsec.h"
18
19#ifdef BUFFER_PROFILING
20BOM_Table * transcode_timer;
21#endif
22
23#ifdef CODE_CLOCKER
24        #define NUM_EVENTS 1
25        int Events[NUM_EVENTS] = {PAPI_TOT_CYC};
26        //int Events[NUM_EVENTS] = {PAPI_L2_DCM};
27        //int Events[NUM_EVENTS] = {PAPI_TOT_CYC, PAPI_BR_MSP};
28        int cal_size = 20;
29        CC * parser_timer = new CC(Events,NUM_EVENTS,cal_size);
30#endif
31
32/*===========================================================================*/
33/* UErrorCode */
34/* Extracted from ICU */
35/*===========================================================================*/
36
37typedef enum UErrorCode {
38
39    U_ZERO_ERROR              =  0,     /**< No error, no warning. */
40    U_TRUNCATED_CHAR_FOUND    = 11,     /**< Character conversion: Incomplete input sequence. */
41    U_ILLEGAL_CHAR_FOUND      = 12,     /**< Character conversion: Illegal input sequence/combination of input units. */
42} UErrorCode;
43
44typedef  uint16_t UChar;
45
46#define s2p_step(s0,s1,hi_mask,shift,p0,p1)  \
47{ \
48BitBlock t0,t1; \
49t0= simd_pack_16_hh(s0,s1) ; \
50t1= simd_pack_16_ll(s0,s1) ; \
51p0= simd_if(hi_mask,t0,simd_srli_16(t1,shift) ) ; \
52p1= simd_if(hi_mask,simd_slli_16(t0,shift) ,t1) ; \
53} \
54
55#define s2p_bytepack(s0,s1,s2,s3,s4,s5,s6,s7,p0,p1,p2,p3,p4,p5,p6,p7)  \
56{BitBlock bit00224466_0,bit00224466_1,bit00224466_2,bit00224466_3; \
57BitBlock bit11335577_0,bit11335577_1,bit11335577_2,bit11335577_3; \
58BitBlock bit00004444_0,bit22226666_0,bit00004444_1,bit22226666_1; \
59BitBlock bit11115555_0,bit33337777_0,bit11115555_1,bit33337777_1; \
60s2p_step(s0,s1,simd_himask_2,1,bit00224466_0,bit11335577_0)  \
61s2p_step(s2,s3,simd_himask_2,1,bit00224466_1,bit11335577_1)  \
62s2p_step(s4,s5,simd_himask_2,1,bit00224466_2,bit11335577_2)  \
63s2p_step(s6,s7,simd_himask_2,1,bit00224466_3,bit11335577_3)  \
64s2p_step(bit00224466_0,bit00224466_1,simd_himask_4,2,bit00004444_0,bit22226666_0)  \
65s2p_step(bit00224466_2,bit00224466_3,simd_himask_4,2,bit00004444_1,bit22226666_1)  \
66s2p_step(bit11335577_0,bit11335577_1,simd_himask_4,2,bit11115555_0,bit33337777_0)  \
67s2p_step(bit11335577_2,bit11335577_3,simd_himask_4,2,bit11115555_1,bit33337777_1)  \
68s2p_step(bit00004444_0,bit00004444_1,simd_himask_8,4,p0,p4)  \
69s2p_step(bit11115555_0,bit11115555_1,simd_himask_8,4,p1,p5)  \
70s2p_step(bit22226666_0,bit22226666_1,simd_himask_8,4,p2,p6)  \
71s2p_step(bit33337777_0,bit33337777_1,simd_himask_8,4,p3,p7)  \
72} \
73
74#define p2s_step(p0,p1,hi_mask,shift,s0,s1)  \
75{ \
76BitBlock t0,t1; \
77t0= simd_if(hi_mask,p0,simd_srli_16(p1,shift) ) ; \
78t1= simd_if(hi_mask,simd_slli_16(p0,shift) ,p1) ; \
79s0= simd_mergeh_8(t0,t1) ; \
80s1= simd_mergel_8(t0,t1) ; \
81} \
82
83#define p2s_bytemerge(p0,p1,p2,p3,p4,p5,p6,p7,s0,s1,s2,s3,s4,s5,s6,s7)  \
84{ \
85BitBlock bit00004444_0,bit22226666_0,bit00004444_1,bit22226666_1; \
86BitBlock bit11115555_0,bit33337777_0,bit11115555_1,bit33337777_1; \
87BitBlock bit00224466_0,bit00224466_1,bit00224466_2,bit00224466_3; \
88BitBlock bit11335577_0,bit11335577_1,bit11335577_2,bit11335577_3; \
89p2s_step(p0,p4,simd_himask_8,4,bit00004444_0,bit00004444_1)  \
90p2s_step(p1,p5,simd_himask_8,4,bit11115555_0,bit11115555_1)  \
91p2s_step(p2,p6,simd_himask_8,4,bit22226666_0,bit22226666_1)  \
92p2s_step(p3,p7,simd_himask_8,4,bit33337777_0,bit33337777_1)  \
93p2s_step(bit00004444_0,bit22226666_0,simd_himask_4,2,bit00224466_0,bit00224466_1)  \
94p2s_step(bit11115555_0,bit33337777_0,simd_himask_4,2,bit11335577_0,bit11335577_1)  \
95p2s_step(bit00004444_1,bit22226666_1,simd_himask_4,2,bit00224466_2,bit00224466_3)  \
96p2s_step(bit11115555_1,bit33337777_1,simd_himask_4,2,bit11335577_2,bit11335577_3)  \
97p2s_step(bit00224466_0,bit11335577_0,simd_himask_2,1,s0,s1)  \
98p2s_step(bit00224466_1,bit11335577_1,simd_himask_2,1,s2,s3)  \
99p2s_step(bit00224466_2,bit11335577_2,simd_himask_2,1,s4,s5)  \
100p2s_step(bit00224466_3,bit11335577_3,simd_himask_2,1,s6,s7)  \
101} \
102
103
104static inline void interleave4(BitBlock p0, BitBlock p1, BitBlock p2, BitBlock p3, 
105                               BitBlock& s0, BitBlock& s1, BitBlock& s2, BitBlock& s3);
106
107static inline void interleave4(BitBlock p0, BitBlock p1, BitBlock p2, BitBlock p3, 
108                               BitBlock& s0, BitBlock& s1, BitBlock& s2, BitBlock& s3){
109        BitBlock hpair0 = simd_mergel_1(p1, p0);
110        BitBlock hpair1 = simd_mergeh_1(p1, p0);
111        BitBlock lpair0 = simd_mergel_1(p3, p2);
112        BitBlock lpair1 = simd_mergeh_1(p3, p2);
113        s0 = simd_mergel_2(lpair0,hpair0);
114        s1 = simd_mergeh_2(lpair0,hpair0);
115        s2 = simd_mergel_2(lpair1,hpair1);
116        s3 = simd_mergeh_2(lpair1,hpair1);
117}
118
119
120
121
122#define do_right16_shifts(vec,rshift1,rshift2,rshift4,rshift8)  \
123{BitBlock s2; \
124vec= simd_sub_16(vec,simd_srli_16(simd_and(rshift1,vec) ,1) ) ; \
125s2= simd_and(rshift2,vec) ; \
126vec= simd_or(simd_srli_16(s2,2) ,simd_xor(vec,s2) ) ; \
127s2= simd_and(rshift4,vec) ; \
128vec= simd_or(simd_srli_16(s2,4) ,simd_xor(vec,s2) ) ; \
129s2= simd_and(rshift8,vec) ; \
130vec= simd_or(simd_srli_16(s2,8) ,simd_xor(vec,s2) ) ; \
131}
132
133static inline void bit_del_16(BitBlock &s, BitBlock delmask){
134        BitBlock del16_rshift1;
135        BitBlock del16_rshift2;
136        BitBlock del16_rshift4;
137        BitBlock del16_rshift8;
138       
139        BitBlock del16_trans2;
140        BitBlock del16_trans4;
141        BitBlock del16_trans8;
142        BitBlock shift_bits;
143       
144        del16_rshift1= simd_xor(simd_slli_16(delmask,1),simd_slli_16(delmask,2));
145        del16_rshift1= simd_xor(del16_rshift1,simd_slli_16(del16_rshift1,2));
146        del16_rshift1= simd_xor(del16_rshift1,simd_slli_16(del16_rshift1,4));
147        del16_rshift1= simd_xor(del16_rshift1,simd_slli_16(del16_rshift1,8));
148       
149        del16_trans2= simd_and(del16_rshift1,delmask);
150        del16_rshift2= simd_xor(simd_slli_16(del16_trans2,1),simd_slli_16(del16_trans2,2));
151        del16_rshift2= simd_xor(del16_rshift2,simd_slli_16(del16_rshift2,2));
152        del16_rshift2= simd_xor(del16_rshift2,simd_slli_16(del16_rshift2,4));
153        del16_rshift2= simd_xor(del16_rshift2,simd_slli_16(del16_rshift2,8));
154       
155        del16_trans4= simd_and(del16_rshift2,del16_trans2);
156        del16_rshift4= simd_xor(simd_slli_16(del16_trans4,1),simd_slli_16(del16_trans4,2));
157        del16_rshift4= simd_xor(del16_rshift4,simd_slli_16(del16_rshift4,2));
158        del16_rshift4= simd_xor(del16_rshift4,simd_slli_16(del16_rshift4,4));
159        del16_rshift4= simd_xor(del16_rshift4,simd_slli_16(del16_rshift4,8));
160       
161        del16_trans8= simd_and(del16_rshift4,del16_trans4);
162        del16_rshift8= simd_xor(simd_slli_16(del16_trans8,1),simd_slli_16(del16_trans8,2));
163        del16_rshift8= simd_xor(del16_rshift8,simd_slli_16(del16_rshift8,2));
164        del16_rshift8= simd_xor(del16_rshift8,simd_slli_16(del16_rshift8,4));
165        del16_rshift8= simd_xor(del16_rshift8,simd_slli_16(del16_rshift8,8));
166       
167        del16_rshift1= simd_andc(del16_rshift1,delmask);
168        del16_rshift2= simd_andc(del16_rshift2,delmask);
169        del16_rshift4= simd_andc(del16_rshift4,delmask);
170        del16_rshift8= simd_andc(del16_rshift8,delmask);
171       
172        del16_rshift2= simd_sub_16(del16_rshift2,simd_srli_16(simd_and(del16_rshift1,del16_rshift2),1));
173       
174        del16_rshift4= simd_sub_16(del16_rshift4,simd_srli_16(simd_and(del16_rshift1,del16_rshift4),1));
175        shift_bits= simd_and(del16_rshift2,del16_rshift4);
176        del16_rshift4= simd_or(simd_srli_16(shift_bits,2),simd_xor(del16_rshift4,shift_bits));
177       
178        del16_rshift8= simd_sub_16(del16_rshift8,simd_srli_16(simd_and(del16_rshift1,del16_rshift8),1));
179        shift_bits= simd_and(del16_rshift2,del16_rshift8);
180        del16_rshift8= simd_or(simd_srli_16(shift_bits,2),simd_xor(del16_rshift8,shift_bits)); 
181        shift_bits= simd_and(del16_rshift4,del16_rshift8);
182        del16_rshift8= simd_or(simd_srli_16(shift_bits,4),simd_xor(del16_rshift8,shift_bits));
183       
184        s = simd_andc(s, delmask);
185        do_right16_shifts (s, del16_rshift1, del16_rshift2, del16_rshift4,  del16_rshift8)
186
187}
188
189
190static inline void del_count(BitBlock delmask, short *u8_bytes_per_reg){
191
192BitBlock delcounts_2;
193BitBlock delcounts_4;
194BitBlock delcounts_8;
195BitBlock delcounts_16;
196
197delcounts_2 = simd_add_2_lh(delmask, delmask);
198delcounts_4 = simd_add_4_lh(delcounts_2, delcounts_2);
199delcounts_8 = simd_add_8_lh(delcounts_4, delcounts_4);
200delcounts_16 = simd_add_16_lh(delcounts_8, delcounts_8);
201sisd_store_aligned(simd_sub_16(simd_const_16(16), delcounts_16), (BytePack *) &u8_bytes_per_reg[0]);
202}
203
204
205
206#define BLOCK_SIZE 128
207
208void u16u8(char ** targetbuf, const char * targetlimit, const UChar ** srcbuf, const UChar * srclimit, UErrorCode * err){
209
210  BitBlock hcarry;
211BitBlock array_u16l__4_;
212BitBlock array_u16h__4_;
213BitBlock array_u8_butlast__5_;
214BitBlock strct_u16__utf8_3_;
215BitBlock array_u8_butlast__2_;
216BitBlock array_u8_last__5_;
217BitBlock Temp37;
218BitBlock array_u16l__0_;
219BitBlock efghi_e;
220BitBlock strct_u16__ASCII_;
221BitBlock array_u8_last__1_;
222BitBlock array_u8_pre__3_;
223BitBlock Temp31;
224BitBlock Temp30;
225BitBlock Temp33;
226BitBlock Temp32;
227BitBlock Temp35;
228BitBlock Temp34;
229BitBlock array_u8_butlast__6_;
230BitBlock Temp36;
231BitBlock array_u16h__0_;
232BitBlock array_u16l__1_;
233BitBlock strct_u16__surrogate_;
234BitBlock array_u8_last__0_;
235BitBlock array_u16l__7_;
236BitBlock array_u8_last__4_;
237BitBlock gcarry;
238BitBlock array_u8_butlast__3_;
239BitBlock strct_u16__error_;
240BitBlock array_u8_pre__7_;
241BitBlock strct_u16__lsurrogate_;
242BitBlock array_u8_butlast__7_;
243BitBlock array_u16h__7_;
244BitBlock array_u8_pre__4_;
245BitBlock Temp17;
246BitBlock array_u16h__3_;
247BitBlock array_u8_pre__0_;
248BitBlock array_u16l__3_;
249BitBlock array_u8_last__3_;
250BitBlock array_u16l__6_;
251BitBlock u8_2or3;
252BitBlock array_u16h__6_;
253BitBlock Temp13;
254BitBlock Temp12;
255BitBlock Temp11;
256BitBlock Temp10;
257BitBlock array_u8_butlast__4_;
258BitBlock Temp16;
259BitBlock Temp15;
260BitBlock Temp14;
261BitBlock array_u8_butlast__0_;
262BitBlock array_u8_last__7_;
263BitBlock Temp19;
264BitBlock Temp18;
265BitBlock array_u16l__2_;
266BitBlock array_u8_pre__1_;
267BitBlock array_u16l__5_;
268BitBlock array_u8_pre__5_;
269BitBlock array_u16h__2_;
270BitBlock Temp5;
271BitBlock array_u8_last__2_;
272BitBlock array_u16h__5_;
273BitBlock above_0x7F;
274BitBlock above_0x7FF;
275BitBlock strct_u16__hsurrogate_;
276BitBlock efghi_i;
277BitBlock efghi_h;
278BitBlock efghi_g;
279BitBlock efghi_f;
280BitBlock array_u8_last__6_;
281BitBlock array_u8_butlast__1_;
282BitBlock AllOne = simd_const_1(1);
283BitBlock AllZero = simd_const_1(0);
284BitBlock Temp28;
285BitBlock Temp29;
286BitBlock array_u8_pre__2_;
287BitBlock Temp22;
288BitBlock Temp23;
289BitBlock Temp20;
290BitBlock Temp21;
291BitBlock Temp26;
292BitBlock strct_u16__utf8_2_;
293BitBlock Temp24;
294BitBlock Temp25;
295BitBlock Temp3;
296BitBlock Temp2;
297BitBlock Temp1;
298BitBlock Temp27;
299BitBlock Temp7;
300BitBlock Temp6;
301BitBlock array_u16h__1_;
302BitBlock Temp4;
303BitBlock array_u8_pre__6_;
304BitBlock Temp9;
305BitBlock Temp8;
306CarryType carry1 = Carry0;
307CarryType carry0 = Carry0;
308CarryType carry2 = Carry0;
309
310
311SIMD_type u16l [8];
312SIMD_type u16h [8];
313
314
315  BytePack * U16;
316  BytePack U16h[8];
317  BytePack U16l[8];
318
319  BitBlock doublepair[32];
320
321  BitBlock endmask;
322
323  BitBlock delmask[4];
324
325  BitBlock U8[32];
326
327  int target_bckup_steps = 0;
328  int pos = 0;
329
330  intptr_t  units_remaining  = 0;
331  intptr_t  units_read  = 0;
332
333  bool error_found = false;
334  int err_pos;
335
336 
337
338  do {
339   
340    PERF_SEC_START(transcode_timer);
341
342    U16 = (BytePack *)(*srcbuf);
343    units_remaining = srclimit-(*srcbuf);
344
345    if(units_remaining < BLOCK_SIZE){
346        endmask = sisd_sll(simd_const_1(1),sisd_from_int((int) units_remaining));
347        units_read = units_remaining;
348
349//      ((uint16_t *) U16)[units_read/2] = 0;
350    }
351    else {
352        endmask = simd_const_1(0);
353        units_read = BLOCK_SIZE;
354    }
355
356    for (int i=0; i< 8; i++){
357      U16h[i] = simd_pack_16_ll(sisd_load_unaligned(&U16[i*2+1]),sisd_load_unaligned(&U16[i*2]));
358      U16l[i] = simd_pack_16_hh(sisd_load_unaligned(&U16[i*2+1]),sisd_load_unaligned(&U16[i*2]));
359    }
360
361
362    s2p_bytepack(U16h[7], U16h[6], U16h[5], U16h[4], U16h[3], U16h[2], U16h[1], U16h[0],
363    u16h[0], u16h[1], u16h[2], u16h[3], u16h[4], u16h[5], u16h[6], u16h[7]);
364
365    s2p_bytepack(U16l[7], U16l[6], U16l[5], U16l[4], U16l[3], U16l[2], U16l[1], U16l[0],
366    u16l[0], u16l[1], u16l[2], u16l[3], u16l[4], u16l[5], u16l[6], u16l[7]);
367
368array_u16l__0_ = u16l [0];
369array_u16l__1_ = u16l [1];
370array_u16l__2_ = u16l [2];
371array_u16l__3_ = u16l [3];
372array_u16l__4_ = u16l [4];
373array_u16l__5_ = u16l [5];
374array_u16l__6_ = u16l [6];
375array_u16l__7_ = u16l [7];
376
377array_u16h__0_ = u16h [0];
378array_u16h__1_ = u16h [1];
379array_u16h__2_ = u16h [2];
380array_u16h__3_ = u16h [3];
381array_u16h__4_ = u16h [4];
382array_u16h__5_ = u16h [5];
383array_u16h__6_ = u16h [6];
384array_u16h__7_ = u16h [7];
385
386    Temp1 = simd_or(array_u16h__0_,array_u16h__1_);
387Temp2 = simd_or(array_u16h__2_,array_u16h__3_);
388Temp3 = simd_or(Temp1,Temp2);
389above_0x7FF = simd_or(Temp3,array_u16h__4_);
390Temp4 = simd_or(above_0x7FF,array_u16h__5_);
391Temp5 = simd_or(array_u16h__6_,array_u16h__7_);
392Temp6 = simd_or(Temp4,Temp5);
393above_0x7F = simd_or(Temp6,array_u16l__0_);
394Temp7 = simd_and(array_u16h__0_,array_u16h__1_);
395Temp8 = simd_andc(array_u16h__3_,array_u16h__2_);
396Temp9 = simd_and(Temp7,Temp8);
397strct_u16__surrogate_ = simd_and(Temp9,array_u16h__4_);
398strct_u16__hsurrogate_ = simd_andc(strct_u16__surrogate_,array_u16h__5_);
399strct_u16__lsurrogate_ = simd_and(strct_u16__surrogate_,array_u16h__5_);
400strct_u16__utf8_3_ = simd_andc(above_0x7FF,strct_u16__surrogate_);
401strct_u16__utf8_2_ = simd_andc(above_0x7F,above_0x7FF);
402strct_u16__ASCII_ = simd_andc(AllOne,above_0x7F);
403advance_with_carry(strct_u16__hsurrogate_, carry0, Temp10);
404strct_u16__error_ = simd_xor(Temp10,strct_u16__lsurrogate_);
405efghi_i = simd_andc(AllOne,array_u16l__1_);
406efghi_h = simd_xor(array_u16l__0_,array_u16l__1_);
407hcarry = simd_andc(array_u16l__0_,efghi_h);
408efghi_g = simd_xor(array_u16h__7_,hcarry);
409gcarry = simd_andc(array_u16h__7_,efghi_g);
410efghi_f = simd_xor(array_u16h__6_,gcarry);
411efghi_e = simd_andc(array_u16h__6_,efghi_f);
412array_u8_last__0_ = simd_andc(AllOne,strct_u16__ASCII_);
413array_u8_last__1_ = simd_and(strct_u16__ASCII_,array_u16l__1_);
414Temp11 = simd_andc(array_u16l__2_,strct_u16__hsurrogate_);
415Temp12 = simd_and(efghi_h,strct_u16__hsurrogate_);
416array_u8_last__2_ = simd_or(Temp11,Temp12);
417Temp13 = simd_andc(array_u16l__3_,strct_u16__hsurrogate_);
418Temp14 = simd_and(efghi_i,strct_u16__hsurrogate_);
419array_u8_last__3_ = simd_or(Temp13,Temp14);
420Temp15 = simd_andc(array_u16l__4_,strct_u16__hsurrogate_);
421Temp16 = simd_and(array_u16l__2_,strct_u16__hsurrogate_);
422array_u8_last__4_ = simd_or(Temp15,Temp16);
423Temp17 = simd_andc(array_u16l__5_,strct_u16__hsurrogate_);
424Temp18 = simd_and(array_u16l__3_,strct_u16__hsurrogate_);
425array_u8_last__5_ = simd_or(Temp17,Temp18);
426Temp19 = simd_andc(array_u16l__6_,strct_u16__hsurrogate_);
427Temp20 = simd_and(array_u16l__4_,strct_u16__hsurrogate_);
428array_u8_last__6_ = simd_or(Temp19,Temp20);
429Temp21 = simd_andc(array_u16l__7_,strct_u16__hsurrogate_);
430Temp22 = simd_and(array_u16l__5_,strct_u16__hsurrogate_);
431array_u8_last__7_ = simd_or(Temp21,Temp22);
432u8_2or3 = simd_or(strct_u16__utf8_2_,strct_u16__utf8_3_);
433array_u8_butlast__0_ = simd_andc(AllOne,strct_u16__ASCII_);
434array_u8_butlast__1_ = simd_or(strct_u16__utf8_2_,strct_u16__hsurrogate_);
435Temp23 = simd_and(strct_u16__utf8_3_,array_u16h__4_);
436Temp24 = simd_or(strct_u16__hsurrogate_,Temp23);
437advance_with_carry(array_u16l__6_, carry1, Temp25);
438Temp26 = simd_and(strct_u16__lsurrogate_,Temp25);
439array_u8_butlast__2_ = simd_or(Temp24,Temp26);
440Temp27 = simd_and(u8_2or3,array_u16h__5_);
441Temp28 = simd_or(strct_u16__hsurrogate_,Temp27);
442advance_with_carry(array_u16l__7_, carry2, Temp29);
443Temp30 = simd_and(strct_u16__lsurrogate_,Temp29);
444array_u8_butlast__3_ = simd_or(Temp28,Temp30);
445Temp31 = simd_or(strct_u16__hsurrogate_,strct_u16__ASCII_);
446array_u8_butlast__4_ = simd_andc(array_u16h__6_,Temp31);
447Temp32 = simd_andc(array_u16h__7_,Temp31);
448Temp33 = simd_and(efghi_e,strct_u16__hsurrogate_);
449array_u8_butlast__5_ = simd_or(Temp32,Temp33);
450Temp34 = simd_andc(array_u16l__0_,Temp31);
451Temp35 = simd_and(efghi_f,strct_u16__hsurrogate_);
452array_u8_butlast__6_ = simd_or(Temp34,Temp35);
453Temp36 = simd_andc(array_u16l__1_,Temp31);
454Temp37 = simd_and(efghi_g,strct_u16__hsurrogate_);
455array_u8_butlast__7_ = simd_or(Temp36,Temp37);
456array_u8_pre__0_ = simd_andc(above_0x7FF,strct_u16__surrogate_);
457array_u8_pre__1_ = simd_andc(above_0x7FF,strct_u16__surrogate_);
458array_u8_pre__2_ = simd_andc(above_0x7FF,strct_u16__surrogate_);
459array_u8_pre__3_ = AllZero;
460array_u8_pre__4_ = simd_and(strct_u16__utf8_3_,array_u16h__0_);
461array_u8_pre__5_ = simd_and(strct_u16__utf8_3_,array_u16h__1_);
462array_u8_pre__6_ = simd_and(strct_u16__utf8_3_,array_u16h__2_);
463array_u8_pre__7_ = simd_and(strct_u16__utf8_3_,array_u16h__3_);
464
465
466/* Convert flattened array values to arrays */
467SIMD_type u8_pre [8];
468u8_pre[0] = array_u8_pre__0_;
469u8_pre[1] = array_u8_pre__1_;
470u8_pre[2] = array_u8_pre__2_;
471u8_pre[3] = array_u8_pre__3_;
472u8_pre[4] = array_u8_pre__4_;
473u8_pre[5] = array_u8_pre__5_;
474u8_pre[6] = array_u8_pre__6_;
475u8_pre[7] = array_u8_pre__7_;
476
477SIMD_type u8_butlast [8];
478u8_butlast[0] = array_u8_butlast__0_;
479u8_butlast[1] = array_u8_butlast__1_;
480u8_butlast[2] = array_u8_butlast__2_;
481u8_butlast[3] = array_u8_butlast__3_;
482u8_butlast[4] = array_u8_butlast__4_;
483u8_butlast[5] = array_u8_butlast__5_;
484u8_butlast[6] = array_u8_butlast__6_;
485u8_butlast[7] = array_u8_butlast__7_;
486
487SIMD_type u8_last [8];
488u8_last[0] = array_u8_last__0_;
489u8_last[1] = array_u8_last__1_;
490u8_last[2] = array_u8_last__2_;
491u8_last[3] = array_u8_last__3_;
492u8_last[4] = array_u8_last__4_;
493u8_last[5] = array_u8_last__5_;
494u8_last[6] = array_u8_last__6_;
495u8_last[7] = array_u8_last__7_;
496
497
498    if (bitblock_has_bit(strct_u16__error_)) {
499       
500       err_pos = count_forward_zeroes(strct_u16__error_);
501       error_found = true;
502        if ((err_pos == units_read)) {
503                err_pos--;
504                *err = U_TRUNCATED_CHAR_FOUND;
505                (*srcbuf) += err_pos;
506                if(err_pos<0){
507                        target_bckup_steps = 2;
508                        (*targetbuf) -= target_bckup_steps;
509                        return;
510                }               
511        }
512        else {
513          if((((unsigned char *)U16h)[err_pos]< 0xDC) || (((unsigned char *)U16h)[err_pos] >= 0xE0))
514                err_pos--;
515                *err = U_ILLEGAL_CHAR_FOUND;
516                (*srcbuf) += err_pos;
517                if(err_pos<0){
518                        target_bckup_steps = 2;
519                        (*targetbuf) -= target_bckup_steps;
520                        return;
521                }
522        }
523        endmask = sisd_sll(simd_const_1(1),sisd_from_int(err_pos));
524    }
525
526    for (int i=0; i< 8; i++){
527        interleave4(simd_const_8(0), u8_pre[i], u8_butlast[i], u8_last[i],
528                                doublepair[i*4], doublepair[i*4+1], 
529                                doublepair[i*4+2], doublepair[i*4+3]);
530    }
531
532        interleave4(simd_const_1(1), simd_or(endmask, simd_not(strct_u16__utf8_3_)), 
533                                simd_or(endmask, strct_u16__ASCII_), endmask,
534                                delmask[0], delmask[1], delmask[2], delmask[3]);
535
536
537     for (int i=0; i< 32; i=i+4){
538        bit_del_16(doublepair[i],delmask[0]);
539        bit_del_16(doublepair[i+1],delmask[1]);
540        bit_del_16(doublepair[i+2],delmask[2]);
541        bit_del_16(doublepair[i+3],delmask[3]);
542     }
543
544    short u8_bytes_per_reg[8];
545
546    for (int i=0; i< 4; i++){
547      p2s_bytemerge(doublepair[i],doublepair[4+i],doublepair[8+i],doublepair[12+i],doublepair[16+i],doublepair[20+i],doublepair[24+i],doublepair[28+i],
548                        U8[i*8+7],U8[i*8+6],U8[i*8+5],U8[i*8+4],U8[i*8+3],U8[i*8+2],U8[i*8+1],U8[i*8]);
549       for(int k=0; k<8; k++) u8_bytes_per_reg[k] = 0;
550       del_count(delmask[i],u8_bytes_per_reg);
551 
552       for(int j=0; j<8; j++){
553        sisd_store_unaligned(U8[i*8+j],(SIMD_type *) (*targetbuf));
554        *targetbuf += u8_bytes_per_reg[j];
555       }
556    }
557
558    if(!error_found) (*srcbuf) += units_read;
559
560
561    PERF_SEC_END(transcode_timer, units_read*2);
562
563
564    } while ((units_read == BLOCK_SIZE) && !error_found);
565
566}
567
568
569
570
571int
572main(int argc, char * argv[]) {
573        char * infilename, * outfilename;       
574        FILE *infile, *outfile;
575        struct stat fileinfo;
576        const UChar * srcbuf;
577        const UChar * srclimit;
578        const char * targetlimit;
579        char * targetbuf;
580        char * target_head;
581        UErrorCode status;
582        int chars_read;
583
584        if (argc < 2) {
585                printf("Usage: %s <filename> [<outputfile>]\n", argv[0]);
586                exit(-1);
587        }
588
589        infilename = argv[1];
590        stat(infilename, &fileinfo);
591        infile = fopen(infilename, "rb");
592        if (!infile) {
593                fprintf(stderr, "Error: cannot open %s for input.\n", infilename);
594                exit(-1);
595        }
596       
597        if (argc < 3) outfile = stdout;
598        else {
599                outfilename = argv[2];
600                outfile = fopen(outfilename, "wb");
601                if (!outfile) {
602                        fprintf(stderr, "Error: cannot open %s for writing.\n", outfilename);
603                        exit(-1);
604                }
605        }
606
607
608        srcbuf = (UChar *) malloc(fileinfo.st_size+1);
609        if (!srcbuf) {
610              fprintf(stderr, "Error: buffer for %s of size %zu cannot be created.\n", infilename, fileinfo.st_size+1);
611              exit(-1);
612        }
613
614        PERF_SEC_INIT(transcode_timer);
615
616
617        chars_read = fread((void *)srcbuf, 1, fileinfo.st_size, infile);
618
619        srclimit = srcbuf + chars_read/2;
620//      (*srcbuf)[fileinfo.st_size] = '\0';
621        fclose(infile);
622
623        targetbuf = (char *) malloc(chars_read*2);
624        targetlimit = targetbuf + chars_read*2;
625        target_head = targetbuf;
626
627        u16u8(&targetbuf, targetlimit, &srcbuf, srclimit, &status);
628        fwrite(target_head , 1 ,  targetbuf - target_head, outfile );
629
630        if (status == U_ILLEGAL_CHAR_FOUND) {
631                fprintf(stderr, "Illegal UTF-16 sequence at position %lu in source.\n", chars_read-(srclimit-srcbuf)*2);
632        }
633        else if (status == U_TRUNCATED_CHAR_FOUND) {
634                fprintf(stderr, "EOF with incomplete UTF-16 sequence at position %lu in source.\n",chars_read-(srclimit-srcbuf)*2);
635        }
636
637        PERF_SEC_DUMP(transcode_timer);
638
639        fclose(outfile);
640
641        return(0);
642}
Note: See TracBrowser for help on using the repository browser.