wok diff memtest64/stuff/unlzsa1.S @ rev 25514

Add memtest64
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Feb 16 14:18:05 2023 +0000 (16 months ago)
parents
children f2b4a9eb8bdd
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/memtest64/stuff/unlzsa1.S	Thu Feb 16 14:18:05 2023 +0000
     1.3 @@ -0,0 +1,197 @@
     1.4 +// Lzsa1Decode:
     1.5 +#ifndef FLAT32
     1.6 +//   input   ds:si=inStream, es:di=outStream
     1.7 +//   output  outStream[], ds:si, es:di
     1.8 +	.code16
     1.9 +#define AX	%ax
    1.10 +#define BX	%bx
    1.11 +#define SI	%si
    1.12 +#define DI	%di
    1.13 +#else
    1.14 +//   input   esi=inStream, edi=outStream
    1.15 +//   output  outStream[], ds:esi, es:edi
    1.16 +	.code32
    1.17 +#define AX	%eax
    1.18 +#define BX	%ebx
    1.19 +#define SI	%esi
    1.20 +#define DI	%edi
    1.21 +#endif
    1.22 +
    1.23 +MATCH_RUN_LEN		=	15
    1.24 +LITERALS_RUN_LEN	=	7
    1.25 +MIN_MATCH_SIZE		=	3
    1.26 +MIN_LITERALS_SIZE	=	0
    1.27 +
    1.28 +#define PACKED_ONLY			// assume no copy block, optional
    1.29 +//#define PARANOIA			// cover rare cases, optional
    1.30 + 
    1.31 +lzsa1main:
    1.32 +#ifdef PARANOIA
    1.33 +	cld
    1.34 +#endif
    1.35 +#ifdef FLAT16OUT
    1.36 +#define RAW_FORMAT
    1.37 +#endif
    1.38 +#ifndef RAW_FORMAT
    1.39 +# if defined(PARANOIA) && !defined(FLAT32) && !defined(FLAT16)
    1.40 +	xorw	%cx, %cx
    1.41 +	call	normalize
    1.42 +# endif
    1.43 +# ifndef NO_LZSA1_HEADER
    1.44 +	lodsw
    1.45 +	cmpw	$0x9E7B, %ax	// magic
    1.46 +	jne	lzsa1main
    1.47 +	lodsb
    1.48 +	cmpb	$0, %al		// lzsa1
    1.49 +	jne	lzsa1main
    1.50 +# endif
    1.51 +lzsa1block:			// uncompress chunk
    1.52 +	lodsw			// block size
    1.53 +	xchgw	%ax, %cx
    1.54 +	lodsb
    1.55 +# ifndef PACKED_ONLY
    1.56 +	orb	%al, %al
    1.57 +	jns	lzsa1compressed
    1.58 +#  if !defined(FLAT32) && !defined(FLAT16OUT)
    1.59 +	movw	%cx, %dx
    1.60 +	movb	$0, %cl
    1.61 +	movb	$0, %dh
    1.62 +copytail:
    1.63 +	call	lzsa1movStr
    1.64 +	xchg	%dx, %cx
    1.65 +	incw	%cx
    1.66 +	loop	copytail
    1.67 +#  else
    1.68 +	movsb			// copy block
    1.69 +copylp:
    1.70 +	movsb			// copy block
    1.71 +	loop	copylp		// handle 64K case
    1.72 +#  endif
    1.73 +	jmp	lzsa1block	// end of block
    1.74 +lzsa1compressed:
    1.75 +	jne	lzsa1chunk	// 64Kb block
    1.76 +# endif
    1.77 +	jcxz	lzsa1quit	// bail if we hit EOD
    1.78 +	pushw	%cx
    1.79 +# if !defined(FLAT32) && !defined(FLAT16)
    1.80 +	xorw	%cx, %cx
    1.81 +	call	normalize
    1.82 +# define NeedNormalize
    1.83 +# endif
    1.84 +	popw	%dx
    1.85 +	addw	%si, %dx
    1.86 +#endif
    1.87 +lzsa1chunk:			// uncompress chunk
    1.88 +	lodsb			// get token O|LLL|MMMM
    1.89 +	movb	%al, %bl	// keep token in bl
    1.90 +	shrb	$4, %al		// shift literals length into place
    1.91 +	movw	$LITERALS_RUN_LEN*256+MIN_LITERALS_SIZE, %cx
    1.92 +	call	lzsa1len	// %ch = LITERALS_RUN_LEN
    1.93 +#if defined(NeedNormalize)
    1.94 +	call	lzsa1movLit	// copy %cx literals from %ds:%si to %es:%di
    1.95 +#else
    1.96 +	rep	movsb		// copy %cx literals from %ds:%si to %es:%di
    1.97 +#endif
    1.98 +#ifndef RAW_FORMAT
    1.99 +	cmpw	%dx, %si
   1.100 +	jae	lzsa1block	// bail if we hit EOD
   1.101 +#endif
   1.102 +#ifdef FLAT32
   1.103 +	orl	$-1, %eax
   1.104 +#else
   1.105 +	movb	$-1, %ah
   1.106 +#endif
   1.107 +	testb	%bl, %bl	// check match offset size in token (O bit)
   1.108 +	jns	lzsa1ShortOfs
   1.109 +	lodsw
   1.110 +	.byte	0x3C		// mask lodsb with cmpb $0xAC, %al
   1.111 +lzsa1ShortOfs:
   1.112 +	lodsb
   1.113 +	xchg	AX, BX		// %bx: match offset  %ax: original token
   1.114 +	movw	$MATCH_RUN_LEN*256+MIN_MATCH_SIZE, %cx
   1.115 +	call	lzsa1len
   1.116 +#ifdef RAW_FORMAT
   1.117 +	jcxz	lzsa1quit	// bail if we hit EOD
   1.118 +#endif
   1.119 +#if !defined(FLAT32) && !defined(FLAT16OUT)
   1.120 +	pushw	%ds
   1.121 +	pushw	%si
   1.122 +	movw	%di, %si
   1.123 +	addw	%bx, %si
   1.124 +	movw	%es, %ax
   1.125 +	jc	axok
   1.126 +	subb	$0x10, %ah
   1.127 +axok:
   1.128 +.macro norm	reg
   1.129 +	movw	%si, \reg
   1.130 +	subw	%si, %dx
   1.131 +	andw	$0xF, %si
   1.132 +	addw	%si, %dx
   1.133 +	shrw	$4, \reg
   1.134 +	addw	\reg, %ax
   1.135 +	movw	%ax, %ds
   1.136 +	movw	%di, \reg
   1.137 +	andw	$0xF, %di
   1.138 +	shrw	$4, \reg
   1.139 +	movw	%es, %ax
   1.140 +	addw	\reg, %ax
   1.141 +	movw	%ax, %es
   1.142 +.endm 
   1.143 +	pushw	%dx
   1.144 +# if defined(NeedNormalize) || defined(PARANOIA)
   1.145 +	call	lzsa1movStr	// copy string
   1.146 +# else
   1.147 +	norm	%bp
   1.148 +	rep movsb
   1.149 +# endif
   1.150 +	popw	%dx
   1.151 +	popw	%si
   1.152 +	popw	%ds
   1.153 +#else
   1.154 +	xchg	AX, SI		// save %si	
   1.155 +	lea	(BX,DI), SI
   1.156 +	rep movsb	%es:(SI), %es:(DI)
   1.157 +	xchg	AX, SI		// restore %si	
   1.158 +#endif
   1.159 +	jmp	lzsa1chunk
   1.160 +
   1.161 +lzsa1len:			// get length in %ecx
   1.162 +	andb	%ch, %al
   1.163 +	cbw			// clear %ah
   1.164 +	cmpb	%ch, %al
   1.165 +	jne	lzsa1minNumber	// S=0-6, L=0-14
   1.166 +	lodsb
   1.167 +	addb	%ch, %cl
   1.168 +lzsa1minNumber:
   1.169 +	addb	%cl, %al
   1.170 +	jnc	lzsa1gotNumber  // 0-255
   1.171 +	movb	%al, %ah	// S=256-1791, L=256-3839 or S=256-511, L=256-511
   1.172 +	jne	lzsa1midNumber
   1.173 +	lodsw			// 0-65535
   1.174 +	.byte	0x3C		// mask lodsb with cmpb $0xAC, %al
   1.175 +lzsa1midNumber:
   1.176 +	lodsb
   1.177 +lzsa1gotNumber:
   1.178 +	xchgw	%ax, %cx
   1.179 +lzsa1quit:
   1.180 +	ret
   1.181 +
   1.182 +#if defined(NeedNormalize) || defined(PARANOIA)
   1.183 +# if defined(PARANOIA)
   1.184 +lzsa1movlp:
   1.185 +	decw	%ch
   1.186 +	rep movsb
   1.187 +	incw	%ch
   1.188 +# endif
   1.189 +normalize:
   1.190 +lzsa1movLit:
   1.191 +	movw	%ds, %ax
   1.192 +lzsa1movStr:
   1.193 +	norm	%bp
   1.194 +# if defined(PARANOIA)
   1.195 +	cmpb	$0xFF, %ch	// catch FFFX case
   1.196 +	je	lzsa1movlp
   1.197 +# endif
   1.198 +	rep movsb
   1.199 +	ret
   1.200 +#endif