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