shithub: h264bsd

Download patch

ref: 4b7065cc238365afc13bd3a92c500b4629ea629b
parent: fbf22d9c44e81ab5593664bdf77d6f7a0bc63770
author: Sigrid Haflínudóttir <[email protected]>
date: Tue Sep 15 16:32:33 EDT 2020

add faster x86 version of clz

--- /dev/null
+++ b/src/clz.386.s
@@ -1,0 +1,4 @@
+TEXT h264bsdCountLeadingZeros(SB),$0
+	BYTE $0x0F; BYTE $0xBD; BYTE $0xC5 /* BSRL RARG, AX */
+	XORL $31, AX
+	RET
--- /dev/null
+++ b/src/clz.amd64.s
@@ -1,0 +1,4 @@
+TEXT h264bsdCountLeadingZeros(SB),$0
+	BYTE $0x0F; BYTE $0xBD; BYTE $0xC5 /* BSRL RARG, AX */
+	XORL $31, AX
+	RET
--- a/src/h264bsd_util.c
+++ b/src/h264bsd_util.c
@@ -68,7 +68,6 @@
 
         Inputs:
             value   code word
-            length  number of bits in the code word
 
         Outputs:
             none
@@ -77,26 +76,14 @@
             number of leading zeros in the code word
 
 ------------------------------------------------------------------------------*/
-#ifndef H264DEC_NEON
-u32 h264bsdCountLeadingZeros(u32 value, u32 length)
+#ifndef __plan9__
+u32 h264bsdCountLeadingZeros(u32 value)
 {
-
-/* Variables */
-
-    u32 zeros = 0;
-    u32 mask = 1 << (length - 1);
-
-/* Code */
-
-    ASSERT(length <= 32);
-
-    while (mask && !(value & mask))
-    {
-        zeros++;
-        mask >>= 1;
-    }
-    return(zeros);
-
+    unsigned int r;
+    if(x == 0)
+        return 32;
+    for(r = 0; (x & (1UL<<31)) == 0; x <<= 1, r++);
+    return r;
 }
 #endif
 /*------------------------------------------------------------------------------
--- a/src/h264bsd_util.h
+++ b/src/h264bsd_util.h
@@ -163,11 +163,7 @@
 /*------------------------------------------------------------------------------
     4. Function prototypes
 ------------------------------------------------------------------------------*/
-#ifndef H264DEC_NEON
-u32 h264bsdCountLeadingZeros(u32 value, u32 length);
-#else
 u32 h264bsdCountLeadingZeros(u32 value);
-#endif
 u32 h264bsdRbspTrailingBits(strmData_t *strmData);
 
 u32 h264bsdMoreRbspData(strmData_t *strmData);
--- a/src/h264bsd_vlc.c
+++ b/src/h264bsd_vlc.c
@@ -150,11 +150,7 @@
     /* other code lengths */
     else
     {
-#ifndef H264DEC_NEON
-        numZeros = 4 + h264bsdCountLeadingZeros(bits, 28);
-#else
         numZeros = h264bsdCountLeadingZeros(bits);
-#endif
         /* all 32 bits are zero */
         if (numZeros == 32)
         {
--- a/src/mkfile
+++ b/src/mkfile
@@ -34,6 +34,7 @@
 	h264bsd_vui.h\
 
 OFILES=\
+	clz.$objtype.$O\
 	h264bsd_byte_stream.$O\
 	h264bsd_cavlc.$O\
 	h264bsd_conceal.$O\
@@ -61,7 +62,4 @@
 	h264bsd_vlc.$O\
 	h264bsd_vui.$O\
 
-/sys/include/%.h:
-	cp ../include/$stem.h /sys/include/$stem.h
-
-</sys/src/cmd/mksyslib
+</sys/src/cmd/mklib