...

Source file src/github.com/klauspost/compress/s2/encode_amd64.go

Documentation: github.com/klauspost/compress/s2

     1  //go:build !appengine && !noasm && gc
     2  // +build !appengine,!noasm,gc
     3  
     4  package s2
     5  
     6  import "github.com/klauspost/compress/internal/race"
     7  
     8  const hasAmd64Asm = true
     9  
    10  // encodeBlock encodes a non-empty src to a guaranteed-large-enough dst. It
    11  // assumes that the varint-encoded length of the decompressed bytes has already
    12  // been written.
    13  //
    14  // It also assumes that:
    15  //
    16  //	len(dst) >= MaxEncodedLen(len(src)) &&
    17  //	minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
    18  func encodeBlock(dst, src []byte) (d int) {
    19  	race.ReadSlice(src)
    20  	race.WriteSlice(dst)
    21  
    22  	const (
    23  		// Use 12 bit table when less than...
    24  		limit12B = 16 << 10
    25  		// Use 10 bit table when less than...
    26  		limit10B = 4 << 10
    27  		// Use 8 bit table when less than...
    28  		limit8B = 512
    29  	)
    30  
    31  	if len(src) >= 4<<20 {
    32  		return encodeBlockAsm(dst, src)
    33  	}
    34  	if len(src) >= limit12B {
    35  		return encodeBlockAsm4MB(dst, src)
    36  	}
    37  	if len(src) >= limit10B {
    38  		return encodeBlockAsm12B(dst, src)
    39  	}
    40  	if len(src) >= limit8B {
    41  		return encodeBlockAsm10B(dst, src)
    42  	}
    43  	if len(src) < minNonLiteralBlockSize {
    44  		return 0
    45  	}
    46  	return encodeBlockAsm8B(dst, src)
    47  }
    48  
    49  // encodeBlockBetter encodes a non-empty src to a guaranteed-large-enough dst. It
    50  // assumes that the varint-encoded length of the decompressed bytes has already
    51  // been written.
    52  //
    53  // It also assumes that:
    54  //
    55  //	len(dst) >= MaxEncodedLen(len(src)) &&
    56  //	minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
    57  func encodeBlockBetter(dst, src []byte) (d int) {
    58  	race.ReadSlice(src)
    59  	race.WriteSlice(dst)
    60  
    61  	const (
    62  		// Use 12 bit table when less than...
    63  		limit12B = 16 << 10
    64  		// Use 10 bit table when less than...
    65  		limit10B = 4 << 10
    66  		// Use 8 bit table when less than...
    67  		limit8B = 512
    68  	)
    69  
    70  	if len(src) > 4<<20 {
    71  		return encodeBetterBlockAsm(dst, src)
    72  	}
    73  	if len(src) >= limit12B {
    74  		return encodeBetterBlockAsm4MB(dst, src)
    75  	}
    76  	if len(src) >= limit10B {
    77  		return encodeBetterBlockAsm12B(dst, src)
    78  	}
    79  	if len(src) >= limit8B {
    80  		return encodeBetterBlockAsm10B(dst, src)
    81  	}
    82  	if len(src) < minNonLiteralBlockSize {
    83  		return 0
    84  	}
    85  	return encodeBetterBlockAsm8B(dst, src)
    86  }
    87  
    88  // encodeBlockSnappy encodes a non-empty src to a guaranteed-large-enough dst. It
    89  // assumes that the varint-encoded length of the decompressed bytes has already
    90  // been written.
    91  //
    92  // It also assumes that:
    93  //
    94  //	len(dst) >= MaxEncodedLen(len(src)) &&
    95  //	minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
    96  func encodeBlockSnappy(dst, src []byte) (d int) {
    97  	race.ReadSlice(src)
    98  	race.WriteSlice(dst)
    99  
   100  	const (
   101  		// Use 12 bit table when less than...
   102  		limit12B = 16 << 10
   103  		// Use 10 bit table when less than...
   104  		limit10B = 4 << 10
   105  		// Use 8 bit table when less than...
   106  		limit8B = 512
   107  	)
   108  	if len(src) >= 64<<10 {
   109  		return encodeSnappyBlockAsm(dst, src)
   110  	}
   111  	if len(src) >= limit12B {
   112  		return encodeSnappyBlockAsm64K(dst, src)
   113  	}
   114  	if len(src) >= limit10B {
   115  		return encodeSnappyBlockAsm12B(dst, src)
   116  	}
   117  	if len(src) >= limit8B {
   118  		return encodeSnappyBlockAsm10B(dst, src)
   119  	}
   120  	if len(src) < minNonLiteralBlockSize {
   121  		return 0
   122  	}
   123  	return encodeSnappyBlockAsm8B(dst, src)
   124  }
   125  
   126  // encodeBlockSnappy encodes a non-empty src to a guaranteed-large-enough dst. It
   127  // assumes that the varint-encoded length of the decompressed bytes has already
   128  // been written.
   129  //
   130  // It also assumes that:
   131  //
   132  //	len(dst) >= MaxEncodedLen(len(src)) &&
   133  //	minNonLiteralBlockSize <= len(src) && len(src) <= maxBlockSize
   134  func encodeBlockBetterSnappy(dst, src []byte) (d int) {
   135  	race.ReadSlice(src)
   136  	race.WriteSlice(dst)
   137  
   138  	const (
   139  		// Use 12 bit table when less than...
   140  		limit12B = 16 << 10
   141  		// Use 10 bit table when less than...
   142  		limit10B = 4 << 10
   143  		// Use 8 bit table when less than...
   144  		limit8B = 512
   145  	)
   146  	if len(src) >= 64<<10 {
   147  		return encodeSnappyBetterBlockAsm(dst, src)
   148  	}
   149  	if len(src) >= limit12B {
   150  		return encodeSnappyBetterBlockAsm64K(dst, src)
   151  	}
   152  	if len(src) >= limit10B {
   153  		return encodeSnappyBetterBlockAsm12B(dst, src)
   154  	}
   155  	if len(src) >= limit8B {
   156  		return encodeSnappyBetterBlockAsm10B(dst, src)
   157  	}
   158  	if len(src) < minNonLiteralBlockSize {
   159  		return 0
   160  	}
   161  	return encodeSnappyBetterBlockAsm8B(dst, src)
   162  }
   163  

View as plain text