-#if defined(ARCH_X86) || defined(ARCH_X86_64) || defined(ARCH_POWERPC)
-#if defined(ARCH_X86_64)
-static inline uint64_t read_time(void)
-{
- uint64_t a, d;
- asm volatile( "rdtsc\n\t"
- : "=a" (a), "=d" (d)
- );
- return (d << 32) | (a & 0xffffffff);
-}
-#elif defined(ARCH_X86)
-static inline long long read_time(void)
-{
- long long l;
- asm volatile( "rdtsc\n\t"
- : "=A" (l)
- );
- return l;
-}
-#else //FIXME check ppc64
-static inline uint64_t read_time(void)
-{
- uint32_t tbu, tbl, temp;
-
- /* from section 2.2.1 of the 32-bit PowerPC PEM */
- __asm__ __volatile__(
- "1:\n"
- "mftbu %2\n"
- "mftb %0\n"
- "mftbu %1\n"
- "cmpw %2,%1\n"
- "bne 1b\n"
- : "=r"(tbl), "=r"(tbu), "=r"(temp)
- :
- : "cc");
-
- return (((uint64_t)tbu)<<32) | (uint64_t)tbl;
-}
-#endif
-
-#define START_TIMER \
-uint64_t tend;\
-uint64_t tstart= read_time();\
-
-#define STOP_TIMER(id) \
-tend= read_time();\
-{\
- static uint64_t tsum=0;\
- static int tcount=0;\
- static int tskip_count=0;\
- if(tcount<2 || tend - tstart < 8*tsum/tcount){\
- tsum+= tend - tstart;\
- tcount++;\
- }else\
- tskip_count++;\
- if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\
- av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\
- }\
-}
-#else
-#define START_TIMER
-#define STOP_TIMER(id) {}
-#endif
-
-/* memory */
-
-#ifdef __GNUC__
- #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
-#else
- #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
-#endif
+/*!
+ * \def GET_UTF16(val, GET_16BIT, ERROR)
+ * Converts a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form
+ * \param val is the output and should be of type uint32_t. It holds the converted
+ * UCS-4 character and should be a left value.
+ * \param GET_16BIT gets two bytes of UTF-16 encoded data converted to native endianness.
+ * It can be a function or a statement whose return value or evaluated value is of type
+ * uint16_t. It will be executed up to 2 times.
+ * \param ERROR action that should be taken when an invalid UTF-16 surrogate is
+ * returned from GET_BYTE. It should be a statement that jumps out of the macro,
+ * like exit(), goto, return, break, or continue.
+ */
+#define GET_UTF16(val, GET_16BIT, ERROR)\
+ val = GET_16BIT;\
+ {\
+ unsigned int hi = val - 0xD800;\
+ if (hi < 0x800) {\
+ val = GET_16BIT - 0xDC00;\
+ if (val > 0x3FFU || hi > 0x3FFU)\
+ ERROR\
+ val += (hi<<10) + 0x10000;\
+ }\
+ }\
+
+/*!
+ * \def PUT_UTF8(val, tmp, PUT_BYTE)
+ * Converts a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long).
+ * \param val is an input-only argument and should be of type uint32_t. It holds
+ * a UCS-4 encoded Unicode character that is to be converted to UTF-8. If
+ * val is given as a function it is executed only once.
+ * \param tmp is a temporary variable and should be of type uint8_t. It
+ * represents an intermediate value during conversion that is to be
+ * output by PUT_BYTE.
+ * \param PUT_BYTE writes the converted UTF-8 bytes to any proper destination.
+ * It could be a function or a statement, and uses tmp as the input byte.
+ * For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be
+ * executed up to 4 times for values in the valid UTF-8 range and up to
+ * 7 times in the general case, depending on the length of the converted
+ * Unicode character.
+ */
+#define PUT_UTF8(val, tmp, PUT_BYTE)\
+ {\
+ int bytes, shift;\
+ uint32_t in = val;\
+ if (in < 0x80) {\
+ tmp = in;\
+ PUT_BYTE\
+ } else {\
+ bytes = (av_log2(in) + 4) / 5;\
+ shift = (bytes - 1) * 6;\
+ tmp = (256 - (256 >> bytes)) | (in >> shift);\
+ PUT_BYTE\
+ while (shift >= 6) {\
+ shift -= 6;\
+ tmp = 0x80 | ((in >> shift) & 0x3f);\
+ PUT_BYTE\
+ }\
+ }\
+ }