@@ -445,50 +445,34 @@ end
445
445
# Helper function to concatenate two UInt64 values with a byte shift
446
446
# Returns the result of shifting 'low' right by 'shift_bytes' bytes and
447
447
# filling the high bits with the low bits of 'high'
448
- @inline function concat_shift (low:: UInt64 , high:: UInt64 , shift_bytes:: Int )
449
- shift_bits = shift_bytes * 8
450
- return (low >> shift_bits) | (high << (64 - shift_bits))
448
+ @inline function concat_shift (low:: UInt64 , high:: UInt64 , shift_bytes:: UInt8 )
449
+ shift_bits = ( shift_bytes * 0x8 ) & 0x3f
450
+ return (low >> shift_bits) | (high << (0x40 - shift_bits))
451
451
end
452
452
453
- @eval @ inline function read_uint64_from_uint8_iter (iter, state)
453
+ @inline function read_uint64_from_uint8_iter (iter, state)
454
454
value = zero (UInt64)
455
- bytes_read = 0
456
- shift = 0
457
-
458
- for _ in 1 : 8
455
+ @nexprs 8 i -> begin
459
456
next_result = iterate (iter, state)
460
- next_result === nothing && break
457
+ next_result === nothing && return value, state, UInt8 (i - 1 )
461
458
byte, state = next_result
462
- value |= UInt64 (byte) << shift
463
- shift += 8
464
- bytes_read += 1
465
- $ (Expr (:loopinfo , (Symbol (" llvm.loop.disable_nonforced" ))))
466
- $ (Expr (:loopinfo , (Symbol (" llvm.loop.vectorize.enable" ), false )))
459
+ value |= UInt64 (byte) << ((i - 1 ) * 8 )
467
460
end
468
-
469
- return value, state, bytes_read
461
+ return value, state, 0x8
470
462
end
471
463
472
- @eval @ inline function read_uint64_from_uint8_iter (iter)
464
+ @inline function read_uint64_from_uint8_iter (iter)
473
465
next_result = iterate (iter)
474
466
next_result === nothing && return nothing
475
-
476
467
byte, state = next_result
477
468
value = UInt64 (byte)
478
- bytes_read = 1
479
-
480
- # Loop for remaining bytes
481
- for i in 2 : 8
469
+ @nexprs 7 i -> begin
482
470
next_result = iterate (iter, state)
483
- next_result === nothing && break
471
+ next_result === nothing && return value, state, UInt8 (i)
484
472
byte, state = next_result
485
- value |= UInt64 (byte:: UInt8 ) << ((i- 1 ) * 8 )
486
- bytes_read += 1
487
- $ (Expr (:loopinfo , (Symbol (" llvm.loop.disable_nonforced" ))))
488
- $ (Expr (:loopinfo , (Symbol (" llvm.loop.vectorize.enable" ), false )))
473
+ value |= UInt64 (byte:: UInt8 ) << (i * 8 )
489
474
end
490
-
491
- return value, state, bytes_read
475
+ return value, state, 0x8
492
476
end
493
477
494
478
@assume_effects :terminates_globally function hash_bytes (
@@ -510,12 +494,12 @@ end
510
494
l3 = zero (UInt64)
511
495
l4 = zero (UInt64)
512
496
l5 = zero (UInt64)
513
- b0 = 0
514
- b1 = 0
515
- b2 = 0
516
- b3 = 0
517
- b4 = 0
518
- b5 = 0
497
+ b0 = 0x0
498
+ b1 = 0x0
499
+ b2 = 0x0
500
+ b3 = 0x0
501
+ b4 = 0x0
502
+ b5 = 0x0
519
503
t0 = zero (UInt64)
520
504
t1 = zero (UInt64)
521
505
@@ -526,18 +510,18 @@ end
526
510
# Repeat hashing chunks until a short read
527
511
while true
528
512
l1, state, b1 = read_uint64_from_uint8_iter (iter, state)
529
- if b1 == 8
513
+ if b1 == 0x8
530
514
l2, state, b2 = read_uint64_from_uint8_iter (iter, state)
531
- if b2 == 8
515
+ if b2 == 0x8
532
516
l3, state, b3 = read_uint64_from_uint8_iter (iter, state)
533
- if b3 == 8
517
+ if b3 == 0x8
534
518
l4, state, b4 = read_uint64_from_uint8_iter (iter, state)
535
- if b4 == 8
519
+ if b4 == 0x8
536
520
l5, state, b5 = read_uint64_from_uint8_iter (iter, state)
537
- if b5 == 8
521
+ if b5 == 0x8
538
522
# Read start of next chunk
539
523
read = read_uint64_from_uint8_iter (iter, state)
540
- if read[3 ] == 0
524
+ if read[3 ] == 0x0
541
525
# Read exactly 48 bytes
542
526
t0 = l4
543
527
t1 = l5
554
538
b3 = 0
555
539
b4 = 0
556
540
b5 = 0
557
- if b0 != 8
541
+ if b0 < 8
558
542
t0 = concat_shift (l4, l5, b0)
559
543
t1 = concat_shift (l5, l0, b0)
560
544
break
@@ -598,26 +582,26 @@ end
598
582
end
599
583
buflen += bytes_chunk
600
584
if buflen ≤ 16
601
- if buflen ≥ 4
602
- seed ⊻= buflen
603
- if buflen ≥ 8
585
+ if bytes_chunk ≥ 0x4
586
+ seed ⊻= bytes_chunk
587
+ if bytes_chunk ≥ 0x8
604
588
a = l0
605
589
b = t1
606
590
else
607
591
a = UInt64 (l0 % UInt32)
608
- b = UInt64 ((l0 >>> (8 * (bytes_chunk - 4 ) )) % UInt32)
592
+ b = UInt64 ((l0 >>> (( 0x8 * (bytes_chunk - 0x4 )) % 0x3f )) % UInt32)
609
593
end
610
- elseif buflen > 0
594
+ elseif bytes_chunk > 0x0
611
595
b0 = l0 % UInt8
612
- b1 = (l0 >>> (8 * div (buflen, 2 ) )) % UInt8
613
- b2 = (l0 >>> (8 * (buflen - 1 ) )) % UInt8
596
+ b1 = (l0 >>> (( 0x8 * div (bytes_chunk, 0x2 )) % 0x3f )) % UInt8
597
+ b2 = (l0 >>> (( 0x8 * (bytes_chunk - 0x1 )) % 0x3f )) % UInt8
614
598
a = (UInt64 (b0) << 45 ) | UInt64 (b2)
615
599
b = UInt64 (b1)
616
600
end
617
601
else
618
- if bytes_chunk > 16
602
+ if bytes_chunk > 0x10
619
603
seed = hash_mix (l0 ⊻ secret[3 ], l1 ⊻ seed)
620
- if bytes_chunk > 32
604
+ if bytes_chunk > 0x20
621
605
seed = hash_mix (l2 ⊻ secret[3 ], l3 ⊻ seed)
622
606
end
623
607
end
0 commit comments