summary refs log tree commit diff
path: root/iconv
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-03-28 17:33:37 +0000
committerUlrich Drepper <drepper@redhat.com>2000-03-28 17:33:37 +0000
commit77e1d15a1afea1189e6aab66cc6e0ce30e3275ce (patch)
tree78849a20d1b650791f0a8d9d53404ef21057dd24 /iconv
parentb35e58e479cd23ff64ad83a30c6670e355a7d642 (diff)
downloadglibc-77e1d15a1afea1189e6aab66cc6e0ce30e3275ce.tar.gz
glibc-77e1d15a1afea1189e6aab66cc6e0ce30e3275ce.tar.xz
glibc-77e1d15a1afea1189e6aab66cc6e0ce30e3275ce.zip
Update.
2000-03-28  Ulrich Drepper  <drepper@redhat.com>

	* iconvdata/TESTS: Use UCS-2BE instead of UCS2.

	* iconv/loop.c: Define get16, get32, put16, and put32 macros to
	allow as well reading from/writing to unaligned addresses on machines
	which don't support this in hardware.  Use FCTNAME macro to define
	function name.  Include the file a second time for platforms which
	need special unaligned handling.
	* iconv/skeleton.c: Define get16u, get32u, put16u, and put32u macros
	to access potentially unaligned addresses.  These macros are intended
	to be used only outside the loops.
	(unaligned): New definition.  In case the machine can handle unaligned
	access define as zero.  Otherwise as a variable which is initialized
	as nonzero in case the buffer passed in at runtime is unaligned with
	respect to the character set encoding involved.
	Call aligned or unaligned looop functions according to unaligned
	variable.
	* iconvdata/8bit-gap.c: Use get16, get32, put16, and put32 instead
	of direct casting pointer to potentially handle unaligned memory
	accesses.
	* iconvdata/8bit-generic.c: Likewise.
	* iconvdata/ansi_x3.110.c: Likewise.
	* iconvdata/big5.c: Likewise.
	* iconvdata/euc-cn.c: Likewise.
	* iconvdata/euc-jp.c: Likewise.
	* iconvdata/euc-kr.c: Likewise.
	* iconvdata/euc-tw.c: Likewise.
	* iconvdata/gbk.c: Likewise.
	* iconvdata/iso-2022-cn.c: Likewise.
	* iconvdata/iso-2022-jp.c: Likewise.
	* iconvdata/iso-2022-kr.c: Likewise.
	* iconvdata/iso646.c: Likewise.
	* iconvdata/iso_6937-2.c: Likewise.
	* iconvdata/iso_6937.c: Likewise.
	* iconvdata/johab.c: Likewise.
	* iconvdata/sjis.c: Likewise.
	* iconvdata/t.61.c: Likewise.
	* iconvdata/uhc.c: Likewise.
	* iconvdata/unicode.c: Likewise.
	* iconvdata/utf-16.c: Likewise.

	* locale/programs/simple-hash.c: Little optimizations.  Remove K&R
	prototypes.

	* malloc/Versions [libc] (GLIBC_2.2): Add mcheck_check_all.
	* malloc/mcheck.c (mcheck_check_all): Renamed from check_all and made
	public.
	* malloc/mcheck.h (mcheck_check_all): Declare.

	* stdio-common/Makefile (tests): Add tst-obprintf.
Diffstat (limited to 'iconv')
-rw-r--r--iconv/skeleton.c132
1 files changed, 123 insertions, 9 deletions
diff --git a/iconv/skeleton.c b/iconv/skeleton.c
index 726a76f00e..ad381ec77c 100644
--- a/iconv/skeleton.c
+++ b/iconv/skeleton.c
@@ -117,6 +117,73 @@ static int to_object;
 #endif
 
 
+/* Define macros which can access unaligned buffers.  These macros are
+   supposed to be used only in code outside the inner loops.  For the inner
+   loops we have other definitions which allow optimized access.  */
+#ifdef _STRING_ARCH_unaligned
+/* We can handle unaligned memory access.  */
+# define get16(addr) *((uint16_t *) (addr))
+# define get32(addr) *((uint32_t *) (addr))
+
+/* We need no special support for writing values either.  */
+# define put16(addr, val) *((uint16_t *) (addr)) = (val)
+# define put32(addr, val) *((uint32_t *) (addr)) = (val)
+#else
+/* Distinguish between big endian and little endian.  */
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+#  define get16(addr) \
+     (((__const unsigned char *) (addr))[1] << 8			      \
+      | ((__const unsigned char *) (addr))[0])
+#  define get32(addr) \
+     (((((__const unsigned char *) (addr))[3] << 8			      \
+	| ((__const unsigned char *) (addr))[2]) << 8			      \
+       | ((__const unsigned char *) (addr))[1]) << 8			      \
+      | ((__const unsigned char *) (addr))[0])
+
+# define put16(addr, val) \
+     ({ uint16_t __val = (val);						      \
+	((__const unsigned char *) (addr))[0] = __val;			      \
+	((__const unsigned char *) (addr))[1] = __val >> 8;		      \
+	(void) 0; })
+# define put32(addr, val) \
+     ({ uint16_t __val = (val);						      \
+	((__const unsigned char *) (addr))[0] = __val;			      \
+	__val >>= 8;							      \
+	((__const unsigned char *) (addr))[1] = __val;			      \
+	__val >>= 8;							      \
+	((__const unsigned char *) (addr))[2] = __val;			      \
+	__val >>= 8;							      \
+	((__const unsigned char *) (addr))[3] = __val;			      \
+	(void) 0; })
+# else
+#  define get16(addr) \
+     (((__const unsigned char *) (addr))[0] << 8			      \
+      | ((__const unsigned char *) (addr))[1])
+#  define get32(addr) \
+     (((((__const unsigned char *) (addr))[0] << 8			      \
+	| ((__const unsigned char *) (addr))[1]) << 8			      \
+       | ((__const unsigned char *) (addr))[2]) << 8			      \
+      | ((__const unsigned char *) (addr))[3])
+
+# define put16(addr, val) \
+     ({ uint16_t __val = (val);						      \
+	((__const unsigned char *) (addr))[1] = __val;			      \
+	((__const unsigned char *) (addr))[2] = __val >> 8;		      \
+	(void) 0; })
+# define put32(addr, val) \
+     ({ uint16_t __val = (val);						      \
+	((__const unsigned char *) (addr))[3] = __val;			      \
+	__val >>= 8;							      \
+	((__const unsigned char *) (addr))[2] = __val;			      \
+	__val >>= 8;							      \
+	((__const unsigned char *) (addr))[1] = __val;			      \
+	__val >>= 8;							      \
+	((__const unsigned char *) (addr))[0] = __val;			      \
+	(void) 0; })
+# endif
+#endif
+
+
 /* For conversions from a fixed width character sets to another fixed width
    character set we we can define RESET_INPUT_BUFFER is necessary.  */
 #if !defined RESET_INPUT_BUFFER && !defined SAVE_RESET_STATE
@@ -230,6 +297,33 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data,
       unsigned char *outbuf = data->__outbuf;
       unsigned char *outend = data->__outbufend;
       unsigned char *outstart;
+#ifdef _STRING_ARCH_unaligned
+# define unaligned 0
+#else
+      /* The following assumes that encodings, which have a variable length
+	 what might unalign a buffer even though it is a aligned in the
+	 beginning, either don't have the minimal number of bytes as a divisor
+	 of the maximum length or have a minimum length of 1.  This is true
+	 for all known and supported encodings.  */
+      int unaligned;
+
+      unaligned = ((FROM_DIRECTION
+		    && ((MIN_NEEDED_FROM > 1
+			 && MAX_NEEDED_FROM % MIN_NEEDED_FROM == 0
+			 && (uintptr_t) inptr % MIN_NEEDED_FROM != 0)
+			|| (MIN_NEEDED_TO > 1
+			    && MAX_NEEDED_TO % MIN_NEEDED_TO == 0
+			    && (uintptr_t) outbuf % MIN_NEEDED_TO != 0)))
+		   || (!FROM_DIRECTION
+		       && ((MIN_NEEDED_FROM > 1
+			    && MAX_NEEDED_FROM % MIN_NEEDED_FROM == 0
+			    && (uintptr_t) outbuf % MIN_NEEDED_FROM != 0)
+			   || (MIN_NEEDED_TO > 1
+			       && MAX_NEEDED_TO % MIN_NEEDED_TO == 0
+			       && (uintptr_t) inptr % MIN_NEEDED_TO != 0))));
+# define GEN_unaligned(name) GEN_unaligned2 (name)
+# define GEN_unaligned2(name) name##_unaligned
+#endif
 
       /* This variable is used to count the number of characters we
 	 actually converted.  */
@@ -250,16 +344,36 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data,
 	  SAVE_RESET_STATE (1);
 #endif
 
-	  if (FROM_DIRECTION)
-	    /* Run the conversion loop.  */
-	    status = FROM_LOOP (inbuf, inbufend, &outbuf, outend,
-				data->__statep, step->__data, &converted
-				EXTRA_LOOP_ARGS);
+	  if (!unaligned)
+	    {
+	      if (FROM_DIRECTION)
+		/* Run the conversion loop.  */
+		status = FROM_LOOP (inbuf, inbufend, &outbuf, outend,
+				    data->__statep, step->__data, &converted
+				    EXTRA_LOOP_ARGS);
+	      else
+		/* Run the conversion loop.  */
+		status = TO_LOOP (inbuf, inbufend, &outbuf, outend,
+				  data->__statep, step->__data, &converted
+				  EXTRA_LOOP_ARGS);
+	    }
+#ifndef _STRING_ARCH_unaligned
 	  else
-	    /* Run the conversion loop.  */
-	    status = TO_LOOP (inbuf, inbufend, &outbuf, outend,
-			      data->__statep, step->__data, &converted
-			      EXTRA_LOOP_ARGS);
+	    {
+	      if (FROM_DIRECTION)
+		/* Run the conversion loop.  */
+		status = GEN_unaligned (FROM_LOOP) (inbuf, inbufend, &outbuf,
+						    outend, data->__statep,
+						    step->__data, &converted
+						    EXTRA_LOOP_ARGS);
+	      else
+		/* Run the conversion loop.  */
+		status = GEN_unaligned (TO_LOOP) (inbuf, inbufend, &outbuf,
+						  outend, data->__statep,
+						  step->__data, &converted
+						  EXTRA_LOOP_ARGS);
+	    }
+#endif
 
 	  /* We finished one use of the loops.  */
 	  ++data->__invocation_counter;