float128: Add strtof128, wcstof128, and related functions.
[glibc.git] / sysdeps / s390 / utf16-utf32-z9.c
blob7a174ea0e5eda93147d1f2e02320fdc46bf78e25
1 /* Conversion between UTF-16 and UTF-32 BE/internal.
3 This module uses the Z9-109 variants of the Convert Unicode
4 instructions.
5 Copyright (C) 1997-2017 Free Software Foundation, Inc.
7 Author: Andreas Krebbel <Andreas.Krebbel@de.ibm.com>
8 Based on the work by Ulrich Drepper <drepper@cygnus.com>, 1997.
10 Thanks to Daniel Appich who covered the relevant performance work
11 in his diploma thesis.
13 This is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 2.1 of the License, or (at your option) any later version.
18 This is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
23 You should have received a copy of the GNU Lesser General Public
24 License along with the GNU C Library; if not, see
25 <http://www.gnu.org/licenses/>. */
27 #include <dlfcn.h>
28 #include <stdint.h>
29 #include <unistd.h>
30 #include <gconv.h>
31 #include <string.h>
33 /* Select which versions should be defined depending on support
34 for multiarch, vector and used minimum architecture level. */
35 #define HAVE_FROM_C 1
36 #define FROM_LOOP_DEFAULT FROM_LOOP_C
37 #define HAVE_TO_C 1
38 #define TO_LOOP_DEFAULT TO_LOOP_C
40 #if defined HAVE_S390_VX_ASM_SUPPORT && defined USE_MULTIARCH
41 # define HAVE_FROM_VX 1
42 # define HAVE_TO_VX 1
43 #else
44 # define HAVE_FROM_VX 0
45 # define HAVE_TO_VX 0
46 #endif
48 #if defined HAVE_S390_VX_GCC_SUPPORT
49 # define ASM_CLOBBER_VR(NR) , NR
50 #else
51 # define ASM_CLOBBER_VR(NR)
52 #endif
54 #if defined __s390x__
55 # define CONVERT_32BIT_SIZE_T(REG)
56 #else
57 # define CONVERT_32BIT_SIZE_T(REG) "llgfr %" #REG ",%" #REG "\n\t"
58 #endif
60 /* UTF-32 big endian byte order mark. */
61 #define BOM_UTF32 0x0000feffu
63 /* UTF-16 big endian byte order mark. */
64 #define BOM_UTF16 0xfeff
66 #define DEFINE_INIT 0
67 #define DEFINE_FINI 0
68 #define MIN_NEEDED_FROM 2
69 #define MAX_NEEDED_FROM 4
70 #define MIN_NEEDED_TO 4
71 #define FROM_LOOP FROM_LOOP_DEFAULT
72 #define TO_LOOP TO_LOOP_DEFAULT
73 #define FROM_DIRECTION (dir == from_utf16)
74 #define ONE_DIRECTION 0
76 /* Direction of the transformation. */
77 enum direction
79 illegal_dir,
80 to_utf16,
81 from_utf16
84 struct utf16_data
86 enum direction dir;
87 int emit_bom;
91 extern int gconv_init (struct __gconv_step *step);
92 int
93 gconv_init (struct __gconv_step *step)
95 /* Determine which direction. */
96 struct utf16_data *new_data;
97 enum direction dir = illegal_dir;
98 int emit_bom;
99 int result;
101 emit_bom = (__strcasecmp (step->__to_name, "UTF-32//") == 0
102 || __strcasecmp (step->__to_name, "UTF-16//") == 0);
104 if (__strcasecmp (step->__from_name, "UTF-16BE//") == 0
105 && (__strcasecmp (step->__to_name, "UTF-32//") == 0
106 || __strcasecmp (step->__to_name, "UTF-32BE//") == 0
107 || __strcasecmp (step->__to_name, "INTERNAL") == 0))
109 dir = from_utf16;
111 else if ((__strcasecmp (step->__to_name, "UTF-16//") == 0
112 || __strcasecmp (step->__to_name, "UTF-16BE//") == 0)
113 && (__strcasecmp (step->__from_name, "UTF-32BE//") == 0
114 || __strcasecmp (step->__from_name, "INTERNAL") == 0))
116 dir = to_utf16;
119 result = __GCONV_NOCONV;
120 if (dir != illegal_dir)
122 new_data = (struct utf16_data *) malloc (sizeof (struct utf16_data));
124 result = __GCONV_NOMEM;
125 if (new_data != NULL)
127 new_data->dir = dir;
128 new_data->emit_bom = emit_bom;
129 step->__data = new_data;
131 if (dir == from_utf16)
133 step->__min_needed_from = MIN_NEEDED_FROM;
134 step->__max_needed_from = MIN_NEEDED_FROM;
135 step->__min_needed_to = MIN_NEEDED_TO;
136 step->__max_needed_to = MIN_NEEDED_TO;
138 else
140 step->__min_needed_from = MIN_NEEDED_TO;
141 step->__max_needed_from = MIN_NEEDED_TO;
142 step->__min_needed_to = MIN_NEEDED_FROM;
143 step->__max_needed_to = MIN_NEEDED_FROM;
146 step->__stateful = 0;
148 result = __GCONV_OK;
152 return result;
156 extern void gconv_end (struct __gconv_step *data);
157 void
158 gconv_end (struct __gconv_step *data)
160 free (data->__data);
163 #define PREPARE_LOOP \
164 enum direction dir = ((struct utf16_data *) step->__data)->dir; \
165 int emit_bom = ((struct utf16_data *) step->__data)->emit_bom; \
167 if (emit_bom && !data->__internal_use \
168 && data->__invocation_counter == 0) \
170 if (dir == to_utf16) \
172 /* Emit the UTF-16 Byte Order Mark. */ \
173 if (__glibc_unlikely (outbuf + 2 > outend)) \
174 return __GCONV_FULL_OUTPUT; \
176 put16u (outbuf, BOM_UTF16); \
177 outbuf += 2; \
179 else \
181 /* Emit the UTF-32 Byte Order Mark. */ \
182 if (__glibc_unlikely (outbuf + 4 > outend)) \
183 return __GCONV_FULL_OUTPUT; \
185 put32u (outbuf, BOM_UTF32); \
186 outbuf += 4; \
190 /* Conversion function from UTF-16 to UTF-32 internal/BE. */
192 #if HAVE_FROM_C == 1
193 /* The software routine is copied from utf-16.c (minus bytes
194 swapping). */
195 # define BODY_FROM_C \
197 uint16_t u1 = get16 (inptr); \
199 if (__builtin_expect (u1 < 0xd800, 1) || u1 > 0xdfff) \
201 /* No surrogate. */ \
202 put32 (outptr, u1); \
203 inptr += 2; \
205 else \
207 /* An isolated low-surrogate was found. This has to be \
208 considered ill-formed. */ \
209 if (__glibc_unlikely (u1 >= 0xdc00)) \
211 STANDARD_FROM_LOOP_ERR_HANDLER (2); \
213 /* It's a surrogate character. At least the first word says \
214 it is. */ \
215 if (__glibc_unlikely (inptr + 4 > inend)) \
217 /* We don't have enough input for another complete input \
218 character. */ \
219 result = __GCONV_INCOMPLETE_INPUT; \
220 break; \
223 inptr += 2; \
224 uint16_t u2 = get16 (inptr); \
225 if (__builtin_expect (u2 < 0xdc00, 0) \
226 || __builtin_expect (u2 > 0xdfff, 0)) \
228 /* This is no valid second word for a surrogate. */ \
229 inptr -= 2; \
230 STANDARD_FROM_LOOP_ERR_HANDLER (2); \
233 put32 (outptr, ((u1 - 0xd7c0) << 10) + (u2 - 0xdc00)); \
234 inptr += 2; \
236 outptr += 4; \
240 /* Generate loop-function with software routing. */
241 # define MIN_NEEDED_INPUT MIN_NEEDED_FROM
242 # define MAX_NEEDED_INPUT MAX_NEEDED_FROM
243 # define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
244 # define FROM_LOOP_C __from_utf16_loop_c
245 # define LOOPFCT FROM_LOOP_C
246 # define LOOP_NEED_FLAGS
247 # define BODY BODY_FROM_C
248 # include <iconv/loop.c>
249 #else
250 # define FROM_LOOP_C NULL
251 #endif /* HAVE_FROM_C != 1 */
253 #if HAVE_FROM_VX == 1
254 # define BODY_FROM_VX \
256 size_t inlen = inend - inptr; \
257 size_t outlen = outend - outptr; \
258 unsigned long tmp, tmp2, tmp3; \
259 asm volatile (".machine push\n\t" \
260 ".machine \"z13\"\n\t" \
261 ".machinemode \"zarch_nohighgprs\"\n\t" \
262 /* Setup to check for surrogates. */ \
263 " larl %[R_TMP],9f\n\t" \
264 " vlm %%v30,%%v31,0(%[R_TMP])\n\t" \
265 CONVERT_32BIT_SIZE_T ([R_INLEN]) \
266 CONVERT_32BIT_SIZE_T ([R_OUTLEN]) \
267 /* Loop which handles UTF-16 chars <0xd800, >0xdfff. */ \
268 "0: clgijl %[R_INLEN],16,2f\n\t" \
269 " clgijl %[R_OUTLEN],32,2f\n\t" \
270 "1: vl %%v16,0(%[R_IN])\n\t" \
271 /* Check for surrogate chars. */ \
272 " vstrchs %%v19,%%v16,%%v30,%%v31\n\t" \
273 " jno 10f\n\t" \
274 /* Enlarge to UTF-32. */ \
275 " vuplhh %%v17,%%v16\n\t" \
276 " la %[R_IN],16(%[R_IN])\n\t" \
277 " vupllh %%v18,%%v16\n\t" \
278 " aghi %[R_INLEN],-16\n\t" \
279 /* Store 32 bytes to buf_out. */ \
280 " vstm %%v17,%%v18,0(%[R_OUT])\n\t" \
281 " aghi %[R_OUTLEN],-32\n\t" \
282 " la %[R_OUT],32(%[R_OUT])\n\t" \
283 " clgijl %[R_INLEN],16,2f\n\t" \
284 " clgijl %[R_OUTLEN],32,2f\n\t" \
285 " j 1b\n\t" \
286 /* Setup to check for ch >= 0xd800 && ch <= 0xdfff. (v30, v31) */ \
287 "9: .short 0xd800,0xdfff,0x0,0x0,0x0,0x0,0x0,0x0\n\t" \
288 " .short 0xa000,0xc000,0x0,0x0,0x0,0x0,0x0,0x0\n\t" \
289 /* At least one uint16_t is in range of surrogates. \
290 Store the preceding chars. */ \
291 "10: vlgvb %[R_TMP],%%v19,7\n\t" \
292 " vuplhh %%v17,%%v16\n\t" \
293 " sllg %[R_TMP3],%[R_TMP],1\n\t" /* Number of out bytes. */ \
294 " ahik %[R_TMP2],%[R_TMP3],-1\n\t" /* Highest index to store. */ \
295 " jl 12f\n\t" \
296 " vstl %%v17,%[R_TMP2],0(%[R_OUT])\n\t" \
297 " vupllh %%v18,%%v16\n\t" \
298 " ahi %[R_TMP2],-16\n\t" \
299 " jl 11f\n\t" \
300 " vstl %%v18,%[R_TMP2],16(%[R_OUT])\n\t" \
301 "11: \n\t" /* Update pointers. */ \
302 " la %[R_IN],0(%[R_TMP],%[R_IN])\n\t" \
303 " slgr %[R_INLEN],%[R_TMP]\n\t" \
304 " la %[R_OUT],0(%[R_TMP3],%[R_OUT])\n\t" \
305 " slgr %[R_OUTLEN],%[R_TMP3]\n\t" \
306 /* Calculate remaining uint16_t values in loaded vrs. */ \
307 "12: lghi %[R_TMP2],16\n\t" \
308 " slgr %[R_TMP2],%[R_TMP]\n\t" \
309 " srl %[R_TMP2],1\n\t" \
310 " llh %[R_TMP],0(%[R_IN])\n\t" \
311 " aghi %[R_OUTLEN],-4\n\t" \
312 " j 16f\n\t" \
313 /* Handle remaining bytes. */ \
314 "2: \n\t" \
315 /* Zero, one or more bytes available? */ \
316 " clgfi %[R_INLEN],1\n\t" \
317 " je 97f\n\t" /* Only one byte available. */ \
318 " jl 99f\n\t" /* End if no bytes available. */ \
319 /* Calculate remaining uint16_t values in inptr. */ \
320 " srlg %[R_TMP2],%[R_INLEN],1\n\t" \
321 /* Handle remaining uint16_t values. */ \
322 "13: llh %[R_TMP],0(%[R_IN])\n\t" \
323 " slgfi %[R_OUTLEN],4\n\t" \
324 " jl 96f \n\t" \
325 " clfi %[R_TMP],0xd800\n\t" \
326 " jhe 15f\n\t" \
327 "14: st %[R_TMP],0(%[R_OUT])\n\t" \
328 " la %[R_IN],2(%[R_IN])\n\t" \
329 " aghi %[R_INLEN],-2\n\t" \
330 " la %[R_OUT],4(%[R_OUT])\n\t" \
331 " brctg %[R_TMP2],13b\n\t" \
332 " j 0b\n\t" /* Switch to vx-loop. */ \
333 /* Handle UTF-16 surrogate pair. */ \
334 "15: clfi %[R_TMP],0xdfff\n\t" \
335 " jh 14b\n\t" /* Jump away if ch > 0xdfff. */ \
336 "16: clfi %[R_TMP],0xdc00\n\t" \
337 " jhe 98f\n\t" /* Jump away in case of low-surrogate. */ \
338 " slgfi %[R_INLEN],4\n\t" \
339 " jl 97f\n\t" /* Big enough input? */ \
340 " llh %[R_TMP3],2(%[R_IN])\n\t" /* Load low surrogate. */ \
341 " slfi %[R_TMP],0xd7c0\n\t" \
342 " sll %[R_TMP],10\n\t" \
343 " risbgn %[R_TMP],%[R_TMP3],54,63,0\n\t" /* Insert klmnopqrst. */ \
344 " nilf %[R_TMP3],0xfc00\n\t" \
345 " clfi %[R_TMP3],0xdc00\n\t" /* Check if it starts with 0xdc00. */ \
346 " jne 98f\n\t" \
347 " st %[R_TMP],0(%[R_OUT])\n\t" \
348 " la %[R_IN],4(%[R_IN])\n\t" \
349 " la %[R_OUT],4(%[R_OUT])\n\t" \
350 " aghi %[R_TMP2],-2\n\t" \
351 " jh 13b\n\t" /* Handle remaining uint16_t values. */ \
352 " j 0b\n\t" /* Switch to vx-loop. */ \
353 "96: \n\t" /* Return full output. */ \
354 " lghi %[R_RES],%[RES_OUT_FULL]\n\t" \
355 " j 99f\n\t" \
356 "97: \n\t" /* Return incomplete input. */ \
357 " lghi %[R_RES],%[RES_IN_FULL]\n\t" \
358 " j 99f\n\t" \
359 "98:\n\t" /* Return Illegal character. */ \
360 " lghi %[R_RES],%[RES_IN_ILL]\n\t" \
361 "99:\n\t" \
362 ".machine pop" \
363 : /* outputs */ [R_IN] "+a" (inptr) \
364 , [R_INLEN] "+d" (inlen), [R_OUT] "+a" (outptr) \
365 , [R_OUTLEN] "+d" (outlen), [R_TMP] "=a" (tmp) \
366 , [R_TMP2] "=d" (tmp2), [R_TMP3] "=a" (tmp3) \
367 , [R_RES] "+d" (result) \
368 : /* inputs */ \
369 [RES_OUT_FULL] "i" (__GCONV_FULL_OUTPUT) \
370 , [RES_IN_ILL] "i" (__GCONV_ILLEGAL_INPUT) \
371 , [RES_IN_FULL] "i" (__GCONV_INCOMPLETE_INPUT) \
372 : /* clobber list */ "memory", "cc" \
373 ASM_CLOBBER_VR ("v16") ASM_CLOBBER_VR ("v17") \
374 ASM_CLOBBER_VR ("v18") ASM_CLOBBER_VR ("v19") \
375 ASM_CLOBBER_VR ("v30") ASM_CLOBBER_VR ("v31") \
376 ); \
377 if (__glibc_likely (inptr == inend) \
378 || result != __GCONV_ILLEGAL_INPUT) \
379 break; \
381 STANDARD_FROM_LOOP_ERR_HANDLER (2); \
385 /* Generate loop-function with hardware vector instructions. */
386 # define MIN_NEEDED_INPUT MIN_NEEDED_FROM
387 # define MAX_NEEDED_INPUT MAX_NEEDED_FROM
388 # define MIN_NEEDED_OUTPUT MIN_NEEDED_TO
389 # define FROM_LOOP_VX __from_utf16_loop_vx
390 # define LOOPFCT FROM_LOOP_VX
391 # define LOOP_NEED_FLAGS
392 # define BODY BODY_FROM_VX
393 # include <iconv/loop.c>
394 #else
395 # define FROM_LOOP_VX NULL
396 #endif /* HAVE_FROM_VX != 1 */
399 /* Conversion from UTF-32 internal/BE to UTF-16. */
401 #if HAVE_TO_C == 1
402 /* The software routine is copied from utf-16.c (minus bytes
403 swapping). */
404 # define BODY_TO_C \
406 uint32_t c = get32 (inptr); \
408 if (__builtin_expect (c <= 0xd7ff, 1) \
409 || (c > 0xdfff && c <= 0xffff)) \
411 /* Two UTF-16 chars. */ \
412 put16 (outptr, c); \
414 else if (__builtin_expect (c >= 0x10000, 1) \
415 && __builtin_expect (c <= 0x10ffff, 1)) \
417 /* Four UTF-16 chars. */ \
418 uint16_t zabcd = ((c & 0x1f0000) >> 16) - 1; \
419 uint16_t out; \
421 /* Generate a surrogate character. */ \
422 if (__glibc_unlikely (outptr + 4 > outend)) \
424 /* Overflow in the output buffer. */ \
425 result = __GCONV_FULL_OUTPUT; \
426 break; \
429 out = 0xd800; \
430 out |= (zabcd & 0xff) << 6; \
431 out |= (c >> 10) & 0x3f; \
432 put16 (outptr, out); \
433 outptr += 2; \
435 out = 0xdc00; \
436 out |= c & 0x3ff; \
437 put16 (outptr, out); \
439 else \
441 STANDARD_TO_LOOP_ERR_HANDLER (4); \
443 outptr += 2; \
444 inptr += 4; \
447 /* Generate loop-function with software routing. */
448 # define MIN_NEEDED_INPUT MIN_NEEDED_TO
449 # define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
450 # define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM
451 # define TO_LOOP_C __to_utf16_loop_c
452 # define LOOPFCT TO_LOOP_C
453 # define LOOP_NEED_FLAGS
454 # define BODY BODY_TO_C
455 # include <iconv/loop.c>
456 #else
457 # define TO_LOOP_C NULL
458 #endif /* HAVE_TO_C != 1 */
460 #if HAVE_TO_VX == 1
461 # define BODY_TO_VX \
463 size_t inlen = inend - inptr; \
464 size_t outlen = outend - outptr; \
465 unsigned long tmp, tmp2, tmp3; \
466 asm volatile (".machine push\n\t" \
467 ".machine \"z13\"\n\t" \
468 ".machinemode \"zarch_nohighgprs\"\n\t" \
469 /* Setup to check for surrogates. */ \
470 " larl %[R_TMP],9f\n\t" \
471 " vlm %%v30,%%v31,0(%[R_TMP])\n\t" \
472 CONVERT_32BIT_SIZE_T ([R_INLEN]) \
473 CONVERT_32BIT_SIZE_T ([R_OUTLEN]) \
474 /* Loop which handles UTF-16 chars \
475 ch < 0xd800 || (ch > 0xdfff && ch < 0x10000). */ \
476 "0: clgijl %[R_INLEN],32,2f\n\t" \
477 " clgijl %[R_OUTLEN],16,2f\n\t" \
478 "1: vlm %%v16,%%v17,0(%[R_IN])\n\t" \
479 " lghi %[R_TMP2],0\n\t" \
480 /* Shorten to UTF-16. */ \
481 " vpkf %%v18,%%v16,%%v17\n\t" \
482 /* Check for surrogate chars. */ \
483 " vstrcfs %%v19,%%v16,%%v30,%%v31\n\t" \
484 " jno 10f\n\t" \
485 " vstrcfs %%v19,%%v17,%%v30,%%v31\n\t" \
486 " jno 11f\n\t" \
487 /* Store 16 bytes to buf_out. */ \
488 " vst %%v18,0(%[R_OUT])\n\t" \
489 " la %[R_IN],32(%[R_IN])\n\t" \
490 " aghi %[R_INLEN],-32\n\t" \
491 " aghi %[R_OUTLEN],-16\n\t" \
492 " la %[R_OUT],16(%[R_OUT])\n\t" \
493 " clgijl %[R_INLEN],32,2f\n\t" \
494 " clgijl %[R_OUTLEN],16,2f\n\t" \
495 " j 1b\n\t" \
496 /* Calculate remaining uint32_t values in inptr. */ \
497 "2: \n\t" \
498 " clgije %[R_INLEN],0,99f\n\t" \
499 " clgijl %[R_INLEN],4,92f\n\t" \
500 " srlg %[R_TMP2],%[R_INLEN],2\n\t" \
501 " j 20f\n\t" \
502 /* Setup to check for ch >= 0xd800 && ch <= 0xdfff \
503 and check for ch >= 0x10000. (v30, v31) */ \
504 "9: .long 0xd800,0xdfff,0x10000,0x10000\n\t" \
505 " .long 0xa0000000,0xc0000000, 0xa0000000,0xa0000000\n\t" \
506 /* At least on UTF32 char is in range of surrogates. \
507 Store the preceding characters. */ \
508 "11: ahi %[R_TMP2],16\n\t" \
509 "10: vlgvb %[R_TMP],%%v19,7\n\t" \
510 " agr %[R_TMP],%[R_TMP2]\n\t" \
511 " srlg %[R_TMP3],%[R_TMP],1\n\t" /* Number of out bytes. */ \
512 " ahik %[R_TMP2],%[R_TMP3],-1\n\t" /* Highest index to store. */ \
513 " jl 12f\n\t" \
514 " vstl %%v18,%[R_TMP2],0(%[R_OUT])\n\t" \
515 /* Update pointers. */ \
516 " la %[R_IN],0(%[R_TMP],%[R_IN])\n\t" \
517 " slgr %[R_INLEN],%[R_TMP]\n\t" \
518 " la %[R_OUT],0(%[R_TMP3],%[R_OUT])\n\t" \
519 " slgr %[R_OUTLEN],%[R_TMP3]\n\t" \
520 /* Calculate remaining uint32_t values in vrs. */ \
521 "12: lghi %[R_TMP2],8\n\t" \
522 " srlg %[R_TMP3],%[R_TMP3],1\n\t" \
523 " slgr %[R_TMP2],%[R_TMP3]\n\t" \
524 /* Handle remaining UTF-32 characters. */ \
525 "20: l %[R_TMP],0(%[R_IN])\n\t" \
526 " aghi %[R_INLEN],-4\n\t" \
527 /* Test if ch is 2byte UTF-16 char. */ \
528 " clfi %[R_TMP],0xffff\n\t" \
529 " jh 21f\n\t" \
530 /* Handle 2 byte UTF16 char. */ \
531 " lgr %[R_TMP3],%[R_TMP]\n\t" \
532 " nilf %[R_TMP],0xf800\n\t" \
533 " clfi %[R_TMP],0xd800\n\t" \
534 " je 91f\n\t" /* Do not accept UTF-16 surrogates. */ \
535 " slgfi %[R_OUTLEN],2\n\t" \
536 " jl 90f \n\t" \
537 " sth %[R_TMP3],0(%[R_OUT])\n\t" \
538 " la %[R_IN],4(%[R_IN])\n\t" \
539 " la %[R_OUT],2(%[R_OUT])\n\t" \
540 " brctg %[R_TMP2],20b\n\t" \
541 " j 0b\n\t" /* Switch to vx-loop. */ \
542 /* Test if ch is 4byte UTF-16 char. */ \
543 "21: clfi %[R_TMP],0x10ffff\n\t" \
544 " jh 91f\n\t" /* ch > 0x10ffff is not allowed! */ \
545 /* Handle 4 byte UTF16 char. */ \
546 " slgfi %[R_OUTLEN],4\n\t" \
547 " jl 90f \n\t" \
548 " slfi %[R_TMP],0x10000\n\t" /* zabcd = uvwxy - 1. */ \
549 " llilf %[R_TMP3],0xd800dc00\n\t" \
550 " la %[R_IN],4(%[R_IN])\n\t" \
551 " risbgn %[R_TMP3],%[R_TMP],38,47,6\n\t" /* High surrogate. */ \
552 " risbgn %[R_TMP3],%[R_TMP],54,63,0\n\t" /* Low surrogate. */ \
553 " st %[R_TMP3],0(%[R_OUT])\n\t" \
554 " la %[R_OUT],4(%[R_OUT])\n\t" \
555 " brctg %[R_TMP2],20b\n\t" \
556 " j 0b\n\t" /* Switch to vx-loop. */ \
557 "92: lghi %[R_RES],%[RES_IN_FULL]\n\t" \
558 " j 99f\n\t" \
559 "91: lghi %[R_RES],%[RES_IN_ILL]\n\t" \
560 " j 99f\n\t" \
561 "90: lghi %[R_RES],%[RES_OUT_FULL]\n\t" \
562 "99: \n\t" \
563 ".machine pop" \
564 : /* outputs */ [R_IN] "+a" (inptr) \
565 , [R_INLEN] "+d" (inlen), [R_OUT] "+a" (outptr) \
566 , [R_OUTLEN] "+d" (outlen), [R_TMP] "=a" (tmp) \
567 , [R_TMP2] "=d" (tmp2), [R_TMP3] "=a" (tmp3) \
568 , [R_RES] "+d" (result) \
569 : /* inputs */ \
570 [RES_OUT_FULL] "i" (__GCONV_FULL_OUTPUT) \
571 , [RES_IN_ILL] "i" (__GCONV_ILLEGAL_INPUT) \
572 , [RES_IN_FULL] "i" (__GCONV_INCOMPLETE_INPUT) \
573 : /* clobber list */ "memory", "cc" \
574 ASM_CLOBBER_VR ("v16") ASM_CLOBBER_VR ("v17") \
575 ASM_CLOBBER_VR ("v18") ASM_CLOBBER_VR ("v19") \
576 ASM_CLOBBER_VR ("v30") ASM_CLOBBER_VR ("v31") \
577 ); \
578 if (__glibc_likely (inptr == inend) \
579 || result != __GCONV_ILLEGAL_INPUT) \
580 break; \
582 STANDARD_TO_LOOP_ERR_HANDLER (4); \
585 /* Generate loop-function with hardware vector instructions. */
586 # define MIN_NEEDED_INPUT MIN_NEEDED_TO
587 # define MIN_NEEDED_OUTPUT MIN_NEEDED_FROM
588 # define MAX_NEEDED_OUTPUT MAX_NEEDED_FROM
589 # define TO_LOOP_VX __to_utf16_loop_vx
590 # define LOOPFCT TO_LOOP_VX
591 # define LOOP_NEED_FLAGS
592 # define BODY BODY_TO_VX
593 # include <iconv/loop.c>
594 #else
595 # define TO_LOOP_VX NULL
596 #endif /* HAVE_TO_VX != 1 */
598 /* This file also exists in sysdeps/s390/multiarch/ which
599 generates ifunc resolvers for FROM/TO_LOOP functions
600 and includes iconv/skeleton.c afterwards. */
601 #if ! defined USE_MULTIARCH
602 # include <iconv/skeleton.c>
603 #endif