Module Name:    src
Committed By:   tls
Date:           Mon Apr  7 01:10:55 UTC 2014

Modified Files:
        src/external/bsd/liblzf/dist [tls-earlyentropy]: lzfP.h lzf_c.c lzf_d.c
        src/sys/lib/libkern [tls-earlyentropy]: Makefile.libkern libkern.h

Log Message:
LZF in the kernel.  As an entropy estimator for now but it's very small, and
we could use it for ipcomp, for hibernation, for paging, for core dumps, etc.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.3.8.1 src/external/bsd/liblzf/dist/lzfP.h
cvs rdiff -u -r1.4 -r1.4.8.1 src/external/bsd/liblzf/dist/lzf_c.c
cvs rdiff -u -r1.3 -r1.3.22.1 src/external/bsd/liblzf/dist/lzf_d.c
cvs rdiff -u -r1.32 -r1.32.2.1 src/sys/lib/libkern/Makefile.libkern
cvs rdiff -u -r1.113 -r1.113.2.1 src/sys/lib/libkern/libkern.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/liblzf/dist/lzfP.h
diff -u src/external/bsd/liblzf/dist/lzfP.h:1.3 src/external/bsd/liblzf/dist/lzfP.h:1.3.8.1
--- src/external/bsd/liblzf/dist/lzfP.h:1.3	Sun Sep 16 18:59:27 2012
+++ src/external/bsd/liblzf/dist/lzfP.h	Mon Apr  7 01:10:55 2014
@@ -37,22 +37,21 @@
 #ifndef LZFP_h
 #define LZFP_h
 
-#define STANDALONE 1 /* at the moment, this is ok. */
-
-#ifndef STANDALONE
-# include "lzf.h"
+#if !defined(_KERNEL) && !defined(_STANDALONE)
+#include <sys/types.h>
+#include <inttypes.h>
 #endif
 
 /*
- * Size of hashtable is (1 << HLOG) * sizeof (char *)
+ * Size of hashtable is (1 << LZF_HLOG) * sizeof (char *)
  * decompression is independent of the hash table size
  * the difference between 15 and 14 is very small
  * for small blocks (and 14 is usually a bit faster).
- * For a low-memory/faster configuration, use HLOG == 13;
+ * For a low-memory/faster configuration, use LZF_HLOG == 13;
  * For best compression, use 15 or 16 (or more, up to 23).
  */
-#ifndef HLOG
-# define HLOG 16
+#ifndef LZF_HLOG
+# define LZF_HLOG 16
 #endif
 
 /*
@@ -77,9 +76,12 @@
 
 /*
  * Unconditionally aligning does not cost very much, so do it if unsure
+ *
+ * In fact, on modern x86 processors, strict alignment is faster whether
+ * in 32 or 64 bit mode.
  */
-#ifndef STRICT_ALIGN
-# define STRICT_ALIGN !(defined(__i386) || defined (__amd64))
+#ifndef STRICT_ALIGN	
+# define STRICT_ALIGN 1 /* !(defined(__i386) || defined (__amd64)) */
 #endif
 
 /*
@@ -124,21 +126,11 @@
 /*****************************************************************************/
 /* nothing should be changed below */
 
-typedef unsigned char u8;
-
-typedef const u8 *LZF_STATE[1 << (HLOG)];
+typedef uint8_t u8;
+typedef uint16_t u16;
 
-#if !STRICT_ALIGN
-/* for unaligned accesses we need a 16 bit datatype. */
-# include <limits.h>
-# if USHRT_MAX == 65535
-    typedef unsigned short u16;
-# elif UINT_MAX == 65535
-    typedef unsigned int u16;
-# else
-#  undef STRICT_ALIGN
-#  define STRICT_ALIGN 1
-# endif
+#if !defined(_KERNEL) && !defined(STANDALONE)
+typedef const u8 *LZF_STATE[1 << (LZF_HLOG)];
 #endif
 
 #if ULTRA_FAST

Index: src/external/bsd/liblzf/dist/lzf_c.c
diff -u src/external/bsd/liblzf/dist/lzf_c.c:1.4 src/external/bsd/liblzf/dist/lzf_c.c:1.4.8.1
--- src/external/bsd/liblzf/dist/lzf_c.c:1.4	Sun Sep 16 18:59:27 2012
+++ src/external/bsd/liblzf/dist/lzf_c.c	Mon Apr  7 01:10:55 2014
@@ -34,9 +34,14 @@
  * either the BSD or the GPL.
  */
 
+#if defined(_KERNEL) || defined (_STANDALONE)
+#include <lib/libkern/libkern.h>
+#include "lzfP.h"
+#else
 #include "lzf.h"
+#endif
 
-#define HSIZE (1 << (HLOG))
+#define HSIZE (1 << (LZF_HLOG))
 
 /*
  * don't play with this unless you benchmark!
@@ -48,16 +53,16 @@
 # define FRST(p) (((p[0]) << 8) | p[1])
 # define NEXT(v,p) (((v) << 8) | p[2])
 # if ULTRA_FAST
-#  define IDX(h) ((( h             >> (3*8 - HLOG)) - h  ) & (HSIZE - 1))
+#  define IDX(h) ((( h             >> (3*8 - LZF_HLOG)) - h  ) & (HSIZE - 1))
 # elif VERY_FAST
-#  define IDX(h) ((( h             >> (3*8 - HLOG)) - h*5) & (HSIZE - 1))
+#  define IDX(h) ((( h             >> (3*8 - LZF_HLOG)) - h*5) & (HSIZE - 1))
 # else
-#  define IDX(h) ((((h ^ (h << 5)) >> (3*8 - HLOG)) - h*5) & (HSIZE - 1))
+#  define IDX(h) ((((h ^ (h << 5)) >> (3*8 - LZF_HLOG)) - h*5) & (HSIZE - 1))
 # endif
 #endif
 /*
  * IDX works because it is very similar to a multiplicative hash, e.g.
- * ((h * 57321 >> (3*8 - HLOG)) & (HSIZE - 1))
+ * ((h * 57321 >> (3*8 - LZF_HLOG)) & (HSIZE - 1))
  * the latter is also quite fast on newer CPUs, and compresses similarly.
  *
  * the next one is also quite good, albeit slow ;)
@@ -147,7 +152,7 @@ lzf_compress_r (const void *const in_dat
 #endif
           && (off = ip - ref - 1) < MAX_OFF
           && ip + 4 < in_end
-          && ref > (u8 *)in_data
+          && ref > (const u8 *)in_data
 #if STRICT_ALIGN
           && ref[0] == ip[0]
           && ref[1] == ip[1]

Index: src/external/bsd/liblzf/dist/lzf_d.c
diff -u src/external/bsd/liblzf/dist/lzf_d.c:1.3 src/external/bsd/liblzf/dist/lzf_d.c:1.3.22.1
--- src/external/bsd/liblzf/dist/lzf_d.c:1.3	Tue Apr  5 06:24:42 2011
+++ src/external/bsd/liblzf/dist/lzf_d.c	Mon Apr  7 01:10:55 2014
@@ -34,13 +34,23 @@
  * either the BSD or the GPL.
  */
 
+#if defined(_KERNEL) || defined (_STANDALONE)
+#include <lib/libkern/libkern.h>
+#include <sys/systm.h>
+#include "lzfP.h"
+#else
 #include "lzf.h"
+#endif
 
-#if AVOID_ERRNO
-# define SET_ERRNO(n)
+#ifdef _KERNEL
+# define SET_ERRNO(n) panic("lzf decompression failure: %s", #n)
 #else
-# include <errno.h>
-# define SET_ERRNO(n) errno = (n)
+# ifdef AVOID_ERRNO
+#  define SET_ERRNO(n)
+# else
+#  include <errno.h>
+#  define SET_ERRNO(n) errno = (n)
+# endif
 #endif
 
 #if (__i386 || __amd64) && __GNUC__ >= 3

Index: src/sys/lib/libkern/Makefile.libkern
diff -u src/sys/lib/libkern/Makefile.libkern:1.32 src/sys/lib/libkern/Makefile.libkern:1.32.2.1
--- src/sys/lib/libkern/Makefile.libkern:1.32	Wed Mar 12 00:22:53 2014
+++ src/sys/lib/libkern/Makefile.libkern	Mon Apr  7 01:10:55 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.libkern,v 1.32 2014/03/12 00:22:53 pooka Exp $
+#	$NetBSD: Makefile.libkern,v 1.32.2.1 2014/04/07 01:10:55 tls Exp $
 
 # 
 # Variable definitions for libkern.  
@@ -94,6 +94,9 @@ SRCS+=	explicit_memset.c consttime_memeq
 SRCS+=	cdbr.c
 SRCS+=	mi_vector_hash.c
 
+.PATH:	${NETBSDSRCDIR}/external/bsd/liblzf/dist
+SRCS+=	lzf_c.c lzf_d.c
+
 # Files to clean up
 CLEANFILES+= lib${LIB}.o lib${LIB}.po
 

Index: src/sys/lib/libkern/libkern.h
diff -u src/sys/lib/libkern/libkern.h:1.113 src/sys/lib/libkern/libkern.h:1.113.2.1
--- src/sys/lib/libkern/libkern.h:1.113	Thu Feb 27 18:05:07 2014
+++ src/sys/lib/libkern/libkern.h	Mon Apr  7 01:10:55 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: libkern.h,v 1.113 2014/02/27 18:05:07 joerg Exp $	*/
+/*	$NetBSD: libkern.h,v 1.113.2.1 2014/04/07 01:10:55 tls Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -379,4 +379,22 @@ unsigned int	popcount64(uint64_t) __cons
 
 void	*explicit_memset(void *, int, size_t);
 int	consttime_memequal(const void *, const void *, size_t);
+
+/*
+ * LZF hashtable/state size: on uncompressible data and on a system with
+ * a sufficiently large d-cache, a larger table produces a considerable
+ * speed benefit.  On systems with small memory and caches, however...
+ */
+#if defined(__vax__) || defined(__m68k__)
+#define LZF_HLOG 14
+#else
+#define LZF_HLOG 15
+#endif
+typedef const uint8_t *LZF_STATE[1 << LZF_HLOG];
+
+unsigned int lzf_compress_r (const void *const, unsigned int, void *,
+			     unsigned int, LZF_STATE);
+unsigned int lzf_decompress (const void *const, unsigned int, void *,
+			     unsigned int);
+
 #endif /* !_LIB_LIBKERN_LIBKERN_H_ */

Reply via email to