| 1 |
|
| 2 |
|
| 3 |
package main |
| 4 |
|
| 5 |
import ( |
| 6 |
"fmt" |
| 7 |
"log" |
| 8 |
|
| 9 |
. "github.com/mmcloughlin/avo/build" |
| 10 |
"github.com/mmcloughlin/avo/buildtags" |
| 11 |
"github.com/mmcloughlin/avo/operand" |
| 12 |
. "github.com/mmcloughlin/avo/operand" |
| 13 |
"github.com/mmcloughlin/avo/reg" |
| 14 |
) |
| 15 |
|
| 16 |
func main() { |
| 17 |
Constraint(buildtags.Not("appengine").ToConstraint()) |
| 18 |
Constraint(buildtags.Not("noasm").ToConstraint()) |
| 19 |
Constraint(buildtags.Term("gc").ToConstraint()) |
| 20 |
|
| 21 |
genEncodeBlockAsm("encodeBlockAsm", 16, 6, false) |
| 22 |
genEncodeBlockAsm("encodeBlockAsm14B", 14, 5, false) |
| 23 |
genEncodeBlockAsm("encodeBlockAsm12B", 12, 4, false) |
| 24 |
genEncodeBlockAsm("encodeBlockAsmAvx", 16, 6, true) |
| 25 |
genEncodeBlockAsm("encodeBlockAsm14BAvx", 14, 5, true) |
| 26 |
genEncodeBlockAsm("encodeBlockAsm12BAvx", 12, 4, true) |
| 27 |
genEmitLiteral() |
| 28 |
genEmitRepeat() |
| 29 |
genEmitCopy() |
| 30 |
genMatchLen() |
| 31 |
Generate() |
| 32 |
} |
| 33 |
|
| 34 |
func debugval(v operand.Op) { |
| 35 |
value := reg.R15 |
| 36 |
MOVQ(v, value) |
| 37 |
INT(Imm(3)) |
| 38 |
} |
| 39 |
|
| 40 |
func genEncodeBlockAsm(name string, tableBits, skipLog int, avx bool) { |
| 41 |
TEXT(name, 0, "func(dst, src []byte) int") |
| 42 |
Doc(name+" encodes a non-empty src to a guaranteed-large-enough dst.", |
| 43 |
"It assumes that the varint-encoded length of the decompressed bytes has already been written.", "") |
| 44 |
Pragma("noescape") |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
var ( |
| 49 |
tableSize = 1 << uint(tableBits) |
| 50 |
|
| 51 |
baseStack = 0 |
| 52 |
|
| 53 |
|
| 54 |
extraStack = 32 |
| 55 |
allocStack = baseStack + extraStack + tableSize |
| 56 |
) |
| 57 |
|
| 58 |
|
| 59 |
if tableSize < 128 { |
| 60 |
panic("tableSize must be at least 128 bytes") |
| 61 |
} |
| 62 |
|
| 63 |
lenSrcBasic, err := Param("src").Len().Resolve() |
| 64 |
if err != nil { |
| 65 |
panic(err) |
| 66 |
} |
| 67 |
lenSrcQ := lenSrcBasic.Addr |
| 68 |
|
| 69 |
stack := AllocLocal(allocStack) |
| 70 |
table := stack.Offset(allocStack - tableSize) |
| 71 |
|
| 72 |
tmpStack := baseStack |
| 73 |
|
| 74 |
dstLimitPtrQ := stack.Offset(tmpStack) |
| 75 |
tmpStack += 8 |
| 76 |
|
| 77 |
dstStartPtrQ := stack.Offset(tmpStack) |
| 78 |
tmpStack += 8 |
| 79 |
|
| 80 |
sLimitL := stack.Offset(tmpStack) |
| 81 |
tmpStack += 4 |
| 82 |
|
| 83 |
nextEmitL := stack.Offset(tmpStack) |
| 84 |
tmpStack += 4 |
| 85 |
|
| 86 |
repeatL := stack.Offset(tmpStack) |
| 87 |
tmpStack += 4 |
| 88 |
|
| 89 |
nextSTempL := stack.Offset(tmpStack) |
| 90 |
tmpStack += 4 |
| 91 |
|
| 92 |
|
| 93 |
if tmpStack-baseStack != extraStack { |
| 94 |
log.Fatal("adjust extraStack to ", tmpStack-baseStack) |
| 95 |
} |
| 96 |
|
| 97 |
dstBaseBasic, err := Param("dst").Base().Resolve() |
| 98 |
if err != nil { |
| 99 |
panic(err) |
| 100 |
} |
| 101 |
dstBase := dstBaseBasic.Addr |
| 102 |
|
| 103 |
if tmpStack > extraStack+baseStack { |
| 104 |
panic(fmt.Sprintf("tmp stack exceeded: %v", tmpStack)) |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
{ |
| 109 |
iReg := GP64() |
| 110 |
MOVQ(U32(tableSize/8/16), iReg) |
| 111 |
tablePtr := GP64() |
| 112 |
LEAQ(table, tablePtr) |
| 113 |
zeroXmm := XMM() |
| 114 |
PXOR(zeroXmm, zeroXmm) |
| 115 |
|
| 116 |
Label("zero_loop_" + name) |
| 117 |
for i := 0; i < 8; i++ { |
| 118 |
MOVOU(zeroXmm, Mem{Base: tablePtr, Disp: i * 16}) |
| 119 |
} |
| 120 |
ADDQ(U8(16*8), tablePtr) |
| 121 |
DECQ(iReg) |
| 122 |
JNZ(LabelRef("zero_loop_" + name)) |
| 123 |
|
| 124 |
|
| 125 |
MOVL(iReg.As32(), nextEmitL) |
| 126 |
} |
| 127 |
|
| 128 |
{ |
| 129 |
const inputMargin = 8 |
| 130 |
tmp, tmp2, tmp3 := GP64(), GP64(), GP64() |
| 131 |
MOVQ(lenSrcQ, tmp) |
| 132 |
LEAQ(Mem{Base: tmp, Disp: -5}, tmp2) |
| 133 |
|
| 134 |
LEAQ(Mem{Base: tmp, Disp: -inputMargin}, tmp3) |
| 135 |
|
| 136 |
SHRQ(U8(5), tmp) |
| 137 |
SUBL(tmp.As32(), tmp2.As32()) |
| 138 |
MOVL(tmp3.As32(), sLimitL) |
| 139 |
dstAddr := GP64() |
| 140 |
MOVQ(dstBase, dstAddr) |
| 141 |
|
| 142 |
MOVQ(dstAddr, dstStartPtrQ) |
| 143 |
LEAQ(Mem{Base: dstAddr, Index: tmp2, Scale: 1}, tmp2) |
| 144 |
MOVQ(tmp2, dstLimitPtrQ) |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
s := GP64().As32() |
| 149 |
MOVL(U32(1), s) |
| 150 |
|
| 151 |
MOVL(s, repeatL) |
| 152 |
|
| 153 |
src := GP64() |
| 154 |
Load(Param("src").Base(), src) |
| 155 |
|
| 156 |
|
| 157 |
Label("search_loop_" + name) |
| 158 |
candidate := GP64().As32() |
| 159 |
{ |
| 160 |
cv := GP64() |
| 161 |
MOVQ(Mem{Base: src, Index: s, Scale: 1}, cv) |
| 162 |
nextS := GP64() |
| 163 |
|
| 164 |
{ |
| 165 |
tmp := GP64() |
| 166 |
MOVL(s, tmp.As32()) |
| 167 |
SUBL(nextEmitL, tmp.As32()) |
| 168 |
SHRL(U8(skipLog), tmp.As32()) |
| 169 |
LEAQ(Mem{Base: s, Disp: 4, Index: tmp, Scale: 1}, nextS) |
| 170 |
} |
| 171 |
|
| 172 |
{ |
| 173 |
tmp := GP64() |
| 174 |
MOVL(sLimitL, tmp.As32()) |
| 175 |
CMPL(nextS.As32(), tmp.As32()) |
| 176 |
JGT(LabelRef("emit_remainder_" + name)) |
| 177 |
} |
| 178 |
|
| 179 |
MOVL(nextS.As32(), nextSTempL) |
| 180 |
|
| 181 |
candidate2 := GP64().As32() |
| 182 |
hasher := hash6(tableBits) |
| 183 |
{ |
| 184 |
hash0, hash1 := GP64(), GP64() |
| 185 |
MOVQ(cv, hash0) |
| 186 |
MOVQ(cv, hash1) |
| 187 |
SHRQ(U8(8), hash1) |
| 188 |
hasher.hash(hash0) |
| 189 |
hasher.hash(hash1) |
| 190 |
MOVL(table.Idx(hash0, 1), candidate) |
| 191 |
MOVL(table.Idx(hash1, 1), candidate2) |
| 192 |
MOVL(s, table.Idx(hash0, 1)) |
| 193 |
tmp := GP64().As32() |
| 194 |
LEAL(Mem{Base: s, Disp: 1}, tmp) |
| 195 |
MOVL(tmp, table.Idx(hash1, 1)) |
| 196 |
} |
| 197 |
|
| 198 |
const checkRep = 1 |
| 199 |
|
| 200 |
if true { |
| 201 |
|
| 202 |
rep := GP64().As32() |
| 203 |
if true { |
| 204 |
|
| 205 |
left, right := GP64(), GP64() |
| 206 |
MOVL(s, rep) |
| 207 |
SUBL(repeatL, rep) |
| 208 |
MOVL(Mem{Base: src, Index: rep, Scale: 1, Disp: checkRep}, right.As32()) |
| 209 |
MOVQ(cv, left) |
| 210 |
SHLQ(U8(checkRep*8), left) |
| 211 |
CMPL(left.As32(), right.As32()) |
| 212 |
|
| 213 |
|
| 214 |
JNE(LabelRef("no_repeat_found_" + name)) |
| 215 |
} |
| 216 |
|
| 217 |
base := GP64() |
| 218 |
LEAQ(Mem{Base: s, Disp: 1}, base) |
| 219 |
|
| 220 |
if true { |
| 221 |
ne := GP64().As32() |
| 222 |
MOVL(nextEmitL, ne) |
| 223 |
TESTL(rep, rep) |
| 224 |
JZ(LabelRef("repeat_extend_back_end_" + name)) |
| 225 |
|
| 226 |
|
| 227 |
Label("repeat_extend_back_loop_" + name) |
| 228 |
CMPL(base.As32(), ne) |
| 229 |
JG(LabelRef("repeat_extend_back_end_" + name)) |
| 230 |
|
| 231 |
tmp, tmp2 := GP64(), GP64() |
| 232 |
MOVB(Mem{Base: src, Index: rep, Scale: 1, Disp: -1}, tmp.As8()) |
| 233 |
MOVB(Mem{Base: src, Index: base, Scale: 1, Disp: -1}, tmp2.As8()) |
| 234 |
CMPB(tmp.As8(), tmp2.As8()) |
| 235 |
JNE(LabelRef("repeat_extend_back_end_" + name)) |
| 236 |
LEAQ(Mem{Base: base, Disp: -1}, base) |
| 237 |
DECL(rep) |
| 238 |
JZ(LabelRef("repeat_extend_back_end_" + name)) |
| 239 |
JMP(LabelRef("repeat_extend_back_loop_" + name)) |
| 240 |
} |
| 241 |
Label("repeat_extend_back_end_" + name) |
| 242 |
|
| 243 |
|
| 244 |
if true { |
| 245 |
emitLiterals(nextEmitL, base, src, dstBase, "repeat_emit_"+name, avx) |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
if true { |
| 250 |
|
| 251 |
ADDL(U8(4+checkRep), s) |
| 252 |
|
| 253 |
|
| 254 |
MOVL(s, candidate) |
| 255 |
SUBL(repeatL, candidate) |
| 256 |
{ |
| 257 |
|
| 258 |
srcLeft := GP64() |
| 259 |
MOVL(sLimitL, srcLeft.As32()) |
| 260 |
SUBL(s, srcLeft.As32()) |
| 261 |
|
| 262 |
|
| 263 |
forwardStart := Mem{Base: src, Index: s, Scale: 1} |
| 264 |
|
| 265 |
backStart := Mem{Base: src, Index: candidate, Scale: 1} |
| 266 |
length := matchLen("repeat_extend", forwardStart, backStart, srcLeft, LabelRef("repeat_extend_forward_end_"+name)) |
| 267 |
Label("repeat_extend_forward_end_" + name) |
| 268 |
|
| 269 |
ADDL(length.As32(), s) |
| 270 |
} |
| 271 |
} |
| 272 |
|
| 273 |
if true { |
| 274 |
|
| 275 |
length := GP64() |
| 276 |
MOVL(s, length.As32()) |
| 277 |
SUBL(base.As32(), length.As32()) |
| 278 |
|
| 279 |
offsetVal := GP64() |
| 280 |
MOVL(repeatL, offsetVal.As32()) |
| 281 |
dst := GP64() |
| 282 |
MOVQ(dstBase, dst) |
| 283 |
|
| 284 |
|
| 285 |
tmp := GP64() |
| 286 |
MOVL(nextEmitL, tmp.As32()) |
| 287 |
TESTL(tmp.As32(), tmp.As32()) |
| 288 |
|
| 289 |
|
| 290 |
JZ(LabelRef("repeat_as_copy_" + name)) |
| 291 |
|
| 292 |
emitRepeat("match_repeat_", length, offsetVal, nil, dst, LabelRef("repeat_end_emit_"+name)) |
| 293 |
|
| 294 |
|
| 295 |
Label("repeat_as_copy_" + name) |
| 296 |
emitCopy("repeat_as_copy_"+name, length, offsetVal, nil, dst, LabelRef("repeat_end_emit_"+name)) |
| 297 |
|
| 298 |
Label("repeat_end_emit_" + name) |
| 299 |
|
| 300 |
MOVQ(dst, dstBase) |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
if true { |
| 305 |
tmp := GP64() |
| 306 |
MOVL(sLimitL, tmp.As32()) |
| 307 |
CMPL(s, tmp.As32()) |
| 308 |
JGT(LabelRef("emit_remainder_" + name)) |
| 309 |
} |
| 310 |
JMP(LabelRef("search_loop_" + name)) |
| 311 |
} |
| 312 |
Label("no_repeat_found_" + name) |
| 313 |
{ |
| 314 |
|
| 315 |
hash2 := GP64() |
| 316 |
{ |
| 317 |
|
| 318 |
hasher = hash6(tableBits) |
| 319 |
MOVQ(cv, hash2) |
| 320 |
SHRQ(U8(16), hash2) |
| 321 |
hasher.hash(hash2) |
| 322 |
} |
| 323 |
|
| 324 |
CMPL(Mem{Base: src, Index: candidate, Scale: 1}, cv.As32()) |
| 325 |
|
| 326 |
SHRQ(U8(8), cv) |
| 327 |
JEQ(LabelRef("candidate_match_" + name)) |
| 328 |
|
| 329 |
|
| 330 |
MOVL(table.Idx(hash2, 1), candidate) |
| 331 |
|
| 332 |
|
| 333 |
CMPL(Mem{Base: src, Index: candidate2, Scale: 1}, cv.As32()) |
| 334 |
JEQ(LabelRef("candidate2_match_" + name)) |
| 335 |
|
| 336 |
|
| 337 |
tmp := GP64() |
| 338 |
LEAQ(Mem{Base: s, Disp: 2}, tmp) |
| 339 |
MOVL(tmp.As32(), table.Idx(hash2, 1)) |
| 340 |
|
| 341 |
|
| 342 |
SHRQ(U8(8), cv) |
| 343 |
CMPL(Mem{Base: src, Index: candidate, Scale: 1}, cv.As32()) |
| 344 |
JEQ(LabelRef("candidate3_match_" + name)) |
| 345 |
|
| 346 |
MOVL(nextSTempL, s) |
| 347 |
JMP(LabelRef("search_loop_" + name)) |
| 348 |
|
| 349 |
|
| 350 |
Label("candidate3_match_" + name) |
| 351 |
ADDL(U8(2), s) |
| 352 |
JMP(LabelRef("candidate_match_" + name)) |
| 353 |
|
| 354 |
Label("candidate2_match_" + name) |
| 355 |
|
| 356 |
tmp = GP64() |
| 357 |
LEAQ(Mem{Base: s, Disp: -2}, tmp) |
| 358 |
MOVL(tmp.As32(), table.Idx(hash2, 1)) |
| 359 |
|
| 360 |
INCL(s) |
| 361 |
MOVL(candidate2, candidate) |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
Label("candidate_match_" + name) |
| 366 |
|
| 367 |
|
| 368 |
{ |
| 369 |
ne := GP64() |
| 370 |
MOVL(nextEmitL, ne.As32()) |
| 371 |
TESTL(candidate, candidate) |
| 372 |
JZ(LabelRef("match_extend_back_end_" + name)) |
| 373 |
|
| 374 |
|
| 375 |
Label("match_extend_back_loop_" + name) |
| 376 |
CMPL(s, ne.As32()) |
| 377 |
JG(LabelRef("match_extend_back_end_" + name)) |
| 378 |
|
| 379 |
tmp, tmp2 := GP64(), GP64() |
| 380 |
MOVB(Mem{Base: src, Index: candidate, Scale: 1, Disp: -1}, tmp.As8()) |
| 381 |
MOVB(Mem{Base: src, Index: s, Scale: 1, Disp: -1}, tmp2.As8()) |
| 382 |
CMPB(tmp.As8(), tmp2.As8()) |
| 383 |
JNE(LabelRef("match_extend_back_end_" + name)) |
| 384 |
LEAL(Mem{Base: s, Disp: -1}, s) |
| 385 |
DECL(candidate) |
| 386 |
JZ(LabelRef("match_extend_back_end_" + name)) |
| 387 |
JMP(LabelRef("match_extend_back_loop_" + name)) |
| 388 |
} |
| 389 |
Label("match_extend_back_end_" + name) |
| 390 |
|
| 391 |
|
| 392 |
if true { |
| 393 |
|
| 394 |
tmp := GP64() |
| 395 |
MOVL(s, tmp.As32()) |
| 396 |
SUBL(nextEmitL, tmp.As32()) |
| 397 |
LEAQ(dstBase.Idx(tmp, 1), tmp) |
| 398 |
CMPQ(tmp, dstLimitPtrQ) |
| 399 |
JL(LabelRef("match_dst_size_check_" + name)) |
| 400 |
ri, err := ReturnIndex(0).Resolve() |
| 401 |
if err != nil { |
| 402 |
panic(err) |
| 403 |
} |
| 404 |
MOVQ(U32(0), ri.Addr) |
| 405 |
RET() |
| 406 |
} |
| 407 |
Label("match_dst_size_check_" + name) |
| 408 |
{ |
| 409 |
base := GP64() |
| 410 |
MOVL(candidate, base.As32()) |
| 411 |
emitLiterals(nextEmitL, base, src, dstBase, "match_emit_"+name, avx) |
| 412 |
NOP() |
| 413 |
} |
| 414 |
|
| 415 |
Label("match_nolit_loop_" + name) |
| 416 |
{ |
| 417 |
base := GP64().As32() |
| 418 |
MOVL(s, base) |
| 419 |
|
| 420 |
{ |
| 421 |
|
| 422 |
repeatVal := GP64().As32() |
| 423 |
MOVL(s, repeatVal) |
| 424 |
SUBL(candidate, repeatVal) |
| 425 |
MOVL(repeatVal, repeatL) |
| 426 |
} |
| 427 |
|
| 428 |
ADDL(U8(4), s) |
| 429 |
ADDL(U8(4), candidate) |
| 430 |
|
| 431 |
{ |
| 432 |
|
| 433 |
srcLeft := GP64() |
| 434 |
MOVL(sLimitL, srcLeft.As32()) |
| 435 |
SUBL(s, srcLeft.As32()) |
| 436 |
length := matchLen("match_nolit_"+name, |
| 437 |
Mem{Base: src, Index: s, Scale: 1}, |
| 438 |
Mem{Base: src, Index: candidate, Scale: 1}, |
| 439 |
srcLeft, |
| 440 |
LabelRef("match_nolit_end_"+name), |
| 441 |
) |
| 442 |
Label("match_nolit_end_" + name) |
| 443 |
offset := GP64() |
| 444 |
MOVL(repeatL, offset.As32()) |
| 445 |
ADDQ(U8(4), length) |
| 446 |
dst := GP64() |
| 447 |
MOVQ(dstBase, dst) |
| 448 |
|
| 449 |
ADDL(length.As32(), s) |
| 450 |
emitCopy("match_nolit_"+name, length, offset, nil, dst, LabelRef("match_nolit_emitcopy_end_"+name)) |
| 451 |
Label("match_nolit_emitcopy_end_" + name) |
| 452 |
MOVQ(dst, dstBase) |
| 453 |
MOVL(s, nextEmitL) |
| 454 |
CMPL(s, sLimitL) |
| 455 |
JGE(LabelRef("emit_remainder_" + name)) |
| 456 |
|
| 457 |
|
| 458 |
{ |
| 459 |
CMPQ(dst, dstLimitPtrQ) |
| 460 |
JL(LabelRef("match_nolit_dst_ok_" + name)) |
| 461 |
ri, err := ReturnIndex(0).Resolve() |
| 462 |
if err != nil { |
| 463 |
panic(err) |
| 464 |
} |
| 465 |
MOVQ(U32(0), ri.Addr) |
| 466 |
RET() |
| 467 |
Label("match_nolit_dst_ok_" + name) |
| 468 |
} |
| 469 |
} |
| 470 |
{ |
| 471 |
|
| 472 |
x := GP64() |
| 473 |
|
| 474 |
MOVQ(Mem{Base: src, Index: s, Scale: 1, Disp: -2}, x) |
| 475 |
hasher := hash6(tableBits) |
| 476 |
hash0, hash1 := GP64(), GP64() |
| 477 |
MOVQ(x, hash0) |
| 478 |
SHRQ(U8(16), x) |
| 479 |
MOVQ(x, hash1) |
| 480 |
hasher.hash(hash0) |
| 481 |
hasher.hash(hash1) |
| 482 |
c0, c1 := GP64(), GP64() |
| 483 |
MOVL(table.Idx(hash0, 1), c0.As32()) |
| 484 |
MOVL(table.Idx(hash1, 1), c1.As32()) |
| 485 |
sm2 := GP64() |
| 486 |
LEAQ(Mem{Base: s, Disp: -2}, sm2) |
| 487 |
MOVL(sm2.As32(), table.Idx(hash0, 1)) |
| 488 |
MOVL(s, table.Idx(hash1, 1)) |
| 489 |
CMPL(Mem{Base: src, Index: hash1, Scale: 1}, x.As32()) |
| 490 |
JEQ(LabelRef("match_nolit_loop_" + name)) |
| 491 |
INCL(s) |
| 492 |
} |
| 493 |
JMP(LabelRef("search_loop_" + name)) |
| 494 |
} |
| 495 |
|
| 496 |
Label("emit_remainder_" + name) |
| 497 |
|
| 498 |
|
| 499 |
{ |
| 500 |
|
| 501 |
remain := GP64() |
| 502 |
MOVQ(lenSrcQ, remain) |
| 503 |
SUBL(nextEmitL, remain.As32()) |
| 504 |
dst := GP64() |
| 505 |
MOVQ(dstBase, dst) |
| 506 |
|
| 507 |
LEAQ(Mem{Base: dst, Index: remain, Scale: 1}, dst) |
| 508 |
CMPQ(dst, dstLimitPtrQ) |
| 509 |
JL(LabelRef("emit_remainder_ok_" + name)) |
| 510 |
ri, err := ReturnIndex(0).Resolve() |
| 511 |
if err != nil { |
| 512 |
panic(err) |
| 513 |
} |
| 514 |
MOVQ(U32(0), ri.Addr) |
| 515 |
RET() |
| 516 |
Label("emit_remainder_ok_" + name) |
| 517 |
} |
| 518 |
|
| 519 |
emitEnd := GP64() |
| 520 |
MOVQ(lenSrcQ, emitEnd) |
| 521 |
|
| 522 |
|
| 523 |
emitLiterals(nextEmitL, emitEnd, src, dstBase, "emit_remainder_"+name, avx) |
| 524 |
|
| 525 |
|
| 526 |
length := GP64() |
| 527 |
MOVQ(dstStartPtrQ, length) |
| 528 |
SUBQ(dstBase, length) |
| 529 |
|
| 530 |
Store(length, ReturnIndex(0)) |
| 531 |
RET() |
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
func emitLiterals(nextEmitL Mem, base reg.GPVirtual, src reg.GPVirtual, dstBase Mem, name string, avx bool) { |
| 538 |
nextEmit, litLen, dstBaseTmp, litBase := GP64().As32(), GP64(), GP64(), GP64() |
| 539 |
MOVL(nextEmitL, nextEmit) |
| 540 |
CMPL(nextEmit, base.As32()) |
| 541 |
JEQ(LabelRef("emit_literal_skip_" + name)) |
| 542 |
MOVL(base.As32(), litLen.As32()) |
| 543 |
|
| 544 |
|
| 545 |
MOVL(base.As32(), nextEmitL) |
| 546 |
|
| 547 |
|
| 548 |
LEAQ(Mem{Base: src, Index: nextEmit, Scale: 1}, litBase) |
| 549 |
SUBL(nextEmit, litLen.As32()) |
| 550 |
|
| 551 |
|
| 552 |
MOVQ(dstBase, dstBaseTmp) |
| 553 |
emitLiteral(name, litLen, nil, dstBaseTmp, litBase, LabelRef("emit_literal_done_"+name), avx, true) |
| 554 |
Label("emit_literal_done_" + name) |
| 555 |
|
| 556 |
MOVQ(dstBaseTmp, dstBase) |
| 557 |
Label("emit_literal_skip_" + name) |
| 558 |
} |
| 559 |
|
| 560 |
type hashGen struct { |
| 561 |
bytes int |
| 562 |
tablebits int |
| 563 |
mulreg reg.GPVirtual |
| 564 |
} |
| 565 |
|
| 566 |
|
| 567 |
func hash6(tablebits int) hashGen { |
| 568 |
h := hashGen{ |
| 569 |
bytes: 6, |
| 570 |
tablebits: tablebits, |
| 571 |
mulreg: GP64(), |
| 572 |
} |
| 573 |
MOVQ(Imm(227718039650203), h.mulreg) |
| 574 |
return h |
| 575 |
} |
| 576 |
|
| 577 |
|
| 578 |
func (h hashGen) hash(val reg.GPVirtual) { |
| 579 |
|
| 580 |
SHLQ(U8(64-8*h.bytes), val) |
| 581 |
IMULQ(h.mulreg, val) |
| 582 |
|
| 583 |
SHRQ(U8(64-h.tablebits), val) |
| 584 |
} |
| 585 |
|
| 586 |
func genEmitLiteral() { |
| 587 |
TEXT("emitLiteral", NOSPLIT, "func(dst, lit []byte) int") |
| 588 |
Doc("emitLiteral writes a literal chunk and returns the number of bytes written.", "", |
| 589 |
"It assumes that:", |
| 590 |
" dst is long enough to hold the encoded bytes", |
| 591 |
" 0 <= len(lit) && len(lit) <= math.MaxUint32", "") |
| 592 |
Pragma("noescape") |
| 593 |
|
| 594 |
dstBase, litBase, litLen, retval := GP64(), GP64(), GP64(), GP64() |
| 595 |
Load(Param("dst").Base(), dstBase) |
| 596 |
Load(Param("lit").Base(), litBase) |
| 597 |
Load(Param("lit").Len(), litLen) |
| 598 |
emitLiteral("standalone", litLen, retval, dstBase, litBase, "emit_literal_end_standalone", false, false) |
| 599 |
Label("emit_literal_end_standalone") |
| 600 |
Store(retval, ReturnIndex(0)) |
| 601 |
RET() |
| 602 |
|
| 603 |
TEXT("emitLiteralAvx", NOSPLIT, "func(dst, lit []byte) int") |
| 604 |
Doc("emitLiteralAvx writes a literal chunk and returns the number of bytes written.", "", |
| 605 |
"It assumes that:", |
| 606 |
" dst is long enough to hold the encoded bytes", |
| 607 |
" 0 <= len(lit) && len(lit) <= math.MaxUint32", "") |
| 608 |
Pragma("noescape") |
| 609 |
|
| 610 |
dstBase, litBase, litLen, retval = GP64(), GP64(), GP64(), GP64() |
| 611 |
Load(Param("dst").Base(), dstBase) |
| 612 |
Load(Param("lit").Base(), litBase) |
| 613 |
Load(Param("lit").Len(), litLen) |
| 614 |
emitLiteral("standalone", litLen, retval, dstBase, litBase, "emit_literal_end_avx_standalone", true, false) |
| 615 |
Label("emit_literal_end_avx_standalone") |
| 616 |
Store(retval, ReturnIndex(0)) |
| 617 |
RET() |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
func emitLiteral(name string, litLen, retval, dstBase, litBase reg.GPVirtual, end LabelRef, avx, updateDst bool) { |
| 627 |
n := GP64() |
| 628 |
n16 := GP64() |
| 629 |
|
| 630 |
|
| 631 |
if retval != nil { |
| 632 |
MOVQ(litLen, retval) |
| 633 |
} |
| 634 |
MOVQ(litLen, n) |
| 635 |
|
| 636 |
SUBL(U8(1), n.As32()) |
| 637 |
|
| 638 |
JC(end) |
| 639 |
|
| 640 |
|
| 641 |
CMPL(n.As32(), U8(60)) |
| 642 |
JLT(LabelRef("one_byte_" + name)) |
| 643 |
CMPL(n.As32(), U32(1<<8)) |
| 644 |
JLT(LabelRef("two_bytes_" + name)) |
| 645 |
CMPL(n.As32(), U32(1<<16)) |
| 646 |
JLT(LabelRef("three_bytes_" + name)) |
| 647 |
CMPL(n.As32(), U32(1<<24)) |
| 648 |
JLT(LabelRef("four_bytes_" + name)) |
| 649 |
|
| 650 |
Label("five_bytes_" + name) |
| 651 |
MOVB(U8(252), Mem{Base: dstBase}) |
| 652 |
MOVL(n.As32(), Mem{Base: dstBase, Disp: 1}) |
| 653 |
if retval != nil { |
| 654 |
ADDQ(U8(5), retval) |
| 655 |
} |
| 656 |
ADDQ(U8(5), dstBase) |
| 657 |
JMP(LabelRef("memmove_" + name)) |
| 658 |
|
| 659 |
Label("four_bytes_" + name) |
| 660 |
MOVQ(n, n16) |
| 661 |
SHRL(U8(16), n16.As32()) |
| 662 |
MOVB(U8(248), Mem{Base: dstBase}) |
| 663 |
MOVW(n.As16(), Mem{Base: dstBase, Disp: 1}) |
| 664 |
MOVB(n16.As8(), Mem{Base: dstBase, Disp: 3}) |
| 665 |
if retval != nil { |
| 666 |
ADDQ(U8(4), retval) |
| 667 |
} |
| 668 |
ADDQ(U8(4), dstBase) |
| 669 |
JMP(LabelRef("memmove_" + name)) |
| 670 |
|
| 671 |
Label("three_bytes_" + name) |
| 672 |
MOVB(U8(0xf4), Mem{Base: dstBase}) |
| 673 |
MOVW(n.As16(), Mem{Base: dstBase, Disp: 1}) |
| 674 |
if retval != nil { |
| 675 |
ADDQ(U8(3), retval) |
| 676 |
} |
| 677 |
ADDQ(U8(3), dstBase) |
| 678 |
JMP(LabelRef("memmove_" + name)) |
| 679 |
|
| 680 |
Label("two_bytes_" + name) |
| 681 |
MOVB(U8(0xf0), Mem{Base: dstBase}) |
| 682 |
MOVB(n.As8(), Mem{Base: dstBase, Disp: 1}) |
| 683 |
if retval != nil { |
| 684 |
ADDQ(U8(2), retval) |
| 685 |
} |
| 686 |
ADDQ(U8(2), dstBase) |
| 687 |
JMP(LabelRef("memmove_" + name)) |
| 688 |
|
| 689 |
Label("one_byte_" + name) |
| 690 |
SHLB(U8(2), n.As8()) |
| 691 |
MOVB(n.As8(), Mem{Base: dstBase}) |
| 692 |
if retval != nil { |
| 693 |
ADDQ(U8(1), retval) |
| 694 |
} |
| 695 |
ADDQ(U8(1), dstBase) |
| 696 |
|
| 697 |
|
| 698 |
Label("memmove_" + name) |
| 699 |
|
| 700 |
|
| 701 |
if true { |
| 702 |
dstEnd := GP64() |
| 703 |
if updateDst { |
| 704 |
LEAQ(Mem{Base: dstBase, Index: litLen, Scale: 1}, dstEnd) |
| 705 |
} |
| 706 |
genMemMove2("emit_lit_memmove_"+name, dstBase, litBase, litLen, end, avx) |
| 707 |
if updateDst { |
| 708 |
MOVQ(dstEnd, dstBase) |
| 709 |
} |
| 710 |
} else { |
| 711 |
genMemMove("emit_lit_memmove_"+name, dstBase, litBase, litLen, end) |
| 712 |
} |
| 713 |
return |
| 714 |
} |
| 715 |
|
| 716 |
|
| 717 |
func genEmitRepeat() { |
| 718 |
TEXT("emitRepeat", NOSPLIT, "func(dst []byte, offset, length int) int") |
| 719 |
Doc("emitRepeat writes a repeat chunk and returns the number of bytes written.", |
| 720 |
"Length must be at least 4 and < 1<<32", "") |
| 721 |
Pragma("noescape") |
| 722 |
|
| 723 |
dstBase, offset, length, retval := GP64(), GP64(), GP64(), GP64() |
| 724 |
|
| 725 |
|
| 726 |
XORQ(retval, retval) |
| 727 |
|
| 728 |
Load(Param("dst").Base(), dstBase) |
| 729 |
Load(Param("offset"), offset) |
| 730 |
Load(Param("length"), length) |
| 731 |
emitRepeat("standalone", length, offset, retval, dstBase, LabelRef("gen_emit_repeat_end")) |
| 732 |
Label("gen_emit_repeat_end") |
| 733 |
Store(retval, ReturnIndex(0)) |
| 734 |
RET() |
| 735 |
} |
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
func emitRepeat(name string, length, offset, retval, dstBase reg.GPVirtual, end LabelRef) { |
| 744 |
Label("emit_repeat_again_" + name) |
| 745 |
tmp := GP64() |
| 746 |
MOVQ(length, tmp) |
| 747 |
|
| 748 |
LEAQ(Mem{Base: length, Disp: -4}, length) |
| 749 |
|
| 750 |
|
| 751 |
CMPL(tmp.As32(), U8(8)) |
| 752 |
JLE(LabelRef("repeat_two_" + name)) |
| 753 |
|
| 754 |
|
| 755 |
CMPL(tmp.As32(), U8(12)) |
| 756 |
JGE(LabelRef("cant_repeat_two_offset_" + name)) |
| 757 |
CMPL(offset.As32(), U32(2048)) |
| 758 |
JLT(LabelRef("repeat_two_offset_" + name)) |
| 759 |
|
| 760 |
const maxRepeat = ((1 << 24) - 1) + 65536 |
| 761 |
Label("cant_repeat_two_offset_" + name) |
| 762 |
CMPL(length.As32(), U32((1<<8)+4)) |
| 763 |
JLT(LabelRef("repeat_three_" + name)) |
| 764 |
CMPL(length.As32(), U32((1<<16)+(1<<8))) |
| 765 |
JLT(LabelRef("repeat_four_" + name)) |
| 766 |
CMPL(length.As32(), U32(maxRepeat)) |
| 767 |
JLT(LabelRef("repeat_five_" + name)) |
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
LEAQ(Mem{Base: length, Disp: -(maxRepeat - 4)}, length) |
| 772 |
MOVW(U16(7<<2|tagCopy1), Mem{Base: dstBase}) |
| 773 |
MOVW(U16(65531), Mem{Base: dstBase, Disp: 2}) |
| 774 |
MOVB(U8(255), Mem{Base: dstBase, Disp: 4}) |
| 775 |
ADDQ(U8(5), dstBase) |
| 776 |
if retval != nil { |
| 777 |
ADDQ(U8(5), retval) |
| 778 |
} |
| 779 |
JMP(LabelRef("emit_repeat_again_" + name)) |
| 780 |
|
| 781 |
|
| 782 |
Label("repeat_five_" + name) |
| 783 |
LEAQ(Mem{Base: length, Disp: -65536}, length) |
| 784 |
MOVQ(length, offset) |
| 785 |
MOVW(U16(7<<2|tagCopy1), Mem{Base: dstBase}) |
| 786 |
MOVW(length.As16(), Mem{Base: dstBase, Disp: 2}) |
| 787 |
SARQ(U8(16), offset) |
| 788 |
MOVB(offset.As8(), Mem{Base: dstBase, Disp: 4}) |
| 789 |
if retval != nil { |
| 790 |
ADDQ(U8(5), retval) |
| 791 |
} |
| 792 |
ADDQ(U8(5), dstBase) |
| 793 |
JMP(end) |
| 794 |
|
| 795 |
Label("repeat_four_" + name) |
| 796 |
LEAQ(Mem{Base: length, Disp: -256}, length) |
| 797 |
MOVW(U16(6<<2|tagCopy1), Mem{Base: dstBase}) |
| 798 |
MOVW(length.As16(), Mem{Base: dstBase, Disp: 2}) |
| 799 |
if retval != nil { |
| 800 |
ADDQ(U8(4), retval) |
| 801 |
} |
| 802 |
ADDQ(U8(4), dstBase) |
| 803 |
JMP(end) |
| 804 |
|
| 805 |
Label("repeat_three_" + name) |
| 806 |
LEAQ(Mem{Base: length, Disp: -4}, length) |
| 807 |
MOVW(U16(5<<2|tagCopy1), Mem{Base: dstBase}) |
| 808 |
MOVB(length.As8(), Mem{Base: dstBase, Disp: 2}) |
| 809 |
if retval != nil { |
| 810 |
ADDQ(U8(3), retval) |
| 811 |
} |
| 812 |
ADDQ(U8(3), dstBase) |
| 813 |
JMP(end) |
| 814 |
|
| 815 |
Label("repeat_two_" + name) |
| 816 |
|
| 817 |
SHLL(U8(2), length.As32()) |
| 818 |
ORL(U8(tagCopy1), length.As32()) |
| 819 |
MOVW(length.As16(), Mem{Base: dstBase}) |
| 820 |
if retval != nil { |
| 821 |
ADDQ(U8(2), retval) |
| 822 |
} |
| 823 |
ADDQ(U8(2), dstBase) |
| 824 |
JMP(end) |
| 825 |
|
| 826 |
Label("repeat_two_offset_" + name) |
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
tmp = GP64() |
| 831 |
XORQ(tmp, tmp) |
| 832 |
|
| 833 |
LEAQ(Mem{Base: tmp, Index: length, Scale: 4, Disp: tagCopy1}, length) |
| 834 |
MOVB(offset.As8(), Mem{Base: dstBase, Disp: 1}) |
| 835 |
SARL(U8(8), offset.As32()) |
| 836 |
SHLL(U8(5), offset.As32()) |
| 837 |
ORL(offset.As32(), length.As32()) |
| 838 |
MOVB(length.As8(), Mem{Base: dstBase, Disp: 0}) |
| 839 |
if retval != nil { |
| 840 |
ADDQ(U8(2), retval) |
| 841 |
} |
| 842 |
ADDQ(U8(2), dstBase) |
| 843 |
|
| 844 |
JMP(end) |
| 845 |
} |
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
func genEmitCopy() { |
| 856 |
TEXT("emitCopy", NOSPLIT, "func(dst []byte, offset, length int) int") |
| 857 |
Doc("emitCopy writes a copy chunk and returns the number of bytes written.", "", |
| 858 |
"It assumes that:", |
| 859 |
" dst is long enough to hold the encoded bytes", |
| 860 |
" 1 <= offset && offset <= math.MaxUint32", |
| 861 |
" 4 <= length && length <= 1 << 24", "") |
| 862 |
Pragma("noescape") |
| 863 |
|
| 864 |
dstBase, offset, length, retval := GP64(), GP64(), GP64(), GP64() |
| 865 |
|
| 866 |
|
| 867 |
XORQ(retval, retval) |
| 868 |
|
| 869 |
Load(Param("dst").Base(), dstBase) |
| 870 |
Load(Param("offset"), offset) |
| 871 |
Load(Param("length"), length) |
| 872 |
emitCopy("standalone", length, offset, retval, dstBase, LabelRef("gen_emit_copy_end")) |
| 873 |
Label("gen_emit_copy_end") |
| 874 |
Store(retval, ReturnIndex(0)) |
| 875 |
RET() |
| 876 |
} |
| 877 |
|
| 878 |
const ( |
| 879 |
tagLiteral = 0x00 |
| 880 |
tagCopy1 = 0x01 |
| 881 |
tagCopy2 = 0x02 |
| 882 |
tagCopy4 = 0x03 |
| 883 |
) |
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
func emitCopy(name string, length, offset, retval, dstBase reg.GPVirtual, end LabelRef) { |
| 891 |
|
| 892 |
CMPL(offset.As32(), U32(65536)) |
| 893 |
JL(LabelRef("two_byte_offset_" + name)) |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
CMPL(length.As32(), U8(64)) |
| 898 |
JLE(LabelRef("four_bytes_remain_" + name)) |
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
MOVB(U8(63<<2|tagCopy4), Mem{Base: dstBase}) |
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
MOVD(offset, Mem{Base: dstBase, Disp: 1}) |
| 908 |
|
| 909 |
LEAQ(Mem{Base: length, Disp: -64}, length) |
| 910 |
if retval != nil { |
| 911 |
ADDQ(U8(5), retval) |
| 912 |
} |
| 913 |
ADDQ(U8(5), dstBase) |
| 914 |
|
| 915 |
|
| 916 |
CMPL(length.As32(), U8(4)) |
| 917 |
JL(LabelRef("four_bytes_remain_" + name)) |
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
emitRepeat(name+"_emit_copy", length, offset, retval, dstBase, end) |
| 923 |
|
| 924 |
Label("four_bytes_remain_" + name) |
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
TESTL(length.As32(), length.As32()) |
| 929 |
JZ(end) |
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
tmp := GP64() |
| 938 |
MOVB(U8(tagCopy4), tmp.As8()) |
| 939 |
|
| 940 |
LEAQ(Mem{Base: tmp, Disp: -(1 << 2), Index: length, Scale: 4}, length) |
| 941 |
MOVB(length.As8(), Mem{Base: dstBase}) |
| 942 |
MOVD(offset, Mem{Base: dstBase, Disp: 1}) |
| 943 |
|
| 944 |
if retval != nil { |
| 945 |
ADDQ(U8(5), retval) |
| 946 |
} |
| 947 |
ADDQ(U8(5), dstBase) |
| 948 |
JMP(end) |
| 949 |
|
| 950 |
Label("two_byte_offset_" + name) |
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
CMPL(length.As32(), U8(64)) |
| 955 |
JLE(LabelRef("two_byte_offset_short_" + name)) |
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
MOVB(U8(59<<2|tagCopy2), Mem{Base: dstBase}) |
| 962 |
MOVW(offset.As16(), Mem{Base: dstBase, Disp: 1}) |
| 963 |
|
| 964 |
LEAQ(Mem{Base: length, Disp: -60}, length) |
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
ADDQ(U8(3), dstBase) |
| 970 |
if retval != nil { |
| 971 |
ADDQ(U8(3), retval) |
| 972 |
} |
| 973 |
|
| 974 |
emitRepeat(name+"_emit_copy_short", length, offset, retval, dstBase, end) |
| 975 |
|
| 976 |
Label("two_byte_offset_short_" + name) |
| 977 |
|
| 978 |
CMPL(length.As32(), U8(12)) |
| 979 |
JGE(LabelRef("emit_copy_three_" + name)) |
| 980 |
CMPL(offset.As32(), U32(2048)) |
| 981 |
JGE(LabelRef("emit_copy_three_" + name)) |
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
tmp = GP64() |
| 987 |
MOVB(U8(tagCopy1), tmp.As8()) |
| 988 |
|
| 989 |
LEAQ(Mem{Base: tmp, Index: length, Scale: 4, Disp: -(4 << 2)}, length) |
| 990 |
MOVB(offset.As8(), Mem{Base: dstBase, Disp: 1}) |
| 991 |
SHRL(U8(8), offset.As32()) |
| 992 |
SHLL(U8(5), offset.As32()) |
| 993 |
ORL(offset.As32(), length.As32()) |
| 994 |
MOVB(length.As8(), Mem{Base: dstBase, Disp: 0}) |
| 995 |
if retval != nil { |
| 996 |
ADDQ(U8(2), retval) |
| 997 |
} |
| 998 |
ADDQ(U8(2), dstBase) |
| 999 |
|
| 1000 |
JMP(end) |
| 1001 |
|
| 1002 |
Label("emit_copy_three_" + name) |
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
tmp = GP64() |
| 1008 |
MOVB(U8(tagCopy2), tmp.As8()) |
| 1009 |
LEAQ(Mem{Base: tmp, Disp: -(1 << 2), Index: length, Scale: 4}, length) |
| 1010 |
MOVB(length.As8(), Mem{Base: dstBase}) |
| 1011 |
MOVW(offset.As16(), Mem{Base: dstBase, Disp: 1}) |
| 1012 |
|
| 1013 |
if retval != nil { |
| 1014 |
ADDQ(U8(3), retval) |
| 1015 |
} |
| 1016 |
ADDQ(U8(3), dstBase) |
| 1017 |
JMP(end) |
| 1018 |
} |
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
func genMemMove(name string, to, from, n reg.GPVirtual, end LabelRef) { |
| 1026 |
tmp := GP64() |
| 1027 |
MOVQ(n, tmp) |
| 1028 |
|
| 1029 |
SHRQ(U8(7), tmp) |
| 1030 |
|
| 1031 |
TESTQ(tmp, tmp) |
| 1032 |
JZ(LabelRef("done_128_" + name)) |
| 1033 |
Label("loop_128_" + name) |
| 1034 |
var xmmregs [8]reg.VecVirtual |
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
const preOff = 128 |
| 1040 |
PREFETCHT0(Mem{Base: to, Disp: preOff}) |
| 1041 |
PREFETCHT0(Mem{Base: to, Disp: preOff + 64}) |
| 1042 |
|
| 1043 |
for i := 0; i < 8; i++ { |
| 1044 |
xmmregs[i] = XMM() |
| 1045 |
MOVOU(Mem{Base: from}.Offset(i*16), xmmregs[i]) |
| 1046 |
} |
| 1047 |
for i := 0; i < 8; i++ { |
| 1048 |
MOVOU(xmmregs[i], Mem{Base: to}.Offset(i*16)) |
| 1049 |
} |
| 1050 |
LEAQ(Mem{Base: n, Disp: -128}, n) |
| 1051 |
ADDQ(U8(8*16), from) |
| 1052 |
ADDQ(U8(8*16), to) |
| 1053 |
DECQ(tmp) |
| 1054 |
JNZ(LabelRef("loop_128_" + name)) |
| 1055 |
|
| 1056 |
Label("done_128_" + name) |
| 1057 |
MOVQ(n, tmp) |
| 1058 |
|
| 1059 |
SHRQ(U8(4), tmp) |
| 1060 |
TESTQ(tmp, tmp) |
| 1061 |
JZ(LabelRef("done_16_" + name)) |
| 1062 |
|
| 1063 |
Label("loop_16_" + name) |
| 1064 |
xmm := XMM() |
| 1065 |
MOVOU(Mem{Base: from}, xmm) |
| 1066 |
MOVOU(xmm, Mem{Base: to}) |
| 1067 |
LEAQ(Mem{Base: n, Disp: -16}, n) |
| 1068 |
ADDQ(U8(16), from) |
| 1069 |
ADDQ(U8(16), to) |
| 1070 |
DECQ(tmp) |
| 1071 |
JNZ(LabelRef("loop_16_" + name)) |
| 1072 |
Label("done_16_" + name) |
| 1073 |
|
| 1074 |
|
| 1075 |
TESTQ(n, n) |
| 1076 |
JZ(end) |
| 1077 |
Label("loop_1_" + name) |
| 1078 |
MOVB(Mem{Base: from}, tmp.As8()) |
| 1079 |
MOVB(tmp.As8(), Mem{Base: to}) |
| 1080 |
INCQ(from) |
| 1081 |
INCQ(to) |
| 1082 |
DECQ(n) |
| 1083 |
JNZ(LabelRef("loop_1_" + name)) |
| 1084 |
} |
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
func genMemMove2(name string, dst, src, length reg.GPVirtual, end LabelRef, avx bool) { |
| 1092 |
AX, CX := GP64(), GP64() |
| 1093 |
NOP() |
| 1094 |
name += "_memmove_" |
| 1095 |
Label(name + "tail") |
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
TESTQ(length, length) |
| 1104 |
JEQ(end) |
| 1105 |
CMPQ(length, U8(2)) |
| 1106 |
JBE(LabelRef(name + "move_1or2")) |
| 1107 |
CMPQ(length, U8(4)) |
| 1108 |
JB(LabelRef(name + "move_3")) |
| 1109 |
JBE(LabelRef(name + "move_4")) |
| 1110 |
CMPQ(length, U8(8)) |
| 1111 |
JB(LabelRef(name + "move_5through7")) |
| 1112 |
JE(LabelRef(name + "move_8")) |
| 1113 |
CMPQ(length, U8(16)) |
| 1114 |
JBE(LabelRef(name + "move_9through16")) |
| 1115 |
CMPQ(length, U8(32)) |
| 1116 |
JBE(LabelRef(name + "move_17through32")) |
| 1117 |
CMPQ(length, U8(64)) |
| 1118 |
JBE(LabelRef(name + "move_33through64")) |
| 1119 |
CMPQ(length, U8(128)) |
| 1120 |
JBE(LabelRef(name + "move_65through128")) |
| 1121 |
CMPQ(length, U32(256)) |
| 1122 |
JBE(LabelRef(name + "move_129through256")) |
| 1123 |
|
| 1124 |
if avx { |
| 1125 |
JMP(LabelRef(name + "avxUnaligned")) |
| 1126 |
} else { |
| 1127 |
if false { |
| 1128 |
|
| 1129 |
Label(name + "forward") |
| 1130 |
CMPQ(length, U32(2048)) |
| 1131 |
JLS(LabelRef(name + "move_256through2048")) |
| 1132 |
|
| 1133 |
genMemMove(name+"fallback", dst, src, length, end) |
| 1134 |
} else { |
| 1135 |
JMP(LabelRef(name + "move_256through2048")) |
| 1136 |
} |
| 1137 |
} |
| 1138 |
|
| 1139 |
|
| 1140 |
SB) |
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
Label(name + "move_1or2") |
| 1203 |
MOVB(Mem{Base: src}, AX.As8()) |
| 1204 |
MOVB(Mem{Base: src, Disp: -1, Index: length, Scale: 1}, CX.As8()) |
| 1205 |
MOVB(AX.As8(), Mem{Base: dst}) |
| 1206 |
MOVB(CX.As8(), Mem{Base: dst, Disp: -1, Index: length, Scale: 1}) |
| 1207 |
JMP(end) |
| 1208 |
|
| 1209 |
Label(name + "move_4") |
| 1210 |
MOVL(Mem{Base: src}, AX.As32()) |
| 1211 |
MOVL(AX.As32(), Mem{Base: dst}) |
| 1212 |
JMP(end) |
| 1213 |
|
| 1214 |
Label(name + "move_3") |
| 1215 |
MOVW(Mem{Base: src}, AX.As16()) |
| 1216 |
MOVB(Mem{Base: src, Disp: 2}, CX.As8()) |
| 1217 |
MOVW(AX.As16(), Mem{Base: dst}) |
| 1218 |
MOVB(CX.As8(), Mem{Base: dst, Disp: 2}) |
| 1219 |
JMP(end) |
| 1220 |
|
| 1221 |
Label(name + "move_5through7") |
| 1222 |
MOVL(Mem{Base: src}, AX.As32()) |
| 1223 |
MOVL(Mem{Base: src, Disp: -4, Index: length, Scale: 1}, CX.As32()) |
| 1224 |
MOVL(AX.As32(), Mem{Base: dst}) |
| 1225 |
MOVL(CX.As32(), Mem{Base: dst, Disp: -4, Index: length, Scale: 1}) |
| 1226 |
JMP(end) |
| 1227 |
|
| 1228 |
Label(name + "move_8") |
| 1229 |
|
| 1230 |
MOVQ(Mem{Base: src}, AX) |
| 1231 |
MOVQ(AX, Mem{Base: dst}) |
| 1232 |
JMP(end) |
| 1233 |
|
| 1234 |
Label(name + "move_9through16") |
| 1235 |
MOVQ(Mem{Base: src}, AX) |
| 1236 |
MOVQ(Mem{Base: src, Disp: -8, Index: length, Scale: 1}, CX) |
| 1237 |
MOVQ(AX, Mem{Base: dst}) |
| 1238 |
MOVQ(CX, Mem{Base: dst, Disp: -8, Index: length, Scale: 1}) |
| 1239 |
JMP(end) |
| 1240 |
|
| 1241 |
Label(name + "move_17through32") |
| 1242 |
X0, X1, X2, X3, X4, X5, X6, X7 := XMM(), XMM(), XMM(), XMM(), XMM(), XMM(), XMM(), XMM() |
| 1243 |
X8, X9, X10, X11, X12, X13, X14, X15 := XMM(), XMM(), XMM(), XMM(), XMM(), XMM(), XMM(), XMM() |
| 1244 |
|
| 1245 |
MOVOU(Mem{Base: src}, X0) |
| 1246 |
MOVOU(Mem{Base: src, Disp: -16, Index: length, Scale: 1}, X1) |
| 1247 |
MOVOU(X0, Mem{Base: dst}) |
| 1248 |
MOVOU(X1, Mem{Base: dst, Disp: -16, Index: length, Scale: 1}) |
| 1249 |
JMP(end) |
| 1250 |
|
| 1251 |
Label(name + "move_33through64") |
| 1252 |
MOVOU(Mem{Base: src}, X0) |
| 1253 |
MOVOU(Mem{Base: src, Disp: 16}, X1) |
| 1254 |
MOVOU(Mem{Base: src, Disp: -32, Index: length, Scale: 1}, X2) |
| 1255 |
MOVOU(Mem{Base: src, Disp: -16, Index: length, Scale: 1}, X3) |
| 1256 |
MOVOU(X0, Mem{Base: dst}) |
| 1257 |
MOVOU(X1, Mem{Base: dst, Disp: 16}) |
| 1258 |
MOVOU(X2, Mem{Base: dst, Disp: -32, Index: length, Scale: 1}) |
| 1259 |
MOVOU(X3, Mem{Base: dst, Disp: -16, Index: length, Scale: 1}) |
| 1260 |
JMP(end) |
| 1261 |
|
| 1262 |
Label(name + "move_65through128") |
| 1263 |
MOVOU(Mem{Base: src}, X0) |
| 1264 |
MOVOU(Mem{Base: src, Disp: 16}, X1) |
| 1265 |
MOVOU(Mem{Base: src, Disp: 32}, X2) |
| 1266 |
MOVOU(Mem{Base: src, Disp: 48}, X3) |
| 1267 |
MOVOU(Mem{Base: src, Index: length, Scale: 1, Disp: -64}, X12) |
| 1268 |
MOVOU(Mem{Base: src, Index: length, Scale: 1, Disp: -48}, X13) |
| 1269 |
MOVOU(Mem{Base: src, Index: length, Scale: 1, Disp: -32}, X14) |
| 1270 |
MOVOU(Mem{Base: src, Index: length, Scale: 1, Disp: -16}, X15) |
| 1271 |
MOVOU(X0, Mem{Base: dst}) |
| 1272 |
MOVOU(X1, Mem{Base: dst, Disp: 16}) |
| 1273 |
MOVOU(X2, Mem{Base: dst, Disp: 32}) |
| 1274 |
MOVOU(X3, Mem{Base: dst, Disp: 48}) |
| 1275 |
MOVOU(X12, Mem{Base: dst, Index: length, Scale: 1, Disp: -64}) |
| 1276 |
MOVOU(X13, Mem{Base: dst, Index: length, Scale: 1, Disp: -48}) |
| 1277 |
MOVOU(X14, Mem{Base: dst, Index: length, Scale: 1, Disp: -32}) |
| 1278 |
MOVOU(X15, Mem{Base: dst, Index: length, Scale: 1, Disp: -16}) |
| 1279 |
JMP(end) |
| 1280 |
|
| 1281 |
Label(name + "move_129through256") |
| 1282 |
MOVOU(Mem{Base: src}, X0) |
| 1283 |
MOVOU(Mem{Base: src, Disp: 16}, X1) |
| 1284 |
MOVOU(Mem{Base: src, Disp: 32}, X2) |
| 1285 |
MOVOU(Mem{Base: src, Disp: 48}, X3) |
| 1286 |
MOVOU(Mem{Base: src, Disp: 64}, X4) |
| 1287 |
MOVOU(Mem{Base: src, Disp: 80}, X5) |
| 1288 |
MOVOU(Mem{Base: src, Disp: 96}, X6) |
| 1289 |
MOVOU(Mem{Base: src, Disp: 112}, X7) |
| 1290 |
MOVOU(Mem{Base: src, Index: length, Scale: 1, Disp: -128}, X8) |
| 1291 |
MOVOU(Mem{Base: src, Index: length, Scale: 1, Disp: -112}, X9) |
| 1292 |
MOVOU(Mem{Base: src, Index: length, Scale: 1, Disp: -96}, X10) |
| 1293 |
MOVOU(Mem{Base: src, Index: length, Scale: 1, Disp: -80}, X11) |
| 1294 |
MOVOU(Mem{Base: src, Index: length, Scale: 1, Disp: -64}, X12) |
| 1295 |
MOVOU(Mem{Base: src, Index: length, Scale: 1, Disp: -48}, X13) |
| 1296 |
MOVOU(Mem{Base: src, Index: length, Scale: 1, Disp: -32}, X14) |
| 1297 |
MOVOU(Mem{Base: src, Index: length, Scale: 1, Disp: -16}, X15) |
| 1298 |
MOVOU(X0, Mem{Base: dst}) |
| 1299 |
MOVOU(X1, Mem{Base: dst, Disp: 16}) |
| 1300 |
MOVOU(X2, Mem{Base: dst, Disp: 32}) |
| 1301 |
MOVOU(X3, Mem{Base: dst, Disp: 48}) |
| 1302 |
MOVOU(X4, Mem{Base: dst, Disp: 64}) |
| 1303 |
MOVOU(X5, Mem{Base: dst, Disp: 80}) |
| 1304 |
MOVOU(X6, Mem{Base: dst, Disp: 96}) |
| 1305 |
MOVOU(X7, Mem{Base: dst, Disp: 112}) |
| 1306 |
MOVOU(X8, Mem{Base: dst, Index: length, Scale: 1, Disp: -128}) |
| 1307 |
MOVOU(X9, Mem{Base: dst, Index: length, Scale: 1, Disp: -112}) |
| 1308 |
MOVOU(X10, Mem{Base: dst, Index: length, Scale: 1, Disp: -96}) |
| 1309 |
MOVOU(X11, Mem{Base: dst, Index: length, Scale: 1, Disp: -80}) |
| 1310 |
MOVOU(X12, Mem{Base: dst, Index: length, Scale: 1, Disp: -64}) |
| 1311 |
MOVOU(X13, Mem{Base: dst, Index: length, Scale: 1, Disp: -48}) |
| 1312 |
MOVOU(X14, Mem{Base: dst, Index: length, Scale: 1, Disp: -32}) |
| 1313 |
MOVOU(X15, Mem{Base: dst, Index: length, Scale: 1, Disp: -16}) |
| 1314 |
JMP(end) |
| 1315 |
|
| 1316 |
Label(name + "move_256through2048") |
| 1317 |
LEAQ(Mem{Base: length, Disp: -256}, length) |
| 1318 |
MOVOU(Mem{Base: src}, X0) |
| 1319 |
MOVOU(Mem{Base: src, Disp: 16}, X1) |
| 1320 |
MOVOU(Mem{Base: src, Disp: 32}, X2) |
| 1321 |
MOVOU(Mem{Base: src, Disp: 48}, X3) |
| 1322 |
MOVOU(Mem{Base: src, Disp: 64}, X4) |
| 1323 |
MOVOU(Mem{Base: src, Disp: 80}, X5) |
| 1324 |
MOVOU(Mem{Base: src, Disp: 96}, X6) |
| 1325 |
MOVOU(Mem{Base: src, Disp: 112}, X7) |
| 1326 |
MOVOU(Mem{Base: src, Disp: 128}, X8) |
| 1327 |
MOVOU(Mem{Base: src, Disp: 144}, X9) |
| 1328 |
MOVOU(Mem{Base: src, Disp: 160}, X10) |
| 1329 |
MOVOU(Mem{Base: src, Disp: 176}, X11) |
| 1330 |
MOVOU(Mem{Base: src, Disp: 192}, X12) |
| 1331 |
MOVOU(Mem{Base: src, Disp: 208}, X13) |
| 1332 |
MOVOU(Mem{Base: src, Disp: 224}, X14) |
| 1333 |
MOVOU(Mem{Base: src, Disp: 240}, X15) |
| 1334 |
MOVOU(X0, Mem{Base: dst}) |
| 1335 |
MOVOU(X1, Mem{Base: dst, Disp: 16}) |
| 1336 |
MOVOU(X2, Mem{Base: dst, Disp: 32}) |
| 1337 |
MOVOU(X3, Mem{Base: dst, Disp: 48}) |
| 1338 |
MOVOU(X4, Mem{Base: dst, Disp: 64}) |
| 1339 |
MOVOU(X5, Mem{Base: dst, Disp: 80}) |
| 1340 |
MOVOU(X6, Mem{Base: dst, Disp: 96}) |
| 1341 |
MOVOU(X7, Mem{Base: dst, Disp: 112}) |
| 1342 |
MOVOU(X8, Mem{Base: dst, Disp: 128}) |
| 1343 |
MOVOU(X9, Mem{Base: dst, Disp: 144}) |
| 1344 |
MOVOU(X10, Mem{Base: dst, Disp: 160}) |
| 1345 |
MOVOU(X11, Mem{Base: dst, Disp: 176}) |
| 1346 |
MOVOU(X12, Mem{Base: dst, Disp: 192}) |
| 1347 |
MOVOU(X13, Mem{Base: dst, Disp: 208}) |
| 1348 |
MOVOU(X14, Mem{Base: dst, Disp: 224}) |
| 1349 |
MOVOU(X15, Mem{Base: dst, Disp: 240}) |
| 1350 |
CMPQ(length, U32(256)) |
| 1351 |
LEAQ(Mem{Base: src, Disp: 256}, src) |
| 1352 |
LEAQ(Mem{Base: dst, Disp: 256}, dst) |
| 1353 |
JGE(LabelRef(name + "move_256through2048")) |
| 1354 |
JMP(LabelRef(name + "tail")) |
| 1355 |
|
| 1356 |
if avx { |
| 1357 |
Label(name + "avxUnaligned") |
| 1358 |
R8, R10 := GP64(), GP64() |
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
const enableBigData = false |
| 1367 |
if enableBigData { |
| 1368 |
CMPQ(length, U32(0x100000)) |
| 1369 |
JAE(LabelRef(name + "gobble_big_data_fwd")) |
| 1370 |
} |
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
Y0, Y1, Y2, Y3, Y4 := YMM(), YMM(), YMM(), YMM(), YMM() |
| 1399 |
|
| 1400 |
LEAQ(Mem{Base: src, Index: length, Scale: 1}, CX) |
| 1401 |
MOVQ(dst, R10) |
| 1402 |
|
| 1403 |
MOVOU(Mem{Base: CX, Disp: -0x80}, X5) |
| 1404 |
MOVOU(Mem{Base: CX, Disp: -0x70}, X6) |
| 1405 |
MOVQ(U32(0x80), AX) |
| 1406 |
|
| 1407 |
|
| 1408 |
ANDQ(U32(0xffffffe0), dst) |
| 1409 |
ADDQ(U8(32), dst) |
| 1410 |
|
| 1411 |
MOVOU(Mem{Base: CX, Disp: -0x60}, X7) |
| 1412 |
MOVOU(Mem{Base: CX, Disp: -0x50}, X8) |
| 1413 |
|
| 1414 |
MOVQ(dst, R8) |
| 1415 |
SUBQ(R10, R8) |
| 1416 |
|
| 1417 |
MOVOU(Mem{Base: CX, Disp: -0x40}, X9) |
| 1418 |
MOVOU(Mem{Base: CX, Disp: -0x30}, X10) |
| 1419 |
|
| 1420 |
SUBQ(R8, length) |
| 1421 |
|
| 1422 |
MOVOU(Mem{Base: CX, Disp: -0x20}, X11) |
| 1423 |
MOVOU(Mem{Base: CX, Disp: -0x10}, X12) |
| 1424 |
|
| 1425 |
|
| 1426 |
VMOVDQU(Mem{Base: src}, Y4) |
| 1427 |
|
| 1428 |
ADDQ(R8, src) |
| 1429 |
SUBQ(AX, length) |
| 1430 |
|
| 1431 |
|
| 1432 |
Label(name + "gobble_128_loop") |
| 1433 |
VMOVDQU(Mem{Base: src}, Y0) |
| 1434 |
VMOVDQU(Mem{Base: src, Disp: 0x20}, Y1) |
| 1435 |
VMOVDQU(Mem{Base: src, Disp: 0x40}, Y2) |
| 1436 |
VMOVDQU(Mem{Base: src, Disp: 0x60}, Y3) |
| 1437 |
ADDQ(AX, src) |
| 1438 |
VMOVDQA(Y0, Mem{Base: dst}) |
| 1439 |
VMOVDQA(Y1, Mem{Base: dst, Disp: 0x20}) |
| 1440 |
VMOVDQA(Y2, Mem{Base: dst, Disp: 0x40}) |
| 1441 |
VMOVDQA(Y3, Mem{Base: dst, Disp: 0x60}) |
| 1442 |
ADDQ(AX, dst) |
| 1443 |
SUBQ(AX, length) |
| 1444 |
JA(LabelRef(name + "gobble_128_loop")) |
| 1445 |
|
| 1446 |
ADDQ(AX, length) |
| 1447 |
ADDQ(dst, length) |
| 1448 |
VMOVDQU(Y4, Mem{Base: R10}) |
| 1449 |
VZEROUPPER() |
| 1450 |
MOVOU(X5, Mem{Base: length, Disp: -0x80}) |
| 1451 |
MOVOU(X6, Mem{Base: length, Disp: -0x70}) |
| 1452 |
MOVOU(X7, Mem{Base: length, Disp: -0x60}) |
| 1453 |
MOVOU(X8, Mem{Base: length, Disp: -0x50}) |
| 1454 |
MOVOU(X9, Mem{Base: length, Disp: -0x40}) |
| 1455 |
MOVOU(X10, Mem{Base: length, Disp: -0x30}) |
| 1456 |
MOVOU(X11, Mem{Base: length, Disp: -0x20}) |
| 1457 |
MOVOU(X12, Mem{Base: length, Disp: -0x10}) |
| 1458 |
JMP(end) |
| 1459 |
|
| 1460 |
if enableBigData { |
| 1461 |
Label(name + "gobble_big_data_fwd") |
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
LEAQ(Mem{Base: src, Index: length, Scale: 1}, CX) |
| 1466 |
MOVOU(Mem{Base: src, Index: length, Scale: 1, Disp: -0x80}, X5) |
| 1467 |
MOVOU(Mem{Base: CX, Disp: -0x70}, X6) |
| 1468 |
MOVOU(Mem{Base: CX, Disp: -0x60}, X7) |
| 1469 |
MOVOU(Mem{Base: CX, Disp: -0x50}, X8) |
| 1470 |
MOVOU(Mem{Base: CX, Disp: -0x40}, X9) |
| 1471 |
MOVOU(Mem{Base: CX, Disp: -0x30}, X10) |
| 1472 |
MOVOU(Mem{Base: CX, Disp: -0x20}, X11) |
| 1473 |
MOVOU(Mem{Base: CX, Disp: -0x10}, X12) |
| 1474 |
VMOVDQU(Mem{Base: src}, Y4) |
| 1475 |
MOVQ(dst, R8) |
| 1476 |
|
| 1477 |
ANDQ(U32(0xffffffe0), dst) |
| 1478 |
ADDQ(U8(32), dst) |
| 1479 |
|
| 1480 |
MOVQ(dst, R10) |
| 1481 |
SUBQ(R8, R10) |
| 1482 |
SUBQ(R10, length) |
| 1483 |
ADDQ(R10, src) |
| 1484 |
LEAQ(Mem{Base: dst, Index: length, Scale: 1}, CX) |
| 1485 |
SUBQ(U8(0x80), length) |
| 1486 |
|
| 1487 |
Label(name + "gobble_mem_fwd_loop") |
| 1488 |
PREFETCHNTA(Mem{Base: src, Disp: 0x1c0}) |
| 1489 |
PREFETCHNTA(Mem{Base: src, Disp: 0x280}) |
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
VMOVDQU(Mem{Base: src}, Y0) |
| 1495 |
VMOVDQU(Mem{Base: src, Disp: 0x20}, Y1) |
| 1496 |
VMOVDQU(Mem{Base: src, Disp: 0x40}, Y2) |
| 1497 |
VMOVDQU(Mem{Base: src, Disp: 0x60}, Y3) |
| 1498 |
|
| 1499 |
ADDQ(U8(0x80), src) |
| 1500 |
VMOVNTDQ(Y0, Mem{Base: dst}) |
| 1501 |
VMOVNTDQ(Y1, Mem{Base: dst, Disp: 0x20}) |
| 1502 |
VMOVNTDQ(Y2, Mem{Base: dst, Disp: 0x20}) |
| 1503 |
VMOVNTDQ(Y3, Mem{Base: dst, Disp: 0x60}) |
| 1504 |
ADDQ(U8(0x80), dst) |
| 1505 |
SUBQ(U8(0x80), length) |
| 1506 |
JA(LabelRef(name + "gobble_mem_fwd_loop")) |
| 1507 |
|
| 1508 |
|
| 1509 |
SFENCE() |
| 1510 |
VMOVDQU(Y4, Mem{Base: R8}) |
| 1511 |
VZEROUPPER() |
| 1512 |
MOVOU(X5, Mem{Base: CX, Disp: -0x80}) |
| 1513 |
MOVOU(X6, Mem{Base: CX, Disp: -0x70}) |
| 1514 |
MOVOU(X7, Mem{Base: CX, Disp: -0x60}) |
| 1515 |
MOVOU(X8, Mem{Base: CX, Disp: -0x50}) |
| 1516 |
MOVOU(X9, Mem{Base: CX, Disp: -0x40}) |
| 1517 |
MOVOU(X10, Mem{Base: CX, Disp: -0x30}) |
| 1518 |
MOVOU(X11, Mem{Base: CX, Disp: -0x20}) |
| 1519 |
MOVOU(X12, Mem{Base: CX, Disp: -0x10}) |
| 1520 |
JMP(end) |
| 1521 |
} |
| 1522 |
} |
| 1523 |
} |
| 1524 |
|
| 1525 |
|
| 1526 |
func genMatchLen() { |
| 1527 |
TEXT("matchLen", NOSPLIT, "func(a, b []byte) int") |
| 1528 |
Doc("matchLen returns how many bytes match in a and b", "", |
| 1529 |
"It assumes that:", |
| 1530 |
" len(a) <= len(b)", "") |
| 1531 |
Pragma("noescape") |
| 1532 |
|
| 1533 |
aBase, bBase, length := GP64(), GP64(), GP64() |
| 1534 |
|
| 1535 |
Load(Param("a").Base(), aBase) |
| 1536 |
Load(Param("b").Base(), bBase) |
| 1537 |
Load(Param("a").Len(), length) |
| 1538 |
l := matchLen("standalone", Mem{Base: aBase}, Mem{Base: bBase}, length, LabelRef("gen_match_len_end")) |
| 1539 |
Label("gen_match_len_end") |
| 1540 |
Store(l, ReturnIndex(0)) |
| 1541 |
RET() |
| 1542 |
} |
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
func matchLen(name string, a, b Mem, len reg.GPVirtual, end LabelRef) reg.GPVirtual { |
| 1549 |
tmp, matched := GP64(), GP64() |
| 1550 |
XORQ(matched, matched) |
| 1551 |
|
| 1552 |
CMPQ(len, U8(8)) |
| 1553 |
JL(LabelRef("matchlen_single_" + name)) |
| 1554 |
|
| 1555 |
Label("matchlen_loopback_" + name) |
| 1556 |
MOVQ(Mem{Base: a.Base, Index: matched, Scale: 1}, tmp) |
| 1557 |
XORQ(Mem{Base: b.Base, Index: matched, Scale: 1}, tmp) |
| 1558 |
TESTQ(tmp, tmp) |
| 1559 |
JZ(LabelRef("matchlen_loop_" + name)) |
| 1560 |
|
| 1561 |
BSFQ(tmp, tmp) |
| 1562 |
SARQ(U8(3), tmp) |
| 1563 |
LEAQ(Mem{Base: matched, Index: tmp, Scale: 1}, matched) |
| 1564 |
JMP(end) |
| 1565 |
|
| 1566 |
|
| 1567 |
Label("matchlen_loop_" + name) |
| 1568 |
LEAQ(Mem{Base: len, Disp: -8}, len) |
| 1569 |
LEAQ(Mem{Base: matched, Disp: 8}, matched) |
| 1570 |
CMPQ(len, U8(8)) |
| 1571 |
JGE(LabelRef("matchlen_loopback_" + name)) |
| 1572 |
|
| 1573 |
|
| 1574 |
Label("matchlen_single_" + name) |
| 1575 |
TESTQ(len, len) |
| 1576 |
JZ(end) |
| 1577 |
Label("matchlen_single_loopback_" + name) |
| 1578 |
MOVB(Mem{Base: a.Base, Index: matched, Scale: 1}, tmp.As8()) |
| 1579 |
CMPB(Mem{Base: b.Base, Index: matched, Scale: 1}, tmp.As8()) |
| 1580 |
JNE(end) |
| 1581 |
LEAQ(Mem{Base: matched, Disp: 1}, matched) |
| 1582 |
DECQ(len) |
| 1583 |
JNZ(LabelRef("matchlen_single_loopback_" + name)) |
| 1584 |
JMP(end) |
| 1585 |
return matched |
| 1586 |
} |