text
stringlengths
1
1.05M
.include "defaults_mod.asm" table_file_jp equ "exe4-utf8.tbl" table_file_en equ "bn4-utf8.tbl" game_code_len equ 3 game_code equ 0x4234574A // B4WJ game_code_2 equ 0x42345745 // B4WE game_code_3 equ 0x42345750 // B4WP card_type equ 1 card_id equ 29 card_no equ "029" card_sub equ "Mod Card 029" card_sub_x equ 64 card_desc_len equ 3 card_desc_1 equ "Address 0F" card_desc_2 equ "PET Screen Color:" card_desc_3 equ "Pink" card_name_jp_full equ "PET画面カラー:ピンク" card_name_jp_game equ "PET画面カラー:ピンク" card_name_en_full equ "PET Screen Color: Pink" card_name_en_game equ "PET Scrn Color: Pink" card_address equ "0F" card_address_id equ 5 card_bug equ 0 card_wrote_en equ "PET Scrn Color: Pink" card_wrote_jp equ "PET画面カラー:ピンク"
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r11 push %r13 push %r15 push %rbp push %rcx push %rdi push %rsi lea addresses_WC_ht+0x195dd, %rbp clflush (%rbp) xor $30447, %rdi and $0xffffffffffffffc0, %rbp movntdqa (%rbp), %xmm0 vpextrq $0, %xmm0, %r11 nop nop nop nop add %r15, %r15 lea addresses_UC_ht+0x69dd, %rsi nop nop nop nop nop xor $38698, %rcx movb $0x61, (%rsi) nop nop and $34591, %r11 lea addresses_A_ht+0xbce5, %rsi nop nop and $18363, %r13 mov (%rsi), %rbp nop nop nop nop nop sub $47247, %rcx lea addresses_WC_ht+0x1d2af, %rcx and %rdi, %rdi vmovups (%rcx), %ymm3 vextracti128 $0, %ymm3, %xmm3 vpextrq $1, %xmm3, %rsi nop nop nop inc %rcx lea addresses_A_ht+0xa05d, %rdi nop xor %r15, %r15 movb $0x61, (%rdi) nop nop add $24635, %rsi lea addresses_WT_ht+0xa9dd, %rdi nop and $12181, %rcx movb (%rdi), %r13b nop lfence lea addresses_WC_ht+0xb1cd, %r11 nop nop dec %rcx mov $0x6162636465666768, %rbp movq %rbp, %xmm4 vmovups %ymm4, (%r11) nop and $31422, %rbp lea addresses_WC_ht+0x3747, %rsi lea addresses_A_ht+0x1765d, %rdi nop cmp %r13, %r13 mov $114, %rcx rep movsw nop cmp $1922, %rcx lea addresses_normal_ht+0x1cfdd, %rsi lea addresses_WC_ht+0x73dd, %rdi nop nop nop nop add $42719, %r10 mov $123, %rcx rep movsb nop nop and $39525, %rsi lea addresses_UC_ht+0xdddd, %rsi lea addresses_WC_ht+0x1bb5d, %rdi xor $27156, %r11 mov $20, %rcx rep movsb nop nop nop nop nop dec %r11 lea addresses_A_ht+0x1e5dd, %rsi lea addresses_WT_ht+0x3f25, %rdi nop nop and $19397, %r10 mov $54, %rcx rep movsq nop nop nop and %r11, %r11 lea addresses_normal_ht+0x15b1d, %r11 clflush (%r11) nop cmp %r10, %r10 mov $0x6162636465666768, %rcx movq %rcx, %xmm4 movups %xmm4, (%r11) xor $13927, %rdi lea addresses_WT_ht+0x53dd, %rsi nop nop nop nop add %rcx, %rcx mov $0x6162636465666768, %r13 movq %r13, (%rsi) nop nop nop nop cmp $41363, %rcx pop %rsi pop %rdi pop %rcx pop %rbp pop %r15 pop %r13 pop %r11 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r14 push %r8 push %rax push %rbp push %rdx // Faulty Load lea addresses_normal+0x15ddd, %rdx nop nop nop and $61355, %r10 mov (%rdx), %eax lea oracles, %rdx and $0xff, %rax shlq $12, %rax mov (%rdx,%rax,1), %rax pop %rdx pop %rbp pop %rax pop %r8 pop %r14 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_normal', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'} [Faulty Load] {'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_normal', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'NT': True, 'same': False, 'congruent': 10, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 7, 'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 1}} {'src': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 8}, 'OP': 'LOAD'} {'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 32}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 6, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 1}} {'src': {'NT': False, 'same': False, 'congruent': 10, 'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 1}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 32}} {'src': {'same': False, 'congruent': 0, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 5, 'type': 'addresses_A_ht'}} {'src': {'same': False, 'congruent': 6, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 9, 'type': 'addresses_WC_ht'}} {'src': {'same': False, 'congruent': 7, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 7, 'type': 'addresses_WC_ht'}} {'src': {'same': False, 'congruent': 9, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 0, 'type': 'addresses_WT_ht'}} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 6, 'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 16}} {'OP': 'STOR', 'dst': {'NT': False, 'same': True, 'congruent': 2, 'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 8}} {'34': 21829} 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 */
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r11 push %r12 push %r14 push %rax push %rcx push %rdi push %rsi lea addresses_normal_ht+0x73ce, %r12 nop nop add %r14, %r14 mov $0x6162636465666768, %rcx movq %rcx, %xmm0 vmovups %ymm0, (%r12) cmp %rax, %rax lea addresses_WC_ht+0x164ce, %r11 clflush (%r11) xor %r10, %r10 mov (%r11), %edi nop nop inc %r10 lea addresses_normal_ht+0x165ce, %r14 nop nop dec %r10 mov (%r14), %r12w nop nop nop nop dec %rcx lea addresses_D_ht+0x607e, %rsi lea addresses_normal_ht+0xa7e0, %rdi nop nop xor $32318, %rax mov $99, %rcx rep movsq nop nop xor %rcx, %rcx lea addresses_normal_ht+0x1c7ce, %r11 nop nop and %r14, %r14 mov $0x6162636465666768, %rsi movq %rsi, (%r11) nop nop dec %rcx lea addresses_D_ht+0x119ce, %rsi lea addresses_WT_ht+0x121ce, %rdi dec %r12 mov $107, %rcx rep movsl and %r12, %r12 lea addresses_WC_ht+0xace2, %rsi lea addresses_WC_ht+0x75ce, %rdi nop nop nop nop cmp %r11, %r11 mov $104, %rcx rep movsw nop nop xor %rcx, %rcx pop %rsi pop %rdi pop %rcx pop %rax pop %r14 pop %r12 pop %r11 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r14 push %rdi push %rdx push %rsi // Faulty Load mov $0x6e5d3900000005ce, %rsi nop nop nop xor $31258, %r10 vmovups (%rsi), %ymm1 vextracti128 $1, %ymm1, %xmm1 vpextrq $0, %xmm1, %rdi lea oracles, %rsi and $0xff, %rdi shlq $12, %rdi mov (%rsi,%rdi,1), %rdi pop %rsi pop %rdx pop %rdi pop %r14 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'AVXalign': False, 'congruent': 0, 'size': 16, 'same': False, 'NT': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_NC', 'AVXalign': False, 'congruent': 0, 'size': 32, 'same': True, 'NT': False}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 4, 'size': 32, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 3, 'size': 4, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 10, 'size': 2, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 1, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 6, 'size': 8, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 8, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 11, 'same': False}} {'6e': 2, '46': 21813, '00': 11, '66': 1, '54': 1, '6f': 1} 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 00 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 */
; A285075: Positions of 1 in A285073; complement of A285074. ; 2,4,6,9,11,14,16,18,21,23,26,28,30,33,35,38,40,43,45,47,50,52,55,57,59,62,64,67,69,72,74,76,79,81,84,86,88,91,93,96,98,100,103,105,108,110,113,115,117,120,122,125,127,129,132,134,137,139,142,144,146,149,151,154,156,158,161,163,166,168,170,173,175,178,180,183,185,187,190,192,195,197,199,202,204,207,209,212,214,216,219,221,224,226,228,231,233,236,238,241,243,245,248,250,253,255,257,260,262,265,267,269,272,274,277,279,282,284,286,289,291,294,296,298,301,303,306,308,311,313,315,318,320,323,325,327,330,332,335,337,339,342,344,347,349,352,354,356,359,361,364,366,368,371,373,376,378,381,383,385,388,390,393,395,397,400,402,405,407,410,412,414,417,419,422,424,426,429,431,434,436,438,441,443,446,448,451,453,455,458,460,463,465,467,470,472,475,477,480,482,484,487,489,492,494,496,499,501,504,506,508,511,513,516,518,521,523,525,528,530,533,535,537,540,542,545,547,550,552,554,557,559,562,564,566,569,571,574,576,578,581,583,586,588,591,593,595,598,600,603 mov $4,$0 add $4,1 mov $6,$0 lpb $4 mov $0,$6 sub $4,1 sub $0,$4 mov $7,$0 mov $9,2 lpb $9 mov $0,$7 sub $9,1 add $0,$9 sub $0,1 pow $0,2 mul $0,2 mov $2,$0 mov $5,2 lpb $2 sub $2,1 trn $2,$5 add $5,2 lpe mov $3,$9 lpb $3 sub $3,1 mov $8,$5 lpe lpe lpb $7 mov $7,0 sub $8,$5 lpe mov $5,$8 sub $5,2 div $5,2 add $5,2 add $1,$5 lpe
// ************************************************************************* // // This File Is Automatically Generated by the StarBusIDL-to-C++ Compiler ! // // Copyright (c) 2003 // Network Information Security Institute,Computer College,NUDT. // ChangSha,Hunan,PRC // // All Rights Reserved // // ************************************************************************* // Version: 5.0.0 #include <STAR/CORBAClient.h> #include <STAR/CORBAServer.h> #include <counter.h> STAR::TypeCodeConst _tc_Counter( "01a97d000e0000002400000001f0fd7f1000000049444c3a436f756e7465723a312e300008000" "000436f756e74657200" ); // // Interface declare ::Counter // const char* Counter::ids_[] = { "IDL:Counter:1.0", 0 }; void STARDuplicate(Counter_ptr p) { if(p) p -> _STAR_incRef(); } void STARRelease(Counter_ptr p) { if(p) p -> _STAR_decRef(); } Counter_ptr Counter::_narrow(CORBA::Object_ptr p) { if(!CORBA::is_nil(p)) { Counter_ptr v = dynamic_cast<Counter_ptr>(p); if(v) return _duplicate(v); if(p -> _is_a(ids_[0])) { Counter_broker* val = new Counter_broker; val -> _STAR_copyFrom(p); return val; } } return _nil(); } Counter_ptr Counter::_narrow(CORBA::AbstractBase_ptr p) { if(!CORBA::is_nil(p)) { CORBA::Object_var obj = p -> _to_object(); return _narrow(obj); } return _nil(); } Counter_ptr Counter::_unchecked_narrow(CORBA::Object_ptr p) { if(!CORBA::is_nil(p)) { Counter_ptr v = dynamic_cast<Counter_ptr>(p); if(v) return _duplicate(v); Counter_broker* val = new Counter_broker; val -> _STAR_copyFrom(p); return val; } return _nil(); } Counter_ptr Counter::_unchecked_narrow(CORBA::AbstractBase_ptr p) { if(!CORBA::is_nil(p)) { CORBA::Object_var obj = p -> _to_object(); return _unchecked_narrow(obj); } return _nil(); } const char** Counter::_STAR_staticIds() { return ids_; } void STARMarshal(Counter_ptr _star_v, STAR::OutputStreamImpl* _star_out) { _star_out -> write_Object(_star_v); } void STARUnmarshal(Counter_ptr& _star_v, STAR::InputStreamImpl* _star_in) { Counter_var old = _star_v; CORBA::Object_var p = _star_in -> read_Object(); if(!CORBA::is_nil(p)) { Counter_broker* _star_obj = new Counter_broker; _star_obj -> _STAR_copyFrom(p); _star_v = _star_obj; } else _star_v = Counter::_nil(); } void operator<<=(CORBA::Any& any, Counter_ptr* v) { any.replace(_tc_Counter, (CORBA::Object_ptr)*v, true); } void operator<<=(CORBA::Any& any, Counter_ptr v) { Counter_ptr val = Counter::_duplicate(v); any <<= &val; } CORBA::Boolean operator>>=(const CORBA::Any& any, Counter_ptr& v) { if(any.check_type(_tc_Counter)) { CORBA::Object_ptr val = (CORBA::Object_ptr)any.value(); if(!CORBA::is_nil(val)) { if(!(v = dynamic_cast<Counter_ptr>(val))) { Counter_broker* obj = new Counter_broker; obj -> _STAR_copyFrom(val); v = obj; (CORBA::Any&)any <<= &v; } } else v = Counter::_nil(); return true; } else return false; } const char** Counter_broker::_STAR_ids() const { return ids_; } // // Attribute declare Counter_broker::count // CORBA::Long Counter_broker::count() { bool _star_retry = true; while(true) { try { STAR::StubBase_var _star_stubBase = _STAR_getStub(); STAR::MarshalStub_ptr _star_stub = dynamic_cast<STAR::MarshalStub_ptr>(_star_stubBase.in()); if (_star_stub!=NULL) { for(;;) { STAR::Downcall_var _star_down = _star_stub->_STAR_createDowncall("_get_count", true); try { _star_stub->_STAR_prePrepareHeader(_star_down); _star_stub->_STAR_postPrepareHeader(_star_down); _star_stub->_STAR_request(_star_down); STAR::InputStreamImpl* _star_in = _star_stub->_STAR_preRemoveHeader(_star_down); CORBA::Long _star_r; try { _star_r = _star_in -> read_long(); } catch(const CORBA::SystemException& _star_ex) { _star_stub->_STAR_unmarshalEx(_star_down, _star_ex); } _star_stub->_STAR_postRemoveHeader(_star_down); return _star_r; } catch(const STAR::FailureException& _star_ex) { _star_stub->_STAR_handleNetworkFailureException(_star_down, _star_ex); } } } } catch(const STAR::ExceptionBase& _star_ex) { _STAR_handleException(_star_ex, _star_retry); } } } // // Operation declare Counter_broker::increment // void Counter_broker::increment() { bool _star_retry = true; while(true) { try { STAR::StubBase_var _star_stubBase = _STAR_getStub(); STAR::MarshalStub_ptr _star_stub = dynamic_cast<STAR::MarshalStub_ptr>(_star_stubBase.in()); if (_star_stub!=NULL) { for(;;) { STAR::Downcall_var _star_down = _star_stub->_STAR_createDowncall("increment", true); try { _star_stub->_STAR_prePrepareHeader(_star_down); _star_stub->_STAR_postPrepareHeader(_star_down); _star_stub->_STAR_request(_star_down); _star_stub->_STAR_preRemoveHeader(_star_down); _star_stub->_STAR_postRemoveHeader(_star_down); break; } catch(const STAR::FailureException& _star_ex) { _star_stub->_STAR_handleNetworkFailureException(_star_down, _star_ex); } } #if defined(__GNUC__) && defined(__OPTIMIZE__) // COMPILERFIX volatile int i = 1; i++; #endif return; } else { throw CORBA::INV_OBJREF(); } } catch(const STAR::ExceptionBase& _star_ex) { _STAR_handleException(_star_ex, _star_retry); } } } // // Operation declare Counter_broker::decrement // void Counter_broker::decrement() { bool _star_retry = true; while(true) { try { STAR::StubBase_var _star_stubBase = _STAR_getStub(); STAR::MarshalStub_ptr _star_stub = dynamic_cast<STAR::MarshalStub_ptr>(_star_stubBase.in()); if (_star_stub!=NULL) { for(;;) { STAR::Downcall_var _star_down = _star_stub->_STAR_createDowncall("decrement", true); try { _star_stub->_STAR_prePrepareHeader(_star_down); _star_stub->_STAR_postPrepareHeader(_star_down); _star_stub->_STAR_request(_star_down); _star_stub->_STAR_preRemoveHeader(_star_down); _star_stub->_STAR_postRemoveHeader(_star_down); break; } catch(const STAR::FailureException& _star_ex) { _star_stub->_STAR_handleNetworkFailureException(_star_down, _star_ex); } } #if defined(__GNUC__) && defined(__OPTIMIZE__) // COMPILERFIX volatile int i = 1; i++; #endif return; } else { throw CORBA::INV_OBJREF(); } } catch(const STAR::ExceptionBase& _star_ex) { _STAR_handleException(_star_ex, _star_retry); } } }
frame 1, 08 frame 2, 18 frame 3, 12 frame 1, 08 endanim
#ifndef CLIENT_PRIVATE_HTTP_HPP #define CLIENT_PRIVATE_HTTP_HPP #include <boost/asio.hpp> #include <boost/beast/http.hpp> #include <memory> #include "client_private.hpp" namespace simple_http { template <typename RequestBody, typename ResponseBody> class basic_client; template <typename RequestBody, typename ResponseBody> class client_private_http : public client_private<RequestBody, ResponseBody>, public std::enable_shared_from_this<client_private_http<RequestBody, ResponseBody>> { public: explicit client_private_http(boost::asio::io_context &io, std::shared_ptr<basic_client<RequestBody, ResponseBody>> c) : client_private<RequestBody, ResponseBody>{io, c}, m_socket{io} { } private: boost::asio::ip::tcp::socket m_socket; inline std::shared_ptr<client_private<RequestBody, ResponseBody>> shared_from_this() { return std::enable_shared_from_this<client_private_http<RequestBody, ResponseBody>>::shared_from_this(); } inline std::shared_ptr<client_private_http<RequestBody, ResponseBody>> self() { return std::enable_shared_from_this<client_private_http<RequestBody, ResponseBody>>::shared_from_this(); } void connectSocket() { this->resetTimeout(Connect); boost::asio::async_connect(m_socket, this->m_resolveResults.begin(), this->m_resolveResults.end(), std::bind(&client_private_http<RequestBody, ResponseBody>::onConnect, self(), std::placeholders::_1)); } void sendRequest() { this->resetTimeout(RequestSend); this->clearResponse(); boost::beast::http::async_write( m_socket, this->m_request, std::bind(&client_private_http<RequestBody, ResponseBody>::onWrite, self(), std::placeholders::_1, std::placeholders::_2)); } void initiateReadHeader() { this->resetTimeout(Header); // Receive the HTTP response header boost::beast::http::async_read_header( m_socket, this->m_buffer, *(this->m_responseParser), std::bind(&client_private_http<RequestBody, ResponseBody>::onReadHeader, self(), std::placeholders::_1, std::placeholders::_2)); } void initiateRead() { this->resetTimeout(Contents); // Receive the HTTP response boost::beast::http::async_read( m_socket, this->m_buffer, *(this->m_responseParser), std::bind(&client_private_http<RequestBody, ResponseBody>::onRead, self(), std::placeholders::_1, std::placeholders::_2)); } void closeSocket(boost::system::error_code &ec) { m_socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec); } }; } // namespace simple_http #endif // CLIENT_PRIVATE_HTTP_HPP
%include "common.inc" global gdt_load gdt_load: lgdt [rdi] mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment mov ds, ax ; Load all data segment selectors mov es, ax mov ss, ax ; flush the CS segment with iretq mov rcx, qword .reloadcs mov rsi, rsp push rax ; new SS push rsi ; new RSP push 2 ; new FLAGS push 0x8 ; new CS push rcx ; new RIP iretq .reloadcs: ret global tss_load tss_load: mov ax, (0x28 | 3) ltr ax ; Set FS and GS to enable writing to them using MSRs mov ax, 0x1B mov fs, ax mov gs, ax ret global gs_load gs_load: ; KernelGSBase - The MSR that swapgs loads from mov ecx, 0xC0000102 mov rax, rdi ; EAX stores lower 32 bits mov rdx, rdi ; EDX stores upper 32 bits shr rdx, 32 wrmsr ret %macro ISR_NOERROR_CODE 1 [GLOBAL isr%1] isr%1: push qword 0 push qword %1 jmp interrupt_common_stub %endmacro %macro ISR_ERROR_CODE 1 [GLOBAL isr%1] isr%1: push qword %1 jmp interrupt_common_stub %endmacro %macro IRQ 2 [GLOBAL irq%1] irq%1: push qword 0 push qword %2 jmp interrupt_common_stub %endmacro ISR_NOERROR_CODE 0 ISR_NOERROR_CODE 1 ISR_NOERROR_CODE 2 ISR_NOERROR_CODE 3 ISR_NOERROR_CODE 4 ISR_NOERROR_CODE 5 ISR_NOERROR_CODE 6 ISR_NOERROR_CODE 7 ISR_ERROR_CODE 8 ISR_NOERROR_CODE 9 ISR_ERROR_CODE 10 ISR_ERROR_CODE 11 ISR_ERROR_CODE 12 ISR_ERROR_CODE 13 ISR_ERROR_CODE 14 ISR_NOERROR_CODE 15 ; Reserved ISR_NOERROR_CODE 16 ISR_ERROR_CODE 17 ISR_NOERROR_CODE 18 ISR_NOERROR_CODE 19 ISR_NOERROR_CODE 20 ISR_NOERROR_CODE 21 ; Reserved ISR_NOERROR_CODE 22 ; Reserved ISR_NOERROR_CODE 23 ; Reserved ISR_NOERROR_CODE 24 ; Reserved ISR_NOERROR_CODE 25 ; Reserved ISR_NOERROR_CODE 26 ; Reserved ISR_NOERROR_CODE 27 ; Reserved ISR_NOERROR_CODE 28 ; Reserved ISR_NOERROR_CODE 29 ; Reserved ISR_ERROR_CODE 30 ISR_NOERROR_CODE 31 ISR_NOERROR_CODE 128 ; System call vector ISR_NOERROR_CODE 129 ; Yield ; IRQs IRQ 0, 32 IRQ 1, 33 IRQ 2, 34 IRQ 3, 35 IRQ 4, 36 IRQ 5, 37 IRQ 6, 38 IRQ 7, 39 IRQ 8, 40 IRQ 9, 41 IRQ 10, 42 IRQ 11, 43 IRQ 12, 44 IRQ 13, 45 IRQ 14, 46 IRQ 15, 47 extern arch_handler interrupt_common_stub: cld PUSHA ; Store DS xor rax, rax mov ax, ds push rax mov ax, 0x10 mov ds, ax mov es, ax ; Store FS mov rcx, 0xC0000100 rdmsr shl rdx, 32 or rdx, rax push rdx ; Store GS mov rcx, 0xC0000101 rdmsr shl rdx, 32 or rdx, rax push rdx mov rdi, rsp call arch_handler interrupt_return: pop rdx mov eax, edx shr rdx, 32 mov rcx, 0xC0000101 wrmsr pop rdx mov eax, edx shr rdx, 32 mov rcx, 0xC0000100 wrmsr pop rax mov ds, ax mov es, ax POPA add rsp, 16 iretq global idt_load idt_load: lidt [rdi] ret global load_register_state load_register_state: mov rsp, rdi jmp interrupt_return
SafariZoneEast_h: db FOREST ; tileset db SAFARI_ZONE_EAST_HEIGHT, SAFARI_ZONE_EAST_WIDTH ; dimensions (y, x) dw SafariZoneEastBlocks, SafariZoneEastTextPointers, SafariZoneEastScript ; blocks, texts, scripts db $00 ; connections dw SafariZoneEastObject ; objects
; ; jdmerge.asm - merged upsampling/color conversion (64-bit AVX2) ; ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB ; Copyright (C) 2009, 2016, D. R. Commander. ; Copyright (C) 2015, Intel Corporation. ; ; 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 %include "jsimdext.inc" ; -------------------------------------------------------------------------- %define SCALEBITS 16 F_0_344 equ 22554 ; FIX(0.34414) F_0_714 equ 46802 ; FIX(0.71414) F_1_402 equ 91881 ; FIX(1.40200) F_1_772 equ 116130 ; FIX(1.77200) F_0_402 equ (F_1_402 - 65536) ; FIX(1.40200) - FIX(1) F_0_285 equ ( 65536 - F_0_714) ; FIX(1) - FIX(0.71414) F_0_228 equ (131072 - F_1_772) ; FIX(2) - FIX(1.77200) ; -------------------------------------------------------------------------- SECTION SEG_CONST alignz 32 GLOBAL_DATA(jconst_merged_upsample_avx2) EXTN(jconst_merged_upsample_avx2): PW_F0402 times 16 dw F_0_402 PW_MF0228 times 16 dw -F_0_228 PW_MF0344_F0285 times 8 dw -F_0_344, F_0_285 PW_ONE times 16 dw 1 PD_ONEHALF times 8 dd 1 << (SCALEBITS - 1) alignz 32 ; -------------------------------------------------------------------------- SECTION SEG_TEXT BITS 64 %include "jdmrgext-avx2.asm" %undef RGB_RED %undef RGB_GREEN %undef RGB_BLUE %undef RGB_PIXELSIZE %define RGB_RED EXT_RGB_RED %define RGB_GREEN EXT_RGB_GREEN %define RGB_BLUE EXT_RGB_BLUE %define RGB_PIXELSIZE EXT_RGB_PIXELSIZE %define jsimd_h2v1_merged_upsample_avx2 \ jsimd_h2v1_extrgb_merged_upsample_avx2 %define jsimd_h2v2_merged_upsample_avx2 \ jsimd_h2v2_extrgb_merged_upsample_avx2 %include "jdmrgext-avx2.asm" %undef RGB_RED %undef RGB_GREEN %undef RGB_BLUE %undef RGB_PIXELSIZE %define RGB_RED EXT_RGBX_RED %define RGB_GREEN EXT_RGBX_GREEN %define RGB_BLUE EXT_RGBX_BLUE %define RGB_PIXELSIZE EXT_RGBX_PIXELSIZE %define jsimd_h2v1_merged_upsample_avx2 \ jsimd_h2v1_extrgbx_merged_upsample_avx2 %define jsimd_h2v2_merged_upsample_avx2 \ jsimd_h2v2_extrgbx_merged_upsample_avx2 %include "jdmrgext-avx2.asm" %undef RGB_RED %undef RGB_GREEN %undef RGB_BLUE %undef RGB_PIXELSIZE %define RGB_RED EXT_BGR_RED %define RGB_GREEN EXT_BGR_GREEN %define RGB_BLUE EXT_BGR_BLUE %define RGB_PIXELSIZE EXT_BGR_PIXELSIZE %define jsimd_h2v1_merged_upsample_avx2 \ jsimd_h2v1_extbgr_merged_upsample_avx2 %define jsimd_h2v2_merged_upsample_avx2 \ jsimd_h2v2_extbgr_merged_upsample_avx2 %include "jdmrgext-avx2.asm" %undef RGB_RED %undef RGB_GREEN %undef RGB_BLUE %undef RGB_PIXELSIZE %define RGB_RED EXT_BGRX_RED %define RGB_GREEN EXT_BGRX_GREEN %define RGB_BLUE EXT_BGRX_BLUE %define RGB_PIXELSIZE EXT_BGRX_PIXELSIZE %define jsimd_h2v1_merged_upsample_avx2 \ jsimd_h2v1_extbgrx_merged_upsample_avx2 %define jsimd_h2v2_merged_upsample_avx2 \ jsimd_h2v2_extbgrx_merged_upsample_avx2 %include "jdmrgext-avx2.asm" %undef RGB_RED %undef RGB_GREEN %undef RGB_BLUE %undef RGB_PIXELSIZE %define RGB_RED EXT_XBGR_RED %define RGB_GREEN EXT_XBGR_GREEN %define RGB_BLUE EXT_XBGR_BLUE %define RGB_PIXELSIZE EXT_XBGR_PIXELSIZE %define jsimd_h2v1_merged_upsample_avx2 \ jsimd_h2v1_extxbgr_merged_upsample_avx2 %define jsimd_h2v2_merged_upsample_avx2 \ jsimd_h2v2_extxbgr_merged_upsample_avx2 %include "jdmrgext-avx2.asm" %undef RGB_RED %undef RGB_GREEN %undef RGB_BLUE %undef RGB_PIXELSIZE %define RGB_RED EXT_XRGB_RED %define RGB_GREEN EXT_XRGB_GREEN %define RGB_BLUE EXT_XRGB_BLUE %define RGB_PIXELSIZE EXT_XRGB_PIXELSIZE %define jsimd_h2v1_merged_upsample_avx2 \ jsimd_h2v1_extxrgb_merged_upsample_avx2 %define jsimd_h2v2_merged_upsample_avx2 \ jsimd_h2v2_extxrgb_merged_upsample_avx2 %include "jdmrgext-avx2.asm"
disableGameLogik dc.b $00 ; no gamelogik at all just interstitials and so on disablePlayerInteraction dc.b $00 ; the player isn't controllable and doesn't collide playerShotActive dc.b $00 ;------------------------------------------------------------- ;-- The main gamelogik loopfunction -- ;------------------------------------------------------------- gameLogik SUBROUTINE lda disableGameLogik beq .enabled jmp .disabled .enabled lda disablePlayerInteraction beq .playerInteraction jsr playerNotMoveUp jsr playerNotMoveDown jmp .noPlayerInteraction .playerInteraction ; player inputs lda joyMoveLeft beq .notleft jsr playerMoveLeft .notleft lda joyMoveRight beq .notright jsr playerMoveRight .notright lda joyMoveUp beq .notup jsr playerMoveUp jmp .updone .notup jsr playerNotMoveUp .updone lda joyMoveDown beq .notdown jsr playerMoveDown jmp .downdone .notdown jsr playerNotMoveDown .downdone lda joyPressed beq .notpressed jsr playerButton jmp .donepressed .notpressed jsr playerNotButton .donepressed ; gravity jsr playerGravity jsr playerAlways ; display some dust if required jsr playerDisplayDustFrame ; clamp the player jsr clampPlayerPos .noPlayerInteraction ; handle the enemies jsr handleEnemies ; perhaps we can clear some enemies jsr clearSomeEnemies ; did our shot hit something ; shots are evaluated every frame (not every second like the enemies) lda playerShotActive beq .noshotactive jsr checkCollsionWithPlayerShot lda #$00 sta playerShotActive .noshotactive lda disablePlayerInteraction bne .noplayerStuff ; check collisions lda gameLogikCounter and #$03 bne .defercollision lda #NOSTONE sta playerIsBeforeStone lda #NOSCHALTER sta playerIsBeforeSchalter jsr checkCollisionWithPlayer .defercollision ; place the right animation frame jsr animatePlayer ; generate a new scroll position jsr playerGenNewScrollPos .noplayerStuff incWord gameLogikCounter .disabled inc lastSoundTrigger rts ;------------------------------------------------------------- ;-- The gamelogik once a frame loopfunction -- ;------------------------------------------------------------- gameLogikPerBlit SUBROUTINE jsr clearEnemyHitFlags rts ;------------------------------------------------------------- ;-- Clears some enemies on a constant framerate -- ;------------------------------------------------------------- clearSomeEnemies SUBROUTINE lda gameLogikCounter and #31 bne .dontClearEnemies lda #NORMALENEMIESSTARTINDEX sta enemyAddGameObjectIndexStart lda #NORMALENEMIESENDINDEX sta enemyAddGameObjectIndexEnd jsr clearMostOutsideEnemyExpanded lda #COLLECTABLESFROM sta enemyAddGameObjectIndexStart lda #COLLECTABLESTO sta enemyAddGameObjectIndexEnd jsr clearMostOutsideEnemyExpanded lda #ENEMYSHOTSFROM sta enemyAddGameObjectIndexStart lda #ENEMYSHOTSTO sta enemyAddGameObjectIndexEnd jsr clearMostOutsideEnemyExpanded .dontClearEnemies rts ------------------------------------------------------------- ;-- handles the enemies (main loopfunction) -- ;------------------------------------------------------------- handleEnemies SUBROUTINE ; oneframed gamelogik lda #PLAYERSHOTSFROM sta gameObjectsStart lda #PLAYERSHOTSTO sta gameObjectsEnd jsr handleGameEnemyObjects lda gameLogikCounter and #$01 bne .do rts .do ; twoframed gamelogik lda #COLLECTABLESFROM sta gameObjectsStart lda #COLLECTABLESTO sta gameObjectsEnd jsr handleGameEnemyObjects lda #NORMALENEMIESSTARTINDEX sta gameObjectsStart lda #NORMALENEMIESENDINDEX sta gameObjectsEnd jsr handleGameEnemyObjects lda #ENEMYSHOTSFROM sta gameObjectsStart lda #ENEMYSHOTSTO sta gameObjectsEnd jsr handleGameEnemyObjects lda #ITEMGAMEOBJECT sta gameObjectsStart lda #ITEMGAMEOBJECT + 1 sta gameObjectsEnd jsr handleGameEnemyObjects rts gameObjectsStart dc.b $00 ; enemies to handle start gameObjectsEnd dc.b $00 ; enemies to handle end ;------------------------------------------------------------- ;-- handles a subpart of the GameObjectEnemies -- ;------------------------------------------------------------- SUBROUTINE .current dc.b $00 handleGameEnemyObjects lda gameObjectsStart sta .current .reloop ldx .current lda GameObjectCollisionType,x beq .nothandle txa jsr handleEnemy ldx .current inc GameObjectActiveCounter,x .nothandle inc .current lda .current cmp gameObjectsEnd bne .reloop rts SUBROUTINE .count dc.b $00 checkCollisionWithPlayer ldx #$02 ldy #PLAYERGAMEOBJECT jsr getGameObjectRectangle lda #$00 sta .count .next ldx .count lda GameObjectCollisionType,x tay lda checkIsCollidesForPlayer,y ; be aware here the enemies will be filtered beq .notcollidewithplayer lda GameObjectVisible,x beq .notcollidewithplayer ldx #$00 ldy .count jsr getGameObjectRectangle jsr gameObjectsCollided cmp #$01 beq .notcollidewithplayer lda .count jsr gameObjectCollidedWithPlayer .notcollidewithplayer inc .count lda .count cmp #GAMEOBJECTCOUNT bne .next rts SUBROUTINE .count1 dc.b $00 .count2 dc.b $00 checkCollsionWithPlayerShot lda #$00 sta .count1 .nextshot ldx .count1 lda GameObjectCollisionType,x cmp #GAMEOBJECT_COLLISIONTYPE_PLAYER_SHOT bne .donextshot txa tay ldx #$02 jsr getGameObjectRectangle ; the shot in slot2 lda #$00 sta .count2 .nextenemy ldx .count2 lda GameObjectCollisionType,x cmp #GAMEOBJECT_COLLISIONTYPE_ENEMY beq .collidewithshot jmp .notcollidewithshot .collidewithshot lda GameObjectVisible,x beq .notcollidewithshot ldx #$00 ldy .count2 jsr getGameObjectRectangle jsr gameObjectsCollided cmp #$01 beq .notcollidewithshot lda .count1 ;jsr explodeEnemy jsr removeEnemyFromScreen lda .count2 jsr gameObjectCollidedWithShot .notcollidewithshot inc .count2 lda .count2 cmp #GAMEOBJECTCOUNT bne .nextenemy .donextshot inc .count1 lda .count1 cmp #GAMEOBJECTCOUNT bne .nextshot rts ;------------------------------------------------------------- ;-- a enemy collided with the player so handle it -- ;------------------------------------------------------------- gameObjectCollidedWithPlayer SUBROUTINE tax lda GameObjectCollisionType,x cmp #GAMEOBJECT_COLLISIONTYPE_ENEMY bne .notEnemy txa jmp enemyCollidedWithPlayer .notEnemy cmp #GAMEOBJECT_COLLISIONTYPE_ENEMY_SHOT bne .notEnemyShot txa jmp enemyShotCollidedWithPlayer .notEnemyShot cmp #GAMEOBJECT_COLLISIONTYPE_COLLECTABLE bne .notCollectable txa jmp collectableCollidedWithPlayer .notCollectable cmp #GAMEOBJECT_COLLISIONTYPE_MAGIC bne .notMagic txa jmp magicCollidedWithPlayer .notMagic cmp #GAMEOBJECT_COLLISIONTYPE_SCHALTER bne .notSchalter txa jmp schalterCollidedWithPlayer .notSchalter rts ;------------------------------------------------------------- ;-- a gameObject collided with a player shot so handle it -- ;------------------------------------------------------------- gameObjectCollidedWithShot SUBROUTINE jmp enemyCollidedWithPlayerShot ;------------------------------------------------------------- ;-- clears the blink flag of a enemy updated once per frame -- ;------------------------------------------------------------- clearEnemyHitFlags SUBROUTINE ldx #GAMEOBJECTCOUNT - 1 .next lda GameObjectHit,x beq .nothit dec GameObjectHit,x .nothit dex bpl .next rts
// Copyright 2020 Google LLC // // This source code is licensed under the BSD-style license found in the // LICENSE file in the root directory of this source tree. #include <xnnpack.h> #include <algorithm> #include <functional> #include <iostream> #include <limits> #include <random> #include "models/models.h" namespace models { ExecutionPlan MobileNetV3Small(pthreadpool_t threadpool) { alignas(16) static float v0[150528]; alignas(16) static float v1[200704]; alignas(16) static float v2[200704]; alignas(16) static float v3[50176]; alignas(16) static float v4[16]; alignas(16) static float v5[8]; alignas(16) static float v6[16]; alignas(16) static float v7[50176]; alignas(16) static float v8[50176]; alignas(16) static float v9[225792]; alignas(16) static float v10[56448]; alignas(16) static float v11[18816]; alignas(16) static float v12[68992]; alignas(16) static float v13[68992]; alignas(16) static float v14[18816]; alignas(16) static float v15[18816]; alignas(16) static float v16[75264]; alignas(16) static float v17[75264]; alignas(16) static float v18[18816]; alignas(16) static float v19[18816]; alignas(16) static float v20[96]; alignas(16) static float v21[24]; alignas(16) static float v22[96]; alignas(16) static float v23[18816]; alignas(16) static float v24[7840]; alignas(16) static float v25[47040]; alignas(16) static float v26[47040]; alignas(16) static float v27[47040]; alignas(16) static float v28[47040]; alignas(16) static float v29[240]; alignas(16) static float v30[64]; alignas(16) static float v31[240]; alignas(16) static float v32[47040]; alignas(16) static float v33[7840]; alignas(16) static float v34[7840]; alignas(16) static float v35[47040]; alignas(16) static float v36[47040]; alignas(16) static float v37[47040]; alignas(16) static float v38[47040]; alignas(16) static float v39[240]; alignas(16) static float v40[64]; alignas(16) static float v41[240]; alignas(16) static float v42[47040]; alignas(16) static float v43[7840]; alignas(16) static float v44[7840]; alignas(16) static float v45[23520]; alignas(16) static float v46[23520]; alignas(16) static float v47[23520]; alignas(16) static float v48[23520]; alignas(16) static float v49[120]; alignas(16) static float v50[32]; alignas(16) static float v51[120]; alignas(16) static float v52[23520]; alignas(16) static float v53[9408]; alignas(16) static float v54[28224]; alignas(16) static float v55[28224]; alignas(16) static float v56[28224]; alignas(16) static float v57[28224]; alignas(16) static float v58[144]; alignas(16) static float v59[40]; alignas(16) static float v60[144]; alignas(16) static float v61[28224]; alignas(16) static float v62[9408]; alignas(16) static float v63[9408]; alignas(16) static float v64[56448]; alignas(16) static float v65[56448]; alignas(16) static float v66[14112]; alignas(16) static float v67[14112]; alignas(16) static float v68[288]; alignas(16) static float v69[72]; alignas(16) static float v70[288]; alignas(16) static float v71[14112]; alignas(16) static float v72[4704]; alignas(16) static float v73[28224]; alignas(16) static float v74[28224]; alignas(16) static float v75[28224]; alignas(16) static float v76[28224]; alignas(16) static float v77[576]; alignas(16) static float v78[144]; alignas(16) static float v79[576]; alignas(16) static float v80[28224]; alignas(16) static float v81[4704]; alignas(16) static float v82[4704]; alignas(16) static float v83[28224]; alignas(16) static float v84[28224]; alignas(16) static float v85[28224]; alignas(16) static float v86[28224]; alignas(16) static float v87[576]; alignas(16) static float v88[144]; alignas(16) static float v89[576]; alignas(16) static float v90[28224]; alignas(16) static float v91[4704]; alignas(16) static float v92[4704]; alignas(16) static float v93[28224]; alignas(16) static float v94[28224]; alignas(16) static float v95[576]; alignas(16) static float v96[1024]; alignas(16) static float v97[1024]; alignas(16) static float v98[1024]; alignas(16) static float v99[1001]; alignas(16) static float w100[432]; alignas(16) static float w101[16]; alignas(16) static float w102[144]; alignas(16) static float w103[16]; alignas(16) static float w104[128]; alignas(16) static float w105[8]; alignas(16) static float w106[128]; alignas(16) static float w107[16]; alignas(16) static float w108[256]; alignas(16) static float w109[16]; alignas(16) static float w110[1152]; alignas(16) static float w111[72]; alignas(16) static float w112[648]; alignas(16) static float w113[72]; alignas(16) static float w114[1728]; alignas(16) static float w115[24]; alignas(16) static float w116[2112]; alignas(16) static float w117[88]; alignas(16) static float w118[792]; alignas(16) static float w119[88]; alignas(16) static float w120[2112]; alignas(16) static float w121[24]; alignas(16) static float w122[2304]; alignas(16) static float w123[96]; alignas(16) static float w124[2400]; alignas(16) static float w125[96]; alignas(16) static float w126[2304]; alignas(16) static float w127[24]; alignas(16) static float w128[2304]; alignas(16) static float w129[96]; alignas(16) static float w130[3840]; alignas(16) static float w131[40]; alignas(16) static float w132[9600]; alignas(16) static float w133[240]; alignas(16) static float w134[6000]; alignas(16) static float w135[240]; alignas(16) static float w136[15360]; alignas(16) static float w137[64]; alignas(16) static float w138[15360]; alignas(16) static float w139[240]; alignas(16) static float w140[9600]; alignas(16) static float w141[40]; alignas(16) static float w142[9600]; alignas(16) static float w143[240]; alignas(16) static float w144[6000]; alignas(16) static float w145[240]; alignas(16) static float w146[15360]; alignas(16) static float w147[64]; alignas(16) static float w148[15360]; alignas(16) static float w149[240]; alignas(16) static float w150[9600]; alignas(16) static float w151[40]; alignas(16) static float w152[4800]; alignas(16) static float w153[120]; alignas(16) static float w154[3000]; alignas(16) static float w155[120]; alignas(16) static float w156[3840]; alignas(16) static float w157[32]; alignas(16) static float w158[3840]; alignas(16) static float w159[120]; alignas(16) static float w160[5760]; alignas(16) static float w161[48]; alignas(16) static float w162[6912]; alignas(16) static float w163[144]; alignas(16) static float w164[3600]; alignas(16) static float w165[144]; alignas(16) static float w166[5760]; alignas(16) static float w167[40]; alignas(16) static float w168[5760]; alignas(16) static float w169[144]; alignas(16) static float w170[6912]; alignas(16) static float w171[48]; alignas(16) static float w172[13824]; alignas(16) static float w173[288]; alignas(16) static float w174[7200]; alignas(16) static float w175[288]; alignas(16) static float w176[20736]; alignas(16) static float w177[72]; alignas(16) static float w178[20736]; alignas(16) static float w179[288]; alignas(16) static float w180[27648]; alignas(16) static float w181[96]; alignas(16) static float w182[55296]; alignas(16) static float w183[576]; alignas(16) static float w184[14400]; alignas(16) static float w185[576]; alignas(16) static float w186[82944]; alignas(16) static float w187[144]; alignas(16) static float w188[82944]; alignas(16) static float w189[576]; alignas(16) static float w190[55296]; alignas(16) static float w191[96]; alignas(16) static float w192[55296]; alignas(16) static float w193[576]; alignas(16) static float w194[14400]; alignas(16) static float w195[576]; alignas(16) static float w196[82944]; alignas(16) static float w197[144]; alignas(16) static float w198[82944]; alignas(16) static float w199[576]; alignas(16) static float w200[55296]; alignas(16) static float w201[96]; alignas(16) static float w202[55296]; alignas(16) static float w203[576]; alignas(16) static float w204[589824]; alignas(16) static float w205[1024]; alignas(16) static float w206[1025024]; alignas(16) static float w207[1001]; std::random_device random_device; auto rng = std::mt19937(random_device()); auto f32rng = std::bind(std::uniform_real_distribution<float>(-1.0f, +1.0f), rng); std::generate(v0, v0 + 150528, std::ref(f32rng)); std::generate(v1, v1 + 200704, std::ref(f32rng)); std::generate(v2, v2 + 200704, std::ref(f32rng)); std::generate(v3, v3 + 50176, std::ref(f32rng)); std::generate(v4, v4 + 16, std::ref(f32rng)); std::generate(v5, v5 + 8, std::ref(f32rng)); std::generate(v6, v6 + 16, std::ref(f32rng)); std::generate(v7, v7 + 50176, std::ref(f32rng)); std::generate(v8, v8 + 50176, std::ref(f32rng)); std::generate(v9, v9 + 225792, std::ref(f32rng)); std::generate(v10, v10 + 56448, std::ref(f32rng)); std::generate(v11, v11 + 18816, std::ref(f32rng)); std::generate(v12, v12 + 68992, std::ref(f32rng)); std::generate(v13, v13 + 68992, std::ref(f32rng)); std::generate(v14, v14 + 18816, std::ref(f32rng)); std::generate(v15, v15 + 18816, std::ref(f32rng)); std::generate(v16, v16 + 75264, std::ref(f32rng)); std::generate(v17, v17 + 75264, std::ref(f32rng)); std::generate(v18, v18 + 18816, std::ref(f32rng)); std::generate(v19, v19 + 18816, std::ref(f32rng)); std::generate(v20, v20 + 96, std::ref(f32rng)); std::generate(v21, v21 + 24, std::ref(f32rng)); std::generate(v22, v22 + 96, std::ref(f32rng)); std::generate(v23, v23 + 18816, std::ref(f32rng)); std::generate(v24, v24 + 7840, std::ref(f32rng)); std::generate(v25, v25 + 47040, std::ref(f32rng)); std::generate(v26, v26 + 47040, std::ref(f32rng)); std::generate(v27, v27 + 47040, std::ref(f32rng)); std::generate(v28, v28 + 47040, std::ref(f32rng)); std::generate(v29, v29 + 240, std::ref(f32rng)); std::generate(v30, v30 + 64, std::ref(f32rng)); std::generate(v31, v31 + 240, std::ref(f32rng)); std::generate(v32, v32 + 47040, std::ref(f32rng)); std::generate(v33, v33 + 7840, std::ref(f32rng)); std::generate(v34, v34 + 7840, std::ref(f32rng)); std::generate(v35, v35 + 47040, std::ref(f32rng)); std::generate(v36, v36 + 47040, std::ref(f32rng)); std::generate(v37, v37 + 47040, std::ref(f32rng)); std::generate(v38, v38 + 47040, std::ref(f32rng)); std::generate(v39, v39 + 240, std::ref(f32rng)); std::generate(v40, v40 + 64, std::ref(f32rng)); std::generate(v41, v41 + 240, std::ref(f32rng)); std::generate(v42, v42 + 47040, std::ref(f32rng)); std::generate(v43, v43 + 7840, std::ref(f32rng)); std::generate(v44, v44 + 7840, std::ref(f32rng)); std::generate(v45, v45 + 23520, std::ref(f32rng)); std::generate(v46, v46 + 23520, std::ref(f32rng)); std::generate(v47, v47 + 23520, std::ref(f32rng)); std::generate(v48, v48 + 23520, std::ref(f32rng)); std::generate(v49, v49 + 120, std::ref(f32rng)); std::generate(v50, v50 + 32, std::ref(f32rng)); std::generate(v51, v51 + 120, std::ref(f32rng)); std::generate(v52, v52 + 23520, std::ref(f32rng)); std::generate(v53, v53 + 9408, std::ref(f32rng)); std::generate(v54, v54 + 28224, std::ref(f32rng)); std::generate(v55, v55 + 28224, std::ref(f32rng)); std::generate(v56, v56 + 28224, std::ref(f32rng)); std::generate(v57, v57 + 28224, std::ref(f32rng)); std::generate(v58, v58 + 144, std::ref(f32rng)); std::generate(v59, v59 + 40, std::ref(f32rng)); std::generate(v60, v60 + 144, std::ref(f32rng)); std::generate(v61, v61 + 28224, std::ref(f32rng)); std::generate(v62, v62 + 9408, std::ref(f32rng)); std::generate(v63, v63 + 9408, std::ref(f32rng)); std::generate(v64, v64 + 56448, std::ref(f32rng)); std::generate(v65, v65 + 56448, std::ref(f32rng)); std::generate(v66, v66 + 14112, std::ref(f32rng)); std::generate(v67, v67 + 14112, std::ref(f32rng)); std::generate(v68, v68 + 288, std::ref(f32rng)); std::generate(v69, v69 + 72, std::ref(f32rng)); std::generate(v70, v70 + 288, std::ref(f32rng)); std::generate(v71, v71 + 14112, std::ref(f32rng)); std::generate(v72, v72 + 4704, std::ref(f32rng)); std::generate(v73, v73 + 28224, std::ref(f32rng)); std::generate(v74, v74 + 28224, std::ref(f32rng)); std::generate(v75, v75 + 28224, std::ref(f32rng)); std::generate(v76, v76 + 28224, std::ref(f32rng)); std::generate(v77, v77 + 576, std::ref(f32rng)); std::generate(v78, v78 + 144, std::ref(f32rng)); std::generate(v79, v79 + 576, std::ref(f32rng)); std::generate(v80, v80 + 28224, std::ref(f32rng)); std::generate(v81, v81 + 4704, std::ref(f32rng)); std::generate(v82, v82 + 4704, std::ref(f32rng)); std::generate(v83, v83 + 28224, std::ref(f32rng)); std::generate(v84, v84 + 28224, std::ref(f32rng)); std::generate(v85, v85 + 28224, std::ref(f32rng)); std::generate(v86, v86 + 28224, std::ref(f32rng)); std::generate(v87, v87 + 576, std::ref(f32rng)); std::generate(v88, v88 + 144, std::ref(f32rng)); std::generate(v89, v89 + 576, std::ref(f32rng)); std::generate(v90, v90 + 28224, std::ref(f32rng)); std::generate(v91, v91 + 4704, std::ref(f32rng)); std::generate(v92, v92 + 4704, std::ref(f32rng)); std::generate(v93, v93 + 28224, std::ref(f32rng)); std::generate(v94, v94 + 28224, std::ref(f32rng)); std::generate(v95, v95 + 576, std::ref(f32rng)); std::generate(v96, v96 + 1024, std::ref(f32rng)); std::generate(v97, v97 + 1024, std::ref(f32rng)); std::generate(v98, v98 + 1024, std::ref(f32rng)); std::generate(v99, v99 + 1001, std::ref(f32rng)); std::generate(w100, w100 + 432, std::ref(f32rng)); std::generate(w101, w101 + 16, std::ref(f32rng)); std::generate(w102, w102 + 144, std::ref(f32rng)); std::generate(w103, w103 + 16, std::ref(f32rng)); std::generate(w104, w104 + 128, std::ref(f32rng)); std::generate(w105, w105 + 8, std::ref(f32rng)); std::generate(w106, w106 + 128, std::ref(f32rng)); std::generate(w107, w107 + 16, std::ref(f32rng)); std::generate(w108, w108 + 256, std::ref(f32rng)); std::generate(w109, w109 + 16, std::ref(f32rng)); std::generate(w110, w110 + 1152, std::ref(f32rng)); std::generate(w111, w111 + 72, std::ref(f32rng)); std::generate(w112, w112 + 648, std::ref(f32rng)); std::generate(w113, w113 + 72, std::ref(f32rng)); std::generate(w114, w114 + 1728, std::ref(f32rng)); std::generate(w115, w115 + 24, std::ref(f32rng)); std::generate(w116, w116 + 2112, std::ref(f32rng)); std::generate(w117, w117 + 88, std::ref(f32rng)); std::generate(w118, w118 + 792, std::ref(f32rng)); std::generate(w119, w119 + 88, std::ref(f32rng)); std::generate(w120, w120 + 2112, std::ref(f32rng)); std::generate(w121, w121 + 24, std::ref(f32rng)); std::generate(w122, w122 + 2304, std::ref(f32rng)); std::generate(w123, w123 + 96, std::ref(f32rng)); std::generate(w124, w124 + 2400, std::ref(f32rng)); std::generate(w125, w125 + 96, std::ref(f32rng)); std::generate(w126, w126 + 2304, std::ref(f32rng)); std::generate(w127, w127 + 24, std::ref(f32rng)); std::generate(w128, w128 + 2304, std::ref(f32rng)); std::generate(w129, w129 + 96, std::ref(f32rng)); std::generate(w130, w130 + 3840, std::ref(f32rng)); std::generate(w131, w131 + 40, std::ref(f32rng)); std::generate(w132, w132 + 9600, std::ref(f32rng)); std::generate(w133, w133 + 240, std::ref(f32rng)); std::generate(w134, w134 + 6000, std::ref(f32rng)); std::generate(w135, w135 + 240, std::ref(f32rng)); std::generate(w136, w136 + 15360, std::ref(f32rng)); std::generate(w137, w137 + 64, std::ref(f32rng)); std::generate(w138, w138 + 15360, std::ref(f32rng)); std::generate(w139, w139 + 240, std::ref(f32rng)); std::generate(w140, w140 + 9600, std::ref(f32rng)); std::generate(w141, w141 + 40, std::ref(f32rng)); std::generate(w142, w142 + 9600, std::ref(f32rng)); std::generate(w143, w143 + 240, std::ref(f32rng)); std::generate(w144, w144 + 6000, std::ref(f32rng)); std::generate(w145, w145 + 240, std::ref(f32rng)); std::generate(w146, w146 + 15360, std::ref(f32rng)); std::generate(w147, w147 + 64, std::ref(f32rng)); std::generate(w148, w148 + 15360, std::ref(f32rng)); std::generate(w149, w149 + 240, std::ref(f32rng)); std::generate(w150, w150 + 9600, std::ref(f32rng)); std::generate(w151, w151 + 40, std::ref(f32rng)); std::generate(w152, w152 + 4800, std::ref(f32rng)); std::generate(w153, w153 + 120, std::ref(f32rng)); std::generate(w154, w154 + 3000, std::ref(f32rng)); std::generate(w155, w155 + 120, std::ref(f32rng)); std::generate(w156, w156 + 3840, std::ref(f32rng)); std::generate(w157, w157 + 32, std::ref(f32rng)); std::generate(w158, w158 + 3840, std::ref(f32rng)); std::generate(w159, w159 + 120, std::ref(f32rng)); std::generate(w160, w160 + 5760, std::ref(f32rng)); std::generate(w161, w161 + 48, std::ref(f32rng)); std::generate(w162, w162 + 6912, std::ref(f32rng)); std::generate(w163, w163 + 144, std::ref(f32rng)); std::generate(w164, w164 + 3600, std::ref(f32rng)); std::generate(w165, w165 + 144, std::ref(f32rng)); std::generate(w166, w166 + 5760, std::ref(f32rng)); std::generate(w167, w167 + 40, std::ref(f32rng)); std::generate(w168, w168 + 5760, std::ref(f32rng)); std::generate(w169, w169 + 144, std::ref(f32rng)); std::generate(w170, w170 + 6912, std::ref(f32rng)); std::generate(w171, w171 + 48, std::ref(f32rng)); std::generate(w172, w172 + 13824, std::ref(f32rng)); std::generate(w173, w173 + 288, std::ref(f32rng)); std::generate(w174, w174 + 7200, std::ref(f32rng)); std::generate(w175, w175 + 288, std::ref(f32rng)); std::generate(w176, w176 + 20736, std::ref(f32rng)); std::generate(w177, w177 + 72, std::ref(f32rng)); std::generate(w178, w178 + 20736, std::ref(f32rng)); std::generate(w179, w179 + 288, std::ref(f32rng)); std::generate(w180, w180 + 27648, std::ref(f32rng)); std::generate(w181, w181 + 96, std::ref(f32rng)); std::generate(w182, w182 + 55296, std::ref(f32rng)); std::generate(w183, w183 + 576, std::ref(f32rng)); std::generate(w184, w184 + 14400, std::ref(f32rng)); std::generate(w185, w185 + 576, std::ref(f32rng)); std::generate(w186, w186 + 82944, std::ref(f32rng)); std::generate(w187, w187 + 144, std::ref(f32rng)); std::generate(w188, w188 + 82944, std::ref(f32rng)); std::generate(w189, w189 + 576, std::ref(f32rng)); std::generate(w190, w190 + 55296, std::ref(f32rng)); std::generate(w191, w191 + 96, std::ref(f32rng)); std::generate(w192, w192 + 55296, std::ref(f32rng)); std::generate(w193, w193 + 576, std::ref(f32rng)); std::generate(w194, w194 + 14400, std::ref(f32rng)); std::generate(w195, w195 + 576, std::ref(f32rng)); std::generate(w196, w196 + 82944, std::ref(f32rng)); std::generate(w197, w197 + 144, std::ref(f32rng)); std::generate(w198, w198 + 82944, std::ref(f32rng)); std::generate(w199, w199 + 576, std::ref(f32rng)); std::generate(w200, w200 + 55296, std::ref(f32rng)); std::generate(w201, w201 + 96, std::ref(f32rng)); std::generate(w202, w202 + 55296, std::ref(f32rng)); std::generate(w203, w203 + 576, std::ref(f32rng)); std::generate(w204, w204 + 589824, std::ref(f32rng)); std::generate(w205, w205 + 1024, std::ref(f32rng)); std::generate(w206, w206 + 1025024, std::ref(f32rng)); std::generate(w207, w207 + 1001, std::ref(f32rng)); ExecutionPlan operators; xnn_status status; xnn_operator_t op0 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 1 /* right padding */, 1 /* bottom padding */, 0 /* left padding */, 3 /* kernel height */, 3 /* kernel width */, 2 /* subsampling height */, 2 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 3 /* input channels per group */, 16 /* output_channels_per_group */, 3 /* input pixel stride */, 16 /* output pixel stride */, w100, w101, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op0); if (status != xnn_status_success) { std::cerr << "failed to create operation #0" << std::endl; return ExecutionPlan(); } operators.emplace_back(op0, xnn_delete_operator); xnn_operator_t op1 = nullptr; status = xnn_create_hardswish_nc_f32( 16 /* channels */, 16 /* input stride */, 16 /* output stride */, 0 /* flags */, &op1); if (status != xnn_status_success) { std::cerr << "failed to create operation #1" << std::endl; return ExecutionPlan(); } operators.emplace_back(op1, xnn_delete_operator); xnn_operator_t op2 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 1 /* right padding */, 1 /* bottom padding */, 0 /* left padding */, 3 /* kernel height */, 3 /* kernel width */, 2 /* subsampling height */, 2 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 16 /* groups */, 1 /* input channels per group */, 1 /* output_channels_per_group */, 16 /* input pixel stride */, 16 /* output pixel stride */, w102, w103, 0.0f /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op2); if (status != xnn_status_success) { std::cerr << "failed to create operation #2" << std::endl; return ExecutionPlan(); } operators.emplace_back(op2, xnn_delete_operator); xnn_operator_t op3 = nullptr; status = xnn_create_global_average_pooling_nwc_f32( 16 /* channels */, 16 /* input stride */, 16 /* output stride */, -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), 0 /* flags */, &op3); if (status != xnn_status_success) { std::cerr << "failed to create operation #3" << std::endl; return ExecutionPlan(); } operators.emplace_back(op3, xnn_delete_operator); xnn_operator_t op4 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 16 /* input channels per group */, 8 /* output_channels_per_group */, 16 /* input pixel stride */, 8 /* output pixel stride */, w104, w105, 0.0f /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op4); if (status != xnn_status_success) { std::cerr << "failed to create operation #4" << std::endl; return ExecutionPlan(); } operators.emplace_back(op4, xnn_delete_operator); xnn_operator_t op5 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 8 /* input channels per group */, 16 /* output_channels_per_group */, 8 /* input pixel stride */, 16 /* output pixel stride */, w106, w107, 0.0f /* output min */, +0x1.00014Fp+0 /* output max */, 0 /* flags */, &op5); if (status != xnn_status_success) { std::cerr << "failed to create operation #5" << std::endl; return ExecutionPlan(); } operators.emplace_back(op5, xnn_delete_operator); xnn_operator_t op6 = nullptr; status = xnn_create_multiply_nd_f32( -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op6); if (status != xnn_status_success) { std::cerr << "failed to create operation #6" << std::endl; return ExecutionPlan(); } operators.emplace_back(op6, xnn_delete_operator); xnn_operator_t op7 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 16 /* input channels per group */, 16 /* output_channels_per_group */, 16 /* input pixel stride */, 16 /* output pixel stride */, w108, w109, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op7); if (status != xnn_status_success) { std::cerr << "failed to create operation #7" << std::endl; return ExecutionPlan(); } operators.emplace_back(op7, xnn_delete_operator); xnn_operator_t op8 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 16 /* input channels per group */, 72 /* output_channels_per_group */, 16 /* input pixel stride */, 72 /* output pixel stride */, w110, w111, 0.0f /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op8); if (status != xnn_status_success) { std::cerr << "failed to create operation #8" << std::endl; return ExecutionPlan(); } operators.emplace_back(op8, xnn_delete_operator); xnn_operator_t op9 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 1 /* right padding */, 1 /* bottom padding */, 0 /* left padding */, 3 /* kernel height */, 3 /* kernel width */, 2 /* subsampling height */, 2 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 72 /* groups */, 1 /* input channels per group */, 1 /* output_channels_per_group */, 72 /* input pixel stride */, 72 /* output pixel stride */, w112, w113, 0.0f /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op9); if (status != xnn_status_success) { std::cerr << "failed to create operation #9" << std::endl; return ExecutionPlan(); } operators.emplace_back(op9, xnn_delete_operator); xnn_operator_t op10 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 72 /* input channels per group */, 24 /* output_channels_per_group */, 72 /* input pixel stride */, 24 /* output pixel stride */, w114, w115, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op10); if (status != xnn_status_success) { std::cerr << "failed to create operation #10" << std::endl; return ExecutionPlan(); } operators.emplace_back(op10, xnn_delete_operator); xnn_operator_t op11 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 24 /* input channels per group */, 88 /* output_channels_per_group */, 24 /* input pixel stride */, 88 /* output pixel stride */, w116, w117, 0.0f /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op11); if (status != xnn_status_success) { std::cerr << "failed to create operation #11" << std::endl; return ExecutionPlan(); } operators.emplace_back(op11, xnn_delete_operator); xnn_operator_t op12 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 1 /* top padding */, 1 /* right padding */, 1 /* bottom padding */, 1 /* left padding */, 3 /* kernel height */, 3 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 88 /* groups */, 1 /* input channels per group */, 1 /* output_channels_per_group */, 88 /* input pixel stride */, 88 /* output pixel stride */, w118, w119, 0.0f /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op12); if (status != xnn_status_success) { std::cerr << "failed to create operation #12" << std::endl; return ExecutionPlan(); } operators.emplace_back(op12, xnn_delete_operator); xnn_operator_t op13 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 88 /* input channels per group */, 24 /* output_channels_per_group */, 88 /* input pixel stride */, 24 /* output pixel stride */, w120, w121, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op13); if (status != xnn_status_success) { std::cerr << "failed to create operation #13" << std::endl; return ExecutionPlan(); } operators.emplace_back(op13, xnn_delete_operator); xnn_operator_t op14 = nullptr; status = xnn_create_add_nd_f32( -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op14); if (status != xnn_status_success) { std::cerr << "failed to create operation #14" << std::endl; return ExecutionPlan(); } operators.emplace_back(op14, xnn_delete_operator); xnn_operator_t op15 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 24 /* input channels per group */, 96 /* output_channels_per_group */, 24 /* input pixel stride */, 96 /* output pixel stride */, w122, w123, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op15); if (status != xnn_status_success) { std::cerr << "failed to create operation #15" << std::endl; return ExecutionPlan(); } operators.emplace_back(op15, xnn_delete_operator); xnn_operator_t op16 = nullptr; status = xnn_create_hardswish_nc_f32( 96 /* channels */, 96 /* input stride */, 96 /* output stride */, 0 /* flags */, &op16); if (status != xnn_status_success) { std::cerr << "failed to create operation #16" << std::endl; return ExecutionPlan(); } operators.emplace_back(op16, xnn_delete_operator); xnn_operator_t op17 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 1 /* top padding */, 2 /* right padding */, 2 /* bottom padding */, 1 /* left padding */, 5 /* kernel height */, 5 /* kernel width */, 2 /* subsampling height */, 2 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 96 /* groups */, 1 /* input channels per group */, 1 /* output_channels_per_group */, 96 /* input pixel stride */, 96 /* output pixel stride */, w124, w125, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op17); if (status != xnn_status_success) { std::cerr << "failed to create operation #17" << std::endl; return ExecutionPlan(); } operators.emplace_back(op17, xnn_delete_operator); xnn_operator_t op18 = nullptr; status = xnn_create_hardswish_nc_f32( 96 /* channels */, 96 /* input stride */, 96 /* output stride */, 0 /* flags */, &op18); if (status != xnn_status_success) { std::cerr << "failed to create operation #18" << std::endl; return ExecutionPlan(); } operators.emplace_back(op18, xnn_delete_operator); xnn_operator_t op19 = nullptr; status = xnn_create_global_average_pooling_nwc_f32( 96 /* channels */, 96 /* input stride */, 96 /* output stride */, -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), 0 /* flags */, &op19); if (status != xnn_status_success) { std::cerr << "failed to create operation #19" << std::endl; return ExecutionPlan(); } operators.emplace_back(op19, xnn_delete_operator); xnn_operator_t op20 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 96 /* input channels per group */, 24 /* output_channels_per_group */, 96 /* input pixel stride */, 24 /* output pixel stride */, w126, w127, 0.0f /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op20); if (status != xnn_status_success) { std::cerr << "failed to create operation #20" << std::endl; return ExecutionPlan(); } operators.emplace_back(op20, xnn_delete_operator); xnn_operator_t op21 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 24 /* input channels per group */, 96 /* output_channels_per_group */, 24 /* input pixel stride */, 96 /* output pixel stride */, w128, w129, 0.0f /* output min */, +0x1.00014Fp+0 /* output max */, 0 /* flags */, &op21); if (status != xnn_status_success) { std::cerr << "failed to create operation #21" << std::endl; return ExecutionPlan(); } operators.emplace_back(op21, xnn_delete_operator); xnn_operator_t op22 = nullptr; status = xnn_create_multiply_nd_f32( -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op22); if (status != xnn_status_success) { std::cerr << "failed to create operation #22" << std::endl; return ExecutionPlan(); } operators.emplace_back(op22, xnn_delete_operator); xnn_operator_t op23 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 96 /* input channels per group */, 40 /* output_channels_per_group */, 96 /* input pixel stride */, 40 /* output pixel stride */, w130, w131, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op23); if (status != xnn_status_success) { std::cerr << "failed to create operation #23" << std::endl; return ExecutionPlan(); } operators.emplace_back(op23, xnn_delete_operator); xnn_operator_t op24 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 40 /* input channels per group */, 240 /* output_channels_per_group */, 40 /* input pixel stride */, 240 /* output pixel stride */, w132, w133, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op24); if (status != xnn_status_success) { std::cerr << "failed to create operation #24" << std::endl; return ExecutionPlan(); } operators.emplace_back(op24, xnn_delete_operator); xnn_operator_t op25 = nullptr; status = xnn_create_hardswish_nc_f32( 240 /* channels */, 240 /* input stride */, 240 /* output stride */, 0 /* flags */, &op25); if (status != xnn_status_success) { std::cerr << "failed to create operation #25" << std::endl; return ExecutionPlan(); } operators.emplace_back(op25, xnn_delete_operator); xnn_operator_t op26 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 2 /* top padding */, 2 /* right padding */, 2 /* bottom padding */, 2 /* left padding */, 5 /* kernel height */, 5 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 240 /* groups */, 1 /* input channels per group */, 1 /* output_channels_per_group */, 240 /* input pixel stride */, 240 /* output pixel stride */, w134, w135, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op26); if (status != xnn_status_success) { std::cerr << "failed to create operation #26" << std::endl; return ExecutionPlan(); } operators.emplace_back(op26, xnn_delete_operator); xnn_operator_t op27 = nullptr; status = xnn_create_hardswish_nc_f32( 240 /* channels */, 240 /* input stride */, 240 /* output stride */, 0 /* flags */, &op27); if (status != xnn_status_success) { std::cerr << "failed to create operation #27" << std::endl; return ExecutionPlan(); } operators.emplace_back(op27, xnn_delete_operator); xnn_operator_t op28 = nullptr; status = xnn_create_global_average_pooling_nwc_f32( 240 /* channels */, 240 /* input stride */, 240 /* output stride */, -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), 0 /* flags */, &op28); if (status != xnn_status_success) { std::cerr << "failed to create operation #28" << std::endl; return ExecutionPlan(); } operators.emplace_back(op28, xnn_delete_operator); xnn_operator_t op29 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 240 /* input channels per group */, 64 /* output_channels_per_group */, 240 /* input pixel stride */, 64 /* output pixel stride */, w136, w137, 0.0f /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op29); if (status != xnn_status_success) { std::cerr << "failed to create operation #29" << std::endl; return ExecutionPlan(); } operators.emplace_back(op29, xnn_delete_operator); xnn_operator_t op30 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 64 /* input channels per group */, 240 /* output_channels_per_group */, 64 /* input pixel stride */, 240 /* output pixel stride */, w138, w139, 0.0f /* output min */, +0x1.00014Fp+0 /* output max */, 0 /* flags */, &op30); if (status != xnn_status_success) { std::cerr << "failed to create operation #30" << std::endl; return ExecutionPlan(); } operators.emplace_back(op30, xnn_delete_operator); xnn_operator_t op31 = nullptr; status = xnn_create_multiply_nd_f32( -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op31); if (status != xnn_status_success) { std::cerr << "failed to create operation #31" << std::endl; return ExecutionPlan(); } operators.emplace_back(op31, xnn_delete_operator); xnn_operator_t op32 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 240 /* input channels per group */, 40 /* output_channels_per_group */, 240 /* input pixel stride */, 40 /* output pixel stride */, w140, w141, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op32); if (status != xnn_status_success) { std::cerr << "failed to create operation #32" << std::endl; return ExecutionPlan(); } operators.emplace_back(op32, xnn_delete_operator); xnn_operator_t op33 = nullptr; status = xnn_create_add_nd_f32( -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op33); if (status != xnn_status_success) { std::cerr << "failed to create operation #33" << std::endl; return ExecutionPlan(); } operators.emplace_back(op33, xnn_delete_operator); xnn_operator_t op34 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 40 /* input channels per group */, 240 /* output_channels_per_group */, 40 /* input pixel stride */, 240 /* output pixel stride */, w142, w143, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op34); if (status != xnn_status_success) { std::cerr << "failed to create operation #34" << std::endl; return ExecutionPlan(); } operators.emplace_back(op34, xnn_delete_operator); xnn_operator_t op35 = nullptr; status = xnn_create_hardswish_nc_f32( 240 /* channels */, 240 /* input stride */, 240 /* output stride */, 0 /* flags */, &op35); if (status != xnn_status_success) { std::cerr << "failed to create operation #35" << std::endl; return ExecutionPlan(); } operators.emplace_back(op35, xnn_delete_operator); xnn_operator_t op36 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 2 /* top padding */, 2 /* right padding */, 2 /* bottom padding */, 2 /* left padding */, 5 /* kernel height */, 5 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 240 /* groups */, 1 /* input channels per group */, 1 /* output_channels_per_group */, 240 /* input pixel stride */, 240 /* output pixel stride */, w144, w145, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op36); if (status != xnn_status_success) { std::cerr << "failed to create operation #36" << std::endl; return ExecutionPlan(); } operators.emplace_back(op36, xnn_delete_operator); xnn_operator_t op37 = nullptr; status = xnn_create_hardswish_nc_f32( 240 /* channels */, 240 /* input stride */, 240 /* output stride */, 0 /* flags */, &op37); if (status != xnn_status_success) { std::cerr << "failed to create operation #37" << std::endl; return ExecutionPlan(); } operators.emplace_back(op37, xnn_delete_operator); xnn_operator_t op38 = nullptr; status = xnn_create_global_average_pooling_nwc_f32( 240 /* channels */, 240 /* input stride */, 240 /* output stride */, -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), 0 /* flags */, &op38); if (status != xnn_status_success) { std::cerr << "failed to create operation #38" << std::endl; return ExecutionPlan(); } operators.emplace_back(op38, xnn_delete_operator); xnn_operator_t op39 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 240 /* input channels per group */, 64 /* output_channels_per_group */, 240 /* input pixel stride */, 64 /* output pixel stride */, w146, w147, 0.0f /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op39); if (status != xnn_status_success) { std::cerr << "failed to create operation #39" << std::endl; return ExecutionPlan(); } operators.emplace_back(op39, xnn_delete_operator); xnn_operator_t op40 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 64 /* input channels per group */, 240 /* output_channels_per_group */, 64 /* input pixel stride */, 240 /* output pixel stride */, w148, w149, 0.0f /* output min */, +0x1.00014Fp+0 /* output max */, 0 /* flags */, &op40); if (status != xnn_status_success) { std::cerr << "failed to create operation #40" << std::endl; return ExecutionPlan(); } operators.emplace_back(op40, xnn_delete_operator); xnn_operator_t op41 = nullptr; status = xnn_create_multiply_nd_f32( -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op41); if (status != xnn_status_success) { std::cerr << "failed to create operation #41" << std::endl; return ExecutionPlan(); } operators.emplace_back(op41, xnn_delete_operator); xnn_operator_t op42 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 240 /* input channels per group */, 40 /* output_channels_per_group */, 240 /* input pixel stride */, 40 /* output pixel stride */, w150, w151, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op42); if (status != xnn_status_success) { std::cerr << "failed to create operation #42" << std::endl; return ExecutionPlan(); } operators.emplace_back(op42, xnn_delete_operator); xnn_operator_t op43 = nullptr; status = xnn_create_add_nd_f32( -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op43); if (status != xnn_status_success) { std::cerr << "failed to create operation #43" << std::endl; return ExecutionPlan(); } operators.emplace_back(op43, xnn_delete_operator); xnn_operator_t op44 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 40 /* input channels per group */, 120 /* output_channels_per_group */, 40 /* input pixel stride */, 120 /* output pixel stride */, w152, w153, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op44); if (status != xnn_status_success) { std::cerr << "failed to create operation #44" << std::endl; return ExecutionPlan(); } operators.emplace_back(op44, xnn_delete_operator); xnn_operator_t op45 = nullptr; status = xnn_create_hardswish_nc_f32( 120 /* channels */, 120 /* input stride */, 120 /* output stride */, 0 /* flags */, &op45); if (status != xnn_status_success) { std::cerr << "failed to create operation #45" << std::endl; return ExecutionPlan(); } operators.emplace_back(op45, xnn_delete_operator); xnn_operator_t op46 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 2 /* top padding */, 2 /* right padding */, 2 /* bottom padding */, 2 /* left padding */, 5 /* kernel height */, 5 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 120 /* groups */, 1 /* input channels per group */, 1 /* output_channels_per_group */, 120 /* input pixel stride */, 120 /* output pixel stride */, w154, w155, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op46); if (status != xnn_status_success) { std::cerr << "failed to create operation #46" << std::endl; return ExecutionPlan(); } operators.emplace_back(op46, xnn_delete_operator); xnn_operator_t op47 = nullptr; status = xnn_create_hardswish_nc_f32( 120 /* channels */, 120 /* input stride */, 120 /* output stride */, 0 /* flags */, &op47); if (status != xnn_status_success) { std::cerr << "failed to create operation #47" << std::endl; return ExecutionPlan(); } operators.emplace_back(op47, xnn_delete_operator); xnn_operator_t op48 = nullptr; status = xnn_create_global_average_pooling_nwc_f32( 120 /* channels */, 120 /* input stride */, 120 /* output stride */, -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), 0 /* flags */, &op48); if (status != xnn_status_success) { std::cerr << "failed to create operation #48" << std::endl; return ExecutionPlan(); } operators.emplace_back(op48, xnn_delete_operator); xnn_operator_t op49 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 120 /* input channels per group */, 32 /* output_channels_per_group */, 120 /* input pixel stride */, 32 /* output pixel stride */, w156, w157, 0.0f /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op49); if (status != xnn_status_success) { std::cerr << "failed to create operation #49" << std::endl; return ExecutionPlan(); } operators.emplace_back(op49, xnn_delete_operator); xnn_operator_t op50 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 32 /* input channels per group */, 120 /* output_channels_per_group */, 32 /* input pixel stride */, 120 /* output pixel stride */, w158, w159, 0.0f /* output min */, +0x1.00014Fp+0 /* output max */, 0 /* flags */, &op50); if (status != xnn_status_success) { std::cerr << "failed to create operation #50" << std::endl; return ExecutionPlan(); } operators.emplace_back(op50, xnn_delete_operator); xnn_operator_t op51 = nullptr; status = xnn_create_multiply_nd_f32( -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op51); if (status != xnn_status_success) { std::cerr << "failed to create operation #51" << std::endl; return ExecutionPlan(); } operators.emplace_back(op51, xnn_delete_operator); xnn_operator_t op52 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 120 /* input channels per group */, 48 /* output_channels_per_group */, 120 /* input pixel stride */, 48 /* output pixel stride */, w160, w161, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op52); if (status != xnn_status_success) { std::cerr << "failed to create operation #52" << std::endl; return ExecutionPlan(); } operators.emplace_back(op52, xnn_delete_operator); xnn_operator_t op53 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 48 /* input channels per group */, 144 /* output_channels_per_group */, 48 /* input pixel stride */, 144 /* output pixel stride */, w162, w163, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op53); if (status != xnn_status_success) { std::cerr << "failed to create operation #53" << std::endl; return ExecutionPlan(); } operators.emplace_back(op53, xnn_delete_operator); xnn_operator_t op54 = nullptr; status = xnn_create_hardswish_nc_f32( 144 /* channels */, 144 /* input stride */, 144 /* output stride */, 0 /* flags */, &op54); if (status != xnn_status_success) { std::cerr << "failed to create operation #54" << std::endl; return ExecutionPlan(); } operators.emplace_back(op54, xnn_delete_operator); xnn_operator_t op55 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 2 /* top padding */, 2 /* right padding */, 2 /* bottom padding */, 2 /* left padding */, 5 /* kernel height */, 5 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 144 /* groups */, 1 /* input channels per group */, 1 /* output_channels_per_group */, 144 /* input pixel stride */, 144 /* output pixel stride */, w164, w165, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op55); if (status != xnn_status_success) { std::cerr << "failed to create operation #55" << std::endl; return ExecutionPlan(); } operators.emplace_back(op55, xnn_delete_operator); xnn_operator_t op56 = nullptr; status = xnn_create_hardswish_nc_f32( 144 /* channels */, 144 /* input stride */, 144 /* output stride */, 0 /* flags */, &op56); if (status != xnn_status_success) { std::cerr << "failed to create operation #56" << std::endl; return ExecutionPlan(); } operators.emplace_back(op56, xnn_delete_operator); xnn_operator_t op57 = nullptr; status = xnn_create_global_average_pooling_nwc_f32( 144 /* channels */, 144 /* input stride */, 144 /* output stride */, -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), 0 /* flags */, &op57); if (status != xnn_status_success) { std::cerr << "failed to create operation #57" << std::endl; return ExecutionPlan(); } operators.emplace_back(op57, xnn_delete_operator); xnn_operator_t op58 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 144 /* input channels per group */, 40 /* output_channels_per_group */, 144 /* input pixel stride */, 40 /* output pixel stride */, w166, w167, 0.0f /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op58); if (status != xnn_status_success) { std::cerr << "failed to create operation #58" << std::endl; return ExecutionPlan(); } operators.emplace_back(op58, xnn_delete_operator); xnn_operator_t op59 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 40 /* input channels per group */, 144 /* output_channels_per_group */, 40 /* input pixel stride */, 144 /* output pixel stride */, w168, w169, 0.0f /* output min */, +0x1.00014Fp+0 /* output max */, 0 /* flags */, &op59); if (status != xnn_status_success) { std::cerr << "failed to create operation #59" << std::endl; return ExecutionPlan(); } operators.emplace_back(op59, xnn_delete_operator); xnn_operator_t op60 = nullptr; status = xnn_create_multiply_nd_f32( -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op60); if (status != xnn_status_success) { std::cerr << "failed to create operation #60" << std::endl; return ExecutionPlan(); } operators.emplace_back(op60, xnn_delete_operator); xnn_operator_t op61 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 144 /* input channels per group */, 48 /* output_channels_per_group */, 144 /* input pixel stride */, 48 /* output pixel stride */, w170, w171, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op61); if (status != xnn_status_success) { std::cerr << "failed to create operation #61" << std::endl; return ExecutionPlan(); } operators.emplace_back(op61, xnn_delete_operator); xnn_operator_t op62 = nullptr; status = xnn_create_add_nd_f32( -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op62); if (status != xnn_status_success) { std::cerr << "failed to create operation #62" << std::endl; return ExecutionPlan(); } operators.emplace_back(op62, xnn_delete_operator); xnn_operator_t op63 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 48 /* input channels per group */, 288 /* output_channels_per_group */, 48 /* input pixel stride */, 288 /* output pixel stride */, w172, w173, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op63); if (status != xnn_status_success) { std::cerr << "failed to create operation #63" << std::endl; return ExecutionPlan(); } operators.emplace_back(op63, xnn_delete_operator); xnn_operator_t op64 = nullptr; status = xnn_create_hardswish_nc_f32( 288 /* channels */, 288 /* input stride */, 288 /* output stride */, 0 /* flags */, &op64); if (status != xnn_status_success) { std::cerr << "failed to create operation #64" << std::endl; return ExecutionPlan(); } operators.emplace_back(op64, xnn_delete_operator); xnn_operator_t op65 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 1 /* top padding */, 2 /* right padding */, 2 /* bottom padding */, 1 /* left padding */, 5 /* kernel height */, 5 /* kernel width */, 2 /* subsampling height */, 2 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 288 /* groups */, 1 /* input channels per group */, 1 /* output_channels_per_group */, 288 /* input pixel stride */, 288 /* output pixel stride */, w174, w175, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op65); if (status != xnn_status_success) { std::cerr << "failed to create operation #65" << std::endl; return ExecutionPlan(); } operators.emplace_back(op65, xnn_delete_operator); xnn_operator_t op66 = nullptr; status = xnn_create_hardswish_nc_f32( 288 /* channels */, 288 /* input stride */, 288 /* output stride */, 0 /* flags */, &op66); if (status != xnn_status_success) { std::cerr << "failed to create operation #66" << std::endl; return ExecutionPlan(); } operators.emplace_back(op66, xnn_delete_operator); xnn_operator_t op67 = nullptr; status = xnn_create_global_average_pooling_nwc_f32( 288 /* channels */, 288 /* input stride */, 288 /* output stride */, -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), 0 /* flags */, &op67); if (status != xnn_status_success) { std::cerr << "failed to create operation #67" << std::endl; return ExecutionPlan(); } operators.emplace_back(op67, xnn_delete_operator); xnn_operator_t op68 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 288 /* input channels per group */, 72 /* output_channels_per_group */, 288 /* input pixel stride */, 72 /* output pixel stride */, w176, w177, 0.0f /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op68); if (status != xnn_status_success) { std::cerr << "failed to create operation #68" << std::endl; return ExecutionPlan(); } operators.emplace_back(op68, xnn_delete_operator); xnn_operator_t op69 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 72 /* input channels per group */, 288 /* output_channels_per_group */, 72 /* input pixel stride */, 288 /* output pixel stride */, w178, w179, 0.0f /* output min */, +0x1.00014Fp+0 /* output max */, 0 /* flags */, &op69); if (status != xnn_status_success) { std::cerr << "failed to create operation #69" << std::endl; return ExecutionPlan(); } operators.emplace_back(op69, xnn_delete_operator); xnn_operator_t op70 = nullptr; status = xnn_create_multiply_nd_f32( -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op70); if (status != xnn_status_success) { std::cerr << "failed to create operation #70" << std::endl; return ExecutionPlan(); } operators.emplace_back(op70, xnn_delete_operator); xnn_operator_t op71 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 288 /* input channels per group */, 96 /* output_channels_per_group */, 288 /* input pixel stride */, 96 /* output pixel stride */, w180, w181, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op71); if (status != xnn_status_success) { std::cerr << "failed to create operation #71" << std::endl; return ExecutionPlan(); } operators.emplace_back(op71, xnn_delete_operator); xnn_operator_t op72 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 96 /* input channels per group */, 576 /* output_channels_per_group */, 96 /* input pixel stride */, 576 /* output pixel stride */, w182, w183, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op72); if (status != xnn_status_success) { std::cerr << "failed to create operation #72" << std::endl; return ExecutionPlan(); } operators.emplace_back(op72, xnn_delete_operator); xnn_operator_t op73 = nullptr; status = xnn_create_hardswish_nc_f32( 576 /* channels */, 576 /* input stride */, 576 /* output stride */, 0 /* flags */, &op73); if (status != xnn_status_success) { std::cerr << "failed to create operation #73" << std::endl; return ExecutionPlan(); } operators.emplace_back(op73, xnn_delete_operator); xnn_operator_t op74 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 2 /* top padding */, 2 /* right padding */, 2 /* bottom padding */, 2 /* left padding */, 5 /* kernel height */, 5 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 576 /* groups */, 1 /* input channels per group */, 1 /* output_channels_per_group */, 576 /* input pixel stride */, 576 /* output pixel stride */, w184, w185, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op74); if (status != xnn_status_success) { std::cerr << "failed to create operation #74" << std::endl; return ExecutionPlan(); } operators.emplace_back(op74, xnn_delete_operator); xnn_operator_t op75 = nullptr; status = xnn_create_hardswish_nc_f32( 576 /* channels */, 576 /* input stride */, 576 /* output stride */, 0 /* flags */, &op75); if (status != xnn_status_success) { std::cerr << "failed to create operation #75" << std::endl; return ExecutionPlan(); } operators.emplace_back(op75, xnn_delete_operator); xnn_operator_t op76 = nullptr; status = xnn_create_global_average_pooling_nwc_f32( 576 /* channels */, 576 /* input stride */, 576 /* output stride */, -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), 0 /* flags */, &op76); if (status != xnn_status_success) { std::cerr << "failed to create operation #76" << std::endl; return ExecutionPlan(); } operators.emplace_back(op76, xnn_delete_operator); xnn_operator_t op77 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 576 /* input channels per group */, 144 /* output_channels_per_group */, 576 /* input pixel stride */, 144 /* output pixel stride */, w186, w187, 0.0f /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op77); if (status != xnn_status_success) { std::cerr << "failed to create operation #77" << std::endl; return ExecutionPlan(); } operators.emplace_back(op77, xnn_delete_operator); xnn_operator_t op78 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 144 /* input channels per group */, 576 /* output_channels_per_group */, 144 /* input pixel stride */, 576 /* output pixel stride */, w188, w189, 0.0f /* output min */, +0x1.00014Fp+0 /* output max */, 0 /* flags */, &op78); if (status != xnn_status_success) { std::cerr << "failed to create operation #78" << std::endl; return ExecutionPlan(); } operators.emplace_back(op78, xnn_delete_operator); xnn_operator_t op79 = nullptr; status = xnn_create_multiply_nd_f32( -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op79); if (status != xnn_status_success) { std::cerr << "failed to create operation #79" << std::endl; return ExecutionPlan(); } operators.emplace_back(op79, xnn_delete_operator); xnn_operator_t op80 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 576 /* input channels per group */, 96 /* output_channels_per_group */, 576 /* input pixel stride */, 96 /* output pixel stride */, w190, w191, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op80); if (status != xnn_status_success) { std::cerr << "failed to create operation #80" << std::endl; return ExecutionPlan(); } operators.emplace_back(op80, xnn_delete_operator); xnn_operator_t op81 = nullptr; status = xnn_create_add_nd_f32( -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op81); if (status != xnn_status_success) { std::cerr << "failed to create operation #81" << std::endl; return ExecutionPlan(); } operators.emplace_back(op81, xnn_delete_operator); xnn_operator_t op82 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 96 /* input channels per group */, 576 /* output_channels_per_group */, 96 /* input pixel stride */, 576 /* output pixel stride */, w192, w193, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op82); if (status != xnn_status_success) { std::cerr << "failed to create operation #82" << std::endl; return ExecutionPlan(); } operators.emplace_back(op82, xnn_delete_operator); xnn_operator_t op83 = nullptr; status = xnn_create_hardswish_nc_f32( 576 /* channels */, 576 /* input stride */, 576 /* output stride */, 0 /* flags */, &op83); if (status != xnn_status_success) { std::cerr << "failed to create operation #83" << std::endl; return ExecutionPlan(); } operators.emplace_back(op83, xnn_delete_operator); xnn_operator_t op84 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 2 /* top padding */, 2 /* right padding */, 2 /* bottom padding */, 2 /* left padding */, 5 /* kernel height */, 5 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 576 /* groups */, 1 /* input channels per group */, 1 /* output_channels_per_group */, 576 /* input pixel stride */, 576 /* output pixel stride */, w194, w195, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op84); if (status != xnn_status_success) { std::cerr << "failed to create operation #84" << std::endl; return ExecutionPlan(); } operators.emplace_back(op84, xnn_delete_operator); xnn_operator_t op85 = nullptr; status = xnn_create_hardswish_nc_f32( 576 /* channels */, 576 /* input stride */, 576 /* output stride */, 0 /* flags */, &op85); if (status != xnn_status_success) { std::cerr << "failed to create operation #85" << std::endl; return ExecutionPlan(); } operators.emplace_back(op85, xnn_delete_operator); xnn_operator_t op86 = nullptr; status = xnn_create_global_average_pooling_nwc_f32( 576 /* channels */, 576 /* input stride */, 576 /* output stride */, -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), 0 /* flags */, &op86); if (status != xnn_status_success) { std::cerr << "failed to create operation #86" << std::endl; return ExecutionPlan(); } operators.emplace_back(op86, xnn_delete_operator); xnn_operator_t op87 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 576 /* input channels per group */, 144 /* output_channels_per_group */, 576 /* input pixel stride */, 144 /* output pixel stride */, w196, w197, 0.0f /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op87); if (status != xnn_status_success) { std::cerr << "failed to create operation #87" << std::endl; return ExecutionPlan(); } operators.emplace_back(op87, xnn_delete_operator); xnn_operator_t op88 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 144 /* input channels per group */, 576 /* output_channels_per_group */, 144 /* input pixel stride */, 576 /* output pixel stride */, w198, w199, 0.0f /* output min */, +0x1.00014Fp+0 /* output max */, 0 /* flags */, &op88); if (status != xnn_status_success) { std::cerr << "failed to create operation #88" << std::endl; return ExecutionPlan(); } operators.emplace_back(op88, xnn_delete_operator); xnn_operator_t op89 = nullptr; status = xnn_create_multiply_nd_f32( -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op89); if (status != xnn_status_success) { std::cerr << "failed to create operation #89" << std::endl; return ExecutionPlan(); } operators.emplace_back(op89, xnn_delete_operator); xnn_operator_t op90 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 576 /* input channels per group */, 96 /* output_channels_per_group */, 576 /* input pixel stride */, 96 /* output pixel stride */, w200, w201, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op90); if (status != xnn_status_success) { std::cerr << "failed to create operation #90" << std::endl; return ExecutionPlan(); } operators.emplace_back(op90, xnn_delete_operator); xnn_operator_t op91 = nullptr; status = xnn_create_add_nd_f32( -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op91); if (status != xnn_status_success) { std::cerr << "failed to create operation #91" << std::endl; return ExecutionPlan(); } operators.emplace_back(op91, xnn_delete_operator); xnn_operator_t op92 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 96 /* input channels per group */, 576 /* output_channels_per_group */, 96 /* input pixel stride */, 576 /* output pixel stride */, w202, w203, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op92); if (status != xnn_status_success) { std::cerr << "failed to create operation #92" << std::endl; return ExecutionPlan(); } operators.emplace_back(op92, xnn_delete_operator); xnn_operator_t op93 = nullptr; status = xnn_create_hardswish_nc_f32( 576 /* channels */, 576 /* input stride */, 576 /* output stride */, 0 /* flags */, &op93); if (status != xnn_status_success) { std::cerr << "failed to create operation #93" << std::endl; return ExecutionPlan(); } operators.emplace_back(op93, xnn_delete_operator); xnn_operator_t op94 = nullptr; status = xnn_create_global_average_pooling_nwc_f32( 576 /* channels */, 576 /* input stride */, 576 /* output stride */, -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), 0 /* flags */, &op94); if (status != xnn_status_success) { std::cerr << "failed to create operation #94" << std::endl; return ExecutionPlan(); } operators.emplace_back(op94, xnn_delete_operator); xnn_operator_t op95 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 576 /* input channels per group */, 1024 /* output_channels_per_group */, 576 /* input pixel stride */, 1024 /* output pixel stride */, w204, w205, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op95); if (status != xnn_status_success) { std::cerr << "failed to create operation #95" << std::endl; return ExecutionPlan(); } operators.emplace_back(op95, xnn_delete_operator); xnn_operator_t op96 = nullptr; status = xnn_create_hardswish_nc_f32( 1024 /* channels */, 1024 /* input stride */, 1024 /* output stride */, 0 /* flags */, &op96); if (status != xnn_status_success) { std::cerr << "failed to create operation #96" << std::endl; return ExecutionPlan(); } operators.emplace_back(op96, xnn_delete_operator); xnn_operator_t op97 = nullptr; status = xnn_create_global_average_pooling_nwc_f32( 1024 /* channels */, 1024 /* input stride */, 1024 /* output stride */, -std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), 0 /* flags */, &op97); if (status != xnn_status_success) { std::cerr << "failed to create operation #97" << std::endl; return ExecutionPlan(); } operators.emplace_back(op97, xnn_delete_operator); xnn_operator_t op98 = nullptr; status = xnn_create_convolution2d_nhwc_f32( 0 /* top padding */, 0 /* right padding */, 0 /* bottom padding */, 0 /* left padding */, 1 /* kernel height */, 1 /* kernel width */, 1 /* subsampling height */, 1 /* subsampling width */, 1 /* dilation_height */, 1 /* dilation_width */, 1 /* groups */, 1024 /* input channels per group */, 1001 /* output_channels_per_group */, 1024 /* input pixel stride */, 1001 /* output pixel stride */, w206, w207, -std::numeric_limits<float>::infinity() /* output min */, std::numeric_limits<float>::infinity() /* output max */, 0 /* flags */, &op98); if (status != xnn_status_success) { std::cerr << "failed to create operation #98" << std::endl; return ExecutionPlan(); } operators.emplace_back(op98, xnn_delete_operator); status = xnn_setup_convolution2d_nhwc_f32( op0, 1 /* batch size */, 224 /* input height */, 224 /* input width */, v0 /* input */, v1 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #0" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op1, 12544 /* batch size */, v1 /* input */, v2 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #1" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op2, 1 /* batch size */, 112 /* input height */, 112 /* input width */, v2 /* input */, v3 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #2" << std::endl; return ExecutionPlan(); } status = xnn_setup_global_average_pooling_nwc_f32( op3, 1 /* batch size */, 3136 /* width */, v3 /* input */, v4 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #3" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op4, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v4 /* input */, v5 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #4" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op5, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v5 /* input */, v6 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #5" << std::endl; return ExecutionPlan(); } { const size_t a_shape[] = { 1, 56, 56, 16 }; const size_t b_shape[] = { 1, 1, 1, 16 }; status = xnn_setup_multiply_nd_f32( op6, 4, a_shape, 4, b_shape, v3 /* a */, v6 /* b */, v7 /* output */, threadpool /* threadpool */); } if (status != xnn_status_success) { std::cerr << "failed to setup operation #6" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op7, 1 /* batch size */, 56 /* input height */, 56 /* input width */, v7 /* input */, v8 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #7" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op8, 1 /* batch size */, 56 /* input height */, 56 /* input width */, v8 /* input */, v9 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #8" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op9, 1 /* batch size */, 56 /* input height */, 56 /* input width */, v9 /* input */, v10 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #9" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op10, 1 /* batch size */, 28 /* input height */, 28 /* input width */, v10 /* input */, v11 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #10" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op11, 1 /* batch size */, 28 /* input height */, 28 /* input width */, v11 /* input */, v12 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #11" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op12, 1 /* batch size */, 28 /* input height */, 28 /* input width */, v12 /* input */, v13 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #12" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op13, 1 /* batch size */, 28 /* input height */, 28 /* input width */, v13 /* input */, v14 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #13" << std::endl; return ExecutionPlan(); } { const size_t a_shape[] = { 1, 28, 28, 24 }; const size_t b_shape[] = { 1, 28, 28, 24 }; status = xnn_setup_add_nd_f32( op14, 4, a_shape, 4, b_shape, v14 /* a */, v11 /* b */, v15 /* output */, threadpool /* threadpool */); } if (status != xnn_status_success) { std::cerr << "failed to setup operation #14" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op15, 1 /* batch size */, 28 /* input height */, 28 /* input width */, v15 /* input */, v16 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #15" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op16, 784 /* batch size */, v16 /* input */, v17 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #16" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op17, 1 /* batch size */, 28 /* input height */, 28 /* input width */, v17 /* input */, v18 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #17" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op18, 196 /* batch size */, v18 /* input */, v19 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #18" << std::endl; return ExecutionPlan(); } status = xnn_setup_global_average_pooling_nwc_f32( op19, 1 /* batch size */, 196 /* width */, v19 /* input */, v20 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #19" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op20, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v20 /* input */, v21 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #20" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op21, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v21 /* input */, v22 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #21" << std::endl; return ExecutionPlan(); } { const size_t a_shape[] = { 1, 14, 14, 96 }; const size_t b_shape[] = { 1, 1, 1, 96 }; status = xnn_setup_multiply_nd_f32( op22, 4, a_shape, 4, b_shape, v19 /* a */, v22 /* b */, v23 /* output */, threadpool /* threadpool */); } if (status != xnn_status_success) { std::cerr << "failed to setup operation #22" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op23, 1 /* batch size */, 14 /* input height */, 14 /* input width */, v23 /* input */, v24 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #23" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op24, 1 /* batch size */, 14 /* input height */, 14 /* input width */, v24 /* input */, v25 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #24" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op25, 196 /* batch size */, v25 /* input */, v26 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #25" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op26, 1 /* batch size */, 14 /* input height */, 14 /* input width */, v26 /* input */, v27 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #26" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op27, 196 /* batch size */, v27 /* input */, v28 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #27" << std::endl; return ExecutionPlan(); } status = xnn_setup_global_average_pooling_nwc_f32( op28, 1 /* batch size */, 196 /* width */, v28 /* input */, v29 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #28" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op29, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v29 /* input */, v30 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #29" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op30, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v30 /* input */, v31 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #30" << std::endl; return ExecutionPlan(); } { const size_t a_shape[] = { 1, 14, 14, 240 }; const size_t b_shape[] = { 1, 1, 1, 240 }; status = xnn_setup_multiply_nd_f32( op31, 4, a_shape, 4, b_shape, v28 /* a */, v31 /* b */, v32 /* output */, threadpool /* threadpool */); } if (status != xnn_status_success) { std::cerr << "failed to setup operation #31" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op32, 1 /* batch size */, 14 /* input height */, 14 /* input width */, v32 /* input */, v33 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #32" << std::endl; return ExecutionPlan(); } { const size_t a_shape[] = { 1, 14, 14, 40 }; const size_t b_shape[] = { 1, 14, 14, 40 }; status = xnn_setup_add_nd_f32( op33, 4, a_shape, 4, b_shape, v33 /* a */, v24 /* b */, v34 /* output */, threadpool /* threadpool */); } if (status != xnn_status_success) { std::cerr << "failed to setup operation #33" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op34, 1 /* batch size */, 14 /* input height */, 14 /* input width */, v34 /* input */, v35 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #34" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op35, 196 /* batch size */, v35 /* input */, v36 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #35" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op36, 1 /* batch size */, 14 /* input height */, 14 /* input width */, v36 /* input */, v37 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #36" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op37, 196 /* batch size */, v37 /* input */, v38 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #37" << std::endl; return ExecutionPlan(); } status = xnn_setup_global_average_pooling_nwc_f32( op38, 1 /* batch size */, 196 /* width */, v38 /* input */, v39 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #38" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op39, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v39 /* input */, v40 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #39" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op40, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v40 /* input */, v41 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #40" << std::endl; return ExecutionPlan(); } { const size_t a_shape[] = { 1, 14, 14, 240 }; const size_t b_shape[] = { 1, 1, 1, 240 }; status = xnn_setup_multiply_nd_f32( op41, 4, a_shape, 4, b_shape, v38 /* a */, v41 /* b */, v42 /* output */, threadpool /* threadpool */); } if (status != xnn_status_success) { std::cerr << "failed to setup operation #41" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op42, 1 /* batch size */, 14 /* input height */, 14 /* input width */, v42 /* input */, v43 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #42" << std::endl; return ExecutionPlan(); } { const size_t a_shape[] = { 1, 14, 14, 40 }; const size_t b_shape[] = { 1, 14, 14, 40 }; status = xnn_setup_add_nd_f32( op43, 4, a_shape, 4, b_shape, v43 /* a */, v34 /* b */, v44 /* output */, threadpool /* threadpool */); } if (status != xnn_status_success) { std::cerr << "failed to setup operation #43" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op44, 1 /* batch size */, 14 /* input height */, 14 /* input width */, v44 /* input */, v45 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #44" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op45, 196 /* batch size */, v45 /* input */, v46 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #45" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op46, 1 /* batch size */, 14 /* input height */, 14 /* input width */, v46 /* input */, v47 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #46" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op47, 196 /* batch size */, v47 /* input */, v48 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #47" << std::endl; return ExecutionPlan(); } status = xnn_setup_global_average_pooling_nwc_f32( op48, 1 /* batch size */, 196 /* width */, v48 /* input */, v49 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #48" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op49, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v49 /* input */, v50 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #49" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op50, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v50 /* input */, v51 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #50" << std::endl; return ExecutionPlan(); } { const size_t a_shape[] = { 1, 14, 14, 120 }; const size_t b_shape[] = { 1, 1, 1, 120 }; status = xnn_setup_multiply_nd_f32( op51, 4, a_shape, 4, b_shape, v48 /* a */, v51 /* b */, v52 /* output */, threadpool /* threadpool */); } if (status != xnn_status_success) { std::cerr << "failed to setup operation #51" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op52, 1 /* batch size */, 14 /* input height */, 14 /* input width */, v52 /* input */, v53 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #52" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op53, 1 /* batch size */, 14 /* input height */, 14 /* input width */, v53 /* input */, v54 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #53" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op54, 196 /* batch size */, v54 /* input */, v55 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #54" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op55, 1 /* batch size */, 14 /* input height */, 14 /* input width */, v55 /* input */, v56 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #55" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op56, 196 /* batch size */, v56 /* input */, v57 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #56" << std::endl; return ExecutionPlan(); } status = xnn_setup_global_average_pooling_nwc_f32( op57, 1 /* batch size */, 196 /* width */, v57 /* input */, v58 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #57" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op58, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v58 /* input */, v59 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #58" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op59, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v59 /* input */, v60 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #59" << std::endl; return ExecutionPlan(); } { const size_t a_shape[] = { 1, 14, 14, 144 }; const size_t b_shape[] = { 1, 1, 1, 144 }; status = xnn_setup_multiply_nd_f32( op60, 4, a_shape, 4, b_shape, v57 /* a */, v60 /* b */, v61 /* output */, threadpool /* threadpool */); } if (status != xnn_status_success) { std::cerr << "failed to setup operation #60" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op61, 1 /* batch size */, 14 /* input height */, 14 /* input width */, v61 /* input */, v62 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #61" << std::endl; return ExecutionPlan(); } { const size_t a_shape[] = { 1, 14, 14, 48 }; const size_t b_shape[] = { 1, 14, 14, 48 }; status = xnn_setup_add_nd_f32( op62, 4, a_shape, 4, b_shape, v62 /* a */, v53 /* b */, v63 /* output */, threadpool /* threadpool */); } if (status != xnn_status_success) { std::cerr << "failed to setup operation #62" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op63, 1 /* batch size */, 14 /* input height */, 14 /* input width */, v63 /* input */, v64 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #63" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op64, 196 /* batch size */, v64 /* input */, v65 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #64" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op65, 1 /* batch size */, 14 /* input height */, 14 /* input width */, v65 /* input */, v66 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #65" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op66, 49 /* batch size */, v66 /* input */, v67 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #66" << std::endl; return ExecutionPlan(); } status = xnn_setup_global_average_pooling_nwc_f32( op67, 1 /* batch size */, 49 /* width */, v67 /* input */, v68 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #67" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op68, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v68 /* input */, v69 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #68" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op69, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v69 /* input */, v70 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #69" << std::endl; return ExecutionPlan(); } { const size_t a_shape[] = { 1, 7, 7, 288 }; const size_t b_shape[] = { 1, 1, 1, 288 }; status = xnn_setup_multiply_nd_f32( op70, 4, a_shape, 4, b_shape, v67 /* a */, v70 /* b */, v71 /* output */, threadpool /* threadpool */); } if (status != xnn_status_success) { std::cerr << "failed to setup operation #70" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op71, 1 /* batch size */, 7 /* input height */, 7 /* input width */, v71 /* input */, v72 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #71" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op72, 1 /* batch size */, 7 /* input height */, 7 /* input width */, v72 /* input */, v73 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #72" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op73, 49 /* batch size */, v73 /* input */, v74 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #73" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op74, 1 /* batch size */, 7 /* input height */, 7 /* input width */, v74 /* input */, v75 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #74" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op75, 49 /* batch size */, v75 /* input */, v76 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #75" << std::endl; return ExecutionPlan(); } status = xnn_setup_global_average_pooling_nwc_f32( op76, 1 /* batch size */, 49 /* width */, v76 /* input */, v77 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #76" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op77, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v77 /* input */, v78 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #77" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op78, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v78 /* input */, v79 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #78" << std::endl; return ExecutionPlan(); } { const size_t a_shape[] = { 1, 7, 7, 576 }; const size_t b_shape[] = { 1, 1, 1, 576 }; status = xnn_setup_multiply_nd_f32( op79, 4, a_shape, 4, b_shape, v76 /* a */, v79 /* b */, v80 /* output */, threadpool /* threadpool */); } if (status != xnn_status_success) { std::cerr << "failed to setup operation #79" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op80, 1 /* batch size */, 7 /* input height */, 7 /* input width */, v80 /* input */, v81 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #80" << std::endl; return ExecutionPlan(); } { const size_t a_shape[] = { 1, 7, 7, 96 }; const size_t b_shape[] = { 1, 7, 7, 96 }; status = xnn_setup_add_nd_f32( op81, 4, a_shape, 4, b_shape, v81 /* a */, v72 /* b */, v82 /* output */, threadpool /* threadpool */); } if (status != xnn_status_success) { std::cerr << "failed to setup operation #81" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op82, 1 /* batch size */, 7 /* input height */, 7 /* input width */, v82 /* input */, v83 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #82" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op83, 49 /* batch size */, v83 /* input */, v84 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #83" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op84, 1 /* batch size */, 7 /* input height */, 7 /* input width */, v84 /* input */, v85 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #84" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op85, 49 /* batch size */, v85 /* input */, v86 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #85" << std::endl; return ExecutionPlan(); } status = xnn_setup_global_average_pooling_nwc_f32( op86, 1 /* batch size */, 49 /* width */, v86 /* input */, v87 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #86" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op87, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v87 /* input */, v88 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #87" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op88, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v88 /* input */, v89 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #88" << std::endl; return ExecutionPlan(); } { const size_t a_shape[] = { 1, 7, 7, 576 }; const size_t b_shape[] = { 1, 1, 1, 576 }; status = xnn_setup_multiply_nd_f32( op89, 4, a_shape, 4, b_shape, v86 /* a */, v89 /* b */, v90 /* output */, threadpool /* threadpool */); } if (status != xnn_status_success) { std::cerr << "failed to setup operation #89" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op90, 1 /* batch size */, 7 /* input height */, 7 /* input width */, v90 /* input */, v91 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #90" << std::endl; return ExecutionPlan(); } { const size_t a_shape[] = { 1, 7, 7, 96 }; const size_t b_shape[] = { 1, 7, 7, 96 }; status = xnn_setup_add_nd_f32( op91, 4, a_shape, 4, b_shape, v91 /* a */, v82 /* b */, v92 /* output */, threadpool /* threadpool */); } if (status != xnn_status_success) { std::cerr << "failed to setup operation #91" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op92, 1 /* batch size */, 7 /* input height */, 7 /* input width */, v92 /* input */, v93 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #92" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op93, 49 /* batch size */, v93 /* input */, v94 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #93" << std::endl; return ExecutionPlan(); } status = xnn_setup_global_average_pooling_nwc_f32( op94, 1 /* batch size */, 49 /* width */, v94 /* input */, v95 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #94" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op95, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v95 /* input */, v96 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #95" << std::endl; return ExecutionPlan(); } status = xnn_setup_hardswish_nc_f32( op96, 1 /* batch size */, v96 /* input */, v97 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #96" << std::endl; return ExecutionPlan(); } status = xnn_setup_global_average_pooling_nwc_f32( op97, 1 /* batch size */, 1 /* width */, v97 /* input */, v98 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #97" << std::endl; return ExecutionPlan(); } status = xnn_setup_convolution2d_nhwc_f32( op98, 1 /* batch size */, 1 /* input height */, 1 /* input width */, v98 /* input */, v99 /* output */, threadpool /* threadpool */); if (status != xnn_status_success) { std::cerr << "failed to setup operation #98" << std::endl; return ExecutionPlan(); } #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wpessimizing-move" return operators; #pragma clang diagnostic pop } } // namespace models
_MainMenu: ld de, MUSIC_NONE call PlayMusic call DelayFrame ld de, MUSIC_MAIN_MENU ld a, e ld [wMapMusic], a call PlayMusic farcall MainMenu jp StartTitleScreen ; unused ret PrintDayOfWeek: push de ld hl, .Days ld a, b call GetNthString ld d, h ld e, l pop hl call PlaceString ld h, b ld l, c ld de, .Day call PlaceString ret .Days: db "SUN@" db "MON@" db "TUES@" db "WEDNES@" db "THURS@" db "FRI@" db "SATUR@" .Day: db "DAY@" NewGame_ClearTileMapEtc: xor a ldh [hMapAnims], a call ClearTileMap call LoadFontsExtra call LoadStandardFont call ClearWindowData ret MysteryGift: call UpdateTime farcall DoMysteryGiftIfDayHasPassed farcall DoMysteryGift ret OptionsMenu: farcall _OptionsMenu ret NewGame: xor a ld [wDebugFlags], a call ResetWRAM call NewGame_ClearTileMapEtc ; call AreYouABoyOrAreYouAGirl call OakSpeech call InitializeWorld call IntroSandgemScene ld a, 1 ld [wPrevLandmark], a ld a, SPAWN_HOME ld [wDefaultSpawnpoint], a ld a, MAPSETUP_WARP ldh [hMapEntryMethod], a jp FinishContinueFunction AreYouABoyOrAreYouAGirl: farcall Mobile_AlwaysReturnNotCarry ; some mobile stuff jr c, .ok farcall InitGender ret .ok ld c, 0 farcall InitMobileProfile ; mobile ret ResetWRAM: xor a ldh [hBGMapMode], a call _ResetWRAM ret _ResetWRAM: ld a, BANK("16-bit WRAM tables") ldh [rSVBK], a ld hl, wPokemonIndexTable ld bc, wPokemonIndexTableEnd - wPokemonIndexTable xor a call ByteFill ld hl, wMoveIndexTable ld bc, wMoveIndexTableEnd - wMoveIndexTable call ByteFill ld a, 1 ldh [rSVBK], a ld hl, wVirtualOAM ld bc, wOptions - wVirtualOAM xor a call ByteFill ld hl, WRAM1_Begin ld bc, wGameData - WRAM1_Begin xor a call ByteFill ld hl, wGameData ld bc, wGameDataEnd - wGameData xor a call ByteFill ldh a, [rLY] ldh [hSecondsBackup], a call DelayFrame ldh a, [hRandomSub] ld [wPlayerID], a ldh a, [rLY] ldh [hSecondsBackup], a call DelayFrame ldh a, [hRandomAdd] ld [wPlayerID + 1], a call Random ld [wSecretID], a call DelayFrame call Random ld [wSecretID + 1], a ld hl, wPartyCount call .InitList xor a ld [wCurBox], a ld [wSavedAtLeastOnce], a call SetDefaultBoxNames ld a, BANK(sBoxCount) call GetSRAMBank ld hl, sBoxCount call .InitList call CloseSRAM ld hl, wNumItems call .InitList ld hl, wNumKeyItems call .InitList ld hl, wNumBalls call .InitList ld hl, wNumBerries call .InitList ld hl, wNumMedicine call .InitList ld hl, wNumPCItems call .InitList xor a ld [wRoamMon1Species], a ld [wRoamMon2Species], a ld [wRoamMon3Species], a ld a, -1 ld [wRoamMon1MapGroup], a ld [wRoamMon2MapGroup], a ld [wRoamMon3MapGroup], a ld [wRoamMon1MapNumber], a ld [wRoamMon2MapNumber], a ld [wRoamMon3MapNumber], a ld a, BANK(sMysteryGiftItem) call GetSRAMBank ld hl, sMysteryGiftItem xor a ld [hli], a dec a ld [hl], a call CloseSRAM call LoadOrRegenerateLuckyIDNumber call InitializeMagikarpHouse xor a ld [wMonType], a ld [wJohtoBadges], a ld [wKantoBadges], a ld [wCoins], a ld [wCoins + 1], a if START_MONEY >= $10000 ld a, HIGH(START_MONEY >> 8) endc ld [wMoney], a ld a, HIGH(START_MONEY) ; mid ld [wMoney + 1], a ld a, LOW(START_MONEY) ld [wMoney + 2], a xor a ld [wWhichMomItem], a ld hl, wMomItemTriggerBalance ld [hl], HIGH(MOM_MONEY >> 8) inc hl ld [hl], HIGH(MOM_MONEY) ; mid inc hl ld [hl], LOW(MOM_MONEY) call InitializeNPCNames farcall InitDecorations farcall DeletePartyMonMail farcall DeleteMobileEventIndex call ResetGameTime ret .InitList: ; Loads 0 in the count and -1 in the first item or mon slot. xor a ld [hli], a dec a ld [hl], a ret SetDefaultBoxNames: ldh a, [rSVBK] push af ld a, BANK(wBoxNames) ldh [rSVBK], a ld hl, wBoxNames ld c, 0 .loop push hl ld de, .Box call CopyName2 dec hl ld a, c inc a cp 10 jr c, .less sub 10 cp 10 jr c, .less_than_20 sub 10 ld [hl], "2" inc hl jr .less .less_than_20 ld [hl], "1" inc hl .less add "0" ld [hli], a ld [hl], "@" pop hl ld de, 9 add hl, de inc c ld a, c cp NUM_BOXES jr c, .loop pop af ldh [rSVBK], a ret .Box: db "BOX@" InitializeMagikarpHouse: ld hl, wBestMagikarpLengthFeet ld a, $3 ld [hli], a ld a, $6 ld [hli], a ld de, .Ralph call CopyName2 ret .Ralph: db "RALPH@" InitializeNPCNames: ld hl, .Rival ld de, wRivalName call .Copy ld hl, .Mom ld de, wMomsName call .Copy ld hl, .Red ld de, wRedsName call .Copy ld hl, .Green ld de, wGreensName .Copy: ld bc, NAME_LENGTH call CopyBytes ret .Rival: db "CEDRIC@" .Red: db "BRENDAN@" .Green: db "MAY@" .Mom: db "JOHANNA@" InitializeWorld: call ShrinkPlayer farcall SpawnPlayer farcall _InitializeStartDay farcall InitializeEvents ret LoadOrRegenerateLuckyIDNumber: ld a, BANK(sLuckyIDNumber) call GetSRAMBank ld a, [wCurDay] inc a ld b, a ld a, [sLuckyNumberDay] cp b ld a, [sLuckyIDNumber + 1] ld c, a ld a, [sLuckyIDNumber] jr z, .skip ld a, b ld [sLuckyNumberDay], a call Random ld c, a call Random .skip ld [wLuckyIDNumber], a ld [sLuckyIDNumber], a ld a, c ld [wLuckyIDNumber + 1], a ld [sLuckyIDNumber + 1], a jp CloseSRAM Continue: farcall TryLoadSaveFile jr c, .FailToLoad farcall _LoadData call LoadStandardMenuHeader call DisplaySaveInfoOnContinue ld a, $1 ldh [hBGMapMode], a ld c, 20 call DelayFrames call ConfirmContinue jr nc, .Check1Pass call CloseWindow jr .FailToLoad .Check1Pass: call Continue_CheckRTC_RestartClock jr nc, .Check2Pass call CloseWindow jr .FailToLoad .Check2Pass: ld a, $8 ld [wMusicFade], a ld a, LOW(MUSIC_NONE) ld [wMusicFadeID], a ld a, HIGH(MUSIC_NONE) ld [wMusicFadeID + 1], a call ClearBGPalettes call Continue_MobileAdapterMenu call CloseWindow call ClearTileMap ld c, 20 call DelayFrames farcall JumpRoamMons farcall MysteryGift_CopyReceivedDecosToPC ; Mystery Gift farcall Function140ae ; time-related ld a, [wSpawnAfterChampion] cp SPAWN_LANCE jr z, .SpawnAfterE4 ld a, MAPSETUP_CONTINUE ldh [hMapEntryMethod], a jp FinishContinueFunction .FailToLoad: ret .SpawnAfterE4: ld a, SPAWN_TWINLEAF ld [wDefaultSpawnpoint], a call PostCreditsSpawn jp FinishContinueFunction PostCreditsSpawn: xor a ld [wSpawnAfterChampion], a ld a, MAPSETUP_WARP ldh [hMapEntryMethod], a ret Continue_MobileAdapterMenu: farcall Mobile_AlwaysReturnNotCarry ; mobile check ret nc ; the rest of this stuff is never reached because ; the previous function returns with carry not set ld hl, wd479 bit 1, [hl] ret nz ld a, 5 ld [wMusicFade], a ld a, LOW(MUSIC_MOBILE_ADAPTER_MENU) ld [wMusicFadeID], a ld a, HIGH(MUSIC_MOBILE_ADAPTER_MENU) ld [wMusicFadeID + 1], a ld c, 20 call DelayFrames ld c, $1 farcall InitMobileProfile ; mobile farcall _SaveData ld a, 8 ld [wMusicFade], a ld a, LOW(MUSIC_NONE) ld [wMusicFadeID], a ld a, HIGH(MUSIC_NONE) ld [wMusicFadeID + 1], a ld c, 35 call DelayFrames ret ConfirmContinue: .loop call DelayFrame call GetJoypad ld hl, hJoyPressed bit A_BUTTON_F, [hl] jr nz, .PressA bit B_BUTTON_F, [hl] jr z, .loop scf ret .PressA: ret Continue_CheckRTC_RestartClock: call CheckRTCStatus and %10000000 ; Day count exceeded 16383 jr z, .pass farcall RestartClock ld a, c and a jr z, .pass scf ret .pass xor a ret FinishContinueFunction: .loop xor a ld [wDontPlayMapMusicOnReload], a ld [wLinkMode], a ld hl, wGameTimerPause set GAMETIMERPAUSE_TIMER_PAUSED_F, [hl] res GAMETIMERPAUSE_MOBILE_7_F, [hl] ld hl, wEnteredMapFromContinue set 1, [hl] farcall OverworldLoop jp Reset DisplaySaveInfoOnContinue: call CheckRTCStatus and %10000000 jr z, .clock_ok lb de, 4, 8 call DisplayContinueDataWithRTCError ret .clock_ok lb de, 4, 8 call DisplayNormalContinueData ret DisplaySaveInfoOnSave: lb de, 4, 0 jr DisplayNormalContinueData DisplayNormalContinueData: call Continue_LoadMenuHeader call Continue_DisplayBadgesDexPlayerName call Continue_PrintGameTime call LoadFontsExtra call UpdateSprites ret DisplayContinueDataWithRTCError: call Continue_LoadMenuHeader call Continue_DisplayBadgesDexPlayerName call Continue_UnknownGameTime call LoadFontsExtra call UpdateSprites ret Continue_LoadMenuHeader: xor a ldh [hBGMapMode], a ld hl, .MenuHeader_Dex ld a, [wStatusFlags] bit STATUSFLAGS_POKEDEX_F, a jr nz, .show_menu ld hl, .MenuHeader_NoDex .show_menu call _OffsetMenuHeader call MenuBox call PlaceVerticalMenuItems ret .MenuHeader_Dex: db MENU_BACKUP_TILES ; flags menu_coords 0, 0, 15, 9 dw .MenuData_Dex db 1 ; default option .MenuData_Dex: db 0 ; flags db 4 ; items db "PLAYER@" db "BADGES@" db "#DEX@" db "TIME@" .MenuHeader_NoDex: db MENU_BACKUP_TILES ; flags menu_coords 0, 0, 15, 9 dw .MenuData_NoDex db 1 ; default option .MenuData_NoDex: db 0 ; flags db 4 ; items db "PLAYER <PLAYER>@" db "BADGES@" db " @" db "TIME@" Continue_DisplayBadgesDexPlayerName: call MenuBoxCoord2Tile push hl decoord 13, 4, 0 add hl, de call Continue_DisplayBadgeCount pop hl push hl decoord 12, 6, 0 add hl, de call Continue_DisplayPokedexNumCaught pop hl push hl decoord 8, 2, 0 add hl, de ld de, .Player call PlaceString pop hl ret .Player: db "<PLAYER>@" Continue_PrintGameTime: decoord 9, 8, 0 add hl, de call Continue_DisplayGameTime ret Continue_UnknownGameTime: decoord 9, 8, 0 add hl, de ld de, .three_question_marks call PlaceString ret .three_question_marks db " ???@" Continue_DisplayBadgeCount: push hl ld hl, wJohtoBadges ld b, 2 call CountSetBits pop hl ld de, wNumSetBits lb bc, 1, 2 jp PrintNum Continue_DisplayPokedexNumCaught: ld a, [wStatusFlags] bit STATUSFLAGS_POKEDEX_F, a ret z push hl ld hl, wPokedexCaught ld bc, wEndPokedexCaught - wPokedexCaught call CountSetBits16 pop hl ld a, b ld b, c ld c, a push bc push hl ld hl, sp + 2 ld d, h ld e, l lb bc, 2, 3 pop hl call PrintNum pop bc ret Continue_DisplayGameTime: ld de, wGameTimeHours lb bc, 2, 3 call PrintNum ld [hl], "<COLON>" inc hl ld de, wGameTimeMinutes lb bc, PRINTNUM_LEADINGZEROS | 1, 2 jp PrintNum OakSpeech: farcall InitClock call RotateFourPalettesLeft call ClearTileMap ld de, MUSIC_PROF_ELM call PlayMusic call RotateFourPalettesRight call RotateThreePalettesRight xor a ld [wCurPartySpecies], a ld a, POKEMON_PROF ld [wTrainerClass], a call Intro_PrepTrainerPic ld b, SCGB_TRAINER_OR_MON_FRONTPIC_PALS call GetSGBLayout call Intro_RotatePalettesLeftFrontpic ld hl, OakText1 call PrintText call RotateThreePalettesRight call ClearTileMap ld hl, BUNEARY call GetPokemonIDFromIndex ld [wCurSpecies], a ld [wCurPartySpecies], a call GetBaseData hlcoord 6, 4 call PrepMonFrontpic xor a ld [wTempMonDVs], a ld [wTempMonDVs + 1], a ld b, SCGB_TRAINER_OR_MON_FRONTPIC_PALS call GetSGBLayout call Intro_WipeInFrontpic ld hl, OakText2 call PrintText ld hl, OakText4 call PrintText call RotateThreePalettesRight call ClearTileMap xor a ld [wCurPartySpecies], a ld a, POKEMON_PROF ld [wTrainerClass], a call Intro_PrepTrainerPic ld b, SCGB_TRAINER_OR_MON_FRONTPIC_PALS call GetSGBLayout call Intro_RotatePalettesLeftFrontpic ld hl, OakText5 call PrintText call RotateThreePalettesRight call ClearTileMap call IntroMenuChooseGender call RotateThreePalettesRight call ClearTileMap xor a ld [wCurPartySpecies], a farcall DrawIntroPlayerPic ld b, SCGB_TRAINER_OR_MON_FRONTPIC_PALS call GetSGBLayout call Intro_RotatePalettesLeftFrontpic .player_name_loop ld hl, OakText7 call PrintText call NamePlayer ld hl, OakTextConfirmName call PrintText call YesNoBox jr c, .player_name_loop call RotateThreePalettesRight call ClearTileMap xor a ld [wCurPartySpecies], a ld a, RIVAL1 ld [wTrainerClass], a call Intro_PrepTrainerPic ld b, SCGB_TRAINER_OR_MON_FRONTPIC_PALS call GetSGBLayout call Intro_RotatePalettesLeftFrontpic ld hl, OakText8 call PrintText .rival_loop ld hl, OakText9 call PrintText call IntroNameRival ld hl, OakTextConfirmRival call PrintText call YesNoBox jr c, .rival_loop call RotateThreePalettesRight call ClearTileMap xor a ld [wCurPartySpecies], a farcall DrawIntroPlayerPic ld b, SCGB_TRAINER_OR_MON_FRONTPIC_PALS call GetSGBLayout call Intro_RotatePalettesLeftFrontpic ld hl, OakText10 call PrintText ret IF DEF(_DEBUG) OakText1: OakText2: OakText3: OakText4: OakText5: OakText6: OakText7: OakText8: OakText9: OakText10: text_end ELSE OakText1: text_far _OakText1 text_end OakText2: text_far _OakText2 text_asm ld hl, BUNEARY call GetPokemonIDFromIndex call PlayMonCry call WaitSFX ld hl, OakText3 ret OakText3: text_far _OakText3 text_end OakText4: text_far _OakText4 text_end OakText5: text_far _OakText5 text_end OakText6: text_far _OakText6 text_end OakText7: text_far _OakText7 text_end OakText8: text_far _OakText8 text_end OakText9: text_far _OakText9 text_end OakText10: text_far _OakText10 text_end ENDC OakTextBoy: text_far _Oak_YouAreABoy text_end OakTextGirl: text_far _Oak_YouAreAGirl text_end OakTextBoyOrGirl: text_far _Oak_AreYouABoyOrAGirl text_end OakTextConfirmName: text_far _Oak_ConfirmName text_end OakTextConfirmRival: text_far _Oak_ConfirmRival text_end IntroSandgemText: text_far _IntroSandgem text_end NamePlayer: farcall MovePlayerPicRight farcall ShowPlayerNamingChoices ld a, [wMenuCursorY] dec a jr z, .NewName call StorePlayerName farcall ApplyMonOrTrainerPals farcall MovePlayerPicLeft ret .NewName: ld b, NAME_PLAYER ld de, wPlayerName farcall NamingScreen call RotateThreePalettesRight call ClearTileMap call LoadFontsExtra call WaitBGMap xor a ld [wCurPartySpecies], a farcall DrawIntroPlayerPic ld b, SCGB_TRAINER_OR_MON_FRONTPIC_PALS call GetSGBLayout call RotateThreePalettesLeft ld hl, wPlayerName ld de, .Chris ld a, [wPlayerGender] bit PLAYERGENDER_FEMALE_F, a jr z, .Male ld de, .Kris .Male: call InitName ret .Chris: db "LUCAS@@@@@@" .Kris: db "DAWN@@@@@@@" IntroNameRival: farcall MovePlayerPicRight farcall ShowRivalNamingChoices ld a, [wMenuCursorY] dec a jr z, .NewName call StoreRivalName farcall ApplyMonOrTrainerPals farcall MovePlayerPicLeft ret .NewName: ld b, NAME_RIVAL ld de, wRivalName farcall NamingScreen call RotateThreePalettesRight call ClearTileMap call LoadFontsExtra call WaitBGMap xor a ld [wCurPartySpecies], a ld a, RIVAL1 ld [wTrainerClass], a call Intro_PrepTrainerPic ld b, SCGB_TRAINER_OR_MON_FRONTPIC_PALS call GetSGBLayout call RotateThreePalettesLeft ld hl, wRivalName ld de, .DefaultName call InitName ret .DefaultName: db "BARRY@@@@@@" Unreferenced_Function60e9: call LoadMenuHeader call VerticalMenu ld a, [wMenuCursorY] dec a call CopyNameFromMenu call CloseWindow ret StorePlayerName: ld hl, wPlayerName jr StoreName StoreRivalName: ld hl, wRivalName StoreName: push hl ld a, "@" ld bc, NAME_LENGTH call ByteFill pop hl ld de, wStringBuffer2 call CopyName2 ret ShrinkPlayer: ldh a, [hROMBank] push af ld a, 16 ; fade time ld [wMusicFade], a ld de, MUSIC_NONE ld a, e ld [wMusicFadeID], a ld a, d ld [wMusicFadeID + 1], a ld de, SFX_ESCAPE_ROPE call PlaySFX pop af rst Bankswitch ld c, 8 call DelayFrames ld hl, Shrink1Pic ld b, BANK(Shrink1Pic) call ShrinkFrame ld c, 8 call DelayFrames ld hl, Shrink2Pic ld b, BANK(Shrink2Pic) call ShrinkFrame ld c, 8 call DelayFrames hlcoord 6, 5 ld b, 7 ld c, 7 call ClearBox ld c, 3 call DelayFrames call Intro_PlacePlayerSprite call LoadFontsExtra ld c, 50 call DelayFrames call RotateThreePalettesRight call ClearTileMap ret Intro_RotatePalettesLeftFrontpic: ld hl, IntroFadePalettes ld b, IntroFadePalettes.End - IntroFadePalettes .loop ld a, [hli] call DmgToCgbBGPals ld c, 10 call DelayFrames dec b jr nz, .loop ret IntroFadePalettes: dc 1, 1, 1, 0 dc 2, 2, 2, 0 dc 3, 3, 3, 0 dc 3, 3, 2, 0 dc 3, 3, 1, 0 dc 3, 2, 1, 0 .End Intro_WipeInFrontpic: ld a, $77 ldh [hWX], a call DelayFrame ld a, %11100100 call DmgToCgbBGPals .loop call DelayFrame ldh a, [hWX] sub $8 cp -1 ret z ldh [hWX], a jr .loop Intro_PrepTrainerPic: ld de, vTiles2 farcall GetTrainerPic xor a ldh [hGraphicStartTile], a hlcoord 6, 4 lb bc, 7, 7 predef PlaceGraphic ret ShrinkFrame: ld de, vTiles2 ld c, 7 * 7 predef DecompressGet2bpp xor a ldh [hGraphicStartTile], a hlcoord 6, 4 lb bc, 7, 7 predef PlaceGraphic ret Intro_PlacePlayerSprite: farcall GetPlayerIcon ld c, $c ld hl, vTiles0 call Request2bpp ld hl, wVirtualOAMSprite00 ld de, .sprites ld a, [de] inc de ld c, a .loop ld a, [de] inc de ld [hli], a ; y ld a, [de] inc de ld [hli], a ; x ld a, [de] inc de ld [hli], a ; tile id ld b, PAL_OW_BLUE ld a, [wPlayerGender] bit PLAYERGENDER_FEMALE_F, a jr z, .male ld b, PAL_OW_RED .male ld a, b ld [hli], a dec c jr nz, .loop ret .sprites db 4 ; y pxl, x pxl, tile offset db 9 * 8 + 4, 9 * 8, 0 db 9 * 8 + 4, 10 * 8, 1 db 10 * 8 + 4, 9 * 8, 2 db 10 * 8 + 4, 10 * 8, 3 IntroMenuChooseGender: xor a ld [wCurPartySpecies], a farcall DrawBothIntroFrontPics ld b, SCGB_INTRO_BOTH_PLAYER_PALS call GetSGBLayout call Intro_RotatePalettesLeftFrontpic ld hl, OakText6 call PrintText .gender_loop ld hl, OakTextBoyOrGirl call PrintText ; time for hacky bullshit :3 ld a, "▼" hlcoord 5, 2 ld [hl], a ld a, " " hlcoord 13, 2 ld [hl], a xor a ld [wMenuCursorX], a call DelayFrame call .get_input ld a, [wMenuCursorX] and a ld [wPlayerGender], a jr z, .ask_boy ld hl, OakTextGirl jr .ask_gender .ask_boy ld hl, OakTextBoy .ask_gender call PrintText call YesNoBox jr c, .gender_loop ret .get_input call JoyTextDelay ldh a, [hJoypadPressed] bit A_BUTTON_F, a ret nz and D_LEFT | D_RIGHT call nz, .swap_cursor call DelayFrame jr .get_input .swap_cursor ld a, " " hlcoord 5, 2 ld [hl], a hlcoord 13, 2 ld [hl], a ld a, [wMenuCursorX] xor 1 ld [wMenuCursorX], a and a jr z, .cursor_male hlcoord 13, 2 jr .cursor .cursor_male hlcoord 5, 2 .cursor ld a, "▼" ld [hl], a ret CrystalIntroSequence: callfar Copyright_GFPresents jr c, StartTitleScreen farcall CrystalIntro StartTitleScreen: ldh a, [rSVBK] push af ld a, BANK(wBGPals1) ldh [rSVBK], a call .TitleScreen call DelayFrame .loop call RunTitleScreen jr nc, .loop call ClearSprites call ClearBGPalettes pop af ldh [rSVBK], a ld hl, rLCDC res rLCDC_SPRITE_SIZE, [hl] ; 8x8 call ClearScreen call WaitBGMap2 xor a ldh [hLCDCPointer], a ldh [hSCX], a ldh [hSCY], a ld a, $7 ldh [hWX], a ld a, $90 ldh [hWY], a ld b, SCGB_DIPLOMA call GetSGBLayout call UpdateTimePals ld a, [wIntroSceneFrameCounter] cp $5 jr c, .ok xor a .ok ld e, a ld d, 0 ld hl, .dw add hl, de add hl, de ld a, [hli] ld h, [hl] ld l, a jp hl .dw dw _MainMenu dw DeleteSaveData dw CrystalIntroSequence dw CrystalIntroSequence dw ResetClock .TitleScreen: farcall _TitleScreen ret RunTitleScreen: ld a, [wJumptableIndex] bit 7, a jr nz, .done_title call TitleScreenScene farcall SuicuneFrameIterator call DelayFrame and a ret .done_title scf ret Unreferenced_Function6292: ldh a, [hVBlankCounter] and $7 ret nz ld hl, wLYOverrides + $5f ld a, [hl] dec a ld bc, 2 * SCREEN_WIDTH call ByteFill ret TitleScreenScene: ld e, a ld d, 0 ld hl, .scenes add hl, de add hl, de ld a, [hli] ld h, [hl] ld l, a jp hl .scenes dw TitleScreenEntrance dw TitleScreenTimer dw TitleScreenMain dw TitleScreenEnd .Unreferenced_NextScene: ld hl, wJumptableIndex inc [hl] ret TitleScreenEntrance: ; Animate the logo: ; Move each line by 4 pixels until our count hits 0. ldh a, [hSCX] and a jr z, .done sub 4 ldh [hSCX], a ; Lay out a base (all lines scrolling together). ld e, a ld hl, wLYOverrides ld bc, 8 * 10 ; logo height call ByteFill ; Reversed signage for every other line's position. ; This is responsible for the interlaced effect. ld a, e xor $ff inc a ld b, 8 * 10 / 2 ; logo height / 2 ld hl, wLYOverrides + 1 .loop ld [hli], a inc hl dec b jr nz, .loop farcall AnimateTitleCrystal ret .done ; Next scene ld hl, wJumptableIndex inc [hl] xor a ldh [hLCDCPointer], a ; Play the title screen music. ld de, MUSIC_TITLE call PlayMusic ld a, $88 ldh [hWY], a ret TitleScreenTimer: ; Next scene ld hl, wJumptableIndex inc [hl] ; Start a timer ld hl, wTitleScreenTimer ld de, 73 * 60 + 36 ld [hl], e inc hl ld [hl], d ret TitleScreenMain: ; Run the timer down. ld hl, wTitleScreenTimer ld e, [hl] inc hl ld d, [hl] ld a, e or d jr z, .end dec de ld [hl], d dec hl ld [hl], e ; Save data can be deleted by pressing Up + B + Select. call GetJoypad ld hl, hJoyDown ld a, [hl] and D_UP + B_BUTTON + SELECT cp D_UP + B_BUTTON + SELECT jr z, .delete_save_data ; To bring up the clock reset dialog: ; Hold Down + B + Select to initiate the sequence. ldh a, [hClockResetTrigger] cp $34 jr z, .check_clock_reset ld a, [hl] and D_DOWN + B_BUTTON + SELECT cp D_DOWN + B_BUTTON + SELECT jr nz, .check_start ld a, $34 ldh [hClockResetTrigger], a jr .check_start ; Keep Select pressed, and hold Left + Up. ; Then let go of Select. .check_clock_reset bit SELECT_F, [hl] jr nz, .check_start xor a ldh [hClockResetTrigger], a ld a, [hl] and D_LEFT + D_UP cp D_LEFT + D_UP jr z, .clock_reset ; Press Start or A to start the game. .check_start ld a, [hl] and START | A_BUTTON jr nz, .incave ret .incave ld a, 0 jr .done .delete_save_data ld a, 1 .done ld [wIntroSceneFrameCounter], a ; Return to the intro sequence. ld hl, wJumptableIndex set 7, [hl] ret .end ; Next scene ld hl, wJumptableIndex inc [hl] ; Fade out the title screen music xor a ld [wMusicFadeID], a ld [wMusicFadeID + 1], a ld hl, wMusicFade ld [hl], 8 ; 1 second ld hl, wTitleScreenTimer inc [hl] ret .clock_reset ld a, 4 ld [wIntroSceneFrameCounter], a ; Return to the intro sequence. ld hl, wJumptableIndex set 7, [hl] ret TitleScreenEnd: ; Wait until the music is done fading. ld hl, wTitleScreenTimer inc [hl] ld a, [wMusicFade] and a ret nz ld a, 2 ld [wIntroSceneFrameCounter], a ; Back to the intro. ld hl, wJumptableIndex set 7, [hl] ret DeleteSaveData: farcall _DeleteSaveData jp Init ResetClock: farcall _ResetClock jp Init Unreferenced_Function639b: ; If bit 0 or 1 of [wTitleScreenTimer] is set, we don't need to be here. ld a, [wTitleScreenTimer] and %00000011 ret nz ld bc, wSpriteAnim10 ld hl, SPRITEANIMSTRUCT_FRAME add hl, bc ; over-the-top compicated way to load wc3ae into hl ld l, [hl] ld h, 0 add hl, hl add hl, hl ld de, .Data63ca add hl, de ; If bit 2 of [wTitleScreenTimer] is set, get the second dw; else, get the first dw ld a, [wTitleScreenTimer] and %00000100 srl a srl a ld e, a ld d, 0 add hl, de add hl, de ld a, [hli] and a ret z ld e, a ld d, [hl] ld a, SPRITE_ANIM_INDEX_GS_TITLE_TRAIL call _InitSpriteAnimStruct ret .Data63ca: ; frame 0 y, x; frame 1 y, x db 11 * 8 + 4, 10 * 8, 0 * 8, 0 * 8 db 11 * 8 + 4, 13 * 8, 11 * 8 + 4, 11 * 8 db 11 * 8 + 4, 13 * 8, 11 * 8 + 4, 15 * 8 db 11 * 8 + 4, 17 * 8, 11 * 8 + 4, 15 * 8 db 0 * 8, 0 * 8, 11 * 8 + 4, 15 * 8 db 0 * 8, 0 * 8, 11 * 8 + 4, 11 * 8 Copyright: call ClearTileMap call LoadFontsExtra ld de, CopyrightGFX ld hl, vTiles2 tile $60 lb bc, BANK(CopyrightGFX), 29 call Request2bpp hlcoord 2, 7 ld de, CopyrightString jp PlaceString CopyrightString: ; ©1995-2001 Nintendo db $60, $61, $62, $63, $64, $65, $66 db $67, $68, $69, $6a, $6b, $6c ; ©1995-2001 Creatures inc. next $60, $61, $62, $63, $64, $65, $66 db $6d, $6e, $6f, $70, $71, $72, $7a, $7b, $7c ; ©1995-2001 GAME FREAK inc. next $60, $61, $62, $63, $64, $65, $66 db $73, $74, $75, $76, $77, $78, $79, $7a, $7b, $7c db "@" GameInit:: farcall TryLoadSaveData call ClearWindowData call ClearBGPalettes call ClearTileMap ld a, HIGH(vBGMap0) ldh [hBGMapAddress + 1], a xor a ; LOW(vBGMap0) ldh [hBGMapAddress], a ldh [hJoyDown], a ldh [hSCX], a ldh [hSCY], a ld a, $90 ldh [hWY], a call WaitBGMap jp CrystalIntroSequence PUSHS SECTION "Intro Sandgem GFX", ROMX IntroSandgemGFX: INCBIN "gfx/intro/sandgem.2bpp" .end POPS IntroSandgemTilemap: INCBIN "gfx/intro/sandgem.tilemap" IntroSandgemAttrmap: INCBIN "gfx/intro/sandgem.attrmap" INTRO_SANDGEM_TILE_CT EQU (IntroSandgemGFX.end - IntroSandgemGFX) / 16 IntroSandgemScene: call ClearBGPalettes call ClearTileMap call ClearSprites call DisableLCD IF INTRO_SANDGEM_TILE_CT < $80 ld de, IntroSandgemGFX ld b, BANK(IntroSandgemGFX) ld hl, vTiles2 ld c, INTRO_SANDGEM_TILE_CT call Get2bpp ELSE ld de, IntroSandgemGFX ld b, BANK(IntroSandgemGFX) ld hl, vTiles2 ld c, $80 call Get2bpp IF INTRO_SANDGEM_TILE_CT < $100 ld de, IntroSandgemGFX + $80 tiles ld b, BANK(IntroSandgemGFX) ld hl, vTiles1 ld c, INTRO_SANDGEM_TILE_CT - $80 call Get2bpp ELSE ld de, IntroSandgemGFX + $80 ld b, BANK(IntroSandgemGFX) ld hl, vTiles1 ld c, $80 call Get2bpp ld a, BANK(vTiles5) ldh [rVBK], a ld de, IntroSandgemGFX + $100 tiles ld b, BANK(IntroSandgemGFX) ld hl, vTiles5 ld c, INTRO_SANDGEM_TILE_CT - $100 call Get2bpp xor a ldh [rVBK], a ENDC ENDC decoord 0, 0 ld bc, SCREEN_WIDTH * (SCREEN_HEIGHT - 6) ld hl, IntroSandgemTilemap call CopyBytes decoord 0, 0, wAttrMap ld bc, SCREEN_WIDTH * (SCREEN_HEIGHT - 6) ld hl, IntroSandgemAttrmap call CopyBytes call EnableLCD call WaitBGMap2 ld b, SCGB_INTRO_SANDGEM call GetSGBLayout call SetPalettes call DelayFrame ld de, MUSIC_POKEMON_CHANNEL call PlayMusic ld hl, IntroSandgemText call PrintText farcall FadeOutPalettes ret
STDIN equ 0 STDOUT equ 1 SYS_EXIT equ 1 SYS_READ equ 3 SYS_WRITE equ 4 section .data msg db "The sum is: ", 0xA, 0xD len equ $- msg section .bss res resb 1 section .text global main main: mov ecx, '4' sub ecx, '0' mov edx, '5' sub edx, '0' call sum ;call sum procedure mov [res], eax mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, msg mov edx, len int 0x80 nwln mov eax, SYS_WRITE mov ebx, STDOUT mov ecx, res mov edx, 1 int 0x80 mov eax, SYS_EXIT int 0x80 sum: mov eax, ecx add eax, edx add eax, '0' ret ;back to where the procedure is called
_cat: file format elf32-i386 Disassembly of section .text: 00000000 <cat>: char buf[512]; void cat(int fd) { 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 ec 28 sub $0x28,%esp int n; while((n = read(fd, buf, sizeof(buf))) > 0) 6: eb 1b jmp 23 <cat+0x23> write(1, buf, n); 8: 8b 45 f4 mov -0xc(%ebp),%eax b: 89 44 24 08 mov %eax,0x8(%esp) f: c7 44 24 04 20 0d 00 movl $0xd20,0x4(%esp) 16: 00 17: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1e: e8 85 03 00 00 call 3a8 <write> void cat(int fd) { int n; while((n = read(fd, buf, sizeof(buf))) > 0) 23: c7 44 24 08 00 02 00 movl $0x200,0x8(%esp) 2a: 00 2b: c7 44 24 04 20 0d 00 movl $0xd20,0x4(%esp) 32: 00 33: 8b 45 08 mov 0x8(%ebp),%eax 36: 89 04 24 mov %eax,(%esp) 39: e8 62 03 00 00 call 3a0 <read> 3e: 89 45 f4 mov %eax,-0xc(%ebp) 41: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 45: 7f c1 jg 8 <cat+0x8> write(1, buf, n); if(n < 0){ 47: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 4b: 79 19 jns 66 <cat+0x66> printf(1, "cat: read error\n"); 4d: c7 44 24 04 8e 09 00 movl $0x98e,0x4(%esp) 54: 00 55: c7 04 24 01 00 00 00 movl $0x1,(%esp) 5c: e8 b7 04 00 00 call 518 <printf> exit(); 61: e8 22 03 00 00 call 388 <exit> } } 66: c9 leave 67: c3 ret 00000068 <main>: int main(int argc, char *argv[]) { 68: 55 push %ebp 69: 89 e5 mov %esp,%ebp 6b: 83 e4 f0 and $0xfffffff0,%esp 6e: 83 ec 20 sub $0x20,%esp int fd, i; if(argc <= 1){ 71: 83 7d 08 01 cmpl $0x1,0x8(%ebp) 75: 7f 11 jg 88 <main+0x20> cat(0); 77: c7 04 24 00 00 00 00 movl $0x0,(%esp) 7e: e8 7d ff ff ff call 0 <cat> exit(); 83: e8 00 03 00 00 call 388 <exit> } for(i = 1; i < argc; i++){ 88: c7 44 24 1c 01 00 00 movl $0x1,0x1c(%esp) 8f: 00 90: eb 79 jmp 10b <main+0xa3> if((fd = open(argv[i], 0)) < 0){ 92: 8b 44 24 1c mov 0x1c(%esp),%eax 96: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx 9d: 8b 45 0c mov 0xc(%ebp),%eax a0: 01 d0 add %edx,%eax a2: 8b 00 mov (%eax),%eax a4: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) ab: 00 ac: 89 04 24 mov %eax,(%esp) af: e8 14 03 00 00 call 3c8 <open> b4: 89 44 24 18 mov %eax,0x18(%esp) b8: 83 7c 24 18 00 cmpl $0x0,0x18(%esp) bd: 79 2f jns ee <main+0x86> printf(1, "cat: cannot open %s\n", argv[i]); bf: 8b 44 24 1c mov 0x1c(%esp),%eax c3: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx ca: 8b 45 0c mov 0xc(%ebp),%eax cd: 01 d0 add %edx,%eax cf: 8b 00 mov (%eax),%eax d1: 89 44 24 08 mov %eax,0x8(%esp) d5: c7 44 24 04 9f 09 00 movl $0x99f,0x4(%esp) dc: 00 dd: c7 04 24 01 00 00 00 movl $0x1,(%esp) e4: e8 2f 04 00 00 call 518 <printf> exit(); e9: e8 9a 02 00 00 call 388 <exit> } cat(fd); ee: 8b 44 24 18 mov 0x18(%esp),%eax f2: 89 04 24 mov %eax,(%esp) f5: e8 06 ff ff ff call 0 <cat> close(fd); fa: 8b 44 24 18 mov 0x18(%esp),%eax fe: 89 04 24 mov %eax,(%esp) 101: e8 aa 02 00 00 call 3b0 <close> if(argc <= 1){ cat(0); exit(); } for(i = 1; i < argc; i++){ 106: 83 44 24 1c 01 addl $0x1,0x1c(%esp) 10b: 8b 44 24 1c mov 0x1c(%esp),%eax 10f: 3b 45 08 cmp 0x8(%ebp),%eax 112: 0f 8c 7a ff ff ff jl 92 <main+0x2a> exit(); } cat(fd); close(fd); } exit(); 118: e8 6b 02 00 00 call 388 <exit> 11d: 66 90 xchg %ax,%ax 11f: 90 nop 00000120 <stosb>: "cc"); } static inline void stosb(void *addr, int data, int cnt) { 120: 55 push %ebp 121: 89 e5 mov %esp,%ebp 123: 57 push %edi 124: 53 push %ebx asm volatile("cld; rep stosb" : 125: 8b 4d 08 mov 0x8(%ebp),%ecx 128: 8b 55 10 mov 0x10(%ebp),%edx 12b: 8b 45 0c mov 0xc(%ebp),%eax 12e: 89 cb mov %ecx,%ebx 130: 89 df mov %ebx,%edi 132: 89 d1 mov %edx,%ecx 134: fc cld 135: f3 aa rep stos %al,%es:(%edi) 137: 89 ca mov %ecx,%edx 139: 89 fb mov %edi,%ebx 13b: 89 5d 08 mov %ebx,0x8(%ebp) 13e: 89 55 10 mov %edx,0x10(%ebp) "=D" (addr), "=c" (cnt) : "0" (addr), "1" (cnt), "a" (data) : "memory", "cc"); } 141: 5b pop %ebx 142: 5f pop %edi 143: 5d pop %ebp 144: c3 ret 00000145 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, char *t) { 145: 55 push %ebp 146: 89 e5 mov %esp,%ebp 148: 83 ec 10 sub $0x10,%esp char *os; os = s; 14b: 8b 45 08 mov 0x8(%ebp),%eax 14e: 89 45 fc mov %eax,-0x4(%ebp) while((*s++ = *t++) != 0) 151: 90 nop 152: 8b 45 08 mov 0x8(%ebp),%eax 155: 8d 50 01 lea 0x1(%eax),%edx 158: 89 55 08 mov %edx,0x8(%ebp) 15b: 8b 55 0c mov 0xc(%ebp),%edx 15e: 8d 4a 01 lea 0x1(%edx),%ecx 161: 89 4d 0c mov %ecx,0xc(%ebp) 164: 0f b6 12 movzbl (%edx),%edx 167: 88 10 mov %dl,(%eax) 169: 0f b6 00 movzbl (%eax),%eax 16c: 84 c0 test %al,%al 16e: 75 e2 jne 152 <strcpy+0xd> ; return os; 170: 8b 45 fc mov -0x4(%ebp),%eax } 173: c9 leave 174: c3 ret 00000175 <strcmp>: int strcmp(const char *p, const char *q) { 175: 55 push %ebp 176: 89 e5 mov %esp,%ebp while(*p && *p == *q) 178: eb 08 jmp 182 <strcmp+0xd> p++, q++; 17a: 83 45 08 01 addl $0x1,0x8(%ebp) 17e: 83 45 0c 01 addl $0x1,0xc(%ebp) } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 182: 8b 45 08 mov 0x8(%ebp),%eax 185: 0f b6 00 movzbl (%eax),%eax 188: 84 c0 test %al,%al 18a: 74 10 je 19c <strcmp+0x27> 18c: 8b 45 08 mov 0x8(%ebp),%eax 18f: 0f b6 10 movzbl (%eax),%edx 192: 8b 45 0c mov 0xc(%ebp),%eax 195: 0f b6 00 movzbl (%eax),%eax 198: 38 c2 cmp %al,%dl 19a: 74 de je 17a <strcmp+0x5> p++, q++; return (uchar)*p - (uchar)*q; 19c: 8b 45 08 mov 0x8(%ebp),%eax 19f: 0f b6 00 movzbl (%eax),%eax 1a2: 0f b6 d0 movzbl %al,%edx 1a5: 8b 45 0c mov 0xc(%ebp),%eax 1a8: 0f b6 00 movzbl (%eax),%eax 1ab: 0f b6 c0 movzbl %al,%eax 1ae: 29 c2 sub %eax,%edx 1b0: 89 d0 mov %edx,%eax } 1b2: 5d pop %ebp 1b3: c3 ret 000001b4 <strlen>: uint strlen(char *s) { 1b4: 55 push %ebp 1b5: 89 e5 mov %esp,%ebp 1b7: 83 ec 10 sub $0x10,%esp int n; for(n = 0; s[n]; n++) 1ba: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) 1c1: eb 04 jmp 1c7 <strlen+0x13> 1c3: 83 45 fc 01 addl $0x1,-0x4(%ebp) 1c7: 8b 55 fc mov -0x4(%ebp),%edx 1ca: 8b 45 08 mov 0x8(%ebp),%eax 1cd: 01 d0 add %edx,%eax 1cf: 0f b6 00 movzbl (%eax),%eax 1d2: 84 c0 test %al,%al 1d4: 75 ed jne 1c3 <strlen+0xf> ; return n; 1d6: 8b 45 fc mov -0x4(%ebp),%eax } 1d9: c9 leave 1da: c3 ret 000001db <memset>: void* memset(void *dst, int c, uint n) { 1db: 55 push %ebp 1dc: 89 e5 mov %esp,%ebp 1de: 83 ec 0c sub $0xc,%esp stosb(dst, c, n); 1e1: 8b 45 10 mov 0x10(%ebp),%eax 1e4: 89 44 24 08 mov %eax,0x8(%esp) 1e8: 8b 45 0c mov 0xc(%ebp),%eax 1eb: 89 44 24 04 mov %eax,0x4(%esp) 1ef: 8b 45 08 mov 0x8(%ebp),%eax 1f2: 89 04 24 mov %eax,(%esp) 1f5: e8 26 ff ff ff call 120 <stosb> return dst; 1fa: 8b 45 08 mov 0x8(%ebp),%eax } 1fd: c9 leave 1fe: c3 ret 000001ff <strchr>: char* strchr(const char *s, char c) { 1ff: 55 push %ebp 200: 89 e5 mov %esp,%ebp 202: 83 ec 04 sub $0x4,%esp 205: 8b 45 0c mov 0xc(%ebp),%eax 208: 88 45 fc mov %al,-0x4(%ebp) for(; *s; s++) 20b: eb 14 jmp 221 <strchr+0x22> if(*s == c) 20d: 8b 45 08 mov 0x8(%ebp),%eax 210: 0f b6 00 movzbl (%eax),%eax 213: 3a 45 fc cmp -0x4(%ebp),%al 216: 75 05 jne 21d <strchr+0x1e> return (char*)s; 218: 8b 45 08 mov 0x8(%ebp),%eax 21b: eb 13 jmp 230 <strchr+0x31> } char* strchr(const char *s, char c) { for(; *s; s++) 21d: 83 45 08 01 addl $0x1,0x8(%ebp) 221: 8b 45 08 mov 0x8(%ebp),%eax 224: 0f b6 00 movzbl (%eax),%eax 227: 84 c0 test %al,%al 229: 75 e2 jne 20d <strchr+0xe> if(*s == c) return (char*)s; return 0; 22b: b8 00 00 00 00 mov $0x0,%eax } 230: c9 leave 231: c3 ret 00000232 <gets>: char* gets(char *buf, int max) { 232: 55 push %ebp 233: 89 e5 mov %esp,%ebp 235: 83 ec 28 sub $0x28,%esp int i, cc; char c; for(i=0; i+1 < max; ){ 238: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp) 23f: eb 4c jmp 28d <gets+0x5b> cc = read(0, &c, 1); 241: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 248: 00 249: 8d 45 ef lea -0x11(%ebp),%eax 24c: 89 44 24 04 mov %eax,0x4(%esp) 250: c7 04 24 00 00 00 00 movl $0x0,(%esp) 257: e8 44 01 00 00 call 3a0 <read> 25c: 89 45 f0 mov %eax,-0x10(%ebp) if(cc < 1) 25f: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 263: 7f 02 jg 267 <gets+0x35> break; 265: eb 31 jmp 298 <gets+0x66> buf[i++] = c; 267: 8b 45 f4 mov -0xc(%ebp),%eax 26a: 8d 50 01 lea 0x1(%eax),%edx 26d: 89 55 f4 mov %edx,-0xc(%ebp) 270: 89 c2 mov %eax,%edx 272: 8b 45 08 mov 0x8(%ebp),%eax 275: 01 c2 add %eax,%edx 277: 0f b6 45 ef movzbl -0x11(%ebp),%eax 27b: 88 02 mov %al,(%edx) if(c == '\n' || c == '\r') 27d: 0f b6 45 ef movzbl -0x11(%ebp),%eax 281: 3c 0a cmp $0xa,%al 283: 74 13 je 298 <gets+0x66> 285: 0f b6 45 ef movzbl -0x11(%ebp),%eax 289: 3c 0d cmp $0xd,%al 28b: 74 0b je 298 <gets+0x66> gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 28d: 8b 45 f4 mov -0xc(%ebp),%eax 290: 83 c0 01 add $0x1,%eax 293: 3b 45 0c cmp 0xc(%ebp),%eax 296: 7c a9 jl 241 <gets+0xf> break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 298: 8b 55 f4 mov -0xc(%ebp),%edx 29b: 8b 45 08 mov 0x8(%ebp),%eax 29e: 01 d0 add %edx,%eax 2a0: c6 00 00 movb $0x0,(%eax) return buf; 2a3: 8b 45 08 mov 0x8(%ebp),%eax } 2a6: c9 leave 2a7: c3 ret 000002a8 <stat>: int stat(char *n, struct stat *st) { 2a8: 55 push %ebp 2a9: 89 e5 mov %esp,%ebp 2ab: 83 ec 28 sub $0x28,%esp int fd; int r; fd = open(n, O_RDONLY); 2ae: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 2b5: 00 2b6: 8b 45 08 mov 0x8(%ebp),%eax 2b9: 89 04 24 mov %eax,(%esp) 2bc: e8 07 01 00 00 call 3c8 <open> 2c1: 89 45 f4 mov %eax,-0xc(%ebp) if(fd < 0) 2c4: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 2c8: 79 07 jns 2d1 <stat+0x29> return -1; 2ca: b8 ff ff ff ff mov $0xffffffff,%eax 2cf: eb 23 jmp 2f4 <stat+0x4c> r = fstat(fd, st); 2d1: 8b 45 0c mov 0xc(%ebp),%eax 2d4: 89 44 24 04 mov %eax,0x4(%esp) 2d8: 8b 45 f4 mov -0xc(%ebp),%eax 2db: 89 04 24 mov %eax,(%esp) 2de: e8 fd 00 00 00 call 3e0 <fstat> 2e3: 89 45 f0 mov %eax,-0x10(%ebp) close(fd); 2e6: 8b 45 f4 mov -0xc(%ebp),%eax 2e9: 89 04 24 mov %eax,(%esp) 2ec: e8 bf 00 00 00 call 3b0 <close> return r; 2f1: 8b 45 f0 mov -0x10(%ebp),%eax } 2f4: c9 leave 2f5: c3 ret 000002f6 <atoi>: int atoi(const char *s) { 2f6: 55 push %ebp 2f7: 89 e5 mov %esp,%ebp 2f9: 83 ec 10 sub $0x10,%esp int n; n = 0; 2fc: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) while('0' <= *s && *s <= '9') 303: eb 25 jmp 32a <atoi+0x34> n = n*10 + *s++ - '0'; 305: 8b 55 fc mov -0x4(%ebp),%edx 308: 89 d0 mov %edx,%eax 30a: c1 e0 02 shl $0x2,%eax 30d: 01 d0 add %edx,%eax 30f: 01 c0 add %eax,%eax 311: 89 c1 mov %eax,%ecx 313: 8b 45 08 mov 0x8(%ebp),%eax 316: 8d 50 01 lea 0x1(%eax),%edx 319: 89 55 08 mov %edx,0x8(%ebp) 31c: 0f b6 00 movzbl (%eax),%eax 31f: 0f be c0 movsbl %al,%eax 322: 01 c8 add %ecx,%eax 324: 83 e8 30 sub $0x30,%eax 327: 89 45 fc mov %eax,-0x4(%ebp) atoi(const char *s) { int n; n = 0; while('0' <= *s && *s <= '9') 32a: 8b 45 08 mov 0x8(%ebp),%eax 32d: 0f b6 00 movzbl (%eax),%eax 330: 3c 2f cmp $0x2f,%al 332: 7e 0a jle 33e <atoi+0x48> 334: 8b 45 08 mov 0x8(%ebp),%eax 337: 0f b6 00 movzbl (%eax),%eax 33a: 3c 39 cmp $0x39,%al 33c: 7e c7 jle 305 <atoi+0xf> n = n*10 + *s++ - '0'; return n; 33e: 8b 45 fc mov -0x4(%ebp),%eax } 341: c9 leave 342: c3 ret 00000343 <memmove>: void* memmove(void *vdst, void *vsrc, int n) { 343: 55 push %ebp 344: 89 e5 mov %esp,%ebp 346: 83 ec 10 sub $0x10,%esp char *dst, *src; dst = vdst; 349: 8b 45 08 mov 0x8(%ebp),%eax 34c: 89 45 fc mov %eax,-0x4(%ebp) src = vsrc; 34f: 8b 45 0c mov 0xc(%ebp),%eax 352: 89 45 f8 mov %eax,-0x8(%ebp) while(n-- > 0) 355: eb 17 jmp 36e <memmove+0x2b> *dst++ = *src++; 357: 8b 45 fc mov -0x4(%ebp),%eax 35a: 8d 50 01 lea 0x1(%eax),%edx 35d: 89 55 fc mov %edx,-0x4(%ebp) 360: 8b 55 f8 mov -0x8(%ebp),%edx 363: 8d 4a 01 lea 0x1(%edx),%ecx 366: 89 4d f8 mov %ecx,-0x8(%ebp) 369: 0f b6 12 movzbl (%edx),%edx 36c: 88 10 mov %dl,(%eax) { char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 36e: 8b 45 10 mov 0x10(%ebp),%eax 371: 8d 50 ff lea -0x1(%eax),%edx 374: 89 55 10 mov %edx,0x10(%ebp) 377: 85 c0 test %eax,%eax 379: 7f dc jg 357 <memmove+0x14> *dst++ = *src++; return vdst; 37b: 8b 45 08 mov 0x8(%ebp),%eax } 37e: c9 leave 37f: c3 ret 00000380 <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 380: b8 01 00 00 00 mov $0x1,%eax 385: cd 40 int $0x40 387: c3 ret 00000388 <exit>: SYSCALL(exit) 388: b8 02 00 00 00 mov $0x2,%eax 38d: cd 40 int $0x40 38f: c3 ret 00000390 <wait>: SYSCALL(wait) 390: b8 03 00 00 00 mov $0x3,%eax 395: cd 40 int $0x40 397: c3 ret 00000398 <pipe>: SYSCALL(pipe) 398: b8 04 00 00 00 mov $0x4,%eax 39d: cd 40 int $0x40 39f: c3 ret 000003a0 <read>: SYSCALL(read) 3a0: b8 05 00 00 00 mov $0x5,%eax 3a5: cd 40 int $0x40 3a7: c3 ret 000003a8 <write>: SYSCALL(write) 3a8: b8 10 00 00 00 mov $0x10,%eax 3ad: cd 40 int $0x40 3af: c3 ret 000003b0 <close>: SYSCALL(close) 3b0: b8 15 00 00 00 mov $0x15,%eax 3b5: cd 40 int $0x40 3b7: c3 ret 000003b8 <kill>: SYSCALL(kill) 3b8: b8 06 00 00 00 mov $0x6,%eax 3bd: cd 40 int $0x40 3bf: c3 ret 000003c0 <exec>: SYSCALL(exec) 3c0: b8 07 00 00 00 mov $0x7,%eax 3c5: cd 40 int $0x40 3c7: c3 ret 000003c8 <open>: SYSCALL(open) 3c8: b8 0f 00 00 00 mov $0xf,%eax 3cd: cd 40 int $0x40 3cf: c3 ret 000003d0 <mknod>: SYSCALL(mknod) 3d0: b8 11 00 00 00 mov $0x11,%eax 3d5: cd 40 int $0x40 3d7: c3 ret 000003d8 <unlink>: SYSCALL(unlink) 3d8: b8 12 00 00 00 mov $0x12,%eax 3dd: cd 40 int $0x40 3df: c3 ret 000003e0 <fstat>: SYSCALL(fstat) 3e0: b8 08 00 00 00 mov $0x8,%eax 3e5: cd 40 int $0x40 3e7: c3 ret 000003e8 <link>: SYSCALL(link) 3e8: b8 13 00 00 00 mov $0x13,%eax 3ed: cd 40 int $0x40 3ef: c3 ret 000003f0 <mkdir>: SYSCALL(mkdir) 3f0: b8 14 00 00 00 mov $0x14,%eax 3f5: cd 40 int $0x40 3f7: c3 ret 000003f8 <chdir>: SYSCALL(chdir) 3f8: b8 09 00 00 00 mov $0x9,%eax 3fd: cd 40 int $0x40 3ff: c3 ret 00000400 <dup>: SYSCALL(dup) 400: b8 0a 00 00 00 mov $0xa,%eax 405: cd 40 int $0x40 407: c3 ret 00000408 <getpid>: SYSCALL(getpid) 408: b8 0b 00 00 00 mov $0xb,%eax 40d: cd 40 int $0x40 40f: c3 ret 00000410 <sbrk>: SYSCALL(sbrk) 410: b8 0c 00 00 00 mov $0xc,%eax 415: cd 40 int $0x40 417: c3 ret 00000418 <sleep>: SYSCALL(sleep) 418: b8 0d 00 00 00 mov $0xd,%eax 41d: cd 40 int $0x40 41f: c3 ret 00000420 <uptime>: SYSCALL(uptime) 420: b8 0e 00 00 00 mov $0xe,%eax 425: cd 40 int $0x40 427: c3 ret 00000428 <clone>: SYSCALL(clone) 428: b8 16 00 00 00 mov $0x16,%eax 42d: cd 40 int $0x40 42f: c3 ret 00000430 <join>: 430: b8 17 00 00 00 mov $0x17,%eax 435: cd 40 int $0x40 437: c3 ret 00000438 <putc>: #include "stat.h" #include "user.h" static void putc(int fd, char c) { 438: 55 push %ebp 439: 89 e5 mov %esp,%ebp 43b: 83 ec 18 sub $0x18,%esp 43e: 8b 45 0c mov 0xc(%ebp),%eax 441: 88 45 f4 mov %al,-0xc(%ebp) write(fd, &c, 1); 444: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 44b: 00 44c: 8d 45 f4 lea -0xc(%ebp),%eax 44f: 89 44 24 04 mov %eax,0x4(%esp) 453: 8b 45 08 mov 0x8(%ebp),%eax 456: 89 04 24 mov %eax,(%esp) 459: e8 4a ff ff ff call 3a8 <write> } 45e: c9 leave 45f: c3 ret 00000460 <printint>: static void printint(int fd, int xx, int base, int sgn) { 460: 55 push %ebp 461: 89 e5 mov %esp,%ebp 463: 56 push %esi 464: 53 push %ebx 465: 83 ec 30 sub $0x30,%esp static char digits[] = "0123456789ABCDEF"; char buf[16]; int i, neg; uint x; neg = 0; 468: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) if(sgn && xx < 0){ 46f: 83 7d 14 00 cmpl $0x0,0x14(%ebp) 473: 74 17 je 48c <printint+0x2c> 475: 83 7d 0c 00 cmpl $0x0,0xc(%ebp) 479: 79 11 jns 48c <printint+0x2c> neg = 1; 47b: c7 45 f0 01 00 00 00 movl $0x1,-0x10(%ebp) x = -xx; 482: 8b 45 0c mov 0xc(%ebp),%eax 485: f7 d8 neg %eax 487: 89 45 ec mov %eax,-0x14(%ebp) 48a: eb 06 jmp 492 <printint+0x32> } else { x = xx; 48c: 8b 45 0c mov 0xc(%ebp),%eax 48f: 89 45 ec mov %eax,-0x14(%ebp) } i = 0; 492: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp) do{ buf[i++] = digits[x % base]; 499: 8b 4d f4 mov -0xc(%ebp),%ecx 49c: 8d 41 01 lea 0x1(%ecx),%eax 49f: 89 45 f4 mov %eax,-0xc(%ebp) 4a2: 8b 5d 10 mov 0x10(%ebp),%ebx 4a5: 8b 45 ec mov -0x14(%ebp),%eax 4a8: ba 00 00 00 00 mov $0x0,%edx 4ad: f7 f3 div %ebx 4af: 89 d0 mov %edx,%eax 4b1: 0f b6 80 e0 0c 00 00 movzbl 0xce0(%eax),%eax 4b8: 88 44 0d dc mov %al,-0x24(%ebp,%ecx,1) }while((x /= base) != 0); 4bc: 8b 75 10 mov 0x10(%ebp),%esi 4bf: 8b 45 ec mov -0x14(%ebp),%eax 4c2: ba 00 00 00 00 mov $0x0,%edx 4c7: f7 f6 div %esi 4c9: 89 45 ec mov %eax,-0x14(%ebp) 4cc: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 4d0: 75 c7 jne 499 <printint+0x39> if(neg) 4d2: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 4d6: 74 10 je 4e8 <printint+0x88> buf[i++] = '-'; 4d8: 8b 45 f4 mov -0xc(%ebp),%eax 4db: 8d 50 01 lea 0x1(%eax),%edx 4de: 89 55 f4 mov %edx,-0xc(%ebp) 4e1: c6 44 05 dc 2d movb $0x2d,-0x24(%ebp,%eax,1) while(--i >= 0) 4e6: eb 1f jmp 507 <printint+0xa7> 4e8: eb 1d jmp 507 <printint+0xa7> putc(fd, buf[i]); 4ea: 8d 55 dc lea -0x24(%ebp),%edx 4ed: 8b 45 f4 mov -0xc(%ebp),%eax 4f0: 01 d0 add %edx,%eax 4f2: 0f b6 00 movzbl (%eax),%eax 4f5: 0f be c0 movsbl %al,%eax 4f8: 89 44 24 04 mov %eax,0x4(%esp) 4fc: 8b 45 08 mov 0x8(%ebp),%eax 4ff: 89 04 24 mov %eax,(%esp) 502: e8 31 ff ff ff call 438 <putc> buf[i++] = digits[x % base]; }while((x /= base) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) 507: 83 6d f4 01 subl $0x1,-0xc(%ebp) 50b: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 50f: 79 d9 jns 4ea <printint+0x8a> putc(fd, buf[i]); } 511: 83 c4 30 add $0x30,%esp 514: 5b pop %ebx 515: 5e pop %esi 516: 5d pop %ebp 517: c3 ret 00000518 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 518: 55 push %ebp 519: 89 e5 mov %esp,%ebp 51b: 83 ec 38 sub $0x38,%esp char *s; int c, i, state; uint *ap; state = 0; 51e: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp) ap = (uint*)(void*)&fmt + 1; 525: 8d 45 0c lea 0xc(%ebp),%eax 528: 83 c0 04 add $0x4,%eax 52b: 89 45 e8 mov %eax,-0x18(%ebp) for(i = 0; fmt[i]; i++){ 52e: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) 535: e9 7c 01 00 00 jmp 6b6 <printf+0x19e> c = fmt[i] & 0xff; 53a: 8b 55 0c mov 0xc(%ebp),%edx 53d: 8b 45 f0 mov -0x10(%ebp),%eax 540: 01 d0 add %edx,%eax 542: 0f b6 00 movzbl (%eax),%eax 545: 0f be c0 movsbl %al,%eax 548: 25 ff 00 00 00 and $0xff,%eax 54d: 89 45 e4 mov %eax,-0x1c(%ebp) if(state == 0){ 550: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 554: 75 2c jne 582 <printf+0x6a> if(c == '%'){ 556: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp) 55a: 75 0c jne 568 <printf+0x50> state = '%'; 55c: c7 45 ec 25 00 00 00 movl $0x25,-0x14(%ebp) 563: e9 4a 01 00 00 jmp 6b2 <printf+0x19a> } else { putc(fd, c); 568: 8b 45 e4 mov -0x1c(%ebp),%eax 56b: 0f be c0 movsbl %al,%eax 56e: 89 44 24 04 mov %eax,0x4(%esp) 572: 8b 45 08 mov 0x8(%ebp),%eax 575: 89 04 24 mov %eax,(%esp) 578: e8 bb fe ff ff call 438 <putc> 57d: e9 30 01 00 00 jmp 6b2 <printf+0x19a> } } else if(state == '%'){ 582: 83 7d ec 25 cmpl $0x25,-0x14(%ebp) 586: 0f 85 26 01 00 00 jne 6b2 <printf+0x19a> if(c == 'd'){ 58c: 83 7d e4 64 cmpl $0x64,-0x1c(%ebp) 590: 75 2d jne 5bf <printf+0xa7> printint(fd, *ap, 10, 1); 592: 8b 45 e8 mov -0x18(%ebp),%eax 595: 8b 00 mov (%eax),%eax 597: c7 44 24 0c 01 00 00 movl $0x1,0xc(%esp) 59e: 00 59f: c7 44 24 08 0a 00 00 movl $0xa,0x8(%esp) 5a6: 00 5a7: 89 44 24 04 mov %eax,0x4(%esp) 5ab: 8b 45 08 mov 0x8(%ebp),%eax 5ae: 89 04 24 mov %eax,(%esp) 5b1: e8 aa fe ff ff call 460 <printint> ap++; 5b6: 83 45 e8 04 addl $0x4,-0x18(%ebp) 5ba: e9 ec 00 00 00 jmp 6ab <printf+0x193> } else if(c == 'x' || c == 'p'){ 5bf: 83 7d e4 78 cmpl $0x78,-0x1c(%ebp) 5c3: 74 06 je 5cb <printf+0xb3> 5c5: 83 7d e4 70 cmpl $0x70,-0x1c(%ebp) 5c9: 75 2d jne 5f8 <printf+0xe0> printint(fd, *ap, 16, 0); 5cb: 8b 45 e8 mov -0x18(%ebp),%eax 5ce: 8b 00 mov (%eax),%eax 5d0: c7 44 24 0c 00 00 00 movl $0x0,0xc(%esp) 5d7: 00 5d8: c7 44 24 08 10 00 00 movl $0x10,0x8(%esp) 5df: 00 5e0: 89 44 24 04 mov %eax,0x4(%esp) 5e4: 8b 45 08 mov 0x8(%ebp),%eax 5e7: 89 04 24 mov %eax,(%esp) 5ea: e8 71 fe ff ff call 460 <printint> ap++; 5ef: 83 45 e8 04 addl $0x4,-0x18(%ebp) 5f3: e9 b3 00 00 00 jmp 6ab <printf+0x193> } else if(c == 's'){ 5f8: 83 7d e4 73 cmpl $0x73,-0x1c(%ebp) 5fc: 75 45 jne 643 <printf+0x12b> s = (char*)*ap; 5fe: 8b 45 e8 mov -0x18(%ebp),%eax 601: 8b 00 mov (%eax),%eax 603: 89 45 f4 mov %eax,-0xc(%ebp) ap++; 606: 83 45 e8 04 addl $0x4,-0x18(%ebp) if(s == 0) 60a: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 60e: 75 09 jne 619 <printf+0x101> s = "(null)"; 610: c7 45 f4 b4 09 00 00 movl $0x9b4,-0xc(%ebp) while(*s != 0){ 617: eb 1e jmp 637 <printf+0x11f> 619: eb 1c jmp 637 <printf+0x11f> putc(fd, *s); 61b: 8b 45 f4 mov -0xc(%ebp),%eax 61e: 0f b6 00 movzbl (%eax),%eax 621: 0f be c0 movsbl %al,%eax 624: 89 44 24 04 mov %eax,0x4(%esp) 628: 8b 45 08 mov 0x8(%ebp),%eax 62b: 89 04 24 mov %eax,(%esp) 62e: e8 05 fe ff ff call 438 <putc> s++; 633: 83 45 f4 01 addl $0x1,-0xc(%ebp) } else if(c == 's'){ s = (char*)*ap; ap++; if(s == 0) s = "(null)"; while(*s != 0){ 637: 8b 45 f4 mov -0xc(%ebp),%eax 63a: 0f b6 00 movzbl (%eax),%eax 63d: 84 c0 test %al,%al 63f: 75 da jne 61b <printf+0x103> 641: eb 68 jmp 6ab <printf+0x193> putc(fd, *s); s++; } } else if(c == 'c'){ 643: 83 7d e4 63 cmpl $0x63,-0x1c(%ebp) 647: 75 1d jne 666 <printf+0x14e> putc(fd, *ap); 649: 8b 45 e8 mov -0x18(%ebp),%eax 64c: 8b 00 mov (%eax),%eax 64e: 0f be c0 movsbl %al,%eax 651: 89 44 24 04 mov %eax,0x4(%esp) 655: 8b 45 08 mov 0x8(%ebp),%eax 658: 89 04 24 mov %eax,(%esp) 65b: e8 d8 fd ff ff call 438 <putc> ap++; 660: 83 45 e8 04 addl $0x4,-0x18(%ebp) 664: eb 45 jmp 6ab <printf+0x193> } else if(c == '%'){ 666: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp) 66a: 75 17 jne 683 <printf+0x16b> putc(fd, c); 66c: 8b 45 e4 mov -0x1c(%ebp),%eax 66f: 0f be c0 movsbl %al,%eax 672: 89 44 24 04 mov %eax,0x4(%esp) 676: 8b 45 08 mov 0x8(%ebp),%eax 679: 89 04 24 mov %eax,(%esp) 67c: e8 b7 fd ff ff call 438 <putc> 681: eb 28 jmp 6ab <printf+0x193> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); 683: c7 44 24 04 25 00 00 movl $0x25,0x4(%esp) 68a: 00 68b: 8b 45 08 mov 0x8(%ebp),%eax 68e: 89 04 24 mov %eax,(%esp) 691: e8 a2 fd ff ff call 438 <putc> putc(fd, c); 696: 8b 45 e4 mov -0x1c(%ebp),%eax 699: 0f be c0 movsbl %al,%eax 69c: 89 44 24 04 mov %eax,0x4(%esp) 6a0: 8b 45 08 mov 0x8(%ebp),%eax 6a3: 89 04 24 mov %eax,(%esp) 6a6: e8 8d fd ff ff call 438 <putc> } state = 0; 6ab: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp) int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 6b2: 83 45 f0 01 addl $0x1,-0x10(%ebp) 6b6: 8b 55 0c mov 0xc(%ebp),%edx 6b9: 8b 45 f0 mov -0x10(%ebp),%eax 6bc: 01 d0 add %edx,%eax 6be: 0f b6 00 movzbl (%eax),%eax 6c1: 84 c0 test %al,%al 6c3: 0f 85 71 fe ff ff jne 53a <printf+0x22> putc(fd, c); } state = 0; } } } 6c9: c9 leave 6ca: c3 ret 6cb: 90 nop 000006cc <free>: static Header base; static Header *freep; void free(void *ap) { 6cc: 55 push %ebp 6cd: 89 e5 mov %esp,%ebp 6cf: 83 ec 10 sub $0x10,%esp Header *bp, *p; bp = (Header*)ap - 1; 6d2: 8b 45 08 mov 0x8(%ebp),%eax 6d5: 83 e8 08 sub $0x8,%eax 6d8: 89 45 f8 mov %eax,-0x8(%ebp) for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 6db: a1 08 0d 00 00 mov 0xd08,%eax 6e0: 89 45 fc mov %eax,-0x4(%ebp) 6e3: eb 24 jmp 709 <free+0x3d> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 6e5: 8b 45 fc mov -0x4(%ebp),%eax 6e8: 8b 00 mov (%eax),%eax 6ea: 3b 45 fc cmp -0x4(%ebp),%eax 6ed: 77 12 ja 701 <free+0x35> 6ef: 8b 45 f8 mov -0x8(%ebp),%eax 6f2: 3b 45 fc cmp -0x4(%ebp),%eax 6f5: 77 24 ja 71b <free+0x4f> 6f7: 8b 45 fc mov -0x4(%ebp),%eax 6fa: 8b 00 mov (%eax),%eax 6fc: 3b 45 f8 cmp -0x8(%ebp),%eax 6ff: 77 1a ja 71b <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) 701: 8b 45 fc mov -0x4(%ebp),%eax 704: 8b 00 mov (%eax),%eax 706: 89 45 fc mov %eax,-0x4(%ebp) 709: 8b 45 f8 mov -0x8(%ebp),%eax 70c: 3b 45 fc cmp -0x4(%ebp),%eax 70f: 76 d4 jbe 6e5 <free+0x19> 711: 8b 45 fc mov -0x4(%ebp),%eax 714: 8b 00 mov (%eax),%eax 716: 3b 45 f8 cmp -0x8(%ebp),%eax 719: 76 ca jbe 6e5 <free+0x19> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) break; if(bp + bp->s.size == p->s.ptr){ 71b: 8b 45 f8 mov -0x8(%ebp),%eax 71e: 8b 40 04 mov 0x4(%eax),%eax 721: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx 728: 8b 45 f8 mov -0x8(%ebp),%eax 72b: 01 c2 add %eax,%edx 72d: 8b 45 fc mov -0x4(%ebp),%eax 730: 8b 00 mov (%eax),%eax 732: 39 c2 cmp %eax,%edx 734: 75 24 jne 75a <free+0x8e> bp->s.size += p->s.ptr->s.size; 736: 8b 45 f8 mov -0x8(%ebp),%eax 739: 8b 50 04 mov 0x4(%eax),%edx 73c: 8b 45 fc mov -0x4(%ebp),%eax 73f: 8b 00 mov (%eax),%eax 741: 8b 40 04 mov 0x4(%eax),%eax 744: 01 c2 add %eax,%edx 746: 8b 45 f8 mov -0x8(%ebp),%eax 749: 89 50 04 mov %edx,0x4(%eax) bp->s.ptr = p->s.ptr->s.ptr; 74c: 8b 45 fc mov -0x4(%ebp),%eax 74f: 8b 00 mov (%eax),%eax 751: 8b 10 mov (%eax),%edx 753: 8b 45 f8 mov -0x8(%ebp),%eax 756: 89 10 mov %edx,(%eax) 758: eb 0a jmp 764 <free+0x98> } else bp->s.ptr = p->s.ptr; 75a: 8b 45 fc mov -0x4(%ebp),%eax 75d: 8b 10 mov (%eax),%edx 75f: 8b 45 f8 mov -0x8(%ebp),%eax 762: 89 10 mov %edx,(%eax) if(p + p->s.size == bp){ 764: 8b 45 fc mov -0x4(%ebp),%eax 767: 8b 40 04 mov 0x4(%eax),%eax 76a: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx 771: 8b 45 fc mov -0x4(%ebp),%eax 774: 01 d0 add %edx,%eax 776: 3b 45 f8 cmp -0x8(%ebp),%eax 779: 75 20 jne 79b <free+0xcf> p->s.size += bp->s.size; 77b: 8b 45 fc mov -0x4(%ebp),%eax 77e: 8b 50 04 mov 0x4(%eax),%edx 781: 8b 45 f8 mov -0x8(%ebp),%eax 784: 8b 40 04 mov 0x4(%eax),%eax 787: 01 c2 add %eax,%edx 789: 8b 45 fc mov -0x4(%ebp),%eax 78c: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 78f: 8b 45 f8 mov -0x8(%ebp),%eax 792: 8b 10 mov (%eax),%edx 794: 8b 45 fc mov -0x4(%ebp),%eax 797: 89 10 mov %edx,(%eax) 799: eb 08 jmp 7a3 <free+0xd7> } else p->s.ptr = bp; 79b: 8b 45 fc mov -0x4(%ebp),%eax 79e: 8b 55 f8 mov -0x8(%ebp),%edx 7a1: 89 10 mov %edx,(%eax) freep = p; 7a3: 8b 45 fc mov -0x4(%ebp),%eax 7a6: a3 08 0d 00 00 mov %eax,0xd08 } 7ab: c9 leave 7ac: c3 ret 000007ad <morecore>: static Header* morecore(uint nu) { 7ad: 55 push %ebp 7ae: 89 e5 mov %esp,%ebp 7b0: 83 ec 28 sub $0x28,%esp char *p; Header *hp; if(nu < 4096) 7b3: 81 7d 08 ff 0f 00 00 cmpl $0xfff,0x8(%ebp) 7ba: 77 07 ja 7c3 <morecore+0x16> nu = 4096; 7bc: c7 45 08 00 10 00 00 movl $0x1000,0x8(%ebp) p = sbrk(nu * sizeof(Header)); 7c3: 8b 45 08 mov 0x8(%ebp),%eax 7c6: c1 e0 03 shl $0x3,%eax 7c9: 89 04 24 mov %eax,(%esp) 7cc: e8 3f fc ff ff call 410 <sbrk> 7d1: 89 45 f4 mov %eax,-0xc(%ebp) if(p == (char*)-1) 7d4: 83 7d f4 ff cmpl $0xffffffff,-0xc(%ebp) 7d8: 75 07 jne 7e1 <morecore+0x34> return 0; 7da: b8 00 00 00 00 mov $0x0,%eax 7df: eb 22 jmp 803 <morecore+0x56> hp = (Header*)p; 7e1: 8b 45 f4 mov -0xc(%ebp),%eax 7e4: 89 45 f0 mov %eax,-0x10(%ebp) hp->s.size = nu; 7e7: 8b 45 f0 mov -0x10(%ebp),%eax 7ea: 8b 55 08 mov 0x8(%ebp),%edx 7ed: 89 50 04 mov %edx,0x4(%eax) free((void*)(hp + 1)); 7f0: 8b 45 f0 mov -0x10(%ebp),%eax 7f3: 83 c0 08 add $0x8,%eax 7f6: 89 04 24 mov %eax,(%esp) 7f9: e8 ce fe ff ff call 6cc <free> return freep; 7fe: a1 08 0d 00 00 mov 0xd08,%eax } 803: c9 leave 804: c3 ret 00000805 <malloc>: void* malloc(uint nbytes) { 805: 55 push %ebp 806: 89 e5 mov %esp,%ebp 808: 83 ec 28 sub $0x28,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 80b: 8b 45 08 mov 0x8(%ebp),%eax 80e: 83 c0 07 add $0x7,%eax 811: c1 e8 03 shr $0x3,%eax 814: 83 c0 01 add $0x1,%eax 817: 89 45 ec mov %eax,-0x14(%ebp) if((prevp = freep) == 0){ 81a: a1 08 0d 00 00 mov 0xd08,%eax 81f: 89 45 f0 mov %eax,-0x10(%ebp) 822: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 826: 75 23 jne 84b <malloc+0x46> base.s.ptr = freep = prevp = &base; 828: c7 45 f0 00 0d 00 00 movl $0xd00,-0x10(%ebp) 82f: 8b 45 f0 mov -0x10(%ebp),%eax 832: a3 08 0d 00 00 mov %eax,0xd08 837: a1 08 0d 00 00 mov 0xd08,%eax 83c: a3 00 0d 00 00 mov %eax,0xd00 base.s.size = 0; 841: c7 05 04 0d 00 00 00 movl $0x0,0xd04 848: 00 00 00 } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 84b: 8b 45 f0 mov -0x10(%ebp),%eax 84e: 8b 00 mov (%eax),%eax 850: 89 45 f4 mov %eax,-0xc(%ebp) if(p->s.size >= nunits){ 853: 8b 45 f4 mov -0xc(%ebp),%eax 856: 8b 40 04 mov 0x4(%eax),%eax 859: 3b 45 ec cmp -0x14(%ebp),%eax 85c: 72 4d jb 8ab <malloc+0xa6> if(p->s.size == nunits) 85e: 8b 45 f4 mov -0xc(%ebp),%eax 861: 8b 40 04 mov 0x4(%eax),%eax 864: 3b 45 ec cmp -0x14(%ebp),%eax 867: 75 0c jne 875 <malloc+0x70> prevp->s.ptr = p->s.ptr; 869: 8b 45 f4 mov -0xc(%ebp),%eax 86c: 8b 10 mov (%eax),%edx 86e: 8b 45 f0 mov -0x10(%ebp),%eax 871: 89 10 mov %edx,(%eax) 873: eb 26 jmp 89b <malloc+0x96> else { p->s.size -= nunits; 875: 8b 45 f4 mov -0xc(%ebp),%eax 878: 8b 40 04 mov 0x4(%eax),%eax 87b: 2b 45 ec sub -0x14(%ebp),%eax 87e: 89 c2 mov %eax,%edx 880: 8b 45 f4 mov -0xc(%ebp),%eax 883: 89 50 04 mov %edx,0x4(%eax) p += p->s.size; 886: 8b 45 f4 mov -0xc(%ebp),%eax 889: 8b 40 04 mov 0x4(%eax),%eax 88c: c1 e0 03 shl $0x3,%eax 88f: 01 45 f4 add %eax,-0xc(%ebp) p->s.size = nunits; 892: 8b 45 f4 mov -0xc(%ebp),%eax 895: 8b 55 ec mov -0x14(%ebp),%edx 898: 89 50 04 mov %edx,0x4(%eax) } freep = prevp; 89b: 8b 45 f0 mov -0x10(%ebp),%eax 89e: a3 08 0d 00 00 mov %eax,0xd08 return (void*)(p + 1); 8a3: 8b 45 f4 mov -0xc(%ebp),%eax 8a6: 83 c0 08 add $0x8,%eax 8a9: eb 38 jmp 8e3 <malloc+0xde> } if(p == freep) 8ab: a1 08 0d 00 00 mov 0xd08,%eax 8b0: 39 45 f4 cmp %eax,-0xc(%ebp) 8b3: 75 1b jne 8d0 <malloc+0xcb> if((p = morecore(nunits)) == 0) 8b5: 8b 45 ec mov -0x14(%ebp),%eax 8b8: 89 04 24 mov %eax,(%esp) 8bb: e8 ed fe ff ff call 7ad <morecore> 8c0: 89 45 f4 mov %eax,-0xc(%ebp) 8c3: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 8c7: 75 07 jne 8d0 <malloc+0xcb> return 0; 8c9: b8 00 00 00 00 mov $0x0,%eax 8ce: eb 13 jmp 8e3 <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){ 8d0: 8b 45 f4 mov -0xc(%ebp),%eax 8d3: 89 45 f0 mov %eax,-0x10(%ebp) 8d6: 8b 45 f4 mov -0xc(%ebp),%eax 8d9: 8b 00 mov (%eax),%eax 8db: 89 45 f4 mov %eax,-0xc(%ebp) return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) return 0; } 8de: e9 70 ff ff ff jmp 853 <malloc+0x4e> } 8e3: c9 leave 8e4: c3 ret 8e5: 66 90 xchg %ax,%ax 8e7: 90 nop 000008e8 <xchg>: asm volatile("sti"); } static inline uint xchg(volatile uint *addr, uint newval) { 8e8: 55 push %ebp 8e9: 89 e5 mov %esp,%ebp 8eb: 83 ec 10 sub $0x10,%esp uint result; // The + in "+m" denotes a read-modify-write operand. asm volatile("lock; xchgl %0, %1" : 8ee: 8b 55 08 mov 0x8(%ebp),%edx 8f1: 8b 45 0c mov 0xc(%ebp),%eax 8f4: 8b 4d 08 mov 0x8(%ebp),%ecx 8f7: f0 87 02 lock xchg %eax,(%edx) 8fa: 89 45 fc mov %eax,-0x4(%ebp) "+m" (*addr), "=a" (result) : "1" (newval) : "cc"); return result; 8fd: 8b 45 fc mov -0x4(%ebp),%eax } 900: c9 leave 901: c3 ret 00000902 <mutex_init>: #include "types.h" #include "user.h" #include "x86.h" #include "threadlib.h" void mutex_init(mutex_t *m) { 902: 55 push %ebp 903: 89 e5 mov %esp,%ebp // 0 indicates that lock is available, 1 that it is held by a thread m->flag = 0; 905: 8b 45 08 mov 0x8(%ebp),%eax 908: c7 00 00 00 00 00 movl $0x0,(%eax) } 90e: 5d pop %ebp 90f: c3 ret 00000910 <mutex_lock>: void mutex_lock(mutex_t *m) { 910: 55 push %ebp 911: 89 e5 mov %esp,%ebp 913: 83 ec 08 sub $0x8,%esp while (xchg(&m->flag, 1) == 1); // spin-wait (do nothing) 916: 90 nop 917: 8b 45 08 mov 0x8(%ebp),%eax 91a: c7 44 24 04 01 00 00 movl $0x1,0x4(%esp) 921: 00 922: 89 04 24 mov %eax,(%esp) 925: e8 be ff ff ff call 8e8 <xchg> 92a: 83 f8 01 cmp $0x1,%eax 92d: 74 e8 je 917 <mutex_lock+0x7> } 92f: c9 leave 930: c3 ret 00000931 <mutex_unlock>: void mutex_unlock(mutex_t *m) { 931: 55 push %ebp 932: 89 e5 mov %esp,%ebp m->flag = 0; 934: 8b 45 08 mov 0x8(%ebp),%eax 937: c7 00 00 00 00 00 movl $0x0,(%eax) } 93d: 5d pop %ebp 93e: c3 ret 0000093f <thread_create>: if(!pid) (*start_routine)(arg); else return pid; }*/ int thread_create(void(*child)(void*), void *arg_ptr) { 93f: 55 push %ebp 940: 89 e5 mov %esp,%ebp 942: 83 ec 28 sub $0x28,%esp void *stack = malloc(4096); 945: c7 04 24 00 10 00 00 movl $0x1000,(%esp) 94c: e8 b4 fe ff ff call 805 <malloc> 951: 89 45 f4 mov %eax,-0xc(%ebp) int clone_pid = clone(child, arg_ptr, stack); 954: 8b 45 f4 mov -0xc(%ebp),%eax 957: 89 44 24 08 mov %eax,0x8(%esp) 95b: 8b 45 0c mov 0xc(%ebp),%eax 95e: 89 44 24 04 mov %eax,0x4(%esp) 962: 8b 45 08 mov 0x8(%ebp),%eax 965: 89 04 24 mov %eax,(%esp) 968: e8 bb fa ff ff call 428 <clone> 96d: 89 45 f0 mov %eax,-0x10(%ebp) return clone_pid; 970: 8b 45 f0 mov -0x10(%ebp),%eax } 973: c9 leave 974: c3 ret 00000975 <thread_join>: int thread_join(void) { 975: 55 push %ebp 976: 89 e5 mov %esp,%ebp 978: 83 ec 28 sub $0x28,%esp void *join_s; int join_pid = join(&join_s); 97b: 8d 45 f0 lea -0x10(%ebp),%eax 97e: 89 04 24 mov %eax,(%esp) 981: e8 aa fa ff ff call 430 <join> 986: 89 45 f4 mov %eax,-0xc(%ebp) return join_pid; 989: 8b 45 f4 mov -0xc(%ebp),%eax 98c: c9 leave 98d: c3 ret
; A005481: Decimal expansion of cube root of 5. ; Submitted by Jon Maiga ; 1,7,0,9,9,7,5,9,4,6,6,7,6,6,9,6,9,8,9,3,5,3,1,0,8,8,7,2,5,4,3,8,6,0,1,0,9,8,6,8,0,5,5,1,1,0,5,4,3,0,5,4,9,2,4,3,8,2,8,6,1,7,0,7,4,4,4,2,9,5,9,2,0,5,0,4,1,7,3,2,1,6,2,5,7,1,8,7,0,1,0,0,2,0,1,8,9,0,0,2 mov $1,1 pow $2,$0 mov $3,$0 mul $3,4 lpb $3 add $6,$2 div $6,3 mul $6,2 add $1,$6 add $2,$1 mov $5,$1 mul $1,2 mul $2,2 sub $3,1 add $5,$2 add $6,$5 lpe mov $4,10 pow $4,$0 div $2,$4 div $1,$2 mov $0,$1 mod $0,10
; A141107: Upper Odd Swappage of Upper Wythoff Sequence. ; 3,5,7,11,13,15,19,21,23,27,29,31,35,37,39,41,45,47,49,53,55,57,61,63,65,69,71,73,75,79,81,83,87,89,91,95,97,99,103,105,107,109,113,115,117,121,123,125,129,131,133,137,139,141,143,147,149,151,155,157,159,163 add $0,1 mov $1,17 mul $1,$0 div $1,13 mul $1,2 add $1,1
.text main: addi x1, x0, 1 addi x2, x0, 2 jal x1, first addi x3, x0, 3 addi x4, x0, 4 addi x5, x0, 5 first: jal x9, skip addi x6, x0, 6 addi x7, x0, 7 addi x8, x0, 8 skip: addi x9, x0, 9 halt: j halt
/* * Copyright (c) 2020 Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ #include "updated-rpc/config.h" // This file is just to make sure that config.h compiles and is checked by // static analyzers.
#include <LibGUI/GAction.h> #include <LibGUI/GApplication.h> #include <LibGUI/GDesktop.h> #include <LibGUI/GLabel.h> #include <LibGUI/GMenuBar.h> #include <LibGUI/GPainter.h> #include <LibGUI/GWindow.h> #include <LibGUI/GWindowServerConnection.h> static GApplication* s_the; GApplication& GApplication::the() { ASSERT(s_the); return *s_the; } GApplication::GApplication(int argc, char** argv) { (void)argc; (void)argv; ASSERT(!s_the); s_the = this; m_event_loop = make<CEventLoop>(); GWindowServerConnection::the(); if (argc > 0) m_invoked_as = argv[0]; for (int i = 1; i < argc; i++) m_args.append(argv[i]); } GApplication::~GApplication() { s_the = nullptr; } int GApplication::exec() { int exit_code = m_event_loop->exec(); // NOTE: Maybe it would be cool to return instead of exit()? // This would require cleaning up all the CObjects on the heap. exit(exit_code); return exit_code; } void GApplication::quit(int exit_code) { m_event_loop->quit(exit_code); } void GApplication::set_menubar(OwnPtr<GMenuBar>&& menubar) { if (m_menubar) m_menubar->notify_removed_from_application({}); m_menubar = move(menubar); if (m_menubar) m_menubar->notify_added_to_application({}); } void GApplication::register_global_shortcut_action(Badge<GAction>, GAction& action) { m_global_shortcut_actions.set(action.shortcut(), &action); } void GApplication::unregister_global_shortcut_action(Badge<GAction>, GAction& action) { m_global_shortcut_actions.remove(action.shortcut()); } GAction* GApplication::action_for_key_event(const GKeyEvent& event) { auto it = m_global_shortcut_actions.find(GShortcut(event.modifiers(), (KeyCode)event.key())); if (it == m_global_shortcut_actions.end()) return nullptr; return (*it).value; } class GApplication::TooltipWindow final : public GWindow { public: TooltipWindow() { set_window_type(GWindowType::Tooltip); m_label = GLabel::construct(); m_label->set_background_color(Color::from_rgb(0xdac7b5)); m_label->set_fill_with_background_color(true); m_label->set_frame_thickness(1); m_label->set_frame_shape(FrameShape::Container); m_label->set_frame_shadow(FrameShadow::Plain); set_main_widget(m_label); } void set_tooltip(const StringView& tooltip) { // FIXME: Add some kind of GLabel auto-sizing feature. int text_width = m_label->font().width(tooltip); set_rect(100, 100, text_width + 10, m_label->font().glyph_height() + 8); m_label->set_text(tooltip); } RefPtr<GLabel> m_label; }; void GApplication::show_tooltip(const StringView& tooltip, const Point& screen_location) { if (!m_tooltip_window) { m_tooltip_window = new TooltipWindow; m_tooltip_window->set_double_buffering_enabled(false); } m_tooltip_window->set_tooltip(tooltip); Rect desktop_rect = GDesktop::the().rect(); const int margin = 30; Point adjusted_pos = screen_location; if (adjusted_pos.x() + m_tooltip_window->width() >= desktop_rect.width() - margin) { adjusted_pos = adjusted_pos.translated(-m_tooltip_window->width(), 0); } if (adjusted_pos.y() + m_tooltip_window->height() >= desktop_rect.height() - margin) { adjusted_pos = adjusted_pos.translated(0, -(m_tooltip_window->height() * 2)); } m_tooltip_window->move_to(adjusted_pos); m_tooltip_window->show(); } void GApplication::hide_tooltip() { if (m_tooltip_window) { m_tooltip_window->hide(); m_tooltip_window = nullptr; } } void GApplication::did_create_window(Badge<GWindow>) { if (m_event_loop->was_exit_requested()) m_event_loop->unquit(); } void GApplication::did_delete_last_window(Badge<GWindow>) { if (m_quit_when_last_window_deleted) m_event_loop->quit(0); }
; A021671: Decimal expansion of 1/667. ; Submitted by Jamie Morken(s2.) ; 0,0,1,4,9,9,2,5,0,3,7,4,8,1,2,5,9,3,7,0,3,1,4,8,4,2,5,7,8,7,1,0,6,4,4,6,7,7,6,6,1,1,6,9,4,1,5,2,9,2,3,5,3,8,2,3,0,8,8,4,5,5,7,7,2,1,1,3,9,4,3,0,2,8,4,8,5,7,5,7,1,2,1,4,3,9,2,8,0,3,5,9,8,2,0,0,8,9,9 add $0,1 mov $1,10 pow $1,$0 div $1,667 mod $1,10 mov $0,$1
; A160076: Numerator of Hermite(n, 17/26). ; Submitted by Christian Krause ; 1,17,-49,-12325,-159839,13946137,507212239,-19660157773,-1534286839615,27078190344737,5127629801969359,-4354576731731957,-19138555408161520031,-307693278714841022935,78864026725309421626319,2796693049208887888175843,-352296833660767673546447999,-21113562182354716149544574927,1665367049114740877655632428495,156766152152396687973974945140283,-8029962602824122220746897388410079,-1196248552798211688456767884751284423,36660449157276020819096423622162905551,9518531874281194469289165192587320363795 add $0,1 mov $3,1 lpb $0 sub $0,1 add $2,$3 mov $3,$1 mov $1,$2 mul $2,17 mul $3,-338 mul $3,$0 lpe mov $0,$1
// Program: Sum1toN.asm // Computes RAM[1] = 1 + 2 + ... + n // Usage: put a number (n) in RAM[0] // Algorithm: // // Declaration: // n = R0 // i = 1 // sum = 0 // // LOOP: // if i > n goto STOP // sum = sum + i // i = i + 1 // goto LOOP // STOP: // R1 = sum // Declaration: @R0 D=M @n M=D // n = R0 @i M=1 // i = 1 @sum M=0 // sum = 0 (LOOP) @i D=M @n D=D-M @STOP D;JGT // if i > n goto STOP (perhaps switch to `i - n > 0` comment? explains everything much better) @sum D=M @i D=D+M @sum M=D // sum = sum + i @i M=M+1 // i = i + 1 @LOOP 0;JMP (STOP) @sum D=M @R1 M=D // RAM[1] = sum (END) @END 0;JMP
; A328372: Expansion of Sum_{k>=1} x^(k^2) / (1 - x^(2*k^2)). ; Submitted by Jamie Morken(s1.) ; 1,0,1,1,1,0,1,0,2,0,1,1,1,0,1,1,1,0,1,1,1,0,1,0,2,0,2,1,1,0,1,0,1,0,1,2,1,0,1,0,1,0,1,1,2,0,1,1,2,0,1,1,1,0,1,0,1,0,1,1,1,0,2,1,1,0,1,1,1,0,1,0,1,0,2,1,1,0,1,1,3,0,1,1,1,0,1,0,1,0,1,1,1,0,1,0,1,0,2,2 add $0,1 mov $2,$0 lpb $0 mov $4,$0 max $0,1 mov $3,$2 add $3,$2 div $3,$0 gcd $3,$0 sub $0,1 mul $3,$4 cmp $3,$2 add $1,$3 lpe mov $0,$1
// Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #include <config.h> #include <dhcp/pkt4.h> #include <dhcp/dhcp4.h> #include <dhcp/option_int.h> #include <dhcpsrv/shared_network.h> #include <dhcpsrv/host_mgr.h> #include <dhcpsrv/tests/alloc_engine_utils.h> #include <dhcpsrv/testutils/test_utils.h> #include <testutils/gtest_utils.h> #include <hooks/hooks_manager.h> #include <hooks/callout_handle.h> #include <stats/stats_mgr.h> using namespace std; using namespace isc::hooks; using namespace isc::asiolink; using namespace isc::data; using namespace isc::stats; namespace isc { namespace dhcp { namespace test { // This test checks if the v4 Allocation Engine can be instantiated, parses // parameters string and allocators are created. TEST_F(AllocEngine4Test, constructor) { boost::scoped_ptr<AllocEngine> x; // Hashed and random allocators are not supported yet ASSERT_THROW(x.reset(new AllocEngine(AllocEngine::ALLOC_HASHED, 5, false)), NotImplemented); ASSERT_THROW(x.reset(new AllocEngine(AllocEngine::ALLOC_RANDOM, 5, false)), NotImplemented); // Create V4 (ipv6=false) Allocation Engine that will try at most // 100 attempts to pick up a lease ASSERT_NO_THROW(x.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 100, false))); // There should be V4 allocator ASSERT_TRUE(x->getAllocator(Lease::TYPE_V4)); // Check that allocators for V6 stuff are not created EXPECT_THROW(x->getAllocator(Lease::TYPE_NA), BadValue); EXPECT_THROW(x->getAllocator(Lease::TYPE_TA), BadValue); EXPECT_THROW(x->getAllocator(Lease::TYPE_PD), BadValue); } // This test checks if two simple IPv4 allocations succeed and that the // statistics is properly updated. Prior to the second allocation it // resets the pointer to the last allocated address within the address // pool. This causes the engine to walk over the already allocated // address and then pick the first available address for the second // allocation. Because the allocation engine checks the callouts next // step status after each attempt to allocate an address, this test // also sets this status to non-default value prior to the second // allocation attempt, to make sure that this unexpected status will // not interfere with the allocation. TEST_F(AllocEngine4Test, simpleAlloc4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); // Assigned addresses should be zero. EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID())); // Get the cumulative count of assigned addresses. int64_t cumulative = getStatistics("cumulative-assigned-addresses", subnet_->getID()); int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, true, "somehost.example.com.", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr lease = engine->allocateLease4(ctx); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // Check that we got a lease ASSERT_TRUE(lease); // Do all checks on the lease checkLease4(lease); // Check that the lease is indeed in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); // Assigned addresses should have incremented. EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID())); cumulative += 1; EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", cumulative, subnet_->getID())); glbl_cumulative += 1; EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative)); // Second allocation starts here. uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe}; HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr2, IOAddress("0.0.0.0"), false, true, "anotherhost.example.com.", false); ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); // Set the next step to non-default value to verify that it doesn't // affect the allocation. ctx2.callout_handle_ = HooksManager::createCalloutHandle(); ctx2.callout_handle_->setStatus(CalloutHandle::NEXT_STEP_SKIP); // Set the last allocated to the beginning of the pool. The allocation // engine should detect that the first address is already allocated and // assign the first available one. pool_->resetLastAllocated(); lease = engine->allocateLease4(ctx2); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx2.old_lease_); // Check that we got a lease ASSERT_TRUE(lease); // Check that the lease is indeed in LeaseMgr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); // Assigned addresses should have incremented. EXPECT_TRUE(testStatistics("assigned-addresses", 2, subnet_->getID())); cumulative += 1; EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", cumulative, subnet_->getID())); glbl_cumulative += 1; EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative)); } // This test checks that simple allocation uses the default valid lifetime. TEST_F(AllocEngine4Test, defaultAlloc4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, true, "somehost.example.com.", false); subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr lease = engine->allocateLease4(ctx); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // Check that we got a lease ASSERT_TRUE(lease); // Do all checks on the lease checkLease4(lease); // Check the valid lifetime has the default. EXPECT_EQ(subnet_->getValid(), lease->valid_lft_); // Check that the lease is indeed in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); } // This test checks that simple allocation uses the specified valid lifetime. TEST_F(AllocEngine4Test, hintAlloc4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, true, "somehost.example.com.", false); subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); // Speficy the valid lifetime we want. OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 4)); ctx.query_->addOption(opt); Lease4Ptr lease = engine->allocateLease4(ctx); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // Check that we got a lease ASSERT_TRUE(lease); // Do all checks on the lease checkLease4(lease); // Check the valid lifetime has the wanted value. EXPECT_EQ(opt->getValue(), lease->valid_lft_); // Check that the lease is indeed in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); } // This test checks that simple allocation uses the min valid lifetime. TEST_F(AllocEngine4Test, minAlloc4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, true, "somehost.example.com.", false); subnet_->setValid(Triplet<uint32_t>(2, 3, 5)); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); // Speficy the valid lifetime we want, as it is lower than the min value // we'll get this min value instead. OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 1)); ctx.query_->addOption(opt); Lease4Ptr lease = engine->allocateLease4(ctx); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // Check that we got a lease ASSERT_TRUE(lease); // Do all checks on the lease checkLease4(lease); // Check the valid lifetime has the wanted value. EXPECT_EQ(subnet_->getValid().getMin(), lease->valid_lft_); // Check that the lease is indeed in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); } // This test checks that simple allocation uses the max valid lifetime. TEST_F(AllocEngine4Test, maxAlloc4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, true, "somehost.example.com.", false); subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); // Speficy the valid lifetime we want, as it is greater than the max value // we'll get this max value instead. OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 6)); ctx.query_->addOption(opt); Lease4Ptr lease = engine->allocateLease4(ctx); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // Check that we got a lease ASSERT_TRUE(lease); // Do all checks on the lease checkLease4(lease); // Check the valid lifetime has the wanted value. EXPECT_EQ(subnet_->getValid().getMax(), lease->valid_lft_); // Check that the lease is indeed in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); } // This test checks that simple allocation handles BOOTP queries. TEST_F(AllocEngine4Test, bootpAlloc4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, true, "somehost.example.com.", false); subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); // Make the query a BOOTP one. ctx.query_->addClass("BOOTP"); Lease4Ptr lease = engine->allocateLease4(ctx); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // Check that we got a lease ASSERT_TRUE(lease); // Check that is belongs to the right subnet and client. EXPECT_EQ(lease->subnet_id_, subnet_->getID()); EXPECT_TRUE(subnet_->inRange(lease->addr_)); EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, lease->addr_)); ASSERT_TRUE(lease->client_id_); EXPECT_TRUE(*lease->client_id_ == *clientid_); ASSERT_TRUE(lease->hwaddr_); EXPECT_TRUE(*lease->hwaddr_ == *hwaddr_); // Check the valid lifetime is infinite. uint32_t infinity_lft = Lease::INFINITY_LFT; EXPECT_EQ(infinity_lft, lease->valid_lft_); // Check that the lease is indeed in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); } // This test checks if the fake allocation (for DHCPDISCOVER) can succeed TEST_F(AllocEngine4Test, fakeAlloc4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); // Assigned addresses should be zero. EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID())); // Get the cumulative count of assigned addresses. int64_t cumulative = getStatistics("cumulative-assigned-addresses", subnet_->getID()); int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, true, "host.example.com.", true); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); Lease4Ptr lease = engine->allocateLease4(ctx); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // Check that we got a lease ASSERT_TRUE(lease); // Do all checks on the lease checkLease4(lease); // Check that the lease is NOT in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_FALSE(from_mgr); // Assigned addresses should still be zero. EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID())); EXPECT_EQ(cumulative, getStatistics("cumulative-assigned-addresses", subnet_->getID())); EXPECT_EQ(glbl_cumulative, getStatistics("cumulative-assigned-addresses")); } // This test checks if the allocation with a hint that is valid (in range, // in pool and free) can succeed TEST_F(AllocEngine4Test, allocWithValidHint4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.105"), true, true, "host.example.com.", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr lease = engine->allocateLease4(ctx); // Check that we got a lease ASSERT_TRUE(lease); // We have allocated the new lease, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // We should get what we asked for EXPECT_EQ(lease->addr_.toText(), "192.0.2.105"); // Do all checks on the lease checkLease4(lease); // Check that the lease is indeed in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); } // This test checks if the allocation with a hint that is in range, // in pool, but is currently used can succeed TEST_F(AllocEngine4Test, allocWithUsedHint4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); // Let's create a lease and put it in the LeaseMgr uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe}; HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; time_t now = time(NULL); Lease4Ptr used(new Lease4(IOAddress("192.0.2.106"), hwaddr2, clientid2, sizeof(clientid2), 1, now, subnet_->getID())); ASSERT_TRUE(LeaseMgrFactory::instance().addLease(used)); // Another client comes in and request an address that is in pool, but // unfortunately it is used already. The same address must not be allocated // twice. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.106"), false, false, "", true); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr lease = engine->allocateLease4(ctx); // New lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // Check that we got a lease ASSERT_TRUE(lease); // Allocated address must be different EXPECT_NE(used->addr_, lease->addr_); // We should NOT get what we asked for, because it is used already EXPECT_NE("192.0.2.106", lease->addr_.toText()); // Do all checks on the lease checkLease4(lease); // The lease should not be in the LeaseMgr because it was a failed allocation. Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_FALSE(from_mgr); } // This test checks if an allocation with a hint that is out of the blue // can succeed. The invalid hint should be ignored completely. TEST_F(AllocEngine4Test, allocBogusHint4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); // Client would like to get a 10.1.1.1 lease, which does not belong to any // supported lease. Allocation engine should ignore it and carry on // with the normal allocation AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("10.1.1.1"), false, false, "", true); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr lease = engine->allocateLease4(ctx); // Check that we got a lease ASSERT_TRUE(lease); // We have allocated a new lease, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // We should NOT get what we asked for, because it is used already EXPECT_NE("10.1.1.1", lease->addr_.toText()); // Do all checks on the lease checkLease4(lease); // Check that the lease is not in the LeaseMgr as it is a fake allocation. Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); EXPECT_FALSE(from_mgr); } // This test checks that NULL values are handled properly TEST_F(AllocEngine4Test, allocateLease4Nulls) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); // Allocations without subnet are not allowed AllocEngine::ClientContext4 ctx1(Subnet4Ptr(), clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", false); ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr lease = engine->allocateLease4(ctx1); EXPECT_FALSE(lease); // Allocations without HW address are not allowed AllocEngine::ClientContext4 ctx2(subnet_, clientid_, HWAddrPtr(), IOAddress("0.0.0.0"), false, false, "", false); ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); lease = engine->allocateLease4(ctx2); EXPECT_FALSE(lease); EXPECT_FALSE(ctx2.old_lease_); // Allocations without client-id are allowed clientid_.reset(); AllocEngine::ClientContext4 ctx3(subnet_, ClientIdPtr(), hwaddr_, IOAddress("0.0.0.0"), false, false, "", false); ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1234)); lease = engine->allocateLease4(ctx3); // Check that we got a lease ASSERT_TRUE(lease); // New lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx3.old_lease_); // Do all checks on the lease checkLease4(lease); // Check that the lease is indeed in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); } // This test checks if a returning client can renew an // an existing lease and assigned-leases increments accordingly TEST_F(AllocEngine4Test, simpleRenew4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID())); int64_t cumulative = getStatistics("cumulative-assigned-addresses", subnet_->getID()); int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, true, "somehost.example.com.", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr lease = engine->allocateLease4(ctx); // Check that we got a lease and it's sane ASSERT_TRUE(lease); checkLease4(lease); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // We should have incremented assigned-addresses EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID())); cumulative += 1; EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", cumulative, subnet_->getID())); glbl_cumulative += 1; EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative)); // Do it again, this should amount to the renew of an existing lease Lease4Ptr lease2 = engine->allocateLease4(ctx); // Check that we got a lease and it's sane ASSERT_TRUE(lease2); checkLease4(lease2); // Lease already existed, so old_lease should be set. EXPECT_TRUE(ctx.old_lease_); // Should NOT have bumped assigned-addresses EXPECT_TRUE(testStatistics("assigned-addresses", 1, subnet_->getID())); EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", cumulative, subnet_->getID())); EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative)); } // This test checks simple renewal uses the default valid lifetime. TEST_F(AllocEngine4Test, defaultRenew4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, true, "somehost.example.com.", false); subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr lease = engine->allocateLease4(ctx); // Check that we got a lease and it's sane ASSERT_TRUE(lease); checkLease4(lease); // Check the valid lifetime has the default. EXPECT_EQ(subnet_->getValid(), lease->valid_lft_); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // Do it again, this should amount to the renew of an existing lease Lease4Ptr lease2 = engine->allocateLease4(ctx); // Check that we got a lease and it's sane ASSERT_TRUE(lease2); checkLease4(lease2); // Lease already existed, so old_lease should be set. EXPECT_TRUE(ctx.old_lease_); // Check the renewed valid lifetime has the default. EXPECT_EQ(subnet_->getValid(), lease2->valid_lft_); } // This test checks simple renewal uses the specified valid lifetime. TEST_F(AllocEngine4Test, hintRenew4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, true, "somehost.example.com.", false); subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); // Speficy the valid lifetime we want. OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 4)); ctx.query_->addOption(opt); Lease4Ptr lease = engine->allocateLease4(ctx); // Check that we got a lease and it's sane ASSERT_TRUE(lease); checkLease4(lease); // Check the valid lifetime has the wanted value. EXPECT_EQ(opt->getValue(), lease->valid_lft_); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // Do it again, this should amount to the renew of an existing lease Lease4Ptr lease2 = engine->allocateLease4(ctx); // Check that we got a lease and it's sane ASSERT_TRUE(lease2); checkLease4(lease2); // Lease already existed, so old_lease should be set. EXPECT_TRUE(ctx.old_lease_); // Check the renewed valid lifetime has the wanted value. EXPECT_EQ(opt->getValue(), lease2->valid_lft_); } // This test checks simple renewal uses the min valid lifetime. TEST_F(AllocEngine4Test, minRenew4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, true, "somehost.example.com.", false); subnet_->setValid(Triplet<uint32_t>(2, 3, 5)); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); // Speficy the valid lifetime we want, as it is lower than the min value // we'll get this min value instead. OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 1)); ctx.query_->addOption(opt); Lease4Ptr lease = engine->allocateLease4(ctx); // Check that we got a lease and it's sane ASSERT_TRUE(lease); checkLease4(lease); // Check the valid lifetime has the min value. EXPECT_EQ(subnet_->getValid().getMin(), lease->valid_lft_); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // Do it again, this should amount to the renew of an existing lease Lease4Ptr lease2 = engine->allocateLease4(ctx); // Check that we got a lease and it's sane ASSERT_TRUE(lease2); checkLease4(lease2); // Lease already existed, so old_lease should be set. EXPECT_TRUE(ctx.old_lease_); // Check the renewed valid lifetime has the min value. EXPECT_EQ(subnet_->getValid().getMin(), lease2->valid_lft_); } // This test checks simple renewal uses the max valid lifetime. TEST_F(AllocEngine4Test, maxRenew4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, true, "somehost.example.com.", false); subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); // Speficy the valid lifetime we want, as it is greater than the max value // we'll get this max value instead. OptionUint32Ptr opt(new OptionUint32(Option::V4, DHO_DHCP_LEASE_TIME, 6)); ctx.query_->addOption(opt); Lease4Ptr lease = engine->allocateLease4(ctx); // Check that we got a lease and it's sane ASSERT_TRUE(lease); checkLease4(lease); // Check the valid lifetime has the max value. EXPECT_EQ(subnet_->getValid().getMax(), lease->valid_lft_); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // Do it again, this should amount to the renew of an existing lease Lease4Ptr lease2 = engine->allocateLease4(ctx); // Check that we got a lease and it's sane ASSERT_TRUE(lease2); checkLease4(lease2); // Lease already existed, so old_lease should be set. EXPECT_TRUE(ctx.old_lease_); // Check the renewed valid lifetime has the max value. EXPECT_EQ(subnet_->getValid().getMax(), lease2->valid_lft_); } // This test checks simple renewal handles BOOTP queries. TEST_F(AllocEngine4Test, bootpRenew4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, true, "somehost.example.com.", false); subnet_->setValid(Triplet<uint32_t>(1, 3, 5)); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); // Make the query a BOOTP one. ctx.query_->addClass("BOOTP"); Lease4Ptr lease = engine->allocateLease4(ctx); // Check that we got a lease. ASSERT_TRUE(lease); // Check that is belongs to the right subnet and client. EXPECT_EQ(lease->subnet_id_, subnet_->getID()); EXPECT_TRUE(subnet_->inRange(lease->addr_)); EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, lease->addr_)); ASSERT_TRUE(lease->client_id_); EXPECT_TRUE(*lease->client_id_ == *clientid_); ASSERT_TRUE(lease->hwaddr_); EXPECT_TRUE(*lease->hwaddr_ == *hwaddr_); // Check the valid lifetime is infinite. uint32_t infinity_lft = Lease::INFINITY_LFT; EXPECT_EQ(infinity_lft, lease->valid_lft_); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // Do it again, this should amount to the renew of an existing lease Lease4Ptr lease2 = engine->allocateLease4(ctx); // Check that we got a lease. ASSERT_TRUE(lease2); // Check that is belongs to the right subnet and client. EXPECT_EQ(lease2->subnet_id_, subnet_->getID()); EXPECT_TRUE(subnet_->inRange(lease2->addr_)); EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, lease2->addr_)); ASSERT_TRUE(lease2->client_id_); EXPECT_TRUE(*lease2->client_id_ == *clientid_); ASSERT_TRUE(lease2->hwaddr_); EXPECT_TRUE(*lease2->hwaddr_ == *hwaddr_); // Lease already existed, so old_lease should be set. EXPECT_TRUE(ctx.old_lease_); // Check the renewed valid lifetime has the max value. EXPECT_EQ(infinity_lft, lease2->valid_lft_); } // This test verifies that the allocator picks addresses that belong to the // pool TEST_F(AllocEngine4Test, IterativeAllocator) { boost::scoped_ptr<NakedAllocEngine::Allocator> alloc(new NakedAllocEngine::IterativeAllocator(Lease::TYPE_V4)); for (int i = 0; i < 1000; ++i) { IOAddress candidate = alloc->pickAddress(subnet_, cc_, clientid_, IOAddress("0.0.0.0")); EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate)); } } // This test verifies that the allocator picks addresses that belong to the // pool using classification TEST_F(AllocEngine4Test, IterativeAllocator_class) { boost::scoped_ptr<NakedAllocEngine::Allocator> alloc(new NakedAllocEngine::IterativeAllocator(Lease::TYPE_V4)); // Restrict pool_ to the foo class. Add a second pool with bar class. pool_->allowClientClass("foo"); Pool4Ptr pool(new Pool4(IOAddress("192.0.2.200"), IOAddress("192.0.2.209"))); pool->allowClientClass("bar"); subnet_->addPool(pool); // Clients are in bar cc_.insert("bar"); for (int i = 0; i < 1000; ++i) { IOAddress candidate = alloc->pickAddress(subnet_, cc_, clientid_, IOAddress("0.0.0.0")); EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate)); EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate, cc_)); } } // This test verifies that the iterative allocator really walks over all addresses // in all pools in specified subnet. It also must not pick the same address twice // unless it runs out of pool space and must start over. TEST_F(AllocEngine4Test, IterativeAllocator_manyPools4) { NakedAllocEngine::IterativeAllocator alloc(Lease::TYPE_V4); // Let's start from 2, as there is 2001:db8:1::10 - 2001:db8:1::20 pool already. for (int i = 2; i < 10; ++i) { stringstream min, max; min << "192.0.2." << i * 10 + 1; max << "192.0.2." << i * 10 + 9; Pool4Ptr pool(new Pool4(IOAddress(min.str()), IOAddress(max.str()))); // cout << "Adding pool: " << min.str() << "-" << max.str() << endl; subnet_->addPool(pool); } int total = 10 + 8 * 9; // first pool (.100 - .109) has 10 addresses in it, // there are 8 extra pools with 9 addresses in each. // Let's keep picked addresses here and check their uniqueness. std::set<IOAddress> generated_addrs; int cnt = 0; while (++cnt) { IOAddress candidate = alloc.pickAddress(subnet_, cc_, clientid_, IOAddress("0.0.0.0")); EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, candidate)); // One way to easily verify that the iterative allocator really works is // to uncomment the following line and observe its output that it // covers all defined subnets. // cout << candidate.toText() << endl; if (generated_addrs.find(candidate) == generated_addrs.end()) { // We haven't had this generated_addrs.insert(candidate); } else { // We have seen this address before. That should mean that we // iterated over all addresses. if (generated_addrs.size() == total) { // We have exactly the number of address in all pools break; } ADD_FAILURE() << "Too many or not enough unique addresses generated."; break; } if ( cnt>total ) { ADD_FAILURE() << "Too many unique addresses generated."; break; } } } // This test checks if really small pools are working TEST_F(AllocEngine4Test, smallPool4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); IOAddress addr("192.0.2.17"); CfgMgr& cfg_mgr = CfgMgr::instance(); // Get rid of the default subnet configuration. cfg_mgr.clear(); // Create configuration similar to other tests, but with a single address pool subnet_ = Subnet4Ptr(new Subnet4(IOAddress("192.0.2.0"), 24, 1, 2, 3)); pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address subnet_->addPool(pool_); cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "host.example.com.", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr lease = engine->allocateLease4(ctx); // Check that we got that single lease ASSERT_TRUE(lease); // We have allocated new lease, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); EXPECT_EQ("192.0.2.17", lease->addr_.toText()); // Do all checks on the lease checkLease4(lease); // Check that the lease is indeed in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); } // This test checks if all addresses in a pool are currently used, the attempt // to find out a new lease fails. TEST_F(AllocEngine4Test, outOfAddresses4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); IOAddress addr("192.0.2.17"); CfgMgr& cfg_mgr = CfgMgr::instance(); // Get rid of the default test configuration. cfg_mgr.clear(); // Create configuration similar to other tests, but with a single address pool subnet_ = Subnet4Ptr(new Subnet4(IOAddress("192.0.2.0"), 24, 1, 2, 3)); pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address subnet_->addPool(pool_); cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); // Just a different hw/client-id for the second client uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe}; HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; time_t now = time(NULL); Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), 501, now, subnet_->getID())); lease->cltt_ = time(NULL) - 10; // Allocated 10 seconds ago ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // There is just a single address in the pool and allocated it to someone // else, so the allocation should fail AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "host.example.com.", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr lease2 = engine->allocateLease4(ctx); EXPECT_FALSE(lease2); EXPECT_FALSE(ctx.old_lease_); } /// @brief This test class is dedicated to testing shared networks /// /// It uses one common configuration: /// 1 shared network with 2 subnets: /// - 192.0.2.0/24 subnet with a small pool of single address: 192.0.2.17 /// - 10.1.2.0/24 subnet with pool with 96 addresses. class SharedNetworkAlloc4Test : public AllocEngine4Test { public: /// @brief Initializes configuration (2 subnets, 1 shared network) SharedNetworkAlloc4Test() :engine_(AllocEngine::ALLOC_ITERATIVE, 0, false) { // Create two subnets, each with a single address pool. The first subnet // has only one address in its address pool to make it easier to simulate // address exhaustion. subnet1_.reset(new Subnet4(IOAddress("192.0.2.0"), 24, 1, 2, 3, SubnetID(1))); subnet2_.reset(new Subnet4(IOAddress("10.1.2.0"), 24, 1, 2, 3, SubnetID(2))); pool1_.reset(new Pool4(IOAddress("192.0.2.17"), IOAddress("192.0.2.17"))); pool2_.reset(new Pool4(IOAddress("10.1.2.5"), IOAddress("10.1.2.100"))); subnet1_->addPool(pool1_); subnet2_->addPool(pool2_); // Both subnets belong to the same network so they can be used // interchangeably. network_.reset(new SharedNetwork4("test_network")); network_->add(subnet1_); network_->add(subnet2_); std::vector<uint8_t> hwaddr_vec = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe}; hwaddr2_.reset(new HWAddr(hwaddr_vec, HTYPE_ETHER)); } /// @brief Inserts a new lease for specified address /// /// Creates a new lease for specified address and subnet-id and inserts /// it into database. This is not particularly fancy method, it is used /// just to mark existing addresses as used. It uses hwaddr2_ to allocate /// the lease. /// /// @param addr text representation of the address /// @param subnet_id ID of the subnet /// @param return pointer to the lease Lease4Ptr insertLease(std::string addr, SubnetID subnet_id) { Lease4Ptr lease(new Lease4(IOAddress(addr), hwaddr2_, ClientIdPtr(), 501, time(NULL), subnet_id)); lease->cltt_ = time(NULL) - 10; // Allocated 10 seconds ago if (!LeaseMgrFactory::instance().addLease(lease)) { ADD_FAILURE() << "Attempt to add a lease for IP " << addr << " in subnet " << subnet_id << " failed"; } return (lease); } /// Covenience pointers to configuration elements. These are initialized /// in the constructor and are used throughout the tests. AllocEngine engine_; Subnet4Ptr subnet1_; Subnet4Ptr subnet2_; Pool4Ptr pool1_; Pool4Ptr pool2_; SharedNetwork4Ptr network_; HWAddrPtr hwaddr2_; // Note there's hwaddr_ already defined in base class. }; // This test verifies that the server can offer an address from a // subnet and the introduction of shared network doesn't break anything here. TEST_F(SharedNetworkAlloc4Test, discoverSharedNetworkSimple) { // Create context which will be used to try to allocate leases from the // shared network. The context points to subnet1, which address space // is exhausted. We expect the allocation engine to find another subnet // within the same shared network and offer an address from there. AllocEngine::ClientContext4 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "host.example.com.", true); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); Lease4Ptr lease = engine_.allocateLease4(ctx); // The allocation engine should have assigned an address from the first // subnet. ASSERT_TRUE(lease); EXPECT_EQ("192.0.2.17", lease->addr_.toText()); // Make sure the lease is not in the the lease mgr (this is only // discover). ASSERT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_)); } // This test verifies that the server will pick a second subnet out of two // shared subnets if there is a hint for the second subnet. TEST_F(SharedNetworkAlloc4Test, discoverSharedNetworkHint) { // Create context which will be used to try to allocate leases from the // shared network. The context points to subnet1, which address space // is exhausted. We expect the allocation engine to find another subnet // within the same shared network and offer an address from there. AllocEngine::ClientContext4 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress("10.1.2.25"), false, false, "host.example.com.", true); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); Lease4Ptr lease = engine_.allocateLease4(ctx); // The allocation engine should have assigned an address from the second // subnet, because that's what the hint requested. ASSERT_TRUE(lease); EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_)); } // This test verifies that the server can offer an address from a // different subnet than orginally selected, when the address pool in // the first subnet is exhausted. TEST_F(SharedNetworkAlloc4Test, discoverSharedNetwork) { // Create a lease for a single address in the first address pool. The // pool is now exhausted. Lease4Ptr lease = insertLease("192.0.2.17", subnet1_->getID()); // Create context which will be used to try to allocate leases from the // shared network. The context points to subnet1, which address space // is exhausted. We expect the allocation engine to find another subnet // within the same shared network and offer an address from there. AllocEngine::ClientContext4 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "host.example.com.", true); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); Lease4Ptr lease2 = engine_.allocateLease4(ctx); // The allocation engine should have assigned an address from the second // subnet. We could guess that this is 10.1.2.5, being the first address // in the address pool, but to make the test more generic, we merely // verify that the address is in the given address pool. ASSERT_TRUE(lease2); EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease2->addr_)); // The client should also be offered a lease when it specifies a hint // that doesn't match the subnet from which the lease is offered. The // engine should check alternative subnets to match the hint to // a subnet. The requested lease is available, so it should be offered. ctx.subnet_ = subnet1_; ctx.requested_address_ = IOAddress("10.1.2.25"); lease2 = engine_.allocateLease4(ctx); ASSERT_TRUE(lease2); EXPECT_EQ("10.1.2.25", lease2->addr_.toText()); // The returning client (the one that has a lease) should also be able // to renew its lease regardless of a subnet it begins with. So, it has // an address assigned from subnet1, but we use subnet2 as a selected // subnet. AllocEngine::ClientContext4 ctx2(subnet2_, ClientIdPtr(), hwaddr2_, IOAddress("0.0.0.0"), false, false, "host.example.com.", true); ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); lease2 = engine_.allocateLease4(ctx2); // The existing lease should be returned. ASSERT_TRUE(lease2); EXPECT_EQ("192.0.2.17", lease2->addr_.toText()); } // This test verifies that the server can offer an address from a // different subnet than orginally selected, when the address pool in // the first subnet is exhausted. TEST_F(SharedNetworkAlloc4Test, discoverSharedNetworkClassification) { // Try to offer address from subnet1. There is one address available // so it should be offerred. AllocEngine::ClientContext4 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "host.example.com.", true); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); Lease4Ptr lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_)); // Apply restrictions on the subnet1. This should be only assigned // to clients belonging to cable-modem class. subnet1_->allowClientClass("cable-modem"); // The allocation engine should determine that the subnet1 is not // available for the client not belonging to the cable-modem class. // Instead, it should offer an address from subnet2 that belongs // to the same shared network. ctx.subnet_ = subnet1_; lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_)); // Create reservation for the client in subnet1. Because this subnet is // not allowed for the client the client should still be offerred a // lease from subnet2. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet1_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.17"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); AllocEngine::findReservation(ctx); ctx.subnet_ = subnet1_; lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_)); // Assign cable-modem class and try again. This time, we should // offer an address from the subnet1. ctx.query_->addClass(ClientClass("cable-modem")); ctx.subnet_ = subnet1_; lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("192.0.2.17", lease->addr_.toText()); } // This test verifies that the server can offer an address from a // different subnet than orginally selected, when the address pool in // the first subnet requires another class. TEST_F(SharedNetworkAlloc4Test, discoverSharedNetworkPoolClassification) { // Try to offer address from subnet1. There is one address available // so it should be offerred. AllocEngine::ClientContext4 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "host.example.com.", true); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); Lease4Ptr lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_)); // Apply restrictions on the pool1. This should be only assigned // to clients belonging to cable-modem class. pool1_->allowClientClass("cable-modem"); // The allocation engine should determine that the pool1 is not // available for the client not belonging to the cable-modem class. // Instead, it should offer an address from subnet2 that belongs // to the same shared network. ctx.subnet_ = subnet1_; lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_)); // Assign cable-modem class and try again. This time, we should // offer an address from the pool1. ctx.query_->addClass(ClientClass("cable-modem")); // Restrict access to pool2 for this client, to make sure that the // server doesn't accidentally get an address from this pool. pool2_->allowClientClass("telephone"); ctx.subnet_ = subnet1_; lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("192.0.2.17", lease->addr_.toText()); } // Test that reservations within shared network take precedence over the // existing leases regardless in which subnet belonging to a shared network // reservations belong. TEST_F(SharedNetworkAlloc4Test, discoverSharedNetworkReservations) { EXPECT_FALSE(HostMgr::instance().getDisableSingleQuery()); // Create reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet2_->getID(), SUBNET_ID_UNUSED, IOAddress("10.2.3.23"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // Start allocation from subnet1. The engine should determine that the // client has reservations in subnet2 and should rather assign reserved // addresses. AllocEngine::ClientContext4 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "host.example.com.", true); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); AllocEngine::findReservation(ctx); Lease4Ptr lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("10.2.3.23", lease->addr_.toText()); // Let's create a lease for the client to make sure the lease is not // renewed but a reserved lease is offerred. Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), 501, time(NULL), subnet1_->getID())); lease->cltt_ = time(NULL) - 10; // Allocated 10 seconds ago ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease2)); ctx.subnet_ = subnet1_; AllocEngine::findReservation(ctx); lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("10.2.3.23", lease->addr_.toText()); } // Test that reservations within shared network take precedence over the // existing leases regardless in which subnet belonging to a shared network // reservations belong. Host lookups returning a collection are disabled. // As it is only an optimization the behavior (so the test) must stay // unchanged. TEST_F(SharedNetworkAlloc4Test, discoverSharedNetworkReservationsNoColl) { // Disable host lookups returning a collection. ASSERT_FALSE(HostMgr::instance().getDisableSingleQuery()); HostMgr::instance().setDisableSingleQuery(true); // Create reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet2_->getID(), SUBNET_ID_UNUSED, IOAddress("10.2.3.23"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // Start allocation from subnet1. The engine should determine that the // client has reservations in subnet2 and should rather assign reserved // addresses. AllocEngine::ClientContext4 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "host.example.com.", true); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); AllocEngine::findReservation(ctx); Lease4Ptr lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("10.2.3.23", lease->addr_.toText()); // Let's create a lease for the client to make sure the lease is not // renewed but a reserved lease is offerred. Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), 501, time(NULL), subnet1_->getID())); lease->cltt_ = time(NULL) - 10; // Allocated 10 seconds ago ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease2)); ctx.subnet_ = subnet1_; AllocEngine::findReservation(ctx); lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("10.2.3.23", lease->addr_.toText()); } // This test verifies that the server can offer an address from a shared // subnet if there's at least 1 address left there, but will not offer // anything if both subnets are completely full. TEST_F(SharedNetworkAlloc4Test, runningOut) { // Allocate everything in subnet1 insertLease("192.0.2.17", subnet1_->getID()); // Allocate everything, except one address in subnet2. for (int i = 5; i < 100; i++) { stringstream tmp; tmp << "10.1.2." << i; insertLease(tmp.str(), subnet2_->getID()); } // Create context which will be used to try to allocate leases from the // shared network. The context points to subnet1, which address space // is exhausted. We expect the allocation engine to find another subnet // within the same shared network and offer an address from there. AllocEngine::ClientContext4 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "host.example.com.", true); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); Lease4Ptr lease = engine_.allocateLease4(ctx); EXPECT_TRUE(lease); // Now allocate the last address. Now both subnets are exhausted. insertLease("10.1.2.100", subnet2_->getID()); // Ok, we're out. We should not get anything now. lease = engine_.allocateLease4(ctx); EXPECT_FALSE(lease); } // This test verifies that the server can offer an address from a // subnet and the introduction of shared network doesn't break anything here. TEST_F(SharedNetworkAlloc4Test, requestSharedNetworkSimple) { // Create context which will be used to try to allocate leases from the // shared network. The context points to subnet1, which address space // is exhausted. We expect the allocation engine to find another subnet // within the same shared network and offer an address from there. AllocEngine::ClientContext4 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "host.example.com.", false); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); Lease4Ptr lease = engine_.allocateLease4(ctx); // The allocation engine should have assigned an address from the first // subnet. ASSERT_TRUE(lease); EXPECT_EQ("192.0.2.17", lease->addr_.toText()); // Make sure the lease is in the the lease mgr. ASSERT_TRUE(LeaseMgrFactory::instance().getLease4(lease->addr_)); } // This test verifies that the server can allocate an address from a // different subnet than orginally selected, when the address pool in // the first subnet is exhausted. TEST_F(SharedNetworkAlloc4Test, requestSharedNetwork) { // Create a lease for a single address in the first address pool. The // pool is now exhausted. Lease4Ptr lease = insertLease("192.0.2.17", subnet1_->getID()); // Create context which will be used to try to allocate leases from the // shared network. The context points to subnet1, which address space // is exhausted. We expect the allocation engine to find another subnet // within the same shared network and offer an address from there. AllocEngine::ClientContext4 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "host.example.com.", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr lease2 = engine_.allocateLease4(ctx); // The allocation engine should have assigned an address from the second // subnet. We could guess that this is 10.1.2.5, being the first address // in the address pool, but to make the test more generic, we merely // verify that the address is in the given address pool. ASSERT_TRUE(lease2); EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease2->addr_)); ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease2)); // The client should also be assigned a lease when it specifies a hint // that doesn't match the subnet from which the lease is offered. The // engine should check alternative subnets to match the hint to // a subnet. The requested lease is available, so it should be offered. ctx.subnet_ = subnet1_; ctx.requested_address_ = IOAddress("10.1.2.25"); lease2 = engine_.allocateLease4(ctx); ASSERT_TRUE(lease2); EXPECT_EQ("10.1.2.25", lease2->addr_.toText()); // The returning client (the one that has a lease) should also be able // to renew its lease regardless of a subnet it begins with. So, it has // an address assigned from subnet1, but we use subnet2 as a selected // subnet. AllocEngine::ClientContext4 ctx2(subnet2_, ClientIdPtr(), hwaddr2_, IOAddress("0.0.0.0"), false, false, "host.example.com.", false); ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); lease2 = engine_.allocateLease4(ctx2); // The existing lease should be returned. ASSERT_TRUE(lease2); EXPECT_EQ("192.0.2.17", lease2->addr_.toText()); } // This test verifies that the server can assign an address from a // different subnet than orginally selected, when the address pool in // the first subnet is exhausted. TEST_F(SharedNetworkAlloc4Test, requestSharedNetworkClassification) { // Try to offer address from subnet1. There is one address available // so it should be offerred. AllocEngine::ClientContext4 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "host.example.com.", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_)); // Remove the lease so as we can start over. ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease)); // Apply restrictions on the subnet1. This should be only assigned // to clients belonging to cable-modem class. subnet1_->allowClientClass("cable-modem"); // The allocation engine should determine that the subnet1 is not // available for the client not belonging to the cable-modem class. // Instead, it should assign an address from subnet2 that belongs // to the same shared network. ctx.subnet_ = subnet1_; lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_)); // Remove the lease so as we can start over. ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease)); // Assign cable-modem class and try again. This time, we should // offer an address from the subnet1. ctx.query_->addClass(ClientClass("cable-modem")); ctx.subnet_ = subnet1_; lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_)); // Let's now remove the client from the cable-modem class and try // to renew the address. The engine should determine that the // client doesn't have access to the subnet1 pools anymore and // assign an address from unrestricted subnet. ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); ctx.subnet_ = subnet1_; lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_)); } // This test verifies that the server can assign an address from a // different subnet than orginally selected, when the address pool in // the first subnet requires another class. TEST_F(SharedNetworkAlloc4Test, requestSharedNetworkPoolClassification) { // Try to offer address from subnet1. There is one address available // so it should be offerred. AllocEngine::ClientContext4 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "host.example.com.", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_)); // Remove the lease so as we can start over. ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease)); // Apply restrictions on the pool1. This should be only assigned // to clients belonging to cable-modem class. pool1_->allowClientClass("cable-modem"); // The allocation engine should determine that the pool1 is not // available for the client not belonging to the cable-modem class. // Instead, it should assign an address from subnet2 that belongs // to the same shared network. ctx.subnet_ = subnet1_; lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_)); // Remove the lease so as we can start over. ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease)); // Assign cable-modem class and try again. This time, we should // offer an address from the pool1. ctx.query_->addClass(ClientClass("cable-modem")); // Restrict access to pool2 for this client, to make sure that the // server doesn't accidentally get an address from this pool. pool2_->allowClientClass("telephone"); ctx.subnet_ = subnet1_; lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_TRUE(subnet1_->inPool(Lease::TYPE_V4, lease->addr_)); // Let's now remove the client from the cable-modem class and try // to renew the address. The engine should determine that the // client doesn't have access to the pool1 anymore and // assign an address from another pool. ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); ctx.query_->addClass(ClientClass("telephone")); ctx.subnet_ = subnet1_; lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_TRUE(subnet2_->inPool(Lease::TYPE_V4, lease->addr_)); } // Test that reservations within shared network take precedence over the // existing leases regardless in which subnet belonging to a shared network // reservations belong (DHCPREQUEST case). TEST_F(SharedNetworkAlloc4Test, requestSharedNetworkReservations) { EXPECT_FALSE(HostMgr::instance().getDisableSingleQuery()); // Create reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet2_->getID(), SUBNET_ID_UNUSED, IOAddress("10.2.3.23"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // Start allocation from subnet1. The engine should determine that the // client has reservations in subnet2 and should rather assign reserved // addresses. AllocEngine::ClientContext4 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "host.example.com.", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx); Lease4Ptr lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("10.2.3.23", lease->addr_.toText()); // Remove the lease for another test below. ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease)); // Let's create a lease for the client to make sure the lease is not // renewed but a reserved lease is allocated again. Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), 501, time(NULL), subnet1_->getID())); lease->cltt_ = time(NULL) - 10; // Allocated 10 seconds ago ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease2)); ctx.subnet_ = subnet1_; AllocEngine::findReservation(ctx); lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("10.2.3.23", lease->addr_.toText()); } // Test that reservations within shared network take precedence over the // existing leases regardless in which subnet belonging to a shared network // reservations belong (DHCPREQUEST case). Host lookups returning a collection // are disabled. As it is only an optimization the behavior (so the test) // must stay unchanged. TEST_F(SharedNetworkAlloc4Test, requestSharedNetworkReservationsNoColl) { // Disable host lookups returning a collection. ASSERT_FALSE(HostMgr::instance().getDisableSingleQuery()); HostMgr::instance().setDisableSingleQuery(true); // Create reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet2_->getID(), SUBNET_ID_UNUSED, IOAddress("10.2.3.23"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // Start allocation from subnet1. The engine should determine that the // client has reservations in subnet2 and should rather assign reserved // addresses. AllocEngine::ClientContext4 ctx(subnet1_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "host.example.com.", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx); Lease4Ptr lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("10.2.3.23", lease->addr_.toText()); // Remove the lease for another test below. ASSERT_TRUE(LeaseMgrFactory::instance().deleteLease(lease)); // Let's create a lease for the client to make sure the lease is not // renewed but a reserved lease is allocated again. Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.17"), hwaddr_, ClientIdPtr(), 501, time(NULL), subnet1_->getID())); lease->cltt_ = time(NULL) - 10; // Allocated 10 seconds ago ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease2)); ctx.subnet_ = subnet1_; AllocEngine::findReservation(ctx); lease = engine_.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("10.2.3.23", lease->addr_.toText()); } // This test checks if an expired lease can be reused in DHCPDISCOVER (fake // allocation) TEST_F(AllocEngine4Test, discoverReuseExpiredLease4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); IOAddress addr("192.0.2.15"); CfgMgr& cfg_mgr = CfgMgr::instance(); // Get rid of the default test configuration. cfg_mgr.clear(); // Create configuration similar to other tests, but with a single address pool subnet_ = Subnet4Ptr(new Subnet4(IOAddress("192.0.2.0"), 24, 1, 2, 3)); pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address subnet_->addPool(pool_); cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); // Just a different hw/client-id for the second client uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe}; HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; time_t now = time(NULL) - 500; // Allocated 500 seconds ago Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), 495, now, subnet_->getID())); // Copy the lease, so as it can be compared with the old lease returned // by the allocation engine. Lease4 original_lease(*lease); // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it // is expired already ASSERT_TRUE(lease->expired()); ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // CASE 1: Asking for any address AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", true); ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); lease = engine->allocateLease4(ctx1); // Check that we got that single lease ASSERT_TRUE(lease); EXPECT_EQ(addr, lease->addr_); // We are reusing expired lease, the old (expired) instance should be // returned. The returned instance should be the same as the original // lease. ASSERT_TRUE(ctx1.old_lease_); EXPECT_TRUE(original_lease == *ctx1.old_lease_); // Do all checks on the lease (if subnet-id, preferred/valid times are ok etc.) checkLease4(lease); // CASE 2: Asking specifically for this address AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, IOAddress(addr), false, false, "", true); ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); lease = engine->allocateLease4(ctx2); // Check that we got that single lease ASSERT_TRUE(lease); EXPECT_EQ(addr, lease->addr_); // We are updating expired lease. The copy of the old lease should be // returned and it should be equal to the original lease. ASSERT_TRUE(ctx2.old_lease_); EXPECT_TRUE(*ctx2.old_lease_ == original_lease); } // This test checks if an expired lease can be reused in REQUEST (actual allocation) TEST_F(AllocEngine4Test, requestReuseExpiredLease4) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); IOAddress addr("192.0.2.105"); EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID())); int64_t cumulative = getStatistics("cumulative-assigned-addresses", subnet_->getID()); int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); EXPECT_TRUE(testStatistics("reclaimed-leases", 0)); EXPECT_TRUE(testStatistics("reclaimed-leases", 0, subnet_->getID())); // Just a different hw/client-id for the second client uint8_t hwaddr2_data[] = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe}; HWAddrPtr hwaddr2(new HWAddr(hwaddr2_data, sizeof(hwaddr2_data), HTYPE_ETHER)); uint8_t clientid2[] = { 8, 7, 6, 5, 4, 3, 2, 1 }; time_t now = time(NULL) - 500; // Allocated 500 seconds ago Lease4Ptr lease(new Lease4(addr, hwaddr2, clientid2, sizeof(clientid2), 495, now, subnet_->getID())); // Make a copy of the lease, so as we can compare that with the old lease // instance returned by the allocation engine. Lease4 original_lease(*lease); // Lease was assigned 500 seconds ago, but its valid lifetime is 495, so it // is expired already ASSERT_TRUE(lease->expired()); ASSERT_TRUE(LeaseMgrFactory::instance().addLease(lease)); // A client comes along, asking specifically for this address AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress(addr), false, false, "host.example.com.", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); lease = engine->allocateLease4(ctx); // Check that he got that single lease ASSERT_TRUE(lease); EXPECT_EQ(addr, lease->addr_); // Check that the lease is indeed updated in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); // The allocation engine should return a copy of the old lease. This // lease should be equal to the original lease. ASSERT_TRUE(ctx.old_lease_); EXPECT_TRUE(*ctx.old_lease_ == original_lease); // Check that the stats declined stats were modified correctly. Note, because // added the lease directly, assigned-leases never bumped to one, so when we // reclaim it gets decremented to -1, then on assignment back to 0. EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID())); cumulative += 1; EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", cumulative, subnet_->getID())); glbl_cumulative += 1; EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative)); EXPECT_TRUE(testStatistics("reclaimed-leases", 1)); EXPECT_TRUE(testStatistics("reclaimed-leases", 1, subnet_->getID())); } // This test checks if an expired declined lease can be reused when responding // to DHCPDISCOVER (fake allocation) TEST_F(AllocEngine4Test, discoverReuseDeclinedLease4) { AllocEnginePtr engine(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false)); ASSERT_TRUE(engine); // Now prepare a configuration with single address pool. IOAddress addr("192.0.2.15"); CfgMgr& cfg_mgr = CfgMgr::instance(); cfg_mgr.clear(); subnet_ = Subnet4Ptr(new Subnet4(IOAddress("192.0.2.0"), 24, 1, 2, 3)); pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address subnet_->addPool(pool_); cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); // Now create a declined lease, decline it and rewind its cltt, so it // is expired. Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); // CASE 1: Ask for any address Lease4Ptr assigned; testReuseLease4(engine, declined, "0.0.0.0", true, SHOULD_PASS, assigned); // Check that we got that single lease ASSERT_TRUE(assigned); EXPECT_EQ(addr, assigned->addr_); // CASE 2: Asking specifically for this address testReuseLease4(engine, declined, "192.0.2.15", true, SHOULD_PASS, assigned); // Check that we get it again ASSERT_TRUE(assigned); EXPECT_EQ(addr, assigned->addr_); } // This test checks if statistics are not updated when expired declined lease // is reused when responding to DHCPDISCOVER (fake allocation) TEST_F(AllocEngine4Test, discoverReuseDeclinedLease4Stats) { // Now prepare for DISCOVER processing AllocEnginePtr engine(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false)); ASSERT_TRUE(engine); // Now prepare a configuration with single address pool. IOAddress addr("192.0.2.15"); CfgMgr& cfg_mgr = CfgMgr::instance(); cfg_mgr.clear(); subnet_ = Subnet4Ptr(new Subnet4(IOAddress("192.0.2.0"), 24, 1, 2, 3)); pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address subnet_->addPool(pool_); cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); cfg_mgr.commit(); // so we will recalc stats int64_t cumulative = getStatistics("cumulative-assigned-addresses", subnet_->getID()); int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); // Now create a declined lease, decline it and rewind its cltt, so it // is expired. Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); // Ask for any address. There's only one address in the pool, so it doesn't // matter much. Lease4Ptr assigned; testReuseLease4(engine, declined, "0.0.0.0", true, SHOULD_PASS, assigned); // Check that the stats declined stats were not modified EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID())); EXPECT_EQ(cumulative, getStatistics("cumulative-assigned-addresses", subnet_->getID())); EXPECT_EQ(glbl_cumulative, getStatistics("cumulative-assigned-addresses")); EXPECT_TRUE(testStatistics("declined-addresses", 0)); EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 0)); EXPECT_TRUE(testStatistics("declined-addresses", 0, subnet_->getID())); EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 0, subnet_->getID())); } // This test checks if an expired declined lease can be reused when responding // to REQUEST (actual allocation) TEST_F(AllocEngine4Test, requestReuseDeclinedLease4) { AllocEnginePtr engine(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false)); ASSERT_TRUE(engine); // Now prepare a configuration with single address pool. IOAddress addr("192.0.2.15"); CfgMgr& cfg_mgr = CfgMgr::instance(); cfg_mgr.clear(); subnet_ = Subnet4Ptr(new Subnet4(IOAddress("192.0.2.0"), 24, 1, 2, 3)); pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address subnet_->addPool(pool_); cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); // Now create a declined lease, decline it and rewind its cltt, so it // is expired. Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); // Asking specifically for this address Lease4Ptr assigned; testReuseLease4(engine, declined, "192.0.2.15", false, SHOULD_PASS, assigned); // Check that we got it. ASSERT_TRUE(assigned); EXPECT_EQ(addr, assigned->addr_); // Check that the lease is indeed updated in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(addr); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(assigned, from_mgr); } // This test checks if statistics are not updated when expired declined lease // is reused when responding to DHCPREQUEST (actual allocation) TEST_F(AllocEngine4Test, requestReuseDeclinedLease4Stats) { AllocEnginePtr engine(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false)); ASSERT_TRUE(engine); // Now prepare a configuration with single address pool. IOAddress addr("192.0.2.15"); CfgMgr& cfg_mgr = CfgMgr::instance(); cfg_mgr.clear(); subnet_ = Subnet4Ptr(new Subnet4(IOAddress("192.0.2.0"), 24, 1, 2, 3)); pool_ = Pool4Ptr(new Pool4(addr, addr)); // just a single address subnet_->addPool(pool_); cfg_mgr.getStagingCfg()->getCfgSubnets4()->add(subnet_); cfg_mgr.commit(); int64_t cumulative = getStatistics("cumulative-assigned-addresses", subnet_->getID()); int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); // Now create a declined lease, decline it and rewind its cltt, so it // is expired. Lease4Ptr declined = generateDeclinedLease("192.0.2.15", 100, -10); // Asking specifically for this address Lease4Ptr assigned; testReuseLease4(engine, declined, "192.0.2.15", false, SHOULD_PASS, assigned); // Check that we got it. ASSERT_TRUE(assigned); // Check that the stats are correct. Note that assigned-addresses does // not get decremented when a lease is declined, ergo not incremented // when it is reused. Declined address stats will be -1 since // lease was created as declined which does not increment the stat. EXPECT_TRUE(testStatistics("assigned-addresses", 0, subnet_->getID())); cumulative += 1; EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", cumulative, subnet_->getID())); glbl_cumulative += 1; EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative)); EXPECT_TRUE(testStatistics("declined-addresses", -1)); EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 1)); EXPECT_TRUE(testStatistics("declined-addresses", -1, subnet_->getID())); EXPECT_TRUE(testStatistics("reclaimed-declined-addresses", 1, subnet_->getID())); } // This test checks that the Allocation Engine correctly identifies the // existing client's lease in the lease database, using the client // identifier and HW address. TEST_F(AllocEngine4Test, identifyClientLease) { Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, clientid_, 100, time(NULL), subnet_->getID())); LeaseMgrFactory::instance().addLease(lease); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "", true); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr identified_lease = engine.allocateLease4(ctx); ASSERT_TRUE(identified_lease); EXPECT_EQ("192.0.2.101", identified_lease->addr_.toText()); ctx.hwaddr_ = hwaddr2_; ctx.clientid_ = clientid_; identified_lease = engine.allocateLease4(ctx); ASSERT_TRUE(identified_lease); EXPECT_EQ("192.0.2.101", identified_lease->addr_.toText()); ctx.hwaddr_ = hwaddr_; ctx.clientid_ = clientid2_; identified_lease = engine.allocateLease4(ctx); ASSERT_TRUE(identified_lease); EXPECT_NE(identified_lease->addr_.toText(), "192.0.2.101"); ctx.hwaddr_ = hwaddr_; ctx.clientid_.reset(); identified_lease = engine.allocateLease4(ctx); ASSERT_TRUE(identified_lease); EXPECT_EQ("192.0.2.101", identified_lease->addr_.toText()); ctx.hwaddr_ = hwaddr2_; ctx.clientid_.reset(); identified_lease = engine.allocateLease4(ctx); ASSERT_TRUE(identified_lease); EXPECT_NE(identified_lease->addr_.toText(), "192.0.2.101"); lease->client_id_.reset(); ASSERT_NO_THROW(LeaseMgrFactory::instance().updateLease4(lease)); ctx.hwaddr_ = hwaddr_; ctx.clientid_ = clientid_; identified_lease = engine.allocateLease4(ctx); ASSERT_TRUE(identified_lease); EXPECT_EQ("192.0.2.101", identified_lease->addr_.toText()); ctx.hwaddr_ = hwaddr_; ctx.clientid_.reset(); identified_lease = engine.allocateLease4(ctx); ASSERT_TRUE(identified_lease); EXPECT_EQ("192.0.2.101", identified_lease->addr_.toText()); ctx.hwaddr_ = hwaddr2_; ctx.clientid_ = clientid_; identified_lease = engine.allocateLease4(ctx); ASSERT_TRUE(identified_lease); EXPECT_NE(identified_lease->addr_.toText(), "192.0.2.101"); } // This test checks that when the client requests the address which belongs // to another client, the allocation engine returns NULL (for the // DHCPREQUEST case) or a lease for the address which belongs to this // client (DHCPDISCOVER case). TEST_F(AllocEngine4Test, requestOtherClientLease) { // Create the first lease. Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, &clientid_->getClientId()[0], clientid_->getClientId().size(), 100, time(NULL), subnet_->getID(), false, false, "")); // Create the second lease. Note that we use the same client id here and // we expect that the allocation engine will figure out that the hardware // address is different. Lease4Ptr lease2(new Lease4(IOAddress("192.0.2.102"), hwaddr2_, &clientid_->getClientId()[0], clientid_->getClientId().size(), 100, time(NULL), subnet_->getID(), false, false, "")); // Add leases for both clients to the Lease Manager. LeaseMgrFactory::instance().addLease(lease); LeaseMgrFactory::instance().addLease(lease2); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // First client requests the lease which belongs to the second client. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"), false, false, "", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr new_lease = engine.allocateLease4(ctx); // Allocation engine should return NULL. ASSERT_FALSE(new_lease); // Now simulate the DHCPDISCOVER case when the provided address is // treated as a hint. The engine should return a lease for a // different address than requested. ctx.fake_allocation_ = true; new_lease = engine.allocateLease4(ctx); ASSERT_TRUE(new_lease); EXPECT_EQ("192.0.2.101", new_lease->addr_.toText()); } // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. // - Client has a reservation. // - Client sends DHCPREQUEST without requested IP Address, nor ciaddr. // - Client is allocated a reserved address. // // Note that client must normally include a requested IP address or ciaddr // in its message. But, we still want to provision clients that don't do that. // The server simply picks reserved address or any other available one if there // is no reservation. TEST_F(AllocEngine4Test, reservedAddressNoHint) { // Create reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Try to allocate a lease without specifying a hint. This is actually // incorrect behavior of the client to not send an address it wants to // obtain but the server should handle this gracefully. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx); Lease4Ptr lease = engine.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("192.0.2.123", lease->addr_.toText()); // Make sure that the lease has been committed to the lease database. // And that the committed lease is equal to the one returned. Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); detailCompareLease(lease, from_mgr); // Initially, there was no lease for this client, so the returned old // lease should be NULL. EXPECT_FALSE(ctx.old_lease_); } // This test checks behavior of the allocation engine in the following scenario: // - Client has no lease in the database. // - Client has a reservation. // - Client sends DHCPDISCOVER without requested IP Address. // - Server returns DHCPOFFER with the reserved address. TEST_F(AllocEngine4Test,reservedAddressNoHintFakeAllocation) { // Create reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Query allocation engine for the lease to be assigned to this // client without specifying the address to be assigned. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", true); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); AllocEngine::findReservation(ctx); Lease4Ptr lease = engine.allocateLease4(ctx); ASSERT_TRUE(lease); // The allocation engine should return a reserved address. EXPECT_EQ("192.0.2.123", lease->addr_.toText()); // This is a "fake" allocation so the returned lease should not be committed // to the lease database. EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_)); // Client had no lease in the database, so the old lease returned should // be NULL. EXPECT_FALSE(ctx.old_lease_); } // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. // - Client has a reservation. // - Client sends DHCPREQUEST with a requested IP address // - Server returns DHCPNAK when requested IP address is different than // the reserved address. Note that the allocation engine returns NULL // to indicate to the server that it should send DHCPNAK. // - Server allocates a reserved address to the client when the client requests // this address using requested IP address option. TEST_F(AllocEngine4Test, reservedAddressHint) { HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.234"), false, false, "", false); ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx1); Lease4Ptr lease = engine.allocateLease4(ctx1); // The client requested a different address than reserved, so // the allocation engine should return NULL lease. When the server // receives a NULL lease for the client, it will send a DHCPNAK. ASSERT_FALSE(lease); ASSERT_FALSE(ctx1.old_lease_); // Now, request a correct address. The client should obtain it. AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.123"), false, false, "", false); ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx2); lease = engine.allocateLease4(ctx2); ASSERT_TRUE(lease); EXPECT_EQ("192.0.2.123", lease->addr_.toText()); // Make sure that the lease has been committed to the lease database. // And that the committed lease is equal to the one returned. Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); detailCompareLease(lease, from_mgr); EXPECT_FALSE(ctx2.old_lease_); } // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. // - Client has a reservation. // - Client sends DHCPDISCOVER with a requested IP address as a hint. // - Server offers a reserved address, even though it is different than the // requested address. TEST_F(AllocEngine4Test, reservedAddressHintFakeAllocation) { // Create a reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Query the allocation engine for the lease to be assigned to the client // and specify a hint being a different address than the reserved one. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.234"), false, false, "", true); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx); Lease4Ptr lease = engine.allocateLease4(ctx); ASSERT_TRUE(lease); // Allocation engine should return reserved address. EXPECT_EQ("192.0.2.123", lease->addr_.toText()); // This is a "fake" allocation so the returned lease should not be committed // to the lease database. EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_)); EXPECT_FALSE(ctx.old_lease_); } // This test checks that the behavior of the allocation engine in the following // scenario: // - Client has a lease for the address from the dynamic pool in the database. // - Client has a reservation for a different address than the one for which // the client has a lease. // - Client sends DHCPREQUEST, asking for the reserved address (as it has been // offered to it when it sent DHCPDISCOVER). // - Server allocates a reserved address and removes the lease for the address // previously allocated to the client. TEST_F(AllocEngine4Test, reservedAddressExistingLease) { // Create the reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // Create a lease for the client with a different address than the reserved // one. Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, &clientid_->getClientId()[0], clientid_->getClientId().size(), 100, time(NULL), subnet_->getID(), false, false, "")); LeaseMgrFactory::instance().addLease(lease); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Request allocation of the reserved address. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.123"), false, false, "", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx); Lease4Ptr allocated_lease = engine.allocateLease4(ctx); ASSERT_TRUE(allocated_lease); // The engine should have allocated the reserved address. EXPECT_EQ("192.0.2.123", allocated_lease->addr_.toText()); // Make sure that the lease has been committed to the lease database. Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(allocated_lease->addr_); ASSERT_TRUE(from_mgr); detailCompareLease(allocated_lease, from_mgr); // The previous lease should have been replaced by a new one. The previous // lease should be returned by the allocation engine to the caller. ASSERT_TRUE(ctx.old_lease_); EXPECT_EQ("192.0.2.101", ctx.old_lease_->addr_.toText()); detailCompareLease(ctx.old_lease_, lease); } // This test checks that the behavior of the allocation engine in the following // scenario: // - Client A has a lease in the database. // - Client B has a reservation for the address in use by client A. // - Client B sends a DHCPREQUEST requesting the allocation of the reserved // lease (in use by client A). // - Server determines that the reserved address is in use by a different client // and returns DHCPNAK to client B. TEST_F(AllocEngine4Test, reservedAddressHijacked) { // Create host reservation for the client B. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // Allocate a lease for the client A for the same address as reserved // for the client B. Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0, 100, time(NULL), subnet_->getID(), false, false, "")); LeaseMgrFactory::instance().addLease(lease); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Try to allocate the reserved lease to client B. AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.123"), false, false, "", false); ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx1); Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); // The lease is allocated to someone else, so the allocation should not // succeed. ASSERT_FALSE(allocated_lease); EXPECT_FALSE(ctx1.old_lease_); // Make sure that the allocation engine didn't modify the lease of the // client A. Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); detailCompareLease(lease, from_mgr); // Try doing the same thing, but this time do not request any specific // address. It should have the same effect. AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", false); ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx2); allocated_lease = engine.allocateLease4(ctx2); ASSERT_FALSE(allocated_lease); EXPECT_FALSE(ctx2.old_lease_); from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); detailCompareLease(lease, from_mgr); } // This test checks that the behavior of the allocation engine in the following // scenario: // - Client A has a lease in the database. // - Client B has a reservation for the address in use by client A. // - Client B sends a DHCPDISCOVER. // - Server determines that the reserved address is in use by a different client // so it offers an address from the dynamic pool. TEST_F(AllocEngine4Test, reservedAddressHijackedFakeAllocation) { // Create a reservation for the client B. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // Create a lease for the client A. Lease4Ptr lease(new Lease4(IOAddress("192.0.2.123"), hwaddr2_, 0, 0, 100, time(NULL), subnet_->getID(), false, false, "")); LeaseMgrFactory::instance().addLease(lease); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Query allocation engine for the lease to be allocated to the client B. // The allocation engine is not able to allocate the lease to the client // B, because the address is in use by client A. AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.123"), false, false, "", true); ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx1); Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); // The allocation engine should return a lease but for a different address // than requested because this address is in use. ASSERT_TRUE(allocated_lease); EXPECT_FALSE(ctx1.old_lease_); EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.123"); EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_)); // Do the same test. But, this time do not specify any address to be // allocated. AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", true); ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx2); allocated_lease = engine.allocateLease4(ctx2); ASSERT_TRUE(allocated_lease); EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.123"); EXPECT_TRUE(subnet_->inPool(Lease::TYPE_V4, allocated_lease->addr_)); EXPECT_FALSE(ctx2.old_lease_); } // This test checks that the behavior of the allocation engine in the following // scenario: // - Client has a reservation. // - Client has a lease in the database for a different address than reserved. // - Client sends a DHCPREQUEST and asks for a different address than reserved, // and different than it has in a database. // - Server doesn't allocate the reserved address to the client because the // client asked for the different address. // // Note that in this case the client should get the DHCPNAK and should fall back // to the DHCPDISCOVER. TEST_F(AllocEngine4Test, reservedAddressExistingLeaseInvalidHint) { // Create a reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // Create a lease for the client for a different address than reserved. Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, ClientIdPtr(), 100, time(NULL), subnet_->getID(), false, false, "")); LeaseMgrFactory::instance().addLease(lease); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Try to allocate a lease and specify a different address than reserved // and different from the one that client is currently using. AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"), false, false, "", false); ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx1); Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); ASSERT_FALSE(allocated_lease); ASSERT_FALSE(ctx1.old_lease_); // Repeat the test, but this time ask for the address that the client // has allocated. AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.101"), false, false, "", false); ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx2); allocated_lease = engine.allocateLease4(ctx2); // The client has reservation so the server wants to allocate a // reserved address and doesn't want to renew the address that the // client is currently using. This is equivalent of the case when // the client tries to renew the lease but there is a new reservation // for this client. The server doesn't allow for the renewal and // responds with DHCPNAK to force the client to return to the // DHCP server discovery. EXPECT_FALSE(allocated_lease); EXPECT_FALSE(ctx2.old_lease_); } // This test checks that the behavior of the allocation engine in the following // scenario: // - Client has a lease in the database. // - Client has a reservation for a different address than the one for which it // has a lease. // - Client sends a DHCPDISCOVER and asks for a different address than reserved // and different from which it has a lease for. // - Server ignores the client's hint and offers a reserved address. TEST_F(AllocEngine4Test, reservedAddressExistingLeaseFakeAllocation) { // Create a reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // Create a lease for a different address than reserved. Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, &clientid_->getClientId()[0], clientid_->getClientId().size(), 100, time(NULL), subnet_->getID(), false, false, "")); LeaseMgrFactory::instance().addLease(lease); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Try to allocate a lease and use a completely different address // as a hint. AllocEngine::ClientContext4 ctx1(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.102"), false, false, "", true); ctx1.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); AllocEngine::findReservation(ctx1); Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); // Server should offer a lease for a reserved address. ASSERT_TRUE(allocated_lease); EXPECT_EQ("192.0.2.123", allocated_lease->addr_.toText()); // The lease should not be allocated until the client sends a DHCPREQUEST. EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(allocated_lease->addr_)); // Old lease should contain the currently used lease. ASSERT_TRUE(ctx1.old_lease_); EXPECT_EQ("192.0.2.101", ctx1.old_lease_->addr_.toText()); // Repeat the test but this time ask for the address for which the // client has a lease. AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.101"), false, false, "", true); ctx2.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); AllocEngine::findReservation(ctx2); allocated_lease = engine.allocateLease4(ctx2); // The server should offer the lease, but not for the address that // the client requested. The server should offer a reserved address. ASSERT_TRUE(allocated_lease); EXPECT_EQ("192.0.2.123", allocated_lease->addr_.toText()); // Old lease should contain the currently used lease. ASSERT_TRUE(ctx2.old_lease_); EXPECT_EQ("192.0.2.101", ctx2.old_lease_->addr_.toText()); } // This test checks that the behavior of the allocation engine in the following // scenario: // - Client has a reservation. // - Client has a lease for a different address than reserved. // - Client sends a DHCPREQUEST to allocate a lease. // - The server determines that the client has a reservation for the // different address than it is currently using and should assign // a reserved address and remove the previous lease. TEST_F(AllocEngine4Test, reservedAddressExistingLeaseNoHint) { // Create a reservation. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // Create a lease for a different address than reserved. Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, &clientid_->getClientId()[0], clientid_->getClientId().size(), 100, time(NULL), subnet_->getID(), false, false, "")); LeaseMgrFactory::instance().addLease(lease); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Try to allocate a lease with providing no hint. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx); Lease4Ptr allocated_lease = engine.allocateLease4(ctx); // The reserved address should be allocated. ASSERT_TRUE(allocated_lease); EXPECT_EQ("192.0.2.123", allocated_lease->addr_.toText()); // The previous lease should be removed. EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_)); // Make sure that the allocated lease is committed in the lease database. Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(allocated_lease->addr_); ASSERT_TRUE(from_mgr); detailCompareLease(allocated_lease, from_mgr); // Old lease should be returned. ASSERT_TRUE(ctx.old_lease_); detailCompareLease(lease, ctx.old_lease_); } // This test checks that the behavior of the allocation engine in the following // scenario: // - Client has a reservation. // - Client has a lease for a different address than reserved. // - Client sends a DHCPDISCOVER with no hint. // - Server determines that there is a reservation for the client and that // the reserved address should be offered when the client sends a // DHCPDISCOVER. TEST_F(AllocEngine4Test, reservedAddressExistingLeaseNoHintFakeAllocation) { // Create a reservation. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // Create a lease for a different address than reserved. Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, &clientid_->getClientId()[0], clientid_->getClientId().size(), 100, time(NULL), subnet_->getID(), false, false, "")); LeaseMgrFactory::instance().addLease(lease); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Query the allocation engine for the lease to be allocated for the // client. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", true); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); AllocEngine::findReservation(ctx); Lease4Ptr allocated_lease = engine.allocateLease4(ctx); // The server should offer the reserved address. ASSERT_TRUE(allocated_lease); EXPECT_EQ("192.0.2.123", allocated_lease->addr_.toText()); // The lease should not be committed to the lease database until the // client sends a DHCPREQUEST. EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(allocated_lease->addr_)); // The old lease should reflect what is in the database. ASSERT_TRUE(ctx.old_lease_); Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); detailCompareLease(lease, from_mgr); } // This test checks that the behavior of the allocation engine in the following // scenario: // - Client A has a lease for the address. // - Client B has a reservation for the same address that the Client A is using. // - Client B requests allocation of the reserved address. // - Server returns DHCPNAK to the client to indicate that the requested address // can't be allocated. // - Client A renews the lease. // - Server determines that the lease that the Client A is trying to renew // is for the address reserved for Client B. Therefore, the server returns // DHCPNAK to force the client to return to the server discovery. // - The Client A sends DHCPDISCOVER. // - The server offers an address to the Client A, which is different than // the address reserved for Client B. // - The Client A requests allocation of the offered address. // - The server allocates the new address to Client A. // - The Client B sends DHCPDISCOVER to the server. // - The server offers a reserved address to the Client B. // - The Client B requests the offered address. // - The server allocates the reserved address to the Client B. TEST_F(AllocEngine4Test, reservedAddressConflictResolution) { // Create a reservation for client B. HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.101"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // Create a lease for Client A. Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, &clientid_->getClientId()[0], clientid_->getClientId().size(), 100, time(NULL), subnet_->getID(), false, false, "")); LeaseMgrFactory::instance().addLease(lease); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Client B sends a DHCPREQUEST to allocate a reserved lease. The // allocation engine can't allocate a reserved lease for this client // because this specific address is in use by the Client A. AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr2_, IOAddress("192.0.2.101"), false, false, "", false); ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx1); Lease4Ptr offered_lease = engine.allocateLease4(ctx1); ASSERT_FALSE(offered_lease); // Client A tries to renew the lease. The renewal should fail because // server detects that Client A doesn't have reservation for this // address. AllocEngine::ClientContext4 ctx2(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.101"), false, false, "", false); ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx2); ASSERT_FALSE(engine.allocateLease4(ctx2)); ASSERT_FALSE(ctx2.old_lease_); // Client A returns to DHCPDISCOVER and should be offered a lease. // The offered lease address must be different than the one the // Client B has reservation for. AllocEngine::ClientContext4 ctx3(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.101"), false, false, "", true); ctx3.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx3); offered_lease = engine.allocateLease4(ctx3); ASSERT_TRUE(offered_lease); EXPECT_NE(offered_lease->addr_.toText(), "192.0.2.101"); // Client A tries to acquire the lease. It should succeed. At this point // the previous lease should be released and become available for the // Client B. AllocEngine::ClientContext4 ctx4(subnet_, clientid_, hwaddr_, offered_lease->addr_, false, false, "", false); ctx4.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx4); Lease4Ptr allocated_lease = engine.allocateLease4(ctx4); ASSERT_TRUE(allocated_lease); EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.101"); // Client B tries to get the lease again. It should be offered // a reserved lease. AllocEngine::ClientContext4 ctx5(subnet_, ClientIdPtr(), hwaddr2_, IOAddress("0.0.0.0"), false, false, "", true); ctx5.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx5); offered_lease = engine.allocateLease4(ctx5); ASSERT_TRUE(offered_lease); EXPECT_EQ("192.0.2.101", offered_lease->addr_.toText()); // Client B requests allocation of the lease and it should succeed. AllocEngine::ClientContext4 ctx6(subnet_, ClientIdPtr(), hwaddr2_, offered_lease->addr_, false, false, "", false); ctx6.query_.reset(new Pkt4(DHCPREQUEST, 1234)); allocated_lease = engine.allocateLease4(ctx6); ASSERT_TRUE(allocated_lease); EXPECT_EQ("192.0.2.101", allocated_lease->addr_.toText()); } // This test checks that the address is not assigned from the dynamic // pool if it has been reserved for another client. TEST_F(AllocEngine4Test, reservedAddressVsDynamicPool) { // Create a reservation for the client. HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Different client tries to allocate a lease. Note, that we're using // an iterative allocator which would pick the first address from the // dynamic pool, i.e. 192.0.2.100. This address is reserved so we expect // that a different address will be allocated. AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, IOAddress("0.0.0.0"), false, false, "", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx); Lease4Ptr allocated_lease = engine.allocateLease4(ctx); ASSERT_TRUE(allocated_lease); EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.100"); Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(allocated_lease->addr_); ASSERT_TRUE(from_mgr); detailCompareLease(allocated_lease, from_mgr); } // This test checks that the client requesting an address which is // reserved for another client will get no lease or a different // address will be assigned if the client is sending a DHCPDISCOVER. TEST_F(AllocEngine4Test, reservedAddressHintUsedByOtherClient) { // Create a reservation for the client. HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Different client is requesting this address. AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr_, IOAddress("192.0.2.100"), false, false, "", false); ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx1); Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); // The client should get no lease (DHCPNAK). ASSERT_FALSE(allocated_lease); // The same client should get a different lease than requested if // if is sending a DHCPDISCOVER (fake allocation is true). AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr_, IOAddress("192.0.2.100"), false, false, "", true); ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx2); allocated_lease = engine.allocateLease4(ctx2); ASSERT_TRUE(allocated_lease); // Make sure the lease obtained is for a different address. EXPECT_NE(allocated_lease->addr_.toText(), "192.0.2.100"); } // This test checks that the allocation engine refuses to allocate an // address when the pool is exhausted, and the only available // address is reserved for a different client. TEST_F(AllocEngine4Test, reservedAddressShortPool) { AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Create short pool with only one address. initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100")); // Reserve the address for a different client. HostPtr host(new Host(&hwaddr2_->hwaddr_[0], hwaddr2_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // Allocation engine should determine that the available address is // reserved for someone else and not allocate it. AllocEngine::ClientContext4 ctx1(subnet_, ClientIdPtr(), hwaddr_, IOAddress("0.0.0.0"), false, false, "", false); ctx1.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx1); Lease4Ptr allocated_lease = engine.allocateLease4(ctx1); EXPECT_FALSE(allocated_lease); // Now, let's remove the reservation. initSubnet(IOAddress("192.0.2.100"), IOAddress("192.0.2.100")); CfgMgr::instance().commit(); // Address should be successfully allocated. AllocEngine::ClientContext4 ctx2(subnet_, ClientIdPtr(), hwaddr_, IOAddress("0.0.0.0"), false, false, "", false); ctx2.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx2); allocated_lease = engine.allocateLease4(ctx2); ASSERT_TRUE(allocated_lease); EXPECT_EQ("192.0.2.100", allocated_lease->addr_.toText()); } // This test checks that the AllocEngine allocates an address from the // dynamic pool if the client's reservation is made for a hostname but // not for an address. TEST_F(AllocEngine4Test, reservedHostname) { AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Create a reservation for a hostname. Address is set to 0 which // indicates that there is no reservation. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(), "foo.example.org")); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // Try to allocate a lease. AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, IOAddress("192.0.2.109"), false, false, "foo.example.org", true); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx); Lease4Ptr allocated_lease = engine.allocateLease4(ctx); ASSERT_TRUE(allocated_lease); ASSERT_FALSE(allocated_lease->addr_.isV4Zero()); ASSERT_EQ("192.0.2.109", allocated_lease->addr_.toText()); ctx.requested_address_ = allocated_lease->addr_; ctx.fake_allocation_ = false; allocated_lease = engine.allocateLease4(ctx); ASSERT_TRUE(allocated_lease); EXPECT_EQ("192.0.2.109", allocated_lease->addr_.toText()); } // This test checks that the AllocEngine::findReservation method finds // and returns host reservation for the DHCPv4 client using the data from // the client context. If the host reservation can't be found, it sets // the value of NULL in the host_ field of the client context. TEST_F(AllocEngine4Test, findReservation) { // Create the instance of the allocation engine. AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // Context is required to call the AllocEngine::findReservation. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", false); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); ctx.addHostIdentifier(Host::IDENT_HWADDR, hwaddr_->hwaddr_); ctx.addHostIdentifier(Host::IDENT_DUID, clientid_->getDuid()); // There is no reservation in the database so no host should be returned. ASSERT_NO_THROW(engine.findReservation(ctx)); EXPECT_FALSE(ctx.currentHost()); // Create a reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // This time the reservation should be returned. ASSERT_NO_THROW(engine.findReservation(ctx)); EXPECT_TRUE(ctx.currentHost()); EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation()); // It shouldn't be returned when reservations-in-subnet is disabled. subnet_->setReservationsInSubnet(false); ASSERT_NO_THROW(engine.findReservation(ctx)); EXPECT_FALSE(ctx.currentHost()); // Check the reservations-in-subnet and reservations-out-of-pool flags. subnet_->setReservationsInSubnet(true); subnet_->setReservationsOutOfPool(true); ASSERT_NO_THROW(engine.findReservation(ctx)); EXPECT_TRUE(ctx.currentHost()); EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation()); // This time use the client identifier to search for the host. host.reset(new Host(&clientid_->getClientId()[0], clientid_->getClientId().size(), Host::IDENT_DUID, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.101"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); ASSERT_NO_THROW(engine.findReservation(ctx)); EXPECT_TRUE(ctx.currentHost()); EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation()); // Remove the subnet. Subnet id is required to find host reservations, so // if it is set to NULL, no reservation should be returned ctx.subnet_.reset(); ASSERT_NO_THROW(engine.findReservation(ctx)); EXPECT_FALSE(ctx.currentHost()); // The same if there is a mismatch of the subnet id between the reservation // and the context. ctx.subnet_ = subnet_; host.reset(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID() + 1, SUBNET_ID_UNUSED, IOAddress("192.0.2.100"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); ASSERT_NO_THROW(engine.findReservation(ctx)); EXPECT_FALSE(ctx.currentHost()); } // This test checks if the simple IPv4 allocation can succeed and that // statistic for allocated addresses is increased appropriately. TEST_F(AllocEngine4Test, simpleAlloc4Stats) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 0, false))); ASSERT_TRUE(engine); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, true, "somehost.example.com.", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); // Let's pretend 100 addresses were allocated already string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-addresses"); StatsMgr::instance().addValue(name, static_cast<int64_t>(100)); int64_t cumulative = getStatistics("cumulative-assigned-addresses", subnet_->getID()); int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); Lease4Ptr lease = engine->allocateLease4(ctx); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // Check that we got a lease ASSERT_TRUE(lease); // The statistic should be there and it should be increased by 1 (to 101). ObservationPtr stat = StatsMgr::instance().getObservation(name); ASSERT_TRUE(stat); EXPECT_EQ(101, stat->getInteger().first); cumulative += 1; EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", cumulative, subnet_->getID())); glbl_cumulative += 1; EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative)); } // This test checks if the fake allocation (for DHCPDISCOVER) can succeed // and that it doesn't increase allocated-addresses statistic. TEST_F(AllocEngine4Test, fakeAlloc4Stat) { boost::scoped_ptr<AllocEngine> engine; ASSERT_NO_THROW(engine.reset(new AllocEngine(AllocEngine::ALLOC_ITERATIVE, 100, false))); ASSERT_TRUE(engine); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, true, "host.example.com.", true); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); // Let's pretend 100 addresses were allocated already string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-addresses"); StatsMgr::instance().addValue(name, static_cast<int64_t>(100)); int64_t cumulative = getStatistics("cumulative-assigned-addresses", subnet_->getID()); int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); Lease4Ptr lease = engine->allocateLease4(ctx); // The new lease has been allocated, so the old lease should not exist. EXPECT_FALSE(ctx.old_lease_); // Check that we got a lease ASSERT_TRUE(lease); // The statistic should be there and it should not be increased // (should be still equal to 100). ObservationPtr stat = StatsMgr::instance().getObservation(name); ASSERT_TRUE(stat); EXPECT_EQ(100, stat->getInteger().first); EXPECT_EQ(cumulative, getStatistics("cumulative-assigned-addresses", subnet_->getID())); EXPECT_EQ(glbl_cumulative, getStatistics("cumulative-assigned-addresses")); } // This test checks that the allocated-addresses statistic is decreased when // the client has a lease and a reservation for a different address is // available. TEST_F(AllocEngine4Test, reservedAddressExistingLeaseStat) { // Create the reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); // Create a lease for the client with a different address than the reserved // one. Lease4Ptr lease(new Lease4(IOAddress("192.0.2.101"), hwaddr_, &clientid_->getClientId()[0], clientid_->getClientId().size(), 100, time(NULL), subnet_->getID(), false, false, "")); LeaseMgrFactory::instance().addLease(lease); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 100, false); // Let's pretend 100 addresses were allocated already string name = StatsMgr::generateName("subnet", subnet_->getID(), "assigned-addresses"); StatsMgr::instance().addValue(name, static_cast<int64_t>(100)); int64_t cumulative = getStatistics("cumulative-assigned-addresses", subnet_->getID()); int64_t glbl_cumulative = getStatistics("cumulative-assigned-addresses"); // Request allocation of the reserved address. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("192.0.2.123"), false, false, "", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); AllocEngine::findReservation(ctx); Lease4Ptr allocated_lease = engine.allocateLease4(ctx); ASSERT_TRUE(allocated_lease); // The statistic should be still at 100. Note that it was decreased // (because old lease was removed), but also increased (because the // new lease was immediately allocated). ObservationPtr stat = StatsMgr::instance().getObservation(name); ASSERT_TRUE(stat); EXPECT_EQ(100, stat->getInteger().first); cumulative += 1; EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", cumulative, subnet_->getID())); glbl_cumulative += 1; EXPECT_TRUE(testStatistics("cumulative-assigned-addresses", glbl_cumulative)); // Lets' double check that the actual allocation took place. EXPECT_FALSE(ctx.fake_allocation_); } // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. // - Client has a global reservation. // - Client sends DISCOVER // - Client is allocated the reserved address. // - Lease is not added to the lease database TEST_F(AllocEngine4Test, globalReservationReservedAddressDiscover) { // Create reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); subnet_->setReservationsGlobal(true); // Query allocation engine for the lease to be assigned to this // client without specifying the address to be assigned. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", true); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); // Look up the host. AllocEngine::findReservation(ctx); // We should have the correct current host EXPECT_TRUE(ctx.currentHost()); EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname()); EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation()); // We should allocate the reserved address. Lease4Ptr lease = engine.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("192.0.77.123", lease->addr_.toText()); // This is a "fake" allocation so the returned lease should not be committed // to the lease database. EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_)); // Client had no lease in the database, so the old lease returned should // be NULL. EXPECT_FALSE(ctx.old_lease_); } // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. // - Client has a global reservation. // - Client sends REQUEST // - Client is allocated the reserved address. // - Lease is added to the lease database TEST_F(AllocEngine4Test, globalReservationReservedAddressRequest) { // Create reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); subnet_->setReservationsGlobal(true); // Query allocation engine for the lease to be assigned to this // client without specifying the address to be assigned. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); // Look up the host. AllocEngine::findReservation(ctx); // We should have the correct current host EXPECT_TRUE(ctx.currentHost()); EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname()); EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation()); // We should allocate the reserved address. Lease4Ptr lease = engine.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("192.0.77.123", lease->addr_.toText()); // Check that the lease is indeed in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); // Client had no lease in the database, so the old lease returned should // be NULL. EXPECT_FALSE(ctx.old_lease_); } // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. // - Client has a global reservation. // - Client sends DISCOVER // - Client is allocated a dynamic address from matched subnet // - Lease is not added to the lease database TEST_F(AllocEngine4Test, globalReservationDynamicDiscover) { // Create reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(), "foo.example.org")); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); subnet_->setReservationsGlobal(true); // Query allocation engine for the lease to be assigned to this // client without specifying the address to be assigned. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", true); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); // Look up the host. AllocEngine::findReservation(ctx); // We should have the correct current host EXPECT_TRUE(ctx.currentHost()); EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname()); EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation()); // We should allocate a dynamic address. Lease4Ptr lease = engine.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("192.0.2.100", lease->addr_.toText()); // This is a "fake" allocation so the returned lease should not be committed // to the lease database. EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_)); // Client had no lease in the database, so the old lease returned should // be NULL. EXPECT_FALSE(ctx.old_lease_); } // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. // - Client has a global reservation. // - Client sends REQUEST // - Client is allocated a dynamic address from matched subnet // - Lease is added to the lease database TEST_F(AllocEngine4Test, globalReservationDynamicRequest) { // Create reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, SUBNET_ID_UNUSED, IOAddress::IPV4_ZERO_ADDRESS(), "foo.example.org")); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); subnet_->setReservationsGlobal(true); // Query allocation engine for the lease to be assigned to this // client without specifying the address to be assigned. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); // Look up the host. AllocEngine::findReservation(ctx); // We should have the correct current host EXPECT_TRUE(ctx.currentHost()); EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname()); EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation()); // We should allocate a dynamic address. Lease4Ptr lease = engine.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("192.0.2.100", lease->addr_.toText()); // Check that the lease is indeed in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); // Client had no lease in the database, so the old lease returned should // be NULL. EXPECT_FALSE(ctx.old_lease_); } // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. // - Client has a subnet reservation. // - Client sends DISCOVER // - Client is allocated the reserved address. // - Lease is not added to the lease database TEST_F(AllocEngine4Test, mixedReservationReservedAddressDiscover) { // Create reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), "foo.example.org")); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); subnet_->setReservationsGlobal(true); subnet_->setReservationsInSubnet(true); // Query allocation engine for the lease to be assigned to this // client without specifying the address to be assigned. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", true); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); // Look up the host. AllocEngine::findReservation(ctx); // We should have the correct current host EXPECT_TRUE(ctx.currentHost()); EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname()); EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation()); // We should allocate the reserved address. Lease4Ptr lease = engine.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("192.0.2.123", lease->addr_.toText()); // This is a "fake" allocation so the returned lease should not be committed // to the lease database. EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_)); // Client had no lease in the database, so the old lease returned should // be NULL. EXPECT_FALSE(ctx.old_lease_); } // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. // - Client has a subnet reservation. // - Client sends REQUEST // - Client is allocated the reserved address. // - Lease is added to the lease database TEST_F(AllocEngine4Test, mixedReservationReservedAddressRequest) { // Create reservation for the client. HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), "foo.example.org")); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); subnet_->setReservationsGlobal(true); subnet_->setReservationsInSubnet(true); // Query allocation engine for the lease to be assigned to this // client without specifying the address to be assigned. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); // Look up the host. AllocEngine::findReservation(ctx); // We should have the correct current host EXPECT_TRUE(ctx.currentHost()); EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname()); EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation()); // We should allocate the reserved address. Lease4Ptr lease = engine.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("192.0.2.123", lease->addr_.toText()); // Check that the lease is indeed in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); // Client had no lease in the database, so the old lease returned should // be NULL. EXPECT_FALSE(ctx.old_lease_); } // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. // - Client has a global and a subnet reservation. // - Client sends DISCOVER // - Client is allocated the reserved address. // - Lease is not added to the lease database TEST_F(AllocEngine4Test, bothReservationReservedAddressDiscover) { // Create reservations for the client. HostPtr ghost(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(ghost); HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), "foo.example.org")); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); subnet_->setReservationsGlobal(true); subnet_->setReservationsInSubnet(true); // Query allocation engine for the lease to be assigned to this // client without specifying the address to be assigned. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", true); ctx.query_.reset(new Pkt4(DHCPDISCOVER, 1234)); // Look up the host. AllocEngine::findReservation(ctx); // We should have the correct current host EXPECT_TRUE(ctx.currentHost()); EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname()); EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation()); // We should allocate the reserved address. Lease4Ptr lease = engine.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("192.0.2.123", lease->addr_.toText()); // This is a "fake" allocation so the returned lease should not be committed // to the lease database. EXPECT_FALSE(LeaseMgrFactory::instance().getLease4(lease->addr_)); // Client had no lease in the database, so the old lease returned should // be NULL. EXPECT_FALSE(ctx.old_lease_); } // This test checks the behavior of the allocation engine in the following // scenario: // - Client has no lease in the database. // - Client has a global and a subnet reservation. // - Client sends REQUEST // - Client is allocated the reserved address. // - Lease is added to the lease database TEST_F(AllocEngine4Test, bothReservationReservedAddressRequest) { // Create reservations for the client. HostPtr ghost(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, SUBNET_ID_GLOBAL, SUBNET_ID_UNUSED, IOAddress("192.0.77.123"))); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(ghost); HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(), Host::IDENT_HWADDR, subnet_->getID(), SUBNET_ID_UNUSED, IOAddress("192.0.2.123"), "foo.example.org")); CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host); CfgMgr::instance().commit(); AllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); subnet_->setReservationsGlobal(true); subnet_->setReservationsInSubnet(true); // Query allocation engine for the lease to be assigned to this // client without specifying the address to be assigned. AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"), false, false, "", false); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); // Look up the host. AllocEngine::findReservation(ctx); // We should have the correct current host EXPECT_TRUE(ctx.currentHost()); EXPECT_EQ(ctx.currentHost()->getHostname(), host->getHostname()); EXPECT_EQ(ctx.currentHost()->getIPv4Reservation(), host->getIPv4Reservation()); // We should allocate the reserved address. Lease4Ptr lease = engine.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("192.0.2.123", lease->addr_.toText()); // Check that the lease is indeed in LeaseMgr Lease4Ptr from_mgr = LeaseMgrFactory::instance().getLease4(lease->addr_); ASSERT_TRUE(from_mgr); // Now check that the lease in LeaseMgr has the same parameters detailCompareLease(lease, from_mgr); // Client had no lease in the database, so the old lease returned should // be NULL. EXPECT_FALSE(ctx.old_lease_); } // Exercises AllocEnginer4Test::updateExtendedInfo4() through various // permutations of client packet content. TEST_F(AllocEngine4Test, updateExtendedInfo4) { // Structure that defines a test scenario. struct Scenario { std::string description_; // test description std::string orig_context_json_; // user context the lease begins with std::string rai_data_; // RAI option the client packet contains std::string exp_context_json_; // expected user context on the lease }; // Test scenarios. std::vector<Scenario> scenarios { { "no context, no rai", "", "", "" }, { "some original context, no rai", "{\"foo\": 123}", "", "{\"foo\": 123}" }, { "no original context, rai", "", "0x52050104aabbccdd", "{ \"ISC\": { \"relay-agent-info\": \"0x52050104AABBCCDD\" } }", }, { "some original context, rai", "{\"foo\": 123}", "0x52050104aabbccdd", "{ \"ISC\": { \"relay-agent-info\": \"0x52050104AABBCCDD\" }, \"foo\": 123 }" }, { "original rai context, no rai", "{ \"ISC\": { \"relay-agent-info\": \"0x52050104AABBCCDD\" } }", "", "{ \"ISC\": { \"relay-agent-info\": \"0x52050104AABBCCDD\" } }", }, { "original rai context, different rai", "{ \"ISC\": { \"relay-agent-info\": \"0x52050104AABBCCDD\" } }", "0x52050104ddeeffaa", "{ \"ISC\": { \"relay-agent-info\": \"0x52050104DDEEFFAA\" } }", }}; // Create the allocation engine, context and lease. NakedAllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "", true); // All scenarios require storage to be enabled. ctx.subnet_->setStoreExtendedInfo(true); ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); Lease4Ptr lease = engine.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ("192.0.2.100", lease->addr_.toText()); // Verify that the lease begins with no user context. ConstElementPtr user_context = lease->getContext(); ASSERT_FALSE(user_context); // Iterate over the test scenarios. ElementPtr orig_context; ElementPtr exp_context; for (auto scenario : scenarios) { SCOPED_TRACE(scenario.description_); // Create the original user context from JSON. if (scenario.orig_context_json_.empty()) { orig_context.reset(); } else { ASSERT_NO_THROW(orig_context = Element::fromJSON(scenario.orig_context_json_)) << "invalid orig_context_json_, test is broken"; } // Create the expected user context from JSON. if (scenario.exp_context_json_.empty()) { exp_context.reset(); } else { ASSERT_NO_THROW(exp_context = Element::fromJSON(scenario.exp_context_json_)) << "invalid exp_context_json_, test is broken"; } // Initialize lease's user context. lease->setContext(orig_context); if (!orig_context) { ASSERT_FALSE(lease->getContext()); } else { ASSERT_TRUE(lease->getContext()); ASSERT_TRUE(orig_context->equals(*(lease->getContext()))); } // Create the client packet and the add RAI option (if one). ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); if (!scenario.rai_data_.empty()) { std::vector<uint8_t> opt_data; ASSERT_NO_THROW(util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)) << "scenario.rai_data_ is invalid, test is broken"; OptionPtr rai; ASSERT_NO_THROW(rai.reset(new Option(Option::V4, 0x52, opt_data))) << "could not create rai option, test is broken"; ctx.query_->addOption(rai); } // Call AllocEngine::updateLease4ExtendeInfo(). ASSERT_NO_THROW_LOG(engine.callUpdateLease4ExtendedInfo(lease, ctx)); // Verify the lease has the expected user context content. if (!exp_context) { ASSERT_FALSE(lease->getContext()); } else { ASSERT_TRUE(lease->getContext()); ASSERT_TRUE(exp_context->equals(*(lease->getContext()))) << "expected: " << *(exp_context) << std::endl << " actual: " << *(lease->getContext()) << std::endl; } } } // Verifies that the extended data (e.g. RAI option for now) is // added to a V4 lease when leases are created and/or renewed, // when store-extended-info is true. TEST_F(AllocEngine4Test, storeExtendedInfoEnabled4) { // Structure that defines a test scenario. struct Scenario { std::string description_; // test description std::vector<uint8_t> mac_; // MAC address std::string rai_data_; // RAI option the client packet contains std::string exp_context_json_; // expected user context on the lease std::string exp_address_; // expected lease address }; std::vector<uint8_t> mac1 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x01}; std::string mac1_addr = "192.0.2.100"; std::vector<uint8_t> mac2 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x02}; std::string mac2_addr = "192.0.2.101"; // Test scenarios. std::vector<Scenario> scenarios { { "create client one without rai", mac1, "", "", mac1_addr }, { "renew client one without rai", {}, "", "", mac1_addr }, { "create client two with rai", mac2, "0x52050104a1b1c1d1", "{ \"ISC\": { \"relay-agent-info\": \"0x52050104A1B1C1D1\" } }", mac2_addr }, { "renew client two without rai", {}, "", "{ \"ISC\": { \"relay-agent-info\": \"0x52050104A1B1C1D1\" } }", mac2_addr }}; // Create the allocation engine, context and lease. NakedAllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // All of the scenarios require storage to be enabled. subnet_->setStoreExtendedInfo(true); AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "", false); // Iterate over the test scenarios. Lease4Ptr lease; for (auto scenario : scenarios) { SCOPED_TRACE(scenario.description_); ElementPtr exp_context; // Create the expected user context from JSON. if (!scenario.exp_context_json_.empty()) { ASSERT_NO_THROW(exp_context = Element::fromJSON(scenario.exp_context_json_)) << "invalid exp_context_json_, test is broken"; } // If we have a MAC address this scenario is for a new client. if (!scenario.mac_.empty()) { std::cout << "setting mac address" << std::endl; ASSERT_NO_THROW(ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER))) << "invalid MAC address, test is broken"; } // Create the client packet and the add RAI option (if one). ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); if (!scenario.rai_data_.empty()) { std::vector<uint8_t> opt_data; ASSERT_NO_THROW(util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)) << "scenario.rai_data_ is invalid, test is broken"; OptionPtr rai; ASSERT_NO_THROW(rai.reset(new Option(Option::V4, 0x52, opt_data))) << "could not create rai option, test is broken"; ctx.query_->addOption(rai); } // Create or renew the lease. Lease4Ptr lease = engine.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ(scenario.exp_address_, lease->addr_.toText()); // Verify the lease has the expected user context content. if (!exp_context) { ASSERT_FALSE(lease->getContext()); } else { ASSERT_TRUE(lease->getContext()); ASSERT_TRUE(exp_context->equals(*(lease->getContext()))) << "expected: " << *(exp_context) << std::endl << " actual: " << *(lease->getContext()) << std::endl; } } } // Verifies that the extended data (e.g. RAI option for now) is // not added to a V4 lease when leases are created and/or renewed, // when store-extended-info is false. TEST_F(AllocEngine4Test, storeExtendedInfoDisabled4) { // Structure that defines a test scenario. struct Scenario { std::string description_; // test description std::vector<uint8_t> mac_; // MAC address std::string rai_data_; // RAI option the client packet contains std::string exp_address_; // expected lease address }; std::vector<uint8_t> mac1 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x01}; std::string mac1_addr = "192.0.2.100"; std::vector<uint8_t> mac2 = { 0, 0xfe, 0xfe, 0xfe, 0xfe, 0x02}; std::string mac2_addr = "192.0.2.101"; // Test scenarios. std::vector<Scenario> scenarios { { "create client one without rai", mac1, "", mac1_addr }, { "renew client one without rai", {}, "", mac1_addr }, { "create client two with rai", mac2, "0x52050104a1b1c1d1", mac2_addr }, { "renew client two with rai", {}, "0x52050104a1b1c1d1", mac2_addr }}; // Create the allocation engine, context and lease. NakedAllocEngine engine(AllocEngine::ALLOC_ITERATIVE, 0, false); // All of the scenarios require storage to be disabled. subnet_->setStoreExtendedInfo(false); AllocEngine::ClientContext4 ctx(subnet_, ClientIdPtr(), hwaddr_, IOAddress::IPV4_ZERO_ADDRESS(), false, false, "", false); Lease4Ptr lease; // Iterate over the test scenarios. for (auto scenario : scenarios) { SCOPED_TRACE(scenario.description_); // If we have a MAC address this scenario is for a new client. if (!scenario.mac_.empty()) { std::cout << "setting mac address" << std::endl; ASSERT_NO_THROW(ctx.hwaddr_.reset(new HWAddr(scenario.mac_, HTYPE_ETHER))) << "invalid MAC address, test is broken"; } // Create the client packet and the add RAI option (if one). ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234)); if (!scenario.rai_data_.empty()) { std::vector<uint8_t> opt_data; ASSERT_NO_THROW(util::str::decodeFormattedHexString(scenario.rai_data_, opt_data)) << "scenario.rai_data_ is invalid, test is broken"; OptionPtr rai; ASSERT_NO_THROW(rai.reset(new Option(Option::V4, 0x52, opt_data))) << "could not create rai option, test is broken"; ctx.query_->addOption(rai); } // Create or renew the lease. Lease4Ptr lease = engine.allocateLease4(ctx); ASSERT_TRUE(lease); EXPECT_EQ(scenario.exp_address_, lease->addr_.toText()); // Verify the lease does not have user context content. ASSERT_FALSE(lease->getContext()); } } } // namespace test } // namespace dhcp } // namespace isc
/** * Copyright 2017 Colin Doig. Distributed under the MIT license. */ #include <stdexcept> #include "greentop/sport/enum/TimeGranularity.h" #include "greentop/Enum.h" namespace greentop { namespace sport { const std::string TimeGranularity::DAYS = "DAYS"; const std::string TimeGranularity::HOURS = "HOURS"; const std::string TimeGranularity::MINUTES = "MINUTES"; TimeGranularity::TimeGranularity() { valid = false; } TimeGranularity::TimeGranularity(const std::string& v) { if (v != DAYS && v != HOURS && v != MINUTES) { throw std::invalid_argument("Invalid TimeGranularity: " + v); } value = v; valid = true; } bool TimeGranularity::operator<(const TimeGranularity& other) const { return value < other.value; } bool TimeGranularity::operator==(const TimeGranularity& other) const { return value == other.value; } bool TimeGranularity::operator!=(const TimeGranularity& other) const { return value != other.value; } } }
; TRABALHO PRATICO - CODIGO XXXX ; Aluno 1: ; Aluno 2: ; Aluno 3: .8086 .model small .stack 2048 dseg segment para public 'data' lin byte 2 ; VARIAVEIS... col byte 3 alt byte 7 larg byte 5 dseg ends cseg segment para public 'code' assume cs:cseg, ds:dseg main proc mov ax, dseg mov ds, ax mov ax, 0B800h mov es, ax mov al, lin ;iniciar num local do ecra (linha/coluna) mov bl, 160 mul bl mov di, ax mov al, col mov bl, 2 mul bl add di, ax mov al, larg mov bl, 2 mul bl mov si; ax add si, di mov al, alt mov bl, 2 div bl mov bh, 01110100b mov bl, ’+’ mov cx, al ciclo1: mov es:[di], bx mov es:[si], bx mov ah, 4ch int 21h main endp cseg ends end main
global _dialog_box _dialog_box: push bp mov bp, sp mov ax, word [bp+4] mov bx, word [bp+6] mov cx, word [bp+8] movzx dx, byte [bp+10] call os_dialog_box pop bp ret
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1991 -- All Rights Reserved PROJECT: GeoDraw FILE: graphicHead.asm AUTHOR: Steve Scholl, Jun 18, 1991 ROUTINES: Name ---- INT GrObjHeadCreateBlock INT GrObjHeadCreateFloater INT GrObjHeadDestroyFloater INT GrObjHeadGetCurrentBody INT GrObjHeadMessageToFloater INT GrObjHeadAllLargePTRS METHOD HANDLERS: Name ---- GrObjHeadSetCurrentTool GrObjHeadSetCurrentToolWithDataBlock GrObjHeadGetCurrentTool GrObjHeadSetCurrentBody GrObjHeadFloaterFinishedCreate GrObjHeadClassedEventToFloater GrObjHeadClassedEventToFloaterIfCurrentBody REVISION HISTORY: Name Date Description ---- ---- ----------- Steve 06/19/91 Initial revision DESCRIPTION: $Id: head.asm,v 1.1 97/04/04 18:08:15 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjClassStructures segment resource GrObjHeadClass GrObjClassStructures ends GrObjInitCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadBuild %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Return desired super class PASS: *(ds:si) - instance data of object ds:[bx] - instance data of object ds:[di] - master part of object (if any) es - segment of GrObjHeadClass RETURN: cx:dx - fptr to super class DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 7/23/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadBuild method dynamic GrObjHeadClass, MSG_META_RESOLVE_VARIANT_SUPERCLASS .enter mov cx,segment VisEmptyClass mov dx,offset VisEmptyClass .leave ret GrObjHeadBuild endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadSendNotifyCurrentTool %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Description: Sends UI notification to update anyone who cares about the current grobj tool. Pass: *ds:si = GrObjHead Return: nothing Destroyed: nothing Comments: Revision History: Name Date Description ---- ------------ ----------- jon Apr 2, 1992 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadSendNotifyCurrentTool method GrObjHeadClass, MSG_GH_SEND_NOTIFY_CURRENT_TOOL uses bx, cx, dx, bp .enter movdw cxdx, ds:[di].GH_currentTool mov bp, ds:[di].GH_initializeFloaterData mov bx, size GrObjNotifyCurrentTool call GrObjGlobalAllocNotifyBlock push ds call MemLock mov ds, ax mov ds:[GONCT_toolClass].segment, cx mov ds:[GONCT_toolClass].offset, dx mov ds:[GONCT_specInitData], bp call MemUnlock pop ds mov cx, GAGCNLT_APP_TARGET_NOTIFY_GROBJ_CURRENT_TOOL_CHANGE mov dx, GWNT_GROBJ_CURRENT_TOOL_CHANGE call GrObjGlobalUpdateControllerLow .leave ret GrObjHeadSendNotifyCurrentTool endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadGetCurrentTool %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Gets the current tool class. PASS: *(ds:si) - instance data of object ds:[bx] - instance data of object ds:[di] - master part of object (if any) es - segment of GrObjHeadClass RETURN: cx:dx - fptr to object class bp - MSG_GO_GROBJ_SPECIFIC_INITIALIZE data DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 6/18/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadGetCurrentTool method dynamic GrObjHeadClass, MSG_GH_GET_CURRENT_TOOL .enter movdw cxdx, ds:[di].GH_currentTool mov bp, ds:[di].GH_initializeFloaterData .leave ret GrObjHeadGetCurrentTool endm GrObjInitCode ends GrObjRequiredInteractiveCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadCreateBlock %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Allocate an object block CALLED BY: INTERNAL GrObjHeadCreateFloater PASS: nothing RETURN: bx - handle of block DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 6/18/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadCreateBlock proc near .enter call GeodeGetProcessHandle call ProcInfo call UserAllocObjBlock .leave ret GrObjHeadCreateBlock endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadCallFloater %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Send encapsulated message to floater and return params PASS: *(ds:si) - instance data of object ds:[bx] - instance data of object ds:[di] - master part of object (if any) es - segment of GrObjHeadClass cx - message handle RETURN: ax,cx,dx,bp - from floater DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: This method should be optimized for SMALL SIZE over SPEED Common cases: unknown REVISION HISTORY: Name Date Description ---- ---- ----------- srs 10/ 5/92 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadCallFloater method dynamic GrObjHeadClass, MSG_GH_CALL_FLOATER .enter call GrObjHeadGuaranteeFloater mov bx,cx ;event handle movdw cxsi,ds:[di].GH_floater call MessageSetDestination mov di,mask MF_CALL or mask MF_FIXUP_DS call MessageDispatch .leave ret GrObjHeadCallFloater endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadMessageToFloater %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Send a message to the floater CALLED BY: INTERNAL PASS: *(ds:si) - graphic head ax - message cx,dx,bp - other message data di - MessageFlags RETURN: if no floater return zero flag set else zero flag cleared if MF_CALL ax,cx,dx,bp no flags except carry otherwise nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 7/18/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadMessageToFloater proc far class GrObjHeadClass uses bx,si,di .enter EC < call ECGrObjHeadCheckLMemObject > call GrObjHeadGuaranteeFloater mov si,ds:[si] mov bx,ds:[si].GH_floater.handle tst bx jz done mov si,ds:[si].GH_floater.chunk ornf di, mask MF_FIXUP_DS call ObjMessage ; Clear zero flag to signify message being sent ; ClearZeroFlagPreserveCarry si done: .leave ret GrObjHeadMessageToFloater endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadClassedEventToFloater %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Send the encapuslated method to the floater object with a MSG_META_SEND_CLASSED_EVENT PASS: *(ds:si) - instance data of object cx - recorded message handle RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: WARNING: This message handler is not dynamic, so it can be called as a routine. Thusly, only *ds:si can be counted on. And it must be careful about the regsiters is destroys. REVISION HISTORY: Name Date Description ---- ---- ----------- srs 7/16/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadClassedEventToFloater method GrObjHeadClass, \ MSG_GH_CLASSED_EVENT_TO_FLOATER uses ax,bx,dx,di .enter mov di,ds:[si] mov bx,ds:[di].GH_floater.handle tst bx jz done mov si,ds:[di].GH_floater.chunk mov di,mask MF_FIXUP_DS mov ax,MSG_META_SEND_CLASSED_EVENT mov dx, TO_SELF call ObjMessage done: .leave ret GrObjHeadClassedEventToFloater endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadClassedEventToFloaterIfCurrentBody %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Send the encapuslated method to the floater object if the passed body od is the current body PASS: *(ds:si) - instance data of object ds:[bx] - instance data of object ds:[di] - master part of object (if any) es - segment of GrObjHeadClass cx - recorded message handle dx:bp - od of body RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 7/16/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadClassedEventToFloaterIfCurrentBody \ method dynamic GrObjHeadClass, \ MSG_GH_CLASSED_EVENT_TO_FLOATER_IF_CURRENT_BODY uses ax,cx .enter ; Get current body od and compare to passed one ; call GrObjHeadGetCurrentBody cmp dx,ax ;body handles jne done cmp bp,bx ;body chunks jne done call GrObjHeadClassedEventToFloater done: .leave ret GrObjHeadClassedEventToFloaterIfCurrentBody endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadFloaterFinishedCreate %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Notify head that the current floater has just completed creation of a new object. Reset the instance data of the current floater and notify the application that a tool has completed its job PASS: *(ds:si) - instance data of object ds:[bx] - instance data of object ds:[di] - master part of object (if any) es - segment of GrObjHeadClass RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 7/18/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadFloaterFinishedCreate method dynamic GrObjHeadClass, MSG_GH_FLOATER_FINISHED_CREATE .enter mov ax,MSG_GO_REACTIVATE_CREATE clr di ;MessageFlags call GrObjHeadMessageToFloater .leave ret GrObjHeadFloaterFinishedCreate endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadGetCurrentBody %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Return current body od PASS: *(ds:si) - instance data of head RETURN: ax:bx - OD of current body ( 0 if no current body ) DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 6/24/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadGetCurrentBody proc near class GrObjHeadClass uses di,si .enter EC < call ECGrObjHeadCheckLMemObject > mov di,ds:[si] mov ax,ds:[di].GH_currentBody.handle mov bx,ds:[di].GH_currentBody.chunk .leave ret GrObjHeadGetCurrentBody endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadSetCurrentTool %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Sets the current tool class and instantiates a tool of this class for the floater object and sends the new object MSG_GO_OBJECT_SPECIFIC_INIITIALIZE with the data passed in bp PASS: *(ds:si) - instance data of object ds:[bx] - instance data of object ds:[di] - master part of object (if any) es - segment of GrObjHeadClass cx:dx - fptr to object class bp - MSG_GO_GROBJ_SPECIFIC_INITIALIZE data RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 6/18/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadSetCurrentTool method dynamic GrObjHeadClass, MSG_GH_SET_CURRENT_TOOL .enter EC < jcxz noClass > EC < push es,di > EC < mov es,cx > EC < mov di,dx > EC < call ECCheckClass > EC < pop es,di > EC <noClass: > cmp ds:[di].GH_currentTool.offset,dx jne newClass cmp ds:[di].GH_currentTool.segment,cx jne newClass cmp ds:[di].GH_initializeFloaterData,bp jne newClass done: .leave ret newClass: ; Store new class in instance data ; movdw ds:[di].GH_currentTool,cxdx mov ds:[di].GH_initializeFloaterData,bp ; Create new floater of passed class ; call GrObjHeadCreateFloater mov ax, MSG_GH_SEND_NOTIFY_CURRENT_TOOL call ObjCallInstanceNoLock jmp done GrObjHeadSetCurrentTool endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadSetCurrentToolWithDataBlock %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Sets the current tool class and instantiates a tool of this class for the floater object and sends the new object MSG_GO_OBJECT_SPECIFIC_INIITIALIZE_WITH_DATA_BLOCK with the data block passed in bp PASS: *(ds:si) - instance data of object ds:[bx] - instance data of object ds:[di] - master part of object (if any) es - segment of GrObjHeadClass cx:dx - fptr to object class bp - data block RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 6/18/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadSetCurrentToolWithDataBlock method dynamic GrObjHeadClass, MSG_GH_SET_CURRENT_TOOL_WITH_DATA_BLOCK .enter EC < push es,di > EC < mov es,cx > EC < mov di,dx > EC < call ECCheckClass > EC < pop es,di > ; Store new class in instance data ; movdw ds:[di].GH_currentTool,cxdx ; Create new floater of passed class ; call GrObjHeadCreateFloaterWithDataBlock .leave ret GrObjHeadSetCurrentToolWithDataBlock endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadSetCurrentBody %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Make the passed body the current one. PASS: *(ds:si) - instance data of object ds:[bx] - instance data of object ds:[di] - master part of object (if any) es - segment of GrObjHeadClass cx:dx - body to be made the current one RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: This method should be optimized for SMALL SIZE over SPEED Common cases: unknown REVISION HISTORY: Name Date Description ---- ---- ----------- srs 6/26/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadSetCurrentBody method dynamic GrObjHeadClass, MSG_GH_SET_CURRENT_BODY uses ax,cx,dx,bp .enter ; Don't do anything if this body is already the current one ; cmp ds:[di].GH_currentBody.handle,cx jne setNew cmp ds:[di].GH_currentBody.chunk,dx je done ; Store the new body od ; setNew: mov ds:[di].GH_currentBody.handle,cx mov ds:[di].GH_currentBody.chunk,dx tst ds:[di].GH_floater.handle jz newFloater ; ; Store the body in the floater's obj block output ; call GrObjHeadSetBodyInFloaterBlock ; Activate the new floater. This will cause it to notify ; any selected or edited objects in the new body. ; call GrObjHeadActivateCreateFloater mov di, ds:[si] mov cx,ds:[di].GH_currentTool.segment mov dx,ds:[di].GH_currentTool.offset mov bp,ds:[di].GH_initializeFloaterData updateController: mov ax, MSG_GH_SEND_NOTIFY_CURRENT_TOOL call ObjCallInstanceNoLock done: .leave ret newFloater: ; Create floater of current tool class, if ; class has been set ; movdw cxdx,ds:[di].GH_currentTool mov bp,ds:[di].GH_initializeFloaterData jcxz updateController call GrObjHeadCreateFloater jmp updateController GrObjHeadSetCurrentBody endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadSetBodyInFloaterBlock %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Description: Sets the OLMBH_output field of the floater's block to the passed body Pass: *ds:si - GrObjHead ^lcx:dx - GrObjBody Return: nothing Destroyed: nothing Revision History: Name Date Description ---- ------------ ----------- jon Jul 16, 1992 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadSetBodyInFloaterBlock proc near class GrObjHeadClass uses ax, bx, es .enter mov bx, ds:[si] mov bx, ds:[bx].GH_floater.handle tst bx jz done call ObjLockObjBlock mov es, ax movdw es:[OLMBH_output], cxdx call MemUnlock done: .leave ret GrObjHeadSetBodyInFloaterBlock endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadClearCurrentBody %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Clear the current body if it is the passed body. PASS: *(ds:si) - instance data of object ds:[bx] - instance data of object ds:[di] - master part of object (if any) es - segment of GrObjHeadClass cx:dx - body to clear RETURN: nothing DESTROYED: ax PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 6/26/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadClearCurrentBody method dynamic GrObjHeadClass, MSG_GH_CLEAR_CURRENT_BODY uses cx, dx .enter ; Get current body and compare to passed body, if ; different then just exit, otherwise clear current body ; call GrObjHeadGetCurrentBody sub cx,ax ;compare handles jnz done sub dx,bx ;compare chunks jnz done call GrObjHeadSetBodyInFloaterBlock mov di,ds:[si] mov ds:[di].GH_currentBody.handle,cx ;ax=0 from sub mov ds:[di].GH_currentBody.chunk,cx done: .leave ret GrObjHeadClearCurrentBody endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadGuaranteeFloater %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: If we don't have a floater then create one. Unless we have no tool class. Then do nothing CALLED BY: INTERNAL UTILITY PASS: *ds:si - GrObjHead RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: This routine should be optimized for SMALL SIZE over SPEED Common cases: Floater exists REVISION HISTORY: Name Date Description ---- ---- ----------- srs 1/25/93 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadGuaranteeFloater proc near class GrObjHeadClass uses cx,dx,bp,di .enter EC < call ECGrObjHeadCheckLMemObject > mov di,ds:[si] tst ds:[di].GH_floater.handle jz create done: .leave ret create: movdw cxdx,ds:[di].GH_currentTool mov bp,ds:[di].GH_initializeFloaterData jcxz done call GrObjHeadCreateFloater jmp done GrObjHeadGuaranteeFloater endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadCreateFloater %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Create a new floater and destroy any existing floater in the process. Stores od of new floater in graphicHead instance data. CALLED BY: INTERNAL GrObjHeadSetCurrentTool PASS: *ds:si - GrObjHead object cx:dx - fptr to class of floater bp - Word of data to be sent with MSG_GO_OBJECT_SPECIFIC_INIITIALIZE to the floater when it is instantiated RETURN: floater od in GH_floater DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 6/24/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadCreateFloater proc near class GrObjHeadClass uses ax,bx,cx,dx,di,es .enter EC < jcxz noClass > EC < call ECGrObjHeadCheckLMemObject > EC < push es,di > EC < mov es,cx > EC < mov di,dx > EC < call ECCheckClass > EC < pop es,di > EC <noClass: > call GrObjHeadDestroyFloater ; ; If we're passed a null class ptr, don't create a floater... ; jcxz done ; Create new floater push si ;head lmem mov es,cx ;floater class segment mov di,dx ;floater class offset call GrObjHeadCreateBlock call ObjInstantiate ; Store od of new floater in instance data ; mov_tr ax,si ;floater lmem pop si ;head lmem mov di,ds:[si] mov ds:[di].GH_floater.handle,bx mov ds:[di].GH_floater.chunk,ax call GrObjHeadGetCurrentBody mov cx,ax ;body handle mov dx,bx ;body chunk call GrObjHeadSetBodyInFloaterBlock ; Do object specific initialization ; mov ax,MSG_GO_GROBJ_SPECIFIC_INITIALIZE mov di,mask MF_FIXUP_DS call GrObjHeadMessageToFloater ; Activate the new floater ; call GrObjHeadActivateCreateFloater done: .leave ret GrObjHeadCreateFloater endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadCreateFloaterWithDataBlock %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Create a new floater and destroy any existing floater in the process. Stores od of new floater in graphicHead instance data. CALLED BY: INTERNAL GrObjHeadSetCurrentTool PASS: *ds:si - GrObjHead object cx:dx - fptr to class of floater bp - Data block RETURN: floater od in GH_floater DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 6/24/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadCreateFloaterWithDataBlock proc near class GrObjHeadClass uses ax,bx,cx,dx,di,es .enter EC < call ECGrObjHeadCheckLMemObject > EC < push es,di > EC < mov es,cx > EC < mov di,dx > EC < call ECCheckClass > EC < pop es,di > call GrObjHeadDestroyFloater ; ; If we're passed a null class ptr, don't create a floater... ; jcxz done ; Create new floater push si ;head lmem mov es,cx ;floater class segment mov di,dx ;floater class offset call GrObjHeadCreateBlock call ObjInstantiate ; Store od of new floater in instance data ; mov ax,si ;floater lmem pop si ;head lmem mov di,ds:[si] mov ds:[di].GH_floater.handle,bx mov ds:[di].GH_floater.chunk,ax call GrObjHeadGetCurrentBody mov cx,ax ;body handle mov dx,bx ;body chunk call GrObjHeadSetBodyInFloaterBlock ; Do object specific initialization ; mov ax,MSG_GO_GROBJ_SPECIFIC_INITIALIZE_WITH_DATA_BLOCK mov di,mask MF_FIXUP_DS call GrObjHeadMessageToFloater ; Activate the new floater ; call GrObjHeadActivateCreateFloater done: .leave ret GrObjHeadCreateFloaterWithDataBlock endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadActivateCreateFloater %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Send MSG_GO_ACTIVATE_CREATE to the floater CALLED BY: INTERNAL GrObjHeadCreateFloater GrObjHeadSetCurrentBody GrObjSetCurrentTool PASS: *ds:si - GrObjHead RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: This routine should be optimized for SMALL SIZE over SPEED Common cases: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 2/15/92 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadActivateCreateFloater proc near uses ax,cx,di .enter EC < call ECGrObjHeadCheckLMemObject > mov cl,mask ACF_NOTIFY mov ax,MSG_GO_ACTIVATE_CREATE mov di,mask MF_FIXUP_DS call GrObjHeadMessageToFloater .leave ret GrObjHeadActivateCreateFloater endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadDestroyFloater %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Destroy the current floater CALLED BY: INTERNAL GrObjHeadCreateFloater PASS: *ds:si - graphicHead RETURN: nothing DESTROYED: nothing PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 6/24/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadDestroyFloater proc near class GrObjHeadClass uses ax,bx,cx,dx,di,si .enter EC < call ECGrObjHeadCheckLMemObject > ; Get OD of floater in bx:si and clear od in instance data ; mov di,ds:[si] clr bx xchg bx,ds:[di].GH_floater.handle clr si xchg si,ds:[di].GH_floater.chunk ; Exit if current od handle is zero ; tst bx ;floater handle jz done ; Vaporize floater ; mov ax,MSG_GO_CLEAR_SANS_UNDO mov di,mask MF_FIXUP_DS call ObjMessage done: .leave ret GrObjHeadDestroyFloater endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadAllLargePTRs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Pass ptr events onto the floater so we can get the pointer image set correctly. A ptr event should only arrive here from a body with no mouse grab. It is probably a body that is not the current target PASS: *(ds:si) - instance data of object ds:[bx] - instance data of object ds:[di] - master part of object (if any) es - segment of GrObjHeadClass ss:bp - LargeMouseData RETURN: ax - MouseReturnFlags if MRF_SET_POINTER_IMAGE then cx:dx: - optr of image else cx,dx - destroyed DESTROYED: bp, see RETURN PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 9/21/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadAllLargePTRs method dynamic GrObjHeadClass, MSG_META_LARGE_PTR .enter mov di,mask MF_CALL or mask MF_STACK or mask MF_FIXUP_DS mov dx,size LargeMouseData call GrObjHeadMessageToFloater jz noFloater done: .leave ret noFloater: ; Yow, there is no floater. ; clr ax jmp done GrObjHeadAllLargePTRs endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GrObjHeadSetTextToolForSearchSpell %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Set the current tool to the MultTextGuardianClass PASS: *(ds:si) - instance data of object ds:[bx] - instance data of object ds:[di] - master part of object (if any) es - segment of GrObjHeadClass RETURN: nothing DESTROYED: ax PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: This method should be optimized for SMALL SIZE over SPEED Common cases: unknown REVISION HISTORY: Name Date Description ---- ---- ----------- srs 12/11/92 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GrObjHeadSetTextToolForSearchSpell method dynamic GrObjHeadClass, MSG_GH_SET_TEXT_TOOL_FOR_SEARCH_SPELL uses cx,dx,bp .enter mov cx, segment MultTextGuardianClass mov dx, offset MultTextGuardianClass clr bp mov ax,MSG_GH_SET_CURRENT_TOOL call ObjCallInstanceNoLock .leave ret GrObjHeadSetTextToolForSearchSpell endm GrObjRequiredInteractiveCode ends if ERROR_CHECK GrObjErrorCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ECGrObjHeadCheckLMemObject %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Checks to see if *ds:si* is a pointer to an object stored in an object block and that it is an GrObjHeadClass or one of its subclasses CALLED BY: INTERNAL PASS: *(ds:si) - object chunk to check RETURN: none DESTROYED: nothing - not even flags PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- srs 2/24/90 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ECGrObjHeadCheckLMemObject proc far uses es,di .enter pushf call ECCheckLMemObject mov di,segment GrObjHeadClass mov es,di mov di,offset GrObjHeadClass call ObjIsObjectInClass ERROR_NC OBJECT_NOT_OF_CORRECT_CLASS popf .leave ret ECGrObjHeadCheckLMemObject endp GrObjErrorCode ends endif
; A321999: Sum of digits of n minus the number of digits of n. ; 0,0,1,2,3,4,5,6,7,8,-1,0,1,2,3,4,5,6,7,8,0,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,10,2,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,12,4,5,6,7,8,9,10,11,12,13,5,6,7,8,9,10,11,12,13,14,6,7,8,9,10,11,12,13,14,15,7 lpb $0 mov $2,$0 div $0,10 mod $2,10 sub $2,1 add $1,$2 lpe mov $0,$1
title "Histogram AVX Routines" option nokeyword:<Length> ;++ ; ; Copyright (c) 2018 Trent Nelson <trent@trent.me> ; ; Module Name: ; ; Histogram.asm ; ; Abstract: ; ; This module implements various routines for constructing histograms. ; ;-- include ksamd64.inc ; ; Define constants. ; OP_EQ equ 0 OP_NEQ equ 4 ; ; Define constant variables. ; ZMM_ALIGN equ 64 YMM_ALIGN equ 32 XMM_ALIGN equ 16 PVOID typedef ptr _DATA$00 SEGMENT PAGE 'DATA' align ZMM_ALIGN QuickLazy db "The quick brown fox jumps over the lazy dog. " align ZMM_ALIGN public Test1 Test1 db "ABACAEEFGIHIJJJKLMNDOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!!" align ZMM_ALIGN public Shuffle1 Shuffle1 db 64 dup (02h, 00h, 00h, 00h, 60 dup (00h)) align ZMM_ALIGN public AllOnes AllOnes dd 16 dup (1) align ZMM_ALIGN public AllNegativeOnes AllNegativeOnes dd 16 dup (-1) align ZMM_ALIGN public AllBinsMinusOne AllBinsMinusOne dd 16 dup (254) align ZMM_ALIGN public AllThirtyOne AllThirtyOne dd 16 dup (31) _DATA$00 ends IACA_VC_START macro Name mov byte ptr gs:[06fh], 06fh endm IACA_VC_END macro Name mov byte ptr gs:[0deh], 0deh endm ; ; Define the LONG_STRING structure used to encapsulate string information. ; LONG_STRING struct Length dd ? Hash dd ? Buffer dq ? LONG_STRING ends PLONG_STRING typedef ptr LONG_STRING ; ; Define the CHARACTER_HISTOGRAM structure used to encapsulate the histogram. ; CHARACTER_HISTOGRAM struct Count dd 256 dup (?) CHARACTER_HISTOGRAM ends PCHARACTER_HISTOGRAM typedef ptr CHARACTER_HISTOGRAM CHARACTER_HISTOGRAM_V4 struct Histogram1 CHARACTER_HISTOGRAM { } Histogram2 CHARACTER_HISTOGRAM { } Histogram3 CHARACTER_HISTOGRAM { } Histogram4 CHARACTER_HISTOGRAM { } CHARACTER_HISTOGRAM_V4 ends PCHARACTER_HISTOGRAM_V4 typedef ptr CHARACTER_HISTOGRAM_V4 ; ; Define a Locals structure used for referencing our register homing space from ; rsp. ; Locals struct Temp dq ? ; ; Define non-volatile register storage. ; union FirstNvRegister dq ? SavedRbp dq ? ends SavedRbx dq ? SavedRdi dq ? SavedRsi dq ? SavedR12 dq ? SavedR13 dq ? SavedR14 dq ? SavedXmm6 XMMWORD { } SavedXmm7 XMMWORD { } SavedXmm8 XMMWORD { } SavedXmm9 XMMWORD { } SavedXmm10 XMMWORD { } SavedXmm11 XMMWORD { } SavedXmm12 XMMWORD { } SavedXmm13 XMMWORD { } SavedXmm14 XMMWORD { } SavedXmm15 XMMWORD { } ; ; Stash R15 after the return address to ensure the XMM register space ; is aligned on a 16 byte boundary, as we use movdqa (i.e. aligned move) ; which will fault if we're only 8 byte aligned. ; SavedR15 dq ? ReturnAddress dq ? HomeRcx dq ? HomeRdx dq ? HomeR8 dq ? HomeR9 dq ? Locals ends ; ; Exclude the return address onward from the frame calculation size. ; LOCALS_SIZE equ ((sizeof Locals) + (Locals.ReturnAddress - (sizeof Locals))) Locals4 struct Temp dq ? ; ; Define non-volatile register storage. ; union FirstNvRegister dq ? SavedR12 dq ? ends SavedR13 dq ? SavedR14 dq ? SavedR15 dq ? ReturnAddress dq ? HomeRcx dq ? HomeRdx dq ? HomeR8 dq ? HomeR9 dq ? Locals4 ends ; ; Exclude the return address onward from the frame calculation size. ; LOCALS4_SIZE equ ((sizeof Locals4) + (Locals4.ReturnAddress - (sizeof Locals4))) ; ; Define helper typedefs that are nicer to work with in assembly than their long ; uppercase name counterparts. ; String typedef LONG_STRING Histogram typedef CHARACTER_HISTOGRAM_V4 ;++ ; ; BOOLEAN ; CreateHistogramAlignedAsm( ; _In_ PCLONG_STRING String, ; _Inout_updates_bytes_(sizeof(*Histogram)) ; PCHARACTER_HISTOGRAM_V4 Histogram ; ); ; ; Routine Description: ; ; This routine creates a histogram for a given string. ; ; Arguments: ; ; String (rcx) - Supplies a pointer to a LONG_STRING structure that contains ; the string for which a histogram is to be created. ; ; Histogram (rdx) - Supplies an address that receives the histogram for the ; given input string. ; ; Return Value: ; ; TRUE on success, FALSE on failure. ; ;-- LEAF_ENTRY CreateHistogramAlignedAsm, _TEXT$00 ; ; Clear return value (Success = FALSE). ; xor rax, rax ; Clear rax. ; ; Validate parameters. ; test rcx, rcx ; Is rcx NULL? jz Cha99 ; Yes, abort. test rdx, rdx ; Is rdx NULL? jz Cha99 ; Yes, abort. ; ; Verify the string is at least 64 bytes long. ; mov r9, 64 ; Initialize r9 to 64. cmp String.Length[rcx], r9d ; Compare Length to 64. jl Cha99 ; String is too short. ; ; Ensure the incoming string and histogram buffers are aligned to 32-byte ; boundaries. ; mov r9, 31 ; Initialize r9 to 31. test String.Buffer[rcx], r9 ; Is string aligned? jnz Cha99 ; No, abort. ; ; Initialize loop variables. ; ; rcx - Counter. ; ; rdx - Base string buffer. ; ; r8 - Base address of first histogram buffer. ; ; r9 - Base address of second histogram buffer. ; ; r10 - Loop counter (string length shifted right 3 times). ; mov r8, rdx ; Load 1st histo buffer. lea r9, Histogram.Histogram2[r8] ; Load 2nd histo buffer. mov rdx, String.Buffer[rcx] ; Load string buffer. mov r10d, String.Length[rcx] ; Load string length. shr r10, 3 ; Divide by 8 to get loop ; iterations. ; ; Top of the histogram loop. ; align 16 ;IACA_VC_START ; ; Load 8 bytes into rax and advance the buffer pointer rdx. ; Cha50: mov rax, [rdx] ; Load 8 bytes into rax. add rdx, 8 ; Bump pointer. ; ; Process bytes 1 and 2. ; movzx rcx, al ; Isolate lower byte. add dword ptr [r8 + rcx * 4], 1 ; Update count for lower. movzx ecx, ah ; Isolate upper byte. shr rax, 16 ; Shift to the next two bytes. add dword ptr [r8 + rcx * 4], 1 ; Update count for upper byte. ; ; Process bytes 3 and 4. ; movzx rcx, al ; Isolate lower byte. add dword ptr [r8 + rcx * 4], 1 ; Update count for lower. movzx ecx, ah ; Isolate upper byte. shr rax, 16 ; Shift to the next two bytes. add dword ptr [r8 + rcx * 4], 1 ; Update count for upper byte. ; ; Process bytes 5 and 6. ; movzx rcx, al ; Isolate lower byte. add dword ptr [r8 + rcx * 4], 1 ; Update count for lower. movzx ecx, ah ; Isolate upper byte. shr rax, 16 ; Shift to the next two bytes. add dword ptr [r8 + rcx * 4], 1 ; Update count for upper byte. ; ; Process bytes 7 and 8. ; movzx rcx, al ; Isolate lower byte. add dword ptr [r8 + rcx * 4], 1 ; Update count for lower. movzx ecx, ah ; Isolate upper byte. add dword ptr [r8 + rcx * 4], 1 ; Update count for upper byte. ; ; End of loop. Update loop counter and determine if we're finished. ; sub r10, 1 ; Decrement loop counter. jnz short Cha50 ; If nz, continue loop. ; ; We've finished creating the histogram. Indicate success and return. ; Cha98: mov rax, 1 ;IACA_VC_END Cha99: ret LEAF_END CreateHistogramAlignedAsm, _TEXT$00 ; ; Alternate version of routine above that uses two histogram buffers and sums ; them at the end. ; LEAF_ENTRY CreateHistogramAlignedAsm_v2, _TEXT$00 ; ; Clear return value (Success = FALSE). ; xor rax, rax ; Clear rax. ; ; Validate parameters. ; test rcx, rcx ; Is rcx NULL? jz Cha99 ; Yes, abort. test rdx, rdx ; Is rdx NULL? jz Cha99 ; Yes, abort. ; ; Verify the string is at least 64 bytes long. ; mov r9, 64 ; Initialize r9 to 64. cmp String.Length[rcx], r9d ; Compare Length to 64. jl Cha99 ; String is too short. ; ; Ensure the incoming string and histogram buffers are aligned to 32-byte ; boundaries. ; mov r9, 31 ; Initialize r9 to 31. test String.Buffer[rcx], r9 ; Is string aligned? jnz Cha99 ; No, abort. ; ; Initialize loop variables. ; ; rcx - Counter. ; ; rdx - Base string buffer. ; ; r8 - Base address of first histogram buffer. ; ; r9 - Base address of second histogram buffer. ; ; r10 - Loop counter (string length shifted right 3 times). ; mov r8, rdx ; Load 1st histo buffer. lea r9, Histogram.Histogram2[r8] ; Load 2nd histo buffer. mov rdx, String.Buffer[rcx] ; Load string buffer. mov r10d, String.Length[rcx] ; Load string length. shr r10, 3 ; Divide by 8 to get loop ; iterations. ; ; Top of the histogram loop. ; align 16 ;IACA_VC_START ; ; Load 8 bytes into rax and advance the buffer pointer rdx. ; Cha50: mov rax, [rdx] ; Load 8 bytes into rax. add rdx, 8 ; Bump pointer. ; ; Process bytes 1 and 2. ; movzx rcx, al ; Isolate lower byte. add dword ptr [r8 + rcx * 4], 1 ; Update count for lower. movzx ecx, ah ; Isolate upper byte. shr rax, 16 ; Shift to the next two bytes. add dword ptr [r9 + rcx * 4], 1 ; Update count for upper byte. ; ; Process bytes 3 and 4. ; movzx rcx, al ; Isolate lower byte. add dword ptr [r8 + rcx * 4], 1 ; Update count for lower. movzx ecx, ah ; Isolate upper byte. shr rax, 16 ; Shift to the next two bytes. add dword ptr [r9 + rcx * 4], 1 ; Update count for upper byte. ; ; Process bytes 5 and 6. ; movzx rcx, al ; Isolate lower byte. add dword ptr [r8 + rcx * 4], 1 ; Update count for lower. movzx ecx, ah ; Isolate upper byte. shr rax, 16 ; Shift to the next two bytes. add dword ptr [r9 + rcx * 4], 1 ; Update count for upper byte. ; ; Process bytes 7 and 8. ; movzx rcx, al ; Isolate lower byte. add dword ptr [r8 + rcx * 4], 1 ; Update count for lower. movzx ecx, ah ; Isolate upper byte. shr rax, 16 ; Shift to the next two bytes. add dword ptr [r9 + rcx * 4], 1 ; Update count for upper byte. ; ; End of loop. Update loop counter and determine if we're finished. ; sub r10, 1 ; Decrement loop counter. jnz short Cha50 ; If nz, continue loop. ; ; We've finished creating the histogram. Merge the two histograms 64 bytes at ; a time using YMM registers. ; mov ecx, 16 ; Initialize counter. align 16 Cha75: vmovntdqa ymm0, ymmword ptr [r8+rax] ; Load 1st histo 0-31. vmovntdqa ymm1, ymmword ptr [r8+rax+20h] ; Load 1st histo 32-63. vmovntdqa ymm2, ymmword ptr [r9+rax] ; Load 2nd histo 0-31. vmovntdqa ymm3, ymmword ptr [r9+rax+20h] ; Load 2nd histo 32-63. vpaddd ymm4, ymm0, ymm2 ; Add 0-31 counts. vpaddd ymm5, ymm1, ymm3 ; Add 32-63 counts. vmovntdq ymmword ptr [r8+rax], ymm4 ; Save counts for 0-31. vmovntdq ymmword ptr [r8+rax+20h], ymm5 ; Save counts for 32-63. add rax, 40h ; Advance to next 64 bytes. sub ecx, 1 ; Decrement loop counter. jnz short Cha75 ; Continue if != 0. ; ; Indicate success and return. ; Cha98: mov rax, 1 ;IACA_VC_END Cha99: ret LEAF_END CreateHistogramAlignedAsm_v2, _TEXT$00 ;++ ; ; BOOLEAN ; CreateHistogramAvx2AlignedAsm( ; _In_ PCLONG_STRING String, ; _Inout_updates_bytes_(sizeof(*Histogram)) ; PCHARACTER_HISTOGRAM_V4 Histogram ; ); ; ; Routine Description: ; ; This routine creates a histogram for a given string. ; ; Arguments: ; ; String (rcx) - Supplies a pointer to a LONG_STRING structure that contains ; the string for which a histogram is to be created. ; ; Histogram (rdx) - Supplies an address that receives the histogram for the ; given input string. ; ; Return Value: ; ; TRUE on success, FALSE on failure. ; ;-- LEAF_ENTRY CreateHistogramAvx2AlignedAsm, _TEXT$00 ; ; Clear return value (Success = FALSE). ; xor rax, rax ; Clear rax. ; ; Validate parameters. ; test rcx, rcx ; Is rcx NULL? jz Cha99 ; Yes, abort. test rdx, rdx ; Is rdx NULL? jz Cha99 ; Yes, abort. ; ; Verify the string is at least 64 bytes long. ; mov r9, 64 ; Initialize r9 to 64. cmp String.Length[rcx], r9d ; Compare Length to 64. jl Cha99 ; String is too short. ; ; Ensure the incoming string and histogram buffers are aligned to 32-byte ; boundaries. ; mov r9, 31 ; Initialize r9 to 31. test String.Buffer[rcx], r9 ; Is string aligned? jnz Cha99 ; No, abort. ; ; Initialize loop variables. ; ; rcx - Counter. ; ; rdx - Base string buffer. ; ; r8 - Base address of first histogram buffer. ; ; r9 - Base address of second histogram buffer. ; ; r10 - Byte counter. ; ; r11 - Byte counter. ; mov r8, rdx ; Load 1st histo buffer. lea r9, Histogram.Histogram2[r8] ; Load 2nd histo buffer. mov rdx, String.Buffer[rcx] ; Load string buffer. mov ecx, String.Length[rcx] ; Load string length. shr ecx, 5 ; Divide by 32 to get loop ; iterations. ; ; Top of the histogram loop. ; align 16 ;IACA_VC_START ; ; Load the first 32 bytes into ymm0. Duplicate the lower 16 bytes in xmm0 and ; xmm1, then extract the high 16 bytes into xmm2 and xmm3. ; Cha50: vmovntdqa ymm0, ymmword ptr [rdx] ; Load 32 bytes into ymm0. vextracti128 xmm2, ymm0, 1 ; Copy 16-31 bytes to xmm2. vmovdqa xmm1, xmm0 ; Duplicate xmm0 into xmm1. vmovdqa xmm3, xmm2 ; Duplicate xmm2 into xmm3. add rdx, 32 ; Increment pointer. ; ; Process bytes 0-15, registers xmm0 and xmm1. ; vpextrb r10, xmm0, 0 ; Extract byte 0. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 1 ; Extract byte 1. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 2 ; Extract byte 2. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 3 ; Extract byte 3. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 4 ; Extract byte 4. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 5 ; Extract byte 5. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 6 ; Extract byte 6. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 7 ; Extract byte 7. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 8 ; Extract byte 8. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 9 ; Extract byte 9. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 10 ; Extract byte 10. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 11 ; Extract byte 11. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 12 ; Extract byte 12. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 13 ; Extract byte 13. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 14 ; Extract byte 14. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 15 ; Extract byte 15. add dword ptr [r9 + r11 * 4], 1 ; Update count. ; ; Continue processing the second set of 16 bytes (16-31) via xmm2 and xmm3. ; vpextrb r10, xmm2, 0 ; Extract byte 16. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 1 ; Extract byte 17. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 2 ; Extract byte 18. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 3 ; Extract byte 19. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 4 ; Extract byte 20. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 5 ; Extract byte 21. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 6 ; Extract byte 22. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 7 ; Extract byte 23. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 8 ; Extract byte 24. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 9 ; Extract byte 25. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 10 ; Extract byte 26. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 11 ; Extract byte 27. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 12 ; Extract byte 28. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 13 ; Extract byte 29. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 14 ; Extract byte 30. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 15 ; Extract byte 31. add dword ptr [r9 + r11 * 4], 1 ; Update count. ; ; End of loop. Update loop counter and determine if we're finished. ; sub ecx, 1 ; Decrement counter. jnz Cha50 ; Continue loop if != 0. ; ; We've finished creating the histogram. Merge the two histograms 64 bytes at ; a time using YMM registers. ; mov ecx, 16 ; Initialize counter. align 16 Cha75: vmovntdqa ymm0, ymmword ptr [r8+rax] ; Load 1st histo 0-31. vmovntdqa ymm1, ymmword ptr [r8+rax+20h] ; Load 1st histo 32-63. vmovntdqa ymm2, ymmword ptr [r9+rax] ; Load 2nd histo 0-31. vmovntdqa ymm3, ymmword ptr [r9+rax+20h] ; Load 2nd histo 32-63. vpaddd ymm4, ymm0, ymm2 ; Add 0-31 counts. vpaddd ymm5, ymm1, ymm3 ; Add 32-63 counts. vmovntdq ymmword ptr [r8+rax], ymm4 ; Save counts for 0-31. vmovntdq ymmword ptr [r8+rax+20h], ymm5 ; Save counts for 32-63. add rax, 40h ; Advance to next 64 bytes. sub ecx, 1 ; Decrement loop counter. jnz short Cha75 ; Continue if != 0. ; ; Indicate success and return. ; Cha98: mov rax, 1 ;IACA_VC_END Cha99: ret LEAF_END CreateHistogramAvx2AlignedAsm, _TEXT$00 LEAF_ENTRY CreateHistogramAvx2AlignedAsm_v2, _TEXT$00 ; ; Clear return value (Success = FALSE). ; xor rax, rax ; Clear rax. ; ; Validate parameters. ; test rcx, rcx ; Is rcx NULL? jz Cha99 ; Yes, abort. test rdx, rdx ; Is rdx NULL? jz Cha99 ; Yes, abort. ; ; Verify the string is at least 64 bytes long. ; mov r9, 64 ; Initialize r9 to 64. cmp String.Length[rcx], r9d ; Compare Length to 64. jl Cha99 ; String is too short. ; ; Ensure the incoming string and histogram buffers are aligned to 32-byte ; boundaries. ; mov r9, 31 ; Initialize r9 to 31. test String.Buffer[rcx], r9 ; Is string aligned? jnz Cha99 ; No, abort. ; ; Initialize loop variables. ; ; rcx - Counter. ; ; rdx - Base string buffer. ; ; r8 - Base address of first histogram buffer. ; ; r9 - Base address of second histogram buffer. ; ; r10 - Byte counter. ; ; r11 - Byte counter. ; mov r8, rdx ; Load 1st histo buffer. lea r9, Histogram.Histogram2[r8] ; Load 2nd histo buffer. mov rdx, String.Buffer[rcx] ; Load string buffer. mov ecx, String.Length[rcx] ; Load string length. shr ecx, 5 ; Divide by 16 to get loop ; iterations. ; ; Top of the histogram loop. ; align 16 ;IACA_VC_START ; ; Load the first 32 bytes into ymm0. Duplicate the lower 16 bytes in xmm0 and ; xmm1, then extract the high 16 bytes into xmm2 and xmm3. ; Cha50: vmovntdqa xmm0, xmmword ptr [rdx] ; Load 16 bytes into xmm0. vmovdqa xmm1, xmm0 ; Duplicate xmm0 into xmm1. vmovntdqa xmm2, xmmword ptr [rdx+10h] ; Load 16 bytes into xmm2. vmovdqa xmm3, xmm2 ; Duplicate xmm2 into xmm3. add rdx, 20h ; Increment pointer. ; ; Process bytes 0-15, registers xmm0 and xmm1. ; vpextrb r10, xmm0, 0 ; Extract byte 0. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 1 ; Extract byte 1. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 2 ; Extract byte 2. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 3 ; Extract byte 3. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 4 ; Extract byte 4. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 5 ; Extract byte 5. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 6 ; Extract byte 6. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 7 ; Extract byte 7. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 8 ; Extract byte 8. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 9 ; Extract byte 9. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 10 ; Extract byte 10. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 11 ; Extract byte 11. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 12 ; Extract byte 12. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 13 ; Extract byte 13. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 14 ; Extract byte 14. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 15 ; Extract byte 15. add dword ptr [r9 + r11 * 4], 1 ; Update count. ; ; Continue processing the second set of 16 bytes (16-31) via xmm2 and xmm3. ; vpextrb r10, xmm2, 0 ; Extract byte 16. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 1 ; Extract byte 17. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 2 ; Extract byte 18. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 3 ; Extract byte 19. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 4 ; Extract byte 20. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 5 ; Extract byte 21. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 6 ; Extract byte 22. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 7 ; Extract byte 23. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 8 ; Extract byte 24. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 9 ; Extract byte 25. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 10 ; Extract byte 26. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 11 ; Extract byte 27. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 12 ; Extract byte 28. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 13 ; Extract byte 29. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 14 ; Extract byte 30. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 15 ; Extract byte 31. add dword ptr [r9 + r11 * 4], 1 ; Update count. ; ; End of loop. Update loop counter and determine if we're finished. ; sub ecx, 1 ; Decrement counter. jnz Cha50 ; Continue loop if != 0. ; ; We've finished creating the histogram. Merge the two histograms 64 bytes at ; a time using YMM registers. ; mov ecx, 16 ; Initialize counter. align 16 Cha75: vmovntdqa ymm0, ymmword ptr [r8+rax] ; Load 1st histo 0-31. vmovntdqa ymm1, ymmword ptr [r8+rax+20h] ; Load 1st histo 32-63. vmovntdqa ymm2, ymmword ptr [r9+rax] ; Load 2nd histo 0-31. vmovntdqa ymm3, ymmword ptr [r9+rax+20h] ; Load 2nd histo 32-63. vpaddd ymm4, ymm0, ymm2 ; Add 0-31 counts. vpaddd ymm5, ymm1, ymm3 ; Add 32-63 counts. vmovntdq ymmword ptr [r8+rax], ymm4 ; Save counts for 0-31. vmovntdq ymmword ptr [r8+rax+20h], ymm5 ; Save counts for 32-63. add rax, 40h ; Advance to next 64 bytes. sub ecx, 1 ; Decrement loop counter. jnz short Cha75 ; Continue if != 0. ; ; Indicate success and return. ; Cha98: mov rax, 1 ;IACA_VC_END Cha99: ret LEAF_END CreateHistogramAvx2AlignedAsm_v2, _TEXT$00 LEAF_ENTRY CreateHistogramAvx2AlignedAsm_v3, _TEXT$00 ; ; Clear return value (Success = FALSE). ; xor rax, rax ; Clear rax. ; ; Validate parameters. ; test rcx, rcx ; Is rcx NULL? jz Cha99 ; Yes, abort. test rdx, rdx ; Is rdx NULL? jz Cha99 ; Yes, abort. ; ; Verify the string is at least 64 bytes long. ; mov r9, 64 ; Initialize r9 to 64. cmp String.Length[rcx], r9d ; Compare Length to 64. jl Cha99 ; String is too short. ; ; Ensure the incoming string and histogram buffers are aligned to 32-byte ; boundaries. ; mov r9, 31 ; Initialize r9 to 31. test String.Buffer[rcx], r9 ; Is string aligned? jnz Cha99 ; No, abort. ; ; Initialize loop variables. ; ; rcx - Counter. ; ; rdx - Base string buffer. ; ; r8 - Base address of first histogram buffer. ; ; r9 - Base address of second histogram buffer. ; ; r10 - Byte counter. ; ; r11 - Byte counter. ; mov r8, rdx ; Load 1st histo buffer. lea r9, Histogram.Histogram2[r8] ; Load 2nd histo buffer. mov rdx, String.Buffer[rcx] ; Load string buffer. mov ecx, String.Length[rcx] ; Load string length. shr ecx, 4 ; Divide by 16 to get loop ; iterations. ; ; Top of the histogram loop. ; align 16 ;IACA_VC_START ; ; Load 16 bytes into xmm0. ; Cha50: vmovntdqa xmm0, xmmword ptr [rdx] ; Load 16 bytes into xmm0. vmovdqa xmm1, xmm0 ; Duplicate xmm0 into xmm1. ;vmovntdqa xmm2, xmmword ptr [rdx+10h] ; Load 16 bytes into xmm2. ;vmovdqa xmm3, xmm2 ; Duplicate xmm2 into xmm3. add rdx, 10h ; Increment pointer. prefetchnta xmmword ptr [rdx] ; Prefetch next chunk. ; ; Process bytes 0-15, registers xmm0 and xmm1. ; vpextrb r10, xmm0, 0 ; Extract byte 0. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 1 ; Extract byte 1. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 2 ; Extract byte 2. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 3 ; Extract byte 3. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 4 ; Extract byte 4. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 5 ; Extract byte 5. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 6 ; Extract byte 6. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 7 ; Extract byte 7. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 8 ; Extract byte 8. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 9 ; Extract byte 9. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 10 ; Extract byte 10. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 11 ; Extract byte 11. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 12 ; Extract byte 12. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 13 ; Extract byte 13. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 14 ; Extract byte 14. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 15 ; Extract byte 15. add dword ptr [r9 + r11 * 4], 1 ; Update count. ; ; End of loop. Update loop counter and determine if we're finished. ; sub ecx, 1 ; Decrement counter. jnz Cha50 ; Continue loop if != 0. ; ; We've finished creating the histogram. Merge the two histograms 64 bytes at ; a time using YMM registers. ; mov ecx, 16 ; Initialize counter. align 16 Cha75: vmovntdqa ymm0, ymmword ptr [r8+rax] ; Load 1st histo 0-31. vmovntdqa ymm1, ymmword ptr [r8+rax+20h] ; Load 1st histo 32-63. vmovntdqa ymm2, ymmword ptr [r9+rax] ; Load 2nd histo 0-31. vmovntdqa ymm3, ymmword ptr [r9+rax+20h] ; Load 2nd histo 32-63. vpaddd ymm4, ymm0, ymm2 ; Add 0-31 counts. vpaddd ymm5, ymm1, ymm3 ; Add 32-63 counts. vmovntdq ymmword ptr [r8+rax], ymm4 ; Save counts for 0-31. vmovntdq ymmword ptr [r8+rax+20h], ymm5 ; Save counts for 32-63. add rax, 40h ; Advance to next 64 bytes. sub ecx, 1 ; Decrement loop counter. jnz short Cha75 ; Continue if != 0. ; ; Indicate success and return. ; Cha98: mov rax, 1 ;IACA_VC_END Cha99: ret LEAF_END CreateHistogramAvx2AlignedAsm_v3, _TEXT$00 NESTED_ENTRY CreateHistogramAvx2AlignedAsm_v4, _TEXT$00 alloc_stack LOCALS4_SIZE save_reg r12, Locals4.SavedR12 ; Save non-volatile r12. save_reg r13, Locals4.SavedR13 ; Save non-volatile r13. save_reg r14, Locals4.SavedR14 ; Save non-volatile r14. save_reg r15, Locals4.SavedR15 ; Save non-volatile r15. END_PROLOGUE ; ; Clear return value (Success = FALSE). ; xor rax, rax ; Clear rax. ; ; Validate parameters. ; test rcx, rcx ; Is rcx NULL? jz Cha99 ; Yes, abort. test rdx, rdx ; Is rdx NULL? jz Cha99 ; Yes, abort. ; ; Verify the string is at least 64 bytes long. ; mov r9, 64 ; Initialize r9 to 64. cmp String.Length[rcx], r9d ; Compare Length to 64. jl Cha99 ; String is too short. ; ; Ensure the incoming string and histogram buffers are aligned to 32-byte ; boundaries. ; mov r9, 31 ; Initialize r9 to 31. test String.Buffer[rcx], r9 ; Is string aligned? jnz Cha99 ; No, abort. ; ; Initialize loop variables. ; ; rcx - Counter. ; ; rdx - Base string buffer. ; ; r8 - Base address of first histogram buffer. ; ; r9 - Base address of second histogram buffer. ; ; r10 - Byte counter. ; ; r11 - Byte counter. ; mov r8, rdx ; Load 1st histo buffer. lea r9, Histogram.Histogram2[r8] ; Load 2nd histo buffer. lea r12, Histogram.Histogram3[r8] ; Load 3rd histo buffer. lea r13, Histogram.Histogram4[r8] ; Load 4th histo buffer. mov rdx, String.Buffer[rcx] ; Load string buffer. mov ecx, String.Length[rcx] ; Load string length. shr ecx, 5 ; Divide by 16 to get loop ; iterations. ; ; Top of the histogram loop. ; align 16 ;IACA_VC_START ; ; Load the first 32 bytes into ymm0. Duplicate the lower 16 bytes in xmm0 and ; xmm1, then extract the high 16 bytes into xmm2 and xmm3. ; Cha50: vmovntdqa xmm0, xmmword ptr [rdx] ; Load 16 bytes into xmm0. vmovdqa xmm1, xmm0 ; Duplicate xmm0 into xmm1. vmovntdqa xmm2, xmmword ptr [rdx+10h] ; Load 16 bytes into xmm2. vmovdqa xmm3, xmm2 ; Duplicate xmm2 into xmm3. add rdx, 20h ; Increment pointer. ; ; Process bytes 0-15, registers xmm0 and xmm1. ; vpextrb r10, xmm0, 0 ; Extract byte 0. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 1 ; Extract byte 1. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r14, xmm0, 2 ; Extract byte 2. add dword ptr [r12 + r14 * 4], 1 ; Update count. vpextrb r15, xmm1, 3 ; Extract byte 3. add dword ptr [r13 + r15 * 4], 1 ; Update count. vpextrb r10, xmm0, 4 ; Extract byte 4. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 5 ; Extract byte 5. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r14, xmm0, 6 ; Extract byte 6. add dword ptr [r12 + r14 * 4], 1 ; Update count. vpextrb r15, xmm1, 7 ; Extract byte 7. add dword ptr [r13 + r15 * 4], 1 ; Update count. vpextrb r10, xmm0, 8 ; Extract byte 8. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 9 ; Extract byte 9. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r14, xmm0, 10 ; Extract byte 10. add dword ptr [r12 + r14 * 4], 1 ; Update count. vpextrb r15, xmm1, 11 ; Extract byte 11. add dword ptr [r13 + r15 * 4], 1 ; Update count. vpextrb r10, xmm0, 12 ; Extract byte 12. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm1, 13 ; Extract byte 13. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r14, xmm0, 14 ; Extract byte 14. add dword ptr [r12 + r14 * 4], 1 ; Update count. vpextrb r15, xmm1, 15 ; Extract byte 15. add dword ptr [r13 + r15 * 4], 1 ; Update count. ; ; Continue processing the second set of 16 bytes (16-31) via xmm2 and xmm3. ; vpextrb r10, xmm2, 0 ; Extract byte 16. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 1 ; Extract byte 17. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r14, xmm2, 2 ; Extract byte 18. add dword ptr [r12 + r14 * 4], 1 ; Update count. vpextrb r15, xmm3, 3 ; Extract byte 19. add dword ptr [r13 + r15 * 4], 1 ; Update count. vpextrb r10, xmm2, 4 ; Extract byte 20. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 5 ; Extract byte 21. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r14, xmm2, 6 ; Extract byte 22. add dword ptr [r12 + r14 * 4], 1 ; Update count. vpextrb r15, xmm3, 7 ; Extract byte 23. add dword ptr [r13 + r15 * 4], 1 ; Update count. vpextrb r10, xmm2, 8 ; Extract byte 24. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 9 ; Extract byte 25. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r14, xmm2, 10 ; Extract byte 26. add dword ptr [r12 + r14 * 4], 1 ; Update count. vpextrb r15, xmm3, 11 ; Extract byte 27. add dword ptr [r13 + r15 * 4], 1 ; Update count. vpextrb r10, xmm2, 12 ; Extract byte 28. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm3, 13 ; Extract byte 29. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r14, xmm2, 14 ; Extract byte 30. add dword ptr [r12 + r14 * 4], 1 ; Update count. vpextrb r15, xmm3, 15 ; Extract byte 31. add dword ptr [r13 + r15 * 4], 1 ; Update count. ; ; End of loop. Update loop counter and determine if we're finished. ; sub ecx, 1 ; Decrement counter. jnz Cha50 ; Continue loop if != 0. ; ; We've finished creating the histogram. Merge the four histograms 64 bytes at ; a time using YMM registers. ; mov ecx, 16 ; Initialize counter. align 16 Cha75: vmovntdqa ymm0, ymmword ptr [r8+rax] ; Load 1st histo 0-31. vmovntdqa ymm2, ymmword ptr [r9+rax] ; Load 2nd histo 0-31. vpaddd ymm4, ymm0, ymm2 ; Add 0-31 counts. vmovntdqa ymm1, ymmword ptr [r8+rax+20h] ; Load 1st histo 32-63. vmovntdqa ymm3, ymmword ptr [r9+rax+20h] ; Load 2nd histo 32-63. vpaddd ymm5, ymm1, ymm3 ; Add 32-63 counts. vmovntdqa ymm0, ymmword ptr [r12+rax] ; Load 3rd histo 0-31. vmovntdqa ymm2, ymmword ptr [r13+rax] ; Load 4th histo 0-31. vpaddd ymm0, ymm0, ymm2 ; Add 3-4 0-31. vmovntdqa ymm1, ymmword ptr [r12+rax+20h] ; Load 3rd histo 32-63. vmovntdqa ymm3, ymmword ptr [r13+rax+20h] ; Load 4th histo 32-63. vpaddd ymm1, ymm1, ymm3 ; Add 3-4 32-64. vpaddd ymm4, ymm4, ymm0 ; Merge 1-2 & 3-4 for 0-31. vmovntdq ymmword ptr [r8+rax], ymm4 ; Save counts for 0-31. vpaddd ymm5, ymm5, ymm1 ; Merge 1-2 & 3-4 for 32-63. vmovntdq ymmword ptr [r8+rax+20h], ymm5 ; Save counts for 32-63. add rax, 40h ; Advance to next 64 bytes. sub ecx, 1 ; Decrement loop counter. jnz short Cha75 ; Continue if != 0. ; ; Indicate success and return. ; Cha98: mov rax, 1 ;IACA_VC_END Cha99: mov r12, Locals4.SavedR12[rsp] mov r13, Locals4.SavedR13[rsp] mov r14, Locals4.SavedR14[rsp] mov r15, Locals4.SavedR15[rsp] add rsp, LOCALS4_SIZE ret NESTED_END CreateHistogramAvx2AlignedAsm_v4, _TEXT$00 LEAF_ENTRY CreateHistogramAvx2AlignedAsm_v5, _TEXT$00 ; ; Clear return value (Success = FALSE). ; xor rax, rax ; Clear rax. ; ; Validate parameters. ; test rcx, rcx ; Is rcx NULL? jz Cha99 ; Yes, abort. test rdx, rdx ; Is rdx NULL? jz Cha99 ; Yes, abort. ; ; Verify the string is at least 64 bytes long. ; mov r9, 64 ; Initialize r9 to 64. cmp String.Length[rcx], r9d ; Compare Length to 64. jl Cha99 ; String is too short. ; ; Ensure the incoming string and histogram buffers are aligned to 32-byte ; boundaries. ; mov r9, 31 ; Initialize r9 to 31. test String.Buffer[rcx], r9 ; Is string aligned? jnz Cha99 ; No, abort. ; ; Initialize loop variables. ; ; rcx - Counter. ; ; rdx - Base string buffer. ; ; r8 - Base address of first histogram buffer. ; ; r9 - Base address of second histogram buffer. ; ; r10 - Byte counter. ; ; r11 - Byte counter. ; mov r8, rdx ; Load 1st histo buffer. lea r9, Histogram.Histogram2[r8] ; Load 2nd histo buffer. mov rdx, String.Buffer[rcx] ; Load string buffer. mov ecx, String.Length[rcx] ; Load string length. shr ecx, 5 ; Divide by 16 to get loop ; iterations. ; ; Top of the histogram loop. ; align 16 ;IACA_VC_START ; ; Load the first 32 bytes into ymm0. Duplicate the lower 16 bytes in xmm0 and ; xmm1, then extract the high 16 bytes into xmm2 and xmm3. ; Cha50: vmovntdqa xmm0, xmmword ptr [rdx] ; Load 16 bytes into xmm0. vmovntdqa xmm2, xmmword ptr [rdx+10h] ; Load 16 bytes into xmm2. add rdx, 20h ; Increment pointer. ; ; Process bytes 0-15, registers xmm0 and xmm1. ; vpextrb r10, xmm0, 0 ; Extract byte 0. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 1 ; Extract byte 1. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 2 ; Extract byte 2. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 3 ; Extract byte 3. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 4 ; Extract byte 4. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 5 ; Extract byte 5. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 6 ; Extract byte 6. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 7 ; Extract byte 7. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 8 ; Extract byte 8. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 9 ; Extract byte 9. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 10 ; Extract byte 10. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 11 ; Extract byte 11. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 12 ; Extract byte 12. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 13 ; Extract byte 13. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 14 ; Extract byte 14. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 15 ; Extract byte 15. add dword ptr [r9 + r11 * 4], 1 ; Update count. ; ; Continue processing the second set of 16 bytes (16-31) via xmm2 and xmm3. ; vpextrb r10, xmm2, 0 ; Extract byte 16. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 1 ; Extract byte 17. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 2 ; Extract byte 18. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 3 ; Extract byte 19. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 4 ; Extract byte 20. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 5 ; Extract byte 21. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 6 ; Extract byte 22. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 7 ; Extract byte 23. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 8 ; Extract byte 24. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 9 ; Extract byte 25. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 10 ; Extract byte 26. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 11 ; Extract byte 27. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 12 ; Extract byte 28. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 13 ; Extract byte 29. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 14 ; Extract byte 30. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 15 ; Extract byte 31. add dword ptr [r9 + r11 * 4], 1 ; Update count. ; ; End of loop. Update loop counter and determine if we're finished. ; sub ecx, 1 ; Decrement counter. jnz Cha50 ; Continue loop if != 0. ; ; We've finished creating the histogram. Merge the two histograms 64 bytes at ; a time using YMM registers. ; mov ecx, 16 ; Initialize counter. align 16 Cha75: vmovntdqa ymm0, ymmword ptr [r8+rax] ; Load 1st histo 0-31. vmovntdqa ymm1, ymmword ptr [r8+rax+20h] ; Load 1st histo 32-63. vmovntdqa ymm2, ymmword ptr [r9+rax] ; Load 2nd histo 0-31. vmovntdqa ymm3, ymmword ptr [r9+rax+20h] ; Load 2nd histo 32-63. vpaddd ymm4, ymm0, ymm2 ; Add 0-31 counts. vpaddd ymm5, ymm1, ymm3 ; Add 32-63 counts. vmovntdq ymmword ptr [r8+rax], ymm4 ; Save counts for 0-31. vmovntdq ymmword ptr [r8+rax+20h], ymm5 ; Save counts for 32-63. add rax, 40h ; Advance to next 64 bytes. sub ecx, 1 ; Decrement loop counter. jnz short Cha75 ; Continue if != 0. ; ; Indicate success and return. ; Cha98: mov rax, 1 ;IACA_VC_END Cha99: ret LEAF_END CreateHistogramAvx2AlignedAsm_v5, _TEXT$00 LEAF_ENTRY CreateHistogramAvx2AlignedAsm_v5_2, _TEXT$00 ; ; Clear return value (Success = FALSE). ; xor rax, rax ; Clear rax. ; ; Validate parameters. ; test rcx, rcx ; Is rcx NULL? jz Cha99 ; Yes, abort. test rdx, rdx ; Is rdx NULL? jz Cha99 ; Yes, abort. ; ; Verify the string is at least 64 bytes long. ; mov r9, 64 ; Initialize r9 to 64. cmp String.Length[rcx], r9d ; Compare Length to 64. jl Cha99 ; String is too short. ; ; Ensure the incoming string and histogram buffers are aligned to 32-byte ; boundaries. ; mov r9, 31 ; Initialize r9 to 31. test String.Buffer[rcx], r9 ; Is string aligned? jnz Cha99 ; No, abort. ; ; Initialize loop variables. ; ; rcx - Counter. ; ; rdx - Base string buffer. ; ; r8 - Base address of first histogram buffer. ; ; r9 - Base address of second histogram buffer. ; ; r10 - Byte counter. ; ; r11 - Byte counter. ; mov r8, rdx ; Load 1st histo buffer. lea r9, Histogram.Histogram2[r8] ; Load 2nd histo buffer. mov rdx, String.Buffer[rcx] ; Load string buffer. mov ecx, String.Length[rcx] ; Load string length. shr ecx, 5 ; Divide by 16 to get loop ; iterations. ; ; Top of the histogram loop. ; align 16 ;IACA_VC_START ; ; Load the first 32 bytes into ymm0. Duplicate the lower 16 bytes in xmm0 and ; xmm1, then extract the high 16 bytes into xmm2 and xmm3. ; Cha50: vmovdqa xmm0, xmmword ptr [rdx] ; Load 16 bytes into xmm0. vmovdqa xmm2, xmmword ptr [rdx+10h] ; Load 16 bytes into xmm2. add rdx, 20h ; Increment pointer. ; ; Process bytes 0-15, registers xmm0 and xmm1. ; vpextrb r10, xmm0, 0 ; Extract byte 0. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 1 ; Extract byte 1. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 2 ; Extract byte 2. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 3 ; Extract byte 3. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 4 ; Extract byte 4. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 5 ; Extract byte 5. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 6 ; Extract byte 6. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 7 ; Extract byte 7. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 8 ; Extract byte 8. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 9 ; Extract byte 9. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 10 ; Extract byte 10. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 11 ; Extract byte 11. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 12 ; Extract byte 12. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 13 ; Extract byte 13. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 14 ; Extract byte 14. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 15 ; Extract byte 15. add dword ptr [r9 + r11 * 4], 1 ; Update count. ; ; Continue processing the second set of 16 bytes (16-31) via xmm2 and xmm3. ; vpextrb r10, xmm2, 0 ; Extract byte 16. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 1 ; Extract byte 17. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 2 ; Extract byte 18. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 3 ; Extract byte 19. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 4 ; Extract byte 20. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 5 ; Extract byte 21. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 6 ; Extract byte 22. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 7 ; Extract byte 23. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 8 ; Extract byte 24. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 9 ; Extract byte 25. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 10 ; Extract byte 26. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 11 ; Extract byte 27. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 12 ; Extract byte 28. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 13 ; Extract byte 29. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 14 ; Extract byte 30. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 15 ; Extract byte 31. add dword ptr [r9 + r11 * 4], 1 ; Update count. ; ; End of loop. Update loop counter and determine if we're finished. ; sub ecx, 1 ; Decrement counter. jnz Cha50 ; Continue loop if != 0. ; ; We've finished creating the histogram. Merge the two histograms 64 bytes at ; a time using YMM registers. ; mov ecx, 16 ; Initialize counter. align 16 Cha75: vmovdqa ymm0, ymmword ptr [r8+rax] ; Load 1st histo 0-31. vmovdqa ymm1, ymmword ptr [r8+rax+20h] ; Load 1st histo 32-63. vmovdqa ymm2, ymmword ptr [r9+rax] ; Load 2nd histo 0-31. vmovdqa ymm3, ymmword ptr [r9+rax+20h] ; Load 2nd histo 32-63. vpaddd ymm4, ymm0, ymm2 ; Add 0-31 counts. vpaddd ymm5, ymm1, ymm3 ; Add 32-63 counts. vmovdqa ymmword ptr [r8+rax], ymm4 ; Save counts for 0-31. vmovdqa ymmword ptr [r8+rax+20h], ymm5 ; Save counts for 32-63. add rax, 40h ; Advance to next 64 bytes. sub ecx, 1 ; Decrement loop counter. jnz short Cha75 ; Continue if != 0. ; ; Indicate success and return. ; Cha98: mov rax, 1 ;IACA_VC_END Cha99: ret LEAF_END CreateHistogramAvx2AlignedAsm_v5_2, _TEXT$00 LEAF_ENTRY CreateHistogramAvx2AlignedAsm_v5_3, _TEXT$00 ; ; Clear return value (Success = FALSE). ; xor rax, rax ; Clear rax. ; ; Validate parameters. ; test rcx, rcx ; Is rcx NULL? jz Cha99 ; Yes, abort. test rdx, rdx ; Is rdx NULL? jz Cha99 ; Yes, abort. ; ; Verify the string is at least 64 bytes long. ; mov r9, 64 ; Initialize r9 to 64. cmp String.Length[rcx], r9d ; Compare Length to 64. jl Cha99 ; String is too short. ; ; Ensure the incoming string and histogram buffers are aligned to 32-byte ; boundaries. ; mov r9, 31 ; Initialize r9 to 31. test String.Buffer[rcx], r9 ; Is string aligned? jnz Cha99 ; No, abort. ; ; Initialize loop variables. ; ; rcx - Counter. ; ; rdx - Base string buffer. ; ; r8 - Base address of first histogram buffer. ; ; r9 - Base address of second histogram buffer. ; ; r10 - Byte counter. ; ; r11 - Byte counter. ; mov r8, rdx ; Load 1st histo buffer. lea r9, Histogram.Histogram2[r8] ; Load 2nd histo buffer. mov rdx, String.Buffer[rcx] ; Load string buffer. mov ecx, String.Length[rcx] ; Load string length. shr ecx, 5 ; Divide by 16 to get loop ; iterations. ; ; Top of the histogram loop. ; align 16 ;IACA_VC_START ; ; Load the first 32 bytes into ymm0. Duplicate the lower 16 bytes in xmm0 and ; xmm1, then extract the high 16 bytes into xmm2 and xmm3. ; Cha50: vmovdqa xmm0, xmmword ptr [rdx] ; Load 16 bytes into xmm0. vmovdqa xmm2, xmmword ptr [rdx+10h] ; Load 16 bytes into xmm2. add rdx, 20h ; Increment pointer. ; ; Process bytes 0-15, registers xmm0 and xmm1. ; vpextrb r10, xmm0, 0 ; Extract byte 0. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 1 ; Extract byte 1. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 2 ; Extract byte 2. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 3 ; Extract byte 3. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 4 ; Extract byte 4. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 5 ; Extract byte 5. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 6 ; Extract byte 6. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 7 ; Extract byte 7. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 8 ; Extract byte 8. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 9 ; Extract byte 9. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 10 ; Extract byte 10. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 11 ; Extract byte 11. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 12 ; Extract byte 12. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 13 ; Extract byte 13. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 14 ; Extract byte 14. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 15 ; Extract byte 15. add dword ptr [r9 + r11 * 4], 1 ; Update count. ; ; Continue processing the second set of 16 bytes (16-31) via xmm2 and xmm3. ; vpextrb r10, xmm2, 0 ; Extract byte 16. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 1 ; Extract byte 17. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 2 ; Extract byte 18. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 3 ; Extract byte 19. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 4 ; Extract byte 20. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 5 ; Extract byte 21. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 6 ; Extract byte 22. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 7 ; Extract byte 23. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 8 ; Extract byte 24. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 9 ; Extract byte 25. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 10 ; Extract byte 26. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 11 ; Extract byte 27. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 12 ; Extract byte 28. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 13 ; Extract byte 29. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 14 ; Extract byte 30. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 15 ; Extract byte 31. add dword ptr [r9 + r11 * 4], 1 ; Update count. ; ; End of loop. Update loop counter and determine if we're finished. ; sub ecx, 1 ; Decrement counter. jnz Cha50 ; Continue loop if != 0. ; ; We've finished creating the histogram. Merge the two histograms 64 bytes at ; a time using YMM registers. ; mov ecx, 16 ; Initialize counter. align 16 Cha75: vmovntdqa ymm0, ymmword ptr [r8+rax] ; Load 1st histo 0-31. vmovntdqa ymm1, ymmword ptr [r8+rax+20h] ; Load 1st histo 32-63. vmovntdqa ymm2, ymmword ptr [r9+rax] ; Load 2nd histo 0-31. vmovntdqa ymm3, ymmword ptr [r9+rax+20h] ; Load 2nd histo 32-63. vpaddd ymm4, ymm0, ymm2 ; Add 0-31 counts. vpaddd ymm5, ymm1, ymm3 ; Add 32-63 counts. vmovntdq ymmword ptr [r8+rax], ymm4 ; Save counts for 0-31. vmovntdq ymmword ptr [r8+rax+20h], ymm5 ; Save counts for 32-63. add rax, 40h ; Advance to next 64 bytes. sub ecx, 1 ; Decrement loop counter. jnz short Cha75 ; Continue if != 0. ; ; Indicate success and return. ; Cha98: mov rax, 1 ;IACA_VC_END Cha99: ret LEAF_END CreateHistogramAvx2AlignedAsm_v5_3, _TEXT$00 LEAF_ENTRY CreateHistogramAvx2AlignedAsm_v5_3_2, _TEXT$00 ; ; Clear return value (Success = FALSE). ; xor rax, rax ; Clear rax. ; ; Validate parameters. ; test rcx, rcx ; Is rcx NULL? jz Cha99 ; Yes, abort. test rdx, rdx ; Is rdx NULL? jz Cha99 ; Yes, abort. ; ; Verify the string is at least 64 bytes long. ; mov r9, 64 ; Initialize r9 to 64. cmp String.Length[rcx], r9d ; Compare Length to 64. jl Cha99 ; String is too short. ; ; Ensure the incoming string and histogram buffers are aligned to 32-byte ; boundaries. ; mov r9, 31 ; Initialize r9 to 31. test String.Buffer[rcx], r9 ; Is string aligned? jnz Cha99 ; No, abort. ; ; Initialize loop variables. ; ; rcx - Counter. ; ; rdx - Base string buffer. ; ; r8 - Base address of first histogram buffer. ; ; r9 - Base address of second histogram buffer. ; ; r10 - Byte counter. ; ; r11 - Byte counter. ; mov r8, rdx ; Load 1st histo buffer. lea r9, Histogram.Histogram2[r8] ; Load 2nd histo buffer. lea r8, Histogram.Histogram3[r8] ; Load 3rd histo buffer. mov rdx, String.Buffer[rcx] ; Load string buffer. mov ecx, String.Length[rcx] ; Load string length. shr ecx, 5 ; Divide by 16 to get loop ; iterations. ; ; Top of the histogram loop. ; align 16 ;IACA_VC_START ; ; Load the first 32 bytes into ymm0. Duplicate the lower 16 bytes in xmm0 and ; xmm1, then extract the high 16 bytes into xmm2 and xmm3. ; Cha50: vmovdqa xmm0, xmmword ptr [rdx] ; Load 16 bytes into xmm0. vmovdqa xmm2, xmmword ptr [rdx+10h] ; Load 16 bytes into xmm2. add rdx, 20h ; Increment pointer. ; ; Process bytes 0-15, registers xmm0 and xmm1. ; vpextrb r10, xmm0, 0 ; Extract byte 0. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 1 ; Extract byte 1. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 2 ; Extract byte 2. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 3 ; Extract byte 3. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 4 ; Extract byte 4. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 5 ; Extract byte 5. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 6 ; Extract byte 6. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 7 ; Extract byte 7. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 8 ; Extract byte 8. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 9 ; Extract byte 9. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 10 ; Extract byte 10. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 11 ; Extract byte 11. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 12 ; Extract byte 12. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 13 ; Extract byte 13. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 14 ; Extract byte 14. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 15 ; Extract byte 15. add dword ptr [r9 + r11 * 4], 1 ; Update count. ; ; Continue processing the second set of 16 bytes (16-31) via xmm2 and xmm3. ; vpextrb r10, xmm2, 0 ; Extract byte 16. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 1 ; Extract byte 17. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 2 ; Extract byte 18. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 3 ; Extract byte 19. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 4 ; Extract byte 20. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 5 ; Extract byte 21. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 6 ; Extract byte 22. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 7 ; Extract byte 23. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 8 ; Extract byte 24. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 9 ; Extract byte 25. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 10 ; Extract byte 26. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 11 ; Extract byte 27. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 12 ; Extract byte 28. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 13 ; Extract byte 29. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 14 ; Extract byte 30. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 15 ; Extract byte 31. add dword ptr [r9 + r11 * 4], 1 ; Update count. ; ; End of loop. Update loop counter and determine if we're finished. ; sub ecx, 1 ; Decrement counter. jnz Cha50 ; Continue loop if != 0. ; ; We've finished creating the histogram. Merge the two histograms 64 bytes at ; a time using YMM registers. ; mov ecx, 16 ; Initialize counter. lea r10, [r9 - size CHARACTER_HISTOGRAM]; Copy 2nd histo addr. align 16 Cha75: vmovntdqa ymm0, ymmword ptr [r8+rax] ; Load 1st histo 0-31. vmovntdqa ymm1, ymmword ptr [r8+rax+20h] ; Load 1st histo 32-63. vmovntdqa ymm2, ymmword ptr [r9+rax] ; Load 2nd histo 0-31. vmovntdqa ymm3, ymmword ptr [r9+rax+20h] ; Load 2nd histo 32-63. prefetchw [r10+rax] vpaddd ymm4, ymm0, ymm2 ; Add 0-31 counts. vpaddd ymm5, ymm1, ymm3 ; Add 32-63 counts. vmovntdq ymmword ptr [r10+rax], ymm4 ; Save counts for 0-31. vmovntdq ymmword ptr [r10+rax+20h], ymm5 ; Save counts for 32-63. add rax, 40h ; Advance to next 64 bytes. sub ecx, 1 ; Decrement loop counter. jnz short Cha75 ; Continue if != 0. ; ; Indicate success and return. ; Cha98: mov rax, 1 ;IACA_VC_END Cha99: ret LEAF_END CreateHistogramAvx2AlignedAsm_v5_3_2, _TEXT$00 LEAF_ENTRY CreateHistogramAvx2AlignedAsm_v5_3_3, _TEXT$00 ; ; Clear return value (Success = FALSE). ; xor rax, rax ; Clear rax. ; ; Validate parameters. ; test rcx, rcx ; Is rcx NULL? jz Cha99 ; Yes, abort. test rdx, rdx ; Is rdx NULL? jz Cha99 ; Yes, abort. ; ; Verify the string is at least 64 bytes long. ; mov r9, 64 ; Initialize r9 to 64. cmp String.Length[rcx], r9d ; Compare Length to 64. jl Cha99 ; String is too short. ; ; Ensure the incoming string and histogram buffers are aligned to 32-byte ; boundaries. ; mov r9, 31 ; Initialize r9 to 31. test String.Buffer[rcx], r9 ; Is string aligned? jnz Cha99 ; No, abort. ; ; Initialize loop variables. ; ; rcx - Counter. ; ; rdx - Base string buffer. ; ; r8 - Base address of first histogram buffer. ; ; r9 - Base address of second histogram buffer. ; ; r10 - Byte counter. ; ; r11 - Byte counter. ; mov r8, rdx ; Load 1st histo buffer. lea r9, Histogram.Histogram2[r8] ; Load 2nd histo buffer. mov rdx, String.Buffer[rcx] ; Load string buffer. mov ecx, String.Length[rcx] ; Load string length. shr ecx, 5 ; Divide by 16 to get loop ; iterations. ; ; Top of the histogram loop. ; align 16 ;IACA_VC_START ; ; Load the first 32 bytes into ymm0. Duplicate the lower 16 bytes in xmm0 and ; xmm1, then extract the high 16 bytes into xmm2 and xmm3. ; Cha50: vmovdqa xmm0, xmmword ptr [rdx] ; Load 16 bytes into xmm0. vmovdqa xmm2, xmmword ptr [rdx+10h] ; Load 16 bytes into xmm2. add rdx, 20h ; Increment pointer. ; ; Process bytes 0-15, registers xmm0 and xmm1. ; vpextrb r10, xmm0, 0 ; Extract byte 0. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 1 ; Extract byte 1. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 2 ; Extract byte 2. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 3 ; Extract byte 3. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 4 ; Extract byte 4. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 5 ; Extract byte 5. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 6 ; Extract byte 6. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 7 ; Extract byte 7. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 8 ; Extract byte 8. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 9 ; Extract byte 9. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 10 ; Extract byte 10. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 11 ; Extract byte 11. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 12 ; Extract byte 12. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 13 ; Extract byte 13. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm0, 14 ; Extract byte 14. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm0, 15 ; Extract byte 15. add dword ptr [r9 + r11 * 4], 1 ; Update count. ; ; Continue processing the second set of 16 bytes (16-31) via xmm2 and xmm3. ; vpextrb r10, xmm2, 0 ; Extract byte 16. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 1 ; Extract byte 17. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 2 ; Extract byte 18. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 3 ; Extract byte 19. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 4 ; Extract byte 20. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 5 ; Extract byte 21. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 6 ; Extract byte 22. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 7 ; Extract byte 23. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 8 ; Extract byte 24. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 9 ; Extract byte 25. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 10 ; Extract byte 26. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 11 ; Extract byte 27. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 12 ; Extract byte 28. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 13 ; Extract byte 29. add dword ptr [r9 + r11 * 4], 1 ; Update count. vpextrb r10, xmm2, 14 ; Extract byte 30. add dword ptr [r8 + r10 * 4], 1 ; Update count. vpextrb r11, xmm2, 15 ; Extract byte 31. add dword ptr [r9 + r11 * 4], 1 ; Update count. ; ; End of loop. Update loop counter and determine if we're finished. ; sub ecx, 1 ; Decrement counter. jnz Cha50 ; Continue loop if != 0. ; ; We've finished creating the histogram. Merge the two histograms 128 bytes at ; a time using YMM registers. ; mov ecx, 8 ; Initialize counter. mov rdx, 80h align 16 Cha75: vmovdqa ymm0, ymmword ptr [r8+rax] ; Load 1st histo 0-31. vpaddd ymm0, ymm0, ymmword ptr [r9+rax]; Add 2nd histo 0-31. vmovntdq ymmword ptr [r8+rax], ymm0 ; Save counts for 0-31. vmovdqa ymm1, ymmword ptr [r8+rax+20h] ; Load 1st 32-63. vpaddd ymm1, ymm1, ymmword ptr [r9+rax+20h] ; Add 2nd 32-63. vmovntdq ymmword ptr [r8+rax+20h], ymm1 ; Save 32-63. vmovdqa ymm2, ymmword ptr [r8+rax+40h] ; Load 1st 64-95. vpaddd ymm2, ymm2, ymmword ptr [r9+rax+40h] ; Add 2nd 64-95. vmovntdq ymmword ptr [r8+rax+40h], ymm2 ; Save 64-95. vmovdqa ymm3, ymmword ptr [r8+rax+60h] ; Load 1st 96-127. vpaddd ymm3, ymm3, ymmword ptr [r9+rax+60h] ; Add 2nd 96-127. vmovntdq ymmword ptr [r8+rax+60h], ymm3 ; Save 96-127. add rax, 100h vmovdqa ymm0, ymmword ptr [r8+rdx] ; Load 1st histo 0-31. vpaddd ymm0, ymm0, ymmword ptr [r9+rdx]; Add 2nd histo 0-31. vmovntdq ymmword ptr [r8+rdx], ymm0 ; Save counts for 0-31. vmovdqa ymm1, ymmword ptr [r8+rdx+20h] ; Load 1st 32-63. vpaddd ymm1, ymm1, ymmword ptr [r9+rdx+20h] ; Add 2nd 32-63. vmovntdq ymmword ptr [r8+rdx+20h], ymm1 ; Save 32-63. vmovdqa ymm2, ymmword ptr [r8+rdx+40h] ; Load 1st 64-95. vpaddd ymm2, ymm2, ymmword ptr [r9+rdx+40h] ; Add 2nd 64-95. vmovntdq ymmword ptr [r8+rdx+40h], ymm2 ; Save 64-95. vmovdqa ymm3, ymmword ptr [r8+rdx+60h] ; Load 1st 96-127. vpaddd ymm3, ymm3, ymmword ptr [r9+rdx+60h] ; Add 2nd 96-127. vmovntdq ymmword ptr [r8+rdx+60h], ymm3 ; Save 96-127. add rdx, 100h ; ; 256 bytes processed. ; vmovdqa ymm0, ymmword ptr [r8+rax] ; Load 1st histo 0-31. vpaddd ymm0, ymm0, ymmword ptr [r9+rax]; Add 2nd histo 0-31. vmovntdq ymmword ptr [r8+rax], ymm0 ; Save counts for 0-31. vmovdqa ymm1, ymmword ptr [r8+rax+20h] ; Load 1st 32-63. vpaddd ymm1, ymm1, ymmword ptr [r9+rax+20h] ; Add 2nd 32-63. vmovntdq ymmword ptr [r8+rax+20h], ymm1 ; Save 32-63. vmovdqa ymm2, ymmword ptr [r8+rax+40h] ; Load 1st 64-95. vpaddd ymm2, ymm2, ymmword ptr [r9+rax+40h] ; Add 2nd 64-95. vmovntdq ymmword ptr [r8+rax+40h], ymm2 ; Save 64-95. vmovdqa ymm3, ymmword ptr [r8+rax+60h] ; Load 1st 96-127. vpaddd ymm3, ymm3, ymmword ptr [r9+rax+60h] ; Add 2nd 96-127. vmovntdq ymmword ptr [r8+rax+60h], ymm3 ; Save 96-127. add rax, 100h vmovdqa ymm0, ymmword ptr [r8+rdx] ; Load 1st histo 0-31. vpaddd ymm0, ymm0, ymmword ptr [r9+rdx]; Add 2nd histo 0-31. vmovntdq ymmword ptr [r8+rdx], ymm0 ; Save counts for 0-31. vmovdqa ymm1, ymmword ptr [r8+rdx+20h] ; Load 1st 32-63. vpaddd ymm1, ymm1, ymmword ptr [r9+rdx+20h] ; Add 2nd 32-63. vmovntdq ymmword ptr [r8+rdx+20h], ymm1 ; Save 32-63. vmovdqa ymm2, ymmword ptr [r8+rdx+40h] ; Load 1st 64-95. vpaddd ymm2, ymm2, ymmword ptr [r9+rdx+40h] ; Add 2nd 64-95. vmovntdq ymmword ptr [r8+rdx+40h], ymm2 ; Save 64-95. vmovdqa ymm3, ymmword ptr [r8+rdx+60h] ; Load 1st 96-127. vpaddd ymm3, ymm3, ymmword ptr [r9+rdx+60h] ; Add 2nd 96-127. vmovntdq ymmword ptr [r8+rdx+60h], ymm3 ; Save 96-127. add rdx, 100h ; ; 512 bytes processed. ; vmovdqa ymm0, ymmword ptr [r8+rax] ; Load 1st histo 0-31. vpaddd ymm0, ymm0, ymmword ptr [r9+rax]; Add 2nd histo 0-31. vmovntdq ymmword ptr [r8+rax], ymm0 ; Save counts for 0-31. vmovdqa ymm1, ymmword ptr [r8+rax+20h] ; Load 1st 32-63. vpaddd ymm1, ymm1, ymmword ptr [r9+rax+20h] ; Add 2nd 32-63. vmovntdq ymmword ptr [r8+rax+20h], ymm1 ; Save 32-63. vmovdqa ymm2, ymmword ptr [r8+rax+40h] ; Load 1st 64-95. vpaddd ymm2, ymm2, ymmword ptr [r9+rax+40h] ; Add 2nd 64-95. vmovntdq ymmword ptr [r8+rax+40h], ymm2 ; Save 64-95. vmovdqa ymm3, ymmword ptr [r8+rax+60h] ; Load 1st 96-127. vpaddd ymm3, ymm3, ymmword ptr [r9+rax+60h] ; Add 2nd 96-127. vmovntdq ymmword ptr [r8+rax+60h], ymm3 ; Save 96-127. add rax, 100h vmovdqa ymm0, ymmword ptr [r8+rdx] ; Load 1st histo 0-31. vpaddd ymm0, ymm0, ymmword ptr [r9+rdx]; Add 2nd histo 0-31. vmovntdq ymmword ptr [r8+rdx], ymm0 ; Save counts for 0-31. vmovdqa ymm1, ymmword ptr [r8+rdx+20h] ; Load 1st 32-63. vpaddd ymm1, ymm1, ymmword ptr [r9+rdx+20h] ; Add 2nd 32-63. vmovntdq ymmword ptr [r8+rdx+20h], ymm1 ; Save 32-63. vmovdqa ymm2, ymmword ptr [r8+rdx+40h] ; Load 1st 64-95. vpaddd ymm2, ymm2, ymmword ptr [r9+rdx+40h] ; Add 2nd 64-95. vmovntdq ymmword ptr [r8+rdx+40h], ymm2 ; Save 64-95. vmovdqa ymm3, ymmword ptr [r8+rdx+60h] ; Load 1st 96-127. vpaddd ymm3, ymm3, ymmword ptr [r9+rdx+60h] ; Add 2nd 96-127. vmovntdq ymmword ptr [r8+rdx+60h], ymm3 ; Save 96-127. add rdx, 100h ; ; 768 bytes processed. ; vmovdqa ymm0, ymmword ptr [r8+rax] ; Load 1st histo 0-31. vpaddd ymm0, ymm0, ymmword ptr [r9+rax]; Add 2nd histo 0-31. vmovntdq ymmword ptr [r8+rax], ymm0 ; Save counts for 0-31. vmovdqa ymm1, ymmword ptr [r8+rax+20h] ; Load 1st 32-63. vpaddd ymm1, ymm1, ymmword ptr [r9+rax+20h] ; Add 2nd 32-63. vmovntdq ymmword ptr [r8+rax+20h], ymm1 ; Save 32-63. vmovdqa ymm2, ymmword ptr [r8+rax+40h] ; Load 1st 64-95. vpaddd ymm2, ymm2, ymmword ptr [r9+rax+40h] ; Add 2nd 64-95. vmovntdq ymmword ptr [r8+rax+40h], ymm2 ; Save 64-95. vmovdqa ymm3, ymmword ptr [r8+rax+60h] ; Load 1st 96-127. vpaddd ymm3, ymm3, ymmword ptr [r9+rax+60h] ; Add 2nd 96-127. vmovntdq ymmword ptr [r8+rax+60h], ymm3 ; Save 96-127. ; ; Set rax to 1. ; shr rax, 9 vmovdqa ymm0, ymmword ptr [r8+rdx] ; Load 1st histo 0-31. vpaddd ymm0, ymm0, ymmword ptr [r9+rdx]; Add 2nd histo 0-31. vmovntdq ymmword ptr [r8+rdx], ymm0 ; Save counts for 0-31. vmovdqa ymm1, ymmword ptr [r8+rdx+20h] ; Load 1st 32-63. vpaddd ymm1, ymm1, ymmword ptr [r9+rdx+20h] ; Add 2nd 32-63. vmovntdq ymmword ptr [r8+rdx+20h], ymm1 ; Save 32-63. vmovdqa ymm2, ymmword ptr [r8+rdx+40h] ; Load 1st 64-95. vpaddd ymm2, ymm2, ymmword ptr [r9+rdx+40h] ; Add 2nd 64-95. vmovntdq ymmword ptr [r8+rdx+40h], ymm2 ; Save 64-95. vmovdqa ymm3, ymmword ptr [r8+rdx+60h] ; Load 1st 96-127. vpaddd ymm3, ymm3, ymmword ptr [r9+rdx+60h] ; Add 2nd 96-127. vmovntdq ymmword ptr [r8+rdx+60h], ymm3 ; Save 96-127. ;IACA_VC_END Cha99: ret LEAF_END CreateHistogramAvx2AlignedAsm_v5_3_3, _TEXT$00 ;++ ; ; BOOLEAN ; CreateHistogramAvx512AlignedAsm( ; _In_ PCLONG_STRING String, ; _Inout_updates_bytes_(sizeof(*Histogram)) ; PCHARACTER_HISTOGRAM_V4 Histogram ; ); ; ; Routine Description: ; ; This routine creates a histogram for a given string. ; ; Arguments: ; ; String (rcx) - Supplies a pointer to a LONG_STRING structure that contains ; the string for which a histogram is to be created. ; ; Histogram (rdx) - Supplies an address that receives the histogram for the ; given input string. ; ; Return Value: ; ; TRUE on success, FALSE on failure. ; ;-- NESTED_ENTRY CreateHistogramAvx512AlignedAsm, _TEXT$00 ; ; Begin prologue. Allocate stack space and save non-volatile registers. ; alloc_stack LOCALS_SIZE save_reg rbp, Locals.SavedRbp ; Save non-volatile rbp. save_reg rbx, Locals.SavedRbx ; Save non-volatile rbx. save_reg rdi, Locals.SavedRdi ; Save non-volatile rdi. save_reg rsi, Locals.SavedRsi ; Save non-volatile rsi. save_reg r12, Locals.SavedR12 ; Save non-volatile r12. save_reg r13, Locals.SavedR13 ; Save non-volatile r13. save_reg r14, Locals.SavedR14 ; Save non-volatile r14. save_reg r15, Locals.SavedR15 ; Save non-volatile r15. save_xmm128 xmm6, Locals.SavedXmm6 ; Save non-volatile xmm6. save_xmm128 xmm7, Locals.SavedXmm7 ; Save non-volatile xmm7. save_xmm128 xmm8, Locals.SavedXmm8 ; Save non-volatile xmm8. save_xmm128 xmm9, Locals.SavedXmm9 ; Save non-volatile xmm9. save_xmm128 xmm10, Locals.SavedXmm10 ; Save non-volatile xmm10. save_xmm128 xmm11, Locals.SavedXmm11 ; Save non-volatile xmm11. save_xmm128 xmm12, Locals.SavedXmm12 ; Save non-volatile xmm12. save_xmm128 xmm13, Locals.SavedXmm13 ; Save non-volatile xmm13. save_xmm128 xmm14, Locals.SavedXmm14 ; Save non-volatile xmm14. save_xmm128 xmm15, Locals.SavedXmm15 ; Save non-volatile xmm15. END_PROLOGUE ; ; Clear return value (Success = FALSE). ; ;IACA_VC_START xor rax, rax ; Clear rax. ; ; Validate parameters. ; test rcx, rcx ; Is rcx NULL? jz Chb99 ; Yes, abort. test rdx, rdx ; Is rdx NULL? jz Chb99 ; Yes, abort. ; ; Verify the string is at least 64 bytes long. ; mov r9, 64 ; Initialize r9 to 64. cmp String.Length[rcx], r9d ; Compare Length to 64. jl Chb99 ; String is too short. ; ; Ensure the incoming string and histogram buffers are aligned to 32-byte ; boundaries. ; mov r9, 31 ; Initialize r9 to 31. test String.Buffer[rcx], r9 ; Is string aligned? jnz Chb99 ; No, abort. ; ; Initialize loop variables. ; ; rcx - Counter. ; ; rdx - Base string buffer. ; ; r8 - Base address of first histogram buffer. ; ; r9 - Base address of second histogram buffer. ; ; r10 - Base address of third histogram buffer. ; ; r11 - Base address of fourth histogram buffer. ; mov r8, rdx ; Load 1st histo buffer. lea r9, Histogram.Histogram2[r8] ; Load 2nd histo buffer. lea r10, Histogram.Histogram3[r8] ; Load 3rd histo buffer. lea r11, Histogram.Histogram4[r8] ; Load 4th histo buffer. mov rdx, String.Buffer[rcx] ; Load string buffer. mov ecx, String.Length[rcx] ; Load string length. shr ecx, 6 ; Divide by 64 to get loop ; iterations. vmovntdqa zmm28, zmmword ptr [AllOnes] vmovntdqa zmm29, zmmword ptr [AllNegativeOnes] vmovntdqa zmm30, zmmword ptr [AllBinsMinusOne] vmovntdqa zmm31, zmmword ptr [AllThirtyOne] mov rax, 1111111111111111h kmovq k1, rax vpmovm2b zmm1, k1 kshiftlq k2, k1, 1 vpmovm2b zmm2, k2 kshiftlq k3, k1, 2 vpmovm2b zmm3, k3 kshiftlq k4, k1, 3 vpmovm2b zmm4, k4 align 16 Chb30: vmovntdqa zmm0, zmmword ptr [rdx] ; Load 64 bytes into zmm0. ; ; Advance the source input pointer by 64 bytes. Clear the k1 mask ; which we'll use later for the vpgatherds. ; add rdx, 40h ; Advance 64 bytes. ; ; Extract byte values for each doubleword into separate registers. ; ;IACA_VC_START vpandd zmm5, zmm1, zmm0 vpandd zmm6, zmm2, zmm0 vpandd zmm7, zmm3, zmm0 vpandd zmm8, zmm4, zmm0 ; ; Toggle all bits in the writemasks. ; kxnorq k1, k5, k5 kxnorq k2, k6, k6 kxnorq k3, k7, k7 kxnorq k4, k0, k0 ; ; Shift the second to fourth registers such that the byte value is moved to the ; least significant portion of the doubleword element of the register. ; vpsrldq zmm6, zmm6, 1 vpsrldq zmm7, zmm7, 2 vpsrldq zmm8, zmm8, 3 ; ; Gather the counts for the byte locations. ; vpgatherdd zmm20 {k1}, [r8+4*zmm5] ; Gather 1st counts. vpgatherdd zmm21 {k2}, [r9+4*zmm6] ; Gather 2nd counts. vpgatherdd zmm22 {k3}, [r10+4*zmm7] ; Gather 3rd counts. vpgatherdd zmm23 {k4}, [r11+4*zmm8] ; Gather 4th counts. ; ; Determine if the characters loaded into each ZMM register conflict. ; vpconflictd zmm10, zmm5 vpconflictd zmm11, zmm6 vpconflictd zmm12, zmm7 vpconflictd zmm13, zmm8 vpord zmm14, zmm10, zmm11 vpord zmm15, zmm12, zmm13 vpord zmm14, zmm14, zmm15 vptestmd k1, zmm14, zmm14 ; Any conflicts anywhere? kortestw k1, k1 jne Chb40 ; At least one conflict. ; ; No conflicts across all registers. Proceed with adding 1 (zmm28) to all ; the counts and then scattering the results back into memory. ; align 16 Chb35: vpaddd zmm24, zmm20, zmm28 ; Add 1st counts. vpaddd zmm25, zmm21, zmm28 ; Add 2nd counts. vpaddd zmm26, zmm22, zmm28 ; Add 3rd counts. vpaddd zmm27, zmm23, zmm28 ; Add 4th counts. ; ; Toggle all bits in the writemasks. ; kxnorq k1, k5, k5 kxnorq k2, k6, k6 kxnorq k3, k7, k7 kxnorq k4, k0, k0 ; ; Scatter the counts back into their respective locations. ; vpscatterdd [r8+4*zmm5] {k1}, zmm24 ; Save 1st counts. vpscatterdd [r9+4*zmm6] {k2}, zmm25 ; Save 2nd counts. vpscatterdd [r10+4*zmm7] {k3}, zmm26 ; Save 3rd counts. vpscatterdd [r11+4*zmm8] {k4}, zmm27 ; Save 4th counts. ; ; Decrement loop counter and jump back to the top of the processing loop if ; there are more elements. ; Chb38: sub ecx, 1 ; Decrement counter. jnz Chb30 ; Continue if != 0. ; ; We've finished processing the input string, jump to finalization logic. ; jmp Chb85 ; ; Conflict handling logic. At least one of the zmm registers had a conflict. ; ; ; Test the first register (zmm5) to see if it has any conflicts (zmm10). ; Chb40: vptestmd k1, zmm10, zmm10 ; Test 1st for conflicts. vmovaps zmm16, zmm28 ; Copy AllOnes into zmm16. kmovw ebx, k1 ; Move mask into ebx. vpaddd zmm16, zmm16, zmm20 ; Add partial counts. test ebx, ebx ; Any conflicts? jz short Chb47 ; No conflicts. ; ; First register (zmm5) has a conflict (zmm10). ; align 16 Chb45: vpbroadcastd zmm18, ebx ; Bcast mask into zmm18. kmovw k1, ebx ; Move mask into k1. vpaddd zmm16 {k1}, zmm16, zmm28 ; Add masked counts. vptestmd k0 {k1}, zmm18, zmm10 ; Test against conflict. kmovw esi, k0 ; Move new mask into esi. and ebx, esi ; Mask off recent bit. jnz short Chb45 ; Continue loop if bits left ; ; Conflicts have been resolved for first register (zmm5), with the final count ; now living in zmm16. Scatter back to memory. ; Chb47: kxnorw k7, k3, k3 ; Set all bits in writemask. vpscatterdd [r8+4*zmm5] {k7}, zmm16 ; Save counts. ; ; Intentional follow-on. ; ; ; Test the second register (zmm6) to see if it has any conflicts (zmm11). ; Chb50: vptestmd k1, zmm11, zmm11 ; Test 2nd for conflicts. vmovaps zmm16, zmm28 ; Copy AllOnes into zmm16. kmovw ebx, k1 ; Move mask into ebx. vpaddd zmm16, zmm16, zmm21 ; Add partial counts. test ebx, ebx ; Any conflicts? jz short Chb57 ; No conflicts. ; ; Second register (zmm6) has a conflict (zmm11). ; align 16 Chb55: vpbroadcastd zmm18, ebx ; Bcast mask into zmm18. kmovw k1, ebx ; Move mask into k1. vpaddd zmm16 {k1}, zmm16, zmm28 ; Add masked counts. vptestmd k0 {k1}, zmm18, zmm11 ; Test against conflict. kmovw esi, k0 ; Move new mask into esi. and ebx, esi ; Mask off recent bit. jnz short Chb55 ; Continue loop if bits left ; ; Conflicts have been resolved for second register (zmm6), with the final count ; now living in zmm16. Scatter back to memory. ; Chb57: kxnorw k7, k3, k3 ; Set all bits in writemask. vpscatterdd [r9+4*zmm6] {k7}, zmm16 ; Save counts. ; ; Intentional follow-on. ; ; ; Test the third register (zmm7) to see if it has any conflicts (zmm16). ; Chb60: vptestmd k1, zmm12, zmm12 ; Test 3rd for conflicts. vmovaps zmm16, zmm28 ; Copy AllOnes into zmm16. kmovw ebx, k1 ; Move mask into ebx. vpaddd zmm16, zmm16, zmm22 ; Add partial counts. test ebx, ebx ; Any conflicts? jz short Chb67 ; No conflicts. ; ; Third register (zmm7) has a conflict (zmm16). ; align 16 Chb65: vpbroadcastd zmm18, ebx ; Bcast mask into zmm18. kmovw k1, ebx ; Move mask into k1. vpaddd zmm16 {k1}, zmm16, zmm28 ; Add masked counts. vptestmd k0 {k1}, zmm18, zmm12 ; Test against conflict. kmovw esi, k0 ; Move new mask into esi. and ebx, esi ; Mask off recent bit. jnz short Chb65 ; Continue loop if bits left ; ; Conflicts have been resolved for third register (zmm7), with the final count ; now living in zmm16. Scatter back to memory. ; Chb67: kxnorw k7, k3, k3 ; Set all bits in writemask. vpscatterdd [r10+4*zmm7] {k7}, zmm16 ; Save counts. ; ; Intentional follow-on. ; ; ; Test the second register (zmm8) to see if it has any conflicts (zmm13). ; Chb70: vptestmd k1, zmm13, zmm13 ; Test 4th for conflicts. vmovaps zmm16, zmm28 ; Copy AllOnes into zmm16. kmovw ebx, k1 ; Move mask into ebx. vpaddd zmm16, zmm16, zmm23 ; Add partial counts. test ebx, ebx ; Any conflicts? jz short Chb77 ; No conflicts. ; ; Fourth register (zmm8) has a conflict (zmm13). ; align 16 Chb75: vpbroadcastd zmm18, ebx ; Bcast mask into zmm18. kmovw k1, ebx ; Move mask into k1. vpaddd zmm16 {k1}, zmm16, zmm28 ; Add masked counts. vptestmd k0 {k1}, zmm18, zmm13 ; Test against conflict. kmovw esi, k0 ; Move new mask into esi. and ebx, esi ; Mask off recent bit. jnz short Chb75 ; Continue loop if bits left ; ; Conflicts have been resolved for second register (zmm8), with the final count ; now living in zmm16. Scatter back to memory. ; Chb77: kxnorw k7, k3, k3 ; Set all bits in writemask. vpscatterdd [r11+4*zmm8] {k7}, zmm16 ; Save counts. ; ; Check for loop termination. ; sub ecx, 1 ; Decrement counter. jnz Chb30 ; Continue if != 0. ; ; Merge four histograms into one, 128 bytes at a time (two zmm registers in ; flight per histogram). ; Chb85: mov ecx, 8 xor rax, rax align 16 Chb90: vmovdqa32 zmm20, zmmword ptr [r8+rax] ; Load 1st histo 0-63. vmovdqa32 zmm21, zmmword ptr [r8+rax+40h] ; Load 1st histo 64-127. vmovdqa32 zmm22, zmmword ptr [r9+rax] ; Load 2nd histo 0-63. vmovdqa32 zmm23, zmmword ptr [r9+rax+40h] ; Load 2nd histo 64-127. vmovdqa32 zmm24, zmmword ptr [r10+rax] ; Load 3rd histo 0-63. vmovdqa32 zmm25, zmmword ptr [r10+rax+40h]; Load 3rd histo 64-127. vmovdqa32 zmm26, zmmword ptr [r11+rax] ; Load 4th histo 0-63. vmovdqa32 zmm27, zmmword ptr [r11+rax+40h]; Load 4th histo 64-127. vpaddd zmm10, zmm20, zmm22 ; Add 1-2 0-63 histo. vpaddd zmm11, zmm24, zmm26 ; Add 3-4 0-63 histo. vpaddd zmm12, zmm10, zmm11 ; Merge 0-63 histo. vpaddd zmm13, zmm21, zmm23 ; Add 1-2 64-127 histo. vpaddd zmm14, zmm25, zmm27 ; Add 3-4 64-127 histo. vpaddd zmm15, zmm13, zmm14 ; Merge 64-127 histo. vmovdqa32 zmmword ptr [r8+rax], zmm12 ; Save 0-63 histo. vmovdqa32 zmmword ptr [r8+rax+40h], zmm15 ; Save 64-127 histo. add rax, 80h ; Advance to next 128b. sub ecx, 1 ; Decrement loop cntr. jnz Chb90 ; Continue if != 0. ; ; Indicate success. ; mov rax, 1 ; ; Restore non-volatile registers. ; Chb99: mov rbp, Locals.SavedRbp[rsp] mov rbx, Locals.SavedRbx[rsp] mov rdi, Locals.SavedRdi[rsp] mov rsi, Locals.SavedRsi[rsp] mov r12, Locals.SavedR12[rsp] mov r13, Locals.SavedR13[rsp] mov r14, Locals.SavedR14[rsp] mov r15, Locals.SavedR15[rsp] movdqa xmm6, Locals.SavedXmm6[rsp] movdqa xmm7, Locals.SavedXmm7[rsp] movdqa xmm8, Locals.SavedXmm8[rsp] movdqa xmm9, Locals.SavedXmm9[rsp] movdqa xmm10, Locals.SavedXmm10[rsp] movdqa xmm11, Locals.SavedXmm11[rsp] movdqa xmm12, Locals.SavedXmm12[rsp] movdqa xmm13, Locals.SavedXmm13[rsp] movdqa xmm14, Locals.SavedXmm14[rsp] movdqa xmm15, Locals.SavedXmm15[rsp] ; ; Begin epilogue. Deallocate stack space and return. ; add rsp, LOCALS_SIZE ret ;IACA_VC_END NESTED_END CreateHistogramAvx512AlignedAsm, _TEXT$00 ; ; Tweak ordering to improve IACA static analysis. ; NESTED_ENTRY CreateHistogramAvx512AlignedAsm_v2, _TEXT$00 ; ; Begin prologue. Allocate stack space and save non-volatile registers. ; alloc_stack LOCALS_SIZE save_reg rbp, Locals.SavedRbp ; Save non-volatile rbp. save_reg rbx, Locals.SavedRbx ; Save non-volatile rbx. save_reg rdi, Locals.SavedRdi ; Save non-volatile rdi. save_reg rsi, Locals.SavedRsi ; Save non-volatile rsi. save_reg r12, Locals.SavedR12 ; Save non-volatile r12. save_reg r13, Locals.SavedR13 ; Save non-volatile r13. save_reg r14, Locals.SavedR14 ; Save non-volatile r14. save_reg r15, Locals.SavedR15 ; Save non-volatile r15. save_xmm128 xmm6, Locals.SavedXmm6 ; Save non-volatile xmm6. save_xmm128 xmm7, Locals.SavedXmm7 ; Save non-volatile xmm7. save_xmm128 xmm8, Locals.SavedXmm8 ; Save non-volatile xmm8. save_xmm128 xmm9, Locals.SavedXmm9 ; Save non-volatile xmm9. save_xmm128 xmm10, Locals.SavedXmm10 ; Save non-volatile xmm10. save_xmm128 xmm11, Locals.SavedXmm11 ; Save non-volatile xmm11. save_xmm128 xmm12, Locals.SavedXmm12 ; Save non-volatile xmm12. save_xmm128 xmm13, Locals.SavedXmm13 ; Save non-volatile xmm13. save_xmm128 xmm14, Locals.SavedXmm14 ; Save non-volatile xmm14. save_xmm128 xmm15, Locals.SavedXmm15 ; Save non-volatile xmm15. END_PROLOGUE ; ; Clear return value (Success = FALSE). ; ;IACA_VC_START xor rax, rax ; Clear rax. ; ; Validate parameters. ; test rcx, rcx ; Is rcx NULL? jz Chc99 ; Yes, abort. test rdx, rdx ; Is rdx NULL? jz Chc99 ; Yes, abort. ; ; Verify the string is at least 64 bytes long. ; mov r9, 64 ; Initialize r9 to 64. cmp String.Length[rcx], r9d ; Compare Length to 64. jl Chc99 ; String is too short. ; ; Ensure the incoming string and histogram buffers are aligned to 32-byte ; boundaries. ; mov r9, 31 ; Initialize r9 to 31. test String.Buffer[rcx], r9 ; Is string aligned? jnz Chc99 ; No, abort. ; ; Initialize loop variables. ; ; rcx - Counter. ; ; rdx - Base string buffer. ; ; r8 - Base address of first histogram buffer. ; ; r9 - Base address of second histogram buffer. ; ; r10 - Base address of third histogram buffer. ; ; r11 - Base address of fourth histogram buffer. ; mov r8, rdx ; Load 1st histo buffer. lea r9, Histogram.Histogram2[r8] ; Load 2nd histo buffer. lea r10, Histogram.Histogram3[r8] ; Load 3rd histo buffer. lea r11, Histogram.Histogram4[r8] ; Load 4th histo buffer. mov rdx, String.Buffer[rcx] ; Load string buffer. mov ecx, String.Length[rcx] ; Load string length. shr ecx, 6 ; Divide by 64 to get loop ; iterations. vmovntdqa zmm28, zmmword ptr [AllOnes] vmovntdqa zmm29, zmmword ptr [AllNegativeOnes] vmovntdqa zmm30, zmmword ptr [AllBinsMinusOne] vmovntdqa zmm31, zmmword ptr [AllThirtyOne] mov rax, 1111111111111111h kmovq k1, rax vpmovm2b zmm1, k1 kshiftlq k2, k1, 1 vpmovm2b zmm2, k2 kshiftlq k3, k1, 2 vpmovm2b zmm3, k3 kshiftlq k4, k1, 3 vpmovm2b zmm4, k4 align 16 Chc30: vmovntdqa zmm0, zmmword ptr [rdx] ; Load 64 bytes into zmm0. ; ; Advance the source input pointer by 64 bytes. Clear the k1 mask ; which we'll use later for the vpgatherds. ; add rdx, 40h ; Advance 64 bytes. ; ; Extract byte values for each doubleword into separate registers. ; ;IACA_VC_START kxnorq k1, k5, k5 vpandd zmm5, zmm1, zmm0 vpgatherdd zmm20 {k1}, [r8+4*zmm5] ; Gather 1st counts. vpconflictd zmm10, zmm5 kxnorq k2, k6, k6 vpandd zmm6, zmm2, zmm0 vpsrldq zmm6, zmm6, 1 vpgatherdd zmm21 {k2}, [r9+4*zmm6] ; Gather 2nd counts. vpconflictd zmm11, zmm6 vpord zmm14, zmm10, zmm11 kxnorq k3, k7, k7 vpandd zmm7, zmm3, zmm0 vpsrldq zmm7, zmm7, 2 vpgatherdd zmm22 {k3}, [r10+4*zmm7] ; Gather 3rd counts. vpconflictd zmm12, zmm7 vpandd zmm8, zmm4, zmm0 vpsrldq zmm8, zmm8, 3 kxnorq k4, k0, k0 vpgatherdd zmm23 {k4}, [r11+4*zmm8] ; Gather 4th counts. vpconflictd zmm13, zmm8 vpord zmm15, zmm12, zmm13 vpord zmm14, zmm14, zmm15 vptestmd k1, zmm14, zmm14 ; Any conflicts anywhere? kortestw k1, k1 jne Chc40 ; At least one conflict. ; ; No conflicts across all registers. Proceed with adding 1 (zmm28) to all ; the counts and then scattering the results back into memory. ; align 16 Chc35: kxnorq k1, k5, k5 vpaddd zmm24, zmm20, zmm28 ; Add 1st counts. vpscatterdd [r8+4*zmm5] {k1}, zmm24 ; Save 1st counts. kxnorq k2, k6, k6 vpaddd zmm25, zmm21, zmm28 ; Add 2nd counts. vpscatterdd [r9+4*zmm6] {k2}, zmm25 ; Save 2nd counts. kxnorq k3, k7, k7 vpaddd zmm26, zmm22, zmm28 ; Add 3rd counts. vpscatterdd [r10+4*zmm7] {k3}, zmm26 ; Save 3rd counts. kxnorq k4, k0, k0 vpaddd zmm27, zmm23, zmm28 ; Add 4th counts. vpscatterdd [r11+4*zmm8] {k4}, zmm27 ; Save 4th counts. Chc38: sub ecx, 1 ; Decrement counter. jnz Chc30 ; Continue if != 0. ; ; We've finished processing the input string, jump to finalization logic. ; jmp Chc85 ; ; Conflict handling logic. At least one of the zmm registers had a conflict. ; ; ; Test the first register (zmm5) to see if it has any conflicts (zmm10). ; Chc40: vptestmd k1, zmm10, zmm10 ; Test 1st for conflicts. vmovaps zmm16, zmm28 ; Copy AllOnes into zmm16. kmovw ebx, k1 ; Move mask into ebx. vpaddd zmm16, zmm16, zmm20 ; Add partial counts. test ebx, ebx ; Any conflicts? jz short Chc47 ; No conflicts. ; ; First register (zmm5) has a conflict (zmm10). ; align 16 Chc45: vpbroadcastd zmm18, ebx ; Bcast mask into zmm18. kmovw k1, ebx ; Move mask into k1. vpaddd zmm16 {k1}, zmm16, zmm28 ; Add masked counts. vptestmd k0 {k1}, zmm18, zmm10 ; Test against conflict. kmovw esi, k0 ; Move new mask into esi. and ebx, esi ; Mask off recent bit. jnz short Chc45 ; Continue loop if bits left ; ; Conflicts have been resolved for first register (zmm5), with the final count ; now living in zmm16. Scatter back to memory. ; Chc47: kxnorw k7, k3, k3 ; Set all bits in writemask. vpscatterdd [r8+4*zmm5] {k7}, zmm16 ; Save counts. ; ; Intentional follow-on. ; ; ; Test the second register (zmm6) to see if it has any conflicts (zmm11). ; Chc50: vptestmd k1, zmm11, zmm11 ; Test 2nd for conflicts. vmovaps zmm16, zmm28 ; Copy AllOnes into zmm16. kmovw ebx, k1 ; Move mask into ebx. vpaddd zmm16, zmm16, zmm21 ; Add partial counts. test ebx, ebx ; Any conflicts? jz short Chc57 ; No conflicts. ; ; Second register (zmm6) has a conflict (zmm11). ; align 16 Chc55: vpbroadcastd zmm18, ebx ; Bcast mask into zmm18. kmovw k1, ebx ; Move mask into k1. vpaddd zmm16 {k1}, zmm16, zmm28 ; Add masked counts. vptestmd k0 {k1}, zmm18, zmm11 ; Test against conflict. kmovw esi, k0 ; Move new mask into esi. and ebx, esi ; Mask off recent bit. jnz short Chc55 ; Continue loop if bits left ; ; Conflicts have been resolved for second register (zmm6), with the final count ; now living in zmm16. Scatter back to memory. ; Chc57: kxnorw k7, k3, k3 ; Set all bits in writemask. vpscatterdd [r9+4*zmm6] {k7}, zmm16 ; Save counts. ; ; Intentional follow-on. ; ; ; Test the third register (zmm7) to see if it has any conflicts (zmm16). ; Chc60: vptestmd k1, zmm12, zmm12 ; Test 3rd for conflicts. vmovaps zmm16, zmm28 ; Copy AllOnes into zmm16. kmovw ebx, k1 ; Move mask into ebx. vpaddd zmm16, zmm16, zmm22 ; Add partial counts. test ebx, ebx ; Any conflicts? jz short Chc67 ; No conflicts. ; ; Third register (zmm7) has a conflict (zmm16). ; align 16 Chc65: vpbroadcastd zmm18, ebx ; Bcast mask into zmm18. kmovw k1, ebx ; Move mask into k1. vpaddd zmm16 {k1}, zmm16, zmm28 ; Add masked counts. vptestmd k0 {k1}, zmm18, zmm12 ; Test against conflict. kmovw esi, k0 ; Move new mask into esi. and ebx, esi ; Mask off recent bit. jnz short Chc65 ; Continue loop if bits left ; ; Conflicts have been resolved for third register (zmm7), with the final count ; now living in zmm16. Scatter back to memory. ; Chc67: kxnorw k7, k3, k3 ; Set all bits in writemask. vpscatterdd [r10+4*zmm7] {k7}, zmm16 ; Save counts. ; ; Intentional follow-on. ; ; ; Test the second register (zmm8) to see if it has any conflicts (zmm13). ; Chc70: vptestmd k1, zmm13, zmm13 ; Test 4th for conflicts. vmovaps zmm16, zmm28 ; Copy AllOnes into zmm16. kmovw ebx, k1 ; Move mask into ebx. vpaddd zmm16, zmm16, zmm23 ; Add partial counts. test ebx, ebx ; Any conflicts? jz short Chc77 ; No conflicts. ; ; Fourth register (zmm8) has a conflict (zmm13). ; align 16 Chc75: vpbroadcastd zmm18, ebx ; Bcast mask into zmm18. kmovw k1, ebx ; Move mask into k1. vpaddd zmm16 {k1}, zmm16, zmm28 ; Add masked counts. vptestmd k0 {k1}, zmm18, zmm13 ; Test against conflict. kmovw esi, k0 ; Move new mask into esi. and ebx, esi ; Mask off recent bit. jnz short Chc75 ; Continue loop if bits left ; ; Conflicts have been resolved for second register (zmm8), with the final count ; now living in zmm16. Scatter back to memory. ; Chc77: kxnorw k7, k3, k3 ; Set all bits in writemask. vpscatterdd [r11+4*zmm8] {k7}, zmm16 ; Save counts. ; ; Check for loop termination. ; sub ecx, 1 ; Decrement counter. jnz Chc30 ; Continue if != 0. ; ; Merge four histograms into one, 128 bytes at a time (two zmm registers in ; flight per histogram). ; Chc85: mov ecx, 8 xor rax, rax align 16 Chc90: vmovdqa32 zmm20, zmmword ptr [r8+rax] ; Load 1st histo 0-63. vmovdqa32 zmm22, zmmword ptr [r9+rax] ; Load 2nd histo 0-63. vpaddd zmm10, zmm20, zmm22 ; Add 1-2 0-63 histo. vmovdqa32 zmm21, zmmword ptr [r8+rax+40h] ; Load 1st histo 64-127. vmovdqa32 zmm23, zmmword ptr [r9+rax+40h] ; Load 2nd histo 64-127. vpaddd zmm13, zmm21, zmm23 ; Add 1-2 64-127 histo. vmovdqa32 zmm24, zmmword ptr [r10+rax] ; Load 3rd histo 0-63. vmovdqa32 zmm26, zmmword ptr [r11+rax] ; Load 4th histo 0-63. vpaddd zmm11, zmm24, zmm26 ; Add 3-4 0-63 histo. vmovdqa32 zmm25, zmmword ptr [r10+rax+40h]; Load 3rd histo 64-127. vmovdqa32 zmm27, zmmword ptr [r11+rax+40h]; Load 4th histo 64-127. vpaddd zmm14, zmm25, zmm27 ; Add 3-4 64-127 histo. vpaddd zmm12, zmm10, zmm11 ; Merge 0-63 histo. vmovdqa32 zmmword ptr [r8+rax], zmm12 ; Save 0-63 histo. vpaddd zmm15, zmm13, zmm14 ; Merge 64-127 histo. vmovdqa32 zmmword ptr [r8+rax+40h], zmm15 ; Save 64-127 histo. add rax, 80h ; Advance to next 128b. sub ecx, 1 ; Decrement loop cntr. jnz Chc90 ; Continue if != 0. ; ; Indicate success. ; mov rax, 1 ; ; Restore non-volatile registers. ; Chc99: mov rbp, Locals.SavedRbp[rsp] mov rbx, Locals.SavedRbx[rsp] mov rdi, Locals.SavedRdi[rsp] mov rsi, Locals.SavedRsi[rsp] mov r12, Locals.SavedR12[rsp] mov r13, Locals.SavedR13[rsp] mov r14, Locals.SavedR14[rsp] mov r15, Locals.SavedR15[rsp] movdqa xmm6, Locals.SavedXmm6[rsp] movdqa xmm7, Locals.SavedXmm7[rsp] movdqa xmm8, Locals.SavedXmm8[rsp] movdqa xmm9, Locals.SavedXmm9[rsp] movdqa xmm10, Locals.SavedXmm10[rsp] movdqa xmm11, Locals.SavedXmm11[rsp] movdqa xmm12, Locals.SavedXmm12[rsp] movdqa xmm13, Locals.SavedXmm13[rsp] movdqa xmm14, Locals.SavedXmm14[rsp] movdqa xmm15, Locals.SavedXmm15[rsp] ; ; Begin epilogue. Deallocate stack space and return. ; add rsp, LOCALS_SIZE ret ;IACA_VC_END NESTED_END CreateHistogramAvx512AlignedAsm_v2, _TEXT$00 NESTED_ENTRY CreateHistogramAvx512AlignedAsm_v3, _TEXT$00 ; ; Begin prologue. Allocate stack space and save non-volatile registers. ; alloc_stack LOCALS_SIZE save_reg rbp, Locals.SavedRbp ; Save non-volatile rbp. save_reg rbx, Locals.SavedRbx ; Save non-volatile rbx. save_reg rdi, Locals.SavedRdi ; Save non-volatile rdi. save_reg rsi, Locals.SavedRsi ; Save non-volatile rsi. save_reg r12, Locals.SavedR12 ; Save non-volatile r12. save_reg r13, Locals.SavedR13 ; Save non-volatile r13. save_reg r14, Locals.SavedR14 ; Save non-volatile r14. save_reg r15, Locals.SavedR15 ; Save non-volatile r15. save_xmm128 xmm6, Locals.SavedXmm6 ; Save non-volatile xmm6. save_xmm128 xmm7, Locals.SavedXmm7 ; Save non-volatile xmm7. save_xmm128 xmm8, Locals.SavedXmm8 ; Save non-volatile xmm8. save_xmm128 xmm9, Locals.SavedXmm9 ; Save non-volatile xmm9. save_xmm128 xmm10, Locals.SavedXmm10 ; Save non-volatile xmm10. save_xmm128 xmm11, Locals.SavedXmm11 ; Save non-volatile xmm11. save_xmm128 xmm12, Locals.SavedXmm12 ; Save non-volatile xmm12. save_xmm128 xmm13, Locals.SavedXmm13 ; Save non-volatile xmm13. save_xmm128 xmm14, Locals.SavedXmm14 ; Save non-volatile xmm14. save_xmm128 xmm15, Locals.SavedXmm15 ; Save non-volatile xmm15. END_PROLOGUE ; ; Clear return value (Success = FALSE). ; ;IACA_VC_START xor rax, rax ; Clear rax. ; ; Validate parameters. ; test rcx, rcx ; Is rcx NULL? jz Chc99 ; Yes, abort. test rdx, rdx ; Is rdx NULL? jz Chc99 ; Yes, abort. ; ; Verify the string is at least 64 bytes long. ; mov r9, 64 ; Initialize r9 to 64. cmp String.Length[rcx], r9d ; Compare Length to 64. jl Chc99 ; String is too short. ; ; Ensure the incoming string and histogram buffers are aligned to 32-byte ; boundaries. ; mov r9, 31 ; Initialize r9 to 31. test String.Buffer[rcx], r9 ; Is string aligned? jnz Chc99 ; No, abort. ; ; Initialize loop variables. ; ; rcx - Counter. ; ; rdx - Base string buffer. ; ; r8 - Base address of first histogram buffer. ; ; r9 - Base address of second histogram buffer. ; ; r10 - Base address of third histogram buffer. ; ; r11 - Base address of fourth histogram buffer. ; mov r8, rdx ; Load 1st histo buffer. lea r9, Histogram.Histogram2[r8] ; Load 2nd histo buffer. lea r10, Histogram.Histogram3[r8] ; Load 3rd histo buffer. lea r11, Histogram.Histogram4[r8] ; Load 4th histo buffer. mov rdx, String.Buffer[rcx] ; Load string buffer. mov ecx, String.Length[rcx] ; Load string length. shr ecx, 6 ; Divide by 64 to get loop ; iterations. vmovntdqa zmm28, zmmword ptr [AllOnes] vmovntdqa zmm29, zmmword ptr [AllNegativeOnes] vmovntdqa zmm30, zmmword ptr [AllBinsMinusOne] vmovntdqa zmm31, zmmword ptr [AllThirtyOne] mov rax, 1111111111111111h kmovq k1, rax vpmovm2b zmm1, k1 kshiftlq k2, k1, 1 vpmovm2b zmm2, k2 kshiftlq k3, k1, 2 vpmovm2b zmm3, k3 kshiftlq k4, k1, 3 vpmovm2b zmm4, k4 align 16 Chc30: vmovntdqa zmm0, zmmword ptr [rdx] ; Load 64 bytes into zmm0. ; ; Advance the source input pointer by 64 bytes. Clear the k1 mask ; which we'll use later for the vpgatherds. ; add rdx, 40h ; Advance 64 bytes. ; ; Extract byte values for each doubleword into separate registers. ; ;IACA_VC_START kxnorq k1, k5, k5 vpandd zmm5, zmm1, zmm0 vpgatherdd zmm20 {k1}, [r8+4*zmm5] ; Gather 1st counts. vpconflictd zmm10, zmm5 kxnorq k2, k6, k6 vpandd zmm6, zmm2, zmm0 vpsrldq zmm6, zmm6, 1 vpgatherdd zmm21 {k2}, [r9+4*zmm6] ; Gather 2nd counts. vpconflictd zmm11, zmm6 vpord zmm14, zmm10, zmm11 kxnorq k3, k7, k7 vpandd zmm7, zmm3, zmm0 vpsrldq zmm7, zmm7, 2 vpgatherdd zmm22 {k3}, [r10+4*zmm7] ; Gather 3rd counts. vpconflictd zmm12, zmm7 vpandd zmm8, zmm4, zmm0 vpsrldq zmm8, zmm8, 3 kxnorq k4, k0, k0 vpgatherdd zmm23 {k4}, [r11+4*zmm8] ; Gather 4th counts. vpconflictd zmm13, zmm8 vpord zmm15, zmm12, zmm13 vpord zmm14, zmm14, zmm15 vptestmd k1, zmm14, zmm14 ; Any conflicts anywhere? kortestw k1, k1 jne Chc40 ; At least one conflict. ; ; No conflicts across all registers. Proceed with adding 1 (zmm28) to all ; the counts and then scattering the results back into memory. ; align 16 Chc35: kxnorq k1, k5, k5 vpaddd zmm24, zmm20, zmm28 ; Add 1st counts. vpscatterdd [r8+4*zmm5] {k1}, zmm24 ; Save 1st counts. kxnorq k2, k6, k6 vpaddd zmm25, zmm21, zmm28 ; Add 2nd counts. vpscatterdd [r9+4*zmm6] {k2}, zmm25 ; Save 2nd counts. kxnorq k3, k7, k7 vpaddd zmm26, zmm22, zmm28 ; Add 3rd counts. vpscatterdd [r10+4*zmm7] {k3}, zmm26 ; Save 3rd counts. kxnorq k4, k0, k0 vpaddd zmm27, zmm23, zmm28 ; Add 4th counts. vpscatterdd [r11+4*zmm8] {k4}, zmm27 ; Save 4th counts. Chc38: sub ecx, 1 ; Decrement counter. jnz Chc30 ; Continue if != 0. ; ; We've finished processing the input string, jump to finalization logic. ; jmp Chc85 ; ; Conflict handling logic. At least one of the zmm registers had a conflict. ; ; ; Test the first register (zmm5) to see if it has any conflicts (zmm10). ; Chc40: vptestmd k1, zmm10, zmm10 ; Test 1st for conflicts. vmovaps zmm16, zmm28 ; Copy AllOnes into zmm16. kortestw k1, k1 ; Any conflicts? jz short Chc47 ; No conflicts. ; ; First register (zmm5) has a conflict (zmm10). ; vplzcntd zmm10, zmm10 ; Count leading zeros. vpsubd zmm10, zmm31, zmm10 ; Subtract 31 from each cnt. align 16 Chc45: vpermd zmm18 {k1} {z}, zmm10, zmm16 vpermd zmm10 {k1}, zmm10, zmm10 vpaddd zmm16 {k1}, zmm16, zmm18 vpcmpd k1, zmm29, zmm10, OP_NEQ ; Generate new mask. kortestw k1, k1 jne short Chc45 ; ; Conflicts have been resolved for first register (zmm5), with the final count ; now living in zmm16. Scatter back to memory. ; Chc47: kxnorw k7, k3, k3 ; Set all bits in writemask. vpaddd zmm16, zmm16, zmm20 ; Add partial counts. vpscatterdd [r8+4*zmm5] {k7}, zmm16 ; Save counts. ; ; Intentional follow-on. ; ; ; Test the second register (zmm6) to see if it has any conflicts (zmm11). ; Chc50: vptestmd k1, zmm11, zmm11 ; Test 2nd for conflicts. vmovaps zmm16, zmm28 ; Copy AllOnes into zmm16. kortestw k1, k1 ; Any conflicts? jz short Chc57 ; No conflicts. ; ; Second register (zmm6) has a conflict (zmm11). ; vplzcntd zmm10, zmm11 ; Count leading zeros. vpsubd zmm10, zmm31, zmm10 ; Subtract 31 from each cnt. align 16 Chc55: vpermd zmm18 {k1} {z}, zmm10, zmm16 vpermd zmm10 {k1}, zmm10, zmm10 vpaddd zmm16 {k1}, zmm16, zmm18 vpcmpd k1, zmm29, zmm10, OP_NEQ ; Generate new mask. kortestw k1, k1 jne short Chc55 ; ; Conflicts have been resolved for second register (zmm6), with the final count ; now living in zmm16. Scatter back to memory. ; Chc57: kxnorw k7, k3, k3 ; Set all bits in writemask. vpaddd zmm16, zmm16, zmm21 ; Add partial counts. vpscatterdd [r9+4*zmm6] {k7}, zmm16 ; Save counts. ; ; Intentional follow-on. ; ; ; Test the third register (zmm7) to see if it has any conflicts (zmm12). ; Chc60: vptestmd k1, zmm12, zmm12 ; Test 3rd for conflicts. vmovaps zmm16, zmm28 ; Copy AllOnes into zmm16. kortestw k1, k1 ; Any conflicts? jz short Chc67 ; No conflicts. ; ; Third register (zmm7) has a conflict (zmm12). ; vplzcntd zmm10, zmm12 ; Count leading zeros. vpsubd zmm10, zmm31, zmm10 ; Subtract 31 from each cnt. align 16 Chc65: vpermd zmm18 {k1} {z}, zmm10, zmm16 vpermd zmm10 {k1}, zmm10, zmm10 vpaddd zmm16 {k1}, zmm16, zmm18 vpcmpd k1, zmm29, zmm10, OP_NEQ ; Generate new mask. kortestw k1, k1 jne short Chc65 ; ; Conflicts have been resolved for third register (zmm7), with the final count ; now living in zmm16. Scatter back to memory. ; Chc67: kxnorw k7, k3, k3 ; Set all bits in writemask. vpaddd zmm16, zmm16, zmm22 ; Add partial counts. vpscatterdd [r10+4*zmm7] {k7}, zmm16 ; Save counts. ; ; Intentional follow-on. ; ; ; Test the fourth register (zmm8) to see if it has any conflicts (zmm13). ; Chc70: vptestmd k1, zmm13, zmm13 ; Test 4th for conflicts. vmovaps zmm16, zmm28 ; Copy AllOnes into zmm16. kortestw k1, k1 ; Any conflicts? jz short Chc77 ; No conflicts. ; ; Fourth register (zmm8) has a conflict (zmm13). ; vplzcntd zmm10, zmm13 ; Count leading zeros. vpsubd zmm10, zmm31, zmm10 ; Subtract 31 from each cnt. align 16 Chc75: vpermd zmm18 {k1} {z}, zmm10, zmm16 vpermd zmm10 {k1}, zmm10, zmm10 vpaddd zmm16 {k1}, zmm16, zmm18 vpcmpd k1, zmm29, zmm10, OP_NEQ ; Generate new mask. kortestw k1, k1 jne short Chc75 ; ; Conflicts have been resolved for second register (zmm8), with the final count ; now living in zmm16. Scatter back to memory. ; Chc77: kxnorw k7, k3, k3 ; Set all bits in writemask. vpaddd zmm16, zmm16, zmm23 ; Add partial counts. vpscatterdd [r11+4*zmm8] {k7}, zmm16 ; Save counts. ; ; Check for loop termination. ; sub ecx, 1 ; Decrement counter. jnz Chc30 ; Continue if != 0. ; ; Merge four histograms into one, 128 bytes at a time (two zmm registers in ; flight per histogram). ; Chc85: mov ecx, 8 xor rax, rax align 16 Chc90: vmovdqa32 zmm20, zmmword ptr [r8+rax] ; Load 1st histo 0-63. vmovdqa32 zmm22, zmmword ptr [r9+rax] ; Load 2nd histo 0-63. vpaddd zmm10, zmm20, zmm22 ; Add 1-2 0-63 histo. vmovdqa32 zmm21, zmmword ptr [r8+rax+40h] ; Load 1st histo 64-127. vmovdqa32 zmm23, zmmword ptr [r9+rax+40h] ; Load 2nd histo 64-127. vpaddd zmm13, zmm21, zmm23 ; Add 1-2 64-127 histo. vmovdqa32 zmm24, zmmword ptr [r10+rax] ; Load 3rd histo 0-63. vmovdqa32 zmm26, zmmword ptr [r11+rax] ; Load 4th histo 0-63. vpaddd zmm11, zmm24, zmm26 ; Add 3-4 0-63 histo. vmovdqa32 zmm25, zmmword ptr [r10+rax+40h]; Load 3rd histo 64-127. vmovdqa32 zmm27, zmmword ptr [r11+rax+40h]; Load 4th histo 64-127. vpaddd zmm14, zmm25, zmm27 ; Add 3-4 64-127 histo. vpaddd zmm12, zmm10, zmm11 ; Merge 0-63 histo. vmovdqa32 zmmword ptr [r8+rax], zmm12 ; Save 0-63 histo. vpaddd zmm15, zmm13, zmm14 ; Merge 64-127 histo. vmovdqa32 zmmword ptr [r8+rax+40h], zmm15 ; Save 64-127 histo. add rax, 80h ; Advance to next 128b. sub ecx, 1 ; Decrement loop cntr. jnz Chc90 ; Continue if != 0. ; ; Shift rax (0x400) right 10 to indicate 1, our success return value. ; shr rax, 10 ; ; Restore non-volatile registers. ; Chc99: mov rbp, Locals.SavedRbp[rsp] mov rbx, Locals.SavedRbx[rsp] mov rdi, Locals.SavedRdi[rsp] mov rsi, Locals.SavedRsi[rsp] mov r12, Locals.SavedR12[rsp] mov r13, Locals.SavedR13[rsp] mov r14, Locals.SavedR14[rsp] mov r15, Locals.SavedR15[rsp] movdqa xmm6, Locals.SavedXmm6[rsp] movdqa xmm7, Locals.SavedXmm7[rsp] movdqa xmm8, Locals.SavedXmm8[rsp] movdqa xmm9, Locals.SavedXmm9[rsp] movdqa xmm10, Locals.SavedXmm10[rsp] movdqa xmm11, Locals.SavedXmm11[rsp] movdqa xmm12, Locals.SavedXmm12[rsp] movdqa xmm13, Locals.SavedXmm13[rsp] movdqa xmm14, Locals.SavedXmm14[rsp] movdqa xmm15, Locals.SavedXmm15[rsp] ; ; Begin epilogue. Deallocate stack space and return. ; add rsp, LOCALS_SIZE ret ;IACA_VC_END NESTED_END CreateHistogramAvx512AlignedAsm_v3, _TEXT$00 NESTED_ENTRY CreateHistogramAvx512AlignedAsm_v4, _TEXT$00 ; ; Begin prologue. Allocate stack space and save non-volatile registers. ; alloc_stack LOCALS_SIZE save_xmm128 xmm6, Locals.SavedXmm6 ; Save non-volatile xmm6. save_xmm128 xmm7, Locals.SavedXmm7 ; Save non-volatile xmm7. save_xmm128 xmm8, Locals.SavedXmm8 ; Save non-volatile xmm8. save_xmm128 xmm9, Locals.SavedXmm9 ; Save non-volatile xmm9. END_PROLOGUE ; ; Clear return value (Success = FALSE). ; IACA_VC_START xor rax, rax ; Clear rax. ; ; Validate parameters. ; test rcx, rcx ; Is rcx NULL? jz Chf99 ; Yes, abort. test rdx, rdx ; Is rdx NULL? jz Chf99 ; Yes, abort. ; ; Verify the string is at least 64 bytes long. ; mov r9, 64 ; Initialize r9 to 64. cmp String.Length[rcx], r9d ; Compare Length to 64. jl Chf99 ; String is too short. ; ; Ensure the incoming string and histogram buffers are aligned to 32-byte ; boundaries. ; mov r9, 31 ; Initialize r9 to 31. test String.Buffer[rcx], r9 ; Is string aligned? jnz Chf99 ; No, abort. ; ; Initialize loop variables. ; ; rax - Counter for which byte of a doubleword we're processing. ; ; rcx - Counter (length of string in multiples of 64). ; ; rdx - Base string buffer. ; ; r8 - Base address of first histogram buffer. ; ; r9 - Inverted version of rax. E.g. if: ; rax == 0, r9 == 4 ; rax == 1, r9 == 3 ; rax == 2, r9 == 2 ; rax == 3, r9 == 1 ; rax == 4, r9 == 0 ; ; r10 - Unused. ; ; r11 - Unused. ; ; zmm0 - Receives 64 bytes of the input string. ; ; zmm1 - Vectorized mask isolating the byte we're interested in for a given ; round. E.g. 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff. ; ; N.B. We start off with byte 4 and work backwards to the first byte. ; ; zmm2 - Receives the isolated byte in each doubleword. ; ; zmm3 - Receives the gathered counts for a given set of bytes being ; processed. ; ; zmm4 - Used as the permute control register. Initially captures the result ; of the conflict comparison, and then the leading zero count. ; ; zmm5 - Used to capture partial counts when handling conflicts. ; ; zmm6 - Used for permuting counts as per the control register. ; ; zmm7 - Vectorized mask base used at the top of the loop. ; ; zmm28 - AllOnes ; ; zmm29 - AllNegativeOnes ; ; zmm31 - AllThirtyOne ; mov r8, rdx ; Load 1st histo buffer. mov rdx, String.Buffer[rcx] ; Load string buffer. mov ecx, String.Length[rcx] ; Load string length. shr ecx, 6 ; Divide by 64 to get loop ; iterations. vmovntdqa zmm28, zmmword ptr [AllOnes] vmovntdqa zmm29, zmmword ptr [AllNegativeOnes] vmovntdqa zmm31, zmmword ptr [AllThirtyOne] ; ; Isolate the 4th byte in every doubleword. ; xor rax, rax not al vpbroadcastd zmm7, eax align 16 Chf15: vmovntdqa zmm0, zmmword ptr [rdx] ; Load 64 bytes into zmm0. mov eax, 4 ; Initialize eax counter. xor r9, r9 ; Clear r9. add rdx, 40h ; Advance buffer 64 bytes. vmovaps zmm1, zmm7 ; Initialize byte mask. vpxord zmm9, zmm9, zmm9 ; Clear shift vector. align 16 Chf20: kxnorw k1, k5, k5 vpandd zmm2, zmm1, zmm0 vpsrlq zmm2, zmm2, xmm9 vpxord zmm3, zmm3, zmm3 ; Clear counts. vpgatherdd zmm3 {k1}, [r8+4*zmm2] ; Gather counts for bytes. vpconflictd zmm4, zmm2 ; Detect conflicts. vmovaps zmm5, zmm28 ; Copy AllOnes register. ; ; Increment the 0..3 counter (r9) by one, shift the vectorized mask control ; (zmm1) right by one quadword. ; add r9, 8 movd xmm9, r9 vpslldq zmm1, zmm1, 1 ; ; Were there any conflicts? ; vptestmd k1, zmm4, zmm4 ; Generate conflict mask. kortestw k1, k1 ; Any conflicts? je Chf27 ; No conflicts, update. ; ; There was at least one conflict. Proceed with the conflict handling logic. ; vplzcntd zmm4, zmm4 ; Count leading zeros. vpsubd zmm4, zmm31, zmm4 ; Subtract 31 from elems. Chf25: vpermd zmm6 {k1} {z}, zmm4, zmm5 ; Capture partials. vpermd zmm4 {k1}, zmm4, zmm4 ; Permute control reg. vpaddd zmm5 {k1}, zmm5, zmm6 ; Add counts. vpcmpd k1, zmm4, zmm29, OP_NEQ ; Generate new mask. kortestw k1, k1 ; Any more conflicts? jne short Chf25 ; Yes, jump back and repeat. ; ; If we get here, we've resolved all the conflicts (if there were any), and ; need to add the final counts together then scatter everything back to its ; appropriate location. ; Chf27: kxnorw k1, k6, k6 ; Set all bits in writemask. vpaddd zmm3, zmm3, zmm5 ; Add counts to total. vpscatterdd [r8+4*zmm2] {k1}, zmm3 ; Save counts. sub rax, 1 ; Decrement loop counter. jnz Chf20 ; If nz, jump back to cont. ; ; We've finished processing all four bytes in each doubleword in each vector. ; Check for loop termination against the rcx counter. ; sub ecx, 1 ; Decrement counter. jnz Chf15 ; Continue if != 0. ; ; No more bytes to process. Indicate success and return. ; mov rax, 1 ; ; Restore non-volatile registers. ; Chf99: movdqa xmm6, Locals.SavedXmm6[rsp] movdqa xmm7, Locals.SavedXmm7[rsp] movdqa xmm8, Locals.SavedXmm8[rsp] movdqa xmm9, Locals.SavedXmm9[rsp] ; ; Begin epilogue. Deallocate stack space and return. ; add rsp, LOCALS_SIZE ret IACA_VC_END NESTED_END CreateHistogramAvx512AlignedAsm_v4, _TEXT$00 LEAF_ENTRY CreateHistogramAvx512AlignedAsm_v5, _TEXT$00 ret LEAF_END CreateHistogramAvx512AlignedAsm_v5, _TEXT$00 ; vim:set tw=80 ts=8 sw=4 sts=4 et syntax=masm fo=croql comments=\:; : end
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef NDEBUG #include "ui/compositor/debug_utils.h" #include <iomanip> #include <iostream> #include <string> #include "base/logging.h" #include "base/utf_string_conversions.h" #include "ui/compositor/layer.h" #include "ui/gfx/interpolated_transform.h" #include "ui/gfx/point.h" #include "ui/gfx/point_conversions.h" #include "ui/gfx/transform.h" namespace ui { namespace { void PrintLayerHierarchyImp(const Layer* layer, int indent, gfx::Point mouse_location) { std::wostringstream buf; std::string indent_str(indent, ' '); std::string content_indent_str(indent+1, ' '); layer->transform().TransformPointReverse(mouse_location); bool mouse_inside_layer_bounds = layer->bounds().Contains(mouse_location); mouse_location.Offset(-layer->bounds().x(), -layer->bounds().y()); buf << UTF8ToWide(indent_str); if (mouse_inside_layer_bounds) buf << L'*'; else buf << L' '; buf << UTF8ToWide(layer->name()) << L' ' << layer; switch (layer->type()) { case ui::LAYER_NOT_DRAWN: buf << L" not_drawn"; break; case ui::LAYER_TEXTURED: buf << L" textured"; if (layer->fills_bounds_opaquely()) buf << L" opaque"; break; case ui::LAYER_SOLID_COLOR: buf << L" solid"; break; } if (!layer->visible()) buf << L" !visible"; buf << L'\n' << UTF8ToWide(content_indent_str); buf << L"bounds: " << layer->bounds().x() << L',' << layer->bounds().y(); buf << L' ' << layer->bounds().width() << L'x' << layer->bounds().height(); if (layer->opacity() != 1.0f) { buf << L'\n' << UTF8ToWide(content_indent_str); buf << L"opacity: " << std::setprecision(2) << layer->opacity(); } if (layer->transform().HasChange()) { gfx::Point translation; float rotation; gfx::Point3F scale; if (ui::InterpolatedTransform::FactorTRS(layer->transform(), &translation, &rotation, &scale)) { if (!translation.IsOrigin()) { buf << L'\n' << UTF8ToWide(content_indent_str); buf << L"translation: " << translation.x() << L", " << translation.y(); } if (fabs(rotation) > 1e-5) { buf << L'\n' << UTF8ToWide(content_indent_str); buf << L"rotation: " << std::setprecision(4) << rotation; } if (!gfx::ToFlooredPoint(scale.AsPointF()).IsOrigin()) { buf << L'\n' << UTF8ToWide(content_indent_str); buf << std::setprecision(4); buf << L"scale: " << scale.x() << L", " << scale.y(); } } } VLOG(1) << buf.str(); std::cout << buf.str() << std::endl; for (size_t i = 0, count = layer->children().size(); i < count; ++i) PrintLayerHierarchyImp(layer->children()[i], indent + 3, mouse_location); } } // namespace void PrintLayerHierarchy(const Layer* layer, gfx::Point mouse_location) { PrintLayerHierarchyImp(layer, 0, mouse_location); } } // namespace ui #endif // NDEBUG
db DEX_CHARIZARD ; pokedex id db 78 ; base hp db 84 ; base attack db 78 ; base defense db 100 ; base speed db 85 ; base special db FIRE ; species type 1 db FLYING ; species type 2 db FULL_HEAL ;make lance more annoying yes? db 209 ; base exp yield INCBIN "pic/ymon/charizard.pic",0,1 ; 77, sprite dimensions dw CharizardPicFront dw CharizardPicBack ; attacks known at lvl 0 db SCRATCH db GROWL db EMBER db LEER db 3 ; growth rate ; learnset tmlearn 1,3,5,6,7,8 tmlearn 9,10,15 tmlearn 17,18,19,20,23 tmlearn 26,27,28,31,32 tmlearn 33,34,38,39,40 tmlearn 44 tmlearn 50,51,52,54 db BANK(CharizardPicFront)
// -*- C++ -*- //===----------------------------------------------------------------------===// // // 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 // //===----------------------------------------------------------------------===// // <iterator> // <iterator> // template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8 #include <vector> #include <iterator> #include "test_macros.h" int main(int, char**) { int c[5]; std::empty(c); // expected-error {{ignoring return value of function declared with 'nodiscard' attribute}} return 0; }
/************************************************* Author:Micooz Date:2013-10-23 Description:精灵实现 **************************************************/ #include "Config.h" #include "QSprite.h" #include "CTimeDelay.h" extern CTimeDelay timeController; extern QPainter *p; QSprite::QSprite() { this->Init(); } void QSprite::Init(void) { m_frames.clear(); m_nframe = 0; m_animate_i = 0; m_pos.setX(0); m_pos.setY(0); m_destroyed = false; m_execRender = true; } //QSprite::QSprite(QImage *src,QRect *rects,int n/* =1 */) //{ // m_frames.clear(); // m_nframe = 0; // m_destroyed = false; // m_execRender = true; // m_animate_i = 0; // m_pos = QPoint(0,0); // this->setResource(src,rects,n); //} void QSprite::setResource(const QImage *src, const QRect *rects, const int &n /* =1 */) { if(src && n > 0) { static QImage t_img; for(int i = 0;i<n;++i) { t_img = src->copy(rects[i]); t_img = t_img.scaled(rects[i].width() * SCALE,rects[i].height() * SCALE); m_frames.append(t_img); ++m_nframe; } } } QRect* QSprite::Region() { if(m_destroyed) { return 0; } else { m_reg.setTopLeft(m_pos); m_reg.setWidth(Width()); m_reg.setHeight(Height()); return &m_reg; } } //从帧序列的from位置依次渲染到to位置,位置是x,y,渲染时间间隔f毫秒,默认重复动画 void QSprite::display(int from/* =0 */, int to/* =-1 */, int x/* =-1 */, int y/* =-1 */, int f /* =0 */ ) { if(!m_execRender) return; if(x != -1 && y != -1) { setPos(x,y); } if(to == -1) to = m_nframe - 1; //to为默认值-1表示渲染全部帧 if(f > 0) { //当前帧保持(无变化) p->drawImage(m_pos, m_frames[m_animate_i + from] ); if(timeController.Delay(f,this - 9)) { ++m_animate_i; } if(m_animate_i + from > to ) { //最后一帧 m_animate_i = 0; if(m_destroyed) { //被销毁则不重复渲染 m_execRender = false; } } } else { //当f为0时仅渲染第一帧 p->drawImage(m_pos,m_frames.at(from)); } } void QSprite::setPos(int x, int y) { m_pos.setX(x); m_pos.setY(y); } void QSprite::setOffset(int dx,int dy) { m_pos.setX(m_pos.x()+dx); m_pos.setY(m_pos.y()+dy); } void QSprite::destroy() { m_destroyed = true; } bool QSprite::IsDestroyed()const { return m_destroyed; } bool QSprite::IsFinishRender()const { return !m_execRender; } int QSprite::x()const { return m_pos.x(); } int QSprite::y()const { return m_pos.y(); } int QSprite::Width(int index /* =0 */) const { //m_frames未初始化问题 return m_frames.at(index).width(); } int QSprite::Height(int index /* =0 */) const { return m_frames.at(index).height(); }
############################################################################### # Copyright 2018 Intel Corporation # All Rights Reserved. # # If this software was obtained under the Intel Simplified Software License, # the following terms apply: # # The source code, information and material ("Material") contained herein is # owned by Intel Corporation or its suppliers or licensors, and title to such # Material remains with Intel Corporation or its suppliers or licensors. The # Material contains proprietary information of Intel or its suppliers and # licensors. The Material is protected by worldwide copyright laws and treaty # provisions. No part of the Material may be used, copied, reproduced, # modified, published, uploaded, posted, transmitted, distributed or disclosed # in any way without Intel's prior express written permission. No license under # any patent, copyright or other intellectual property rights in the Material # is granted to or conferred upon you, either expressly, by implication, # inducement, estoppel or otherwise. Any license under such intellectual # property rights must be express and approved by Intel in writing. # # Unless otherwise agreed by Intel in writing, you may not remove or alter this # notice or any other notice embedded in Materials by Intel or Intel's # suppliers or licensors in any way. # # # If this software was obtained under the Apache License, Version 2.0 (the # "License"), the following terms apply: # # 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. ############################################################################### .section .note.GNU-stack,"",%progbits .text p192r1_data: _prime192r1: .long 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF .p2align 5, 0x90 .globl h9_add_192 .type h9_add_192, @function h9_add_192: movl (%esi), %eax addl (%ebx), %eax movl %eax, (%edi) movl (4)(%esi), %eax adcl (4)(%ebx), %eax movl %eax, (4)(%edi) movl (8)(%esi), %eax adcl (8)(%ebx), %eax movl %eax, (8)(%edi) movl (12)(%esi), %eax adcl (12)(%ebx), %eax movl %eax, (12)(%edi) movl (16)(%esi), %eax adcl (16)(%ebx), %eax movl %eax, (16)(%edi) movl (20)(%esi), %eax adcl (20)(%ebx), %eax movl %eax, (20)(%edi) mov $(0), %eax adc $(0), %eax ret .Lfe1: .size h9_add_192, .Lfe1-(h9_add_192) .p2align 5, 0x90 .globl h9_sub_192 .type h9_sub_192, @function h9_sub_192: movl (%esi), %eax subl (%ebx), %eax movl %eax, (%edi) movl (4)(%esi), %eax sbbl (4)(%ebx), %eax movl %eax, (4)(%edi) movl (8)(%esi), %eax sbbl (8)(%ebx), %eax movl %eax, (8)(%edi) movl (12)(%esi), %eax sbbl (12)(%ebx), %eax movl %eax, (12)(%edi) movl (16)(%esi), %eax sbbl (16)(%ebx), %eax movl %eax, (16)(%edi) movl (20)(%esi), %eax sbbl (20)(%ebx), %eax movl %eax, (20)(%edi) mov $(0), %eax adc $(0), %eax ret .Lfe2: .size h9_sub_192, .Lfe2-(h9_sub_192) .p2align 5, 0x90 .globl h9_shl_192 .type h9_shl_192, @function h9_shl_192: movl (20)(%esi), %eax movq (16)(%esi), %xmm2 movdqu (%esi), %xmm1 movdqa %xmm2, %xmm3 palignr $(8), %xmm1, %xmm3 psllq $(1), %xmm2 psrlq $(63), %xmm3 por %xmm3, %xmm2 movq %xmm2, (16)(%edi) movdqa %xmm1, %xmm3 pslldq $(8), %xmm3 psllq $(1), %xmm1 psrlq $(63), %xmm3 por %xmm3, %xmm1 movdqu %xmm1, (%edi) shr $(31), %eax ret .Lfe3: .size h9_shl_192, .Lfe3-(h9_shl_192) .p2align 5, 0x90 .globl h9_shr_192 .type h9_shr_192, @function h9_shr_192: movdqu (%esi), %xmm2 movq (16)(%esi), %xmm1 movdqa %xmm1, %xmm3 palignr $(8), %xmm2, %xmm3 psrlq $(1), %xmm2 psllq $(63), %xmm3 por %xmm3, %xmm2 movdqu %xmm2, (%edi) movdqa %xmm0, %xmm3 psrlq $(1), %xmm1 psllq $(63), %xmm3 por %xmm3, %xmm1 movq %xmm1, (16)(%edi) ret .Lfe4: .size h9_shr_192, .Lfe4-(h9_shr_192) .p2align 5, 0x90 .globl h9_p192r1_add .type h9_p192r1_add, @function h9_p192r1_add: push %ebp mov %esp, %ebp push %ebx push %esi push %edi mov %esp, %eax sub $(28), %esp and $(-16), %esp movl %eax, (24)(%esp) movl (8)(%ebp), %edi movl (12)(%ebp), %esi movl (16)(%ebp), %ebx call h9_add_192 mov %eax, %edx lea (%esp), %edi movl (8)(%ebp), %esi lea p192r1_data, %ebx lea ((_prime192r1-p192r1_data))(%ebx), %ebx call h9_sub_192 lea (%esp), %esi movl (8)(%ebp), %edi sub %eax, %edx cmovne %edi, %esi movdqu (%esi), %xmm0 movq (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movq %xmm1, (16)(%edi) mov (24)(%esp), %esp pop %edi pop %esi pop %ebx pop %ebp ret .Lfe5: .size h9_p192r1_add, .Lfe5-(h9_p192r1_add) .p2align 5, 0x90 .globl h9_p192r1_sub .type h9_p192r1_sub, @function h9_p192r1_sub: push %ebp mov %esp, %ebp push %ebx push %esi push %edi mov %esp, %eax sub $(28), %esp and $(-16), %esp movl %eax, (24)(%esp) movl (8)(%ebp), %edi movl (12)(%ebp), %esi movl (16)(%ebp), %ebx call h9_sub_192 mov %eax, %edx lea (%esp), %edi movl (8)(%ebp), %esi lea p192r1_data, %ebx lea ((_prime192r1-p192r1_data))(%ebx), %ebx call h9_add_192 lea (%esp), %esi movl (8)(%ebp), %edi test %edx, %edx cmove %edi, %esi movdqu (%esi), %xmm0 movq (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movq %xmm1, (16)(%edi) mov (24)(%esp), %esp pop %edi pop %esi pop %ebx pop %ebp ret .Lfe6: .size h9_p192r1_sub, .Lfe6-(h9_p192r1_sub) .p2align 5, 0x90 .globl h9_p192r1_neg .type h9_p192r1_neg, @function h9_p192r1_neg: push %ebp mov %esp, %ebp push %ebx push %esi push %edi mov %esp, %eax sub $(28), %esp and $(-16), %esp movl %eax, (24)(%esp) movl (8)(%ebp), %edi movl (12)(%ebp), %esi mov $(0), %eax subl (%esi), %eax movl %eax, (%edi) mov $(0), %eax sbbl (4)(%esi), %eax movl %eax, (4)(%edi) mov $(0), %eax sbbl (8)(%esi), %eax movl %eax, (8)(%edi) mov $(0), %eax sbbl (12)(%esi), %eax movl %eax, (12)(%edi) mov $(0), %eax sbbl (16)(%esi), %eax movl %eax, (16)(%edi) mov $(0), %eax sbbl (20)(%esi), %eax movl %eax, (20)(%edi) sbb %edx, %edx lea (%esp), %edi movl (8)(%ebp), %esi lea p192r1_data, %ebx lea ((_prime192r1-p192r1_data))(%ebx), %ebx call h9_add_192 lea (%esp), %esi movl (8)(%ebp), %edi test %edx, %edx cmove %edi, %esi movdqu (%esi), %xmm0 movq (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movq %xmm1, (16)(%edi) mov (24)(%esp), %esp pop %edi pop %esi pop %ebx pop %ebp ret .Lfe7: .size h9_p192r1_neg, .Lfe7-(h9_p192r1_neg) .p2align 5, 0x90 .globl h9_p192r1_mul_by_2 .type h9_p192r1_mul_by_2, @function h9_p192r1_mul_by_2: push %ebp mov %esp, %ebp push %ebx push %esi push %edi mov %esp, %eax sub $(28), %esp and $(-16), %esp movl %eax, (24)(%esp) lea (%esp), %edi movl (12)(%ebp), %esi call h9_shl_192 mov %eax, %edx mov %edi, %esi movl (8)(%ebp), %edi lea p192r1_data, %ebx lea ((_prime192r1-p192r1_data))(%ebx), %ebx call h9_sub_192 sub %eax, %edx cmove %edi, %esi movdqu (%esi), %xmm0 movq (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movq %xmm1, (16)(%edi) mov (24)(%esp), %esp pop %edi pop %esi pop %ebx pop %ebp ret .Lfe8: .size h9_p192r1_mul_by_2, .Lfe8-(h9_p192r1_mul_by_2) .p2align 5, 0x90 .globl h9_p192r1_mul_by_3 .type h9_p192r1_mul_by_3, @function h9_p192r1_mul_by_3: push %ebp mov %esp, %ebp push %ebx push %esi push %edi mov %esp, %eax sub $(56), %esp and $(-16), %esp movl %eax, (52)(%esp) lea p192r1_data, %eax lea ((_prime192r1-p192r1_data))(%eax), %eax movl %eax, (48)(%esp) lea (%esp), %edi movl (12)(%ebp), %esi call h9_shl_192 mov %eax, %edx mov %edi, %esi lea (24)(%esp), %edi mov (48)(%esp), %ebx call h9_sub_192 sub %eax, %edx cmove %edi, %esi movdqu (%esi), %xmm0 movq (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movq %xmm1, (16)(%edi) mov %edi, %esi movl (12)(%ebp), %ebx call h9_add_192 mov %eax, %edx movl (8)(%ebp), %edi mov (48)(%esp), %ebx call h9_sub_192 sub %eax, %edx cmove %edi, %esi movdqu (%esi), %xmm0 movq (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movq %xmm1, (16)(%edi) mov (52)(%esp), %esp pop %edi pop %esi pop %ebx pop %ebp ret .Lfe9: .size h9_p192r1_mul_by_3, .Lfe9-(h9_p192r1_mul_by_3) .p2align 5, 0x90 .globl h9_p192r1_div_by_2 .type h9_p192r1_div_by_2, @function h9_p192r1_div_by_2: push %ebp mov %esp, %ebp push %ebx push %esi push %edi mov %esp, %eax sub $(28), %esp and $(-16), %esp movl %eax, (24)(%esp) lea (%esp), %edi movl (12)(%ebp), %esi lea p192r1_data, %ebx lea ((_prime192r1-p192r1_data))(%ebx), %ebx call h9_add_192 mov $(0), %edx movl (%esi), %ecx and $(1), %ecx cmovne %edi, %esi cmove %edx, %eax movd %eax, %xmm0 movl (8)(%ebp), %edi call h9_shr_192 mov (24)(%esp), %esp pop %edi pop %esi pop %ebx pop %ebp ret .Lfe10: .size h9_p192r1_div_by_2, .Lfe10-(h9_p192r1_div_by_2) .p2align 5, 0x90 .globl h9_p192r1_mul_mont_slm .type h9_p192r1_mul_mont_slm, @function h9_p192r1_mul_mont_slm: push %ebp mov %esp, %ebp push %ebx push %esi push %edi push %ebp mov %esp, %eax sub $(44), %esp and $(-16), %esp movl %eax, (40)(%esp) pxor %mm0, %mm0 movq %mm0, (%esp) movq %mm0, (8)(%esp) movq %mm0, (16)(%esp) movq %mm0, (24)(%esp) movl (8)(%ebp), %edi movl (12)(%ebp), %esi movl (16)(%ebp), %ebp movl %edi, (28)(%esp) movl %esi, (32)(%esp) movl %ebp, (36)(%esp) mov $(6), %edi movd (4)(%esi), %mm1 movd (8)(%esi), %mm2 .p2align 5, 0x90 .Lmmul_loopgas_11: movd %edi, %mm7 movl (%ebp), %edx movl (%esi), %eax movd %edx, %mm0 add $(4), %ebp movl %ebp, (36)(%esp) pmuludq %mm0, %mm1 mul %edx addl (%esp), %eax adc $(0), %edx pmuludq %mm0, %mm2 movd %mm1, %ecx psrlq $(32), %mm1 add %edx, %ecx movd %mm1, %edx adc $(0), %edx addl (4)(%esp), %ecx movd (12)(%esi), %mm1 adc $(0), %edx movd %mm2, %ebx psrlq $(32), %mm2 add %edx, %ebx movd %mm2, %edx adc $(0), %edx addl (8)(%esp), %ebx movd (16)(%esi), %mm2 movd (20)(%esi), %mm3 adc $(0), %edx pmuludq %mm0, %mm1 pmuludq %mm0, %mm2 pmuludq %mm0, %mm3 movl %ecx, (%esp) sub %eax, %ebx mov $(0), %edi movl %ebx, (4)(%esp) adc $(0), %edi movd %mm1, %ecx psrlq $(32), %mm1 add %edx, %ecx movd %mm1, %edx adc $(0), %edx addl (12)(%esp), %ecx adc $(0), %edx movd %mm2, %ebx psrlq $(32), %mm2 add %edx, %ebx movd %mm2, %edx adc $(0), %edx addl (16)(%esp), %ebx adc $(0), %edx movd %mm3, %ebp psrlq $(32), %mm3 add %edx, %ebp movd %mm3, %edx adc $(0), %edx addl (20)(%esp), %ebp adc $(0), %edx sub %edi, %ecx movl %ecx, (8)(%esp) sbb $(0), %ebx movl %ebx, (12)(%esp) sbb $(0), %ebp movl %ebp, (16)(%esp) movd %mm7, %edi sbb $(0), %eax mov $(0), %ebx addl (24)(%esp), %edx adc $(0), %ebx add %eax, %edx adc $(0), %ebx movl %edx, (20)(%esp) movl %ebx, (24)(%esp) sub $(1), %edi movd (4)(%esi), %mm1 movd (8)(%esi), %mm2 jz .Lexit_mmul_loopgas_11 movl (36)(%esp), %ebp jmp .Lmmul_loopgas_11 .Lexit_mmul_loopgas_11: emms mov (28)(%esp), %edi lea (%esp), %esi lea p192r1_data, %ebx lea ((_prime192r1-p192r1_data))(%ebx), %ebx call h9_sub_192 movl (24)(%esp), %edx sub %eax, %edx cmove %edi, %esi movdqu (%esi), %xmm0 movq (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movq %xmm1, (16)(%edi) mov (40)(%esp), %esp pop %ebp pop %edi pop %esi pop %ebx pop %ebp ret .Lfe11: .size h9_p192r1_mul_mont_slm, .Lfe11-(h9_p192r1_mul_mont_slm) .p2align 5, 0x90 .globl h9_p192r1_sqr_mont_slm .type h9_p192r1_sqr_mont_slm, @function h9_p192r1_sqr_mont_slm: push %ebp mov %esp, %ebp push %esi push %edi movl (12)(%ebp), %esi movl (8)(%ebp), %edi push %esi push %esi push %edi call h9_p192r1_mul_mont_slm add $(12), %esp pop %edi pop %esi pop %ebp ret .Lfe12: .size h9_p192r1_sqr_mont_slm, .Lfe12-(h9_p192r1_sqr_mont_slm) .p2align 5, 0x90 .globl h9_p192r1_mred .type h9_p192r1_mred, @function h9_p192r1_mred: push %ebp mov %esp, %ebp push %ebx push %esi push %edi movl (12)(%ebp), %esi mov $(6), %ecx xor %edx, %edx .p2align 5, 0x90 .Lmred_loopgas_13: movl (%esi), %eax mov $(0), %ebx movl %ebx, (%esi) movl (4)(%esi), %ebx movl %ebx, (4)(%esi) movl (8)(%esi), %ebx sub %eax, %ebx movl %ebx, (8)(%esi) movl (12)(%esi), %ebx sbb $(0), %ebx movl %ebx, (12)(%esi) movl (16)(%esi), %ebx sbb $(0), %ebx movl %ebx, (16)(%esi) movl (20)(%esi), %ebx sbb $(0), %ebx movl %ebx, (20)(%esi) movl (24)(%esi), %ebx sbb $(0), %eax add %edx, %eax mov $(0), %edx adc $(0), %edx add %eax, %ebx movl %ebx, (24)(%esi) adc $(0), %edx lea (4)(%esi), %esi sub $(1), %ecx jnz .Lmred_loopgas_13 movl (8)(%ebp), %edi lea p192r1_data, %ebx lea ((_prime192r1-p192r1_data))(%ebx), %ebx call h9_sub_192 sub %eax, %edx cmove %edi, %esi movdqu (%esi), %xmm0 movq (16)(%esi), %xmm1 movdqu %xmm0, (%edi) movq %xmm1, (16)(%edi) pop %edi pop %esi pop %ebx pop %ebp ret .Lfe13: .size h9_p192r1_mred, .Lfe13-(h9_p192r1_mred) .p2align 5, 0x90 .globl h9_p192r1_select_pp_w5 .type h9_p192r1_select_pp_w5, @function h9_p192r1_select_pp_w5: push %ebp mov %esp, %ebp push %esi push %edi pxor %xmm0, %xmm0 movl (8)(%ebp), %edi movl (12)(%ebp), %esi movl (16)(%ebp), %eax movd %eax, %xmm7 pshufd $(0), %xmm7, %xmm7 mov $(1), %edx movd %edx, %xmm6 pshufd $(0), %xmm6, %xmm6 movdqa %xmm0, (%edi) movdqa %xmm0, (16)(%edi) movdqa %xmm0, (32)(%edi) movdqa %xmm0, (48)(%edi) movq %xmm0, (64)(%edi) movdqa %xmm6, %xmm5 mov $(16), %ecx .p2align 5, 0x90 .Lselect_loopgas_14: movdqa %xmm5, %xmm4 pcmpeqd %xmm7, %xmm4 movdqu (%esi), %xmm0 pand %xmm4, %xmm0 por (%edi), %xmm0 movdqa %xmm0, (%edi) movdqu (16)(%esi), %xmm1 pand %xmm4, %xmm1 por (16)(%edi), %xmm1 movdqa %xmm1, (16)(%edi) movdqu (32)(%esi), %xmm2 pand %xmm4, %xmm2 por (32)(%edi), %xmm2 movdqa %xmm2, (32)(%edi) movdqu (48)(%esi), %xmm3 pand %xmm4, %xmm3 por (48)(%edi), %xmm3 movdqa %xmm3, (48)(%edi) movq (64)(%esi), %xmm0 movq (64)(%edi), %xmm1 pand %xmm4, %xmm0 por %xmm1, %xmm0 movq %xmm0, (64)(%edi) paddd %xmm6, %xmm5 add $(72), %esi sub $(1), %ecx jnz .Lselect_loopgas_14 pop %edi pop %esi pop %ebp ret .Lfe14: .size h9_p192r1_select_pp_w5, .Lfe14-(h9_p192r1_select_pp_w5)
/** * @file AccumulatorProofOfKnowledge.cpp * * @brief AccumulatorProofOfKnowledge class for the Zerocoin library. * * @author Ian Miers, Christina Garman and Matthew Green * @date June 2013 * * @copyright Copyright 2013 Ian Miers, Christina Garman and Matthew Green * @license This project is released under the MIT license. **/ // Copyright (c) 2017 The Brewhaust developers #include "AccumulatorProofOfKnowledge.h" #include "hash.h" namespace libzerocoin { AccumulatorProofOfKnowledge::AccumulatorProofOfKnowledge(const AccumulatorAndProofParams* p): params(p) {} AccumulatorProofOfKnowledge::AccumulatorProofOfKnowledge(const AccumulatorAndProofParams* p, const Commitment& commitmentToCoin, const AccumulatorWitness& witness, Accumulator& a): params(p) { CBigNum sg = params->accumulatorPoKCommitmentGroup.g; CBigNum sh = params->accumulatorPoKCommitmentGroup.h; CBigNum g_n = params->accumulatorQRNCommitmentGroup.g; CBigNum h_n = params->accumulatorQRNCommitmentGroup.h; CBigNum e = commitmentToCoin.getContents(); CBigNum r = commitmentToCoin.getRandomness(); CBigNum aM_4 = params->accumulatorModulus/CBigNum((long)4); CBigNum r_1 = CBigNum::randBignum(params->accumulatorModulus/4); CBigNum r_2 = CBigNum::randBignum(params->accumulatorModulus/4); CBigNum r_3 = CBigNum::randBignum(params->accumulatorModulus/4); this->C_e = g_n.pow_mod(e, params->accumulatorModulus) * h_n.pow_mod(r_1, params->accumulatorModulus); this->C_u = witness.getValue() * h_n.pow_mod(r_2, params->accumulatorModulus); this->C_r = g_n.pow_mod(r_2, params->accumulatorModulus) * h_n.pow_mod(r_3, params->accumulatorModulus); CBigNum r_alpha = CBigNum::randBignum(params->maxCoinValue * CBigNum(2).pow(params->k_prime + params->k_dprime)); if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { r_alpha = 0-r_alpha; } CBigNum r_gamma = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus); CBigNum r_phi = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus); CBigNum r_psi = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus); CBigNum r_sigma = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus); CBigNum r_xi = CBigNum::randBignum(params->accumulatorPoKCommitmentGroup.modulus); CBigNum r_epsilon = CBigNum::randBignum((params->accumulatorModulus/4) * CBigNum(2).pow(params->k_prime + params->k_dprime)); if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { r_epsilon = 0-r_epsilon; } CBigNum r_eta = CBigNum::randBignum((params->accumulatorModulus/4) * CBigNum(2).pow(params->k_prime + params->k_dprime)); if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { r_eta = 0-r_eta; } CBigNum r_zeta = CBigNum::randBignum((params->accumulatorModulus/4) * CBigNum(2).pow(params->k_prime + params->k_dprime)); if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { r_zeta = 0-r_zeta; } CBigNum r_beta = CBigNum::randBignum((params->accumulatorModulus/4) * params->accumulatorPoKCommitmentGroup.modulus * CBigNum(2).pow(params->k_prime + params->k_dprime)); if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { r_beta = 0-r_beta; } CBigNum r_delta = CBigNum::randBignum((params->accumulatorModulus/4) * params->accumulatorPoKCommitmentGroup.modulus * CBigNum(2).pow(params->k_prime + params->k_dprime)); if(!(CBigNum::randBignum(CBigNum(3)) % 2)) { r_delta = 0-r_delta; } this->st_1 = (sg.pow_mod(r_alpha, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(r_phi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; this->st_2 = (((commitmentToCoin.getCommitmentValue() * sg.inverse(params->accumulatorPoKCommitmentGroup.modulus)).pow_mod(r_gamma, params->accumulatorPoKCommitmentGroup.modulus)) * sh.pow_mod(r_psi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; this->st_3 = ((sg * commitmentToCoin.getCommitmentValue()).pow_mod(r_sigma, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(r_xi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; this->t_1 = (h_n.pow_mod(r_zeta, params->accumulatorModulus) * g_n.pow_mod(r_epsilon, params->accumulatorModulus)) % params->accumulatorModulus; this->t_2 = (h_n.pow_mod(r_eta, params->accumulatorModulus) * g_n.pow_mod(r_alpha, params->accumulatorModulus)) % params->accumulatorModulus; this->t_3 = (C_u.pow_mod(r_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(r_beta, params->accumulatorModulus))) % params->accumulatorModulus; this->t_4 = (C_r.pow_mod(r_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(r_delta, params->accumulatorModulus)) * ((g_n.inverse(params->accumulatorModulus)).pow_mod(r_beta, params->accumulatorModulus))) % params->accumulatorModulus; CHashWriter hasher(0,0); hasher << *params << sg << sh << g_n << h_n << commitmentToCoin.getCommitmentValue() << C_e << C_u << C_r << st_1 << st_2 << st_3 << t_1 << t_2 << t_3 << t_4; //According to the proof, this hash should be of length k_prime bits. It is currently greater than that, which should not be a problem, but we should check this. CBigNum c = CBigNum(hasher.GetHash()); this->s_alpha = r_alpha - c*e; this->s_beta = r_beta - c*r_2*e; this->s_zeta = r_zeta - c*r_3; this->s_sigma = r_sigma - c*((e+1).inverse(params->accumulatorPoKCommitmentGroup.groupOrder)); this->s_eta = r_eta - c*r_1; this->s_epsilon = r_epsilon - c*r_2; this->s_delta = r_delta - c*r_3*e; this->s_xi = r_xi + c*r*((e+1).inverse(params->accumulatorPoKCommitmentGroup.groupOrder)); this->s_phi = (r_phi - c*r) % params->accumulatorPoKCommitmentGroup.groupOrder; this->s_gamma = r_gamma - c*((e-1).inverse(params->accumulatorPoKCommitmentGroup.groupOrder)); this->s_psi = r_psi + c*r*((e-1).inverse(params->accumulatorPoKCommitmentGroup.groupOrder)); } /** Verifies that a commitment c is accumulated in accumulator a */ bool AccumulatorProofOfKnowledge:: Verify(const Accumulator& a, const CBigNum& valueOfCommitmentToCoin) const { CBigNum sg = params->accumulatorPoKCommitmentGroup.g; CBigNum sh = params->accumulatorPoKCommitmentGroup.h; CBigNum g_n = params->accumulatorQRNCommitmentGroup.g; CBigNum h_n = params->accumulatorQRNCommitmentGroup.h; //According to the proof, this hash should be of length k_prime bits. It is currently greater than that, which should not be a problem, but we should check this. CHashWriter hasher(0,0); hasher << *params << sg << sh << g_n << h_n << valueOfCommitmentToCoin << C_e << C_u << C_r << st_1 << st_2 << st_3 << t_1 << t_2 << t_3 << t_4; CBigNum c = CBigNum(hasher.GetHash()); //this hash should be of length k_prime bits CBigNum st_1_prime = (valueOfCommitmentToCoin.pow_mod(c, params->accumulatorPoKCommitmentGroup.modulus) * sg.pow_mod(s_alpha, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(s_phi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; CBigNum st_2_prime = (sg.pow_mod(c, params->accumulatorPoKCommitmentGroup.modulus) * ((valueOfCommitmentToCoin * sg.inverse(params->accumulatorPoKCommitmentGroup.modulus)).pow_mod(s_gamma, params->accumulatorPoKCommitmentGroup.modulus)) * sh.pow_mod(s_psi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; CBigNum st_3_prime = (sg.pow_mod(c, params->accumulatorPoKCommitmentGroup.modulus) * (sg * valueOfCommitmentToCoin).pow_mod(s_sigma, params->accumulatorPoKCommitmentGroup.modulus) * sh.pow_mod(s_xi, params->accumulatorPoKCommitmentGroup.modulus)) % params->accumulatorPoKCommitmentGroup.modulus; CBigNum t_1_prime = (C_r.pow_mod(c, params->accumulatorModulus) * h_n.pow_mod(s_zeta, params->accumulatorModulus) * g_n.pow_mod(s_epsilon, params->accumulatorModulus)) % params->accumulatorModulus; CBigNum t_2_prime = (C_e.pow_mod(c, params->accumulatorModulus) * h_n.pow_mod(s_eta, params->accumulatorModulus) * g_n.pow_mod(s_alpha, params->accumulatorModulus)) % params->accumulatorModulus; CBigNum t_3_prime = ((a.getValue()).pow_mod(c, params->accumulatorModulus) * C_u.pow_mod(s_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(s_beta, params->accumulatorModulus))) % params->accumulatorModulus; CBigNum t_4_prime = (C_r.pow_mod(s_alpha, params->accumulatorModulus) * ((h_n.inverse(params->accumulatorModulus)).pow_mod(s_delta, params->accumulatorModulus)) * ((g_n.inverse(params->accumulatorModulus)).pow_mod(s_beta, params->accumulatorModulus))) % params->accumulatorModulus; bool result = false; bool result_st1 = (st_1 == st_1_prime); bool result_st2 = (st_2 == st_2_prime); bool result_st3 = (st_3 == st_3_prime); bool result_t1 = (t_1 == t_1_prime); bool result_t2 = (t_2 == t_2_prime); bool result_t3 = (t_3 == t_3_prime); bool result_t4 = (t_4 == t_4_prime); bool result_range = ((s_alpha >= -(params->maxCoinValue * CBigNum(2).pow(params->k_prime + params->k_dprime + 1))) && (s_alpha <= (params->maxCoinValue * CBigNum(2).pow(params->k_prime + params->k_dprime + 1)))); result = result_st1 && result_st2 && result_st3 && result_t1 && result_t2 && result_t3 && result_t4 && result_range; return result; } } /* namespace libzerocoin */
;nasm 2.11.08 section .data hello: db 'Hello world!',10 ; 'Hello world!' plus a linefeed character helloLen: equ $-hello ; Length of the 'Hello world!' string section .bss var1: resb 4 section .text global _start _start: mov esp, 65 mov [var1], esp mov eax,4 ; The system call for write (sys_write) mov ebx,1 ; File descriptor 1 - standard output mov ecx,var1 ; Put the offset of hello in ecx mov edx,1 ; helloLen is a constant, so we don't need to say ; mov edx,[helloLen] to get it's actual value int 80h ; Call the kernel mov eax,1 ; The system call for exit (sys_exit) mov ebx,0 ; Exit with return code of 0 (no error) int 80h;
// Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2015 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 "amount.h" #include "tinyformat.h" const std::string CURRENCY_UNIT = "XSB"; CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nBytes_) { assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max())); int64_t nSize = int64_t(nBytes_); if (nSize > 0) nSatoshisPerK = nFeePaid * 1000 / nSize; else nSatoshisPerK = 0; } CAmount CFeeRate::GetFee(size_t nBytes_) const { assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max())); int64_t nSize = int64_t(nBytes_); CAmount nFee = nSatoshisPerK * nSize / 1000; if (nFee == 0 && nSize != 0) { if (nSatoshisPerK > 0) nFee = CAmount(1); if (nSatoshisPerK < 0) nFee = CAmount(-1); } return nFee; } std::string CFeeRate::ToString() const { return strprintf("%d.%08d %s/kB", nSatoshisPerK / COIN, nSatoshisPerK % COIN, CURRENCY_UNIT); }
; A242181: Numbers with four X's in Roman numerals. ; 39,89,139,189,239,289,339,389,439,489,539,589,639,689,739,789,839,889,939,989,1039,1089,1139,1189,1239,1289,1339,1389,1439,1489,1539,1589,1639,1689,1739,1789,1839,1889,1939,1989,2039,2089,2139,2189,2239,2289,2339 mul $0,50 add $0,39
; A154519: a(n) = 216*n + 12. ; 228,444,660,876,1092,1308,1524,1740,1956,2172,2388,2604,2820,3036,3252,3468,3684,3900,4116,4332,4548,4764,4980,5196,5412,5628,5844,6060,6276,6492,6708,6924,7140,7356,7572,7788,8004,8220,8436,8652,8868,9084,9300,9516,9732,9948,10164,10380,10596,10812,11028,11244,11460,11676,11892,12108,12324,12540,12756,12972,13188,13404,13620,13836,14052,14268,14484,14700,14916,15132,15348,15564,15780,15996,16212,16428,16644,16860,17076,17292,17508,17724,17940,18156,18372,18588,18804,19020,19236,19452,19668,19884,20100,20316,20532,20748,20964,21180,21396,21612,21828,22044,22260,22476,22692,22908,23124,23340,23556,23772,23988,24204,24420,24636,24852,25068,25284,25500,25716,25932,26148,26364,26580,26796,27012,27228,27444,27660,27876,28092,28308,28524,28740,28956,29172,29388,29604,29820,30036,30252,30468,30684,30900,31116,31332,31548,31764,31980,32196,32412,32628,32844,33060,33276,33492,33708,33924,34140,34356,34572,34788,35004,35220,35436,35652,35868,36084,36300,36516,36732,36948,37164,37380,37596,37812,38028,38244,38460,38676,38892,39108,39324,39540,39756,39972,40188,40404,40620,40836,41052,41268,41484,41700,41916,42132,42348,42564,42780,42996,43212,43428,43644,43860,44076,44292,44508,44724,44940,45156,45372,45588,45804,46020,46236,46452,46668,46884,47100,47316,47532,47748,47964,48180,48396,48612,48828,49044,49260,49476,49692,49908,50124,50340,50556,50772,50988,51204,51420,51636,51852,52068,52284,52500,52716,52932,53148,53364,53580,53796,54012 mov $1,$0 mul $1,216 add $1,228
/* * example6: instruction examples */ /* no-operation instruction */ nop # no-operation /* move instructions */ mov r1, 0x403 # r1 = 0x403 mov r2, 0x101 mov r3, 0 mov r4, 2 mov r5, 27 mov r0, r1 # r0 = r1 mov r0, pc # r0 = pc /* arithmetic operation instructions */ add r0, r1, r2 # r0 = r1 + r2 sub r0, r1, r2 # r0 = r1 - r2 cmp r0, r1 # flag = compare(r0, r1) abs r0, r1 # r0 = abs(r1) ash r0, r2, r4 # r0 = r2 << r4 // arithmetic mul r0, r1, r4 # r0 = r1 * r4 div r0, r1, r4 # r0 = r1 / r4 /* logical operation instructions */ and r0, r1, r2 # r0 = r1 & r2 or r0, r1, r2 # r0 = r1 | r2 not r0, r1 # r0 = ~r1 xor r0, r1, r2 # r0 = r1 ^ r2 lsh r0, r2, r4 # r0 = r2 << r4 // logical /* memory access instructions */ st m(r3), r1 # *r3 = r1 ld r0, m(r3) # r0 = *r3 /* control flow instructions */ b eq, 1 # if (flag == eq) goto pc+1 jmp 1 # goto pc+1 jmp r5 # goto r5 call r1 # goto r1; r0 = pc ret # goto r0 /* machine halt instruction */ halt # halt cpu
CGROUP group code code segment dword 'CODE' assume cs:CGROUP,ds:CGROUP ;pj_stuff_words(USHORT data, USHORT *buf, unsigned count) ;careful about passing a zero count. It will be interpreted as 4 Gigawords. public pj_stuff_words pj_stuff_words proc near push edi push ecx mov edi,[esp+16] ;buf mov eax,[esp+12] ;value to poke mov ecx,[esp+20] ;count rep stosw pop ecx pop edi ret pj_stuff_words endp code ends end
; ************************************************************************************************ ; ************************************************************************************************ ; ; Name: search.asm ; Purpose: Search for token in the token tables ; Created: 8th March 2021 ; Reviewed: 16th March 2021 ; Author: Paul Robson (paul@robsons.org.uk) ; ; ************************************************************************************************ ; ************************************************************************************************ .section storage currentSet: ; token set being searched (0-3) .fill 1 .send storage .section code ; ************************************************************************************************ ; ; Find token in convertBuffer (length prefix string), if found compile it and ; return CS, else return CC ; ; ************************************************************************************************ TokenSearch: .pshx .pshy lda #0 sta currentSet _TSLoop: lda currentSet ; 2 x currentset in X asl a tax ; lda TokenTableAddress,x ; set temp0 to the table address sta temp0 lda TokenTableAddress+1,x sta temp0+1 ; jsr TokenSearchOne ; search one table bcs _TSFound ; found a token. ; inc currentSet ; next set lda currentSet cmp #4 bne _TSLoop ; back if not done all four. clc ; clear carry and exit bcc _TSExit ; _TSFound: pha ; save token lda currentSet ; if set zero no shift beq _TSNoShift ora #$80 ; Write as $81-$83 jsr TokenWrite _TSNoShift: pla ; get token back jsr TokenWrite ; write it sec ; carry set indicating success _TSExit: .puly .pulx rts ; ************************************************************************************************ ; ; Search token list at temp0 for the token in convertBuffer. If found return CS and ; token# in A. ; ; ************************************************************************************************ TokenSearchOne: ldx #$86 ; current token being tested. _TSOLoop: ldy #0 lda (temp0),y ; get length of token beq _TSOFail ; if zero, end of table cmp convertBuffer ; length is the same, compare the text matches. beq _TSOCheckText ; _TSONext: ; go to next inx ; bump token ldy #0 ; get length lda (temp0),y sec adc temp0 ; add to temp0 + 1 sta temp0 bcc _TSOLoop inc temp0+1 jmp _TSOLoop ; ; Check if the token at temp0 and the token in the convertBuffer match. ; _TSOCheckText: tay ; compare length downto 1. _TSOCheckLoop: lda (temp0),y ; use EOR to compare eor convertBuffer,y and #$7F ; ignore bit 7 bne _TSONext ; different goto next. dey ; do all bne _TSOCheckLoop ; txa ; return token in A and carry set sec rts _TSOFail: clc rts .send code
; A338206: Inverse of A160016. ; 0,2,1,6,3,10,4,14,5,18,7,22,8,26,9,30,11,34,12,38,13,42,15,46,16,50,17,54,19,58,20,62,21,66,23,70,24,74,25,78,27,82,28,86,29,90,31,94,32,98,33,102,35,106,36,110,37,114,39,118,40,122,41,126,43,130,44,134,45,138,47,142,48,146,49,150,51,154,52,158 mov $1,$0 mod $0,2 sub $0,1 mul $1,2 lpb $0,1 mul $0,$2 add $3,1 add $1,$3 div $1,3 lpe
/*************************************************************************************************************************** * landpad_det.cpp * Author: Jario * Update Time: 2020.1.12 * * 说明: 降落目标识别程序,降落板的尺寸为60cmX60cm * 1. 【订阅】图像话题 (默认来自web_cam) * /prometheus/camera/rgb/image_raw * 2. 【发布】目标位置,发布话题见 Prometheus/Modules/msgs/msg/DetectionInfo.msg * /prometheus/object_detection/landpad_det * 3. 【发布】检测结果的可视化图像话题 * /prometheus/camera/rgb/image_landpad_det ***************************************************************************************************************************/ #include <time.h> #include <fstream> #include <iostream> #include <math.h> #include <pthread.h> #include <thread> #include <chrono> #include <numeric> #include <boost/thread/mutex.hpp> #include <boost/thread/shared_mutex.hpp> #include <eigen3/Eigen/Core> #include <eigen3/Eigen/Geometry> // ros头文件 #include <ros/ros.h> #include <yaml-cpp/yaml.h> #include <ros/package.h> #include <image_transport/image_transport.h> #include <cv_bridge/cv_bridge.h> #include <tf/transform_datatypes.h> #include <tf/transform_broadcaster.h> // opencv头文件 #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/aruco.hpp> #include <opencv2/aruco/dictionary.hpp> #include <opencv2/aruco/charuco.hpp> #include <opencv2/calib3d.hpp> #include <opencv2/core/eigen.hpp> // topic 头文件 #include <geometry_msgs/Point.h> #include <geometry_msgs/PoseStamped.h> #include <geometry_msgs/Pose.h> #include <std_msgs/Bool.h> #include <prometheus_msgs/DetectionInfo.h> #include <prometheus_msgs/Message.h> #include "message_utils.h" using namespace std; using namespace cv; double threshold_error=0.4; //---------------------------variables--------------------------------------- //------------ROS TOPIC--------- //【订阅】无人机位置 ros::Subscriber drone_pose_sub; //【订阅】小车位置 ros::Subscriber vehicle_pose_sub; //【订阅】输入图像 image_transport::Subscriber image_subscriber; //【订阅】输入开关量 ros::Subscriber switch_subscriber; //【发布】无人机和小车相对位置 ros::Publisher position_pub; //【发布】识别后的图像 image_transport::Publisher landpad_pub; //【发布】调试消息 ros::Publisher message_pub; std::string msg_node_name; //-------------VISION----------- Mat img; prometheus_msgs::DetectionInfo pose_now; //-------------TIME------------- ros::Time begin_time; float photo_time; double calculation_time; // 相机话题中的图像同步相关变量 int frame_width, frame_height; std_msgs::Header image_header; cv::Mat cam_image_copy; boost::shared_mutex mutex_image_callback; bool image_status = false; boost::shared_mutex mutex_image_status; // 无人机位姿message geometry_msgs::Pose pos_drone_optitrack; Eigen::Vector3d euler_drone_optitrack; Eigen::Quaterniond q_drone; // 小车位姿message geometry_msgs::Pose pos_vehicle_optitrack; Eigen::Vector3d euler_vehicle_optitrack; Eigen::Quaterniond q_vehicle; // 保存的上次观测的位置 用于cluster算法使用 Eigen::Vector3d last_position; bool bool_last_position = false; // 接收消息,允许暂停检测 bool is_suspanded = false; bool local_print = false; bool message_print = true; void printf_result(); //-----------------利用Euler角进行三次旋转得到无人机相对目标的位置------------------ void CodeRotateByZ(double x, double y, double thetaz, double& outx, double& outy) { double x1 = x; // 将变量拷贝一次,保证&x == &outx这种情况下也能计算正确 double y1 = y; double rz = thetaz * CV_PI / 180; outx = cos(rz) * x1 - sin(rz) * y1; outy = sin(rz) * x1 + cos(rz) * y1; } void CodeRotateByY(double x, double z, double thetay, double& outx, double& outz) { double x1 = x; double z1 = z; double ry = thetay * CV_PI / 180; outx = cos(ry) * x1 + sin(ry) * z1; outz = cos(ry) * z1 - sin(ry) * x1; } void CodeRotateByX(double y, double z, double thetax, double& outy, double& outz) { double y1 = y; // 将变量拷贝一次,保证&y == &y这种情况下也能计算正确 double z1 = z; double rx = thetax * CV_PI / 180; outy = cos(rx) * y1 - sin(rx) * z1; outz = cos(rx) * z1 + sin(rx) * y1; } // 四元数转Euler // q0 q1 q2 q3 // w x y z void quaternion_2_euler(Eigen::Quaterniond quat, Eigen::Vector3d &angle) { angle(0) = atan2(2.0 * (quat.z() * quat.y() + quat.w() * quat.x()), 1.0 - 2.0 * (quat.x() * quat.x() + quat.y() * quat.y())); angle(1) = asin(2.0 * (quat.y() * quat.w() - quat.z() * quat.x())); // angle[2] = atan2(2.0 * (quat[3] * quat[0] + quat[1] * quat[2]), -1.0 + 2.0 * (quat[0] * quat[0] + quat[1] * quat[1])); angle(2) = atan2(2.0 * (quat.z() * quat.w() + quat.x() * quat.y()), 1.0 - 2.0 * (quat.y() * quat.y() + quat.z() * quat.z())); } //--------------------------利用optitrack获取真值------------------------------- // 获取系统时间 float get_dt(ros::Time last) { ros::Time time_now = ros::Time::now(); float currTimeSec = time_now.sec-last.sec; float currTimenSec = time_now.nsec / 1e9 - last.nsec / 1e9; return (currTimeSec + currTimenSec); } // 图像接收回调函数,接收web_cam的话题,并将图像保存在cam_image_copy中 void cameraCallback(const sensor_msgs::ImageConstPtr& msg) { if (local_print) ROS_DEBUG("[LandpadDetector] USB image received."); cv_bridge::CvImagePtr cam_image; try { cam_image = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8); image_header = msg->header; } catch (cv_bridge::Exception& e) { if (local_print) ROS_ERROR("cv_bridge exception: %s", e.what()); if (message_print) pub_message(message_pub, prometheus_msgs::Message::ERROR, msg_node_name, "cv_bridge exception"); return; } if (cam_image) { { boost::unique_lock<boost::shared_mutex> lockImageCallback(mutex_image_callback); cam_image_copy = cam_image->image.clone(); } { boost::unique_lock<boost::shared_mutex> lockImageStatus(mutex_image_status); image_status = true; } frame_width = cam_image->image.size().width; frame_height = cam_image->image.size().height; } return; } // 用此函数查看是否收到图像话题 bool getImageStatus(void) { boost::shared_lock<boost::shared_mutex> lock(mutex_image_status); return image_status; } void switchCallback(const std_msgs::Bool::ConstPtr& msg) { is_suspanded = !(bool)msg->data; // cout << is_suspanded << endl; } int main(int argc, char **argv) { ros::init(argc, argv, "landpad_det"); ros::NodeHandle nh("~"); image_transport::ImageTransport it(nh); // 发布调试消息 msg_node_name = "/prometheus/message/landpad_det"; message_pub = nh.advertise<prometheus_msgs::Message>(msg_node_name, 10); std::string camera_topic, camera_info; if (nh.getParam("camera_topic", camera_topic)) { if (local_print) ROS_INFO("camera_topic is %s", camera_topic.c_str()); if (message_print) pub_message(message_pub, prometheus_msgs::Message::NORMAL, msg_node_name, "camera_topic is" + camera_topic); } else { if (local_print) ROS_WARN("didn't find parameter camera_topic"); if (message_print) pub_message(message_pub, prometheus_msgs::Message::WARN, msg_node_name, "didn't find parameter camera_topic"); camera_topic = "/prometheus/camera/rgb/image_raw"; } if (nh.getParam("camera_info", camera_info)) { if (local_print) ROS_INFO("camera_info is %s", camera_info.c_str()); if (message_print) pub_message(message_pub, prometheus_msgs::Message::NORMAL, msg_node_name, "camera_info is" + camera_info); } else { if (local_print) ROS_WARN("didn't find parameter camera_info"); if (message_print) pub_message(message_pub, prometheus_msgs::Message::WARN, msg_node_name, "didn't find parameter camera_info"); camera_info = "camera_param.yaml"; } position_pub = nh.advertise<prometheus_msgs::DetectionInfo>("/prometheus/object_detection/landpad_det", 10); // 接收开关话题 switch_subscriber = nh.subscribe("/prometheus/switch/landpad_det", 10, switchCallback); // 接收图像的话题 image_subscriber = it.subscribe(camera_topic.c_str(), 1, cameraCallback); // 发布ArUco检测结果的话题 landpad_pub = it.advertise("/prometheus/camera/rgb/image_landpad_det", 1); sensor_msgs::ImagePtr msg_ellipse; std::string ros_path = ros::package::getPath("prometheus_detection"); if (local_print) cout << "DETECTION_PATH: " << ros_path << endl; if (message_print) pub_message(message_pub, prometheus_msgs::Message::NORMAL, msg_node_name, "DETECTION_PATH: " + ros_path); // 读取参数文档camera_param.yaml中的参数值; YAML::Node camera_config = YAML::LoadFile(camera_info); // 相机内部参数 double fx = camera_config["fx"].as<double>(); double fy = camera_config["fy"].as<double>(); double cx = camera_config["x0"].as<double>(); double cy = camera_config["y0"].as<double>(); // 相机畸变系数 double k1 = camera_config["k1"].as<double>(); double k2 = camera_config["k2"].as<double>(); double p1 = camera_config["p1"].as<double>(); double p2 = camera_config["p2"].as<double>(); double k3 = camera_config["k3"].as<double>(); double landpad_det_len = camera_config["landpad_det_len"].as<double>(); // DEBUG // cout << fx << " " << fy << " " << cx << " " << cy << " " << k1 << " " << k2 << " "; //--------------------------相机参数赋值--------------------- // 相机内参 Mat camera_matrix; camera_matrix = cv::Mat(3,3,CV_64FC1,cv::Scalar::all(0)); camera_matrix.ptr<double>(0)[0] = fx; camera_matrix.ptr<double>(0)[2] = cx; camera_matrix.ptr<double>(1)[1] = fy; camera_matrix.ptr<double>(1)[2] = cy; camera_matrix.ptr<double>(2)[2] = 1.0f; // 相机畸变参数k1 k2 p1 p2 k3 Mat distortion_coefficients; distortion_coefficients = cv::Mat(5,1,CV_64FC1,cv::Scalar::all(0)); distortion_coefficients.ptr<double>(0)[0] = k1; distortion_coefficients.ptr<double>(1)[0] = k2; distortion_coefficients.ptr<double>(2)[0] = p1; distortion_coefficients.ptr<double>(3)[0] = p2; distortion_coefficients.ptr<double>(4)[0] = k3; // ArUco Marker字典选择以及旋转向量和评议向量初始化 Ptr<cv::aruco::Dictionary> dictionary = cv::aruco::getPredefinedDictionary(10); vector<double> rv(3), tv(3); cv::Mat rvec(rv), tvec(tv); // cv::VideoCapture capture(0); float last_x(0), last_y(0), last_z(0), last_yaw(0), last_az(0), last_ay(0), last_ax(0), last_qx(0), last_qy(0), last_qz(0), last_qw(0); bool switch_state = is_suspanded; // 节点运行频率: 20hz 【视觉端解算频率大概为20HZ】 ros::Rate loopRate(20); ros::Rate loopRate_1Hz(1); //----------------------------------------主循环------------------------------------ // const auto wait_duration = std::chrono::milliseconds(2000); while (ros::ok()) { while (!getImageStatus() && ros::ok()) { if (local_print) cout << "Waiting for image." << endl; if (message_print) pub_message(message_pub, prometheus_msgs::Message::NORMAL, msg_node_name, "Waiting for image."); // std::this_thread::sleep_for(wait_duration); ros::spinOnce(); loopRate_1Hz.sleep(); } if (switch_state != is_suspanded) { switch_state = is_suspanded; if (!is_suspanded) { if (local_print) cout << "Start Detection." << endl; if (message_print) pub_message(message_pub, prometheus_msgs::Message::NORMAL, msg_node_name, "Start Detection."); } else { if (local_print) cout << "Stop Detection." << endl; if (message_print) pub_message(message_pub, prometheus_msgs::Message::NORMAL, msg_node_name, "Stop Detection."); } } if (!is_suspanded) { { boost::unique_lock<boost::shared_mutex> lockImageCallback(mutex_image_callback); img = cam_image_copy.clone(); } clock_t start = clock(); //------------------调用ArUco Marker库对图像进行识别-------------- // markerids存储每个识别到二维码的编号 markerCorners每个二维码对应的四个角点的像素坐标 std::vector<int> markerids, markerids_deted; vector<vector<Point2f> > markerCorners, markerCorners_deted, rejectedCandidate; Ptr<cv::aruco::DetectorParameters> parameters = cv::aruco::DetectorParameters::create(); cv::aruco::detectMarkers(img, dictionary, markerCorners_deted, markerids_deted, parameters, rejectedCandidate); if (markerids_deted.size() > 0) { for (int tt=0; tt<markerids_deted.size(); tt++) { if (19 == markerids_deted[tt]) { markerids.push_back(markerids_deted[tt]); markerCorners.push_back(markerCorners_deted[tt]); } } if (markerids.size() == 0) { for (int tt=0; tt<markerids_deted.size(); tt++) { if (43 == markerids_deted[tt]) { markerids.push_back(markerids_deted[tt]); markerCorners.push_back(markerCorners_deted[tt]); } } } if (markerids.size() == 0) { for (int tt=0; tt<markerids_deted.size(); tt++) { if (1 == markerids_deted[tt]) { markerids.push_back(markerids_deted[tt]); markerCorners.push_back(markerCorners_deted[tt]); } } } if (markerids.size() == 0) { for (int tt=0; tt<markerids_deted.size(); tt++) { if (2 == markerids_deted[tt]) { markerids.push_back(markerids_deted[tt]); markerCorners.push_back(markerCorners_deted[tt]); } } } if (markerids.size() == 0) { for (int tt=0; tt<markerids_deted.size(); tt++) { if (3 == markerids_deted[tt]) { markerids.push_back(markerids_deted[tt]); markerCorners.push_back(markerCorners_deted[tt]); } } } if (markerids.size() == 0) { for (int tt=0; tt<markerids_deted.size(); tt++) { if (4 == markerids_deted[tt]) { markerids.push_back(markerids_deted[tt]); markerCorners.push_back(markerCorners_deted[tt]); } } } } //-------------------多于一个目标被识别到,进入算法----------------- if (markerids.size() > 0) { aruco::drawDetectedMarkers(img, markerCorners, markerids); std::vector<float> collected_tx, collected_ty, collected_tz; std::vector<float> collected_qx, collected_qy, collected_qz, collected_qw; int tt=0; vector< Vec3d > rvecs, tvecs; if (19 == markerids[tt]) { vector<vector<Point2f> > markerCornersONE; markerCornersONE.push_back(markerCorners[tt]); aruco::estimatePoseSingleMarkers(markerCornersONE, landpad_det_len*0.666667, camera_matrix, distortion_coefficients, rvecs, tvecs); aruco::drawAxis(img, camera_matrix, distortion_coefficients, rvecs[0], tvecs[0],landpad_det_len*0.666667*0.5f); } else if (43 == markerids[tt]) { vector<vector<Point2f> > markerCornersONE; markerCornersONE.push_back(markerCorners[tt]); aruco::estimatePoseSingleMarkers(markerCornersONE, landpad_det_len*0.066667, camera_matrix, distortion_coefficients, rvecs, tvecs); aruco::drawAxis(img, camera_matrix, distortion_coefficients, rvecs[0], tvecs[0],landpad_det_len*0.066667*0.5f); } else if (1 == markerids[tt] || 2 == markerids[tt] || 3 == markerids[tt] || 4 == markerids[tt]) { vector<vector<Point2f> > markerCornersONE; markerCornersONE.push_back(markerCorners[tt]); aruco::estimatePoseSingleMarkers(markerCornersONE, landpad_det_len*0.133334, camera_matrix, distortion_coefficients, rvecs, tvecs); aruco::drawAxis(img, camera_matrix, distortion_coefficients, rvecs[0], tvecs[0],landpad_det_len*0.133334*0.5f); } cv::Mat rotation_matrix; cv::Rodrigues(rvecs[0], rotation_matrix); Eigen::Matrix3d rotation_matrix_eigen; cv::cv2eigen(rotation_matrix, rotation_matrix_eigen); Eigen::Quaterniond q = Eigen::Quaterniond(rotation_matrix_eigen); q.normalize(); /*if (43 != markerids[tt] && 19 != markerids[tt]) { static tf::TransformBroadcaster br; tf::Transform world2camera = tf::Transform(tf::Quaternion(q.x(), q.y(), q.z(), q.w()), tf::Vector3(tvecs[0][0], tvecs[0][1], tvecs[0][2])); char obj_str[16]; sprintf(obj_str, "object-%d", markerids[tt]); tf::StampedTransform trans_world2camera = tf::StampedTransform(world2camera, ros::Time(), "camera", obj_str); br.sendTransform(trans_world2camera); }*/ std::vector<double> vec_t{tvecs[0][0], tvecs[0][1], tvecs[0][2]}; cv::Mat vec_t_mat{vec_t}; vec_t_mat = vec_t_mat; vec_t_mat.convertTo(vec_t_mat, CV_32FC1); // cout << "vec_t_mat.size():" << vec_t_mat.size() << endl; // cout << "vec_t_mat.type():" << vec_t_mat.type() <<endl; std::vector<double> id_to8_t(3); if (19 == markerids[tt] || 43 == markerids[tt]) { id_to8_t[0] = 0.; id_to8_t[1] = 0.; id_to8_t[2] = 0.; } else if (1 == markerids[tt]) { id_to8_t[0] = -(landpad_det_len*0.666667 + landpad_det_len*0.133334) / 2.; id_to8_t[1] = (landpad_det_len*0.666667 + landpad_det_len*0.133334) / 2.; id_to8_t[2] = 0.; } else if (2 == markerids[tt]) { id_to8_t[0] = -(landpad_det_len*0.666667 + landpad_det_len*0.133334) / 2.; id_to8_t[1] = -(landpad_det_len*0.666667 + landpad_det_len*0.133334) / 2.; id_to8_t[2] = 0.; } else if (3 == markerids[tt]) { id_to8_t[0] = (landpad_det_len*0.666667 + landpad_det_len*0.133334) / 2.; id_to8_t[1] = -(landpad_det_len*0.666667 + landpad_det_len*0.133334) / 2.; id_to8_t[2] = 0.; } else if (4 == markerids[tt]) { id_to8_t[0] = (landpad_det_len*0.666667 + landpad_det_len*0.133334) / 2.; id_to8_t[1] = (landpad_det_len*0.666667 + landpad_det_len*0.133334) / 2.; id_to8_t[2] = 0.; } cv::Mat id_to8_t_mat{id_to8_t}; id_to8_t_mat.convertTo(id_to8_t_mat, CV_32FC1); rotation_matrix.convertTo(rotation_matrix, CV_32FC1); // cv::invert(rotation_matrix, rotation_matrix); cv::Mat id_8_t = rotation_matrix * id_to8_t_mat + vec_t_mat; // cout << id_8_t << endl; float o_tx = id_8_t.at<float>(0); float o_ty = id_8_t.at<float>(1); float o_tz = id_8_t.at<float>(2); float o_qx = q.x(); float o_qy = q.y(); float o_qz = q.z(); float o_qw = q.w(); // 将解算的位置转化成旋转矩阵 并旋转计算无人机相对于目标的位置 float r11 = rotation_matrix.ptr<float>(0)[0]; float r12 = rotation_matrix.ptr<float>(0)[1]; float r13 = rotation_matrix.ptr<float>(0)[2]; float r21 = rotation_matrix.ptr<float>(1)[0]; float r22 = rotation_matrix.ptr<float>(1)[1]; float r23 = rotation_matrix.ptr<float>(1)[2]; float r31 = rotation_matrix.ptr<float>(2)[0]; float r32 = rotation_matrix.ptr<float>(2)[1]; float r33 = rotation_matrix.ptr<float>(2)[2]; // 计算欧拉角 float thetaz = atan2(r21, r11) / CV_PI * 180; float thetay = atan2(-1 * r31, sqrt(r32*r32 + r33*r33)) / CV_PI * 180; float thetax = atan2(r32, r33) / CV_PI * 180; // C2W代表 相机坐标系转换到世界坐标系 W2C代表 世界坐标系转换到相机坐标系 Theta为欧拉角 cv::Point3f Theta_C2W; cv::Point3f Theta_W2C; cv::Point3f Position_OcInW; Theta_C2W.z = thetaz; Theta_C2W.y = thetay; Theta_C2W.x = thetax; Theta_W2C.x = -1 * thetax; Theta_W2C.y = -1 * thetay; Theta_W2C.z = -1 * thetaz; Position_OcInW.x = id_8_t.at<float>(0); Position_OcInW.y = id_8_t.at<float>(1); Position_OcInW.z = id_8_t.at<float>(2); Eigen::Vector3d eulerVec; eulerVec(0) = (Theta_C2W.z) / 180 * CV_PI; double A1_yaw = eulerVec(0); // 将解算后的位置发给控制端 pose_now.header.stamp = ros::Time::now(); pose_now.detected = true; pose_now.frame = 0; pose_now.position[0] = o_tx; pose_now.position[1] = o_ty; pose_now.position[2] = o_tz; pose_now.attitude[0] = thetaz; pose_now.attitude[1] = thetay; pose_now.attitude[2] = thetax; pose_now.attitude_q[0] = o_qx; pose_now.attitude_q[1] = o_qy; pose_now.attitude_q[2] = o_qz; pose_now.attitude_q[3] = o_qw; pose_now.sight_angle[0] = atan(o_tx / o_tz); pose_now.sight_angle[1] = atan(o_ty / o_tz); pose_now.yaw_error = A1_yaw; last_x = pose_now.position[0]; last_y = pose_now.position[1]; last_z = pose_now.position[2]; last_az = pose_now.attitude[0]; last_ay = pose_now.attitude[1]; last_ax = pose_now.attitude[2]; last_qx = pose_now.attitude_q[0]; last_qy = pose_now.attitude_q[1]; last_qz = pose_now.attitude_q[2]; last_qw = pose_now.attitude_q[3]; last_yaw = pose_now.yaw_error; } else { pose_now.header.stamp = ros::Time::now(); pose_now.detected = false; pose_now.frame = 0; pose_now.position[0] = last_x; pose_now.position[1] = last_y; pose_now.position[2] = last_z; pose_now.attitude[0] = last_az; pose_now.attitude[1] = last_ay; pose_now.attitude[2] = last_ax; pose_now.attitude_q[0] = last_qx; pose_now.attitude_q[1] = last_qy; pose_now.attitude_q[2] = last_qz; pose_now.attitude_q[3] = last_qw; pose_now.sight_angle[0] = atan(last_x / last_z); pose_now.sight_angle[1] = atan(last_y / last_z); pose_now.yaw_error = last_yaw; } position_pub.publish(pose_now); // 计算算法运行时间 clock_t finish=clock(); calculation_time=(finish-start)/1000; // 打印 // printf_result(); // 画出识别到的二维码 // cv::aruco::drawDetectedMarkers(img, markerCorners, markerids); msg_ellipse = cv_bridge::CvImage(std_msgs::Header(), "bgr8", img).toImageMsg(); landpad_pub.publish(msg_ellipse); } // cv::imshow("test",img); ros::spinOnce(); cv::waitKey(1); loopRate.sleep(); } } void printf_result() { // 固定的浮点显示 cout.setf(ios::fixed); // setprecision(n) 设显示小数精度为n位 cout<<setprecision(4); // 左对齐 cout.setf(ios::left); // 强制显示小数点 cout.setf(ios::showpoint); // 强制显示符号 cout.setf(ios::showpos); cout <<">>>>>>>>>>>>>>>>>>>>>>>>>>>>>Landpad Detection<<<<<<<<<<<<<<<<<<<<<<<<<<" <<endl; if(pose_now.detected) { cout << "is_detected: ture" <<endl; }else { cout << "is_detected: false" <<endl; } cout << "pos_target: [X Y Z] : " << pose_now.position[0] << " [m] "<< pose_now.position[1] <<" [m] " << pose_now.position[2] << " [m] "<<endl; cout << "pos_target: [Yaw] : " << pose_now.yaw_error/3.1415926 *180 << " [du] "<<endl; cout << "calculation_time = " << time << " [ms] " << endl; }
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r14 push %rdx lea addresses_A_ht+0x18545, %r12 nop nop nop nop nop add %r14, %r14 movups (%r12), %xmm7 vpextrq $1, %xmm7, %rdx nop nop nop nop nop cmp $17428, %rdx pop %rdx pop %r14 pop %r12 ret .global s_faulty_load s_faulty_load: push %r11 push %r13 push %r8 push %r9 push %rax push %rcx push %rdi // Store lea addresses_PSE+0x1dbc5, %rax cmp $55516, %r9 mov $0x5152535455565758, %r11 movq %r11, %xmm7 vmovups %ymm7, (%rax) nop nop sub $44286, %r8 // Store lea addresses_UC+0x8645, %rcx clflush (%rcx) nop nop nop nop xor $29650, %r11 movw $0x5152, (%rcx) // Exception!!! nop nop mov (0), %rcx nop nop nop dec %rcx // Store lea addresses_UC+0x1c34d, %r13 nop nop nop sub $5354, %rdi movl $0x51525354, (%r13) nop nop xor $32214, %r11 // Store lea addresses_normal+0x16a45, %r11 nop nop nop add %r8, %r8 movw $0x5152, (%r11) nop nop nop nop sub %r11, %r11 // Store lea addresses_RW+0xb645, %rdi nop nop dec %r13 mov $0x5152535455565758, %r11 movq %r11, (%rdi) nop and %r8, %r8 // Store lea addresses_US+0x8e45, %r8 and %r13, %r13 movl $0x51525354, (%r8) nop nop nop sub $5844, %r8 // Faulty Load lea addresses_RW+0xb645, %r9 cmp %rdi, %rdi movb (%r9), %r11b lea oracles, %r13 and $0xff, %r11 shlq $12, %r11 mov (%r13,%r11,1), %r11 pop %rdi pop %rcx pop %rax pop %r9 pop %r8 pop %r13 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 0, 'same': True, 'type': 'addresses_RW'}, 'OP': 'LOAD'} {'dst': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 7, 'same': False, 'type': 'addresses_PSE'}, 'OP': 'STOR'} {'dst': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 11, 'same': False, 'type': 'addresses_UC'}, 'OP': 'STOR'} {'dst': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 3, 'same': False, 'type': 'addresses_UC'}, 'OP': 'STOR'} {'dst': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 8, 'same': False, 'type': 'addresses_normal'}, 'OP': 'STOR'} {'dst': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 0, 'same': True, 'type': 'addresses_RW'}, 'OP': 'STOR'} {'dst': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 9, 'same': False, 'type': 'addresses_US'}, 'OP': 'STOR'} [Faulty Load] {'src': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 0, 'same': True, 'type': 'addresses_RW'}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 8, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'LOAD'} {'58': 21829} 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 */
;****************************************************************************** ;* MMX optimized DSP utils ;* Copyright (c) 2008 Loren Merritt ;* Copyright (c) 2003-2013 Michael Niedermayer ;* Copyright (c) 2013 Daniel Kang ;* ;* This file is part of FFmpeg. ;* ;* FFmpeg is free software; you can redistribute it and/or ;* modify it under the terms of the GNU Lesser General Public ;* License as published by the Free Software Foundation; either ;* version 2.1 of the License, or (at your option) any later version. ;* ;* FFmpeg is distributed in the hope that it will be useful, ;* but WITHOUT ANY WARRANTY; without even the implied warranty of ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;* Lesser General Public License for more details. ;* ;* You should have received a copy of the GNU Lesser General Public ;* License along with FFmpeg; if not, write to the Free Software ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ;****************************************************************************** %include "libavutil/x86/x86util.asm" SECTION .text INIT_MMX mmxext ; void pixels(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) %macro PIXELS48 2 %if %2 == 4 %define OP movh %else %define OP mova %endif cglobal %1_pixels%2, 4,5 movsxdifnidn r2, r2d lea r4, [r2*3] .loop: OP m0, [r1] OP m1, [r1+r2] OP m2, [r1+r2*2] OP m3, [r1+r4] lea r1, [r1+r2*4] %ifidn %1, avg pavgb m0, [r0] pavgb m1, [r0+r2] pavgb m2, [r0+r2*2] pavgb m3, [r0+r4] %endif OP [r0], m0 OP [r0+r2], m1 OP [r0+r2*2], m2 OP [r0+r4], m3 sub r3d, 4 lea r0, [r0+r2*4] jne .loop RET %endmacro PIXELS48 put, 4 PIXELS48 avg, 4 PIXELS48 put, 8 PIXELS48 avg, 8 INIT_XMM sse2 ; void put_pixels16_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) cglobal put_pixels16, 4,5,4 lea r4, [r2*3] .loop: movu m0, [r1] movu m1, [r1+r2] movu m2, [r1+r2*2] movu m3, [r1+r4] lea r1, [r1+r2*4] mova [r0], m0 mova [r0+r2], m1 mova [r0+r2*2], m2 mova [r0+r4], m3 sub r3d, 4 lea r0, [r0+r2*4] jnz .loop REP_RET ; void avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h) cglobal avg_pixels16, 4,5,4 lea r4, [r2*3] .loop: movu m0, [r1] movu m1, [r1+r2] movu m2, [r1+r2*2] movu m3, [r1+r4] lea r1, [r1+r2*4] pavgb m0, [r0] pavgb m1, [r0+r2] pavgb m2, [r0+r2*2] pavgb m3, [r0+r4] mova [r0], m0 mova [r0+r2], m1 mova [r0+r2*2], m2 mova [r0+r4], m3 sub r3d, 4 lea r0, [r0+r2*4] jnz .loop REP_RET
// Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "init.h" #include "util.h" #include "sync.h" #include "ui_interface.h" #include "base58.h" #include "bitcoinrpc.h" #include "db.h" #undef printf #include <boost/asio.hpp> #include <boost/asio/ip/v6_only.hpp> #include <boost/bind.hpp> #include <boost/filesystem.hpp> #include <boost/foreach.hpp> #include <boost/iostreams/concepts.hpp> #include <boost/iostreams/stream.hpp> #include <boost/algorithm/string.hpp> #include <boost/lexical_cast.hpp> #include <boost/asio/ssl.hpp> #include <boost/filesystem/fstream.hpp> #include <boost/shared_ptr.hpp> #include <list> #define printf OutputDebugStringF using namespace std; using namespace boost; using namespace boost::asio; using namespace json_spirit; void ThreadRPCServer2(void* parg); static std::string strRPCUserColonPass; const Object emptyobj; void ThreadRPCServer3(void* parg); static inline unsigned short GetDefaultRPCPort() { return GetBoolArg("-testnet", false) ? 26329 : 16329; } Object JSONRPCError(int code, const string& message) { Object error; error.push_back(Pair("code", code)); error.push_back(Pair("message", message)); return error; } void RPCTypeCheck(const Array& params, const list<Value_type>& typesExpected, bool fAllowNull) { unsigned int i = 0; BOOST_FOREACH(Value_type t, typesExpected) { if (params.size() <= i) break; const Value& v = params[i]; if (!((v.type() == t) || (fAllowNull && (v.type() == null_type)))) { string err = strprintf("Expected type %s, got %s", Value_type_name[t], Value_type_name[v.type()]); throw JSONRPCError(RPC_TYPE_ERROR, err); } i++; } } void RPCTypeCheck(const Object& o, const map<string, Value_type>& typesExpected, bool fAllowNull) { BOOST_FOREACH(const PAIRTYPE(string, Value_type)& t, typesExpected) { const Value& v = find_value(o, t.first); if (!fAllowNull && v.type() == null_type) throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing %s", t.first.c_str())); if (!((v.type() == t.second) || (fAllowNull && (v.type() == null_type)))) { string err = strprintf("Expected type %s for %s, got %s", Value_type_name[t.second], t.first.c_str(), Value_type_name[v.type()]); throw JSONRPCError(RPC_TYPE_ERROR, err); } } } int64 AmountFromValue(const Value& value) { double dAmount = value.get_real(); if (dAmount <= 0.0 || dAmount > MAX_MONEY) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount"); int64 nAmount = roundint64(dAmount * COIN); if (!MoneyRange(nAmount)) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount"); return nAmount; } Value ValueFromAmount(int64 amount) { return (double)amount / (double)COIN; } std::string HexBits(unsigned int nBits) { union { int32_t nBits; char cBits[4]; } uBits; uBits.nBits = htonl((int32_t)nBits); return HexStr(BEGIN(uBits.cBits), END(uBits.cBits)); } /// /// Note: This interface may still be subject to change. /// string CRPCTable::help(string strCommand) const { string strRet; set<rpcfn_type> setDone; for (map<string, const CRPCCommand*>::const_iterator mi = mapCommands.begin(); mi != mapCommands.end(); ++mi) { const CRPCCommand *pcmd = mi->second; string strMethod = mi->first; // We already filter duplicates, but these deprecated screw up the sort order if (strMethod.find("label") != string::npos) continue; if (strCommand != "" && strMethod != strCommand) continue; try { Array params; rpcfn_type pfn = pcmd->actor; if (setDone.insert(pfn).second) (*pfn)(params, true); } catch (std::exception& e) { // Help text is returned in an exception string strHelp = string(e.what()); if (strCommand == "") if (strHelp.find('\n') != string::npos) strHelp = strHelp.substr(0, strHelp.find('\n')); strRet += strHelp + "\n"; } } if (strRet == "") strRet = strprintf("help: unknown command: %s\n", strCommand.c_str()); strRet = strRet.substr(0,strRet.size()-1); return strRet; } Value help(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) throw runtime_error( "help [command]\n" "List commands, or get help for a command."); string strCommand; if (params.size() > 0) strCommand = params[0].get_str(); return tableRPC.help(strCommand); } Value stop(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) throw runtime_error( "stop <detach>\n" "<detach> is true or false to detach the database or not for this stop only\n" "Stop OfferlibationCoin server (and possibly override the detachdb config value)."); // Shutdown will take long enough that the response should get back if (params.size() > 0) bitdb.SetDetach(params[0].get_bool()); StartShutdown(); return "OfferlibationCoin server stopping"; } // // Call Table // static const CRPCCommand vRPCCommands[] = { // name function safemd unlocked // ------------------------ ----------------------- ------ -------- { "help", &help, true, true }, { "stop", &stop, true, true }, { "getblockcount", &getblockcount, true, false }, { "getconnectioncount", &getconnectioncount, true, false }, { "getpeerinfo", &getpeerinfo, true, false }, { "getdifficulty", &getdifficulty, true, false }, { "getgenerate", &getgenerate, true, false }, { "setgenerate", &setgenerate, true, false }, { "gethashespersec", &gethashespersec, true, false }, { "getinfo", &getinfo, true, false }, { "getmininginfo", &getmininginfo, true, false }, { "getnewaddress", &getnewaddress, true, false }, { "getnewpubkey", &getnewpubkey, true, false }, { "getaccountaddress", &getaccountaddress, true, false }, { "setaccount", &setaccount, true, false }, { "getaccount", &getaccount, false, false }, { "getaddressesbyaccount", &getaddressesbyaccount, true, false }, { "sendtoaddress", &sendtoaddress, false, false }, { "getreceivedbyaddress", &getreceivedbyaddress, false, false }, { "getreceivedbyaccount", &getreceivedbyaccount, false, false }, { "listreceivedbyaddress", &listreceivedbyaddress, false, false }, { "listreceivedbyaccount", &listreceivedbyaccount, false, false }, { "backupwallet", &backupwallet, true, false }, { "keypoolrefill", &keypoolrefill, true, false }, { "walletpassphrase", &walletpassphrase, true, false }, { "walletpassphrasechange", &walletpassphrasechange, false, false }, { "walletlock", &walletlock, true, false }, { "encryptwallet", &encryptwallet, false, false }, { "validateaddress", &validateaddress, true, false }, { "validatepubkey", &validatepubkey, true, false }, { "getbalance", &getbalance, false, false }, { "move", &movecmd, false, false }, { "sendfrom", &sendfrom, false, false }, { "sendmany", &sendmany, false, false }, { "addmultisigaddress", &addmultisigaddress, false, false }, { "getrawmempool", &getrawmempool, true, false }, { "getblock", &getblock, false, false }, { "getblockbynumber", &getblockbynumber, false, false }, { "getblockhash", &getblockhash, false, false }, { "getpowheight", &getpowheight, false, false }, { "gettransaction", &gettransaction, false, false }, { "listtransactions", &listtransactions, false, false }, { "listaddressgroupings", &listaddressgroupings, false, false }, { "signmessage", &signmessage, false, false }, { "verifymessage", &verifymessage, false, false }, { "getwork", &getwork, true, false }, { "getworkex", &getworkex, true, false }, { "listaccounts", &listaccounts, false, false }, { "settxfee", &settxfee, false, false }, { "getblocktemplate", &getblocktemplate, true, false }, { "submitblock", &submitblock, false, false }, { "listsinceblock", &listsinceblock, false, false }, { "dumpprivkey", &dumpprivkey, false, false }, { "importprivkey", &importprivkey, false, false }, { "listunspent", &listunspent, false, false }, { "getrawtransaction", &getrawtransaction, false, false }, { "createrawtransaction", &createrawtransaction, false, false }, { "decoderawtransaction", &decoderawtransaction, false, false }, { "signrawtransaction", &signrawtransaction, false, false }, { "sendrawtransaction", &sendrawtransaction, false, false }, { "getcheckpoint", &getcheckpoint, true, false }, { "reservebalance", &reservebalance, false, true}, { "checkwallet", &checkwallet, false, true}, { "repairwallet", &repairwallet, false, true}, { "resendtx", &resendtx, false, true}, { "makekeypair", &makekeypair, false, true}, { "sendalert", &sendalert, false, false}, }; CRPCTable::CRPCTable() { unsigned int vcidx; for (vcidx = 0; vcidx < (sizeof(vRPCCommands) / sizeof(vRPCCommands[0])); vcidx++) { const CRPCCommand *pcmd; pcmd = &vRPCCommands[vcidx]; mapCommands[pcmd->name] = pcmd; } } const CRPCCommand *CRPCTable::operator[](string name) const { map<string, const CRPCCommand*>::const_iterator it = mapCommands.find(name); if (it == mapCommands.end()) return NULL; return (*it).second; } // // HTTP protocol // // This ain't Apache. We're just using HTTP header for the length field // and to be compatible with other JSON-RPC implementations. // string HTTPPost(const string& strMsg, const map<string,string>& mapRequestHeaders) { ostringstream s; s << "POST / HTTP/1.1\r\n" << "User-Agent: OfferlibationCoin-json-rpc/" << FormatFullVersion() << "\r\n" << "Host: 127.0.0.1\r\n" << "Content-Type: application/json\r\n" << "Content-Length: " << strMsg.size() << "\r\n" << "Connection: close\r\n" << "Accept: application/json\r\n"; BOOST_FOREACH(const PAIRTYPE(string, string)& item, mapRequestHeaders) s << item.first << ": " << item.second << "\r\n"; s << "\r\n" << strMsg; return s.str(); } string rfc1123Time() { char buffer[64]; time_t now; time(&now); struct tm* now_gmt = gmtime(&now); string locale(setlocale(LC_TIME, NULL)); setlocale(LC_TIME, "C"); // we want POSIX (aka "C") weekday/month strings strftime(buffer, sizeof(buffer), "%a, %d %b %Y %H:%M:%S +0000", now_gmt); setlocale(LC_TIME, locale.c_str()); return string(buffer); } static string HTTPReply(int nStatus, const string& strMsg, bool keepalive) { if (nStatus == HTTP_UNAUTHORIZED) return strprintf("HTTP/1.0 401 Authorization Required\r\n" "Date: %s\r\n" "Server: OfferlibationCoin-json-rpc/%s\r\n" "WWW-Authenticate: Basic realm=\"jsonrpc\"\r\n" "Content-Type: text/html\r\n" "Content-Length: 296\r\n" "\r\n" "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\r\n" "\"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd\">\r\n" "<HTML>\r\n" "<HEAD>\r\n" "<TITLE>Error</TITLE>\r\n" "<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>\r\n" "</HEAD>\r\n" "<BODY><H1>401 Unauthorized.</H1></BODY>\r\n" "</HTML>\r\n", rfc1123Time().c_str(), FormatFullVersion().c_str()); const char *cStatus; if (nStatus == HTTP_OK) cStatus = "OK"; else if (nStatus == HTTP_BAD_REQUEST) cStatus = "Bad Request"; else if (nStatus == HTTP_FORBIDDEN) cStatus = "Forbidden"; else if (nStatus == HTTP_NOT_FOUND) cStatus = "Not Found"; else if (nStatus == HTTP_INTERNAL_SERVER_ERROR) cStatus = "Internal Server Error"; else cStatus = ""; return strprintf( "HTTP/1.1 %d %s\r\n" "Date: %s\r\n" "Connection: %s\r\n" "Content-Length: %"PRIszu"\r\n" "Content-Type: application/json\r\n" "Server: OfferlibationCoin-json-rpc/%s\r\n" "\r\n" "%s", nStatus, cStatus, rfc1123Time().c_str(), keepalive ? "keep-alive" : "close", strMsg.size(), FormatFullVersion().c_str(), strMsg.c_str()); } int ReadHTTPStatus(std::basic_istream<char>& stream, int &proto) { string str; getline(stream, str); vector<string> vWords; boost::split(vWords, str, boost::is_any_of(" ")); if (vWords.size() < 2) return HTTP_INTERNAL_SERVER_ERROR; proto = 0; const char *ver = strstr(str.c_str(), "HTTP/1."); if (ver != NULL) proto = atoi(ver+7); return atoi(vWords[1].c_str()); } int ReadHTTPHeader(std::basic_istream<char>& stream, map<string, string>& mapHeadersRet) { int nLen = 0; loop { string str; std::getline(stream, str); if (str.empty() || str == "\r") break; string::size_type nColon = str.find(":"); if (nColon != string::npos) { string strHeader = str.substr(0, nColon); boost::trim(strHeader); boost::to_lower(strHeader); string strValue = str.substr(nColon+1); boost::trim(strValue); mapHeadersRet[strHeader] = strValue; if (strHeader == "content-length") nLen = atoi(strValue.c_str()); } } return nLen; } int ReadHTTP(std::basic_istream<char>& stream, map<string, string>& mapHeadersRet, string& strMessageRet) { mapHeadersRet.clear(); strMessageRet = ""; // Read status int nProto = 0; int nStatus = ReadHTTPStatus(stream, nProto); // Read header int nLen = ReadHTTPHeader(stream, mapHeadersRet); if (nLen < 0 || nLen > (int)MAX_SIZE) return HTTP_INTERNAL_SERVER_ERROR; // Read message if (nLen > 0) { vector<char> vch(nLen); stream.read(&vch[0], nLen); strMessageRet = string(vch.begin(), vch.end()); } string sConHdr = mapHeadersRet["connection"]; if ((sConHdr != "close") && (sConHdr != "keep-alive")) { if (nProto >= 1) mapHeadersRet["connection"] = "keep-alive"; else mapHeadersRet["connection"] = "close"; } return nStatus; } bool HTTPAuthorized(map<string, string>& mapHeaders) { string strAuth = mapHeaders["authorization"]; if (strAuth.substr(0,6) != "Basic ") return false; string strUserPass64 = strAuth.substr(6); boost::trim(strUserPass64); string strUserPass = DecodeBase64(strUserPass64); return strUserPass == strRPCUserColonPass; } // // JSON-RPC protocol. Bitcoin speaks version 1.0 for maximum compatibility, // but uses JSON-RPC 1.1/2.0 standards for parts of the 1.0 standard that were // unspecified (HTTP errors and contents of 'error'). // // 1.0 spec: http://json-rpc.org/wiki/specification // 1.2 spec: http://groups.google.com/group/json-rpc/web/json-rpc-over-http // http://www.codeproject.com/KB/recipes/JSON_Spirit.aspx // string JSONRPCRequest(const string& strMethod, const Array& params, const Value& id) { Object request; request.push_back(Pair("method", strMethod)); request.push_back(Pair("params", params)); request.push_back(Pair("id", id)); return write_string(Value(request), false) + "\n"; } Object JSONRPCReplyObj(const Value& result, const Value& error, const Value& id) { Object reply; if (error.type() != null_type) reply.push_back(Pair("result", Value::null)); else reply.push_back(Pair("result", result)); reply.push_back(Pair("error", error)); reply.push_back(Pair("id", id)); return reply; } string JSONRPCReply(const Value& result, const Value& error, const Value& id) { Object reply = JSONRPCReplyObj(result, error, id); return write_string(Value(reply), false) + "\n"; } void ErrorReply(std::ostream& stream, const Object& objError, const Value& id) { // Send error reply from json-rpc error object int nStatus = HTTP_INTERNAL_SERVER_ERROR; int code = find_value(objError, "code").get_int(); if (code == RPC_INVALID_REQUEST) nStatus = HTTP_BAD_REQUEST; else if (code == RPC_METHOD_NOT_FOUND) nStatus = HTTP_NOT_FOUND; string strReply = JSONRPCReply(Value::null, objError, id); stream << HTTPReply(nStatus, strReply, false) << std::flush; } bool ClientAllowed(const boost::asio::ip::address& address) { // Make sure that IPv4-compatible and IPv4-mapped IPv6 addresses are treated as IPv4 addresses if (address.is_v6() && (address.to_v6().is_v4_compatible() || address.to_v6().is_v4_mapped())) return ClientAllowed(address.to_v6().to_v4()); std::string ipv4addr = address.to_string(); if (address == asio::ip::address_v4::loopback() || address == asio::ip::address_v6::loopback() || (address.is_v4() // Check whether IPv4 addresses match 127.0.0.0/8 (loopback subnet) && (address.to_v4().to_ulong() & 0xff000000) == 0x7f000000)) return true; const string strAddress = address.to_string(); const vector<string>& vAllow = mapMultiArgs["-rpcallowip"]; BOOST_FOREACH(string strAllow, vAllow) if (WildcardMatch(strAddress, strAllow)) return true; return false; } // // IOStream device that speaks SSL but can also speak non-SSL // template <typename Protocol> class SSLIOStreamDevice : public iostreams::device<iostreams::bidirectional> { public: SSLIOStreamDevice(asio::ssl::stream<typename Protocol::socket> &streamIn, bool fUseSSLIn) : stream(streamIn) { fUseSSL = fUseSSLIn; fNeedHandshake = fUseSSLIn; } void handshake(ssl::stream_base::handshake_type role) { if (!fNeedHandshake) return; fNeedHandshake = false; stream.handshake(role); } std::streamsize read(char* s, std::streamsize n) { handshake(ssl::stream_base::server); // HTTPS servers read first if (fUseSSL) return stream.read_some(asio::buffer(s, n)); return stream.next_layer().read_some(asio::buffer(s, n)); } std::streamsize write(const char* s, std::streamsize n) { handshake(ssl::stream_base::client); // HTTPS clients write first if (fUseSSL) return asio::write(stream, asio::buffer(s, n)); return asio::write(stream.next_layer(), asio::buffer(s, n)); } bool connect(const std::string& server, const std::string& port) { ip::tcp::resolver resolver(stream.get_io_service()); ip::tcp::resolver::query query(server.c_str(), port.c_str()); ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); ip::tcp::resolver::iterator end; boost::system::error_code error = asio::error::host_not_found; while (error && endpoint_iterator != end) { stream.lowest_layer().close(); stream.lowest_layer().connect(*endpoint_iterator++, error); } if (error) return false; return true; } private: bool fNeedHandshake; bool fUseSSL; asio::ssl::stream<typename Protocol::socket>& stream; }; class AcceptedConnection { public: virtual ~AcceptedConnection() {} virtual std::iostream& stream() = 0; virtual std::string peer_address_to_string() const = 0; virtual void close() = 0; }; template <typename Protocol> class AcceptedConnectionImpl : public AcceptedConnection { public: AcceptedConnectionImpl( asio::io_service& io_service, ssl::context &context, bool fUseSSL) : sslStream(io_service, context), _d(sslStream, fUseSSL), _stream(_d) { } virtual std::iostream& stream() { return _stream; } virtual std::string peer_address_to_string() const { return peer.address().to_string(); } virtual void close() { _stream.close(); } typename Protocol::endpoint peer; asio::ssl::stream<typename Protocol::socket> sslStream; private: SSLIOStreamDevice<Protocol> _d; iostreams::stream< SSLIOStreamDevice<Protocol> > _stream; }; void ThreadRPCServer(void* parg) { // Make this thread recognisable as the RPC listener RenameThread("bitcoin-rpclist"); try { vnThreadsRunning[THREAD_RPCLISTENER]++; ThreadRPCServer2(parg); vnThreadsRunning[THREAD_RPCLISTENER]--; } catch (std::exception& e) { vnThreadsRunning[THREAD_RPCLISTENER]--; PrintException(&e, "ThreadRPCServer()"); } catch (...) { vnThreadsRunning[THREAD_RPCLISTENER]--; PrintException(NULL, "ThreadRPCServer()"); } printf("ThreadRPCServer exited\n"); } // Forward declaration required for RPCListen template <typename Protocol, typename SocketAcceptorService> static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor<Protocol, SocketAcceptorService> > acceptor, ssl::context& context, bool fUseSSL, AcceptedConnection* conn, const boost::system::error_code& error); /** * Sets up I/O resources to accept and handle a new connection. */ template <typename Protocol, typename SocketAcceptorService> static void RPCListen(boost::shared_ptr< basic_socket_acceptor<Protocol, SocketAcceptorService> > acceptor, ssl::context& context, const bool fUseSSL) { // Accept connection AcceptedConnectionImpl<Protocol>* conn = new AcceptedConnectionImpl<Protocol>(acceptor->get_io_service(), context, fUseSSL); acceptor->async_accept( conn->sslStream.lowest_layer(), conn->peer, boost::bind(&RPCAcceptHandler<Protocol, SocketAcceptorService>, acceptor, boost::ref(context), fUseSSL, conn, boost::asio::placeholders::error)); } /** * Accept and handle incoming connection. */ template <typename Protocol, typename SocketAcceptorService> static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor<Protocol, SocketAcceptorService> > acceptor, ssl::context& context, const bool fUseSSL, AcceptedConnection* conn, const boost::system::error_code& error) { vnThreadsRunning[THREAD_RPCLISTENER]++; // Immediately start accepting new connections, except when we're cancelled or our socket is closed. if (error != asio::error::operation_aborted && acceptor->is_open()) RPCListen(acceptor, context, fUseSSL); AcceptedConnectionImpl<ip::tcp>* tcp_conn = dynamic_cast< AcceptedConnectionImpl<ip::tcp>* >(conn); // TODO: Actually handle errors if (error) { delete conn; } // Restrict callers by IP. It is important to // do this before starting client thread, to filter out // certain DoS and misbehaving clients. else if (tcp_conn && !ClientAllowed(tcp_conn->peer.address())) { // Only send a 403 if we're not using SSL to prevent a DoS during the SSL handshake. if (!fUseSSL) conn->stream() << HTTPReply(HTTP_FORBIDDEN, "", false) << std::flush; delete conn; } // start HTTP client thread else if (!NewThread(ThreadRPCServer3, conn)) { printf("Failed to create RPC server client thread\n"); delete conn; } vnThreadsRunning[THREAD_RPCLISTENER]--; } void ThreadRPCServer2(void* parg) { printf("ThreadRPCServer started\n"); strRPCUserColonPass = mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]; if (mapArgs["-rpcpassword"] == "") { unsigned char rand_pwd[32]; RAND_bytes(rand_pwd, 32); string strWhatAmI = "To use OfferlibationCoind"; if (mapArgs.count("-server")) strWhatAmI = strprintf(_("To use the %s option"), "\"-server\""); else if (mapArgs.count("-daemon")) strWhatAmI = strprintf(_("To use the %s option"), "\"-daemon\""); uiInterface.ThreadSafeMessageBox(strprintf( _("%s, you must set a rpcpassword in the configuration file:\n %s\n" "It is recommended you use the following random password:\n" "rpcuser=bitcoinrpc\n" "rpcpassword=%s\n" "(you do not need to remember this password)\n" "If the file does not exist, create it with owner-readable-only file permissions.\n"), strWhatAmI.c_str(), GetConfigFile().string().c_str(), EncodeBase58(&rand_pwd[0],&rand_pwd[0]+32).c_str()), _("Error"), CClientUIInterface::OK | CClientUIInterface::MODAL); StartShutdown(); return; } const bool fUseSSL = GetBoolArg("-rpcssl"); asio::io_service io_service; ssl::context context(io_service, ssl::context::sslv23); if (fUseSSL) { context.set_options(ssl::context::no_sslv2); filesystem::path pathCertFile(GetArg("-rpcsslcertificatechainfile", "server.cert")); if (!pathCertFile.is_complete()) pathCertFile = filesystem::path(GetDataDir()) / pathCertFile; if (filesystem::exists(pathCertFile)) context.use_certificate_chain_file(pathCertFile.string()); else printf("ThreadRPCServer ERROR: missing server certificate file %s\n", pathCertFile.string().c_str()); filesystem::path pathPKFile(GetArg("-rpcsslprivatekeyfile", "server.pem")); if (!pathPKFile.is_complete()) pathPKFile = filesystem::path(GetDataDir()) / pathPKFile; if (filesystem::exists(pathPKFile)) context.use_private_key_file(pathPKFile.string(), ssl::context::pem); else printf("ThreadRPCServer ERROR: missing server private key file %s\n", pathPKFile.string().c_str()); string strCiphers = GetArg("-rpcsslciphers", "TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH"); SSL_CTX_set_cipher_list(context.impl(), strCiphers.c_str()); } // Try a dual IPv6/IPv4 socket, falling back to separate IPv4 and IPv6 sockets const bool loopback = !mapArgs.count("-rpcallowip"); asio::ip::address bindAddress = loopback ? asio::ip::address_v6::loopback() : asio::ip::address_v6::any(); ip::tcp::endpoint endpoint(bindAddress, GetArg("-rpcport", GetDefaultRPCPort())); boost::system::error_code v6_only_error; boost::shared_ptr<ip::tcp::acceptor> acceptor(new ip::tcp::acceptor(io_service)); boost::signals2::signal<void ()> StopRequests; bool fListening = false; std::string strerr; try { acceptor->open(endpoint.protocol()); acceptor->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); // Try making the socket dual IPv6/IPv4 (if listening on the "any" address) acceptor->set_option(boost::asio::ip::v6_only(loopback), v6_only_error); acceptor->bind(endpoint); acceptor->listen(socket_base::max_connections); RPCListen(acceptor, context, fUseSSL); // Cancel outstanding listen-requests for this acceptor when shutting down StopRequests.connect(signals2::slot<void ()>( static_cast<void (ip::tcp::acceptor::*)()>(&ip::tcp::acceptor::close), acceptor.get()) .track(acceptor)); fListening = true; } catch(boost::system::system_error &e) { strerr = strprintf(_("An error occurred while setting up the RPC port %u for listening on IPv6, falling back to IPv4: %s"), endpoint.port(), e.what()); } try { // If dual IPv6/IPv4 failed (or we're opening loopback interfaces only), open IPv4 separately if (!fListening || loopback || v6_only_error) { bindAddress = loopback ? asio::ip::address_v4::loopback() : asio::ip::address_v4::any(); endpoint.address(bindAddress); acceptor.reset(new ip::tcp::acceptor(io_service)); acceptor->open(endpoint.protocol()); acceptor->set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); acceptor->bind(endpoint); acceptor->listen(socket_base::max_connections); RPCListen(acceptor, context, fUseSSL); // Cancel outstanding listen-requests for this acceptor when shutting down StopRequests.connect(signals2::slot<void ()>( static_cast<void (ip::tcp::acceptor::*)()>(&ip::tcp::acceptor::close), acceptor.get()) .track(acceptor)); fListening = true; } } catch(boost::system::system_error &e) { strerr = strprintf(_("An error occurred while setting up the RPC port %u for listening on IPv4: %s"), endpoint.port(), e.what()); } if (!fListening) { uiInterface.ThreadSafeMessageBox(strerr, _("Error"), CClientUIInterface::OK | CClientUIInterface::MODAL); StartShutdown(); return; } vnThreadsRunning[THREAD_RPCLISTENER]--; while (!fShutdown) io_service.run_one(); vnThreadsRunning[THREAD_RPCLISTENER]++; StopRequests(); } class JSONRequest { public: Value id; string strMethod; Array params; JSONRequest() { id = Value::null; } void parse(const Value& valRequest); }; void JSONRequest::parse(const Value& valRequest) { // Parse request if (valRequest.type() != obj_type) throw JSONRPCError(RPC_INVALID_REQUEST, "Invalid Request object"); const Object& request = valRequest.get_obj(); // Parse id now so errors from here on will have the id id = find_value(request, "id"); // Parse method Value valMethod = find_value(request, "method"); if (valMethod.type() == null_type) throw JSONRPCError(RPC_INVALID_REQUEST, "Missing method"); if (valMethod.type() != str_type) throw JSONRPCError(RPC_INVALID_REQUEST, "Method must be a string"); strMethod = valMethod.get_str(); if (strMethod != "getwork" && strMethod != "getblocktemplate") printf("ThreadRPCServer method=%s\n", strMethod.c_str()); // Parse params Value valParams = find_value(request, "params"); if (valParams.type() == array_type) params = valParams.get_array(); else if (valParams.type() == null_type) params = Array(); else throw JSONRPCError(RPC_INVALID_REQUEST, "Params must be an array"); } static Object JSONRPCExecOne(const Value& req) { Object rpc_result; JSONRequest jreq; try { jreq.parse(req); Value result = tableRPC.execute(jreq.strMethod, jreq.params); rpc_result = JSONRPCReplyObj(result, Value::null, jreq.id); } catch (Object& objError) { rpc_result = JSONRPCReplyObj(Value::null, objError, jreq.id); } catch (std::exception& e) { rpc_result = JSONRPCReplyObj(Value::null, JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id); } return rpc_result; } static string JSONRPCExecBatch(const Array& vReq) { Array ret; for (unsigned int reqIdx = 0; reqIdx < vReq.size(); reqIdx++) ret.push_back(JSONRPCExecOne(vReq[reqIdx])); return write_string(Value(ret), false) + "\n"; } static CCriticalSection cs_THREAD_RPCHANDLER; void ThreadRPCServer3(void* parg) { // Make this thread recognisable as the RPC handler RenameThread("bitcoin-rpchand"); { LOCK(cs_THREAD_RPCHANDLER); vnThreadsRunning[THREAD_RPCHANDLER]++; } AcceptedConnection *conn = (AcceptedConnection *) parg; bool fRun = true; loop { if (fShutdown || !fRun) { conn->close(); delete conn; { LOCK(cs_THREAD_RPCHANDLER); --vnThreadsRunning[THREAD_RPCHANDLER]; } return; } map<string, string> mapHeaders; string strRequest; ReadHTTP(conn->stream(), mapHeaders, strRequest); // Check authorization if (mapHeaders.count("authorization") == 0) { conn->stream() << HTTPReply(HTTP_UNAUTHORIZED, "", false) << std::flush; break; } if (!HTTPAuthorized(mapHeaders)) { printf("ThreadRPCServer incorrect password attempt from %s\n", conn->peer_address_to_string().c_str()); /* Deter brute-forcing short passwords. If this results in a DOS the user really shouldn't have their RPC port exposed.*/ if (mapArgs["-rpcpassword"].size() < 20) Sleep(250); conn->stream() << HTTPReply(HTTP_UNAUTHORIZED, "", false) << std::flush; break; } if (mapHeaders["connection"] == "close") fRun = false; JSONRequest jreq; try { // Parse request Value valRequest; if (!read_string(strRequest, valRequest)) throw JSONRPCError(RPC_PARSE_ERROR, "Parse error"); string strReply; // singleton request if (valRequest.type() == obj_type) { jreq.parse(valRequest); Value result = tableRPC.execute(jreq.strMethod, jreq.params); // Send reply strReply = JSONRPCReply(result, Value::null, jreq.id); // array of requests } else if (valRequest.type() == array_type) strReply = JSONRPCExecBatch(valRequest.get_array()); else throw JSONRPCError(RPC_PARSE_ERROR, "Top-level object parse error"); conn->stream() << HTTPReply(HTTP_OK, strReply, fRun) << std::flush; } catch (Object& objError) { ErrorReply(conn->stream(), objError, jreq.id); break; } catch (std::exception& e) { ErrorReply(conn->stream(), JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id); break; } } delete conn; { LOCK(cs_THREAD_RPCHANDLER); vnThreadsRunning[THREAD_RPCHANDLER]--; } } json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_spirit::Array &params) const { // Find method const CRPCCommand *pcmd = tableRPC[strMethod]; if (!pcmd) throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found"); // Observe safe mode string strWarning = GetWarnings("rpc"); if (strWarning != "" && !GetBoolArg("-disablesafemode") && !pcmd->okSafeMode) throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, string("Safe mode: ") + strWarning); try { // Execute Value result; { if (pcmd->unlocked) result = pcmd->actor(params, false); else { LOCK2(cs_main, pwalletMain->cs_wallet); result = pcmd->actor(params, false); } } return result; } catch (std::exception& e) { throw JSONRPCError(RPC_MISC_ERROR, e.what()); } } Object CallRPC(const string& strMethod, const Array& params) { if (mapArgs["-rpcuser"] == "" && mapArgs["-rpcpassword"] == "") throw runtime_error(strprintf( _("You must set rpcpassword=<password> in the configuration file:\n%s\n" "If the file does not exist, create it with owner-readable-only file permissions."), GetConfigFile().string().c_str())); // Connect to localhost bool fUseSSL = GetBoolArg("-rpcssl"); asio::io_service io_service; ssl::context context(io_service, ssl::context::sslv23); context.set_options(ssl::context::no_sslv2); asio::ssl::stream<asio::ip::tcp::socket> sslStream(io_service, context); SSLIOStreamDevice<asio::ip::tcp> d(sslStream, fUseSSL); iostreams::stream< SSLIOStreamDevice<asio::ip::tcp> > stream(d); if (!d.connect(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", itostr(GetDefaultRPCPort())))) throw runtime_error("couldn't connect to server"); // HTTP basic authentication string strUserPass64 = EncodeBase64(mapArgs["-rpcuser"] + ":" + mapArgs["-rpcpassword"]); map<string, string> mapRequestHeaders; mapRequestHeaders["Authorization"] = string("Basic ") + strUserPass64; // Send request string strRequest = JSONRPCRequest(strMethod, params, 1); string strPost = HTTPPost(strRequest, mapRequestHeaders); stream << strPost << std::flush; // Receive reply map<string, string> mapHeaders; string strReply; int nStatus = ReadHTTP(stream, mapHeaders, strReply); if (nStatus == HTTP_UNAUTHORIZED) throw runtime_error("incorrect rpcuser or rpcpassword (authorization failed)"); else if (nStatus >= 400 && nStatus != HTTP_BAD_REQUEST && nStatus != HTTP_NOT_FOUND && nStatus != HTTP_INTERNAL_SERVER_ERROR) throw runtime_error(strprintf("server returned HTTP error %d", nStatus)); else if (strReply.empty()) throw runtime_error("no response from server"); // Parse reply Value valReply; if (!read_string(strReply, valReply)) throw runtime_error("couldn't parse reply from server"); const Object& reply = valReply.get_obj(); if (reply.empty()) throw runtime_error("expected reply to have result, error and id properties"); return reply; } template<typename T> void ConvertTo(Value& value, bool fAllowNull=false) { if (fAllowNull && value.type() == null_type) return; if (value.type() == str_type) { // reinterpret string as unquoted json value Value value2; string strJSON = value.get_str(); if (!read_string(strJSON, value2)) throw runtime_error(string("Error parsing JSON:")+strJSON); ConvertTo<T>(value2, fAllowNull); value = value2; } else { value = value.get_value<T>(); } } // Convert strings to command-specific RPC representation Array RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams) { Array params; BOOST_FOREACH(const std::string &param, strParams) params.push_back(param); int n = params.size(); // // Special case non-string parameter types // if (strMethod == "stop" && n > 0) ConvertTo<bool>(params[0]); if (strMethod == "setgenerate" && n > 0) ConvertTo<bool>(params[0]); if (strMethod == "setgenerate" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "sendtoaddress" && n > 1) ConvertTo<double>(params[1]); if (strMethod == "settxfee" && n > 0) ConvertTo<double>(params[0]); if (strMethod == "getreceivedbyaddress" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "getreceivedbyaccount" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "listreceivedbyaddress" && n > 0) ConvertTo<boost::int64_t>(params[0]); if (strMethod == "listreceivedbyaddress" && n > 1) ConvertTo<bool>(params[1]); if (strMethod == "listreceivedbyaccount" && n > 0) ConvertTo<boost::int64_t>(params[0]); if (strMethod == "listreceivedbyaccount" && n > 1) ConvertTo<bool>(params[1]); if (strMethod == "getbalance" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "getblock" && n > 1) ConvertTo<bool>(params[1]); if (strMethod == "getblockbynumber" && n > 0) ConvertTo<boost::int64_t>(params[0]); if (strMethod == "getblockbynumber" && n > 1) ConvertTo<bool>(params[1]); if (strMethod == "getblockhash" && n > 0) ConvertTo<boost::int64_t>(params[0]); if (strMethod == "getpowheight" && n > 0) ConvertTo<boost::int64_t>(params[0]); if (strMethod == "move" && n > 2) ConvertTo<double>(params[2]); if (strMethod == "move" && n > 3) ConvertTo<boost::int64_t>(params[3]); if (strMethod == "sendfrom" && n > 2) ConvertTo<double>(params[2]); if (strMethod == "sendfrom" && n > 3) ConvertTo<boost::int64_t>(params[3]); if (strMethod == "listtransactions" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "listtransactions" && n > 2) ConvertTo<boost::int64_t>(params[2]); if (strMethod == "listaccounts" && n > 0) ConvertTo<boost::int64_t>(params[0]); if (strMethod == "walletpassphrase" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "walletpassphrase" && n > 2) ConvertTo<bool>(params[2]); if (strMethod == "getblocktemplate" && n > 0) ConvertTo<Object>(params[0]); if (strMethod == "listsinceblock" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "sendmany" && n > 1) ConvertTo<Object>(params[1]); if (strMethod == "sendmany" && n > 2) ConvertTo<boost::int64_t>(params[2]); if (strMethod == "reservebalance" && n > 0) ConvertTo<bool>(params[0]); if (strMethod == "reservebalance" && n > 1) ConvertTo<double>(params[1]); if (strMethod == "addmultisigaddress" && n > 0) ConvertTo<boost::int64_t>(params[0]); if (strMethod == "addmultisigaddress" && n > 1) ConvertTo<Array>(params[1]); if (strMethod == "listunspent" && n > 0) ConvertTo<boost::int64_t>(params[0]); if (strMethod == "listunspent" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "listunspent" && n > 2) ConvertTo<Array>(params[2]); if (strMethod == "getrawtransaction" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "createrawtransaction" && n > 0) ConvertTo<Array>(params[0]); if (strMethod == "createrawtransaction" && n > 1) ConvertTo<Object>(params[1]); if (strMethod == "signrawtransaction" && n > 1) ConvertTo<Array>(params[1], true); if (strMethod == "signrawtransaction" && n > 2) ConvertTo<Array>(params[2], true); return params; } int CommandLineRPC(int argc, char *argv[]) { string strPrint; int nRet = 0; try { // Skip switches while (argc > 1 && IsSwitchChar(argv[1][0])) { argc--; argv++; } // Method if (argc < 2) throw runtime_error("too few parameters"); string strMethod = argv[1]; // Parameters default to strings std::vector<std::string> strParams(&argv[2], &argv[argc]); Array params = RPCConvertValues(strMethod, strParams); // Execute Object reply = CallRPC(strMethod, params); // Parse reply const Value& result = find_value(reply, "result"); const Value& error = find_value(reply, "error"); if (error.type() != null_type) { // Error strPrint = "error: " + write_string(error, false); int code = find_value(error.get_obj(), "code").get_int(); nRet = abs(code); } else { // Result if (result.type() == null_type) strPrint = ""; else if (result.type() == str_type) strPrint = result.get_str(); else strPrint = write_string(result, true); } } catch (std::exception& e) { strPrint = string("error: ") + e.what(); nRet = 87; } catch (...) { PrintException(NULL, "CommandLineRPC()"); } if (strPrint != "") { fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str()); } return nRet; } #ifdef TEST int main(int argc, char *argv[]) { #ifdef _MSC_VER // Turn off Microsoft heap dump noise _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); _CrtSetReportFile(_CRT_WARN, CreateFile("NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0)); #endif setbuf(stdin, NULL); setbuf(stdout, NULL); setbuf(stderr, NULL); try { if (argc >= 2 && string(argv[1]) == "-server") { printf("server ready\n"); ThreadRPCServer(NULL); } else { return CommandLineRPC(argc, argv); } } catch (std::exception& e) { PrintException(&e, "main()"); } catch (...) { PrintException(NULL, "main()"); } return 0; } #endif const CRPCTable tableRPC;
; A199750: 2*11^n+1. ; 3,23,243,2663,29283,322103,3543123,38974343,428717763,4715895383,51874849203,570623341223,6276856753443,69045424287863,759499667166483,8354496338831303,91899459727144323,1010894056998587543,11119834626984462963,122318180896829092583,1345499989865120018403,14800499888516320202423,162805498773679522226643,1790860486510474744493063,19699465351615222189423683,216694118867767444083660503,2383635307545441884920265523,26219988382999860734122920743,288419872212998468075352128163 mov $1,11 pow $1,$0 sub $1,1 mul $1,2 add $1,3 mov $0,$1
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r12 push %r13 push %rax push %rbp push %rcx push %rdi push %rsi lea addresses_D_ht+0x7206, %rsi lea addresses_UC_ht+0x1d46a, %rdi clflush (%rsi) nop nop nop nop and %r13, %r13 mov $88, %rcx rep movsw nop nop nop nop nop add $61143, %rbp lea addresses_WC_ht+0xf286, %rsi lea addresses_D_ht+0xdcde, %rdi nop nop nop nop sub %r12, %r12 mov $42, %rcx rep movsw nop nop and %rcx, %rcx lea addresses_WC_ht+0x1bc96, %r13 nop cmp $63329, %r10 and $0xffffffffffffffc0, %r13 movaps (%r13), %xmm0 vpextrq $1, %xmm0, %rsi nop nop add $54332, %r12 lea addresses_WT_ht+0x1f76, %rdi xor %rcx, %rcx movb (%rdi), %r13b nop nop nop nop and %r13, %r13 lea addresses_A_ht+0x1267a, %rbp nop nop nop nop nop xor $56093, %r10 mov (%rbp), %rdi nop nop nop nop nop and $57440, %r13 lea addresses_D_ht+0x18fe6, %r10 and %r12, %r12 mov $0x6162636465666768, %rdi movq %rdi, %xmm0 and $0xffffffffffffffc0, %r10 movntdq %xmm0, (%r10) nop nop dec %rbp lea addresses_normal_ht+0x13386, %rsi lea addresses_WC_ht+0x12d26, %rdi clflush (%rdi) nop cmp %rbp, %rbp mov $104, %rcx rep movsl and $61947, %rcx lea addresses_UC_ht+0x12206, %r10 nop xor %r12, %r12 movb $0x61, (%r10) cmp $52731, %r13 lea addresses_WT_ht+0x1be66, %rsi add %r13, %r13 movw $0x6162, (%rsi) add $63432, %r13 lea addresses_UC_ht+0x13476, %rdi nop inc %r10 mov (%rdi), %ebp nop nop add $47120, %r12 lea addresses_UC_ht+0xbee6, %rsi lea addresses_WC_ht+0x3886, %rdi sub %rax, %rax mov $5, %rcx rep movsq nop nop nop nop nop dec %rcx lea addresses_WT_ht+0x6f06, %rsi lea addresses_WT_ht+0x17b86, %rdi nop nop nop nop cmp $26930, %r10 mov $59, %rcx rep movsw nop nop nop nop nop dec %rcx lea addresses_UC_ht+0xc2a6, %r12 nop nop nop nop nop inc %r13 mov (%r12), %ax nop nop nop nop sub $58932, %rbp lea addresses_normal_ht+0xde06, %rsi lea addresses_A_ht+0x4c66, %rdi nop nop nop add %r12, %r12 mov $61, %rcx rep movsw nop nop nop nop nop sub %r12, %r12 pop %rsi pop %rdi pop %rcx pop %rbp pop %rax pop %r13 pop %r12 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r12 push %r8 push %rbp push %rbx push %rsi // Faulty Load lea addresses_WC+0xa606, %rbp and $39428, %r8 mov (%rbp), %esi lea oracles, %rbp and $0xff, %rsi shlq $12, %rsi mov (%rbp,%rsi,1), %rsi pop %rsi pop %rbx pop %rbp pop %r8 pop %r12 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'size': 2, 'NT': False, 'type': 'addresses_WC', 'same': False, 'AVXalign': False, 'congruent': 0}} [Faulty Load] {'OP': 'LOAD', 'src': {'size': 4, 'NT': False, 'type': 'addresses_WC', 'same': True, 'AVXalign': False, 'congruent': 0}} <gen_prepare_buffer> {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_D_ht', 'congruent': 9}, 'dst': {'same': False, 'type': 'addresses_UC_ht', 'congruent': 0}} {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_WC_ht', 'congruent': 6}, 'dst': {'same': False, 'type': 'addresses_D_ht', 'congruent': 3}} {'OP': 'LOAD', 'src': {'size': 16, 'NT': False, 'type': 'addresses_WC_ht', 'same': False, 'AVXalign': True, 'congruent': 4}} {'OP': 'LOAD', 'src': {'size': 1, 'NT': False, 'type': 'addresses_WT_ht', 'same': False, 'AVXalign': False, 'congruent': 4}} {'OP': 'LOAD', 'src': {'size': 8, 'NT': False, 'type': 'addresses_A_ht', 'same': False, 'AVXalign': False, 'congruent': 2}} {'OP': 'STOR', 'dst': {'size': 16, 'NT': True, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 4}} {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_normal_ht', 'congruent': 6}, 'dst': {'same': False, 'type': 'addresses_WC_ht', 'congruent': 4}} {'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_UC_ht', 'same': False, 'AVXalign': False, 'congruent': 8}} {'OP': 'STOR', 'dst': {'size': 2, 'NT': False, 'type': 'addresses_WT_ht', 'same': False, 'AVXalign': False, 'congruent': 5}} {'OP': 'LOAD', 'src': {'size': 4, 'NT': False, 'type': 'addresses_UC_ht', 'same': False, 'AVXalign': False, 'congruent': 3}} {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_UC_ht', 'congruent': 2}, 'dst': {'same': False, 'type': 'addresses_WC_ht', 'congruent': 5}} {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_WT_ht', 'congruent': 6}, 'dst': {'same': False, 'type': 'addresses_WT_ht', 'congruent': 5}} {'OP': 'LOAD', 'src': {'size': 2, 'NT': False, 'type': 'addresses_UC_ht', 'same': False, 'AVXalign': False, 'congruent': 5}} {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_normal_ht', 'congruent': 11}, 'dst': {'same': False, 'type': 'addresses_A_ht', 'congruent': 4}} {'00': 21829} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */ class Solution { public: TreeNode* buildTree(vector<int>& inorder, vector<int>& postorder) { if (inorder.size() == 0) return NULL; unordered_map<int, int> in_idx; for (int i = 0; i < inorder.size(); ++i) { in_idx[inorder[i]] = i; } int root_idx = postorder.size() - 1; return build(inorder, postorder, in_idx, 0, inorder.size() - 1, root_idx); } private: TreeNode* build(vector<int>& inorder, vector<int>& postorder, unordered_map<int, int>& in_idx, int in_l, int in_r, int& root_idx) { if (in_l > in_r) return NULL; TreeNode* node = new TreeNode(postorder[root_idx]); --root_idx; if (in_l == in_r) return node; int in_root_idx = in_idx[node->val]; node->right = build(inorder, postorder, in_idx, in_root_idx + 1, in_r, root_idx); node->left = build(inorder, postorder, in_idx, in_l, in_root_idx - 1, root_idx); return node; } };
;---------------------------------------------------------------------- ; dup2.asm - user-callable entry point to dup2() function. ;---------------------------------------------------------------------- ; ; C/C++ Run Time Library - Version 10.0 ; ; Copyright (c) 1991, 2000 by Inprise Corporation ; All Rights Reserved. ; ; $Revision: 9.0 $ include rules.asi include entry.inc Entry@ dup2, __dup2, _RTLENTRY, 8 end
; A047360: Numbers that are congruent to {1, 2, 3} mod 7. ; 1,2,3,8,9,10,15,16,17,22,23,24,29,30,31,36,37,38,43,44,45,50,51,52,57,58,59,64,65,66,71,72,73,78,79,80,85,86,87,92,93,94,99,100,101,106,107,108,113,114,115,120,121,122,127,128,129,134,135,136,141 mov $1,$0 div $1,3 mul $1,4 add $0,$1 add $0,1
;; ;; Title: Random number generators. ;; .zp seed .ds 1 .code ;; ;; Function: rand8_seed ;; Set pseudo-random number seed. ;; ;; Parameters: ;; A - Seed. rand8_seed: cmp #$00 bne @store lda #$b8 @store: sta <seed rts ;; ;; Function: rand8 ;; Generates 8-bit pseudo-random number. ;; ;; Parameters: ;; seed - Pseudo-random number generator seed. ;; ;; Return: ;; A - Pseud-random number. ;; rand8: lda <seed beq @rand8_xor asl A beq @rand8_store bcc @rand8_store @rand8_xor: eor #$1d @rand8_store: sta <seed rts
; process ; CALLEE linkage for long2ipstring ; int long2ipstring_callee(inet_addr_t *addr, char *str); PUBLIC long2ipstring_callee PUBLIC ASMDISP_LONG2IPSTRING_CALLEE include "spectranet.asm" .long2ipstring_callee pop bc ; return address pop de ; char *str pop hl ; inet_addr_t *addr push bc ; restore return address .asmentry IXCALL LONG2IPSTRING_ROM ret defc ASMDISP_LONG2IPSTRING_CALLEE = asmentry - long2ipstring_callee
Name: zel_sut1.asm Type: file Size: 67203 Last-Modified: '2016-05-13T04:20:48Z' SHA-1: EC74D956A544DE4AC0058BD1F3142094A50C254E Description: null
/** * @file nsga2.hpp * @author Sayan Goswami * * NSGA-II is a multi-objective optimization algorithm, widely used in * many real-world applications. NSGA-II generates offsprings using * crossover and mutation and then selects the next generation according * to non-dominated-sorting and crowding distance comparison. * * ensmallen is free software; you may redistribute it and/or modify it under * the terms of the 3-clause BSD license. You should have received a copy of * the 3-clause BSD license along with ensmallen. If not, see * http://www.opensource.org/licenses/BSD-3-Clause for more information. */ #ifndef ENSMALLEN_NSGA2_NSGA2_HPP #define ENSMALLEN_NSGA2_NSGA2_HPP namespace ens { /** * NSGA-II (Non-dominated Sorting Genetic Algorithm - II) is a multi-objective * optimization algorithm. This class implements the NSGA-II algorithm. * * The algorithm works by generating a candidate population from a fixed * starting point. At each stage of optimization, a new population of children * is generated. This new population along with its predecessor is sorted using * non-domination as the metric. Following this, the population is further * segregated in fronts. A new population is generated from these fronts having * size equal to that of the starting population. * * During evolution, two parents are randomly chosen using binary tournament * selection. A pair of children are generated by crossing over these two * candidates followed by mutation. * * The best front (Pareto optimal) is returned by the Optimize() method. * * For more information, see the following: * * @code * @article{10.1109/4235.996017, * author = {Deb, K. and Pratap, A. and Agarwal, S. and Meyarivan, T.}, * title = {A Fast and Elitist Multiobjective Genetic Algorithm: NSGA-II}, * year = {2002}, * url = {https://doi.org/10.1109/4235.996017}, * journal = {Trans. Evol. Comp}} * @endcode * * NSGA-II can optimize arbitrary multi-objective functions. For more details, * see the documentation on function types included with this distribution or * on the ensmallen website. */ class NSGA2 { public: /** * Constructor for the NSGA2 optimizer. * * The default values provided over here are not necessarily suitable for a * given function. Therefore it is highly recommended to adjust the * parameters according to the problem. * * @param populationSize The number of candidates in the population. * This should be atleast 4 in size and a multiple of 4. * @param maxGenerations The maximum number of generations allowed for NSGA-II. * @param crossoverProb The probability that a crossover will occur. * @param mutationProb The probability that a mutation will occur. * @param mutationStrength The strength of the mutation. * @param epsilon The minimum difference required to distinguish between * candidate solutions. * @param lowerBound Lower bound of the coordinates of the initial population. * @param upperBound Upper bound of the coordinates of the initial population. */ NSGA2(const size_t populationSize = 100, const size_t maxGenerations = 2000, const double crossoverProb = 0.6, const double mutationProb = 0.3, const double mutationStrength = 1e-3, const double epsilon = 1e-6, const arma::vec& lowerBound = arma::zeros(1, 1), const arma::vec& upperBound = arma::ones(1, 1)); /** * Constructor for the NSGA2 optimizer. This constructor provides an overload * to use `lowerBound` and `upperBound` of type double. * * The default values provided over here are not necessarily suitable for a * given function. Therefore it is highly recommended to adjust the * parameters according to the problem. * * @param populationSize The number of candidates in the population. * This should be atleast 4 in size and a multiple of 4. * @param maxGenerations The maximum number of generations allowed for NSGA-II. * @param crossoverProb The probability that a crossover will occur. * @param mutationProb The probability that a mutation will occur. * @param mutationStrength The strength of the mutation. * @param epsilon The minimum difference required to distinguish between * candidate solutions. * @param lowerBound Lower bound of the coordinates of the initial population. * @param upperBound Upper bound of the coordinates of the initial population. */ NSGA2(const size_t populationSize = 100, const size_t maxGenerations = 2000, const double crossoverProb = 0.6, const double mutationProb = 0.3, const double mutationStrength = 1e-3, const double epsilon = 1e-6, const double lowerBound = 0, const double upperBound = 1); /** * Optimize a set of objectives. The initial population is generated using the * starting point. The output is the best generated front. * * @tparam ArbitraryFunctionType std::tuple of multiple objectives. * @tparam MatType Type of matrix to optimize. * @tparam CallbackTypes Types of callback functions. * @param objectives Vector of objective functions to optimize for. * @param iterate Starting point. * @param callbacks Callback functions. * @return MatType::elem_type The minimum of the accumulated sum over the * objective values in the best front. */ template<typename MatType, typename... ArbitraryFunctionType, typename... CallbackTypes> typename MatType::elem_type Optimize( std::tuple<ArbitraryFunctionType...>& objectives, MatType& iterate, CallbackTypes&&... callbacks); //! Get the population size. size_t PopulationSize() const { return populationSize; } //! Modify the population size. size_t& PopulationSize() { return populationSize; } //! Get the maximum number of generations. size_t MaxGenerations() const { return maxGenerations; } //! Modify the maximum number of generations. size_t& MaxGenerations() { return maxGenerations; } //! Get the crossover rate. double CrossoverRate() const { return crossoverProb; } //! Modify the crossover rate. double& CrossoverRate() { return crossoverProb; } //! Get the mutation probability. double MutationProbability() const { return mutationProb; } //! Modify the mutation probability. double& MutationProbability() { return mutationProb; } //! Get the mutation strength. double MutationStrength() const { return mutationStrength; } //! Modify the mutation strength. double& MutationStrength() { return mutationStrength; } //! Get the tolerance. double Epsilon() const { return epsilon; } //! Modify the tolerance. double& Epsilon() { return epsilon; } //! Retrieve value of lowerBound. const arma::vec& LowerBound() const { return lowerBound; } //! Modify value of lowerBound. arma::vec& LowerBound() { return lowerBound; } //! Retrieve value of upperBound. const arma::vec& UpperBound() const { return upperBound; } //! Modify value of upperBound. arma::vec& UpperBound() { return upperBound; } //! Retrieve the best front (the Pareto frontier). This returns an empty vector until `Optimize()` //! has been called. const std::vector<arma::mat>& Front() const { return bestFront; } private: /** * Evaluate objectives for the elite population. * * @tparam ArbitraryFunctionType std::tuple of multiple function types. * @tparam MatType Type of matrix to optimize. * @param population The elite population. * @param objectives The set of objectives. * @param calculatedObjectives Vector to store calculated objectives. */ template<std::size_t I = 0, typename MatType, typename ...ArbitraryFunctionType> typename std::enable_if<I == sizeof...(ArbitraryFunctionType), void>::type EvaluateObjectives(std::vector<MatType>&, std::tuple<ArbitraryFunctionType...>&, std::vector<arma::Col<double> >&); template<std::size_t I = 0, typename MatType, typename ...ArbitraryFunctionType> typename std::enable_if<I < sizeof...(ArbitraryFunctionType), void>::type EvaluateObjectives(std::vector<MatType>& population, std::tuple<ArbitraryFunctionType...>& objectives, std::vector<arma::Col<double> >& calculatedObjectives); /** * Reproduce candidates from the elite population to generate a new * population. * * @tparam MatType Type of matrix to optimize. * @param population The elite population. * @param objectives The set of objectives. * @param lowerBound Lower bound of the coordinates of the initial population. * @param upperBound Upper bound of the coordinates of the initial population. */ template<typename MatType> void BinaryTournamentSelection(std::vector<MatType>& population, const arma::vec& lowerBound, const arma::vec& upperBound); /** * Crossover two parents to create a pair of new children. * * @tparam MatType Type of matrix to optimize. * @param childA A newly generated candidate. * @param childB Another newly generated candidate. * @param parentA First parent from elite population. * @param parentB Second parent from elite population. */ template<typename MatType> void Crossover(MatType& childA, MatType& childB, const MatType& parentA, const MatType& parentB); /** * Mutate the coordinates for a candidate. * * @tparam MatType Type of matrix to optimize. * @param child The candidate whose coordinates are being modified. * @param objectives The set of objectives. * @param lowerBound Lower bound of the coordinates of the initial population. * @param upperBound Upper bound of the coordinates of the initial population. */ template<typename MatType> void Mutate(MatType& child, const arma::vec& lowerBound, const arma::vec& upperBound); /** * Sort the candidate population using their domination count and the set of * dominated nodes. * * @tparam MatType Type of matrix to optimize. * @param fronts The population is sorted into these Pareto fronts. The first * front is the best, the second worse and so on. * @param ranks The assigned ranks, used for crowding distance based sorting. * @param calculatedObjectives The previously calculated objectives. */ template<typename MatType> void FastNonDominatedSort( std::vector<std::vector<size_t> >& fronts, std::vector<size_t>& ranks, std::vector<arma::Col<typename MatType::elem_type> >& calculatedObjectives); /** * Operator to check if one candidate Pareto-dominates the other. * * A candidate is said to dominate the other if it is at least as good as the * other candidate for all the objectives and there exists at least one * objective for which it is strictly better than the other candidate. * * @tparam MatType Type of matrix to optimize. * @param calculatedObjectives The previously calculated objectives. * @param candidateP The candidate being compared from the elite population. * @param candidateQ The candidate being compared against. * @return true if candidateP Pareto dominates candidateQ, otherwise, false. */ template<typename MatType> bool Dominates( std::vector<arma::Col<typename MatType::elem_type> >& calculatedObjectives, size_t candidateP, size_t candidateQ); /** * Assigns crowding distance metric for sorting. * * @param front The previously generated Pareto fronts. * @param objectives The set of objectives. * @param crowdingDistance The previously calculated objectives. */ void CrowdingDistanceAssignment(const std::vector<size_t>& front, std::vector<double>& crowdingDistance); /** * The operator used in the crowding distance based sorting. * * If a candidates has a lower rank then it is preferred. * Otherwise, if the ranks are equal then the candidate with the larger * crowding distance is preferred. * * @param idxP The index of the first cadidate from the elite population being * sorted. * @param idxQ The index of the second cadidate from the elite population * being sorted. * @param ranks The previously calculated ranks. * @param crowdingDistance The previously calculated objectives. * @return true if the first candidate is preferred, otherwise, false. */ bool CrowdingOperator(size_t idxP, size_t idxQ, const std::vector<size_t>& ranks, const std::vector<double>& crowdingDistance); //! The number of objectives being optimised for. size_t numObjectives; //! The numbeer of variables used per objectives. size_t numVariables; //! The number of candidates in the population. size_t populationSize; //! Maximum number of generations before termination criteria is met. size_t maxGenerations; //! Probability that crossover will occur. double crossoverProb; //! Probability that mutation will occur. double mutationProb; //! Strength of the mutation. double mutationStrength; //! The tolerance for termination. double epsilon; //! Lower bound of the initial swarm. arma::vec lowerBound; //! Upper bound of the initial swarm. arma::vec upperBound; //! Best front, stored after Optimize() is called. std::vector<arma::mat> bestFront; }; } // namespace ens // Include implementation. #include "nsga2_impl.hpp" #endif
; A266591: Middle column of the "Rule 37" elementary cellular automaton starting with a single ON (black) cell. ; Submitted by Christian Krause ; 1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0 trn $0,2 add $0,1 mod $0,2
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r15 push %rax push %rcx lea addresses_D_ht+0x1864b, %rax nop nop nop nop nop cmp $61538, %rcx mov (%rax), %r15 nop nop nop nop dec %r10 pop %rcx pop %rax pop %r15 pop %r10 ret .global s_faulty_load s_faulty_load: push %r12 push %r13 push %r14 push %r15 push %rbp push %rbx push %rdx // Store lea addresses_A+0xcbfb, %r12 clflush (%r12) nop nop nop nop xor %r13, %r13 mov $0x5152535455565758, %r15 movq %r15, %xmm6 vmovups %ymm6, (%r12) nop nop sub %rbp, %rbp // Store lea addresses_WC+0x290b, %r12 nop nop nop nop cmp %rbx, %rbx movl $0x51525354, (%r12) nop nop nop nop dec %rbx // Load lea addresses_normal+0x1884b, %r14 nop inc %r15 mov (%r14), %rbp nop nop nop nop xor $33012, %rbx // Load lea addresses_D+0x1a15f, %r15 nop nop nop nop nop add $9910, %r13 movntdqa (%r15), %xmm5 vpextrq $1, %xmm5, %rdx dec %rbx // Store mov $0x97b, %rdx and %r15, %r15 movb $0x51, (%rdx) nop nop nop nop xor %r13, %r13 // Load lea addresses_WC+0x1f14b, %rdx cmp $49, %r12 mov (%rdx), %r15 nop nop xor %r12, %r12 // Faulty Load lea addresses_RW+0x1a64b, %rbx clflush (%rbx) nop nop nop and $19784, %r14 movb (%rbx), %r13b lea oracles, %rbx and $0xff, %r13 shlq $12, %r13 mov (%rbx,%r13,1), %r13 pop %rdx pop %rbx pop %rbp pop %r15 pop %r14 pop %r13 pop %r12 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_RW', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'type': 'addresses_A', 'AVXalign': False, 'size': 32, 'NT': False, 'same': False, 'congruent': 2}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC', 'AVXalign': True, 'size': 4, 'NT': False, 'same': False, 'congruent': 6}} {'src': {'type': 'addresses_normal', 'AVXalign': True, 'size': 8, 'NT': False, 'same': False, 'congruent': 7}, 'OP': 'LOAD'} {'src': {'type': 'addresses_D', 'AVXalign': False, 'size': 16, 'NT': True, 'same': False, 'congruent': 1}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'type': 'addresses_P', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 4}} {'src': {'type': 'addresses_WC', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 7}, 'OP': 'LOAD'} [Faulty Load] {'src': {'type': 'addresses_RW', 'AVXalign': True, 'size': 1, 'NT': False, 'same': True, 'congruent': 0}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'size': 8, 'NT': False, 'same': False, 'congruent': 10}, 'OP': 'LOAD'} {'32': 10} 32 32 32 32 32 32 32 32 32 32 */
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r14 push %r8 push %rax push %rbx push %rdi push %rdx lea addresses_D_ht+0x3d70, %r14 nop nop add %rbx, %rbx vmovups (%r14), %ymm5 vextracti128 $1, %ymm5, %xmm5 vpextrq $0, %xmm5, %rax nop nop nop inc %r8 lea addresses_WC_ht+0x57e0, %r12 nop nop nop nop dec %rdi mov (%r12), %eax nop nop nop cmp %rbx, %rbx lea addresses_D_ht+0x7714, %rbx nop nop nop nop cmp %rdx, %rdx movups (%rbx), %xmm5 vpextrq $1, %xmm5, %r8 nop xor $59301, %r12 pop %rdx pop %rdi pop %rbx pop %rax pop %r8 pop %r14 pop %r12 ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %r9 push %rbx push %rcx push %rdi push %rsi // Load lea addresses_UC+0x3b5c, %r12 nop nop nop and $21069, %rcx mov (%r12), %esi nop sub $46370, %rbx // REPMOV lea addresses_normal+0x115e0, %rsi lea addresses_normal+0x39e0, %rdi clflush (%rdi) nop cmp $59417, %r9 mov $102, %rcx rep movsb sub $14846, %r9 // Faulty Load mov $0x52d7900000009e0, %rbx nop nop and $16383, %rcx vmovaps (%rbx), %ymm6 vextracti128 $0, %ymm6, %xmm6 vpextrq $1, %xmm6, %rsi lea oracles, %rdi and $0xff, %rsi shlq $12, %rsi mov (%rdi,%rsi,1), %rsi pop %rsi pop %rdi pop %rcx pop %rbx pop %r9 pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_NC', 'same': False, 'size': 2, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_UC', 'same': False, 'size': 4, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_normal', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_normal', 'congruent': 10, 'same': False}, 'OP': 'REPM'} [Faulty Load] {'src': {'type': 'addresses_NC', 'same': True, 'size': 32, 'congruent': 0, 'NT': False, 'AVXalign': True}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_D_ht', 'same': False, 'size': 32, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 4, 'congruent': 6, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_D_ht', 'same': False, 'size': 16, 'congruent': 2, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'00': 171, 'ff': 8} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff 00 ff */
.global s_prepare_buffers s_prepare_buffers: ret .global s_faulty_load s_faulty_load: push %r12 push %r14 push %r15 push %rbx push %rdi push %rsi // Faulty Load lea addresses_PSE+0x17c51, %rsi nop nop nop inc %r14 movups (%rsi), %xmm6 vpextrq $0, %xmm6, %r12 lea oracles, %rdi and $0xff, %r12 shlq $12, %r12 mov (%rdi,%r12,1), %r12 pop %rsi pop %rdi pop %rbx pop %r15 pop %r14 pop %r12 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'33': 124} 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 */
; A153026: a(1)=0, a(n) = n^3 - a(n-1). ; 0,8,19,45,80,136,207,305,424,576,755,973,1224,1520,1855,2241,2672,3160,3699,4301,4960,5688,6479,7345,8280,9296,10387,11565,12824,14176,15615,17153,18784,20520,22355,24301,26352,28520,30799,33201,35720,38368,41139,44045,47080,50256,53567,57025,60624,64376,68275,72333,76544,80920,85455,90161,95032,100080,105299,110701,116280,122048,127999,134145,140480,147016,153747,160685,167824,175176,182735,190513,198504,206720,215155,223821,232712,241840,251199,260801,270640,280728,291059,301645,312480,323576,334927,346545,358424,370576,382995,395693,408664,421920,435455,449281,463392,477800,492499,507501,522800,538408,554319,570545,587080,603936,621107,638605,656424,674576,693055,711873,731024,750520,770355,790541,811072,831960,853199,874801,896760,919088,941779,964845,988280,1012096,1036287,1060865,1085824,1111176,1136915,1163053,1189584,1216520,1243855,1271601,1299752,1328320,1357299,1386701,1416520,1446768,1477439,1508545,1540080,1572056,1604467,1637325,1670624,1704376,1738575,1773233,1808344,1843920,1879955,1916461,1953432,1990880,2028799,2067201,2106080,2145448,2185299,2225645,2266480,2307816,2349647,2391985,2434824,2478176,2522035,2566413,2611304,2656720,2702655,2749121,2796112,2843640,2891699,2940301,2989440,3039128,3089359,3140145,3191480,3243376,3295827,3348845,3402424,3456576,3511295,3566593,3622464,3678920,3735955,3793581,3851792,3910600,3969999,4030001,4090600,4151808,4213619,4276045,4339080,4402736,4467007,4531905,4597424,4663576,4730355,4797773,4865824,4934520,5003855,5073841,5144472,5215760,5287699,5360301,5433560,5507488,5582079,5657345,5733280,5809896,5887187,5965165,6043824,6123176,6203215,6283953,6365384,6447520,6530355,6613901,6698152,6783120,6868799,6955201,7042320,7130168,7218739,7308045,7398080,7488856,7580367,7672625,7765624,7859376 mov $4,$0 mov $6,2 lpb $6 clr $0,4 mov $0,$4 sub $6,1 add $0,$6 lpb $0 mov $1,$0 sub $0,2 pow $1,3 add $3,$1 lpe mov $1,$3 mov $7,$6 lpb $7 mov $5,$1 sub $7,1 lpe lpe lpb $4 mov $4,0 sub $5,$1 lpe mov $1,$5
#include "common/generate_tone.h" #include <cmath> #include <cstddef> #include <vector> namespace vrt::common { /** * Generate tone signal in vector. * * \param n Number of elements to generate. * \param fc Center frequency [Hz]. * \param sr Sample rate [Hz]. * * \return Generated signal tone. */ std::vector<float> generate_tone(uint64_t n, float fc, float sr) { // M_PI is nonstandard :( const float PI{3.1415926F}; std::vector<float> v(n); for (size_t i{0}; i < v.size(); ++i) { v[i] = std::sin(2.0F * PI * fc * static_cast<float>(i) / sr); } return v; } } // namespace vrt::common
; ; jidctint.asm - accurate integer IDCT (64-bit SSE2) ; ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB ; Copyright 2009 D. R. Commander ; ; Based on ; 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 ; ; This file contains a slow-but-accurate integer implementation of the ; inverse DCT (Discrete Cosine Transform). The following code is based ; directly on the IJG's original jidctint.c; see the jidctint.c for ; more details. ; ; [TAB8] %include "jsimdext.inc" %include "jdct.inc" ; -------------------------------------------------------------------------- %define CONST_BITS 13 %define PASS1_BITS 2 %define DESCALE_P1 (CONST_BITS-PASS1_BITS) %define DESCALE_P2 (CONST_BITS+PASS1_BITS+3) %if CONST_BITS == 13 F_0_298 equ 2446 ; FIX(0.298631336) F_0_390 equ 3196 ; FIX(0.390180644) F_0_541 equ 4433 ; FIX(0.541196100) F_0_765 equ 6270 ; FIX(0.765366865) F_0_899 equ 7373 ; FIX(0.899976223) F_1_175 equ 9633 ; FIX(1.175875602) F_1_501 equ 12299 ; FIX(1.501321110) F_1_847 equ 15137 ; FIX(1.847759065) F_1_961 equ 16069 ; FIX(1.961570560) F_2_053 equ 16819 ; FIX(2.053119869) F_2_562 equ 20995 ; FIX(2.562915447) F_3_072 equ 25172 ; FIX(3.072711026) %else ; NASM cannot do compile-time arithmetic on floating-point constants. %define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) F_0_298 equ DESCALE( 320652955,30-CONST_BITS) ; FIX(0.298631336) F_0_390 equ DESCALE( 418953276,30-CONST_BITS) ; FIX(0.390180644) F_0_541 equ DESCALE( 581104887,30-CONST_BITS) ; FIX(0.541196100) F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865) F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223) F_1_175 equ DESCALE(1262586813,30-CONST_BITS) ; FIX(1.175875602) F_1_501 equ DESCALE(1612031267,30-CONST_BITS) ; FIX(1.501321110) F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065) F_1_961 equ DESCALE(2106220350,30-CONST_BITS) ; FIX(1.961570560) F_2_053 equ DESCALE(2204520673,30-CONST_BITS) ; FIX(2.053119869) F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447) F_3_072 equ DESCALE(3299298341,30-CONST_BITS) ; FIX(3.072711026) %endif ; -------------------------------------------------------------------------- SECTION SEG_CONST alignz 16 global EXTN(jconst_idct_islow_sse2) EXTN(jconst_idct_islow_sse2): PW_F130_F054 times 4 dw (F_0_541+F_0_765), F_0_541 PW_F054_MF130 times 4 dw F_0_541, (F_0_541-F_1_847) PW_MF078_F117 times 4 dw (F_1_175-F_1_961), F_1_175 PW_F117_F078 times 4 dw F_1_175, (F_1_175-F_0_390) PW_MF060_MF089 times 4 dw (F_0_298-F_0_899),-F_0_899 PW_MF089_F060 times 4 dw -F_0_899, (F_1_501-F_0_899) PW_MF050_MF256 times 4 dw (F_2_053-F_2_562),-F_2_562 PW_MF256_F050 times 4 dw -F_2_562, (F_3_072-F_2_562) PD_DESCALE_P1 times 4 dd 1 << (DESCALE_P1-1) PD_DESCALE_P2 times 4 dd 1 << (DESCALE_P2-1) PB_CENTERJSAMP times 16 db CENTERJSAMPLE alignz 16 ; -------------------------------------------------------------------------- SECTION SEG_TEXT BITS 64 ; ; Perform dequantization and inverse DCT on one block of coefficients. ; ; GLOBAL(void) ; jsimd_idct_islow_sse2 (void * dct_table, JCOEFPTR coef_block, ; JSAMPARRAY output_buf, JDIMENSION output_col) ; ; r10 = jpeg_component_info * compptr ; r11 = JCOEFPTR coef_block ; r12 = JSAMPARRAY output_buf ; r13 = JDIMENSION output_col %define original_rbp rbp+0 %define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] %define WK_NUM 12 align 16 global EXTN(jsimd_idct_islow_sse2) EXTN(jsimd_idct_islow_sse2): push rbp mov rax,rsp ; rax = original rbp sub rsp, byte 4 and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits mov [rsp],rax mov rbp,rsp ; rbp = aligned rbp lea rsp, [wk(0)] collect_args ; ---- Pass 1: process columns from input. mov rdx, r10 ; quantptr mov rsi, r11 ; inptr %ifndef NO_ZERO_COLUMN_TEST_ISLOW_SSE2 mov eax, DWORD [DWBLOCK(1,0,rsi,SIZEOF_JCOEF)] or eax, DWORD [DWBLOCK(2,0,rsi,SIZEOF_JCOEF)] jnz near .columnDCT movdqa xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)] movdqa xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)] por xmm0, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)] por xmm1, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)] por xmm0, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)] por xmm1, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)] por xmm0, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)] por xmm1,xmm0 packsswb xmm1,xmm1 packsswb xmm1,xmm1 movd eax,xmm1 test rax,rax jnz short .columnDCT ; -- AC terms all zero movdqa xmm5, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)] pmullw xmm5, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] psllw xmm5,PASS1_BITS movdqa xmm4,xmm5 ; xmm5=in0=(00 01 02 03 04 05 06 07) punpcklwd xmm5,xmm5 ; xmm5=(00 00 01 01 02 02 03 03) punpckhwd xmm4,xmm4 ; xmm4=(04 04 05 05 06 06 07 07) pshufd xmm7,xmm5,0x00 ; xmm7=col0=(00 00 00 00 00 00 00 00) pshufd xmm6,xmm5,0x55 ; xmm6=col1=(01 01 01 01 01 01 01 01) pshufd xmm1,xmm5,0xAA ; xmm1=col2=(02 02 02 02 02 02 02 02) pshufd xmm5,xmm5,0xFF ; xmm5=col3=(03 03 03 03 03 03 03 03) pshufd xmm0,xmm4,0x00 ; xmm0=col4=(04 04 04 04 04 04 04 04) pshufd xmm3,xmm4,0x55 ; xmm3=col5=(05 05 05 05 05 05 05 05) pshufd xmm2,xmm4,0xAA ; xmm2=col6=(06 06 06 06 06 06 06 06) pshufd xmm4,xmm4,0xFF ; xmm4=col7=(07 07 07 07 07 07 07 07) movdqa XMMWORD [wk(8)], xmm6 ; wk(8)=col1 movdqa XMMWORD [wk(9)], xmm5 ; wk(9)=col3 movdqa XMMWORD [wk(10)], xmm3 ; wk(10)=col5 movdqa XMMWORD [wk(11)], xmm4 ; wk(11)=col7 jmp near .column_end %endif .columnDCT: ; -- Even part movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)] movdqa xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)] pmullw xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] pmullw xmm1, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] movdqa xmm2, XMMWORD [XMMBLOCK(4,0,rsi,SIZEOF_JCOEF)] movdqa xmm3, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)] pmullw xmm2, XMMWORD [XMMBLOCK(4,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] pmullw xmm3, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] ; (Original) ; z1 = (z2 + z3) * 0.541196100; ; tmp2 = z1 + z3 * -1.847759065; ; tmp3 = z1 + z2 * 0.765366865; ; ; (This implementation) ; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065); ; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100; movdqa xmm4,xmm1 ; xmm1=in2=z2 movdqa xmm5,xmm1 punpcklwd xmm4,xmm3 ; xmm3=in6=z3 punpckhwd xmm5,xmm3 movdqa xmm1,xmm4 movdqa xmm3,xmm5 pmaddwd xmm4,[rel PW_F130_F054] ; xmm4=tmp3L pmaddwd xmm5,[rel PW_F130_F054] ; xmm5=tmp3H pmaddwd xmm1,[rel PW_F054_MF130] ; xmm1=tmp2L pmaddwd xmm3,[rel PW_F054_MF130] ; xmm3=tmp2H movdqa xmm6,xmm0 paddw xmm0,xmm2 ; xmm0=in0+in4 psubw xmm6,xmm2 ; xmm6=in0-in4 pxor xmm7,xmm7 pxor xmm2,xmm2 punpcklwd xmm7,xmm0 ; xmm7=tmp0L punpckhwd xmm2,xmm0 ; xmm2=tmp0H psrad xmm7,(16-CONST_BITS) ; psrad xmm7,16 & pslld xmm7,CONST_BITS psrad xmm2,(16-CONST_BITS) ; psrad xmm2,16 & pslld xmm2,CONST_BITS movdqa xmm0,xmm7 paddd xmm7,xmm4 ; xmm7=tmp10L psubd xmm0,xmm4 ; xmm0=tmp13L movdqa xmm4,xmm2 paddd xmm2,xmm5 ; xmm2=tmp10H psubd xmm4,xmm5 ; xmm4=tmp13H movdqa XMMWORD [wk(0)], xmm7 ; wk(0)=tmp10L movdqa XMMWORD [wk(1)], xmm2 ; wk(1)=tmp10H movdqa XMMWORD [wk(2)], xmm0 ; wk(2)=tmp13L movdqa XMMWORD [wk(3)], xmm4 ; wk(3)=tmp13H pxor xmm5,xmm5 pxor xmm7,xmm7 punpcklwd xmm5,xmm6 ; xmm5=tmp1L punpckhwd xmm7,xmm6 ; xmm7=tmp1H psrad xmm5,(16-CONST_BITS) ; psrad xmm5,16 & pslld xmm5,CONST_BITS psrad xmm7,(16-CONST_BITS) ; psrad xmm7,16 & pslld xmm7,CONST_BITS movdqa xmm2,xmm5 paddd xmm5,xmm1 ; xmm5=tmp11L psubd xmm2,xmm1 ; xmm2=tmp12L movdqa xmm0,xmm7 paddd xmm7,xmm3 ; xmm7=tmp11H psubd xmm0,xmm3 ; xmm0=tmp12H movdqa XMMWORD [wk(4)], xmm5 ; wk(4)=tmp11L movdqa XMMWORD [wk(5)], xmm7 ; wk(5)=tmp11H movdqa XMMWORD [wk(6)], xmm2 ; wk(6)=tmp12L movdqa XMMWORD [wk(7)], xmm0 ; wk(7)=tmp12H ; -- Odd part movdqa xmm4, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)] movdqa xmm6, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)] pmullw xmm4, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] pmullw xmm6, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] movdqa xmm1, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)] movdqa xmm3, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)] pmullw xmm1, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] pmullw xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_ISLOW_MULT_TYPE)] movdqa xmm5,xmm6 movdqa xmm7,xmm4 paddw xmm5,xmm3 ; xmm5=z3 paddw xmm7,xmm1 ; xmm7=z4 ; (Original) ; z5 = (z3 + z4) * 1.175875602; ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; ; z3 += z5; z4 += z5; ; ; (This implementation) ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); movdqa xmm2,xmm5 movdqa xmm0,xmm5 punpcklwd xmm2,xmm7 punpckhwd xmm0,xmm7 movdqa xmm5,xmm2 movdqa xmm7,xmm0 pmaddwd xmm2,[rel PW_MF078_F117] ; xmm2=z3L pmaddwd xmm0,[rel PW_MF078_F117] ; xmm0=z3H pmaddwd xmm5,[rel PW_F117_F078] ; xmm5=z4L pmaddwd xmm7,[rel PW_F117_F078] ; xmm7=z4H movdqa XMMWORD [wk(10)], xmm2 ; wk(10)=z3L movdqa XMMWORD [wk(11)], xmm0 ; wk(11)=z3H ; (Original) ; z1 = tmp0 + tmp3; z2 = tmp1 + tmp2; ; tmp0 = tmp0 * 0.298631336; tmp1 = tmp1 * 2.053119869; ; tmp2 = tmp2 * 3.072711026; tmp3 = tmp3 * 1.501321110; ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; ; tmp0 += z1 + z3; tmp1 += z2 + z4; ; tmp2 += z2 + z3; tmp3 += z1 + z4; ; ; (This implementation) ; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223; ; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447; ; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447); ; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223); ; tmp0 += z3; tmp1 += z4; ; tmp2 += z3; tmp3 += z4; movdqa xmm2,xmm3 movdqa xmm0,xmm3 punpcklwd xmm2,xmm4 punpckhwd xmm0,xmm4 movdqa xmm3,xmm2 movdqa xmm4,xmm0 pmaddwd xmm2,[rel PW_MF060_MF089] ; xmm2=tmp0L pmaddwd xmm0,[rel PW_MF060_MF089] ; xmm0=tmp0H pmaddwd xmm3,[rel PW_MF089_F060] ; xmm3=tmp3L pmaddwd xmm4,[rel PW_MF089_F060] ; xmm4=tmp3H paddd xmm2, XMMWORD [wk(10)] ; xmm2=tmp0L paddd xmm0, XMMWORD [wk(11)] ; xmm0=tmp0H paddd xmm3,xmm5 ; xmm3=tmp3L paddd xmm4,xmm7 ; xmm4=tmp3H movdqa XMMWORD [wk(8)], xmm2 ; wk(8)=tmp0L movdqa XMMWORD [wk(9)], xmm0 ; wk(9)=tmp0H movdqa xmm2,xmm1 movdqa xmm0,xmm1 punpcklwd xmm2,xmm6 punpckhwd xmm0,xmm6 movdqa xmm1,xmm2 movdqa xmm6,xmm0 pmaddwd xmm2,[rel PW_MF050_MF256] ; xmm2=tmp1L pmaddwd xmm0,[rel PW_MF050_MF256] ; xmm0=tmp1H pmaddwd xmm1,[rel PW_MF256_F050] ; xmm1=tmp2L pmaddwd xmm6,[rel PW_MF256_F050] ; xmm6=tmp2H paddd xmm2,xmm5 ; xmm2=tmp1L paddd xmm0,xmm7 ; xmm0=tmp1H paddd xmm1, XMMWORD [wk(10)] ; xmm1=tmp2L paddd xmm6, XMMWORD [wk(11)] ; xmm6=tmp2H movdqa XMMWORD [wk(10)], xmm2 ; wk(10)=tmp1L movdqa XMMWORD [wk(11)], xmm0 ; wk(11)=tmp1H ; -- Final output stage movdqa xmm5, XMMWORD [wk(0)] ; xmm5=tmp10L movdqa xmm7, XMMWORD [wk(1)] ; xmm7=tmp10H movdqa xmm2,xmm5 movdqa xmm0,xmm7 paddd xmm5,xmm3 ; xmm5=data0L paddd xmm7,xmm4 ; xmm7=data0H psubd xmm2,xmm3 ; xmm2=data7L psubd xmm0,xmm4 ; xmm0=data7H movdqa xmm3,[rel PD_DESCALE_P1] ; xmm3=[rel PD_DESCALE_P1] paddd xmm5,xmm3 paddd xmm7,xmm3 psrad xmm5,DESCALE_P1 psrad xmm7,DESCALE_P1 paddd xmm2,xmm3 paddd xmm0,xmm3 psrad xmm2,DESCALE_P1 psrad xmm0,DESCALE_P1 packssdw xmm5,xmm7 ; xmm5=data0=(00 01 02 03 04 05 06 07) packssdw xmm2,xmm0 ; xmm2=data7=(70 71 72 73 74 75 76 77) movdqa xmm4, XMMWORD [wk(4)] ; xmm4=tmp11L movdqa xmm3, XMMWORD [wk(5)] ; xmm3=tmp11H movdqa xmm7,xmm4 movdqa xmm0,xmm3 paddd xmm4,xmm1 ; xmm4=data1L paddd xmm3,xmm6 ; xmm3=data1H psubd xmm7,xmm1 ; xmm7=data6L psubd xmm0,xmm6 ; xmm0=data6H movdqa xmm1,[rel PD_DESCALE_P1] ; xmm1=[rel PD_DESCALE_P1] paddd xmm4,xmm1 paddd xmm3,xmm1 psrad xmm4,DESCALE_P1 psrad xmm3,DESCALE_P1 paddd xmm7,xmm1 paddd xmm0,xmm1 psrad xmm7,DESCALE_P1 psrad xmm0,DESCALE_P1 packssdw xmm4,xmm3 ; xmm4=data1=(10 11 12 13 14 15 16 17) packssdw xmm7,xmm0 ; xmm7=data6=(60 61 62 63 64 65 66 67) movdqa xmm6,xmm5 ; transpose coefficients(phase 1) punpcklwd xmm5,xmm4 ; xmm5=(00 10 01 11 02 12 03 13) punpckhwd xmm6,xmm4 ; xmm6=(04 14 05 15 06 16 07 17) movdqa xmm1,xmm7 ; transpose coefficients(phase 1) punpcklwd xmm7,xmm2 ; xmm7=(60 70 61 71 62 72 63 73) punpckhwd xmm1,xmm2 ; xmm1=(64 74 65 75 66 76 67 77) movdqa xmm3, XMMWORD [wk(6)] ; xmm3=tmp12L movdqa xmm0, XMMWORD [wk(7)] ; xmm0=tmp12H movdqa xmm4, XMMWORD [wk(10)] ; xmm4=tmp1L movdqa xmm2, XMMWORD [wk(11)] ; xmm2=tmp1H movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=(00 10 01 11 02 12 03 13) movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=(04 14 05 15 06 16 07 17) movdqa XMMWORD [wk(4)], xmm7 ; wk(4)=(60 70 61 71 62 72 63 73) movdqa XMMWORD [wk(5)], xmm1 ; wk(5)=(64 74 65 75 66 76 67 77) movdqa xmm5,xmm3 movdqa xmm6,xmm0 paddd xmm3,xmm4 ; xmm3=data2L paddd xmm0,xmm2 ; xmm0=data2H psubd xmm5,xmm4 ; xmm5=data5L psubd xmm6,xmm2 ; xmm6=data5H movdqa xmm7,[rel PD_DESCALE_P1] ; xmm7=[rel PD_DESCALE_P1] paddd xmm3,xmm7 paddd xmm0,xmm7 psrad xmm3,DESCALE_P1 psrad xmm0,DESCALE_P1 paddd xmm5,xmm7 paddd xmm6,xmm7 psrad xmm5,DESCALE_P1 psrad xmm6,DESCALE_P1 packssdw xmm3,xmm0 ; xmm3=data2=(20 21 22 23 24 25 26 27) packssdw xmm5,xmm6 ; xmm5=data5=(50 51 52 53 54 55 56 57) movdqa xmm1, XMMWORD [wk(2)] ; xmm1=tmp13L movdqa xmm4, XMMWORD [wk(3)] ; xmm4=tmp13H movdqa xmm2, XMMWORD [wk(8)] ; xmm2=tmp0L movdqa xmm7, XMMWORD [wk(9)] ; xmm7=tmp0H movdqa xmm0,xmm1 movdqa xmm6,xmm4 paddd xmm1,xmm2 ; xmm1=data3L paddd xmm4,xmm7 ; xmm4=data3H psubd xmm0,xmm2 ; xmm0=data4L psubd xmm6,xmm7 ; xmm6=data4H movdqa xmm2,[rel PD_DESCALE_P1] ; xmm2=[rel PD_DESCALE_P1] paddd xmm1,xmm2 paddd xmm4,xmm2 psrad xmm1,DESCALE_P1 psrad xmm4,DESCALE_P1 paddd xmm0,xmm2 paddd xmm6,xmm2 psrad xmm0,DESCALE_P1 psrad xmm6,DESCALE_P1 packssdw xmm1,xmm4 ; xmm1=data3=(30 31 32 33 34 35 36 37) packssdw xmm0,xmm6 ; xmm0=data4=(40 41 42 43 44 45 46 47) movdqa xmm7, XMMWORD [wk(0)] ; xmm7=(00 10 01 11 02 12 03 13) movdqa xmm2, XMMWORD [wk(1)] ; xmm2=(04 14 05 15 06 16 07 17) movdqa xmm4,xmm3 ; transpose coefficients(phase 1) punpcklwd xmm3,xmm1 ; xmm3=(20 30 21 31 22 32 23 33) punpckhwd xmm4,xmm1 ; xmm4=(24 34 25 35 26 36 27 37) movdqa xmm6,xmm0 ; transpose coefficients(phase 1) punpcklwd xmm0,xmm5 ; xmm0=(40 50 41 51 42 52 43 53) punpckhwd xmm6,xmm5 ; xmm6=(44 54 45 55 46 56 47 57) movdqa xmm1,xmm7 ; transpose coefficients(phase 2) punpckldq xmm7,xmm3 ; xmm7=(00 10 20 30 01 11 21 31) punpckhdq xmm1,xmm3 ; xmm1=(02 12 22 32 03 13 23 33) movdqa xmm5,xmm2 ; transpose coefficients(phase 2) punpckldq xmm2,xmm4 ; xmm2=(04 14 24 34 05 15 25 35) punpckhdq xmm5,xmm4 ; xmm5=(06 16 26 36 07 17 27 37) movdqa xmm3, XMMWORD [wk(4)] ; xmm3=(60 70 61 71 62 72 63 73) movdqa xmm4, XMMWORD [wk(5)] ; xmm4=(64 74 65 75 66 76 67 77) movdqa XMMWORD [wk(6)], xmm2 ; wk(6)=(04 14 24 34 05 15 25 35) movdqa XMMWORD [wk(7)], xmm5 ; wk(7)=(06 16 26 36 07 17 27 37) movdqa xmm2,xmm0 ; transpose coefficients(phase 2) punpckldq xmm0,xmm3 ; xmm0=(40 50 60 70 41 51 61 71) punpckhdq xmm2,xmm3 ; xmm2=(42 52 62 72 43 53 63 73) movdqa xmm5,xmm6 ; transpose coefficients(phase 2) punpckldq xmm6,xmm4 ; xmm6=(44 54 64 74 45 55 65 75) punpckhdq xmm5,xmm4 ; xmm5=(46 56 66 76 47 57 67 77) movdqa xmm3,xmm7 ; transpose coefficients(phase 3) punpcklqdq xmm7,xmm0 ; xmm7=col0=(00 10 20 30 40 50 60 70) punpckhqdq xmm3,xmm0 ; xmm3=col1=(01 11 21 31 41 51 61 71) movdqa xmm4,xmm1 ; transpose coefficients(phase 3) punpcklqdq xmm1,xmm2 ; xmm1=col2=(02 12 22 32 42 52 62 72) punpckhqdq xmm4,xmm2 ; xmm4=col3=(03 13 23 33 43 53 63 73) movdqa xmm0, XMMWORD [wk(6)] ; xmm0=(04 14 24 34 05 15 25 35) movdqa xmm2, XMMWORD [wk(7)] ; xmm2=(06 16 26 36 07 17 27 37) movdqa XMMWORD [wk(8)], xmm3 ; wk(8)=col1 movdqa XMMWORD [wk(9)], xmm4 ; wk(9)=col3 movdqa xmm3,xmm0 ; transpose coefficients(phase 3) punpcklqdq xmm0,xmm6 ; xmm0=col4=(04 14 24 34 44 54 64 74) punpckhqdq xmm3,xmm6 ; xmm3=col5=(05 15 25 35 45 55 65 75) movdqa xmm4,xmm2 ; transpose coefficients(phase 3) punpcklqdq xmm2,xmm5 ; xmm2=col6=(06 16 26 36 46 56 66 76) punpckhqdq xmm4,xmm5 ; xmm4=col7=(07 17 27 37 47 57 67 77) movdqa XMMWORD [wk(10)], xmm3 ; wk(10)=col5 movdqa XMMWORD [wk(11)], xmm4 ; wk(11)=col7 .column_end: ; -- Prefetch the next coefficient block prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32] prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32] prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32] prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32] ; ---- Pass 2: process rows from work array, store into output array. mov rax, [original_rbp] mov rdi, r12 ; (JSAMPROW *) mov eax, r13d ; -- Even part ; xmm7=col0, xmm1=col2, xmm0=col4, xmm2=col6 ; (Original) ; z1 = (z2 + z3) * 0.541196100; ; tmp2 = z1 + z3 * -1.847759065; ; tmp3 = z1 + z2 * 0.765366865; ; ; (This implementation) ; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065); ; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100; movdqa xmm6,xmm1 ; xmm1=in2=z2 movdqa xmm5,xmm1 punpcklwd xmm6,xmm2 ; xmm2=in6=z3 punpckhwd xmm5,xmm2 movdqa xmm1,xmm6 movdqa xmm2,xmm5 pmaddwd xmm6,[rel PW_F130_F054] ; xmm6=tmp3L pmaddwd xmm5,[rel PW_F130_F054] ; xmm5=tmp3H pmaddwd xmm1,[rel PW_F054_MF130] ; xmm1=tmp2L pmaddwd xmm2,[rel PW_F054_MF130] ; xmm2=tmp2H movdqa xmm3,xmm7 paddw xmm7,xmm0 ; xmm7=in0+in4 psubw xmm3,xmm0 ; xmm3=in0-in4 pxor xmm4,xmm4 pxor xmm0,xmm0 punpcklwd xmm4,xmm7 ; xmm4=tmp0L punpckhwd xmm0,xmm7 ; xmm0=tmp0H psrad xmm4,(16-CONST_BITS) ; psrad xmm4,16 & pslld xmm4,CONST_BITS psrad xmm0,(16-CONST_BITS) ; psrad xmm0,16 & pslld xmm0,CONST_BITS movdqa xmm7,xmm4 paddd xmm4,xmm6 ; xmm4=tmp10L psubd xmm7,xmm6 ; xmm7=tmp13L movdqa xmm6,xmm0 paddd xmm0,xmm5 ; xmm0=tmp10H psubd xmm6,xmm5 ; xmm6=tmp13H movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=tmp10L movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=tmp10H movdqa XMMWORD [wk(2)], xmm7 ; wk(2)=tmp13L movdqa XMMWORD [wk(3)], xmm6 ; wk(3)=tmp13H pxor xmm5,xmm5 pxor xmm4,xmm4 punpcklwd xmm5,xmm3 ; xmm5=tmp1L punpckhwd xmm4,xmm3 ; xmm4=tmp1H psrad xmm5,(16-CONST_BITS) ; psrad xmm5,16 & pslld xmm5,CONST_BITS psrad xmm4,(16-CONST_BITS) ; psrad xmm4,16 & pslld xmm4,CONST_BITS movdqa xmm0,xmm5 paddd xmm5,xmm1 ; xmm5=tmp11L psubd xmm0,xmm1 ; xmm0=tmp12L movdqa xmm7,xmm4 paddd xmm4,xmm2 ; xmm4=tmp11H psubd xmm7,xmm2 ; xmm7=tmp12H movdqa XMMWORD [wk(4)], xmm5 ; wk(4)=tmp11L movdqa XMMWORD [wk(5)], xmm4 ; wk(5)=tmp11H movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=tmp12L movdqa XMMWORD [wk(7)], xmm7 ; wk(7)=tmp12H ; -- Odd part movdqa xmm6, XMMWORD [wk(9)] ; xmm6=col3 movdqa xmm3, XMMWORD [wk(8)] ; xmm3=col1 movdqa xmm1, XMMWORD [wk(11)] ; xmm1=col7 movdqa xmm2, XMMWORD [wk(10)] ; xmm2=col5 movdqa xmm5,xmm6 movdqa xmm4,xmm3 paddw xmm5,xmm1 ; xmm5=z3 paddw xmm4,xmm2 ; xmm4=z4 ; (Original) ; z5 = (z3 + z4) * 1.175875602; ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; ; z3 += z5; z4 += z5; ; ; (This implementation) ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); movdqa xmm0,xmm5 movdqa xmm7,xmm5 punpcklwd xmm0,xmm4 punpckhwd xmm7,xmm4 movdqa xmm5,xmm0 movdqa xmm4,xmm7 pmaddwd xmm0,[rel PW_MF078_F117] ; xmm0=z3L pmaddwd xmm7,[rel PW_MF078_F117] ; xmm7=z3H pmaddwd xmm5,[rel PW_F117_F078] ; xmm5=z4L pmaddwd xmm4,[rel PW_F117_F078] ; xmm4=z4H movdqa XMMWORD [wk(10)], xmm0 ; wk(10)=z3L movdqa XMMWORD [wk(11)], xmm7 ; wk(11)=z3H ; (Original) ; z1 = tmp0 + tmp3; z2 = tmp1 + tmp2; ; tmp0 = tmp0 * 0.298631336; tmp1 = tmp1 * 2.053119869; ; tmp2 = tmp2 * 3.072711026; tmp3 = tmp3 * 1.501321110; ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; ; tmp0 += z1 + z3; tmp1 += z2 + z4; ; tmp2 += z2 + z3; tmp3 += z1 + z4; ; ; (This implementation) ; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223; ; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447; ; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447); ; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223); ; tmp0 += z3; tmp1 += z4; ; tmp2 += z3; tmp3 += z4; movdqa xmm0,xmm1 movdqa xmm7,xmm1 punpcklwd xmm0,xmm3 punpckhwd xmm7,xmm3 movdqa xmm1,xmm0 movdqa xmm3,xmm7 pmaddwd xmm0,[rel PW_MF060_MF089] ; xmm0=tmp0L pmaddwd xmm7,[rel PW_MF060_MF089] ; xmm7=tmp0H pmaddwd xmm1,[rel PW_MF089_F060] ; xmm1=tmp3L pmaddwd xmm3,[rel PW_MF089_F060] ; xmm3=tmp3H paddd xmm0, XMMWORD [wk(10)] ; xmm0=tmp0L paddd xmm7, XMMWORD [wk(11)] ; xmm7=tmp0H paddd xmm1,xmm5 ; xmm1=tmp3L paddd xmm3,xmm4 ; xmm3=tmp3H movdqa XMMWORD [wk(8)], xmm0 ; wk(8)=tmp0L movdqa XMMWORD [wk(9)], xmm7 ; wk(9)=tmp0H movdqa xmm0,xmm2 movdqa xmm7,xmm2 punpcklwd xmm0,xmm6 punpckhwd xmm7,xmm6 movdqa xmm2,xmm0 movdqa xmm6,xmm7 pmaddwd xmm0,[rel PW_MF050_MF256] ; xmm0=tmp1L pmaddwd xmm7,[rel PW_MF050_MF256] ; xmm7=tmp1H pmaddwd xmm2,[rel PW_MF256_F050] ; xmm2=tmp2L pmaddwd xmm6,[rel PW_MF256_F050] ; xmm6=tmp2H paddd xmm0,xmm5 ; xmm0=tmp1L paddd xmm7,xmm4 ; xmm7=tmp1H paddd xmm2, XMMWORD [wk(10)] ; xmm2=tmp2L paddd xmm6, XMMWORD [wk(11)] ; xmm6=tmp2H movdqa XMMWORD [wk(10)], xmm0 ; wk(10)=tmp1L movdqa XMMWORD [wk(11)], xmm7 ; wk(11)=tmp1H ; -- Final output stage movdqa xmm5, XMMWORD [wk(0)] ; xmm5=tmp10L movdqa xmm4, XMMWORD [wk(1)] ; xmm4=tmp10H movdqa xmm0,xmm5 movdqa xmm7,xmm4 paddd xmm5,xmm1 ; xmm5=data0L paddd xmm4,xmm3 ; xmm4=data0H psubd xmm0,xmm1 ; xmm0=data7L psubd xmm7,xmm3 ; xmm7=data7H movdqa xmm1,[rel PD_DESCALE_P2] ; xmm1=[rel PD_DESCALE_P2] paddd xmm5,xmm1 paddd xmm4,xmm1 psrad xmm5,DESCALE_P2 psrad xmm4,DESCALE_P2 paddd xmm0,xmm1 paddd xmm7,xmm1 psrad xmm0,DESCALE_P2 psrad xmm7,DESCALE_P2 packssdw xmm5,xmm4 ; xmm5=data0=(00 10 20 30 40 50 60 70) packssdw xmm0,xmm7 ; xmm0=data7=(07 17 27 37 47 57 67 77) movdqa xmm3, XMMWORD [wk(4)] ; xmm3=tmp11L movdqa xmm1, XMMWORD [wk(5)] ; xmm1=tmp11H movdqa xmm4,xmm3 movdqa xmm7,xmm1 paddd xmm3,xmm2 ; xmm3=data1L paddd xmm1,xmm6 ; xmm1=data1H psubd xmm4,xmm2 ; xmm4=data6L psubd xmm7,xmm6 ; xmm7=data6H movdqa xmm2,[rel PD_DESCALE_P2] ; xmm2=[rel PD_DESCALE_P2] paddd xmm3,xmm2 paddd xmm1,xmm2 psrad xmm3,DESCALE_P2 psrad xmm1,DESCALE_P2 paddd xmm4,xmm2 paddd xmm7,xmm2 psrad xmm4,DESCALE_P2 psrad xmm7,DESCALE_P2 packssdw xmm3,xmm1 ; xmm3=data1=(01 11 21 31 41 51 61 71) packssdw xmm4,xmm7 ; xmm4=data6=(06 16 26 36 46 56 66 76) packsswb xmm5,xmm4 ; xmm5=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76) packsswb xmm3,xmm0 ; xmm3=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77) movdqa xmm6, XMMWORD [wk(6)] ; xmm6=tmp12L movdqa xmm2, XMMWORD [wk(7)] ; xmm2=tmp12H movdqa xmm1, XMMWORD [wk(10)] ; xmm1=tmp1L movdqa xmm7, XMMWORD [wk(11)] ; xmm7=tmp1H movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76) movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77) movdqa xmm4,xmm6 movdqa xmm0,xmm2 paddd xmm6,xmm1 ; xmm6=data2L paddd xmm2,xmm7 ; xmm2=data2H psubd xmm4,xmm1 ; xmm4=data5L psubd xmm0,xmm7 ; xmm0=data5H movdqa xmm5,[rel PD_DESCALE_P2] ; xmm5=[rel PD_DESCALE_P2] paddd xmm6,xmm5 paddd xmm2,xmm5 psrad xmm6,DESCALE_P2 psrad xmm2,DESCALE_P2 paddd xmm4,xmm5 paddd xmm0,xmm5 psrad xmm4,DESCALE_P2 psrad xmm0,DESCALE_P2 packssdw xmm6,xmm2 ; xmm6=data2=(02 12 22 32 42 52 62 72) packssdw xmm4,xmm0 ; xmm4=data5=(05 15 25 35 45 55 65 75) movdqa xmm3, XMMWORD [wk(2)] ; xmm3=tmp13L movdqa xmm1, XMMWORD [wk(3)] ; xmm1=tmp13H movdqa xmm7, XMMWORD [wk(8)] ; xmm7=tmp0L movdqa xmm5, XMMWORD [wk(9)] ; xmm5=tmp0H movdqa xmm2,xmm3 movdqa xmm0,xmm1 paddd xmm3,xmm7 ; xmm3=data3L paddd xmm1,xmm5 ; xmm1=data3H psubd xmm2,xmm7 ; xmm2=data4L psubd xmm0,xmm5 ; xmm0=data4H movdqa xmm7,[rel PD_DESCALE_P2] ; xmm7=[rel PD_DESCALE_P2] paddd xmm3,xmm7 paddd xmm1,xmm7 psrad xmm3,DESCALE_P2 psrad xmm1,DESCALE_P2 paddd xmm2,xmm7 paddd xmm0,xmm7 psrad xmm2,DESCALE_P2 psrad xmm0,DESCALE_P2 movdqa xmm5,[rel PB_CENTERJSAMP] ; xmm5=[rel PB_CENTERJSAMP] packssdw xmm3,xmm1 ; xmm3=data3=(03 13 23 33 43 53 63 73) packssdw xmm2,xmm0 ; xmm2=data4=(04 14 24 34 44 54 64 74) movdqa xmm7, XMMWORD [wk(0)] ; xmm7=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76) movdqa xmm1, XMMWORD [wk(1)] ; xmm1=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77) packsswb xmm6,xmm2 ; xmm6=(02 12 22 32 42 52 62 72 04 14 24 34 44 54 64 74) packsswb xmm3,xmm4 ; xmm3=(03 13 23 33 43 53 63 73 05 15 25 35 45 55 65 75) paddb xmm7,xmm5 paddb xmm1,xmm5 paddb xmm6,xmm5 paddb xmm3,xmm5 movdqa xmm0,xmm7 ; transpose coefficients(phase 1) punpcklbw xmm7,xmm1 ; xmm7=(00 01 10 11 20 21 30 31 40 41 50 51 60 61 70 71) punpckhbw xmm0,xmm1 ; xmm0=(06 07 16 17 26 27 36 37 46 47 56 57 66 67 76 77) movdqa xmm2,xmm6 ; transpose coefficients(phase 1) punpcklbw xmm6,xmm3 ; xmm6=(02 03 12 13 22 23 32 33 42 43 52 53 62 63 72 73) punpckhbw xmm2,xmm3 ; xmm2=(04 05 14 15 24 25 34 35 44 45 54 55 64 65 74 75) movdqa xmm4,xmm7 ; transpose coefficients(phase 2) punpcklwd xmm7,xmm6 ; xmm7=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33) punpckhwd xmm4,xmm6 ; xmm4=(40 41 42 43 50 51 52 53 60 61 62 63 70 71 72 73) movdqa xmm5,xmm2 ; transpose coefficients(phase 2) punpcklwd xmm2,xmm0 ; xmm2=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37) punpckhwd xmm5,xmm0 ; xmm5=(44 45 46 47 54 55 56 57 64 65 66 67 74 75 76 77) movdqa xmm1,xmm7 ; transpose coefficients(phase 3) punpckldq xmm7,xmm2 ; xmm7=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17) punpckhdq xmm1,xmm2 ; xmm1=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37) movdqa xmm3,xmm4 ; transpose coefficients(phase 3) punpckldq xmm4,xmm5 ; xmm4=(40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57) punpckhdq xmm3,xmm5 ; xmm3=(60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77) pshufd xmm6,xmm7,0x4E ; xmm6=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07) pshufd xmm0,xmm1,0x4E ; xmm0=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27) pshufd xmm2,xmm4,0x4E ; xmm2=(50 51 52 53 54 55 56 57 40 41 42 43 44 45 46 47) pshufd xmm5,xmm3,0x4E ; xmm5=(70 71 72 73 74 75 76 77 60 61 62 63 64 65 66 67) mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW] mov rsi, JSAMPROW [rdi+2*SIZEOF_JSAMPROW] movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm7 movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm1 mov rdx, JSAMPROW [rdi+4*SIZEOF_JSAMPROW] mov rsi, JSAMPROW [rdi+6*SIZEOF_JSAMPROW] movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm4 movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm3 mov rdx, JSAMPROW [rdi+1*SIZEOF_JSAMPROW] mov rsi, JSAMPROW [rdi+3*SIZEOF_JSAMPROW] movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm6 movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm0 mov rdx, JSAMPROW [rdi+5*SIZEOF_JSAMPROW] mov rsi, JSAMPROW [rdi+7*SIZEOF_JSAMPROW] movq XMM_MMWORD [rdx+rax*SIZEOF_JSAMPLE], xmm2 movq XMM_MMWORD [rsi+rax*SIZEOF_JSAMPLE], xmm5 uncollect_args mov rsp,rbp ; rsp <- aligned rbp pop rsp ; rsp <- original rbp 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
; A138102: The number 2*k^2 repeated 2*k^2 times, k=1 to 4. ; 2,2,8,8,8,8,8,8,8,8,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32 add $0,1 lpb $0 add $2,2 add $1,$2 trn $0,$1 add $2,2 lpe mov $0,$1
; L1503.asm ; Generated 03.08.2001 by mlevel ; Modified 03.08.2001 by Abe Pralle INCLUDE "Source/Defs.inc" INCLUDE "Source/Levels.inc" VAR_DESTZONE EQU 0 VAR_DESTCOLOR EQU 1 VAR_DESTBG EQU 3 VAR_DESTBANK EQU 5 VAR_SELSTAGE EQU 6 ;--------------------------------------------------------------------- SECTION "Level1503Gfx1",ROMX ;--------------------------------------------------------------------- downramp_bg:: INCBIN "Data/Cinema/Distress/downramp.bg" downramp_sprites_sp: INCBIN "Data/Cinema/Distress/downramp_sprites.sp" ;--------------------------------------------------------------------- SECTION "Level1503Gfx2",ROMX ;--------------------------------------------------------------------- flower_and_flour_establishing_bg: INCBIN "Data/Cinema/Distress/flower_and_flour_establishing.bg" flour_and_flower_bg: INCBIN "Data/Cinema/Distress/flour_and_flower.bg" ;--------------------------------------------------------------------- SECTION "Level1503Section",ROMX ;--------------------------------------------------------------------- L1503_Contents:: DW L1503_Load DW L1503_Init DW L1503_Check DW L1503_Map ;--------------------------------------------------------------------- ; Load ;--------------------------------------------------------------------- L1503_Load: DW ((L1503_LoadFinished - L1503_Load2)) ;size L1503_Load2: ld a,1 ld [displayType],a xor a ld [scrollSprites],a ld a,1 call Delay ld de,((.landingOnKiwi-L1503_Load2)+levelCheckRAM) call SetDialogForward ld de,((.endCinema-L1503_Load2)+levelCheckRAM) call SetDialogSkip .flying ld a,BANK(cloud0_bg) ld hl,cloud0_bg call LoadCinemaBG ld a,1 call Delay ld a,15 call ((.setupFadeToClouds-L1503_Load2)+levelCheckRAM) ld b,50 ld c,1 .cloudAnim ;load next cloud frame ld d,0 ;de = c*4 ld e,c sla e rl d sla e rl d ld hl,((.cloudFrames-L1503_Load2)+levelCheckRAM) add hl,de ld a,[hl+] ;mem bank of cloud frame inc hl push af ld a,[hl+] ld h,[hl] ld l,a pop af call LoadCinemaBG ;ld a,1 ;call Delay call ((.animateWave-L1503_Load2)+levelCheckRAM) ld a,c inc a and 7 ld c,a ld a,b cp 20 jr nz,.afterStartFadeOutInClouds ld a,15 call ((.setupFadeToSky-L1503_Load2)+levelCheckRAM) .afterStartFadeOutInClouds dec b jr nz,.cloudAnim ld a,3 ld [levelVars+VAR_SELSTAGE],a call ((.setPowerBar-L1503_Load2)+levelCheckRAM) ;----Load picture of new landing zone--------------------------------- ld hl,levelVars+VAR_DESTBANK ld a,[hl-] push af ld a,[hl-] ld l,[hl] ld h,a pop af call LoadCinemaBG ld a,1 call Delay ld a,FADEBANK ld [$ff70],a ld hl,gamePalette ld de,fadeFinalPalette call FadeCommonCopyPalette ld a,1 call FadeInit call WaitFade ld a,2 call Delay ld a,190 ldio [jiggleDuration],a ld a,1 ldio [jiggleType],a ;take-off jiggle ld a,18 ld [camera_j],a ld a,$11 ldio [scrollSpeed],a ld a,[amLinkMaster] bit 7,a jr nz,.afterRemoteAppx .addRemoteAppx ld a,LCHANGEAPPXMAP call ExchangeByte call CheckSimultaneousLCC jr nz,.addRemoteAppx ;must repeat ld a,[appomattoxMapIndex] call TransmitByte .afterRemoteAppx ld hl,musicEnabled ;disable track 4 res 3,[hl] ld hl,((.engineSound1-L1503_Load2)+levelCheckRAM) call PlaySound ld a,40 call ((.delayAdjustHorizon-L1503_Load2)+levelCheckRAM) ld a,2 ld [levelVars+VAR_SELSTAGE],a call ((.setPowerBar-L1503_Load2)+levelCheckRAM) ld a,15 call ((.delayAdjustHorizon-L1503_Load2)+levelCheckRAM) ld a,1 ld [levelVars+VAR_SELSTAGE],a call ((.setPowerBar-L1503_Load2)+levelCheckRAM) ;ld hl,((.engineSound2-L1503_Load2)+levelCheckRAM) ;call PlaySound ;ld a,30 ;call ((.delayAdjustHorizon-L1503_Load2)+levelCheckRAM) ;xor a ;ld [levelVars+VAR_SELSTAGE],a ;call ((.setPowerBar-L1503_Load2)+levelCheckRAM) ;ld a,30 ;call ((.delayAdjustHorizon-L1503_Load2)+levelCheckRAM) ;ld hl,musicEnabled ;enable track 4 ;set 3,[hl] ;call ((.powerDown-L1503_Load2)+levelCheckRAM) ;----------------landing on kiwi----------------------- .landingOnKiwi xor a ldio [jiggleDuration],a call ((.delay2-L1503_Load2)+levelCheckRAM) call BlackoutPalette call ClearDialog call ResetSprites call ((.delay2-L1503_Load2)+levelCheckRAM) ld a,BANK(landing_bg_bg) ld hl,landing_bg_bg call LoadCinemaBG ld a,BANK(landing_sprites_sp) ld hl,landing_sprites_sp call LoadCinemaSprite ld d,16 call ScrollSpritesRight ld d,48 call ScrollSpritesUp ;set landing gear sprites and flame to off ld hl,spriteOAMBuffer+6 ld c,8 xor a .init_landing_loop ld [hl+],a inc hl inc hl inc hl dec c jr nz,.init_landing_loop ld de,((.ramp-L1503_Load2)+levelCheckRAM) call SetDialogForward ;----------------animate descent of appomattox ;landing gear stowed ld a,1 call SetupFadeFromBlack ld b,60 .descent1 push bc ld a,1 call Delay ld d,1 call ((.scrollAllSpritesDown-L1503_Load2)+levelCheckRAM) pop bc dec b jr nz,.descent1 ;landing gear half-out ld hl,spriteOAMBuffer+(9*4)+2 ld c,4 ld a,2 .gear_half_loop ld [hl+],a ;change tile index inc hl inc hl inc hl add 2 dec c jr nz,.gear_half_loop ld b,5 .descent2 push bc call ((.delay2-L1503_Load2)+levelCheckRAM) ld d,1 call ((.scrollAllSpritesDown-L1503_Load2)+levelCheckRAM) pop bc dec b jr nz,.descent2 ;landing gear full out ld hl,spriteOAMBuffer+(9*4)+2 ld c,4 ld a,10 .gear_full_loop ld [hl+],a ;change tile index inc hl inc hl inc hl add 2 dec c jr nz,.gear_full_loop ld b,20 .descent3 push bc call ((.delay2-L1503_Load2)+levelCheckRAM) ld d,1 call ((.scrollAllSpritesDown-L1503_Load2)+levelCheckRAM) pop bc dec b jr nz,.descent3 ;engine noise fade to off ld hl,((.engineSound2-L1503_Load2)+levelCheckRAM) call PlaySound ld b,10 .descent4 push bc ld a,3 call Delay ld d,1 call ((.scrollAllSpritesDown-L1503_Load2)+levelCheckRAM) pop bc dec b jr nz,.descent4 ld a,30 call Delay ;----Walking down the landing ramp------------------------------------ .ramp call BlackoutPalette call ResetSprites ld a,BANK(downramp_bg) ld hl,downramp_bg call LoadCinemaBG ld a,BANK(downramp_sprites_sp) ld hl,downramp_sprites_sp call LoadCinemaSprite call ((.quickFromBlack-L1503_Load2)+levelCheckRAM) ld de,((.establishing-L1503_Load2)+levelCheckRAM) call SetDialogForward ld a,BANK(lady_flower_gbm) ld hl,lady_flower_gbm call InitMusic ld a,30 call Delay ld c,9 .walkDownRamp ;second frame ld a,8 call ((.animateRampSprites-L1503_Load2)+levelCheckRAM) ld d,2 call ScrollSpritesRight ld d,1 call ScrollSpritesDown ld a,5 call Delay ;first frame xor a call ((.animateRampSprites-L1503_Load2)+levelCheckRAM) ld d,2 call ScrollSpritesRight ld d,1 call ScrollSpritesDown ld a,5 call Delay dec c jr nz,.walkDownRamp ld a,30 call Delay .establishing call BlackoutPalette call ResetSprites call LoadFont ld a,BANK(flower_and_flour_establishing_bg) ld hl,flower_and_flour_establishing_bg call LoadCinemaBG call ((.quickFromBlack-L1503_Load2)+levelCheckRAM) ld de,((.talking-L1503_Load2)+levelCheckRAM) call SetDialogForward ld a,60 call Delay .talking ld a,$21 ldio [scrollSpeed],a call BlackoutPalette ld a,BANK(flour_and_flower_bg) ld hl,flour_and_flower_bg call LoadCinemaBG call ((.quickFromBlack-L1503_Load2)+levelCheckRAM) ld de,((.nostuff-L1503_Load2)+levelCheckRAM) call SetDialogForward ld a,BANK(lady_stay_gtx) ld [dialogBank],a ld c,0 DIALOGBOTTOM lady_stay_gtx ld d,3 LONGCALLNOARGS AnimateLadyFlowerRamp .nostuff call ((.panToCaptain-L1503_Load2)+levelCheckRAM) ld c,0 DIALOGBOTTOM captain_nostuff_gtx ld de,((.please-L1503_Load2)+levelCheckRAM) call SetDialogForward ld d,3 LONGCALLNOARGS AnimateCaptainRamp .please call ((.panToLady-L1503_Load2)+levelCheckRAM) ld c,0 DIALOGBOTTOM lady_please_gtx ld de,((.nothanks-L1503_Load2)+levelCheckRAM) call SetDialogForward ld d,3 LONGCALLNOARGS AnimateLadyFlowerRamp .nothanks call ((.panToCaptain-L1503_Load2)+levelCheckRAM) ld c,0 DIALOGBOTTOM captain_nothanks_gtx ld de,((.must-L1503_Load2)+levelCheckRAM) call SetDialogForward ld d,2 LONGCALLNOARGS AnimateCaptainRamp .must ;call StopMusic ;ld hl,((.buzzerSound-L1503_Load2)+levelCheckRAM) ;call PlaySound ld a,$41 ldio [scrollSpeed],a call ((.panToLady-L1503_Load2)+levelCheckRAM) ;ld a,30 ;call Delay ;ld a,15 ;ldio [jiggleDuration],a ld c,0 DIALOGBOTTOM lady_must_gtx ld de,((.no-L1503_Load2)+levelCheckRAM) call SetDialogForward ld d,2 LONGCALLNOARGS AnimateLadyFlowerRamp .no call ((.panToCaptain-L1503_Load2)+levelCheckRAM) ld c,0 DIALOGBOTTOM captain_no_gtx ld de,((.insist-L1503_Load2)+levelCheckRAM) call SetDialogForward ld d,2 LONGCALLNOARGS AnimateCaptainRamp .insist ld a,$82 ldio [scrollSpeed],a call ((.panToLady-L1503_Load2)+levelCheckRAM) ld c,0 DIALOGBOTTOM lady_insist_gtx ld de,((.okay-L1503_Load2)+levelCheckRAM) call SetDialogForward ld d,2 LONGCALLNOARGS AnimateLadyFlowerRamp .okay .endCinema call BlackoutPalette call ClearDialog call ResetSprites LDHL_CURHERODATA HERODATA_ENTERDIR ld a,EXIT_N ld [hl],a ld hl,$1504 ld a,l ld [curLevelIndex],a ld a,h ld [curLevelIndex+1],a ld a,2 ld [timeToChangeLevel],a ret .panToCaptain ld a,21 ld [camera_i],a ld a,23 ld [camera_j],a ret .panToLady xor a ld [camera_i],a ld [camera_j],a ret .animateRampSprites push bc ld hl,spriteOAMBuffer+2 ld de,4 ld c,4 .animateRampSpritesLoop ld [hl],a add hl,de add 2 dec c jr nz,.animateRampSpritesLoop pop bc ret .powerDown ;xor a ;ld [levelVars+VAR_SELSTAGE],a call ((.setPowerBar-L1503_Load2)+levelCheckRAM) call ((.recticleOff-L1503_Load2)+levelCheckRAM) call ((.horizonOff-L1503_Load2)+levelCheckRAM) call ((.diagramOff-L1503_Load2)+levelCheckRAM) ld a,30 call ((.delayAnimateWave-L1503_Load2)+levelCheckRAM) ret .setPowerBar ld a,[levelVars+VAR_SELSTAGE] inc a ld [musicRegisters+0],a dec a rlca ;sprite = stage*4 + 44 rlca add 44 ld hl,spriteOAMBuffer+22*4+2 ld [hl+],a inc hl inc hl inc hl add 2 ld [hl],a ret .horizonOff ld de,4 xor a ld hl,spriteOAMBuffer+16*4 ld c,4 .horizonOffLoop ld [hl],a add hl,de dec c jr nz,.horizonOffLoop ret .recticleOff ld de,4 xor a ld hl,spriteOAMBuffer+8*4 ld c,8 .recticleOffLoop ld [hl],a add hl,de dec c jr nz,.recticleOffLoop ret .diagramOff ld hl,spriteOAMBuffer+20*4 ld [hl],160 ld hl,spriteOAMBuffer+21*4 ld [hl],160 ret .delayAdjustHorizon ld c,a ld hl,spriteOAMBuffer+16*4 ld de,4 .delayLoop call ((.animateWave-L1503_Load2)+levelCheckRAM) ld a,1 call Delay ;horizon = 58 - ((mapTop*8+desiredPixelOffset_y)/4) ld a,[mapTop] rlca rlca rlca ld b,a ld a,[desiredPixelOffset_y] add b srl a srl a cpl add 59 push hl ld b,4 .alterHorizonSpriteLoop ld [hl],a add hl,de dec b jr nz,.alterHorizonSpriteLoop pop hl dec c jr nz,.delayLoop ret .setupFadeFromSky push af ld a,FADEBANK ld [$ff70],a ;set final palette bg7 to be bg7 color 0 ld hl,gamePalette ld de,fadeCurPalette call FadeCommonCopyPalette ld de,fadeFinalPalette call FadeCommonCopyPalette ld hl,fadeFinalPalette+8*7 ld a,$80 ld c,a ld b,$7d ld hl,fadeFinalPalette+8*7 call ((.setBG7-L1503_Load2)+levelCheckRAM) pop af call FadeInit ret .setBG7 ;copy bc to 4 entries at palette hl ld hl,fadeFinalPalette+8*7 ld a,4 .setBG7Loop ld [hl],c inc hl ld [hl],b inc hl dec a jr nz,.setBG7Loop ret .setupFadeToSky push bc push de push hl push af ld hl,gamePalette ld de,fadeCurPalette call FadeCommonCopyPalette ld de,fadeFinalPalette call FadeCommonCopyPalette ld hl,levelVars+VAR_DESTZONE ld a,[hl+] ld [appomattoxMapIndex],a ld a,[hl+] ld b,[hl] ld c,a ld hl,fadeCurPalette+8*7 call ((.setBG7-L1503_Load2)+levelCheckRAM) pop af call FadeInit pop hl pop de pop bc ret .defaultSkyColor ld bc,$7e20 ret .setupFadeToClouds push af ld a,FADEBANK ld [$ff70],a ld hl,gamePalette ld de,fadeFinalPalette call FadeCommonCopyPalette ;set all colors to be $7d80 ld hl,fadeCurPalette ld c,64 .setAll7d80 ld [hl],$80 inc hl ld [hl],$7d inc hl dec c jr nz,.setAll7d80 pop af call FadeInit ret .cloudFrames DW BANK(cloud0_bg), cloud0_bg, BANK(cloud1_bg), cloud1_bg DW BANK(cloud2_bg), cloud2_bg, BANK(cloud3_bg), cloud3_bg DW BANK(cloud4_bg), cloud4_bg, BANK(cloud5_bg), cloud5_bg DW BANK(cloud6_bg), cloud6_bg, BANK(cloud7_bg), cloud7_bg .engineSound1 DB 4,$00,$df,$a9,$80 ;looping/infinite .engineSound2 DB 4,$00,$d7,$a9,$80 ;fades .byte8 DB 8 .delayAnimateWave push af call ((.animateWave-L1503_Load2)+levelCheckRAM) ld a,1 call Delay pop af dec a jr nz,.delayAnimateWave ret .animateWave push bc push de push hl PUSHROM ld a,BANK(appwaves0_dat) call SetActiveROM ld a,[levelVars+VAR_SELSTAGE] ;a=stage*8 + frame*2 rlca rlca rlca ld b,a ldio a,[vblankTimer] and %11000 rrca rrca or b add (((.waveFrameTable-L1503_Load2)+levelCheckRAM) & $ff) ld l,a ld a,0 adc ((((.waveFrameTable-L1503_Load2)+levelCheckRAM)>>8) & $ff) ld h,a ld a,[hl+] ld h,[hl] ld l,a ld de,$9420 ld c,40 ld a,1 call VMemCopy POPROM pop hl pop de pop bc ret .waveFrameTable DW appwaves0_dat,appwaves0_dat+640,appwaves0_dat+640*2,appwaves0_dat+640*3 DW appwaves1_dat,appwaves1_dat+640,appwaves1_dat+640*2,appwaves1_dat+640*3 DW appwaves2_dat,appwaves2_dat+640,appwaves2_dat+640*2,appwaves2_dat+640*3 DW appwaves3_dat,appwaves3_dat+640,appwaves3_dat+640*2,appwaves3_dat+640*3 DW appwaves4_dat,appwaves4_dat+640,appwaves4_dat+640*2,appwaves4_dat+640*3 .scrollAllSpritesDown push bc push de push hl ld hl,spriteOAMBuffer ld c,35 .scrollDownLoop ld a,[hl] add d ld [hl+],a inc hl inc hl inc hl dec c jr nz,.scrollDownLoop pop hl pop de pop bc ret .quickFromBlack ld a,1 jp SetupFadeFromBlack .delay2 ld a,2 jp Delay L1503_LoadFinished: ;--------------------------------------------------------------------- ; Map ;--------------------------------------------------------------------- L1503_Map: ;--------------------------------------------------------------------- ; Init ;--------------------------------------------------------------------- L1503_Init: DW ((L1503_InitFinished - L1503_Init2)) ;size L1503_Init2: ret L1503_InitFinished: ;--------------------------------------------------------------------- ; Check ;--------------------------------------------------------------------- L1503_Check: DW ((L1503_CheckFinished - L1503_Check2)) ;size L1503_Check2: ret L1503_CheckFinished: PRINT "1503 Script Sizes (Load/Init/Check) (of $500): " PRINT (L1503_LoadFinished - L1503_Load2) PRINT " / " PRINT (L1503_InitFinished - L1503_Init2) PRINT " / " PRINT (L1503_CheckFinished - L1503_Check2) PRINT "\n"
; A114119: Row sums of triangle A114118. ; 1,3,5,6,8,9,11,12,14,15,17,18,20,21,23,24,26,27,29,30,32,33,35,36,38,39,41,42,44,45,47,48,50,51,53,54,56,57,59,60,62,63,65,66,68,69,71,72,74,75,77,78,80,81,83,84,86,87,89,90,92,93,95,96,98,99,101,102,104,105 mov $1,$0 mul $0,2 sub $1,1 div $1,2 sub $0,$1 add $0,1
; A156718: Numbers k such that k^2 == -1 (mod 13^2). ; 70,99,239,268,408,437,577,606,746,775,915,944,1084,1113,1253,1282,1422,1451,1591,1620,1760,1789,1929,1958,2098,2127,2267,2296,2436,2465,2605,2634,2774,2803,2943,2972,3112,3141,3281,3310,3450,3479,3619,3648,3788,3817,3957,3986,4126,4155,4295,4324,4464,4493,4633,4662,4802,4831,4971,5000,5140,5169,5309,5338,5478,5507,5647,5676,5816,5845,5985,6014,6154,6183,6323,6352,6492,6521,6661,6690,6830,6859,6999,7028,7168,7197,7337,7366,7506,7535,7675,7704,7844,7873,8013,8042,8182,8211,8351,8380,8520,8549,8689,8718,8858,8887,9027,9056,9196,9225,9365,9394,9534,9563,9703,9732,9872,9901,10041,10070,10210,10239,10379,10408,10548,10577,10717,10746,10886,10915,11055,11084,11224,11253,11393,11422,11562,11591,11731,11760,11900,11929,12069,12098,12238,12267,12407,12436,12576,12605,12745,12774,12914,12943,13083,13112,13252,13281,13421,13450,13590,13619,13759,13788,13928,13957,14097,14126,14266,14295,14435,14464,14604,14633,14773,14802,14942,14971,15111,15140,15280,15309,15449,15478,15618,15647,15787,15816,15956,15985,16125,16154,16294,16323,16463,16492,16632,16661,16801,16830,16970,16999,17139,17168,17308,17337,17477,17506,17646,17675,17815,17844,17984,18013,18153,18182,18322,18351,18491,18520,18660,18689,18829,18858,18998,19027,19167,19196,19336,19365,19505,19534,19674,19703,19843,19872,20012,20041,20181,20210,20350,20379,20519,20548,20688,20717,20857,20886,21026,21055 mov $3,$0 mov $4,$0 mov $5,$0 mov $0,3 mul $0,$4 div $0,6 gcd $5,2 pow $5,$5 mul $5,6 add $0,$5 add $0,2 mul $0,3 mov $1,$0 sub $1,8 mov $2,$3 mul $2,83 add $1,$2
#include "format/json.hpp" #include <parsium/common/tag/throw.hpp> #include <parsium/mckeeman/formatting.hpp> #include <parsium/mckeeman/parser.hpp> #include <iostream> #include <sstream> using namespace parsium; using namespace parsium::mckeeman; std::string formatted(const builder::Grammar& g, const MultiHead& mh) { auto ss = std::stringstream(); ss << "heads = {\n"; for(auto& head : mh.heads) { ss << " "; auto rule = mh.base_rule; for(auto& cursor : head.nested_cursors) { ss << name(*rule).string << "/"; auto alternative_index = index_of_or(*rule, *cursor.alternative, _throw); ss << alternative_index << "/" << cursor.item_index << "/"; auto& item = current_item(cursor); if(auto literal = literal_or(item, nullptr)) { ss << head.character_index; } else if(auto name = name_or(item, nullptr)) { rule = rule_or(g, *name, nullptr); } else { throw PreconditionViolation(); } } ss << "\n"; } ss << "}\n"; return ss.str(); } std::string formatted(const parser::Parser& p) { auto ss = std::stringstream(); ss << "is_accepting = " << is_accepting(p) << ",\n"; ss << formatted(p.grammar(), p.multi_head_); return ss.str(); } void throwing_main() { auto format = format::json(); auto json_parser = parser::Parser(rule_or(*format, builder::Name("json"), _throw)); std::cout << formatted(json_parser) << std::endl; std::cout << "> " << std::flush; for(int c = std::getchar(); c != '!'; c = std::getchar()) { if(c == '\n') { continue; } feed(json_parser, char(c)); std::cout << formatted(json_parser) << std::endl; std::cout << "> " << std::flush; } } int main() { try { throwing_main(); return 0; } catch(parsium::Exception) { std::cerr << "Unhandled Parsium exception." << std::endl; return -1; } catch(...) { std::cerr << "Unhandled exception." << std::endl; return -1; } }
; A341055: Inverse permutation to A341054. ; Submitted by Christian Krause ; 0,1,4,2,3,12,13,11,5,6,7,10,8,9,36,37,35,38,39,40,34,32,33,15,16,14,17,18,19,22,20,21,30,31,29,23,24,25,28,26,27,108,109,107,110,111,112,106,104,105,114,115,113,116,117,118,121,119,120,102,103,101,95,96,97,100,98,99,45,46,44,47,48,49,43,41,42,51,52,50,53,54,55,58,56,57,66,67,65,59,60,61,64,62,63,90,91,89,92,93 mov $2,1 lpb $0 add $0,1 mov $3,$0 div $0,3 sub $3,$0 mod $3,3 mul $3,$2 add $1,$3 sub $1,$2 mul $2,3 lpe mov $0,$1
; A211440: Number of ordered triples (w,x,y) with all terms in {-n,...,0,...,n} and 2w+3x+3y=0. ; 1,3,5,17,23,29,53,63,73,109,123,137,185,203,221,281,303,325,397,423,449,533,563,593,689,723,757,865,903,941,1061,1103,1145,1277,1323,1369,1513,1563,1613,1769,1823,1877,2045,2103,2161,2341,2403,2465,2657,2723,2789,2993,3063,3133,3349,3423,3497,3725,3803,3881,4121,4203,4285,4537,4623,4709,4973,5063,5153,5429,5523,5617,5905,6003,6101,6401,6503,6605,6917,7023,7129,7453,7563,7673,8009,8123,8237,8585,8703,8821,9181,9303,9425,9797,9923,10049,10433,10563,10693,11089,11223,11357,11765,11903,12041,12461,12603,12745,13177,13323,13469,13913,14063,14213,14669,14823,14977,15445,15603,15761,16241,16403,16565,17057,17223,17389,17893,18063,18233,18749,18923,19097,19625,19803,19981,20521,20703,20885,21437,21623,21809,22373,22563,22753,23329,23523,23717,24305,24503,24701,25301,25503,25705,26317,26523,26729,27353,27563,27773,28409,28623,28837,29485,29703,29921,30581,30803,31025,31697,31923,32149,32833,33063,33293,33989,34223,34457,35165,35403,35641,36361,36603,36845,37577,37823,38069,38813,39063,39313,40069,40323,40577,41345,41603,41861,42641,42903,43165,43957,44223,44489,45293,45563,45833,46649,46923,47197,48025,48303,48581,49421,49703,49985,50837,51123,51409,52273,52563,52853,53729,54023,54317,55205,55503,55801,56701,57003,57305,58217,58523,58829,59753,60063,60373,61309,61623,61937,62885,63203,63521,64481,64803,65125,66097,66423,66749,67733,68063,68393,69389 mov $4,$0 mov $5,$0 add $0,1 add $0,$4 mul $0,2 mov $2,$0 lpb $0,1 sub $0,7 trn $0,5 mov $1,$3 sub $2,4 add $3,$2 lpe add $1,6 lpb $5,1 add $1,2 sub $5,1 lpe sub $1,5
; int isgreater(real-floating x, real-floating y) SECTION code_clib SECTION code_fp_math48 PUBLIC am48_isgreater EXTERN am48_dgt ; Return bool (AC > AC') ; ; enter : AC = double x ; AC' = double y ; ; exit : HL = 0 and carry reset if false ; HL = 1 and carry set if true ; ; uses : af, hl defc am48_isgreater = am48_dgt
TITLE Segment Example (main module, Seg2.asm) EXTRN var2:WORD, subroutine_1:PROC cseg SEGMENT BYTE PUBLIC 'CODE' ASSUME cs:cseg,ds:dseg, ss:sseg main PROC mov ax,dseg ; initialize DS mov ds,ax mov ax,var1 ; local variable mov bx,var2 ; external variable call subroutine_1 ; external procedure mov ax,4C00h ; exit to OS int 21h main ENDP cseg ENDS dseg SEGMENT WORD PUBLIC 'DATA' ; local data segment var1 WORD 1000h dseg ends sseg SEGMENT STACK 'STACK' ; stack segment BYTE 100h dup('S') sseg ENDS END main
; A199474: Leftmost column in the monotonic justified array of all positive generalized Fibonacci sequences (A160271). ; Submitted by Jamie Morken(s2) ; 1,2,3,2,4,3,5,4,3,6,5,4,7,6,5,4,8,7,6,5,9,8,7,6,5,10,9,8,7,6,11,10,9,8,7,6,12,11,10,9,8,7,13,12,11,10,9,8,7,14,13,12,11,10,9,8,15,14,13,12,11,10,9,8,16,15,14,13,12,11,10,9,17,16,15,14 lpb $0 cmp $4,0 add $3,$4 sub $0,$3 add $2,1 lpe sub $2,$0 mov $0,$2 add $0,1
; t10-challenge-1.0-HOT-TOPIC.asm ; Write a program to determine the number of positive & ; negative numbers in a list LIST DB 12, 29, -9, 5, -48, 20 MOV SI, 0 MOV CX, 6 L1: CMP LIST[SI], 0 JE L2 JG L3 INC CNTN ; > 0 JMP L2 L3: INC CNTP ; <0 L2: INC SI LOOP L1 MOV AH, 02H
; A158064: a(n) = 36*n^2 + 2*n. ; 38,148,330,584,910,1308,1778,2320,2934,3620,4378,5208,6110,7084,8130,9248,10438,11700,13034,14440,15918,17468,19090,20784,22550,24388,26298,28280,30334,32460,34658,36928,39270,41684,44170,46728,49358,52060,54834,57680,60598,63588,66650,69784,72990,76268,79618,83040,86534,90100,93738,97448,101230,105084,109010,113008,117078,121220,125434,129720,134078,138508,143010,147584,152230,156948,161738,166600,171534,176540,181618,186768,191990,197284,202650,208088,213598,219180,224834,230560,236358,242228,248170,254184,260270,266428,272658,278960,285334,291780,298298,304888,311550,318284,325090,331968,338918,345940,353034,360200 add $0,1 mul $0,18 add $0,1 bin $0,2 div $0,9 mul $0,2
; A094875: a(n)=1 if floor(Pi*10^n) is prime, otherwise a(n)=0. ; Submitted by Jon Maiga ; 1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 lpb $0 gcd $0,20165 mov $2,20165 lpe mov $0,$2 add $0,1 mod $0,2
// Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "irc.h" #include "net.h" #include "strlcpy.h" #include "base58.h" using namespace std; using namespace boost; int nGotIRCAddresses = 0; void ThreadIRCSeed2(void* parg); #pragma pack(push, 1) struct ircaddr { struct in_addr ip; short port; }; #pragma pack(pop) string EncodeAddress(const CService& addr) { struct ircaddr tmp; if (addr.GetInAddr(&tmp.ip)) { tmp.port = htons(addr.GetPort()); vector<unsigned char> vch(UBEGIN(tmp), UEND(tmp)); return string("u") + EncodeBase58Check(vch); } return ""; } bool DecodeAddress(string str, CService& addr) { vector<unsigned char> vch; if (!DecodeBase58Check(str.substr(1), vch)) return false; struct ircaddr tmp; if (vch.size() != sizeof(tmp)) return false; memcpy(&tmp, &vch[0], sizeof(tmp)); addr = CService(tmp.ip, ntohs(tmp.port)); return true; } static bool Send(SOCKET hSocket, const char* pszSend) { if (strstr(pszSend, "PONG") != pszSend) printf("IRC SENDING: %s\n", pszSend); const char* psz = pszSend; const char* pszEnd = psz + strlen(psz); while (psz < pszEnd) { int ret = send(hSocket, psz, pszEnd - psz, MSG_NOSIGNAL); if (ret < 0) return false; psz += ret; } return true; } bool RecvLineIRC(SOCKET hSocket, string& strLine) { while (true) { bool fRet = RecvLine(hSocket, strLine); if (fRet) { if (fShutdown) return false; vector<string> vWords; ParseString(strLine, ' ', vWords); if (vWords.size() >= 1 && vWords[0] == "PING") { strLine[1] = 'O'; strLine += '\r'; Send(hSocket, strLine.c_str()); continue; } } return fRet; } } int RecvUntil(SOCKET hSocket, const char* psz1, const char* psz2=NULL, const char* psz3=NULL, const char* psz4=NULL) { while (true) { string strLine; strLine.reserve(10000); if (!RecvLineIRC(hSocket, strLine)) return 0; printf("IRC %s\n", strLine.c_str()); if (psz1 && strLine.find(psz1) != string::npos) return 1; if (psz2 && strLine.find(psz2) != string::npos) return 2; if (psz3 && strLine.find(psz3) != string::npos) return 3; if (psz4 && strLine.find(psz4) != string::npos) return 4; } } bool Wait(int nSeconds) { if (fShutdown) return false; printf("IRC waiting %d seconds to reconnect\n", nSeconds); for (int i = 0; i < nSeconds; i++) { if (fShutdown) return false; MilliSleep(1000); } return true; } bool RecvCodeLine(SOCKET hSocket, const char* psz1, string& strRet) { strRet.clear(); while (true) { string strLine; if (!RecvLineIRC(hSocket, strLine)) return false; vector<string> vWords; ParseString(strLine, ' ', vWords); if (vWords.size() < 2) continue; if (vWords[1] == psz1) { printf("IRC %s\n", strLine.c_str()); strRet = strLine; return true; } } } bool GetIPFromIRC(SOCKET hSocket, string strMyName, CNetAddr& ipRet) { Send(hSocket, strprintf("USERHOST %s\r", strMyName.c_str()).c_str()); string strLine; if (!RecvCodeLine(hSocket, "302", strLine)) return false; vector<string> vWords; ParseString(strLine, ' ', vWords); if (vWords.size() < 4) return false; string str = vWords[3]; if (str.rfind("@") == string::npos) return false; string strHost = str.substr(str.rfind("@")+1); // Hybrid IRC used by lfnet always returns IP when you userhost yourself, // but in case another IRC is ever used this should work. printf("GetIPFromIRC() got userhost %s\n", strHost.c_str()); CNetAddr addr(strHost, true); if (!addr.IsValid()) return false; ipRet = addr; return true; } void ThreadIRCSeed(void* parg) { // Make this thread recognisable as the IRC seeding thread RenameThread("MetalCoin-ircseed"); try { ThreadIRCSeed2(parg); } catch (std::exception& e) { PrintExceptionContinue(&e, "ThreadIRCSeed()"); } catch (...) { PrintExceptionContinue(NULL, "ThreadIRCSeed()"); } printf("ThreadIRCSeed exited\n"); } void ThreadIRCSeed2(void* parg) { // Don't connect to IRC if we won't use IPv4 connections. if (IsLimited(NET_IPV4)) return; // ... or if we won't make outbound connections and won't accept inbound ones. if (mapArgs.count("-connect") && fNoListen) return; // ... or if IRC is not enabled. if (!GetBoolArg("-irc", false)) return; printf("ThreadIRCSeed started\n"); int nErrorWait = 10; int nRetryWait = 10; int nNameRetry = 0; while (!fShutdown) { CService addrConnect("92.243.23.21", 6667); // irc.lfnet.org CService addrIRC("irc.lfnet.org", 6667, true); if (addrIRC.IsValid()) addrConnect = addrIRC; SOCKET hSocket; if (!ConnectSocket(addrConnect, hSocket)) { printf("IRC connect failed\n"); nErrorWait = nErrorWait * 11 / 10; if (Wait(nErrorWait += 60)) continue; else return; } if (!RecvUntil(hSocket, "Found your hostname", "using your IP address instead", "Couldn't look up your hostname", "ignoring hostname")) { closesocket(hSocket); hSocket = INVALID_SOCKET; nErrorWait = nErrorWait * 11 / 10; if (Wait(nErrorWait += 60)) continue; else return; } CNetAddr addrIPv4("1.2.3.4"); // arbitrary IPv4 address to make GetLocal prefer IPv4 addresses CService addrLocal; string strMyName; // Don't use our IP as our nick if we're not listening // or if it keeps failing because the nick is already in use. if (!fNoListen && GetLocal(addrLocal, &addrIPv4) && nNameRetry<3) strMyName = EncodeAddress(GetLocalAddress(&addrConnect)); if (strMyName == "") strMyName = strprintf("x%"PRIu64"", GetRand(1000000000)); Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str()); Send(hSocket, strprintf("USER %s 8 * : %s\r", strMyName.c_str(), strMyName.c_str()).c_str()); int nRet = RecvUntil(hSocket, " 004 ", " 433 "); if (nRet != 1) { closesocket(hSocket); hSocket = INVALID_SOCKET; if (nRet == 2) { printf("IRC name already in use\n"); nNameRetry++; Wait(10); continue; } nErrorWait = nErrorWait * 11 / 10; if (Wait(nErrorWait += 60)) continue; else return; } nNameRetry = 0; MilliSleep(500); // Get our external IP from the IRC server and re-nick before joining the channel CNetAddr addrFromIRC; if (GetIPFromIRC(hSocket, strMyName, addrFromIRC)) { printf("GetIPFromIRC() returned %s\n", addrFromIRC.ToString().c_str()); // Don't use our IP as our nick if we're not listening if (!fNoListen && addrFromIRC.IsRoutable()) { // IRC lets you to re-nick AddLocal(addrFromIRC, LOCAL_IRC); strMyName = EncodeAddress(GetLocalAddress(&addrConnect)); Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str()); } } if (fTestNet) { Send(hSocket, "JOIN #MetalCoinTEST\r"); Send(hSocket, "WHO #MetalCoinTEST\r"); } else { // randomly join #MetalCoin00-#MetalCoin05 //int channel_number = GetRandInt(5); int channel_number = 0; // Channel number is always 0 for initial release //int channel_number = 0; Send(hSocket, strprintf("JOIN #MetalCoin%02d\r", channel_number).c_str()); Send(hSocket, strprintf("WHO #MetalCoin%02d\r", channel_number).c_str()); } int64_t nStart = GetTime(); string strLine; strLine.reserve(10000); while (!fShutdown && RecvLineIRC(hSocket, strLine)) { if (strLine.empty() || strLine.size() > 900 || strLine[0] != ':') continue; vector<string> vWords; ParseString(strLine, ' ', vWords); if (vWords.size() < 2) continue; char pszName[10000]; pszName[0] = '\0'; if (vWords[1] == "352" && vWords.size() >= 8) { // index 7 is limited to 16 characters // could get full length name at index 10, but would be different from join messages strlcpy(pszName, vWords[7].c_str(), sizeof(pszName)); printf("IRC got who\n"); } if (vWords[1] == "JOIN" && vWords[0].size() > 1) { // :username!username@50000007.F000000B.90000002.IP JOIN :#channelname strlcpy(pszName, vWords[0].c_str() + 1, sizeof(pszName)); if (strchr(pszName, '!')) *strchr(pszName, '!') = '\0'; printf("IRC got join\n"); } if (pszName[0] == 'u') { CAddress addr; if (DecodeAddress(pszName, addr)) { addr.nTime = GetAdjustedTime(); if (addrman.Add(addr, addrConnect, 51 * 60)) printf("IRC got new address: %s\n", addr.ToString().c_str()); nGotIRCAddresses++; } else { printf("IRC decode failed\n"); } } } closesocket(hSocket); hSocket = INVALID_SOCKET; if (GetTime() - nStart > 20 * 60) { nErrorWait /= 3; nRetryWait /= 3; } nRetryWait = nRetryWait * 11 / 10; if (!Wait(nRetryWait += 60)) return; } } #ifdef TEST int main(int argc, char *argv[]) { WSADATA wsadata; if (WSAStartup(MAKEWORD(2,2), &wsadata) != NO_ERROR) { printf("Error at WSAStartup()\n"); return false; } ThreadIRCSeed(NULL); WSACleanup(); return 0; } #endif
; int wv_priority_queue_reserve(wv_priority_queue_t *q, size_t n) SECTION code_clib SECTION code_adt_wv_priority_queue PUBLIC wv_priority_queue_reserve_callee EXTERN asm_wv_priority_queue_reserve wv_priority_queue_reserve_callee: pop hl pop bc ex (sp),hl jp asm_wv_priority_queue_reserve
// Copyright 2016 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "components/arc/intent_helper/local_activity_resolver.h" #include <string> #include <utility> #include "components/arc/intent_helper/intent_filter.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" namespace arc { namespace { mojom::IntentFilterPtr GetIntentFilter(const std::string& host) { mojom::IntentFilterPtr filter = mojom::IntentFilter::New(); mojom::AuthorityEntryPtr authority_entry = mojom::AuthorityEntry::New(); authority_entry->host = host; authority_entry->port = -1; filter->data_authorities = std::vector<mojom::AuthorityEntryPtr>(); filter->data_authorities->push_back(std::move(authority_entry)); return filter; } } // namespace // Tests that ShouldChromeHandleUrl returns true by default. TEST(LocalActivityResolverTest, TestDefault) { scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("file:///etc/password"))); EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("chrome://help"))); EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("about://chrome"))); } // Tests that ShouldChromeHandleUrl returns false when there's a match. TEST(LocalActivityResolverTest, TestSingleFilter) { scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); std::vector<mojom::IntentFilterPtr> array; array.push_back(GetIntentFilter("www.google.com")); resolver->UpdateIntentFilters(std::move(array)); EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); EXPECT_TRUE( resolver->ShouldChromeHandleUrl(GURL("https://www.google.co.uk"))); } // Tests the same with multiple filters. TEST(LocalActivityResolverTest, TestMultipleFilters) { scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); std::vector<mojom::IntentFilterPtr> array; array.push_back(GetIntentFilter("www.google.com")); array.push_back(GetIntentFilter("www.google.co.uk")); array.push_back(GetIntentFilter("dev.chromium.org")); resolver->UpdateIntentFilters(std::move(array)); EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); EXPECT_FALSE( resolver->ShouldChromeHandleUrl(GURL("http://www.google.co.uk"))); EXPECT_FALSE( resolver->ShouldChromeHandleUrl(GURL("https://www.google.co.uk"))); EXPECT_FALSE( resolver->ShouldChromeHandleUrl(GURL("http://dev.chromium.org"))); EXPECT_FALSE( resolver->ShouldChromeHandleUrl(GURL("https://dev.chromium.org"))); EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("http://www.android.com"))); } // Tests that ShouldChromeHandleUrl returns true for non http(s) URLs. TEST(LocalActivityResolverTest, TestNonHttp) { scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); std::vector<mojom::IntentFilterPtr> array; array.push_back(GetIntentFilter("www.google.com")); resolver->UpdateIntentFilters(std::move(array)); EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("chrome://www.google.com"))); EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("custom://www.google.com"))); } // Tests that ShouldChromeHandleUrl discards the previous filters when // UpdateIntentFilters is called with new ones. TEST(LocalActivityResolverTest, TestMultipleUpdate) { scoped_refptr<LocalActivityResolver> resolver(new LocalActivityResolver()); std::vector<mojom::IntentFilterPtr> array; array.push_back(GetIntentFilter("www.google.com")); array.push_back(GetIntentFilter("dev.chromium.org")); resolver->UpdateIntentFilters(std::move(array)); std::vector<mojom::IntentFilterPtr> array2; array2.push_back(GetIntentFilter("www.google.co.uk")); array2.push_back(GetIntentFilter("dev.chromium.org")); array2.push_back(GetIntentFilter("www.android.com")); resolver->UpdateIntentFilters(std::move(array2)); EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("http://www.google.com"))); EXPECT_TRUE(resolver->ShouldChromeHandleUrl(GURL("https://www.google.com"))); EXPECT_FALSE( resolver->ShouldChromeHandleUrl(GURL("http://www.google.co.uk"))); EXPECT_FALSE( resolver->ShouldChromeHandleUrl(GURL("https://www.google.co.uk"))); EXPECT_FALSE( resolver->ShouldChromeHandleUrl(GURL("http://dev.chromium.org"))); EXPECT_FALSE( resolver->ShouldChromeHandleUrl(GURL("https://dev.chromium.org"))); EXPECT_FALSE(resolver->ShouldChromeHandleUrl(GURL("http://www.android.com"))); EXPECT_FALSE( resolver->ShouldChromeHandleUrl(GURL("https://www.android.com"))); } } // namespace arc
; sounds.asm - makes sounds 'n' stuff SUBROUTINE LDA stepVol STA AUDV0 LDA stepSnd STA AUDC0 LDA #NULL STA stepVol
; unsigned int sms_dzx7_standard_vram(void *src, unsigned int dst) SECTION code_clib SECTION code_compress_zx7 PUBLIC _sms_dzx7_standard_vram EXTERN asm_sms_dzx7_standard_vram _sms_dzx7_standard_vram: pop af pop hl pop de push de push hl push af jp asm_sms_dzx7_standard_vram
; A165020: Length of cycle mentioned in A165019 ; 2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3 add $0,3896 div $0,1300 mov $1,$0
_ln: file format elf32-littlearm Disassembly of section .text: 00000000 <main>: #include "user.h" int main(int argc, char *argv[]) { if(argc != 3){ 0: e3500003 cmp r0, #3 #include "stat.h" #include "user.h" int main(int argc, char *argv[]) { 4: e92d4818 push {r3, r4, fp, lr} 8: e1a04001 mov r4, r1 c: e28db00c add fp, sp, #12 if(argc != 3){ 10: 0a000003 beq 24 <main+0x24> printf(2, "Usage: ln old new\n"); 14: e3a00002 mov r0, #2 18: e59f102c ldr r1, [pc, #44] ; 4c <main+0x4c> 1c: eb000207 bl 840 <printf> exit(); 20: eb0000b3 bl 2f4 <exit> } if(link(argv[1], argv[2]) < 0) 24: e9910003 ldmib r1, {r0, r1} 28: eb00014d bl 564 <link> 2c: e3500000 cmp r0, #0 30: ba000000 blt 38 <main+0x38> printf(2, "link %s %s: failed\n", argv[1], argv[2]); exit(); 34: eb0000ae bl 2f4 <exit> if(argc != 3){ printf(2, "Usage: ln old new\n"); exit(); } if(link(argv[1], argv[2]) < 0) printf(2, "link %s %s: failed\n", argv[1], argv[2]); 38: e3a00002 mov r0, #2 3c: e59f100c ldr r1, [pc, #12] ; 50 <main+0x50> 40: e994000c ldmib r4, {r2, r3} 44: eb0001fd bl 840 <printf> exit(); 48: eb0000a9 bl 2f4 <exit> 4c: 00000b28 .word 0x00000b28 50: 00000b3c .word 0x00000b3c 00000054 <strcpy>: #include "user.h" #include "arm.h" char* strcpy(char *s, char *t) { 54: e52db004 push {fp} ; (str fp, [sp, #-4]!) char *os; os = s; while((*s++ = *t++) != 0) 58: e1a02000 mov r2, r0 #include "user.h" #include "arm.h" char* strcpy(char *s, char *t) { 5c: e28db000 add fp, sp, #0 char *os; os = s; while((*s++ = *t++) != 0) 60: e4d13001 ldrb r3, [r1], #1 64: e3530000 cmp r3, #0 68: e4c23001 strb r3, [r2], #1 6c: 1afffffb bne 60 <strcpy+0xc> ; return os; } 70: e28bd000 add sp, fp, #0 74: e8bd0800 pop {fp} 78: e12fff1e bx lr 0000007c <strcmp>: int strcmp(const char *p, const char *q) { 7c: e52db004 push {fp} ; (str fp, [sp, #-4]!) 80: e28db000 add fp, sp, #0 while(*p && *p == *q) 84: e5d03000 ldrb r3, [r0] 88: e5d12000 ldrb r2, [r1] 8c: e3530000 cmp r3, #0 90: 1a000004 bne a8 <strcmp+0x2c> 94: ea000005 b b0 <strcmp+0x34> 98: e5f03001 ldrb r3, [r0, #1]! 9c: e3530000 cmp r3, #0 a0: 0a000006 beq c0 <strcmp+0x44> a4: e5f12001 ldrb r2, [r1, #1]! a8: e1530002 cmp r3, r2 ac: 0afffff9 beq 98 <strcmp+0x1c> p++, q++; return (uchar)*p - (uchar)*q; } b0: e0620003 rsb r0, r2, r3 b4: e28bd000 add sp, fp, #0 b8: e8bd0800 pop {fp} bc: e12fff1e bx lr } int strcmp(const char *p, const char *q) { while(*p && *p == *q) c0: e5d12001 ldrb r2, [r1, #1] c4: eafffff9 b b0 <strcmp+0x34> 000000c8 <strlen>: return (uchar)*p - (uchar)*q; } uint strlen(char *s) { c8: e52db004 push {fp} ; (str fp, [sp, #-4]!) cc: e28db000 add fp, sp, #0 int n; for(n = 0; s[n]; n++) d0: e5d03000 ldrb r3, [r0] d4: e3530000 cmp r3, #0 d8: 01a00003 moveq r0, r3 dc: 0a000006 beq fc <strlen+0x34> e0: e1a02000 mov r2, r0 e4: e3a03000 mov r3, #0 e8: e5f21001 ldrb r1, [r2, #1]! ec: e2833001 add r3, r3, #1 f0: e1a00003 mov r0, r3 f4: e3510000 cmp r1, #0 f8: 1afffffa bne e8 <strlen+0x20> ; return n; } fc: e28bd000 add sp, fp, #0 100: e8bd0800 pop {fp} 104: e12fff1e bx lr 00000108 <memset>: memset(void *dst, int c, uint n) { char *p=dst; u32 rc=n; while (rc-- > 0) *p++ = c; 108: e3520000 cmp r2, #0 return n; } void* memset(void *dst, int c, uint n) { 10c: e52db004 push {fp} ; (str fp, [sp, #-4]!) 110: e28db000 add fp, sp, #0 char *p=dst; u32 rc=n; while (rc-- > 0) *p++ = c; 114: 0a000006 beq 134 <memset+0x2c> 118: e6ef1071 uxtb r1, r1 11c: e1a03002 mov r3, r2 } void* memset(void *dst, int c, uint n) { char *p=dst; 120: e1a0c000 mov ip, r0 u32 rc=n; while (rc-- > 0) *p++ = c; 124: e2533001 subs r3, r3, #1 128: e4cc1001 strb r1, [ip], #1 12c: 1afffffc bne 124 <memset+0x1c> 130: e0800002 add r0, r0, r2 return (void *)p; } 134: e28bd000 add sp, fp, #0 138: e8bd0800 pop {fp} 13c: e12fff1e bx lr 00000140 <strchr>: char* strchr(const char *s, char c) { 140: e52db004 push {fp} ; (str fp, [sp, #-4]!) 144: e28db000 add fp, sp, #0 for(; *s; s++) 148: e5d03000 ldrb r3, [r0] 14c: e3530000 cmp r3, #0 150: 1a000004 bne 168 <strchr+0x28> 154: ea000008 b 17c <strchr+0x3c> 158: e5d03001 ldrb r3, [r0, #1] 15c: e2800001 add r0, r0, #1 160: e3530000 cmp r3, #0 164: 0a000004 beq 17c <strchr+0x3c> if(*s == c) 168: e1530001 cmp r3, r1 16c: 1afffff9 bne 158 <strchr+0x18> return (char*)s; return 0; } 170: e28bd000 add sp, fp, #0 174: e8bd0800 pop {fp} 178: e12fff1e bx lr strchr(const char *s, char c) { for(; *s; s++) if(*s == c) return (char*)s; return 0; 17c: e1a00003 mov r0, r3 180: eafffffa b 170 <strchr+0x30> 00000184 <gets>: } char* gets(char *buf, int max) { 184: e92d49f0 push {r4, r5, r6, r7, r8, fp, lr} 188: e28db018 add fp, sp, #24 18c: e24dd00c sub sp, sp, #12 190: e1a08000 mov r8, r0 194: e1a07001 mov r7, r1 int i, cc; char c; for(i=0; i+1 < max; ){ 198: e1a06000 mov r6, r0 19c: e3a05000 mov r5, #0 1a0: ea000008 b 1c8 <gets+0x44> cc = read(0, &c, 1); 1a4: eb000079 bl 390 <read> if(cc < 1) 1a8: e3500000 cmp r0, #0 1ac: da00000b ble 1e0 <gets+0x5c> break; buf[i++] = c; 1b0: e55b301d ldrb r3, [fp, #-29] if(c == '\n' || c == '\r') 1b4: e1a05004 mov r5, r4 1b8: e353000a cmp r3, #10 1bc: 1353000d cmpne r3, #13 for(i=0; i+1 < max; ){ cc = read(0, &c, 1); if(cc < 1) break; buf[i++] = c; 1c0: e4c63001 strb r3, [r6], #1 if(c == '\n' || c == '\r') 1c4: 0a00000a beq 1f4 <gets+0x70> { int i, cc; char c; for(i=0; i+1 < max; ){ cc = read(0, &c, 1); 1c8: e3a02001 mov r2, #1 gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 1cc: e0854002 add r4, r5, r2 1d0: e1540007 cmp r4, r7 cc = read(0, &c, 1); 1d4: e3a00000 mov r0, #0 1d8: e24b101d sub r1, fp, #29 gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 1dc: bafffff0 blt 1a4 <gets+0x20> break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 1e0: e3a03000 mov r3, #0 1e4: e7c83005 strb r3, [r8, r5] return buf; } 1e8: e1a00008 mov r0, r8 1ec: e24bd018 sub sp, fp, #24 1f0: e8bd89f0 pop {r4, r5, r6, r7, r8, fp, pc} gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 1f4: e1a05004 mov r5, r4 1f8: eafffff8 b 1e0 <gets+0x5c> 000001fc <stat>: return buf; } int stat(char *n, struct stat *st) { 1fc: e92d4830 push {r4, r5, fp, lr} 200: e1a05001 mov r5, r1 204: e28db00c add fp, sp, #12 int fd; int r; fd = open(n, O_RDONLY); 208: e3a01000 mov r1, #0 20c: eb0000a0 bl 494 <open> if(fd < 0) 210: e2504000 subs r4, r0, #0 return -1; 214: b3e05000 mvnlt r5, #0 { int fd; int r; fd = open(n, O_RDONLY); if(fd < 0) 218: ba000004 blt 230 <stat+0x34> return -1; r = fstat(fd, st); 21c: e1a01005 mov r1, r5 220: eb0000c2 bl 530 <fstat> 224: e1a05000 mov r5, r0 close(fd); 228: e1a00004 mov r0, r4 22c: eb000071 bl 3f8 <close> return r; } 230: e1a00005 mov r0, r5 234: e8bd8830 pop {r4, r5, fp, pc} 00000238 <atoi>: int atoi(const char *s) { 238: e52db004 push {fp} ; (str fp, [sp, #-4]!) 23c: e28db000 add fp, sp, #0 int n; n = 0; while('0' <= *s && *s <= '9') 240: e5d03000 ldrb r3, [r0] 244: e2432030 sub r2, r3, #48 ; 0x30 248: e6ef2072 uxtb r2, r2 24c: e3520009 cmp r2, #9 int atoi(const char *s) { int n; n = 0; 250: 83a00000 movhi r0, #0 while('0' <= *s && *s <= '9') 254: 8a000009 bhi 280 <atoi+0x48> 258: e1a02000 mov r2, r0 int atoi(const char *s) { int n; n = 0; 25c: e3a00000 mov r0, #0 while('0' <= *s && *s <= '9') n = n*10 + *s++ - '0'; 260: e0800100 add r0, r0, r0, lsl #2 264: e0830080 add r0, r3, r0, lsl #1 atoi(const char *s) { int n; n = 0; while('0' <= *s && *s <= '9') 268: e5f23001 ldrb r3, [r2, #1]! n = n*10 + *s++ - '0'; 26c: e2400030 sub r0, r0, #48 ; 0x30 atoi(const char *s) { int n; n = 0; while('0' <= *s && *s <= '9') 270: e2431030 sub r1, r3, #48 ; 0x30 274: e6ef1071 uxtb r1, r1 278: e3510009 cmp r1, #9 27c: 9afffff7 bls 260 <atoi+0x28> n = n*10 + *s++ - '0'; return n; } 280: e28bd000 add sp, fp, #0 284: e8bd0800 pop {fp} 288: e12fff1e bx lr 0000028c <memmove>: { char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 28c: e3520000 cmp r2, #0 return n; } void* memmove(void *vdst, void *vsrc, int n) { 290: e52db004 push {fp} ; (str fp, [sp, #-4]!) 294: e28db000 add fp, sp, #0 char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 298: da000005 ble 2b4 <memmove+0x28> n = n*10 + *s++ - '0'; return n; } void* memmove(void *vdst, void *vsrc, int n) 29c: e0802002 add r2, r0, r2 { char *dst, *src; dst = vdst; 2a0: e1a03000 mov r3, r0 src = vsrc; while(n-- > 0) *dst++ = *src++; 2a4: e4d1c001 ldrb ip, [r1], #1 2a8: e4c3c001 strb ip, [r3], #1 { char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 2ac: e1530002 cmp r3, r2 2b0: 1afffffb bne 2a4 <memmove+0x18> *dst++ = *src++; return vdst; } 2b4: e28bd000 add sp, fp, #0 2b8: e8bd0800 pop {fp} 2bc: e12fff1e bx lr 000002c0 <fork>: 2c0: e92d4000 push {lr} 2c4: e92d0008 push {r3} 2c8: e92d0004 push {r2} 2cc: e92d0002 push {r1} 2d0: e92d0001 push {r0} 2d4: e3a00001 mov r0, #1 2d8: ef000040 svc 0x00000040 2dc: e8bd0002 pop {r1} 2e0: e8bd0002 pop {r1} 2e4: e8bd0004 pop {r2} 2e8: e8bd0008 pop {r3} 2ec: e8bd4000 pop {lr} 2f0: e12fff1e bx lr 000002f4 <exit>: 2f4: e92d4000 push {lr} 2f8: e92d0008 push {r3} 2fc: e92d0004 push {r2} 300: e92d0002 push {r1} 304: e92d0001 push {r0} 308: e3a00002 mov r0, #2 30c: ef000040 svc 0x00000040 310: e8bd0002 pop {r1} 314: e8bd0002 pop {r1} 318: e8bd0004 pop {r2} 31c: e8bd0008 pop {r3} 320: e8bd4000 pop {lr} 324: e12fff1e bx lr 00000328 <wait>: 328: e92d4000 push {lr} 32c: e92d0008 push {r3} 330: e92d0004 push {r2} 334: e92d0002 push {r1} 338: e92d0001 push {r0} 33c: e3a00003 mov r0, #3 340: ef000040 svc 0x00000040 344: e8bd0002 pop {r1} 348: e8bd0002 pop {r1} 34c: e8bd0004 pop {r2} 350: e8bd0008 pop {r3} 354: e8bd4000 pop {lr} 358: e12fff1e bx lr 0000035c <pipe>: 35c: e92d4000 push {lr} 360: e92d0008 push {r3} 364: e92d0004 push {r2} 368: e92d0002 push {r1} 36c: e92d0001 push {r0} 370: e3a00004 mov r0, #4 374: ef000040 svc 0x00000040 378: e8bd0002 pop {r1} 37c: e8bd0002 pop {r1} 380: e8bd0004 pop {r2} 384: e8bd0008 pop {r3} 388: e8bd4000 pop {lr} 38c: e12fff1e bx lr 00000390 <read>: 390: e92d4000 push {lr} 394: e92d0008 push {r3} 398: e92d0004 push {r2} 39c: e92d0002 push {r1} 3a0: e92d0001 push {r0} 3a4: e3a00005 mov r0, #5 3a8: ef000040 svc 0x00000040 3ac: e8bd0002 pop {r1} 3b0: e8bd0002 pop {r1} 3b4: e8bd0004 pop {r2} 3b8: e8bd0008 pop {r3} 3bc: e8bd4000 pop {lr} 3c0: e12fff1e bx lr 000003c4 <write>: 3c4: e92d4000 push {lr} 3c8: e92d0008 push {r3} 3cc: e92d0004 push {r2} 3d0: e92d0002 push {r1} 3d4: e92d0001 push {r0} 3d8: e3a00010 mov r0, #16 3dc: ef000040 svc 0x00000040 3e0: e8bd0002 pop {r1} 3e4: e8bd0002 pop {r1} 3e8: e8bd0004 pop {r2} 3ec: e8bd0008 pop {r3} 3f0: e8bd4000 pop {lr} 3f4: e12fff1e bx lr 000003f8 <close>: 3f8: e92d4000 push {lr} 3fc: e92d0008 push {r3} 400: e92d0004 push {r2} 404: e92d0002 push {r1} 408: e92d0001 push {r0} 40c: e3a00015 mov r0, #21 410: ef000040 svc 0x00000040 414: e8bd0002 pop {r1} 418: e8bd0002 pop {r1} 41c: e8bd0004 pop {r2} 420: e8bd0008 pop {r3} 424: e8bd4000 pop {lr} 428: e12fff1e bx lr 0000042c <kill>: 42c: e92d4000 push {lr} 430: e92d0008 push {r3} 434: e92d0004 push {r2} 438: e92d0002 push {r1} 43c: e92d0001 push {r0} 440: e3a00006 mov r0, #6 444: ef000040 svc 0x00000040 448: e8bd0002 pop {r1} 44c: e8bd0002 pop {r1} 450: e8bd0004 pop {r2} 454: e8bd0008 pop {r3} 458: e8bd4000 pop {lr} 45c: e12fff1e bx lr 00000460 <exec>: 460: e92d4000 push {lr} 464: e92d0008 push {r3} 468: e92d0004 push {r2} 46c: e92d0002 push {r1} 470: e92d0001 push {r0} 474: e3a00007 mov r0, #7 478: ef000040 svc 0x00000040 47c: e8bd0002 pop {r1} 480: e8bd0002 pop {r1} 484: e8bd0004 pop {r2} 488: e8bd0008 pop {r3} 48c: e8bd4000 pop {lr} 490: e12fff1e bx lr 00000494 <open>: 494: e92d4000 push {lr} 498: e92d0008 push {r3} 49c: e92d0004 push {r2} 4a0: e92d0002 push {r1} 4a4: e92d0001 push {r0} 4a8: e3a0000f mov r0, #15 4ac: ef000040 svc 0x00000040 4b0: e8bd0002 pop {r1} 4b4: e8bd0002 pop {r1} 4b8: e8bd0004 pop {r2} 4bc: e8bd0008 pop {r3} 4c0: e8bd4000 pop {lr} 4c4: e12fff1e bx lr 000004c8 <mknod>: 4c8: e92d4000 push {lr} 4cc: e92d0008 push {r3} 4d0: e92d0004 push {r2} 4d4: e92d0002 push {r1} 4d8: e92d0001 push {r0} 4dc: e3a00011 mov r0, #17 4e0: ef000040 svc 0x00000040 4e4: e8bd0002 pop {r1} 4e8: e8bd0002 pop {r1} 4ec: e8bd0004 pop {r2} 4f0: e8bd0008 pop {r3} 4f4: e8bd4000 pop {lr} 4f8: e12fff1e bx lr 000004fc <unlink>: 4fc: e92d4000 push {lr} 500: e92d0008 push {r3} 504: e92d0004 push {r2} 508: e92d0002 push {r1} 50c: e92d0001 push {r0} 510: e3a00012 mov r0, #18 514: ef000040 svc 0x00000040 518: e8bd0002 pop {r1} 51c: e8bd0002 pop {r1} 520: e8bd0004 pop {r2} 524: e8bd0008 pop {r3} 528: e8bd4000 pop {lr} 52c: e12fff1e bx lr 00000530 <fstat>: 530: e92d4000 push {lr} 534: e92d0008 push {r3} 538: e92d0004 push {r2} 53c: e92d0002 push {r1} 540: e92d0001 push {r0} 544: e3a00008 mov r0, #8 548: ef000040 svc 0x00000040 54c: e8bd0002 pop {r1} 550: e8bd0002 pop {r1} 554: e8bd0004 pop {r2} 558: e8bd0008 pop {r3} 55c: e8bd4000 pop {lr} 560: e12fff1e bx lr 00000564 <link>: 564: e92d4000 push {lr} 568: e92d0008 push {r3} 56c: e92d0004 push {r2} 570: e92d0002 push {r1} 574: e92d0001 push {r0} 578: e3a00013 mov r0, #19 57c: ef000040 svc 0x00000040 580: e8bd0002 pop {r1} 584: e8bd0002 pop {r1} 588: e8bd0004 pop {r2} 58c: e8bd0008 pop {r3} 590: e8bd4000 pop {lr} 594: e12fff1e bx lr 00000598 <mkdir>: 598: e92d4000 push {lr} 59c: e92d0008 push {r3} 5a0: e92d0004 push {r2} 5a4: e92d0002 push {r1} 5a8: e92d0001 push {r0} 5ac: e3a00014 mov r0, #20 5b0: ef000040 svc 0x00000040 5b4: e8bd0002 pop {r1} 5b8: e8bd0002 pop {r1} 5bc: e8bd0004 pop {r2} 5c0: e8bd0008 pop {r3} 5c4: e8bd4000 pop {lr} 5c8: e12fff1e bx lr 000005cc <chdir>: 5cc: e92d4000 push {lr} 5d0: e92d0008 push {r3} 5d4: e92d0004 push {r2} 5d8: e92d0002 push {r1} 5dc: e92d0001 push {r0} 5e0: e3a00009 mov r0, #9 5e4: ef000040 svc 0x00000040 5e8: e8bd0002 pop {r1} 5ec: e8bd0002 pop {r1} 5f0: e8bd0004 pop {r2} 5f4: e8bd0008 pop {r3} 5f8: e8bd4000 pop {lr} 5fc: e12fff1e bx lr 00000600 <dup>: 600: e92d4000 push {lr} 604: e92d0008 push {r3} 608: e92d0004 push {r2} 60c: e92d0002 push {r1} 610: e92d0001 push {r0} 614: e3a0000a mov r0, #10 618: ef000040 svc 0x00000040 61c: e8bd0002 pop {r1} 620: e8bd0002 pop {r1} 624: e8bd0004 pop {r2} 628: e8bd0008 pop {r3} 62c: e8bd4000 pop {lr} 630: e12fff1e bx lr 00000634 <getpid>: 634: e92d4000 push {lr} 638: e92d0008 push {r3} 63c: e92d0004 push {r2} 640: e92d0002 push {r1} 644: e92d0001 push {r0} 648: e3a0000b mov r0, #11 64c: ef000040 svc 0x00000040 650: e8bd0002 pop {r1} 654: e8bd0002 pop {r1} 658: e8bd0004 pop {r2} 65c: e8bd0008 pop {r3} 660: e8bd4000 pop {lr} 664: e12fff1e bx lr 00000668 <sbrk>: 668: e92d4000 push {lr} 66c: e92d0008 push {r3} 670: e92d0004 push {r2} 674: e92d0002 push {r1} 678: e92d0001 push {r0} 67c: e3a0000c mov r0, #12 680: ef000040 svc 0x00000040 684: e8bd0002 pop {r1} 688: e8bd0002 pop {r1} 68c: e8bd0004 pop {r2} 690: e8bd0008 pop {r3} 694: e8bd4000 pop {lr} 698: e12fff1e bx lr 0000069c <sleep>: 69c: e92d4000 push {lr} 6a0: e92d0008 push {r3} 6a4: e92d0004 push {r2} 6a8: e92d0002 push {r1} 6ac: e92d0001 push {r0} 6b0: e3a0000d mov r0, #13 6b4: ef000040 svc 0x00000040 6b8: e8bd0002 pop {r1} 6bc: e8bd0002 pop {r1} 6c0: e8bd0004 pop {r2} 6c4: e8bd0008 pop {r3} 6c8: e8bd4000 pop {lr} 6cc: e12fff1e bx lr 000006d0 <uptime>: 6d0: e92d4000 push {lr} 6d4: e92d0008 push {r3} 6d8: e92d0004 push {r2} 6dc: e92d0002 push {r1} 6e0: e92d0001 push {r0} 6e4: e3a0000e mov r0, #14 6e8: ef000040 svc 0x00000040 6ec: e8bd0002 pop {r1} 6f0: e8bd0002 pop {r1} 6f4: e8bd0004 pop {r2} 6f8: e8bd0008 pop {r3} 6fc: e8bd4000 pop {lr} 700: e12fff1e bx lr 00000704 <putc>: #include "stat.h" #include "user.h" static void putc(int fd, char c) { 704: e92d4800 push {fp, lr} 708: e28db004 add fp, sp, #4 70c: e24b3004 sub r3, fp, #4 710: e24dd008 sub sp, sp, #8 write(fd, &c, 1); 714: e3a02001 mov r2, #1 #include "stat.h" #include "user.h" static void putc(int fd, char c) { 718: e5631001 strb r1, [r3, #-1]! write(fd, &c, 1); 71c: e1a01003 mov r1, r3 720: ebffff27 bl 3c4 <write> } 724: e24bd004 sub sp, fp, #4 728: e8bd8800 pop {fp, pc} 0000072c <printint>: return q; } static void printint(int fd, int xx, int base, int sgn) { 72c: e92d4ff0 push {r4, r5, r6, r7, r8, r9, sl, fp, lr} 730: e1a04000 mov r4, r0 char buf[16]; int i, neg; uint x, y, b; neg = 0; if(sgn && xx < 0){ 734: e1a00fa1 lsr r0, r1, #31 738: e3530000 cmp r3, #0 73c: 03a03000 moveq r3, #0 740: 12003001 andne r3, r0, #1 return q; } static void printint(int fd, int xx, int base, int sgn) { 744: e28db020 add fp, sp, #32 char buf[16]; int i, neg; uint x, y, b; neg = 0; if(sgn && xx < 0){ 748: e3530000 cmp r3, #0 return q; } static void printint(int fd, int xx, int base, int sgn) { 74c: e24dd014 sub sp, sp, #20 750: e59f909c ldr r9, [pc, #156] ; 7f4 <printint+0xc8> uint x, y, b; neg = 0; if(sgn && xx < 0){ neg = 1; x = -xx; 754: 12611000 rsbne r1, r1, #0 int i, neg; uint x, y, b; neg = 0; if(sgn && xx < 0){ neg = 1; 758: 13a03001 movne r3, #1 } else { x = xx; } b = base; i = 0; 75c: e3a0a000 mov sl, #0 760: e24b6034 sub r6, fp, #52 ; 0x34 for(i=31;i>=0;i--){ r = r << 1; r = r | ((n >> i) & 1); if(r >= d) { r = r - d; q = q | (1 << i); 764: e3a08001 mov r8, #1 write(fd, &c, 1); } u32 div(u32 n, u32 d) // long division { u32 q=0, r=0; 768: e3a07000 mov r7, #0 int i; for(i=31;i>=0;i--){ 76c: e3a0001f mov r0, #31 write(fd, &c, 1); } u32 div(u32 n, u32 d) // long division { u32 q=0, r=0; 770: e1a0c007 mov ip, r7 int i; for(i=31;i>=0;i--){ r = r << 1; r = r | ((n >> i) & 1); 774: e1a0e031 lsr lr, r1, r0 778: e20ee001 and lr, lr, #1 77c: e18ec08c orr ip, lr, ip, lsl #1 if(r >= d) { 780: e152000c cmp r2, ip r = r - d; q = q | (1 << i); 784: 91877018 orrls r7, r7, r8, lsl r0 for(i=31;i>=0;i--){ r = r << 1; r = r | ((n >> i) & 1); if(r >= d) { r = r - d; 788: 9062c00c rsbls ip, r2, ip u32 div(u32 n, u32 d) // long division { u32 q=0, r=0; int i; for(i=31;i>=0;i--){ 78c: e2500001 subs r0, r0, #1 790: 2afffff7 bcs 774 <printint+0x48> b = base; i = 0; do{ y = div(x, b); buf[i++] = digits[x - y * b]; 794: e0000792 mul r0, r2, r7 }while((x = y) != 0); 798: e3570000 cmp r7, #0 b = base; i = 0; do{ y = div(x, b); buf[i++] = digits[x - y * b]; 79c: e0601001 rsb r1, r0, r1 7a0: e28a5001 add r5, sl, #1 7a4: e7d91001 ldrb r1, [r9, r1] 7a8: e7c6100a strb r1, [r6, sl] }while((x = y) != 0); 7ac: 11a01007 movne r1, r7 b = base; i = 0; do{ y = div(x, b); buf[i++] = digits[x - y * b]; 7b0: 11a0a005 movne sl, r5 7b4: 1affffeb bne 768 <printint+0x3c> }while((x = y) != 0); if(neg) 7b8: e3530000 cmp r3, #0 buf[i++] = '-'; 7bc: 124b2024 subne r2, fp, #36 ; 0x24 7c0: 10823005 addne r3, r2, r5 7c4: 128a5002 addne r5, sl, #2 while(--i >= 0) 7c8: e2455001 sub r5, r5, #1 do{ y = div(x, b); buf[i++] = digits[x - y * b]; }while((x = y) != 0); if(neg) buf[i++] = '-'; 7cc: 13a0202d movne r2, #45 ; 0x2d 7d0: 15432010 strbne r2, [r3, #-16] while(--i >= 0) putc(fd, buf[i]); 7d4: e7d61005 ldrb r1, [r6, r5] 7d8: e1a00004 mov r0, r4 buf[i++] = digits[x - y * b]; }while((x = y) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) 7dc: e2455001 sub r5, r5, #1 putc(fd, buf[i]); 7e0: ebffffc7 bl 704 <putc> buf[i++] = digits[x - y * b]; }while((x = y) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) 7e4: e3750001 cmn r5, #1 7e8: 1afffff9 bne 7d4 <printint+0xa8> putc(fd, buf[i]); } 7ec: e24bd020 sub sp, fp, #32 7f0: e8bd8ff0 pop {r4, r5, r6, r7, r8, r9, sl, fp, pc} 7f4: 00000b50 .word 0x00000b50 000007f8 <div>: write(fd, &c, 1); } u32 div(u32 n, u32 d) // long division { u32 q=0, r=0; 7f8: e3a03000 mov r3, #0 { write(fd, &c, 1); } u32 div(u32 n, u32 d) // long division { 7fc: e92d0830 push {r4, r5, fp} 800: e1a02000 mov r2, r0 804: e28db008 add fp, sp, #8 u32 q=0, r=0; int i; for(i=31;i>=0;i--){ 808: e3a0c01f mov ip, #31 write(fd, &c, 1); } u32 div(u32 n, u32 d) // long division { u32 q=0, r=0; 80c: e1a00003 mov r0, r3 for(i=31;i>=0;i--){ r = r << 1; r = r | ((n >> i) & 1); if(r >= d) { r = r - d; q = q | (1 << i); 810: e3a05001 mov r5, #1 u32 q=0, r=0; int i; for(i=31;i>=0;i--){ r = r << 1; r = r | ((n >> i) & 1); 814: e1a04c32 lsr r4, r2, ip 818: e2044001 and r4, r4, #1 81c: e1843083 orr r3, r4, r3, lsl #1 if(r >= d) { 820: e1530001 cmp r3, r1 r = r - d; q = q | (1 << i); 824: 21800c15 orrcs r0, r0, r5, lsl ip for(i=31;i>=0;i--){ r = r << 1; r = r | ((n >> i) & 1); if(r >= d) { r = r - d; 828: 20613003 rsbcs r3, r1, r3 u32 div(u32 n, u32 d) // long division { u32 q=0, r=0; int i; for(i=31;i>=0;i--){ 82c: e25cc001 subs ip, ip, #1 830: 2afffff7 bcs 814 <div+0x1c> r = r - d; q = q | (1 << i); } } return q; } 834: e24bd008 sub sp, fp, #8 838: e8bd0830 pop {r4, r5, fp} 83c: e12fff1e bx lr 00000840 <printf>: } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 840: e92d000e push {r1, r2, r3} 844: e92d4ff0 push {r4, r5, r6, r7, r8, r9, sl, fp, lr} 848: e28db020 add fp, sp, #32 84c: e1a05000 mov r5, r0 int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 850: e59b4004 ldr r4, [fp, #4] 854: e5d48000 ldrb r8, [r4] 858: e3580000 cmp r8, #0 85c: 0a000027 beq 900 <printf+0xc0> ap++; } else if(c == 's'){ s = (char*)*ap; ap++; if(s == 0) s = "(null)"; 860: e59f712c ldr r7, [pc, #300] ; 994 <printf+0x154> char *s; int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; 864: e28b6008 add r6, fp, #8 { char *s; int c, i, state; uint *ap; state = 0; 868: e3a0a000 mov sl, #0 86c: ea000008 b 894 <printf+0x54> ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ 870: e3580025 cmp r8, #37 ; 0x25 state = '%'; 874: 01a0a008 moveq sl, r8 state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ 878: 0a000002 beq 888 <printf+0x48> state = '%'; } else { putc(fd, c); 87c: e1a00005 mov r0, r5 880: e1a01008 mov r1, r8 884: ebffff9e bl 704 <putc> int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 888: e5f48001 ldrb r8, [r4, #1]! 88c: e3580000 cmp r8, #0 890: 0a00001a beq 900 <printf+0xc0> c = fmt[i] & 0xff; if(state == 0){ 894: e35a0000 cmp sl, #0 898: 0afffff4 beq 870 <printf+0x30> if(c == '%'){ state = '%'; } else { putc(fd, c); } } else if(state == '%'){ 89c: e35a0025 cmp sl, #37 ; 0x25 8a0: 1afffff8 bne 888 <printf+0x48> if(c == 'd'){ 8a4: e3580064 cmp r8, #100 ; 0x64 8a8: 0a00002c beq 960 <printf+0x120> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 8ac: e3580078 cmp r8, #120 ; 0x78 8b0: 13580070 cmpne r8, #112 ; 0x70 8b4: 13a09000 movne r9, #0 8b8: 03a09001 moveq r9, #1 8bc: 0a000013 beq 910 <printf+0xd0> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 8c0: e3580073 cmp r8, #115 ; 0x73 8c4: 0a000018 beq 92c <printf+0xec> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 8c8: e3580063 cmp r8, #99 ; 0x63 8cc: 0a00002a beq 97c <printf+0x13c> putc(fd, *ap); ap++; } else if(c == '%'){ 8d0: e3580025 cmp r8, #37 ; 0x25 putc(fd, c); 8d4: e1a0100a mov r1, sl 8d8: e1a00005 mov r0, r5 s++; } } else if(c == 'c'){ putc(fd, *ap); ap++; } else if(c == '%'){ 8dc: 0a000002 beq 8ec <printf+0xac> putc(fd, c); } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); 8e0: ebffff87 bl 704 <putc> putc(fd, c); 8e4: e1a00005 mov r0, r5 8e8: e1a01008 mov r1, r8 8ec: ebffff84 bl 704 <putc> int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 8f0: e5f48001 ldrb r8, [r4, #1]! } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 8f4: e1a0a009 mov sl, r9 int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 8f8: e3580000 cmp r8, #0 8fc: 1affffe4 bne 894 <printf+0x54> putc(fd, c); } state = 0; } } } 900: e24bd020 sub sp, fp, #32 904: e8bd4ff0 pop {r4, r5, r6, r7, r8, r9, sl, fp, lr} 908: e28dd00c add sp, sp, #12 90c: e12fff1e bx lr } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ printint(fd, *ap, 16, 0); 910: e1a00005 mov r0, r5 914: e4961004 ldr r1, [r6], #4 918: e3a02010 mov r2, #16 91c: e3a03000 mov r3, #0 920: ebffff81 bl 72c <printint> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 924: e3a0a000 mov sl, #0 928: eaffffd6 b 888 <printf+0x48> ap++; } else if(c == 'x' || c == 'p'){ printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ s = (char*)*ap; 92c: e4968004 ldr r8, [r6], #4 ap++; if(s == 0) s = "(null)"; 930: e3580000 cmp r8, #0 934: 01a08007 moveq r8, r7 while(*s != 0){ 938: e5d81000 ldrb r1, [r8] 93c: e3510000 cmp r1, #0 940: 0a000004 beq 958 <printf+0x118> putc(fd, *s); 944: e1a00005 mov r0, r5 948: ebffff6d bl 704 <putc> } else if(c == 's'){ s = (char*)*ap; ap++; if(s == 0) s = "(null)"; while(*s != 0){ 94c: e5f81001 ldrb r1, [r8, #1]! 950: e3510000 cmp r1, #0 954: 1afffffa bne 944 <printf+0x104> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 958: e1a0a001 mov sl, r1 95c: eaffffc9 b 888 <printf+0x48> } else { putc(fd, c); } } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); 960: e1a00005 mov r0, r5 964: e4961004 ldr r1, [r6], #4 968: e3a0200a mov r2, #10 96c: e3a03001 mov r3, #1 970: ebffff6d bl 72c <printint> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 974: e3a0a000 mov sl, #0 978: eaffffc2 b 888 <printf+0x48> while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ putc(fd, *ap); 97c: e4961004 ldr r1, [r6], #4 980: e1a00005 mov r0, r5 } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 984: e1a0a009 mov sl, r9 while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ putc(fd, *ap); 988: e6ef1071 uxtb r1, r1 98c: ebffff5c bl 704 <putc> 990: eaffffbc b 888 <printf+0x48> 994: 00000b64 .word 0x00000b64 00000998 <free>: free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 998: e59f3098 ldr r3, [pc, #152] ; a38 <free+0xa0> static Header base; static Header *freep; void free(void *ap) { 99c: e92d0830 push {r4, r5, fp} Header *bp, *p; bp = (Header*)ap - 1; 9a0: e240c008 sub ip, r0, #8 for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 9a4: e5932000 ldr r2, [r3] static Header base; static Header *freep; void free(void *ap) { 9a8: e28db008 add fp, sp, #8 Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 9ac: e152000c cmp r2, ip 9b0: e5921000 ldr r1, [r2] 9b4: 2a000001 bcs 9c0 <free+0x28> 9b8: e15c0001 cmp ip, r1 9bc: 3a000007 bcc 9e0 <free+0x48> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 9c0: e1520001 cmp r2, r1 9c4: 3a000003 bcc 9d8 <free+0x40> 9c8: e152000c cmp r2, ip 9cc: 3a000003 bcc 9e0 <free+0x48> 9d0: e15c0001 cmp ip, r1 9d4: 3a000001 bcc 9e0 <free+0x48> static Header base; static Header *freep; void free(void *ap) { 9d8: e1a02001 mov r2, r1 9dc: eafffff2 b 9ac <free+0x14> 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){ 9e0: e5104004 ldr r4, [r0, #-4] if(p + p->s.size == bp){ p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; freep = p; 9e4: e5832000 str r2, [r3] 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){ 9e8: e08c5184 add r5, ip, r4, lsl #3 9ec: e1550001 cmp r5, r1 bp->s.size += p->s.ptr->s.size; 9f0: 05911004 ldreq r1, [r1, #4] 9f4: 00814004 addeq r4, r1, r4 9f8: 05004004 streq r4, [r0, #-4] bp->s.ptr = p->s.ptr->s.ptr; 9fc: 05921000 ldreq r1, [r2] a00: 05911000 ldreq r1, [r1] } else bp->s.ptr = p->s.ptr; a04: e5001008 str r1, [r0, #-8] if(p + p->s.size == bp){ a08: e5921004 ldr r1, [r2, #4] a0c: e0824181 add r4, r2, r1, lsl #3 a10: e15c0004 cmp ip, r4 p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; a14: 1582c000 strne ip, [r2] 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; a18: 0510c004 ldreq ip, [r0, #-4] a1c: 008c1001 addeq r1, ip, r1 a20: 05821004 streq r1, [r2, #4] p->s.ptr = bp->s.ptr; a24: 05101008 ldreq r1, [r0, #-8] a28: 05821000 streq r1, [r2] } else p->s.ptr = bp; freep = p; } a2c: e24bd008 sub sp, fp, #8 a30: e8bd0830 pop {r4, r5, fp} a34: e12fff1e bx lr a38: 00000b6c .word 0x00000b6c 00000a3c <malloc>: return freep; } void* malloc(uint nbytes) { a3c: e92d49f8 push {r3, r4, r5, r6, r7, r8, fp, lr} Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; a40: e2804007 add r4, r0, #7 if((prevp = freep) == 0){ a44: e59f50d4 ldr r5, [pc, #212] ; b20 <malloc+0xe4> malloc(uint nbytes) { Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; a48: e1a041a4 lsr r4, r4, #3 return freep; } void* malloc(uint nbytes) { a4c: e28db01c add fp, sp, #28 Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ a50: e5953000 ldr r3, [r5] malloc(uint nbytes) { Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; a54: e2844001 add r4, r4, #1 if((prevp = freep) == 0){ a58: e3530000 cmp r3, #0 a5c: 0a00002b beq b10 <malloc+0xd4> a60: e5930000 ldr r0, [r3] a64: e5902004 ldr r2, [r0, #4] 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){ a68: e1520004 cmp r2, r4 a6c: 2a00001b bcs ae0 <malloc+0xa4> morecore(uint nu) { char *p; Header *hp; if(nu < 4096) a70: e59f80ac ldr r8, [pc, #172] ; b24 <malloc+0xe8> p->s.size -= nunits; p += p->s.size; p->s.size = nunits; } freep = prevp; return (void*)(p + 1); a74: e1a07184 lsl r7, r4, #3 a78: ea000003 b a8c <malloc+0x50> 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){ a7c: e5930000 ldr r0, [r3] if(p->s.size >= nunits){ a80: e5902004 ldr r2, [r0, #4] a84: e1540002 cmp r4, r2 a88: 9a000014 bls ae0 <malloc+0xa4> p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if(p == freep) a8c: e5952000 ldr r2, [r5] a90: e1a03000 mov r3, r0 a94: e1500002 cmp r0, r2 a98: 1afffff7 bne a7c <malloc+0x40> morecore(uint nu) { char *p; Header *hp; if(nu < 4096) a9c: e1540008 cmp r4, r8 nu = 4096; p = sbrk(nu * sizeof(Header)); aa0: 81a00007 movhi r0, r7 aa4: 93a00902 movls r0, #32768 ; 0x8000 morecore(uint nu) { char *p; Header *hp; if(nu < 4096) aa8: 81a06004 movhi r6, r4 aac: 93a06a01 movls r6, #4096 ; 0x1000 nu = 4096; p = sbrk(nu * sizeof(Header)); ab0: ebfffeec bl 668 <sbrk> ab4: e1a03000 mov r3, r0 if(p == (char*)-1) ab8: e3730001 cmn r3, #1 return 0; hp = (Header*)p; hp->s.size = nu; free((void*)(hp + 1)); abc: e2800008 add r0, r0, #8 Header *hp; if(nu < 4096) nu = 4096; p = sbrk(nu * sizeof(Header)); if(p == (char*)-1) ac0: 0a000010 beq b08 <malloc+0xcc> return 0; hp = (Header*)p; hp->s.size = nu; ac4: e5836004 str r6, [r3, #4] free((void*)(hp + 1)); ac8: ebffffb2 bl 998 <free> return freep; acc: e5953000 ldr r3, [r5] } freep = prevp; return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) ad0: e3530000 cmp r3, #0 ad4: 1affffe8 bne a7c <malloc+0x40> return 0; ad8: e1a00003 mov r0, r3 } } adc: e8bd89f8 pop {r3, r4, r5, r6, r7, r8, fp, pc} 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) ae0: e1540002 cmp r4, r2 prevp->s.ptr = p->s.ptr; else { p->s.size -= nunits; ae4: 10642002 rsbne r2, r4, r2 ae8: 15802004 strne r2, [r0, #4] 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; aec: 05902000 ldreq r2, [r0] else { p->s.size -= nunits; p += p->s.size; af0: 10800182 addne r0, r0, r2, lsl #3 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; af4: 05832000 streq r2, [r3] else { p->s.size -= nunits; p += p->s.size; p->s.size = nunits; af8: 15804004 strne r4, [r0, #4] } freep = prevp; afc: e5853000 str r3, [r5] return (void*)(p + 1); b00: e2800008 add r0, r0, #8 b04: e8bd89f8 pop {r3, r4, r5, r6, r7, r8, fp, pc} } if(p == freep) if((p = morecore(nunits)) == 0) return 0; b08: e3a00000 mov r0, #0 b0c: e8bd89f8 pop {r3, r4, r5, r6, r7, r8, fp, pc} Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; b10: e2850004 add r0, r5, #4 b14: e5850000 str r0, [r5] base.s.size = 0; b18: e9850009 stmib r5, {r0, r3} b1c: eaffffd3 b a70 <malloc+0x34> b20: 00000b6c .word 0x00000b6c b24: 00000fff .word 0x00000fff
#include <bits/stdc++.h> using namespace std; #define f(i,x,n) for(int i=x;i<n;i++) // Let Bot is 2 and User is 1 int n=8,m=8; int la; int a[16][16],sum=0; array <int,8> b; int check() { if(sum==64) return 3; f(i,0,n) f(j,0,m) { if(a[i][j]!=0&&a[i][j]==a[i][j+1]&&a[i][j+1]==a[i][j+2]&&a[i][j+2]==a[i][j+3]) return a[i][j]; if(a[i][j]!=0&&a[i][j]==a[i+1][j]&&a[i+1][j]==a[i+2][j]&&a[i+2][j]==a[i+3][j]) return a[i][j]; if(a[i][j]!=0&&a[i][j]==a[i+1][j+1]&&a[i+1][j+1]==a[i+2][j+2]&&a[i+2][j+2]==a[i+3][j+3]) return a[i][j]; if(a[i][j]!=0&&i-3>=0&&a[i][j]==a[i-1][j+1]&&a[i-1][j+1]==a[i-2][j+2]&&a[i-2][j+2]==a[i-3][j+3]) return a[i][j]; } return 0; } int32_t main() { cout<<"Enter 1 if u want to play first\n"; int turn; cin>>turn; if(turn!=1) turn=2; cout<<"Enter the difficulty level starting from 0\n"; f(i,0,m) b[i]=n-1; cin>>la; while(1) { int won=check(); if(won) { if(won==3) cout<<"It's a draw\n"; else if(won==2) cout<<"Bot won\n"; else cout<<"User won\n"; break; } f(i,0,n) { f(j,0,m) { cout<<a[i][j]<<" "; } cout<<'\n'; } int ch; cin>>ch; ch--; int flag=0; if(b[ch]<0) { cout<<"Wrong Move, the column is already filled, Enter a different move\n"; continue; } sum++; a[b[ch]][ch]=turn; b[ch]--; turn =3-turn; } f(i,0,n) { f(j,0,m) { cout<<a[i][j]<<" "; } cout<<'\n'; } return 0; }
_ln: file format elf32-i386 Disassembly of section .text: 00000000 <main>: #include "stat.h" #include "user.h" int main(int argc, char *argv[]) { 0: 8d 4c 24 04 lea 0x4(%esp),%ecx 4: 83 e4 f0 and $0xfffffff0,%esp if(argc != 3){ 7: 83 39 03 cmpl $0x3,(%ecx) { a: ff 71 fc pushl -0x4(%ecx) d: 55 push %ebp e: 89 e5 mov %esp,%ebp 10: 53 push %ebx 11: 51 push %ecx 12: 8b 59 04 mov 0x4(%ecx),%ebx if(argc != 3){ 15: 74 13 je 2a <main+0x2a> printf(2, "Usage: ln old new\n"); 17: 52 push %edx 18: 52 push %edx 19: 68 58 07 00 00 push $0x758 1e: 6a 02 push $0x2 20: e8 db 03 00 00 call 400 <printf> exit(); 25: e8 88 02 00 00 call 2b2 <exit> } if(link(argv[1], argv[2]) < 0) 2a: 50 push %eax 2b: 50 push %eax 2c: ff 73 08 pushl 0x8(%ebx) 2f: ff 73 04 pushl 0x4(%ebx) 32: e8 db 02 00 00 call 312 <link> 37: 83 c4 10 add $0x10,%esp 3a: 85 c0 test %eax,%eax 3c: 78 05 js 43 <main+0x43> printf(2, "link %s %s: failed\n", argv[1], argv[2]); exit(); 3e: e8 6f 02 00 00 call 2b2 <exit> printf(2, "link %s %s: failed\n", argv[1], argv[2]); 43: ff 73 08 pushl 0x8(%ebx) 46: ff 73 04 pushl 0x4(%ebx) 49: 68 6b 07 00 00 push $0x76b 4e: 6a 02 push $0x2 50: e8 ab 03 00 00 call 400 <printf> 55: 83 c4 10 add $0x10,%esp 58: eb e4 jmp 3e <main+0x3e> 5a: 66 90 xchg %ax,%ax 5c: 66 90 xchg %ax,%ax 5e: 66 90 xchg %ax,%ax 00000060 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, const char *t) { 60: 55 push %ebp 61: 89 e5 mov %esp,%ebp 63: 53 push %ebx 64: 8b 45 08 mov 0x8(%ebp),%eax 67: 8b 4d 0c mov 0xc(%ebp),%ecx char *os; os = s; while((*s++ = *t++) != 0) 6a: 89 c2 mov %eax,%edx 6c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 70: 83 c1 01 add $0x1,%ecx 73: 0f b6 59 ff movzbl -0x1(%ecx),%ebx 77: 83 c2 01 add $0x1,%edx 7a: 84 db test %bl,%bl 7c: 88 5a ff mov %bl,-0x1(%edx) 7f: 75 ef jne 70 <strcpy+0x10> ; return os; } 81: 5b pop %ebx 82: 5d pop %ebp 83: c3 ret 84: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 8a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 00000090 <strcmp>: int strcmp(const char *p, const char *q) { 90: 55 push %ebp 91: 89 e5 mov %esp,%ebp 93: 53 push %ebx 94: 8b 55 08 mov 0x8(%ebp),%edx 97: 8b 4d 0c mov 0xc(%ebp),%ecx while(*p && *p == *q) 9a: 0f b6 02 movzbl (%edx),%eax 9d: 0f b6 19 movzbl (%ecx),%ebx a0: 84 c0 test %al,%al a2: 75 1c jne c0 <strcmp+0x30> a4: eb 2a jmp d0 <strcmp+0x40> a6: 8d 76 00 lea 0x0(%esi),%esi a9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi p++, q++; b0: 83 c2 01 add $0x1,%edx while(*p && *p == *q) b3: 0f b6 02 movzbl (%edx),%eax p++, q++; b6: 83 c1 01 add $0x1,%ecx b9: 0f b6 19 movzbl (%ecx),%ebx while(*p && *p == *q) bc: 84 c0 test %al,%al be: 74 10 je d0 <strcmp+0x40> c0: 38 d8 cmp %bl,%al c2: 74 ec je b0 <strcmp+0x20> return (uchar)*p - (uchar)*q; c4: 29 d8 sub %ebx,%eax } c6: 5b pop %ebx c7: 5d pop %ebp c8: c3 ret c9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi d0: 31 c0 xor %eax,%eax return (uchar)*p - (uchar)*q; d2: 29 d8 sub %ebx,%eax } d4: 5b pop %ebx d5: 5d pop %ebp d6: c3 ret d7: 89 f6 mov %esi,%esi d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000000e0 <strlen>: uint strlen(const char *s) { e0: 55 push %ebp e1: 89 e5 mov %esp,%ebp e3: 8b 4d 08 mov 0x8(%ebp),%ecx int n; for(n = 0; s[n]; n++) e6: 80 39 00 cmpb $0x0,(%ecx) e9: 74 15 je 100 <strlen+0x20> eb: 31 d2 xor %edx,%edx ed: 8d 76 00 lea 0x0(%esi),%esi f0: 83 c2 01 add $0x1,%edx f3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1) f7: 89 d0 mov %edx,%eax f9: 75 f5 jne f0 <strlen+0x10> ; return n; } fb: 5d pop %ebp fc: c3 ret fd: 8d 76 00 lea 0x0(%esi),%esi for(n = 0; s[n]; n++) 100: 31 c0 xor %eax,%eax } 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 <memset>: void* memset(void *dst, int c, uint n) { 110: 55 push %ebp 111: 89 e5 mov %esp,%ebp 113: 57 push %edi 114: 8b 55 08 mov 0x8(%ebp),%edx } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : 117: 8b 4d 10 mov 0x10(%ebp),%ecx 11a: 8b 45 0c mov 0xc(%ebp),%eax 11d: 89 d7 mov %edx,%edi 11f: fc cld 120: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 122: 89 d0 mov %edx,%eax 124: 5f pop %edi 125: 5d pop %ebp 126: c3 ret 127: 89 f6 mov %esi,%esi 129: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000130 <strchr>: char* strchr(const char *s, char c) { 130: 55 push %ebp 131: 89 e5 mov %esp,%ebp 133: 53 push %ebx 134: 8b 45 08 mov 0x8(%ebp),%eax 137: 8b 5d 0c mov 0xc(%ebp),%ebx for(; *s; s++) 13a: 0f b6 10 movzbl (%eax),%edx 13d: 84 d2 test %dl,%dl 13f: 74 1d je 15e <strchr+0x2e> if(*s == c) 141: 38 d3 cmp %dl,%bl 143: 89 d9 mov %ebx,%ecx 145: 75 0d jne 154 <strchr+0x24> 147: eb 17 jmp 160 <strchr+0x30> 149: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 150: 38 ca cmp %cl,%dl 152: 74 0c je 160 <strchr+0x30> for(; *s; s++) 154: 83 c0 01 add $0x1,%eax 157: 0f b6 10 movzbl (%eax),%edx 15a: 84 d2 test %dl,%dl 15c: 75 f2 jne 150 <strchr+0x20> return (char*)s; return 0; 15e: 31 c0 xor %eax,%eax } 160: 5b pop %ebx 161: 5d pop %ebp 162: c3 ret 163: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 169: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000170 <gets>: char* gets(char *buf, int max) { 170: 55 push %ebp 171: 89 e5 mov %esp,%ebp 173: 57 push %edi 174: 56 push %esi 175: 53 push %ebx int i, cc; char c; for(i=0; i+1 < max; ){ 176: 31 f6 xor %esi,%esi 178: 89 f3 mov %esi,%ebx { 17a: 83 ec 1c sub $0x1c,%esp 17d: 8b 7d 08 mov 0x8(%ebp),%edi for(i=0; i+1 < max; ){ 180: eb 2f jmp 1b1 <gets+0x41> 182: 8d b6 00 00 00 00 lea 0x0(%esi),%esi cc = read(0, &c, 1); 188: 8d 45 e7 lea -0x19(%ebp),%eax 18b: 83 ec 04 sub $0x4,%esp 18e: 6a 01 push $0x1 190: 50 push %eax 191: 6a 00 push $0x0 193: e8 32 01 00 00 call 2ca <read> if(cc < 1) 198: 83 c4 10 add $0x10,%esp 19b: 85 c0 test %eax,%eax 19d: 7e 1c jle 1bb <gets+0x4b> break; buf[i++] = c; 19f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax 1a3: 83 c7 01 add $0x1,%edi 1a6: 88 47 ff mov %al,-0x1(%edi) if(c == '\n' || c == '\r') 1a9: 3c 0a cmp $0xa,%al 1ab: 74 23 je 1d0 <gets+0x60> 1ad: 3c 0d cmp $0xd,%al 1af: 74 1f je 1d0 <gets+0x60> for(i=0; i+1 < max; ){ 1b1: 83 c3 01 add $0x1,%ebx 1b4: 3b 5d 0c cmp 0xc(%ebp),%ebx 1b7: 89 fe mov %edi,%esi 1b9: 7c cd jl 188 <gets+0x18> 1bb: 89 f3 mov %esi,%ebx break; } buf[i] = '\0'; return buf; } 1bd: 8b 45 08 mov 0x8(%ebp),%eax buf[i] = '\0'; 1c0: c6 03 00 movb $0x0,(%ebx) } 1c3: 8d 65 f4 lea -0xc(%ebp),%esp 1c6: 5b pop %ebx 1c7: 5e pop %esi 1c8: 5f pop %edi 1c9: 5d pop %ebp 1ca: c3 ret 1cb: 90 nop 1cc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 1d0: 8b 75 08 mov 0x8(%ebp),%esi 1d3: 8b 45 08 mov 0x8(%ebp),%eax 1d6: 01 de add %ebx,%esi 1d8: 89 f3 mov %esi,%ebx buf[i] = '\0'; 1da: c6 03 00 movb $0x0,(%ebx) } 1dd: 8d 65 f4 lea -0xc(%ebp),%esp 1e0: 5b pop %ebx 1e1: 5e pop %esi 1e2: 5f pop %edi 1e3: 5d pop %ebp 1e4: c3 ret 1e5: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 1e9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000001f0 <stat>: int stat(const char *n, struct stat *st) { 1f0: 55 push %ebp 1f1: 89 e5 mov %esp,%ebp 1f3: 56 push %esi 1f4: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); 1f5: 83 ec 08 sub $0x8,%esp 1f8: 6a 00 push $0x0 1fa: ff 75 08 pushl 0x8(%ebp) 1fd: e8 f0 00 00 00 call 2f2 <open> if(fd < 0) 202: 83 c4 10 add $0x10,%esp 205: 85 c0 test %eax,%eax 207: 78 27 js 230 <stat+0x40> return -1; r = fstat(fd, st); 209: 83 ec 08 sub $0x8,%esp 20c: ff 75 0c pushl 0xc(%ebp) 20f: 89 c3 mov %eax,%ebx 211: 50 push %eax 212: e8 f3 00 00 00 call 30a <fstat> close(fd); 217: 89 1c 24 mov %ebx,(%esp) r = fstat(fd, st); 21a: 89 c6 mov %eax,%esi close(fd); 21c: e8 b9 00 00 00 call 2da <close> return r; 221: 83 c4 10 add $0x10,%esp } 224: 8d 65 f8 lea -0x8(%ebp),%esp 227: 89 f0 mov %esi,%eax 229: 5b pop %ebx 22a: 5e pop %esi 22b: 5d pop %ebp 22c: c3 ret 22d: 8d 76 00 lea 0x0(%esi),%esi return -1; 230: be ff ff ff ff mov $0xffffffff,%esi 235: eb ed jmp 224 <stat+0x34> 237: 89 f6 mov %esi,%esi 239: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000240 <atoi>: int atoi(const char *s) { 240: 55 push %ebp 241: 89 e5 mov %esp,%ebp 243: 53 push %ebx 244: 8b 4d 08 mov 0x8(%ebp),%ecx int n; n = 0; while('0' <= *s && *s <= '9') 247: 0f be 11 movsbl (%ecx),%edx 24a: 8d 42 d0 lea -0x30(%edx),%eax 24d: 3c 09 cmp $0x9,%al n = 0; 24f: b8 00 00 00 00 mov $0x0,%eax while('0' <= *s && *s <= '9') 254: 77 1f ja 275 <atoi+0x35> 256: 8d 76 00 lea 0x0(%esi),%esi 259: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi n = n*10 + *s++ - '0'; 260: 8d 04 80 lea (%eax,%eax,4),%eax 263: 83 c1 01 add $0x1,%ecx 266: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax while('0' <= *s && *s <= '9') 26a: 0f be 11 movsbl (%ecx),%edx 26d: 8d 5a d0 lea -0x30(%edx),%ebx 270: 80 fb 09 cmp $0x9,%bl 273: 76 eb jbe 260 <atoi+0x20> return n; } 275: 5b pop %ebx 276: 5d pop %ebp 277: c3 ret 278: 90 nop 279: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000280 <memmove>: void* memmove(void *vdst, const void *vsrc, int n) { 280: 55 push %ebp 281: 89 e5 mov %esp,%ebp 283: 56 push %esi 284: 53 push %ebx 285: 8b 5d 10 mov 0x10(%ebp),%ebx 288: 8b 45 08 mov 0x8(%ebp),%eax 28b: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 28e: 85 db test %ebx,%ebx 290: 7e 14 jle 2a6 <memmove+0x26> 292: 31 d2 xor %edx,%edx 294: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi *dst++ = *src++; 298: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx 29c: 88 0c 10 mov %cl,(%eax,%edx,1) 29f: 83 c2 01 add $0x1,%edx while(n-- > 0) 2a2: 39 d3 cmp %edx,%ebx 2a4: 75 f2 jne 298 <memmove+0x18> return vdst; } 2a6: 5b pop %ebx 2a7: 5e pop %esi 2a8: 5d pop %ebp 2a9: c3 ret 000002aa <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 2aa: b8 01 00 00 00 mov $0x1,%eax 2af: cd 40 int $0x40 2b1: c3 ret 000002b2 <exit>: SYSCALL(exit) 2b2: b8 02 00 00 00 mov $0x2,%eax 2b7: cd 40 int $0x40 2b9: c3 ret 000002ba <wait>: SYSCALL(wait) 2ba: b8 03 00 00 00 mov $0x3,%eax 2bf: cd 40 int $0x40 2c1: c3 ret 000002c2 <pipe>: SYSCALL(pipe) 2c2: b8 04 00 00 00 mov $0x4,%eax 2c7: cd 40 int $0x40 2c9: c3 ret 000002ca <read>: SYSCALL(read) 2ca: b8 05 00 00 00 mov $0x5,%eax 2cf: cd 40 int $0x40 2d1: c3 ret 000002d2 <write>: SYSCALL(write) 2d2: b8 10 00 00 00 mov $0x10,%eax 2d7: cd 40 int $0x40 2d9: c3 ret 000002da <close>: SYSCALL(close) 2da: b8 15 00 00 00 mov $0x15,%eax 2df: cd 40 int $0x40 2e1: c3 ret 000002e2 <kill>: SYSCALL(kill) 2e2: b8 06 00 00 00 mov $0x6,%eax 2e7: cd 40 int $0x40 2e9: c3 ret 000002ea <exec>: SYSCALL(exec) 2ea: b8 07 00 00 00 mov $0x7,%eax 2ef: cd 40 int $0x40 2f1: c3 ret 000002f2 <open>: SYSCALL(open) 2f2: b8 0f 00 00 00 mov $0xf,%eax 2f7: cd 40 int $0x40 2f9: c3 ret 000002fa <mknod>: SYSCALL(mknod) 2fa: b8 11 00 00 00 mov $0x11,%eax 2ff: cd 40 int $0x40 301: c3 ret 00000302 <unlink>: SYSCALL(unlink) 302: b8 12 00 00 00 mov $0x12,%eax 307: cd 40 int $0x40 309: c3 ret 0000030a <fstat>: SYSCALL(fstat) 30a: b8 08 00 00 00 mov $0x8,%eax 30f: cd 40 int $0x40 311: c3 ret 00000312 <link>: SYSCALL(link) 312: b8 13 00 00 00 mov $0x13,%eax 317: cd 40 int $0x40 319: c3 ret 0000031a <mkdir>: SYSCALL(mkdir) 31a: b8 14 00 00 00 mov $0x14,%eax 31f: cd 40 int $0x40 321: c3 ret 00000322 <chdir>: SYSCALL(chdir) 322: b8 09 00 00 00 mov $0x9,%eax 327: cd 40 int $0x40 329: c3 ret 0000032a <dup>: SYSCALL(dup) 32a: b8 0a 00 00 00 mov $0xa,%eax 32f: cd 40 int $0x40 331: c3 ret 00000332 <getpid>: SYSCALL(getpid) 332: b8 0b 00 00 00 mov $0xb,%eax 337: cd 40 int $0x40 339: c3 ret 0000033a <sbrk>: SYSCALL(sbrk) 33a: b8 0c 00 00 00 mov $0xc,%eax 33f: cd 40 int $0x40 341: c3 ret 00000342 <sleep>: SYSCALL(sleep) 342: b8 0d 00 00 00 mov $0xd,%eax 347: cd 40 int $0x40 349: c3 ret 0000034a <uptime>: SYSCALL(uptime) 34a: b8 0e 00 00 00 mov $0xe,%eax 34f: cd 40 int $0x40 351: c3 ret 00000352 <lseek>: SYSCALL(lseek) 352: b8 16 00 00 00 mov $0x16,%eax 357: cd 40 int $0x40 359: c3 ret 35a: 66 90 xchg %ax,%ax 35c: 66 90 xchg %ax,%ax 35e: 66 90 xchg %ax,%ax 00000360 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 360: 55 push %ebp 361: 89 e5 mov %esp,%ebp 363: 57 push %edi 364: 56 push %esi 365: 53 push %ebx 366: 83 ec 3c sub $0x3c,%esp char buf[16]; int i, neg; uint x; neg = 0; if(sgn && xx < 0){ 369: 85 d2 test %edx,%edx { 36b: 89 45 c0 mov %eax,-0x40(%ebp) neg = 1; x = -xx; 36e: 89 d0 mov %edx,%eax if(sgn && xx < 0){ 370: 79 76 jns 3e8 <printint+0x88> 372: f6 45 08 01 testb $0x1,0x8(%ebp) 376: 74 70 je 3e8 <printint+0x88> x = -xx; 378: f7 d8 neg %eax neg = 1; 37a: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp) } else { x = xx; } i = 0; 381: 31 f6 xor %esi,%esi 383: 8d 5d d7 lea -0x29(%ebp),%ebx 386: eb 0a jmp 392 <printint+0x32> 388: 90 nop 389: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi do{ buf[i++] = digits[x % base]; 390: 89 fe mov %edi,%esi 392: 31 d2 xor %edx,%edx 394: 8d 7e 01 lea 0x1(%esi),%edi 397: f7 f1 div %ecx 399: 0f b6 92 88 07 00 00 movzbl 0x788(%edx),%edx }while((x /= base) != 0); 3a0: 85 c0 test %eax,%eax buf[i++] = digits[x % base]; 3a2: 88 14 3b mov %dl,(%ebx,%edi,1) }while((x /= base) != 0); 3a5: 75 e9 jne 390 <printint+0x30> if(neg) 3a7: 8b 45 c4 mov -0x3c(%ebp),%eax 3aa: 85 c0 test %eax,%eax 3ac: 74 08 je 3b6 <printint+0x56> buf[i++] = '-'; 3ae: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1) 3b3: 8d 7e 02 lea 0x2(%esi),%edi 3b6: 8d 74 3d d7 lea -0x29(%ebp,%edi,1),%esi 3ba: 8b 7d c0 mov -0x40(%ebp),%edi 3bd: 8d 76 00 lea 0x0(%esi),%esi 3c0: 0f b6 06 movzbl (%esi),%eax write(fd, &c, 1); 3c3: 83 ec 04 sub $0x4,%esp 3c6: 83 ee 01 sub $0x1,%esi 3c9: 6a 01 push $0x1 3cb: 53 push %ebx 3cc: 57 push %edi 3cd: 88 45 d7 mov %al,-0x29(%ebp) 3d0: e8 fd fe ff ff call 2d2 <write> while(--i >= 0) 3d5: 83 c4 10 add $0x10,%esp 3d8: 39 de cmp %ebx,%esi 3da: 75 e4 jne 3c0 <printint+0x60> putc(fd, buf[i]); } 3dc: 8d 65 f4 lea -0xc(%ebp),%esp 3df: 5b pop %ebx 3e0: 5e pop %esi 3e1: 5f pop %edi 3e2: 5d pop %ebp 3e3: c3 ret 3e4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; 3e8: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp) 3ef: eb 90 jmp 381 <printint+0x21> 3f1: eb 0d jmp 400 <printf> 3f3: 90 nop 3f4: 90 nop 3f5: 90 nop 3f6: 90 nop 3f7: 90 nop 3f8: 90 nop 3f9: 90 nop 3fa: 90 nop 3fb: 90 nop 3fc: 90 nop 3fd: 90 nop 3fe: 90 nop 3ff: 90 nop 00000400 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 400: 55 push %ebp 401: 89 e5 mov %esp,%ebp 403: 57 push %edi 404: 56 push %esi 405: 53 push %ebx 406: 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++){ 409: 8b 75 0c mov 0xc(%ebp),%esi 40c: 0f b6 1e movzbl (%esi),%ebx 40f: 84 db test %bl,%bl 411: 0f 84 b3 00 00 00 je 4ca <printf+0xca> ap = (uint*)(void*)&fmt + 1; 417: 8d 45 10 lea 0x10(%ebp),%eax 41a: 83 c6 01 add $0x1,%esi state = 0; 41d: 31 ff xor %edi,%edi ap = (uint*)(void*)&fmt + 1; 41f: 89 45 d4 mov %eax,-0x2c(%ebp) 422: eb 2f jmp 453 <printf+0x53> 424: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ 428: 83 f8 25 cmp $0x25,%eax 42b: 0f 84 a7 00 00 00 je 4d8 <printf+0xd8> write(fd, &c, 1); 431: 8d 45 e2 lea -0x1e(%ebp),%eax 434: 83 ec 04 sub $0x4,%esp 437: 88 5d e2 mov %bl,-0x1e(%ebp) 43a: 6a 01 push $0x1 43c: 50 push %eax 43d: ff 75 08 pushl 0x8(%ebp) 440: e8 8d fe ff ff call 2d2 <write> 445: 83 c4 10 add $0x10,%esp 448: 83 c6 01 add $0x1,%esi for(i = 0; fmt[i]; i++){ 44b: 0f b6 5e ff movzbl -0x1(%esi),%ebx 44f: 84 db test %bl,%bl 451: 74 77 je 4ca <printf+0xca> if(state == 0){ 453: 85 ff test %edi,%edi c = fmt[i] & 0xff; 455: 0f be cb movsbl %bl,%ecx 458: 0f b6 c3 movzbl %bl,%eax if(state == 0){ 45b: 74 cb je 428 <printf+0x28> state = '%'; } else { putc(fd, c); } } else if(state == '%'){ 45d: 83 ff 25 cmp $0x25,%edi 460: 75 e6 jne 448 <printf+0x48> if(c == 'd'){ 462: 83 f8 64 cmp $0x64,%eax 465: 0f 84 05 01 00 00 je 570 <printf+0x170> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 46b: 81 e1 f7 00 00 00 and $0xf7,%ecx 471: 83 f9 70 cmp $0x70,%ecx 474: 74 72 je 4e8 <printf+0xe8> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 476: 83 f8 73 cmp $0x73,%eax 479: 0f 84 99 00 00 00 je 518 <printf+0x118> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 47f: 83 f8 63 cmp $0x63,%eax 482: 0f 84 08 01 00 00 je 590 <printf+0x190> putc(fd, *ap); ap++; } else if(c == '%'){ 488: 83 f8 25 cmp $0x25,%eax 48b: 0f 84 ef 00 00 00 je 580 <printf+0x180> write(fd, &c, 1); 491: 8d 45 e7 lea -0x19(%ebp),%eax 494: 83 ec 04 sub $0x4,%esp 497: c6 45 e7 25 movb $0x25,-0x19(%ebp) 49b: 6a 01 push $0x1 49d: 50 push %eax 49e: ff 75 08 pushl 0x8(%ebp) 4a1: e8 2c fe ff ff call 2d2 <write> 4a6: 83 c4 0c add $0xc,%esp 4a9: 8d 45 e6 lea -0x1a(%ebp),%eax 4ac: 88 5d e6 mov %bl,-0x1a(%ebp) 4af: 6a 01 push $0x1 4b1: 50 push %eax 4b2: ff 75 08 pushl 0x8(%ebp) 4b5: 83 c6 01 add $0x1,%esi } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 4b8: 31 ff xor %edi,%edi write(fd, &c, 1); 4ba: e8 13 fe ff ff call 2d2 <write> for(i = 0; fmt[i]; i++){ 4bf: 0f b6 5e ff movzbl -0x1(%esi),%ebx write(fd, &c, 1); 4c3: 83 c4 10 add $0x10,%esp for(i = 0; fmt[i]; i++){ 4c6: 84 db test %bl,%bl 4c8: 75 89 jne 453 <printf+0x53> } } } 4ca: 8d 65 f4 lea -0xc(%ebp),%esp 4cd: 5b pop %ebx 4ce: 5e pop %esi 4cf: 5f pop %edi 4d0: 5d pop %ebp 4d1: c3 ret 4d2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi state = '%'; 4d8: bf 25 00 00 00 mov $0x25,%edi 4dd: e9 66 ff ff ff jmp 448 <printf+0x48> 4e2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi printint(fd, *ap, 16, 0); 4e8: 83 ec 0c sub $0xc,%esp 4eb: b9 10 00 00 00 mov $0x10,%ecx 4f0: 6a 00 push $0x0 4f2: 8b 7d d4 mov -0x2c(%ebp),%edi 4f5: 8b 45 08 mov 0x8(%ebp),%eax 4f8: 8b 17 mov (%edi),%edx 4fa: e8 61 fe ff ff call 360 <printint> ap++; 4ff: 89 f8 mov %edi,%eax 501: 83 c4 10 add $0x10,%esp state = 0; 504: 31 ff xor %edi,%edi ap++; 506: 83 c0 04 add $0x4,%eax 509: 89 45 d4 mov %eax,-0x2c(%ebp) 50c: e9 37 ff ff ff jmp 448 <printf+0x48> 511: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi s = (char*)*ap; 518: 8b 45 d4 mov -0x2c(%ebp),%eax 51b: 8b 08 mov (%eax),%ecx ap++; 51d: 83 c0 04 add $0x4,%eax 520: 89 45 d4 mov %eax,-0x2c(%ebp) if(s == 0) 523: 85 c9 test %ecx,%ecx 525: 0f 84 8e 00 00 00 je 5b9 <printf+0x1b9> while(*s != 0){ 52b: 0f b6 01 movzbl (%ecx),%eax state = 0; 52e: 31 ff xor %edi,%edi s = (char*)*ap; 530: 89 cb mov %ecx,%ebx while(*s != 0){ 532: 84 c0 test %al,%al 534: 0f 84 0e ff ff ff je 448 <printf+0x48> 53a: 89 75 d0 mov %esi,-0x30(%ebp) 53d: 89 de mov %ebx,%esi 53f: 8b 5d 08 mov 0x8(%ebp),%ebx 542: 8d 7d e3 lea -0x1d(%ebp),%edi 545: 8d 76 00 lea 0x0(%esi),%esi write(fd, &c, 1); 548: 83 ec 04 sub $0x4,%esp s++; 54b: 83 c6 01 add $0x1,%esi 54e: 88 45 e3 mov %al,-0x1d(%ebp) write(fd, &c, 1); 551: 6a 01 push $0x1 553: 57 push %edi 554: 53 push %ebx 555: e8 78 fd ff ff call 2d2 <write> while(*s != 0){ 55a: 0f b6 06 movzbl (%esi),%eax 55d: 83 c4 10 add $0x10,%esp 560: 84 c0 test %al,%al 562: 75 e4 jne 548 <printf+0x148> 564: 8b 75 d0 mov -0x30(%ebp),%esi state = 0; 567: 31 ff xor %edi,%edi 569: e9 da fe ff ff jmp 448 <printf+0x48> 56e: 66 90 xchg %ax,%ax printint(fd, *ap, 10, 1); 570: 83 ec 0c sub $0xc,%esp 573: b9 0a 00 00 00 mov $0xa,%ecx 578: 6a 01 push $0x1 57a: e9 73 ff ff ff jmp 4f2 <printf+0xf2> 57f: 90 nop write(fd, &c, 1); 580: 83 ec 04 sub $0x4,%esp 583: 88 5d e5 mov %bl,-0x1b(%ebp) 586: 8d 45 e5 lea -0x1b(%ebp),%eax 589: 6a 01 push $0x1 58b: e9 21 ff ff ff jmp 4b1 <printf+0xb1> putc(fd, *ap); 590: 8b 7d d4 mov -0x2c(%ebp),%edi write(fd, &c, 1); 593: 83 ec 04 sub $0x4,%esp putc(fd, *ap); 596: 8b 07 mov (%edi),%eax write(fd, &c, 1); 598: 6a 01 push $0x1 ap++; 59a: 83 c7 04 add $0x4,%edi putc(fd, *ap); 59d: 88 45 e4 mov %al,-0x1c(%ebp) write(fd, &c, 1); 5a0: 8d 45 e4 lea -0x1c(%ebp),%eax 5a3: 50 push %eax 5a4: ff 75 08 pushl 0x8(%ebp) 5a7: e8 26 fd ff ff call 2d2 <write> ap++; 5ac: 89 7d d4 mov %edi,-0x2c(%ebp) 5af: 83 c4 10 add $0x10,%esp state = 0; 5b2: 31 ff xor %edi,%edi 5b4: e9 8f fe ff ff jmp 448 <printf+0x48> s = "(null)"; 5b9: bb 7f 07 00 00 mov $0x77f,%ebx while(*s != 0){ 5be: b8 28 00 00 00 mov $0x28,%eax 5c3: e9 72 ff ff ff jmp 53a <printf+0x13a> 5c8: 66 90 xchg %ax,%ax 5ca: 66 90 xchg %ax,%ax 5cc: 66 90 xchg %ax,%ax 5ce: 66 90 xchg %ax,%ax 000005d0 <free>: static Header base; static Header *freep; void free(void *ap) { 5d0: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 5d1: a1 30 0a 00 00 mov 0xa30,%eax { 5d6: 89 e5 mov %esp,%ebp 5d8: 57 push %edi 5d9: 56 push %esi 5da: 53 push %ebx 5db: 8b 5d 08 mov 0x8(%ebp),%ebx bp = (Header*)ap - 1; 5de: 8d 4b f8 lea -0x8(%ebx),%ecx 5e1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 5e8: 39 c8 cmp %ecx,%eax 5ea: 8b 10 mov (%eax),%edx 5ec: 73 32 jae 620 <free+0x50> 5ee: 39 d1 cmp %edx,%ecx 5f0: 72 04 jb 5f6 <free+0x26> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 5f2: 39 d0 cmp %edx,%eax 5f4: 72 32 jb 628 <free+0x58> break; if(bp + bp->s.size == p->s.ptr){ 5f6: 8b 73 fc mov -0x4(%ebx),%esi 5f9: 8d 3c f1 lea (%ecx,%esi,8),%edi 5fc: 39 fa cmp %edi,%edx 5fe: 74 30 je 630 <free+0x60> bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; 600: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 603: 8b 50 04 mov 0x4(%eax),%edx 606: 8d 34 d0 lea (%eax,%edx,8),%esi 609: 39 f1 cmp %esi,%ecx 60b: 74 3a je 647 <free+0x77> p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; 60d: 89 08 mov %ecx,(%eax) freep = p; 60f: a3 30 0a 00 00 mov %eax,0xa30 } 614: 5b pop %ebx 615: 5e pop %esi 616: 5f pop %edi 617: 5d pop %ebp 618: c3 ret 619: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 620: 39 d0 cmp %edx,%eax 622: 72 04 jb 628 <free+0x58> 624: 39 d1 cmp %edx,%ecx 626: 72 ce jb 5f6 <free+0x26> { 628: 89 d0 mov %edx,%eax 62a: eb bc jmp 5e8 <free+0x18> 62c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi bp->s.size += p->s.ptr->s.size; 630: 03 72 04 add 0x4(%edx),%esi 633: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 636: 8b 10 mov (%eax),%edx 638: 8b 12 mov (%edx),%edx 63a: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 63d: 8b 50 04 mov 0x4(%eax),%edx 640: 8d 34 d0 lea (%eax,%edx,8),%esi 643: 39 f1 cmp %esi,%ecx 645: 75 c6 jne 60d <free+0x3d> p->s.size += bp->s.size; 647: 03 53 fc add -0x4(%ebx),%edx freep = p; 64a: a3 30 0a 00 00 mov %eax,0xa30 p->s.size += bp->s.size; 64f: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 652: 8b 53 f8 mov -0x8(%ebx),%edx 655: 89 10 mov %edx,(%eax) } 657: 5b pop %ebx 658: 5e pop %esi 659: 5f pop %edi 65a: 5d pop %ebp 65b: c3 ret 65c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000660 <malloc>: return freep; } void* malloc(uint nbytes) { 660: 55 push %ebp 661: 89 e5 mov %esp,%ebp 663: 57 push %edi 664: 56 push %esi 665: 53 push %ebx 666: 83 ec 0c sub $0xc,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 669: 8b 45 08 mov 0x8(%ebp),%eax if((prevp = freep) == 0){ 66c: 8b 15 30 0a 00 00 mov 0xa30,%edx nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 672: 8d 78 07 lea 0x7(%eax),%edi 675: c1 ef 03 shr $0x3,%edi 678: 83 c7 01 add $0x1,%edi if((prevp = freep) == 0){ 67b: 85 d2 test %edx,%edx 67d: 0f 84 9d 00 00 00 je 720 <malloc+0xc0> 683: 8b 02 mov (%edx),%eax 685: 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){ 688: 39 cf cmp %ecx,%edi 68a: 76 6c jbe 6f8 <malloc+0x98> 68c: 81 ff 00 10 00 00 cmp $0x1000,%edi 692: bb 00 10 00 00 mov $0x1000,%ebx 697: 0f 43 df cmovae %edi,%ebx p = sbrk(nu * sizeof(Header)); 69a: 8d 34 dd 00 00 00 00 lea 0x0(,%ebx,8),%esi 6a1: eb 0e jmp 6b1 <malloc+0x51> 6a3: 90 nop 6a4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 6a8: 8b 02 mov (%edx),%eax if(p->s.size >= nunits){ 6aa: 8b 48 04 mov 0x4(%eax),%ecx 6ad: 39 f9 cmp %edi,%ecx 6af: 73 47 jae 6f8 <malloc+0x98> p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if(p == freep) 6b1: 39 05 30 0a 00 00 cmp %eax,0xa30 6b7: 89 c2 mov %eax,%edx 6b9: 75 ed jne 6a8 <malloc+0x48> p = sbrk(nu * sizeof(Header)); 6bb: 83 ec 0c sub $0xc,%esp 6be: 56 push %esi 6bf: e8 76 fc ff ff call 33a <sbrk> if(p == (char*)-1) 6c4: 83 c4 10 add $0x10,%esp 6c7: 83 f8 ff cmp $0xffffffff,%eax 6ca: 74 1c je 6e8 <malloc+0x88> hp->s.size = nu; 6cc: 89 58 04 mov %ebx,0x4(%eax) free((void*)(hp + 1)); 6cf: 83 ec 0c sub $0xc,%esp 6d2: 83 c0 08 add $0x8,%eax 6d5: 50 push %eax 6d6: e8 f5 fe ff ff call 5d0 <free> return freep; 6db: 8b 15 30 0a 00 00 mov 0xa30,%edx if((p = morecore(nunits)) == 0) 6e1: 83 c4 10 add $0x10,%esp 6e4: 85 d2 test %edx,%edx 6e6: 75 c0 jne 6a8 <malloc+0x48> return 0; } } 6e8: 8d 65 f4 lea -0xc(%ebp),%esp return 0; 6eb: 31 c0 xor %eax,%eax } 6ed: 5b pop %ebx 6ee: 5e pop %esi 6ef: 5f pop %edi 6f0: 5d pop %ebp 6f1: c3 ret 6f2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi if(p->s.size == nunits) 6f8: 39 cf cmp %ecx,%edi 6fa: 74 54 je 750 <malloc+0xf0> p->s.size -= nunits; 6fc: 29 f9 sub %edi,%ecx 6fe: 89 48 04 mov %ecx,0x4(%eax) p += p->s.size; 701: 8d 04 c8 lea (%eax,%ecx,8),%eax p->s.size = nunits; 704: 89 78 04 mov %edi,0x4(%eax) freep = prevp; 707: 89 15 30 0a 00 00 mov %edx,0xa30 } 70d: 8d 65 f4 lea -0xc(%ebp),%esp return (void*)(p + 1); 710: 83 c0 08 add $0x8,%eax } 713: 5b pop %ebx 714: 5e pop %esi 715: 5f pop %edi 716: 5d pop %ebp 717: c3 ret 718: 90 nop 719: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi base.s.ptr = freep = prevp = &base; 720: c7 05 30 0a 00 00 34 movl $0xa34,0xa30 727: 0a 00 00 72a: c7 05 34 0a 00 00 34 movl $0xa34,0xa34 731: 0a 00 00 base.s.size = 0; 734: b8 34 0a 00 00 mov $0xa34,%eax 739: c7 05 38 0a 00 00 00 movl $0x0,0xa38 740: 00 00 00 743: e9 44 ff ff ff jmp 68c <malloc+0x2c> 748: 90 nop 749: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi prevp->s.ptr = p->s.ptr; 750: 8b 08 mov (%eax),%ecx 752: 89 0a mov %ecx,(%edx) 754: eb b1 jmp 707 <malloc+0xa7>
<% from pwnlib.shellcraft.i386.linux import syscall %> <%page args="file, owner, group"/> <%docstring> Invokes the syscall lchown. See 'man 2 lchown' for more information. Arguments: file(char): file owner(uid_t): owner group(gid_t): group </%docstring> ${syscall('SYS_lchown', file, owner, group)}
CHECK 0 ADD 0 ADD 1 JZ error EXIT 0 error: EXIT 1
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r14 push %rax push %rbp push %rcx push %rdi push %rdx push %rsi lea addresses_WC_ht+0xae56, %r11 nop nop nop nop sub %rcx, %rcx mov $0x6162636465666768, %rbp movq %rbp, (%r11) nop nop nop cmp $5271, %rbp lea addresses_A_ht+0x19556, %rdx nop nop nop cmp %r14, %r14 vmovups (%rdx), %ymm1 vextracti128 $1, %ymm1, %xmm1 vpextrq $1, %xmm1, %rcx nop nop nop nop xor %r14, %r14 lea addresses_A_ht+0x168da, %rsi lea addresses_D_ht+0xae56, %rdi clflush (%rsi) nop nop nop and %rax, %rax mov $43, %rcx rep movsb nop nop lfence lea addresses_WT_ht+0x16756, %rsi lea addresses_UC_ht+0x2a53, %rdi nop nop cmp $60051, %rax mov $116, %rcx rep movsw nop nop nop xor $31487, %rcx lea addresses_UC_ht+0x7cd8, %rsi lea addresses_D_ht+0x17056, %rdi nop nop nop dec %r11 mov $87, %rcx rep movsb and %rdx, %rdx lea addresses_WC_ht+0xffee, %rsi nop nop and %rax, %rax mov (%rsi), %r11w nop nop nop and $7793, %rcx lea addresses_D_ht+0x1cb56, %r14 sub $28474, %r11 mov (%r14), %di nop nop nop nop xor %rcx, %rcx lea addresses_WT_ht+0x12e56, %r14 sub %rdi, %rdi mov (%r14), %ax nop nop sub %r11, %r11 lea addresses_UC_ht+0x1c556, %rsi lea addresses_WT_ht+0xed06, %rdi add %r14, %r14 mov $103, %rcx rep movsw nop nop nop nop nop cmp $7782, %rdi lea addresses_normal_ht+0x1cb1a, %rsi lea addresses_normal_ht+0xcc96, %rdi nop nop nop and %rax, %rax mov $66, %rcx rep movsw nop nop nop nop sub $18454, %rcx lea addresses_UC_ht+0x5c1e, %rsi lea addresses_WT_ht+0x3ad6, %rdi nop cmp %r11, %r11 mov $125, %rcx rep movsb nop nop nop nop nop and %rsi, %rsi lea addresses_UC_ht+0x10a86, %rsi lea addresses_A_ht+0x3e56, %rdi nop nop nop and $31406, %rbp mov $50, %rcx rep movsl nop nop nop cmp %rcx, %rcx lea addresses_WT_ht+0x1ca66, %rbp nop nop nop nop nop xor %rdx, %rdx mov $0x6162636465666768, %r14 movq %r14, (%rbp) nop sub $989, %r11 pop %rsi pop %rdx pop %rdi pop %rcx pop %rbp pop %rax pop %r14 pop %r11 ret .global s_faulty_load s_faulty_load: push %r13 push %r9 push %rax push %rbp push %rcx push %rdi push %rsi // REPMOV lea addresses_WT+0xf0d6, %rsi lea addresses_US+0x2656, %rdi nop sub %r9, %r9 mov $56, %rcx rep movsb nop nop nop nop add %rsi, %rsi // Faulty Load lea addresses_UC+0x1a656, %rsi cmp $48894, %rcx movb (%rsi), %r9b lea oracles, %rdi and $0xff, %r9 shlq $12, %r9 mov (%rdi,%r9,1), %r9 pop %rsi pop %rdi pop %rcx pop %rbp pop %rax pop %r9 pop %r13 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_UC', 'AVXalign': False, 'congruent': 0, 'size': 8, 'same': True, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_US', 'congruent': 9, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_UC', 'AVXalign': True, 'congruent': 0, 'size': 1, 'same': True, 'NT': False}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 9, 'size': 8, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 7, 'size': 32, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 11, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 7, 'same': True}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 0, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 8, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 3, 'size': 2, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 7, 'size': 2, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 11, 'size': 2, 'same': False, 'NT': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 4, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 6, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 7, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 11, 'same': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 3, 'size': 8, 'same': False, 'NT': False}} {'5f': 4523, '00': 17306} 00 00 00 00 00 00 00 5f 00 5f 00 00 00 00 00 00 00 5f 00 00 00 00 00 00 5f 00 00 00 00 00 00 00 00 5f 00 5f 00 00 00 00 00 00 00 00 00 00 5f 00 00 00 00 5f 00 00 00 00 00 5f 00 5f 5f 00 00 00 5f 00 5f 5f 5f 00 5f 00 00 00 5f 00 00 00 00 00 5f 00 00 00 00 00 00 00 5f 00 00 00 5f 00 00 00 5f 5f 00 00 00 00 00 00 00 5f 00 00 00 00 5f 00 00 5f 00 00 00 00 5f 5f 00 00 00 00 5f 00 00 5f 00 00 00 00 00 00 00 00 00 5f 5f 00 5f 00 00 00 00 00 00 00 00 5f 00 5f 00 5f 00 00 00 00 00 5f 00 00 5f 00 5f 00 00 5f 00 5f 00 00 00 00 00 00 00 5f 00 5f 00 5f 00 00 00 00 00 00 00 00 00 00 00 00 5f 00 00 00 00 5f 00 00 00 5f 00 5f 00 00 5f 00 00 00 5f 00 00 5f 00 00 00 00 00 00 00 00 5f 00 00 00 00 00 00 00 00 00 5f 00 00 5f 00 00 5f 00 00 00 5f 00 00 00 5f 00 00 00 00 00 00 00 00 00 00 5f 00 5f 00 00 00 5f 00 00 5f 00 00 00 5f 00 5f 00 5f 00 00 5f 5f 00 00 00 5f 00 00 5f 00 5f 5f 00 00 00 00 00 00 5f 00 00 5f 5f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5f 00 5f 00 00 00 00 00 5f 00 00 5f 00 5f 5f 00 00 00 00 00 5f 00 00 00 00 5f 00 5f 00 00 00 00 00 00 00 00 5f 00 5f 00 00 00 5f 00 00 00 00 00 00 00 5f 00 00 00 5f 00 00 00 5f 00 00 00 00 00 00 00 5f 00 00 5f 5f 00 00 5f 00 5f 00 00 5f 00 00 00 00 00 00 00 00 00 00 00 00 5f 00 00 00 00 5f 00 5f 5f 00 00 00 5f 00 00 5f 00 00 00 00 00 00 00 5f 00 00 00 00 00 00 5f 00 00 00 00 5f 00 00 00 00 5f 00 00 00 00 00 00 00 00 5f 00 00 5f 00 00 00 00 00 00 00 00 00 00 00 00 5f 00 00 00 00 00 00 00 5f 00 00 00 00 00 5f 00 00 00 5f 00 00 5f 00 00 00 00 5f 00 5f 00 00 00 00 00 00 5f 00 00 00 00 5f 00 5f 00 00 00 00 5f 00 00 00 5f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5f 00 00 00 5f 00 00 00 00 00 00 00 5f 00 00 00 5f 00 00 00 00 5f 00 00 5f 00 00 00 00 00 00 00 5f 00 00 5f 00 00 5f 00 00 00 5f 00 00 00 00 00 5f 00 00 00 00 5f 00 00 5f 00 00 00 00 00 5f 00 00 5f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5f 00 00 5f 00 00 00 5f 00 00 5f 00 00 00 00 00 00 00 5f 00 00 00 00 00 00 00 00 5f 00 00 00 00 00 00 5f 00 00 00 00 5f 00 5f 00 5f 00 00 00 00 00 00 5f 00 00 5f 5f 00 00 00 5f 00 00 5f 00 5f 00 00 00 00 00 00 00 00 00 00 5f 00 00 5f 00 00 00 5f 00 00 00 00 5f 00 5f 5f 00 00 00 00 00 5f 5f 00 00 00 00 00 5f 00 5f 00 00 00 5f 00 00 5f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5f 5f 00 00 00 00 00 00 5f 5f 5f 00 5f 00 00 00 00 00 5f 00 5f 00 00 00 00 00 00 00 00 00 00 5f 00 00 00 00 00 5f 5f 5f 00 00 5f 00 00 00 00 00 00 00 00 00 00 00 00 5f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5f 00 00 00 00 00 5f 00 00 5f 00 00 00 00 00 00 00 00 00 00 00 5f 5f 00 00 00 00 00 5f 00 00 5f 00 00 00 00 00 00 00 00 5f 5f 00 00 00 5f 00 00 00 00 00 00 00 5f 00 00 00 00 00 00 00 00 00 5f 00 5f 00 00 00 00 00 00 00 00 00 5f 00 00 00 5f 5f 00 5f 00 00 00 00 00 00 00 00 00 00 00 00 00 5f 00 5f 00 00 5f 5f 00 00 5f 00 00 00 00 00 00 00 00 5f 00 00 00 00 00 00 00 5f 00 00 00 00 00 5f 00 5f 00 00 00 00 5f 00 5f 00 00 00 5f 00 5f 00 00 00 5f 00 5f 00 00 5f 00 5f 00 00 00 5f 00 00 00 00 00 */
;************************************************* .define gpu_addr, 0x2000 .define gpu_ctrl_reg, 0x80 .define gpu_isr_vector, 0x14 ;************************************************* .code ldi r0, 0b00001100 out r0, gpu_ctrl_reg ldi r2, gpu_addr[l] ldi r3, gpu_addr[h] stable: in r0, gpu_ctrl_reg ani r0, 0x80 bz stable ldi r0, text[l] ldi r1, text[h] loop: lri r4, p0 cpi r4, 0 bz end sri r4, p2 br loop end: hlt ;************************************************* .data text: .string "GitHub repo at: https://github.com/ept221/tinySoC" ;*************************************************
; A284557: a(n) = A048727(n) mod 3. ; Submitted by Jamie Morken(s1) ; 0,1,2,0,1,0,0,0,2,0,0,1,0,2,0,0,1,2,0,1,0,2,2,2,0,1,1,2,0,2,0,0,2,0,1,2,0,2,2,2,0,1,1,2,1,0,1,1,0,1,2,0,2,1,1,1,0,1,1,2,0,2,0,0,1,2,0,1,2,1,1,1,0,1,1,2,1,0,1,1,0,1,2,0,2,1,1,1,2,0,0,1,2,1,2,2,0,1,2,0 seq $0,48727 ; a(n) = Xmult(n,7) or rule150(n,1). mod $0,3
// Copyright 2020 Google LLC // // 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 "third_party/pybind11/include/pybind11/pybind11.h" #include "clif/testing/operators.h" #include <pybind11/operators.h> // NOLINT namespace py = pybind11; PYBIND11_MODULE(operators, m) { py::class_<clif_ops_test::Abc>(m, "Abc") .def(py::init<::uint8_t, ::uint8_t>()) .def("__bool__", (bool (::clif_ops_test::Abc::*)()) &::clif_ops_test::Abc::operator bool) .def(py::self == py::self) // eq .def(py::self != py::self) // ne .def(py::self < py::self) // lt .def(py::self <= py::self) // le .def(py::self > py::self) // gt .def(py::self >= py::self) // ge .def(int_(py::self)) // int .def(float_(py::self)) // float .def(py::self += int()) // iadd .def("__len__", (int (::clif_ops_test::Abc::*)()) &::clif_ops_test::Abc::length) // __len__ // This does not work for negative indexes. .def("__getitem__", (char (::clif_ops_test::Abc::*)(int)) &::clif_ops_test::Abc::operator[]) // __getitem__ .def("__contains__", (bool (*)(const ::clif_ops_test::Abc &, ::uint8_t)) &::clif_ops_test::Abc_has, py::arg("k")); // __getitem__ py::class_<clif_ops_test::Num>(m, "Num") .def(py::init<>()) .def(py::self + int()) // add .def(int() - py::self) // rsub .def(py::self % int()) // mod .def(int() % py::self); // rmod }
org 0E NOP LOADIM R1, #5 LOADIM R5, #AC LOADIM R6, #79 ROTAR R3, R5, R1 ROTAL R4, R6, R1 GRTEQ R3, R4 JMPADDR greater greater: XOR R1, R3, R4 NOT R3, R3 NEG R4, R4 fin: JMPADDR fin
db JIGGLYPUFF ; pokedex id db 115 ; base hp db 45 ; base attack db 20 ; base defense db 20 ; base speed db 25 ; base special db NORMAL ; species type 1 db NORMAL ; species type 2 db 170 ; catch rate db 76 ; base exp yield INCBIN "pic/gsmon/jigglypuff.pic",0,1 ; 55, sprite dimensions dw JigglypuffPicFront dw JigglypuffPicBack ; attacks known at lvl 0 db SING db 0 db 0 db 0 db 4 ; growth rate ; learnset tmlearn 1,5,6,8 tmlearn 9,10,11,13,14 tmlearn 17,18,19,20,22,24 tmlearn 25,29,31,32 tmlearn 33,34,38 tmlearn 41,44,45,46 tmlearn 49,50,54,55 db BANK(JigglypuffPicFront)
; A051708: Number of ways to move a chess rook from the lower left corner to square (n,n), with the rook moving only up or right. ; Submitted by Jon Maiga ; 1,2,14,106,838,6802,56190,470010,3968310,33747490,288654574,2480593546,21400729382,185239360178,1607913963614,13991107041306,122002082809110,1065855419418690,9327252391907790,81744134786314410,717367363052796678,6303080714967178962,55442415802430586174,488166038461550194746,4302218944630062062838,37947642101127770120802,334977761601783084811950,2959107762596925411599050,26157526097740725747576550,231368076739562525423902450,2047683932826690652874600990,18132543469364133527040005210 mov $1,2 mov $3,$0 mov $4,2 lpb $3 mov $0,$4 add $0,1 mul $0,2 add $2,$1 sub $3,1 mul $1,$3 mul $1,$0 mul $1,2 add $5,$4 div $1,$5 add $2,$1 add $4,2 lpe mov $0,$2 div $0,2 add $0,1
.include "header.inc" .include "misc_macros.inc" .include "zeropage.inc" .define TEXT_SCREEN_BYTE_PITCH 64 ; define characters used for drawing boxes .define FIRST_BOX_CHAR $80 .define BOX_CHAR_UL FIRST_BOX_CHAR+0 ; upper left corner .define BOX_CHAR_UR FIRST_BOX_CHAR+1 ; upper right corner .define BOX_CHAR_LL FIRST_BOX_CHAR+2 ; lower left corner .define BOX_CHAR_LR FIRST_BOX_CHAR+3 ; lower right corner .define BOX_CHAR_HB FIRST_BOX_CHAR+4 ; horizontal bar, bottom .define BOX_CHAR_VR FIRST_BOX_CHAR+5 ; vertical bar, right .define BOX_CHAR_HT FIRST_BOX_CHAR+6 ; horizontal bar, top .define BOX_CHAR_VL FIRST_BOX_CHAR+7 ; vertical bar, left .define BOX_CHAR_FILL FIRST_BOX_CHAR+8 ; Filler ; word addresses for bgmap in bank 7F .define TEXT_SCREEN_RAM_START $0 .define TEXT_SCREEN_RAM_MAX TEXT_SCREEN_RAM_START+32*32 .define TEXT_SCREEN_RAM_BANK $7F .bank 0 slot 1 .ramsection "text_variables" SLOT RAM_SLOT text_cursor_x: dw text_cursor_y: dw ; text_vram_ptr: dw ; word address for current cursor x,y ; arguments for drawing text boxes text_box_x: dw text_box_y: dw text_box_w: dw text_box_h: dw .ends .16BIT .section "text screen" FREE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Initialize the text system ; text_init: pushall A16 stz text_cursor_x stz text_cursor_y jsr _text_xy_to_ptr ; sets text_vram_ptr popall rts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Move the cursor to X,Y ; ; X: X coordinate ; Y: Y coordinate ; text_gotoxy: pushall XY16 stx text_cursor_x sty text_cursor_y jsr _text_xy_to_ptr popall rts text_putbcd: pushall popall rts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; print a character ; ; A: character ; Y: Y coordinate ; text_putchar: pushall XY16 A8 sta [dp_text_ptr] inc dp_text_ptr inc dp_text_ptr lda #1 sta bg1_need_resync popall rts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Print a string to the screen ; ; Y: 16-bit pointer to zero-terminated string ; text_print: pushall XY16 A8 ; Set pointer in RAM ldx dp_text_ptr @next_char: lda 0, Y ; Get new character beq @done ; 0 means end of string sta [dp_text_ptr] iny ; Advance to next ASCII character inc dp_text_ptr ; Increase vram pointer inc dp_text_ptr ; Increase vram pointer bra @next_char @done: stx dp_text_ptr lda #1 sta bg1_need_resync popall rts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Erase a box ; text_clearBox: pushall A16 XY16 ; This sets dp_text_ptr to the upper-left corner of the box ldx text_box_x ldy text_box_y jsr text_gotoxy ; save line origin lda dp_text_ptr sta dp_text_tmp ldy text_box_h ; Load height in X @lp_y: ldx text_box_w ; Load width in X @lp_x: lda #0 sta [dp_text_ptr] inc dp_text_ptr inc dp_text_ptr dex bne @lp_x lda dp_text_tmp clc adc #TEXT_SCREEN_BYTE_PITCH sta dp_text_tmp sta dp_text_ptr dey bne @lp_y A8 lda #1 sta bg1_need_resync popall rts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Draw a box ; text_drawBox: pushall A16 XY16 ; This sets dp_text_ptr to the upper-left corner of the box ldx text_box_x ldy text_box_y jsr text_gotoxy ; Save start of line ptr ldx dp_text_ptr stx dp_text_tmp ;;; Top line of the box ;;; ldx dp_text_ptr ; ldx text_box_w ; Load width in X ; Upper left corner lda #BOX_CHAR_UL sta [dp_text_ptr] inc dp_text_ptr inc dp_text_ptr ; Horizontal bar, top ldy text_box_w ; Load height in W dey dey lda #BOX_CHAR_HT @lp_horiz_top: sta [dp_text_ptr] inc dp_text_ptr inc dp_text_ptr dey bne @lp_horiz_top ; Upper right corner lda #BOX_CHAR_UR sta [dp_text_ptr] inc dp_text_ptr inc dp_text_ptr ;;; Middle lines of the box ;;; ldy text_box_h ; Load height in Y dey ; subtract top and bottom lines dey @inner_lines_lp: lda dp_text_tmp ; Get start of previous line clc adc #TEXT_SCREEN_BYTE_PITCH ; advance to next line sta dp_text_tmp ; save it for next tome sta dp_text_ptr ; point to it now ldx text_box_w ; Load width in X ; Vertical bar left lda #BOX_CHAR_VL sta [dp_text_ptr] inc dp_text_ptr inc dp_text_ptr dex ; Background filler lda #BOX_CHAR_FILL @lp_horiz_fill: sta [dp_text_ptr] inc dp_text_ptr inc dp_text_ptr dex cpx #1 bne @lp_horiz_fill ; Vertical bar right lda #BOX_CHAR_VR sta [dp_text_ptr] inc dp_text_ptr inc dp_text_ptr dey bne @inner_lines_lp ;;; Bottom line of the box ;;; lda dp_text_tmp ; Get start of previous line clc adc #TEXT_SCREEN_BYTE_PITCH ; advance to next line sta dp_text_tmp ; save it for next tome sta dp_text_ptr ; point to it now ldx text_box_w ; Load width in X ; Lower left corner lda #BOX_CHAR_LL sta [dp_text_ptr] inc dp_text_ptr inc dp_text_ptr dex ; Horizontal bar, bottom lda #BOX_CHAR_HB @lp_horiz_bottom: sta [dp_text_ptr] inc dp_text_ptr inc dp_text_ptr dex cpx #1 bne @lp_horiz_bottom ; Lower right corner lda #BOX_CHAR_LR sta [dp_text_ptr] popall rts _text_xy_to_ptr: pushall A8 ; set bank lda #TEXT_SCREEN_RAM_BANK sta dp_text_ptr + 2 lda text_cursor_y A16 XY16 and #$ff asl ; *2 asl ; *4 asl ; *8 asl ; *16 asl ; *32 asl ; *32 adc text_cursor_x adc text_cursor_x adc #TEXT_SCREEN_RAM_START sta dp_text_ptr popall rts .ends
; A257970: a(1) = 1, a(2) = 2, a(3) = 5; thereafter a(n) = 2 * Sum_{k=1..n-1} a(k). ; 1,2,5,16,48,144,432,1296,3888,11664,34992,104976,314928,944784,2834352,8503056,25509168,76527504,229582512,688747536,2066242608,6198727824,18596183472,55788550416,167365651248,502096953744,1506290861232,4518872583696,13556617751088 mov $1,3 pow $1,$0 lpb $0 mov $0,0 mul $1,8 lpe div $1,3 sub $1,1 div $1,3 mul $1,2 div $1,3 add $1,1
; A078716: Sequence has period 9 and differences between successive terms are 4, -3, 4, -3, 4, -3, 4, -3, -4. ; 1,5,2,6,3,7,4,8,5,1,5,2,6,3,7,4,8,5,1,5,2,6,3,7,4,8,5,1,5,2,6,3,7,4,8,5,1,5,2,6,3,7,4,8,5,1,5,2,6,3,7,4,8,5,1,5,2,6,3,7,4,8,5,1,5,2,6,3,7,4,8,5,1 mod $0,9 mov $1,$0 mov $2,7 lpb $0,1 div $0,2 mul $0,2 mul $2,2 lpe add $1,$2 sub $1,7 div $1,2 add $1,1
; A309322: Expansion of Sum_{k>=1} phi(k) * x^k/(1 - x^k)^3, where phi = Euler totient function (A000010). ; Submitted by Christian Krause ; 1,4,8,15,19,35,34,56,63,86,76,141,103,157,182,212,169,294,208,355,335,359,298,556,405,490,522,657,463,865,526,816,773,812,856,1239,739,1003,1058,1424,901,1610,988,1525,1617,1445,1174,2188,1435,1960,1760,2091,1483,2529,1994,2660,2177,2258,1828,3689,1951,2569,3024,3184,2737,3760,2344,3487,3143,4163,2626,5040,2773,3622,4260,4317,3739,5165,3238,5668,4509,4424,3568,6915,4571,4855,4922,6236,4093,7896,5140,6241,5603,5777,5662,8640,4849,7042,7098,8455 add $0,1 mov $2,$0 mov $4,$0 lpb $0 lpb $4 mov $3,$2 gcd $3,$0 sub $4,1 lpe sub $0,1 add $1,$3 pow $3,2 add $1,$3 add $4,3 lpe mov $0,$1 div $0,2