text
stringlengths
1
1.05M
bits 64 ; set architecture global strcspn:function ; export strcspn / RDI RSI s + reject parameters strcspn: xor RAX, RAX ; set result to 0 in case of non-match cmp RDI, 0 ; check if pointer null je .end .loop: ; loop label cmp byte [RDI], 0 ; check if end of string je .end xor RCX, RCX ; set counter to 0 mov R8B, byte [RDI] ; get current char to test .loopreject: cmp byte [RSI + RCX], R8B ; check if current char is matching je .end cmp byte [RSI + RCX], 0 ; check if all chars not matching je .continue inc RCX ; inc counter to move on next byte jmp .loopreject .continue: inc RDI ; main string pointer incrementation inc RAX jmp .loop ; continue to iterate .end: ret
# Programa: # i = 0; # j = 0; # do { # do { # aux = vet[j];; # vet[j] = vet[j+1]; # vet[j+1] = aux; # j++; # } while ( j < 100 ); # j = 0; # i++; # } while ( i < 100 ); # Variaveis associadas aos registradores # endBase -> $16 # i -> $17 # j -> $18 .data a: .word 5 : 20 b: .word 4 : 20 c: .word 3 : 20 d: .word 2 : 20 e: .word 1 : 20 .text .globl main main: addi $8, $0, 0x1001 # t0 = 0x00001001 sll $16, $8, 0x10 # endBase = 0x10010000 addi $9, $0, 0x63 # t1 = 99 doExterno: addi $18, $0, 0x0 # j = 0 doInterno: sll $8, $18, 0x2 # t0 = j * 4 add $8, $8, $16 # t0 = j * 4 + endBase lw $10, 0x0($8) # aux = vet[j] lw $11, 0x4($8) # t3 = vet[j+1] if: slt $12, $11, $10 # if (vet[j+1] < vet[j]) t4 = 1; else t4 = 0 beq $12, $0, fimIf # if (t4 == 0) goto fimIf sw $11, 0x0($8) # vet[j] = vet[j+1] sw $10, 0x4($8) # vet[j+1] = aux fimIf: addi $18, $18, 0x1 # j = j + 1 bne $18, $9, doInterno # if (j != 99) goto doInterno addi $17, $17, 0x1 # i = i + 1 bne $17, $9, doExterno # if (i != 99) goto doExterno
; ================================================================== ; Simple command shell for MS-DOS and dosbox. ; Below are currently implemented for you. ; ================================================================== ; 1. Exit command. ; 2. Reboot command. ; 3. Help command. ; ================================================================== ; Exercises below, greater the number the harder to exercise. ; ================================================================== ; 1. Implement version command. ; 2. Add clear screen command, also clear screen for shell. ; 3. Make text type out for version info (like typewriters do). ; ================================================================== ; by 5n4k3 ; ================================================================== [bits 16] [org 100h] [section .bss] buffer resb 32 [section .text] global _start jmp _start ; =========================== Data Section ========================= reboot_msg db "Press any key to reboot . . .",0dh,0ah,24h help_msg: db "========================================",0dh,0ah db "= *** Help *** =",0dh,0ah db "========================================",0dh,0ah db "help - This text is help.",0dh,0ah db "reboot - Warm reboot the machine.",0dh,0ah db "exit - Exit back to DOS.",0dh,0ah db "========================================",0dh,0ah,24h help_cmd db "help",24h reboot_cmd db "reboot",24h exit_cmd db "exit",24h bad_cmd db "Bad command.",0dh,0ah,24h prompt db "> ",24h crlf_msg db 0dh,0ah,24h ; ================================================================== _start: ; setup segments mov ax, cs mov ds, ax mov es, ax call shell ; return from COM file if reboot doesn't occur int 20h ; ============================ Subroutines ========================= ; put message in dx print: mov si, dx .loop: lodsb cmp al, 24h je .done mov ah, 0eh mov bx, 0007h int 10h jmp short .loop .done: ret ; put command in di cmp_str: clc .loop: lodsb mov bl, byte [di] cmp al, bl jne .fail cmp byte [di], 24h je .done inc di jmp short .loop .fail: stc .done: ret get_str: mov di, buffer .loop: xor ax, ax int 16h cmp al, 08h je .back cmp al, 0dh je .done mov ah, 0eh mov bx, 7 int 10h stosb jmp short .loop .back: mov ah, 0eh mov al, 08h mov bx, 0007h mov cx, 0001h int 10h mov ah, 0eh mov al, 20h mov bx, 0007h mov cx, 0001h int 10h mov ah, 0eh mov al, 08h mov bx, 0007h mov cx, 0001h int 10h dec di mov byte [di], 24h jmp short .loop .done: mov al, 24h stosb mov dx, crlf_msg call print ret clr_str: mov di, buffer mov cx, 0020h .loop: dec cx xor ax, ax mov al, 24h stosb cmp cx, 0 jne .loop ret shell: mov dx, prompt call print call clr_str call get_str mov si, buffer mov di, help_cmd call cmp_str jnc .help mov si, buffer mov di, reboot_cmd call cmp_str jnc .reboot mov si, buffer mov di, exit_cmd call cmp_str jnc .exit mov dx, bad_cmd call print jmp short shell .help: mov dx, help_msg call print jmp short shell .reboot: mov dx, reboot_msg call print ; get key press mov ax, 0001h int 16h ; warm reboot machine push 0ffffh push 0000h retf .exit: ret
bits 16 ; glb intptr_t : int ; glb uintptr_t : unsigned ; glb intmax_t : int ; glb uintmax_t : unsigned ; glb int8_t : signed char ; glb int_least8_t : signed char ; glb int_fast8_t : signed char ; glb uint8_t : unsigned char ; glb uint_least8_t : unsigned char ; glb uint_fast8_t : unsigned char ; glb int16_t : short ; glb int_least16_t : short ; glb int_fast16_t : short ; glb uint16_t : unsigned short ; glb uint_least16_t : unsigned short ; glb uint_fast16_t : unsigned short ; glb int32_t : int ; glb int_least32_t : int ; glb int_fast32_t : int ; glb uint32_t : unsigned ; glb uint_least32_t : unsigned ; glb uint_fast32_t : unsigned ; glb imaxdiv_t : struct <something> ; glb bool_t : int ; glb pointer_t : * unsigned char ; glb funcion_t : * ( ; prm <something> : * void ; ) * void ; glb manejador_t : * (void) void ; glb rti_t : * (void) void ; glb isr_t : * (void) void ; glb handler_t : * (void) void ; glb retardarThread_t : * (void) int ; glb ptrTVI_t : * * (void) void ; glb modoSO1_t : int ; glb lh_t : struct <something> ; glb address_t : struct <something> ; glb uPtrAdr_t : union <something> ; glb pid_t : int ; glb tid_t : int ; glb uid_t : int ; glb gid_t : int ; glb pindx_t : int ; glb tindx_t : int ; glb df_t : int ; glb dfs_t : int ; glb rindx_t : int ; glb inportb : ( ; prm port : unsigned short ; ) unsigned char ; glb inport : ( ; prm port : unsigned short ; ) unsigned short ; glb outport : ( ; prm port : unsigned short ; prm val : unsigned short ; ) void ; glb outportb : ( ; prm port : unsigned short ; prm val : unsigned char ; ) void ; glb inportb_r : ( ; prm port : unsigned char ; ) unsigned char ; glb outportb_r : ( ; prm port : unsigned char ; prm val : unsigned char ; ) void ; glb contadorTimer0 : (void) unsigned short ; glb inportb : ( ; prm port : unsigned short ; ) unsigned char section .text global _inportb _inportb: push ebp movzx ebp, sp ;sub sp, 0 ; loc port : (@8): unsigned short mov dx,[bp+8] in al,dx xor ah,ah L1: db 0x66 leave retf L3: section .fxnsz noalloc dd L3 - _inportb ; glb inport : ( ; prm port : unsigned short ; ) unsigned short section .text global _inport _inport: push ebp movzx ebp, sp ;sub sp, 0 ; loc port : (@8): unsigned short mov dx,[bp+8] in ax,dx L4: db 0x66 leave retf L6: section .fxnsz dd L6 - _inport ; glb outportb : ( ; prm port : unsigned short ; prm val : unsigned char ; ) void section .text global _outportb _outportb: push ebp movzx ebp, sp ;sub sp, 0 ; loc port : (@8): unsigned short ; loc val : (@12): unsigned char mov dx,[bp+ 8] mov al,[bp+12] out dx,al L7: db 0x66 leave retf L9: section .fxnsz dd L9 - _outportb ; glb outport : ( ; prm port : unsigned short ; prm val : unsigned short ; ) void section .text global _outport _outport: push ebp movzx ebp, sp ;sub sp, 0 ; loc port : (@8): unsigned short ; loc val : (@12): unsigned short mov dx,[bp+ 8] mov ax,[bp+12] out dx,ax L10: db 0x66 leave retf L12: section .fxnsz dd L12 - _outport ; glb inportb_r : ( ; prm port : unsigned char ; ) unsigned char section .text global _inportb_r _inportb_r: push ebp movzx ebp, sp sub sp, 4 ; loc port : (@8): unsigned char ; loc __ret : (@-4): int ; RPN'ized expression: "__ret ( port inportb ) = " ; Expanded expression: "(@-4) (@8) *(1) inportb ()4 =(4) " ; Fused expression: "( *(1) (@8) , inportb )4 =(204) *(@-4) ax " mov al, [bp+8] movzx eax, al push eax db 0x9A section .relot dd L15 section .text L15: dd _inportb sub sp, -4 mov [bp-4], eax jmp $+2 jmp $+2 ; return ; RPN'ized expression: "__ret " ; Expanded expression: "(@-4) *(4) " ; Fused expression: "*(4) (@-4) unsigned char " mov eax, [bp-4] and eax, 255 L13: db 0x66 leave retf L16: section .fxnsz dd L16 - _inportb_r ; glb outportb_r : ( ; prm port : unsigned char ; prm val : unsigned char ; ) void section .text global _outportb_r _outportb_r: push ebp movzx ebp, sp ;sub sp, 0 ; loc port : (@8): unsigned char ; loc val : (@12): unsigned char ; RPN'ized expression: "( val , port outportb ) " ; Expanded expression: " (@12) *(1) (@8) *(1) outportb ()8 " ; Fused expression: "( *(1) (@12) , *(1) (@8) , outportb )8 " mov al, [bp+12] movzx eax, al push eax mov al, [bp+8] movzx eax, al push eax db 0x9A section .relot dd L19 section .text L19: dd _outportb sub sp, -8 jmp $+2 jmp $+2 L17: db 0x66 leave retf L20: section .fxnsz dd L20 - _outportb_r ; glb contadorTimer0 : (void) unsigned short section .text global _contadorTimer0 _contadorTimer0: push ebp movzx ebp, sp ;sub sp, 0 mov al,11010010b out 01000011b,al jmp $+2 in al,01000000b mov ah,al jmp $+2 in al,01000000b xchg ah,al L21: db 0x66 leave retf L23: section .fxnsz dd L23 - _contadorTimer0 ; Syntax/declaration table/stack: ; Bytes used: 1490/40960 ; Macro table: ; Macro __SMALLER_C__ = `0x0100` ; Macro __SMALLER_C_32__ = `` ; Macro __HUGE__ = `` ; Macro __SMALLER_C_SCHAR__ = `` ; Bytes used: 74/5120 ; Identifier table: ; Ident __floatsisf ; Ident __floatunsisf ; Ident __fixsfsi ; Ident __fixunssfsi ; Ident __addsf3 ; Ident __subsf3 ; Ident __negsf2 ; Ident __mulsf3 ; Ident __divsf3 ; Ident __lesf2 ; Ident __gesf2 ; Ident intptr_t ; Ident uintptr_t ; Ident intmax_t ; Ident uintmax_t ; Ident int8_t ; Ident int_least8_t ; Ident int_fast8_t ; Ident uint8_t ; Ident uint_least8_t ; Ident uint_fast8_t ; Ident int16_t ; Ident int_least16_t ; Ident int_fast16_t ; Ident uint16_t ; Ident uint_least16_t ; Ident uint_fast16_t ; Ident int32_t ; Ident int_least32_t ; Ident int_fast32_t ; Ident uint32_t ; Ident uint_least32_t ; Ident uint_fast32_t ; Ident <something> ; Ident quot ; Ident rem ; Ident imaxdiv_t ; Ident FALSE ; Ident TRUE ; Ident bool_t ; Ident pointer_t ; Ident funcion_t ; Ident manejador_t ; Ident rti_t ; Ident isr_t ; Ident handler_t ; Ident retardarThread_t ; Ident ptrTVI_t ; Ident modoSO1_Bin ; Ident modoSO1_Exe ; Ident modoSO1_Bs ; Ident modoSO1_t ; Ident lo ; Ident hi ; Ident lh_t ; Ident offset ; Ident segment ; Ident address_t ; Ident ptr ; Ident adr ; Ident uPtrAdr_t ; Ident pid_t ; Ident tid_t ; Ident uid_t ; Ident gid_t ; Ident pindx_t ; Ident tindx_t ; Ident df_t ; Ident dfs_t ; Ident rindx_t ; Ident inportb ; Ident port ; Ident inport ; Ident outport ; Ident val ; Ident outportb ; Ident inportb_r ; Ident outportb_r ; Ident contadorTimer0 ; Bytes used: 804/16384 ; Next label number: 24 ; Compilation succeeded.
// This file is part of RAVL, Recognition And Vision Library // Copyright (C) 2001, University of Surrey // This code may be redistributed under the terms of the GNU Lesser // General Public License (LGPL). See the lgpl.licence file for details or // see http://www.gnu.org/copyleft/lesser.html // file-header-ends-here #ifndef RAVLJPEGFORMAT_HEADER #define RAVLJPEGFORMAT_HEADER 1 //////////////////////////////////////////////////////////// //! rcsid="$Id: JPEGFormat.hh 5240 2005-12-06 17:16:50Z plugger $" //! file="Ravl/Image/ExternalImageIO/JPEGFormat.hh" //! lib=RavlExtImgIO //! author="Charles Galambos" //! docentry="Ravl.API.Images.IO.Formats" //! date="29/10/98" #include "Ravl/DP/FileFormat.hh" #include "Ravl/Image/Image.hh" #include "Ravl/Image/ByteRGBValue.hh" namespace RavlImageN { //! userlevel=Develop //: JPEG File format information. class FileFormatJPEGBodyC : public FileFormatBodyC { public: FileFormatJPEGBodyC(); //: Default constructor. FileFormatJPEGBodyC(int comp,int pri,bool asSequence,const StringC &name,const StringC &desc); //: Constructor. const type_info &ChooseFormat(const type_info &obj_type) const; //: Try and choose best format for IO. virtual const type_info &ProbeLoad(IStreamC &in,const type_info &obj_type) const; //: Is stream in std stream format ? virtual const type_info &ProbeLoad(const StringC &filename,IStreamC &in,const type_info &obj_type) const; //: Probe for load. virtual const type_info &ProbeSave(const StringC &filename,const type_info &obj_type,bool forceFormat) const; //: Probe for Save. virtual DPIPortBaseC CreateInput(const StringC &filename,const type_info &obj_type) const; //: Create a input port for loading from file 'filename'. // Will create an Invalid port if not supported. <p> virtual DPOPortBaseC CreateOutput(const StringC &filename,const type_info &obj_type) const; //: Create a output port for saving to file 'filename'.. // Will create an Invalid port if not supported. <p> virtual DPIPortBaseC CreateInput(IStreamC &in,const type_info &obj_type) const; //: Create a input port for loading. // Will create an Invalid port if not supported. virtual DPOPortBaseC CreateOutput(OStreamC &out,const type_info &obj_type) const; //: Create a output port for saving. // Will create an Invalid port if not supported. virtual const type_info &DefaultType() const; //: Get prefered IO type. virtual IntT Priority() const { return pri; } //: Find the priority of the format. the higher the better. // Default is zero, this is better than the default (streams.) virtual bool IsStream() const { return asSequence; } //: Test if format is a fully streamable. // i.e. check if you can read/write more than object object. // jpeg supports sequences.. but not with this software for now... protected: int compression; int pri; bool asSequence; }; ///////////////////////////// //! userlevel=Advanced //: Create an instance of a JPEG File Format. class FileFormatJPEGC : public FileFormatC<ImageC<ByteT> > { public: FileFormatJPEGC(int comp,int pri,bool asSequence,const StringC &name,const StringC &desc) : FileFormatC<ImageC<ByteT> >(*new FileFormatJPEGBodyC(comp,pri,asSequence,name,desc)) {} }; } #endif
section .data array: dd 1,2,3,4,5,6,7 len equ ($-array)/4 section .text global _main _main: push ebp mov ebp, esp and esp, 0xfffffff0 mov eax, [array] mov ecx, 1 rotate_loop: xchg eax, [array+ecx*4] inc ecx cmp ecx, len jl rotate_loop xchg eax, [array] xor eax, eax leave ret
; A122047: Degree of the polynomial P(n,x), defined by a Somos-6 type sequence: P(n,x)=(x^(n-1)*P(n-1,x)*P(n-5,x) + P(n-2,x)*P(n-4,x))/P(n-6,x), initialized with P(n,x)=1 at n<0. ; 0,0,1,3,6,10,15,22,31,42,55,70,88,109,133,160,190,224,262,304,350,400,455,515,580,650,725,806,893,986,1085,1190,1302,1421,1547,1680,1820,1968,2124,2288,2460,2640,2829,3027 mov $2,$0 lpb $2 lpb $3 add $1,$3 trn $3,5 lpe sub $2,1 add $3,$2 lpe
; A157330: a(n) = 64*n - 8. ; 56,120,184,248,312,376,440,504,568,632,696,760,824,888,952,1016,1080,1144,1208,1272,1336,1400,1464,1528,1592,1656,1720,1784,1848,1912,1976,2040,2104,2168,2232,2296,2360,2424,2488,2552,2616,2680,2744,2808,2872,2936,3000,3064,3128,3192,3256,3320,3384,3448,3512,3576,3640,3704,3768,3832,3896,3960,4024,4088,4152,4216,4280,4344,4408,4472,4536,4600,4664,4728,4792,4856,4920,4984,5048,5112,5176,5240,5304,5368,5432,5496,5560,5624,5688,5752,5816,5880,5944,6008,6072,6136,6200,6264,6328,6392,6456,6520,6584,6648,6712,6776,6840,6904,6968,7032,7096,7160,7224,7288,7352,7416,7480,7544,7608,7672,7736,7800,7864,7928,7992,8056,8120,8184,8248,8312,8376,8440,8504,8568,8632,8696,8760,8824,8888,8952,9016,9080,9144,9208,9272,9336,9400,9464,9528,9592,9656,9720,9784,9848,9912,9976,10040,10104,10168,10232,10296,10360,10424,10488,10552,10616,10680,10744,10808,10872,10936,11000,11064,11128,11192,11256,11320,11384,11448,11512,11576,11640,11704,11768,11832,11896,11960,12024,12088,12152,12216,12280,12344,12408,12472,12536,12600,12664,12728,12792,12856,12920,12984,13048,13112,13176,13240,13304,13368,13432,13496,13560,13624,13688,13752,13816,13880,13944,14008,14072,14136,14200,14264,14328,14392,14456,14520,14584,14648,14712,14776,14840,14904,14968,15032,15096,15160,15224,15288,15352,15416,15480,15544,15608,15672,15736,15800,15864,15928,15992 mov $1,$0 mul $1,64 add $1,56
match ,{ include 'macro/struct.inc' include '../linux/import32.inc' } match -,{ else include 'selfhost.inc' end match _ equ } format ELF public main include '../version.inc' extrn 'malloc' as libc.malloc extrn 'realloc' as libc.realloc extrn 'free' as libc.free extrn 'fopen' as libc.fopen extrn 'fclose' as libc.fclose extrn 'fread' as libc.fread extrn 'fwrite' as libc.fwrite extrn 'fseek' as libc.fseek extrn 'ftell' as libc.ftell extrn 'time' as libc.time extrn 'write' as libc.write extrn getenv extrn gettimeofday extrn exit struct timeval time_t dd ? suseconds_t dd ? ends section '.text' executable align 16 main: mov ecx,[esp+4] mov [argc],ecx mov ebx,[esp+8] mov [argv],ebx call system_init call get_arguments jc display_usage_information cmp [no_logo],0 jne arguments_ok mov esi,_logo xor ecx,ecx call display_string arguments_ok: xor al,al mov ecx,[verbosity_level] jecxz init or al,TRACE_ERROR_STACK dec ecx jz init or al,TRACE_DISPLAY init: call assembly_init ccall gettimeofday,start_time,0 assemble: mov esi,[initial_commands] mov edx,[source_path] call assembly_pass jc assembly_done mov eax,[current_pass] cmp eax,[maximum_number_of_passes] jb assemble call show_display_data mov esi,_error_prefix xor ecx,ecx call display_error_string mov esi,_code_cannot_be_generated xor ecx,ecx call display_error_string mov esi,_message_suffix xor ecx,ecx call display_error_string jmp assembly_failed assembly_done: call show_display_data cmp [first_error],0 jne assembly_failed cmp [no_logo],0 jne summary_done mov eax,[current_pass] xor edx,edx call itoa call display_string mov esi,_passes cmp [current_pass],1 jne display_passes_suffix mov esi,_pass display_passes_suffix: xor ecx,ecx call display_string ccall gettimeofday,end_time,0 mov eax,[end_time.time_t] sub eax,[start_time.time_t] mov ecx,1000000 mul ecx add eax,[end_time.suseconds_t] adc edx,0 sub eax,[start_time.suseconds_t] sbb edx,0 add eax,50000 mov ecx,1000000 div ecx mov ebx,eax mov eax,edx xor edx,edx mov ecx,100000 div ecx mov [tenths_of_second],eax xchg eax,ebx or ebx,eax jz display_output_length xor edx,edx call itoa call display_string mov esi,_message_suffix mov ecx,1 call display_string mov eax,[tenths_of_second] xor edx,edx call itoa call display_string mov esi,_seconds xor ecx,ecx call display_string display_output_length: call get_output_length push eax edx call itoa call display_string pop edx eax mov esi,_bytes cmp eax,1 jne display_bytes_suffix test edx,edx jnz display_bytes_suffix mov esi,_byte display_bytes_suffix: xor ecx,ecx call display_string mov esi,_new_line xor ecx,ecx call display_string summary_done: mov ebx,[source_path] mov edi,[output_path] call write_output_file jc write_failed call assembly_shutdown call system_shutdown ccall exit,0 assembly_failed: call show_errors call assembly_shutdown call system_shutdown ccall exit,2 write_failed: mov ebx,_write_failed jmp fatal_error out_of_memory: mov ebx,_out_of_memory jmp fatal_error fatal_error: mov esi,_error_prefix xor ecx,ecx call display_error_string mov esi,ebx xor ecx,ecx call display_error_string mov esi,_message_suffix xor ecx,ecx call display_error_string call assembly_shutdown call system_shutdown ccall exit,3 display_usage_information: mov esi,_usage xor ecx,ecx call display_string call system_shutdown ccall exit,1 get_arguments: xor eax,eax mov [initial_commands],eax mov [source_path],eax mov [output_path],eax mov [maximum_number_of_passes],100 mov [maximum_number_of_errors],1 mov [maximum_depth_of_stack],10000 mov ecx,[argc] mov ebx,[argv] add ebx,4 dec ecx jz error_in_arguments get_argument: mov esi,[ebx] mov al,[esi] cmp al,'-' je get_option cmp [source_path],0 jne get_output_file mov [source_path],esi jmp next_argument get_output_file: cmp [output_path],0 jne error_in_arguments mov [output_path],esi jmp next_argument get_option: inc esi lodsb cmp al,'e' je set_errors_limit cmp al,'E' je set_errors_limit cmp al,'i' je insert_initial_command cmp al,'I' je insert_initial_command cmp al,'p' je set_passes_limit cmp al,'P' je set_passes_limit cmp al,'r' je set_recursion_limit cmp al,'R' je set_recursion_limit cmp al,'v' je set_verbose_mode cmp al,'V' je set_verbose_mode cmp al,'n' je set_no_logo cmp al,'N' jne error_in_arguments set_no_logo: or [no_logo],-1 cmp byte [esi],0 je next_argument error_in_arguments: stc ret set_verbose_mode: cmp byte [esi],0 jne get_verbose_setting dec ecx jz error_in_arguments add ebx,4 mov esi,[ebx] get_verbose_setting: call get_option_value cmp edx,2 ja error_in_arguments mov [verbosity_level],edx jmp next_argument set_errors_limit: cmp byte [esi],0 jne get_errors_setting dec ecx jz error_in_arguments add ebx,4 mov esi,[ebx] get_errors_setting: call get_option_value test edx,edx jz error_in_arguments mov [maximum_number_of_errors],edx jmp next_argument set_recursion_limit: cmp byte [esi],0 jne get_recursion_setting dec ecx jz error_in_arguments add ebx,4 mov esi,[ebx] get_recursion_setting: call get_option_value test edx,edx jz error_in_arguments mov [maximum_depth_of_stack],edx jmp next_argument set_passes_limit: cmp byte [esi],0 jne get_passes_setting dec ecx jz error_in_arguments add ebx,4 mov esi,[ebx] get_passes_setting: call get_option_value test edx,edx jz error_in_arguments mov [maximum_number_of_passes],edx next_argument: add ebx,4 dec ecx jnz get_argument cmp [source_path],0 je error_in_arguments clc ret get_option_value: xor eax,eax mov edx,eax find_option_value: cmp byte [esi],20h jne get_option_digit inc esi jmp find_option_value get_option_digit: lodsb test al,al jz option_value_ok sub al,30h jc invalid_option_value cmp al,9 ja invalid_option_value imul edx,10 jo invalid_option_value add edx,eax jc invalid_option_value jmp get_option_digit option_value_ok: dec esi clc ret invalid_option_value: stc ret insert_initial_command: cmp byte [esi],0 jne measure_initial_command dec ecx jz error_in_arguments add ebx,4 mov esi,[ebx] measure_initial_command: push ebx ecx edi mov edi,esi or ecx,-1 xor al,al repne scasb not ecx dec ecx mov edi,[initial_commands] lea eax,[ecx+2] test edi,edi jz allocate_initial_commands_buffer mov edx,[initial_commands_length] add edi,edx add eax,edx cmp eax,[initial_commands_maximum_length] ja grow_initial_commands_buffer copy_initial_command: rep movsb mov ax,0Ah stosw dec edi sub edi,[initial_commands] mov [initial_commands_length],edi pop edi ecx ebx jmp next_argument allocate_initial_commands_buffer: push ecx mov ecx,eax call malloc mov [initial_commands],eax mov [initial_commands_maximum_length],ecx mov edi,eax pop ecx jmp copy_initial_command grow_initial_commands_buffer: push ecx mov ecx,eax mov eax,[initial_commands] call realloc mov [initial_commands],eax mov [initial_commands_maximum_length],ecx mov edi,eax add edi,[initial_commands_length] pop ecx jmp copy_initial_command include 'system.inc' include '../assembler.inc' include '../symbols.inc' include '../expressions.inc' include '../conditions.inc' include '../directives.inc' include '../floats.inc' include '../errors.inc' include '../map.inc' include '../reader.inc' include '../output.inc' include '../console.inc' section '.data' _logo db 'flat assembler version g.',VERSION,10,0 _usage db 'Usage: fasmg source [output]',10 db 'Optional settings:',10 db ' -p limit Set the maximum allowed number of passes (default 100)',10 db ' -e limit Set the maximum number of displayed errors (default 1)',10 db ' -r limit Set the maximum depth of stack (default 10000)',10 db ' -v flag Enable or disable showing all lines from the stack (default 0)',10 db ' -i command Insert instruction at the beginning of source',13,10 db ' -n Do not show logo nor summary',13,10 db 0 _pass db ' pass, ',0 _passes db ' passes, ',0 _dot db '.' _seconds db ' seconds, ',0 _byte db ' byte.',0 _bytes db ' bytes.',0 _write_failed db 'failed to write the output file',0 _out_of_memory db 'not enough memory to complete the assembly',0 _code_cannot_be_generated db 'could not generate code within the allowed number of passes',0 _open_mode db 'r',0 _create_mode db 'w',0 include '../tables.inc' include '../messages.inc' section '.bss' writeable include '../variables.inc' source_path dd ? output_path dd ? maximum_number_of_passes dd ? initial_commands dd ? initial_commands_length dd ? initial_commands_maximum_length dd ? argc dd ? argv dd ? timestamp dq ? start_time timeval end_time timeval tenths_of_second dd ? verbosity_level dd ? no_logo db ? path_buffer rb 1000h
; A151988: G.f.: (x*(x^4+1)*(x^2-x+1)*(x^2+x+1))/((x^4+x^3+x^2+x+1)*(x^4-x^3+x^2-x+1)*(x-1)^2). ; 0,1,2,3,4,6,8,9,10,11,12,13,14,15,16,18,20,21,22,23,24,25,26,27,28,30,32,33,34,35,36,37,38,39,40,42,44,45,46,47,48,49,50,51,52,54,56,57,58,59,60,61,62,63,64,66,68,69,70,71,72,73,74,75,76,78,80,81,82,83,84,85,86,87,88,90,92,93,94,95,96,97,98,99,100,102,104,105,106,107,108,109,110,111,112,114,116,117,118,119,120 mov $1,$0 mov $2,$0 lpb $2 sub $2,4 add $1,$2 trn $2,2 sub $1,$2 sub $2,4 lpe
; A132708: Period 6: repeat [4, 2, 1, -4, -2, -1]. ; 4,2,1,-4,-2,-1,4,2,1,-4,-2,-1,4,2,1,-4,-2,-1,4,2,1,-4,-2,-1,4,2,1,-4,-2,-1,4,2,1,-4,-2,-1,4,2,1,-4,-2,-1,4,2,1,-4,-2,-1,4,2,1,-4,-2,-1,4,2,1,-4,-2,-1,4,2,1,-4,-2,-1,4,2,1,-4,-2,-1,4,2,1,-4,-2,-1,4,2,1,-4,-2,-1,4,2,1,-4,-2,-1,4,2,1,-4,-2,-1,4,2,1,-4,-2,-1 cal $0,70372 ; a(n) = 5^n mod 18. mov $1,8 sub $1,$0 mul $1,2 sub $1,2 div $1,4 add $1,1
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r11 push %r14 push %r15 push %r9 push %rcx push %rdi push %rsi lea addresses_WT_ht+0x30d4, %r9 nop nop nop and $8941, %r10 movb (%r9), %r11b sub $17407, %rcx lea addresses_WC_ht+0x1c3e4, %r15 nop nop and %r14, %r14 mov $0x6162636465666768, %r11 movq %r11, (%r15) nop nop nop nop nop dec %r9 lea addresses_UC_ht+0x7284, %r15 clflush (%r15) xor $41866, %r9 mov $0x6162636465666768, %rcx movq %rcx, (%r15) nop nop nop nop and $30613, %r9 lea addresses_UC_ht+0x2310, %r10 nop nop nop nop nop sub $48989, %r11 mov (%r10), %r9w nop add %rcx, %rcx lea addresses_WT_ht+0x2bfe, %r10 nop add $13997, %rcx mov $0x6162636465666768, %r9 movq %r9, %xmm0 movups %xmm0, (%r10) nop nop nop xor %r15, %r15 lea addresses_D_ht+0x1954, %rsi lea addresses_normal_ht+0x180d4, %rdi nop and %r9, %r9 mov $81, %rcx rep movsb dec %rsi lea addresses_D_ht+0xb54, %rsi lea addresses_A_ht+0x1e848, %rdi nop nop inc %r10 mov $77, %rcx rep movsw nop nop cmp $21755, %rsi lea addresses_D_ht+0x160d2, %rsi lea addresses_A_ht+0x1efd4, %rdi nop cmp $21398, %r14 mov $92, %rcx rep movsw nop nop nop nop and %r11, %r11 lea addresses_WT_ht+0x1dda4, %r11 nop nop nop nop nop and %rdi, %rdi movw $0x6162, (%r11) nop nop add $7416, %r9 lea addresses_D_ht+0x69d4, %r11 nop nop nop nop nop cmp $55223, %rsi mov (%r11), %r14w nop nop xor %rdi, %rdi lea addresses_UC_ht+0x1ded4, %rsi nop nop nop nop and $31831, %r15 mov $0x6162636465666768, %rdi movq %rdi, %xmm1 vmovups %ymm1, (%rsi) nop xor $39101, %r9 lea addresses_D_ht+0x112d4, %rcx clflush (%rcx) nop nop nop nop sub %r11, %r11 mov (%rcx), %r10w and $14505, %rdi lea addresses_WC_ht+0x7634, %r11 nop nop cmp %r14, %r14 vmovups (%r11), %ymm6 vextracti128 $1, %ymm6, %xmm6 vpextrq $1, %xmm6, %rsi nop add $26243, %r15 lea addresses_A_ht+0x6934, %rsi lea addresses_UC_ht+0x170d4, %rdi clflush (%rdi) inc %r11 mov $99, %rcx rep movsw nop nop nop nop nop xor $12107, %r9 pop %rsi pop %rdi pop %rcx pop %r9 pop %r15 pop %r14 pop %r11 pop %r10 ret .global s_faulty_load s_faulty_load: push %r14 push %r8 push %r9 push %rax push %rbp push %rbx push %rdi // Store lea addresses_A+0x1e504, %rax nop nop xor %r14, %r14 mov $0x5152535455565758, %r8 movq %r8, %xmm6 movntdq %xmm6, (%rax) nop add $31472, %r8 // Load mov $0x8d4, %rbx inc %rdi mov (%rbx), %rbp nop nop nop nop nop cmp $41040, %rbp // Faulty Load lea addresses_US+0x148d4, %rdi nop nop sub %rbp, %rbp movntdqa (%rdi), %xmm0 vpextrq $0, %xmm0, %rbx lea oracles, %r9 and $0xff, %rbx shlq $12, %rbx mov (%r9,%rbx,1), %rbx pop %rdi pop %rbx pop %rbp pop %rax pop %r9 pop %r8 pop %r14 ret /* <gen_faulty_load> [REF] {'src': {'same': False, 'congruent': 0, 'NT': True, 'type': 'addresses_US', 'size': 1, 'AVXalign': True}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 4, 'NT': True, 'type': 'addresses_A', 'size': 16, 'AVXalign': False}} {'src': {'same': False, 'congruent': 11, 'NT': False, 'type': 'addresses_P', 'size': 8, 'AVXalign': False}, 'OP': 'LOAD'} [Faulty Load] {'src': {'same': True, 'congruent': 0, 'NT': True, 'type': 'addresses_US', 'size': 16, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'same': False, 'congruent': 11, 'NT': False, 'type': 'addresses_WT_ht', 'size': 1, 'AVXalign': False}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'same': True, 'congruent': 1, 'NT': False, 'type': 'addresses_WC_ht', 'size': 8, 'AVXalign': False}} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 4, 'NT': False, 'type': 'addresses_UC_ht', 'size': 8, 'AVXalign': False}} {'src': {'same': False, 'congruent': 2, 'NT': False, 'type': 'addresses_UC_ht', 'size': 2, 'AVXalign': False}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 1, 'NT': False, 'type': 'addresses_WT_ht', 'size': 16, 'AVXalign': False}} {'src': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_normal_ht', 'congruent': 11, 'same': False}} {'src': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 0, 'same': False}} {'src': {'type': 'addresses_D_ht', 'congruent': 0, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_A_ht', 'congruent': 4, 'same': False}} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 4, 'NT': False, 'type': 'addresses_WT_ht', 'size': 2, 'AVXalign': False}} {'src': {'same': False, 'congruent': 8, 'NT': True, 'type': 'addresses_D_ht', 'size': 2, 'AVXalign': False}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'same': False, 'congruent': 8, 'NT': False, 'type': 'addresses_UC_ht', 'size': 32, 'AVXalign': False}} {'src': {'same': False, 'congruent': 9, 'NT': False, 'type': 'addresses_D_ht', 'size': 2, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'same': False, 'congruent': 5, 'NT': False, 'type': 'addresses_WC_ht', 'size': 32, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_A_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': False}} {'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 */
// Copyright (c) 2014-2015 The Bitcoin Core developers // Copyright (c) 2018 The Navcoin Core developers // Copyright (c) 2019 The DeVault Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "base58.h" #include "hash.h" #include "uint256.h" #include <assert.h> #include <stdint.h> #include <string.h> #include <vector> #include <string> #include <boost/variant/apply_visitor.hpp> #include <boost/variant/static_visitor.hpp> /** All alphanumeric characters except for "0", "I", "O", and "l" */ static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; bool DecodeBase58(const char* psz, std::vector<unsigned char>& vch) { // Skip leading spaces. while (*psz && isspace(*psz)) psz++; // Skip and count leading '1's. int zeroes = 0; while (*psz == '1') { zeroes++; psz++; } // Allocate enough space in big-endian base256 representation. std::vector<unsigned char> b256(strlen(psz) * 733 / 1000 + 1); // log(58) / log(256), rounded up. // Process the characters. while (*psz && !isspace(*psz)) { // Decode base58 character const char* ch = strchr(pszBase58, *psz); if (ch == NULL) return false; // Apply "b256 = b256 * 58 + ch". int carry = ch - pszBase58; for (std::vector<unsigned char>::reverse_iterator it = b256.rbegin(); it != b256.rend(); it++) { carry += 58 * (*it); *it = carry % 256; carry /= 256; } assert(carry == 0); psz++; } // Skip trailing spaces. while (isspace(*psz)) psz++; if (*psz != 0) return false; // Skip leading zeroes in b256. std::vector<unsigned char>::iterator it = b256.begin(); while (it != b256.end() && *it == 0) it++; // Copy result into output vector. vch.reserve(zeroes + (b256.end() - it)); vch.assign(zeroes, 0x00); while (it != b256.end()) vch.push_back(*(it++)); return true; } std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend) { // Skip & count leading zeroes. int zeroes = 0; int length = 0; while (pbegin != pend && *pbegin == 0) { pbegin++; zeroes++; } // Allocate enough space in big-endian base58 representation. int size = (pend - pbegin) * 138 / 100 + 1; // log(256) / log(58), rounded up. std::vector<unsigned char> b58(size); // Process the bytes. while (pbegin != pend) { int carry = *pbegin; int i = 0; // Apply "b58 = b58 * 256 + ch". for (std::vector<unsigned char>::reverse_iterator it = b58.rbegin(); (carry != 0 || i < length) && (it != b58.rend()); it++, i++) { carry += 256 * (*it); *it = carry % 58; carry /= 58; } assert(carry == 0); length = i; pbegin++; } // Skip leading zeroes in base58 result. std::vector<unsigned char>::iterator it = b58.begin() + (size - length); while (it != b58.end() && *it == 0) it++; // Translate the result into a string. std::string str; str.reserve(zeroes + (b58.end() - it)); str.assign(zeroes, '1'); while (it != b58.end()) str += pszBase58[*(it++)]; return str; } std::string EncodeBase58(const std::vector<unsigned char>& vch) { return EncodeBase58(&vch[0], &vch[0] + vch.size()); } bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet) { return DecodeBase58(str.c_str(), vchRet); } std::string EncodeBase58Check(const std::vector<unsigned char>& vchIn) { // add 4-byte hash check to the end std::vector<unsigned char> vch(vchIn); uint256 hash = Hash(vch.begin(), vch.end()); vch.insert(vch.end(), (unsigned char*)&hash, (unsigned char*)&hash + 4); return EncodeBase58(vch); } bool DecodeBase58Check(const char* psz, std::vector<unsigned char>& vchRet) { if (!DecodeBase58(psz, vchRet) || (vchRet.size() < 4)) { vchRet.clear(); return false; } // re-calculate the checksum, insure it matches the included 4-byte checksum uint256 hash = Hash(vchRet.begin(), vchRet.end() - 4); if (memcmp(&hash, &vchRet.end()[-4], 4) != 0) { vchRet.clear(); return false; } vchRet.resize(vchRet.size() - 4); return true; } bool DecodeBase58Check(const std::string& str, std::vector<unsigned char>& vchRet) { return DecodeBase58Check(str.c_str(), vchRet); } CBase58Data::CBase58Data() { vchVersion.clear(); vchData.clear(); } void CBase58Data::SetData(const std::vector<unsigned char>& vchVersionIn, const void* pdata, size_t nSize) { vchVersion = vchVersionIn; vchData.resize(nSize); if (!vchData.empty()) memcpy(&vchData[0], pdata, nSize); } void CBase58Data::SetData(const std::vector<unsigned char>& vchVersionIn, const void* pdata, size_t nSize, const void* pdata2, size_t nSize2) { vchVersion = vchVersionIn; vchData.resize(nSize+nSize2); if (!vchData.empty()) { memcpy(&vchData[0], pdata, nSize); memcpy(&vchData[nSize], pdata2, nSize2); } } void CBase58Data::SetData(const std::vector<unsigned char>& vchVersionIn, const unsigned char* pbegin, const unsigned char* pend) { SetData(vchVersionIn, (void*)pbegin, pend - pbegin); } bool CBase58Data::SetString(const char* psz, unsigned int nVersionBytes) { std::vector<unsigned char> vchTemp; bool rc58 = DecodeBase58Check(psz, vchTemp); if ((!rc58) || (vchTemp.size() < nVersionBytes)) { vchData.clear(); vchVersion.clear(); return false; } vchVersion.assign(vchTemp.begin(), vchTemp.begin() + nVersionBytes); vchData.resize(vchTemp.size() - nVersionBytes); if (!vchData.empty()) memcpy(&vchData[0], &vchTemp[nVersionBytes], vchData.size()); memory_cleanse(&vchTemp[0], vchTemp.size()); return true; } bool CBase58Data::SetString(const std::string& str) { return SetString(str.c_str(), str.length() == 410 ? 2 : 1); } std::string CBase58Data::ToString() const { std::vector<unsigned char> vch = vchVersion; vch.insert(vch.end(), vchData.begin(), vchData.end()); return EncodeBase58Check(vch); } int CBase58Data::CompareTo(const CBase58Data& b58) const { if (vchVersion < b58.vchVersion) return -1; if (vchVersion > b58.vchVersion) return 1; if (vchData < b58.vchData) return -1; if (vchData > b58.vchData) return 1; return 0; } namespace { class CDeVaultAddressVisitor : public boost::static_visitor<bool> { private: CDeVaultAddress* addr; public: CDeVaultAddressVisitor(CDeVaultAddress* addrIn) : addr(addrIn) {} bool operator()(const CKeyID& id) const { return addr->Set(id); } bool operator()(const pair<CKeyID, CKeyID>& id) const { return addr->Set(id.first, id.second); } bool operator()(const libzerocoin::CPrivateAddress &id) const { return addr->Set(id); } bool operator()(const CScriptID& id) const { return addr->Set(id); } bool operator()(const CNoDestination& no) const { return false; } }; } // anon namespace bool CDeVaultAddress::Set(const CKeyID& id) { SetData(Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS), &id, 20); return true; } bool CDeVaultAddress::Set(const CKeyID& id, const CKeyID& id2) { SetData(Params().Base58Prefix(CChainParams::COLDSTAKING_ADDRESS), &id, 20, &id2, 20); return true; } bool CDeVaultAddress::Set(const libzerocoin::CPrivateAddress& id) { CDataStream ss(SER_NETWORK, 0); ss << id; std::vector<unsigned char> vch(ss.begin(),ss.end()); SetData(Params().Base58Prefix(CChainParams::PRIVATE_ADDRESS), (void *)&vch[0], vch.size()); return true; } bool CDeVaultAddress::Set(const CScriptID& id) { SetData(Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS), &id, 20); return true; } bool CDeVaultAddress::Set(const CTxDestination& dest) { return boost::apply_visitor(CDeVaultAddressVisitor(this), dest); } bool CDeVaultAddress::IsValid() const { return IsValid(Params()); } bool CDeVaultAddress::GetSpendingAddress(CDeVaultAddress &address) const { if(!IsColdStakingAddress(Params())) return false; uint160 id; memcpy(&id, &vchData[20], 20); address.Set(CKeyID(id)); return true; } bool CDeVaultAddress::GetStakingAddress(CDeVaultAddress &address) const { if(!IsColdStakingAddress(Params())) return false; uint160 id; memcpy(&id, &vchData[0], 20); address.Set(CKeyID(id)); return true; } bool CDeVaultAddress::GetBlindingCommitment(libzerocoin::BlindingCommitment &bc) const { if(!IsPrivateAddress(Params())) return false; libzerocoin::CPrivateAddress id(&Params().GetConsensus().Zerocoin_Params); CDataStream ss(std::vector<unsigned char>(vchData.begin(), vchData.end()), SER_NETWORK, 0); ss >> id; if(!id.GetBlindingCommitment(bc)) return false; return true; } bool CDeVaultAddress::GetZeroPubKey(CPubKey &zerokey) const{ if(!IsPrivateAddress(Params())) return false; libzerocoin::CPrivateAddress id(&Params().GetConsensus().Zerocoin_Params); CDataStream ss(std::vector<unsigned char>(vchData.begin(), vchData.end()), SER_NETWORK, 0); ss >> id; if(!id.GetPubKey(zerokey)) return false; return true; } bool CDeVaultAddress::IsValid(const CChainParams& params) const { if (vchVersion == params.Base58Prefix(CChainParams::PRIVATE_ADDRESS)) { libzerocoin::CPrivateAddress id(&Params().GetConsensus().Zerocoin_Params); CDataStream ss(std::vector<unsigned char>(vchData.begin(), vchData.end()), SER_NETWORK, 0); ss >> id; CPubKey zpk; libzerocoin::BlindingCommitment bc; if(!id.GetPubKey(zpk)) return false; if(!id.GetBlindingCommitment(bc)) return false; return zpk.IsValid() && bc.first != CBigNum() && bc.second != CBigNum(); } if (vchVersion == params.Base58Prefix(CChainParams::COLDSTAKING_ADDRESS)) return vchData.size() == 40; bool fCorrectSize = vchData.size() == 20; bool fKnownVersion = vchVersion == params.Base58Prefix(CChainParams::PUBKEY_ADDRESS) || vchVersion == params.Base58Prefix(CChainParams::SCRIPT_ADDRESS); return fCorrectSize && fKnownVersion; } bool CDeVaultAddress::IsColdStakingAddress(const CChainParams& params) const { return vchVersion == params.Base58Prefix(CChainParams::COLDSTAKING_ADDRESS) && vchData.size() == 40; } bool CDeVaultAddress::IsPrivateAddress(const CChainParams& params) const { return vchVersion == params.Base58Prefix(CChainParams::PRIVATE_ADDRESS); } CTxDestination CDeVaultAddress::Get() const { if (!IsValid()) return CNoDestination(); uint160 id; memcpy(&id, &vchData[0], 20); if (vchVersion == Params().Base58Prefix(CChainParams::COLDSTAKING_ADDRESS)) { uint160 id2; memcpy(&id2, &vchData[20], 20); return make_pair(CKeyID(id), CKeyID(id2)); } else if (vchVersion == Params().Base58Prefix(CChainParams::PRIVATE_ADDRESS)) { if(!IsPrivateAddress(Params())) return CNoDestination(); libzerocoin::CPrivateAddress id(&Params().GetConsensus().Zerocoin_Params); CDataStream ss(std::vector<unsigned char>(vchData.begin(), vchData.end()), SER_NETWORK, 0); ss >> id; return id; } else if (vchVersion == Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS)) return CKeyID(id); else if (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS)) return CScriptID(id); else return CNoDestination(); } bool CDeVaultAddress::GetIndexKey(uint160& hashBytes, int& type) const { if (!IsValid()) { return false; } else if (vchVersion == Params().Base58Prefix(CChainParams::COLDSTAKING_ADDRESS)) { hashBytes = uint160(Hash160(vchData.begin(), vchData.end())); type = 3; return true; } else if (vchVersion == Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS)) { memcpy(&hashBytes, &vchData[0], 20); type = 1; return true; } else if (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS)) { memcpy(&hashBytes, &vchData[0], 20); type = 2; return true; } return false; } bool CDeVaultAddress::GetKeyID(CKeyID& keyID) const { if (!(IsValid() && vchVersion == Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS))) return false; uint160 id; memcpy(&id, &vchData[0], 20); keyID = CKeyID(id); return true; } bool CDeVaultAddress::GetStakingKeyID(CKeyID& keyID) const { if (!(IsValid() && vchVersion == Params().Base58Prefix(CChainParams::COLDSTAKING_ADDRESS))) return false; uint160 id; memcpy(&id, &vchData[0], 20); keyID = CKeyID(id); return true; } bool CDeVaultAddress::GetSpendingKeyID(CKeyID& keyID) const { if (!(IsValid() && vchVersion == Params().Base58Prefix(CChainParams::COLDSTAKING_ADDRESS))) return false; uint160 id; memcpy(&id, &vchData[20], 20); keyID = CKeyID(id); return true; } bool CDeVaultAddress::IsScript() const { return IsValid() && vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS); } void CDeVaultSecret::SetKey(const CKey& vchSecret) { assert(vchSecret.IsValid()); SetData(Params().Base58Prefix(CChainParams::SECRET_KEY), vchSecret.begin(), vchSecret.size()); if (vchSecret.IsCompressed()) vchData.push_back(1); } CKey CDeVaultSecret::GetKey() { CKey ret; assert(vchData.size() >= 32); ret.Set(vchData.begin(), vchData.begin() + 32, vchData.size() > 32 && vchData[32] == 1); return ret; } bool CDeVaultSecret::IsValid() const { bool fExpectedFormat = vchData.size() == 32 || (vchData.size() == 33 && vchData[32] == 1); bool fCorrectVersion = vchVersion == Params().Base58Prefix(CChainParams::SECRET_KEY); return fExpectedFormat && fCorrectVersion; } bool CDeVaultSecret::SetString(const char* pszSecret) { return CBase58Data::SetString(pszSecret) && IsValid(); } bool CDeVaultSecret::SetString(const std::string& strSecret) { return SetString(strSecret.c_str()); }
/* * Copyright (c) 2022 Tuukka Norri * This code is licensed under MIT license (see LICENSE for details). */ #ifndef FOUNDER_GRAPHS_LEXICOGRAPHIC_RANGE_HH #define FOUNDER_GRAPHS_LEXICOGRAPHIC_RANGE_HH #include <libbio/assert.hh> #include <sdsl/suffix_array_algorithm.hpp> #include <vector> namespace founder_graphs::detail { template <typename t_wt, typename = void> struct has_r2d_res_type : std::false_type { }; template <typename t_wt> struct has_r2d_res_type <t_wt, std::void_t <typename t_wt::r2d_res_type>> : std::true_type { }; template <typename t_wt> constexpr inline bool has_r2d_res_type_v = std::is_base_of_v <std::true_type, has_r2d_res_type <t_wt>>; // Store the buffers for range_search_2d conditionally. template <typename t_wt, bool t_uses_r2d = has_r2d_res_type_v <t_wt>> struct lexicographic_range_pair_support { typedef typename t_wt::size_type wt_size_type; constexpr static inline bool USES_RANGE_SEARCH_2D{true}; std::vector <wt_size_type> offsets; std::vector <wt_size_type> ones_before_os; typename t_wt::point_vec_type points; }; template <typename t_wt> struct lexicographic_range_pair_support <t_wt, false> { constexpr static inline bool USES_RANGE_SEARCH_2D{false}; }; } namespace founder_graphs { template <typename t_csa> struct interval_symbols_context { typedef t_csa csa_type; typedef typename csa_type::size_type size_type; typedef typename csa_type::value_type value_type; std::vector <value_type> cs; std::vector <size_type> rank_c_i; std::vector <size_type> rank_c_j; interval_symbols_context() = default; interval_symbols_context(csa_type const &csa): cs(csa.sigma, 0), rank_c_i(csa.sigma, 0), rank_c_j(csa.sigma, 0) { } }; template <typename t_csa> struct lexicographic_range { typedef t_csa csa_type; typedef typename csa_type::size_type size_type; typedef typename csa_type::char_type char_type; typedef interval_symbols_context <csa_type> interval_symbols_context_type; size_type lb{}; size_type rb{}; lexicographic_range() = default; explicit lexicographic_range(csa_type const &csa): rb(csa.size() - 1) { } lexicographic_range(size_type const lb_, size_type const rb_): lb(lb_), rb(rb_) { } size_type size() const { return rb - lb + 1; } bool empty() const { return rb < lb; } bool is_singleton() const { return lb == rb; } bool has_prefix(lexicographic_range const other) const { return other.lb <= lb && rb <= other.rb; } void reset(csa_type const &csa) { lb = 0; rb = csa.size() - 1; } size_type backward_search(csa_type const &csa, char_type const cc) { return sdsl::backward_search(csa, lb, rb, cc, lb, rb); } template <typename t_it> size_type backward_search(csa_type const &csa, t_it begin, t_it it) { while (it != begin && 0 < rb + 1 - lb) { --it; backward_search(csa, *it); } return rb + 1 - lb; } template <typename t_it> size_type backward_search_h(csa_type const &csa, t_it begin, t_it it) { if (!backward_search(csa, '#')) return 0; return backward_search(csa, begin, it); } size_type forward_search(csa_type const &reverse_csa, char_type const cc) { // Assume that the index is reversed. return sdsl::backward_search(reverse_csa, lb, rb, cc, lb, rb); } template <typename t_it> size_type forward_search(csa_type const &reverse_csa, t_it it, t_it const end) { // Assume that the index is reversed. for (; it != end && 0 < rb + 1 - lb; ++it) backward_search(reverse_csa, *it); return rb + 1 - lb; } template <typename t_it> size_type forward_search_h(csa_type const &reverse_csa, t_it it, t_it end) { // Assume that the index is reversed. // ‘#’ should be the last character. if (!forward_search(reverse_csa, it, end)) return 0; return forward_search(reverse_csa, '#'); } size_type interval_symbols(csa_type const &csa, interval_symbols_context_type &ctx) const { size_type retval{}; // interval_symbols takes a half-open range. csa.wavelet_tree.interval_symbols(lb, 1 + rb, retval, ctx.cs, ctx.rank_c_i, ctx.rank_c_j); return retval; } }; template < typename t_csa, typename t_reverse_csa = t_csa, typename t_base = detail::lexicographic_range_pair_support <typename t_csa::wavelet_tree_type> > struct lexicographic_range_pair : public t_base { // We could also use std::common_type to find a suitable size_type. static_assert(std::is_same_v <typename t_csa::size_type, typename t_reverse_csa::size_type>); using t_base::USES_RANGE_SEARCH_2D; typedef t_csa csa_type; typedef t_reverse_csa reverse_csa_type; typedef typename csa_type::size_type size_type; typedef typename csa_type::wavelet_tree_type wavelet_tree_type; typedef typename csa_type::char_type char_type; typedef lexicographic_range <csa_type> lexicographic_range_type; lexicographic_range_type range{}; lexicographic_range_type co_range{}; lexicographic_range_pair() = default; explicit lexicographic_range_pair(csa_type const &csa): range(csa), co_range(range) { } lexicographic_range_pair(csa_type const &csa, reverse_csa_type const &): range(csa), co_range(range) { } lexicographic_range_pair(size_type const lb, size_type const rb, size_type const rlb, size_type const rrb): range(lb, rb), co_range(rlb, rrb) { } size_type size() const { return range.size(); } bool empty() const { return range.empty(); } bool is_singleton() const { return range.is_singleton(); } bool has_prefix(lexicographic_range <t_csa> const other) const { return range.has_prefix(other); } bool has_prefix(lexicographic_range_pair <t_csa> const other) const { return range.has_prefix(other.range); } void reset(csa_type const &csa) { range.reset(csa); co_range.reset(csa); } // Maintain both ranges. // Having this if USES_RANGE_SEARCH_2D is false seems too error-prone. size_type backward_search(csa_type const &csa, char_type const cc) requires(USES_RANGE_SEARCH_2D) { libbio_assert_neq(cc, 0); auto const kk(csa.wavelet_tree.range_search_2d(range.lb, range.rb, 0, cc - 1, this->offsets, this->ones_before_os, this->points, false)); auto const retval(range.backward_search(csa, cc)); co_range.lb += kk; co_range.rb = co_range.lb + retval - 1; return retval; } template <typename t_it> size_type backward_search(csa_type const &csa, t_it begin, t_it it) requires(USES_RANGE_SEARCH_2D) { while (it != begin && 0 < range.rb + 1 - range.lb) { --it; backward_search(csa, *it); } return range.rb + 1 - range.lb; } template <typename t_it> size_type backward_search_h(csa_type const &csa, t_it begin, t_it end) requires(USES_RANGE_SEARCH_2D) { if (!backward_search(csa, '#')) return 0; return backward_search(csa, begin, end); } template <typename t_it> size_type backward_search(csa_type const &csa, reverse_csa_type const &reverse_csa, t_it begin, t_it end) requires(!USES_RANGE_SEARCH_2D) { auto const retval(range.backward_search(csa, begin, end)); co_range.forward_search(reverse_csa, begin, end); libbio_assert_eq(retval, co_range.size()); return retval; } template <typename t_it> size_type backward_search_h(csa_type const &csa, reverse_csa_type const &reverse_csa, t_it begin, t_it end) requires(!USES_RANGE_SEARCH_2D) { auto const retval(range.backward_search_h(csa, begin, end)); co_range.forward_search_h(reverse_csa, begin, end); libbio_assert_eq(retval, co_range.size()); return retval; } }; } #endif
SFX_Noise_Instrument05_2_Ch8: noise_note 7, 8, 4, 55 noise_note 6, 8, 4, 54 noise_note 5, 8, 3, 53 noise_note 4, 8, 3, 52 noise_note 3, 8, 2, 51 noise_note 2, 8, 1, 50 sound_ret
#include "SceneRenderer.h" namespace fightdude { void SceneRenderer::drawMesh(Mesh *mesh, std::vector<Material> *materials) {} } //namespace fightdude
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r11 push %r14 push %r8 push %r9 push %rax push %rcx push %rdi push %rsi lea addresses_WT_ht+0x6342, %r11 sub %rcx, %rcx mov (%r11), %r8 nop nop nop nop dec %r14 lea addresses_WT_ht+0x1d39a, %r9 nop nop nop nop and $1937, %rax mov (%r9), %cx nop nop nop inc %r14 lea addresses_A_ht+0xe43a, %r9 clflush (%r9) nop nop nop inc %r10 movb $0x61, (%r9) nop nop nop xor %rax, %rax lea addresses_normal_ht+0x1ec24, %rsi lea addresses_A_ht+0x15f9a, %rdi clflush (%rsi) nop nop nop nop nop xor %rax, %rax mov $72, %rcx rep movsw nop nop nop nop dec %rsi lea addresses_WT_ht+0xff9a, %rcx nop nop nop nop sub %r14, %r14 mov (%rcx), %r11w and %rax, %rax lea addresses_WT_ht+0x13a4a, %rdi clflush (%rdi) nop nop nop add %r11, %r11 movb $0x61, (%rdi) nop nop nop nop xor $57387, %rdi lea addresses_UC_ht+0x13f9a, %r14 nop nop xor $27200, %r8 mov (%r14), %cx nop nop nop nop sub %rcx, %rcx lea addresses_A_ht+0x1b63a, %rsi nop nop nop nop add %r14, %r14 mov $0x6162636465666768, %r10 movq %r10, %xmm3 movups %xmm3, (%rsi) nop nop nop add $56789, %rax lea addresses_A_ht+0x18d9a, %rcx nop nop xor %rax, %rax mov $0x6162636465666768, %rsi movq %rsi, %xmm2 movups %xmm2, (%rcx) nop nop nop and %rax, %rax lea addresses_WC_ht+0x1dcb6, %rdi nop xor $54225, %r9 mov (%rdi), %rax nop nop and %r11, %r11 lea addresses_WC_ht+0x629a, %r8 nop and %r14, %r14 mov (%r8), %r9 cmp $26770, %r9 lea addresses_A_ht+0x47cc, %rcx nop nop and %rsi, %rsi movups (%rcx), %xmm3 vpextrq $0, %xmm3, %rdi mfence lea addresses_WC_ht+0x1309a, %rcx nop nop nop nop nop and %r11, %r11 vmovups (%rcx), %ymm5 vextracti128 $1, %ymm5, %xmm5 vpextrq $0, %xmm5, %r14 add $6090, %rdi lea addresses_WC_ht+0x1939a, %rsi nop nop add $30353, %r10 mov $0x6162636465666768, %r11 movq %r11, %xmm3 vmovups %ymm3, (%rsi) nop nop nop nop xor %r14, %r14 pop %rsi pop %rdi pop %rcx pop %rax pop %r9 pop %r8 pop %r14 pop %r11 pop %r10 ret .global s_faulty_load s_faulty_load: push %r14 push %r8 push %r9 push %rax push %rbx push %rcx // Faulty Load lea addresses_A+0x1e79a, %r14 nop nop nop nop add $51262, %rcx movntdqa (%r14), %xmm7 vpextrq $1, %xmm7, %r9 lea oracles, %rax and $0xff, %r9 shlq $12, %r9 mov (%rax,%r9,1), %r9 pop %rcx pop %rbx pop %rax pop %r9 pop %r8 pop %r14 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_A', 'size': 16, 'AVXalign': False, 'NT': True, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 11, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'size': 2, 'AVXalign': True, 'NT': False, 'congruent': 11, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 9, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 8, 'AVXalign': True, 'NT': False, 'congruent': 8, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': True}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}} {'00': 1674, '44': 624, '45': 394, '48': 21} 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 44 00 00 45 00 00 45 00 00 44 44 00 00 45 44 48 00 44 44 00 45 00 00 00 00 00 00 00 00 44 00 00 00 44 00 00 45 00 44 45 00 45 00 44 00 00 45 00 45 00 00 45 44 00 00 45 44 00 00 45 44 00 00 44 00 44 00 00 45 00 45 45 00 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00 44 45 00 00 00 44 44 44 00 00 00 00 00 00 44 00 00 00 45 44 00 00 00 45 00 00 00 44 00 00 44 45 00 00 00 44 48 00 44 44 45 00 44 00 44 00 00 45 45 44 44 44 00 00 45 00 00 44 00 00 00 00 00 45 44 00 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 00 00 44 44 45 45 44 00 00 00 00 00 44 00 45 00 00 00 45 45 00 00 44 00 00 00 44 44 44 00 00 00 00 00 44 44 00 00 44 00 00 44 45 44 00 00 44 44 44 00 44 00 00 00 00 44 44 00 00 00 44 00 00 00 44 00 00 00 44 44 00 44 00 00 00 00 44 44 00 00 00 44 00 45 44 00 00 00 00 00 45 44 00 44 44 00 45 00 44 44 44 00 45 45 00 44 00 00 45 00 00 00 44 45 44 44 00 44 00 45 44 00 00 00 00 00 00 44 45 45 45 00 00 00 45 00 00 00 44 00 44 00 44 00 44 00 48 00 45 44 00 45 44 00 44 00 44 00 45 00 44 00 00 00 00 00 45 00 00 44 00 00 45 00 00 45 45 00 00 00 44 00 00 44 45 44 45 00 00 45 00 44 44 00 00 00 00 44 00 44 45 00 00 00 00 00 00 00 00 44 00 44 44 00 00 00 00 00 00 00 45 00 00 00 44 00 00 00 00 00 00 44 44 00 00 45 45 45 00 00 00 45 00 00 00 45 00 44 00 44 44 00 00 00 44 00 00 00 44 00 00 45 00 45 00 00 44 00 44 45 00 00 45 44 00 44 00 45 00 44 00 00 00 00 00 44 44 00 00 00 44 00 00 00 00 00 00 00 44 00 44 45 00 00 44 00 44 00 44 45 00 00 44 44 00 00 00 00 44 00 00 45 00 00 00 45 00 00 00 00 00 44 44 00 00 00 00 44 00 00 00 48 44 45 00 00 00 00 00 00 44 00 45 00 48 00 00 00 00 45 44 44 00 00 44 00 44 44 00 00 00 44 00 00 44 48 00 44 45 00 45 44 00 00 00 00 00 00 44 00 00 00 00 00 00 44 00 00 00 00 00 00 44 44 00 00 44 45 00 45 00 44 00 44 00 44 00 45 45 00 44 44 00 44 44 44 45 44 45 45 00 00 00 00 00 44 45 00 00 00 44 00 00 00 00 44 44 00 00 00 44 00 00 45 44 00 00 44 00 44 00 45 00 44 44 00 00 00 45 00 00 00 44 00 00 00 45 00 00 45 00 00 45 45 00 44 45 00 00 44 00 00 00 44 45 44 00 44 44 00 00 44 44 44 44 00 44 44 00 44 00 00 00 44 00 00 00 00 44 44 00 44 00 00 00 45 44 00 00 44 45 44 44 45 00 00 44 44 45 00 00 00 00 44 45 44 45 00 45 00 00 00 00 00 44 00 44 44 00 00 00 44 00 00 48 00 45 00 44 44 00 45 45 44 00 00 00 45 45 00 00 45 44 45 00 44 00 00 00 00 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 45 44 00 44 48 00 00 00 00 00 00 00 00 00 44 44 48 00 00 00 00 00 00 00 00 00 00 00 00 44 00 00 00 44 44 45 00 00 00 00 00 44 00 00 00 44 00 44 00 00 00 44 00 00 00 45 00 00 00 45 00 44 00 48 00 00 00 00 00 45 44 00 00 00 00 00 00 44 44 00 00 44 00 00 44 00 00 45 44 00 00 00 00 00 00 44 00 00 44 00 44 00 45 00 45 00 44 00 45 00 44 00 45 00 44 44 00 45 45 45 45 00 45 00 00 44 00 00 45 00 00 00 00 00 00 44 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 44 00 44 00 44 00 44 44 45 00 44 00 45 44 44 00 00 00 44 00 45 48 44 44 00 00 00 00 44 00 00 00 44 00 00 44 00 00 00 00 44 00 44 44 00 00 00 00 00 45 00 00 */
; A167194: Triangle read by rows. A130713 in the columns. ; 1,2,1,1,2,1,0,1,2,1,0,0,1,2,1,0,0,0,1,2,1,0,0,0,0,1,2,1,0,0,0,0,0,1,2,1,0,0,0,0,0,0,1,2,1,0,0,0,0,0,0,0,1,2,1,0,0,0,0,0,0,0,0,1,2,1,0,0,0,0,0,0,0,0,0,1,2,1,0,0,0,0,0,0,0,0,0,0,1,2,1 add $0,1 lpb $0 sub $0,1 add $1,$0 trn $0,1 add $1,1 sub $1,$0 trn $1,$0 add $2,1 trn $0,$2 lpe
; A077939: Expansion of 1/(1 - 2*x - x^2 - x^3). ; 1,2,5,13,33,84,214,545,1388,3535,9003,22929,58396,148724,378773,964666,2456829,6257097,15935689,40585304,103363394,263247781,670444260,1707499695,4348691431,11075326817,28206844760,71837707768,182957587113,465959726754,1186714748389,3022346810645,7697368096433,19603797751900,49927310410878,127155786670089,323842681502956,824768460086879,2100535388346803,5349681918283441,13624667685000564,34699552676631372,88373454956546749,225071130274725434,573215268182628989,1459875121596530161,3718036641650414745,9469163673079988640,24116239109406922186,61419678533544247757,156424759849575406340,398385437342101982623,1014615313067323619343,2584040823326324627649,6581082397062074857264,16760820930517797961520,42686765081423995407953,108715433490427863634690,276878452992797520638853,705159104557446900320349,1795912095598119184914241,4573861748746482790787684,11648794697648531666809958,29667363239641665309321841,75557382925678345076241324,192430923788646887128614447,490086593742613784642792059,1248161494199552801490439889,3178840505930366274752286284,8095929099802899135637804516,20618860199735717347518335205,52512490005204700105426761210,133739769309948016694009662141,340610888824836450840964420697,867474036964825618481365264745,2209298732064435704497704612328,5626682389918533478317738910098,14330137548866328279614547697269,36496256219715625742044538916964,92949332378216113242021364441295,236725058525014180505701815496823,602895705647960099995469534351905,1535465802199150493738662248641928,3910552368571275267978495847132584,9959466244989661129691123477259001,25364950660749748021099405050292514,64599919935060432439868429424976613,164524256775860274030527387377504741,419013384147530728522022609230278609 lpb $0 mov $2,$0 sub $0,1 seq $2,77997 ; Expansion of (1-x)/(1-2*x-x^2-x^3). add $1,$2 lpe add $1,1 mov $0,$1
Name: Sub_sound.asm Type: file Size: 15272 Last-Modified: '1992-11-18T01:48:26Z' SHA-1: A14A12FBE63F36C66C55E8BE7158E74EF1CDF310 Description: null
/* * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #include <stdio.h> #include <memory> #include <vector> #include "media/base/fakevideocapturer.h" #include "media/base/fakevideorenderer.h" #include "media/base/testutils.h" #include "media/base/videocapturer.h" #include "rtc_base/gunit.h" #include "rtc_base/logging.h" #include "rtc_base/thread.h" using cricket::FakeVideoCapturerWithTaskQueue; namespace { const int kMsCallbackWait = 500; // For HD only the height matters. const int kMinHdHeight = 720; } // namespace class VideoCapturerTest : public sigslot::has_slots<>, public testing::Test { public: VideoCapturerTest() : capture_state_(cricket::CS_STOPPED), num_state_changes_(0) { InitCapturer(false); } protected: void InitCapturer(bool is_screencast) { capturer_ = std::unique_ptr<FakeVideoCapturerWithTaskQueue>( new FakeVideoCapturerWithTaskQueue(is_screencast)); capturer_->SignalStateChange.connect(this, &VideoCapturerTest::OnStateChange); capturer_->AddOrUpdateSink(&renderer_, rtc::VideoSinkWants()); } void InitScreencast() { InitCapturer(true); } void OnStateChange(cricket::VideoCapturer*, cricket::CaptureState capture_state) { capture_state_ = capture_state; ++num_state_changes_; } cricket::CaptureState capture_state() { return capture_state_; } int num_state_changes() { return num_state_changes_; } std::unique_ptr<FakeVideoCapturerWithTaskQueue> capturer_; cricket::CaptureState capture_state_; int num_state_changes_; cricket::FakeVideoRenderer renderer_; bool expects_rotation_applied_; }; TEST_F(VideoCapturerTest, CaptureState) { EXPECT_TRUE(capturer_->enable_video_adapter()); EXPECT_EQ(cricket::CS_RUNNING, capturer_->Start(cricket::VideoFormat( 640, 480, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420))); EXPECT_TRUE(capturer_->IsRunning()); EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait); EXPECT_EQ(1, num_state_changes()); capturer_->Stop(); EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait); EXPECT_EQ(2, num_state_changes()); capturer_->Stop(); rtc::Thread::Current()->ProcessMessages(100); EXPECT_EQ(2, num_state_changes()); } TEST_F(VideoCapturerTest, ScreencastScaledOddWidth) { InitScreencast(); int kWidth = 1281; int kHeight = 720; std::vector<cricket::VideoFormat> formats; formats.push_back(cricket::VideoFormat(kWidth, kHeight, cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(formats); EXPECT_EQ(cricket::CS_RUNNING, capturer_->Start(cricket::VideoFormat( kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420))); EXPECT_TRUE(capturer_->IsRunning()); EXPECT_EQ(0, renderer_.num_rendered_frames()); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(1, renderer_.num_rendered_frames()); EXPECT_EQ(kWidth, renderer_.width()); EXPECT_EQ(kHeight, renderer_.height()); } TEST_F(VideoCapturerTest, TestRotationAppliedBySource) { int kWidth = 800; int kHeight = 400; int frame_count = 0; std::vector<cricket::VideoFormat> formats; formats.push_back(cricket::VideoFormat(kWidth, kHeight, cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(formats); rtc::VideoSinkWants wants; // |capturer_| should compensate rotation. wants.rotation_applied = true; capturer_->AddOrUpdateSink(&renderer_, wants); // capturer_ should compensate rotation as default. EXPECT_EQ(cricket::CS_RUNNING, capturer_->Start(cricket::VideoFormat( kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420))); EXPECT_TRUE(capturer_->IsRunning()); EXPECT_EQ(0, renderer_.num_rendered_frames()); // If the frame's rotation is compensated anywhere in the pipeline based on // the rotation information, the renderer should be given the right dimension // such that the frame could be rendered. capturer_->SetRotation(webrtc::kVideoRotation_90); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); // Swapped width and height EXPECT_EQ(kWidth, renderer_.height()); EXPECT_EQ(kHeight, renderer_.width()); EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); capturer_->SetRotation(webrtc::kVideoRotation_270); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); // Swapped width and height EXPECT_EQ(kWidth, renderer_.height()); EXPECT_EQ(kHeight, renderer_.width()); EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); capturer_->SetRotation(webrtc::kVideoRotation_180); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); // Back to normal width and height EXPECT_EQ(kWidth, renderer_.width()); EXPECT_EQ(kHeight, renderer_.height()); EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); } TEST_F(VideoCapturerTest, TestRotationAppliedBySinkByDefault) { int kWidth = 800; int kHeight = 400; std::vector<cricket::VideoFormat> formats; formats.push_back(cricket::VideoFormat(kWidth, kHeight, cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(formats); EXPECT_EQ(cricket::CS_RUNNING, capturer_->Start(cricket::VideoFormat( kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420))); EXPECT_TRUE(capturer_->IsRunning()); EXPECT_EQ(0, renderer_.num_rendered_frames()); // If the frame's rotation is compensated anywhere in the pipeline, the frame // won't have its original dimension out from capturer. Since the renderer // here has the same dimension as the capturer, it will skip that frame as the // resolution won't match anymore. int frame_count = 0; capturer_->SetRotation(webrtc::kVideoRotation_0); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); EXPECT_EQ(capturer_->GetRotation(), renderer_.rotation()); capturer_->SetRotation(webrtc::kVideoRotation_90); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); EXPECT_EQ(capturer_->GetRotation(), renderer_.rotation()); capturer_->SetRotation(webrtc::kVideoRotation_180); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); EXPECT_EQ(capturer_->GetRotation(), renderer_.rotation()); capturer_->SetRotation(webrtc::kVideoRotation_270); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); EXPECT_EQ(capturer_->GetRotation(), renderer_.rotation()); } TEST_F(VideoCapturerTest, TestRotationAppliedBySourceWhenDifferentWants) { int kWidth = 800; int kHeight = 400; std::vector<cricket::VideoFormat> formats; formats.push_back(cricket::VideoFormat(kWidth, kHeight, cricket::VideoFormat::FpsToInterval(5), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(formats); rtc::VideoSinkWants wants; // capturer_ should not compensate rotation. wants.rotation_applied = false; capturer_->AddOrUpdateSink(&renderer_, wants); EXPECT_EQ(cricket::CS_RUNNING, capturer_->Start(cricket::VideoFormat( kWidth, kHeight, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420))); EXPECT_TRUE(capturer_->IsRunning()); EXPECT_EQ(0, renderer_.num_rendered_frames()); int frame_count = 0; capturer_->SetRotation(webrtc::kVideoRotation_90); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); EXPECT_EQ(capturer_->GetRotation(), renderer_.rotation()); // Add another sink that wants frames to be rotated. cricket::FakeVideoRenderer renderer2; wants.rotation_applied = true; capturer_->AddOrUpdateSink(&renderer2, wants); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(++frame_count, renderer_.num_rendered_frames()); EXPECT_EQ(1, renderer2.num_rendered_frames()); EXPECT_EQ(webrtc::kVideoRotation_0, renderer_.rotation()); EXPECT_EQ(webrtc::kVideoRotation_0, renderer2.rotation()); } // TODO(nisse): This test doesn't quite fit here. It tests two things: // Aggregation of VideoSinkWants, which is the responsibility of // VideoBroadcaster, and translation of VideoSinkWants to actual // resolution, which is the responsibility of the VideoAdapter. TEST_F(VideoCapturerTest, SinkWantsMaxPixelAndMaxPixelCountStepUp) { EXPECT_EQ(cricket::CS_RUNNING, capturer_->Start(cricket::VideoFormat( 1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420))); EXPECT_TRUE(capturer_->IsRunning()); EXPECT_EQ(0, renderer_.num_rendered_frames()); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(1, renderer_.num_rendered_frames()); EXPECT_EQ(1280, renderer_.width()); EXPECT_EQ(720, renderer_.height()); // Request a lower resolution. The output resolution will have a resolution // with less than or equal to |wants.max_pixel_count| depending on how the // capturer can scale the input frame size. rtc::VideoSinkWants wants; wants.max_pixel_count = 1280 * 720 * 3 / 5; capturer_->AddOrUpdateSink(&renderer_, wants); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(2, renderer_.num_rendered_frames()); EXPECT_EQ(960, renderer_.width()); EXPECT_EQ(540, renderer_.height()); // Request a lower resolution. wants.max_pixel_count = (renderer_.width() * renderer_.height() * 3) / 5; capturer_->AddOrUpdateSink(&renderer_, wants); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(3, renderer_.num_rendered_frames()); EXPECT_EQ(640, renderer_.width()); EXPECT_EQ(360, renderer_.height()); // Adding a new renderer should not affect resolution. cricket::FakeVideoRenderer renderer2; capturer_->AddOrUpdateSink(&renderer2, rtc::VideoSinkWants()); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(4, renderer_.num_rendered_frames()); EXPECT_EQ(640, renderer_.width()); EXPECT_EQ(360, renderer_.height()); EXPECT_EQ(1, renderer2.num_rendered_frames()); EXPECT_EQ(640, renderer2.width()); EXPECT_EQ(360, renderer2.height()); // Request higher resolution. wants.target_pixel_count.emplace((wants.max_pixel_count * 5) / 3); wants.max_pixel_count = wants.max_pixel_count * 4; capturer_->AddOrUpdateSink(&renderer_, wants); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(5, renderer_.num_rendered_frames()); EXPECT_EQ(960, renderer_.width()); EXPECT_EQ(540, renderer_.height()); EXPECT_EQ(2, renderer2.num_rendered_frames()); EXPECT_EQ(960, renderer2.width()); EXPECT_EQ(540, renderer2.height()); // Updating with no wants should not affect resolution. capturer_->AddOrUpdateSink(&renderer2, rtc::VideoSinkWants()); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(6, renderer_.num_rendered_frames()); EXPECT_EQ(960, renderer_.width()); EXPECT_EQ(540, renderer_.height()); EXPECT_EQ(3, renderer2.num_rendered_frames()); EXPECT_EQ(960, renderer2.width()); EXPECT_EQ(540, renderer2.height()); // But resetting the wants should reset the resolution to what the camera is // opened with. capturer_->AddOrUpdateSink(&renderer_, rtc::VideoSinkWants()); EXPECT_TRUE(capturer_->CaptureFrame()); EXPECT_EQ(7, renderer_.num_rendered_frames()); EXPECT_EQ(1280, renderer_.width()); EXPECT_EQ(720, renderer_.height()); EXPECT_EQ(4, renderer2.num_rendered_frames()); EXPECT_EQ(1280, renderer2.width()); EXPECT_EQ(720, renderer2.height()); } TEST_F(VideoCapturerTest, TestFourccMatch) { cricket::VideoFormat desired( 640, 480, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_ANY); cricket::VideoFormat best; EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); EXPECT_EQ(640, best.width); EXPECT_EQ(480, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); desired.fourcc = cricket::FOURCC_MJPG; EXPECT_FALSE(capturer_->GetBestCaptureFormat(desired, &best)); desired.fourcc = cricket::FOURCC_I420; EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); } TEST_F(VideoCapturerTest, TestResolutionMatch) { cricket::VideoFormat desired( 1920, 1080, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_ANY); cricket::VideoFormat best; // Ask for 1920x1080. Get HD 1280x720 which is the highest. EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); EXPECT_EQ(1280, best.width); EXPECT_EQ(720, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); desired.width = 360; desired.height = 250; // Ask for a little higher than QVGA. Get QVGA. EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); EXPECT_EQ(320, best.width); EXPECT_EQ(240, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); desired.width = 480; desired.height = 270; // Ask for HVGA. Get VGA. EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); EXPECT_EQ(640, best.width); EXPECT_EQ(480, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); desired.width = 320; desired.height = 240; // Ask for QVGA. Get QVGA. EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); EXPECT_EQ(320, best.width); EXPECT_EQ(240, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); desired.width = 80; desired.height = 60; // Ask for lower than QQVGA. Get QQVGA, which is the lowest. EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); EXPECT_EQ(160, best.width); EXPECT_EQ(120, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); } TEST_F(VideoCapturerTest, TestHDResolutionMatch) { // Add some HD formats typical of a mediocre HD webcam. std::vector<cricket::VideoFormat> formats; formats.push_back(cricket::VideoFormat( 320, 240, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); formats.push_back(cricket::VideoFormat( 640, 480, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); formats.push_back(cricket::VideoFormat( 960, 544, cricket::VideoFormat::FpsToInterval(24), cricket::FOURCC_I420)); formats.push_back( cricket::VideoFormat(1280, 720, cricket::VideoFormat::FpsToInterval(15), cricket::FOURCC_I420)); formats.push_back(cricket::VideoFormat(2592, 1944, cricket::VideoFormat::FpsToInterval(7), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(formats); cricket::VideoFormat desired( 960, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_ANY); cricket::VideoFormat best; // Ask for 960x720 30 fps. Get qHD 24 fps EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); EXPECT_EQ(960, best.width); EXPECT_EQ(544, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(24), best.interval); desired.width = 960; desired.height = 544; desired.interval = cricket::VideoFormat::FpsToInterval(30); // Ask for qHD 30 fps. Get qHD 24 fps EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); EXPECT_EQ(960, best.width); EXPECT_EQ(544, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(24), best.interval); desired.width = 360; desired.height = 250; desired.interval = cricket::VideoFormat::FpsToInterval(30); // Ask for a little higher than QVGA. Get QVGA. EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); EXPECT_EQ(320, best.width); EXPECT_EQ(240, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); desired.width = 480; desired.height = 270; // Ask for HVGA. Get VGA. EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); EXPECT_EQ(640, best.width); EXPECT_EQ(480, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); desired.width = 320; desired.height = 240; // Ask for QVGA. Get QVGA. EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); EXPECT_EQ(320, best.width); EXPECT_EQ(240, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); desired.width = 160; desired.height = 120; // Ask for lower than QVGA. Get QVGA, which is the lowest. EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); EXPECT_EQ(320, best.width); EXPECT_EQ(240, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); desired.width = 1280; desired.height = 720; // Ask for HD. 720p fps is too low. Get VGA which has 30 fps. EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); EXPECT_EQ(640, best.width); EXPECT_EQ(480, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); desired.width = 1280; desired.height = 720; desired.interval = cricket::VideoFormat::FpsToInterval(15); // Ask for HD 15 fps. Fps matches. Get HD EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); EXPECT_EQ(1280, best.width); EXPECT_EQ(720, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), best.interval); desired.width = 1920; desired.height = 1080; desired.interval = cricket::VideoFormat::FpsToInterval(30); // Ask for 1080p. Fps of HD formats is too low. Get VGA which can do 30 fps. EXPECT_TRUE(capturer_->GetBestCaptureFormat(desired, &best)); EXPECT_EQ(640, best.width); EXPECT_EQ(480, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); } // Some cameras support 320x240 and 320x640. Verify we choose 320x240. TEST_F(VideoCapturerTest, TestStrangeFormats) { std::vector<cricket::VideoFormat> supported_formats; supported_formats.push_back(cricket::VideoFormat( 320, 240, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 320, 640, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(supported_formats); std::vector<cricket::VideoFormat> required_formats; required_formats.push_back(cricket::VideoFormat( 320, 240, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); required_formats.push_back(cricket::VideoFormat( 320, 200, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); required_formats.push_back(cricket::VideoFormat( 320, 180, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); cricket::VideoFormat best; for (size_t i = 0; i < required_formats.size(); ++i) { EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); EXPECT_EQ(320, best.width); EXPECT_EQ(240, best.height); } supported_formats.clear(); supported_formats.push_back(cricket::VideoFormat( 320, 640, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 320, 240, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(supported_formats); for (size_t i = 0; i < required_formats.size(); ++i) { EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); EXPECT_EQ(320, best.width); EXPECT_EQ(240, best.height); } } // Some cameras only have very low fps. Verify we choose something sensible. TEST_F(VideoCapturerTest, TestPoorFpsFormats) { // all formats are low framerate std::vector<cricket::VideoFormat> supported_formats; supported_formats.push_back(cricket::VideoFormat( 320, 240, cricket::VideoFormat::FpsToInterval(10), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 480, cricket::VideoFormat::FpsToInterval(7), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 1280, 720, cricket::VideoFormat::FpsToInterval(2), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(supported_formats); std::vector<cricket::VideoFormat> required_formats; required_formats.push_back(cricket::VideoFormat( 320, 240, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); required_formats.push_back(cricket::VideoFormat( 640, 480, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); cricket::VideoFormat best; for (size_t i = 0; i < required_formats.size(); ++i) { EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); EXPECT_EQ(required_formats[i].width, best.width); EXPECT_EQ(required_formats[i].height, best.height); } // Increase framerate of 320x240. Expect low fps VGA avoided. supported_formats.clear(); supported_formats.push_back(cricket::VideoFormat( 320, 240, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 480, cricket::VideoFormat::FpsToInterval(7), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 1280, 720, cricket::VideoFormat::FpsToInterval(2), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(supported_formats); for (size_t i = 0; i < required_formats.size(); ++i) { EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); EXPECT_EQ(320, best.width); EXPECT_EQ(240, best.height); } } // Some cameras support same size with different frame rates. Verify we choose // the frame rate properly. TEST_F(VideoCapturerTest, TestSameSizeDifferentFpsFormats) { std::vector<cricket::VideoFormat> supported_formats; supported_formats.push_back(cricket::VideoFormat( 320, 240, cricket::VideoFormat::FpsToInterval(10), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 320, 240, cricket::VideoFormat::FpsToInterval(20), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 320, 240, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(supported_formats); std::vector<cricket::VideoFormat> required_formats = supported_formats; cricket::VideoFormat best; for (size_t i = 0; i < required_formats.size(); ++i) { EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); EXPECT_EQ(320, best.width); EXPECT_EQ(240, best.height); EXPECT_EQ(required_formats[i].interval, best.interval); } } // Some cameras support the correct resolution but at a lower fps than // we'd like. This tests we get the expected resolution and fps. TEST_F(VideoCapturerTest, TestFpsFormats) { // We have VGA but low fps. Choose VGA, not HD std::vector<cricket::VideoFormat> supported_formats; supported_formats.push_back( cricket::VideoFormat(1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 480, cricket::VideoFormat::FpsToInterval(15), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 400, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 360, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(supported_formats); std::vector<cricket::VideoFormat> required_formats; required_formats.push_back(cricket::VideoFormat( 640, 480, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_ANY)); required_formats.push_back(cricket::VideoFormat( 640, 480, cricket::VideoFormat::FpsToInterval(20), cricket::FOURCC_ANY)); required_formats.push_back(cricket::VideoFormat( 640, 480, cricket::VideoFormat::FpsToInterval(10), cricket::FOURCC_ANY)); cricket::VideoFormat best; // Expect 30 fps to choose 30 fps format. EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[0], &best)); EXPECT_EQ(640, best.width); EXPECT_EQ(400, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); // Expect 20 fps to choose 30 fps format. EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[1], &best)); EXPECT_EQ(640, best.width); EXPECT_EQ(400, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), best.interval); // Expect 10 fps to choose 15 fps format and set fps to 15. EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[2], &best)); EXPECT_EQ(640, best.width); EXPECT_EQ(480, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), best.interval); // We have VGA 60 fps and 15 fps. Choose best fps. supported_formats.clear(); supported_formats.push_back( cricket::VideoFormat(1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 480, cricket::VideoFormat::FpsToInterval(60), cricket::FOURCC_MJPG)); supported_formats.push_back(cricket::VideoFormat( 640, 480, cricket::VideoFormat::FpsToInterval(15), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 400, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 360, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(supported_formats); // Expect 30 fps to choose 60 fps format and will set best fps to 60. EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[0], &best)); EXPECT_EQ(640, best.width); EXPECT_EQ(480, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(60), best.interval); // Expect 20 fps to choose 60 fps format, and will set best fps to 60. EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[1], &best)); EXPECT_EQ(640, best.width); EXPECT_EQ(480, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(60), best.interval); // Expect 10 fps to choose 15 fps. EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[2], &best)); EXPECT_EQ(640, best.width); EXPECT_EQ(480, best.height); EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), best.interval); } TEST_F(VideoCapturerTest, TestRequest16x10_9) { std::vector<cricket::VideoFormat> supported_formats; // We do not support HD, expect 4x3 for 4x3, 16x10, and 16x9 requests. supported_formats.push_back(cricket::VideoFormat( 640, 480, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 400, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 360, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(supported_formats); std::vector<cricket::VideoFormat> required_formats = supported_formats; cricket::VideoFormat best; // Expect 4x3, 16x10, and 16x9 requests are respected. for (size_t i = 0; i < required_formats.size(); ++i) { EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); EXPECT_EQ(required_formats[i].width, best.width); EXPECT_EQ(required_formats[i].height, best.height); } // We do not support 16x9 HD, expect 4x3 for 4x3, 16x10, and 16x9 requests. supported_formats.clear(); supported_formats.push_back(cricket::VideoFormat( 960, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 480, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 400, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 360, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(supported_formats); // Expect 4x3, 16x10, and 16x9 requests are respected. for (size_t i = 0; i < required_formats.size(); ++i) { EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); EXPECT_EQ(required_formats[i].width, best.width); EXPECT_EQ(required_formats[i].height, best.height); } // We support 16x9HD, Expect 4x3, 16x10, and 16x9 requests are respected. supported_formats.clear(); supported_formats.push_back( cricket::VideoFormat(1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 480, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 400, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back(cricket::VideoFormat( 640, 360, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(supported_formats); // Expect 4x3 for 4x3 and 16x10 requests. for (size_t i = 0; i < required_formats.size() - 1; ++i) { EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[i], &best)); EXPECT_EQ(required_formats[i].width, best.width); EXPECT_EQ(required_formats[i].height, best.height); } // Expect 16x9 for 16x9 request. EXPECT_TRUE(capturer_->GetBestCaptureFormat(required_formats[2], &best)); EXPECT_EQ(640, best.width); EXPECT_EQ(360, best.height); } bool HdFormatInList(const std::vector<cricket::VideoFormat>& formats) { for (std::vector<cricket::VideoFormat>::const_iterator found = formats.begin(); found != formats.end(); ++found) { if (found->height >= kMinHdHeight) { return true; } } return false; } TEST_F(VideoCapturerTest, Whitelist) { // The definition of HD only applies to the height. Set the HD width to the // smallest legal number to document this fact in this test. const int kMinHdWidth = 1; cricket::VideoFormat hd_format(kMinHdWidth, kMinHdHeight, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); cricket::VideoFormat vga_format( 640, 480, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); std::vector<cricket::VideoFormat> formats = *capturer_->GetSupportedFormats(); formats.push_back(hd_format); // Enable whitelist. Expect HD not in list. capturer_->set_enable_camera_list(true); capturer_->ResetSupportedFormats(formats); EXPECT_TRUE(HdFormatInList(*capturer_->GetSupportedFormats())); capturer_->ConstrainSupportedFormats(vga_format); EXPECT_FALSE(HdFormatInList(*capturer_->GetSupportedFormats())); // Disable whitelist. Expect HD in list. capturer_->set_enable_camera_list(false); capturer_->ResetSupportedFormats(formats); EXPECT_TRUE(HdFormatInList(*capturer_->GetSupportedFormats())); capturer_->ConstrainSupportedFormats(vga_format); EXPECT_TRUE(HdFormatInList(*capturer_->GetSupportedFormats())); } TEST_F(VideoCapturerTest, BlacklistAllFormats) { cricket::VideoFormat vga_format( 640, 480, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); std::vector<cricket::VideoFormat> supported_formats; // Mock a device that only supports HD formats. supported_formats.push_back( cricket::VideoFormat(1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); supported_formats.push_back( cricket::VideoFormat(1920, 1080, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); capturer_->ResetSupportedFormats(supported_formats); EXPECT_EQ(2u, capturer_->GetSupportedFormats()->size()); // Now, enable the list, which would exclude both formats. However, since // only HD formats are available, we refuse to filter at all, so we don't // break this camera. capturer_->set_enable_camera_list(true); capturer_->ConstrainSupportedFormats(vga_format); EXPECT_EQ(2u, capturer_->GetSupportedFormats()->size()); // To make sure it's not just the camera list being broken, add in VGA and // try again. This time, only the VGA format should be there. supported_formats.push_back(vga_format); capturer_->ResetSupportedFormats(supported_formats); ASSERT_EQ(1u, capturer_->GetSupportedFormats()->size()); EXPECT_EQ(vga_format.height, capturer_->GetSupportedFormats()->at(0).height); }
.include "include/bios.inc" .include "include/zp.inc" .include "include/strings.inc" ;;; ;; INPUT_DEC: Request 1-8 ASCII decimal numbers and convert to binary. ;; ;; Preparation: ;; x: number of decimal characters to read. Max 8. ;; ;; Returned Values: a: used ;; x: number of characters read ;; y: used ;; ;; ;; Examples: ;; ldx #3 ;read up to three characters, ie one byte ;; jsr input_dec ;call subroutine ;; ;;; input_dec: .proc smb 0,control_flags rmb 1,control_flags jmp input .pend ;;; ;; INPUT_HEX: Request 1-8 ASCII hex numbers and convert to binary. ;; ;; Preparation: ;; x: number of hex characters to get from termnial. Max 8. ;; ;; Returned Values: a: used ;; x: number of characters read ;; y: used ;; ;; ;; Examples: ;; ldx #2 ;read up to two characters, ie one byte ;; jsr input_hex ;call subroutine ;; ;;; input_hex: .proc rmb 0,control_flags ;Set flags ... rmb 1,control_flags ;... for hex input jmp input .pend ;;; ;; INPUT: Input characters from console, filtered by control_flags. ;; ;; Preparation: control_flags set to input mode. ;; ;; Returned Values: a: Used ;; x: Will contain number of characters read ;; y: Used ;; number_buffer: Contains the binary number if x > 0 ;; ;; Examples: rmb 0,control_flags ;Set flags ... ;; rmb 1,control_flags ;... for hex input ;; jsr input ;call input ;; ;;; input: .proc lda #>input_buffer ldy #<input_buffer jsr read_line ;x will contain number of characters read jmp ascii_to_bin ;Convert ASCII in input_buffer to binary in number_buffer .pend ;;; ;; READ_LINE subroutine: Read characters from terminal until CR is found or maximum characters have been read. ;; Derived work from "6502 ASSEMBLY LANGUAGE SUBROUTINES", ISBN: 0-931988-59-4 ;; Input is filtered so when hex input is set only hex characters will be allowed. ;; If a disallowed character is pressed, a bell sound will be sent to console. ;; The filter is active for all but 1 input modes which is ASCII text where all characters are allowed. ;; READ_LINE recognises BS and CR and CTRL-X. ;; BS - deletes the previous character ;; CTRL-X - deletes all characters ;; CR - subroutine done ;; Preparation: ;; a: high byte of input address ;; y: low byte of input address ;; x: maximum length of input line ;; control_flags: 00, hex input ;; 01, decimal input ;; 10, binary TODO ;; 11, ASCII text ;; Effect on registers: ;; a - used ;; x - will hold number of characters entered at exit ;; y - used ;; ;; Example: Read four hex characters from terminal and place them in in_buffer. ;; rmb 0,control_flags ; can be replaced with lda #0 ;; rmb 1,control_flags ; and sta control_flags ;; lda #>in_buffer ;; ldy #<in_buffer ;; ldx #4 ;; jsr read_line ;; ;; Example: Read four decimal characters from terminal and place them in in_buffer. ;; smb 0,control_flags ; can be replaced with lda #1 ;; rmb 1,control_flags ; and sta control_flags ;; lda #>in_buffer ;; ldy #<in_buffer ;; ldx #4 ;; jsr read_line ;;; read_line: .proc sta buffer_address_high ;Save high byte of input buffer address sty buffer_address_low ;Save low byte of input buffer address stx buffer_length ;Save maximum length init: stz buffer_index ;Initialise buffer index to zero read_loop: jsr read_character ;Read character from terminal (no echo, converted to uppercase) ; sta temp1 ; jsr hex_byte cmp #a_cr ;Is character CR beq exit_read_line ;Exit if it is cmp #a_bs ;Is character BS bne l1 ;No, branch jsr backspace ;Yes remove character from buffer and send destuctive backspace to terminal bra read_loop l1: cmp #$5f bne iscancel jsr backspace bra read_loop iscancel: cmp #a_can ;Cancel character(s) received (aka CTRL-X) bne l2 ;If not CTRL-X, branch l3: jsr backspace ;Remove character from buffer and send BS to terminal lda buffer_index ;Is buffer empty bne l3 ;No, continue deleting bra read_loop ;Read next character ; Not a special character ; Check if buffer full ; If not, store character and echo l2: .if emulator==true tax lda control_flags bit #1 bne check_buffer ;Bit 1 is set which means any character is allowed, so try to store it bit #0 bne decimal_input ;Bit 0 is set which means decimal input txa .else bbs 1,control_flags,check_buffer bbs 0,control_flags,decimal_input .fi ; Hexdecimal input cmp #'A' ;Else hex input bcc decimal_input ;Branch if character is < 'A' (check 0-9) cmp #'F'+1 bcc check_buffer ;Branch if character is < 'F'+1 decimal_input: .if emulator==true txa .fi cmp #'0' bcc ring_bell ;Branch if character is < '0' cmp #'9'+1 bcs ring_bell ;Branch if character is >= '9'+1 check_buffer: .if emulator==true txa .fi ldy buffer_index ;Is buffer cpy buffer_length ;full bcc store_character ;Branch if room in buffer ring_bell: jsr bell ;Ring the bell, buffer is full bra read_loop ;Continue store_character: sta (buffer_address_low),y ;Store the character jsr chout ;Send character to terminal inc buffer_index bra read_loop ;Read next character exit_read_line: ldx buffer_index ;Exit with X containing amount of characters read rts .pend ;;; ;; BACKSPACE subroutine: Send BS, SPC, BS to terminal and decrement the readline input buffer index. ;; NOTE: This subroutine should only be used by read_line as the buffer is private ;; to read_line. ;; ;; BS - deletes the previous character ;; Preparation: ;; none ;; ;; Effect on registers: ;; a - entry value ;; x - entry value ;; y - entry value ;; ;; Example: ;; jsr backspace ;;; backspace: .proc pha lda buffer_index ;Check for empty buffer beq sound_bell ;If no characters in buffer, branch dec buffer_index ;Decrement the buffer index #print_text destructive_backspace bra exit sound_bell: jsr bell exit: pla rts .pend ;;; ;; READ_CHARACTER subroutine: Read a character from terminal and convert it to uppercase. ;; ;; Preparation: ;; none ;; ;; Effect on registers: ;; a - character in uppercase ;; x - entry value ;; y - entry value ;; ;; Example: ;; jsr read_character ;;; read_character: .proc jsr chin and #extended_ascii_mask ;Remove all ASCII codes above $7f cmp #'a' ;Is character less 'a' bcc exit ;branch if yes, ie number, symbol, uppercase or control character sbc #$20 ;Otherwise substract $20 to convert character to uppercase exit: rts .pend ;;; ;; DEC_INDEX subroutine: Decrement 16 bit variable index_low, index_high ;; Preparation: ;; none ;; ;; Effect on registers: ;; a - used ;; x - entry value ;; y - entry value ;; ;; Example: ;; jsr dec_index ;;; dec_index: .proc lda index_low ;Is index_low being decremented from $00 to $ff? bne done ;No, branch dec index_high ; Yes, decrement high done: dec index_low ;Decrement low rts .pend ;;; ;; INC_INDEX subroutine: Increment 16 bit variable index_low, index_high. ;; Preparation: ;; none ;; ;; Effect on registers: ;; a - entry value ;; x - entry value ;; y - entry value ;; ;; Example: ;; jsr inc_index ;;; inc_index: .proc inc index_low ;Increment low bne done ;if no wrap-around from $ff to $00 take branch inc index_high ; yes, wrap-around so increment high done: rts .pend ;;; ;; SPACEX subroutine: Send X space characters to terminal. ;;; spacex: .proc jsr space dex bne spacex rts .pend ;;; ;; SPACE4 subroutine: Send four space characters to terminal. ;;; space4: .proc jsr space2 .pend ;;; ;; SPACE2 subroutine: Send two space characters to terminal. ;;; space2: .proc jsr space .pend ;;; ;; SPACE subroutine: Send a space character to terminal. ;;; space: .proc pha lda #' ' jsr chout pla rts .pend ;;; ;; COLON subroutine: Send colon sign to terminal. ;; Preparation: ;; none ;; ;; Effect on registers: ;; a - entry value ;; x - entry value ;; y - entry value ;; ;; Example: ;; jsr crout ;;; colon: .proc pha lda #':' bra crout.sendit .pend ;;; ;; DOLLAR subroutine: Send dollar sign to terminal. ;; Preparation: ;; none ;; ;; Effect on registers: ;; a - entry value ;; x - entry value ;; y - entry value ;; ;; Example: ;; jsr crout ;;; dollar: .proc pha lda #'$' bra crout.sendit .pend ;;; ;; CR2 subroutine: Send CR/LF twice to terminal. ;; Preparation: ;; none ;; ;; Effect on registers: ;; a - entry value ;; x - entry value ;; y - entry value ;; ;; Example: ;; jsr cr2 ;;; cr2: .proc jsr crout .pend ;;; ;; CROUT subroutine: Send CR/LF to terminal. ;; Preparation: ;; none ;; ;; Effect on registers: ;; a - entry value ;; x - entry value ;; y - entry value ;; ;; Example: ;; jsr crout ;;; crout: .proc pha lda #a_cr jsr chout lda #a_lf sendit: jsr chout pla rts .pend ;;; ;; PROUT subroutine: Send a zero terminated string to terminal. ;; Preparation: ;; index_low low byte address to string ;; index_high high byte address to string ;; ;; Effect on registers: ;; a - entry value ;; x - entry value ;; y - entry value ;; ;; Example: ;; text .null "hello world" ;; lda #<text ;; sta index_low ;; lda #>text ;; sta index_high ;; jsr prout ;;; prout: .proc pha ;Preserve A l1: lda (index_low) ;Get character beq exit ;If eq zero, branch jsr chout ;Send character to termnial jsr inc_index ;Next character bra l1 ;Loop back exit: pla ;Restore A rts .pend ;;; ;; HEX_ADDRESS subroutine: Send an ASCII hex address to terminal. ;; Preparation: ;; address_low: low byte to send to terminal ;; address_high: high byte to send to terminal ;; Effect on registers: ;; a - entry value ;; x - entry value ;; y - entry value ;; ;; Example: ;; lda #$fc ;; sta address_low ;; lda #$ab ;; sta address_high ;; jsr hex_address ;; ;; Terminal will show: ;; ABFC ;;; hex_address: .proc pha phx phy jsr hex_mode jsr clear_number_buffer lda address_low sta number_buffer lda address_high sta number_buffer+1 jsr binary_to_ascii ldx #4 jsr leading_zeroes jsr prout ply plx pla rts .pend ;;; ;; HEX_BYTE subroutine: Send an ASCII hex byte to terminal. ;; Preparation: ;; temp: byte to send to terminal ;; ;; Effect on registers: ;; a - entry value ;; x - entry value ;; y - entry value ;; ;; Example: ;; lda #12 ;; sta temp1 ;; jsr hex_byte ;; ;; Terminal will show: ;; 0C ;;; hex_byte: .proc pha phy phx jsr hex_mode jsr clear_number_buffer lda temp1 sta number_buffer jsr binary_to_ascii jsr prout ;send hex character(s) to terminal plx ply pla rts .pend ;;; ;; HEX_MODE subroutine: Set control_flags to hex conversion. ;; Preparation: ;; none ;; ;; Effect on registers: ;; a - entry value ;; x - entry value ;; y - entry value ;; ;; Example: ;; jsr hex_mode ;;; hex_mode: .proc rmb 0,control_flags rmb 1,control_flags rts .pend ;;; ;; LEADING_ZEROES subroutine: Send ASCII '0' to terminal. ;; Preparation: ;; x - maximum number of zeroes to print ;; a - number of characters to print ;; ;; Effect on registers: ;; a - entry value ;; x - entry value ;; y - entry value ;; ;; Example: ;; ldx #2 ;; jsr leading_zeroes ;;; leading_zeroes: .proc pha sta temp2 ;Store number of characters to print txa ;Transfer maximum number of leading zeroes to A sec sbc temp2 ;Maximum number of zeroes substracted with number of characters to print (ie X - A) tax ;Number of leading zeroes in X beq exit ;No leading zeroes needed lda #'0' l1: jsr chout dex bne l1 exit: pla rts .pend ;;; ;; CLEAR_NUMBER_BUFFER subroutine: Clear the number buffer. ;; Preparation: ;; none ;; ;; Effect on registers: ;; a - entry value ;; x - entry value ;; y - entry value ;; ;; Example: ;; jsr clear_number_buffer ;;; clear_number_buffer: .proc phx ldx #3 l1: stz number_buffer,x dex bpl l1 plx rts .pend ;;; ;; BELL subroutine: Send a bell sound to terminal. ;; Preparation: ;; none ;; ;; Effect on registers: ;; a - used ;; x - entry value ;; y - entry value ;; ;; Example: ;; jsr bell ;;; bell: .proc lda #a_bel bra chout .pend ;;; ;; chin_no_wait subroutine: Get character from buffer. If no character is available ;; carry is cleared, otherwise set. Returns character in A register. chin_no_wait: .proc lda $f004 rts .pend ;;; CHIN subroutine: Wait for a character in input buffer, return character in A register. ;;; receive is interrupt driven and buffered with a size of 128 bytes. chin: .proc lda $f004 ; py65mon get char beq chin ; If zero wait for characters rts .pend ;;; CHOUT subroutine: Place register A in output buffer, register A is preserved. ;;; transmit is interrupt driven and buffered with a size of 128 bytes chout: .proc sta $f001 ; py65mon put char rts .pend nmi: rti ;;; ;; coldstart - initialises all hardware ;; power up and reset procedure. ;;; coldstart: .block sei ;Turn off interrupts cld ;Make sure MPU is in binary mode ldx #0 l1: stz 0,x ;zero ZP dex bne l1 dex ;effectively ldx #$ff txs ;Initialise stack register ldx #n_soft_vectors ;Initialise IRQ ISR soft vector table l2: lda initial_soft_vectors-1,x sta soft_vector_table-1,x dex bne l2 ; jsr acia_init ;Deprecated (ACIA was a CDP/Rockwell 65C51 at 4 MHz) ; jsr duart_init ;Initialise 28L92 (DUART at 4 MHz initially) ; jsr rtc_init ;Initialise real time clock ; jsr via_init ;No VIA on Pluto v2 (well, right now 24/12/2018 one is connected to the expansion bus) ; cli ;;; ;; Initialise termnial ;;; jsr bell lda #<clear_screen sta index_low lda #>clear_screen sta index_high jsr prout lda #<welcome sta index_low lda #>welcome sta index_high jsr prout ;;; ;; Initialise monitor (cold start of monitor). ;;; jsr monitor_initialiser ;;; ;; Monitor main loop ;;; jmp monitor_main_loop .bend ;;; ;; IRQ interrupt service routine ;;; irq: .block pha phx phy tsx ;Get the stack pointer lda stack_page+4,x ;MPU status register and #brk_irq_mask ;Has brk instruction triggered IRQ bne do_break ;Yes, branch jmp (rtc_soft_vector) ; no, jump to rtc ISR routine do_break: jmp (brk_soft_vector) ;Handle brk instruction .bend irq_end: .block ply plx pla rti .bend brk_irq: .block ply plx pla sta accumulator stx x_register sty y_register pla ;Get MPU status register sta mpu_status_register tsx stx stack_pointer plx ;Pull low byte of return address stx pc_low stx index_low ;For disassemble line plx stx pc_high stx index_high ;For disassemble line ; ; The following 3 subroutines are contained in the base Monitor and S/O/S code ; - if replaced with new code, either replace or remove these routines ; ;jsr decindex ;decrement index to show brk flag byte in register display ;jsr prstat1 ;display contents of all preset/result memory locations ;jsr disline ;disassemble then display instruction at address pointed to by index lda #0 ;clear all processor status flags pha plp stz in_buffer_counter stz in_buffer_tail stz in_buffer_head jmp (monitor_soft_vector) .bend rtc_irq: .block ; jmp (acia_soft_vector) ;Jump to next ISR ;; rtc irq doesn't do anything at the moment so ;; jump directly to duart ISR. jmp (duart_soft_vector) ;Jump to DUART ISR .bend * = $ff00 ;;; ;; BIOS jump table. ;; This table is the official API of the BIOS. Ideally no other routines should be used. ;;; b_input_hex: jmp input_hex ;Binary number in number_buffer b_input_dec: jmp input_dec ;Binary number in number_buffer b_read_char: jmp read_character ;Read character and convert to uppercase. b_read_line: jmp read_line ;Read .X number of characters b_chin_no_wait: jmp chin_no_wait ;Read character but don't wait for input. Used by XMODEM b_bin_to_asc: jmp binary_to_ascii ;Convert a binary to ASCII b_dollar: jmp dollar ;Print '$'. b_colon: jmp colon ;Print ':' b_chout: jmp chout ;Send content .A to console b_chin: jmp chin ;Read datum from console. Value will be in .A. b_crout: jmp crout ;Send CR/LF to console b_cr2: jmp cr2 ;Send two CR/LF to console b_prout: jmp prout ;Send a zero terminated string to console b_bell: jmp bell ;Send BELL to console b_space: jmp space ;Send space character to console b_space2: jmp space2 ;Send two space character to console b_space4: jmp space4 ;Send four character to console b_spacex: jmp spacex ;Send .X space character to console b_hex_byte: jmp hex_byte ;Print a hex byte with leading zeroes. Byte should be stored in temp1. b_hex_address: jmp hex_address ;Print a hex address with leading zeroes. Address should be stored in address_low and address_high. * = $fffa .word nmi ;NMI .word coldstart ;RESET .word irq ;IRQ
; A288994: a(n) = n*(n+3) when n is congruent to 0 or 3 (mod 4), and n*(n+3)/2 otherwise. ; 0,2,5,18,28,20,27,70,88,54,65,154,180,104,119,270,304,170,189,418,460,252,275,598,648,350,377,810,868,464,495,1054,1120,594,629,1330,1404,740,779,1638,1720,902,945,1978,2068,1080,1127,2350,2448,1274,1325,2754,2860,1484,1539,3190,3304,1710,1769,3658,3780,1952,2015,4158,4288,2210,2277,4690,4828,2484,2555,5254,5400,2774,2849,5850,6004,3080,3159,6478,6640,3402,3485,7138,7308,3740,3827,7830,8008,4094,4185,8554,8740,4464,4559,9310,9504,4850,4949,10098 mov $1,$0 add $1,3 mul $0,$1 div $1,2 gcd $1,2 div $0,$1
;----------------------------------------------------------- ; src/prime.asm ; Usage: prime <n> ; Generates the <n>th prime number and all previous ; prime numbers ; TODO: Create an output buffer %include "lib.inc" %include "io.inc" global _start default rel section .data begin_text: db "Generating ", 0 end_text: db " prime(s)", 0 usage_text: db "Usage: prime <n>", 0 section .text ;---------------------- ; bool is_prime(i64 num) ; using 6k+/-1 method is_prime: push r8 push r9 ; if (num <= 3 && num != 1) return true cmp rdi, 3 ; all numbers less than 3 (except one) are prime jg .gt3 cmp rdi, 1 ; one is not a prime number je .not_prime jmp .is_a_prime .gt3: ; num/2 xor rdx, rdx mov rax, rdi mov rsi, 2 div rsi cmp rdx, 0 ; rdx contains the remainder jz .not_prime ; num/3 xor rdx, rdx mov rax, rdi mov rsi, 3 div rsi cmp rdx, 0 ; rdx contains the remainder jz .not_prime mov r8, 5 .loop: ; r8 * r8 mov rax, r8 mul r8 cmp rax, rdi jge .is_a_prime xor rdx, rdx mov rax, rdi div r8 cmp rdx, 0 jz .not_prime xor rdx, rdx mov r9, r8 add r9, 2 mov rax, rdi div r9 cmp rdx, 0 jz .not_prime add r8, 6 jmp .loop .is_a_prime: xor eax, eax pop r9 pop r8 ret .not_prime: mov rax, 1 pop r9 pop r8 ret _start: ; if rcx != 2 { usage() } pop rcx cmp rcx, 2 jne .usage pop rdx ; discard program name ; max_primes (r8) = argv[1] pop rdi call atoi cmp rax, 0 ; don't generate 0 primes jz .usage mov r8, rax ; printf("Generating %d primes", atoi(argv[1])) lea rdi, [begin_text] call print mov rdi, r8 ; primes to generate call iprint lea rdi, [end_text] call println ; candidate xor r9, r9 ; primes_found xor r10, r10 .loop: ; next prime candidate inc r9 ; if(is_prime(candidate)) ... mov rdi, r9 call is_prime cmp rax, 0 jnz .loop ; primes_found += 1 inc r10 ; if(primes_found > max_primes) cmp r10, r8 jg .exit ; else mov rdi, r9 call iprintln jmp .loop .usage: lea rdi, [usage_text] call println mov edi, 1 ; unsuccessful call exit .exit: xor edi, edi call exit
; S2E Selective Symbolic Execution Platform ; ; Copyright (c) 2013 Dependable Systems Laboratory, EPFL ; ; Permission is hereby granted, free of charge, to any person obtaining a copy ; of this software and associated documentation files (the "Software"), to deal ; in the Software without restriction, including without limitation the rights ; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ; copies of the Software, and to permit persons to whom the Software is ; furnished to do so, subject to the following conditions: ; ; The above copyright notice and this permission notice shall be included in all ; copies or substantial portions of the Software. ; ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ; SOFTWARE. .386 ; driver's code start .model flat, stdcall .code public S2EGetVersion S2EGetVersion proc near xor eax, eax db 0fh, 3fh db 00h, 00h, 00h, 00h db 00h, 00h, 00h, 00h ret S2EGetVersion endp .code public S2EGetPathId S2EGetPathId proc near xor eax, eax db 0fh, 3fh db 00h, 05h, 00h, 00h db 00h, 00h, 00h, 00h ret S2EGetPathId endp public S2EGetPathCount S2EGetPathCount proc near xor eax, eax db 0fh, 3fh db 00h, 30h, 00h, 00h db 00h, 00h, 00h, 00h ret S2EGetPathCount endp public S2EIsSymbolic S2EIsSymbolic proc near _Buffer: near ptr dword, _Size: dword mov ecx, _Buffer mov eax, _Size db 0fh, 3fh db 00h, 04h, 00h, 00h db 00h, 00h, 00h, 00h ret 08h S2EIsSymbolic endp public S2EGetExample S2EGetExample proc near _Buffer: near ptr dword, _Size: dword mov eax, _Buffer mov edx, _Size db 0fh, 3fh db 00h, 21h, 00h, 00h db 00h, 00h, 00h, 00h ret 08h S2EGetExample endp public S2EGetRange S2EGetRange proc near _Expr: dword, _Low: near ptr dword, _High: near ptr dword mov eax, _Expr mov ecx, _Low mov edx, _High db 0fh, 3fh db 00h, 34h, 00h, 00h db 00h, 00h, 00h, 00h ret 0ch S2EGetRange endp public S2EGetConstraintCount S2EGetConstraintCount proc near _Expr: dword mov eax, _Expr db 0fh, 3fh db 00h, 35h, 00h, 00h db 00h, 00h, 00h, 00h ret 04h S2EGetConstraintCount endp public S2EConcretize S2EConcretize proc near _Buffer: near ptr dword, _Size: dword mov eax, _Buffer mov edx, _Size db 0fh, 3fh db 00h, 20h, 00h, 00h db 00h, 00h, 00h, 00h ret 08h S2EConcretize endp public S2EMakeSymbolicRaw S2EMakeSymbolicRaw proc near uses ebx, _Buffer: near ptr dword, _Size: dword, _Name: near ptr dword push ebx mov eax, _Buffer mov ebx, _Size mov ecx, _Name db 0fh, 3fh db 00h, 03h, 00h, 00h db 00h, 00h, 00h, 00h pop ebx ret 0ch S2EMakeSymbolicRaw endp public S2EHexDump S2EHexDump proc near uses ebx, _Name: near ptr dword, _Buffer: near ptr dword, _Size: dword push ebx mov eax, _Buffer mov ebx, _Size mov ecx, _Name db 0fh, 3fh db 00h, 36h, 00h, 00h db 00h, 00h, 00h, 00h pop ebx ret 0ch S2EHexDump endp public S2EBeginAtomic S2EBeginAtomic proc near nop db 0fh, 3fh db 00h, 12h, 00h, 00h db 00h, 00h, 00h, 00h ret S2EBeginAtomic endp public S2EEndAtomic S2EEndAtomic proc near nop db 0fh, 3fh db 00h, 13h, 00h, 00h db 00h, 00h, 00h, 00h ret S2EEndAtomic endp public S2EAssume S2EAssume proc near, _Expression: dword mov eax, _Expression db 0fh, 3fh db 00h, 0ch, 00h, 00h db 00h, 00h, 00h, 00h ret 4h S2EAssume endp public S2EMessageRaw S2EMessageRaw proc near, _Message: near ptr dword mov eax, _Message db 0fh, 3fh db 00h, 10h, 00h, 00h db 00h, 00h, 00h, 00h ret 4h S2EMessageRaw endp ;Transmits a buffer of dataSize length to the plugin named in pluginName. ;eax contains the failure code upon return, 0 for success. public S2EInvokePluginRaw S2EInvokePluginRaw proc near, _PluginName: near ptr dword, _UserData: near ptr dword, _DataSize: dword mov eax, _PluginName mov ecx, _UserData mov edx, _DataSize db 0fh, 3fh db 00h, 0bh, 00h, 00h db 00h, 00h, 00h, 00h ret 0ch S2EInvokePluginRaw endp ;Transmits a buffer of dataSize length to the plugin named in pluginName. ;Sets all registers to a concrete value to ensure concrete mode ;eax contains the failure code upon return, 0 for success. public S2EInvokePluginConcreteModeRaw S2EInvokePluginConcreteModeRaw proc near, _PluginName: near ptr dword, _UserData: near ptr dword, _DataSize: dword mov eax, _PluginName mov ecx, _UserData mov edx, _DataSize push ebx push ebp push esi push edi xor ebx, ebx xor ebp, ebp xor esi, esi xor edi, edi ;Clear temp flags db 0fh, 3fh db 00h, 53h, 00h, 00h db 00h, 00h, 00h, 00h jmp __sipcmr ;Ensure switch to concrete mode __sipcmr: db 0fh, 3fh db 00h, 0bh, 00h, 00h db 00h, 00h, 00h, 00h pop edi pop esi pop ebp pop ebx ret 0ch S2EInvokePluginConcreteModeRaw endp ; Add a constraint of the form var == e1 || var == e2 || ... ; The first parameter contains the variable ; The second parameter has the number of passed expressions public S2EAssumeDisjunction S2EAssumeDisjunction proc c, _Variable: dword, _Count: dword, _Expressions: vararg mov eax, _Variable ;Dummy moves to supress unused variable mov eax, _Count mov eax, _Expressions db 0fh, 3fh db 00h, 0dh, 00h, 00h db 00h, 00h, 00h, 00h ret S2EAssumeDisjunction endp public S2EKillState S2EKillState proc near, _Status: near ptr dword, _Message: near ptr dword push ebx mov eax, _Status mov ebx, _Message db 0fh, 3fh db 00h, 06h, 00h, 00h db 00h, 00h, 00h, 00h pop ebx ret 08h S2EKillState endp public S2EPrintExpression S2EPrintExpression proc near, _Expression: near ptr dword, _Name: near ptr dword mov eax, _Expression mov ecx, _Name db 0fh, 3fh db 00h, 07h, 00h, 00h db 00h, 00h, 00h, 00h ret 08h S2EPrintExpression endp public S2EWriteMemory S2EWriteMemory proc near, _Dest: near ptr dword, _Source: near ptr dword, _Size: dword push esi push edi mov esi, _Source mov edi, _Dest mov ecx, _Size db 0fh, 3fh db 00h, 33h, 00h, 00h db 00h, 00h, 00h, 00h pop edi pop esi ret 0ch S2EWriteMemory endp __MergingSearcher db "MergingSearcher", 0 public S2EMergePointCallback S2EMergePointCallback proc near pushfd pusha sub esp, 8 ;Setup the start variable (set to 0) xor eax, eax mov [esp], eax mov [esp+4], eax lea eax, [esp] ;Invoke the merging searcher push 8 ; data size push eax; data pointer push dword ptr __MergingSearcher call S2EInvokePluginConcreteModeRaw call S2EEnableAllApicInterrupts ;Cleanup the mess and return add esp, 8 popa popfd ret S2EMergePointCallback endp public S2EDisableAllApicInterrupts S2EDisableAllApicInterrupts proc near xor eax, eax db 0fh, 3fh db 00h, 51h, 01h, 00h db 00h, 00h, 00h, 00h ret S2EDisableAllApicInterrupts endp public S2EEnableAllApicInterrupts S2EEnableAllApicInterrupts proc near xor eax, eax db 0fh, 3fh db 00h, 51h, 00h, 00h db 00h, 00h, 00h, 00h ret S2EEnableAllApicInterrupts endp public S2ESetCpuLogLevel S2ESetCpuLogLevel proc near _Level: dword mov eax, _Level db 0fh, 3fh db 00h, 56h, 00h, 00h db 00h, 00h, 00h, 00h ret 08h S2ESetCpuLogLevel endp end
; A343176: a(0)=3; for n > 0, a(n) = 2^(2*n) + 3*2^(n-1) + 1. ; 3,8,23,77,281,1073,4193,16577,65921,262913,1050113,4197377,16783361,67121153,268460033,1073790977,4295065601,17180065793,68719869953,274878693377,1099513200641,4398049656833,17592192335873,70368756760577,281475001876481,1125899957174273,4503599728033793 add $0,1 seq $0,257273 ; a(n) = 2^(n-1)*(2^n+3). div $0,2 add $0,1
/** * Copyright (C) 2020-present MongoDB, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the Server Side Public License, version 1, * as published by MongoDB, Inc. * * This program 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 * Server Side Public License for more details. * * You should have received a copy of the Server Side Public License * along with this program. If not, see * <http://www.mongodb.com/licensing/server-side-public-license>. * * As a special exception, the copyright holders give permission to link the * code of portions of this program with the OpenSSL library under certain * conditions as described in each individual source file and distribute * linked combinations including the program with the OpenSSL library. You * must comply with the Server Side Public License in all respects for * all of the code used other than as permitted herein. If you modify file(s) * with this exception, you may extend this exception to your version of the * file(s), but you are not obligated to do so. If you do not wish to do so, * delete this exception statement from your version. If you delete this * exception statement from all source files in the program, then also delete * it in the license file. */ #include "mongo/platform/basic.h" #include "mongo/db/pipeline/aggregation_context_fixture.h" #include "mongo/db/pipeline/document_source_internal_unpack_bucket.h" #include "mongo/db/pipeline/document_source_match.h" #include "mongo/db/pipeline/pipeline.h" #include "mongo/db/query/util/make_data_structure.h" namespace mongo { namespace { using InternalUnpackBucketPredicateMappingOptimizationTest = AggregationContextFixture; TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsGTPredicatesOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {a: {$gt: 1}}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$or: [ {'control.max.a': {$_internalExprGt: 1}}," "{$expr: {$ne: [ {$type: [ \"$control.min.a\" ]}," "{$type: [ \"$control.max.a\" ]} ]}} ]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsGTEPredicatesOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {a: {$gte: 1}}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$or: [ {'control.max.a': {$_internalExprGte: 1}}," "{$expr: {$ne: [ {$type: [ \"$control.min.a\" ]}," "{$type: [ \"$control.max.a\" ]} ]}} ]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsLTPredicatesOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {a: {$lt: 1}}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$or: [ {'control.min.a': {$_internalExprLt: 1}}," "{$expr: {$ne: [ {$type: [ \"$control.min.a\" ]}," "{$type: [ \"$control.max.a\" ]} ]}} ]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsLTEPredicatesOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {a: {$lte: 1}}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$or: [ {'control.min.a': {$_internalExprLte: 1}}," "{$expr: {$ne: [ {$type: [ \"$control.min.a\" ]}," "{$type: [ \"$control.max.a\" ]} ]}} ]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsEQPredicatesOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {a: {$eq: 1}}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$or: [ {$and:[{'control.min.a': {$_internalExprLte: 1}}," "{'control.max.a': {$_internalExprGte: 1}}]}," "{$expr: {$ne: [ {$type: [ \"$control.min.a\" ]}," "{$type: [ \"$control.max.a\" ]} ]}} ]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsINPredicatesOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {a: {$in: [1, 2]}}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT(predicate); auto expected = fromjson( "{$or: [" " {$or: [" " {$and: [" " {'control.min.a': {$_internalExprLte: 1}}," " {'control.max.a': {$_internalExprGte: 1}}" " ]}," " {$expr: {$ne: [" " {$type: [ \"$control.min.a\" ]}," " {$type: [ \"$control.max.a\" ]}" " ]}}" " ]}," " {$or: [" " {$and: [" " {'control.min.a': {$_internalExprLte: 2}}," " {'control.max.a': {$_internalExprGte: 2}}" " ]}," " {$expr: {$ne: [" " {$type: [ \"$control.min.a\" ]}," " {$type: [ \"$control.max.a\" ]}" " ]}}" " ]}" "]}"); ASSERT_BSONOBJ_EQ(predicate->serialize(true), expected); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsAggGTPredicatesOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {$expr: {$gt: [\"$a\", 1]}}}")), getExpCtx()); auto& container = pipeline->getSources(); // $_internalUnpackBucket's doOptimizeAt optimizes the end of the pipeline before attempting to // perform predicate mapping. We will mimic this behavior here to take advantage of the // existing $expr rewrite optimizations. Pipeline::optimizeEndOfPipeline(container.begin(), &container); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$or: [ {'control.max.a': {$_internalExprGt: 1}}," "{$expr: {$ne: [ {$type: [ \"$control.min.a\" ]}," "{$type: [ \"$control.max.a\" ]} ]}} ]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsAggGTEPredicatesOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {$expr: {$gte: [\"$a\", 1]}}}")), getExpCtx()); auto& container = pipeline->getSources(); // $_internalUnpackBucket's doOptimizeAt optimizes the end of the pipeline before attempting to // perform predicate mapping. We will mimic this behavior here to take advantage of the // existing $expr rewrite optimizations. Pipeline::optimizeEndOfPipeline(container.begin(), &container); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$or: [ {'control.max.a': {$_internalExprGte: 1}}," "{$expr: {$ne: [ {$type: [ \"$control.min.a\" ]}," "{$type: [ \"$control.max.a\" ]} ]}} ]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsAggLTPredicatesOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {$expr: {$lt: [\"$a\", 1]}}}")), getExpCtx()); auto& container = pipeline->getSources(); // $_internalUnpackBucket's doOptimizeAt optimizes the end of the pipeline before attempting to // perform predicate mapping. We will mimic this behavior here to take advantage of the // existing $expr rewrite optimizations. Pipeline::optimizeEndOfPipeline(container.begin(), &container); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$or: [ {'control.min.a': {$_internalExprLt: 1}}," "{$expr: {$ne: [ {$type: [ \"$control.min.a\" ]}," "{$type: [ \"$control.max.a\" ]} ]}} ]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsAggLTEPredicatesOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {$expr: {$lte: [\"$a\", 1]}}}")), getExpCtx()); auto& container = pipeline->getSources(); // $_internalUnpackBucket's doOptimizeAt optimizes the end of the pipeline before attempting to // perform predicate mapping. We will mimic this behavior here to take advantage of the // existing $expr rewrite optimizations. Pipeline::optimizeEndOfPipeline(container.begin(), &container); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$or: [ {'control.min.a': {$_internalExprLte: 1}}," "{$expr: {$ne: [ {$type: [ \"$control.min.a\" ]}," "{$type: [ \"$control.max.a\" ]} ]}} ]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsAggEQPredicatesOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {$expr: {$eq: [\"$a\", 1]}}}")), getExpCtx()); auto& container = pipeline->getSources(); // $_internalUnpackBucket's doOptimizeAt optimizes the end of the pipeline before attempting to // perform predicate mapping. We will mimic this behavior here to take advantage of the // existing $expr rewrite optimizations. Pipeline::optimizeEndOfPipeline(container.begin(), &container); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$or: [ {$and:[{'control.min.a': {$_internalExprLte: 1}}," "{'control.max.a': {$_internalExprGte: 1}}]}," "{$expr: {$ne: [ {$type: [ \"$control.min.a\" ]}," "{$type: [ \"$control.max.a\" ]} ]}} ]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsAndWithPushableChildrenOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {$and: [{b: {$gt: 1}}, {a: {$lt: 5}}]}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$and: [ {$or: [ {'control.max.b': {$_internalExprGt: 1}}," "{$expr: {$ne: [ {$type: [ \"$control.min.b\" ]}," "{$type: [ \"$control.max.b\" ]} ]}} ]}," "{$or: [ {'control.min.a': {$_internalExprLt: 5}}," "{$expr: {$ne: [ {$type: [ \"$control.min.a\" ]}," "{$type: [ \"$control.max.a\" ]} ]}} ]} ]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeDoesNotMapAndWithUnpushableChildrenOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {$and: [{b: {$ne: 1}}, {a: {$ne: 5}}]}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT(predicate == nullptr); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsAndWithPushableAndUnpushableChildrenOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {$and: [{b: {$gt: 1}}, {a: {$ne: 5}}]}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$or: [" " {'control.max.b': {$_internalExprGt: 1}}," " {$expr: {$ne: [" " {$type: [ \"$control.min.b\" ]}," " {$type: [ \"$control.max.b\" ]}" " ]}}" "]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsNestedAndWithPushableChildrenOnControlField) { auto pipeline = Pipeline::parse( makeVector( fromjson("{$_internalUnpackBucket: {exclude: [], timeField: 'time', " "bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {$and: [{b: {$gte: 2}}, {$and: [{b: {$gt: 1}}, {a: {$lt: 5}}]}]}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$and: [ {$or: [ {'control.max.b': {$_internalExprGte: 2}}," "{$expr: {$ne: [ {$type: [ \"$control.min.b\" ]}," "{$type: [ \"$control.max.b\" ]} ]}} ]}," "{$and: [ {$or: [ {'control.max.b': {$_internalExprGt: 1}}," "{$expr: {$ne: [ {$type: [ \"$control.min.b\" ]}," "{$type: [ \"$control.max.b\" ]} ]}} ]}," "{$or: [ {'control.min.a': {$_internalExprLt: 5}}," "{$expr: {$ne: [ {$type: [ \"$control.min.a\" ]}," "{$type: [ \"$control.max.a\" ]} ]}} ]} ]} ]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsOrWithPushableChildrenOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {$or: [{b: {$gt: 1}}, {a: {$lt: 5}}]}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT(predicate); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$or: [" " {$or: [" " {'control.max.b': {$_internalExprGt: 1}}," " {$expr: {$ne: [" " {$type: [ \"$control.min.b\" ]}," " {$type: [ \"$control.max.b\" ]}" " ]}}" " ]}," " {$or: [" " {'control.min.a': {$_internalExprLt: 5}}," " {$expr: {$ne: [" " {$type: [ \"$control.min.a\" ]}," " {$type: [ \"$control.max.a\" ]}" " ]}}" " ]}" "]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeDoesNotMapOrWithUnpushableChildrenOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {$or: [{b: {$ne: 1}}, {a: {$ne: 5}}]}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT(predicate == nullptr); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeDoesNotMapOrWithPushableAndUnpushableChildrenOnControlField) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {$or: [{b: {$gt: 1}}, {a: {$ne: 5}}]}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); // When a predicate can't be pushed down, it's the same as pushing down a trivially-true // predicate. So when any child of an $or can't be pushed down, we could generate something like // {$or: [ ... {$alwaysTrue: {}}, ... ]}, but then we might as well not push down the whole $or. ASSERT(predicate == nullptr); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsNestedOrWithPushableChildrenOnControlField) { auto pipeline = Pipeline::parse( makeVector( fromjson("{$_internalUnpackBucket: {exclude: [], timeField: 'time', " "bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {$or: [{b: {$gte: 2}}, {$or: [{b: {$gt: 1}}, {a: {$lt: 5}}]}]}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$or: [" " {$or: [" " {'control.max.b': {$_internalExprGte: 2}}," " {$expr: {$ne: [" " {$type: [ \"$control.min.b\" ]}," " {$type: [ \"$control.max.b\" ]}" " ]}}" " ]}," " {$or: [" " {$or: [" " {'control.max.b': {$_internalExprGt: 1}}," " {$expr: {$ne: [" " {$type: [ \"$control.min.b\" ]}," " {$type: [ \"$control.max.b\" ]}" " ]}}" " ]}," " {$or: [" " {'control.min.a': {$_internalExprLt: 5}}," " {$expr: {$ne: [" " {$type: [ \"$control.min.a\" ]}," " {$type: [ \"$control.max.a\" ]}" " ]}}" " ]}" " ]}" "]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeFurtherOptimizesNewlyAddedMatchWithSingletonAndNode) { auto unpackBucketObj = fromjson( "{$_internalUnpackBucket: {exclude: [], timeField: 'time', bucketMaxSpanSeconds: 3600}}"); auto matchObj = fromjson("{$match: {$and: [{b: {$gt: 1}}, {a: {$ne: 5}}]}}"); auto pipeline = Pipeline::parse(makeVector(unpackBucketObj, matchObj), getExpCtx()); ASSERT_EQ(pipeline->getSources().size(), 2U); pipeline->optimizePipeline(); ASSERT_EQ(pipeline->getSources().size(), 3U); // To get the optimized $match from the pipeline, we have to serialize with explain. auto stages = pipeline->writeExplainOps(ExplainOptions::Verbosity::kQueryPlanner); ASSERT_EQ(stages.size(), 3U); ASSERT_BSONOBJ_EQ(stages[0].getDocument().toBson(), fromjson("{$match: {$or: [ {'control.max.b': {$_internalExprGt: 1}}," "{$expr: {$ne: [ {$type: [ \"$control.min.b\" ]}," "{$type: [ \"$control.max.b\" ]} ]}} ]}}")); ASSERT_BSONOBJ_EQ(stages[1].getDocument().toBson(), unpackBucketObj); ASSERT_BSONOBJ_EQ(stages[2].getDocument().toBson(), fromjson("{$match: {$and: [{b: {$gt: 1}}, {a: {$not: {$eq: 5}}}]}}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeFurtherOptimizesNewlyAddedMatchWithNestedAndNodes) { auto unpackBucketObj = fromjson( "{$_internalUnpackBucket: {exclude: [], timeField: 'time', bucketMaxSpanSeconds: 3600}}"); auto matchObj = fromjson("{$match: {$and: [{b: {$gte: 2}}, {$and: [{c: {$gt: 1}}, {a: {$lt: 5}}]}]}}"); auto pipeline = Pipeline::parse(makeVector(unpackBucketObj, matchObj), getExpCtx()); ASSERT_EQ(pipeline->getSources().size(), 2U); pipeline->optimizePipeline(); ASSERT_EQ(pipeline->getSources().size(), 3U); auto stages = pipeline->serializeToBson(); ASSERT_EQ(stages.size(), 3U); ASSERT_BSONOBJ_EQ( stages[0], fromjson("{$match: {$and: [ {$or: [ {'control.max.b': {$_internalExprGte: 2}}," "{$expr: {$ne: [ {$type: [ \"$control.min.b\" ]}," "{$type: [ \"$control.max.b\" ]} ]}} ]}," "{$or: [ {'control.max.c': {$_internalExprGt: 1}}," "{$expr: {$ne: [ {$type: [ \"$control.min.c\" ]}," "{$type: [ \"$control.max.c\" ]} ]}} ]}," "{$or: [ {'control.min.a': {$_internalExprLt: 5}}," "{$expr: {$ne: [ {$type: [ \"$control.min.a\" ]}," "{$type: [ \"$control.max.a\" ]} ]}} ]} ]}}")); ASSERT_BSONOBJ_EQ(stages[1], unpackBucketObj); ASSERT_BSONOBJ_EQ(stages[2], matchObj); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeDoesNotMapPredicatesOnTypeObject) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {a: {$gt: {b: 5}}}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT(predicate == nullptr); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeDoesNotMapPredicatesOnTypeArray) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {a: {$gt: [5]}}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT(predicate == nullptr); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeDoesNotMapPredicatesOnTypeNull) { auto pipeline = Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {a: {$gt: null}}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT(predicate == nullptr); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeDoesNotMapMetaPredicatesOnControlField) { auto pipeline = Pipeline::parse( makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: 'time', metaField: " "'myMeta', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {myMeta: {$gt: 5}}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); // Meta predicates are mapped to the meta field, not the control min/max fields. ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{meta: {$gt: 5}}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeDoesNotMapMetaPredicatesWithNestedFieldsOnControlField) { auto pipeline = Pipeline::parse( makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: 'time', metaField: " "'myMeta', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {'myMeta.foo': {$gt: 5}}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); // Meta predicates are mapped to the meta field, not the control min/max fields. ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{'meta.foo': {$gt: 5}}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeDoesNotMapNestedMetaPredicatesOnControlField) { auto pipeline = Pipeline::parse( makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: 'time', metaField: " "'myMeta', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {$and: [{a: {$gt: 1}}, {myMeta: {$eq: 5}}]}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$and: [" " {$or: [" " {'control.max.a': {$_internalExprGt: 1}}," " {$expr: {$ne: [" " {$type: [ \"$control.min.a\" ]}," " {$type: [ \"$control.max.a\" ]}" " ]}}" " ]}," " {meta: {$eq: 5}}" "]}")); } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsTimePredicatesOnId) { auto date = Date_t::now(); const auto dateMinusBucketSpan = date - Seconds{3600}; const auto datePlusBucketSpan = date + Seconds{3600}; { auto timePred = BSON("$match" << BSON("time" << BSON("$lt" << date))); auto aggTimePred = BSON("$match" << BSON("$expr" << BSON("$lt" << BSON_ARRAY("$time" << date)))); auto pipelines = { Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), timePred), getExpCtx()), Pipeline::parse(makeVector(fromjson("{$_unpackBucket: {timeField: 'time'}}"), timePred), getExpCtx()), Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), aggTimePred), getExpCtx())}; for (auto& pipeline : pipelines) { auto& container = pipeline->getSources(); // $_internalUnpackBucket's doOptimizeAt optimizes the end of the pipeline before // attempting to perform predicate mapping. We will mimic this behavior here to take // advantage of the existing $expr rewrite optimizations. Pipeline::optimizeEndOfPipeline(container.begin(), &container); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); auto andExpr = dynamic_cast<AndMatchExpression*>(predicate.get()); auto children = andExpr->getChildVector(); ASSERT_EQ(children->size(), 3); ASSERT_BSONOBJ_EQ((*children)[0]->serialize(true), BSON("control.min.time" << BSON("$_internalExprLt" << date))); ASSERT_BSONOBJ_EQ( (*children)[1]->serialize(true), BSON("control.max.time" << BSON("$_internalExprLt" << datePlusBucketSpan))); auto idPred = dynamic_cast<ComparisonMatchExpressionBase*>((*children)[2].get()); ASSERT_EQ(idPred->path(), "_id"_sd); ASSERT_EQ(idPred->getData().type(), BSONType::jstOID); // As ObjectId holds time at a second granularity, the rewrite value used for a $lt/$lte // predicate on _id may be rounded up by a second to missing results due to trunacted // milliseconds. Date_t adjustedDate = date; if (adjustedDate.toMillisSinceEpoch() % 1000 != 0) { adjustedDate += Seconds{1}; } OID oid; oid.init(adjustedDate); ASSERT_TRUE(oid.compare(idPred->getData().OID()) == 0); } } { auto timePred = BSON("$match" << BSON("time" << BSON("$lte" << date))); auto aggTimePred = BSON("$match" << BSON("$expr" << BSON("$lte" << BSON_ARRAY("$time" << date)))); auto pipelines = { Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), timePred), getExpCtx()), Pipeline::parse(makeVector(fromjson("{$_unpackBucket: {timeField: 'time'}}"), timePred), getExpCtx()), Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), aggTimePred), getExpCtx())}; for (auto& pipeline : pipelines) { auto& container = pipeline->getSources(); // $_internalUnpackBucket's doOptimizeAt optimizes the end of the pipeline before // attempting to perform predicate mapping. We will mimic this behavior here to take // advantage of the existing $expr rewrite optimizations. Pipeline::optimizeEndOfPipeline(container.begin(), &container); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); auto andExpr = dynamic_cast<AndMatchExpression*>(predicate.get()); auto children = andExpr->getChildVector(); ASSERT_EQ(children->size(), 3); ASSERT_BSONOBJ_EQ((*children)[0]->serialize(true), BSON("control.min.time" << BSON("$_internalExprLte" << date))); ASSERT_BSONOBJ_EQ( (*children)[1]->serialize(true), BSON("control.max.time" << BSON("$_internalExprLte" << datePlusBucketSpan))); auto idPred = dynamic_cast<ComparisonMatchExpressionBase*>((*children)[2].get()); ASSERT_EQ(idPred->path(), "_id"_sd); ASSERT_EQ(idPred->getData().type(), BSONType::jstOID); OID oid; oid.init(date); ASSERT_TRUE(oid.compare(idPred->getData().OID()) < 0); } } { auto timePred = BSON("$match" << BSON("time" << BSON("$eq" << date))); auto aggTimePred = BSON("$match" << BSON("$expr" << BSON("$eq" << BSON_ARRAY("$time" << date)))); auto pipelines = { Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), timePred), getExpCtx()), Pipeline::parse(makeVector(fromjson("{$_unpackBucket: {timeField: 'time'}}"), timePred), getExpCtx()), Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), aggTimePred), getExpCtx())}; for (auto& pipeline : pipelines) { auto& container = pipeline->getSources(); // $_internalUnpackBucket's doOptimizeAt optimizes the end of the pipeline before // attempting to perform predicate mapping. We will mimic this behavior here to take // advantage of the existing $expr rewrite optimizations. Pipeline::optimizeEndOfPipeline(container.begin(), &container); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); auto andExpr = dynamic_cast<AndMatchExpression*>(predicate.get()); auto children = andExpr->getChildVector(); ASSERT_EQ(children->size(), 6); ASSERT_BSONOBJ_EQ((*children)[0]->serialize(true), BSON("control.min.time" << BSON("$_internalExprLte" << date))); ASSERT_BSONOBJ_EQ( (*children)[1]->serialize(true), BSON("control.min.time" << BSON("$_internalExprGte" << dateMinusBucketSpan))); ASSERT_BSONOBJ_EQ((*children)[2]->serialize(true), BSON("control.max.time" << BSON("$_internalExprGte" << date))); ASSERT_BSONOBJ_EQ( (*children)[3]->serialize(true), BSON("control.max.time" << BSON("$_internalExprLte" << datePlusBucketSpan))); auto idPred = dynamic_cast<ComparisonMatchExpressionBase*>((*children)[4].get()); ASSERT_EQ(idPred->path(), "_id"_sd); ASSERT_EQ(idPred->getData().type(), BSONType::jstOID); OID oid; oid.init(date); ASSERT_TRUE(oid.compare(idPred->getData().OID()) < 0); idPred = dynamic_cast<ComparisonMatchExpressionBase*>((*children)[5].get()); ASSERT_EQ(idPred->path(), "_id"_sd); ASSERT_EQ(idPred->getData().type(), BSONType::jstOID); ASSERT_TRUE(oid.compare(idPred->getData().OID()) > 0); } } { auto timePred = BSON("$match" << BSON("time" << BSON("$gt" << date))); auto aggTimePred = BSON("$match" << BSON("$expr" << BSON("$gt" << BSON_ARRAY("$time" << date)))); auto pipelines = { Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), timePred), getExpCtx()), Pipeline::parse(makeVector(fromjson("{$_unpackBucket: {timeField: 'time'}}"), timePred), getExpCtx()), Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), aggTimePred), getExpCtx())}; for (auto& pipeline : pipelines) { auto& container = pipeline->getSources(); // $_internalUnpackBucket's doOptimizeAt optimizes the end of the pipeline before // attempting to perform predicate mapping. We will mimic this behavior here to take // advantage of the existing $expr rewrite optimizations. Pipeline::optimizeEndOfPipeline(container.begin(), &container); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); auto andExpr = dynamic_cast<AndMatchExpression*>(predicate.get()); auto children = andExpr->getChildVector(); ASSERT_EQ(children->size(), 3); ASSERT_BSONOBJ_EQ((*children)[0]->serialize(true), BSON("control.max.time" << BSON("$_internalExprGt" << date))); ASSERT_BSONOBJ_EQ( (*children)[1]->serialize(true), BSON("control.min.time" << BSON("$_internalExprGt" << dateMinusBucketSpan))); auto idPred = dynamic_cast<ComparisonMatchExpressionBase*>((*children)[2].get()); ASSERT_EQ(idPred->path(), "_id"_sd); ASSERT_EQ(idPred->getData().type(), BSONType::jstOID); OID oid; oid.init(dateMinusBucketSpan); ASSERT_TRUE(oid.compare(idPred->getData().OID()) < 0); } } { auto timePred = BSON("$match" << BSON("time" << BSON("$gte" << date))); auto aggTimePred = BSON("$match" << BSON("$expr" << BSON("$gte" << BSON_ARRAY("$time" << date)))); auto pipelines = { Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), timePred), getExpCtx()), Pipeline::parse(makeVector(fromjson("{$_unpackBucket: {timeField: 'time'}}"), timePred), getExpCtx()), Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), aggTimePred), getExpCtx())}; for (auto& pipeline : pipelines) { auto& container = pipeline->getSources(); // $_internalUnpackBucket's doOptimizeAt optimizes the end of the pipeline before // attempting to perform predicate mapping. We will mimic this behavior here to take // advantage of the existing $expr rewrite optimizations. Pipeline::optimizeEndOfPipeline(container.begin(), &container); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); auto andExpr = dynamic_cast<AndMatchExpression*>(predicate.get()); auto children = andExpr->getChildVector(); ASSERT_EQ(children->size(), 3); ASSERT_BSONOBJ_EQ((*children)[0]->serialize(true), BSON("control.max.time" << BSON("$_internalExprGte" << date))); ASSERT_BSONOBJ_EQ( (*children)[1]->serialize(true), BSON("control.min.time" << BSON("$_internalExprGte" << dateMinusBucketSpan))); auto idPred = dynamic_cast<ComparisonMatchExpressionBase*>((*children)[2].get()); ASSERT_EQ(idPred->path(), "_id"_sd); ASSERT_EQ(idPred->getData().type(), BSONType::jstOID); OID oid; oid.init(date - Seconds{3600}); ASSERT_TRUE(oid.compare(idPred->getData().OID()) == 0); } } } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsTimePredicatesWithNonDateType) { { auto timePred = BSON("$match" << BSON("time" << BSON("$lt" << 1))); auto pipelines = { Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), timePred), getExpCtx()), Pipeline::parse(makeVector(fromjson("{$_unpackBucket: {timeField: 'time'}}"), timePred), getExpCtx())}; for (auto& pipeline : pipelines) { auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_FALSE(predicate); } } { auto timePred = BSON("$match" << BSON("time" << BSON("$lte" << 1))); auto pipelines = { Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), timePred), getExpCtx()), Pipeline::parse(makeVector(fromjson("{$_unpackBucket: {timeField: 'time'}}"), timePred), getExpCtx())}; for (auto& pipeline : pipelines) { auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_FALSE(predicate); } } { auto timePred = BSON("$match" << BSON("time" << BSON("$eq" << 1))); auto pipelines = { Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), timePred), getExpCtx()), Pipeline::parse(makeVector(fromjson("{$_unpackBucket: {timeField: 'time'}}"), timePred), getExpCtx())}; for (auto& pipeline : pipelines) { auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_FALSE(predicate); } } { auto timePred = BSON("$match" << BSON("time" << BSON("$gt" << 1))); auto pipelines = { Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), timePred), getExpCtx()), Pipeline::parse(makeVector(fromjson("{$_unpackBucket: {timeField: 'time'}}"), timePred), getExpCtx())}; for (auto& pipeline : pipelines) { auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_FALSE(predicate); } } { auto timePred = BSON("$match" << BSON("time" << BSON("$gte" << 1))); auto pipelines = { Pipeline::parse(makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), timePred), getExpCtx()), Pipeline::parse(makeVector(fromjson("{$_unpackBucket: {timeField: 'time'}}"), timePred), getExpCtx())}; for (auto& pipeline : pipelines) { auto& container = pipeline->getSources(); ASSERT_EQ(pipeline->getSources().size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_FALSE(predicate); } } } TEST_F(InternalUnpackBucketPredicateMappingOptimizationTest, OptimizeMapsGeoWithinPredicatesUsingInternalBucketGeoWithin) { auto pipeline = Pipeline::parse( makeVector(fromjson("{$_internalUnpackBucket: {exclude: [], timeField: " "'time', bucketMaxSpanSeconds: 3600}}"), fromjson("{$match: {loc: {$geoWithin: {$geometry: {type: \"Polygon\", " "coordinates: [ [ [ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 ] ] ]}}}}}")), getExpCtx()); auto& container = pipeline->getSources(); ASSERT_EQ(container.size(), 2U); auto original = dynamic_cast<DocumentSourceMatch*>(container.back().get()); auto predicate = dynamic_cast<DocumentSourceInternalUnpackBucket*>(container.front().get()) ->createPredicatesOnBucketLevelField(original->getMatchExpression()); ASSERT_BSONOBJ_EQ(predicate->serialize(true), fromjson("{$_internalBucketGeoWithin: { withinRegion: { $geometry: { type : " "\"Polygon\" ,coordinates: [ [ [ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 " "] ] ]}},field: \"loc\"}}")); } } // namespace } // namespace mongo
;; ;; Copyright (c) 2020, Intel Corporation ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions are met: ;; ;; * Redistributions of source code must retain the above copyright notice, ;; this list of conditions and the following disclaimer. ;; * Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. ;; * Neither the name of Intel Corporation nor the names of its contributors ;; may be used to endorse or promote products derived from this software ;; without specific prior written permission. ;; ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;; %include "include/os.asm" %include "imb_job.asm" %include "mb_mgr_datastruct.asm" %include "include/reg_sizes.asm" %define NUM_LANES 4 %ifndef AES_CBCS_ENC_X4 %define AES_CBCS_ENC_X4 aes_cbcs_1_9_enc_128_x4 %define FLUSH_JOB_AES_CBCS_ENC flush_job_aes128_cbcs_1_9_enc_sse %endif ; void aes_cbcs_1_9_enc_128_x4(AES_ARGS *args, UINT64 len_in_bytes); extern AES_CBCS_ENC_X4 section .text %define APPEND(a,b) a %+ b %ifdef LINUX %define arg1 rdi %define arg2 rsi %else %define arg1 rcx %define arg2 rdx %endif %define state arg1 %define len2 arg2 %define job_rax rax %define unused_lanes rbx %define tmp1 rbx %define good_lane rdx %define tmp2 rax ; idx needs to be in rbp %define tmp rbp %define idx rbp %define tmp3 r8 ; STACK_SPACE needs to be an odd multiple of 8 ; This routine and its callee clobbers all GPRs struc STACK _gpr_save: resq 8 _rsp_save: resq 1 endstruc ; JOB* flush_job_aes128_cbcs_1_9_enc_sse(MB_MGR_AES_OOO *state) ; arg 1 : state MKGLOBAL(FLUSH_JOB_AES_CBCS_ENC,function,internal) FLUSH_JOB_AES_CBCS_ENC: mov rax, rsp sub rsp, STACK_size and rsp, -16 mov [rsp + _gpr_save + 8*0], rbx mov [rsp + _gpr_save + 8*1], rbp mov [rsp + _gpr_save + 8*2], r12 mov [rsp + _gpr_save + 8*3], r13 mov [rsp + _gpr_save + 8*4], r14 mov [rsp + _gpr_save + 8*5], r15 %ifndef LINUX mov [rsp + _gpr_save + 8*6], rsi mov [rsp + _gpr_save + 8*7], rdi %endif mov [rsp + _rsp_save], rax ; original SP ; check for empty mov unused_lanes, [state + _aes_unused_lanes] bt unused_lanes, ((NUM_LANES * 4) + 3) jc return_null ; find a lane with a non-null job xor good_lane, good_lane mov tmp3, 1 cmp qword [state + _aes_job_in_lane + 1*8], 0 cmovne good_lane, tmp3 inc tmp3 cmp qword [state + _aes_job_in_lane + 2*8], 0 cmovne good_lane, tmp3 inc tmp3 cmp qword [state + _aes_job_in_lane + 3*8], 0 cmovne good_lane, tmp3 ; copy good_lane to empty lanes mov tmp1, [state + _aes_args_in + good_lane*8] mov tmp2, [state + _aes_args_out + good_lane*8] mov tmp3, [state + _aes_args_keys + good_lane*8] shl good_lane, 4 ; multiply by 16 movdqa xmm2, [state + _aes_args_IV + good_lane] %assign I 0 %rep NUM_LANES cmp qword [state + _aes_job_in_lane + I*8], 0 jne APPEND(skip_,I) mov [state + _aes_args_in + I*8], tmp1 mov [state + _aes_args_out + I*8], tmp2 mov [state + _aes_args_keys + I*8], tmp3 movdqa [state + _aes_args_IV + I*16], xmm2 mov qword [state + _aes_lens_64 + 8*I], 0xffffffffffffffff APPEND(skip_,I): %assign I (I+1) %endrep ; Find min length mov len2, [state + _aes_lens_64 + 8*0] xor idx, idx mov tmp3, 1 cmp len2, [state + _aes_lens_64 + 8*1] cmova len2, [state + _aes_lens_64 + 8*1] cmova idx, tmp3 inc tmp3 cmp len2, [state + _aes_lens_64 + 8*2] cmova len2, [state + _aes_lens_64 + 8*2] cmova idx, tmp3 inc tmp3 cmp len2, [state + _aes_lens_64 + 8*3] cmova len2, [state + _aes_lens_64 + 8*3] cmova idx, tmp3 or len2, len2 jz len_is_0 ; Round up to multiple of 16*10 ; N = (length + 159) / 160 --> Number of 160-byte blocks mov rax, len2 xor rdx, rdx ;; zero rdx for div add rax, 159 mov tmp1, 160 div tmp1 ; Number of 160-byte blocks in rax mov tmp1, 160 mul tmp1 ; Number of bytes to process in rax mov len2, rax xor tmp1, tmp1 %assign I 0 %rep NUM_LANES mov tmp3, [state + _aes_lens_64 + 8*I] sub tmp3, len2 cmovs tmp3, tmp1 ; 0 if negative number mov [state + _aes_lens_64 + 8*I], tmp3 %assign I (I+1) %endrep ; "state" and "args" are the same address, arg1 ; len is arg2 call AES_CBCS_ENC_X4 ; state and idx are intact len_is_0: ; process completed job "idx" mov job_rax, [state + _aes_job_in_lane + idx*8] mov unused_lanes, [state + _aes_unused_lanes] mov qword [state + _aes_job_in_lane + idx*8], 0 or dword [job_rax + _status], STS_COMPLETED_AES shl unused_lanes, 4 or unused_lanes, idx mov [state + _aes_unused_lanes], unused_lanes %ifdef SAFE_DATA ;; clear returned jobs and "NULL lanes" %assign I 0 %rep NUM_LANES cmp qword [state + _aes_job_in_lane + I*8], 0 jne APPEND(skip_clear_,I) APPEND(skip_clear_,I): %assign I (I+1) %endrep %endif return: mov rbx, [rsp + _gpr_save + 8*0] mov rbp, [rsp + _gpr_save + 8*1] mov r12, [rsp + _gpr_save + 8*2] mov r13, [rsp + _gpr_save + 8*3] mov r14, [rsp + _gpr_save + 8*4] mov r15, [rsp + _gpr_save + 8*5] %ifndef LINUX mov rsi, [rsp + _gpr_save + 8*6] mov rdi, [rsp + _gpr_save + 8*7] %endif mov rsp, [rsp + _rsp_save] ; original SP ret return_null: xor job_rax, job_rax jmp return %ifdef LINUX section .note.GNU-stack noalloc noexec nowrite progbits %endif
; int fzx_write_justified(struct fzx_state *fs, char *buf, uint16_t buflen, uint16_t allowed_width) SECTION code_font_fzx PUBLIC asm_fzx_write_justified EXTERN __fzx_puts_newline EXTERN error_mc, error_znc, l_inc_sp, l_divu_16_16x16 EXTERN asm_fzx_buffer_extent, asm_fzx_putc asm_fzx_write_justified: ; enter : ix = struct fzx_state * ; de = char *buf ; bc = unsigned int buflen ; hl = allowed_width in pixels ; ; exit : success ; ; hl = 0 ; carry reset ; ; fail if string extent exceeds allowed_width ; ; hl = -1 ; carry set ; ; fail if y bounds exceeded ; ; hl = next unprinted char *buf ; bc = buflen remaining ; carry set ; ; uses : af, bc, de, hl, af' ld a,b or c jp z, error_znc ; find out amount of additional padding required push de ; save char *buf push bc ; save buflen push de ; save char *buf push bc ; save buflen push hl ; save allowed_width ld l,(ix+3) ld h,(ix+4) ; hl = struct fzx_font * call asm_fzx_buffer_extent ; hl = buffer extent in pixels ; stack = char *buf, buflen, char *buf, buflen, allowed_width ex de,hl ; de = buffer extent pop hl ; hl = allowed_width or a sbc hl,de ; hl = additional_padding in pixels pop bc ; bc = buflen ex (sp),hl ; hl = char *buf jp c, error_mc - 3 ; if buffer extent exceeds allowed width ; count number of spaces in buffer ; hl = char *buf ; bc = buflen ; stack = char *buf, buflen, additional_padding ld a,' ' ld de,0 count_loop: cpir jr nz, no_space inc de ; increase number of spaces found jp pe, count_loop no_space: pop hl ; hl = additional_padding push de ; compute distributed padding ; hl = additional_padding in pixels ; de = number of spaces ; stack = char *buf, buflen, number of spaces ld a,d or e jr z, number_spaces_zero call l_divu_16_16x16 ex de,hl ; hl = remainder_padding, de = extra_padding add hl,de ; hl = last_padding number_spaces_zero: pop af pop bc ex (sp),hl push de push af write_loop: ; hl = char *buf ; bc = buflen ; stack = last_padding, extra_padding, number of spaces push bc push hl ld c,(hl) call asm_fzx_putc jr c, off_screen pop hl pop bc ld a,(hl) cp ' ' jr z, insert_spacing loop_rejoin: cpi ; hl++, bc-- jp pe, write_loop jp error_znc - 3 ; success insert_spacing: ; hl = char *buf ; bc = buflen ; stack = last_padding, extra_padding, number of spaces pop de ; de = number of spaces ex (sp),hl ; hl = extra_padding dec de ld a,d or e jr nz, add_spacing ; last space ; de = number of spaces = 0 ; bc = buflen ; stack = last_padding, char *buf pop de pop hl ; hl = last_padding push hl push de add_spacing: ; hl = extra_padding ; de = number of spaces ; bc = buflen ; stack = last_padding, char *buf ex de,hl ; de = extra_padding push hl ; save number of spaces ld l,(ix+5) ld h,(ix+6) ; hl = x coord add hl,de ld (ix+5),l ld (ix+6),h ; store new x coord pop hl ; hl = number of spaces ex de,hl ; de = number of spaces ex (sp),hl ; hl = char *buf push de jr loop_rejoin off_screen: ; stack = last_padding, extra_padding, number of spaces, buflen, char *buf dec a jr nz, newline ; y went out of bounds, must bail pop hl ; hl = next char *buf pop bc ; bc = buflen remaining jp l_inc_sp - 6 newline: call __fzx_puts_newline pop hl pop bc jr write_loop
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r15 push %r9 push %rax push %rbx push %rcx push %rdi push %rsi lea addresses_A_ht+0x13e73, %rsi nop nop nop nop dec %rcx mov $0x6162636465666768, %r12 movq %r12, %xmm7 movups %xmm7, (%rsi) nop nop nop nop nop cmp $50179, %rcx lea addresses_A_ht+0x197b3, %rsi lea addresses_D_ht+0x7733, %rdi nop nop nop nop add $23178, %rax mov $125, %rcx rep movsq nop nop nop nop nop sub %rdi, %rdi lea addresses_WT_ht+0xf673, %r15 nop nop xor $54843, %r9 movl $0x61626364, (%r15) nop xor $46214, %rsi lea addresses_A_ht+0x14e73, %rdi nop nop add %r12, %r12 mov (%rdi), %esi add %r12, %r12 lea addresses_D_ht+0x7c4, %rsi nop nop nop nop nop cmp %rcx, %rcx movb $0x61, (%rsi) inc %r9 lea addresses_WT_ht+0x4273, %rsi lea addresses_WC_ht+0x16e33, %rdi add %rbx, %rbx mov $80, %rcx rep movsl nop nop dec %r9 lea addresses_D_ht+0x17273, %rsi lea addresses_A_ht+0x19d, %rdi nop nop nop nop nop sub $21433, %rax mov $83, %rcx rep movsb and $51505, %rbx lea addresses_D_ht+0x15d91, %rcx nop nop nop nop cmp $49703, %rsi mov $0x6162636465666768, %rbx movq %rbx, (%rcx) add $3052, %rdi lea addresses_A_ht+0xf873, %rcx cmp %rax, %rax movw $0x6162, (%rcx) nop nop inc %r9 lea addresses_A_ht+0x1aa73, %rsi nop nop nop nop nop and $1748, %rcx mov (%rsi), %rdi nop nop nop nop nop and %rsi, %rsi pop %rsi pop %rdi pop %rcx pop %rbx pop %rax pop %r9 pop %r15 pop %r12 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r12 push %r8 push %r9 push %rax push %rbx // Store lea addresses_normal+0xfcf3, %r11 nop nop and %r10, %r10 mov $0x5152535455565758, %r8 movq %r8, %xmm1 movups %xmm1, (%r11) nop nop xor %r12, %r12 // Load lea addresses_PSE+0x1da73, %r10 nop add %rbx, %rbx vmovups (%r10), %ymm3 vextracti128 $1, %ymm3, %xmm3 vpextrq $1, %xmm3, %r8 nop nop nop nop cmp %r8, %r8 // Store lea addresses_normal+0x19273, %r10 nop nop nop nop nop xor %r11, %r11 movl $0x51525354, (%r10) nop and $30505, %r11 // Faulty Load lea addresses_PSE+0x1da73, %rax nop and $20898, %r12 mov (%rax), %r11d lea oracles, %rbx and $0xff, %r11 shlq $12, %r11 mov (%rbx,%r11,1), %r11 pop %rbx pop %rax pop %r9 pop %r8 pop %r12 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'size': 8, 'NT': False, 'type': 'addresses_PSE', 'same': False, 'AVXalign': False, 'congruent': 0}} {'OP': 'STOR', 'dst': {'size': 16, 'NT': False, 'type': 'addresses_normal', 'same': False, 'AVXalign': False, 'congruent': 2}} {'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_PSE', 'same': True, 'AVXalign': False, 'congruent': 0}} {'OP': 'STOR', 'dst': {'size': 4, 'NT': False, 'type': 'addresses_normal', 'same': False, 'AVXalign': False, 'congruent': 11}} [Faulty Load] {'OP': 'LOAD', 'src': {'size': 4, 'NT': False, 'type': 'addresses_PSE', 'same': True, 'AVXalign': True, 'congruent': 0}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'size': 16, 'NT': False, 'type': 'addresses_A_ht', 'same': False, 'AVXalign': False, 'congruent': 10}} {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_A_ht', 'congruent': 0}, 'dst': {'same': False, 'type': 'addresses_D_ht', 'congruent': 5}} {'OP': 'STOR', 'dst': {'size': 4, 'NT': False, 'type': 'addresses_WT_ht', 'same': False, 'AVXalign': False, 'congruent': 10}} {'OP': 'LOAD', 'src': {'size': 4, 'NT': False, 'type': 'addresses_A_ht', 'same': True, 'AVXalign': False, 'congruent': 3}} {'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 0}} {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_WT_ht', 'congruent': 0}, 'dst': {'same': False, 'type': 'addresses_WC_ht', 'congruent': 6}} {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_D_ht', 'congruent': 10}, 'dst': {'same': False, 'type': 'addresses_A_ht', 'congruent': 0}} {'OP': 'STOR', 'dst': {'size': 8, 'NT': False, 'type': 'addresses_D_ht', 'same': True, 'AVXalign': False, 'congruent': 0}} {'OP': 'STOR', 'dst': {'size': 2, 'NT': False, 'type': 'addresses_A_ht', 'same': False, 'AVXalign': False, 'congruent': 9}} {'OP': 'LOAD', 'src': {'size': 8, 'NT': False, 'type': 'addresses_A_ht', 'same': False, 'AVXalign': False, 'congruent': 10}} {'33': 21829} 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 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 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 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 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 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 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 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 33 33 33 33 33 33 33 33 */
.386 .model flat, stdcall option casemap: none include <windows.inc> include <ntdll.inc> includelib <ntdll.lib> false = 0 true = 1 nullptr = 0 OptionShutdownSystem = 6 SeShutdownPrivilege = 19 .data? res dword ? .code main: invoke RtlAdjustPrivilege \ , SeShutdownPrivilege \ , true \ , false \ , offset res invoke NtRaiseHardError \ , STATUS_FLOAT_MULTIPLE_FAULTS \ , 0 \ , nullptr \ , nullptr \ , OptionShutdownSystem \ , offset res end main
// Copyright (c) 2011-2014 The Bitcoin developers // Copyright (c) 2014-2015 The Dash developers // Copyright (c) 2015-2017 The PIVX developers // Copyright (c) 2017-2018 The Vsync developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "bitcoinunits.h" #include "chainparams.h" #include "primitives/transaction.h" #include <QSettings> #include <QStringList> BitcoinUnits::BitcoinUnits(QObject* parent) : QAbstractListModel(parent), unitlist(availableUnits()) { } QList<BitcoinUnits::Unit> BitcoinUnits::availableUnits() { QList<BitcoinUnits::Unit> unitlist; unitlist.append(VSX); unitlist.append(mVSX); unitlist.append(uVSX); return unitlist; } bool BitcoinUnits::valid(int unit) { switch (unit) { case VSX: case mVSX: case uVSX: return true; default: return false; } } QString BitcoinUnits::id(int unit) { switch (unit) { case VSX: return QString("vsync"); case mVSX: return QString("mvsync"); case uVSX: return QString::fromUtf8("uvsync"); default: return QString("???"); } } QString BitcoinUnits::name(int unit) { if (Params().NetworkID() == CBaseChainParams::MAIN) { switch (unit) { case VSX: return QString("VSX"); case mVSX: return QString("mVSX"); case uVSX: return QString::fromUtf8("μVSX"); default: return QString("???"); } } else { switch (unit) { case VSX: return QString("tVSX"); case mVSX: return QString("mtVSX"); case uVSX: return QString::fromUtf8("μtVSX"); default: return QString("???"); } } } QString BitcoinUnits::description(int unit) { if (Params().NetworkID() == CBaseChainParams::MAIN) { switch (unit) { case VSX: return QString("VSX"); case mVSX: return QString("Milli-VSX (1 / 1" THIN_SP_UTF8 "000)"); case uVSX: return QString("Micro-VSX (1 / 1" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)"); default: return QString("???"); } } else { switch (unit) { case VSX: return QString("TestVSXs"); case mVSX: return QString("Milli-TestVSX (1 / 1" THIN_SP_UTF8 "000)"); case uVSX: return QString("Micro-TestVSX (1 / 1" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)"); default: return QString("???"); } } } qint64 BitcoinUnits::factor(int unit) { switch (unit) { case VSX: return 100000000; case mVSX: return 100000; case uVSX: return 100; default: return 100000000; } } int BitcoinUnits::decimals(int unit) { switch (unit) { case VSX: return 8; case mVSX: return 5; case uVSX: return 2; default: return 0; } } QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, SeparatorStyle separators) { // Note: not using straight sprintf here because we do NOT want // localized number formatting. if (!valid(unit)) return QString(); // Refuse to format invalid unit qint64 n = (qint64)nIn; qint64 coin = factor(unit); int num_decimals = decimals(unit); qint64 n_abs = (n > 0 ? n : -n); qint64 quotient = n_abs / coin; qint64 remainder = n_abs % coin; QString quotient_str = QString::number(quotient); QString remainder_str = QString::number(remainder).rightJustified(num_decimals, '0'); // Use SI-style thin space separators as these are locale independent and can't be // confused with the decimal marker. QChar thin_sp(THIN_SP_CP); int q_size = quotient_str.size(); if (separators == separatorAlways || (separators == separatorStandard && q_size > 4)) for (int i = 3; i < q_size; i += 3) quotient_str.insert(q_size - i, thin_sp); if (n < 0) quotient_str.insert(0, '-'); else if (fPlus && n > 0) quotient_str.insert(0, '+'); if (num_decimals <= 0) return quotient_str; return quotient_str + QString(".") + remainder_str; } // TODO: Review all remaining calls to BitcoinUnits::formatWithUnit to // TODO: determine whether the output is used in a plain text context // TODO: or an HTML context (and replace with // TODO: BtcoinUnits::formatHtmlWithUnit in the latter case). Hopefully // TODO: there aren't instances where the result could be used in // TODO: either context. // NOTE: Using formatWithUnit in an HTML context risks wrapping // quantities at the thousands separator. More subtly, it also results // in a standard space rather than a thin space, due to a bug in Qt's // XML whitespace canonicalisation // // Please take care to use formatHtmlWithUnit instead, when // appropriate. QString BitcoinUnits::formatWithUnit(int unit, const CAmount& amount, bool plussign, SeparatorStyle separators) { return format(unit, amount, plussign, separators) + QString(" ") + name(unit); } QString BitcoinUnits::formatHtmlWithUnit(int unit, const CAmount& amount, bool plussign, SeparatorStyle separators) { QString str(formatWithUnit(unit, amount, plussign, separators)); str.replace(QChar(THIN_SP_CP), QString(THIN_SP_HTML)); return QString("<span style='white-space: nowrap;'>%1</span>").arg(str); } QString BitcoinUnits::floorWithUnit(int unit, const CAmount& amount, bool plussign, SeparatorStyle separators) { QSettings settings; int digits = settings.value("digits").toInt(); QString result = format(unit, amount, plussign, separators); if (decimals(unit) > digits) result.chop(decimals(unit) - digits); return result + QString(" ") + name(unit); } QString BitcoinUnits::floorHtmlWithUnit(int unit, const CAmount& amount, bool plussign, SeparatorStyle separators) { QString str(floorWithUnit(unit, amount, plussign, separators)); str.replace(QChar(THIN_SP_CP), QString(THIN_SP_HTML)); return QString("<span style='white-space: nowrap;'>%1</span>").arg(str); } bool BitcoinUnits::parse(int unit, const QString& value, CAmount* val_out) { if (!valid(unit) || value.isEmpty()) return false; // Refuse to parse invalid unit or empty string int num_decimals = decimals(unit); // Ignore spaces and thin spaces when parsing QStringList parts = removeSpaces(value).split("."); if (parts.size() > 2) { return false; // More than one dot } QString whole = parts[0]; QString decimals; if (parts.size() > 1) { decimals = parts[1]; } if (decimals.size() > num_decimals) { return false; // Exceeds max precision } bool ok = false; QString str = whole + decimals.leftJustified(num_decimals, '0'); if (str.size() > 18) { return false; // Longer numbers will exceed 63 bits } CAmount retvalue(str.toLongLong(&ok)); if (val_out) { *val_out = retvalue; } return ok; } QString BitcoinUnits::getAmountColumnTitle(int unit) { QString amountTitle = QObject::tr("Amount"); if (BitcoinUnits::valid(unit)) { amountTitle += " (" + BitcoinUnits::name(unit) + ")"; } return amountTitle; } int BitcoinUnits::rowCount(const QModelIndex& parent) const { Q_UNUSED(parent); return unitlist.size(); } QVariant BitcoinUnits::data(const QModelIndex& index, int role) const { int row = index.row(); if (row >= 0 && row < unitlist.size()) { Unit unit = unitlist.at(row); switch (role) { case Qt::EditRole: case Qt::DisplayRole: return QVariant(name(unit)); case Qt::ToolTipRole: return QVariant(description(unit)); case UnitRole: return QVariant(static_cast<int>(unit)); } } return QVariant(); } CAmount BitcoinUnits::maxMoney() { return Params().MaxMoneyOut(); }
section .data %include "words.inc" global _start extern find_word extern read_word extern exit extern string_length extern print_string section .text ; enter key, the ^D^D (why twice?) and if key found value is printed _start: sub rsp,255 mov rdi,rsp mov rsi,254 call read_word ; read word, not string test rax,rax jz .err mov rdi,rax lea rsi,[colon_head] call find_word test rax,rax jz .err .ok: lea rdi, [rax + 8] push rdi call string_length pop rdi lea rdi, [rdi + rax+1] call print_string mov rdi, 0 call exit .err: mov rdi, 1 call exit
dnl X64-64 mpn_mullo_basecase optimised for Intel Broadwell. dnl Contributed to the GNU project by Torbjorn Granlund. dnl Copyright 2017 Free Software Foundation, Inc. dnl This file is part of the GNU MP Library. dnl dnl The GNU MP Library is free software; you can redistribute it and/or modify dnl it under the terms of either: dnl dnl * the GNU Lesser General Public License as published by the Free dnl Software Foundation; either version 3 of the License, or (at your dnl option) any later version. dnl dnl or dnl dnl * the GNU General Public License as published by the Free Software dnl Foundation; either version 2 of the License, or (at your option) any dnl later version. dnl dnl or both in parallel, as here. dnl dnl The GNU MP Library is distributed in the hope that it will be useful, but dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License dnl for more details. dnl dnl You should have received copies of the GNU General Public License and the dnl GNU Lesser General Public License along with the GNU MP Library. If not, dnl see https://www.gnu.org/licenses/. include(`../config.m4') C The inner loops of this code are the result of running a code generation and C optimisation tool suite written by David Harvey and Torbjorn Granlund. define(`rp', `%rdi') define(`up', `%rsi') define(`vp_param', `%rdx') define(`n', `%rcx') define(`vp', `%r11') define(`jmpreg',`%rbx') define(`nn', `%rbp') C TODO C * Suppress more rp[] rewrites in corner. C * Rearrange feed-in jumps for short branch forms. C * Perhaps roll out the heavy artillery and 8-way unroll outer loop. Since C feed-in code implodes, the blow-up will not be more than perhaps 4x. C * Micro-optimise critical lead-in code block around L(ent). C * Write n < 4 code specifically for Broadwell (current code is for Haswell). ABI_SUPPORT(DOS64) ABI_SUPPORT(STD64) ASM_START() TEXT ALIGN(32) PROLOGUE(mpn_mullo_basecase) FUNC_ENTRY(4) cmp $4, R32(n) jae L(big) mov vp_param, vp mov (up), %rdx cmp $2, R32(n) jae L(gt1) L(n1): imul (vp), %rdx mov %rdx, (rp) FUNC_EXIT() ret L(gt1): ja L(gt2) L(n2): mov (vp), %r9 mulx( %r9, %rax, %rdx) mov %rax, (rp) mov 8(up), %rax imul %r9, %rax add %rax, %rdx mov 8(vp), %r9 mov (up), %rcx imul %r9, %rcx add %rcx, %rdx mov %rdx, 8(rp) FUNC_EXIT() ret L(gt2): L(n3): mov (vp), %r9 mulx( %r9, %rax, %r10) C u0 x v0 mov %rax, (rp) mov 8(up), %rdx mulx( %r9, %rax, %rdx) C u1 x v0 imul 16(up), %r9 C u2 x v0 add %rax, %r10 adc %rdx, %r9 mov 8(vp), %r8 mov (up), %rdx mulx( %r8, %rax, %rdx) C u0 x v1 add %rax, %r10 adc %rdx, %r9 imul 8(up), %r8 C u1 x v1 add %r8, %r9 mov %r10, 8(rp) mov 16(vp), %r10 mov (up), %rax imul %rax, %r10 C u0 x v2 add %r10, %r9 mov %r9, 16(rp) FUNC_EXIT() ret ALIGN(16) L(big): push %r14 push %r12 push %rbx push %rbp mov -8(vp_param,n,8), %r14 C FIXME Put at absolute end imul (up), %r14 C FIXME Put at absolute end lea -3(n), R32(nn) lea 8(vp_param), vp mov (vp_param), %rdx mov R32(n), R32(%rax) shr $3, R32(n) and $7, R32(%rax) C clear OF, CF as side-effect lea L(mtab)(%rip), %r10 ifdef(`PIC', ` movslq (%r10,%rax,4), %rax lea (%rax, %r10), %r10 jmp *%r10 ',` jmp *(%r10,%rax,8) ') L(mf0): mulx( (up), %r10, %r8) lea 56(up), up lea -8(rp), rp lea L(f7)(%rip), jmpreg jmp L(mb0) L(mf3): mulx( (up), %r9, %rax) lea 16(up), up lea 16(rp), rp jrcxz L(mc) inc R32(n) lea L(f2)(%rip), jmpreg jmp L(mb3) L(mc): mulx( -8,(up), %r10, %r8) add %rax, %r10 mov %r9, -16(rp) mulx( (up), %r9, %rax) mov %r10, -8(rp) adc %r8, %r9 mov %r9, (rp) jmp L(c2) L(mf4): mulx( (up), %r10, %r8) lea 24(up), up lea 24(rp), rp inc R32(n) lea L(f3)(%rip), jmpreg jmp L(mb4) L(mf5): mulx( (up), %r9, %rax) lea 32(up), up lea 32(rp), rp inc R32(n) lea L(f4)(%rip), jmpreg jmp L(mb5) L(mf6): mulx( (up), %r10, %r8) lea 40(up), up lea 40(rp), rp inc R32(n) lea L(f5)(%rip), jmpreg jmp L(mb6) L(mf7): mulx( (up), %r9, %rax) lea 48(up), up lea 48(rp), rp lea L(f6)(%rip), jmpreg jmp L(mb7) L(mf1): mulx( (up), %r9, %rax) lea L(f0)(%rip), jmpreg jmp L(mb1) L(mf2): mulx( (up), %r10, %r8) lea 8(up), up lea 8(rp), rp lea L(f1)(%rip), jmpreg mulx( (up), %r9, %rax) C FIXME ugly fallthrough FIXME ALIGN(32) L(mtop):mov %r10, -8(rp) adc %r8, %r9 L(mb1): mulx( 8,(up), %r10, %r8) adc %rax, %r10 lea 64(up), up mov %r9, (rp) L(mb0): mov %r10, 8(rp) mulx( -48,(up), %r9, %rax) lea 64(rp), rp adc %r8, %r9 L(mb7): mulx( -40,(up), %r10, %r8) mov %r9, -48(rp) adc %rax, %r10 L(mb6): mov %r10, -40(rp) mulx( -32,(up), %r9, %rax) adc %r8, %r9 L(mb5): mulx( -24,(up), %r10, %r8) mov %r9, -32(rp) adc %rax, %r10 L(mb4): mulx( -16,(up), %r9, %rax) mov %r10, -24(rp) adc %r8, %r9 L(mb3): mulx( -8,(up), %r10, %r8) adc %rax, %r10 mov %r9, -16(rp) dec R32(n) mulx( (up), %r9, %rax) jnz L(mtop) L(mend):mov %r10, -8(rp) adc %r8, %r9 mov %r9, (rp) adc %rcx, %rax lea 8(,nn,8), %r12 neg %r12 shr $3, R32(nn) jmp L(ent) L(f0): mulx( (up), %r10, %r8) lea -8(up), up lea -8(rp), rp lea L(f7)(%rip), jmpreg jmp L(b0) L(f1): mulx( (up), %r9, %rax) lea -1(nn), R32(nn) lea L(f0)(%rip), jmpreg jmp L(b1) L(end): adox( (rp), %r9) mov %r9, (rp) adox( %rcx, %rax) C relies on rcx = 0 adc %rcx, %rax C FIXME suppress, use adc below; reqs ent path edits lea 8(%r12), %r12 L(ent): mulx( 8,(up), %r10, %r8) C r8 unused (use imul?) add %rax, %r14 add %r10, %r14 C h lea (up,%r12), up C reset up lea 8(rp,%r12), rp C reset rp mov (vp), %rdx lea 8(vp), vp or R32(nn), R32(n) C copy count, clear CF,OF (n = 0 prior) jmp *jmpreg L(f7): mulx( (up), %r9, %rax) lea -16(up), up lea -16(rp), rp lea L(f6)(%rip), jmpreg jmp L(b7) L(f2): mulx( (up), %r10, %r8) lea 8(up), up lea 8(rp), rp mulx( (up), %r9, %rax) lea L(f1)(%rip), jmpreg C FIXME ugly fallthrough FIXME ALIGN(32) L(top): adox( -8,(rp), %r10) adcx( %r8, %r9) mov %r10, -8(rp) jrcxz L(end) L(b1): mulx( 8,(up), %r10, %r8) adox( (rp), %r9) lea -1(n), R32(n) mov %r9, (rp) adcx( %rax, %r10) L(b0): mulx( 16,(up), %r9, %rax) adcx( %r8, %r9) adox( 8,(rp), %r10) mov %r10, 8(rp) L(b7): mulx( 24,(up), %r10, %r8) lea 64(up), up adcx( %rax, %r10) adox( 16,(rp), %r9) mov %r9, 16(rp) L(b6): mulx( -32,(up), %r9, %rax) adox( 24,(rp), %r10) adcx( %r8, %r9) mov %r10, 24(rp) L(b5): mulx( -24,(up), %r10, %r8) adcx( %rax, %r10) adox( 32,(rp), %r9) mov %r9, 32(rp) L(b4): mulx( -16,(up), %r9, %rax) adox( 40,(rp), %r10) adcx( %r8, %r9) mov %r10, 40(rp) L(b3): adox( 48,(rp), %r9) mulx( -8,(up), %r10, %r8) mov %r9, 48(rp) lea 64(rp), rp adcx( %rax, %r10) mulx( (up), %r9, %rax) jmp L(top) L(f6): mulx( (up), %r10, %r8) lea 40(up), up lea -24(rp), rp lea L(f5)(%rip), jmpreg jmp L(b6) L(f5): mulx( (up), %r9, %rax) lea 32(up), up lea -32(rp), rp lea L(f4)(%rip), jmpreg jmp L(b5) L(f4): mulx( (up), %r10, %r8) lea 24(up), up lea -40(rp), rp lea L(f3)(%rip), jmpreg jmp L(b4) L(f3): mulx( (up), %r9, %rax) lea 16(up), up lea -48(rp), rp jrcxz L(cor) lea L(f2)(%rip), jmpreg jmp L(b3) L(cor): adox( 48,(rp), %r9) mulx( -8,(up), %r10, %r8) mov %r9, 48(rp) lea 64(rp), rp adcx( %rax, %r10) mulx( (up), %r9, %rax) adox( -8,(rp), %r10) adcx( %r8, %r9) mov %r10, -8(rp) C FIXME suppress adox( (rp), %r9) mov %r9, (rp) C FIXME suppress adox( %rcx, %rax) L(c2): mulx( 8,(up), %r10, %r8) adc %rax, %r14 add %r10, %r14 mov (vp), %rdx test R32(%rcx), R32(%rcx) mulx( -16,(up), %r10, %r8) mulx( -8,(up), %r9, %rax) adox( -8,(rp), %r10) adcx( %r8, %r9) mov %r10, -8(rp) adox( (rp), %r9) adox( %rcx, %rax) adc %rcx, %rax mulx( (up), %r10, %r8) add %rax, %r14 add %r10, %r14 mov 8(vp), %rdx mulx( -16,(up), %rcx, %rax) add %r9, %rcx mov %rcx, (rp) adc $0, %rax mulx( -8,(up), %r10, %r8) add %rax, %r14 add %r10, %r14 mov %r14, 8(rp) pop %rbp pop %rbx pop %r12 pop %r14 FUNC_EXIT() ret EPILOGUE() JUMPTABSECT ALIGN(8) L(mtab):JMPENT( L(mf7), L(mtab)) JMPENT( L(mf0), L(mtab)) JMPENT( L(mf1), L(mtab)) JMPENT( L(mf2), L(mtab)) JMPENT( L(mf3), L(mtab)) JMPENT( L(mf4), L(mtab)) JMPENT( L(mf5), L(mtab)) JMPENT( L(mf6), L(mtab))
[bits 64] l1: inc dword [l2] l2 equ 4-(l1-$$)
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r9 push %rax push %rbp push %rbx push %rcx push %rdi push %rsi lea addresses_normal_ht+0x1a5a6, %rax nop cmp $6248, %rsi movw $0x6162, (%rax) nop nop nop xor %rbp, %rbp lea addresses_WT_ht+0x618e, %r12 nop nop nop add $16326, %rsi mov (%r12), %ebx nop nop dec %r12 lea addresses_normal_ht+0xf166, %rsi lea addresses_UC_ht+0xc1a6, %rdi nop nop nop dec %r9 mov $28, %rcx rep movsw nop nop nop nop dec %rbx lea addresses_WC_ht+0x296e, %rsi lea addresses_WT_ht+0x4466, %rdi and $57243, %rbx mov $49, %rcx rep movsb nop nop nop nop nop xor $42691, %rsi pop %rsi pop %rdi pop %rcx pop %rbx pop %rbp pop %rax pop %r9 pop %r12 ret .global s_faulty_load s_faulty_load: push %r10 push %r13 push %r14 push %r15 push %r8 push %rax push %rsi // Store lea addresses_UC+0x21a6, %r15 clflush (%r15) nop dec %rsi mov $0x5152535455565758, %r10 movq %r10, (%r15) nop nop nop nop add %r13, %r13 // Faulty Load lea addresses_WT+0x11da6, %r13 nop nop nop and $28708, %r14 mov (%r13), %r10d lea oracles, %r14 and $0xff, %r10 shlq $12, %r10 mov (%r14,%r10,1), %r10 pop %rsi pop %rax pop %r8 pop %r15 pop %r14 pop %r13 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_WT', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_WT', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': True}} {'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 10, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 2, 'same': True}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': False}} {'39': 5882} 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 */
/* Tencent is pleased to support the open source community by making Plato available. Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. Licensed under the BSD 3-Clause License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://opensource.org/licenses/BSD-3-Clause 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. See the AUTHORS file for names of contributors. */ #ifndef __PLATO_BUFFERS_HPP__ #define __PLATO_BUFFERS_HPP__ #include <unistd.h> #include <cstring> #include <memory> #include <type_traits> namespace plato { struct intrusive_buffer_t { intrusive_buffer_t(const char* data, std::size_t size) : data_(data), size_(size) { } intrusive_buffer_t(const intrusive_buffer_t& o) : data_(o.data_), size_(o.size_) { } const char* data_; const std::size_t size_; protected: intrusive_buffer_t(); }; /***************************************************************************/ struct shared_buffer_t { typedef std::shared_ptr<char> shared_array_type; explicit shared_buffer_t(std::size_t size = 0) :size_(0) { resize(size); } shared_buffer_t(const void* ptr, std::size_t size) :size_(0) { assign(ptr, size); } shared_buffer_t(shared_array_type buf, std::size_t size) :size_(size) { if (size) { data_ = std::move(buf); } } shared_buffer_t(const shared_buffer_t& buf) :size_(buf.size_) { if (size_) { data_ = buf.data_; } } shared_buffer_t(shared_buffer_t&& buf) :data_(std::move(buf.data_)), size_(buf.size_) { buf.size_ = 0; } shared_buffer_t& operator=(const shared_buffer_t&) = default; shared_buffer_t& operator=(shared_buffer_t&&) = default; void resize(std::size_t new_size) { if (new_size > size_) { data_.reset(new char[new_size], &deleter); } size_ = new_size; } void assign(const void* ptr, std::size_t size) { resize(size); if (size_) { std::memcpy(data_.get(), ptr, size_); } } shared_array_type data_; std::size_t size_; protected: static void deleter(char* ptr) { delete[] ptr; } }; /***************************************************************************/ } // namespace plato #endif // buffers.hpp
;//////////////////////////////////////////////////////////////////////////////////////////////////////// ;// Part of Injectable Generic Camera System ;// Copyright(c) 2019, Frans Bouma ;// All rights reserved. ;// https://github.com/FransBouma/InjectableGenericCameraSystem ;// ;// Redistribution and use in source and binary forms, with or without ;// modification, are permitted provided that the following conditions are met : ;// ;// * Redistributions of source code must retain the above copyright notice, this ;// list of conditions and the following disclaimer. ;// ;// * Redistributions in binary form must reproduce the above copyright notice, ;// this list of conditions and the following disclaimer in the documentation ;// and / or other materials provided with the distribution. ;// ;// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ;// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ;// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ;// DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE ;// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;// DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ;// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ;// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ;// OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ;// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;//////////////////////////////////////////////////////////////////////////////////////////////////////// ;--------------------------------------------------------------- ; Game specific asm file to intercept execution flow to obtain addresses, prevent writes etc. ;--------------------------------------------------------------- ;--------------------------------------------------------------- ; Public definitions so the linker knows which names are present in this file PUBLIC cameraStructInterceptor PUBLIC cameraFOVInterceptor PUBLIC timescaleInterceptor PUBLIC HUDinterceptor ;--------------------------------------------------------------- ;--------------------------------------------------------------- ; Externs which are used and set by the system. Read / write these ; values in asm to communicate with the system EXTERN g_cameraEnabled: byte EXTERN g_timestopEnabled: byte EXTERN g_cameraStructAddress: qword EXTERN g_fovStructAddress: qword EXTERN g_timescaleAddress: qword EXTERN g_HUDaddress: qword ;--------------------------------------------------------------- ;--------------------------------------------------------------- ; Own externs, defined in InterceptorHelper.cpp EXTERN _cameraStructInterceptionContinue: qword EXTERN _fovStructInterceptionContinue: qword EXTERN _timescaleInterceptionContinue: qword EXTERN _timestopOneAbsolute: qword EXTERN _timestopTwoAbsolute: qword EXTERN _HUDinterceptionContinue: qword .data .code timevalue dd 0.0 cameraStructInterceptor PROC ;Nino2.exe+39DEFA - F3 0F59 C7 - mulss xmm0,xmm7 ;Nino2.exe+39DEFE - F3 0F5C F0 - subss xmm6,xmm0 ;Nino2.exe+39DF02 - E8 99C7E3FF - call Nino2.exe+1DA6A0 ;Nino2.exe+39DF07 - 0F10 00 - movups xmm0,[rax] ;_camBase2 - 0F11 07 - movups [rdi],xmm0 <<<inject here ;Nino2.exe+39DF0D - 4C 8D 9C 24 B8000000 - lea r11,[rsp+000000B8] ;Nino2.exe+39DF15 - 0F10 48 10 - movups xmm1,[rax+10] ;Nino2.exe+39DF19 - 0F11 4F 10 - movups [rdi+10],xmm1 <<<return here ;Nino2.exe+39DF1D - 0F10 40 20 - movups xmm0,[rax+20] ;Nino2.exe+39DF21 - 0F11 47 20 - movups [rdi+20],xmm0 ;Nino2.exe+39DF25 - 0F10 48 30 - movups xmm1,[rax+30] ;Nino2.exe+39DF29 - 48 8B C7 - mov rax,rdi ;Nino2.exe+39DF2C - F3 0F10 05 ECC6A400 - movss xmm0,[Nino2.exe+DEA620] { (0.00) } ;Nino2.exe+39DF34 - 0F11 4F 30 - movups [rdi+30],xmm1 cmp r15,1 jne skip mov [g_cameraStructAddress],rdi ;cmp byte ptr [g_cameraEnabled],1 skip: movups [rdi],xmm0 lea r11,[rsp+000000B8h] movups xmm1,[rax+10h] movups [rdi+10h],xmm1 exit: jmp qword ptr [_cameraStructInterceptionContinue] ; jmp back into the original game code, which is the location after the original statements above. cameraStructInterceptor ENDP cameraFOVInterceptor PROC ;Nino2.exe+B3DAE0 - 0F2F 83 9C020000 - comiss xmm0,[rbx+0000029C] ;Nino2.exe+B3DAE7 - 72 0F - jb Nino2.exe+B3DAF8 ;Nino2.exe+B3DAE9 - 48 8B CB - mov rcx,rbx ;Nino2.exe+B3DAEC - E8 2F7593FF - call Nino2.exe+475020 ;Nino2.exe+B3DAF1 - C6 83 AC020000 00 - mov byte ptr [rbx+000002AC],00 { 0 } ;Nino2.exe+B3DAF8 - 0F28 83 60010000 - movaps xmm0,[rbx+00000160] <<intercept here ;Nino2.exe+B3DAFF - 0F29 87 80000000 - movaps [rdi+00000080],xmm0 ;Nino2.exe+B3DB06 - 0F28 8B 70010000 - movaps xmm1,[rbx+00000170] <<return here ;Nino2.exe+B3DB0D - 0F29 8F 90000000 - movaps [rdi+00000090],xmm1 ;Nino2.exe+B3DB14 - 0F28 83 80010000 - movaps xmm0,[rbx+00000180] ;Nino2.exe+B3DB1B - 0F29 87 A0000000 - movaps [rdi+000000A0],xmm0 ;Nino2.exe+B3DB22 - 0F28 8B 90010000 - movaps xmm1,[rbx+00000190] mov [g_fovStructAddress],rbx ;cmp byte ptr [g_cameraEnabled],1 movaps xmm0,[rbx+00000160h] movaps [rdi+00000080h],xmm0 exit: jmp qword ptr [_fovStructInterceptionContinue] ; jmp back into the original game code, which is the location after the original statements above. cameraFOVInterceptor ENDP timescaleInterceptor PROC ;Nino2.exe+9D627F - FF 50 08 - call qword ptr [rax+08] ;Nino2.exe+9D6282 - E8 89001900 - call Nino2.exe+B66310 ;Nino2.exe+9D6287 - F3 0F11 35 35168B00 - movss [Nino2.exe+12878C4],xmm6 { (0.00) } <<intercept here ;Nino2.exe+9D628F - F3 0F11 3D 5D168B00 - movss [Nino2.exe+12878F4],xmm7 { (0.02) } ;Nino2.exe+9D6297 - E8 047B9DFF - call Nino2.exe+3ADDA0 <<return here ;Nino2.exe+9D629C - E8 3F7C9DFF - call Nino2.exe+3ADEE0 cmp byte ptr [g_timestopEnabled],1 je stopTime push rcx push rdx mov rcx, [_timestopOneAbsolute] mov rdx, [_timestopTwoAbsolute] movss dword ptr [rcx],xmm6 movss dword ptr [rdx],xmm7 pop rcx pop rdx jmp exit stopTime: push rbx push rcx push rdx mov ebx, [timevalue] mov rcx, [_timestopOneAbsolute] mov rdx, [_timestopTwoAbsolute] mov dword ptr [rcx], ebx movss dword ptr [rdx],xmm7 pop rbx pop rcx pop rdx exit: jmp qword ptr [_timescaleInterceptionContinue] ; jmp back into the original game code, which is the location after the original statements above. timescaleInterceptor ENDP HUDinterceptor PROC ;Nino2.exe+4F98D7 - 8B 81 D0390000 - mov eax,[rcx+000039D0] ;Nino2.exe+4F98DD - F3 0F11 44 24 24 - movss [rsp+24],xmm0 ;Nino2.exe+4F98E3 - 48 C7 44 24 1C 02000000 - mov qword ptr [rsp+1C],00000002 { 2 } ;Nino2.exe+4F98EC - 80 BA 44 61 00 00 00 - cmp byte ptr [rdx+00006144],00 { 0 } <<<Intercept here ;Nino2.exe+4F98F3 - 48 89 4C 24 10 - mov [rsp+10],rcx ;Nino2.exe+4F98F8 - 89 44 24 18 - mov [rsp+18],eax ;Nino2.exe+4F98FC - 74 4E - je Nino2.exe+4F994C <<<return here ;Nino2.exe+4F98FE - 0FB7 82 40610000 - movzx eax,word ptr [rdx+00006140] ;Nino2.exe+4F9905 - B9 00020000 - mov ecx,00000200 { 512 } mov [g_HUDaddress],rdx cmp byte ptr [rdx+00006144h],00 mov [rsp+10h],rcx mov dword ptr [rsp+18h],eax jmp qword ptr [_HUDinterceptionContinue] ; jmp back into the original game code, which is the location after the original statements above. HUDinterceptor ENDP END
/* Copyright (c) <2003-2019> <Newton Game Dynamics> * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely */ #include "toolbox_stdafx.h" #include "TargaToOpenGl.h" struct TextureEntry: public dRefCounter { GLuint m_textureID; dString m_textureName; }; class TextureCache: public dTree<TextureEntry, dCRCTYPE> { public: GLuint GetTexture(const char* const texName) { GLuint texID = 0; dAssert (texName); TextureEntry entry; entry.m_textureName = texName; entry.m_textureName.ToLower(); dCRCTYPE crc = dCRC64 (entry.m_textureName.GetStr()); dTreeNode* node = Find(crc); if (node) { node->GetInfo().AddRef(); texID = node->GetInfo().m_textureID; } return texID; } void InsertText (const char* const texName, GLuint id) { TextureEntry entry; entry.m_textureID = id; entry.m_textureName = texName; entry.m_textureName.ToLower(); dCRCTYPE crc = dCRC64 (entry.m_textureName.GetStr()); Insert(entry, crc); } ~TextureCache () { Iterator iter (*this); for (iter.Begin(); iter; iter ++) { glDeleteTextures(1, &iter.GetNode()->GetInfo().m_textureID); } } void RemoveById (GLuint id) { Iterator iter (*this); for (iter.Begin(); iter; iter ++) { TextureEntry& entry = iter.GetNode()->GetInfo(); if (entry.m_textureID == id) { if (entry.GetRef() == 1) { glDeleteTextures(1, &id); Remove (iter.GetNode()); } break; } } } dTreeNode* FindById (GLuint id) const { Iterator iter (*this); for (iter.Begin(); iter; iter ++) { if (iter.GetNode()->GetInfo().m_textureID == id) { //return iter.GetNode()->GetInfo().m_textureName.GetStr(); return iter.GetNode(); } } return NULL; } static TextureCache& GetChache() { static TextureCache texCache; return texCache; } }; // Loads the texture from the specified file and stores it in iTexture. Note // that we're using the GLAUX library here, which is generally discouraged, // but in this case spares us having to write a bitmap loading routine. GLuint LoadTexture(const char* const filename) { #pragma pack(1) struct TGAHEADER { char identsize; // Size of ID field that follows header (0) char colorMapType; // 0 = None, 1 = palette char imageType; // 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle unsigned short colorMapStart; // First color map entry unsigned short colorMapLength; // Number of colors unsigned char colorMapBits; // bits per palette entry unsigned short xstart; // image x origin unsigned short ystart; // image y origin unsigned short width; // width in pixels unsigned short height; // height in pixels char bits; // bits per pixel (8 16, 24, 32) char descriptor; // image descriptor }; #pragma pack(8) char fullPathName[2048]; dGetWorkingFileName (filename, fullPathName); TextureCache& cache = TextureCache::GetChache(); GLuint texture = cache.GetTexture(fullPathName); if (!texture) { FILE* const pFile = fopen (fullPathName, "rb"); if(pFile == NULL) { return 0; } //dAssert (sizeof (TGAHEADER) == 18); // Read in header (binary) sizeof(TGAHEADER) = 18 TGAHEADER tgaHeader; // TGA file header size_t ret = fread(&tgaHeader, 18, 1, pFile); ret = 0; // Do byte swap for big vs little Indian tgaHeader.colorMapStart = SWAP_INT16(tgaHeader.colorMapStart); tgaHeader.colorMapLength = SWAP_INT16(tgaHeader.colorMapLength); tgaHeader.xstart = SWAP_INT16(tgaHeader.xstart); tgaHeader.ystart = SWAP_INT16(tgaHeader.ystart); tgaHeader.width = SWAP_INT16(tgaHeader.width); tgaHeader.height = SWAP_INT16(tgaHeader.height); // Get width, height, and depth of texture int width = tgaHeader.width; int height = tgaHeader.height; short sDepth = tgaHeader.bits / 8; dAssert ((sDepth == 3) || (sDepth == 4)); // Put some validity checks here. Very simply, I only understand // or care about 8, 24, or 32 bit targa's. if(tgaHeader.bits != 8 && tgaHeader.bits != 24 && tgaHeader.bits != 32) { fclose(pFile); return 0; } // Calculate size of image buffer unsigned lImageSize = width * height * sDepth; // Allocate memory and check for success char* const pBits = new char [width * height * 4]; if(pBits == NULL) { fclose(pFile); return 0; } // Read in the bits // Check for read error. This should catch RLE or other // weird formats that I don't want to recognize int readret = int (fread(pBits, lImageSize, 1, pFile)); if(readret != 1) { fclose(pFile); delete[] pBits; return 0; } TextureImageFormat format = m_rgb; switch(sDepth) { case 1: format = m_luminace; break; case 3: format = m_rgb; break; case 4: format = m_rgba; break; }; texture = LoadImage(fullPathName, pBits, tgaHeader.width, tgaHeader.height, format); // Done with File fclose(pFile); delete[] pBits; } return texture; } #ifndef GL_BGR #define GL_BGR 0x80E0 #define GL_BGRA 0x80E1 #endif GLuint LoadImage(const char* const cacheName, const char* const buffer, int width, int hight, TextureImageFormat format) { // Get width, height, and depth of texture GLint iWidth = width; GLint iHeight = hight; //GL_COLOR_INDEX, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_RGB, GL_RGBA, GL_BGR_EXT, GL_BGRA_EXT, GL_LUMINANCE, or GL_LUMINANCE_ALPHA. GLenum eFormat = GL_RGBA; GLint iComponents = 4; switch(format) { case m_rgb: // Most likely case eFormat = GL_BGR; //eFormat = GL_RGB; iComponents = 4; break; case m_rgba: eFormat = GL_BGRA; //eFormat = GL_RGBA; iComponents = 4; break; case m_luminace: //eFormat = GL_LUMINANCE; eFormat = GL_LUMINANCE_ALPHA; //eFormat = GL_ALPHA; iComponents = 4; break; }; GLuint texture = 0; glGenTextures(1, &texture); if (texture) { //GLenum errr = glGetError (); glBindTexture(GL_TEXTURE_2D, texture); // select modulate to mix texture with color for shading glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // when texture area is small, tri linear filter mip mapped glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // when texture area is large, bilinear filter the first mipmap glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); float anisotropic = 0.0f; glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropic); // build our texture mip maps gluBuild2DMipmaps (GL_TEXTURE_2D, iComponents, iWidth, iHeight, eFormat, GL_UNSIGNED_BYTE, buffer); // Done with File TextureCache& cache = TextureCache::GetChache(); cache.InsertText (cacheName, texture); } return texture; } void ReleaseTexture (GLuint texture) { TextureCache::GetChache().RemoveById (texture); } const char* FindTextureById (GLuint textureID) { TextureCache& cache = TextureCache::GetChache(); TextureCache::dTreeNode* const node = cache.FindById (textureID); if (node) { return node->GetInfo().m_textureName.GetStr(); } return NULL; } GLuint AddTextureRef (GLuint texture) { TextureCache& cache = TextureCache::GetChache(); TextureCache::dTreeNode* const node = cache.FindById (texture); if (node) { node->GetInfo().AddRef(); } return texture; }
include io.h cr equ 10 lf equ 13 .model small .stack 200h .Data promptN1 db cr, lf, 'Enter a NumberBase -> ', 0 promptN2 db cr, lf, 'Enter a NumberGuesses -> ', 0 promptN3 db cr, lf, 'The number Greater :( ', 0 promptN4 db cr, lf, 'The number Less :( ', 0 promptN5 db cr, lf, 'Afaaaaaaaaaaaaaaaarin Pesare Gooolam :)', 0 valueOne db 10 dup(?) valueTwo db 10 dup(?) numberOne dw ? numberTwo dw ? .Code Main proc mov ax, @data mov ds, ax ;=================================================== clrscr output promptN1 inputs valueOne, 5 atoi valueOne mov numberOne, ax clrscr myloop: output promptN2 inputs valueTwo, 5 cmp valueTwo,'q' je endprogrammses atoi valueTwo mov numberTwo, ax while: cmp numberOne, ax je endWhile cmp numberOne, ax ja Balatar cmp numberOne, ax jb Paiiintar Balatar: output promptN4 jmp myloop Paiiintar: output promptN3 jmp myloop endwhile: output promptN5 endprogrammses: ;=================================================== mov ax, 4c00h int 21h Main endp end Main
.data a: 10 .text main: load %x0, $a, %x3 ;loading the input into x3 divi %x3, 2, %x4 ;x4 = x3 / 2 beq %x31, 0, even ;if x3 % 2 == 0, jump to even jmp odd ;else jump to odd even: subi %x0, 1, %x10 ;writing -1 to x10 if even and end end odd: addi %x0, 1, %x10 ;writing 1 to x10 if odd and end end
// Copyright 2011 Baptiste Lepilleur // Distributed under MIT license, or public domain if desired and // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE #if !defined(JSON_IS_AMALGAMATION) #include <json/writer.h> #include "json_tool.h" #endif // if !defined(JSON_IS_AMALGAMATION) #include <utility> #include <assert.h> #include <stdio.h> #include <string.h> #include <sstream> #include <iomanip> #if defined(_MSC_VER) && _MSC_VER >= 1400 // VC++ 8.0 // Disable warning about strdup being deprecated. #pragma warning(disable : 4996) #endif namespace Json { static bool containsControlCharacter(const char *str) { while (*str) { if (isControlCharacter(*(str++))) return true; } return false; } std::string valueToString(LargestInt value) { UIntToStringBuffer buffer; char *current = buffer + sizeof(buffer); bool isNegative = value < 0; if (isNegative) value = -value; uintToString(LargestUInt(value), current); if (isNegative) *--current = '-'; assert(current >= buffer); return current; } std::string valueToString(LargestUInt value) { UIntToStringBuffer buffer; char *current = buffer + sizeof(buffer); uintToString(value, current); assert(current >= buffer); return current; } #if defined(JSON_HAS_INT64) std::string valueToString(Int value) { return valueToString(LargestInt(value)); } std::string valueToString(UInt value) { return valueToString(LargestUInt(value)); } #endif // # if defined(JSON_HAS_INT64) std::string valueToString(double value) { // Allocate a buffer that is more than large enough to store the 16 digits of // precision requested below. char buffer[32]; // Print into the buffer. We need not request the alternative representation // that always has a decimal point because JSON doesn't distingish the // concepts of reals and integers. #if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with // visual studio 2005 to // avoid warning. sprintf_s(buffer, sizeof(buffer), "%.16g", value); #else snprintf(buffer, sizeof(buffer), "%.16g", value); #endif return buffer; } std::string valueToString(bool value) { return value ? "true" : "false"; } std::string valueToQuotedString(const char *value) { if (value == NULL) return ""; // Not sure how to handle unicode... if (strpbrk(value, "\"\\\b\f\n\r\t") == NULL && !containsControlCharacter(value)) return std::string("\"") + value + "\""; // We have to walk value and escape any special characters. // Appending to std::string is not efficient, but this should be rare. // (Note: forward slashes are *not* rare, but I am not escaping them.) std::string::size_type maxsize = strlen(value) * 2 + 3; // allescaped+quotes+NULL std::string result; result.reserve(maxsize); // to avoid lots of mallocs result += "\""; for (const char *c = value; *c != 0; ++c) { switch (*c) { case '\"': result += "\\\""; break; case '\\': result += "\\\\"; break; case '\b': result += "\\b"; break; case '\f': result += "\\f"; break; case '\n': result += "\\n"; break; case '\r': result += "\\r"; break; case '\t': result += "\\t"; break; // case '/': // Even though \/ is considered a legal escape in JSON, a bare // slash is also legal, so I see no reason to escape it. // (I hope I am not misunderstanding something. // blep notes: actually escaping \/ may be useful in javascript to avoid </ // sequence. // Should add a flag to allow this compatibility mode and prevent this // sequence from occurring. default: if (isControlCharacter(*c)) { std::ostringstream oss; oss << "\\u" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << static_cast<int>(*c); result += oss.str(); } else { result += *c; } break; } } result += "\""; return result; } // Class Writer // ////////////////////////////////////////////////////////////////// Writer::~Writer() {} // Class FastWriter // ////////////////////////////////////////////////////////////////// FastWriter::FastWriter() : yamlCompatiblityEnabled_(false), dropNullPlaceholders_(false) {} void FastWriter::enableYAMLCompatibility() { yamlCompatiblityEnabled_ = true; } void FastWriter::dropNullPlaceholders() { dropNullPlaceholders_ = true; } std::string FastWriter::write(const Value &root) { document_ = ""; writeValue(root); document_ += "\n"; return document_; } void FastWriter::writeValue(const Value &value) { switch (value.type()) { case nullValue: if (!dropNullPlaceholders_) document_ += "null"; break; case intValue: document_ += valueToString(value.asLargestInt()); break; case uintValue: document_ += valueToString(value.asLargestUInt()); break; case realValue: document_ += valueToString(value.asDouble()); break; case stringValue: document_ += valueToQuotedString(value.asCString()); break; case booleanValue: document_ += valueToString(value.asBool()); break; case arrayValue: { document_ += "["; int size = value.size(); for (int index = 0; index < size; ++index) { if (index > 0) document_ += ","; writeValue(value[index]); } document_ += "]"; } break; case objectValue: { Value::Members members(value.getMemberNames()); document_ += "{"; for (Value::Members::iterator it = members.begin(); it != members.end(); ++it) { const std::string &name = *it; if (it != members.begin()) document_ += ","; document_ += valueToQuotedString(name.c_str()); document_ += yamlCompatiblityEnabled_ ? ": " : ":"; writeValue(value[name]); } document_ += "}"; } break; } } // Class StyledWriter // ////////////////////////////////////////////////////////////////// StyledWriter::StyledWriter() : rightMargin_(74), indentSize_(3), addChildValues_() {} std::string StyledWriter::write(const Value &root) { document_ = ""; addChildValues_ = false; indentString_ = ""; writeCommentBeforeValue(root); writeValue(root); writeCommentAfterValueOnSameLine(root); document_ += "\n"; return document_; } void StyledWriter::writeValue(const Value &value) { switch (value.type()) { case nullValue: pushValue("null"); break; case intValue: pushValue(valueToString(value.asLargestInt())); break; case uintValue: pushValue(valueToString(value.asLargestUInt())); break; case realValue: pushValue(valueToString(value.asDouble())); break; case stringValue: pushValue(valueToQuotedString(value.asCString())); break; case booleanValue: pushValue(valueToString(value.asBool())); break; case arrayValue: writeArrayValue(value); break; case objectValue: { Value::Members members(value.getMemberNames()); if (members.empty()) pushValue("{}"); else { writeWithIndent("{"); indent(); Value::Members::iterator it = members.begin(); for (;;) { const std::string &name = *it; const Value &childValue = value[name]; writeCommentBeforeValue(childValue); writeWithIndent(valueToQuotedString(name.c_str())); document_ += " : "; writeValue(childValue); if (++it == members.end()) { writeCommentAfterValueOnSameLine(childValue); break; } document_ += ","; writeCommentAfterValueOnSameLine(childValue); } unindent(); writeWithIndent("}"); } } break; } } void StyledWriter::writeArrayValue(const Value &value) { unsigned size = value.size(); if (size == 0) pushValue("[]"); else { bool isArrayMultiLine = isMultineArray(value); if (isArrayMultiLine) { writeWithIndent("["); indent(); bool hasChildValue = !childValues_.empty(); unsigned index = 0; for (;;) { const Value &childValue = value[index]; writeCommentBeforeValue(childValue); if (hasChildValue) writeWithIndent(childValues_[index]); else { writeIndent(); writeValue(childValue); } if (++index == size) { writeCommentAfterValueOnSameLine(childValue); break; } document_ += ","; writeCommentAfterValueOnSameLine(childValue); } unindent(); writeWithIndent("]"); } else // output on a single line { assert(childValues_.size() == size); document_ += "[ "; for (unsigned index = 0; index < size; ++index) { if (index > 0) document_ += ", "; document_ += childValues_[index]; } document_ += " ]"; } } } bool StyledWriter::isMultineArray(const Value &value) { int size = value.size(); bool isMultiLine = size * 3 >= rightMargin_; childValues_.clear(); for (int index = 0; index < size && !isMultiLine; ++index) { const Value &childValue = value[index]; isMultiLine = isMultiLine || ((childValue.isArray() || childValue.isObject()) && childValue.size() > 0); } if (!isMultiLine) // check if line length > max line length { childValues_.reserve(size); addChildValues_ = true; int lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]' for (int index = 0; index < size && !isMultiLine; ++index) { writeValue(value[index]); lineLength += int(childValues_[index].length()); isMultiLine = isMultiLine && hasCommentForValue(value[index]); } addChildValues_ = false; isMultiLine = isMultiLine || lineLength >= rightMargin_; } return isMultiLine; } void StyledWriter::pushValue(const std::string &value) { if (addChildValues_) childValues_.push_back(value); else document_ += value; } void StyledWriter::writeIndent() { if (!document_.empty()) { char last = document_[document_.length() - 1]; if (last == ' ') // already indented return; if (last != '\n') // Comments may add new-line document_ += '\n'; } document_ += indentString_; } void StyledWriter::writeWithIndent(const std::string &value) { writeIndent(); document_ += value; } void StyledWriter::indent() { indentString_ += std::string(indentSize_, ' '); } void StyledWriter::unindent() { assert(int(indentString_.size()) >= indentSize_); indentString_.resize(indentString_.size() - indentSize_); } void StyledWriter::writeCommentBeforeValue(const Value &root) { if (!root.hasComment(commentBefore)) return; document_ += "\n"; writeIndent(); std::string normalizedComment = normalizeEOL(root.getComment(commentBefore)); std::string::const_iterator iter = normalizedComment.begin(); while (iter != normalizedComment.end()) { document_ += *iter; if (*iter == '\n' && *(iter + 1) == '/') writeIndent(); ++iter; } // Comments are stripped of newlines, so add one here document_ += "\n"; } void StyledWriter::writeCommentAfterValueOnSameLine(const Value &root) { if (root.hasComment(commentAfterOnSameLine)) document_ += " " + normalizeEOL(root.getComment(commentAfterOnSameLine)); if (root.hasComment(commentAfter)) { document_ += "\n"; document_ += normalizeEOL(root.getComment(commentAfter)); document_ += "\n"; } } bool StyledWriter::hasCommentForValue(const Value &value) { return value.hasComment(commentBefore) || value.hasComment(commentAfterOnSameLine) || value.hasComment(commentAfter); } std::string StyledWriter::normalizeEOL(const std::string &text) { std::string normalized; normalized.reserve(text.length()); const char *begin = text.c_str(); const char *end = begin + text.length(); const char *current = begin; while (current != end) { char c = *current++; if (c == '\r') // mac or dos EOL { if (*current == '\n') // convert dos EOL ++current; normalized += '\n'; } else // handle unix EOL & other char normalized += c; } return normalized; } // Class StyledStreamWriter // ////////////////////////////////////////////////////////////////// StyledStreamWriter::StyledStreamWriter(std::string indentation) : document_(NULL), rightMargin_(74), indentation_(indentation), addChildValues_() {} void StyledStreamWriter::write(std::ostream &out, const Value &root) { document_ = &out; addChildValues_ = false; indentString_ = ""; writeCommentBeforeValue(root); writeValue(root); writeCommentAfterValueOnSameLine(root); *document_ << "\n"; document_ = NULL; // Forget the stream, for safety. } void StyledStreamWriter::writeValue(const Value &value) { switch (value.type()) { case nullValue: pushValue("null"); break; case intValue: pushValue(valueToString(value.asLargestInt())); break; case uintValue: pushValue(valueToString(value.asLargestUInt())); break; case realValue: pushValue(valueToString(value.asDouble())); break; case stringValue: pushValue(valueToQuotedString(value.asCString())); break; case booleanValue: pushValue(valueToString(value.asBool())); break; case arrayValue: writeArrayValue(value); break; case objectValue: { Value::Members members(value.getMemberNames()); if (members.empty()) pushValue("{}"); else { writeWithIndent("{"); indent(); Value::Members::iterator it = members.begin(); for (;;) { const std::string &name = *it; const Value &childValue = value[name]; writeCommentBeforeValue(childValue); writeWithIndent(valueToQuotedString(name.c_str())); *document_ << " : "; writeValue(childValue); if (++it == members.end()) { writeCommentAfterValueOnSameLine(childValue); break; } *document_ << ","; writeCommentAfterValueOnSameLine(childValue); } unindent(); writeWithIndent("}"); } } break; } } void StyledStreamWriter::writeArrayValue(const Value &value) { unsigned size = value.size(); if (size == 0) pushValue("[]"); else { bool isArrayMultiLine = isMultineArray(value); if (isArrayMultiLine) { writeWithIndent("["); indent(); bool hasChildValue = !childValues_.empty(); unsigned index = 0; for (;;) { const Value &childValue = value[index]; writeCommentBeforeValue(childValue); if (hasChildValue) writeWithIndent(childValues_[index]); else { writeIndent(); writeValue(childValue); } if (++index == size) { writeCommentAfterValueOnSameLine(childValue); break; } *document_ << ","; writeCommentAfterValueOnSameLine(childValue); } unindent(); writeWithIndent("]"); } else // output on a single line { assert(childValues_.size() == size); *document_ << "[ "; for (unsigned index = 0; index < size; ++index) { if (index > 0) *document_ << ", "; *document_ << childValues_[index]; } *document_ << " ]"; } } } bool StyledStreamWriter::isMultineArray(const Value &value) { int size = value.size(); bool isMultiLine = size * 3 >= rightMargin_; childValues_.clear(); for (int index = 0; index < size && !isMultiLine; ++index) { const Value &childValue = value[index]; isMultiLine = isMultiLine || ((childValue.isArray() || childValue.isObject()) && childValue.size() > 0); } if (!isMultiLine) // check if line length > max line length { childValues_.reserve(size); addChildValues_ = true; int lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]' for (int index = 0; index < size && !isMultiLine; ++index) { writeValue(value[index]); lineLength += int(childValues_[index].length()); isMultiLine = isMultiLine && hasCommentForValue(value[index]); } addChildValues_ = false; isMultiLine = isMultiLine || lineLength >= rightMargin_; } return isMultiLine; } void StyledStreamWriter::pushValue(const std::string &value) { if (addChildValues_) childValues_.push_back(value); else *document_ << value; } void StyledStreamWriter::writeIndent() { /* Some comments in this method would have been nice. ;-) if ( !document_.empty() ) { char last = document_[document_.length()-1]; if ( last == ' ' ) // already indented return; if ( last != '\n' ) // Comments may add new-line *document_ << '\n'; } */ *document_ << '\n' << indentString_; } void StyledStreamWriter::writeWithIndent(const std::string &value) { writeIndent(); *document_ << value; } void StyledStreamWriter::indent() { indentString_ += indentation_; } void StyledStreamWriter::unindent() { assert(indentString_.size() >= indentation_.size()); indentString_.resize(indentString_.size() - indentation_.size()); } void StyledStreamWriter::writeCommentBeforeValue(const Value &root) { if (!root.hasComment(commentBefore)) return; *document_ << normalizeEOL(root.getComment(commentBefore)); *document_ << "\n"; } void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value &root) { if (root.hasComment(commentAfterOnSameLine)) *document_ << " " + normalizeEOL(root.getComment(commentAfterOnSameLine)); if (root.hasComment(commentAfter)) { *document_ << "\n"; *document_ << normalizeEOL(root.getComment(commentAfter)); *document_ << "\n"; } } bool StyledStreamWriter::hasCommentForValue(const Value &value) { return value.hasComment(commentBefore) || value.hasComment(commentAfterOnSameLine) || value.hasComment(commentAfter); } std::string StyledStreamWriter::normalizeEOL(const std::string &text) { std::string normalized; normalized.reserve(text.length()); const char *begin = text.c_str(); const char *end = begin + text.length(); const char *current = begin; while (current != end) { char c = *current++; if (c == '\r') // mac or dos EOL { if (*current == '\n') // convert dos EOL ++current; normalized += '\n'; } else // handle unix EOL & other char normalized += c; } return normalized; } std::ostream &operator<<(std::ostream &sout, const Value &root) { Json::StyledStreamWriter writer; writer.write(sout, root); return sout; } } // namespace Json // vim: et ts=3 sts=3 sw=3 tw=0
############################################################################### # 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 4, 0x90 .globl p8_add_192 .type p8_add_192, @function p8_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 p8_add_192, .Lfe1-(p8_add_192) .p2align 4, 0x90 .globl p8_sub_192 .type p8_sub_192, @function p8_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 p8_sub_192, .Lfe2-(p8_sub_192) .p2align 4, 0x90 .globl p8_shl_192 .type p8_shl_192, @function p8_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 p8_shl_192, .Lfe3-(p8_shl_192) .p2align 4, 0x90 .globl p8_shr_192 .type p8_shr_192, @function p8_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 p8_shr_192, .Lfe4-(p8_shr_192) .p2align 4, 0x90 .globl p8_p192r1_add .type p8_p192r1_add, @function p8_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 p8_add_192 mov %eax, %edx lea (%esp), %edi movl (8)(%ebp), %esi call .L__0000gas_5 .L__0000gas_5: pop %ebx sub $(.L__0000gas_5-p192r1_data), %ebx lea ((_prime192r1-p192r1_data))(%ebx), %ebx call p8_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 p8_p192r1_add, .Lfe5-(p8_p192r1_add) .p2align 4, 0x90 .globl p8_p192r1_sub .type p8_p192r1_sub, @function p8_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 p8_sub_192 mov %eax, %edx lea (%esp), %edi movl (8)(%ebp), %esi call .L__0001gas_6 .L__0001gas_6: pop %ebx sub $(.L__0001gas_6-p192r1_data), %ebx lea ((_prime192r1-p192r1_data))(%ebx), %ebx call p8_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 p8_p192r1_sub, .Lfe6-(p8_p192r1_sub) .p2align 4, 0x90 .globl p8_p192r1_neg .type p8_p192r1_neg, @function p8_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 call .L__0002gas_7 .L__0002gas_7: pop %ebx sub $(.L__0002gas_7-p192r1_data), %ebx lea ((_prime192r1-p192r1_data))(%ebx), %ebx call p8_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 p8_p192r1_neg, .Lfe7-(p8_p192r1_neg) .p2align 4, 0x90 .globl p8_p192r1_mul_by_2 .type p8_p192r1_mul_by_2, @function p8_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 p8_shl_192 mov %eax, %edx mov %edi, %esi movl (8)(%ebp), %edi call .L__0003gas_8 .L__0003gas_8: pop %ebx sub $(.L__0003gas_8-p192r1_data), %ebx lea ((_prime192r1-p192r1_data))(%ebx), %ebx call p8_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 p8_p192r1_mul_by_2, .Lfe8-(p8_p192r1_mul_by_2) .p2align 4, 0x90 .globl p8_p192r1_mul_by_3 .type p8_p192r1_mul_by_3, @function p8_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) call .L__0004gas_9 .L__0004gas_9: pop %eax sub $(.L__0004gas_9-p192r1_data), %eax lea ((_prime192r1-p192r1_data))(%eax), %eax movl %eax, (48)(%esp) lea (%esp), %edi movl (12)(%ebp), %esi call p8_shl_192 mov %eax, %edx mov %edi, %esi lea (24)(%esp), %edi mov (48)(%esp), %ebx call p8_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 p8_add_192 mov %eax, %edx movl (8)(%ebp), %edi mov (48)(%esp), %ebx call p8_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 p8_p192r1_mul_by_3, .Lfe9-(p8_p192r1_mul_by_3) .p2align 4, 0x90 .globl p8_p192r1_div_by_2 .type p8_p192r1_div_by_2, @function p8_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 call .L__0005gas_10 .L__0005gas_10: pop %ebx sub $(.L__0005gas_10-p192r1_data), %ebx lea ((_prime192r1-p192r1_data))(%ebx), %ebx call p8_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 p8_shr_192 mov (24)(%esp), %esp pop %edi pop %esi pop %ebx pop %ebp ret .Lfe10: .size p8_p192r1_div_by_2, .Lfe10-(p8_p192r1_div_by_2) .p2align 4, 0x90 .globl p8_p192r1_mul_mont_slm .type p8_p192r1_mul_mont_slm, @function p8_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 4, 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 call .L__0006gas_11 .L__0006gas_11: pop %ebx sub $(.L__0006gas_11-p192r1_data), %ebx lea ((_prime192r1-p192r1_data))(%ebx), %ebx call p8_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 p8_p192r1_mul_mont_slm, .Lfe11-(p8_p192r1_mul_mont_slm) .p2align 4, 0x90 .globl p8_p192r1_sqr_mont_slm .type p8_p192r1_sqr_mont_slm, @function p8_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 p8_p192r1_mul_mont_slm add $(12), %esp pop %edi pop %esi pop %ebp ret .Lfe12: .size p8_p192r1_sqr_mont_slm, .Lfe12-(p8_p192r1_sqr_mont_slm) .p2align 4, 0x90 .globl p8_p192r1_mred .type p8_p192r1_mred, @function p8_p192r1_mred: push %ebp mov %esp, %ebp push %ebx push %esi push %edi movl (12)(%ebp), %esi mov $(6), %ecx xor %edx, %edx .p2align 4, 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 call .L__0007gas_13 .L__0007gas_13: pop %ebx sub $(.L__0007gas_13-p192r1_data), %ebx lea ((_prime192r1-p192r1_data))(%ebx), %ebx call p8_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 p8_p192r1_mred, .Lfe13-(p8_p192r1_mred) .p2align 4, 0x90 .globl p8_p192r1_select_pp_w5 .type p8_p192r1_select_pp_w5, @function p8_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 4, 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 p8_p192r1_select_pp_w5, .Lfe14-(p8_p192r1_select_pp_w5)
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation; * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author: Shih-Hao Tseng (st688@cornell.edu) */ #include "settings/common_settings.h" #include "settings/fig/fig_main_measure.h" #include "settings/topology/Internet2.cc_part" #include <math.h> // testing coding NS_LOG_COMPONENT_DEFINE ("Internet2BulkVaryDst"); int main (int argc, char *argv[]) { double APP_STOP_TIME = SIMULATION_HORIZON; int total_num_destinations = 1; CommandLine cmd; cmd.AddValue ("d", "number of destinations", total_num_destinations); cmd.Parse (argc, argv); std::string sim_name = "Internet2-dst"; std::stringstream sim_serial; sim_serial << "-" << total_num_destinations; #include "settings/fig/fig_file.cc_part" #include "settings/traffic/traffic_setup.cc_part" int TOTAL_NUM_TRAFFIC = 6; std::cout << "Total number of multicast destinations = " << total_num_destinations << std::endl; #include "settings/fig/fig_main.cc_part" return 0; }
; A239462: A239459(n) / n. ; 11,41,91,161,251,361,491,641,811,10001,12101,14401,16901,19601,22501,25601,28901,32401,36101,40001,44101,48401,52901,57601,62501,67601,72901,78401,84101,90001,96101,102401,108901,115601,122501,129601,136901,144401,152101,160001,168101,176401,184901,193601,202501,211601,220901,230401,240101,250001,260101,270401,280901,291601,302501,313601,324901,336401,348101,360001,372101,384401,396901,409601,422501,435601,448901,462401,476101,490001,504101,518401,532901,547601,562501,577601,592901,608401 add $0,1 mov $1,$0 pow $1,2 lpb $0 div $0,10 mul $1,10 lpe mov $0,$1 add $0,1
; get_str3 ; get ONE string from the basic interpreter updating A3 ; entry exit ; d0 0 or error ; a1 top of math stack pointer to string on math stack ; a3 ptr to start of parameter updated to point to next parameter ; a5 ptr to end of all parameters preserved ; ; all other registers presered section procs xdef get_str include dev8_keys_sbasic include dev8_keys_qlv include dev8_keys_err myregs2 reg d1-d4/d6/d7/a0/a2/a5 get_str movem.l myregs2,-(a7) moveq #0,d0 ; no string yet cmp.l a3,a5 ; any param at all? beq.s err ; no-> move.b 1(a6,a3.l),d0 ; type of parameter andi.b #$f,d0 subq.b #1,d0 ; was it a string? beq.s is_str ; yes, get it move.l d0,d7 ; zero upper word of d7 move.w 2(a6,a3.l),d7 ; point to name table lsl.l #3,d7 ; * 8 (eight bytes per entry) add.l sb_nmtbb(a6),d7 ; add offset move.w 2(a6,d7.l),a0 ; point to value now add.l sb_nmlsb(a6),a0 ; add offset moveq #0,d1 move.b (a6,a0.l),d1 ; length of string move.l d1,d7 ; keep addq.w #3,d1 bclr #0,d1 ; add length word & make even move.l a0,d6 ; keep move.w qa.resri,a2 jsr (a2) ; get space on ari stack move.l sb_arthp(a6),a1 , point to top of ari stack move.l d6,a0 ; pointer to string move.w d7,(a6,a1.l) ; set length beq.s ok ; no length, done addq.l #2,a1 ; point first char subq.l #1,d7 ; dbf loop addq.l #1,a0 ; point next char move.b (a6,a0.l),(a6,a1.l) ; transfer it addq.l #1,a1 ; space for next char dbf d7,loop move.l sb_arthp(a6),a1 bra.s ok err moveq #err.ipar,d0 bra.s out is_str lea 8(a3),a5 ; point to end of this param move.w sb.gtstr,a2 move.w (a6,a3.l),d7 ; keep type word! jsr (a2) ; get string move.w d7,(a6,a3.l) subq.w #1,d3 ; one string param bne.s err ; ooops moveq #0,d1 move.w (a6,a1.l),d1 addq.w #3,d1 bclr #0,d1 add.l d1,sb_arthp(a6) ok moveq #0,d0 out movem.l (a7)+,myregs2 rts end
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r11 push %r12 push %r13 push %r14 push %r9 push %rcx push %rdi push %rsi lea addresses_D_ht+0x11157, %r12 clflush (%r12) nop nop nop nop xor $60645, %r14 movups (%r12), %xmm2 vpextrq $0, %xmm2, %r10 and %r10, %r10 lea addresses_WC_ht+0x1099b, %r13 nop nop nop nop mfence mov $0x6162636465666768, %rsi movq %rsi, %xmm6 vmovups %ymm6, (%r13) nop xor $19296, %r12 lea addresses_WT_ht+0x1aadb, %rsi nop nop nop nop nop dec %r11 movw $0x6162, (%rsi) nop nop nop nop nop cmp %r12, %r12 lea addresses_UC_ht+0x181b, %r9 clflush (%r9) nop dec %r14 movl $0x61626364, (%r9) nop and %r9, %r9 lea addresses_A_ht+0x774b, %r11 nop nop nop sub $58693, %r9 mov $0x6162636465666768, %r13 movq %r13, %xmm6 movups %xmm6, (%r11) nop nop nop cmp %r10, %r10 lea addresses_D_ht+0xd07b, %rsi lea addresses_UC_ht+0x1c33b, %rdi nop cmp %r9, %r9 mov $19, %rcx rep movsq xor $12504, %r10 lea addresses_WC_ht+0x1db53, %rsi lea addresses_normal_ht+0x1ac9b, %rdi nop nop nop nop add %r12, %r12 mov $81, %rcx rep movsw nop nop nop nop cmp %rsi, %rsi lea addresses_normal_ht+0x1649b, %rdi nop nop nop and $462, %r10 movl $0x61626364, (%rdi) nop nop nop nop nop add $4632, %r11 lea addresses_UC_ht+0xaa9b, %rsi lea addresses_UC_ht+0x1989b, %rdi nop nop nop nop nop cmp %r10, %r10 mov $36, %rcx rep movsw nop nop nop nop xor %rdi, %rdi lea addresses_D_ht+0x12fb, %r12 nop cmp %r14, %r14 movb (%r12), %cl nop nop nop inc %r12 pop %rsi pop %rdi pop %rcx pop %r9 pop %r14 pop %r13 pop %r12 pop %r11 pop %r10 ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %r14 push %r15 push %r9 push %rdi push %rdx // Load lea addresses_WC+0x279b, %r11 nop nop nop nop add %r15, %r15 mov (%r11), %r9 nop nop add %r15, %r15 // Load lea addresses_US+0x1c06f, %r14 nop nop nop nop cmp $40317, %rdi mov (%r14), %r15w nop nop dec %rdx // Load lea addresses_PSE+0x1a1fb, %r11 clflush (%r11) nop nop nop nop add %r15, %r15 movups (%r11), %xmm4 vpextrq $1, %xmm4, %r14 nop nop xor %rdi, %rdi // Store lea addresses_RW+0x1449b, %r9 nop nop nop add %rdi, %rdi movl $0x51525354, (%r9) xor %r15, %r15 // Store lea addresses_A+0x1aa1b, %r12 nop nop xor %r15, %r15 movb $0x51, (%r12) nop and $50402, %r11 // Faulty Load lea addresses_US+0x17c9b, %r15 nop nop nop nop nop sub $43501, %r11 mov (%r15), %r12w lea oracles, %r14 and $0xff, %r12 shlq $12, %r12 mov (%r14,%r12,1), %r12 pop %rdx pop %rdi pop %r9 pop %r15 pop %r14 pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_US', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WC', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_US', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_RW', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_US', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 5, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 8, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 11, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 10, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}} {'00': 18015} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
/* Copyright (C) 2016 The Android Open Source Project * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This file implements interfaces from the file jvmti.h. This implementation * is licensed under the same terms as the file jvmti.h. The * copyright and license information for the file jvmti.h follows. * * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code 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 General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ #include <memory> #include <string> #include <type_traits> #include <vector> #include <android-base/logging.h> #include <jni.h> #include "jvmti.h" #include "art_jvmti.h" #include "base/logging.h" // For gLogVerbosity. #include "base/mutex.h" #include "events-inl.h" #include "jni/jni_env_ext-inl.h" #include "obj_ptr-inl.h" #include "object_tagging.h" #include "runtime.h" #include "scoped_thread_state_change-inl.h" #include "thread-current-inl.h" #include "thread_list.h" #include "ti_allocator.h" #include "ti_breakpoint.h" #include "ti_class.h" #include "ti_dump.h" #include "ti_extension.h" #include "ti_field.h" #include "ti_heap.h" #include "ti_jni.h" #include "ti_logging.h" #include "ti_method.h" #include "ti_monitor.h" #include "ti_object.h" #include "ti_phase.h" #include "ti_properties.h" #include "ti_redefine.h" #include "ti_search.h" #include "ti_stack.h" #include "ti_thread.h" #include "ti_threadgroup.h" #include "ti_timers.h" #include "transform.h" namespace openjdkjvmti { // NB These are heap allocated to avoid the static destructors being run if an agent calls exit(3). // These should never be null. EventHandler* gEventHandler; DeoptManager* gDeoptManager; #define ENSURE_NON_NULL(n) \ do { \ if ((n) == nullptr) { \ return ERR(NULL_POINTER); \ } \ } while (false) // Returns whether we are able to use all jvmti features. static bool IsFullJvmtiAvailable() { art::Runtime* runtime = art::Runtime::Current(); return runtime->GetInstrumentation()->IsForcedInterpretOnly() || runtime->IsJavaDebuggable(); } class JvmtiFunctions { private: static jvmtiError getEnvironmentError(jvmtiEnv* env) { if (env == nullptr) { return ERR(INVALID_ENVIRONMENT); } else if (art::Thread::Current() == nullptr) { return ERR(UNATTACHED_THREAD); } else { return OK; } } #define ENSURE_VALID_ENV(env) \ do { \ jvmtiError ensure_valid_env_ ## __LINE__ = getEnvironmentError(env); \ if (ensure_valid_env_ ## __LINE__ != OK) { \ return ensure_valid_env_ ## __LINE__ ; \ } \ } while (false) #define ENSURE_HAS_CAP(env, cap) \ do { \ if (ArtJvmTiEnv::AsArtJvmTiEnv(env)->capabilities.cap != 1) { \ return ERR(MUST_POSSESS_CAPABILITY); \ } \ } while (false) public: static jvmtiError Allocate(jvmtiEnv* env, jlong size, unsigned char** mem_ptr) { jvmtiError err = getEnvironmentError(env); // Allow UNATTACHED_THREAD since we don't really care about that for this function. if (err != OK && err != ERR(UNATTACHED_THREAD)) { return err; } ENSURE_NON_NULL(mem_ptr); return AllocUtil::Allocate(env, size, mem_ptr); } static jvmtiError Deallocate(jvmtiEnv* env, unsigned char* mem) { jvmtiError err = getEnvironmentError(env); // Allow UNATTACHED_THREAD since we don't really care about that for this function. if (err != OK && err != ERR(UNATTACHED_THREAD)) { return err; } return AllocUtil::Deallocate(env, mem); } static jvmtiError GetThreadState(jvmtiEnv* env, jthread thread, jint* thread_state_ptr) { ENSURE_VALID_ENV(env); return ThreadUtil::GetThreadState(env, thread, thread_state_ptr); } static jvmtiError GetCurrentThread(jvmtiEnv* env, jthread* thread_ptr) { ENSURE_VALID_ENV(env); return ThreadUtil::GetCurrentThread(env, thread_ptr); } static jvmtiError GetAllThreads(jvmtiEnv* env, jint* threads_count_ptr, jthread** threads_ptr) { ENSURE_VALID_ENV(env); return ThreadUtil::GetAllThreads(env, threads_count_ptr, threads_ptr); } static jvmtiError SuspendThread(jvmtiEnv* env, jthread thread) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_suspend); return ThreadUtil::SuspendThread(env, thread); } static jvmtiError SuspendThreadList(jvmtiEnv* env, jint request_count, const jthread* request_list, jvmtiError* results) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_suspend); return ThreadUtil::SuspendThreadList(env, request_count, request_list, results); } static jvmtiError ResumeThread(jvmtiEnv* env, jthread thread) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_suspend); return ThreadUtil::ResumeThread(env, thread); } static jvmtiError ResumeThreadList(jvmtiEnv* env, jint request_count, const jthread* request_list, jvmtiError* results) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_suspend); return ThreadUtil::ResumeThreadList(env, request_count, request_list, results); } static jvmtiError StopThread(jvmtiEnv* env, jthread thread, jobject exception) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_signal_thread); return ThreadUtil::StopThread(env, thread, exception); } static jvmtiError InterruptThread(jvmtiEnv* env, jthread thread) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_signal_thread); return ThreadUtil::InterruptThread(env, thread); } static jvmtiError GetThreadInfo(jvmtiEnv* env, jthread thread, jvmtiThreadInfo* info_ptr) { ENSURE_VALID_ENV(env); return ThreadUtil::GetThreadInfo(env, thread, info_ptr); } static jvmtiError GetOwnedMonitorInfo(jvmtiEnv* env, jthread thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_get_owned_monitor_info); return StackUtil::GetOwnedMonitorInfo(env, thread, owned_monitor_count_ptr, owned_monitors_ptr); } static jvmtiError GetOwnedMonitorStackDepthInfo(jvmtiEnv* env, jthread thread, jint* monitor_info_count_ptr, jvmtiMonitorStackDepthInfo** monitor_info_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_get_owned_monitor_stack_depth_info); return StackUtil::GetOwnedMonitorStackDepthInfo(env, thread, monitor_info_count_ptr, monitor_info_ptr); } static jvmtiError GetCurrentContendedMonitor(jvmtiEnv* env, jthread thread, jobject* monitor_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_get_current_contended_monitor); return MonitorUtil::GetCurrentContendedMonitor(env, thread, monitor_ptr); } static jvmtiError RunAgentThread(jvmtiEnv* env, jthread thread, jvmtiStartFunction proc, const void* arg, jint priority) { ENSURE_VALID_ENV(env); return ThreadUtil::RunAgentThread(env, thread, proc, arg, priority); } static jvmtiError SetThreadLocalStorage(jvmtiEnv* env, jthread thread, const void* data) { ENSURE_VALID_ENV(env); return ThreadUtil::SetThreadLocalStorage(env, thread, data); } static jvmtiError GetThreadLocalStorage(jvmtiEnv* env, jthread thread, void** data_ptr) { ENSURE_VALID_ENV(env); return ThreadUtil::GetThreadLocalStorage(env, thread, data_ptr); } static jvmtiError GetTopThreadGroups(jvmtiEnv* env, jint* group_count_ptr, jthreadGroup** groups_ptr) { ENSURE_VALID_ENV(env); return ThreadGroupUtil::GetTopThreadGroups(env, group_count_ptr, groups_ptr); } static jvmtiError GetThreadGroupInfo(jvmtiEnv* env, jthreadGroup group, jvmtiThreadGroupInfo* info_ptr) { ENSURE_VALID_ENV(env); return ThreadGroupUtil::GetThreadGroupInfo(env, group, info_ptr); } static jvmtiError GetThreadGroupChildren(jvmtiEnv* env, jthreadGroup group, jint* thread_count_ptr, jthread** threads_ptr, jint* group_count_ptr, jthreadGroup** groups_ptr) { ENSURE_VALID_ENV(env); return ThreadGroupUtil::GetThreadGroupChildren(env, group, thread_count_ptr, threads_ptr, group_count_ptr, groups_ptr); } static jvmtiError GetStackTrace(jvmtiEnv* env, jthread thread, jint start_depth, jint max_frame_count, jvmtiFrameInfo* frame_buffer, jint* count_ptr) { ENSURE_VALID_ENV(env); return StackUtil::GetStackTrace(env, thread, start_depth, max_frame_count, frame_buffer, count_ptr); } static jvmtiError GetAllStackTraces(jvmtiEnv* env, jint max_frame_count, jvmtiStackInfo** stack_info_ptr, jint* thread_count_ptr) { ENSURE_VALID_ENV(env); return StackUtil::GetAllStackTraces(env, max_frame_count, stack_info_ptr, thread_count_ptr); } static jvmtiError GetThreadListStackTraces(jvmtiEnv* env, jint thread_count, const jthread* thread_list, jint max_frame_count, jvmtiStackInfo** stack_info_ptr) { ENSURE_VALID_ENV(env); return StackUtil::GetThreadListStackTraces(env, thread_count, thread_list, max_frame_count, stack_info_ptr); } static jvmtiError GetFrameCount(jvmtiEnv* env, jthread thread, jint* count_ptr) { ENSURE_VALID_ENV(env); return StackUtil::GetFrameCount(env, thread, count_ptr); } static jvmtiError PopFrame(jvmtiEnv* env, jthread thread) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_pop_frame); return StackUtil::PopFrame(env, thread); } static jvmtiError GetFrameLocation(jvmtiEnv* env, jthread thread, jint depth, jmethodID* method_ptr, jlocation* location_ptr) { ENSURE_VALID_ENV(env); return StackUtil::GetFrameLocation(env, thread, depth, method_ptr, location_ptr); } static jvmtiError NotifyFramePop(jvmtiEnv* env, jthread thread, jint depth) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_generate_frame_pop_events); return StackUtil::NotifyFramePop(env, thread, depth); } static jvmtiError ForceEarlyReturnObject(jvmtiEnv* env, jthread thread ATTRIBUTE_UNUSED, jobject value ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_force_early_return); return ERR(NOT_IMPLEMENTED); } static jvmtiError ForceEarlyReturnInt(jvmtiEnv* env, jthread thread ATTRIBUTE_UNUSED, jint value ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_force_early_return); return ERR(NOT_IMPLEMENTED); } static jvmtiError ForceEarlyReturnLong(jvmtiEnv* env, jthread thread ATTRIBUTE_UNUSED, jlong value ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_force_early_return); return ERR(NOT_IMPLEMENTED); } static jvmtiError ForceEarlyReturnFloat(jvmtiEnv* env, jthread thread ATTRIBUTE_UNUSED, jfloat value ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_force_early_return); return ERR(NOT_IMPLEMENTED); } static jvmtiError ForceEarlyReturnDouble(jvmtiEnv* env, jthread thread ATTRIBUTE_UNUSED, jdouble value ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_force_early_return); return ERR(NOT_IMPLEMENTED); } static jvmtiError ForceEarlyReturnVoid(jvmtiEnv* env, jthread thread ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_force_early_return); return ERR(NOT_IMPLEMENTED); } static jvmtiError FollowReferences(jvmtiEnv* env, jint heap_filter, jclass klass, jobject initial_object, const jvmtiHeapCallbacks* callbacks, const void* user_data) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_tag_objects); HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get()); return heap_util.FollowReferences(env, heap_filter, klass, initial_object, callbacks, user_data); } static jvmtiError IterateThroughHeap(jvmtiEnv* env, jint heap_filter, jclass klass, const jvmtiHeapCallbacks* callbacks, const void* user_data) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_tag_objects); HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get()); return heap_util.IterateThroughHeap(env, heap_filter, klass, callbacks, user_data); } static jvmtiError GetTag(jvmtiEnv* env, jobject object, jlong* tag_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_tag_objects); JNIEnv* jni_env = GetJniEnv(env); if (jni_env == nullptr) { return ERR(INTERNAL); } art::ScopedObjectAccess soa(jni_env); art::ObjPtr<art::mirror::Object> obj = soa.Decode<art::mirror::Object>(object); if (!ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table->GetTag(obj.Ptr(), tag_ptr)) { *tag_ptr = 0; } return ERR(NONE); } static jvmtiError SetTag(jvmtiEnv* env, jobject object, jlong tag) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_tag_objects); if (object == nullptr) { return ERR(NULL_POINTER); } JNIEnv* jni_env = GetJniEnv(env); if (jni_env == nullptr) { return ERR(INTERNAL); } art::ScopedObjectAccess soa(jni_env); art::ObjPtr<art::mirror::Object> obj = soa.Decode<art::mirror::Object>(object); ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table->Set(obj.Ptr(), tag); return ERR(NONE); } static jvmtiError GetObjectsWithTags(jvmtiEnv* env, jint tag_count, const jlong* tags, jint* count_ptr, jobject** object_result_ptr, jlong** tag_result_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_tag_objects); JNIEnv* jni_env = GetJniEnv(env); if (jni_env == nullptr) { return ERR(INTERNAL); } art::ScopedObjectAccess soa(jni_env); return ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table->GetTaggedObjects(env, tag_count, tags, count_ptr, object_result_ptr, tag_result_ptr); } static jvmtiError ForceGarbageCollection(jvmtiEnv* env) { ENSURE_VALID_ENV(env); return HeapUtil::ForceGarbageCollection(env); } static jvmtiError IterateOverObjectsReachableFromObject( jvmtiEnv* env, jobject object ATTRIBUTE_UNUSED, jvmtiObjectReferenceCallback object_reference_callback ATTRIBUTE_UNUSED, const void* user_data ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_tag_objects); return ERR(NOT_IMPLEMENTED); } static jvmtiError IterateOverReachableObjects( jvmtiEnv* env, jvmtiHeapRootCallback heap_root_callback ATTRIBUTE_UNUSED, jvmtiStackReferenceCallback stack_ref_callback ATTRIBUTE_UNUSED, jvmtiObjectReferenceCallback object_ref_callback ATTRIBUTE_UNUSED, const void* user_data ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_tag_objects); return ERR(NOT_IMPLEMENTED); } static jvmtiError IterateOverHeap(jvmtiEnv* env, jvmtiHeapObjectFilter object_filter ATTRIBUTE_UNUSED, jvmtiHeapObjectCallback heap_object_callback ATTRIBUTE_UNUSED, const void* user_data ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_tag_objects); return ERR(NOT_IMPLEMENTED); } static jvmtiError IterateOverInstancesOfClass( jvmtiEnv* env, jclass klass, jvmtiHeapObjectFilter object_filter, jvmtiHeapObjectCallback heap_object_callback, const void* user_data) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_tag_objects); HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get()); return heap_util.IterateOverInstancesOfClass( env, klass, object_filter, heap_object_callback, user_data); } static jvmtiError GetLocalObject(jvmtiEnv* env, jthread thread, jint depth, jint slot, jobject* value_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_access_local_variables); return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr); } static jvmtiError GetLocalInstance(jvmtiEnv* env, jthread thread, jint depth, jobject* value_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_access_local_variables); return MethodUtil::GetLocalInstance(env, thread, depth, value_ptr); } static jvmtiError GetLocalInt(jvmtiEnv* env, jthread thread, jint depth, jint slot, jint* value_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_access_local_variables); return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr); } static jvmtiError GetLocalLong(jvmtiEnv* env, jthread thread, jint depth, jint slot, jlong* value_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_access_local_variables); return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr); } static jvmtiError GetLocalFloat(jvmtiEnv* env, jthread thread, jint depth, jint slot, jfloat* value_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_access_local_variables); return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr); } static jvmtiError GetLocalDouble(jvmtiEnv* env, jthread thread, jint depth, jint slot, jdouble* value_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_access_local_variables); return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr); } static jvmtiError SetLocalObject(jvmtiEnv* env, jthread thread, jint depth, jint slot, jobject value) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_access_local_variables); return MethodUtil::SetLocalVariable(env, thread, depth, slot, value); } static jvmtiError SetLocalInt(jvmtiEnv* env, jthread thread, jint depth, jint slot, jint value) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_access_local_variables); return MethodUtil::SetLocalVariable(env, thread, depth, slot, value); } static jvmtiError SetLocalLong(jvmtiEnv* env, jthread thread, jint depth, jint slot, jlong value) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_access_local_variables); return MethodUtil::SetLocalVariable(env, thread, depth, slot, value); } static jvmtiError SetLocalFloat(jvmtiEnv* env, jthread thread, jint depth, jint slot, jfloat value) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_access_local_variables); return MethodUtil::SetLocalVariable(env, thread, depth, slot, value); } static jvmtiError SetLocalDouble(jvmtiEnv* env, jthread thread, jint depth, jint slot, jdouble value) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_access_local_variables); return MethodUtil::SetLocalVariable(env, thread, depth, slot, value); } static jvmtiError SetBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_generate_breakpoint_events); return BreakpointUtil::SetBreakpoint(env, method, location); } static jvmtiError ClearBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_generate_breakpoint_events); return BreakpointUtil::ClearBreakpoint(env, method, location); } static jvmtiError SetFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_generate_field_access_events); return FieldUtil::SetFieldAccessWatch(env, klass, field); } static jvmtiError ClearFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_generate_field_access_events); return FieldUtil::ClearFieldAccessWatch(env, klass, field); } static jvmtiError SetFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_generate_field_modification_events); return FieldUtil::SetFieldModificationWatch(env, klass, field); } static jvmtiError ClearFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_generate_field_modification_events); return FieldUtil::ClearFieldModificationWatch(env, klass, field); } static jvmtiError GetLoadedClasses(jvmtiEnv* env, jint* class_count_ptr, jclass** classes_ptr) { ENSURE_VALID_ENV(env); HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get()); return heap_util.GetLoadedClasses(env, class_count_ptr, classes_ptr); } static jvmtiError GetClassLoaderClasses(jvmtiEnv* env, jobject initiating_loader, jint* class_count_ptr, jclass** classes_ptr) { ENSURE_VALID_ENV(env); return ClassUtil::GetClassLoaderClasses(env, initiating_loader, class_count_ptr, classes_ptr); } static jvmtiError GetClassSignature(jvmtiEnv* env, jclass klass, char** signature_ptr, char** generic_ptr) { ENSURE_VALID_ENV(env); return ClassUtil::GetClassSignature(env, klass, signature_ptr, generic_ptr); } static jvmtiError GetClassStatus(jvmtiEnv* env, jclass klass, jint* status_ptr) { ENSURE_VALID_ENV(env); return ClassUtil::GetClassStatus(env, klass, status_ptr); } static jvmtiError GetSourceFileName(jvmtiEnv* env, jclass klass, char** source_name_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_get_source_file_name); return ClassUtil::GetSourceFileName(env, klass, source_name_ptr); } static jvmtiError GetClassModifiers(jvmtiEnv* env, jclass klass, jint* modifiers_ptr) { ENSURE_VALID_ENV(env); return ClassUtil::GetClassModifiers(env, klass, modifiers_ptr); } static jvmtiError GetClassMethods(jvmtiEnv* env, jclass klass, jint* method_count_ptr, jmethodID** methods_ptr) { ENSURE_VALID_ENV(env); return ClassUtil::GetClassMethods(env, klass, method_count_ptr, methods_ptr); } static jvmtiError GetClassFields(jvmtiEnv* env, jclass klass, jint* field_count_ptr, jfieldID** fields_ptr) { ENSURE_VALID_ENV(env); return ClassUtil::GetClassFields(env, klass, field_count_ptr, fields_ptr); } static jvmtiError GetImplementedInterfaces(jvmtiEnv* env, jclass klass, jint* interface_count_ptr, jclass** interfaces_ptr) { ENSURE_VALID_ENV(env); return ClassUtil::GetImplementedInterfaces(env, klass, interface_count_ptr, interfaces_ptr); } static jvmtiError GetClassVersionNumbers(jvmtiEnv* env, jclass klass, jint* minor_version_ptr, jint* major_version_ptr) { ENSURE_VALID_ENV(env); return ClassUtil::GetClassVersionNumbers(env, klass, minor_version_ptr, major_version_ptr); } static jvmtiError GetConstantPool(jvmtiEnv* env, jclass klass ATTRIBUTE_UNUSED, jint* constant_pool_count_ptr ATTRIBUTE_UNUSED, jint* constant_pool_byte_count_ptr ATTRIBUTE_UNUSED, unsigned char** constant_pool_bytes_ptr ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_get_constant_pool); return ERR(NOT_IMPLEMENTED); } static jvmtiError IsInterface(jvmtiEnv* env, jclass klass, jboolean* is_interface_ptr) { ENSURE_VALID_ENV(env); return ClassUtil::IsInterface(env, klass, is_interface_ptr); } static jvmtiError IsArrayClass(jvmtiEnv* env, jclass klass, jboolean* is_array_class_ptr) { ENSURE_VALID_ENV(env); return ClassUtil::IsArrayClass(env, klass, is_array_class_ptr); } static jvmtiError IsModifiableClass(jvmtiEnv* env, jclass klass, jboolean* is_modifiable_class_ptr) { ENSURE_VALID_ENV(env); return Redefiner::IsModifiableClass(env, klass, is_modifiable_class_ptr); } static jvmtiError GetClassLoader(jvmtiEnv* env, jclass klass, jobject* classloader_ptr) { ENSURE_VALID_ENV(env); return ClassUtil::GetClassLoader(env, klass, classloader_ptr); } static jvmtiError GetSourceDebugExtension(jvmtiEnv* env, jclass klass, char** source_debug_extension_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_get_source_debug_extension); return ClassUtil::GetSourceDebugExtension(env, klass, source_debug_extension_ptr); } static jvmtiError RetransformClasses(jvmtiEnv* env, jint class_count, const jclass* classes) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_retransform_classes); std::string error_msg; jvmtiError res = Transformer::RetransformClasses(ArtJvmTiEnv::AsArtJvmTiEnv(env), gEventHandler, art::Runtime::Current(), art::Thread::Current(), class_count, classes, &error_msg); if (res != OK) { JVMTI_LOG(WARNING, env) << "FAILURE TO RETRANFORM " << error_msg; } return res; } static jvmtiError RedefineClasses(jvmtiEnv* env, jint class_count, const jvmtiClassDefinition* class_definitions) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_redefine_classes); std::string error_msg; jvmtiError res = Redefiner::RedefineClasses(ArtJvmTiEnv::AsArtJvmTiEnv(env), gEventHandler, art::Runtime::Current(), art::Thread::Current(), class_count, class_definitions, &error_msg); if (res != OK) { JVMTI_LOG(WARNING, env) << "FAILURE TO REDEFINE " << error_msg; } return res; } static jvmtiError GetObjectSize(jvmtiEnv* env, jobject object, jlong* size_ptr) { ENSURE_VALID_ENV(env); return ObjectUtil::GetObjectSize(env, object, size_ptr); } static jvmtiError GetObjectHashCode(jvmtiEnv* env, jobject object, jint* hash_code_ptr) { ENSURE_VALID_ENV(env); return ObjectUtil::GetObjectHashCode(env, object, hash_code_ptr); } static jvmtiError GetObjectMonitorUsage(jvmtiEnv* env, jobject object, jvmtiMonitorUsage* info_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_get_monitor_info); return ObjectUtil::GetObjectMonitorUsage(env, object, info_ptr); } static jvmtiError GetFieldName(jvmtiEnv* env, jclass klass, jfieldID field, char** name_ptr, char** signature_ptr, char** generic_ptr) { ENSURE_VALID_ENV(env); return FieldUtil::GetFieldName(env, klass, field, name_ptr, signature_ptr, generic_ptr); } static jvmtiError GetFieldDeclaringClass(jvmtiEnv* env, jclass klass, jfieldID field, jclass* declaring_class_ptr) { ENSURE_VALID_ENV(env); return FieldUtil::GetFieldDeclaringClass(env, klass, field, declaring_class_ptr); } static jvmtiError GetFieldModifiers(jvmtiEnv* env, jclass klass, jfieldID field, jint* modifiers_ptr) { ENSURE_VALID_ENV(env); return FieldUtil::GetFieldModifiers(env, klass, field, modifiers_ptr); } static jvmtiError IsFieldSynthetic(jvmtiEnv* env, jclass klass, jfieldID field, jboolean* is_synthetic_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_get_synthetic_attribute); return FieldUtil::IsFieldSynthetic(env, klass, field, is_synthetic_ptr); } static jvmtiError GetMethodName(jvmtiEnv* env, jmethodID method, char** name_ptr, char** signature_ptr, char** generic_ptr) { ENSURE_VALID_ENV(env); return MethodUtil::GetMethodName(env, method, name_ptr, signature_ptr, generic_ptr); } static jvmtiError GetMethodDeclaringClass(jvmtiEnv* env, jmethodID method, jclass* declaring_class_ptr) { ENSURE_VALID_ENV(env); return MethodUtil::GetMethodDeclaringClass(env, method, declaring_class_ptr); } static jvmtiError GetMethodModifiers(jvmtiEnv* env, jmethodID method, jint* modifiers_ptr) { ENSURE_VALID_ENV(env); return MethodUtil::GetMethodModifiers(env, method, modifiers_ptr); } static jvmtiError GetMaxLocals(jvmtiEnv* env, jmethodID method, jint* max_ptr) { ENSURE_VALID_ENV(env); return MethodUtil::GetMaxLocals(env, method, max_ptr); } static jvmtiError GetArgumentsSize(jvmtiEnv* env, jmethodID method, jint* size_ptr) { ENSURE_VALID_ENV(env); return MethodUtil::GetArgumentsSize(env, method, size_ptr); } static jvmtiError GetLineNumberTable(jvmtiEnv* env, jmethodID method, jint* entry_count_ptr, jvmtiLineNumberEntry** table_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_get_line_numbers); return MethodUtil::GetLineNumberTable(env, method, entry_count_ptr, table_ptr); } static jvmtiError GetMethodLocation(jvmtiEnv* env, jmethodID method, jlocation* start_location_ptr, jlocation* end_location_ptr) { ENSURE_VALID_ENV(env); return MethodUtil::GetMethodLocation(env, method, start_location_ptr, end_location_ptr); } static jvmtiError GetLocalVariableTable(jvmtiEnv* env, jmethodID method, jint* entry_count_ptr, jvmtiLocalVariableEntry** table_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_access_local_variables); return MethodUtil::GetLocalVariableTable(env, method, entry_count_ptr, table_ptr); } static jvmtiError GetBytecodes(jvmtiEnv* env, jmethodID method, jint* bytecode_count_ptr, unsigned char** bytecodes_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_get_bytecodes); return MethodUtil::GetBytecodes(env, method, bytecode_count_ptr, bytecodes_ptr); } static jvmtiError IsMethodNative(jvmtiEnv* env, jmethodID method, jboolean* is_native_ptr) { ENSURE_VALID_ENV(env); return MethodUtil::IsMethodNative(env, method, is_native_ptr); } static jvmtiError IsMethodSynthetic(jvmtiEnv* env, jmethodID method, jboolean* is_synthetic_ptr) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_get_synthetic_attribute); return MethodUtil::IsMethodSynthetic(env, method, is_synthetic_ptr); } static jvmtiError IsMethodObsolete(jvmtiEnv* env, jmethodID method, jboolean* is_obsolete_ptr) { ENSURE_VALID_ENV(env); return MethodUtil::IsMethodObsolete(env, method, is_obsolete_ptr); } static jvmtiError SetNativeMethodPrefix(jvmtiEnv* env, const char* prefix ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_set_native_method_prefix); return ERR(NOT_IMPLEMENTED); } static jvmtiError SetNativeMethodPrefixes(jvmtiEnv* env, jint prefix_count ATTRIBUTE_UNUSED, char** prefixes ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_set_native_method_prefix); return ERR(NOT_IMPLEMENTED); } static jvmtiError CreateRawMonitor(jvmtiEnv* env, const char* name, jrawMonitorID* monitor_ptr) { ENSURE_VALID_ENV(env); return MonitorUtil::CreateRawMonitor(env, name, monitor_ptr); } static jvmtiError DestroyRawMonitor(jvmtiEnv* env, jrawMonitorID monitor) { ENSURE_VALID_ENV(env); return MonitorUtil::DestroyRawMonitor(env, monitor); } static jvmtiError RawMonitorEnter(jvmtiEnv* env, jrawMonitorID monitor) { ENSURE_VALID_ENV(env); return MonitorUtil::RawMonitorEnter(env, monitor); } static jvmtiError RawMonitorExit(jvmtiEnv* env, jrawMonitorID monitor) { ENSURE_VALID_ENV(env); return MonitorUtil::RawMonitorExit(env, monitor); } static jvmtiError RawMonitorWait(jvmtiEnv* env, jrawMonitorID monitor, jlong millis) { ENSURE_VALID_ENV(env); return MonitorUtil::RawMonitorWait(env, monitor, millis); } static jvmtiError RawMonitorNotify(jvmtiEnv* env, jrawMonitorID monitor) { ENSURE_VALID_ENV(env); return MonitorUtil::RawMonitorNotify(env, monitor); } static jvmtiError RawMonitorNotifyAll(jvmtiEnv* env, jrawMonitorID monitor) { ENSURE_VALID_ENV(env); return MonitorUtil::RawMonitorNotifyAll(env, monitor); } static jvmtiError SetJNIFunctionTable(jvmtiEnv* env, const jniNativeInterface* function_table) { ENSURE_VALID_ENV(env); return JNIUtil::SetJNIFunctionTable(env, function_table); } static jvmtiError GetJNIFunctionTable(jvmtiEnv* env, jniNativeInterface** function_table) { ENSURE_VALID_ENV(env); return JNIUtil::GetJNIFunctionTable(env, function_table); } // TODO: This will require locking, so that an agent can't remove callbacks when we're dispatching // an event. static jvmtiError SetEventCallbacks(jvmtiEnv* env, const jvmtiEventCallbacks* callbacks, jint size_of_callbacks) { ENSURE_VALID_ENV(env); if (size_of_callbacks < 0) { return ERR(ILLEGAL_ARGUMENT); } if (callbacks == nullptr) { ArtJvmTiEnv::AsArtJvmTiEnv(env)->event_callbacks.reset(); return ERR(NONE); } // Lock the event_info_mutex_ while we replace the callbacks. ArtJvmTiEnv* art_env = ArtJvmTiEnv::AsArtJvmTiEnv(env); art::WriterMutexLock lk(art::Thread::Current(), art_env->event_info_mutex_); std::unique_ptr<ArtJvmtiEventCallbacks> tmp(new ArtJvmtiEventCallbacks()); // Copy over the extension events. tmp->CopyExtensionsFrom(art_env->event_callbacks.get()); // Never overwrite the extension events. size_t copy_size = std::min(sizeof(jvmtiEventCallbacks), static_cast<size_t>(size_of_callbacks)); copy_size = art::RoundDown(copy_size, sizeof(void*)); // Copy non-extension events. memcpy(tmp.get(), callbacks, copy_size); // replace the event table. art_env->event_callbacks = std::move(tmp); return ERR(NONE); } static jvmtiError SetEventNotificationMode(jvmtiEnv* env, jvmtiEventMode mode, jvmtiEvent event_type, jthread event_thread, ...) { ENSURE_VALID_ENV(env); ArtJvmTiEnv* art_env = ArtJvmTiEnv::AsArtJvmTiEnv(env); return gEventHandler->SetEvent(art_env, event_thread, GetArtJvmtiEvent(art_env, event_type), mode); } static jvmtiError GenerateEvents(jvmtiEnv* env, jvmtiEvent event_type ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); return OK; } static jvmtiError GetExtensionFunctions(jvmtiEnv* env, jint* extension_count_ptr, jvmtiExtensionFunctionInfo** extensions) { ENSURE_VALID_ENV(env); ENSURE_NON_NULL(extension_count_ptr); ENSURE_NON_NULL(extensions); return ExtensionUtil::GetExtensionFunctions(env, extension_count_ptr, extensions); } static jvmtiError GetExtensionEvents(jvmtiEnv* env, jint* extension_count_ptr, jvmtiExtensionEventInfo** extensions) { ENSURE_VALID_ENV(env); ENSURE_NON_NULL(extension_count_ptr); ENSURE_NON_NULL(extensions); return ExtensionUtil::GetExtensionEvents(env, extension_count_ptr, extensions); } static jvmtiError SetExtensionEventCallback(jvmtiEnv* env, jint extension_event_index, jvmtiExtensionEvent callback) { ENSURE_VALID_ENV(env); return ExtensionUtil::SetExtensionEventCallback(env, extension_event_index, callback, gEventHandler); } #define FOR_ALL_CAPABILITIES(FUN) \ FUN(can_tag_objects) \ FUN(can_generate_field_modification_events) \ FUN(can_generate_field_access_events) \ FUN(can_get_bytecodes) \ FUN(can_get_synthetic_attribute) \ FUN(can_get_owned_monitor_info) \ FUN(can_get_current_contended_monitor) \ FUN(can_get_monitor_info) \ FUN(can_pop_frame) \ FUN(can_redefine_classes) \ FUN(can_signal_thread) \ FUN(can_get_source_file_name) \ FUN(can_get_line_numbers) \ FUN(can_get_source_debug_extension) \ FUN(can_access_local_variables) \ FUN(can_maintain_original_method_order) \ FUN(can_generate_single_step_events) \ FUN(can_generate_exception_events) \ FUN(can_generate_frame_pop_events) \ FUN(can_generate_breakpoint_events) \ FUN(can_suspend) \ FUN(can_redefine_any_class) \ FUN(can_get_current_thread_cpu_time) \ FUN(can_get_thread_cpu_time) \ FUN(can_generate_method_entry_events) \ FUN(can_generate_method_exit_events) \ FUN(can_generate_all_class_hook_events) \ FUN(can_generate_compiled_method_load_events) \ FUN(can_generate_monitor_events) \ FUN(can_generate_vm_object_alloc_events) \ FUN(can_generate_native_method_bind_events) \ FUN(can_generate_garbage_collection_events) \ FUN(can_generate_object_free_events) \ FUN(can_force_early_return) \ FUN(can_get_owned_monitor_stack_depth_info) \ FUN(can_get_constant_pool) \ FUN(can_set_native_method_prefix) \ FUN(can_retransform_classes) \ FUN(can_retransform_any_class) \ FUN(can_generate_resource_exhaustion_heap_events) \ FUN(can_generate_resource_exhaustion_threads_events) static jvmtiError GetPotentialCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) { ENSURE_VALID_ENV(env); ENSURE_NON_NULL(capabilities_ptr); *capabilities_ptr = kPotentialCapabilities; if (UNLIKELY(!IsFullJvmtiAvailable())) { #define REMOVE_NONDEBUGGABLE_UNSUPPORTED(e) \ do { \ if (kNonDebuggableUnsupportedCapabilities.e == 1) { \ capabilities_ptr->e = 0; \ } \ } while (false); FOR_ALL_CAPABILITIES(REMOVE_NONDEBUGGABLE_UNSUPPORTED); #undef REMOVE_NONDEBUGGABLE_UNSUPPORTED } return OK; } static jvmtiError AddCapabilities(jvmtiEnv* env, const jvmtiCapabilities* capabilities_ptr) { ENSURE_VALID_ENV(env); ENSURE_NON_NULL(capabilities_ptr); ArtJvmTiEnv* art_env = static_cast<ArtJvmTiEnv*>(env); jvmtiError ret = OK; jvmtiCapabilities changed = {}; jvmtiCapabilities potential_capabilities = {}; ret = env->GetPotentialCapabilities(&potential_capabilities); if (ret != OK) { return ret; } #define ADD_CAPABILITY(e) \ do { \ if (capabilities_ptr->e == 1) { \ if (potential_capabilities.e == 1) { \ if (art_env->capabilities.e != 1) { \ art_env->capabilities.e = 1; \ changed.e = 1; \ }\ } else { \ ret = ERR(NOT_AVAILABLE); \ } \ } \ } while (false); FOR_ALL_CAPABILITIES(ADD_CAPABILITY); #undef ADD_CAPABILITY gEventHandler->HandleChangedCapabilities(ArtJvmTiEnv::AsArtJvmTiEnv(env), changed, /*added=*/true); return ret; } static jvmtiError RelinquishCapabilities(jvmtiEnv* env, const jvmtiCapabilities* capabilities_ptr) { ENSURE_VALID_ENV(env); ENSURE_NON_NULL(capabilities_ptr); ArtJvmTiEnv* art_env = reinterpret_cast<ArtJvmTiEnv*>(env); jvmtiCapabilities changed = {}; #define DEL_CAPABILITY(e) \ do { \ if (capabilities_ptr->e == 1) { \ if (art_env->capabilities.e == 1) { \ art_env->capabilities.e = 0;\ changed.e = 1; \ } \ } \ } while (false); FOR_ALL_CAPABILITIES(DEL_CAPABILITY); #undef DEL_CAPABILITY gEventHandler->HandleChangedCapabilities(ArtJvmTiEnv::AsArtJvmTiEnv(env), changed, /*added=*/false); return OK; } #undef FOR_ALL_CAPABILITIES static jvmtiError GetCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) { ENSURE_VALID_ENV(env); ENSURE_NON_NULL(capabilities_ptr); ArtJvmTiEnv* artenv = reinterpret_cast<ArtJvmTiEnv*>(env); *capabilities_ptr = artenv->capabilities; return OK; } static jvmtiError GetCurrentThreadCpuTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_get_current_thread_cpu_time); return ERR(NOT_IMPLEMENTED); } static jvmtiError GetCurrentThreadCpuTime(jvmtiEnv* env, jlong* nanos_ptr ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_get_current_thread_cpu_time); return ERR(NOT_IMPLEMENTED); } static jvmtiError GetThreadCpuTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_get_thread_cpu_time); return ERR(NOT_IMPLEMENTED); } static jvmtiError GetThreadCpuTime(jvmtiEnv* env, jthread thread ATTRIBUTE_UNUSED, jlong* nanos_ptr ATTRIBUTE_UNUSED) { ENSURE_VALID_ENV(env); ENSURE_HAS_CAP(env, can_get_thread_cpu_time); return ERR(NOT_IMPLEMENTED); } static jvmtiError GetTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) { ENSURE_VALID_ENV(env); return TimerUtil::GetTimerInfo(env, info_ptr); } static jvmtiError GetTime(jvmtiEnv* env, jlong* nanos_ptr) { ENSURE_VALID_ENV(env); return TimerUtil::GetTime(env, nanos_ptr); } static jvmtiError GetAvailableProcessors(jvmtiEnv* env, jint* processor_count_ptr) { ENSURE_VALID_ENV(env); return TimerUtil::GetAvailableProcessors(env, processor_count_ptr); } static jvmtiError AddToBootstrapClassLoaderSearch(jvmtiEnv* env, const char* segment) { ENSURE_VALID_ENV(env); return SearchUtil::AddToBootstrapClassLoaderSearch(env, segment); } static jvmtiError AddToSystemClassLoaderSearch(jvmtiEnv* env, const char* segment) { ENSURE_VALID_ENV(env); return SearchUtil::AddToSystemClassLoaderSearch(env, segment); } static jvmtiError GetSystemProperties(jvmtiEnv* env, jint* count_ptr, char*** property_ptr) { ENSURE_VALID_ENV(env); return PropertiesUtil::GetSystemProperties(env, count_ptr, property_ptr); } static jvmtiError GetSystemProperty(jvmtiEnv* env, const char* property, char** value_ptr) { ENSURE_VALID_ENV(env); return PropertiesUtil::GetSystemProperty(env, property, value_ptr); } static jvmtiError SetSystemProperty(jvmtiEnv* env, const char* property, const char* value) { ENSURE_VALID_ENV(env); return PropertiesUtil::SetSystemProperty(env, property, value); } static jvmtiError GetPhase(jvmtiEnv* env, jvmtiPhase* phase_ptr) { ENSURE_VALID_ENV(env); return PhaseUtil::GetPhase(env, phase_ptr); } static jvmtiError DisposeEnvironment(jvmtiEnv* env) { ENSURE_VALID_ENV(env); ArtJvmTiEnv* tienv = ArtJvmTiEnv::AsArtJvmTiEnv(env); gEventHandler->RemoveArtJvmTiEnv(tienv); art::Runtime::Current()->RemoveSystemWeakHolder(tienv->object_tag_table.get()); ThreadUtil::RemoveEnvironment(tienv); delete tienv; return OK; } static jvmtiError SetEnvironmentLocalStorage(jvmtiEnv* env, const void* data) { ENSURE_VALID_ENV(env); reinterpret_cast<ArtJvmTiEnv*>(env)->local_data = const_cast<void*>(data); return OK; } static jvmtiError GetEnvironmentLocalStorage(jvmtiEnv* env, void** data_ptr) { ENSURE_VALID_ENV(env); *data_ptr = reinterpret_cast<ArtJvmTiEnv*>(env)->local_data; return OK; } static jvmtiError GetVersionNumber(jvmtiEnv* env, jint* version_ptr) { ENSURE_VALID_ENV(env); *version_ptr = ArtJvmTiEnv::AsArtJvmTiEnv(env)->ti_version; return OK; } static jvmtiError GetErrorName(jvmtiEnv* env, jvmtiError error, char** name_ptr) { ENSURE_NON_NULL(name_ptr); auto copy_fn = [&](const char* name_cstr) { jvmtiError res; JvmtiUniquePtr<char[]> copy = CopyString(env, name_cstr, &res); if (copy == nullptr) { *name_ptr = nullptr; return res; } else { *name_ptr = copy.release(); return OK; } }; switch (error) { #define ERROR_CASE(e) case (JVMTI_ERROR_ ## e) : \ return copy_fn("JVMTI_ERROR_"#e); ERROR_CASE(NONE); ERROR_CASE(INVALID_THREAD); ERROR_CASE(INVALID_THREAD_GROUP); ERROR_CASE(INVALID_PRIORITY); ERROR_CASE(THREAD_NOT_SUSPENDED); ERROR_CASE(THREAD_SUSPENDED); ERROR_CASE(THREAD_NOT_ALIVE); ERROR_CASE(INVALID_OBJECT); ERROR_CASE(INVALID_CLASS); ERROR_CASE(CLASS_NOT_PREPARED); ERROR_CASE(INVALID_METHODID); ERROR_CASE(INVALID_LOCATION); ERROR_CASE(INVALID_FIELDID); ERROR_CASE(NO_MORE_FRAMES); ERROR_CASE(OPAQUE_FRAME); ERROR_CASE(TYPE_MISMATCH); ERROR_CASE(INVALID_SLOT); ERROR_CASE(DUPLICATE); ERROR_CASE(NOT_FOUND); ERROR_CASE(INVALID_MONITOR); ERROR_CASE(NOT_MONITOR_OWNER); ERROR_CASE(INTERRUPT); ERROR_CASE(INVALID_CLASS_FORMAT); ERROR_CASE(CIRCULAR_CLASS_DEFINITION); ERROR_CASE(FAILS_VERIFICATION); ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_ADDED); ERROR_CASE(UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED); ERROR_CASE(INVALID_TYPESTATE); ERROR_CASE(UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED); ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_DELETED); ERROR_CASE(UNSUPPORTED_VERSION); ERROR_CASE(NAMES_DONT_MATCH); ERROR_CASE(UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED); ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED); ERROR_CASE(UNMODIFIABLE_CLASS); ERROR_CASE(NOT_AVAILABLE); ERROR_CASE(MUST_POSSESS_CAPABILITY); ERROR_CASE(NULL_POINTER); ERROR_CASE(ABSENT_INFORMATION); ERROR_CASE(INVALID_EVENT_TYPE); ERROR_CASE(ILLEGAL_ARGUMENT); ERROR_CASE(NATIVE_METHOD); ERROR_CASE(CLASS_LOADER_UNSUPPORTED); ERROR_CASE(OUT_OF_MEMORY); ERROR_CASE(ACCESS_DENIED); ERROR_CASE(WRONG_PHASE); ERROR_CASE(INTERNAL); ERROR_CASE(UNATTACHED_THREAD); ERROR_CASE(INVALID_ENVIRONMENT); #undef ERROR_CASE } return ERR(ILLEGAL_ARGUMENT); } static jvmtiError SetVerboseFlag(jvmtiEnv* env, jvmtiVerboseFlag flag, jboolean value) { ENSURE_VALID_ENV(env); if (flag == jvmtiVerboseFlag::JVMTI_VERBOSE_OTHER) { // OTHER is special, as it's 0, so can't do a bit check. bool val = (value == JNI_TRUE) ? true : false; art::gLogVerbosity.collector = val; art::gLogVerbosity.compiler = val; art::gLogVerbosity.deopt = val; art::gLogVerbosity.heap = val; art::gLogVerbosity.jdwp = val; art::gLogVerbosity.jit = val; art::gLogVerbosity.monitor = val; art::gLogVerbosity.oat = val; art::gLogVerbosity.profiler = val; art::gLogVerbosity.signals = val; art::gLogVerbosity.simulator = val; art::gLogVerbosity.startup = val; art::gLogVerbosity.third_party_jni = val; art::gLogVerbosity.threads = val; art::gLogVerbosity.verifier = val; // Do not set verifier-debug. art::gLogVerbosity.image = val; // Note: can't switch systrace_lock_logging. That requires changing entrypoints. art::gLogVerbosity.agents = val; } else { // Spec isn't clear whether "flag" is a mask or supposed to be single. We implement the mask // semantics. constexpr std::underlying_type<jvmtiVerboseFlag>::type kMask = jvmtiVerboseFlag::JVMTI_VERBOSE_GC | jvmtiVerboseFlag::JVMTI_VERBOSE_CLASS | jvmtiVerboseFlag::JVMTI_VERBOSE_JNI; if ((flag & ~kMask) != 0) { return ERR(ILLEGAL_ARGUMENT); } bool val = (value == JNI_TRUE) ? true : false; if ((flag & jvmtiVerboseFlag::JVMTI_VERBOSE_GC) != 0) { art::gLogVerbosity.gc = val; } if ((flag & jvmtiVerboseFlag::JVMTI_VERBOSE_CLASS) != 0) { art::gLogVerbosity.class_linker = val; } if ((flag & jvmtiVerboseFlag::JVMTI_VERBOSE_JNI) != 0) { art::gLogVerbosity.jni = val; } } return ERR(NONE); } static jvmtiError GetJLocationFormat(jvmtiEnv* env, jvmtiJlocationFormat* format_ptr) { ENSURE_VALID_ENV(env); // Report BCI as jlocation format. We report dex bytecode indices. if (format_ptr == nullptr) { return ERR(NULL_POINTER); } *format_ptr = jvmtiJlocationFormat::JVMTI_JLOCATION_JVMBCI; return ERR(NONE); } }; static bool IsJvmtiVersion(jint version) { return version == JVMTI_VERSION_1 || version == JVMTI_VERSION_1_0 || version == JVMTI_VERSION_1_1 || version == JVMTI_VERSION_1_2 || version == JVMTI_VERSION; } extern const jvmtiInterface_1 gJvmtiInterface; ArtJvmTiEnv::ArtJvmTiEnv(art::JavaVMExt* runtime, EventHandler* event_handler, jint version) : art_vm(runtime), local_data(nullptr), ti_version(version), capabilities(), event_info_mutex_("jvmtiEnv_EventInfoMutex"), last_error_mutex_("jvmtiEnv_LastErrorMutex", art::LockLevel::kGenericBottomLock) { object_tag_table = std::make_unique<ObjectTagTable>(event_handler, this); functions = &gJvmtiInterface; } // Creates a jvmtiEnv and returns it with the art::ti::Env that is associated with it. new_art_ti // is a pointer to the uninitialized memory for an art::ti::Env. static void CreateArtJvmTiEnv(art::JavaVMExt* vm, jint version, /*out*/void** new_jvmtiEnv) { struct ArtJvmTiEnv* env = new ArtJvmTiEnv(vm, gEventHandler, version); *new_jvmtiEnv = env; gEventHandler->RegisterArtJvmTiEnv(env); art::Runtime::Current()->AddSystemWeakHolder( ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get()); } // A hook that the runtime uses to allow plugins to handle GetEnv calls. It returns true and // places the return value in 'env' if this library can handle the GetEnv request. Otherwise // returns false and does not modify the 'env' pointer. static jint GetEnvHandler(art::JavaVMExt* vm, /*out*/void** env, jint version) { // JavaDebuggable will either be set by the runtime as it is starting up or the plugin if it's // loaded early enough. If this is false we cannot guarantee conformance to all JVMTI behaviors // due to optimizations. We will only allow agents to get ArtTiEnvs using the kArtTiVersion. if (IsFullJvmtiAvailable() && IsJvmtiVersion(version)) { CreateArtJvmTiEnv(vm, JVMTI_VERSION, env); return JNI_OK; } else if (version == kArtTiVersion) { CreateArtJvmTiEnv(vm, kArtTiVersion, env); return JNI_OK; } else { printf("version 0x%x is not valid!", version); return JNI_EVERSION; } } // The plugin initialization function. This adds the jvmti environment. extern "C" bool ArtPlugin_Initialize() { art::Runtime* runtime = art::Runtime::Current(); gDeoptManager = new DeoptManager; gEventHandler = new EventHandler; gDeoptManager->Setup(); if (runtime->IsStarted()) { PhaseUtil::SetToLive(); } else { PhaseUtil::SetToOnLoad(); } PhaseUtil::Register(gEventHandler); ThreadUtil::Register(gEventHandler); ClassUtil::Register(gEventHandler); DumpUtil::Register(gEventHandler); MethodUtil::Register(gEventHandler); SearchUtil::Register(); HeapUtil::Register(); Transformer::Setup(); { // Make sure we can deopt anything we need to. art::ScopedSuspendAll ssa(__FUNCTION__); gDeoptManager->FinishSetup(); } runtime->GetJavaVM()->AddEnvironmentHook(GetEnvHandler); return true; } extern "C" bool ArtPlugin_Deinitialize() { gEventHandler->Shutdown(); gDeoptManager->Shutdown(); PhaseUtil::Unregister(); ThreadUtil::Unregister(); ClassUtil::Unregister(); DumpUtil::Unregister(); MethodUtil::Unregister(); SearchUtil::Unregister(); HeapUtil::Unregister(); // TODO It would be good to delete the gEventHandler and gDeoptManager here but we cannot since // daemon threads might be suspended and we want to make sure that even if they wake up briefly // they won't hit deallocated memory. By this point none of the functions will do anything since // they have already shutdown. return true; } // The actual struct holding all of the entrypoints into the jvmti interface. const jvmtiInterface_1 gJvmtiInterface = { nullptr, // reserved1 JvmtiFunctions::SetEventNotificationMode, nullptr, // reserved3 JvmtiFunctions::GetAllThreads, JvmtiFunctions::SuspendThread, JvmtiFunctions::ResumeThread, JvmtiFunctions::StopThread, JvmtiFunctions::InterruptThread, JvmtiFunctions::GetThreadInfo, JvmtiFunctions::GetOwnedMonitorInfo, // 10 JvmtiFunctions::GetCurrentContendedMonitor, JvmtiFunctions::RunAgentThread, JvmtiFunctions::GetTopThreadGroups, JvmtiFunctions::GetThreadGroupInfo, JvmtiFunctions::GetThreadGroupChildren, JvmtiFunctions::GetFrameCount, JvmtiFunctions::GetThreadState, JvmtiFunctions::GetCurrentThread, JvmtiFunctions::GetFrameLocation, JvmtiFunctions::NotifyFramePop, // 20 JvmtiFunctions::GetLocalObject, JvmtiFunctions::GetLocalInt, JvmtiFunctions::GetLocalLong, JvmtiFunctions::GetLocalFloat, JvmtiFunctions::GetLocalDouble, JvmtiFunctions::SetLocalObject, JvmtiFunctions::SetLocalInt, JvmtiFunctions::SetLocalLong, JvmtiFunctions::SetLocalFloat, JvmtiFunctions::SetLocalDouble, // 30 JvmtiFunctions::CreateRawMonitor, JvmtiFunctions::DestroyRawMonitor, JvmtiFunctions::RawMonitorEnter, JvmtiFunctions::RawMonitorExit, JvmtiFunctions::RawMonitorWait, JvmtiFunctions::RawMonitorNotify, JvmtiFunctions::RawMonitorNotifyAll, JvmtiFunctions::SetBreakpoint, JvmtiFunctions::ClearBreakpoint, nullptr, // reserved40 JvmtiFunctions::SetFieldAccessWatch, JvmtiFunctions::ClearFieldAccessWatch, JvmtiFunctions::SetFieldModificationWatch, JvmtiFunctions::ClearFieldModificationWatch, JvmtiFunctions::IsModifiableClass, JvmtiFunctions::Allocate, JvmtiFunctions::Deallocate, JvmtiFunctions::GetClassSignature, JvmtiFunctions::GetClassStatus, JvmtiFunctions::GetSourceFileName, // 50 JvmtiFunctions::GetClassModifiers, JvmtiFunctions::GetClassMethods, JvmtiFunctions::GetClassFields, JvmtiFunctions::GetImplementedInterfaces, JvmtiFunctions::IsInterface, JvmtiFunctions::IsArrayClass, JvmtiFunctions::GetClassLoader, JvmtiFunctions::GetObjectHashCode, JvmtiFunctions::GetObjectMonitorUsage, JvmtiFunctions::GetFieldName, // 60 JvmtiFunctions::GetFieldDeclaringClass, JvmtiFunctions::GetFieldModifiers, JvmtiFunctions::IsFieldSynthetic, JvmtiFunctions::GetMethodName, JvmtiFunctions::GetMethodDeclaringClass, JvmtiFunctions::GetMethodModifiers, nullptr, // reserved67 JvmtiFunctions::GetMaxLocals, JvmtiFunctions::GetArgumentsSize, JvmtiFunctions::GetLineNumberTable, // 70 JvmtiFunctions::GetMethodLocation, JvmtiFunctions::GetLocalVariableTable, JvmtiFunctions::SetNativeMethodPrefix, JvmtiFunctions::SetNativeMethodPrefixes, JvmtiFunctions::GetBytecodes, JvmtiFunctions::IsMethodNative, JvmtiFunctions::IsMethodSynthetic, JvmtiFunctions::GetLoadedClasses, JvmtiFunctions::GetClassLoaderClasses, JvmtiFunctions::PopFrame, // 80 JvmtiFunctions::ForceEarlyReturnObject, JvmtiFunctions::ForceEarlyReturnInt, JvmtiFunctions::ForceEarlyReturnLong, JvmtiFunctions::ForceEarlyReturnFloat, JvmtiFunctions::ForceEarlyReturnDouble, JvmtiFunctions::ForceEarlyReturnVoid, JvmtiFunctions::RedefineClasses, JvmtiFunctions::GetVersionNumber, JvmtiFunctions::GetCapabilities, JvmtiFunctions::GetSourceDebugExtension, // 90 JvmtiFunctions::IsMethodObsolete, JvmtiFunctions::SuspendThreadList, JvmtiFunctions::ResumeThreadList, nullptr, // reserved94 nullptr, // reserved95 nullptr, // reserved96 nullptr, // reserved97 nullptr, // reserved98 nullptr, // reserved99 JvmtiFunctions::GetAllStackTraces, // 100 JvmtiFunctions::GetThreadListStackTraces, JvmtiFunctions::GetThreadLocalStorage, JvmtiFunctions::SetThreadLocalStorage, JvmtiFunctions::GetStackTrace, nullptr, // reserved105 JvmtiFunctions::GetTag, JvmtiFunctions::SetTag, JvmtiFunctions::ForceGarbageCollection, JvmtiFunctions::IterateOverObjectsReachableFromObject, JvmtiFunctions::IterateOverReachableObjects, // 110 JvmtiFunctions::IterateOverHeap, JvmtiFunctions::IterateOverInstancesOfClass, nullptr, // reserved113 JvmtiFunctions::GetObjectsWithTags, JvmtiFunctions::FollowReferences, JvmtiFunctions::IterateThroughHeap, nullptr, // reserved117 nullptr, // reserved118 nullptr, // reserved119 JvmtiFunctions::SetJNIFunctionTable, // 120 JvmtiFunctions::GetJNIFunctionTable, JvmtiFunctions::SetEventCallbacks, JvmtiFunctions::GenerateEvents, JvmtiFunctions::GetExtensionFunctions, JvmtiFunctions::GetExtensionEvents, JvmtiFunctions::SetExtensionEventCallback, JvmtiFunctions::DisposeEnvironment, JvmtiFunctions::GetErrorName, JvmtiFunctions::GetJLocationFormat, JvmtiFunctions::GetSystemProperties, // 130 JvmtiFunctions::GetSystemProperty, JvmtiFunctions::SetSystemProperty, JvmtiFunctions::GetPhase, JvmtiFunctions::GetCurrentThreadCpuTimerInfo, JvmtiFunctions::GetCurrentThreadCpuTime, JvmtiFunctions::GetThreadCpuTimerInfo, JvmtiFunctions::GetThreadCpuTime, JvmtiFunctions::GetTimerInfo, JvmtiFunctions::GetTime, JvmtiFunctions::GetPotentialCapabilities, // 140 nullptr, // reserved141 JvmtiFunctions::AddCapabilities, JvmtiFunctions::RelinquishCapabilities, JvmtiFunctions::GetAvailableProcessors, JvmtiFunctions::GetClassVersionNumbers, JvmtiFunctions::GetConstantPool, JvmtiFunctions::GetEnvironmentLocalStorage, JvmtiFunctions::SetEnvironmentLocalStorage, JvmtiFunctions::AddToBootstrapClassLoaderSearch, JvmtiFunctions::SetVerboseFlag, // 150 JvmtiFunctions::AddToSystemClassLoaderSearch, JvmtiFunctions::RetransformClasses, JvmtiFunctions::GetOwnedMonitorStackDepthInfo, JvmtiFunctions::GetObjectSize, JvmtiFunctions::GetLocalInstance, }; }; // namespace openjdkjvmti
.686 .model flat,stdcall option casemap:none include .\bnlib.inc include .\bignum.inc .code bnXchg proc uses esi edi bnX:DWORD,bnY:DWORD mov ecx,BN_ALLOC_BYTES mov edi,bnX sub ecx,4 mov esi,bnY .repeat mov eax,[esi+ecx] mov edx,[edi+ecx] mov [edi+ecx],eax mov [esi+ecx],edx sub ecx,4 .until sign? ret bnXchg endp end
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r11 push %r12 push %r8 push %rcx push %rdi push %rdx push %rsi lea addresses_WT_ht+0x1b008, %r12 clflush (%r12) inc %rsi movw $0x6162, (%r12) nop add $60568, %rdx lea addresses_UC_ht+0x1ee2, %rsi lea addresses_normal_ht+0xaaf8, %rdi nop sub $35747, %r11 mov $93, %rcx rep movsb nop cmp %rcx, %rcx lea addresses_D_ht+0x9f08, %r11 nop nop nop nop nop cmp %r10, %r10 movb $0x61, (%r11) nop nop nop nop xor $39750, %rsi lea addresses_UC_ht+0x16008, %r10 clflush (%r10) nop and $14220, %r12 movl $0x61626364, (%r10) nop nop nop dec %rdi lea addresses_WC_ht+0x1443, %rsi lea addresses_A_ht+0x7108, %rdi nop nop nop nop sub $65043, %r8 mov $74, %rcx rep movsw nop and $20171, %r11 lea addresses_D_ht+0x1d808, %r11 nop nop nop nop nop sub $31954, %r10 movw $0x6162, (%r11) nop nop nop nop nop add %rcx, %rcx pop %rsi pop %rdx pop %rdi pop %rcx pop %r8 pop %r12 pop %r11 pop %r10 ret .global s_faulty_load s_faulty_load: push %r11 push %r8 push %rbp push %rbx push %rcx push %rdi push %rdx // Store lea addresses_WC+0xf008, %rdx nop nop nop nop nop sub %rbx, %rbx mov $0x5152535455565758, %rbp movq %rbp, %xmm7 vmovups %ymm7, (%rdx) cmp %rbp, %rbp // Store mov $0x557e850000000808, %rcx clflush (%rcx) nop nop sub %rdi, %rdi mov $0x5152535455565758, %rdx movq %rdx, %xmm1 vmovups %ymm1, (%rcx) nop nop nop add $4530, %rcx // Store lea addresses_RW+0x1e808, %rcx nop sub $40695, %rdi movl $0x51525354, (%rcx) nop cmp %r11, %r11 // Faulty Load lea addresses_RW+0x1e808, %r8 nop nop nop nop nop xor %rbp, %rbp vmovntdqa (%r8), %ymm0 vextracti128 $1, %ymm0, %xmm0 vpextrq $0, %xmm0, %rdi lea oracles, %rdx and $0xff, %rdi shlq $12, %rdi mov (%rdx,%rdi,1), %rdi pop %rdx pop %rdi pop %rcx pop %rbx pop %rbp pop %r8 pop %r11 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_RW', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_RW', 'size': 32, 'AVXalign': False, 'NT': True, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 3, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 1, 'AVXalign': False, 'NT': True, 'congruent': 8, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 7, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 11, 'same': False}} {'00': 4024} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
;=============================================================================== ; 16b - 16b ; Positive integers only, 1st byte must be greater than the 2nd one ;=============================================================================== include REG515.INC ;SFR Table ;------------------------------------------------------------------------------- MOV R0, #0FFh ;65 535 MOV R1, #0FFh MOV R2, #03Ch ;15 535 MOV R3, #0AFh ;expected result - C3 50 - 50 000 ;subb lower byte MOV A, R1 SUBB A, R3 MOV 11h, A ;subb high byte MOV A, R0 SUBB A, R2 MOV 10h, A MAIN: LJMP MAIN ;------------------------------------------------------------------------------- END
; A315536: Coordination sequence Gal.5.306.4 where G.u.t.v denotes the coordination sequence for a vertex of type v in tiling number t in the Galebach list of u-uniform tilings. ; 1,6,11,17,23,28,33,39,45,50,56,62,67,73,79,84,89,95,101,106,112,118,123,129,135,140,145,151,157,162,168,174,179,185,191,196,201,207,213,218,224,230,235,241,247,252,257,263,269,274 mov $5,$0 mov $7,$0 add $7,1 mov $8,$0 lpb $7 clr $0,5 mov $0,$5 sub $7,1 sub $0,$7 lpb $0 mov $1,$0 sub $1,$0 add $1,1 add $1,$0 sub $3,1 lpb $3 sub $0,1 mod $3,7 lpe sub $0,1 mul $1,3 sub $3,2 lpe div $1,2 add $1,1 add $6,$1 lpe mov $1,$6 add $1,$8
;Testname=O0; Arguments=-O0 -fbin -oexpimp.bin; Files=stdout stderr expimp.bin ;Testname=O1; Arguments=-O1 -fbin -oexpimp.bin; Files=stdout stderr expimp.bin ;Testname=Ox; Arguments=-Ox -fbin -oexpimp.bin; Files=stdout stderr expimp.bin ;Testname=error-O0; Arguments=-O0 -fbin -oexpimp.bin -DERROR; Files=stdout stderr expimp.bin ;Testname=error-Ox; Arguments=-Ox -fbin -oexpimp.bin -DERROR; Files=stdout stderr expimp.bin ; ; Test of explicitly and implicitly sized operands ; BITS 32 add esi,2 ; Implicit add esi,123456h ; Implicit add esi,byte 2 ; Explicit add esi,dword 2 ; Explicit add esi,dword 123456h ; Explicit add esi,byte 123456h ; Explicit Truncation add esi,strict 2 ; Implicit Strict add esi,strict 123456h ; Implicit Strict add esi,strict byte 2 ; Explicit Strict add esi,strict dword 2 ; Explicit Strict add esi,strict dword 123456h ; Explicit Strict add esi,strict byte 123456h ; Explicit Strict Truncation add eax,2 ; Implicit add eax,123456h ; Implicit add eax,byte 2 ; Explicit add eax,dword 2 ; Explicit add eax,dword 123456h ; Explicit add eax,byte 123456h ; Explicit Truncation add eax,strict 2 ; Implicit Strict add eax,strict 123456h ; Implicit Strict add eax,strict byte 2 ; Explicit Strict add eax,strict dword 2 ; Explicit Strict add eax,strict dword 123456h ; Explicit Strict add eax,strict byte 123456h ; Explicit Strict Truncation imul dx,3 ; Implicit imul dx,byte 3 ; Explicit imul dx,word 3 ; Explicit imul dx,strict byte 3 ; Explicit Strict imul dx,strict word 3 ; Explicit Strict ; ; Same thing with branches ; start: jmp short start ; Explicit jmp near start ; Explicit jmp word start ; Explicit jmp dword start ; Explicit jmp short forward ; Explicit jmp near forward ; Explicit jmp word forward ; Explicit jmp dword forward ; Explicit %ifdef ERROR jmp short faraway ; Explicit (ERROR) %endif jmp near faraway ; Explicit jmp word faraway ; Explicit jmp dword faraway ; Explicit jmp start ; Implicit jmp forward ; Implicit jmp faraway ; Implicit jmp strict short start ; Explicit Strict jmp strict near start ; Explicit Strict jmp strict word start ; Explicit Strict jmp strict dword start ; Explicit Strict jmp strict short forward ; Explicit Strict jmp strict near forward ; Explicit Strict jmp strict word forward ; Explicit Strict jmp strict dword forward ; Explicit Strict %ifdef ERROR jmp strict short faraway ; Explicit (ERROR) %endif jmp strict near faraway ; Explicit Strict jmp strict word faraway ; Explicit Strict jmp strict dword faraway ; Explicit Strict jmp strict start ; Implicit Strict jmp strict forward ; Implicit Strict jmp strict faraway ; Implicit Strict forward: times 256 nop faraway:
/** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ #include <aws/waf-regional/model/GetGeoMatchSetResult.h> #include <aws/core/utils/json/JsonSerializer.h> #include <aws/core/AmazonWebServiceResult.h> #include <aws/core/utils/StringUtils.h> #include <aws/core/utils/UnreferencedParam.h> #include <utility> using namespace Aws::WAFRegional::Model; using namespace Aws::Utils::Json; using namespace Aws::Utils; using namespace Aws; GetGeoMatchSetResult::GetGeoMatchSetResult() { } GetGeoMatchSetResult::GetGeoMatchSetResult(const Aws::AmazonWebServiceResult<JsonValue>& result) { *this = result; } GetGeoMatchSetResult& GetGeoMatchSetResult::operator =(const Aws::AmazonWebServiceResult<JsonValue>& result) { JsonView jsonValue = result.GetPayload().View(); if(jsonValue.ValueExists("GeoMatchSet")) { m_geoMatchSet = jsonValue.GetObject("GeoMatchSet"); } return *this; }
// // Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.20714 // // /// // Buffer Definitions: // // cbuffer cbMultiPerFrameFrame // { // // float4x4 mWorldViewProj; // Offset: 0 Size: 64 [unused] // float4x4 mWorldView; // Offset: 64 Size: 64 [unused] // float4x4 mWorld; // Offset: 128 Size: 64 // float4x4 mView; // Offset: 192 Size: 64 [unused] // float4x4 mProj; // Offset: 256 Size: 64 [unused] // float3 vEye; // Offset: 320 Size: 12 [unused] // // } // // // Resource Bindings: // // Name Type Format Dim Slot Elements // ------------------------------ ---------- ------- ----------- ---- -------- // cbMultiPerFrameFrame cbuffer NA NA 0 1 // // // // Input signature: // // Name Index Mask Register SysValue Format Used // -------------------- ----- ------ -------- -------- ------- ------ // POSITION 0 xyzw 0 NONE float xyzw // NORMAL 0 xyz 1 NONE float // TEXCOORD 0 xy 2 NONE float xy // // // Output signature: // // Name Index Mask Register SysValue Format Used // -------------------- ----- ------ -------- -------- ------- ------ // SV_POSITION 0 xyzw 0 POS float xyzw // TEXCOORD 0 xy 1 NONE float xy // vs_4_0 dcl_constantbuffer cb0[12], immediateIndexed dcl_input v0.xyzw dcl_input v2.xy dcl_output_siv o0.xyzw, position dcl_output o1.xy dp4 o0.x, v0.xyzw, cb0[8].xyzw dp4 o0.y, v0.xyzw, cb0[9].xyzw dp4 o0.z, v0.xyzw, cb0[10].xyzw dp4 o0.w, v0.xyzw, cb0[11].xyzw mov o1.xy, v2.xyxx ret // Approximately 6 instruction slots used
; A132141: Numbers whose ternary representation begins with 1. ; 1,3,4,5,9,10,11,12,13,14,15,16,17,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140 seq $0,297251 ; Numbers whose base-3 digits have greater up-variation than down-variation; see Comments. sub $0,5 div $0,3 add $0,1
.model small .data num1 db 0,0,0,0,0,0,0,1,0,0,'$' decimales_1 db 0,9,9,0,0,0,0,0,0,0,'$' num2 db 0,0,0,0,0,0,0,0,9,9,'$' decimales_2 db 0,9,9,0,0,0,0,0,0,0,'$' num_res db 0,0,0,0,0,0,0,0,0,0,'$' decimales_Res db 0,0,0,0,0,0,0,0,0,0,'$' hay_acarreo db 0h .stack .code begin proc far mov ax,@data mov ds,ax CALL SUMA ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;IMPRIMIR RESULTADO LEA DX,num_res MOV AH,09 INT 21H MOV AH,02 MOV DL,'.' INT 21H LEA DX,decimales_Res MOV AH,09 INT 21H XOR AX,AX INT 16H begin endp ;;;;;;;;;;;PROCEDIMIENTOS SUMA PROC NEAR ;SUMAR PARTES ENTERAS SIN IMPORTAR ACARREOS MOV SI,09h JMP siguiente_entero fin_enteros: MOV num_res[SI],'$' DEC SI JMP siguiente_entero siguiente_entero: MOV AL,num1[SI] CMP AL,24h ;si es el fin de cadena JE fin_enteros ADD AL,num2[SI] MOV num_res[SI],AL DEC SI JNS siguiente_entero ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MOV num1[0Ah],'$' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;SUMAR PARTES DECIMALES SIN IMPORTAR ACARREOS MOV SI,0Ah JMP siguiente_decimal fin_decimales: MOV decimales_Res[SI],'$' DEC SI JMP siguiente_decimal siguiente_decimal: MOV AL,decimales_1[SI] CMP AL,24h ;si es el fin de cadena JE fin_decimales ADD AL,decimales_2[SI] MOV decimales_Res[SI],AL DEC SI JNS siguiente_decimal ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; JMP primer_vezSumando acarreo_del_Acarreo: MOV hay_acarreo,00h primer_vezSumando: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;AJUSTAR LOS ACARREOS DECIMALES MOV SI,0Ah JMP siguiente_Acarreo_decimal ; es_fin_decimal: DEC SI JMP siguiente_Acarreo_decimal ; AcarreoDecimal: MOV hay_acarreo,01h MOV Al,decimales_Res[SI] AAM ;;si es el primer numero decimal deselo a los enteros cmp SI,0000h JNE no_es_primero JMP es_primero ;; no_es_primero: ADD decimales_Res[SI-1],Ah MOV decimales_Res[SI],Al DEC SI JMP siguiente_Acarreo_decimal es_primero: ;;--> es primero MOV decimales_Res[SI],Al DEC SI ;;fin el primero siguiente_Acarreo_decimal: CMP SI,0FFFFh JE fin_ajuste_AcarreoDecimal CMP decimales_Res[SI],'$' JE es_fin_decimal CMP decimales_Res[SI],0Ah JAE AcarreoDecimal DEC SI JNS siguiente_Acarreo_decimal ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; fin_ajuste_AcarreoDecimal: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;AJUSTAR LOS ACARREOS ENTEROS MOV SI,09h JMP siguiente_Acarreo_entero ; es_fin_entero: DEC SI ;MOV posicion_ultimo_entero,SI JMP siguiente_Acarreo_entero ; AcarreoEntero: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CMP SI,0000h MOV hay_acarreo,01h MOV Al,num_res[SI] AAM ADD num_res[SI-1],Ah MOV num_res[SI],Al DEC SI siguiente_Acarreo_entero: CMP decimales_Res[SI-1],'$' JE es_fin_entero CMP num_res[SI],0Ah JAE AcarreoEntero DEC SI JNS siguiente_Acarreo_entero ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;AGREGAR ACARREOS PENDIENTES MOV AL,num_res[09h] ADD AL,decimales_Res[0h] MOV num_res[09h],Al MOV decimales_Res[0h],00h ;limpiar el acarreo CMP hay_acarreo,01h JE acarreo_del_Acarreo ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;AJUSTAR PARA IMPRESION ;;ajustar la parte entera MOV SI,09h JMP inicia_ajuste salta_fin: DEC SI JMP inicia_ajuste inicia_ajuste: MOV AL,num_res[SI] CMP AL,24h JE salta_fin ADD AL,30h MOV num_res[SI],AL DEC SI JNS inicia_ajuste ;;ajustar la parte decimal MOV SI,09h JMP inicia_ajuste_d salta_fin_d: DEC SI JMP inicia_ajuste_d inicia_ajuste_d: MOV AL,decimales_Res[SI] CMP AL,24h JE salta_fin_d ADD AL,30h MOV decimales_Res[SI],AL DEC SI JNS inicia_ajuste_d MOV decimales_Res[0h],07h ;limpiar el acarreo RET ENDP end begin
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r8 push %rax push %rdx lea addresses_WC_ht+0x1e243, %r11 clflush (%r11) add %rax, %rax mov $0x6162636465666768, %rdx movq %rdx, %xmm7 vmovups %ymm7, (%r11) inc %r8 pop %rdx pop %rax pop %r8 pop %r11 ret .global s_faulty_load s_faulty_load: push %r11 push %r14 push %r8 push %rcx push %rdi // Faulty Load lea addresses_US+0x15f43, %rcx clflush (%rcx) nop nop nop nop nop cmp %r14, %r14 mov (%rcx), %r11d lea oracles, %r14 and $0xff, %r11 shlq $12, %r11 mov (%r14,%r11,1), %r11 pop %rdi pop %rcx pop %r8 pop %r14 pop %r11 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': False, 'NT': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': True, 'NT': True}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 7, 'size': 32, 'same': False, 'NT': False}} {'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 */
#ifndef SYNCH_PARTICLE_REDEFINITION_H #define SYNCH_PARTICLE_REDEFINITION_H //pyORBIT utils #include "CppPyWrapper.hh" #include "Bunch.hh" using namespace std; /** The SynchPartRedefinitionZdE class calculates the average of z and dE coordinates redefines the syncronous particle's energy to move the synch. particle to the center of the bunch's phase space. */ class SynchPartRedefinitionZdE: public OrbitUtils::CppPyWrapper { public: /** Constructor*/ SynchPartRedefinitionZdE(); /** Destructor */ virtual ~SynchPartRedefinitionZdE(); /** Performs the calculation of the z and dE averages of the bunch */ void analyzeBunch(Bunch* bunch); /** Transforms the synch particle parameters and the coordinates of the particles */ void transformBunch(Bunch* bunch); /**Returns the average z postion */ double getAvg_Z(); /** Returns the average dE value */ double getAvg_dE(); private: /** array with average values for z and dE coordinates */ double* z_dE_avg_arr; double* z_dE_avg_arr_MPI; }; #endif //endif for SYNCH_PARTICLE_REDEFINITION_H
;;; GLOBAL DESCRIPTOR TABLE gdt_start: gdt_null: ; mandatory null descriptor dd 0x0 dd 0x0 gdt_code: ; code segment descriptor ; base=0x0, limit=0xfffff, ; 1st flags: (present)1 (privilege)00 (descriptor type)1 -> 1001b ; type flags: (code)1 (conforming)0 (readable)1 (accessed)0 -> 1010b ; 2nd flags: (granularity)1 (32-bit default)1 (64-bit seg)0 (AVL)0 -> 1100b dw 0xffff ; limit (bits 0-15) dw 0x0 ; base (bits 0-15) db 0x0 ; base (bits 16-23) db 10011010b ; 1st flags (type flags) db 11001111b ; 2nd flags (limit) (bits 16-29) db 0x0 ; base (bits 24-31) gdt_data: ; data segment descriptor ; Same as code segment except for the type flags ; type flags: (code)0 (expand down)0 (writable)1 (accessed)0 -> 0010b dw 0xffff ; limit (bits 0-15) dw 0x0 ; base (bits 0-15) db 0x0 ; base (bits 16-23) db 10010010b ; 1st flags (type flags) db 11001111b ; 2nd flags (limit) (bits 16-29) db 0x0 ; base (bits 24-31) gdt_end: ; for calculating the end of the GDT below ; GDT descriptor gdtr: dw gdt_end - gdt_start - 1 ; size of GDT dd gdt_start ; start address of GDT CODE_SEG equ gdt_code - gdt_start DATA_SEG equ gdt_data - gdt_start
; ; Z88dk Generic Floating Point Math Library ; ; Find exponent for product (l=0) or quotient(l=ff) ; ; $Id: div14.asm,v 1.4 2016-06-21 21:16:49 dom Exp $: SECTION code_fp PUBLIC div14 EXTERN unpack EXTERN norm4 EXTERN fa .div14 LD A,B OR A JR Z,DIV20 LD A,L ;get product/quotient flag LD HL,fa+5 XOR (HL) ;get +-FA exponent ADD A,B ;find and... LD B,A ;...load new exponent RRA XOR B LD A,B JP P,DIV18 ADD A,$80 LD (HL),A Jr Z,div14_1 CALL unpack ;restore hidden bits & compare signs LD (HL),A ;save difference of signs DEC HL ;point to MSB of fraction RET .div14_1 pop hl ret .DIV18 or a .DIV20 pop hl jp p,norm4 ret ;jp oflow
############################################################################### # Copyright 2019 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 .p2align 6, 0x90 .globl n0_DecryptECB_RIJ128pipe_AES_NI .type n0_DecryptECB_RIJ128pipe_AES_NI, @function n0_DecryptECB_RIJ128pipe_AES_NI: lea (,%rdx,4), %rax movslq %r8d, %r8 sub $(64), %r8 jl .Lshort_inputgas_1 .Lblks_loopgas_1: lea (%rcx,%rax,4), %r9 movdqa (%r9), %xmm4 sub $(16), %r9 movdqu (%rdi), %xmm0 movdqu (16)(%rdi), %xmm1 movdqu (32)(%rdi), %xmm2 movdqu (48)(%rdi), %xmm3 add $(64), %rdi pxor %xmm4, %xmm0 pxor %xmm4, %xmm1 pxor %xmm4, %xmm2 pxor %xmm4, %xmm3 movdqa (%r9), %xmm4 sub $(16), %r9 mov %rdx, %r10 sub $(1), %r10 .Lcipher_loopgas_1: aesdec %xmm4, %xmm0 aesdec %xmm4, %xmm1 aesdec %xmm4, %xmm2 aesdec %xmm4, %xmm3 movdqa (%r9), %xmm4 sub $(16), %r9 dec %r10 jnz .Lcipher_loopgas_1 aesdeclast %xmm4, %xmm0 movdqu %xmm0, (%rsi) aesdeclast %xmm4, %xmm1 movdqu %xmm1, (16)(%rsi) aesdeclast %xmm4, %xmm2 movdqu %xmm2, (32)(%rsi) aesdeclast %xmm4, %xmm3 movdqu %xmm3, (48)(%rsi) add $(64), %rsi sub $(64), %r8 jge .Lblks_loopgas_1 .Lshort_inputgas_1: add $(64), %r8 jz .Lquitgas_1 lea (%rcx,%rax,4), %r9 .p2align 6, 0x90 .Lsingle_blk_loopgas_1: movdqu (%rdi), %xmm0 add $(16), %rdi pxor (%r9), %xmm0 cmp $(12), %rdx jl .Lkey_128_sgas_1 jz .Lkey_192_sgas_1 .Lkey_256_sgas_1: aesdec (208)(%rcx), %xmm0 aesdec (192)(%rcx), %xmm0 .Lkey_192_sgas_1: aesdec (176)(%rcx), %xmm0 aesdec (160)(%rcx), %xmm0 .Lkey_128_sgas_1: aesdec (144)(%rcx), %xmm0 aesdec (128)(%rcx), %xmm0 aesdec (112)(%rcx), %xmm0 aesdec (96)(%rcx), %xmm0 aesdec (80)(%rcx), %xmm0 aesdec (64)(%rcx), %xmm0 aesdec (48)(%rcx), %xmm0 aesdec (32)(%rcx), %xmm0 aesdec (16)(%rcx), %xmm0 aesdeclast (%rcx), %xmm0 movdqu %xmm0, (%rsi) add $(16), %rsi sub $(16), %r8 jnz .Lsingle_blk_loopgas_1 .Lquitgas_1: pxor %xmm4, %xmm4 ret .Lfe1: .size n0_DecryptECB_RIJ128pipe_AES_NI, .Lfe1-(n0_DecryptECB_RIJ128pipe_AES_NI)
_zombie: file format elf32-i386 Disassembly of section .text: 00000000 <main>: #include "stat.h" #include "user.h" int main(void) { 0: 8d 4c 24 04 lea 0x4(%esp),%ecx 4: 83 e4 f0 and $0xfffffff0,%esp 7: ff 71 fc pushl -0x4(%ecx) a: 55 push %ebp b: 89 e5 mov %esp,%ebp d: 51 push %ecx e: 83 ec 04 sub $0x4,%esp if(fork() > 0) 11: e8 74 02 00 00 call 28a <fork> 16: 85 c0 test %eax,%eax 18: 7e 0d jle 27 <main+0x27> sleep(5); // Let child exit before parent. 1a: 83 ec 0c sub $0xc,%esp 1d: 6a 05 push $0x5 1f: e8 fe 02 00 00 call 322 <sleep> 24: 83 c4 10 add $0x10,%esp exit(0); 27: 83 ec 0c sub $0xc,%esp 2a: 6a 00 push $0x0 2c: e8 61 02 00 00 call 292 <exit> 31: 66 90 xchg %ax,%ax 33: 66 90 xchg %ax,%ax 35: 66 90 xchg %ax,%ax 37: 66 90 xchg %ax,%ax 39: 66 90 xchg %ax,%ax 3b: 66 90 xchg %ax,%ax 3d: 66 90 xchg %ax,%ax 3f: 90 nop 00000040 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, const char *t) { 40: 55 push %ebp 41: 89 e5 mov %esp,%ebp 43: 53 push %ebx 44: 8b 45 08 mov 0x8(%ebp),%eax 47: 8b 4d 0c mov 0xc(%ebp),%ecx char *os; os = s; while((*s++ = *t++) != 0) 4a: 89 c2 mov %eax,%edx 4c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 50: 83 c1 01 add $0x1,%ecx 53: 0f b6 59 ff movzbl -0x1(%ecx),%ebx 57: 83 c2 01 add $0x1,%edx 5a: 84 db test %bl,%bl 5c: 88 5a ff mov %bl,-0x1(%edx) 5f: 75 ef jne 50 <strcpy+0x10> ; return os; } 61: 5b pop %ebx 62: 5d pop %ebp 63: c3 ret 64: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 6a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 00000070 <strcmp>: int strcmp(const char *p, const char *q) { 70: 55 push %ebp 71: 89 e5 mov %esp,%ebp 73: 53 push %ebx 74: 8b 55 08 mov 0x8(%ebp),%edx 77: 8b 4d 0c mov 0xc(%ebp),%ecx while(*p && *p == *q) 7a: 0f b6 02 movzbl (%edx),%eax 7d: 0f b6 19 movzbl (%ecx),%ebx 80: 84 c0 test %al,%al 82: 75 1c jne a0 <strcmp+0x30> 84: eb 2a jmp b0 <strcmp+0x40> 86: 8d 76 00 lea 0x0(%esi),%esi 89: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi p++, q++; 90: 83 c2 01 add $0x1,%edx while(*p && *p == *q) 93: 0f b6 02 movzbl (%edx),%eax p++, q++; 96: 83 c1 01 add $0x1,%ecx 99: 0f b6 19 movzbl (%ecx),%ebx while(*p && *p == *q) 9c: 84 c0 test %al,%al 9e: 74 10 je b0 <strcmp+0x40> a0: 38 d8 cmp %bl,%al a2: 74 ec je 90 <strcmp+0x20> return (uchar)*p - (uchar)*q; a4: 29 d8 sub %ebx,%eax } a6: 5b pop %ebx a7: 5d pop %ebp a8: c3 ret a9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi b0: 31 c0 xor %eax,%eax return (uchar)*p - (uchar)*q; b2: 29 d8 sub %ebx,%eax } b4: 5b pop %ebx b5: 5d pop %ebp b6: c3 ret b7: 89 f6 mov %esi,%esi b9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000000c0 <strlen>: uint strlen(const char *s) { c0: 55 push %ebp c1: 89 e5 mov %esp,%ebp c3: 8b 4d 08 mov 0x8(%ebp),%ecx int n; for(n = 0; s[n]; n++) c6: 80 39 00 cmpb $0x0,(%ecx) c9: 74 15 je e0 <strlen+0x20> cb: 31 d2 xor %edx,%edx cd: 8d 76 00 lea 0x0(%esi),%esi d0: 83 c2 01 add $0x1,%edx d3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1) d7: 89 d0 mov %edx,%eax d9: 75 f5 jne d0 <strlen+0x10> ; return n; } db: 5d pop %ebp dc: c3 ret dd: 8d 76 00 lea 0x0(%esi),%esi for(n = 0; s[n]; n++) e0: 31 c0 xor %eax,%eax } e2: 5d pop %ebp e3: c3 ret e4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi ea: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 000000f0 <memset>: void* memset(void *dst, int c, uint n) { f0: 55 push %ebp f1: 89 e5 mov %esp,%ebp f3: 57 push %edi f4: 8b 55 08 mov 0x8(%ebp),%edx } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : f7: 8b 4d 10 mov 0x10(%ebp),%ecx fa: 8b 45 0c mov 0xc(%ebp),%eax fd: 89 d7 mov %edx,%edi ff: fc cld 100: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 102: 89 d0 mov %edx,%eax 104: 5f pop %edi 105: 5d pop %ebp 106: c3 ret 107: 89 f6 mov %esi,%esi 109: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000110 <strchr>: char* strchr(const char *s, char c) { 110: 55 push %ebp 111: 89 e5 mov %esp,%ebp 113: 53 push %ebx 114: 8b 45 08 mov 0x8(%ebp),%eax 117: 8b 5d 0c mov 0xc(%ebp),%ebx for(; *s; s++) 11a: 0f b6 10 movzbl (%eax),%edx 11d: 84 d2 test %dl,%dl 11f: 74 1d je 13e <strchr+0x2e> if(*s == c) 121: 38 d3 cmp %dl,%bl 123: 89 d9 mov %ebx,%ecx 125: 75 0d jne 134 <strchr+0x24> 127: eb 17 jmp 140 <strchr+0x30> 129: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 130: 38 ca cmp %cl,%dl 132: 74 0c je 140 <strchr+0x30> for(; *s; s++) 134: 83 c0 01 add $0x1,%eax 137: 0f b6 10 movzbl (%eax),%edx 13a: 84 d2 test %dl,%dl 13c: 75 f2 jne 130 <strchr+0x20> return (char*)s; return 0; 13e: 31 c0 xor %eax,%eax } 140: 5b pop %ebx 141: 5d pop %ebp 142: c3 ret 143: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 149: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000150 <gets>: char* gets(char *buf, int max) { 150: 55 push %ebp 151: 89 e5 mov %esp,%ebp 153: 57 push %edi 154: 56 push %esi 155: 53 push %ebx int i, cc; char c; for(i=0; i+1 < max; ){ 156: 31 f6 xor %esi,%esi 158: 89 f3 mov %esi,%ebx { 15a: 83 ec 1c sub $0x1c,%esp 15d: 8b 7d 08 mov 0x8(%ebp),%edi for(i=0; i+1 < max; ){ 160: eb 2f jmp 191 <gets+0x41> 162: 8d b6 00 00 00 00 lea 0x0(%esi),%esi cc = read(0, &c, 1); 168: 8d 45 e7 lea -0x19(%ebp),%eax 16b: 83 ec 04 sub $0x4,%esp 16e: 6a 01 push $0x1 170: 50 push %eax 171: 6a 00 push $0x0 173: e8 32 01 00 00 call 2aa <read> if(cc < 1) 178: 83 c4 10 add $0x10,%esp 17b: 85 c0 test %eax,%eax 17d: 7e 1c jle 19b <gets+0x4b> break; buf[i++] = c; 17f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax 183: 83 c7 01 add $0x1,%edi 186: 88 47 ff mov %al,-0x1(%edi) if(c == '\n' || c == '\r') 189: 3c 0a cmp $0xa,%al 18b: 74 23 je 1b0 <gets+0x60> 18d: 3c 0d cmp $0xd,%al 18f: 74 1f je 1b0 <gets+0x60> for(i=0; i+1 < max; ){ 191: 83 c3 01 add $0x1,%ebx 194: 3b 5d 0c cmp 0xc(%ebp),%ebx 197: 89 fe mov %edi,%esi 199: 7c cd jl 168 <gets+0x18> 19b: 89 f3 mov %esi,%ebx break; } buf[i] = '\0'; return buf; } 19d: 8b 45 08 mov 0x8(%ebp),%eax buf[i] = '\0'; 1a0: c6 03 00 movb $0x0,(%ebx) } 1a3: 8d 65 f4 lea -0xc(%ebp),%esp 1a6: 5b pop %ebx 1a7: 5e pop %esi 1a8: 5f pop %edi 1a9: 5d pop %ebp 1aa: c3 ret 1ab: 90 nop 1ac: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 1b0: 8b 75 08 mov 0x8(%ebp),%esi 1b3: 8b 45 08 mov 0x8(%ebp),%eax 1b6: 01 de add %ebx,%esi 1b8: 89 f3 mov %esi,%ebx buf[i] = '\0'; 1ba: c6 03 00 movb $0x0,(%ebx) } 1bd: 8d 65 f4 lea -0xc(%ebp),%esp 1c0: 5b pop %ebx 1c1: 5e pop %esi 1c2: 5f pop %edi 1c3: 5d pop %ebp 1c4: c3 ret 1c5: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 1c9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000001d0 <stat>: int stat(const char *n, struct stat *st) { 1d0: 55 push %ebp 1d1: 89 e5 mov %esp,%ebp 1d3: 56 push %esi 1d4: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); 1d5: 83 ec 08 sub $0x8,%esp 1d8: 6a 00 push $0x0 1da: ff 75 08 pushl 0x8(%ebp) 1dd: e8 f0 00 00 00 call 2d2 <open> if(fd < 0) 1e2: 83 c4 10 add $0x10,%esp 1e5: 85 c0 test %eax,%eax 1e7: 78 27 js 210 <stat+0x40> return -1; r = fstat(fd, st); 1e9: 83 ec 08 sub $0x8,%esp 1ec: ff 75 0c pushl 0xc(%ebp) 1ef: 89 c3 mov %eax,%ebx 1f1: 50 push %eax 1f2: e8 f3 00 00 00 call 2ea <fstat> close(fd); 1f7: 89 1c 24 mov %ebx,(%esp) r = fstat(fd, st); 1fa: 89 c6 mov %eax,%esi close(fd); 1fc: e8 b9 00 00 00 call 2ba <close> return r; 201: 83 c4 10 add $0x10,%esp } 204: 8d 65 f8 lea -0x8(%ebp),%esp 207: 89 f0 mov %esi,%eax 209: 5b pop %ebx 20a: 5e pop %esi 20b: 5d pop %ebp 20c: c3 ret 20d: 8d 76 00 lea 0x0(%esi),%esi return -1; 210: be ff ff ff ff mov $0xffffffff,%esi 215: eb ed jmp 204 <stat+0x34> 217: 89 f6 mov %esi,%esi 219: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000220 <atoi>: int atoi(const char *s) { 220: 55 push %ebp 221: 89 e5 mov %esp,%ebp 223: 53 push %ebx 224: 8b 4d 08 mov 0x8(%ebp),%ecx int n; n = 0; while('0' <= *s && *s <= '9') 227: 0f be 11 movsbl (%ecx),%edx 22a: 8d 42 d0 lea -0x30(%edx),%eax 22d: 3c 09 cmp $0x9,%al n = 0; 22f: b8 00 00 00 00 mov $0x0,%eax while('0' <= *s && *s <= '9') 234: 77 1f ja 255 <atoi+0x35> 236: 8d 76 00 lea 0x0(%esi),%esi 239: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi n = n*10 + *s++ - '0'; 240: 8d 04 80 lea (%eax,%eax,4),%eax 243: 83 c1 01 add $0x1,%ecx 246: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax while('0' <= *s && *s <= '9') 24a: 0f be 11 movsbl (%ecx),%edx 24d: 8d 5a d0 lea -0x30(%edx),%ebx 250: 80 fb 09 cmp $0x9,%bl 253: 76 eb jbe 240 <atoi+0x20> return n; } 255: 5b pop %ebx 256: 5d pop %ebp 257: c3 ret 258: 90 nop 259: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000260 <memmove>: void* memmove(void *vdst, const void *vsrc, int n) { 260: 55 push %ebp 261: 89 e5 mov %esp,%ebp 263: 56 push %esi 264: 53 push %ebx 265: 8b 5d 10 mov 0x10(%ebp),%ebx 268: 8b 45 08 mov 0x8(%ebp),%eax 26b: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 26e: 85 db test %ebx,%ebx 270: 7e 14 jle 286 <memmove+0x26> 272: 31 d2 xor %edx,%edx 274: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi *dst++ = *src++; 278: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx 27c: 88 0c 10 mov %cl,(%eax,%edx,1) 27f: 83 c2 01 add $0x1,%edx while(n-- > 0) 282: 39 d3 cmp %edx,%ebx 284: 75 f2 jne 278 <memmove+0x18> return vdst; } 286: 5b pop %ebx 287: 5e pop %esi 288: 5d pop %ebp 289: c3 ret 0000028a <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 28a: b8 01 00 00 00 mov $0x1,%eax 28f: cd 40 int $0x40 291: c3 ret 00000292 <exit>: SYSCALL(exit) 292: b8 02 00 00 00 mov $0x2,%eax 297: cd 40 int $0x40 299: c3 ret 0000029a <wait>: SYSCALL(wait) 29a: b8 03 00 00 00 mov $0x3,%eax 29f: cd 40 int $0x40 2a1: c3 ret 000002a2 <pipe>: SYSCALL(pipe) 2a2: b8 04 00 00 00 mov $0x4,%eax 2a7: cd 40 int $0x40 2a9: c3 ret 000002aa <read>: SYSCALL(read) 2aa: b8 05 00 00 00 mov $0x5,%eax 2af: cd 40 int $0x40 2b1: c3 ret 000002b2 <write>: SYSCALL(write) 2b2: b8 10 00 00 00 mov $0x10,%eax 2b7: cd 40 int $0x40 2b9: c3 ret 000002ba <close>: SYSCALL(close) 2ba: b8 15 00 00 00 mov $0x15,%eax 2bf: cd 40 int $0x40 2c1: c3 ret 000002c2 <kill>: SYSCALL(kill) 2c2: b8 06 00 00 00 mov $0x6,%eax 2c7: cd 40 int $0x40 2c9: c3 ret 000002ca <exec>: SYSCALL(exec) 2ca: b8 07 00 00 00 mov $0x7,%eax 2cf: cd 40 int $0x40 2d1: c3 ret 000002d2 <open>: SYSCALL(open) 2d2: b8 0f 00 00 00 mov $0xf,%eax 2d7: cd 40 int $0x40 2d9: c3 ret 000002da <mknod>: SYSCALL(mknod) 2da: b8 11 00 00 00 mov $0x11,%eax 2df: cd 40 int $0x40 2e1: c3 ret 000002e2 <unlink>: SYSCALL(unlink) 2e2: b8 12 00 00 00 mov $0x12,%eax 2e7: cd 40 int $0x40 2e9: c3 ret 000002ea <fstat>: SYSCALL(fstat) 2ea: b8 08 00 00 00 mov $0x8,%eax 2ef: cd 40 int $0x40 2f1: c3 ret 000002f2 <link>: SYSCALL(link) 2f2: b8 13 00 00 00 mov $0x13,%eax 2f7: cd 40 int $0x40 2f9: c3 ret 000002fa <mkdir>: SYSCALL(mkdir) 2fa: b8 14 00 00 00 mov $0x14,%eax 2ff: cd 40 int $0x40 301: c3 ret 00000302 <chdir>: SYSCALL(chdir) 302: b8 09 00 00 00 mov $0x9,%eax 307: cd 40 int $0x40 309: c3 ret 0000030a <dup>: SYSCALL(dup) 30a: b8 0a 00 00 00 mov $0xa,%eax 30f: cd 40 int $0x40 311: c3 ret 00000312 <getpid>: SYSCALL(getpid) 312: b8 0b 00 00 00 mov $0xb,%eax 317: cd 40 int $0x40 319: c3 ret 0000031a <sbrk>: SYSCALL(sbrk) 31a: b8 0c 00 00 00 mov $0xc,%eax 31f: cd 40 int $0x40 321: c3 ret 00000322 <sleep>: SYSCALL(sleep) 322: b8 0d 00 00 00 mov $0xd,%eax 327: cd 40 int $0x40 329: c3 ret 0000032a <uptime>: SYSCALL(uptime) 32a: b8 0e 00 00 00 mov $0xe,%eax 32f: cd 40 int $0x40 331: c3 ret 00000332 <memsize>: SYSCALL(memsize) 332: b8 16 00 00 00 mov $0x16,%eax 337: cd 40 int $0x40 339: c3 ret 0000033a <set_ps_priority>: SYSCALL(set_ps_priority) 33a: b8 17 00 00 00 mov $0x17,%eax 33f: cd 40 int $0x40 341: c3 ret 00000342 <set_cfs_priority>: SYSCALL(set_cfs_priority) 342: b8 18 00 00 00 mov $0x18,%eax 347: cd 40 int $0x40 349: c3 ret 0000034a <policy>: SYSCALL(policy) 34a: b8 19 00 00 00 mov $0x19,%eax 34f: cd 40 int $0x40 351: c3 ret 00000352 <proc_info>: 352: b8 1a 00 00 00 mov $0x1a,%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 60 07 00 00 movzbl 0x760(%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 dd fe ff ff call 2b2 <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 6d fe ff ff call 2b2 <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 0c fe ff ff call 2b2 <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 f3 fd ff ff call 2b2 <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 58 fd ff ff call 2b2 <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 06 fd ff ff call 2b2 <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 58 07 00 00 mov $0x758,%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 04 0a 00 00 mov 0xa04,%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 04 0a 00 00 mov %eax,0xa04 } 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 04 0a 00 00 mov %eax,0xa04 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 04 0a 00 00 mov 0xa04,%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 04 0a 00 00 cmp %eax,0xa04 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 56 fc ff ff call 31a <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 04 0a 00 00 mov 0xa04,%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 04 0a 00 00 mov %edx,0xa04 } 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 04 0a 00 00 08 movl $0xa08,0xa04 727: 0a 00 00 72a: c7 05 08 0a 00 00 08 movl $0xa08,0xa08 731: 0a 00 00 base.s.size = 0; 734: b8 08 0a 00 00 mov $0xa08,%eax 739: c7 05 0c 0a 00 00 00 movl $0x0,0xa0c 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>
/* * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz * Copyright 2010, Clemens Zeidler <haiku@clemens-zeidler.de> * Distributed under the terms of the MIT License. */ #include <Application.h> #include <File.h> #include <Button.h> #include <Window.h> #include "ALMLayout.h" #include "Row.h" #include "Column.h" class TableDemoWindow : public BWindow { public: TableDemoWindow(BRect frame) : BWindow(frame, "ALM Table Demo", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE) { // create a new BALMLayout and use it for this window BALMLayout* layout = new BALMLayout(); SetLayout(layout); Column* c1 = layout->AddColumn(layout->Left(), layout->Right()); Row* r1 = layout->AddRow(layout->Top(), NULL); Row* r2 = layout->AddRow(r1->Bottom(), NULL); Row* r3 = layout->AddRow(r2->Bottom(), layout->Bottom()); BButton* b1 = new BButton("A1"); layout->AddView(b1, r1, c1); b1->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP)); BButton* b2 = new BButton("A2"); layout->AddView(b2, r2, c1); b2->SetExplicitAlignment(BAlignment( B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER)); BButton* b3 = new BButton("A3"); layout->AddView(b3, r3, c1); b3->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_BOTTOM)); // test size limits BSize min = layout->MinSize(); BSize max = layout->MaxSize(); SetSizeLimits(min.Width(), max.Width(), min.Height(), max.Height()); } }; class TableDemo : public BApplication { public: TableDemo() : BApplication("application/x-vnd.haiku.table-demo") { BRect frameRect; frameRect.Set(100, 100, 400, 400); TableDemoWindow* window = new TableDemoWindow(frameRect); window->Show(); } }; int main() { TableDemo app; app.Run(); return 0; }
; A080775: Number of n X n monomial matrices whose nonzero entries are unit Hurwitz quaternions. ; 1,24,1152,82944,7962624,955514880,137594142720,23115815976960,4438236667576320,958659120196485120,230078188847156428800,60740641855649297203200,17493304854426997594521600,5457911114581223249490739200,1833858134499291011828888371200,660188928419744764258399813632000 mul $0,2 mov $2,1 lpb $0 sub $0,2 mul $2,4 add $3,6 mul $2,$3 lpe mov $0,$2
; Tests instructions CMP (all addressing modes) & BEQ & BNE. ; Assumes that loads & stores work with all addressing modes. ; Also assumes that AND & ORA & EOR work with all addressing modes. ; ; Expected Results: $15 = 0x7F ; Note that this test does not seem to work in 6502js, but Visual 6502 gives the ; correct result start: ; prepare memory LDA #$00 STA $34 LDA #$FF STA $0130 LDA #$99 STA $019D LDA #$DB STA $0199 LDA #$2F STA $32 LDA #$32 STA $4F LDA #$30 STA $33 LDA #$70 STA $AF LDA #$18 STA $30 ; imm CMP #$18 BEQ beq1 ; taken AND #$00 ; not done beq1: ; zpg ORA #$01 CMP $30 BNE bne1 ; taken AND #$00 ; not done bne1: ; abs LDX #$00 CMP $0130 BEQ beq2 ; not taken STA $40 LDX $40 beq2: ; zpx CMP $27,X BNE bne2 ; not taken ORA #$84 STA $41 LDX $41 bne2: ; abx AND #$DB CMP $0100,X BEQ beq3 ; taken AND #$00 ; not done beq3: ; aby STA $42 LDY $42 AND #$00 CMP $0100,Y BNE bne3 ; taken ORA #$0F ; not done bne3: ; idx STA $43 LDX $43 ORA #$24 CMP ($40,X) ; TODO: Reads from $9D19, which is uninitialized... BEQ beq4 ; not taken ORA #$7F beq4: ; idy STA $44 LDY $44 EOR #$0F CMP ($33),Y BNE bne4 ; not taken LDA $44 STA $15 bne4:
; ; Startup for Sorcerer Exidy ; ; $Id: sorcerer_crt0.asm,v 1.15 2016-07-15 21:03:25 dom Exp $ ; ; There are a couple of #pragma commands which affect ; this file: ; ; #pragma no-streams - No stdio disc files ; #pragma no-fileio - No fileio at all ; ; These can cut down the size of the resultant executable MODULE sorcerer_crt0 ;------------------------------------------------- ; Include zcc_opt.def to find out some information ;------------------------------------------------- defc crt0 = 1 INCLUDE "zcc_opt.def" ;----------------------- ; Some scope definitions ;----------------------- EXTERN _main ;main() is always external to crt0 PUBLIC cleanup ;jp'd to by exit() PUBLIC l_dcal ;jp(hl) ;-------- ; Set an origin for the application (-zorg=) default to 100h ;-------- IF !DEFINED_CRT_ORG_CODE defc CRT_ORG_CODE = 100h ENDIF org CRT_ORG_CODE ;---------------------- ; Execution starts here ;---------------------- start: ld (start1+1),sp ;Save entry stack ld hl,-64 add hl,sp ld sp,hl call crt0_init_bss ld (exitsp),sp ; Optional definition for auto MALLOC init ; it assumes we have free space between the end of ; the compiled program and the stack pointer IF DEFINED_USING_amalloc INCLUDE "amalloc.def" ENDIF call _main ;Call user code cleanup: push hl ;Save return value IF !DEFINED_nostreams EXTERN closeall ;Close any opened files call closeall ENDIF pop bc ;Get exit() value into bc start1: ld sp,0 ;Pick up entry sp jp $e003 ; Monitor warm start l_dcal: jp (hl) ;Used for call by function ptr defm "Small C+ Sorcerer" end: defb 0 ; null file name INCLUDE "crt0_runtime_selection.asm" INCLUDE "crt0_section.asm" SECTION code_crt_init ld hl,$F080 ld (base_graphics),hl
#include<iostream> using namespace std; int main(){ cout<<"file doesnot contain any codes just some notes"<<endl; // Why Object-Oriented Programming? // Before we discuss object-oriented programming, we need to learn why we need object-oriented programming? // C++ language was designed with the main intention of adding object-oriented programming to C language // As the size of the program increases readability, maintainability, and bug-free nature of the program decrease. // This was the major problem with languages like C which relied upon functions or procedure (hence the name procedural programming language) // As a result, the possibility of not addressing the problem adequately was high // Also, data was almost neglected, data security was easily compromised // Using classes solves this problem by modeling program as a real-world scenario // Difference between Procedure Oriented Programming and Object-Oriented Programming // Procedure Oriented Programming // Consists of writing a set of instruction for the computer to follow // The main focus is on functions and not on the flow of data // Functions can either use local or global data // Data moves openly from function to function // Object-Oriented Programming // Works on the concept of classes and object // A class is a template to create objects // Treats data as a critical element // Decomposes the problem in objects and builds data and functions around the objects // Basic Concepts in Object-Oriented Programming // Classes - Basic template for creating objects // Objects – Basic run-time entities // Data Abstraction & Encapsulation – Wrapping data and functions into a single unit // Inheritance – Properties of one class can be inherited into others // Polymorphism – Ability to take more than one forms // Dynamic Binding – Code which will execute is not known until the program runs // Message Passing – message (Information) call format // Benefits of Object-Oriented Programming // Better code reusability using objects and inheritance // Principle of data hiding helps build secure systems // Multiple Objects can co-exist without any interference // Software complexity can be easily managed return 0; }
_zombie: file format elf32-i386 Disassembly of section .text: 00000000 <main>: #include "stat.h" #include "user.h" int main(void) { 0: 8d 4c 24 04 lea 0x4(%esp),%ecx 4: 83 e4 f0 and $0xfffffff0,%esp 7: ff 71 fc pushl -0x4(%ecx) a: 55 push %ebp b: 89 e5 mov %esp,%ebp d: 51 push %ecx e: 83 ec 04 sub $0x4,%esp if(fork() > 0) 11: e8 65 02 00 00 call 27b <fork> 16: 85 c0 test %eax,%eax 18: 7e 0d jle 27 <main+0x27> sleep(5); // Let child exit before parent. 1a: 83 ec 0c sub $0xc,%esp 1d: 6a 05 push $0x5 1f: e8 ef 02 00 00 call 313 <sleep> 24: 83 c4 10 add $0x10,%esp exit(); 27: e8 57 02 00 00 call 283 <exit> 2c: 66 90 xchg %ax,%ax 2e: 66 90 xchg %ax,%ax 00000030 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, const char *t) { 30: 55 push %ebp char *os; os = s; while((*s++ = *t++) != 0) 31: 31 c0 xor %eax,%eax { 33: 89 e5 mov %esp,%ebp 35: 53 push %ebx 36: 8b 4d 08 mov 0x8(%ebp),%ecx 39: 8b 5d 0c mov 0xc(%ebp),%ebx 3c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi while((*s++ = *t++) != 0) 40: 0f b6 14 03 movzbl (%ebx,%eax,1),%edx 44: 88 14 01 mov %dl,(%ecx,%eax,1) 47: 83 c0 01 add $0x1,%eax 4a: 84 d2 test %dl,%dl 4c: 75 f2 jne 40 <strcpy+0x10> ; return os; } 4e: 8b 5d fc mov -0x4(%ebp),%ebx 51: 89 c8 mov %ecx,%eax 53: c9 leave 54: c3 ret 55: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 5c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000060 <strcmp>: int strcmp(const char *p, const char *q) { 60: 55 push %ebp 61: 89 e5 mov %esp,%ebp 63: 53 push %ebx 64: 8b 4d 08 mov 0x8(%ebp),%ecx 67: 8b 55 0c mov 0xc(%ebp),%edx while(*p && *p == *q) 6a: 0f b6 01 movzbl (%ecx),%eax 6d: 0f b6 1a movzbl (%edx),%ebx 70: 84 c0 test %al,%al 72: 75 1d jne 91 <strcmp+0x31> 74: eb 2a jmp a0 <strcmp+0x40> 76: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 7d: 8d 76 00 lea 0x0(%esi),%esi 80: 0f b6 41 01 movzbl 0x1(%ecx),%eax p++, q++; 84: 83 c1 01 add $0x1,%ecx 87: 83 c2 01 add $0x1,%edx return (uchar)*p - (uchar)*q; 8a: 0f b6 1a movzbl (%edx),%ebx while(*p && *p == *q) 8d: 84 c0 test %al,%al 8f: 74 0f je a0 <strcmp+0x40> 91: 38 d8 cmp %bl,%al 93: 74 eb je 80 <strcmp+0x20> return (uchar)*p - (uchar)*q; 95: 29 d8 sub %ebx,%eax } 97: 8b 5d fc mov -0x4(%ebp),%ebx 9a: c9 leave 9b: c3 ret 9c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi a0: 31 c0 xor %eax,%eax return (uchar)*p - (uchar)*q; a2: 29 d8 sub %ebx,%eax } a4: 8b 5d fc mov -0x4(%ebp),%ebx a7: c9 leave a8: c3 ret a9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 000000b0 <strlen>: uint strlen(const char *s) { b0: 55 push %ebp b1: 89 e5 mov %esp,%ebp b3: 8b 55 08 mov 0x8(%ebp),%edx int n; for(n = 0; s[n]; n++) b6: 80 3a 00 cmpb $0x0,(%edx) b9: 74 15 je d0 <strlen+0x20> bb: 31 c0 xor %eax,%eax bd: 8d 76 00 lea 0x0(%esi),%esi c0: 83 c0 01 add $0x1,%eax c3: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1) c7: 89 c1 mov %eax,%ecx c9: 75 f5 jne c0 <strlen+0x10> ; return n; } cb: 89 c8 mov %ecx,%eax cd: 5d pop %ebp ce: c3 ret cf: 90 nop for(n = 0; s[n]; n++) d0: 31 c9 xor %ecx,%ecx } d2: 5d pop %ebp d3: 89 c8 mov %ecx,%eax d5: c3 ret d6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi dd: 8d 76 00 lea 0x0(%esi),%esi 000000e0 <memset>: void* memset(void *dst, int c, uint n) { e0: 55 push %ebp e1: 89 e5 mov %esp,%ebp e3: 57 push %edi e4: 8b 55 08 mov 0x8(%ebp),%edx } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : e7: 8b 4d 10 mov 0x10(%ebp),%ecx ea: 8b 45 0c mov 0xc(%ebp),%eax ed: 89 d7 mov %edx,%edi ef: fc cld f0: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } f2: 8b 7d fc mov -0x4(%ebp),%edi f5: 89 d0 mov %edx,%eax f7: c9 leave f8: c3 ret f9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000100 <strchr>: char* strchr(const char *s, char c) { 100: 55 push %ebp 101: 89 e5 mov %esp,%ebp 103: 8b 45 08 mov 0x8(%ebp),%eax 106: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx for(; *s; s++) 10a: 0f b6 10 movzbl (%eax),%edx 10d: 84 d2 test %dl,%dl 10f: 75 12 jne 123 <strchr+0x23> 111: eb 1d jmp 130 <strchr+0x30> 113: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 117: 90 nop 118: 0f b6 50 01 movzbl 0x1(%eax),%edx 11c: 83 c0 01 add $0x1,%eax 11f: 84 d2 test %dl,%dl 121: 74 0d je 130 <strchr+0x30> if(*s == c) 123: 38 d1 cmp %dl,%cl 125: 75 f1 jne 118 <strchr+0x18> return (char*)s; return 0; } 127: 5d pop %ebp 128: c3 ret 129: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi return 0; 130: 31 c0 xor %eax,%eax } 132: 5d pop %ebp 133: c3 ret 134: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 13b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 13f: 90 nop 00000140 <gets>: char* gets(char *buf, int max) { 140: 55 push %ebp 141: 89 e5 mov %esp,%ebp 143: 57 push %edi 144: 56 push %esi int i, cc; char c; for(i=0; i+1 < max; ){ 145: 31 f6 xor %esi,%esi { 147: 53 push %ebx 148: 89 f3 mov %esi,%ebx 14a: 83 ec 1c sub $0x1c,%esp 14d: 8b 7d 08 mov 0x8(%ebp),%edi for(i=0; i+1 < max; ){ 150: eb 2f jmp 181 <gets+0x41> 152: 8d b6 00 00 00 00 lea 0x0(%esi),%esi cc = read(0, &c, 1); 158: 83 ec 04 sub $0x4,%esp 15b: 8d 45 e7 lea -0x19(%ebp),%eax 15e: 6a 01 push $0x1 160: 50 push %eax 161: 6a 00 push $0x0 163: e8 33 01 00 00 call 29b <read> if(cc < 1) 168: 83 c4 10 add $0x10,%esp 16b: 85 c0 test %eax,%eax 16d: 7e 1c jle 18b <gets+0x4b> break; buf[i++] = c; 16f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax if(c == '\n' || c == '\r') 173: 83 c7 01 add $0x1,%edi buf[i++] = c; 176: 88 47 ff mov %al,-0x1(%edi) if(c == '\n' || c == '\r') 179: 3c 0a cmp $0xa,%al 17b: 74 23 je 1a0 <gets+0x60> 17d: 3c 0d cmp $0xd,%al 17f: 74 1f je 1a0 <gets+0x60> for(i=0; i+1 < max; ){ 181: 83 c3 01 add $0x1,%ebx buf[i++] = c; 184: 89 fe mov %edi,%esi for(i=0; i+1 < max; ){ 186: 3b 5d 0c cmp 0xc(%ebp),%ebx 189: 7c cd jl 158 <gets+0x18> 18b: 89 f3 mov %esi,%ebx break; } buf[i] = '\0'; return buf; } 18d: 8b 45 08 mov 0x8(%ebp),%eax buf[i] = '\0'; 190: c6 03 00 movb $0x0,(%ebx) } 193: 8d 65 f4 lea -0xc(%ebp),%esp 196: 5b pop %ebx 197: 5e pop %esi 198: 5f pop %edi 199: 5d pop %ebp 19a: c3 ret 19b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 19f: 90 nop buf[i] = '\0'; 1a0: 8b 75 08 mov 0x8(%ebp),%esi } 1a3: 8b 45 08 mov 0x8(%ebp),%eax buf[i] = '\0'; 1a6: 01 de add %ebx,%esi 1a8: 89 f3 mov %esi,%ebx 1aa: c6 03 00 movb $0x0,(%ebx) } 1ad: 8d 65 f4 lea -0xc(%ebp),%esp 1b0: 5b pop %ebx 1b1: 5e pop %esi 1b2: 5f pop %edi 1b3: 5d pop %ebp 1b4: c3 ret 1b5: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1bc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 000001c0 <stat>: int stat(const char *n, struct stat *st) { 1c0: 55 push %ebp 1c1: 89 e5 mov %esp,%ebp 1c3: 56 push %esi 1c4: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); 1c5: 83 ec 08 sub $0x8,%esp 1c8: 6a 00 push $0x0 1ca: ff 75 08 pushl 0x8(%ebp) 1cd: e8 f1 00 00 00 call 2c3 <open> if(fd < 0) 1d2: 83 c4 10 add $0x10,%esp 1d5: 85 c0 test %eax,%eax 1d7: 78 27 js 200 <stat+0x40> return -1; r = fstat(fd, st); 1d9: 83 ec 08 sub $0x8,%esp 1dc: ff 75 0c pushl 0xc(%ebp) 1df: 89 c3 mov %eax,%ebx 1e1: 50 push %eax 1e2: e8 f4 00 00 00 call 2db <fstat> close(fd); 1e7: 89 1c 24 mov %ebx,(%esp) r = fstat(fd, st); 1ea: 89 c6 mov %eax,%esi close(fd); 1ec: e8 ba 00 00 00 call 2ab <close> return r; 1f1: 83 c4 10 add $0x10,%esp } 1f4: 8d 65 f8 lea -0x8(%ebp),%esp 1f7: 89 f0 mov %esi,%eax 1f9: 5b pop %ebx 1fa: 5e pop %esi 1fb: 5d pop %ebp 1fc: c3 ret 1fd: 8d 76 00 lea 0x0(%esi),%esi return -1; 200: be ff ff ff ff mov $0xffffffff,%esi 205: eb ed jmp 1f4 <stat+0x34> 207: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 20e: 66 90 xchg %ax,%ax 00000210 <atoi>: int atoi(const char *s) { 210: 55 push %ebp 211: 89 e5 mov %esp,%ebp 213: 53 push %ebx 214: 8b 55 08 mov 0x8(%ebp),%edx int n; n = 0; while('0' <= *s && *s <= '9') 217: 0f be 02 movsbl (%edx),%eax 21a: 8d 48 d0 lea -0x30(%eax),%ecx 21d: 80 f9 09 cmp $0x9,%cl n = 0; 220: b9 00 00 00 00 mov $0x0,%ecx while('0' <= *s && *s <= '9') 225: 77 1e ja 245 <atoi+0x35> 227: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 22e: 66 90 xchg %ax,%ax n = n*10 + *s++ - '0'; 230: 83 c2 01 add $0x1,%edx 233: 8d 0c 89 lea (%ecx,%ecx,4),%ecx 236: 8d 4c 48 d0 lea -0x30(%eax,%ecx,2),%ecx while('0' <= *s && *s <= '9') 23a: 0f be 02 movsbl (%edx),%eax 23d: 8d 58 d0 lea -0x30(%eax),%ebx 240: 80 fb 09 cmp $0x9,%bl 243: 76 eb jbe 230 <atoi+0x20> return n; } 245: 8b 5d fc mov -0x4(%ebp),%ebx 248: 89 c8 mov %ecx,%eax 24a: c9 leave 24b: c3 ret 24c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000250 <memmove>: void* memmove(void *vdst, const void *vsrc, int n) { 250: 55 push %ebp 251: 89 e5 mov %esp,%ebp 253: 57 push %edi 254: 8b 45 10 mov 0x10(%ebp),%eax 257: 8b 55 08 mov 0x8(%ebp),%edx 25a: 56 push %esi 25b: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 25e: 85 c0 test %eax,%eax 260: 7e 13 jle 275 <memmove+0x25> 262: 01 d0 add %edx,%eax dst = vdst; 264: 89 d7 mov %edx,%edi 266: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 26d: 8d 76 00 lea 0x0(%esi),%esi *dst++ = *src++; 270: a4 movsb %ds:(%esi),%es:(%edi) while(n-- > 0) 271: 39 f8 cmp %edi,%eax 273: 75 fb jne 270 <memmove+0x20> return vdst; } 275: 5e pop %esi 276: 89 d0 mov %edx,%eax 278: 5f pop %edi 279: 5d pop %ebp 27a: c3 ret 0000027b <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 27b: b8 01 00 00 00 mov $0x1,%eax 280: cd 40 int $0x40 282: c3 ret 00000283 <exit>: SYSCALL(exit) 283: b8 02 00 00 00 mov $0x2,%eax 288: cd 40 int $0x40 28a: c3 ret 0000028b <wait>: SYSCALL(wait) 28b: b8 03 00 00 00 mov $0x3,%eax 290: cd 40 int $0x40 292: c3 ret 00000293 <pipe>: SYSCALL(pipe) 293: b8 04 00 00 00 mov $0x4,%eax 298: cd 40 int $0x40 29a: c3 ret 0000029b <read>: SYSCALL(read) 29b: b8 05 00 00 00 mov $0x5,%eax 2a0: cd 40 int $0x40 2a2: c3 ret 000002a3 <write>: SYSCALL(write) 2a3: b8 10 00 00 00 mov $0x10,%eax 2a8: cd 40 int $0x40 2aa: c3 ret 000002ab <close>: SYSCALL(close) 2ab: b8 15 00 00 00 mov $0x15,%eax 2b0: cd 40 int $0x40 2b2: c3 ret 000002b3 <kill>: SYSCALL(kill) 2b3: b8 06 00 00 00 mov $0x6,%eax 2b8: cd 40 int $0x40 2ba: c3 ret 000002bb <exec>: SYSCALL(exec) 2bb: b8 07 00 00 00 mov $0x7,%eax 2c0: cd 40 int $0x40 2c2: c3 ret 000002c3 <open>: SYSCALL(open) 2c3: b8 0f 00 00 00 mov $0xf,%eax 2c8: cd 40 int $0x40 2ca: c3 ret 000002cb <mknod>: SYSCALL(mknod) 2cb: b8 11 00 00 00 mov $0x11,%eax 2d0: cd 40 int $0x40 2d2: c3 ret 000002d3 <unlink>: SYSCALL(unlink) 2d3: b8 12 00 00 00 mov $0x12,%eax 2d8: cd 40 int $0x40 2da: c3 ret 000002db <fstat>: SYSCALL(fstat) 2db: b8 08 00 00 00 mov $0x8,%eax 2e0: cd 40 int $0x40 2e2: c3 ret 000002e3 <link>: SYSCALL(link) 2e3: b8 13 00 00 00 mov $0x13,%eax 2e8: cd 40 int $0x40 2ea: c3 ret 000002eb <mkdir>: SYSCALL(mkdir) 2eb: b8 14 00 00 00 mov $0x14,%eax 2f0: cd 40 int $0x40 2f2: c3 ret 000002f3 <chdir>: SYSCALL(chdir) 2f3: b8 09 00 00 00 mov $0x9,%eax 2f8: cd 40 int $0x40 2fa: c3 ret 000002fb <dup>: SYSCALL(dup) 2fb: b8 0a 00 00 00 mov $0xa,%eax 300: cd 40 int $0x40 302: c3 ret 00000303 <getpid>: SYSCALL(getpid) 303: b8 0b 00 00 00 mov $0xb,%eax 308: cd 40 int $0x40 30a: c3 ret 0000030b <sbrk>: SYSCALL(sbrk) 30b: b8 0c 00 00 00 mov $0xc,%eax 310: cd 40 int $0x40 312: c3 ret 00000313 <sleep>: SYSCALL(sleep) 313: b8 0d 00 00 00 mov $0xd,%eax 318: cd 40 int $0x40 31a: c3 ret 0000031b <uptime>: SYSCALL(uptime) 31b: b8 0e 00 00 00 mov $0xe,%eax 320: cd 40 int $0x40 322: c3 ret 00000323 <getyear>: SYSCALL(getyear) 323: b8 16 00 00 00 mov $0x16,%eax 328: cd 40 int $0x40 32a: c3 ret 0000032b <lseek>: 32b: b8 17 00 00 00 mov $0x17,%eax 330: cd 40 int $0x40 332: c3 ret 333: 66 90 xchg %ax,%ax 335: 66 90 xchg %ax,%ax 337: 66 90 xchg %ax,%ax 339: 66 90 xchg %ax,%ax 33b: 66 90 xchg %ax,%ax 33d: 66 90 xchg %ax,%ax 33f: 90 nop 00000340 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 340: 55 push %ebp 341: 89 e5 mov %esp,%ebp 343: 57 push %edi 344: 56 push %esi 345: 53 push %ebx 346: 83 ec 3c sub $0x3c,%esp 349: 89 4d c4 mov %ecx,-0x3c(%ebp) uint x; neg = 0; if(sgn && xx < 0){ neg = 1; x = -xx; 34c: 89 d1 mov %edx,%ecx { 34e: 89 45 b8 mov %eax,-0x48(%ebp) if(sgn && xx < 0){ 351: 85 d2 test %edx,%edx 353: 0f 89 7f 00 00 00 jns 3d8 <printint+0x98> 359: f6 45 08 01 testb $0x1,0x8(%ebp) 35d: 74 79 je 3d8 <printint+0x98> neg = 1; 35f: c7 45 bc 01 00 00 00 movl $0x1,-0x44(%ebp) x = -xx; 366: f7 d9 neg %ecx } else { x = xx; } i = 0; 368: 31 db xor %ebx,%ebx 36a: 8d 75 d7 lea -0x29(%ebp),%esi 36d: 8d 76 00 lea 0x0(%esi),%esi do{ buf[i++] = digits[x % base]; 370: 89 c8 mov %ecx,%eax 372: 31 d2 xor %edx,%edx 374: 89 cf mov %ecx,%edi 376: f7 75 c4 divl -0x3c(%ebp) 379: 0f b6 92 60 07 00 00 movzbl 0x760(%edx),%edx 380: 89 45 c0 mov %eax,-0x40(%ebp) 383: 89 d8 mov %ebx,%eax 385: 8d 5b 01 lea 0x1(%ebx),%ebx }while((x /= base) != 0); 388: 8b 4d c0 mov -0x40(%ebp),%ecx buf[i++] = digits[x % base]; 38b: 88 14 1e mov %dl,(%esi,%ebx,1) }while((x /= base) != 0); 38e: 39 7d c4 cmp %edi,-0x3c(%ebp) 391: 76 dd jbe 370 <printint+0x30> if(neg) 393: 8b 4d bc mov -0x44(%ebp),%ecx 396: 85 c9 test %ecx,%ecx 398: 74 0c je 3a6 <printint+0x66> buf[i++] = '-'; 39a: c6 44 1d d8 2d movb $0x2d,-0x28(%ebp,%ebx,1) buf[i++] = digits[x % base]; 39f: 89 d8 mov %ebx,%eax buf[i++] = '-'; 3a1: ba 2d 00 00 00 mov $0x2d,%edx while(--i >= 0) 3a6: 8b 7d b8 mov -0x48(%ebp),%edi 3a9: 8d 5c 05 d7 lea -0x29(%ebp,%eax,1),%ebx 3ad: eb 07 jmp 3b6 <printint+0x76> 3af: 90 nop putc(fd, buf[i]); 3b0: 0f b6 13 movzbl (%ebx),%edx 3b3: 83 eb 01 sub $0x1,%ebx write(fd, &c, 1); 3b6: 83 ec 04 sub $0x4,%esp 3b9: 88 55 d7 mov %dl,-0x29(%ebp) 3bc: 6a 01 push $0x1 3be: 56 push %esi 3bf: 57 push %edi 3c0: e8 de fe ff ff call 2a3 <write> while(--i >= 0) 3c5: 83 c4 10 add $0x10,%esp 3c8: 39 de cmp %ebx,%esi 3ca: 75 e4 jne 3b0 <printint+0x70> } 3cc: 8d 65 f4 lea -0xc(%ebp),%esp 3cf: 5b pop %ebx 3d0: 5e pop %esi 3d1: 5f pop %edi 3d2: 5d pop %ebp 3d3: c3 ret 3d4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; 3d8: c7 45 bc 00 00 00 00 movl $0x0,-0x44(%ebp) 3df: eb 87 jmp 368 <printint+0x28> 3e1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 3e8: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 3ef: 90 nop 000003f0 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 3f0: 55 push %ebp 3f1: 89 e5 mov %esp,%ebp 3f3: 57 push %edi 3f4: 56 push %esi 3f5: 53 push %ebx 3f6: 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++){ 3f9: 8b 75 0c mov 0xc(%ebp),%esi 3fc: 0f b6 1e movzbl (%esi),%ebx 3ff: 84 db test %bl,%bl 401: 0f 84 b8 00 00 00 je 4bf <printf+0xcf> ap = (uint*)(void*)&fmt + 1; 407: 8d 45 10 lea 0x10(%ebp),%eax 40a: 83 c6 01 add $0x1,%esi write(fd, &c, 1); 40d: 8d 7d e7 lea -0x19(%ebp),%edi state = 0; 410: 31 d2 xor %edx,%edx ap = (uint*)(void*)&fmt + 1; 412: 89 45 d0 mov %eax,-0x30(%ebp) 415: eb 37 jmp 44e <printf+0x5e> 417: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 41e: 66 90 xchg %ax,%ax 420: 89 55 d4 mov %edx,-0x2c(%ebp) c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ state = '%'; 423: ba 25 00 00 00 mov $0x25,%edx if(c == '%'){ 428: 83 f8 25 cmp $0x25,%eax 42b: 74 17 je 444 <printf+0x54> write(fd, &c, 1); 42d: 83 ec 04 sub $0x4,%esp 430: 88 5d e7 mov %bl,-0x19(%ebp) 433: 6a 01 push $0x1 435: 57 push %edi 436: ff 75 08 pushl 0x8(%ebp) 439: e8 65 fe ff ff call 2a3 <write> 43e: 8b 55 d4 mov -0x2c(%ebp),%edx } else { putc(fd, c); 441: 83 c4 10 add $0x10,%esp for(i = 0; fmt[i]; i++){ 444: 0f b6 1e movzbl (%esi),%ebx 447: 83 c6 01 add $0x1,%esi 44a: 84 db test %bl,%bl 44c: 74 71 je 4bf <printf+0xcf> c = fmt[i] & 0xff; 44e: 0f be cb movsbl %bl,%ecx 451: 0f b6 c3 movzbl %bl,%eax if(state == 0){ 454: 85 d2 test %edx,%edx 456: 74 c8 je 420 <printf+0x30> } } else if(state == '%'){ 458: 83 fa 25 cmp $0x25,%edx 45b: 75 e7 jne 444 <printf+0x54> if(c == 'd'){ 45d: 83 f8 64 cmp $0x64,%eax 460: 0f 84 9a 00 00 00 je 500 <printf+0x110> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 466: 81 e1 f7 00 00 00 and $0xf7,%ecx 46c: 83 f9 70 cmp $0x70,%ecx 46f: 74 5f je 4d0 <printf+0xe0> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 471: 83 f8 73 cmp $0x73,%eax 474: 0f 84 d6 00 00 00 je 550 <printf+0x160> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 47a: 83 f8 63 cmp $0x63,%eax 47d: 0f 84 8d 00 00 00 je 510 <printf+0x120> putc(fd, *ap); ap++; } else if(c == '%'){ 483: 83 f8 25 cmp $0x25,%eax 486: 0f 84 b4 00 00 00 je 540 <printf+0x150> write(fd, &c, 1); 48c: 83 ec 04 sub $0x4,%esp 48f: c6 45 e7 25 movb $0x25,-0x19(%ebp) 493: 6a 01 push $0x1 495: 57 push %edi 496: ff 75 08 pushl 0x8(%ebp) 499: e8 05 fe ff ff call 2a3 <write> putc(fd, c); } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); 49e: 88 5d e7 mov %bl,-0x19(%ebp) write(fd, &c, 1); 4a1: 83 c4 0c add $0xc,%esp 4a4: 6a 01 push $0x1 for(i = 0; fmt[i]; i++){ 4a6: 83 c6 01 add $0x1,%esi write(fd, &c, 1); 4a9: 57 push %edi 4aa: ff 75 08 pushl 0x8(%ebp) 4ad: e8 f1 fd ff ff call 2a3 <write> for(i = 0; fmt[i]; i++){ 4b2: 0f b6 5e ff movzbl -0x1(%esi),%ebx putc(fd, c); 4b6: 83 c4 10 add $0x10,%esp } state = 0; 4b9: 31 d2 xor %edx,%edx for(i = 0; fmt[i]; i++){ 4bb: 84 db test %bl,%bl 4bd: 75 8f jne 44e <printf+0x5e> } } } 4bf: 8d 65 f4 lea -0xc(%ebp),%esp 4c2: 5b pop %ebx 4c3: 5e pop %esi 4c4: 5f pop %edi 4c5: 5d pop %ebp 4c6: c3 ret 4c7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 4ce: 66 90 xchg %ax,%ax printint(fd, *ap, 16, 0); 4d0: 83 ec 0c sub $0xc,%esp 4d3: b9 10 00 00 00 mov $0x10,%ecx 4d8: 6a 00 push $0x0 4da: 8b 5d d0 mov -0x30(%ebp),%ebx 4dd: 8b 45 08 mov 0x8(%ebp),%eax 4e0: 8b 13 mov (%ebx),%edx 4e2: e8 59 fe ff ff call 340 <printint> ap++; 4e7: 89 d8 mov %ebx,%eax 4e9: 83 c4 10 add $0x10,%esp state = 0; 4ec: 31 d2 xor %edx,%edx ap++; 4ee: 83 c0 04 add $0x4,%eax 4f1: 89 45 d0 mov %eax,-0x30(%ebp) 4f4: e9 4b ff ff ff jmp 444 <printf+0x54> 4f9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi printint(fd, *ap, 10, 1); 500: 83 ec 0c sub $0xc,%esp 503: b9 0a 00 00 00 mov $0xa,%ecx 508: 6a 01 push $0x1 50a: eb ce jmp 4da <printf+0xea> 50c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi putc(fd, *ap); 510: 8b 5d d0 mov -0x30(%ebp),%ebx write(fd, &c, 1); 513: 83 ec 04 sub $0x4,%esp putc(fd, *ap); 516: 8b 03 mov (%ebx),%eax write(fd, &c, 1); 518: 6a 01 push $0x1 ap++; 51a: 83 c3 04 add $0x4,%ebx write(fd, &c, 1); 51d: 57 push %edi 51e: ff 75 08 pushl 0x8(%ebp) putc(fd, *ap); 521: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 524: e8 7a fd ff ff call 2a3 <write> ap++; 529: 89 5d d0 mov %ebx,-0x30(%ebp) 52c: 83 c4 10 add $0x10,%esp state = 0; 52f: 31 d2 xor %edx,%edx 531: e9 0e ff ff ff jmp 444 <printf+0x54> 536: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 53d: 8d 76 00 lea 0x0(%esi),%esi putc(fd, c); 540: 88 5d e7 mov %bl,-0x19(%ebp) write(fd, &c, 1); 543: 83 ec 04 sub $0x4,%esp 546: e9 59 ff ff ff jmp 4a4 <printf+0xb4> 54b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 54f: 90 nop s = (char*)*ap; 550: 8b 45 d0 mov -0x30(%ebp),%eax 553: 8b 18 mov (%eax),%ebx ap++; 555: 83 c0 04 add $0x4,%eax 558: 89 45 d0 mov %eax,-0x30(%ebp) if(s == 0) 55b: 85 db test %ebx,%ebx 55d: 74 17 je 576 <printf+0x186> while(*s != 0){ 55f: 0f b6 03 movzbl (%ebx),%eax state = 0; 562: 31 d2 xor %edx,%edx while(*s != 0){ 564: 84 c0 test %al,%al 566: 0f 84 d8 fe ff ff je 444 <printf+0x54> 56c: 89 75 d4 mov %esi,-0x2c(%ebp) 56f: 89 de mov %ebx,%esi 571: 8b 5d 08 mov 0x8(%ebp),%ebx 574: eb 1a jmp 590 <printf+0x1a0> s = "(null)"; 576: bb 58 07 00 00 mov $0x758,%ebx while(*s != 0){ 57b: 89 75 d4 mov %esi,-0x2c(%ebp) 57e: b8 28 00 00 00 mov $0x28,%eax 583: 89 de mov %ebx,%esi 585: 8b 5d 08 mov 0x8(%ebp),%ebx 588: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 58f: 90 nop write(fd, &c, 1); 590: 83 ec 04 sub $0x4,%esp s++; 593: 83 c6 01 add $0x1,%esi 596: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 599: 6a 01 push $0x1 59b: 57 push %edi 59c: 53 push %ebx 59d: e8 01 fd ff ff call 2a3 <write> while(*s != 0){ 5a2: 0f b6 06 movzbl (%esi),%eax 5a5: 83 c4 10 add $0x10,%esp 5a8: 84 c0 test %al,%al 5aa: 75 e4 jne 590 <printf+0x1a0> state = 0; 5ac: 8b 75 d4 mov -0x2c(%ebp),%esi 5af: 31 d2 xor %edx,%edx 5b1: e9 8e fe ff ff jmp 444 <printf+0x54> 5b6: 66 90 xchg %ax,%ax 5b8: 66 90 xchg %ax,%ax 5ba: 66 90 xchg %ax,%ax 5bc: 66 90 xchg %ax,%ax 5be: 66 90 xchg %ax,%ax 000005c0 <free>: static Header base; static Header *freep; void free(void *ap) { 5c0: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 5c1: a1 04 0a 00 00 mov 0xa04,%eax { 5c6: 89 e5 mov %esp,%ebp 5c8: 57 push %edi 5c9: 56 push %esi 5ca: 53 push %ebx 5cb: 8b 5d 08 mov 0x8(%ebp),%ebx bp = (Header*)ap - 1; 5ce: 8d 4b f8 lea -0x8(%ebx),%ecx for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 5d1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 5d8: 89 c2 mov %eax,%edx 5da: 8b 00 mov (%eax),%eax 5dc: 39 ca cmp %ecx,%edx 5de: 73 30 jae 610 <free+0x50> 5e0: 39 c1 cmp %eax,%ecx 5e2: 72 04 jb 5e8 <free+0x28> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 5e4: 39 c2 cmp %eax,%edx 5e6: 72 f0 jb 5d8 <free+0x18> break; if(bp + bp->s.size == p->s.ptr){ 5e8: 8b 73 fc mov -0x4(%ebx),%esi 5eb: 8d 3c f1 lea (%ecx,%esi,8),%edi 5ee: 39 f8 cmp %edi,%eax 5f0: 74 30 je 622 <free+0x62> bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; 5f2: 89 43 f8 mov %eax,-0x8(%ebx) if(p + p->s.size == bp){ 5f5: 8b 42 04 mov 0x4(%edx),%eax 5f8: 8d 34 c2 lea (%edx,%eax,8),%esi 5fb: 39 f1 cmp %esi,%ecx 5fd: 74 3a je 639 <free+0x79> p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; 5ff: 89 0a mov %ecx,(%edx) freep = p; } 601: 5b pop %ebx freep = p; 602: 89 15 04 0a 00 00 mov %edx,0xa04 } 608: 5e pop %esi 609: 5f pop %edi 60a: 5d pop %ebp 60b: c3 ret 60c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 610: 39 c2 cmp %eax,%edx 612: 72 c4 jb 5d8 <free+0x18> 614: 39 c1 cmp %eax,%ecx 616: 73 c0 jae 5d8 <free+0x18> if(bp + bp->s.size == p->s.ptr){ 618: 8b 73 fc mov -0x4(%ebx),%esi 61b: 8d 3c f1 lea (%ecx,%esi,8),%edi 61e: 39 f8 cmp %edi,%eax 620: 75 d0 jne 5f2 <free+0x32> bp->s.size += p->s.ptr->s.size; 622: 03 70 04 add 0x4(%eax),%esi 625: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 628: 8b 02 mov (%edx),%eax 62a: 8b 00 mov (%eax),%eax 62c: 89 43 f8 mov %eax,-0x8(%ebx) if(p + p->s.size == bp){ 62f: 8b 42 04 mov 0x4(%edx),%eax 632: 8d 34 c2 lea (%edx,%eax,8),%esi 635: 39 f1 cmp %esi,%ecx 637: 75 c6 jne 5ff <free+0x3f> p->s.size += bp->s.size; 639: 03 43 fc add -0x4(%ebx),%eax freep = p; 63c: 89 15 04 0a 00 00 mov %edx,0xa04 p->s.size += bp->s.size; 642: 89 42 04 mov %eax,0x4(%edx) p->s.ptr = bp->s.ptr; 645: 8b 43 f8 mov -0x8(%ebx),%eax 648: 89 02 mov %eax,(%edx) } 64a: 5b pop %ebx 64b: 5e pop %esi 64c: 5f pop %edi 64d: 5d pop %ebp 64e: c3 ret 64f: 90 nop 00000650 <malloc>: return freep; } void* malloc(uint nbytes) { 650: 55 push %ebp 651: 89 e5 mov %esp,%ebp 653: 57 push %edi 654: 56 push %esi 655: 53 push %ebx 656: 83 ec 1c sub $0x1c,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 659: 8b 45 08 mov 0x8(%ebp),%eax if((prevp = freep) == 0){ 65c: 8b 3d 04 0a 00 00 mov 0xa04,%edi nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 662: 8d 70 07 lea 0x7(%eax),%esi 665: c1 ee 03 shr $0x3,%esi 668: 83 c6 01 add $0x1,%esi if((prevp = freep) == 0){ 66b: 85 ff test %edi,%edi 66d: 0f 84 ad 00 00 00 je 720 <malloc+0xd0> base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 673: 8b 07 mov (%edi),%eax if(p->s.size >= nunits){ 675: 8b 48 04 mov 0x4(%eax),%ecx 678: 39 f1 cmp %esi,%ecx 67a: 73 71 jae 6ed <malloc+0x9d> 67c: 81 fe 00 10 00 00 cmp $0x1000,%esi 682: bb 00 10 00 00 mov $0x1000,%ebx 687: 0f 43 de cmovae %esi,%ebx p = sbrk(nu * sizeof(Header)); 68a: 8d 0c dd 00 00 00 00 lea 0x0(,%ebx,8),%ecx 691: 89 4d e4 mov %ecx,-0x1c(%ebp) 694: eb 1b jmp 6b1 <malloc+0x61> 696: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 69d: 8d 76 00 lea 0x0(%esi),%esi for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 6a0: 8b 10 mov (%eax),%edx if(p->s.size >= nunits){ 6a2: 8b 4a 04 mov 0x4(%edx),%ecx 6a5: 39 f1 cmp %esi,%ecx 6a7: 73 4f jae 6f8 <malloc+0xa8> p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if(p == freep) 6a9: 8b 3d 04 0a 00 00 mov 0xa04,%edi 6af: 89 d0 mov %edx,%eax 6b1: 39 c7 cmp %eax,%edi 6b3: 75 eb jne 6a0 <malloc+0x50> p = sbrk(nu * sizeof(Header)); 6b5: 83 ec 0c sub $0xc,%esp 6b8: ff 75 e4 pushl -0x1c(%ebp) 6bb: e8 4b fc ff ff call 30b <sbrk> if(p == (char*)-1) 6c0: 83 c4 10 add $0x10,%esp 6c3: 83 f8 ff cmp $0xffffffff,%eax 6c6: 74 1b je 6e3 <malloc+0x93> hp->s.size = nu; 6c8: 89 58 04 mov %ebx,0x4(%eax) free((void*)(hp + 1)); 6cb: 83 ec 0c sub $0xc,%esp 6ce: 83 c0 08 add $0x8,%eax 6d1: 50 push %eax 6d2: e8 e9 fe ff ff call 5c0 <free> return freep; 6d7: a1 04 0a 00 00 mov 0xa04,%eax if((p = morecore(nunits)) == 0) 6dc: 83 c4 10 add $0x10,%esp 6df: 85 c0 test %eax,%eax 6e1: 75 bd jne 6a0 <malloc+0x50> return 0; } } 6e3: 8d 65 f4 lea -0xc(%ebp),%esp return 0; 6e6: 31 c0 xor %eax,%eax } 6e8: 5b pop %ebx 6e9: 5e pop %esi 6ea: 5f pop %edi 6eb: 5d pop %ebp 6ec: c3 ret if(p->s.size >= nunits){ 6ed: 89 c2 mov %eax,%edx 6ef: 89 f8 mov %edi,%eax 6f1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi if(p->s.size == nunits) 6f8: 39 ce cmp %ecx,%esi 6fa: 74 54 je 750 <malloc+0x100> p->s.size -= nunits; 6fc: 29 f1 sub %esi,%ecx 6fe: 89 4a 04 mov %ecx,0x4(%edx) p += p->s.size; 701: 8d 14 ca lea (%edx,%ecx,8),%edx p->s.size = nunits; 704: 89 72 04 mov %esi,0x4(%edx) freep = prevp; 707: a3 04 0a 00 00 mov %eax,0xa04 } 70c: 8d 65 f4 lea -0xc(%ebp),%esp return (void*)(p + 1); 70f: 8d 42 08 lea 0x8(%edx),%eax } 712: 5b pop %ebx 713: 5e pop %esi 714: 5f pop %edi 715: 5d pop %ebp 716: c3 ret 717: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 71e: 66 90 xchg %ax,%ax base.s.ptr = freep = prevp = &base; 720: c7 05 04 0a 00 00 08 movl $0xa08,0xa04 727: 0a 00 00 base.s.size = 0; 72a: bf 08 0a 00 00 mov $0xa08,%edi base.s.ptr = freep = prevp = &base; 72f: c7 05 08 0a 00 00 08 movl $0xa08,0xa08 736: 0a 00 00 for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 739: 89 f8 mov %edi,%eax base.s.size = 0; 73b: c7 05 0c 0a 00 00 00 movl $0x0,0xa0c 742: 00 00 00 if(p->s.size >= nunits){ 745: e9 32 ff ff ff jmp 67c <malloc+0x2c> 74a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi prevp->s.ptr = p->s.ptr; 750: 8b 0a mov (%edx),%ecx 752: 89 08 mov %ecx,(%eax) 754: eb b1 jmp 707 <malloc+0xb7>
.MACRO LKS_BG1_update lda LKS_BG+_bg1x sta BG1H0FS lda LKS_BG+_bg1x+1 sta BG1H0FS lda LKS_BG+_bg1y sta BG1V0FS lda LKS_BG+_bg1y+1 sta BG1V0FS .ENDM .MACRO LKS_BG3_update lda LKS_BG+_bg3x sta BG3H0FS lda LKS_BG+_bg3x+1 sta BG3H0FS lda LKS_BG+_bg3y sta BG3V0FS lda LKS_BG+_bg3y+1 sta BG3V0FS .ENDM .MACRO LKS_BG4_update lda LKS_BG+_bg4x sta BG4H0FS lda LKS_BG+_bg4x+1 sta BG4H0FS lda LKS_BG+_bg4y sta BG4V0FS lda LKS_BG+_bg4y+1 sta BG4V0FS .ENDM .MACRO LKS_BG2_update lda LKS_BG+_bg2x sta BG2H0FS lda LKS_BG+_bg2x+1 sta BG2H0FS lda LKS_BG+_bg2y sta BG2V0FS lda LKS_BG+_bg2y+1 sta BG2V0FS .ENDM .MACRO LKS_BG1_cpy_BG2 ldx LKS_BG+_bg1x stx LKS_BG+_bg2x ldx LKS_BG+_bg1y stx LKS_BG+_bg2y .ENDM .MACRO LKS_BG1_set ldx \1 stx LKS_BG+_bg1x ldx \2 stx LKS_BG+_bg1y .ENDM .MACRO LKS_BG2_set ldx \1 stx LKS_BG+_bg2x ldx \2 stx LKS_BG+_bg2y .ENDM
#include "askpassphrasedialog.h" #include "ui_askpassphrasedialog.h" #include "guiconstants.h" #include "walletmodel.h" #include <QMessageBox> #include <QPushButton> #include <QKeyEvent> extern bool fWalletUnlockStakingOnly; AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget *parent) : QDialog(parent), ui(new Ui::AskPassphraseDialog), mode(mode), model(0), fCapsLock(false) { ui->setupUi(this); ui->passEdit1->setMaxLength(MAX_PASSPHRASE_SIZE); ui->passEdit2->setMaxLength(MAX_PASSPHRASE_SIZE); ui->passEdit3->setMaxLength(MAX_PASSPHRASE_SIZE); // Setup Caps Lock detection. ui->passEdit1->installEventFilter(this); ui->passEdit2->installEventFilter(this); ui->passEdit3->installEventFilter(this); ui->stakingCheckBox->setChecked(fWalletUnlockStakingOnly); switch(mode) { case Encrypt: // Ask passphrase x2 ui->passLabel1->hide(); ui->passEdit1->hide(); ui->warningLabel->setText(tr("Enter the new passphrase to the wallet.<br/>Please use a passphrase of <b>10 or more random characters</b>, or <b>eight or more words</b>.")); setWindowTitle(tr("Encrypt wallet")); break; case UnlockStaking: ui->stakingCheckBox->setChecked(true); ui->stakingCheckBox->show(); // fallthru case Unlock: // Ask passphrase ui->warningLabel->setText(tr("This operation needs your wallet passphrase to unlock the wallet.")); ui->passLabel2->hide(); ui->passEdit2->hide(); ui->passLabel3->hide(); ui->passEdit3->hide(); setWindowTitle(tr("Unlock wallet")); break; case Decrypt: // Ask passphrase ui->warningLabel->setText(tr("This operation needs your wallet passphrase to decrypt the wallet.")); ui->passLabel2->hide(); ui->passEdit2->hide(); ui->passLabel3->hide(); ui->passEdit3->hide(); setWindowTitle(tr("Decrypt wallet")); break; case ChangePass: // Ask old passphrase + new passphrase x2 setWindowTitle(tr("Change passphrase")); ui->warningLabel->setText(tr("Enter the old and new passphrase to the wallet.")); break; } textChanged(); connect(ui->passEdit1, SIGNAL(textChanged(QString)), this, SLOT(textChanged())); connect(ui->passEdit2, SIGNAL(textChanged(QString)), this, SLOT(textChanged())); connect(ui->passEdit3, SIGNAL(textChanged(QString)), this, SLOT(textChanged())); } AskPassphraseDialog::~AskPassphraseDialog() { secureClearPassFields(); delete ui; } void AskPassphraseDialog::setModel(WalletModel *model) { this->model = model; } void AskPassphraseDialog::accept() { SecureString oldpass, newpass1, newpass2; if(!model) return; oldpass.reserve(MAX_PASSPHRASE_SIZE); newpass1.reserve(MAX_PASSPHRASE_SIZE); newpass2.reserve(MAX_PASSPHRASE_SIZE); // TODO: get rid of this .c_str() by implementing SecureString::operator=(std::string) // Alternately, find a way to make this input mlock()'d to begin with. oldpass.assign(ui->passEdit1->text().toStdString().c_str()); newpass1.assign(ui->passEdit2->text().toStdString().c_str()); newpass2.assign(ui->passEdit3->text().toStdString().c_str()); secureClearPassFields(); switch(mode) { case Encrypt: { if(newpass1.empty() || newpass2.empty()) { // Cannot encrypt with empty passphrase break; } QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm wallet encryption"), tr("Warning: If you encrypt your wallet and lose your passphrase, you will <b>LOSE ALL OF YOUR COINS</b>!") + "<br><br>" + tr("Are you sure you wish to encrypt your wallet?"), QMessageBox::Yes|QMessageBox::Cancel, QMessageBox::Cancel); if(retval == QMessageBox::Yes) { if(newpass1 == newpass2) { if(model->setWalletEncrypted(true, newpass1)) { QMessageBox::warning(this, tr("Wallet encrypted"), "<qt>" + tr("PokeCoin will close now to finish the encryption process. " "Remember that encrypting your wallet cannot fully protect " "your coins from being stolen by malware infecting your computer.") + "<br><br><b>" + tr("IMPORTANT: Any previous backups you have made of your wallet file " "should be replaced with the newly generated, encrypted wallet file. " "For security reasons, previous backups of the unencrypted wallet file " "will become useless as soon as you start using the new, encrypted wallet.") + "</b></qt>"); QApplication::quit(); } else { QMessageBox::critical(this, tr("Wallet encryption failed"), tr("Wallet encryption failed due to an internal error. Your wallet was not encrypted.")); } QDialog::accept(); // Success } else { QMessageBox::critical(this, tr("Wallet encryption failed"), tr("The supplied passphrases do not match.")); } } else { QDialog::reject(); // Cancelled } } break; case UnlockStaking: case Unlock: if(!model->setWalletLocked(false, oldpass)) { QMessageBox::critical(this, tr("Wallet unlock failed"), tr("The passphrase entered for the wallet decryption was incorrect.")); } else { fWalletUnlockStakingOnly = ui->stakingCheckBox->isChecked(); QDialog::accept(); // Success } break; case Decrypt: if(!model->setWalletEncrypted(false, oldpass)) { QMessageBox::critical(this, tr("Wallet decryption failed"), tr("The passphrase entered for the wallet decryption was incorrect.")); } else { QDialog::accept(); // Success } break; case ChangePass: if(newpass1 == newpass2) { if(model->changePassphrase(oldpass, newpass1)) { QMessageBox::information(this, tr("Wallet encrypted"), tr("Wallet passphrase was successfully changed.")); QDialog::accept(); // Success } else { QMessageBox::critical(this, tr("Wallet encryption failed"), tr("The passphrase entered for the wallet decryption was incorrect.")); } } else { QMessageBox::critical(this, tr("Wallet encryption failed"), tr("The supplied passphrases do not match.")); } break; } } void AskPassphraseDialog::textChanged() { // Validate input, set Ok button to enabled when acceptable bool acceptable = false; switch(mode) { case Encrypt: // New passphrase x2 acceptable = !ui->passEdit2->text().isEmpty() && !ui->passEdit3->text().isEmpty(); break; case UnlockStaking: case Unlock: // Old passphrase x1 case Decrypt: acceptable = !ui->passEdit1->text().isEmpty(); break; case ChangePass: // Old passphrase x1, new passphrase x2 acceptable = !ui->passEdit1->text().isEmpty() && !ui->passEdit2->text().isEmpty() && !ui->passEdit3->text().isEmpty(); break; } ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(acceptable); } bool AskPassphraseDialog::event(QEvent *event) { // Detect Caps Lock key press. if (event->type() == QEvent::KeyPress) { QKeyEvent *ke = static_cast<QKeyEvent *>(event); if (ke->key() == Qt::Key_CapsLock) { fCapsLock = !fCapsLock; } if (fCapsLock) { ui->capsLabel->setText(tr("Warning: The Caps Lock key is on!")); } else { ui->capsLabel->clear(); } } return QWidget::event(event); } bool AskPassphraseDialog::eventFilter(QObject *object, QEvent *event) { /* Detect Caps Lock. * There is no good OS-independent way to check a key state in Qt, but we * can detect Caps Lock by checking for the following condition: * Shift key is down and the result is a lower case character, or * Shift key is not down and the result is an upper case character. */ if (event->type() == QEvent::KeyPress) { QKeyEvent *ke = static_cast<QKeyEvent *>(event); QString str = ke->text(); if (str.length() != 0) { const QChar *psz = str.unicode(); bool fShift = (ke->modifiers() & Qt::ShiftModifier) != 0; if ((fShift && psz->isLower()) || (!fShift && psz->isUpper())) { fCapsLock = true; ui->capsLabel->setText(tr("Warning: The Caps Lock key is on!")); } else if (psz->isLetter()) { fCapsLock = false; ui->capsLabel->clear(); } } } return QDialog::eventFilter(object, event); } void AskPassphraseDialog::secureClearPassFields() { // Attempt to overwrite text so that they do not linger around in memory ui->passEdit1->setText(QString(" ").repeated(ui->passEdit1->text().size())); ui->passEdit2->setText(QString(" ").repeated(ui->passEdit2->text().size())); ui->passEdit3->setText(QString(" ").repeated(ui->passEdit3->text().size())); ui->passEdit1->clear(); ui->passEdit2->clear(); ui->passEdit3->clear(); }
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> #include <bits/stdc++.h> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<vector<int>> vvi; typedef vector<vector<long long>> vvl; typedef pair<int,int> pt; typedef pair<long long ,long long> ptl; typedef set<int> si; typedef set<long long> sl; typedef unordered_set <int> usi; typedef unordered_set <long long> usl; typedef multiset<int> msi; typedef multiset<long long> msl; template <typename T> using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // order_of_key: The number of items in a set that are strictly smaller than k // find_by_order: It returns an iterator to the ith largest element //Anubhaw Bhalotia https://github.com/anubhawbhalotia #define x first #define y second #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define beg(x) x.begin() #define en(x) x.end() #define all(x) x.begin(), x.end() #define f(i,s,n) for(int i=s;i<n;i++) #define fe(i,s,n) for(int i=s;i<=n;i++) #define fr(i,s,n) for(int i=s;i>n;i--) #define fre(i,s,n) for(int i=s;i>=n;i--) const int MOD = 998244353; template <typename T,typename U, typename V,typename W> auto operator+=(const pair<T,U> & l, pair<V,W> & r) -> pair<decltype(l.first+r.first),decltype(l.second+r.second)> { return {l.first+r.first,l.second+r.second}; } template <typename T,typename U, typename V,typename W> auto operator+(const pair<T,U> & l, pair<V,W> & r) -> pair<decltype(l.first+r.first),decltype(l.second+r.second)> { return {l.first+r.first,l.second+r.second}; } template <typename T> T gcd(T a, T b) {return b == 0 ? a : gcd(b, a % b);} int extendedEuclid(int a, int b, int *x, int *y){if(a == 0){*x = 0;*y = 1; return b;}int x1, y1;int gcd = extendedEuclid(b % a, a, &x1, &y1); *x = y1 - (b/a) * x1;*y = x1;return gcd;} int solution(int t) { int n, k, p, s; cin>>n>>k>>p; vvi a(n, vi(k)); f(i, 0, n) { f(j, 0, k) cin>>a[i][j]; } vvi dp(n, vi(max(p + 1, k + 1), 0)); f(i, 0, k) { dp[n-1][i + 1] = dp[n - 1][i] + a[n - 1][i]; } fre(i, n - 2, 0) { fe(j, 1, min(k * (n - i), p)) { s = 0; fe(x, 0, min(j, k)) { dp[i][j] = max(dp[i][j], s + dp[i + 1][j - x]); if(x < k) s += a[i][x]; } } } // f(i, 0, n) // { // fe(j, 0, p) // cout<<dp[i][j]<<" "; // cout<<endl; // } return dp[0][p]; } void testCase() { int t = 1; cin>>t; f(i, 0, t) { cout<<"Case #"<<i + 1<<": "<<solution(i + 1)<<endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); testCase(); }
class Solution { public: int getMax(int val) { return max(val,0); } int maximumSum(vector<int>& ar) { int n = ar.size() , mn; if(n == 1) return ar[0]; mn = 0; vector<int> lmax(n); for( int i = 0 , sum = 0 ; i < n ; i++ ) { sum += ar[i]; lmax[i] = sum - mn; mn = min(mn , sum); } mn = 0; vector<int> rmax(n); for( int i = n-1 , sum = 0 ; i >= 0 ; i-- ) { sum += ar[i]; rmax[i] = sum - mn; mn = min(mn , sum); } int ans = INT_MIN; for( int i = 0 ; i < n ; i++ ) { if(i == 0) { ans = max(ans , rmax[i+1] + getMax(ar[i])); ans = max(ans , getMax(rmax[i+1]) + ar[i]); } else if(i == n-1) { ans = max(ans , lmax[i-1] + getMax(ar[i])); ans = max(ans , getMax(lmax[i-1]) + ar[i]); } else { ans = max(ans , lmax[i-1] + getMax(ar[i]) + getMax(rmax[i+1])); ans = max(ans , getMax(lmax[i-1]) + ar[i] + getMax(rmax[i+1])); ans = max(ans , getMax(lmax[i-1]) + getMax(ar[i]) + rmax[i+1]); } } return ans; } };
;; ; ; Name: stub_sock_find_peek_flusher.asm ; Qualities: Can Have Nulls ; Platforms: MacOS X / PPC ; Authors: H D Moore <hdm [at] metasploit.com> ; Version: $Revision: 1612 $ ; License: ; ; This file is part of the Metasploit Exploit Framework ; and is subject to the same licenses and copyrights as ; the rest of this package. ; ; Description: ; ; This stub will flush the recv queue and continue ; execution. It can be used a prefix before a shell ; stage when using the MSG_PEEK stager. ; ;; .globl _main .text _main: li r0, 102 mr r3, r30 subi r4, r1, 0xfff * 2 li r5, 0xfff xor r6, r6, r6 .long 0x44ffff02 xor. r6, r6, r6
;/*! ; @file ; ; @ingroup fapi ; ; @brief BmsOpen DOS wrapper ; ; (c) osFree Project 2021, <http://www.osFree.org> ; for licence see licence.txt in root directory, or project website ; ; This is Family API implementation for DOS, used with BIND tools ; to link required API ; ; @author Yuri Prokushev (yuri.prokushev@gmail.com) ; ; 0 NO_ERROR ; 385 ERROR_MOUSE_NO_DEVICE ; 390 ERROR_MOUSE_INV_MODULE_PT ; 466 ERROR_MOU_DETACHED ; 501 ERROR_MOUSE_NO_CONSOLE ; 505 ERROR_MOU_EXTENDED_SG ; ;INT 33 - MS MOUSE - RESET DRIVER AND READ STATUS ; ; AX = 0000h ;Return: AX = status ; 0000h hardware/driver not installed ; FFFFh hardware/driver installed ; BX = number of buttons ; 0000h other than two ; 0002h two buttons (many drivers) ; 0003h Mouse Systems/Logitech three-button mouse ; FFFFh two buttons ;Notes: since INT 33 might be uninitialized on old machines, the caller ; should first check that INT 33 is neither 0000h:0000h nor points at ; an IRET instruction (BYTE CFh) before calling this API ; to use mouse on a Hercules-compatible monographics card in graphics ; mode, you must first set 0040h:0049h to 6 for page 0 or 5 for page 1, ; and then call this function. Logitech drivers v5.01 and v6.00 ; reportedly do not correctly use Hercules graphics in dual-monitor ; systems, while version 4.10 does. ; the Logitech mouse driver contains the signature string "LOGITECH" ; three bytes past the interrupt handler; many of the Logitech mouse ; utilities check for this signature. ; Logitech MouseWare v6.30 reportedly does not support CGA video modes ; if no CGA is present when it is started and the video board is ; later switched into CGA emulation ;SeeAlso: AX=0011h,AX=0021h,AX=002Fh,INT 62/AX=007Ah,INT 74 ; ;*/ .8086 ; Helpers INCLUDE helpers.inc INCLUDE bseerr.inc _TEXT SEGMENT BYTE PUBLIC 'CODE' USE16 @BMSPROLOG BMSOPEN MOUHANDLE DD ? ;MOUSE HANDLE DRIVERNAME DD ? ; @BMSSTART BMSOPEN XOR AX, AX INT 33H CMP AX, 0FFFFH MOV AX, ERROR_MOUSE_NO_DEVICE JNZ @f XOR AX,AX @@: @BMSEPILOG BMSOPEN _TEXT ENDS END
dc.w word_ABE2C-Map_SStageSonic dc.w word_ABE2E-Map_SStageSonic dc.w word_ABE3C-Map_SStageSonic dc.w word_ABE4A-Map_SStageSonic dc.w word_ABE5E-Map_SStageSonic dc.w word_ABE72-Map_SStageSonic dc.w word_ABE86-Map_SStageSonic dc.w word_ABE9A-Map_SStageSonic dc.w word_ABEAE-Map_SStageSonic dc.w word_ABEC2-Map_SStageSonic dc.w word_ABECA-Map_SStageSonic dc.w word_ABED2-Map_SStageSonic PLC_SStageSonic:dc.w word_ABE2C-PLC_SStageSonic dc.w word_ABEDA-PLC_SStageSonic dc.w word_ABEE0-PLC_SStageSonic dc.w word_ABEE6-PLC_SStageSonic dc.w word_ABEEE-PLC_SStageSonic dc.w word_ABEF6-PLC_SStageSonic dc.w word_ABEFE-PLC_SStageSonic dc.w word_ABF06-PLC_SStageSonic dc.w word_ABF0E-PLC_SStageSonic dc.w word_ABF16-PLC_SStageSonic dc.w word_ABF1A-PLC_SStageSonic dc.w word_ABF1E-PLC_SStageSonic word_ABE2C: dc.w 0 word_ABE2E: dc.w 2 dc.b $DD, $F, 0, 0, $FF, $F0 dc.b $FD, 8, 0, $10, $FF, $F2 word_ABE3C: dc.w 2 dc.b $D5, $F, 0, 0, $FF, $F0 dc.b $F5, 9, 0, $10, $FF, $F1 word_ABE4A: dc.w 3 dc.b $D5, $F, 0, 0, $FF, $F0 dc.b $F5, 8, 0, $10, $FF, $F2 dc.b $FD, 5, 0, $13, $FF, $F2 word_ABE5E: dc.w 3 dc.b $D5, $F, 0, 0, $FF, $F0 dc.b $F5, 8, 0, $10, $FF, $F2 dc.b $FD, 5, 0, $13, $FF, $F2 word_ABE72: dc.w 3 dc.b $D5, $F, 0, 0, $FF, $EE dc.b $F5, 8, 0, $10, $FF, $F6 dc.b $FD, 1, 0, $13, $FF, $F6 word_ABE86: dc.w 3 dc.b $D5, $F, 8, 0, $FF, $EF dc.b $F5, 8, 8, $10, $FF, $F7 dc.b $FD, 5, 8, $13, $FF, $FF word_ABE9A: dc.w 3 dc.b $D5, $F, 8, 0, $FF, $EF dc.b $F5, 8, 8, $10, $FF, $F7 dc.b $FD, 5, 8, $13, $FF, $FF word_ABEAE: dc.w 3 dc.b $D5, $F, 8, 0, $FF, $F0 dc.b $F5, 8, 8, $10, $FF, $F0 dc.b $FD, 1, 8, $13, 0, 0 word_ABEC2: dc.w 1 dc.b $DA, $F, 0, 0, $FF, $F0 word_ABECA: dc.w 1 dc.b $DA, $F, 0, 0, $FF, $F0 word_ABED2: dc.w 1 dc.b $DA, $F, 0, 0, $FF, $F0 word_ABEDA: dc.w 2 dc.w $F000 dc.w $2010 word_ABEE0: dc.w 2 dc.w $F013 dc.w $5023 word_ABEE6: dc.w 3 dc.w $F029 dc.w $2039 dc.w $303C word_ABEEE: dc.w 3 dc.w $F040 dc.w $2050 dc.w $3053 word_ABEF6: dc.w 3 dc.w $F057 dc.w $2067 dc.w $106A word_ABEFE: dc.w 3 dc.w $F029 dc.w $2039 dc.w $303C word_ABF06: dc.w 3 dc.w $F040 dc.w $2050 dc.w $3053 word_ABF0E: dc.w 3 dc.w $F057 dc.w $2067 dc.w $106A word_ABF16: dc.w 1 dc.w $F06C word_ABF1A: dc.w 1 dc.w $F07C word_ABF1E: dc.w 1 dc.w $F08C
section .text bits 64 global out_8 global out_16 global out_32 global in_8 global in_16 global in_32 global read_msr global read_cr8 global write_cr8 global write_msr global cpuid global flush_gdt global flush_idt global cmpxchg_32 global xinc_32 global cli global sti global read_cr3 global write_cr3 global flush_tlb global hlt global flush_tss flush_tss: mov ax, di ltr ax ret hlt: hlt ret flush_tlb: mov rax, cr3 mov cr3, rax ret read_cr3: mov rax, cr3 ret write_cr3: mov cr3, rdi ret read_cr8: mov rax, cr8 ret write_cr8: mov cr8, rdi ret cli: cli ret sti: sti ret out_32: mov rdx,rdi mov rax,rsi out dx,eax nop nop nop ret out_16: mov rdx,rdi mov rax,rsi out dx,ax nop nop nop ret out_8: mov rdx,rdi mov rax,rsi out dx,al nop nop nop ret in_8: mov rdx,rdi xor rax,rax in al,dx nop nop nop ret in_16: mov rdx,rdi xor rax,rax in ax,dx nop nop nop ret in_32: mov rdx,rdi xor rax,rax in eax,dx nop nop nop ret read_msr: ; preserve rdx push rdx mov ecx, dword [rdi] rdmsr mov dword [rdi], ecx mov dword [rsi], edx pop r11 mov dword [r11], eax ret write_msr: mov ecx, dword [rdi] mov eax, dword [rdx] mov edx, dword [rsi] wrmsr ret cpuid: push rbp mov rbp,rsp ; preserve rbx,rcx,rdx push rbx push rcx push rdx ; cpuid parameters eax,ecx mov eax, dword [rdi] mov ecx, dword [rdx] cpuid ; write results back to memory mov dword [rdi], eax mov dword [rsi], ebx pop r11 mov dword [r11], ecx pop r11 mov dword [r11], edx pop rbx mov rsp,rbp pop rbp ret flush_gdt: push rbp mov rbp, rsp lgdt [rdi] ;reload cs push rdx ; data_slct : ss push rbp ; rsp pushfq push rsi ; cs mov rax, .reload push rax ;rip iretq .reload: mov es,rdx mov fs,rdx mov gs,rdx mov ds,rdx pop rbp ret flush_idt: lidt [rdi] ret ; ============================ cmpxchg_32: mov eax, esi; eax = test_node_compare lock cmpxchg dword [rdi], edx ; edx = val, rdi = ptr to dst ret ; ============================ xinc_32: lock xadd dword [rdi], esi ; [rdi] = [rdi] + esi, esi = old [rdi] xor rax, rax mov eax, esi ret
ORG 0x7c00 BITS 16 CODE_SEG equ gdt_code - gdt_start DATA_SEG equ gdt_data - gdt_start _start: jmp short start nop times 33 db 0 start: jmp 0:step2 step2: cli ; Clear Interrupts mov ax, 0x00 mov ds, ax mov es, ax mov ss, ax mov sp, 0x7c00 sti ; Enable Interrupts .load_protected: cli lgdt[gdt_descriptor] mov eax, cr0 or eax, 0x1 mov cr0, eax jmp CODE_SEG:load32 ; GDT gdt_start: gdt_null: dd 0x0 dd 0x0 ;offset 0x0 gdt_code: ; CS SHOULD POINT TO THIS dw 0xffff ; Segment limit first 0-15 bits dw 0 ; Base first 0-15 bits db 0 ; Base 16-23 bits db 0x9a ; Access bit db 11001111b ; High 4 bit flags and the low 4 bit flags db 0 ; Base 24-31 bits ; offset 0x10 gdt_data: ; DS, SS, ES FS, GS dw 0xffff ; Segment limit first 0-15 bits dw 0 ; Base first 0-15 bits db 0 ; Base 16-23 bits db 0x92 ; Access bit db 11001111b ; High 4 bit flags and the low 4 bit flags db 0 ; Base 24-31 bits gdt_end: gdt_descriptor: dw gdt_end - gdt_start - 1 dd gdt_start [BITS 32] load32: mov eax, 1 mov ecx, 100 mov edi, 0x0100000 call ata_lba_read jmp CODE_SEG: 0x100000 ata_lba_read: mov ebx, eax, ; Backup the LBA ; Send the highest 8 bits of the lba to hard disk controller shr eax, 24 or eax, 0xE0 ; Select master drive mov dx, 0x1F6 out dx, al ; Finished sending the highest 8 bits of the lba ; Send the total sectors to read mov eax ,ecx mov dx, 0x1F2 out dx, al ; Finished sending the total sectors to read ; Send more bits of the LBA mov eax, ebx ; Restore the backup LBA mov dx, 0x1F3 out dx, al ; Finished sending more bits of the LBA ; Send more bits of the LBA mov dx, 0x1F4 mov eax, ebx ; Restore the backup LBA shr eax, 8 out dx, al ; Finished sending more bits of the LBA ; Send upper 16 bits of the LBA mov dx, 0x1F5 mov eax, ebx ; Restore the backup LBA shr eax, 16 out dx, al ; Finished sending upper 16 bits of the LBA mov dx, 0x1f7 mov al, 0x20 out dx, al ; Read all sectors into memory .next_sector: push ecx ; Check if we need to read .try_again: mov dx, 0x1f7 in al, dx test al, 8 jz .try_again ; We need to read 256 words at a time mov ecx, 256 mov dx, 0x1F0 rep insw pop ecx loop .next_sector ; End of reading sectors into memory ret times 510-($ - $$) db 0 dw 0xAA55
Name: zel_enmy5.asm Type: file Size: 31027 Last-Modified: '2016-05-13T04:23:03Z' SHA-1: 8A28027FF00D00B9215BBB9CC20B08F29637C40C Description: null
SECTION code_l_sccz80 PUBLIC l_i64_case EXTERN __i64_acc ; Entry: ; ACC = value to compare against l_i64_case: pop hl ; hl = & switch table loop: ld a,(hl) inc hl or (hl) inc hl jr z, end ; if end of table ld de,__i64_acc push hl ld b,8 continue: ld a,(de) inc de cp (hl) inc hl jr nz,nomatch djnz continue pop hl dec hl ld a,(hl) dec hl ld l,(hl) ld h,a end: jp (hl) nomatch: pop hl ld bc,8 add hl,bc jr loop
; A056169: Number of unitary prime divisors of n. ; 0,1,1,0,1,2,1,0,0,2,1,1,1,2,2,0,1,1,1,1,2,2,1,1,0,2,0,1,1,3,1,0,2,2,2,0,1,2,2,1,1,3,1,1,1,2,1,1,0,1,2,1,1,1,2,1,2,2,1,2,1,2,1,0,2,3,1,1,2,3,1,0,1,2,1,1,2,3,1,1,0,2,1,2,2,2,2,1,1,2,2,1,2,2,2,1,1,1,1,0 seq $0,55231 ; Powerfree part of n: product of primes that divide n only once. sub $0,1 seq $0,1222 ; Number of prime divisors of n counted with multiplicity (also called bigomega(n) or Omega(n)).
// // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // Official repository: https://github.com/boostorg/beast // //------------------------------------------------------------------------------ // // Example: WebSocket server, coroutine // //------------------------------------------------------------------------------ #include <boost/beast/core.hpp> #include <boost/beast/websocket.hpp> #include <boost/asio/ip/tcp.hpp> #include <boost/asio/spawn.hpp> #include <algorithm> #include <cstdlib> #include <functional> #include <iostream> #include <memory> #include <string> #include <thread> #include <vector> using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp> namespace websocket = boost::beast::websocket; // from <boost/beast/websocket.hpp> //------------------------------------------------------------------------------ // Report a failure void fail(boost::system::error_code ec, char const* what) { std::cerr << what << ": " << ec.message() << "\n"; } // Echoes back all received WebSocket messages void do_session(tcp::socket& socket, boost::asio::yield_context yield) { boost::system::error_code ec; // Construct the stream by moving in the socket websocket::stream<tcp::socket> ws{std::move(socket)}; // Accept the websocket handshake ws.async_accept(yield[ec]); if(ec) return fail(ec, "accept"); for(;;) { // This buffer will hold the incoming message boost::beast::multi_buffer buffer; // Read a message ws.async_read(buffer, yield[ec]); // This indicates that the session was closed if(ec == websocket::error::closed) break; if(ec) return fail(ec, "read"); // Echo the message back ws.text(ws.got_text()); ws.async_write(buffer.data(), yield[ec]); if(ec) return fail(ec, "write"); } } //------------------------------------------------------------------------------ // Accepts incoming connections and launches the sessions void do_listen( boost::asio::io_context& ioc, tcp::endpoint endpoint, boost::asio::yield_context yield) { boost::system::error_code ec; // Open the acceptor tcp::acceptor acceptor(ioc); acceptor.open(endpoint.protocol(), ec); if(ec) return fail(ec, "open"); // Allow address reuse acceptor.set_option(boost::asio::socket_base::reuse_address(true), ec); if(ec) return fail(ec, "set_option"); // Bind to the server address acceptor.bind(endpoint, ec); if(ec) return fail(ec, "bind"); // Start listening for connections acceptor.listen(boost::asio::socket_base::max_listen_connections, ec); if(ec) return fail(ec, "listen"); for(;;) { tcp::socket socket(ioc); acceptor.async_accept(socket, yield[ec]); if(ec) fail(ec, "accept"); else boost::asio::spawn( acceptor.get_executor().context(), std::bind( &do_session, std::move(socket), std::placeholders::_1)); } } int main(int argc, char* argv[]) { // Check command line arguments. if (argc != 4) { std::cerr << "Usage: websocket-server-coro <address> <port> <threads>\n" << "Example:\n" << " websocket-server-coro 0.0.0.0 8080 1\n"; return EXIT_FAILURE; } auto const address = boost::asio::ip::make_address(argv[1]); auto const port = static_cast<unsigned short>(std::atoi(argv[2])); auto const threads = std::max<int>(1, std::atoi(argv[3])); // The io_context is required for all I/O boost::asio::io_context ioc{threads}; // Spawn a listening port boost::asio::spawn(ioc, std::bind( &do_listen, std::ref(ioc), tcp::endpoint{address, port}, std::placeholders::_1)); // Run the I/O service on the requested number of threads std::vector<std::thread> v; v.reserve(threads - 1); for(auto i = threads - 1; i > 0; --i) v.emplace_back( [&ioc] { ioc.run(); }); ioc.run(); return EXIT_SUCCESS; }
// Copyright (c) 2014-2017, The Shangcoin Project // Copyright (c) 2017, The Masari Project // Zawy's LWMA difficulty algorithm // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, are // permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this list of // conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, this list // of conditions and the following disclaimer in the documentation and/or other // materials provided with the distribution. // // 3. Neither the name of the copyright holder nor the names of its contributors may be // used to endorse or promote products derived from this software without specific // prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #include <algorithm> #include <cassert> #include <cstddef> #include <cstdint> #include <vector> #include "common/int-util.h" #include "crypto/hash.h" #include "cryptonote_config.h" #include "difficulty.h" #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "difficulty" namespace cryptonote { using std::size_t; using std::uint64_t; using std::vector; #if defined(__x86_64__) static inline void mul(uint64_t a, uint64_t b, uint64_t &low, uint64_t &high) { low = mul128(a, b, &high); } #else static inline void mul(uint64_t a, uint64_t b, uint64_t &low, uint64_t &high) { // __int128 isn't part of the standard, so the previous function wasn't portable. mul128() in Windows is fine, // but this portable function should be used elsewhere. Credit for this function goes to latexi95. uint64_t aLow = a & 0xFFFFFFFF; uint64_t aHigh = a >> 32; uint64_t bLow = b & 0xFFFFFFFF; uint64_t bHigh = b >> 32; uint64_t res = aLow * bLow; uint64_t lowRes1 = res & 0xFFFFFFFF; uint64_t carry = res >> 32; res = aHigh * bLow + carry; uint64_t highResHigh1 = res >> 32; uint64_t highResLow1 = res & 0xFFFFFFFF; res = aLow * bHigh; uint64_t lowRes2 = res & 0xFFFFFFFF; carry = res >> 32; res = aHigh * bHigh + carry; uint64_t highResHigh2 = res >> 32; uint64_t highResLow2 = res & 0xFFFFFFFF; //Addition uint64_t r = highResLow1 + lowRes2; carry = r >> 32; low = (r << 32) | lowRes1; r = highResHigh1 + highResLow2 + carry; uint64_t d3 = r & 0xFFFFFFFF; carry = r >> 32; r = highResHigh2 + carry; high = d3 | (r << 32); } #endif static inline bool cadd(uint64_t a, uint64_t b) { return a + b < a; } static inline bool cadc(uint64_t a, uint64_t b, bool c) { return a + b < a || (c && a + b == (uint64_t) -1); } bool check_hash(const crypto::hash &hash, difficulty_type difficulty) { uint64_t low, high, top, cur; // First check the highest word, this will most likely fail for a random hash. mul(swap64le(((const uint64_t *) &hash)[3]), difficulty, top, high); if (high != 0) { return false; } mul(swap64le(((const uint64_t *) &hash)[0]), difficulty, low, cur); mul(swap64le(((const uint64_t *) &hash)[1]), difficulty, low, high); bool carry = cadd(cur, low); cur = high; mul(swap64le(((const uint64_t *) &hash)[2]), difficulty, low, high); carry = cadc(cur, low, carry); carry = cadc(high, top, carry); return !carry; } difficulty_type next_difficulty(std::vector<std::uint64_t> timestamps, std::vector<difficulty_type> cumulative_difficulties, size_t target_seconds) { if(timestamps.size() > DIFFICULTY_WINDOW) { timestamps.resize(DIFFICULTY_WINDOW); cumulative_difficulties.resize(DIFFICULTY_WINDOW); } size_t length = timestamps.size(); assert(length == cumulative_difficulties.size()); if (length <= 1) { return 1; } static_assert(DIFFICULTY_WINDOW >= 2, "Window is too small"); assert(length <= DIFFICULTY_WINDOW); sort(timestamps.begin(), timestamps.end()); size_t cut_begin, cut_end; static_assert(2 * DIFFICULTY_CUT <= DIFFICULTY_WINDOW - 2, "Cut length is too large"); if (length <= DIFFICULTY_WINDOW - 2 * DIFFICULTY_CUT) { cut_begin = 0; cut_end = length; } else { cut_begin = (length - (DIFFICULTY_WINDOW - 2 * DIFFICULTY_CUT) + 1) / 2; cut_end = cut_begin + (DIFFICULTY_WINDOW - 2 * DIFFICULTY_CUT); } assert(/*cut_begin >= 0 &&*/ cut_begin + 2 <= cut_end && cut_end <= length); uint64_t time_span = timestamps[cut_end - 1] - timestamps[cut_begin]; if (time_span == 0) { time_span = 1; } difficulty_type total_work = cumulative_difficulties[cut_end - 1] - cumulative_difficulties[cut_begin]; assert(total_work > 0); uint64_t low, high; mul(total_work, target_seconds, low, high); // blockchain errors "difficulty overhead" if this function returns zero. // TODO: consider throwing an exception instead if (high != 0 || low + time_span - 1 < low) { return 0; } return (low + time_span - 1) / time_span; } /* # Tom Harold (Degnr8) WT # Modified by Zawy to be a weighted-Weighted Harmonic Mean (WWHM) # No limits in rise or fall rate should be employed. # MTP should not be used. k = (N+1)/2 * T # original algorithm d=0, t=0, j=0 for i = height - N+1 to height # (N most recent blocks) # TS = timestamp solvetime = TS[i] - TS[i-1] solvetime = 10*T if solvetime > 10*T solvetime = -9*T if solvetime < -9*T j++ t += solvetime * j d +=D[i] # sum the difficulties next i t=T*N/2 if t < T*N/2 # in case of startup weirdness, keep t reasonable next_D = d * k / t */ difficulty_type next_difficulty_v2(std::vector<std::uint64_t> timestamps, std::vector<difficulty_type> cumulative_difficulties, size_t target_seconds) { if (timestamps.size() > DIFFICULTY_BLOCKS_COUNT_V2) { timestamps.resize(DIFFICULTY_BLOCKS_COUNT_V2); cumulative_difficulties.resize(DIFFICULTY_BLOCKS_COUNT_V2); } size_t length = timestamps.size(); assert(length == cumulative_difficulties.size()); if (length <= 1) { return 1; } uint64_t weighted_timespans = 0; uint64_t target; uint64_t previous_max = timestamps[0]; for (size_t i = 1; i < length; i++) { uint64_t timespan; uint64_t max_timestamp; if (timestamps[i] > previous_max) { max_timestamp = timestamps[i]; } else { max_timestamp = previous_max; } timespan = max_timestamp - previous_max; if (timespan == 0) { timespan = 1; } else if (timespan > 10 * target_seconds) { timespan = 10 * target_seconds; } weighted_timespans += i * timespan; previous_max = max_timestamp; } // adjust = 0.99 for N=60, leaving the + 1 for now as it's not affecting N target = 99 * (((length + 1) / 2) * target_seconds) / 100; uint64_t minimum_timespan = target_seconds * length / 2; if (weighted_timespans < minimum_timespan) { weighted_timespans = minimum_timespan; } difficulty_type total_work = cumulative_difficulties.back() - cumulative_difficulties.front(); assert(total_work > 0); uint64_t low, high; mul(total_work, target, low, high); if (high != 0) { return 0; } return low / weighted_timespans; } }
// // EnumValueParserScenarios.cpp // TUCUT // // Created by Wahid Tanner on 10/7/14. // Copyright © 2018 Take Up Code. All rights reserved. // #include <string> #include "../../Test/Test.h" #include "../ProtoParser.h" #include "../EnumValueParser.h" using namespace std; using namespace TUCUT; SCENARIO( EnumValueParser, "Construction/Normal", "unit,protocol", "EnumValueParser can be constructed." ) { Protocol::EnumValueParser parser; } SCENARIO( EnumValueParser, "Parsing/Normal", "unit,protocol", "EnumParser can parse simple enum." ) { shared_ptr<Protocol::ProtoModel> model; Protocol::ProtoParser parser("Messages/EnumValue.proto"); model = parser.parse(); int count = 0; auto begin = model->enums()->cbegin(); auto end = model->enums()->cend(); while (begin != end) { count++; auto enumeration = *begin; VERIFY_EQUAL("enumOne", enumeration->name()); int valueCount = 0; auto begin1 = enumeration->enumValues()->cbegin(); auto end1 = enumeration->enumValues()->cend(); while (begin1 != end1) { valueCount++; auto value = *begin1; unsigned int expectedValue = 0; if (valueCount == 1) { VERIFY_EQUAL("empty", value->name()); expectedValue = 0; VERIFY_EQUAL(expectedValue, value->value()); } else { VERIFY_EQUAL("full", value->name()); expectedValue = 1; VERIFY_EQUAL(expectedValue, value->value()); } begin1++; } VERIFY_EQUAL(2, valueCount); begin++; } VERIFY_EQUAL(1, count); } SCENARIO( EnumValueParser, "Parsing/Normal", "unit,protocol", "EnumValueParser can parse multiple enums with values and different parents." ) { shared_ptr<Protocol::ProtoModel> model; Protocol::ProtoParser parser("Messages/EnumValueMultipleMessage.proto"); model = parser.parse(); int enum0Count = 0; auto begin = model->enums()->cbegin(); auto end = model->enums()->cend(); while (begin != end) { enum0Count++; auto enumeration = *begin; if (enum0Count == 1) { VERIFY_EQUAL("enumZero1", enumeration->name()); int valueCount = 0; auto begin5 = enumeration->enumValues()->cbegin(); auto end5 = enumeration->enumValues()->cend(); while (begin5 != end5) { valueCount++; auto value = *begin5; unsigned int expectedValue = 0; if (valueCount == 1) { VERIFY_EQUAL("abc", value->name()); expectedValue = 5; VERIFY_EQUAL(expectedValue, value->value()); } else { VERIFY_EQUAL("def", value->name()); expectedValue = 10; VERIFY_EQUAL(expectedValue, value->value()); } begin5++; } VERIFY_EQUAL(2, valueCount); } else { VERIFY_EQUAL("enumZero2", enumeration->name()); int valueCount = 0; auto begin5 = enumeration->enumValues()->cbegin(); auto end5 = enumeration->enumValues()->cend(); while (begin5 != end5) { valueCount++; auto value = *begin5; unsigned int expectedValue = 15; VERIFY_EQUAL("ghi", value->name()); VERIFY_EQUAL(expectedValue, value->value()); begin5++; } VERIFY_EQUAL(1, valueCount); } VERIFY_EQUAL("", enumeration->package()); begin++; } int message1Count = 0; auto begin1 = model->messages()->cbegin(); auto end1 = model->messages()->cend(); while (begin1 != end1) { message1Count++; auto message1 = *begin1; VERIFY_EQUAL("messageOne", message1->name()); int message2Count = 0; auto begin2 = message1->messages()->cbegin(); auto end2 = message1->messages()->cend(); while (begin2 != end2) { message2Count++; auto message2 = *begin2; VERIFY_EQUAL("messageTwo", message2->name()); int enum2Count = 0; auto begin3 = message2->enums()->cbegin(); auto end3 = message2->enums()->cend(); while (begin3 != end3) { enum2Count++; auto enumeration = *begin3; VERIFY_EQUAL("enumTwo", enumeration->name()); VERIFY_EQUAL("", enumeration->package()); int valueCount = 0; auto begin5 = enumeration->enumValues()->cbegin(); auto end5 = enumeration->enumValues()->cend(); while (begin5 != end5) { valueCount++; auto value = *begin5; unsigned int expectedValue = 0; if (valueCount == 1) { VERIFY_EQUAL("true", value->name()); expectedValue = 1; VERIFY_EQUAL(expectedValue, value->value()); } else { VERIFY_EQUAL("false", value->name()); expectedValue = 0; VERIFY_EQUAL(expectedValue, value->value()); } begin5++; } VERIFY_EQUAL(2, valueCount); begin3++; } VERIFY_EQUAL(1, enum2Count); begin2++; } int enum1Count = 0; auto begin4 = message1->enums()->cbegin(); auto end4 = message1->enums()->cend(); while (begin4 != end4) { enum1Count++; auto enumeration = *begin4; VERIFY_EQUAL("enumOne", enumeration->name()); VERIFY_EQUAL("", enumeration->package()); int valueCount = 0; auto begin5 = enumeration->enumValues()->cbegin(); auto end5 = enumeration->enumValues()->cend(); while (begin5 != end5) { valueCount++; auto value = *begin5; unsigned int expectedValue = 0; if (valueCount == 1) { VERIFY_EQUAL("and", value->name()); expectedValue = 0; VERIFY_EQUAL(expectedValue, value->value()); } else if (valueCount == 2) { VERIFY_EQUAL("or", value->name()); expectedValue = 1; VERIFY_EQUAL(expectedValue, value->value()); } else { VERIFY_EQUAL("xor", value->name()); expectedValue = 2; VERIFY_EQUAL(expectedValue, value->value()); } begin5++; } VERIFY_EQUAL(3, valueCount); begin4++; } VERIFY_EQUAL(1, enum1Count); VERIFY_EQUAL(1, message2Count); begin1++; } VERIFY_EQUAL(2, enum0Count); VERIFY_EQUAL(1, message1Count); }
; /***************************************************************************** ; * ugBASIC - an isomorphic BASIC language compiler for retrocomputers * ; ***************************************************************************** ; * Copyright 2021 Marco Spedaletti (asimov@mclink.it) ; * ; * 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. ; *---------------------------------------------------------------------------- ; * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0 ; * (la "Licenza"); è proibito usare questo file se non in conformità alla ; * Licenza. Una copia della Licenza è disponibile all'indirizzo: ; * ; * http://www.apache.org/licenses/LICENSE-2.0 ; * ; * Se non richiesto dalla legislazione vigente o concordato per iscritto, ; * il software distribuito nei termini della Licenza è distribuito ; * "COSì COM'è", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o ; * implicite. Consultare la Licenza per il testo specifico che regola le ; * autorizzazioni e le limitazioni previste dalla medesima. ; ****************************************************************************/ ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ;* * ;* CLEAR SCREEN ROUTINE FOR VIC-II * ;* * ;* by Marco Spedaletti * ;* * ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * CLSG: LDA BITMAPADDRESS STA COPYOFBITMAPADDRESS LDA BITMAPADDRESS+1 STA COPYOFBITMAPADDRESS+1 LDX #31 LDY #0 LDA #$0 CLSGY: STA (COPYOFBITMAPADDRESS),Y INY BNE CLSGY INC COPYOFBITMAPADDRESS+1 DEX BNE CLSGY LDX #64 CLSGY2: STA (COPYOFBITMAPADDRESS),Y INY DEX BNE CLSGY2 LDA COLORMAPADDRESS STA COPYOFCOLORMAPADDRESS LDA COLORMAPADDRESS+1 STA COPYOFCOLORMAPADDRESS+1 LDX #3 LDY #0 LDA _PEN ASL A ASL A ASL A ASL A ORA _PAPER CLGC: STA (COPYOFCOLORMAPADDRESS),Y INY BNE CLGC INC COPYOFCOLORMAPADDRESS+1 CPX #1 BNE CLGCNB CLGC2: STA (COPYOFCOLORMAPADDRESS),Y INY CPY #232 BNE CLGC2 CLGCNB: DEX BNE CLGC RTS
;------------------------------------------------------------------------------ ; ; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR> ; This program and the accompanying materials ; are licensed and made available under the terms and conditions of the BSD License ; which accompanies this distribution. The full text of the license may be found at ; http://opensource.org/licenses/bsd-license.php. ; ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. ; ; Module Name: ; ; CpuIceBreakpoint.Asm ; ; Abstract: ; ; CpuIceBreakpoint function ; ; Notes: ; ;------------------------------------------------------------------------------ DEFAULT REL SECTION .text ;------------------------------------------------------------------------------ ; VOID ; EFIAPI ; CpuIceBreakpoint ( ; VOID ; ); ;------------------------------------------------------------------------------ global ASM_PFX(CpuIceBreakpoint) ASM_PFX(CpuIceBreakpoint): int1 ret
; --------------------------------------------------------------------------- ; Sprite mappings - smashable walls (GHZ, SLZ) ; --------------------------------------------------------------------------- dc.w byte_D2BC-Map_obj3C dc.w byte_D2E5-Map_obj3C dc.w byte_D30E-Map_obj3C byte_D2BC: dc.b 8 dc.b $E0, 5, 0, 0, $F0 dc.b $F0, 5, 0, 0, $F0 dc.b 0, 5, 0, 0, $F0 dc.b $10, 5, 0, 0, $F0 dc.b $E0, 5, 0, 4, 0 dc.b $F0, 5, 0, 4, 0 dc.b 0, 5, 0, 4, 0 dc.b $10, 5, 0, 4, 0 byte_D2E5: dc.b 8 dc.b $E0, 5, 0, 4, $F0 dc.b $F0, 5, 0, 4, $F0 dc.b 0, 5, 0, 4, $F0 dc.b $10, 5, 0, 4, $F0 dc.b $E0, 5, 0, 4, 0 dc.b $F0, 5, 0, 4, 0 dc.b 0, 5, 0, 4, 0 dc.b $10, 5, 0, 4, 0 byte_D30E: dc.b 8 dc.b $E0, 5, 0, 4, $F0 dc.b $F0, 5, 0, 4, $F0 dc.b 0, 5, 0, 4, $F0 dc.b $10, 5, 0, 4, $F0 dc.b $E0, 5, 0, 8, 0 dc.b $F0, 5, 0, 8, 0 dc.b 0, 5, 0, 8, 0 dc.b $10, 5, 0, 8, 0 even
//sesui_packer:ignore #include <windows.h> #include "../sesui.hpp" //sesui_packer:resume sesui::color color_clipboard = sesui::color( 1.0f, 1.0f, 1.0f, 1.0f ); std::array< sesui::color, 7 > hue_colors = { sesui::color ( 1.0f, 0, 0, 1.0f ), sesui::color ( 1.0f, 1.0f, 0, 1.0f ), sesui::color ( 0, 1.0f, 0 , 1.0f ), sesui::color ( 0, 1.0f, 1.0f , 1.0f ), sesui::color ( 0, 0, 1.0f, 1.0f ), sesui::color ( 1.0f, 0, 1.0f , 1.0f ), sesui::color ( 1.0f, 0, 0, 1.0f ) }; std::array< std::basic_string < sesui::ses_char >, 2 > color_options { L"Copy", L"Paste" }; void sesui::colorpicker ( const ses_string& name, color& option ) { const auto window = globals::window_ctx.find ( globals::cur_window ); if ( window == globals::window_ctx.end ( ) ) throw L"Current window context not valid."; const auto same_line_backup = window->second.cursor_stack.back ( ); if ( window->second.same_line ) { window->second.cursor_stack.back ( ).y -= window->second.last_cursor_offset; window->second.cursor_stack.back ( ).x += style.same_line_offset; } const auto parts = split ( name.get ( ) ); auto title = ses_string ( parts.first.data ( ) ); const auto& id = parts.second; vec2 title_size; draw_list.get_text_size ( style.control_font, title, title_size ); rect check_rect { window->second.cursor_stack.back ( ).x + scale_dpi ( style.button_size.x - style.inline_button_size.x ), window->second.cursor_stack.back ( ).y, style.inline_button_size.x, style.inline_button_size.y }; if ( window->second.same_line ) check_rect = { window->second.cursor_stack.back ( ).x, window->second.cursor_stack.back ( ).y, style.inline_button_size.x, style.inline_button_size.y }; const auto frametime = draw_list.get_frametime ( ); /* don't draw objects we don't need so our fps doesnt go to shit */ auto should_draw = true; if ( !window->second.group_ctx.empty ( ) && !input::in_clip ( vec2 ( window->second.cursor_stack.back ( ).x + 1.0f, window->second.cursor_stack.back ( ).y ) ) && !input::in_clip ( vec2 ( window->second.cursor_stack.back ( ).x + 1.0f, window->second.cursor_stack.back ( ).y + scale_dpi ( 60.0f ) ) ) ) should_draw = false; const auto in_region = input::mouse_in_region ( check_rect ); if ( in_region && !window->second.tooltip.empty ( ) ) window->second.hover_time [ window->second.cur_index ] += frametime; else window->second.hover_time [ window->second.cur_index ] = 0.0f; if ( window->second.hover_time [ window->second.cur_index ] > style.tooltip_hover_time ) { window->second.tooltip_anim_time += frametime * style.animation_speed; window->second.selected_tooltip = window->second.tooltip; } const auto active = in_region && input::key_down ( VK_LBUTTON ); if ( in_region && input::key_pressed ( VK_LBUTTON ) ) { window->second.anim_time [ window->second.cur_index ] = 1.0f; /* searching for input */ window->second.anim_time [ window->second.cur_index + 2 ] = 1.0f; } if ( ( input::key_pressed ( VK_RBUTTON ) || ( window->second.anim_time [ window->second.cur_index + 4 ] > 0.0f && input::key_state [ VK_LBUTTON ] && !input::old_key_state [ VK_LBUTTON ] ) ) ) { const auto calculated_height = style.button_size.y * color_options.size ( ); const auto list_rect = rect ( check_rect.x, check_rect.y + scale_dpi ( style.button_size.y + style.padding + style.padding ), style.button_size.x, calculated_height ); if ( in_region ) { if ( !window->second.anim_time [ window->second.cur_index + 3 ] ) window->second.anim_time [ window->second.cur_index + 3 ] = -1.0f; window->second.anim_time [ window->second.cur_index + 3 ] = -window->second.anim_time [ window->second.cur_index + 3 ]; input::enable_input ( false ); } else if ( !input::mouse_in_region ( list_rect, true ) && window->second.anim_time [ window->second.cur_index + 3 ] > 0.0f ) { window->second.anim_time [ window->second.cur_index + 3 ] = -1.0f; input::enable_input ( true ); } } window->second.anim_time [ window->second.cur_index ] = std::clamp< float > ( window->second.anim_time [ window->second.cur_index ] + -frametime * style.animation_speed, 0.0f, 1.0f ); window->second.anim_time [ window->second.cur_index + 1 ] = std::clamp< float > ( window->second.anim_time [ window->second.cur_index + 1 ] + ( in_region ? frametime : -frametime ) * style.animation_speed, 0.0f, 1.0f ); window->second.anim_time [ window->second.cur_index + 4 ] = std::clamp< float > ( window->second.anim_time [ window->second.cur_index + 4 ] + ( window->second.anim_time [ window->second.cur_index + 3 ] > 0.0f ? frametime : -frametime )* style.animation_speed, 0.0f, 1.0f ); window->second.anim_time [ window->second.cur_index + 6 ] = std::clamp< float > ( window->second.anim_time [ window->second.cur_index + 6 ] + ( window->second.anim_time [ window->second.cur_index + 2 ] ? frametime : -frametime ) * style.animation_speed, 0.0f, 1.0f ); rect color_picker_region { check_rect.x, check_rect.y - scale_dpi ( style.color_popup.y + style.padding ), style.color_popup.x, style.color_popup.y }; /* searching for input */ if ( window->second.anim_time [ window->second.cur_index + 2 ] ) { const auto original_input = input::enabled; input::enable_input ( false ); const auto backup_clip_enabled = globals::clip_enabled; globals::clip_enabled = false; const auto in_color_picker = input::mouse_in_region( color_picker_region, true ); globals::clip_enabled = backup_clip_enabled; if ( !original_input && !in_color_picker && input::key_state [ VK_LBUTTON ] && !input::old_key_state [ VK_LBUTTON ] ) { window->second.anim_time [ window->second.cur_index + 2 ] = 0.0f; window->second.anim_time [ window->second.cur_index ] = 1.0f; input::enable_input ( true ); } } if ( should_draw ) { if ( !window->second.same_line ) draw_list.add_text ( window->second.cursor_stack.back ( ), style.control_font, title, false, style.control_text.lerp ( style.control_text_hovered, window->second.anim_time [ window->second.cur_index + 1 ] ) ); const auto square_side_len = check_rect.h * 0.5f; auto alpha_clr_flip = false; const auto remaining_len = std::fmodf ( check_rect.w, square_side_len ); for ( auto i = 0.0f; i < check_rect.w; i += square_side_len ) { const auto calc_len = i > check_rect.w - square_side_len ? remaining_len : square_side_len; draw_list.add_rect ( rect ( check_rect.x + scale_dpi ( i ), check_rect.y, calc_len, calc_len ), alpha_clr_flip ? color ( 1.0f, 1.0f, 1.0f, 1.0f ) : color ( 0.82f, 0.82f, 0.82f, 1.0f ), true ); draw_list.add_rect ( rect ( check_rect.x + scale_dpi ( i ), check_rect.y + scale_dpi ( calc_len ), calc_len, calc_len ), alpha_clr_flip ? color ( 0.82f, 0.82f, 0.82f, 1.0f ) : color ( 1.0f, 1.0f, 1.0f, 1.0f ), true ); alpha_clr_flip = !alpha_clr_flip; } draw_list.add_rect ( check_rect, option, true ); draw_list.add_rect ( check_rect, style.control_borders.lerp ( active ? style.control_accent_borders : style.control_accent, window->second.anim_time [ window->second.cur_index + 1 ] ), false ); if ( window->second.anim_time [ window->second.cur_index + 6 ] ) { auto hue_bar_region = rect ( color_picker_region.x + scale_dpi ( color_picker_region.h - style.padding - style.color_bar_width ), color_picker_region.y + scale_dpi ( style.padding ), style.color_bar_width, color_picker_region.h - style.padding * 2.0f - style.color_bar_width - style.padding ); auto alpha_bar_region = rect ( color_picker_region.x + scale_dpi ( style.padding ), color_picker_region.y + scale_dpi ( color_picker_region.h - style.color_bar_width - style.padding ), color_picker_region.w - style.padding * 2.0f - style.color_bar_width - style.padding, style.color_bar_width ); auto color_square_region = rect ( color_picker_region.x + scale_dpi ( style.padding ), color_picker_region.y + scale_dpi ( style.padding ), color_picker_region.w - style.color_bar_width - style.padding * 3.0f, color_picker_region.h - style.color_bar_width - style.padding * 3.0f ); auto preview_color = rect ( color_picker_region.x + scale_dpi( color_picker_region.w - style.color_bar_width - style.padding ), color_picker_region.y + scale_dpi ( color_picker_region.h - style.color_bar_width - style.padding ), style.color_bar_width, style.color_bar_width ); const auto backup_clip_enabled = globals::clip_enabled; globals::clip_enabled = false; /* clicking logic */ /* color square */ if ( input::click_in_region ( color_square_region, true ) && input::key_state [ VK_LBUTTON ] ) { auto mouse_delta = input::mouse_pos - vec2 ( color_square_region.x, color_square_region.y ); mouse_delta.x = std::clamp < float > ( mouse_delta.x, 1.0f, scale_dpi(color_square_region.w) - 1.0f); mouse_delta.y = std::clamp < float > ( mouse_delta.y, 0.0f, scale_dpi(color_square_region.h) - 2.0f ); color as_hsv = option.to_hsv(); as_hsv.b = 1.0f - ( mouse_delta.y / ( scale_dpi ( color_square_region.h ) - 1.0f ) ); as_hsv.g = mouse_delta.x / ( scale_dpi ( color_square_region.w ) - 1.0f ); option = as_hsv.to_rgb ( ); } /* hue bar */ if ( input::click_in_region ( hue_bar_region, true ) && input::key_state [ VK_LBUTTON ] ) { const auto mouse_delta = std::clamp < float > ( input::mouse_pos.y - hue_bar_region.y, 0.0f, scale_dpi ( hue_bar_region.h ) - 1.0f ); color as_hsv = option.to_hsv ( ); as_hsv.r = mouse_delta / scale_dpi ( hue_bar_region.h ); option = as_hsv.to_rgb ( ); } /* alpha bar */ if ( input::click_in_region ( alpha_bar_region, true ) && input::key_state [ VK_LBUTTON ] ) { const auto mouse_delta = std::clamp < float > ( input::mouse_pos.x - alpha_bar_region.x, 0.0f, scale_dpi ( alpha_bar_region.w ) ); color as_hsv = option.to_hsv ( ); as_hsv.a = mouse_delta / scale_dpi ( alpha_bar_region.w ); option = as_hsv.to_rgb ( ); } globals::clip_enabled = backup_clip_enabled; /* window rect */ draw_list.add_rounded_rect ( color_picker_region, style.rounding, color ( style.control_background.r, style.control_background.g, style.control_background.b, 0.0f ).lerp ( style.control_background, window->second.anim_time [ window->second.cur_index + 6 ] ), true, true ); draw_list.add_rounded_rect ( color_picker_region, style.rounding, color ( style.control_borders.r, style.control_borders.g, style.control_borders.b, 0.0f ).lerp ( style.control_borders, window->second.anim_time [ window->second.cur_index + 6 ] ), false, true ); for ( auto i = 0; i < 6; i++ ) { draw_list.add_rect_gradient ( rect ( hue_bar_region.x, hue_bar_region.y + scale_dpi ( hue_bar_region.h ) / 6.0f * static_cast< float > ( i ), style.color_bar_width, hue_bar_region.h / 6.0f ), color ( ).lerp ( hue_colors [ i ], window->second.anim_time [ window->second.cur_index + 6 ] ), color ( ).lerp ( hue_colors [ i + 1 ], window->second.anim_time [ window->second.cur_index + 6 ] ), false, true, true ); } /* alpha bar background */ const auto square_side_len = alpha_bar_region.h * 0.5f; auto alpha_clr_flip = false; const auto remaining_len = std::fmodf ( alpha_bar_region.w, square_side_len ); for ( auto i = 0.0f; i < alpha_bar_region.w; i += square_side_len ) { const auto calc_len = i > alpha_bar_region.w - square_side_len ? remaining_len : square_side_len; draw_list.add_rect ( rect( alpha_bar_region.x + scale_dpi( i ), alpha_bar_region.y, calc_len, calc_len ), color ( ).lerp ( alpha_clr_flip ? color ( 1.0f, 1.0f, 1.0f, 1.0f ) : color ( 0.82f, 0.82f, 0.82f, 1.0f ), window->second.anim_time [ window->second.cur_index + 6 ] ), true, true ); draw_list.add_rect ( rect ( alpha_bar_region.x + scale_dpi ( i ), alpha_bar_region.y + scale_dpi( calc_len ), calc_len, calc_len ), color ( ).lerp ( alpha_clr_flip ? color ( 0.82f, 0.82f, 0.82f, 1.0f ) : color ( 1.0f, 1.0f, 1.0f, 1.0f ), window->second.anim_time [ window->second.cur_index + 6 ] ), true, true ); alpha_clr_flip = !alpha_clr_flip; } const auto preview_square_side_len = preview_color.h * 0.5f; auto preview_alpha_clr_flip = false; const auto preview_remaining_len = std::fmodf ( preview_color.w, preview_square_side_len ); for ( auto i = 0.0f; i < preview_color.w; i += preview_square_side_len ) { const auto calc_len = i > preview_color.w - preview_square_side_len ? preview_remaining_len : preview_square_side_len; draw_list.add_rect ( rect ( preview_color.x + scale_dpi ( i ), preview_color.y, calc_len, calc_len ), color ( ).lerp ( preview_alpha_clr_flip ? color ( 1.0f, 1.0f, 1.0f, 1.0f ) : color ( 0.82f, 0.82f, 0.82f, 1.0f ), window->second.anim_time [ window->second.cur_index + 6 ] ), true, true ); draw_list.add_rect ( rect ( preview_color.x + scale_dpi ( i ), preview_color.y + scale_dpi ( calc_len ), calc_len, calc_len ), color ( ).lerp ( preview_alpha_clr_flip ? color ( 0.82f, 0.82f, 0.82f, 1.0f ) : color ( 1.0f, 1.0f, 1.0f, 1.0f ), window->second.anim_time [ window->second.cur_index + 6 ] ), true, true ); preview_alpha_clr_flip = !preview_alpha_clr_flip; } draw_list.add_rect_gradient ( alpha_bar_region, color ( ).lerp ( color( option.r, option.g, option.b, 0.0f ), window->second.anim_time [ window->second.cur_index + 6 ] ), color ( ).lerp ( color ( option.r, option.g, option.b, 1.0f ), window->second.anim_time [ window->second.cur_index + 6 ] ), true, true, true ); draw_list.add_rect ( preview_color, color ( ).lerp ( option, window->second.anim_time [ window->second.cur_index + 6 ] ), true, true ); const auto step = 5; color as_hsv = option.to_hsv(); as_hsv.a = 1.0f; vec2 offset = vec2 ( 0.0f, 0.0f ); /* credits to ocornut ( ocornut's IMGUI ) */ for ( auto y = 0; y < step; y++ ) { for ( auto x = 0; x < step; x++ ) { const auto s0 = ( float ) x / ( float ) step; const auto s1 = ( float ) ( x + 1 ) / ( float ) step; const auto v0 = 1.0 - ( float ) ( y ) / ( float ) step; const auto v1 = 1.0 - ( float ) ( y + 1 ) / ( float ) step; color c00 = color ( as_hsv.r, s0, v0, 1.0f ).to_rgb ( ); color c10 = color ( as_hsv.r, s1, v0, 1.0f ).to_rgb ( ); color c01 = color ( as_hsv.r, s0, v1, 1.0f ).to_rgb ( ); color c11 = color ( as_hsv.r, s1, v1, 1.0f ).to_rgb ( ); draw_list.add_rect_multicolor ( rect( color_square_region.x + scale_dpi( offset.x ), color_square_region.y + scale_dpi( offset.y ), color_square_region.w / step, color_square_region.h / step ), color ( ).lerp ( c00, window->second.anim_time [ window->second.cur_index + 6 ] ), color ( ).lerp ( c10, window->second.anim_time [ window->second.cur_index + 6 ] ), color ( ).lerp ( c01, window->second.anim_time [ window->second.cur_index + 6 ] ), color ( ).lerp ( c11, window->second.anim_time [ window->second.cur_index + 6 ] ), true, true ); offset.x += color_square_region.w / step; } offset.x = 0; offset.y += color_square_region.h / step; } /* picker circle */ draw_list.add_circle ( vec2 ( color_square_region.x + as_hsv.g * scale_dpi ( color_square_region.w ), color_square_region.y + ( 1.0f - as_hsv.b ) * scale_dpi ( color_square_region.h ) ), 8.0f, color ( ).lerp ( color ( 1.0f, 1.0f, 1.0f, 0.6f ), window->second.anim_time [ window->second.cur_index + 6 ] ), false, true ); draw_list.add_circle ( vec2 ( color_square_region.x + as_hsv.g * scale_dpi ( color_square_region.w ), color_square_region.y + ( 1.0f - as_hsv.b ) * scale_dpi ( color_square_region.h ) ), 8.0f + unscale_dpi ( 1.0f ), color ( ).lerp ( color ( 0.0f, 0.0f, 0.0f, 0.3f ), window->second.anim_time [ window->second.cur_index + 6 ] ), false, true ); /* hue picker circle */ draw_list.add_circle ( vec2 ( hue_bar_region.x + scale_dpi ( hue_bar_region.w ) * 0.5f, hue_bar_region.y + scale_dpi ( hue_bar_region.h ) * as_hsv.r ), 8.0f, color ( ).lerp ( color ( 1.0f, 1.0f, 1.0f, 0.6f ), window->second.anim_time [ window->second.cur_index + 6 ] ), false, true ); draw_list.add_circle ( vec2 ( hue_bar_region.x + scale_dpi ( hue_bar_region.w ) * 0.5f, hue_bar_region.y + scale_dpi ( hue_bar_region.h ) * as_hsv.r ), 8.0f + unscale_dpi ( 1.0f ), color ( ).lerp ( color ( 0.0f, 0.0f, 0.0f, 0.3f ), window->second.anim_time [ window->second.cur_index + 6 ] ), false, true ); /* alpha picker circle */ draw_list.add_circle ( vec2 ( alpha_bar_region.x + scale_dpi ( alpha_bar_region.w ) * option.a, alpha_bar_region.y + scale_dpi ( alpha_bar_region.h ) * 0.5f ), 8.0f, color ( ).lerp ( color ( 1.0f, 1.0f, 1.0f, 0.6f ), window->second.anim_time [ window->second.cur_index + 6 ] ), false, true ); draw_list.add_circle ( vec2 ( alpha_bar_region.x + scale_dpi ( alpha_bar_region.w ) * option.a, alpha_bar_region.y + scale_dpi ( alpha_bar_region.h ) * 0.5f ), 8.0f + unscale_dpi ( 1.0f ), color ( ).lerp ( color ( 0.0f, 0.0f, 0.0f, 0.3f ), window->second.anim_time [ window->second.cur_index + 6 ] ), false, true ); } const auto backup_clip_enabled = globals::clip_enabled; globals::clip_enabled = false; if ( window->second.anim_time [ window->second.cur_index + 4 ] > 0.0f ) { const auto calculated_height = style.button_size.y * color_options.size ( ); const auto list_rect = rect ( check_rect.x, check_rect.y + scale_dpi ( style.button_size.y + style.padding + style.padding ), style.button_size.x, calculated_height * window->second.anim_time [ window->second.cur_index + 4 ] ); draw_list.add_rounded_rect ( list_rect, style.control_rounding, color ( style.control_background.r, style.control_background.g, style.control_background.b, 0.0f ).lerp ( style.control_background, window->second.anim_time [ window->second.cur_index + 4 ] ), true, true ); draw_list.add_rounded_rect ( list_rect, style.control_rounding, color ( style.control_borders.r, style.control_borders.g, style.control_borders.b, 0.0f ).lerp ( style.control_borders, window->second.anim_time [ window->second.cur_index + 4 ] ), false, true ); for ( auto i = 0; i < color_options.size ( ); i++ ) { vec2 text_size; draw_list.get_text_size ( style.control_font, color_options [ i ].data ( ), text_size ); if ( input::mouse_in_region ( rect ( window->second.cursor_stack.back ( ).x, list_rect.y + scale_dpi ( style.button_size.y ) * i, style.button_size.x, style.button_size.y ), true ) ) { if ( std::fabsf ( window->second.anim_time [ window->second.cur_index + 5 ] - static_cast< float > ( i ) ) > 0.1f ) window->second.anim_time [ window->second.cur_index + 5 ] += ( static_cast< float > ( i ) - window->second.anim_time [ window->second.cur_index + 5 ] > 0.0f ) ? frametime * style.animation_speed * 3.0f : ( -frametime * style.animation_speed * 3.0f ); else window->second.anim_time [ window->second.cur_index + 5 ] = static_cast< float > ( i ); if ( input::key_state [ VK_LBUTTON ] && !input::old_key_state [ VK_LBUTTON ] ) { window->second.anim_time [ window->second.cur_index + 3 ] = -1.0f; input::enable_input ( true ); switch ( i ) { case 0: { color_clipboard = option; } break; case 1: { option = color_clipboard; } break; } } } const auto lerped_color = style.control_accent.lerp ( style.control_text, std::clamp< float > ( std::fabsf ( static_cast< float > ( i ) - window->second.anim_time [ window->second.cur_index + 5 ] ), 0.0f, 1.0f ) ); if ( list_rect.y + scale_dpi ( style.button_size.y * 0.5f + i * style.button_size.y ) + text_size.y * 0.5f > list_rect.y + scale_dpi ( list_rect.h ) ) break; draw_list.add_text ( vec2 ( window->second.cursor_stack.back ( ).x + scale_dpi ( style.padding ), list_rect.y + scale_dpi ( style.button_size.y * 0.5f + i * style.button_size.y ) - text_size.y * 0.5f ), style.control_font, color_options [ i ].data ( ), true, color ( lerped_color.r, lerped_color.g, lerped_color.b, 0.0f ).lerp ( lerped_color, window->second.anim_time [ window->second.cur_index + 4 ] ), true ); } } globals::clip_enabled = backup_clip_enabled; } window->second.last_cursor_offset = scale_dpi ( style.padding + style.inline_button_size.y ); window->second.cursor_stack.back ( ).y += window->second.last_cursor_offset; window->second.cur_index += 7; window->second.tooltip.clear ( ); if ( window->second.same_line ) { window->second.cursor_stack.back ( ).x = same_line_backup.x; window->second.cursor_stack.back ( ).y = std::max< float > ( same_line_backup.y, window->second.cursor_stack.back ( ).y ); window->second.same_line = false; } }
; A078654: a(n) = prime(k) where k = n-th prime congruent to 3 mod 4. ; 5,17,31,67,83,127,191,211,277,331,353,401,431,563,587,709,739,797,877,967,991,1063,1153,1217,1297,1409,1433,1499,1597,1669,1741,1847,2027,2063,2221,2341,2417,2477,2609,2647,2897,3001,3067,3109,3299,3319,3407,3469,3517,3559,3593,3761,3943,4091,4153,4273,4397,4463,4567,4663,4787,4801,4933,5107,5189,5441,5503,5623,5651,5701,6037,6229,6323,6353,6469,6661,6691,6863,6899,7057,7109,7193,7481,7607,7649,7753,7841,8101,8221,8287,8389,8527,8719,8747,8849,9041,9293,9403,9461,9619 seq $0,97538 ; Subtract 2 from primes == 3 (mod 4). add $0,1 seq $0,40976 ; a(n) = prime(n) - 2. add $0,2
#include "stone/Gen/CodeEmitter.h" #include "stone/Syntax/Decl.h" using namespace stone; using namespace stone::codegen; using namespace stone::syn; CodeEmitter::CodeEmitter() {} //===----------------------------------------------------------------------===// // Decl //===----------------------------------------------------------------------===// void CodeEmitter::EmitDecl(const Decl &del) {} //===----------------------------------------------------------------------===// // Stmt //===----------------------------------------------------------------------===// void CodeEmitter::EmitStmt() {} //===----------------------------------------------------------------------===// // Expr //===----------------------------------------------------------------------===// void CodeEmitter::EmitExpr() {}
.main:
// Copyright 2015 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 "chromecast/browser/cast_resource_dispatcher_host_delegate.h" #include "chromecast/browser/cast_browser_process.h" #include "chromecast/net/connectivity_checker.h" #include "net/base/net_errors.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_status.h" namespace chromecast { namespace shell { void CastResourceDispatcherHostDelegate::RequestComplete( net::URLRequest* url_request) { if (url_request->status().status() == net::URLRequestStatus::FAILED) { LOG(ERROR) << "Failed to load resource " << url_request->url() << "; status:" << url_request->status().status() << ", error:" << net::ErrorToShortString(url_request->status().error()); CastBrowserProcess::GetInstance()->connectivity_checker()->Check(); } } } // namespace shell } // namespace chromecast
OaksLab_h: db DOJO ; tileset db OAKS_LAB_HEIGHT, OAKS_LAB_WIDTH ; dimensions (y, x) dw OaksLab_Blocks ; blocks dw OaksLab_TextPointers ; texts dw OaksLab_Script ; scripts db 0 ; connections dw OaksLab_Object ; objects
dnl AMD64 mpn_addmul_2 optimised for Intel Sandy Bridge. dnl Contributed to the GNU project by Torbjörn Granlund. dnl Copyright 2003-2005, 2007, 2008, 2011-2013 Free Software Foundation, Inc. dnl This file is part of the GNU MP Library. dnl dnl The GNU MP Library is free software; you can redistribute it and/or modify dnl it under the terms of either: dnl dnl * the GNU Lesser General Public License as published by the Free dnl Software Foundation; either version 3 of the License, or (at your dnl option) any later version. dnl dnl or dnl dnl * the GNU General Public License as published by the Free Software dnl Foundation; either version 2 of the License, or (at your option) any dnl later version. dnl dnl or both in parallel, as here. dnl dnl The GNU MP Library is distributed in the hope that it will be useful, but dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License dnl for more details. dnl dnl You should have received copies of the GNU General Public License and the dnl GNU Lesser General Public License along with the GNU MP Library. If not, dnl see https://www.gnu.org/licenses/. include(`../config.m4') C cycles/limb best C AMD K8,K9 C AMD K10 C AMD bull C AMD pile C AMD bobcat C AMD jaguar C Intel P4 C Intel core C Intel NHM C Intel SBR 2.93 this C Intel IBR 2.66 this C Intel HWL 2.5 2.15 C Intel BWL C Intel atom C VIA nano C This code is the result of running a code generation and optimisation tool C suite written by David Harvey and Torbjorn Granlund. C When playing with pointers, set this to $2 to fall back to conservative C indexing in wind-down code. define(`I',`$1') define(`rp', `%rdi') C rcx define(`up', `%rsi') C rdx define(`n_param', `%rdx') C r8 define(`vp', `%rcx') C r9 define(`n', `%rcx') define(`v0', `%rbx') define(`v1', `%rbp') define(`w0', `%r8') define(`w1', `%r9') define(`w2', `%r10') define(`w3', `%r11') define(`X0', `%r12') define(`X1', `%r13') ABI_SUPPORT(DOS64) ABI_SUPPORT(STD64) ASM_START() TEXT ALIGN(32) PROLOGUE(mpn_addmul_2) FUNC_ENTRY(4) push %rbx push %rbp push %r12 push %r13 mov (vp), v0 mov 8(vp), v1 mov (up), %rax mov n_param, n neg n lea (up,n_param,8), up lea 8(rp,n_param,8), rp mul v0 test $1, R8(n) jnz L(bx1) L(bx0): mov -8(rp,n,8), X0 mov %rdx, w1 add %rax, X0 adc $0, w1 mov (up,n,8), %rax xor w0, w0 xor w3, w3 test $2, R8(n) jnz L(b10) L(b00): nop C this nop make loop go faster on SBR! mul v1 mov (rp,n,8), X1 jmp L(lo0) L(b10): lea -2(n), n jmp L(lo2) L(bx1): mov -8(rp,n,8), X1 mov %rdx, w3 add %rax, X1 adc $0, w3 mov (up,n,8), %rax xor w1, w1 xor w2, w2 test $2, R8(n) jz L(b11) L(b01): mov (rp,n,8), X0 inc n jmp L(lo1) L(b11): dec n jmp L(lo3) ALIGN(32) L(top): L(lo1): mul v1 mov %rdx, w0 C 1 add %rax, X0 C 0 adc $0, w0 C 1 add w1, X1 C 3 adc $0, w3 C 0 add w2, X0 C 0 adc $0, w0 C 1 mov (up,n,8), %rax mul v0 add %rax, X0 C 0 mov %rdx, w1 C 1 adc $0, w1 C 1 mov (up,n,8), %rax mul v1 mov X1, -16(rp,n,8) C 3 mov (rp,n,8), X1 C 1 add w3, X0 C 0 adc $0, w1 C 1 L(lo0): mov %rdx, w2 C 2 mov X0, -8(rp,n,8) C 0 add %rax, X1 C 1 adc $0, w2 C 2 mov 8(up,n,8), %rax add w0, X1 C 1 adc $0, w2 C 2 mul v0 add %rax, X1 C 1 mov %rdx, w3 C 2 adc $0, w3 C 2 mov 8(up,n,8), %rax L(lo3): mul v1 add w1, X1 C 1 mov 8(rp,n,8), X0 C 2 adc $0, w3 C 2 mov %rdx, w0 C 3 add %rax, X0 C 2 adc $0, w0 C 3 mov 16(up,n,8), %rax mul v0 add w2, X0 C 2 mov X1, (rp,n,8) C 1 mov %rdx, w1 C 3 adc $0, w0 C 3 add %rax, X0 C 2 adc $0, w1 C 3 mov 16(up,n,8), %rax add w3, X0 C 2 adc $0, w1 C 3 L(lo2): mul v1 mov 16(rp,n,8), X1 C 3 add %rax, X1 C 3 mov %rdx, w2 C 4 adc $0, w2 C 4 mov 24(up,n,8), %rax mov X0, 8(rp,n,8) C 2 mul v0 add w0, X1 C 3 mov %rdx, w3 C 4 adc $0, w2 C 4 add %rax, X1 C 3 mov 24(up,n,8), %rax mov 24(rp,n,8), X0 C 0 useless but harmless final read adc $0, w3 C 4 add $4, n jnc L(top) L(end): mul v1 add w1, X1 adc $0, w3 add w2, %rax adc $0, %rdx mov X1, I(-16(rp),-16(rp,n,8)) add w3, %rax adc $0, %rdx mov %rax, I(-8(rp),-8(rp,n,8)) mov %rdx, %rax pop %r13 pop %r12 pop %rbp pop %rbx FUNC_EXIT() ret EPILOGUE()
; A038459: A sequence for measuring seconds: read it aloud. ; 1,1000,2,1000,3,1000,4,1000,5,1000,6,1000,7,1000,8,1000,9,1000,10,1000,11,1000,12,1000,13,1000,14,1000,15,1000,16,1000,17,1000,18,1000,19,1000,20,1000,21,1000,22,1000,23,1000,24,1000,25,1000 mov $1,3 add $1,$0 gcd $0,2 sub $0,1 sub $1,2002 div $1,2 mul $1,$0 add $1,1000
; A013709: a(n) = 4^(2n+1). ; 4,64,1024,16384,262144,4194304,67108864,1073741824,17179869184,274877906944,4398046511104,70368744177664,1125899906842624,18014398509481984,288230376151711744,4611686018427387904,73786976294838206464,1180591620717411303424,18889465931478580854784,302231454903657293676544,4835703278458516698824704,77371252455336267181195264,1237940039285380274899124224,19807040628566084398385987584,316912650057057350374175801344,5070602400912917605986812821504,81129638414606681695789005144064,1298074214633706907132624082305024,20769187434139310514121985316880384,332306998946228968225951765070086144 mov $1,16 pow $1,$0 mul $1,4 mov $0,$1
; Ok no lookers now. We need to write a program that can write any hex value in a register [org 0x7c00] ; Use dx as the parameter we pass mov dx, 0x1C9B call print_hex ; Loop infinitely after finishing jmp $ ; Lets write a print library %include "print_hex.asm" ; Define vars (note how we terminate stings with a null). This is the string we'll write into HEX_OUT: db '0x0000', 0 ; Pad rest of boot sector with zeroes times 510-($-$$) db 0 ; Write magic number at end of boot sector dw 0xaa55
; ---------------------------------------------------------------------- ; ahex.inc.asm ; ; A simple cat which write on STDOUT all what it reads on STDIN ; To assemble and run: ; ; nasm -felf64 acat.asm acat.data.asm \ ; && ld acat.o acat.data.o && ./a.out ; ---------------------------------------------------------------------- %assign buffer_size 16 %ifdef DATA %define _ATTR_ global %else %define _ATTR_ extern %endif _ATTR_ buffer_in _ATTR_ buffer_len _ATTR_ address _ATTR_ ptr_out _ATTR_ chars2display _ATTR_ line _ATTR_ bytes1 _ATTR_ bytes2 _ATTR_ chars _ATTR_ Lline _ATTR_ emptybytes _ATTR_ Lemptybytes _ATTR_ hexsymbols
/* * Copyright (C) 2019-2020 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "shared/source/helpers/state_compute_mode_helper.h" namespace NEO { template <> bool StateComputeModeHelper<TGLLPFamily>::isStateComputeModeRequired(CsrSizeRequestFlags &csrSizeRequestFlags, bool isThreadArbitionPolicyProgrammed) { return false; } } // namespace NEO
// // Copyright (c) 2012-2013, ARM Limited. All rights reserved. // // SPDX-License-Identifier: BSD-2-Clause-Patent // // #include <Library/ArmLib.h> INCLUDE AsmMacroIoLib.inc EXPORT ArmPlatformPeiBootAction EXPORT ArmPlatformGetCorePosition EXPORT ArmPlatformGetPrimaryCoreMpId EXPORT ArmPlatformIsPrimaryCore IMPORT _gPcd_FixedAtBuild_PcdArmPrimaryCore IMPORT _gPcd_FixedAtBuild_PcdArmPrimaryCoreMask PRESERVE8 AREA ArmPlatformNullHelper, CODE, READONLY ArmPlatformPeiBootAction FUNCTION bx lr ENDFUNC //UINTN //ArmPlatformGetCorePosition ( // IN UINTN MpId // ); ArmPlatformGetCorePosition FUNCTION and r1, r0, #ARM_CORE_MASK and r0, r0, #ARM_CLUSTER_MASK add r0, r1, r0, LSR #7 bx lr ENDFUNC //UINTN //ArmPlatformGetPrimaryCoreMpId ( // VOID // ); ArmPlatformGetPrimaryCoreMpId FUNCTION mov32 r0, FixedPcdGet32(PcdArmPrimaryCore) bx lr ENDFUNC //UINTN //ArmPlatformIsPrimaryCore ( // IN UINTN MpId // ); ArmPlatformIsPrimaryCore FUNCTION mov32 r1, FixedPcdGet32(PcdArmPrimaryCoreMask) and r0, r0, r1 mov32 r1, FixedPcdGet32(PcdArmPrimaryCore) cmp r0, r1 moveq r0, #1 movne r0, #0 bx lr ENDFUNC END