encode_amd64.go 3.8 KB

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